Operators and Algebra
Base.:* — Method*(b::Number, A::ScalarField)Performs multiplication of a ScalarField objects and a Number.
Return: ScalarField
Examples
C = 2.0 * ABase.:* — Method*(A::ScalarField, b::Number)Performs multiplication of a ScalarField objects and a Number.
Return: ScalarField
Examples
C = A * 2.0Base.:* — Method*(A::ScalarField, B::ScalarField)Performs element-wise multiplication of two ScalarField objects on the same set of elements.
Returns: ScalarField
Examples
C = A * BBase.:* — Method*(A::ScalarField, B::VectorField)Scales a VectorField by a ScalarField element-wise on matching elements.
Returns: VectorField
Examples
v2 = s .* v # equivalent to s * vBase.:* — Method*(A::SystemMatrix, b::Number)
*(b::Number, A::SystemMatrix)
/(A::SystemMatrix, b::Number)Scalar multiplication of a system matrix.
Base.:* — Method*(A::TensorField, B::TensorField)Tensor contraction (matrix multiplication) for each element/node: reshapes 9×1 blocks into 3×3, multiplies, then flattens back.
Returns: TensorField
Base.:* — Method*(A::Union{SystemMatrix,Matrix}, B::Union{ScalarField,VectorField,TensorField})Matrix–vector multiplication between a system matrix and a nodal vector field.
If the vector field is defined elementwise, it is automatically converted to nodal representation before multiplication.
Returns
VectorFieldcontaining the nodal result with one time step.
Base.:* — Method*(B::VectorField, A::ScalarField)Scales a VectorField by a ScalarField element-wise on matching elements.
Returns: VectorField
Base.:+ — Method+(b::Number, A::ScalarField)Add a constant offset to a scalar field.
The scalar b is added elementwise to each entry of every element-wise matrix of the scalar field.
If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the shifted values.
Base.:+ — Method+(A::ScalarField, b::Number)Add a constant offset to a scalar field.
The scalar b is added elementwise to each entry of every element-wise matrix of the scalar field.
If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the shifted values.
Base.:+ — Method+(A::ScalarField, B::ScalarField)Performs element-wise addition of two ScalarField objects on the same set of elements.
Returns: ScalarField
Examples
C = A + BBase.:+ — Method+(A::SystemMatrix, B::SystemMatrix)
-(A::SystemMatrix, B::SystemMatrix)Addition and subtraction of system matrices.
If the sparse matrices have identical CSC patterns, only the numerical values are added or subtracted. Otherwise, the general sparse matrix operation is used.
Base.:- — Method-(b::Number, A::ScalarField)Subtract a constant offset from a scalar field.
The scalar b is subtracted elementwise from each entry of every element-wise matrix of the scalar field.
If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the shifted values.
Base.:- — Method-(A::ScalarField, b::Number)Subtract a constant offset from a scalar field.
The scalar b is subtracted elementwise from each entry of every element-wise matrix of the scalar field.
If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the shifted values.
Base.:- — Method-(A::ScalarField, B::ScalarField)Performs element-wise subtraction of two ScalarField objects on the same set of elements.
Returns: ScalarField
Examples
C = A - BBase.:/ — Method/(b::Number, A::ScalarField)Elementwise division of a constant by a scalar field.
Each element-wise matrix of the scalar field is used as the divisor of the constant b, i.e. b ./ A.
If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the elementwise divided values.
Base.:/ — Method/(A::ScalarField, b::Number)Elementwise division of a scalar field by a constant.
Each element-wise matrix of the scalar field is divided by the scalar b. If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the elementwise divided values.
Base.:/ — Method/(A::ScalarField, B::ScalarField)Performs element-wise division of two ScalarField objects on the same set of elements.
Returns: ScalarField
Examples
C = A / BBase.:/ — Method/(B::VectorField, A::ScalarField)Divides a VectorField by a ScalarField element-wise on matching elements.
Returns: VectorField
Base.:\ — Method\(A::Union{SystemMatrix,Matrix}, b::Union{ScalarField,VectorField,TensorField})Solves the linear system A * x = b for a nodal scalar, vectoror tensor field right-hand side.
If the field is defined elementwise, it will be converted to nodal form before solving.
Returns
ScalarFieldorVectorFieldorTensorFieldcontaining the solution.
Base.:\ — Method\(K::Union{SystemMatrix,SparseMatrixCSC}, F::SparseMatrixCSC)Solves a sparse linear system with multiple right-hand sides.
Returns
- Sparse matrix containing the solution.
Base.:∘ — Method∘(D::Function, A::Union{ScalarField,VectorField})Left application of differential operator D to field A.
- If
D == ∇andAisScalarField: returnsgrad(A). - If
D == ∇andAisVectorField: returnsgrad(A)'(transpose).
Returns: VectorField or TensorField
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)])
T = ∇ ∘ V # equals grad(V)'Base.:∘ — Method∘(A::Union{ScalarField,VectorField}, D::Function)Right application of differential operator D to field A.
- If
D == ∇andAisScalarField: returnsgrad(A). - If
D == ∇andAisVectorField: returnsgrad(A).
Returns: VectorField or TensorField
Examples
# 3D (assumes `problem` and a "body" physical group are defined)
S = scalarField(problem, [field("body", f=(x,y,z)->x*y)])
G = S ∘ ∇ # grad of scalar field
V = vectorField(problem, [field("body", fx=x->x, fy=y->y, fz=z->z)])
H = V ∘ ∇ # grad of vector field (tensor)Base.Math.cbrt — Methodcbrt(A::ScalarField)Elementwise cubic root of a scalar field.
Applies the cubic root to each entry of every element-wise matrix of the scalar field.
If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the elementwise cubic-rooted values.
Base.abs — Methodabs(A::ScalarField)Elementwise absolute value of a scalar field.
Applies the absolute value to each entry of every element-wise matrix of the scalar field.
If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the elementwise absolute values.
Base.adjoint — Methodadjoint(A::TensorField)Adjoint (conjugate transpose) of each 3×3 tensor block.
Returns: TensorField
Base.axes — Methodaxes(K::SystemMatrix)Return the valid index ranges for the system matrix.
Equivalent to axes(K.A).
Base.copy — Methodcopy(K::SystemMatrix)Returns a deep copy of the system matrix.
Base.eltype — Methodeltype(K::SystemMatrix)Return the element type of the system matrix.
Equivalent to eltype(K.A).
Base.getindex — Methodgetindex(K::SystemMatrix, I...)Indexing operation for SystemMatrix.
Forwards all indexing operations to the underlying sparse matrix K.A, allowing a SystemMatrix to be indexed in the same way as a SparseMatrixCSC.
Examples include:
K[i, j]K[:, j],K[i, :]K[a:b, c:d]K[v1, v2]wherev1andv2are index vectors.
Base.inv — Methodinv(A::TensorField)Matrix inverse of each 3×3 tensor block.
Returns: TensorField
Base.log — Methodlog(A::ScalarField)Elementwise natural logarithm of a scalar field.
Applies the natural logarithm to each entry of every element-wise matrix of the scalar field.
If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the elementwise logarithmic values.
Base.setindex! — Methodsetindex!(K::SystemMatrix, v, I...)In-place assignment for SystemMatrix.
Forwards indexed assignment to the underlying sparse matrix K.A, enabling modifications such as:
K[i, j] = vK[a:b, c:d] .= vK[v1, v2] .= submatrix
Note that assignment follows the semantics and performance characteristics of SparseMatrixCSC.
Base.size — Methodsize(K::SystemMatrix)Return the size of the system matrix.
Equivalent to size(K.A).
Base.sqrt — Methodsqrt(A::ScalarField)Elementwise square root of a scalar field.
Applies the square root to each entry of every element-wise matrix of the scalar field.
If the field is nodal, it is first converted to elementwise form.
Returns
- A new
ScalarFieldcontaining the elementwise square-rooted values.
Base.transpose — Methodtranspose(K::SystemMatrix)
adjoint(K::SystemMatrix)Transpose / adjoint of a system matrix.
Base.transpose — Methodtranspose(A::TensorField)Transposes each 3×3 tensor block.
Returns: TensorField
LinearAlgebra.:× — Method×(D::Function, A::VectorField)Left curl. With D == ∇, returns curl(A).
Returns: VectorField
Examples
# 3D (assumes `problem` and a "body" physical group are defined)
V = vectorField(problem, [field("body", fx=x->0, fy=x->x, fz=z->0)])
C = ∇ × VLinearAlgebra.:× — Method×(A::VectorField, D::Function)Right curl with sign convention. With D == ∇, returns -curl(A).
Returns: VectorField
Examples
# 3D (assumes `problem` and a "body" physical group are defined)
V = vectorField(problem, [field("body", fx=x->0, fy=x->x, fz=z->0)])
Cneg = V × ∇ # -curl(V)LinearAlgebra.:× — Method×(a::VectorField, b::VectorField)Element-wise 3D vector cross product on matching elements.
Returns: VectorField
Examples
w = u × vLinearAlgebra.:⋅ — Method⋅(D::Function, A::Union{VectorField,TensorField})Left contraction with the differential operator. With D == ∇:
- If
AisVectorField: returnsdiv(A). - If
AisTensorField: returnsdiv(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)LinearAlgebra.:⋅ — Method⋅(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
LinearAlgebra.:⋅ — Method⋅(A::Union{VectorField,TensorField}, D::Function)Right contraction with the differential operator. With D == ∇:
- If
AisVectorField: returnsdiv(A)(scalar field). - If
AisTensorField: returnsdiv(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 ⋅ ∇ # ScalarFieldLinearAlgebra.det — Methoddet(A::TensorField)Computes the determinant of each 3×3 tensor block.
Returns: ScalarField
LinearAlgebra.diagm — Methoddiagm(A::VectorField)Creates a diagonal TensorField from a VectorField (dim=3), i.e., places vector components on the tensor diagonal for each node/element.
Returns: TensorField
LinearAlgebra.issymmetric — Methodissymmetric(K::SystemMatrix)Checks whether the system matrix is symmetric.
LinearAlgebra.norm — Methodnorm(A::VectorField)Element-wise Euclidean norm of a VectorField.
Returns: ScalarField
LowLevelFEM.ldiv_sparse! — Methodldiv_sparse!(X::SparseMatrixCSC, K::Union{SystemMatrix,SparseMatrixCSC}, F::SparseMatrixCSC)Solves the sparse linear system K * X = F column-by-column, where F is a sparse matrix representing multiple right-hand sides.
Returns
- Sparse matrix
Xcontaining the solution.
LowLevelFEM.mapScalarField — MethodmapScalarField(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
ScalarFieldcontaining the transformed values.
LowLevelFEM.trace — Methodtrace(A::TensorField)Computes the trace of each 3×3 tensor block.
Returns: ScalarField
LowLevelFEM.unitTensor — MethodunitTensor(A::TensorField)Creates an identity tensor field (I) with the same element structure and time steps as A.
Returns: TensorField