From 9512d8449f9cc30649cb128582e7d1c986f2ee4e Mon Sep 17 00:00:00 2001 From: "Z J Wegert (Workstation)" Date: Tue, 14 May 2024 11:50:43 +1000 Subject: [PATCH] add test --- .../seq/NeohookAnalyticJacALMTests.jl | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) rename scripts/Serial/hyperelastic_compliance_neohook_jac_ALM.jl => test/seq/NeohookAnalyticJacALMTests.jl (76%) diff --git a/scripts/Serial/hyperelastic_compliance_neohook_jac_ALM.jl b/test/seq/NeohookAnalyticJacALMTests.jl similarity index 76% rename from scripts/Serial/hyperelastic_compliance_neohook_jac_ALM.jl rename to test/seq/NeohookAnalyticJacALMTests.jl index 18ef848a..8ef5d702 100644 --- a/scripts/Serial/hyperelastic_compliance_neohook_jac_ALM.jl +++ b/test/seq/NeohookAnalyticJacALMTests.jl @@ -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); @@ -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() \ No newline at end of file +# Test that these run successfully +@test main() + +end # module \ No newline at end of file