pub struct StateRefMut<'a, V: Vector> {
pub y: &'a mut V,
pub dy: &'a mut V,
pub g: &'a mut V,
pub dg: &'a mut V,
pub s: &'a mut [V],
pub ds: &'a mut [V],
pub sg: &'a mut [V],
pub dsg: &'a mut [V],
pub t: &'a mut V::T,
pub h: &'a mut V::T,
}Expand description
A mutable reference to the state of the ODE solver, containing:
- the current solution
y - the derivative of the solution wrt time
dy - the current integral of the output function
g - the current derivative of the integral of the output function wrt time
dg - the current time
t - the current step size
h - the sensitivity vectors
s - the derivative of the sensitivity vectors wrt time
ds - the sensitivity vectors of the output function
sg - the derivative of the sensitivity vectors of the output function wrt time
dsg
Fields§
§y: &'a mut V§dy: &'a mut V§g: &'a mut V§dg: &'a mut V§s: &'a mut [V]§ds: &'a mut [V]§sg: &'a mut [V]§dsg: &'a mut [V]§t: &'a mut V::T§h: &'a mut V::TImplementations§
Source§impl<V: Vector> StateRefMut<'_, V>
impl<V: Vector> StateRefMut<'_, V>
Sourcepub fn set_consistent<Eqn, S>(
&mut self,
ode_problem: &OdeSolverProblem<Eqn>,
root_solver: &mut S,
) -> Result<(), DiffsolError>
pub fn set_consistent<Eqn, S>( &mut self, ode_problem: &OdeSolverProblem<Eqn>, root_solver: &mut S, ) -> Result<(), DiffsolError>
Calculate a consistent state and time derivative of the state, based on the equations of the problem.
Sourcepub fn set_consistent_augmented<Eqn, AugmentedEqn, S>(
&mut self,
ode_problem: &OdeSolverProblem<Eqn>,
augmented_eqn: &mut AugmentedEqn,
root_solver: &mut S,
) -> Result<(), DiffsolError>where
Eqn: OdeEquationsImplicit<T = V::T, V = V, C = V::C>,
AugmentedEqn: AugmentedOdeEquationsImplicit<Eqn> + Debug,
S: NonLinearSolver<AugmentedEqn::M>,
pub fn set_consistent_augmented<Eqn, AugmentedEqn, S>(
&mut self,
ode_problem: &OdeSolverProblem<Eqn>,
augmented_eqn: &mut AugmentedEqn,
root_solver: &mut S,
) -> Result<(), DiffsolError>where
Eqn: OdeEquationsImplicit<T = V::T, V = V, C = V::C>,
AugmentedEqn: AugmentedOdeEquationsImplicit<Eqn> + Debug,
S: NonLinearSolver<AugmentedEqn::M>,
Calculate the initial sensitivity vectors and their time derivatives, based on the equations of the problem. Note that this function assumes that the state is already consistent with the algebraic constraints (either via Self::set_consistent or by setting the state up manually).
Sourcepub fn apply_reset<Eqn>(
&mut self,
problem: &OdeSolverProblem<Eqn>,
) -> Result<(), DiffsolError>
pub fn apply_reset<Eqn>( &mut self, problem: &OdeSolverProblem<Eqn>, ) -> Result<(), DiffsolError>
Apply the equation set’s reset operator to the current state in-place (no mass matrix).
Applies op(y, t) to update y, then recomputes dy = rhs(y, t).
Only valid for equations without a mass matrix. If a mass matrix is present use
Self::apply_reset_with_mass instead.
Sourcepub fn apply_reset_with_mass<LS, Eqn>(
&mut self,
problem: &OdeSolverProblem<Eqn>,
) -> Result<(), DiffsolError>
pub fn apply_reset_with_mass<LS, Eqn>( &mut self, problem: &OdeSolverProblem<Eqn>, ) -> Result<(), DiffsolError>
Apply the equation set’s reset operator to the current state in-place (with mass matrix support).
Applies op(y, t) to update y, then recomputes dy. If the equations have no mass
matrix, dy is set directly from rhs(y, t). If a mass matrix is present,
Self::set_consistent is called after the reset to ensure y and dy satisfy the
algebraic constraints.
pub fn apply_reset_with_sens<Eqn>( &mut self, problem: &OdeSolverProblem<Eqn>, root_idx: usize, ) -> Result<(), DiffsolError>
Sourcepub fn apply_reset_with_sens_mass<LS, Eqn>(
&mut self,
problem: &OdeSolverProblem<Eqn>,
root_idx: usize,
) -> Result<(), DiffsolError>
pub fn apply_reset_with_sens_mass<LS, Eqn>( &mut self, problem: &OdeSolverProblem<Eqn>, root_idx: usize, ) -> Result<(), DiffsolError>
Apply a reset operator to the current state and propagate sensitivities through a time-dependent root-triggered event correction, with mass-matrix support.
Like Self::apply_reset_with_sens but also handles DAE problems with a mass matrix by
calling Self::set_consistent_augmented after the reset.
Sourcepub fn apply_reset_with_adjoint<Eqn>(
&mut self,
eqn: &Eqn,
root_idx: usize,
fwd_state_minus: StateRef<'_, V>,
fwd_state_plus: StateRef<'_, V>,
integrate_out: bool,
) -> Result<(), DiffsolError>
pub fn apply_reset_with_adjoint<Eqn>( &mut self, eqn: &Eqn, root_idx: usize, fwd_state_minus: StateRef<'_, V>, fwd_state_plus: StateRef<'_, V>, integrate_out: bool, ) -> Result<(), DiffsolError>
Propagate adjoint variables through a time-dependent root-triggered reset.
This helper pulls the reset and root operators from eqn, checks that both are
configured, then applies the adjoint event correction.
This method assumes self stores the post-event adjoint state (lambda^+, q^+),
while fwd_state_minus and fwd_state_plus provide the forward state derivatives
immediately before and after the reset. The terminal-root contribution for a root-defined
segment end must already have been applied with
Self::state_mut_adjoint_terminal_root.
If the pre-event forward state is x^-, the post-event state is x^+ = g(x^-, t, p),
and the active root is r_k(x^-, t, p) = 0, define
f^- = dx^-/dt,
f^+ = dx^+/dt,
c = g_x f^- + g_t - f^+,
d = [r_x f^-]_k + [r_t]_k,
and, when continuous outputs are being integrated, l^- = out(x^-, t) and
l^+ = out(x^+, t).
For each adjoint channel with post-event adjoint lambda^+ and post-event parameter
gradient q^+, the pre-event values are
alpha = (lambda^+ · c + l^- - l^+) / d,
lambda^- = g_x^T lambda^+ - r_{x,k}^T alpha,
and
q^- = q^+ + g_p^T lambda^+ - r_{p,k}^T alpha.
Here g_x = ∂g/∂x, g_t = ∂g/∂t, g_p = ∂g/∂p, r_x = ∂r/∂x,
r_t = ∂r/∂t, and r_p = ∂r/∂p, all evaluated at (x^-, t, p).
The l^- - l^+ term is the running-cost jump contribution at the interior event.
The forward state vectors in self are left untouched; self.s and self.sg
are updated to the pre-event values.
Note: mass matrix equations are not supported for this operation.
Sourcepub fn state_mut_adjoint_terminal_root<Eqn, State>(
&mut self,
eqn: &Eqn,
root_idx: usize,
forward: &State,
integrate_out: bool,
) -> Result<(), DiffsolError>where
Eqn: OdeEquationsAdjoint<T = V::T, V = V, C = V::C, Root: NonLinearOpJacobian<T = V::T, V = V, M = Eqn::M, C = V::C> + NonLinearOpAdjoint<T = V::T, V = V, M = Eqn::M, C = V::C> + NonLinearOpSensAdjoint<T = V::T, V = V, M = Eqn::M, C = V::C> + NonLinearOpTimePartial<T = V::T, V = V, M = Eqn::M, C = V::C>, Out: NonLinearOp<T = V::T, V = V, M = Eqn::M, C = V::C>>,
State: OdeSolverState<V>,
pub fn state_mut_adjoint_terminal_root<Eqn, State>(
&mut self,
eqn: &Eqn,
root_idx: usize,
forward: &State,
integrate_out: bool,
) -> Result<(), DiffsolError>where
Eqn: OdeEquationsAdjoint<T = V::T, V = V, C = V::C, Root: NonLinearOpJacobian<T = V::T, V = V, M = Eqn::M, C = V::C> + NonLinearOpAdjoint<T = V::T, V = V, M = Eqn::M, C = V::C> + NonLinearOpSensAdjoint<T = V::T, V = V, M = Eqn::M, C = V::C> + NonLinearOpTimePartial<T = V::T, V = V, M = Eqn::M, C = V::C>, Out: NonLinearOp<T = V::T, V = V, M = Eqn::M, C = V::C>>,
State: OdeSolverState<V>,
Given a forward terminal state satisfying the active root condition
r_k(y_f, t_f, p) = 0, this method adds the terminal contribution
lambda_f += r_{x,k}^T * (u_k / d) and q_f += r_{p,k}^T * (u_k / d) to each adjoint
channel, where u_k is the corresponding model output component and
d = [r_x f_f]_k + [r_t]_k.
Sourcepub fn set_step_size<Eqn>(
&mut self,
h0: Eqn::T,
atol: &Eqn::V,
rtol: Eqn::T,
eqn: &Eqn,
solver_order: usize,
)
pub fn set_step_size<Eqn>( &mut self, h0: Eqn::T, atol: &Eqn::V, rtol: Eqn::T, eqn: &Eqn, solver_order: usize, )
compute size of first step based on alg in Hairer, Norsett, Wanner Solving Ordinary Differential Equations I, Nonstiff Problems Section II.4.2 Note: this assumes that the state is already consistent with the algebraic constraints and y and dy are already set appropriately
Auto Trait Implementations§
impl<'a, V> Freeze for StateRefMut<'a, V>
impl<'a, V> RefUnwindSafe for StateRefMut<'a, V>
impl<'a, V> Send for StateRefMut<'a, V>
impl<'a, V> Sync for StateRefMut<'a, V>where
V: Sync,
impl<'a, V> Unpin for StateRefMut<'a, V>
impl<'a, V> UnsafeUnpin for StateRefMut<'a, V>
impl<'a, V> !UnwindSafe for StateRefMut<'a, V>
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.