Skip to content

Commit a357a76

Browse files
authored
Merge pull request #47 from MultiSimOLab/test
Adds HGO_1Fiber model and tests
2 parents 39ee6fd + 36bdb82 commit a357a76

7 files changed

Lines changed: 115 additions & 9 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Example of a Monolithic implementation for the simulation of Nonlinear ElectroMe
3939

4040
```julia
4141
using HyperFEM
42-
using HyperFEM: jacobian, solve!
4342
using Gridap, GridapGmsh, GridapSolvers, DrWatson
4443
using GridapSolvers.NonlinearSolvers
4544
using Gridap.FESpaces

src/Exports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ end
6565
@publish PhysicalModels ViscousIncompressible
6666
@publish PhysicalModels GeneralizedMaxwell
6767
@publish PhysicalModels HGO_4Fibers
68+
@publish PhysicalModels HGO_1Fiber
6869

6970
@publish PhysicalModels Mechano
7071
@publish PhysicalModels Thermo

src/PhysicalModels/ElectroMechanicalModels.jl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11

2-
struct ElectroMechModel{E<:Electro, M<:Mechano} <: ElectroMechano
2+
struct ElectroMechModel{E<:Electro,M<:Mechano} <: ElectroMechano
33
electro::E
44
mechano::M
55

6-
function ElectroMechModel(electro::E, mechano::M) where {E<:Electro, M<:Mechano}
6+
function ElectroMechModel(electro::E, mechano::M) where {E<:Electro,M<:Mechano}
77
new{E,M}(electro, mechano)
88
end
99

10-
function ElectroMechModel(; electro::E, mechano::M) where {E<:Electro, M<:Mechano}
10+
function ElectroMechModel(; electro::E, mechano::M) where {E<:Electro,M<:Mechano}
1111
new{E,M}(electro, mechano)
1212
end
1313

14-
function (obj::ElectroMechModel)(Λ::Float64=1.0)
14+
function (obj::ElectroMechModel{<:Electro,<:IsoElastic})(Λ::Float64=1.0)
1515
Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano(Λ)
1616
Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano, Λ)
1717
Ψ(F, E) = Ψm(F) + Ψem(F, E)
@@ -22,7 +22,17 @@ struct ElectroMechModel{E<:Electro, M<:Mechano} <: ElectroMechano
2222
∂Ψφφ(F, E) = ∂Ψem_φφ(F, E)
2323
return (Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ)
2424
end
25-
25+
function (obj::ElectroMechModel{<:Electro,<:AnisoElastic})(Λ::Float64=1.0)
26+
Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano(Λ)
27+
Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano, Λ)
28+
Ψ(F, E, N) = Ψm(F, N) + Ψem(F, E)
29+
∂Ψu(F, E, N) = ∂Ψm_u(F, N) + ∂Ψem_u(F, E)
30+
∂Ψφ(F, E, N) = ∂Ψem_φ(F, E)
31+
∂Ψuu(F, E, N) = ∂Ψm_uu(F, N) + ∂Ψem_uu(F, E)
32+
∂Ψφu(F, E, N) = ∂Ψem_φu(F, E)
33+
∂Ψφφ(F, E, N) = ∂Ψem_φφ(F, E)
34+
return (Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ)
35+
end
2636
function (obj::ElectroMechModel{<:Electro,<:ViscoElastic})(Λ::Float64=1.0; Δt)
2737
Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano(Λ, Δt=Δt)
2838
Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano, Λ)
@@ -34,6 +44,7 @@ struct ElectroMechModel{E<:Electro, M<:Mechano} <: ElectroMechano
3444
∂Ψφφ(F, Fn, E, A...) = ∂Ψem_φφ(F, E)
3545
return (Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ)
3646
end
47+
3748
end
3849

3950
ViscoElectricModel = ElectroMechModel{<:Electro,<:ViscoElastic}
@@ -92,12 +103,12 @@ struct FlexoElectroModel{EM<:ElectroMechano} <: FlexoElectro
92103
electromechano::EM
93104
κ::Float64
94105

95-
function FlexoElectroModel(electro::E, mechano::M; κ=1.0) where {E <: Electro, M <: Mechano}
106+
function FlexoElectroModel(electro::E, mechano::M; κ=1.0) where {E<:Electro,M<:Mechano}
96107
physmodel = ElectroMechModel(electro, mechano)
97108
new{ElectroMechModel{E,M}}(physmodel, κ)
98109
end
99110

100-
function FlexoElectroModel(; electro::E, mechano::M, κ=1.0) where {E <: Electro, M <: Mechano}
111+
function FlexoElectroModel(; electro::E, mechano::M, κ=1.0) where {E<:Electro,M<:Mechano}
101112
physmodel = ElectroMechModel(electro, mechano)
102113
new{ElectroMechModel{E,M}}(physmodel, κ)
103114
end

src/PhysicalModels/MechanicalModels.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,36 @@ end
757757

758758

759759

760+
struct HGO_1Fiber <: AnisoElastic
761+
c1::Float64
762+
c2::Float64
763+
Kinematic::Kinematics{Mechano}
764+
function HGO_1Fiber(; c1::Float64, c2::Float64, Kinematic::KinematicModel=Kinematics(Mechano))
765+
new(c1, c2, Kinematic)
766+
end
767+
768+
function (obj::HGO_1Fiber)(Λ::Float64=1.0; Threshold=0.01)
769+
c1, c2 = obj.c1, obj.c2
770+
771+
Ψ(F, N1) = begin
772+
M1 = N1 / norm(N1)
773+
c1 / (4 * c2) * (exp(c2 * ((F * M1) (F * M1) - 1.0)^2.0) - 1.0)
774+
end
775+
776+
∂Ψ∂F(F, N1) = begin
777+
M1 = N1 / norm(N1)
778+
c1 * exp(c2 * ((F * M1) (F * M1) - 1.0)^2.0) * ((F * M1) (F * M1) - 1.0) * ((F * M1) M1)
779+
end
780+
781+
∂Ψ2∂F∂F(F, N1) = begin
782+
M1 = N1 / norm(N1)
783+
c1 * exp(c2 * ((F * M1) (F * M1) - 1.0)^2.0) * ((4 * c2 * (((F * M1) (F * M1) - 1.0)^2.0) + 2.0) * (((F * M1) M1) ((F * M1) M1)) + ((F * M1) (F * M1) - 1.0) * (I3 ₁₃²⁴ (M1 M1)))
784+
end
785+
786+
return (Ψ, ∂Ψ∂F, ∂Ψ2∂F∂F)
787+
end
788+
end
789+
760790

761791
struct IncompressibleNeoHookean3D{A} <: IsoElastic
762792
λ::Float64

src/PhysicalModels/PhysicalModels.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export MagnetoMechModel
5555
export GeneralizedMaxwell
5656
export ViscousIncompressible
5757
export HGO_4Fibers
58+
export HGO_1Fiber
5859

5960
export PhysicalModel
6061
export Mechano

test/TestConstitutiveModels/ElectroMechanicalTests.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,38 @@ const ∇u = TensorValue(1.0:9.0...) * 1e-3
77
const ∇un = TensorValue(1.0:9.0...) * 5e-4
88

99

10+
@testset "Electro+4*HGO_1Fiber" begin
11+
c1 = [0.6639232500447778, 0.5532987701062146, 0.9912576142028674, 0.4951942011240962]
12+
c2 = [0.800583033264982, 0.3141082734275339, 0.8063905248474006, 0.5850486948450955]
13+
M1 = [ 0.36799630150742724, 0.8353476258002335, 0.57704047269419]
14+
M1 = VectorValue(M1/norm(M1))
15+
M2 = [ 0.3857610953527303, 0.024655018338846868, 0.6133770006613235]
16+
M2 = VectorValue(M2/norm(M2))
17+
M3 = [ 0.4516424464747618, 0.6609741557924332, 0.8441070681368911]
18+
M3 = VectorValue(M3/norm(M3))
19+
M4 = [0.7650638541897623, 0.8268625401770648, 0.3103412304991431]
20+
M4 = VectorValue(M4/norm(M4))
21+
22+
model1 = HGO_1Fiber(c1=c1[1], c2=c2[1])
23+
model2 = HGO_1Fiber(c1=c1[2], c2=c2[2])
24+
model3 = HGO_1Fiber(c1=c1[3], c2=c2[3])
25+
model4 = HGO_1Fiber(c1=c1[4], c2=c2[4])
26+
modelMR = MooneyRivlin3D=3.0, μ1=1.0, μ2=2.0)
27+
modelID = IdealDielectric=4.0)
28+
modelelectro=modelMR+[model1 model2 model3 model4]+modelID
29+
30+
31+
Ψ, ∂Ψ∂F, ∂Ψ∂F∂F = modelelectro()
32+
33+
F, _, _ = get_Kinematics(model1.Kinematic)
34+
E = get_Kinematics(modelID.Kinematic)
35+
@test Ψ(F(∇u),E(∇φ) ,(M1,M2,M3,M4)) == -27.513663654827152
36+
@test isapprox(norm(∂Ψ∂F(F(∇u),E(∇φ) ,(M1,M2,M3,M4))) , 47.45420724735932,rtol=1e-14)
37+
@test isapprox(norm(∂Ψ∂F∂F(F(∇u),E(∇φ) ,(M1,M2,M3,M4))), 14.707913034885005,rtol=1e-14)
38+
end
39+
40+
41+
1042
@testset "ElectroMechano" begin
1143
modelMR = MooneyRivlin3D=3.0, μ1=1.0, μ2=2.0)
1244
modelID = IdealDielectric=4.0)

test/TestConstitutiveModels/PhysicalModelTests.jl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,38 @@ function test_derivatives_3D_(model::PhysicalModel; rtol=1e-14, kwargs...)
3939
end
4040

4141

42+
43+
44+
@testset "composition of HGO_1Fiber" begin
45+
c1 = [0.6639232500447778, 0.5532987701062146, 0.9912576142028674, 0.4951942011240962]
46+
c2 = [0.800583033264982, 0.3141082734275339, 0.8063905248474006, 0.5850486948450955]
47+
M1 = [ 0.36799630150742724, 0.8353476258002335, 0.57704047269419]
48+
M1 = VectorValue(M1/norm(M1))
49+
M2 = [ 0.3857610953527303, 0.024655018338846868, 0.6133770006613235]
50+
M2 = VectorValue(M2/norm(M2))
51+
M3 = [ 0.4516424464747618, 0.6609741557924332, 0.8441070681368911]
52+
M3 = VectorValue(M3/norm(M3))
53+
M4 = [0.7650638541897623, 0.8268625401770648, 0.3103412304991431]
54+
M4 = VectorValue(M4/norm(M4))
55+
56+
model1 = HGO_1Fiber(c1=c1[1], c2=c2[1])
57+
model2 = HGO_1Fiber(c1=c1[2], c2=c2[2])
58+
model3 = HGO_1Fiber(c1=c1[3], c2=c2[3])
59+
model4 = HGO_1Fiber(c1=c1[4], c2=c2[4])
60+
61+
model=[model1 model2 model3 model4]
62+
63+
Ψ, ∂Ψ∂F, ∂Ψ∂F∂F = model()
64+
∂Ψ∂F_(F,M1,M2,M3,M4) = TensorValue(ForwardDiff.gradient(F -> Ψ(F,(get_array(M1),get_array(M2),get_array(M3),get_array(M4))), get_array(F)))
65+
∂Ψ∂F∂F_(F,M1,M2,M3,M4) = TensorValue(ForwardDiff.hessian(F -> Ψ(F,(get_array(M1),get_array(M2),get_array(M3),get_array(M4))), get_array(F)))
66+
67+
68+
F, _, _ = get_Kinematics(model1.Kinematic)
69+
@test Ψ(F(∇u3), (M1,M2,M3,M4)) == 0.0005561006012767033
70+
@test isapprox(norm(∂Ψ∂F(F(∇u3), (M1,M2,M3,M4))) , norm(∂Ψ∂F_(F(∇u3), M1,M2,M3,M4)),rtol=1e-14)
71+
@test isapprox(norm(∂Ψ∂F∂F(F(∇u3), (M1,M2,M3,M4))), norm(∂Ψ∂F∂F_(F(∇u3), M1,M2,M3,M4)),rtol=1e-14)
72+
end
73+
4274
@testset "HGO_4Fibers" begin
4375
c1 = [0.6639232500447778, 0.5532987701062146, 0.9912576142028674, 0.4951942011240962]
4476
c2 = [0.800583033264982, 0.3141082734275339, 0.8063905248474006, 0.5850486948450955]
@@ -64,7 +96,7 @@ end
6496
end
6597

6698

67-
@testset "HGO_4Fibers+MooneyRivlin3D" begin
99+
@testset "composition of HGO_4Fibers+MooneyRivlin3D" begin
68100
c1 = [0.6639232500447778, 0.5532987701062146, 0.9912576142028674, 0.4951942011240962]
69101
c2 = [0.800583033264982, 0.3141082734275339, 0.8063905248474006, 0.5850486948450955]
70102
M1 = [ 0.36799630150742724, 0.8353476258002335, 0.57704047269419]

0 commit comments

Comments
 (0)