From 11586384dc7b5336492ddf3de0da166764ec9301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 11:47:40 +0100 Subject: [PATCH 01/14] dirichlet test file --- .../StaticMechanicalDirichletSimulation.jl | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 test/data/StaticMechanicalDirichletSimulation.jl diff --git a/test/data/StaticMechanicalDirichletSimulation.jl b/test/data/StaticMechanicalDirichletSimulation.jl new file mode 100644 index 0000000..fe7ae3a --- /dev/null +++ b/test/data/StaticMechanicalDirichletSimulation.jl @@ -0,0 +1,84 @@ +using Gridap, GridapGmsh, GridapSolvers, DrWatson +using GridapSolvers.NonlinearSolvers +using GridapSolvers.LinearSolvers +using TimerOutputs +using Gridap.FESpaces +using HyperFEM +using HyperFEM.ComputationalModels.CartesianTags + + +function main(;writevtk=true, verbose=true) + + pname = "Stretch" + + long = 0.05 # m + width = 0.005 # m + thick = 0.002 # m + geometry = CartesianDiscreteModel((0, long, 0, width, 0, thick), (5,2,2)) + labels = get_face_labeling(geometry) + add_tag_from_tags!(labels, "fixed", CartesianTags.faceX0) + add_tag_from_tags!(labels, "moving", CartesianTags.faceX1) + + simdir = datadir("sims", pname) + setupfolder(simdir) + + physmodel = MooneyRivlin3D(λ=3.0, μ1=1.0, μ2=0.0, ρ=1.0) + + # Setup integration + order = 1 + degree = 2 * order + Ω = Triangulation(geometry) + dΩ = Measure(Ω, degree) + + # Dirichlet boundary conditions + dir_u_tags = ["fixed", "moving"] + dir_u_values = [[0.0, 0.0, 0.0], [0.08, 0.0, 0.0]] + dir_u_timesteps = [Λ -> 1.0, Λ -> Λ] + D_bc = DirichletBC(dir_u_tags, dir_u_values, dir_u_timesteps) + + # FE spaces + reffeu = ReferenceFE(lagrangian, VectorValue{3,Float64}, order) + + V = TestFESpace(Ω, reffeu, D_bc, conformity=:H1) + U = TrialFESpace(V, D_bc, 0.0) + + # residual and jacobian function of load factor + res(Λ) = (u, v) -> residual(physmodel, u, v, dΩ) + jac(Λ) = (u, du, v) -> jacobian(physmodel, u, du, v, dΩ) + + #computational model + ls = LUSolver() + nls_ = NewtonSolver(ls; maxiter=15, rtol=1.e-12, verbose=verbose) + + comp_model = StaticNonlinearModel(res, jac, U, V, D_bc; nls=nls_) + + function driverpost_mech(post) + if writevtk + state = post.comp_model.caches[3] + Λ_ = post.iter + Λ = post.Λ[Λ_] + xh = FEFunction(U, state) + pvd = post.cachevtk[3] + filePath = post.cachevtk[2] + if post.cachevtk[1] + Λstring = replace(string(round(Λ, digits=2)), "." => "_") + pvd[Λ_] = createvtk(Ω, + filePath * "/" * pname * "_Λ_" * Λstring * ".vtu", + cellfields=["u" => xh]) + end + end + end + + post_model = PostProcessor(comp_model, driverpost_mech; is_vtk=writevtk, filepath=simdir) + + @timeit pname begin + x, flag = solve!(comp_model; stepping=(nsteps=10, maxbisec=10), post=post_model) + end +end + + +if abspath(PROGRAM_FILE) == @__FILE__ + reset_timer!() + main() + print_timer() +end From 86608d061c2349ff16408e3c9de4b4846281d224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 11:57:15 +0100 Subject: [PATCH 02/14] added static dirichlet test --- test/SimulationsTests/StaticMechanicalDirichletTest.jl | 8 ++++++++ test/SimulationsTests/runtests.jl | 2 ++ test/data/StaticMechanicalDirichletSimulation.jl | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/SimulationsTests/StaticMechanicalDirichletTest.jl diff --git a/test/SimulationsTests/StaticMechanicalDirichletTest.jl b/test/SimulationsTests/StaticMechanicalDirichletTest.jl new file mode 100644 index 0000000..cd0d743 --- /dev/null +++ b/test/SimulationsTests/StaticMechanicalDirichletTest.jl @@ -0,0 +1,8 @@ + +BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) +filename = joinpath(BASE_FOLDER, "test/data/StaticMechanicalDirichletSimulation.jl") +include(filename) + +x = static_mechanical_dirichlet_simulation(writevtk=false, verbose=false) + +@test norm(x) ≈ 0.27148722276 diff --git a/test/SimulationsTests/runtests.jl b/test/SimulationsTests/runtests.jl index 108a5e9..61043fa 100644 --- a/test/SimulationsTests/runtests.jl +++ b/test/SimulationsTests/runtests.jl @@ -6,4 +6,6 @@ using Test include("ViscoElasticSimulationTest.jl") + include("StaticMechanicalDirichletTest.jl") + end diff --git a/test/data/StaticMechanicalDirichletSimulation.jl b/test/data/StaticMechanicalDirichletSimulation.jl index fe7ae3a..1eaa1c8 100644 --- a/test/data/StaticMechanicalDirichletSimulation.jl +++ b/test/data/StaticMechanicalDirichletSimulation.jl @@ -7,7 +7,7 @@ using HyperFEM using HyperFEM.ComputationalModels.CartesianTags -function main(;writevtk=true, verbose=true) +function static_mechanical_dirichlet_simulation(;writevtk=true, verbose=true) pname = "Stretch" @@ -74,11 +74,12 @@ function main(;writevtk=true, verbose=true) @timeit pname begin x, flag = solve!(comp_model; stepping=(nsteps=10, maxbisec=10), post=post_model) end + return x end if abspath(PROGRAM_FILE) == @__FILE__ reset_timer!() - main() + static_mechanical_dirichlet_simulation() print_timer() end From e7c789cac96901cc8ea74106380389f5647d71ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 11:58:23 +0100 Subject: [PATCH 03/14] minor renaming --- .../SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl | 2 +- test/SimulationsTests/ViscoElasticSimulationTest.jl | 2 +- test/data/ViscoElasticSimulation.jl | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl b/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl index d611519..e09514a 100644 --- a/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl +++ b/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl @@ -3,4 +3,4 @@ BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) filename = joinpath(BASE_FOLDER, "test/data/ViscoElasticSimulation.jl") include(filename) -SUITE["Simulations"]["ViscoElastic"] = @benchmarkable visco_elastic_simulation(write_vtk=false) +SUITE["Simulations"]["ViscoElastic"] = @benchmarkable visco_elastic_simulation(writevtk=false) diff --git a/test/SimulationsTests/ViscoElasticSimulationTest.jl b/test/SimulationsTests/ViscoElasticSimulationTest.jl index d03765b..35f1af0 100644 --- a/test/SimulationsTests/ViscoElasticSimulationTest.jl +++ b/test/SimulationsTests/ViscoElasticSimulationTest.jl @@ -3,6 +3,6 @@ BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) filename = joinpath(BASE_FOLDER, "test/data/ViscoElasticSimulation.jl") include(filename) -λx, σΓ = visco_elastic_simulation(t_end=5, write_vtk=false, verbose=false) +λx, σΓ = visco_elastic_simulation(t_end=5, writevtk=false, verbose=false) @test σΓ[end] ≈ 152821.386 diff --git a/test/data/ViscoElasticSimulation.jl b/test/data/ViscoElasticSimulation.jl index 66fdd28..c267d88 100644 --- a/test/data/ViscoElasticSimulation.jl +++ b/test/data/ViscoElasticSimulation.jl @@ -8,7 +8,7 @@ using HyperFEM.ComputationalModels:constant using HyperFEM.ComputationalModels:triangular using HyperFEM.ComputationalModels.PostMetrics -function visco_elastic_simulation(;t_end=15, write_vtk=true, verbose=true) +function visco_elastic_simulation(;t_end=15, writevtk=true, verbose=true) # Domain and tessellation long = 0.05 # m width = 0.005 # m @@ -78,7 +78,7 @@ function visco_elastic_simulation(;t_end=15, write_vtk=true, verbose=true) updateStateVariables!(state_vars, cons_model, Δt, uh, unh) end - post_model = PostProcessor(comp_model, driverpost; is_vtk=false, filepath="") + post_model = PostProcessor(comp_model, driverpost; is_vtk=writevtk, filepath="") solve!(comp_model; stepping=(nsteps=Int(t_end/Δt), maxbisec=1), post=post_model, ProjectDirichlet=true) (λx, σΓ) end From 3926a72a432fd877a79ece67b37bc3e7887f13de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 12:00:21 +0100 Subject: [PATCH 04/14] no verbose --- .../SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl b/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl index e09514a..5bd29e7 100644 --- a/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl +++ b/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl @@ -3,4 +3,4 @@ BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) filename = joinpath(BASE_FOLDER, "test/data/ViscoElasticSimulation.jl") include(filename) -SUITE["Simulations"]["ViscoElastic"] = @benchmarkable visco_elastic_simulation(writevtk=false) +SUITE["Simulations"]["ViscoElastic"] = @benchmarkable visco_elastic_simulation(writevtk=false, verbose=false) From bd3dd596bb226c6eeb84208e5cd3a6df2690a942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 12:01:15 +0100 Subject: [PATCH 05/14] static mech bench --- .../StaticMechanicalDirichletBenchmark.jl | 6 ++++++ benchmark/SimulationsBenchmarks/benchmarks.jl | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 benchmark/SimulationsBenchmarks/StaticMechanicalDirichletBenchmark.jl diff --git a/benchmark/SimulationsBenchmarks/StaticMechanicalDirichletBenchmark.jl b/benchmark/SimulationsBenchmarks/StaticMechanicalDirichletBenchmark.jl new file mode 100644 index 0000000..6216136 --- /dev/null +++ b/benchmark/SimulationsBenchmarks/StaticMechanicalDirichletBenchmark.jl @@ -0,0 +1,6 @@ + +BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) +filename = joinpath(BASE_FOLDER, "test/data/StaticMechanicalDirichletSimulation.jl") +include(filename) + +SUITE["Simulations"]["StaticMechanicalDirichlet"] = @benchmarkable static_mechanical_dirichlet_simulation(writevtk=false, verbose=false) diff --git a/benchmark/SimulationsBenchmarks/benchmarks.jl b/benchmark/SimulationsBenchmarks/benchmarks.jl index f0042f9..3dc0f65 100644 --- a/benchmark/SimulationsBenchmarks/benchmarks.jl +++ b/benchmark/SimulationsBenchmarks/benchmarks.jl @@ -2,3 +2,5 @@ SUITE["Simulations"] = BenchmarkGroup() include("ViscoElasticSimulationBenchmark.jl") + +include("StaticMechanicalDirichletBenchmark.jl") From c3ce5789a8e0ebe67532e668f5fa9fd252973ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 14:54:39 +0100 Subject: [PATCH 06/14] added neumann simulation --- .../StaticMechanicalDirichletSimulation.jl | 11 ++- .../data/StaticMechanicalNeumannSimulation.jl | 89 +++++++++++++++++++ 2 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 test/data/StaticMechanicalNeumannSimulation.jl diff --git a/test/data/StaticMechanicalDirichletSimulation.jl b/test/data/StaticMechanicalDirichletSimulation.jl index 1eaa1c8..b6a3898 100644 --- a/test/data/StaticMechanicalDirichletSimulation.jl +++ b/test/data/StaticMechanicalDirichletSimulation.jl @@ -10,7 +10,9 @@ using HyperFEM.ComputationalModels.CartesianTags function static_mechanical_dirichlet_simulation(;writevtk=true, verbose=true) pname = "Stretch" - + simdir = datadir("sims", pname) + setupfolder(simdir) + long = 0.05 # m width = 0.005 # m thick = 0.002 # m @@ -19,9 +21,6 @@ function static_mechanical_dirichlet_simulation(;writevtk=true, verbose=true) add_tag_from_tags!(labels, "fixed", CartesianTags.faceX0) add_tag_from_tags!(labels, "moving", CartesianTags.faceX1) - simdir = datadir("sims", pname) - setupfolder(simdir) - physmodel = MooneyRivlin3D(λ=3.0, μ1=1.0, μ2=0.0, ρ=1.0) # Setup integration @@ -48,9 +47,9 @@ function static_mechanical_dirichlet_simulation(;writevtk=true, verbose=true) #computational model ls = LUSolver() - nls_ = NewtonSolver(ls; maxiter=15, rtol=1.e-12, verbose=verbose) + nls = NewtonSolver(ls; maxiter=15, rtol=1.e-12, verbose=verbose) - comp_model = StaticNonlinearModel(res, jac, U, V, D_bc; nls=nls_) + comp_model = StaticNonlinearModel(res, jac, U, V, D_bc; nls=nls) function driverpost_mech(post) if writevtk diff --git a/test/data/StaticMechanicalNeumannSimulation.jl b/test/data/StaticMechanicalNeumannSimulation.jl new file mode 100644 index 0000000..e59c9ee --- /dev/null +++ b/test/data/StaticMechanicalNeumannSimulation.jl @@ -0,0 +1,89 @@ +using Gridap, GridapGmsh, GridapSolvers, DrWatson +using GridapSolvers.NonlinearSolvers +using GridapSolvers.LinearSolvers +using TimerOutputs +using Gridap.FESpaces +using HyperFEM +using HyperFEM.ComputationalModels.CartesianTags + + +function static_mechanical_neumann_simulation(;writevtk=true, verbose=true) + + pname = "StaticMechanical" + simdir = datadir("sims", pname) + setupfolder(simdir) + + long = 0.05 # m + width = 0.005 # m + thick = 0.002 # m + geometry = CartesianDiscreteModel((0, long, 0, width, 0, thick), (5,2,2)) + labels = get_face_labeling(geometry) + add_tag_from_tags!(labels, "fixed", CartesianTags.faceX0) + add_tag_from_tags!(labels, "force", CartesianTags.faceX1) + + physmodel = MooneyRivlin3D(λ=3.0, μ1=1.0, μ2=0.0, ρ=1.0) + + # Setup integration + order = 1 + degree = 2 * order + 1 + Ω = Triangulation(geometry) + dΩ = Measure(Ω, degree) + + # Dirichlet conditions + dir_u_tags = ["fixed"] + dir_u_values = [[0.0, 0.0, 0.0]] + dir_u_timesteps = [Λ -> 1.0] + D_bc = DirichletBC(dir_u_tags, dir_u_values, dir_u_timesteps) + + # Neumann conditions + neu_F_tags = ["force"] + neu_F_values = [[0.0, 0.0, -1e-3]] + neu_F_timesteps = [Λ -> Λ] + N_bc = NeumannBC(neu_F_tags, neu_F_values, neu_F_timesteps) + dΓ = get_Neumann_dΓ(geometry, N_bc, degree) + + # FE spaces + reffeu = ReferenceFE(lagrangian, VectorValue{3,Float64}, order) + V = TestFESpace(Ω, reffeu, D_bc, conformity=:H1) + U = TrialFESpace(V, D_bc, 0.0) + + # residual and jacobian function of load factor + res(Λ) = (u, v) -> residual(physmodel, u, v, dΩ) + residual_Neumann(N_bc, v, dΓ, Λ) + jac(Λ) = (u, du, v) -> jacobian(physmodel, u, du, v, dΩ) + + ls = LUSolver() + nls = NewtonSolver(ls; maxiter=20, atol=1.e-10, rtol=1.e-8, verbose=verbose) + + comp_model = StaticNonlinearModel(res, jac, U, V, D_bc; nls=nls) + + function driverpost_mech(post) + if writevtk + state = post.comp_model.caches[3] + Λ_ = post.iter + Λ = post.Λ[Λ_] + xh = FEFunction(U, state) + pvd = post.cachevtk[3] + filePath = post.cachevtk[2] + if post.cachevtk[1] + Λstring = replace(string(round(Λ, digits=2)), "." => "_") + pvd[Λ_] = createvtk(Ω, + filePath * "/" * pname * "_Λ_" * Λstring * ".vtu", + cellfields=["u" => xh]) + end + end + end + + post_model = PostProcessor(comp_model, driverpost_mech; is_vtk=writevtk, filepath=simdir) + + @timeit pname begin + x = solve!(comp_model; stepping=(nsteps=8, maxbisec=0), post=post_model) + end + return x +end + + +if abspath(PROGRAM_FILE) == @__FILE__ + reset_timer!() + static_mechanical_neumann_simulation() + print_timer() +end From 2a5c0a476db743eac12bc9744126196dde263eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 14:56:42 +0100 Subject: [PATCH 07/14] added neumann test --- test/SimulationsTests/StaticMechanicalNeumannTest.jl | 8 ++++++++ test/SimulationsTests/runtests.jl | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 test/SimulationsTests/StaticMechanicalNeumannTest.jl diff --git a/test/SimulationsTests/StaticMechanicalNeumannTest.jl b/test/SimulationsTests/StaticMechanicalNeumannTest.jl new file mode 100644 index 0000000..64a3ec5 --- /dev/null +++ b/test/SimulationsTests/StaticMechanicalNeumannTest.jl @@ -0,0 +1,8 @@ + +BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) +filename = joinpath(BASE_FOLDER, "test/data/StaticMechanicalNeumannSimulation.jl") +include(filename) + +x = static_mechanical_neumann_simulation(writevtk=false, verbose=false) + +@test norm(x) ≈ 1.000148588846 diff --git a/test/SimulationsTests/runtests.jl b/test/SimulationsTests/runtests.jl index 61043fa..7bff736 100644 --- a/test/SimulationsTests/runtests.jl +++ b/test/SimulationsTests/runtests.jl @@ -8,4 +8,6 @@ using Test include("StaticMechanicalDirichletTest.jl") + include("StaticMechanicalNeumannTest.jl") + end From 6bca34ec082659a571eb9c9f05f0eda61554aea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 14:58:20 +0100 Subject: [PATCH 08/14] added neumann benchmark --- .../StaticMechanicalNeumannBenchmark.jl | 6 ++++++ benchmark/SimulationsBenchmarks/benchmarks.jl | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 benchmark/SimulationsBenchmarks/StaticMechanicalNeumannBenchmark.jl diff --git a/benchmark/SimulationsBenchmarks/StaticMechanicalNeumannBenchmark.jl b/benchmark/SimulationsBenchmarks/StaticMechanicalNeumannBenchmark.jl new file mode 100644 index 0000000..8d880ea --- /dev/null +++ b/benchmark/SimulationsBenchmarks/StaticMechanicalNeumannBenchmark.jl @@ -0,0 +1,6 @@ + +BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) +filename = joinpath(BASE_FOLDER, "test/data/StaticMechanicalNeumannSimulation.jl") +include(filename) + +SUITE["Simulations"]["StaticMechanicalNeumann"] = @benchmarkable static_mechanical_neumann_simulation(writevtk=false, verbose=false) diff --git a/benchmark/SimulationsBenchmarks/benchmarks.jl b/benchmark/SimulationsBenchmarks/benchmarks.jl index 3dc0f65..05bc7cd 100644 --- a/benchmark/SimulationsBenchmarks/benchmarks.jl +++ b/benchmark/SimulationsBenchmarks/benchmarks.jl @@ -4,3 +4,5 @@ SUITE["Simulations"] = BenchmarkGroup() include("ViscoElasticSimulationBenchmark.jl") include("StaticMechanicalDirichletBenchmark.jl") + +include("StaticMechanicalNeumannBenchmark.jl") From 9a3a3313725c5153b5d485da7aefa00551c36ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 19:43:48 +0100 Subject: [PATCH 09/14] helper functions --- src/Exports.jl | 8 +++----- src/HyperFEM.jl | 6 +----- src/Io.jl | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Exports.jl b/src/Exports.jl index 272e6db..47831df 100644 --- a/src/Exports.jl +++ b/src/Exports.jl @@ -135,8 +135,6 @@ end @publish Solvers Roman_LS @publish Solvers update_cellstate! - - - -# @publish LinearSolvers solve -# @publish LinearSolvers solve! \ No newline at end of file +export setupfolder +export projdir +export filedir diff --git a/src/HyperFEM.jl b/src/HyperFEM.jl index 1a52061..6a8ff3e 100644 --- a/src/HyperFEM.jl +++ b/src/HyperFEM.jl @@ -1,8 +1,5 @@ module HyperFEM -using TimerOutputs - - include("TensorAlgebra/TensorAlgebra.jl") include("PhysicalModels/PhysicalModels.jl") include("WeakForms/WeakForms.jl") @@ -10,7 +7,6 @@ include("Solvers/Solvers.jl") include("ComputationalModels/ComputationalModels.jl") include("Io.jl") -export setupfolder - include("Exports.jl") + end diff --git a/src/Io.jl b/src/Io.jl index affff38..ce66d61 100644 --- a/src/Io.jl +++ b/src/Io.jl @@ -31,3 +31,26 @@ end function cleandir(::String, ::Nothing) end + +""" +Return the path to the specified folders relative to the HyperFEM path. + +# Examples + folder = projdir("data", "sims") + folder = projdir("test/data/mesh.msh") +""" +function projdir(folders::String...) + base_folder = dirname(dirname(pathof(HyperFEM))) + joinpath(base_folder, folders...) +end + +""" +Return the path to the specified folders relative to the file from which this function is being called. + +# Examples + outpath = filedir("results") +""" +function filedir(folders::String...) + base_folder = dirname(@__FILE__) + joinpath(base_folder, folders...) +end From 3943bf777f6466fb21e62017d17c20ff496965b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 19:44:32 +0100 Subject: [PATCH 10/14] using helper functions in tests --- .../StaticMechanicalDirichletBenchmark.jl | 3 +-- .../SimulationsBenchmarks/StaticMechanicalNeumannBenchmark.jl | 3 +-- .../SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl | 3 +-- test/SimulationsTests/StaticMechanicalDirichletTest.jl | 3 +-- test/SimulationsTests/StaticMechanicalNeumannTest.jl | 3 +-- test/SimulationsTests/ViscoElasticSimulationTest.jl | 3 +-- test/TestConstitutiveModels/PhysicalModelTests.jl | 3 +-- 7 files changed, 7 insertions(+), 14 deletions(-) diff --git a/benchmark/SimulationsBenchmarks/StaticMechanicalDirichletBenchmark.jl b/benchmark/SimulationsBenchmarks/StaticMechanicalDirichletBenchmark.jl index 6216136..b94c47d 100644 --- a/benchmark/SimulationsBenchmarks/StaticMechanicalDirichletBenchmark.jl +++ b/benchmark/SimulationsBenchmarks/StaticMechanicalDirichletBenchmark.jl @@ -1,6 +1,5 @@ -BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) -filename = joinpath(BASE_FOLDER, "test/data/StaticMechanicalDirichletSimulation.jl") +filename = projdir("test/data/StaticMechanicalDirichletSimulation.jl") include(filename) SUITE["Simulations"]["StaticMechanicalDirichlet"] = @benchmarkable static_mechanical_dirichlet_simulation(writevtk=false, verbose=false) diff --git a/benchmark/SimulationsBenchmarks/StaticMechanicalNeumannBenchmark.jl b/benchmark/SimulationsBenchmarks/StaticMechanicalNeumannBenchmark.jl index 8d880ea..5c396ae 100644 --- a/benchmark/SimulationsBenchmarks/StaticMechanicalNeumannBenchmark.jl +++ b/benchmark/SimulationsBenchmarks/StaticMechanicalNeumannBenchmark.jl @@ -1,6 +1,5 @@ -BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) -filename = joinpath(BASE_FOLDER, "test/data/StaticMechanicalNeumannSimulation.jl") +filename = projdir("test/data/StaticMechanicalNeumannSimulation.jl") include(filename) SUITE["Simulations"]["StaticMechanicalNeumann"] = @benchmarkable static_mechanical_neumann_simulation(writevtk=false, verbose=false) diff --git a/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl b/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl index 5bd29e7..5bed0d9 100644 --- a/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl +++ b/benchmark/SimulationsBenchmarks/ViscoElasticSimulationBenchmark.jl @@ -1,6 +1,5 @@ -BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) -filename = joinpath(BASE_FOLDER, "test/data/ViscoElasticSimulation.jl") +filename = projdir("test/data/ViscoElasticSimulation.jl") include(filename) SUITE["Simulations"]["ViscoElastic"] = @benchmarkable visco_elastic_simulation(writevtk=false, verbose=false) diff --git a/test/SimulationsTests/StaticMechanicalDirichletTest.jl b/test/SimulationsTests/StaticMechanicalDirichletTest.jl index cd0d743..f104686 100644 --- a/test/SimulationsTests/StaticMechanicalDirichletTest.jl +++ b/test/SimulationsTests/StaticMechanicalDirichletTest.jl @@ -1,6 +1,5 @@ -BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) -filename = joinpath(BASE_FOLDER, "test/data/StaticMechanicalDirichletSimulation.jl") +filename = projdir("test/data/StaticMechanicalDirichletSimulation.jl") include(filename) x = static_mechanical_dirichlet_simulation(writevtk=false, verbose=false) diff --git a/test/SimulationsTests/StaticMechanicalNeumannTest.jl b/test/SimulationsTests/StaticMechanicalNeumannTest.jl index 64a3ec5..262674d 100644 --- a/test/SimulationsTests/StaticMechanicalNeumannTest.jl +++ b/test/SimulationsTests/StaticMechanicalNeumannTest.jl @@ -1,6 +1,5 @@ -BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) -filename = joinpath(BASE_FOLDER, "test/data/StaticMechanicalNeumannSimulation.jl") +filename = projdir("test/data/StaticMechanicalNeumannSimulation.jl") include(filename) x = static_mechanical_neumann_simulation(writevtk=false, verbose=false) diff --git a/test/SimulationsTests/ViscoElasticSimulationTest.jl b/test/SimulationsTests/ViscoElasticSimulationTest.jl index 35f1af0..f75d321 100644 --- a/test/SimulationsTests/ViscoElasticSimulationTest.jl +++ b/test/SimulationsTests/ViscoElasticSimulationTest.jl @@ -1,6 +1,5 @@ -BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) -filename = joinpath(BASE_FOLDER, "test/data/ViscoElasticSimulation.jl") +filename = projdir("test/data/ViscoElasticSimulation.jl") include(filename) λx, σΓ = visco_elastic_simulation(t_end=5, writevtk=false, verbose=false) diff --git a/test/TestConstitutiveModels/PhysicalModelTests.jl b/test/TestConstitutiveModels/PhysicalModelTests.jl index ee6ebc1..30ab71d 100644 --- a/test/TestConstitutiveModels/PhysicalModelTests.jl +++ b/test/TestConstitutiveModels/PhysicalModelTests.jl @@ -510,8 +510,7 @@ end return n_layers, Weights, Biases, ϵ, β end - BASE_FOLDER = dirname(dirname(pathof(HyperFEM))) - data_filename = joinpath(BASE_FOLDER, "test/models/test_NN_TEM.json") + data_filename = projdir("test/models/test_NN_TEM.json") n_layers, Weights, Biases, ϵ, β = ExtractingInfo(data_filename) model = ThermoElectroMech_PINNs(; W=Weights, b=Biases, ϵ=ϵ, β=β, nLayer=n_layers) From d572b25f0aac67293112a2ed114e8d9d0982165e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 19:45:01 +0100 Subject: [PATCH 11/14] Fix tests: removed GridapGmsh, DrWatson --- test/data/StaticMechanicalDirichletSimulation.jl | 4 ++-- test/data/StaticMechanicalNeumannSimulation.jl | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/data/StaticMechanicalDirichletSimulation.jl b/test/data/StaticMechanicalDirichletSimulation.jl index b6a3898..65b9e52 100644 --- a/test/data/StaticMechanicalDirichletSimulation.jl +++ b/test/data/StaticMechanicalDirichletSimulation.jl @@ -1,4 +1,4 @@ -using Gridap, GridapGmsh, GridapSolvers, DrWatson +using Gridap, GridapSolvers using GridapSolvers.NonlinearSolvers using GridapSolvers.LinearSolvers using TimerOutputs @@ -10,7 +10,7 @@ using HyperFEM.ComputationalModels.CartesianTags function static_mechanical_dirichlet_simulation(;writevtk=true, verbose=true) pname = "Stretch" - simdir = datadir("sims", pname) + simdir = projdir("data", "sims", pname) setupfolder(simdir) long = 0.05 # m diff --git a/test/data/StaticMechanicalNeumannSimulation.jl b/test/data/StaticMechanicalNeumannSimulation.jl index e59c9ee..955ade2 100644 --- a/test/data/StaticMechanicalNeumannSimulation.jl +++ b/test/data/StaticMechanicalNeumannSimulation.jl @@ -1,4 +1,4 @@ -using Gridap, GridapGmsh, GridapSolvers, DrWatson +using Gridap, GridapSolvers using GridapSolvers.NonlinearSolvers using GridapSolvers.LinearSolvers using TimerOutputs @@ -10,9 +10,9 @@ using HyperFEM.ComputationalModels.CartesianTags function static_mechanical_neumann_simulation(;writevtk=true, verbose=true) pname = "StaticMechanical" - simdir = datadir("sims", pname) + simdir = projdir("data", "sims", pname) setupfolder(simdir) - + long = 0.05 # m width = 0.005 # m thick = 0.002 # m From aa6ae59742242c38904d6e674e1cc1c6f4d32bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 4 Nov 2025 19:59:35 +0100 Subject: [PATCH 12/14] Fix tests: added TimerOutputs --- benchmark/Project.toml | 1 + test/Project.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/benchmark/Project.toml b/benchmark/Project.toml index d24eda8..69726fa 100644 --- a/benchmark/Project.toml +++ b/benchmark/Project.toml @@ -3,3 +3,4 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e" GridapGmsh = "3025c34a-b394-11e9-2a55-3fee550c04c8" GridapSolvers = "6d3209ee-5e3c-4db7-a716-942eb12ed534" +TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" diff --git a/test/Project.toml b/test/Project.toml index 81723d2..d898967 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -5,3 +5,4 @@ GridapSolvers = "6d3209ee-5e3c-4db7-a716-942eb12ed534" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" From e3a2858e50417a3555330b699ef8292e7e2852b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Wed, 5 Nov 2025 12:35:52 +0100 Subject: [PATCH 13/14] removed dangerous function --- src/Io.jl | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Io.jl b/src/Io.jl index ce66d61..8c2853e 100644 --- a/src/Io.jl +++ b/src/Io.jl @@ -43,14 +43,3 @@ function projdir(folders::String...) base_folder = dirname(dirname(pathof(HyperFEM))) joinpath(base_folder, folders...) end - -""" -Return the path to the specified folders relative to the file from which this function is being called. - -# Examples - outpath = filedir("results") -""" -function filedir(folders::String...) - base_folder = dirname(@__FILE__) - joinpath(base_folder, folders...) -end From 50a994571531c9cb4290a0b9fcc5e0bfdfb341c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Thu, 6 Nov 2025 10:02:36 +0100 Subject: [PATCH 14/14] updated kinematics --- test/data/StaticMechanicalDirichletSimulation.jl | 5 +++-- test/data/StaticMechanicalNeumannSimulation.jl | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/data/StaticMechanicalDirichletSimulation.jl b/test/data/StaticMechanicalDirichletSimulation.jl index 65b9e52..1bb0688 100644 --- a/test/data/StaticMechanicalDirichletSimulation.jl +++ b/test/data/StaticMechanicalDirichletSimulation.jl @@ -42,8 +42,9 @@ function static_mechanical_dirichlet_simulation(;writevtk=true, verbose=true) U = TrialFESpace(V, D_bc, 0.0) # residual and jacobian function of load factor - res(Λ) = (u, v) -> residual(physmodel, u, v, dΩ) - jac(Λ) = (u, du, v) -> jacobian(physmodel, u, du, v, dΩ) + k = Kinematics(Mechano, Solid) + res(Λ) = (u, v) -> residual(physmodel, k, u, v, dΩ) + jac(Λ) = (u, du, v) -> jacobian(physmodel, k, u, du, v, dΩ) #computational model ls = LUSolver() diff --git a/test/data/StaticMechanicalNeumannSimulation.jl b/test/data/StaticMechanicalNeumannSimulation.jl index 955ade2..718863c 100644 --- a/test/data/StaticMechanicalNeumannSimulation.jl +++ b/test/data/StaticMechanicalNeumannSimulation.jl @@ -48,8 +48,9 @@ function static_mechanical_neumann_simulation(;writevtk=true, verbose=true) U = TrialFESpace(V, D_bc, 0.0) # residual and jacobian function of load factor - res(Λ) = (u, v) -> residual(physmodel, u, v, dΩ) + residual_Neumann(N_bc, v, dΓ, Λ) - jac(Λ) = (u, du, v) -> jacobian(physmodel, u, du, v, dΩ) + k = Kinematics(Mechano, Solid) + res(Λ) = (u, v) -> residual(physmodel, k, u, v, dΩ) + residual_Neumann(N_bc, v, dΓ, Λ) + jac(Λ) = (u, du, v) -> jacobian(physmodel, k, u, du, v, dΩ) ls = LUSolver() nls = NewtonSolver(ls; maxiter=20, atol=1.e-10, rtol=1.e-8, verbose=verbose)