Karana.Integrators#
Collection of classes to represent mathematical object used in Karana Dynamics simulations.
Examples include unit quaternions, homogeneous transforms, and spatial vectors.
Submodules#
Attributes#
Classes#
The multistep ArkODE explicit integrator from the SUNDIALS suite |
|
The Vars for the ArkExplicitIntegrator class. |
|
The (implicit) Adaptive Runge-Kutta integrator from the SUNDIALS suite |
|
The Vars for the ArkImplicitIntegrator class. |
|
The multistep CVode integrator from the SUNDIALS suite |
|
The Vars for the CVodeIntegrator class. |
|
The fixed-step Euler one step integrator. |
|
Base class for numerical integrators |
|
A struct with integrator options. This struct can be |
|
Enum of integrator types. |
|
Fixed-step Runge-Kutta 4th order integrator |
|
Abstract base class for implicit Sundials integrators (CVode/ARKStep). |
|
Struct with options for this integrator |
|
The Vars for the SundialsImplicitIntegrator class. |
|
Abstract base class for Sundials-related integrators. |
|
Struct with options for this integrator |
|
The Vars for the SundialsIntegrator class. |
Functions#
Factory method for creating DAE Integrator instances |
|
|
Convert string to IntegratorType enum. |
Package Contents#
- class Karana.Integrators.ArkExplicitIntegrator#
Bases:
SundialsIntegrator,IntegratorThe multistep ArkODE explicit integrator from the SUNDIALS suite
- getAdaptiveStepping() bool#
Check whether this integrator is using adaptive step sizes.
- Returns:
A boolean corresponding to the adaptive status.
- getErrorContributions() Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
Get the error contribution for each state.
- Returns:
A vector with the error contribution for each state.
- getVars() ArkExplicitIntegratorVars#
- setAdaptiveStepping(use_adaptive_steps: bool) None#
Set whether adaptive timestepping should be used (defaults to true).
This converts all methods to fixed-step, regular variants. Prefer RK4Integrator unless you need a higher- or lower-order integration rule.
- Parameters:
use_adaptive_steps – Whether to use adaptive steps (the default) or lock the step size.
- Karana.Integrators.ArkExplicitIntegratorOptions#
- class Karana.Integrators.ArkExplicitIntegratorVars#
Bases:
SundialsIntegratorVarsThe Vars for the ArkExplicitIntegrator class.
- class Karana.Integrators.ArkImplicitIntegrator#
Bases:
SundialsImplicitIntegratorThe (implicit) Adaptive Runge-Kutta integrator from the SUNDIALS suite
- getErrorContributions() Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
Get the error contribution for each state.
- Returns:
A vector with the error contribution for each state.
- getVars() ArkImplicitIntegratorVars#
- Karana.Integrators.ArkImplicitIntegratorOptions#
- class Karana.Integrators.ArkImplicitIntegratorVars#
Bases:
SundialsImplicitIntegratorVarsThe Vars for the ArkImplicitIntegrator class.
- class Karana.Integrators.CVodeIntegrator#
Bases:
SundialsImplicitIntegratorThe multistep CVode integrator from the SUNDIALS suite
- getErrorContributions() Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
Get the error contribution for each state.
- Returns:
A vector with the error contribution for each state.
- getVars() CVodeIntegratorVars#
- Karana.Integrators.CVodeIntegratorOptions#
- class Karana.Integrators.CVodeIntegratorVars#
Bases:
SundialsImplicitIntegratorVarsThe Vars for the CVodeIntegrator class.
- property last_order: Karana.Core.VarInt#
Integration method order used during last step
- class Karana.Integrators.EulerIntegrator#
Bases:
IntegratorThe fixed-step Euler one step integrator.
- class Karana.Integrators.Integrator#
Bases:
Karana.Core.BaseWithVarsBase class for numerical integrators
- advanceTo(to_t: SupportsFloat | SupportsIndex | numpy.timedelta64) numpy.timedelta64#
Method to advance the system state to a specified time
- Parameters:
to_t – the desired end time
- Returns:
the actual end time
- derivFunction() collections.abc.Callable[[SupportsFloat | SupportsIndex | numpy.timedelta64, Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]], bool]#
Return the derivative function
- Returns:
the derivative function
- getIntegratorType() IntegratorType#
Get the IntegratorType for this integrator.
- Returns:
The IntegratorType for this integrator.
- getOptions() IntegratorOptions#
Get the options associated with the integrator.
- Returns:
The options associated with the integrator.
- getTime() numpy.timedelta64#
Return the current integrator time
- Returns:
the integrator state time
- getX() Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
Return the current integrator state
- Returns:
the integrator state vector
- hardReset(nstates: SupportsInt | SupportsIndex) None#
Reset the state size
- Parameters:
nstates – the new state size
- setVerboseTracing(verbose: bool) None#
Tell the integrator to be very verbose; mostly used for debugging numerics in a brute-force approach.
- Parameters:
verbose
- class Karana.Integrators.IntegratorOptions#
A struct with integrator options. This struct can be
sub-classed by specialized classes to add custom options.
- class Karana.Integrators.IntegratorType(*args, **kwds)#
Bases:
enum.EnumEnum of integrator types.
- ARKEXPLICIT: ClassVar[IntegratorType]#
- ARKEXPLICIT_CASH: ClassVar[IntegratorType]#
- ARKEXPLICIT_DOPRI: ClassVar[IntegratorType]#
- ARKEXPLICIT_FEHLBERG78: ClassVar[IntegratorType]#
- ARKEXPLICIT_HUEN_EULER: ClassVar[IntegratorType]#
- ARKIMPLICIT: ClassVar[IntegratorType]#
- ARKIMPLICIT_DIRK23: ClassVar[IntegratorType]#
- ARKIMPLICIT_ESDIRK45: ClassVar[IntegratorType]#
- ARKIMPLICIT_SDIRK12: ClassVar[IntegratorType]#
- ARKIMPLICIT_SDIRK34: ClassVar[IntegratorType]#
- CVODE: ClassVar[IntegratorType]#
- CVODE_NEWTON: ClassVar[IntegratorType]#
- CVODE_STIFF: ClassVar[IntegratorType]#
- EULER: ClassVar[IntegratorType]#
- IDA: ClassVar[IntegratorType]#
- NO_OP: ClassVar[IntegratorType]#
- RK4: ClassVar[IntegratorType]#
- classmethod to_yaml(representer, node)#
Class method used to represent IntegratorType in a yaml file.
- classmethod from_yaml(_, node) Self#
Construct a IntegratorType from yaml file data.
- static to_json(o: IntegratorType) dict[str, Any]#
Class method used to represent IntegratorType in a json file.
- class Karana.Integrators.RK4Integrator#
Bases:
IntegratorFixed-step Runge-Kutta 4th order integrator
- class Karana.Integrators.SundialsImplicitIntegrator#
Bases:
SundialsIntegratorAbstract base class for implicit Sundials integrators (CVode/ARKStep).
This class manages linear and nonlinear solvers specifically, and adds options and vars relating to implicit integration.
- getOptions() SundialsImplicitIntegratorOptions#
Get the options associated with the integrator.
- Returns:
The options associated with the integrator.
- setAndersonDamping(damping: SupportsFloat | SupportsIndex) None#
Set the Anderson damping factor to use for nonlinear solves; must be in (0, 1] and smaller means stronger damping.
- Parameters:
damping – Damping factor; pass a value of 1 for no damping.
- class Karana.Integrators.SundialsImplicitIntegratorOptions#
Bases:
SundialsIntegratorOptionsStruct with options for this integrator
- property anderson_damping: float#
Anderson damping in (0, 1] used for implicit integrators with fixed- point solves.
This is used to potentially speed up internal iterations by reusing past iterates (within the same time step). A value of 1 indicates no damping, and smaller values imply a “stronger” damping.
- class Karana.Integrators.SundialsImplicitIntegratorVars#
Bases:
SundialsIntegratorVarsThe Vars for the SundialsImplicitIntegrator class.
- property num_jac_evals: Karana.Core.VarLong#
Number of calls made to the CVLS Jacobian approximation function
- property num_lin_iters: Karana.Core.VarLong#
Number of linear iterations
- property num_lin_rhs_evals: Karana.Core.VarLong#
Number of RHS/derivative calls used to estimate jacobians
- property num_nonlin_iters: Karana.Core.VarLong#
Number of nonlinear iterations
- property num_step_solve_fails: Karana.Core.VarLong#
Number of rejected timesteps due to nonlinear solve failure
- class Karana.Integrators.SundialsIntegrator#
Bases:
IntegratorAbstract base class for Sundials-related integrators.
This class helps manage shared memory, options, and vars. It defines several pure virtual methods for the subclass to override and satisfies all virtual functions of an Integrator.
- getOptions() SundialsIntegratorOptions#
Get the options associated with the integrator.
- Returns:
The options associated with the integrator.
- setAtol(atol: SupportsFloat | SupportsIndex) None#
Set the scalar absolute tolerance used for controlling error vs runtime.
- Parameters:
atol – The scalar atol to use for all state variables.
- setRtol(rtol: SupportsFloat | SupportsIndex) None#
Set the relative tolerance used for controlling error vs runtime.
- Parameters:
rtol – The rtol to use for all state variables.
- setVectorAtol(atol_vec: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]] | None) None#
Set the vector absolute tolerance used for controlling error vs runtime, or a null value to fall back to scalar atol.
- Parameters:
atol_vec – The optional vector atol to use; must have same length as state vector or be null.
- class Karana.Integrators.SundialsIntegratorOptions#
Bases:
IntegratorOptionsStruct with options for this integrator
- property atol_vec: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]] | None#
The desired absolute tolerance vector used to control the integrator error. This can be used rather than a scalar tolerance to set different values for different states.
- class Karana.Integrators.SundialsIntegratorVars#
The Vars for the SundialsIntegrator class.
- property curr_step: Karana.Core.VarDouble#
Current step size to try on next advance call
- property last_step: Karana.Core.VarDouble#
Last successful step size
- property num_err_test_fails: Karana.Core.VarLong#
Cumulative number of error test failures due to too large of step size
- property num_rhs_evals: Karana.Core.VarLong#
Cumulative number of RHS calls taken by the solver
- property num_steps: Karana.Core.VarLong#
Cumulative number of internal steps taken by the solver
- Karana.Integrators.createIntegrator(integrator_type: IntegratorType, nstates: SupportsInt | SupportsIndex, deriv_fn: collections.abc.Callable, options: IntegratorOptions = None) Integrator#
- Karana.Integrators.createIntegrator(integrator_type: IntegratorType, nstates: SupportsInt | SupportsIndex, nalgebraic: SupportsInt | SupportsIndex, residuals_fn: collections.abc.Callable[[SupportsFloat | SupportsIndex | numpy.timedelta64, Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]], None], options: IntegratorOptions = None) Integrator
Factory method for creating DAE Integrator instances
- Parameters:
integrator_type – the type of integrator to create
nstates – the length of the states vector (continuous+algebraic)
nalgebraic – the number of algebraic values
residuals_fn – the residuals function
options – options for the integrator
- Returns:
a new DAE Integrator instance
- Karana.Integrators.strToIntegratorType(arg0: str) IntegratorType#
Convert string to IntegratorType enum.
- Parameters:
str – The name of the integrator type.
- Returns:
The IntegratorType associated with the string.