DiffModule#
- class fridom.framework.grid.DiffModule[source]#
Bases:
ModuleBase class for differentiation modules.
Description#
A differentiation module is a class that computes derivatives of a field, for example the partial derivative in a specific direction, or the gradient of a field, or divergence of a vector etc.
- __init__() None#
Methods
__init__()diff(f, axis[, order])Compute the partial derivative of a field along an axis.
disable()Enabling the module means that it will be executed at each time step.
div(vec)Compute the divergence of a vector field.
enable()Enabling the module means that it will be executed at each time step.
grad(f[, axes])Compute the gradient of a field.
is_enabled()Return whether the module is enabled or not.
laplacian(f[, axes])Compute the Laplacian of a scalar field.
reset()Stop and start the module.
setup(mset)Start the module
start()Start the module
stop()Stop the module
update(mz)Update the module
Attributes
diff_moduleThe differentiation module to be used by this module.
gridThe grid of the model settings
infoReturn a dictionary with information about the time stepper.
interp_moduleThe interpolation module to be used by this module.
msetThe model settings
required_halo- name = 'Diff. Module'#
- abstract diff(f: FieldVariable, axis: int, order: int = 1) FieldVariable[source]#
Compute the partial derivative of a field along an axis.
\[\partial_i^n f\]with axis \(i\) and order \(n\).
Parameters#
- ffr.FieldVariable
The field to differentiate.
- axisint
The axis along which to differentiate.
- orderint
The order of the derivative. Default is 1.
Returns#
- fr.FieldVariable
The derivative of the field along the specified axis.
- grad(f: FieldVariable, axes: list[int] | None = None) tuple[FieldVariable | None][source]#
Compute the gradient of a field.
\[\begin{split}\nabla f = \begin{pmatrix} \partial_1 f \\ \dots \\ \partial_n f \end{pmatrix}\end{split}\]Parameters#
- ffr.FieldVariable
The field to differentiate.
- axeslist[int] | None (default is None)
The axes along which to compute the gradient. If None, the gradient is computed along all axes.
Returns#
- tuple[fr.FieldVariable | None]
The gradient of the field along the specified axes. The list contains the gradient components along each axis. Axis which are not included in axes will have a value of None. E.g. for a 3D grid, diff.grad(f, axes=[0, 2]) will return [df/dx, None, df/dz].
- div(vec: tuple[FieldVariable | None]) FieldVariable[source]#
Compute the divergence of a vector field.
\[\nable \cdot \boldsymbol{v} = \sum_{i=1}^n \partial_i v_i\]Parameters#
- vectuple[fr.FieldVariable | None]
The vector field to compute the divergence of. Tuple entries that are None are ignored (for example to calculate 2D divergence in a 3D system).
Returns#
- fr.FieldVariable
The divergence of the field.
Examples#
# Create diff module (Let mset be a ModelSettingsBase object) diff = DiffModule(...) diff.setup(mset) # let u, v, w be the components of the vector field # Calculate 3D divergence div = diff.div((u, v, w)) # Calculate 2D horizontal divergence div = diff.div((u, v, None))
- laplacian(f: FieldVariable, axes: tuple[int] | None = None) FieldVariable[source]#
Compute the Laplacian of a scalar field.
\[\nabla^2 f = \sum_{i=1}^n \partial_i^2 f\]Parameters#
- ffr.FieldVariable
The field to differentiate.
- axestuple[int] | None (default is None)
The axes along which to compute the Laplacian. If None, the Laplacian is computed along all axes.
Returns#
- fr.FieldVariable
The Laplacian of the field.