Hello!
I am unsure of how to make a proper MWE, so I will explain what I would like to achieve, which is the automatic construction of this matrix:
[Source: https://dual.sphysics.org/7thworkshop/workshop/program/7DSW_mDBC.pdf]My code needs to adapt, in the sense that if it is a 2D case, then the last row and column from the matrix A is neglected. Currently what I do is using StaticArrays
, SMatrix
functionality, and construct column per column the matrix as shown below.
I have had to use an if
statement, I wonder if I could do this without an if
statement in a smart way?
Kind regards
EDIT: Code below is just to explain how I am handling it right now
# Filling the Aᵧ matrix is done in column-major order
xⱼᵢ = -xᵢⱼ
if Dimensions == 2
Aᵧ[i] += SMatrix{DimensionsPlus, DimensionsPlus, FloatType, DimensionsPlus*DimensionsPlus}(
# First row
VⱼWᵢⱼ, (Vⱼ * ∇ᵢWᵢⱼ)...,
# Second row
xⱼᵢ[1] * VⱼWᵢⱼ, (xⱼᵢ[1] * Vⱼ * ∇ᵢWᵢⱼ)...,
# Third row
xⱼᵢ[2] * VⱼWᵢⱼ, (xⱼᵢ[2] * Vⱼ * ∇ᵢWᵢⱼ)...,
)
elseif Dimensions == 3
Aᵧ[i] += SMatrix{DimensionsPlus, DimensionsPlus, FloatType, DimensionsPlus*DimensionsPlus}(
# First row
VⱼWᵢⱼ, (Vⱼ * ∇ᵢWᵢⱼ)...,
# Second row
xⱼᵢ[1] * VⱼWᵢⱼ, (xⱼᵢ[1] * Vⱼ * ∇ᵢWᵢⱼ)...,
# Third row
xⱼᵢ[2] * VⱼWᵢⱼ, (xⱼᵢ[2] * Vⱼ * ∇ᵢWᵢⱼ)...,
# Fourth row
xⱼᵢ[3] * VⱼWᵢⱼ, (xⱼᵢ[3] * Vⱼ * ∇ᵢWᵢⱼ)...,
)