Skip to main content

StateRefMut

Struct StateRefMut 

Source
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::T

Implementations§

Source§

impl<V: Vector> StateRefMut<'_, V>

Source

pub fn set_consistent<Eqn, S>( &mut self, ode_problem: &OdeSolverProblem<Eqn>, root_solver: &mut S, ) -> Result<(), DiffsolError>
where Eqn: OdeEquationsImplicit<T = V::T, V = V, C = V::C>, S: NonLinearSolver<Eqn::M>,

Calculate a consistent state and time derivative of the state, based on the equations of the problem.

Source

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).

Source

pub fn apply_reset<Eqn>( &mut self, problem: &OdeSolverProblem<Eqn>, ) -> Result<(), DiffsolError>
where Eqn: OdeEquations<T = V::T, V = V, C = V::C>,

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.

Source

pub fn apply_reset_with_mass<LS, Eqn>( &mut self, problem: &OdeSolverProblem<Eqn>, ) -> Result<(), DiffsolError>
where Eqn: OdeEquationsImplicit<T = V::T, V = V, C = V::C>, LS: LinearSolver<Eqn::M>,

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.

Source

pub fn apply_reset_with_sens<Eqn>( &mut self, problem: &OdeSolverProblem<Eqn>, root_idx: usize, ) -> Result<(), DiffsolError>
where Eqn: OdeEquationsImplicitSens<T = V::T, V = V, C = V::C>,

Source

pub fn apply_reset_with_sens_mass<LS, Eqn>( &mut self, problem: &OdeSolverProblem<Eqn>, root_idx: usize, ) -> Result<(), DiffsolError>
where Eqn: OdeEquationsImplicitSens<T = V::T, V = V, C = V::C>, LS: LinearSolver<Eqn::M>,

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.

Source

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>
where Eqn: OdeEquationsImplicitAdjoint<T = V::T, V = V, C = V::C>,

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.

Source

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.

Source

pub fn set_step_size<Eqn>( &mut self, h0: Eqn::T, atol: &Eqn::V, rtol: Eqn::T, eqn: &Eqn, solver_order: usize, )
where Eqn: OdeEquations<T = V::T, V = V, C = V::C>,

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,