From e8160ea09aa92232ff7f41b38d5b7f727a7521e9 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Mon, 28 Jul 2025 16:01:12 +0200 Subject: [PATCH 1/6] Add Elixir for Measurements.jl --- .../elixir_advection_uncertainty.jl | 37 +++++++++++++++++++ test/Project.toml | 2 + test/test_special_elixirs.jl | 5 +++ 3 files changed, 44 insertions(+) create mode 100644 examples/tree_1d_dgsem/elixir_advection_uncertainty.jl diff --git a/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl b/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl new file mode 100644 index 00000000000..eb44f241643 --- /dev/null +++ b/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl @@ -0,0 +1,37 @@ +using Trixi +using OrdinaryDiffEqLowStorageRK +using Measurements # For propagating uncertainty/measurement errors in parameters + +# Note the `±` operator for defining uncertain parameters +equations = LinearScalarAdvectionEquation1D(1.0 ± 0.1) + +x_min = (-1.0) +x_max = (1.0) +mesh = TreeMesh(x_min, x_max, + n_cells_max = 10^5, initial_refinement_level = 5) + +solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) + +RealT = Measurement{Float64} # Measurement datatype +semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test, + solver, uEltype = RealT) + +tspan = (0.0, 1.5) +ode = semidiscretize(semi, tspan) + +summary_callback = SummaryCallback() +alive_callback = AliveCallback(alive_interval = 5) + +callbacks = CallbackSet(summary_callback, alive_callback) + +############################################################################### +# run the simulation + +sol = solve(ode, RDPK3SpFSAL49(); + ode_default_options()..., callback = callbacks); + +############################################################################### +# visualize results + +using Plots +plot(sol) diff --git a/test/Project.toml b/test/Project.toml index b085cf23860..1d578e2fe66 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -13,6 +13,7 @@ ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7" FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56" OrdinaryDiffEqFeagin = "101fe9f7-ebb6-4678-b671-3a81e7194747" @@ -45,6 +46,7 @@ ExplicitImports = "1.0.1" FFMPEG = "0.4" ForwardDiff = "0.10.36, 1" LinearAlgebra = "1" +Measurements = "2.14.0" MPI = "0.20.6" NLsolve = "4.5.1" OrdinaryDiffEqFeagin = "1" diff --git a/test/test_special_elixirs.jl b/test/test_special_elixirs.jl index 77dec71f8ca..179fe79d8b2 100644 --- a/test/test_special_elixirs.jl +++ b/test/test_special_elixirs.jl @@ -332,6 +332,11 @@ end "elixir_euler_ad.jl")) end end + +@timed_testset "Measurements" begin + @test_nowarn_mod trixi_include(joinpath(examples_dir(), "tree_1d_dgsem", + "elixir_advection_uncertainty.jl")) +end end # Clean up afterwards: delete Trixi.jl output directory From 55569a514648f9a06aa7a56d497d46e86d097fe3 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Tue, 29 Jul 2025 10:18:59 +0200 Subject: [PATCH 2/6] ci --- .../elixir_advection_uncertainty.jl | 8 ++++---- test/test_special_elixirs.jl | 5 ----- test/test_tree_1d_advection.jl | 17 +++++++++++++++++ test/test_trixi.jl | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl b/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl index eb44f241643..74ef5309912 100644 --- a/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl +++ b/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl @@ -5,8 +5,8 @@ using Measurements # For propagating uncertainty/measurement errors in parameter # Note the `±` operator for defining uncertain parameters equations = LinearScalarAdvectionEquation1D(1.0 ± 0.1) -x_min = (-1.0) -x_max = (1.0) +x_min = (-1.0,) +x_max = (1.0,) mesh = TreeMesh(x_min, x_max, n_cells_max = 10^5, initial_refinement_level = 5) @@ -20,9 +20,9 @@ tspan = (0.0, 1.5) ode = semidiscretize(semi, tspan) summary_callback = SummaryCallback() -alive_callback = AliveCallback(alive_interval = 5) +analysis_callback = AnalysisCallback(semi, interval = 50) -callbacks = CallbackSet(summary_callback, alive_callback) +callbacks = CallbackSet(summary_callback, analysis_callback) ############################################################################### # run the simulation diff --git a/test/test_special_elixirs.jl b/test/test_special_elixirs.jl index 179fe79d8b2..77dec71f8ca 100644 --- a/test/test_special_elixirs.jl +++ b/test/test_special_elixirs.jl @@ -332,11 +332,6 @@ end "elixir_euler_ad.jl")) end end - -@timed_testset "Measurements" begin - @test_nowarn_mod trixi_include(joinpath(examples_dir(), "tree_1d_dgsem", - "elixir_advection_uncertainty.jl")) -end end # Clean up afterwards: delete Trixi.jl output directory diff --git a/test/test_tree_1d_advection.jl b/test/test_tree_1d_advection.jl index ebc78c063e8..004a7d58320 100644 --- a/test/test_tree_1d_advection.jl +++ b/test/test_tree_1d_advection.jl @@ -169,6 +169,23 @@ end @test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000 end end + +@trixi_testset "elixir_advection_uncertainty.jl" begin + # Run this first to collect LoopVectorization warnings before error-check run + @test_nowarn_mod trixi_include(joinpath(examples_dir(), "tree_1d_dgsem", + "elixir_advection_uncertainty.jl")) + + @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_uncertainty.jl"), + l2=Measurement{Float64}[0.0012576893000440965 ± 0.017581020765034417], + linf=Measurement{Float64}[0.004425204509676317 ± 0.0633672486044246]) + # Using Measurements.jl actually allocotes quite significantly + let + t = sol.t[end] + u_ode = sol.u[end] + du_ode = similar(u_ode) + @test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 100_000 + end +end end end # module diff --git a/test/test_trixi.jl b/test/test_trixi.jl index 00baf2162d0..d20a325cb8c 100644 --- a/test/test_trixi.jl +++ b/test/test_trixi.jl @@ -120,7 +120,7 @@ macro test_nowarn_mod(expr, additional_ignore_content = []) # Warnings from third party packages r"┌ Warning: Problem status ALMOST_INFEASIBLE; solution may be inaccurate.\n└ @ Convex ~/.julia/packages/Convex/.*\n", r"┌ Warning: Problem status ALMOST_OPTIMAL; solution may be inaccurate.\n└ @ Convex ~/.julia/packages/Convex/.*\n", - # Warnings for higher-precision floating data types + # Warnings for higher-precision floating data types or Measurements.jl r"┌ Warning: #= /home/runner/work/Trixi.jl/Trixi.jl/src/solvers/dgsem/interpolation.jl:118 =#:\n│ `LoopVectorization.check_args` on your inputs failed; running fallback `@inbounds @fastmath` loop instead.\n│ Use `warn_check_args=false`, e.g. `@turbo warn_check_args=false ...`, to disable this warning.\n└ @ Trixi ~/.julia/packages/LoopVectorization/.*\n", r"┌ Warning: #= /home/runner/work/Trixi.jl/Trixi.jl/src/solvers/dgsem/interpolation.jl:136 =#:\n│ `LoopVectorization.check_args` on your inputs failed; running fallback `@inbounds @fastmath` loop instead.\n│ Use `warn_check_args=false`, e.g. `@turbo warn_check_args=false ...`, to disable this warning.\n└ @ Trixi ~/.julia/packages/LoopVectorization/.*\n" ] From 4bf400b0154736b192eae0031ded2faaeb5e958b Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Tue, 29 Jul 2025 10:19:52 +0200 Subject: [PATCH 3/6] typo --- test/test_tree_1d_advection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_tree_1d_advection.jl b/test/test_tree_1d_advection.jl index 004a7d58320..e5ee2e46a05 100644 --- a/test/test_tree_1d_advection.jl +++ b/test/test_tree_1d_advection.jl @@ -178,7 +178,7 @@ end @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_uncertainty.jl"), l2=Measurement{Float64}[0.0012576893000440965 ± 0.017581020765034417], linf=Measurement{Float64}[0.004425204509676317 ± 0.0633672486044246]) - # Using Measurements.jl actually allocotes quite significantly + # Using Measurements.jl actually allocates quite significantly let t = sol.t[end] u_ode = sol.u[end] From 36225121b50d1250fe2afbbc9b1279aeadd5caaa Mon Sep 17 00:00:00 2001 From: Daniel Doehring Date: Tue, 29 Jul 2025 17:18:50 +0200 Subject: [PATCH 4/6] Update test/test_tree_1d_advection.jl Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> --- test/test_tree_1d_advection.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_tree_1d_advection.jl b/test/test_tree_1d_advection.jl index e5ee2e46a05..b1644b9d0b4 100644 --- a/test/test_tree_1d_advection.jl +++ b/test/test_tree_1d_advection.jl @@ -176,8 +176,8 @@ end "elixir_advection_uncertainty.jl")) @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_uncertainty.jl"), - l2=Measurement{Float64}[0.0012576893000440965 ± 0.017581020765034417], - linf=Measurement{Float64}[0.004425204509676317 ± 0.0633672486044246]) + l2=[0.0012576893000440965 ± 0.017581020765034417], + linf=[0.004425204509676317 ± 0.0633672486044246]) # Using Measurements.jl actually allocates quite significantly let t = sol.t[end] From 9aab5a87ae6c57c6547dbe3237cbe25843a106f3 Mon Sep 17 00:00:00 2001 From: Daniel Doehring Date: Tue, 29 Jul 2025 17:20:08 +0200 Subject: [PATCH 5/6] Update examples/tree_1d_dgsem/elixir_advection_uncertainty.jl --- examples/tree_1d_dgsem/elixir_advection_uncertainty.jl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl b/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl index 74ef5309912..145e4130c37 100644 --- a/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl +++ b/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl @@ -30,8 +30,3 @@ callbacks = CallbackSet(summary_callback, analysis_callback) sol = solve(ode, RDPK3SpFSAL49(); ode_default_options()..., callback = callbacks); -############################################################################### -# visualize results - -using Plots -plot(sol) From a94dd4776e6d1b7d3b34e0f99c7842ca9459d128 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Tue, 29 Jul 2025 17:28:44 +0200 Subject: [PATCH 6/6] fmt --- examples/tree_1d_dgsem/elixir_advection_uncertainty.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl b/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl index 145e4130c37..8796d03b094 100644 --- a/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl +++ b/examples/tree_1d_dgsem/elixir_advection_uncertainty.jl @@ -29,4 +29,3 @@ callbacks = CallbackSet(summary_callback, analysis_callback) sol = solve(ode, RDPK3SpFSAL49(); ode_default_options()..., callback = callbacks); -