pathsim.solvers.gear module
- pathsim.solvers.gear.compute_bdf_coefficients(order, timesteps)[source]
Computes the coefficients for backward differentiation formulas for a given order. The timesteps can be specified for variable timestep BDF methods.
- For m-th order BDF we have for the n-th timestep:
sum(alpha_i * x_i; i=n-m,…,n) = h_n * f_n(x_n, t_n)
- or
x_n = beta * h_n * f_n(x_n, t_n) - sum(alpha_j * x_{n-1-j}; j=0,…,order-1)
- class pathsim.solvers.gear.GEAR(*solver_args, **solver_kwargs)[source]
Bases:
ImplicitSolverBase class for GEAR-type integrators that defines the universal methods.
Numerical integration method based on BDFs (linear multistep methods). Uses n-th order BDF for timestepping and (n-1)-th order BDF coefficients to estimate a lower ordersolutuin for error control.
The adaptive timestep BDF coefficients are dynamically computed at the beginning of each timestep from the buffered previous timsteps.
Notes
Not to be used directly!!!
- buffer(dt)[source]
Buffer the state and timestep. Dynamically precompute the variable timestep BDF coefficients on the fly for the current timestep.
- Parameters:
dt (float) – integration timestep
- revert()[source]
Revert integration engine to previous timestep, this is only relevant for adaptive methods where the simulation timestep ‘dt’ is rescaled and the engine step is recomputed with the smaller timestep.
- error_controller(tr)[source]
Compute scaling factor for adaptive timestep based on absolute and relative tolerances for local truncation error.
Checks if the error tolerance is achieved and returns a success metric.
- Parameters:
tr (array[float]) – truncation error estimate
- Returns:
success (bool) – True if the timestep was successful
error (float) – estimated error of the internal error controller
scale (float) – estimated timestep rescale factor for error control
- step(f, dt)[source]
Finalizes the timestep by resetting the solver for the implicit update equation and computing the lower order estimate of the solution for error control.
- Parameters:
f (array_like) – evaluation of function
dt (float) – integration timestep
- Returns:
success (bool) – True if the timestep was successful
error (float) – estimated error of the internal error controller
scale (float) – estimated timestep rescale factor for error control
- class pathsim.solvers.gear.GEAR21(*solver_args, **solver_kwargs)[source]
Bases:
GEARAdaptive GEAR integrator with 2-nd order BDF for timestepping and 1-st order BDF (euler backward) for truncation error estimation.
- class pathsim.solvers.gear.GEAR32(*solver_args, **solver_kwargs)[source]
Bases:
GEARAdaptive GEAR integrator with 3-rd order BDF for timestepping and 2-nd order BDF for truncation error estimation.
- class pathsim.solvers.gear.GEAR43(*solver_args, **solver_kwargs)[source]
Bases:
GEARAdaptive GEAR integrator with 4-th order BDF for timestepping and 3-rd order BDF for truncation error estimation.
- class pathsim.solvers.gear.GEAR54(*solver_args, **solver_kwargs)[source]
Bases:
GEARAdaptive GEAR integrator with 5-th order BDF for timestepping and 4-th order BDF for truncation error estimation.
- class pathsim.solvers.gear.GEAR52A(*solver_args, **solver_kwargs)[source]
Bases:
GEARAdaptive order adaptive stepsize GEAR integrator.
Adaptively selects the order (BDF coefficients) for timestepping between 2 and 5 depending on which method yields the lower truncation error. This balances the stability of the lower order methods with the accuracy of higher order methods.
Previous solutions and the variable timestep BDF coefficients are used to estimate a lower and a higher order solution from the solution of the timestepping method. This gives two separate estimates for the local tuncation error.
If the error is dominated by stability (lte of lower order method is lower), the order of the stepping method is decreased for the next timestep.
If the error is dominated by the accuracy of the method (higher order error is lower), the order of the stepping method is increased for the next timestep.
This means the integrator can take larger steps in regions where the solution is smooth using a higher order method and use more stable lower order methods in regions where the system exhibits stiffness or discontinuities.
- buffer(dt)[source]
Buffer the state and timestep. Dynamically precompute the variable timestep BDF coefficients on the fly for the current timestep.
- Parameters:
dt (float) – evaluation time
- error_controller(tr_m, tr_p)[source]
Compute scaling factor for adaptive timestep based on absolute and relative tolerances of the local truncation error estimate obtained from esimated lower and higher order solution.
Checks if the error tolerance is achieved and returns a success metric.
Adapts the stepping order such that the normalized error is minimized and larger steps can be taken by the integrator.
- Parameters:
- Returns:
success (bool) – True if the timestep was successful
error (float) – estimated error of the internal error controller
scale (float) – estimated timestep rescale factor for error control
- step(f, dt)[source]
Finalizes the timestep by resetting the solver for the implicit update equation and computing the lower and higher order estimate of the solution.
Then calls the error controller.
- Parameters:
f (array_like) – evaluation of function
dt (float) – integration timestep
- Returns:
success (bool) – True if the timestep was successful
error (float) – estimated error of the internal error controller
scale (float) – estimated timestep rescale factor for error control