implementations.problem_classes.DiscontinuousTestODE module

class DiscontinuousTestODE(newton_maxiter=100, newton_tol=1e-08, stop_at_nan=True)[source]

Bases: ptype

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

t_switch_exact

Exact event time with \(t^* = \log(5)\).

Type:

float

t_switch

Time point of the discrete event found by switch estimation.

Type:

float

nswitches

Number of switches found by switch estimation.

Type:

int

work_counters

Counts different things, here: Number of Newton iterations is counted.

Type:

WorkCounter

count_switches()[source]

Setter to update the number of switches if one is found.

dtype_f

alias of mesh

dtype_u

alias of mesh

eval_f(u, t)[source]

Routine to evaluate the right-hand side of the problem.

Parameters:
  • u (dtype_u) – Current values of the numerical solution.

  • t (float) – Current time of the numerical solution is computed.

Returns:

f – The right-hand side of the problem.

Return type:

dtype_f

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

Parameters:
  • rhs (dtype_f) – Right-hand side for the linear system.

  • dt (float) – Abbrev. for the local stepsize (or any other factor required).

  • u0 (dtype_u) – Initial guess for the iterative solver.

  • t (float) – Current time (e.g. for time-dependent BCs).

Returns:

me – The solution as mesh.

Return type:

dtype_u

u_exact(t, u_init=None, t_init=None)[source]

Routine to compute the exact solution at time \(t\).

Parameters:
  • t (float) – Time of the exact solution.

  • u_init (dtype_u) – Initial conditions for getting the exact solution.

  • t_init (float) – The starting time.

Returns:

me – The exact solution.

Return type:

dtype_u

class ExactDiscontinuousTestODE(newton_maxiter=100, newton_tol=1e-08)[source]

Bases: DiscontinuousTestODE

Dummy ODE problem for testing the SwitchEstimator class. The problem contains the exact dynamics of the problem class DiscontinuousTestODE.

eval_f(u, t)[source]

Derivative.

Parameters:
  • u (dtype_u) – Exact value of u.

  • t (float) – Time \(t\).

Returns:

f – Derivative.

Return type:

dtype_f

solve_system(rhs, factor, u0, t)[source]

Just return the exact solution…

Parameters:
  • rhs (dtype_f) – Right-hand side for the linear system.

  • factor (float) – Abbrev. for the local stepsize (or any other factor required).

  • u0 (dtype_u) – Initial guess for the iterative solver.

  • t (float) – Current time (e.g. for time-dependent BCs).

Returns:

me – The solution as mesh.

Return type:

dtype_u