Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zjwegert committed May 14, 2024
1 parent 2d2acee commit 9512d84
Showing 1 changed file with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
using Gridap, LevelSetTopOpt
module NeohookAnalyticJacALMTests
using Test

using Gridap, GridapTopOpt

"""
(Serial) Minimum hyperelastic (neohookean) compliance with augmented Lagrangian method in 2D.
"""
"""
function main()
## Parameters
order = 1
xmax,ymax=2.0,1.0
xmax=ymax=1.0
prop_Γ_N = 0.2
dom = (0,xmax,0,ymax)
el_size = (200,200)
γ = 0.05
el_size = (20,20)
γ = 0.1
γ_reinit = 0.5
max_steps = floor(Int,minimum(el_size)/10)
max_steps = floor(Int,order*minimum(el_size)/10)
tol = 1/(5order^2)/minimum(el_size)
η_coeff = 2
α_coeff = 4
α_coeff = 4max_steps*γ
vf = 0.6
path = dirname(dirname(@__DIR__))*"/results/hyperelastic_compliance_neohook_jac_ALM"
mkdir(path)

## FE Setup
model = CartesianDiscreteModel(dom,el_size);
Expand Down Expand Up @@ -88,31 +89,33 @@ function main()
jac(u,du,v,φ,dΩ,dΓ_N) = jac_mat(u,du,v,φ,dΩ,dΓ_N) + jac_geo(u,du,v,φ,dΩ,dΓ_N)

## Optimisation functionals
Obj(u,φ,dΩ,dΓ_N) = ((I φ)*((dE((u),(u))) (S(u))))dΩ
J(u,φ,dΩ,dΓ_N) = ((I φ)*((dE((u),(u))) (S(u))))dΩ
Vol(u,φ,dΩ,dΓ_N) = (((ρ φ) - vf)/vol_D)dΩ;
dVol(q,u,φ,dΩ,dΓ_N) = (-1/vol_D*q*(DH φ)*(norm (φ)))dΩ

## Finite difference solver and level set function
stencil = AdvectionStencil(FirstOrderStencil(2,Float64),model,V_φ,tol,max_steps)
ls_evo = HamiltonJacobiEvolution(FirstOrderStencil(2,Float64),model,V_φ,tol,max_steps)

## Setup solver and FE operators
state_map = NonlinearFEStateMap(res,U,V,V_φ,U_reg,φh,dΩ,dΓ_N;jac)
pcfs = PDEConstrainedFunctionals(Obj,[Vol],state_map,analytic_dC=[dVol])
pcfs = PDEConstrainedFunctionals(J,[Vol],state_map,analytic_dC=[dVol])

## Hilbertian extension-regularisation problems
α = α_coeff*maximum(el_Δ)
a_hilb(p,q) =^2*(p)(q) + p*q)dΩ
vel_ext = VelocityExtension(a_hilb,U_reg,V_reg)

## Optimiser
optimiser = AugmentedLagrangian(pcfs,stencil,vel_ext,φh;
optimiser = AugmentedLagrangian(pcfs,ls_evo,vel_ext,φh;
γ,γ_reinit,verbose=true,constraint_names=[:Vol])
for (it,uh,φh) in optimiser
write_vtk(Ω,path*"/struc_$it",it,["phi"=>φh,"H(phi)"=>(H φh),"|nabla(phi)|"=>(norm (φh)),"uh"=>uh])
write_history(path*"/history.txt",optimiser.history)
end
it = get_history(optimiser).niter; uh = get_state(pcfs)
write_vtk(Ω,path*"/struc_$it",it,["phi"=>φh,"H(phi)"=>(H φh),"|nabla(phi)|"=>(norm (φh)),"uh"=>uh];iter_mod=1)

# Do a few iterations
vars, state = iterate(optimiser)
vars, state = iterate(optimiser,state)
true
end

main()
# Test that these run successfully
@test main()

end # module

0 comments on commit 9512d84

Please sign in to comment.