core.solvers¶
Numerical ODE solvers used by the simulation engine.
rk4.integrate_scalar_ode integrates a scalar ODE over an interval in equal classical fourth-order Runge-Kutta steps of at most one time constant each.
Integrating the Chamber Pressure explains the limit.
rk4.step_ode_system takes one classical fourth-order Runge-Kutta step for a system of variables.
machwave.core.solvers.rk4
¶
get_stable_step_count(variable_name, initial_value, compute_derivatives, interval, **constant_arguments)
¶
Return the number of equal Runge-Kutta steps to split interval into.
Each step spans at most _MAX_TIME_CONSTANTS_PER_STEP time constants.
A longer step can overshoot equilibrium.
A variable that is not settling toward equilibrium takes a single step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Keyword under which |
required |
initial_value
|
float
|
Value of the variable at the start of the interval. |
required |
compute_derivatives
|
Callable
|
Callable returning a tuple whose first item is the time derivative of the variable. |
required |
interval
|
float
|
Time interval to integrate over [s]. |
required |
**constant_arguments
|
Any
|
Keyword arguments passed unchanged to
|
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of steps, at least one. |
References
Dahlquist, G., "A Special Stability Problem for Linear Multistep Methods", BIT 3, 1963, pp. 27-43.
Source code in machwave/core/solvers/rk4.py
integrate_scalar_ode(variable_name, initial_value, compute_derivatives, interval, **constant_arguments)
¶
Integrate a scalar ODE over interval in equal Runge-Kutta steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Keyword under which |
required |
initial_value
|
float
|
Value of the variable at the start of the interval. |
required |
compute_derivatives
|
Callable
|
Callable returning a tuple whose first item is the time derivative of the variable. |
required |
interval
|
float
|
Time interval to integrate over [s]. |
required |
**constant_arguments
|
Any
|
Keyword arguments passed unchanged to
|
{}
|
Returns:
| Type | Description |
|---|---|
float
|
Value of the variable at the end of the interval and the number of steps |
int
|
taken. |
Source code in machwave/core/solvers/rk4.py
step_ode_system(initial_values, compute_derivatives, time_step, **constant_arguments)
¶
Advance a system of ODEs by one classical fourth-order Runge-Kutta step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_values
|
dict[str, float]
|
Mapping of variable name to its value at the start of the step. |
required |
compute_derivatives
|
Callable
|
Callable taking the variables and |
required |
time_step
|
float
|
Step size [s]. |
required |
**constant_arguments
|
Any
|
Keyword arguments passed unchanged to
|
{}
|
Returns:
| Type | Description |
|---|---|
float
|
Values of the variables at the end of the step, in the order of |
...
|
|