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\) matrixmin: 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ο
Dictionary containing all specialized |
Classesο
Base abstract class for \(Q_\Delta\) coefficients generators. |
Functionsο
|
Class decorator to register a specialized |
|
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.
- 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
QDeltaGeneratorclasses
- register(cls: type[T]) type[T][source]ο
Class decorator to register a specialized
QDeltaGeneratorclass 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