Skip to content

Commit 2a6d715

Browse files
committed
Merge branch 'main' into fix-mpi
2 parents 1e8585a + c1ba357 commit 2a6d715

20 files changed

Lines changed: 303 additions & 137 deletions

Project.toml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "HyperFEM"
22
uuid = "ddbf423a-3df4-409e-9685-3dc416cae46c"
3+
version = "0.0.2"
34
authors = ["MultiSimo_Group"]
4-
version = "1.0.0-DEV"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -28,3 +28,25 @@ PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
2828

2929
[extensions]
3030
HyperFEMDistributed = ["GridapDistributed", "GridapPETSc", "PartitionedArrays"]
31+
32+
[compat]
33+
AbstractTrees = "0.4.5"
34+
BlockArrays = "1.9.3"
35+
DrWatson = "2.19.1"
36+
ForwardDiff = "1.3.2"
37+
Gridap = "0.19.7"
38+
GridapDistributed = "0.4.10"
39+
GridapGmsh = "0.7.3"
40+
GridapPETSc = "0.5.6"
41+
GridapSolvers = "0.6.1"
42+
IterativeSolvers = "0.9.4"
43+
JSON = "1.4.0"
44+
PartitionedArrays = "0.3.5"
45+
ProfileView = "1.10.2"
46+
Roots = "2.2.10"
47+
StaticArrays = "1.9.16"
48+
TimerOutputs = "0.5.29"
49+
WriteVTK = "1.21.2"
50+
LinearAlgebra = "1.10.0"
51+
Profile = "1.10.0"
52+
julia = "1.10"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ src="https://github.com/jmartfrut/HyperFEM/blob/main/docs/imgs/logo.png?raw=true
2525
## Installation
2626
Open the Julia REPL, type `]` to enter package mode, and install as follows
2727
```julia
28-
pkg> add https://github.com/MultiSimOLab/HyperFEM
28+
pkg> add HyperFEM
2929
```
3030

3131
## Usage
@@ -99,7 +99,7 @@ U = MultiFieldFESpace([Uu, Uφ])
9999
km=Kinematics(Mechano,Solid)
100100
ke=Kinematics(Electro,Solid)
101101

102-
F,_,_ = get_Kinematics(kM)
102+
F,_,_ = get_Kinematics(km)
103103
E = get_Kinematics(ke)
104104

105105
# residual and jacobian function of load factor
@@ -154,7 +154,7 @@ src="https://github.com/MultiSimOLab/HyperFEM/blob/main/docs/imgs/sims_.png?raw=
154154

155155
In order to give credit to the HyperFEM contributors, we ask that you please reference the paper:
156156

157-
C. Perez‐Garcia, R. Ortigosa, J. Martínez‐Frutos, and D. Garcia‐Gonzalez, **Topology and material optimization in ultra-soft magnetoactive structures: making advantage of residual anisotropies.** Adv. Mater. (2025): e18489. https://https://doi.org/10.1002/adma.202518489
157+
C. Perez‐Garcia, R. Ortigosa, J. Martínez‐Frutos, and D. Garcia‐Gonzalez, **Topology and material optimization in ultra-soft magnetoactive structures: making advantage of residual anisotropies.** Adv. Mater. (2025): e18489. https://doi.org/10.1002/adma.202518489
158158

159159

