Algebraic operators#
BOUT++ provides a wide variety of algebraic operators acting on fields.
Most of these operators can participate in the lazy field-expression system described in Field Expressions. In practice this means you can usually write ordinary algebraic code and let BOUT++ delay evaluation until assignment or reduction.
For a completely up-to-date list, see the Non-member functions part
of field2d.hxx,
field3d.hxx, and
fieldperp.hxx.
Common operators#
Name |
Description |
|---|---|
|
Minimum (optionally over all processes) |
|
Maximum (optionally over all processes) |
|
Mean (optionally over all processes) |
|
\(\mathtt{lhs}^\mathtt{rhs}\) |
|
Square of |
|
\(\sqrt{(f)}\) |
|
\(|f|\) |
|
\(e^f\) |
|
\(\log(f)\) |
|
\(\sin(f)\) |
|
\(\cos(f)\) |
|
\(\tan(f)\) |
|
\(\sinh(f)\) |
|
\(\cosh(f)\) |
|
\(\tanh(f)\) |
|
Returns a field where values below |
|
Calculate the amplitude of the Fourier mode in the
z-direction with mode number |
|
Remove Fourier modes (in the z-direction) with mode
number higher than |
|
Remove Fourier modes (in the z-direction) with mode
number higher than |
|
Rotate |
|
The average in the z-direction of |
|
Select between two algebraic branches |
|
Select either |
These operators can usually be combined directly in expressions:
Field3D rhs = sqrt(SQ(n) + SQ(T));
Field3D profile = pow(n + n0, 1.5);
Field3D masked = if_else(use_drive, source * profile, sink * profile);
BoutReal max_error = max(abs(lhs - rhs), true);
Reductions such as min, max, and mean can operate directly
on an expression, so an intermediate field is often unnecessary.
pow also participates in lazy field expressions, including mixed
Field2D/Field3D cases where the Field2D operand is broadcast in
z. FieldPerp also has pow overloads for FieldPerp with
FieldPerp or a scalar.
Region arguments#
These operators take a region argument. Common values are [1] (see
Iterating over fields):
RGN_ALL, which is the whole meshRGN_NOBNDRY, which skips all boundariesRGN_NOX, which skips the x boundariesRGN_NOY, which skips the y boundaries
The default is usually RGN_ALL. Restricting the region can improve
performance when guard-cell values will not be used.
When a region-limited expression is materialized into a field, only the selected region is guaranteed to contain valid values. This is the same performance-oriented convention used by other field operators.
Field3DParallel follows the same rule for the main field data. On FCI
meshes, materializing a lazy expression into Field3DParallel also
preserves the forward and backward parallel slices when those slices are
available on the expression operands. Materializing the same expression
into plain Field3D does not preserve those slices.