Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HyperFEM"
uuid = "ddbf423a-3df4-409e-9685-3dc416cae46c"
version = "0.0.4"
authors = ["MultiSimo_Group"]
authors = ["MultiSimOLab"]

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
4 changes: 3 additions & 1 deletion src/Exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ end
@publish TensorAlgebra VectorValue # Reexport from Gridap for convenience
@publish TensorAlgebra (*)
@publish TensorAlgebra (×ᵢ⁴)
@publish TensorAlgebra (⊗₁²)
@publish TensorAlgebra (⊗₁₂³)
@publish TensorAlgebra (⊗₁₃²)
@publish TensorAlgebra (⊗₁²³)
@publish TensorAlgebra (⊗₁₃²⁴)
@publish TensorAlgebra (⊗₁₂³⁴)
@publish TensorAlgebra (⊗₁²)
@publish TensorAlgebra (⊗₁₂₃⁴)
@publish TensorAlgebra (⊗₁₂₃₄²⁴)
@publish TensorAlgebra logreg
@publish TensorAlgebra Box
@publish TensorAlgebra Ellipsoid
Expand Down
60 changes: 59 additions & 1 deletion src/TensorAlgebra/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ function Gridap.TensorValues.outer(A::VectorValue{D,Float64}, B::VectorValue{D,F
return (A ⊗₁² B)
end

function Gridap.TensorValues.outer(A::TensorValue{4,2,Float64}, B::VectorValue{2,Float64})
return (A ⊗₁₂₃⁴ B)
end

function Gridap.TensorValues.outer(A::TensorValue{9,3,Float64}, B::VectorValue{3,Float64})
return (A ⊗₁₂₃⁴ B)
end


"""
⊗₁²(A::VectorValue{D}, B::VectorValue{D})::TensorValue{D,D}
Expand Down Expand Up @@ -121,7 +129,7 @@ end


"""
⊗₁²³(A::TensorValue{D}, B::VectorValue{D})::TensorValue{D,D*D}
⊗₁³(A::TensorValue{D}, B::VectorValue{D})::TensorValue{D,D*D}

Outer product of a second-order and first-order tensors (matrix and vector),
returning a third-order tensor represented in a `D x D²` flattened matrix using combined indices.
Expand Down Expand Up @@ -156,6 +164,29 @@ returning a third-order tensor represented in a `D x D²` flattened matrix using
end


"""
⊗₁₂₃⁴(A::TensorValue{D²,D}, B::TensorValue{D})::TensorValue{D,D*D}

Outer product of a third-order and first-order tensors (tensor and vector),
returning a fourth-order tensor represented in a `D² x D²` flattened matrix using combined indices.
"""
@generated function (⊗₁₂₃⁴)(A::TensorValue{D²,D}, V::VectorValue{D}) where {D,D²}
@assert D*D == D² "Third- and first-order tensors size mismatch with $D² × $D and $D"
str = ""
for l in 1:D
for k in 1:D
for j in 1:D
for i in 1:D
a = _flat_idx(i,j,D)
str *= "A[$a,$k]*V[$l],"
end
end
end
end
Meta.parse("TensorValue{D*D,D*D}($str)")
end


function (×ᵢ⁴)(A::TensorValue{3,3,Float64})

TensorValue(0.0, 0.0, 0.0, 0.0, A[9], -A[8], 0.0, -A[6], A[5], 0.0, 0.0, 0.0, -A[9],
Expand Down Expand Up @@ -516,3 +547,30 @@ The operation follows the **index contraction pattern**, where addition is perfo
end
Meta.parse("TensorValue{D²}($str)")
end


"""
contraction_IJKL_JL(A::TensorValue{D*D}, H::TensorValue{D})::TensorValue{D*D}

Performs a tensor contraction between a fourth-order tensor (represented as a `D² × D²` matrix in flattened index notation)
and a second-order tensor (of size `D × D`).
The operation follows the **index contraction pattern**, where addition is performed for repeated indices.
"""
@generated function contraction_IJKL_JL(H::TensorValue{D²}, A::TensorValue{D}) where {D, D²}
@assert D*D == D² "Fourth- and Second-order tensors size mismatch"
str = ""
for i in 1:D
for k in 1:D
for j in 1:D
for l in 1:D
a = _flat_idx(i,j,k,l,D)
str *= "+H[$a]*A[$j,$l]"
end
end
str *= ","
end
end
Meta.parse("TensorValue{D}($str)")
end

(⊗₁₂₃₄²⁴) = contraction_IJKL_JL
Loading