160160
along with the required citations for [Gridap](https://github.com/gridap/Gridap.jl).

src/ComputationalModels/BoundaryConditions.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function _get_bc_func(tags_::Vector{String}, values_, bc_timesteps)
6767
@inbounds for i in eachindex(tags_)
6868

6969
if values_[i] === DirichletCoupling || typeof(values_[i]) <: DirichletCoupling
70-
bc_func_[i] = (Λ) -> (x) -> x
70+
bc_func_[i] = (Λ) -> (x) -> x
7171
else
7272
if isnothing(bc_timesteps[i])
7373
bc_func_[i] = values_[i]
@@ -97,6 +97,16 @@ struct DirichletBC{A} <: BoundaryCondition
9797
caches = (bc_values)
9898
new{typeof(caches)}(tags_, funcs_, bc_timesteps, caches)
9999
end
100+
101+
102+
function DirichletBC(bc_tags::Vector{String}, bc_values)
103+
@assert(length(bc_tags) == length(bc_values))
104+
bc_timesteps =-> 1.0 for _ in 1:length(bc_tags)]
105+
tags_, funcs_ = _get_bc_func(bc_tags, bc_values, bc_timesteps)
106+
caches = (bc_values)
107+
new{typeof(caches)}(tags_, funcs_, bc_timesteps, caches)
108+
end
109+
100110
end
101111

102112
function updateBC!(m::DirichletBC, bc_values, bc_timesteps)
@@ -206,7 +216,7 @@ struct InterpolableBC{A,B,C} <: DirichletCoupling
206216
dim = length(U.space.fe_dof_basis.trian.model.grid.node_coordinates[1])
207217
mask = U.space.dirichlet_dof_tag .== dcmask[1]
208218
vals = U.dirichlet_values[mask]
209-
Interface_coords_ = reshape(vals, dim,:)'
219+
Interface_coords_ = reshape(vals, dim, :)'
210220
coords = VectorValue.(eachrow(Interface_coords_))
211221
v = evaluate(Interpolable(1.0), coords)
212222
bc_values = reduce(vcat, map(x -> get_array(x), v))
@@ -228,4 +238,3 @@ function InterpolableBC!(U::TrialFESpace, bc::DirichletBC, interface_tags::Strin
228238
return obj
229239
end
230240

231-

src/ComputationalModels/ComputationalModels.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ export reset!
7878
export interpolate_L2_tensor
7979
export interpolate_L2_vector
8080
export interpolate_L2_scalar
81-
81+
export L2_Projection
8282
end

src/ComputationalModels/Drivers.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ end
4343
function solve!(m::StaggeredModel;
4444
stepping=(nsteps=20, nsubsteps=1, maxbisec=15),
4545
presolver=(τ, ∆τ) -> nothing,
46+
evolτ=t-> max(min(t, 1.0), 0.0),
4647
kargsolve)
4748

4849
nsubsteps = stepping[:nsubsteps]
@@ -59,7 +60,10 @@ function solve!(m::StaggeredModel;
5960
println(" Staggered Step: ")
6061
println("*******************************************")
6162
presolver(τ, ∆τ)
62-
stevol(Λ) = ∆τ *+ τ)
63+
τ⁻=evolτ*∆τ)
64+
τ⁺=evolτ((τ+1)*∆τ)
65+
stevol(Λ) = τ⁻+ (τ⁺-τ⁻)*Λ
66+
# stevol(Λ) = ∆τ * (Λ + τ)
6367
map(x -> updateBC!(x.dirichlet, x.dirichlet.caches, [stevol for _ in 1:length(x.dirichlet.caches)]), m.compmodels)
6468
for τ_inner in 1:nsubsteps
6569
map((x) -> TrialFESpace!(x.spaces[1], x.dirichlet, 1.0), m.compmodels)
@@ -141,7 +145,7 @@ function solve!(m::StaticNonlinearModel;
141145
x⁻ .= x
142146
α = 1.0
143147

144-
while Λ < 1.0
148+
while !isapprox(Λ, 1.0; atol=1e-12)
145149
Λ += ∆Λ
146150
if Λ > 1.0
147151
∆Λ = 1.0 -- ∆Λ)

src/Exports.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ end
1717
@publish TensorAlgebra logreg
1818
@publish TensorAlgebra Box
1919
@publish TensorAlgebra Ellipsoid
20+
@publish TensorAlgebra I2
21+
@publish TensorAlgebra I3
22+
@publish TensorAlgebra I4
2023
@publish TensorAlgebra I9
2124
@publish TensorAlgebra Tensorize
2225

