qmat.qcoeff

Defines the base abstract class to generate \(Q\)-coefficients (Butcher tables) : the QGenerator πŸš€

Each submodule contains specializations of this class for many kind of methods :

Submodules

Attributes

Q_GENERATORS

Dictionary containing all specialized QGenerator classes, with all their aliases

Classes

QGenerator

Base abstract class for all \(Q\)-coefficients generators

Functions

register(β†’Β type[T])

Class decorator to register a specialized QGenerator class in qmat

genQCoeffs(qType[,Β form,Β hCoeffs,Β embedded])

Generate \(Q\)-coefficients for a given method

Package Contents

class QGenerator[source]

Base abstract class for all \(Q\)-coefficients generators

classmethod getInstance()[source]

Provide an instance of this QGenerator using default parameters.

abstract property nodes

Nodes \(\tau\) (\(c\) coefficients in Butcher table)

abstract property Q

\(Q\) coefficients (\(A\) Butcher table)

abstract property weights

Weights \(\omega\) (\(b\) coefficients in Butcher table)

abstract property weightsEmbedded

Weights for a secondary lower order method from the same stages.

property nNodes: int

Number of nodes (or stages) for this QGenerator

property rightIsNode: bool

Wether or not the last nodes is the right boundary

property T: numpy.ndarray

Transfer matrix from zero-to-nodes to node-to-node

property S: numpy.ndarray

Quadrature matrix in node to node (N2N)

property Tinv: numpy.ndarray

Transfer matrix from node-to-node to zero-to-node

property hCoeffs: numpy.ndarray

\(h\) interpolation coefficients for the right boundary

genCoeffs(form='Z2N', hCoeffs=False, embedded=False)[source]

Generate \(Q\)-coefficients of this QGenerator object.

Parameters:
  • form (str, optional) – Write coefficients in zero-to-nodes (Z2N) or node-to-node (N2N). The default is β€œZ2N”.

  • hCoeffs (bool, optional) – Wether or not returning the \(h\) coefficients. The default is False.

  • embedded (bool, optional) – Wether or not returning the embedded \(h\) coefficients. The default is False.

Returns:

out – Contains (nodes, weights, Q). If hCoeffs=True, returns (nodes, weights, Q, hCoeffs). If embedded=True, weights is a 2xM array containing embedded weights in weights[1].

Return type:

tuple

abstract property order

Global convergence order of the method

property orderEmbedded: int

Global convergence order of the associated embedded method

solveDahlquist(lam, u0, tEnd, nSteps, useEmbeddedWeights=False)[source]

Solve the Dahlquist test problem

\[\frac{du}{dt} = \lambda u, \quad t \in [0, T], \quad u(0)=u_0\]
Parameters:
  • lam (complex or float) – The \(\lambda\) coefficient.

  • u0 (complex or float) – The initial solution \(u_0\).

  • tEnd (float) – Final time \(T\).

  • nSteps (int) – Number of time-step for the whole \([0,T]\) interval.

  • useEmbeddedWeights (bool, optional) – Wether or not use the embedded weights for the step update. The default is False.

Returns:

uNum – Array containing the nSteps+1 solutions \(\{u(0), ..., u(T)\}\).

Return type:

np.ndarray

errorDahlquist(lam, u0, tEnd, nSteps, uNum=None, useEmbeddedWeights=False)[source]

Compute \(L_\infty\) error in time for the Dahlquist problem

Parameters:
  • lam (complex or float) – The \(\lambda\) coefficient.

  • u0 (complex or float) – The initial solution \(u_0\).

  • tEnd (float) – Final time \(T\).

  • nSteps (int) – Number of time-step for the whole \([0,T]\) interval.

  • uNum (np.ndarray, optional) – Numerical solution, if not provided use the solveDahlquist method to compute the solution. The default is None.

  • useEmbeddedWeights (bool, optional) – Wether or not use the embedded weights for the step update. The default is False.

Returns:

The \(L_\infty\) norm.

Return type:

float

Q_GENERATORS: dict[str, type[QGenerator]]

Dictionary containing all specialized QGenerator classes, with all their aliases

register(cls: type[T]) type[T][source]

Class decorator to register a specialized QGenerator class in qmat

genQCoeffs(qType, form='Z2N', hCoeffs=False, embedded=False, **params)[source]

Generate \(Q\)-coefficients for a given method

Parameters:
  • qType (str) – Name (or alias) of the QGenerator.

  • form (str, optional) – Write coefficients in zero-to-nodes (Z2N) or node-to-node (N2N). The default is β€œZ2N”.

  • hCoeffs (bool, optional) – Wether or not returning the \(h\) coefficients. The default is False.

  • embedded (bool, optional) – Wether or not returning the embedded \(h\) coefficients. The default is False.

  • **params – Parameters to be used to instantiate the QGenerator.

Returns:

out – Contains (nodes, weights, Q). If hCoeffs=True, returns (nodes, weights, Q, hCoeffs). If embedded=True, weights is a 2xM array containing embedded weights in weights[1].

Return type:

tuple