qmat.solvers.dahlquist

Solvers for the Dahlquist equation based on \(Q\) coefficients, also implementing SDC sweeps with given \(Q_\Delta\) coefficients.

Classes

Dahlquist

Solver for the classical Dahlquist equation

DahlquistIMEX

Solver for the IMEX Dahlquist equation

Module Contents

class Dahlquist(lam, u0=1, tEnd=1, nSteps=1)[source]

Solver for the classical Dahlquist equation

\[\frac{du}{dt} = \lambda u, \quad u(0)=u_0, \quad t \in [0,T].\]

It can be used to solve the equation with multiple \(\lambda\) values (multiple trajectories) using efficient vectorized computation. Furthermore, it has no restriction on the used \(Q\) and \(Q_\Delta\) matrices (can be dense), which is not the case for the generic CoeffSolver used with qmat.solvers.generic.diffops.Dahlquist.

Parameters:
  • lam (scalar or array) – Value(s) used for \(\lambda\).

  • u0 (scalar or array, optional) – Initial value \(\lambda\), must be compatible with lam. The default is 1.

  • tEnd (float, optional) – Final simulation time \(T\). The default is 1.

  • nSteps (float, optional) – Number of time-step to solve. The default is 1.

u0 = 1

initial solution value

tEnd = 1

final simulation time

nSteps = 1

number of time-steps

dt = 1.0

time-step size

lam

array storing the \(\lambda\) values

uShape

shape of the solution at a given time

dtype

solution datatype

static checkCoeff(Q, weights)[source]

Check \(Q\) coefficients and associated weights.

Parameters:
  • Q (2D array-like) – The \(Q\) coefficients.

  • weights (1D array-like) – Quadrature weights associated to the nodes.

Returns:

  • nNodes (int) – Number of nodes (stages).

  • Q (np.2darray) – The \(Q\) coefficients.

  • weights (np.1darray) – Quadrature weights associated to the nodes.

solve(Q, weights)[source]

Solve for all \(\lambda\) using a direct solve of the \(Q\) matrix, i.e for each time-step it solves :

\[(I - \Delta{t}\lambda Q){\bf u} = {\bf u}_0,\]

where \({\bf u}_0\) is the vector containing the initial solution of the time-step in each entry. The next step solution is computed using the step update :

\[u_1 = u_0 + \Delta{t}\lambda{\bf w}^T{\bf u},\]

or simply use the last node solution \({\bf u}[-1]\) if no weights are given (weights=None).

Parameters:
  • Q (2D array-like) – The \(Q\) coefficients.

  • weights (1D array-like or None) – Quadrature weights associated to the nodes. If None, do not use them for the step update (requires last node equal to 1)

Returns:

uNum – The solution at each time-steps (+ initial solution).

Return type:

np.ndarray

static checkCoeffSDC(Q, weights, QDelta, nSweeps)[source]

Check SDC coefficients

Parameters:
  • Q (2D array-like) – The \(Q\) coefficients.

  • weights (1D array-like) – Quadrature weights associated to the nodes.

  • QDelta (2D or 3D array-like) – The \(Q_\Delta\) coefficients (3D if changes with sweeps).

  • nSweeps (int) – Number of sweeps.

Returns:

  • nNodes (int) – Number of nodes.

  • Q (np.2darray) – The \(Q\) coefficients.

  • weights (np.1darray) – Quadrature weights associated to the nodes.

  • QDelta (np.2darray) – The \(Q_\Delta\) coefficients for each sweep.

  • nSweeps (int) – The number of sweeps.

solveSDC(Q, weights, QDelta, nSweeps)[source]

Solve for all \(\lambda\) using SDC sweeps, i.e solves for each time-step and sweep \(k\) :

\[(I - \Delta{t}\lambda Q_\Delta){\bf u}^{k+1} = {\bf u}_0 + \Delta{t}\lambda(Q - Q_\Delta){\bf u}^{k},\]

where \({\bf u}_0\) is the vector containing the initial solution of the time-step in each entry and \({\bf u}^0 = {\bf u}_0\) (copy initialization).

The next step solution is computed using the step update :

\[u_1 = u_0 + \Delta{t}\lambda{\bf w}^T{\bf u}^{K},\]

where \(K\) is the total number of sweeps. If no weights are given (weights=None), it simply uses the last node solution \({\bf u}[-1]\).

Parameters:
  • Q (2D array-like) – The \(Q\) coefficients.

  • weights (1D array-like or None) – Quadrature weights associated to the nodes. If None, do not use them for the step update (requires last node equal to 1)

  • QDelta (2D or 3D array-like) – The \(Q_\Delta\) coefficients (3D if changes with sweeps).

  • nSweeps (int) – Number of sweeps.

Returns:

uNum – The solution at each time-steps (+ initial solution).

Return type:

np.ndarray

class DahlquistIMEX(lamI, lamE, u0=1, tEnd=1, nSteps=1)[source]

Solver for the IMEX Dahlquist equation

\[\frac{du}{dt} = (\lambda_I + \lambda_E) u, \quad u(0)=u_0, \quad t \in [0,T].\]

It can be used to solve the equation with multiple \(\lambda_I\) and / or \(\lambda_E\) values (multiple trajectories).

Parameters:
  • lamI (TYPE) – Value(s) used for \(\lambda_I\)..

  • lamE (scalar or array) – Value(s) used for \(\lambda_E\).

  • u0 (scalar or array, optional) – Initial value \(\lambda\), must be compatible with lam. The default is 1.

  • tEnd (float, optional) – Final simulation time \(T\). The default is 1.

  • nSteps (float, optional) – Number of time-step to solve. The default is 1.