@@ -25,6 +28,7 @@ end
2528
@publish PhysicalModels LinearElasticity3D
2629
@publish PhysicalModels LinearElasticity2D
2730
@publish PhysicalModels Yeoh3D
31+
@publish PhysicalModels Gent2D
2832
@publish PhysicalModels NeoHookean3D
2933
@publish PhysicalModels IncompressibleNeoHookean3D
3034
@publish PhysicalModels IncompressibleNeoHookean2D
@@ -43,6 +47,7 @@ end
4347
@publish PhysicalModels TransverseIsotropy3D
4448
@publish PhysicalModels TransverseIsotropy2D
4549
@publish PhysicalModels ThermalModel
50+
@publish PhysicalModels ThermalModel3rdLaw
4651
@publish PhysicalModels IdealDielectric
4752
@publish PhysicalModels Magnetic
4853
@publish PhysicalModels IdealMagnetic
@@ -56,7 +61,6 @@ end
5661
@publish PhysicalModels FlexoElectroModel
5762
@publish PhysicalModels ThermoElectroMech_Govindjee
5863
@publish PhysicalModels ThermoElectroMech_PINNs
59-
@publish PhysicalModels ThermoElectroMech_Bonet
6064
@publish PhysicalModels MagnetoMechModel
6165
@publish PhysicalModels ARAP2D
6266
@publish PhysicalModels ARAP2D_regularized
@@ -135,7 +139,8 @@ end
135139
@publish ComputationalModels evaluate!
136140
@publish ComputationalModels InterpolableBC
137141
@publish ComputationalModels InterpolableBC!
138-
@publish ComputationalModels TrialFESpace! # Exporting internal function of Gridap
142+
@publish ComputationalModels TrialFESpace! # Exporting internal function of Gridap
143+
@publish ComputationalModels L2_Projection
139144

140145
# Note: the files FaceLabeling, CartesianTags and Evolution functions should be moved to a module different than ComputationalModels
141146
@publish ComputationalModels add_tag_from_vertex_filter!

src/PhysicalModels/ElectroMechanicalModels.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ struct ElectroMechModel{E<:Electro,M<:Mechano} <: ElectroMechano
1212
end
1313

1414
function (obj::ElectroMechModel{<:Electro,<:IsoElastic})(Λ::Float64=1.0)
15-
Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano(Λ)
16-
Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano, Λ)
15+
Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano()
16+
Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano)
1717
Ψ(F, E) = Ψm(F) + Ψem(F, E)
1818
∂Ψu(F, E) = ∂Ψm_u(F) + ∂Ψem_u(F, E)
1919
∂Ψφ(F, E) = ∂Ψem_φ(F, E)
@@ -23,8 +23,8 @@ struct ElectroMechModel{E<:Electro,M<:Mechano} <: ElectroMechano
2323
return (Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ)
2424
end
2525
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, Λ)
26+
Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano()
27+
Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano)
2828
Ψ(F, E, N) = Ψm(F, N) + Ψem(F, E)
2929
∂Ψu(F, E, N) = ∂Ψm_u(F, N) + ∂Ψem_u(F, E)
3030
∂Ψφ(F, E, N) = ∂Ψem_φ(F, E)
@@ -35,7 +35,7 @@ struct ElectroMechModel{E<:Electro,M<:Mechano} <: ElectroMechano
3535
end
3636
function (obj::ElectroMechModel{<:Electro,<:ViscoElastic{<:IsoElastic}})(Λ::Float64=1.0)
3737
Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano()
38-
Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano, Λ)
38+
Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano)
3939
Ψ(F, E, Fn, A...) = Ψm(F, Fn, A...) + Ψem(F, E)
4040
∂Ψu(F, E, Fn, A...) = ∂Ψm_u(F, Fn, A...) + ∂Ψem_u(F, E)
4141
∂Ψφ(F, E, Fn, A...) = ∂Ψem_φ(F, E)
@@ -44,7 +44,7 @@ struct ElectroMechModel{E<:Electro,M<:Mechano} <: ElectroMechano
4444
∂Ψφφ(F, E, Fn, A...) = ∂Ψem_φφ(F, E)
4545
return (Ψ, ∂Ψu, ∂Ψφ, ∂Ψuu, ∂Ψφu, ∂Ψφφ)
4646
end
47-
function (obj::ElectroMechModel{<:Electro,<:ViscoElastic{<:AnisoElastic}})()
47+
function (obj::ElectroMechModel{<:Electro,<:ViscoElastic{<:AnisoElastic}})(Λ::Float64=1.0)
4848
Ψm, ∂Ψm_u, ∂Ψm_uu = obj.mechano()
4949
Ψem, ∂Ψem_u, ∂Ψem_φ, ∂Ψem_uu, ∂Ψem_φu, ∂Ψem_φφ = _getCoupling(obj.electro, obj.mechano)
5050
Ψ(F, E, n, Fn, A...) = Ψm(F, n, Fn, A...) + Ψem(F, E)
@@ -57,8 +57,6 @@ struct ElectroMechModel{E<:Electro,M<:Mechano} <: ElectroMechano
5757
end
5858
end
5959

