DiscontinuousTestODE#
- class DiscontinuousTestODE(newton_maxiter=100, newton_tol=1e-08, stop_at_nan=True)[source]#
Bases:
ProblemThis class implements a very simple test case of a ordinary differential equation consisting of one discrete event. The dynamics of the solution changes when the state function \(h(u) := u - 5\) changes the sign. The problem is defined by:
if \(u - 5 < 0:\)
\[\frac{d u}{dt} = u\]else:
\[\frac{d u}{dt} = \frac{4}{t^*},\]where \(t^* = \log(5) \approx 1.6094379\). For \(h(u) < 0\), i.e. \(t \leq t^*\), the exact solution is \(u(t) = \exp(t)\); for \(h(u) \geq 0\), i.e. \(t \geq t^*\), the exact solution is \(u(t) = \frac{4 t}{t^*} + 1\).
- Parameters:
newton_maxiter (
int, optional) – Maximum number of iterations for Newton’s method.newton_tol (
float, optional) – Absolute tolerance for Newton’s method to terminate, applied to the maximum norm of the residual.stop_at_nan (
bool, optional) – Indicates that the Newton solver should stop ifnanvalues arise.
- Variables:
t_switch_exact (
float) – Exact event time with \(t^* = \log(5)\).t_switch (
float) – Time point of the discrete event found by switch estimation.nswitches (
int) – Number of switches found by switch estimation.work_counters (
WorkCounter) – Counts different things, here: Number of Newton iterations is counted.
- get_switching_info(u, t)[source]#
Provides information about the state function of the problem. When the state function changes its sign, typically an event occurs. So the check for an event should be done in the way that the state function is checked for a sign change. If this is the case, the intermediate value theorem states a root in this step.
- Parameters:
u (
dtype_u) – Current values of the numerical solution at time \(t\).t (
float) – Current time of the numerical solution.
- Returns:
switch_detected (
bool) – Indicates whether a discrete event is found or not.m_guess (
int) – The index before the sign changes.state_function (
list) – Defines the values of the state function at collocation nodes where it changes the sign.
- solve_system(rhs, dt, u0, t)[source]#
Simple Newton solver for \((I-factor\cdot A)\vec{u}=\vec{rhs}\).
- class ExactDiscontinuousTestODE(newton_maxiter=100, newton_tol=1e-08)[source]#
Bases:
DiscontinuousTestODEVariant of
DiscontinuousTestODEwhosesolve_systemreturns the exact solution, to test theSwitchEstimator. The problem contains the exact dynamics of the problem classDiscontinuousTestODE.- Parameters:
newton_maxiter (
int, optional) – Maximum number of iterations for Newton’s method. Not used here, sincesolve_systemreturns the exact solution.newton_tol (
float, optional) – Tolerance for Newton’s method to terminate. Not used here, sincesolve_systemreturns the exact solution.