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()Disable the module.
div(vec)Compute the divergence of a vector field.
enable()Enable the module.
grad(f[, axes])Compute the gradient of a field.
is_enabled()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[, setup_mode])Set the module up.
start()Start the module.
stop()Stop the module.
update(mz)Update the model state.
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.
is_setupWhether the module is set up.
msetThe model settings.
required_haloThe required halo points for this module.
- name = 'Diff. Module'#
- abstract diff(f: ScalarField, axis: int, order: int = 1) ScalarField[source]#
Compute the partial derivative of a field along an axis.
\[\partial_i^n f\]with axis \(i\) and order \(n\).
Parameters#
- ffr.ScalarField
The field to differentiate.
- axisint
The axis along which to differentiate.
- orderint
The order of the derivative. Default is 1.
Returns#
- fr.ScalarField
The derivative of the field along the specified axis.
- grad(f: ScalarField, axes: list[int] | None = None) tuple[ScalarField | 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.ScalarField
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.ScalarField | 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[ScalarField | None]) ScalarField[source]#
Compute the divergence of a vector field.
\[\nable \cdot \boldsymbol{v} = \sum_{i=1}^n \partial_i v_i\]Parameters#
- vectuple[fr.ScalarField | 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.ScalarField
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: ScalarField, axes: tuple[int] | None = None) ScalarField[source]#
Compute the Laplacian of a scalar field.
\[\nabla^2 f = \sum_{i=1}^n \partial_i^2 f\]Parameters#
- ffr.ScalarField
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.ScalarField
The Laplacian of the field.