pub struct OdeBuilder<M: Matrix = NalgebraMat<f64>, Rhs = UnitCallable<M>, Init = UnitCallable<M>, Mass = UnitCallable<M>, Root = UnitCallable<M>, Out = UnitCallable<M>> { /* private fields */ }
Expand description
Builder for ODE problems. Use methods to set parameters and then call one of the build methods when done.
Implementations§
Source§impl<M, Rhs, Init, Mass, Root, Out> OdeBuilder<M, Rhs, Init, Mass, Root, Out>where
M: Matrix,
Builder for ODE problems. Use methods to set parameters and then call one of the build methods when done.
impl<M, Rhs, Init, Mass, Root, Out> OdeBuilder<M, Rhs, Init, Mass, Root, Out>where
M: Matrix,
Builder for ODE problems. Use methods to set parameters and then call one of the build methods when done.
§Example
use diffsol::{OdeBuilder, NalgebraLU, Bdf, OdeSolverState, OdeSolverMethod, NalgebraMat};
type M = NalgebraMat<f64>;
type LS = NalgebraLU<f64>;
let problem = OdeBuilder::<M>::new()
.rtol(1e-6)
.p([0.1])
.rhs_implicit(
// dy/dt = -ay
|x, p, t, y| {
y[0] = -p[0] * x[0];
},
// Jv = -av
|x, p, t, v, y| {
y[0] = -p[0] * v[0];
},
)
.init(
// y(0) = 1
|p, t, y| y[0] = 1.0,
1,
)
.build()
.unwrap();
let mut solver = problem.bdf::<LS>().unwrap();
let t = 0.4;
while solver.state().t <= t {
solver.step().unwrap();
}
let y = solver.interpolate(t);
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder with default parameters:
- t0 = 0.0
- h0 = 1.0
- rtol = 1e-6
- atol = [1e-6]
- p = []
- use_coloring = false
- constant_mass = false
Sourcepub fn rhs<F>(
self,
rhs: F,
) -> OdeBuilder<M, ClosureNoJac<M, F>, Init, Mass, Root, Out>
pub fn rhs<F>( self, rhs: F, ) -> OdeBuilder<M, ClosureNoJac<M, F>, Init, Mass, Root, Out>
Set the right-hand side of the ODE.
§Arguments
rhs
: Function of type Fn(x: &V, p: &V, t: S, y: &mut V) that computes the right-hand side of the ODE.
Sourcepub fn rhs_implicit<F, G>(
self,
rhs: F,
rhs_jac: G,
) -> OdeBuilder<M, Closure<M, F, G>, Init, Mass, Root, Out>
pub fn rhs_implicit<F, G>( self, rhs: F, rhs_jac: G, ) -> OdeBuilder<M, Closure<M, F, G>, Init, Mass, Root, Out>
Set the right-hand side of the ODE.
§Arguments
rhs
: Function of type Fn(x: &V, p: &V, t: S, y: &mut V) that computes the right-hand side of the ODE.rhs_jac
: Function of type Fn(x: &V, p: &V, t: S, v: &V, y: &mut V) that computes the multiplication of the Jacobian of the right-hand side with the vector v.
Sourcepub fn rhs_sens_implicit<F, G, H>(
self,
rhs: F,
rhs_jac: G,
rhs_sens: H,
) -> OdeBuilder<M, ClosureWithSens<M, F, G, H>, Init, Mass, Root, Out>
pub fn rhs_sens_implicit<F, G, H>( self, rhs: F, rhs_jac: G, rhs_sens: H, ) -> OdeBuilder<M, ClosureWithSens<M, F, G, H>, Init, Mass, Root, Out>
Set the right-hand side of the ODE for forward sensitivity analysis.
§Arguments
rhs
: Function of type Fn(x: &V, p: &V, t: S, y: &mut V) that computes the right-hand side of the ODE.rhs_jac
: Function of type Fn(x: &V, p: &V, t: S, v: &V, y: &mut V) that computes the multiplication of the Jacobian of the right-hand side with the vector v.rhs_sens
: Function of type Fn(x: &V, p: &V, t: S, v: &V, y: &mut V) that computes the multiplication of the partial derivative of the rhs wrt the parameters, with the vector v.
pub fn rhs_adjoint_implicit<F, G, H, I>( self, rhs: F, rhs_jac: G, rhs_adjoint: H, rhs_sens_adjoint: I, ) -> OdeBuilder<M, ClosureWithAdjoint<M, F, G, H, I>, Init, Mass, Root, Out>
Sourcepub fn init<F>(
self,
init: F,
nstates: usize,
) -> OdeBuilder<M, Rhs, ConstantClosure<M, F>, Mass, Root, Out>
pub fn init<F>( self, init: F, nstates: usize, ) -> OdeBuilder<M, Rhs, ConstantClosure<M, F>, Mass, Root, Out>
Set the initial condition of the ODE.
§Arguments
init
: Function of type Fn(p: &V, t: S) -> V that computes the initial state.
Sourcepub fn init_sens<F, G>(
self,
init: F,
init_sens: G,
nstates: usize,
) -> OdeBuilder<M, Rhs, ConstantClosureWithSens<M, F, G>, Mass, Root, Out>
pub fn init_sens<F, G>( self, init: F, init_sens: G, nstates: usize, ) -> OdeBuilder<M, Rhs, ConstantClosureWithSens<M, F, G>, Mass, Root, Out>
Set the initial condition of the ODE for forward sensitivity analysis.
§Arguments
init
: Function of type Fn(p: &V, t: S) -> V that computes the initial state.init_sens
: Function of type Fn(p: &V, t: S, y: &mut V) that computes the multiplication of the partial derivative of the initial state wrt the parameters, with the vector v.
Sourcepub fn init_adjoint<F, G>(
self,
init: F,
init_sens_adjoint: G,
nstates: usize,
) -> OdeBuilder<M, Rhs, ConstantClosureWithAdjoint<M, F, G>, Mass, Root, Out>
pub fn init_adjoint<F, G>( self, init: F, init_sens_adjoint: G, nstates: usize, ) -> OdeBuilder<M, Rhs, ConstantClosureWithAdjoint<M, F, G>, Mass, Root, Out>
Set the initial condition of the ODE for adjoint sensitivity analysis.
§Arguments
init
: Function of type Fn(p: &V, t: S) -> V that computes the initial state.init_sens_adjoint
: Function of type Fn(p: &V, t: S, y: &V, y_adj: &mut V) that computes the multiplication of the partial derivative of the initial state wrt the parameters, with the vector v.
Sourcepub fn mass<F>(
self,
mass: F,
) -> OdeBuilder<M, Rhs, Init, LinearClosure<M, F>, Root, Out>
pub fn mass<F>( self, mass: F, ) -> OdeBuilder<M, Rhs, Init, LinearClosure<M, F>, Root, Out>
Set the mass matrix of the ODE.
§Arguments
mass
: Function of type Fn(v: &V, p: &V, t: S, beta: S, y: &mut V) that computes a gemv multiplication of the mass matrix with the vector v (i.e. y = M * v + beta * y).
Sourcepub fn mass_adjoint<F, G>(
self,
mass: F,
mass_adjoint: G,
) -> OdeBuilder<M, Rhs, Init, LinearClosureWithAdjoint<M, F, G>, Root, Out>
pub fn mass_adjoint<F, G>( self, mass: F, mass_adjoint: G, ) -> OdeBuilder<M, Rhs, Init, LinearClosureWithAdjoint<M, F, G>, Root, Out>
Set the mass matrix of the ODE for adjoint sensitivity analysis.
§Arguments
mass
: Function of type Fn(v: &V, p: &V, t: S, beta: S, y: &mut V) that computes a gemv multiplication of the mass matrix with the vector v (i.e. y = M * v + beta * y).mass_adjoint
: Function of type Fn(v: &V, p: &V, t: S, beta: S, y: &mut V) that computes a gemv multiplication of the transpose of the mass matrix with the vector v (i.e. y = M^T * v + beta * y).
Sourcepub fn root<F>(
self,
root: F,
nroots: usize,
) -> OdeBuilder<M, Rhs, Init, Mass, ClosureNoJac<M, F>, Out>
pub fn root<F>( self, root: F, nroots: usize, ) -> OdeBuilder<M, Rhs, Init, Mass, ClosureNoJac<M, F>, Out>
Set a root equation for the ODE.
§Arguments
root
: Function of type Fn(x: &V, p: &V, t: S, y: &mut V) that computes the root function.nroots
: Number of roots (i.e. number of elements in they
arg inroot
), an event is triggered when any of the roots changes sign.
pub fn out_implicit<F, G>( self, out: F, out_jac: G, nout: usize, ) -> OdeBuilder<M, Rhs, Init, Mass, Root, Closure<M, F, G>>
pub fn out_adjoint_implicit<F, G, H, I>( self, out: F, out_jac: G, out_adjoint: H, out_sens_adjoint: I, nout: usize, ) -> OdeBuilder<M, Rhs, Init, Mass, Root, ClosureWithAdjoint<M, F, G, H, I>>
pub fn sens_rtol(self, sens_rtol: f64) -> Self
pub fn sens_atol<V, T>(self, sens_atol: V) -> Self
pub fn turn_off_sensitivities_error_control(self) -> Self
pub fn turn_off_output_error_control(self) -> Self
pub fn turn_off_param_error_control(self) -> Self
pub fn out_rtol(self, out_rtol: f64) -> Self
pub fn out_atol<V, T>(self, out_atol: V) -> Self
pub fn param_rtol(self, param_rtol: f64) -> Self
pub fn param_atol<V, T>(self, param_atol: V) -> Self
Sourcepub fn integrate_out(self, integrate_out: bool) -> Self
pub fn integrate_out(self, integrate_out: bool) -> Self
Set whether to integrate the output. If true, the output will be integrated using the same method as the ODE.
Sourcepub fn use_coloring(self, use_coloring: bool) -> Self
pub fn use_coloring(self, use_coloring: bool) -> Self
Set whether to use coloring when computing the Jacobian. This is always true if matrix type is sparse, but can be set to true for dense matrices as well. This can speed up the computation of the Jacobian for large sparse systems. However, it relys on the sparsity of the Jacobian being constant, and for certain systems it may detect the wrong sparsity pattern.
pub fn build(
self,
) -> Result<OdeSolverProblem<OdeSolverEquations<M, Rhs, Init, Mass, Root, Out>>, DiffsolError>where
M: Matrix,
Rhs: BuilderOp<V = M::V, T = M::T, M = M, C = M::C>,
Init: BuilderOp<V = M::V, T = M::T, M = M, C = M::C>,
Mass: BuilderOp<V = M::V, T = M::T, M = M, C = M::C>,
Root: BuilderOp<V = M::V, T = M::T, M = M, C = M::C>,
Out: BuilderOp<V = M::V, T = M::T, M = M, C = M::C>,
for<'a> ParameterisedOp<'a, Rhs>: NonLinearOp<M = M, V = M::V, T = M::T, C = M::C>,
for<'a> ParameterisedOp<'a, Init>: ConstantOp<M = M, V = M::V, T = M::T, C = M::C>,
for<'a> ParameterisedOp<'a, Mass>: LinearOp<M = M, V = M::V, T = M::T, C = M::C>,
for<'a> ParameterisedOp<'a, Root>: NonLinearOp<M = M, V = M::V, T = M::T, C = M::C>,
for<'a> ParameterisedOp<'a, Out>: NonLinearOp<M = M, V = M::V, T = M::T, C = M::C>,
pub fn build_from_diffsl<CG: CodegenModuleJit + CodegenModuleCompile>( self, code: &str, ) -> Result<OdeSolverProblem<DiffSl<M, CG>>, DiffsolError>
Sourcepub fn build_from_eqn<Eqn>(
self,
eqn: Eqn,
) -> Result<OdeSolverProblem<Eqn>, DiffsolError>
pub fn build_from_eqn<Eqn>( self, eqn: Eqn, ) -> Result<OdeSolverProblem<Eqn>, DiffsolError>
Build an ODE problem from a set of equations
Trait Implementations§
Auto Trait Implementations§
impl<M, Rhs, Init, Mass, Root, Out> Freeze for OdeBuilder<M, Rhs, Init, Mass, Root, Out>
impl<M, Rhs, Init, Mass, Root, Out> RefUnwindSafe for OdeBuilder<M, Rhs, Init, Mass, Root, Out>where
<M as MatrixCommon>::T: RefUnwindSafe,
<M as MatrixCommon>::C: RefUnwindSafe,
Rhs: RefUnwindSafe,
Init: RefUnwindSafe,
Mass: RefUnwindSafe,
Root: RefUnwindSafe,
Out: RefUnwindSafe,
impl<M, Rhs, Init, Mass, Root, Out> Send for OdeBuilder<M, Rhs, Init, Mass, Root, Out>
impl<M, Rhs, Init, Mass, Root, Out> Sync for OdeBuilder<M, Rhs, Init, Mass, Root, Out>
impl<M, Rhs, Init, Mass, Root, Out> Unpin for OdeBuilder<M, Rhs, Init, Mass, Root, Out>
impl<M, Rhs, Init, Mass, Root, Out> UnwindSafe for OdeBuilder<M, Rhs, Init, Mass, Root, Out>where
<M as MatrixCommon>::T: UnwindSafe,
<M as MatrixCommon>::C: UnwindSafe,
Rhs: UnwindSafe,
Init: UnwindSafe,
Mass: UnwindSafe,
Root: UnwindSafe,
Out: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.