qmat.qdelta

Defines the base abstract class to generate \(Q_\Delta\) approximations : the QDeltaGenerator πŸš€

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

  • timestepping : based on time-stepping methods (Backward Euler, etc …)

  • algebraic : based on algebraic consideration on the \(Q\) matrix

  • min : diagonal approximations based on minimization

Examples

>>> qGen:QGenerator = ... # any QGenerator object implemented in qmat.qcoeff.[...]
>>>
>>> # Generate QDelta coefficients with generic function
>>> from qmat.qdelta import genQDeltaCoeffs
>>> qDeltaBE = genQDeltaCoeffs("BE", nodes=qGen.nodes)  # Backward Euler approximation
>>> qDeltaLU = genQDeltaCoeffs("LU", Q=qGen.Q)          # LU approximation
>>>
>>> # Generate QDelta coefficients with QDeltaGenerator objects
>>> from qmat.qdelta.timestepping import BE
>>> qDeltaBE = BE(nodes=qGen.nodes).getQDelta()
>>> from qmat.qdelta.algebraic import LU
>>> qDeltaLU = LU(Q=qGen.Q)
>>>
>>> # Simplified import for all QDeltaGenerator objects
>>> from qmat.qdelta import QDELTA_GENERATORS   # πŸ’‘ can also be imported from qmat directly
>>> qDeltaBE = QDELTA_GENERATORS["BE"](nodes=qGen.nodes).getQDelta()
>>> qDeltaLU = QDELTA_GENERATORS["LU"](Q=qGen.Q).getQDelta()

Note

πŸ“£ If you want to cover all available approximations implemented in qmat, we highly suggest to use the qGen keyword argument, allowing to extract any required parameter from a QGenerator object, e.g :

>>> # Using generic function
>>> for qdType in ["BE", "LU", "MIN-SR-S", "MIN-SR-NS", "MIN-SR-FLEX"]:
>>>     qDelta = genQDeltaCoeffs(qdType, qGen=qGen)
>>>
>>> # Using QDeltaGenerator objects
>>> for qdType in ["BE", "LU", "MIN-SR-S", "MIN-SR-NS", "MIN-SR-FLEX"]:
>>>     qDelta = QDELTA_GENERATORS[qdType](qGen=qGen).getQDelta()

πŸ’‘ This ensure forward compatibility in your code, so it can use any other \(Q_\Delta\) approximations added later in qmat without modification.

⚠️ You can also specify \(Q_\Delta\) specific parameter(s) in addition to qGen : in that case, the corresponding parameters extracted from qGen are overridden.

Submodules

Attributes

QDELTA_GENERATORS

Dictionary containing all specialized QDeltaGenerator classes

Classes

QDeltaGenerator

Base abstract class for \(Q_\Delta\) coefficients generators.

Functions

register(β†’Β type[T])

Class decorator to register a specialized QDeltaGenerator class in qmat

genQDeltaCoeffs(qDeltaType[,Β nSweeps,Β form,Β dTau])

Generic function to produce \(Q_\Delta\) coefficients

Package Contents

class QDeltaGenerator(Q, **kwargs)[source]

Base abstract class for \(Q_\Delta\) coefficients generators.

Parameters:
  • Q (np.ndarray) – The \(Q\) matrix of the base approximated method.

  • **kwargs – Additional parameters given in for generic calls, ignored by the class.

isKDependent()[source]

Wether or not the \(Q_\Delta\) coefficients varies with the iterations

Q: numpy.ndarray

\(Q\) matrix of the approximated time-integration method

static extractParams(qGen: qmat.qcoeff.QGenerator) dict[source]

Extract from a \(Q\)-generator object all parameters required to instantiate the \(Q_\Delta\)-generator

property size: int

Dimension of the approximated \(Q\)-coefficients (number of nodes)

property zeros: numpy.ndarray

Seros matrix with the same size of the underlying \(Q\) matrix

abstractmethod computeQDelta(k=None) numpy.ndarray[source]

Compute and returns the \(Q_\Delta\) matrix, has to be implemented in the specialized class.

Parameters:

k (int, optional) – Iteration number of the approximation. The default is None.

Returns:

QDelta

Return type:

np.ndarray

getQDelta(k=None, copy=True)[source]

Generic method to retrieve the \(Q_\Delta\) coefficients

Parameters:
  • k (int, optional) – Iteration number of the approximation (if needed). The default is None.

  • copy (bool, optional) – Return a copy of the the result returned by computeQDelta. The default is True.

Returns:

QDelta

Return type:

np.ndarray

getSDelta(k=None)[source]

Compute the \(S_\Delta\) matrix (approximation of \(S\)).

Parameters:

k (int, optional) – Iteration number, used when the approximation depends on it. The default is None.

Returns:

SDelta

Return type:

np.ndarray

property dTau: numpy.ndarray

The \(\delta_\tau\) coefficients associated to \(Q_\Delta\)

genCoeffs(k=None, form='Z2N', dTau=False)[source]

Generic method to produce \(Q_\Delta\) coefficients

Parameters:
  • k (int or list, optional) – Iteration(s) for the approximation. The default is None.

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

  • dTau (bool, optional) – Wether or not to return the \(\delta_\tau\). The default is False.

Returns:

If k is a scalar or None, returns a MxM matrix. If k is a list, returns a len(k)xMxM matrix. If dTau=True, returns a tuple (QDelta, dTau).

Return type:

np.ndarray or tuple

QDELTA_GENERATORS: dict[str, type[QDeltaGenerator]]

Dictionary containing all specialized QDeltaGenerator classes

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

Class decorator to register a specialized QDeltaGenerator class in qmat

genQDeltaCoeffs(qDeltaType, nSweeps=None, form='Z2N', dTau=False, **params)[source]

Generic function to produce \(Q_\Delta\) coefficients

Parameters:
  • qDeltaType (str or list) – The type of approximation, can be a list to have several sweeps.

  • nSweeps (int, optional) – Number of sweeps when \(Q_\Delta\) matrices are required for several sweeps. The default is None.

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

  • dTau (bool, optional) – Wether or not to return the \(\delta_\tau\). The default is False.

  • **params – Additional arguments used to instantiate all QDeltaGenerator

Returns:

If qDeltaType is a string, returns a \(M \times M\) matrix. If qDeltaType is a list or nSweeps != None, returns a \(N_{sweeps} \times M \times M\) matrix. If dTau=True, returns a tuple (QDelta, dTau).

Return type:

np.ndarray or tuple