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
∇(r::Union{VectorField, ScalarField, TensorField}; nabla=:grad)

Computes derivatives of r.

  • If r is a ScalarField and nabla == :grad, returns the gradient (a VectorField).
  • If r is a VectorField and nabla == :grad, returns the gradient (a TensorField).
  • If r is a VectorField and nabla == :curl, returns the curl (a VectorField).
  • If r is a VectorField and nabla == :div, returns the divergence (a ScalarField).
  • If r is a TensorField and nabla == :div, returns the divergence (a VectorField).

Returns: ScalarField, VectorField, or TensorField

Types:

  • r: ScalarField, VectorField, or TensorField
  • nabla: Symbol

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

# One-time 3D setup (assumes examples/Fields/cube.geo exists with physical group "body")
using LowLevelFEM
gmsh.initialize()
gmsh.open("examples/Fields/cube.geo")
mat = material("body", E=210e3, ν=0.3, ρ=7.85e-9)
problem = Problem([mat], type=:Solid)

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

# 2) Curl of a 3D vector field: ∇ × v → VectorField
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)])
C = ∇(V, nabla=:curl)  # approx (0, 0, 1) everywhere

# 3) Divergence of a 3D vector field: ∇ ⋅ v → ScalarField
v1(X,Y,Z) = X
v2(X,Y,Z) = Y
v3(X,Y,Z) = Z
V2 = vectorField(problem, [field("body", fx=v1, fy=v2, fz=v3)])
D = ∇(V2, nabla=:div)  # ≈ 3

# 4) Divergence of a 3D tensor field: ∇ · T → VectorField (if T is TensorField)
# For example, a diagonal tensor T with only Tzz = g(Z): div(T) = (0, 0, ∂g/∂Z)
g(Z) = 10 - Z
T = tensorField(problem, [field("body", fz=g)])
DV = ∇(T, nabla=:div)  # VectorField

# Symmetric displacement gradient via operators
# A = (u ∘ ∇ + ∇ ∘ u) / 2
gmsh.finalize()
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