From 10895d0c0d2734216f25b5956eb50f3a95239b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Thu, 30 Apr 2026 15:33:48 +0200 Subject: [PATCH 01/22] Refactor Electro and ThermoElectro --- src/PhysicalModels/ElectricalModels.jl | 35 +++++++++++++++++++++++ src/PhysicalModels/PhysicalModels.jl | 2 +- src/PhysicalModels/ThermoElectroModels.jl | 27 +++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/PhysicalModels/ThermoElectroModels.jl diff --git a/src/PhysicalModels/ElectricalModels.jl b/src/PhysicalModels/ElectricalModels.jl index c4b5c20..f4ab527 100644 --- a/src/PhysicalModels/ElectricalModels.jl +++ b/src/PhysicalModels/ElectricalModels.jl @@ -9,3 +9,38 @@ struct IdealDielectric <: Electro new(ε) end end + +function (obj::Electro)() + J(F) = det(F) + H(F) = det(F) * inv(F)' + + # Energy # + HE(F, E) = H(F) * E + HEHE(F, E) = HE(F, E) ⋅ HE(F, E) + Ψem(F, E) = (-elec.ε / (2.0 * J(F))) * HEHE(F, E) + + # First Derivatives # + ∂Ψem_∂H(F, E) = (-elec.ε / (J(F))) * (HE(F, E) ⊗ E) + ∂Ψem_∂J(F, E) = (+elec.ε / (2.0 * J(F)^2.0)) * HEHE(F, E) + ∂Ψem_∂E(F, E) = (-elec.ε / (J(F))) * (H(F)' * HE(F, E)) + ∂Ψem∂F(F, E) = ∂Ψem_∂H(F, E) × F + ∂Ψem_∂J(F, E) * H(F) + ∂Ψem∂E(F, E) = ∂Ψem_∂E(F, E) + + # Second Derivatives # + ∂Ψem_HH(F, E) = (-elec.ε / (J(F))) * (I3 ⊗₁₃²⁴ (E ⊗ E)) + ∂Ψem_HJ(F, E) = (+elec.ε / (J(F))^2.0) * (HE(F, E) ⊗ E) + ∂Ψem_JJ(F, E) = (-elec.ε / (J(F))^3.0) * HEHE(F, E) + ∂Ψem∂FF(F, E) = (F × (∂Ψem_HH(F, E) × F)) + + H(F) ⊗₁₂³⁴ (∂Ψem_HJ(F, E) × F) + + (∂Ψem_HJ(F, E) × F) ⊗₁₂³⁴ H(F) + + ∂Ψem_JJ(F, E) * (H(F) ⊗₁₂³⁴ H(F)) + + ×ᵢ⁴(∂Ψem_∂H(F, E) + ∂Ψem_∂J(F, E) * F) + + ∂Ψem_EH(F, E) = (-elec.ε / (J(F))) * ((I3 ⊗₁₃² HE(F, E)) + (H(F)' ⊗₁₂³ E)) + ∂Ψem_EJ(F, E) = (+elec.ε / (J(F))^2.0) * (H(F)' * HE(F, E)) + ∂Ψem∂EF(F, E) = (∂Ψem_EH(F, E) × F) + (∂Ψem_EJ(F, E) ⊗₁²³ H(F)) + + ∂Ψem∂EE(F, E) = (-elec.ε / (J(F))) * (H(F)' * H(F)) + + return (Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂Ψem∂EE) +end diff --git a/src/PhysicalModels/PhysicalModels.jl b/src/PhysicalModels/PhysicalModels.jl index b45ae7e..b04fc0a 100644 --- a/src/PhysicalModels/PhysicalModels.jl +++ b/src/PhysicalModels/PhysicalModels.jl @@ -119,7 +119,7 @@ abstract type MultiPhysicalModel <: PhysicalModel end abstract type ElectroMechano{E,M} <: MultiPhysicalModel end abstract type ThermoElectroMechano{T,E,M} <: MultiPhysicalModel end abstract type ThermoMechano{T,M} <: MultiPhysicalModel end -abstract type ThermoElectro{E,M} <: MultiPhysicalModel end +abstract type ThermoElectro{T,E} <: MultiPhysicalModel end abstract type FlexoElectro{EM} <: MultiPhysicalModel end abstract type MagnetoMechano{G,M} <: MultiPhysicalModel end diff --git a/src/PhysicalModels/ThermoElectroModels.jl b/src/PhysicalModels/ThermoElectroModels.jl new file mode 100644 index 0000000..91d23f3 --- /dev/null +++ b/src/PhysicalModels/ThermoElectroModels.jl @@ -0,0 +1,27 @@ + +struct ThermoElectroModel{E} <: ThermoElectro + electro::E + law::ThermalLaw + + function ThermoElectroModel(electro::E, law::ThermalLaw) where {E <: Electro} + new{E}(electro, law) + end +end + +function (obj::ThermoElectroModel)() + Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂∂Ψem∂FF, ∂∂Ψem∂EF, ∂∂Ψem∂EE = obj() + f, df, ddf = law() + + Ψ(F, E, θ) = f(θ)*Ψem(F,E) + ∂Ψ∂F(F, E, θ) = f(θ)*∂Ψem∂F(F,E) + ∂Ψ∂E(F, E, θ) = f(θ)*∂Ψem∂E(F,E) + ∂Ψ∂θ(F, E, θ) = df(θ)*Ψem(F,E) + ∂∂Ψ∂FF(F, E, θ) = f(θ)*∂∂Ψem∂FF(F,E) + ∂∂Ψ∂EE(F, E, θ) = f(θ)*∂∂Ψem∂EE(F,E) + ∂∂Ψ∂θθ(F, E, θ) = ddf(θ)*Ψem(F,E) + ∂∂Ψ∂EF(F, E, θ) = f(θ)*∂∂Ψem∂EF(F,E) + ∂∂Ψ∂Fθ(F, E, θ) = df(θ)*∂Ψem∂F(F,E) + ∂∂Ψ∂Eθ(F, E, θ) = df(θ)*∂Ψem∂E(F,E) + + return (Ψ, ∂Ψ∂F, ∂Ψ∂E, ∂Ψ∂θ, ∂∂Ψ∂FF, ∂∂Ψ∂EE, ∂∂Ψ∂θθ, ∂∂Ψ∂EF, ∂∂Ψ∂Fθ, ∂∂Ψ∂Eθ) +end From c92d54287d1c738d6f8de843f8f1b6d8c8147705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Thu, 30 Apr 2026 16:57:56 +0200 Subject: [PATCH 02/22] Fixed compilation --- src/Exports.jl | 1 + src/PhysicalModels/PhysicalModels.jl | 5 ++++- src/PhysicalModels/ThermoElectroModels.jl | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Exports.jl b/src/Exports.jl index 824bbc4..c9276cd 100644 --- a/src/Exports.jl +++ b/src/Exports.jl @@ -58,6 +58,7 @@ end @publish PhysicalModels ElectroMechModel @publish PhysicalModels ThermoElectroMechModel @publish PhysicalModels ThermoMechModel +@publish PhysicalModels ThermoElectroModel @publish PhysicalModels ThermoMech_Bonet @publish PhysicalModels ThermoMech_EntropicPolyconvex @publish PhysicalModels FlexoElectroModel diff --git a/src/PhysicalModels/PhysicalModels.jl b/src/PhysicalModels/PhysicalModels.jl index b04fc0a..4015465 100644 --- a/src/PhysicalModels/PhysicalModels.jl +++ b/src/PhysicalModels/PhysicalModels.jl @@ -50,6 +50,7 @@ export ThermalVolumetric export ElectroMechModel export ThermoElectroMechModel export ThermoMechModel +export ThermoElectroModel export ThermoMech_Bonet export ThermoMech_EntropicPolyconvex export FlexoElectroModel @@ -119,7 +120,7 @@ abstract type MultiPhysicalModel <: PhysicalModel end abstract type ElectroMechano{E,M} <: MultiPhysicalModel end abstract type ThermoElectroMechano{T,E,M} <: MultiPhysicalModel end abstract type ThermoMechano{T,M} <: MultiPhysicalModel end -abstract type ThermoElectro{T,E} <: MultiPhysicalModel end +abstract type ThermoElectro{E} <: MultiPhysicalModel end abstract type FlexoElectro{EM} <: MultiPhysicalModel end abstract type MagnetoMechano{G,M} <: MultiPhysicalModel end @@ -137,6 +138,8 @@ include("ThermalModels.jl") include("ThermoMechanicalModels.jl") +include("ThermoElectroModels.jl") + include("ElectroMechanicalModels.jl") include("MagnetoMechanicalModels.jl") diff --git a/src/PhysicalModels/ThermoElectroModels.jl b/src/PhysicalModels/ThermoElectroModels.jl index 91d23f3..9f575a6 100644 --- a/src/PhysicalModels/ThermoElectroModels.jl +++ b/src/PhysicalModels/ThermoElectroModels.jl @@ -1,5 +1,5 @@ -struct ThermoElectroModel{E} <: ThermoElectro +struct ThermoElectroModel{E<:Electro} <: ThermoElectro{E} electro::E law::ThermalLaw From bf90ec903bdc1516994a32260f8336d36a6e3040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Thu, 30 Apr 2026 17:01:17 +0200 Subject: [PATCH 03/22] fix overflow --- src/PhysicalModels/ThermoElectroModels.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhysicalModels/ThermoElectroModels.jl b/src/PhysicalModels/ThermoElectroModels.jl index 9f575a6..a0ce872 100644 --- a/src/PhysicalModels/ThermoElectroModels.jl +++ b/src/PhysicalModels/ThermoElectroModels.jl @@ -9,7 +9,7 @@ struct ThermoElectroModel{E<:Electro} <: ThermoElectro{E} end function (obj::ThermoElectroModel)() - Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂∂Ψem∂FF, ∂∂Ψem∂EF, ∂∂Ψem∂EE = obj() + Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂∂Ψem∂FF, ∂∂Ψem∂EF, ∂∂Ψem∂EE = obj.electro() f, df, ddf = law() Ψ(F, E, θ) = f(θ)*Ψem(F,E) From cf7a74814f3754cc585bcba9e75c133b905e627b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Thu, 30 Apr 2026 17:03:52 +0200 Subject: [PATCH 04/22] fixed missing obj --- src/PhysicalModels/ThermoElectroModels.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhysicalModels/ThermoElectroModels.jl b/src/PhysicalModels/ThermoElectroModels.jl index a0ce872..522be7b 100644 --- a/src/PhysicalModels/ThermoElectroModels.jl +++ b/src/PhysicalModels/ThermoElectroModels.jl @@ -10,7 +10,7 @@ end function (obj::ThermoElectroModel)() Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂∂Ψem∂FF, ∂∂Ψem∂EF, ∂∂Ψem∂EE = obj.electro() - f, df, ddf = law() + f, df, ddf = obj.law() Ψ(F, E, θ) = f(θ)*Ψem(F,E) ∂Ψ∂F(F, E, θ) = f(θ)*∂Ψem∂F(F,E) From cafdd84841ffc75a197972c34e02046e62346fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Thu, 30 Apr 2026 18:22:03 +0200 Subject: [PATCH 05/22] missing obj, added ctor --- src/PhysicalModels/ElectricalModels.jl | 20 +++++++++---------- .../ThermoElectroMechanicalModels.jl | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/PhysicalModels/ElectricalModels.jl b/src/PhysicalModels/ElectricalModels.jl index f4ab527..a133604 100644 --- a/src/PhysicalModels/ElectricalModels.jl +++ b/src/PhysicalModels/ElectricalModels.jl @@ -17,30 +17,30 @@ function (obj::Electro)() # Energy # HE(F, E) = H(F) * E HEHE(F, E) = HE(F, E) ⋅ HE(F, E) - Ψem(F, E) = (-elec.ε / (2.0 * J(F))) * HEHE(F, E) + Ψem(F, E) = (-obj.ε / (2.0 * J(F))) * HEHE(F, E) # First Derivatives # - ∂Ψem_∂H(F, E) = (-elec.ε / (J(F))) * (HE(F, E) ⊗ E) - ∂Ψem_∂J(F, E) = (+elec.ε / (2.0 * J(F)^2.0)) * HEHE(F, E) - ∂Ψem_∂E(F, E) = (-elec.ε / (J(F))) * (H(F)' * HE(F, E)) + ∂Ψem_∂H(F, E) = (-obj.ε / (J(F))) * (HE(F, E) ⊗ E) + ∂Ψem_∂J(F, E) = (+obj.ε / (2.0 * J(F)^2.0)) * HEHE(F, E) + ∂Ψem_∂E(F, E) = (-obj.ε / (J(F))) * (H(F)' * HE(F, E)) ∂Ψem∂F(F, E) = ∂Ψem_∂H(F, E) × F + ∂Ψem_∂J(F, E) * H(F) ∂Ψem∂E(F, E) = ∂Ψem_∂E(F, E) # Second Derivatives # - ∂Ψem_HH(F, E) = (-elec.ε / (J(F))) * (I3 ⊗₁₃²⁴ (E ⊗ E)) - ∂Ψem_HJ(F, E) = (+elec.ε / (J(F))^2.0) * (HE(F, E) ⊗ E) - ∂Ψem_JJ(F, E) = (-elec.ε / (J(F))^3.0) * HEHE(F, E) + ∂Ψem_HH(F, E) = (-obj.ε / (J(F))) * (I3 ⊗₁₃²⁴ (E ⊗ E)) + ∂Ψem_HJ(F, E) = (+obj.ε / (J(F))^2.0) * (HE(F, E) ⊗ E) + ∂Ψem_JJ(F, E) = (-obj.ε / (J(F))^3.0) * HEHE(F, E) ∂Ψem∂FF(F, E) = (F × (∂Ψem_HH(F, E) × F)) + H(F) ⊗₁₂³⁴ (∂Ψem_HJ(F, E) × F) + (∂Ψem_HJ(F, E) × F) ⊗₁₂³⁴ H(F) + ∂Ψem_JJ(F, E) * (H(F) ⊗₁₂³⁴ H(F)) + ×ᵢ⁴(∂Ψem_∂H(F, E) + ∂Ψem_∂J(F, E) * F) - ∂Ψem_EH(F, E) = (-elec.ε / (J(F))) * ((I3 ⊗₁₃² HE(F, E)) + (H(F)' ⊗₁₂³ E)) - ∂Ψem_EJ(F, E) = (+elec.ε / (J(F))^2.0) * (H(F)' * HE(F, E)) + ∂Ψem_EH(F, E) = (-obj.ε / (J(F))) * ((I3 ⊗₁₃² HE(F, E)) + (H(F)' ⊗₁₂³ E)) + ∂Ψem_EJ(F, E) = (+obj.ε / (J(F))^2.0) * (H(F)' * HE(F, E)) ∂Ψem∂EF(F, E) = (∂Ψem_EH(F, E) × F) + (∂Ψem_EJ(F, E) ⊗₁²³ H(F)) - ∂Ψem∂EE(F, E) = (-elec.ε / (J(F))) * (H(F)' * H(F)) + ∂Ψem∂EE(F, E) = (-obj.ε / (J(F))) * (H(F)' * H(F)) return (Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂Ψem∂EE) end diff --git a/src/PhysicalModels/ThermoElectroMechanicalModels.jl b/src/PhysicalModels/ThermoElectroMechanicalModels.jl index 1fff381..262d71d 100644 --- a/src/PhysicalModels/ThermoElectroMechanicalModels.jl +++ b/src/PhysicalModels/ThermoElectroMechanicalModels.jl @@ -134,6 +134,10 @@ function ThermoElectroMech_Bonet(thermo::ThermalVolumetric, electro::E, mechano: ThermoElectroMech_Bonet{E,M}(thermo,electro,mechano,el,vis,elec) end +function ThermoElectroMech_Bonet(thermo::ThermalVolumetric, electro::ThermoElectro, mechano::M; el::ThermalLaw, vis::ThermalLaw) where {M<:ViscoElastic} + ThermoElectroMech_Bonet{E,M}(thermo,electro.electro,mechano,el,vis,electro.law) +end + function (obj::ThermoElectroMech_Bonet{<:Electro,<:Elasto})() Ψt, ∂Ψt∂F, ∂Ψt∂θ, ∂∂Ψt∂FF, ∂∂Ψt∂θθ, ∂∂Ψt∂Fθ = obj.thermo() Ψm, ∂Ψm∂F, ∂∂Ψm∂FF = obj.mechano() From 0340de8782c3983891f06db44eb807663a2acaee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Mon, 4 May 2026 13:02:44 +0200 Subject: [PATCH 06/22] fixed model ctor --- src/PhysicalModels/ThermoElectroMechanicalModels.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhysicalModels/ThermoElectroMechanicalModels.jl b/src/PhysicalModels/ThermoElectroMechanicalModels.jl index 262d71d..c834e60 100644 --- a/src/PhysicalModels/ThermoElectroMechanicalModels.jl +++ b/src/PhysicalModels/ThermoElectroMechanicalModels.jl @@ -134,7 +134,7 @@ function ThermoElectroMech_Bonet(thermo::ThermalVolumetric, electro::E, mechano: ThermoElectroMech_Bonet{E,M}(thermo,electro,mechano,el,vis,elec) end -function ThermoElectroMech_Bonet(thermo::ThermalVolumetric, electro::ThermoElectro, mechano::M; el::ThermalLaw, vis::ThermalLaw) where {M<:ViscoElastic} +function ThermoElectroMech_Bonet(thermo::ThermalVolumetric, electro::ThermoElectro{E}, mechano::M; el::ThermalLaw, vis::ThermalLaw) where {E<:Electro,M<:ViscoElastic} ThermoElectroMech_Bonet{E,M}(thermo,electro.electro,mechano,el,vis,electro.law) end From f89c442890d9d3e13a0820865b32cee14618e5ae Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Wed, 6 May 2026 10:05:06 +0200 Subject: [PATCH 07/22] cleaner electro-mech --- src/PhysicalModels/ElectroMechanicalModels.jl | 145 +++++++----------- 1 file changed, 57 insertions(+), 88 deletions(-) diff --git a/src/PhysicalModels/ElectroMechanicalModels.jl b/src/PhysicalModels/ElectroMechanicalModels.jl index 930df47..4a76388 100644 --- a/src/PhysicalModels/ElectroMechanicalModels.jl +++ b/src/PhysicalModels/ElectroMechanicalModels.jl @@ -10,51 +10,62 @@ struct ElectroMechModel{E<:Electro,M<:Mechano} <: ElectroMechano{E,M} function ElectroMechModel(; electro::E, mechano::M) where {E<:Electro,M<:Mechano} new{E,M}(electro, mechano) end +end - function (obj::ElectroMechModel{<:Electro,<:IsoElastic})(Λ::Float64=1.0) - Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano() - Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano) - Ψ(F, E) = Ψm(F) + Ψem(F, E) - ∂Ψu(F, E) = ∂Ψm_u(F) + ∂Ψem_u(F, E) - ∂Ψφ(F, E) = ∂Ψem_φ(F, E) - ∂Ψuu(F, E) = ∂Ψm_uu(F) + ∂Ψem_uu(F, E) - ∂Ψφu(F, E) = ∂Ψem_φu(F, E) - ∂Ψφφ(F, E) = ∂Ψem_φφ(F, E) - return (Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ) - end - function (obj::ElectroMechModel{<:Electro,<:AnisoElastic})(Λ::Float64=1.0) - Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano() - Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano) - Ψ(F, E, N) = Ψm(F, N) + Ψem(F, E) - ∂Ψu(F, E, N) = ∂Ψm_u(F, N) + ∂Ψem_u(F, E) - ∂Ψφ(F, E, N) = ∂Ψem_φ(F, E) - ∂Ψuu(F, E, N) = ∂Ψm_uu(F, N) + ∂Ψem_uu(F, E) - ∂Ψφu(F, E, N) = ∂Ψem_φu(F, E) - ∂Ψφφ(F, E, N) = ∂Ψem_φφ(F, E) - return (Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ) - end - function (obj::ElectroMechModel{<:Electro,<:ViscoElastic{<:IsoElastic}})(Λ::Float64=1.0) - Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano() - Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano) - Ψ(F, E, Fn, A...) = Ψm(F, Fn, A...) + Ψem(F, E) - ∂Ψu(F, E, Fn, A...) = ∂Ψm_u(F, Fn, A...) + ∂Ψem_u(F, E) - ∂Ψφ(F, E, Fn, A...) = ∂Ψem_φ(F, E) - ∂Ψuu(F, E, Fn, A...) = ∂Ψm_uu(F, Fn, A...) + ∂Ψem_uu(F, E) - ∂Ψφu(F, E, Fn, A...) = ∂Ψem_φu(F, E) - ∂Ψφφ(F, E, Fn, A...) = ∂Ψem_φφ(F, E) - return (Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ) - end - function (obj::ElectroMechModel{<:Electro,<:ViscoElastic{<:AnisoElastic}})(Λ::Float64=1.0) - Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano() - Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano) - Ψ(F, E, n, Fn, A...) = Ψm(F, n, Fn, A...) + Ψem(F, E) - ∂Ψu(F, E, n, Fn, A...) = ∂Ψm_u(F, n, Fn, A...) + ∂Ψem_u(F, E) - ∂Ψφ(F, E, n, Fn, A...) = ∂Ψem_φ(F, E) - ∂Ψuu(F, E, n, Fn, A...) = ∂Ψm_uu(F, n, Fn, A...) + ∂Ψem_uu(F, E) - ∂Ψφu(F, E, n, Fn, A...) = ∂Ψem_φu(F, E) - ∂Ψφφ(F, E, n, Fn, A...) = ∂Ψem_φφ(F, E) - return (Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ) - end +function (+)(Model1::Electro, Model2::Mechano) + ElectroMechModel(Model1, Model2) +end + +function (+)(Model1::Mechano, Model2::Electro) + ElectroMechModel(Model2, Model1) +end + +function (obj::ElectroMechModel{<:Electro,<:IsoElastic})(Λ::Float64=1.0) + Ψm, ∂Ψm∂F, ∂Ψm∂FF = obj.mechano() + Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂Ψem∂EE = obj.electro() + Ψ(F, E) = Ψm(F) + Ψem(F, E) + ∂Ψ∂F(F, E) = ∂Ψm∂F(F) + ∂Ψem∂F(F, E) + ∂Ψ∂E(F, E) = ∂Ψem∂E(F, E) + ∂Ψ∂FF(F, E) = ∂Ψm∂FF(F) + ∂Ψem∂FF(F, E) + ∂Ψ∂EF(F, E) = ∂Ψem∂EF(F, E) + ∂Ψ∂EE(F, E) = ∂Ψem∂EE(F, E) + return (Ψ, ∂Ψ∂F, ∂Ψ∂E, ∂Ψ∂FF, ∂Ψ∂EF, ∂Ψ∂EE) +end + +function (obj::ElectroMechModel{<:Electro,<:AnisoElastic})(Λ::Float64=1.0) + Ψm, ∂Ψm∂F, ∂Ψm∂FF = obj.mechano() + Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂Ψem∂EE = obj.electro() + Ψ(F, E, N) = Ψm(F, N) + Ψem(F, E) + ∂Ψ∂F(F, E, N) = ∂Ψm∂F(F, N) + ∂Ψem∂F(F, E) + ∂Ψ∂E(F, E, N) = ∂Ψem∂E(F, E) + ∂Ψ∂FF(F, E, N) = ∂Ψm∂FF(F, N) + ∂Ψem∂FF(F, E) + ∂Ψ∂EF(F, E, N) = ∂Ψem∂EF(F, E) + ∂Ψ∂EE(F, E, N) = ∂Ψem∂EE(F, E) + return (Ψ, ∂Ψ∂F, ∂Ψ∂E, ∂Ψ∂FF, ∂Ψ∂EF, ∂Ψ∂EE) +end + +function (obj::ElectroMechModel{<:Electro,<:ViscoElastic{<:IsoElastic}})(Λ::Float64=1.0) + Ψm, ∂Ψm∂F, ∂Ψm∂FF = obj.mechano() + Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂Ψem∂EE = obj.electro() + Ψ(F, E, Fn, A...) = Ψm(F, Fn, A...) + Ψem(F, E) + ∂Ψ∂F(F, E, Fn, A...) = ∂Ψm∂F(F, Fn, A...) + ∂Ψem∂F(F, E) + ∂Ψ∂E(F, E, Fn, A...) = ∂Ψem∂E(F, E) + ∂Ψ∂FF(F, E, Fn, A...) = ∂Ψm∂FF(F, Fn, A...) + ∂Ψem∂FF(F, E) + ∂Ψ∂EF(F, E, Fn, A...) = ∂Ψem∂EF(F, E) + ∂Ψ∂EE(F, E, Fn, A...) = ∂Ψem∂EE(F, E) + return (Ψ, ∂Ψ∂F, ∂Ψ∂E, ∂Ψ∂FF, ∂Ψ∂EF, ∂Ψ∂EE) +end + +function (obj::ElectroMechModel{<:Electro,<:ViscoElastic{<:AnisoElastic}})(Λ::Float64=1.0) + Ψm, ∂Ψm∂F, ∂Ψm∂FF = obj.mechano() + Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂Ψem∂EE = obj.electro() + Ψ(F, E, n, Fn, A...) = Ψm(F, n, Fn, A...) + Ψem(F, E) + ∂Ψ∂F(F, E, n, Fn, A...) = ∂Ψm∂F(F, n, Fn, A...) + ∂Ψem∂F(F, E) + ∂Ψ∂E(F, E, n, Fn, A...) = ∂Ψem∂E(F, E) + ∂Ψ∂FF(F, E, n, Fn, A...) = ∂Ψm∂FF(F, n, Fn, A...) + ∂Ψem∂FF(F, E) + ∂Ψ∂EF(F, E, n, Fn, A...) = ∂Ψem∂EF(F, E) + ∂Ψ∂EE(F, E, n, Fn, A...) = ∂Ψem∂EE(F, E) + return (Ψ, ∂Ψ∂F, ∂Ψ∂E, ∂Ψ∂FF, ∂Ψ∂EF, ∂Ψ∂EE) end function update_time_step!(obj::ElectroMechModel, Δt::Float64) @@ -75,48 +86,6 @@ function Dissipation(obj::ElectroMechModel) D(F, E, X...) = Dvis(F, X...) end - -function _getCoupling(elec::Electro, mec::Mechano, Λ::Float64=0.0) - J(F) = det(F) - H(F) = det(F) * inv(F)' - # Energy # - HE(F, E) = H(F) * E - HEHE(F, E) = HE(F, E) ⋅ HE(F, E) - Ψem(F, E) = (-elec.ε / (2.0 * J(F))) * HEHE(F, E) - # First Derivatives # - ∂Ψem_∂H(F, E) = (-elec.ε / (J(F))) * (HE(F, E) ⊗ E) - ∂Ψem_∂J(F, E) = (+elec.ε / (2.0 * J(F)^2.0)) * HEHE(F, E) - ∂Ψem_∂E(F, E) = (-elec.ε / (J(F))) * (H(F)' * HE(F, E)) - ∂Ψem_u(F, E) = ∂Ψem_∂H(F, E) × F + ∂Ψem_∂J(F, E) * H(F) - ∂Ψem_φ(F, E) = ∂Ψem_∂E(F, E) - - # Second Derivatives # - ∂Ψem_HH(F, E) = (-elec.ε / (J(F))) * (I3 ⊗₁₃²⁴ (E ⊗ E)) - ∂Ψem_HJ(F, E) = (+elec.ε / (J(F))^2.0) * (HE(F, E) ⊗ E) - ∂Ψem_JJ(F, E) = (-elec.ε / (J(F))^3.0) * HEHE(F, E) - ∂Ψem_uu(F, E) = (F × (∂Ψem_HH(F, E) × F)) + - H(F) ⊗₁₂³⁴ (∂Ψem_HJ(F, E) × F) + - (∂Ψem_HJ(F, E) × F) ⊗₁₂³⁴ H(F) + - ∂Ψem_JJ(F, E) * (H(F) ⊗₁₂³⁴ H(F)) + - ×ᵢ⁴(∂Ψem_∂H(F, E) + ∂Ψem_∂J(F, E) * F) - - ∂Ψem_EH(F, E) = (-elec.ε / (J(F))) * ((I3 ⊗₁₃² HE(F, E)) + (H(F)' ⊗₁₂³ E)) - ∂Ψem_EJ(F, E) = (+elec.ε / (J(F))^2.0) * (H(F)' * HE(F, E)) - ∂Ψem_φu(F, E) = (∂Ψem_EH(F, E) × F) + (∂Ψem_EJ(F, E) ⊗₁²³ H(F)) - - ∂Ψem_φφ(F, E) = (-elec.ε / (J(F))) * (H(F)' * H(F)) - - return (Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ) -end - - -function (+)(Model1::Electro, Model2::Mechano) - ElectroMechModel(Model1, Model2) -end -function (+)(Model1::Mechano, Model2::Electro) - ElectroMechModel(Model2, Model1) -end - struct FlexoElectroModel{EM<:ElectroMechano} <: FlexoElectro{EM} electromechano::EM κ::Float64 @@ -141,7 +110,7 @@ struct FlexoElectroModel{EM<:ElectroMechano} <: FlexoElectro{EM} f3(δϕ) = δϕ ⊗₁² e₃ Φ(ϕ₁, ϕ₂, ϕ₃) = (f1 ∘ (ϕ₁) + f2 ∘ (ϕ₂) + f3 ∘ (ϕ₃)) - Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ = obj.electromechano(Λ) - return Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ, Φ + Ψ, ∂Ψ∂F, ∂Ψ∂E, ∂Ψ∂FF, ∂Ψ∂EF, ∂Ψ∂EE = obj.electromechano(Λ) + return Ψ, ∂Ψ∂F, ∂Ψ∂E, ∂Ψ∂FF, ∂Ψ∂EF, ∂Ψ∂EE, Φ end end From 24d544dde22f902a67caf31b881973777ea7d73e Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Wed, 6 May 2026 10:26:16 +0200 Subject: [PATCH 08/22] removed old get coupling --- src/PhysicalModels/ThermoElectroMechanicalModels.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhysicalModels/ThermoElectroMechanicalModels.jl b/src/PhysicalModels/ThermoElectroMechanicalModels.jl index c834e60..613cd3a 100644 --- a/src/PhysicalModels/ThermoElectroMechanicalModels.jl +++ b/src/PhysicalModels/ThermoElectroMechanicalModels.jl @@ -31,7 +31,7 @@ struct ThermoElectroMechModel{T<:Thermo,E<:Electro,M<:Mechano} <: ThermoElectroM function (obj::ThermoElectroMechModel)(Λ::Float64=1.0) Ψt, ∂Ψt_θ, ∂Ψt_θθ = obj.thermo(Λ) Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano(Λ) - Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano, Λ) + Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = obj.electro() Ψtm, ∂Ψtm_u, ∂Ψtm_θ, ∂Ψtm_uu, ∂Ψtm_uθ, ∂Ψtm_θθ = _getCoupling(obj.thermo, obj.mechano, Λ) f(δθ) = (obj.fθ(δθ)::Float64) df(δθ) = (obj.dfdθ(δθ)::Float64) @@ -73,7 +73,7 @@ struct ThermoElectroMech_Govindjee{T<:Thermo,E<:Electro,M<:Mechano} <: ThermoEle function (obj::ThermoElectroMech_Govindjee)(Λ::Float64=1.0) Ψm, _, _ = obj.mechano(Λ) - Ψem, _, _, _, _, _ = _getCoupling(obj.electro, obj.mechano, Λ) + Ψem, _, _, _, _, _ = obj.electro() f(δθ) = obj.fθ(δθ) df(δθ) = obj.dfdθ(δθ) g(δθ) = obj.gθ(δθ) @@ -141,7 +141,7 @@ end function (obj::ThermoElectroMech_Bonet{<:Electro,<:Elasto})() Ψt, ∂Ψt∂F, ∂Ψt∂θ, ∂∂Ψt∂FF, ∂∂Ψt∂θθ, ∂∂Ψt∂Fθ = obj.thermo() Ψm, ∂Ψm∂F, ∂∂Ψm∂FF = obj.mechano() - Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂∂Ψem∂EE = _getCoupling(obj.electro, obj.mechano) + Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂∂Ψem∂EE = obj.electro() fe, dfe, ddfe = obj.lawel() felec, dfelec, ddfelec = obj.lawelec() @@ -163,7 +163,7 @@ function (obj::ThermoElectroMech_Bonet{<:Electro,<:ViscoElastic})() Ψt, ∂Ψt∂F, ∂Ψt∂θ, ∂∂Ψt∂FF, ∂∂Ψt∂θθ, ∂∂Ψt∂Fθ = obj.thermo() Ψe, ∂Ψe∂F, ∂∂Ψe∂FF = obj.mechano.longterm() Ψv, ∂Ψv∂F, ∂∂Ψv∂FF = obj.mechano.branches() - Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂∂Ψem∂EE = _getCoupling(obj.electro, obj.mechano) + Ψem, ∂Ψem∂F, ∂Ψem∂E, ∂Ψem∂FF, ∂Ψem∂EF, ∂∂Ψem∂EE = obj.electro() fe, dfe, ddfe = obj.lawel() fv, dfv, ddfv = obj.lawvis() felec, dfelec, ddfelec = obj.lawelec() From 2ea565f1aa045862c7eacb693180ff941a2c5464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Thu, 7 May 2026 20:02:45 +0200 Subject: [PATCH 09/22] Updated polynomial law --- src/Exports.jl | 1 - src/PhysicalModels/ThermalModels.jl | 17 +---------------- test/TestConstitutiveModels/ThermalLawsTests.jl | 4 ++-- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/Exports.jl b/src/Exports.jl index c9276cd..4137fe9 100644 --- a/src/Exports.jl +++ b/src/Exports.jl @@ -98,7 +98,6 @@ end @publish PhysicalModels EntropicElasticityLaw @publish PhysicalModels NonlinearMeltingLaw @publish PhysicalModels NonlinearSofteningLaw -@publish PhysicalModels TrigonometricLaw @publish PhysicalModels PolynomialLaw @publish PhysicalModels SecondPiola diff --git a/src/PhysicalModels/ThermalModels.jl b/src/PhysicalModels/ThermalModels.jl index 0a005ac..c796289 100644 --- a/src/PhysicalModels/ThermalModels.jl +++ b/src/PhysicalModels/ThermalModels.jl @@ -72,27 +72,12 @@ function (law::NonlinearSofteningLaw)() return (f, ∂f, ∂∂f) end -struct TrigonometricLaw <: ThermalLaw - θr::Float64 - θM::Float64 -end - -function (law::TrigonometricLaw)() - @unpack θr, θM = law - g(θ) = θ/θr * sin(2π*θ/θM) - G(θ) = 1/2/π * θM/θr * (1 - cos(2π*θ/θM)) - H(θ) = 1/2/π * θM/θr * (θ - θM/2/π * sin(2π*θ/θM)) - f(θ) = (H(θr) - H(θ)) / (H(θM) - H(θr)) + 1.0 - ∂f(θ) = -G(θ) / (H(θM) - H(θr)) - ∂∂f(θ) = -g(θ) / θ / (H(θM) - H(θr)) - return (f, ∂f, ∂∂f) -end - struct PolynomialLaw <: ThermalLaw θr::Float64 a::Float64 b::Float64 c::Float64 + PolynomialLaw(; θr, a, b, c) = new(θr, a, b, c) end function (law::PolynomialLaw)() diff --git a/test/TestConstitutiveModels/ThermalLawsTests.jl b/test/TestConstitutiveModels/ThermalLawsTests.jl index 5fc74c9..faa6dad 100644 --- a/test/TestConstitutiveModels/ThermalLawsTests.jl +++ b/test/TestConstitutiveModels/ThermalLawsTests.jl @@ -29,8 +29,8 @@ end end end -@testset "TrigonometricLaw" begin - law = TrigonometricLaw(273.15, 400.0) +@testset "PolynomialLaw" begin + law = PolynomialLaw(θr=273.15, a=1.1, b=2.2, c=3.3) f, df, ddf = law() for θ ∈ 200.0:50:400 @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-10) From 2bb77becd308d197368124f965f76dd962e62788 Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Mon, 11 May 2026 12:32:24 +0200 Subject: [PATCH 10/22] rename internal variable --- src/PhysicalModels/ThermalModels.jl | 12 ++++++------ test/TestConstitutiveModels/ThermalLawsTests.jl | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/PhysicalModels/ThermalModels.jl b/src/PhysicalModels/ThermalModels.jl index c796289..7627ba8 100644 --- a/src/PhysicalModels/ThermalModels.jl +++ b/src/PhysicalModels/ThermalModels.jl @@ -56,19 +56,19 @@ end struct NonlinearSofteningLaw <: ThermalLaw θr::Float64 - θt::Float64 + θT::Float64 γ::Float64 δ::Float64 - NonlinearSofteningLaw(; θr, θt, γ, δ=0) = new(θr, θt, γ, δ) + NonlinearSofteningLaw(; θr, θT, γ, δ=0) = new(θr, θT, γ, δ) end function (law::NonlinearSofteningLaw)() - @unpack θr, θt, γ, δ = law - u(θ) = exp(-(θ/θt)^(γ+1)) + @unpack θr, θT, γ, δ = law + u(θ) = exp(-(θ/θT)^(γ+1)) C = (1-δ) * u(θr) + δ f(θ) = ((1-δ) * u(θ) + δ) / C - ∂f(θ) = -(1-δ)/C * (γ+1)/θt * (θ/θt)^γ * u(θ) - ∂∂f(θ) = (1-δ)/C * (γ+1)/θ^2 * (θ/θt)^(γ+1) * ((γ+1)*(θ/θt)^(γ+1)-γ) * u(θ) + ∂f(θ) = -(1-δ)/C * (γ+1)/θT * (θ/θT)^γ * u(θ) + ∂∂f(θ) = (1-δ)/C * (γ+1)/θ^2 * (θ/θT)^(γ+1) * ((γ+1)*(θ/θT)^(γ+1)-γ) * u(θ) return (f, ∂f, ∂∂f) end diff --git a/test/TestConstitutiveModels/ThermalLawsTests.jl b/test/TestConstitutiveModels/ThermalLawsTests.jl index faa6dad..31a0172 100644 --- a/test/TestConstitutiveModels/ThermalLawsTests.jl +++ b/test/TestConstitutiveModels/ThermalLawsTests.jl @@ -21,7 +21,7 @@ end end @testset "NonlinearSofteningLaw" begin - law = NonlinearSofteningLaw(θr=273.15, θt=300.0, γ=2.0, δ=0.5) + law = NonlinearSofteningLaw(θr=273.15, θT=300.0, γ=2.0, δ=0.5) f, df, ddf = law() for θ ∈ 200.0:50:400 @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-10) From faf9e5971ba923f49cae0dae2ffe446297bd7bb6 Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Mon, 11 May 2026 16:36:23 +0200 Subject: [PATCH 11/22] added thermal deviatoric --- src/Exports.jl | 1 + src/PhysicalModels/PhysicalModels.jl | 1 + src/PhysicalModels/ThermoMechanicalModels.jl | 22 ++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/Exports.jl b/src/Exports.jl index 4137fe9..220d57f 100644 --- a/src/Exports.jl +++ b/src/Exports.jl @@ -49,6 +49,7 @@ end @publish PhysicalModels TransverseIsotropy2D @publish PhysicalModels ThermalModel @publish PhysicalModels ThermalVolumetric +@publish PhysicalModels ThermalDeviatoric @publish PhysicalModels IdealDielectric @publish PhysicalModels Magnetic @publish PhysicalModels IdealMagnetic diff --git a/src/PhysicalModels/PhysicalModels.jl b/src/PhysicalModels/PhysicalModels.jl index 4015465..b284eeb 100644 --- a/src/PhysicalModels/PhysicalModels.jl +++ b/src/PhysicalModels/PhysicalModels.jl @@ -47,6 +47,7 @@ export HardMagnetic export HardMagnetic2D export ThermalModel export ThermalVolumetric +export ThermalDeviatoric export ElectroMechModel export ThermoElectroMechModel export ThermoMechModel diff --git a/src/PhysicalModels/ThermoMechanicalModels.jl b/src/PhysicalModels/ThermoMechanicalModels.jl index 5ad7af1..f626401 100644 --- a/src/PhysicalModels/ThermoMechanicalModels.jl +++ b/src/PhysicalModels/ThermoMechanicalModels.jl @@ -64,6 +64,28 @@ function (obj::ThermalVolumetric)() end +struct ThermalDeviatoric{M<:Mechano} <: ThermoMechano{Nothing,M} + mechano::M + law::ThermalLaw + + function ThermalDeviatoric(mechano::M, law::ThermalLaw) where {M<:Mechano} + new{M}(mechano, law) + end +end + +function (obj::ThermalDeviatoric{<:IsoElastic})() + Ψm, ∂Ψm∂F, ∂∂Ψm∂FF = obj.mechano() + f, df, ddf = obj.law() + Ψ(F,θ) = Ψm(F) * f(θ) + ∂Ψ∂F(F,θ) = ∂Ψm∂F(F) * f(θ) + ∂∂Ψ∂FF(F,θ) = ∂∂Ψm∂FF(F) * f(θ) + ∂Ψ∂θ(F,θ) = Ψm(F) * df(θ) + ∂∂Ψ∂θθ(F,θ) = Ψm(F) * ddf(θ) + ∂∂Ψ∂Fθ(F,θ) = ∂Ψm∂F(F) * df(θ) + return (Ψ, ∂Ψ∂F, ∂Ψ∂θ, ∂∂Ψ∂FF, ∂∂Ψ∂θθ, ∂∂Ψ∂Fθ) +end + + struct ThermoMechModel{T<:Thermo,M<:Mechano} <: ThermoMechano{T,M} thermo::T mechano::M From 3b1212c4a0e9918941c95a93b8877132b99ba032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 12 May 2026 18:58:03 +0200 Subject: [PATCH 12/22] fix dielectric energy definition --- src/PhysicalModels/ElectricalModels.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhysicalModels/ElectricalModels.jl b/src/PhysicalModels/ElectricalModels.jl index a133604..cc203de 100644 --- a/src/PhysicalModels/ElectricalModels.jl +++ b/src/PhysicalModels/ElectricalModels.jl @@ -10,7 +10,7 @@ struct IdealDielectric <: Electro end end -function (obj::Electro)() +function (obj::IdealDielectric)() J(F) = det(F) H(F) = det(F) * inv(F)' From ea0b43dd2782f1cadf9fc9c42bd4395417118b63 Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Wed, 13 May 2026 10:14:08 +0200 Subject: [PATCH 13/22] added constant laws --- src/PhysicalModels/ThermalModels.jl | 22 +++++++++++++++++++ .../ThermalLawsTests.jl | 18 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/PhysicalModels/ThermalModels.jl b/src/PhysicalModels/ThermalModels.jl index 7627ba8..b310bfc 100644 --- a/src/PhysicalModels/ThermalModels.jl +++ b/src/PhysicalModels/ThermalModels.jl @@ -25,6 +25,28 @@ end # Thermal laws # =================== +struct ConstantEnergyLaw <: ThermalLaw end + +function (law::ConstantEnergyLaw)() + f(θ) = 1.0 + ∂f(θ) = 0.0 + ∂∂f(θ) = 0.0 + return (f, ∂f, ∂∂f) +end + +struct ConstantCvLaw <: ThermalLaw + θr::Float64 + ConstantCvLaw(θr) = new(θr) + ConstantCvLaw(; θr) = new(θr) +end + +function (law::ConstantCvLaw)() + f(θ) = (θ-θr) -θ*log(θ/θr) + ∂f(θ) = -log(θ/θr) + ∂∂f(θ) = -1/θ + return (f, ∂f, ∂∂f) +end + struct EntropicElasticityLaw <: ThermalLaw θr::Float64 γ::Float64 diff --git a/test/TestConstitutiveModels/ThermalLawsTests.jl b/test/TestConstitutiveModels/ThermalLawsTests.jl index 31a0172..555584f 100644 --- a/test/TestConstitutiveModels/ThermalLawsTests.jl +++ b/test/TestConstitutiveModels/ThermalLawsTests.jl @@ -2,6 +2,24 @@ using ForwardDiff using HyperFEM using Test +@testset "ConstantEnergyLaw" begin + law = ConstantEnergyLaw() + f, df, ddf = law() + for θ ∈ 200.0:50:400 + @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-3) + @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) + end +end + +@testset "ConstantCvLaw" begin + law = ConstantCvLaw(θr=273.15) + f, df, ddf = law() + for θ ∈ 200.0:50:400 + @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-3) + @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) + end +end + @testset "EntropicElasticityLaw" begin law = EntropicElasticityLaw(θr=273.15, γ=0.55) f, df, ddf = law() From 07847975d9638194c0e84d23d8f229d66576e250 Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Thu, 14 May 2026 17:56:09 +0200 Subject: [PATCH 14/22] CellState: Allowed initial value, deprecated initialize_state --- src/Exports.jl | 1 - src/PhysicalModels/ElectroMechanicalModels.jl | 7 ++++- src/PhysicalModels/PhysicalModels.jl | 12 ++++----- .../ThermoElectroMechanicalModels.jl | 7 ++++- src/PhysicalModels/ThermoMechanicalModels.jl | 7 ++++- src/PhysicalModels/ViscousModels.jl | 27 ++++++++++++++++--- test/data/StaggeredViscoElectricSimulation.jl | 2 +- test/data/ViscoElasticSimulation.jl | 2 +- 8 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/Exports.jl b/src/Exports.jl index 220d57f..2d0845b 100644 --- a/src/Exports.jl +++ b/src/Exports.jl @@ -24,7 +24,6 @@ end @publish TensorAlgebra Tensorize -@publish PhysicalModels DerivativeStrategy @publish PhysicalModels LinearElasticity3D @publish PhysicalModels LinearElasticity2D @publish PhysicalModels Yeoh3D diff --git a/src/PhysicalModels/ElectroMechanicalModels.jl b/src/PhysicalModels/ElectroMechanicalModels.jl index 4a76388..f51a592 100644 --- a/src/PhysicalModels/ElectroMechanicalModels.jl +++ b/src/PhysicalModels/ElectroMechanicalModels.jl @@ -73,8 +73,13 @@ function update_time_step!(obj::ElectroMechModel, Δt::Float64) update_time_step!(obj.mechano, Δt) end +function CellState(obj::ElectroMechModel, args...) + CellState(obj.mechano, args...) +end + function initialize_state(obj::ElectroMechModel, points::Measure) - initialize_state(obj.mechano, points) + @warn "The function 'initialize_state' is deprecated, use 'CellState' instead." + CellState(obj.mechano, points) end function update_state!(obj::ElectroMechModel, state, F, E, args...) diff --git a/src/PhysicalModels/PhysicalModels.jl b/src/PhysicalModels/PhysicalModels.jl index b284eeb..d992db9 100644 --- a/src/PhysicalModels/PhysicalModels.jl +++ b/src/PhysicalModels/PhysicalModels.jl @@ -13,7 +13,7 @@ using ..TensorAlgebra: _∂H∂F_2D using ..TensorAlgebra: trAA import Base: + -import Gridap: update_state! +import Gridap: CellState, update_state! export Yeoh3D export Gent2D @@ -83,8 +83,6 @@ export EnergyInterpolationScheme export SecondPiola export Dissipation -export DerivativeStrategy - export initialize_state export update_time_step! @@ -99,8 +97,6 @@ export getIsoInvariants export HessianRegularization export Hessian∇JRegularization -struct DerivativeStrategy{Kind} end - abstract type PhysicalModel end abstract type Mechano <: PhysicalModel end abstract type Electro <: PhysicalModel end @@ -159,13 +155,17 @@ Base.broadcastable(m::PhysicalModel) = Ref(m) # Allows to use the @. syntax for """ Initialize the state variables for the given constitutive model and discretization. """ +function CellState(::PhysicalModel, args...) + return nothing +end + function initialize_state(::PhysicalModel, points::Measure) return nothing end """ -Update the state variables. The state variables must be initialized using the function 'initialize_state'. +Update the state variables. The state variables must be initialized using the function 'CellState' with the constitutive model. """ function update_state!(::PhysicalModel, vars...) end diff --git a/src/PhysicalModels/ThermoElectroMechanicalModels.jl b/src/PhysicalModels/ThermoElectroMechanicalModels.jl index 613cd3a..e8c76b9 100644 --- a/src/PhysicalModels/ThermoElectroMechanicalModels.jl +++ b/src/PhysicalModels/ThermoElectroMechanicalModels.jl @@ -1,6 +1,11 @@ +function CellState(obj::ThermoElectroMechano, args...) + CellState(obj.mechano, args...) +end + function initialize_state(obj::ThermoElectroMechano, points::Measure) - initialize_state(obj.mechano, points) + @warn "The function 'initialize_state' is deprecated, use 'CellState' instead." + CellState(obj.mechano, points) end function update_state!(obj::ThermoElectroMechano, state, F, E, θ, args...) diff --git a/src/PhysicalModels/ThermoMechanicalModels.jl b/src/PhysicalModels/ThermoMechanicalModels.jl index f626401..8b25172 100644 --- a/src/PhysicalModels/ThermoMechanicalModels.jl +++ b/src/PhysicalModels/ThermoMechanicalModels.jl @@ -3,8 +3,13 @@ # Common functions # =================== +function CellState(obj::ThermoMechano, args...) + CellState(obj.mechano, args...) +end + function initialize_state(obj::TM, points::Measure) where {TM<:ThermoMechano} - initialize_state(obj.mechano, points) + @warn "The function 'initialize_state' is deprecated, use 'CellState' instead." + CellState(obj.mechano, points) end function update_state!(obj::TM, state, F, θ, args...) where {TM<:ThermoMechano} diff --git a/src/PhysicalModels/ViscousModels.jl b/src/PhysicalModels/ViscousModels.jl index 4113aa9..649384e 100644 --- a/src/PhysicalModels/ViscousModels.jl +++ b/src/PhysicalModels/ViscousModels.jl @@ -26,11 +26,20 @@ function update_time_step!(obj::ViscousIncompressible, Δt::Float64) obj.Δt[] = Δt end -function initialize_state(::ViscousIncompressible, points::Measure) - v = VectorValue(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0) +function CellState(::ViscousIncompressible, F0::TensorValue, points::Measure) + v = VectorValue(F0..., 0.0) CellState(v, points) end +function CellState(obj::ViscousIncompressible, points::Measure) + CellState(obj, I3, points) +end + +function initialize_state(obj::ViscousIncompressible, points::Measure) + @warn "The function 'initialize_state' is deprecated, use 'CellState' instead." + CellState(obj, points) +end + function update_state!(obj::ViscousIncompressible, state, F, Fn) _, Se, ∂Se∂Ce = SecondPiola(obj.elasto) return_mapping(A, F, Fn) = ReturnMapping(obj, Se, ∂Se∂Ce, F, Fn, A) @@ -79,8 +88,13 @@ function update_time_step!(obj::NVisco, Δt::Float64) Δt end +function CellState(obj::NVisco, args...) + map(b -> CellState(b, args...), obj) +end + function initialize_state(obj::NVisco, points::Measure) - map(b -> initialize_state(b, points), obj) + @warn "The function 'initialize_state' is deprecated, use 'CellState' instead." + map(b -> CellState(b, points), obj) end function update_state!(obj::NVisco, states, F, Fn) @@ -125,8 +139,13 @@ function update_time_step!(obj::GeneralizedMaxwell, Δt::Float64) update_time_step!(obj.branches, Δt) end +function CellState(obj::GeneralizedMaxwell, args...) + CellState(obj.branches, args...) +end + function initialize_state(obj::GeneralizedMaxwell, points::Measure) - initialize_state(obj.branches, points) + @warn "The function 'initialize_state' is deprecated, use 'CellState' instead." + CellState(obj.branches, points) end function update_state!(obj::GeneralizedMaxwell{<:IsoElastic}, states, F, Fn) diff --git a/test/data/StaggeredViscoElectricSimulation.jl b/test/data/StaggeredViscoElectricSimulation.jl index fb3abbf..7d8a099 100644 --- a/test/data/StaggeredViscoElectricSimulation.jl +++ b/test/data/StaggeredViscoElectricSimulation.jl @@ -80,7 +80,7 @@ function staggered_visco_electric_simulation(; t_end=2, writevtk=true, verbose=t Fh = F∘∇(uh⁺)' Fh⁻ = F∘∇(uh⁻)' - A = initialize_state(cons_model, dΩ) + A = CellState(cons_model, dΩ) # Electrical staggered step res_elec(Λ) = (φ, vφ) -> residual(cons_model, Electro, (ku, ke), (uh⁺, φ), vφ, dΩ, 0.0, Fh⁻, A...) diff --git a/test/data/ViscoElasticSimulation.jl b/test/data/ViscoElasticSimulation.jl index 8c38bdf..96b519f 100644 --- a/test/data/ViscoElasticSimulation.jl +++ b/test/data/ViscoElasticSimulation.jl @@ -66,7 +66,7 @@ function visco_elastic_simulation(;t_end=15, writevtk=true, verbose=true) uh = FEFunction(Uu, zero_free_values(Uu)) unh = FEFunction(Uun, zero_free_values(Uun)) - state_vars = initialize_state(cons_model, dΩ) + state_vars = CellState(cons_model, dΩ) F,_,_ = get_Kinematics(k) Fnh = F∘∇(unh)' From 8ba74c3e08c34acd3c5df68431400ea54c953ffd Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Thu, 14 May 2026 18:32:32 +0200 Subject: [PATCH 15/22] missing export thermal laws --- src/Exports.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Exports.jl b/src/Exports.jl index 2d0845b..e3e6338 100644 --- a/src/Exports.jl +++ b/src/Exports.jl @@ -95,6 +95,8 @@ end @publish PhysicalModels getIsoInvariants @publish PhysicalModels ThermalLaw +@publish PhysicalModels ConstantEnergyLaw +@publish PhysicalModels ConstantCvLaw @publish PhysicalModels EntropicElasticityLaw @publish PhysicalModels NonlinearMeltingLaw @publish PhysicalModels NonlinearSofteningLaw From 71e28af5cb9462ff759b53b720637a9e3059805a Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Fri, 15 May 2026 09:08:43 +0200 Subject: [PATCH 16/22] missing unpack field --- src/PhysicalModels/ThermalModels.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PhysicalModels/ThermalModels.jl b/src/PhysicalModels/ThermalModels.jl index b310bfc..8abf887 100644 --- a/src/PhysicalModels/ThermalModels.jl +++ b/src/PhysicalModels/ThermalModels.jl @@ -41,6 +41,7 @@ struct ConstantCvLaw <: ThermalLaw end function (law::ConstantCvLaw)() + θr = law.θr f(θ) = (θ-θr) -θ*log(θ/θr) ∂f(θ) = -log(θ/θr) ∂∂f(θ) = -1/θ From c01fe726500516174a61ab225dadce9f10ac008f Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Fri, 15 May 2026 09:13:24 +0200 Subject: [PATCH 17/22] adjust tolerances --- .../ThermalLawsTests.jl | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/TestConstitutiveModels/ThermalLawsTests.jl b/test/TestConstitutiveModels/ThermalLawsTests.jl index 555584f..e5877c3 100644 --- a/test/TestConstitutiveModels/ThermalLawsTests.jl +++ b/test/TestConstitutiveModels/ThermalLawsTests.jl @@ -6,8 +6,8 @@ using Test law = ConstantEnergyLaw() f, df, ddf = law() for θ ∈ 200.0:50:400 - @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-3) - @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) + @test df(θ) ≈ ForwardDiff.derivative(f, θ) + @test ddf(θ) ≈ ForwardDiff.derivative(df, θ) end end @@ -15,8 +15,8 @@ end law = ConstantCvLaw(θr=273.15) f, df, ddf = law() for θ ∈ 200.0:50:400 - @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-3) - @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) + @test df(θ) ≈ ForwardDiff.derivative(f, θ) + @test ddf(θ) ≈ ForwardDiff.derivative(df, θ) end end @@ -24,8 +24,8 @@ end law = EntropicElasticityLaw(θr=273.15, γ=0.55) f, df, ddf = law() for θ ∈ 200.0:50:400 - @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-3) - @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) + @test df(θ) ≈ ForwardDiff.derivative(f, θ) + @test ddf(θ) ≈ ForwardDiff.derivative(df, θ) end end @@ -33,8 +33,8 @@ end law = NonlinearMeltingLaw(θr=273.15, θM=400.0, γ=0.55) f, df, ddf = law() for θ ∈ 200.0:50:400 - @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-10) - @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) + @test df(θ) ≈ ForwardDiff.derivative(f, θ) + @test ddf(θ) ≈ ForwardDiff.derivative(df, θ) end end @@ -42,8 +42,8 @@ end law = NonlinearSofteningLaw(θr=273.15, θT=300.0, γ=2.0, δ=0.5) f, df, ddf = law() for θ ∈ 200.0:50:400 - @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-10) - @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) + @test df(θ) ≈ ForwardDiff.derivative(f, θ) + @test ddf(θ) ≈ ForwardDiff.derivative(df, θ) end end @@ -51,7 +51,7 @@ end law = PolynomialLaw(θr=273.15, a=1.1, b=2.2, c=3.3) f, df, ddf = law() for θ ∈ 200.0:50:400 - @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-10) - @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) + @test df(θ) ≈ ForwardDiff.derivative(f, θ) + @test ddf(θ) ≈ ForwardDiff.derivative(df, θ) end end From b8ace666b4f0067acdf12a6d9629dc160e022607 Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Mon, 18 May 2026 12:36:42 +0200 Subject: [PATCH 18/22] added IdealDielectric test --- .../ElectroMechanicalTests.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/TestConstitutiveModels/ElectroMechanicalTests.jl b/test/TestConstitutiveModels/ElectroMechanicalTests.jl index ed703f3..815e467 100644 --- a/test/TestConstitutiveModels/ElectroMechanicalTests.jl +++ b/test/TestConstitutiveModels/ElectroMechanicalTests.jl @@ -1,6 +1,7 @@ using Gridap.TensorValues using HyperFEM.PhysicalModels using HyperFEM.TensorAlgebra +using ForwardDiff const ∇φ = VectorValue(1.0:3.0...) @@ -8,6 +9,20 @@ const ∇u = TensorValue(1.0:9.0...) * 1e-3 const ∇un = TensorValue(1.0:9.0...) * 5e-4 +@testset "IdealDielectric" begin + model = IdealDielectric(ε=4.0*8.85e-12) + Ψ, ∂Ψ∂F, ∂Ψ∂E, ∂Ψ∂FF, ∂Ψ∂EF, ∂Ψ∂EE = model() + E0 = VectorValue(rand(3)) * 6000 / 0.001 + F1 = I3 + 0.1*TensorValue(rand(9)...) + @test get_array(∂Ψ∂F(F1,E0)) ≈ ForwardDiff.gradient(Fi -> Ψ(Fi, get_array(E0)), get_array(F1)) + @test get_array(∂Ψ∂E(F1,E0)) ≈ ForwardDiff.gradient(Ei -> Ψ(get_array(F1), Ei), get_array(E0)) + @test get_array(∂Ψ∂FF(F1,E0)) ≈ ForwardDiff.jacobian(Fi -> ∂Ψ∂F(Fi, get_array(E0)), get_array(F1)) + @test get_array(∂Ψ∂EF(F1,E0)) ≈ ForwardDiff.jacobian(Fi -> ∂Ψ∂E(Fi, get_array(E0)), get_array(F1)) + @test get_array(∂Ψ∂EF(F1,E0)) ≈ ForwardDiff.jacobian(Ei -> ∂Ψ∂F(get_array(F1), Ei), get_array(E0))' + @test get_array(∂Ψ∂EE(F1,E0)) ≈ ForwardDiff.jacobian(Ei -> ∂Ψ∂E(get_array(F1), Ei), get_array(E0)) +end + + @testset "Electro+4*HGO_1Fiber" begin c1 = [0.6639232500447778, 0.5532987701062146, 0.9912576142028674, 0.4951942011240962] c2 = [0.800583033264982, 0.3141082734275339, 0.8063905248474006, 0.5850486948450955] From 065fb64b5254774b93a15f2667e9d9c5056b0125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Thu, 21 May 2026 15:24:07 +0200 Subject: [PATCH 19/22] consistent cartesian tags --- src/ComputationalModels/CartesianTags.jl | 96 +++++++++++++++++++++--- 1 file changed, 84 insertions(+), 12 deletions(-) diff --git a/src/ComputationalModels/CartesianTags.jl b/src/ComputationalModels/CartesianTags.jl index fe0f285..dc119de 100644 --- a/src/ComputationalModels/CartesianTags.jl +++ b/src/ComputationalModels/CartesianTags.jl @@ -2,24 +2,27 @@ "Shortcuts for the tags of cartesian discrete models." module CartesianTags -"Tags indicating points, edges and faces at plane X0." -const faceX0 = [1, 3, 5, 7, 13, 15, 17, 19, 25] +# --- Face tags --- -"Tags indicating points, edges and faces at plane X1." -const faceX1 = [2, 4, 6, 8, 14, 16, 18, 20, 26] +"Tags indicating the face at plane X0." +const face0YZ = [25] -"Tags indicating points, edges and faces at plane Y0." -const faceY0 = [1, 2, 5, 6, 9, 11, 17, 18, 23] +"Tags indicating the face at plane X1." +const face1YZ = [26] -"Tags indicating points, edges and faces at plane Y1." -const faceY1 = [3, 4, 7, 8, 10, 12, 19, 20, 24] +"Tags indicating the face at plane Y0." +const faceX0Z = [23] -"Tags indicating points, edges and faces at plane Z0." -const faceZ0 = [1, 2, 3, 4, 9, 10, 13, 14, 21] +"Tags indicating the face at plane Y1." +const faceX1Z = [24] -"Tags indicating points, edges and faces at plane Z1." -const faceZ1 = [5, 6, 7, 8, 11, 12, 15, 16, 22] +"Tags indicating the face at plane Z0." +const faceXY0 = [21] + +"Tags indicating the face at plane Z1." +const faceXY1 = [22] +# --- Edge tags --- "Tag indicating the edge at X, Y0, Z0." const edgeX00 = [9] @@ -57,6 +60,7 @@ const edge01Z = [19] "Tag indicating the edge at X1, Y1, Z." const edge11Z = [20] +# --- Corner tags --- "Tag indicating the point at corner X0, Y0, Z0." const corner000 = [1] @@ -81,4 +85,72 @@ const corner011 = [7] "Tag indicating the point at corner X1, Y1, Z1." const corner111 = [8] + +# --- Edge & corner tags --- + +"Tags indicating points and edge at X, Y0, Z0." +const edgeX00⁺ = [edgeX00; corner000; corner100] + +"Tags indicating points and edge at X, Y1, Z0." +const edgeX10⁺ = [edgeX10; corner010; corner110] + +"Tags indicating points and edge at X, Y0, Z1." +const edgeX01⁺ = [edgeX01; corner001; corner101] + +"Tags indicating points and edge at X, Y1, Z1." +const edgeX11⁺ = [edgeX11; corner011; corner111] + +"Tags indicating points and edge at X0, Y, Z0." +const edge0Y0⁺ = [edge0Y0; corner000; corner010] + +"Tags indicating points and edge at X1, Y, Z0." +const edge1Y0⁺ = [edge1Y0; corner100; corner110] + +"Tags indicating points and edge at X0, Y, Z1." +const edge0Y1⁺ = [edge0Y1; corner001; corner011] + +"Tags indicating points and edge at X1, Y, Z1." +const edge1Y1⁺ = [edge1Y1; corner101; corner111] + +"Tags indicating points and edge at X0, Y0, Z." +const edge00Z⁺ = [edge00Z; corner000; corner001] + +"Tags indicating points and edge at X1, Y0, Z." +const edge10Z⁺ = [edge10Z; corner100; corner101] + +"Tags indicating points and edge at X0, Y1, Z." +const edge01Z⁺ = [edge01Z; corner010; corner011] + +"Tags indicating points and edge at X1, Y1, Z." +const edge11Z⁺ = [edge11Z; corner110; corner111] + +# --- Face & edge & corner tags --- + +"Tags indicating points, edges and faces at plane X0." +const face0YZ⁺ = [face0YZ; edge00Z⁺; edge01Z⁺; edge0Y0⁺; edge0Y1⁺] + +"Tags indicating points, edges and faces at plane X1." +const face1YZ⁺ = [face1YZ; edge10Z⁺; edge11Z⁺; edge1Y0⁺; edge1Y1⁺] + +"Tags indicating points, edges and faces at plane Y0." +const faceX0Z⁺ = [faceX0Z; edgeX00⁺; edgeX01⁺; edge00Z⁺; edge10Z⁺] + +"Tags indicating points, edges and faces at plane Y1." +const faceX1Z⁺ = [faceX1Z; edgeX10⁺; edgeX11⁺; edge01Z⁺; edge11Z⁺] + +"Tags indicating points, edges and faces at plane Z0." +const faceXY0⁺ = [faceXY0; edgeX00⁺; edgeX10⁺; edge0Y0⁺; edge1Y0⁺] + +"Tags indicating points, edges and faces at plane Z1." +const faceXY1⁺ = [faceXY1; edgeX01⁺; edgeX11⁺; edge0Y1⁺; edge1Y1⁺] + +# --- Deprecations --- + +Base.@deprecate_binding faceX0 face0YZ +Base.@deprecate_binding faceX1 face1YZ +Base.@deprecate_binding faceY0 faceX0Z +Base.@deprecate_binding faceY1 faceX1Z +Base.@deprecate_binding faceZ0 faceXY0 +Base.@deprecate_binding faceZ1 faceXY1 + end From b9361c624aef0066371b891535ceabfb036a8097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Thu, 21 May 2026 15:25:26 +0200 Subject: [PATCH 20/22] Fix HyperFEM distributed compilation --- .../ComputationalModels.jl | 20 ++++++++++++++++--- ext/ComputationalModels/FESpaces.jl | 6 ------ ext/ComputationalModels/GridapExtras.jl | 14 ------------- 3 files changed, 17 insertions(+), 23 deletions(-) delete mode 100644 ext/ComputationalModels/FESpaces.jl delete mode 100644 ext/ComputationalModels/GridapExtras.jl diff --git a/ext/ComputationalModels/ComputationalModels.jl b/ext/ComputationalModels/ComputationalModels.jl index de08eb9..0e4714c 100644 --- a/ext/ComputationalModels/ComputationalModels.jl +++ b/ext/ComputationalModels/ComputationalModels.jl @@ -1,11 +1,25 @@ module ComputationalModels using HyperFEM -using Gridap, GridapDistributed, GridapPETSc +using Gridap, Gridap.Algebra, GridapDistributed, GridapPETSc using PartitionedArrays using PartitionedArrays: getany -include("FESpaces.jl") -include("GridapExtras.jl") + +function HyperFEM.ComputationalModels.instantiate_caches(x, nls::PETScNonlinearSolver, op::NonlinearOperator) + return GridapPETSc._setup_cache(x, nls, op) +end + +function HyperFEM.ComputationalModels.get_local_matrix_type(a::GridapDistributed.DistributedSparseMatrixAssembler) + return getany(map(get_matrix_type,a.assems)) +end + +function HyperFEM.ComputationalModels.get_local_vector_type(a::GridapDistributed.DistributedSparseMatrixAssembler) + return getany(map(get_vector_type,a.assems)) +end + +function HyperFEM.ComputationalModels.get_local_assembly_strategy(a::GridapDistributed.DistributedSparseMatrixAssembler) + return get_assembly_strategy(a) +end end diff --git a/ext/ComputationalModels/FESpaces.jl b/ext/ComputationalModels/FESpaces.jl deleted file mode 100644 index c260bfd..0000000 --- a/ext/ComputationalModels/FESpaces.jl +++ /dev/null @@ -1,6 +0,0 @@ - -import HyperFEM.instantiate_caches - -function instantiate_caches(x, nls::PETScNonlinearSolver, op::NonlinearOperator) - return GridapPETSc._setup_cache(x, nls, op) -end diff --git a/ext/ComputationalModels/GridapExtras.jl b/ext/ComputationalModels/GridapExtras.jl deleted file mode 100644 index 5282d8c..0000000 --- a/ext/ComputationalModels/GridapExtras.jl +++ /dev/null @@ -1,14 +0,0 @@ - -import HyperFEM.ComputationalModels.get_local_matrix_type -import HyperFEM.ComputationalModels.get_local_vector_type -import HyperFEM.ComputationalModels.get_local_assembly_strategy - -function get_local_matrix_type(a::GridapDistributed.DistributedSparseMatrixAssembler) - return getany(map(get_matrix_type,a.assems)) -end -function get_local_vector_type(a::GridapDistributed.DistributedSparseMatrixAssembler) - return getany(map(get_vector_type,a.assems)) -end -function get_local_assembly_strategy(a::GridapDistributed.DistributedSparseMatrixAssembler) - return get_assembly_strategy(a) -end From 248fb6ee28b76de9a22c9f419fffde55079dbf5d Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Wed, 27 May 2026 11:01:22 +0200 Subject: [PATCH 21/22] property destructing --- src/PhysicalModels/PhysicalModels.jl | 1 - src/PhysicalModels/ThermalModels.jl | 8 ++++---- src/PhysicalModels/ThermoMechanicalModels.jl | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/PhysicalModels/PhysicalModels.jl b/src/PhysicalModels/PhysicalModels.jl index d992db9..9c46458 100644 --- a/src/PhysicalModels/PhysicalModels.jl +++ b/src/PhysicalModels/PhysicalModels.jl @@ -3,7 +3,6 @@ module PhysicalModels using Gridap using Gridap.CellData using Gridap.Helpers -using UnPack using ForwardDiff using LinearAlgebra using StaticArrays diff --git a/src/PhysicalModels/ThermalModels.jl b/src/PhysicalModels/ThermalModels.jl index 8abf887..03cd8af 100644 --- a/src/PhysicalModels/ThermalModels.jl +++ b/src/PhysicalModels/ThermalModels.jl @@ -55,7 +55,7 @@ struct EntropicElasticityLaw <: ThermalLaw end function (law::EntropicElasticityLaw)() - @unpack θr, γ = law + (; θr, γ) = law f(θ) = (θ/θr)^(γ+1) ∂f(θ) = (γ+1) * θ^γ / θr^(γ+1) ∂∂f(θ) = γ*(γ+1) * θ^(γ-1) / θr^(γ+1) @@ -70,7 +70,7 @@ struct NonlinearMeltingLaw <: ThermalLaw end function (law::NonlinearMeltingLaw)() - @unpack θr, θM, γ = law + (; θr, θM, γ) = law f(θ) = (1 - (θ/θM)^(γ+1)) / (1 - (θr/θM)^(γ+1)) ∂f(θ) = -(γ+1)*θ^γ/θM^(γ+1) / (1 - (θr/θM)^(γ+1)) ∂∂f(θ) = -γ*(γ+1)*θ^(γ-1)/θM^(γ+1) / (1 - (θr/θM)^(γ+1)) @@ -86,7 +86,7 @@ struct NonlinearSofteningLaw <: ThermalLaw end function (law::NonlinearSofteningLaw)() - @unpack θr, θT, γ, δ = law + (; θr, θT, γ, δ) = law u(θ) = exp(-(θ/θT)^(γ+1)) C = (1-δ) * u(θr) + δ f(θ) = ((1-δ) * u(θ) + δ) / C @@ -104,7 +104,7 @@ struct PolynomialLaw <: ThermalLaw end function (law::PolynomialLaw)() - @unpack θr, a, b, c = law + (; θr, a, b, c) = law f(θ) = a*((θ-θr)/θr)^3 + b*((θ-θr)/θr)^2 + c*(θ-θr)/θr + 1 ∂f(θ) = 3a*(θ-θr)^2/θr^3 + 2b*(θ-θr)/θr^2 + c/θr ∂∂f(θ) = 6a*(θ-θr)/θr^3 + 2b/θr^2 diff --git a/src/PhysicalModels/ThermoMechanicalModels.jl b/src/PhysicalModels/ThermoMechanicalModels.jl index 8b25172..bed94e2 100644 --- a/src/PhysicalModels/ThermoMechanicalModels.jl +++ b/src/PhysicalModels/ThermoMechanicalModels.jl @@ -46,7 +46,7 @@ struct ThermalVolumetric{T<:Thermo} <: ThermoMechano{T,Volumetric} end function (obj::ThermalVolumetric)() - @unpack Cv, θr, α, κ = obj.thermo + (; Cv, θr, α, κ) = obj.thermo cv0 = Cv # FIXME U, ∂U∂F, ∂∂U∂FF = obj.mechano() κr = tangent(obj.mechano) From 7e81de8c978041dca4eeb634470513ea291e1830 Mon Sep 17 00:00:00 2001 From: miguelmaso Date: Wed, 27 May 2026 11:19:39 +0200 Subject: [PATCH 22/22] Explicit multiple dispatch --- src/PhysicalModels/ElectroMechanicalModels.jl | 2 +- src/PhysicalModels/PhysicalModels.jl | 4 ++-- src/PhysicalModels/ThermoElectroMechanicalModels.jl | 2 +- src/PhysicalModels/ThermoMechanicalModels.jl | 2 +- src/PhysicalModels/ViscousModels.jl | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/PhysicalModels/ElectroMechanicalModels.jl b/src/PhysicalModels/ElectroMechanicalModels.jl index f51a592..d773c6b 100644 --- a/src/PhysicalModels/ElectroMechanicalModels.jl +++ b/src/PhysicalModels/ElectroMechanicalModels.jl @@ -73,7 +73,7 @@ function update_time_step!(obj::ElectroMechModel, Δt::Float64) update_time_step!(obj.mechano, Δt) end -function CellState(obj::ElectroMechModel, args...) +function Gridap.CellData.CellState(obj::ElectroMechModel, args...) CellState(obj.mechano, args...) end diff --git a/src/PhysicalModels/PhysicalModels.jl b/src/PhysicalModels/PhysicalModels.jl index 9c46458..d23847e 100644 --- a/src/PhysicalModels/PhysicalModels.jl +++ b/src/PhysicalModels/PhysicalModels.jl @@ -12,7 +12,7 @@ using ..TensorAlgebra: _∂H∂F_2D using ..TensorAlgebra: trAA import Base: + -import Gridap: CellState, update_state! +import Gridap: update_state! export Yeoh3D export Gent2D @@ -154,7 +154,7 @@ Base.broadcastable(m::PhysicalModel) = Ref(m) # Allows to use the @. syntax for """ Initialize the state variables for the given constitutive model and discretization. """ -function CellState(::PhysicalModel, args...) +function Gridap.CellData.CellState(::PhysicalModel, args...) return nothing end diff --git a/src/PhysicalModels/ThermoElectroMechanicalModels.jl b/src/PhysicalModels/ThermoElectroMechanicalModels.jl index e8c76b9..13092fd 100644 --- a/src/PhysicalModels/ThermoElectroMechanicalModels.jl +++ b/src/PhysicalModels/ThermoElectroMechanicalModels.jl @@ -1,5 +1,5 @@ -function CellState(obj::ThermoElectroMechano, args...) +function Gridap.CellData.CellState(obj::ThermoElectroMechano, args...) CellState(obj.mechano, args...) end diff --git a/src/PhysicalModels/ThermoMechanicalModels.jl b/src/PhysicalModels/ThermoMechanicalModels.jl index bed94e2..4eba993 100644 --- a/src/PhysicalModels/ThermoMechanicalModels.jl +++ b/src/PhysicalModels/ThermoMechanicalModels.jl @@ -3,7 +3,7 @@ # Common functions # =================== -function CellState(obj::ThermoMechano, args...) +function Gridap.CellData.CellState(obj::ThermoMechano, args...) CellState(obj.mechano, args...) end diff --git a/src/PhysicalModels/ViscousModels.jl b/src/PhysicalModels/ViscousModels.jl index 649384e..d247c0c 100644 --- a/src/PhysicalModels/ViscousModels.jl +++ b/src/PhysicalModels/ViscousModels.jl @@ -26,12 +26,12 @@ function update_time_step!(obj::ViscousIncompressible, Δt::Float64) obj.Δt[] = Δt end -function CellState(::ViscousIncompressible, F0::TensorValue, points::Measure) +function Gridap.CellData.CellState(::ViscousIncompressible, F0::TensorValue, points::Measure) v = VectorValue(F0..., 0.0) CellState(v, points) end -function CellState(obj::ViscousIncompressible, points::Measure) +function Gridap.CellData.CellState(obj::ViscousIncompressible, points::Measure) CellState(obj, I3, points) end @@ -88,7 +88,7 @@ function update_time_step!(obj::NVisco, Δt::Float64) Δt end -function CellState(obj::NVisco, args...) +function Gridap.CellData.CellState(obj::NVisco, args...) map(b -> CellState(b, args...), obj) end @@ -139,7 +139,7 @@ function update_time_step!(obj::GeneralizedMaxwell, Δt::Float64) update_time_step!(obj.branches, Δt) end -function CellState(obj::GeneralizedMaxwell, args...) +function Gridap.CellData.CellState(obj::GeneralizedMaxwell, args...) CellState(obj.branches, args...) end