60-
ViscoElectricModel = ElectroMechModel{<:Electro,<:ViscoElastic}
61-
6260
function update_time_step!(obj::ElectroMechModel, Δt::Float64)
6361
update_time_step!(obj.electro, Δt)
6462
update_time_step!(obj.mechano, Δt)
@@ -72,8 +70,13 @@ function update_state!(obj::ElectroMechModel, state, F, E, args...)
7270
update_state!(obj.mechano, state, F, args...)
7371
end
7472

73+
function Dissipation(obj::ElectroMechModel)
74+
Dvis = Dissipation(obj.mechano)
75+
D(F, E, X...) = Dvis(F, X...)
76+
end
77+
7578

76-
function _getCoupling(elec::Electro, mec::Mechano, Λ::Float64)
79+
function _getCoupling(elec::Electro, mec::Mechano, Λ::Float64=0.0)
7780
J(F) = det(F)
7881
H(F) = det(F) * inv(F)'
7982
# Energy #

src/PhysicalModels/MagneticModels.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ end
162162

163163
struct HardMagnetic2D <: Magneto
164164
μ::Float64
165-
αr::Float64
165+
αr::Ref{Float64}
166166
χe::Float64
167167
χr::Float64
168168
βmok::Float64
169169
βcoup::Float64
170170
function HardMagnetic2D(; μ0::Float64, αr::Float64, χe::Float64=0.0, χr::Float64=8.0, βmok::Float64=0.0, βcoup::Float64=0.0)
171-
new(μ0, αr, χe, χr, βmok, βcoup)
171+
new(μ0, Ref(αr), χe, χr, βmok, βcoup)
172172
end
173173

174174
function (obj::HardMagnetic2D)(Λ::Float64=1.0)

src/PhysicalModels/MagnetoMechanicalModels.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function _getCoupling(mag::HardMagnetic2D, ::Mechano, Λ::Float64=1.0)
164164
#-------------------------------------------------------------------------------------
165165
Hℋ₀(F, ℋ₀) = H(F) * ℋ₀
166166
Hℋ₀Hℋ₀(F, ℋ₀) = Hℋ₀(F, ℋ₀) Hℋ₀(F, ℋ₀)
167-
ℋᵣ(N) = αr * Λ* N
167+
ℋᵣ(N) = αr[] * Λ* N
168168
Fℋᵣ(F, N) = F * ℋᵣ(N)
169169
Ψcoup(F, N) =* J(F)) * (Fℋᵣ(F, N) Fℋᵣ(F, N) - ℋᵣ(N) ℋᵣ(N))
170170
∂Ψcoup_∂F(F, N) = 2 ** J(F)) * (Fℋᵣ(F, N) ℋᵣ(N))

0 commit comments

Comments
 (0)