Operators API

Low-level operator algebra and tensor/scalar utilities.

Tensor and Scalar Algebra

LinearAlgebra.:⋅Function
⋅(A::TensorField, B::TensorField)

Element-wise (Hadamard) product followed by summation of all components, yielding a scalar per tensor (i.e., Frobenius inner product).

Returns: ScalarField

source
⋅(A::Union{VectorField,TensorField}, D::Function)

Right contraction with the differential operator. With D == ∇:

  • If A is VectorField: returns div(A) (scalar field).
  • If A is TensorField: returns div(A) (vector field).

Returns: ScalarField or VectorField

Examples

# 3D (assumes `problem` and a "body" physical group are defined)
V = vectorField(problem, [field("body", fx=x->x, fy=y->y, fz=z->z)])
divV = V ⋅ ∇   # ScalarField
source
⋅(D::Function, A::Union{VectorField,TensorField})

Left contraction with the differential operator. With D == ∇:

  • If A is VectorField: returns div(A).
  • If A is TensorField: returns div(A').

Returns: ScalarField or VectorField

Examples

# 3D (assumes `problem` and a "body" physical group are defined)
T = tensorField(problem, [field("body", fz=z->z)])
DV = ∇ ⋅ T     # VectorField (divergence of tensor)
source
LowLevelFEM.unitTensorFunction
unitTensor(A::TensorField)

Creates an identity tensor field (I) with the same element structure and time steps as A.

Returns: TensorField

source
LowLevelFEM.traceFunction
trace(A::TensorField)

Computes the trace of each 3×3 tensor block.

Returns: ScalarField

source
LowLevelFEM.mapScalarFieldFunction
mapScalarField(f, A::ScalarField)

Apply a function elementwise to a scalar field.

The function f is applied to each element-wise matrix of the scalar field. If the field is nodal, it is first converted to elementwise form.

This is a low-level helper used to implement elementwise scalar-field operations such as abs, +, -, log, sqrt, etc.

Returns

  • A new ScalarField containing the transformed values.
source

Differential Operators

LowLevelFEM.∇Function
∇_new(r::Union{ScalarField,VectorField,TensorField}; nabla=:grad)

Compute spatial derivatives at the element nodes and return an element-wise field. This experimental implementation retrieves the Jacobians of all elements of a given type and entity in one Gmsh call and evaluates the field derivatives directly, without assembling element derivative matrices.

Nodal input is converted to element-wise storage with nodesToElements, which preserves its values at the element nodes. Element-wise input is used directly, so discontinuities between adjacent elements are preserved. The result is always element-wise because derivatives can also be discontinuous between adjacent elements. For element-wise input, r.numElem defines the domain of the operation; consequently, fields restricted to a surface, curve, or another physical group remain restricted to that group.

Supported operations:

  • ScalarField, nabla=:grad -> VectorField
  • three-component VectorField, nabla=:grad -> TensorField
  • three-component VectorField, nabla=:div -> ScalarField
  • three-component VectorField, nabla=:curl -> VectorField
  • TensorField, nabla=:div -> VectorField
  • axisymmetric two-component VectorField, nabla=:grad -> TensorField
source
LowLevelFEM.gradFunction
grad(r::Union{ScalarField,VectorField})

Solves the gradient of the scalar field or vector field r. An alternative way to solve grad is to use as a differencial operator.

Return: VectorField or TensorField

Types:

  • r: ScalarField or VectorField

3D Examples

# Assumes a 3D mesh with physical group "body".

# 1) Gradient of a 3D scalar field → VectorField
f(X,Y,Z) = X^2 + Y*Z
S = scalarField(problem, [field("body", f=f)])
G1 = grad(S)
G2 = ∇(S)

# 2) Gradient of a 3D vector field → TensorField
vx(X,Y,Z) = X
vy(X,Y,Z) = Y
vz(X,Y,Z) = Z
V = vectorField(problem, [field("body", fx=vx, fy=vy, fz=vz)])
T1 = grad(V)
T2 = V ∘ ∇
source
LowLevelFEM.curlFunction
curl(r::VectorField)

Solves the rotation of the vector field r. An alternative way to solve curl is to use as a differencial operator.

Return: VectorField

Types:

  • r: VectorField

3D Example (assumes problem is set as in the ∇ doc setup)

# Assumes a 3D mesh with physical group "body".
vx(X, Y, Z) = 0
vy(X, Y, Z) = X
vz(X, Y, Z) = 0
v = vectorField(problem, [field("body", fx=vx, fy=vy, fz=vz)])
D1 = curl(v)
D2 = ∇ × v
source
LowLevelFEM.rotFunction
rot(r::VectorField)

Solves the rotation of the vector field r. In some countries "rot" denotes the English "curl". (See the curl function.)

Return: VectorField

Types:

  • r: VectorField
source