u0 = 1

initial solution value

tEnd = 1

final simulation time

nSteps = 1

number of time-steps

dt = 1.0

time-step size

lamI

array storing the \(\lambda_I\) values

lamE

array storing the \(\lambda_E\) values

uShape

shape of the solution at one given time

dtype

datatype of the solution array

static checkCoeff(QI, wI, QE, wE)[source]

Check IMEX \(Q\) coefficients and assert their consistency.

Parameters:
  • QI (2D array-like) – \(Q\) coefficients used for \(\lambda_I\).

  • wI (1D array-like or None) – Weights used for the step update on \(\lambda_I\). If None, then step update is not done.

  • QE (2D array-like) – \(Q\) coefficients used for \(\lambda_E\).

  • wE (1D array-like or None) – Weights used for the step update on \(\lambda_E\). If None, then step update is not done.

Returns:

  • nNodes (int) – Number of nodes.

  • QI (np.2darray) – \(Q\) coefficients used for \(\lambda_I\).

  • wI (np.1darray or None) – Weights used for the step update on \(\lambda_I\).

  • QE (np.2darray) – \(Q\) coefficients used for \(\lambda_E\).

  • wE (np.1darray or None) – Weights used for the step update on \(\lambda_E\).

  • useWeights (boll) – Wether or not the step update (using weights) is done.

solve(QI, wI, QE, wE)[source]

Solve for all \(\lambda_I\) and \(\lambda_E\) using a direct solve of the \(Q^I\) and \(Q^E\) matrices, i.e for each time-step it solves :

\[(I - \lambda_I Q^I - \lambda_E Q^E){\bf u} = {\bf u}_0\]

where \({\bf u}_0\) is the vector containing the initial solution of the time-step in each entry. The next step solution is computed using the IMEX step update :

\[u_1 = u_0 + \Delta{t}\lambda_I{\bf w}_I^T{\bf u} + \Delta{t}\lambda_E{\bf w}_E^T{\bf u},\]

or simply use the last node solution \({\bf u}[-1]\) if no weights are given (wI=wE=None).

Parameters:
  • QI (2D array-like) – \(Q^I\) coefficients used for \(\lambda_I\).

  • wI (1D array-like or None) – Weights used for the step update on \(\lambda_I\). If None, then step update is not done.

  • QE (2D array-like) – \(Q^E\) coefficients used for \(\lambda_E\).

  • wE (1D array-like or None) – Weights used for the step update on \(\lambda_E\). If None, then step update is not done.

Returns:

uNum – The solution at each time-steps (+ initial solution).

Return type:

np.ndarray

static checkCoeffSDC(Q, weights, QDeltaI, QDeltaE, nSweeps)[source]

Check coefficients given for a IMEX SDC sweeps

Parameters:
  • Q (2D array-like) – The \(Q\) coefficients.

  • weights (1D array-like or none) – Quadrature weights associated to the nodes. If None, last node is used for the step update.

  • QDeltaE (2D or 3D array-like) – The \(Q_\Delta^I\) coefficients used for the \(\lambda_I\) term (3D if changes with sweeps).

  • QDeltaE (2D or 3D array-like) – The \(Q_\Delta^E\) coefficients used for the \(\lambda_E\) term (3D if changes with sweeps).

  • nSweeps (int) – Number of sweeps.

Returns:

  • nNodes (int) – Number of nodes.

  • Q (np.2darray) – The \(Q\) coefficients.

  • weights (np.1darray) – Quadrature weights associated to the nodes.

  • QDeltaI (np.3darray) – The \(Q_\Delta^I\) coefficients used for the \(\lambda_I\) term for each sweeps.

  • QDeltaE (np.3darray) – The \(Q_\Delta^E\) coefficients used for the \(\lambda_E\) term for each sweeps.

  • nSweeps (int) – Number of SDC sweeps.

solveSDC(Q, weights, QDeltaI, QDeltaE, nSweeps)[source]

Solve for all \(\lambda_I\) and \(\lambda_E\) using SDC sweeps, i.e for each time-step and sweep \(k\) it solves :

\[(I - \Delta{t}\lambda_I Q_\Delta^I - \Delta{t}\lambda_E Q_\Delta^I){\bf u}^{k+1} = {\bf u}_0 + \Delta{t}\left[ \lambda Q - \lambda_I Q_\Delta^I - \lambda_E Q_\Delta^E\right] {\bf u}^{k},\]

where \({\bf u}_0\) is the vector containing the initial solution of the time-step in each entry and \({\bf u}^0 = {\bf u}_0\) (copy initialization). The next step solution is computed using the step update :

\[u_1 = u_0 + \Delta{t}\lambda{\bf w}^T{\bf u}^{K},\]

where \(K\) is the total number of sweeps. If no weights are given (weights=None), it simply uses the last node solution \({\bf u}[-1]\).

Parameters:
  • Q (2D array-like) – The \(Q\) coefficients.

  • weights (1D array-like or none) – Quadrature weights associated to the nodes. If None, last node is used for the step update.

  • QDeltaE (2D or 3D array-like) – The \(Q_\Delta^I\) coefficients used for the \(\lambda_I\) term (3D if changes with sweeps).

  • QDeltaE (2D or 3D array-like) – The \(Q_\Delta^E\) coefficients used for the \(\lambda_E\) term (3D if changes with sweeps).

  • nSweeps (int) – Number of sweeps.

Returns:

uNum – The solution at each time-steps (+ initial solution).

Return type:

np.ndarray