qmat.solvers.generic.diffops
Contains various specialized implementation of DiffOp classes.
Attributes
Dictionary containing all specialized |
Classes
Implements a Dahlquist differential operator |
|
RHS of the Lorenz system, which can be written : |
|
Implement the Prothero-Robinson problem: |
Functions
|
Class decorator to register a specialized |
Module Contents
- T
- DIFFOPS: dict[str, type[qmat.solvers.generic.DiffOp]]
Dictionary containing all specialized
DiffOpclasses
- registerDiffOp(cls: type[T]) type[T][source]
Class decorator to register a specialized
DiffOpclass in qmat
- class Dahlquist(lam=1j)[source]

Implements a Dahlquist differential operator
\[f(u,t) = \lambda u\]Note
This class is implemented for illustration and testing purposes. To solve with many \(\lambda\) values, consider using the
qmat.solvers.dahlquist.Dahlquistclass instead.- Parameters:
lam (complex, optional) – The \(\lambda\) value. The default is 1j.
- lam = 1j
- class Lorenz(sigma=10, rho=28, beta=8 / 3, nativeFSolve=False)[source]

RHS of the Lorenz system, which can be written :
\[\frac{dx}{dt} = \sigma (y-x), \; \frac{dy}{dt} = x (\rho - z) - y, \; \frac{dz}{dt} = xy - \beta z,\]with starting initial solution \(u_0=(x_0,y_0,z_0)=(5, -5, 20)\). Considering the three dimensional vector \(u=(x,y,z)\), the formal expression of \(f\) is then
\[f(u,t) = [ \sigma (y-x), x (\rho - z) - y, xy - \beta z ]\]- Parameters:
sigma (float, optional) – The \(\sigma\) parameter (default=10).
rho (float, optional) – The \(\rho\) parameter (default=28).
beta (float, optional) – The \(\beta\) parameter (default=8/3).
nativeFSolve (bool, optional) – Wether or not using the native fSolve method (default is False).
- params
List containing \(\sigma\), \(\rho\) and \(\beta\)
- newton
Parameters for the Newton iteration used in native fSolve
- gemv
Level-2 blas gemv function used in the native solver (just for flex, very small speedup)
- classmethod test()[source]
Class method to test the DiffOp implementation.
- Parameters:
t0 (float, optional) – Evaluation time to test the instance. The default is 0.
dt (float, optional) – Time-step to test the fSolve method. The default is 1e-1.
eps (float, optional) – Perturbation added in the expected solution to test the fSolve method. The default is 1e-3.
instance (DiffOp, optional) – Instance to be tested. If not provided (None), an instance is created using the default constructor.
- evalF(u, t, out)[source]
Evaluate \(f(u,t)\) and store the result into out.
- Parameters:
u (np.ndarray) – Input solution for the evaluation.
t (float) – Time for the evaluation.
out (np.ndarray) – Output array in which is stored the evaluation.
- fSolve_NATIVE(a, rhs, t, out)[source]
Solve \(u-\alpha f(u,t)=rhs\) for given \(u,t,rhs\), using a Newton iteration with exact Jacobian of \(f(u,t)\).
- Parameters:
a (float) – The \(\alpha\) coefficient.
rhs (np.ndarray) – The right hand side.
t (float) – Time for the evaluation.
out (np.ndarray) – Input-output array used as initial guess, in which is stored the solution.
- class ProtheroRobinson(epsilon=0.001, nonLinear=False, nativeFSolve=True)[source]

Implement 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)
Reference
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.
- 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.
nativeFSolve (bool, optional) – Wether or not use the native fSolver using exact Jacobian. The default is True.
- epsilon = 0.001
Value used for \(\epsilon\).
- newton
Parameters used for the Newton iteration in fSolve.
- evalF[source]
Evaluate \(f(u,t)\) and store the result into out.
- Parameters:
u (np.ndarray) – Input solution for the evaluation.
t (float) – Time for the evaluation.
out (np.ndarray) – Output array in which is stored the evaluation.
- property nonLinear
Wether the current operator is non-linear
- fSolve_NATIVE(a, rhs, t, out)[source]
Solve \(u-\alpha f(u,t)=rhs\) for given \(u,t,rhs\), using a Newton iteration with exact Jacobian (derivative) of \(f(u,t)\).
- Parameters:
a (float) – The \(\alpha\) coefficient.
rhs (np.ndarray) – The right hand side.
t (float) – Time for the evaluation.
out (np.ndarray) – Input-output array used as initial guess, in which is stored the solution.