odeScalar#
Implementation of scalar test problem ODEs.
Reference :
Van der Houwen, P. J., & Sommeijer, B. P. (1991). Iterated Runge–Kutta methods on parallel computers. SIAM journal on scientific and statistical computing, 12(5), 1000-1028.
- class ProtheroRobinson(epsilon=0.001, nonLinear=False, newton_maxiter=200, newton_tol=5e-11, stop_at_nan=True)[source]#
Bases:
ProblemImplement the Prothero-Robinson problem:
\[\frac{du}{dt} = -\frac{u-g(t)}{\epsilon} + \frac{dg}{dt}, \quad u(0) = g(0).,\]with \(\epsilon\) a stiffness parameter, that makes the problem more stiff the smaller it is (usual taken value is \(\epsilon=1e^{-3}\)). Exact solution is given by \(u(t)=g(t)\), and this implementation uses \(g(t)=\cos(t)\).
Implement also the non-linear form of this problem:
\[\frac{du}{dt} = -\frac{u^3-g(t)^3}{\epsilon} + \frac{dg}{dt}, \quad u(0) = g(0).\]To use an other exact solution, one just have to derivate this class and overload the g and dg methods. For instance, to use \(g(t)=e^{-0.2*t}\), define and use the following class:
>>> class MyProtheroRobinson(ProtheroRobinson): >>> >>> def g(self, t): >>> return np.exp(-0.2 * t) >>> >>> def dg(self, t): >>> return (-0.2) * np.exp(-0.2 * t)
- Parameters:
epsilon (
float, optional) – Stiffness parameter. The default is 1e-3.nonLinear (
bool, optional) – Wether or not to use the non-linear form of the problem. The default is False.newton_maxiter (
int, optional) – Maximum number of Newton iteration in solve_system. The default is 200.newton_tol (
float, optional) – Residuum tolerance for Newton iteration in solve_system. The default is 5e-11.stop_at_nan (
bool, optional) – Wheter to stop or not solve_system when getting NAN. The default is True.
References
A. Prothero and A. Robinson, On the stability and accuracy of one-step methods for solving stiff systems of ordinary differential equations, Mathematics of Computation, 28 (1974), pp. 145–162.
- dg(t)[source]#
First derivative \(g'(t) = -\sin(t)\) of \(g\).
- Parameters:
t (
float) – Time.- Returns:
float– The value of \(g'(t)\).
- f(u, t)[source]#
Right-hand side, replaced in
__init__byf_LINorf_NONLIN.- Parameters:
u (
dtype_u) – Current values of the numerical solution.t (
float) – Current time.
- Raises:
NotImplementedError – Always.
- f_NONLIN(u, t)[source]#
Right-hand side \(-(u^3 - g(t)^3) / \epsilon + g'(t)\) of the nonlinear form.
- g(t)[source]#
Function \(g(t) = \cos(t)\), which is the exact solution.
- Parameters:
t (
float) – Time.- Returns:
float– The value of \(g(t)\).
- jac(u, t)[source]#
Jacobian of the right-hand side, replaced in
__init__byjac_LINorjac_NONLIN.- Parameters:
u (
dtype_u) – Current values of the numerical solution.t (
float) – Current time.
- Raises:
NotImplementedError – Always.
- jac_LIN(u, t)[source]#
Jacobian \(-1/\epsilon\) of the right-hand side of the linear form.
- Parameters:
u (
dtype_u) – Current values of the numerical solution.t (
float) – Current time.
- Returns:
float– The Jacobian.
- jac_NONLIN(u, t)[source]#
Jacobian \(-3 u^2 / \epsilon\) of the right-hand side of the nonlinear form.
- solve_system(rhs, dt, u0, t)[source]#
Simple Newton solver for the nonlinear equation
- Parameters:
- Returns:
u (
dtype_u) – The solution as mesh.