Skip to content

Commit 13fd168

Browse files
Add Elixir for Measurements.jl (#2504)
* Add Elixir for Measurements.jl * ci * typo * Update test/test_tree_1d_advection.jl Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> * Update examples/tree_1d_dgsem/elixir_advection_uncertainty.jl * fmt --------- Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com>
1 parent 035aec0 commit 13fd168

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Trixi
2+
using OrdinaryDiffEqLowStorageRK
3+
using Measurements # For propagating uncertainty/measurement errors in parameters
4+
5+
# Note the `±` operator for defining uncertain parameters
6+
equations = LinearScalarAdvectionEquation1D(1.0 ± 0.1)
7+
8+
x_min = (-1.0,)
9+
x_max = (1.0,)
10+
mesh = TreeMesh(x_min, x_max,
11+
n_cells_max = 10^5, initial_refinement_level = 5)
12+
13+
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
14+
15+
RealT = Measurement{Float64} # Measurement datatype
16+
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
17+
solver, uEltype = RealT)
18+
19+
tspan = (0.0, 1.5)
20+
ode = semidiscretize(semi, tspan)
21+
22+
summary_callback = SummaryCallback()
23+
analysis_callback = AnalysisCallback(semi, interval = 50)
24+
25+
callbacks = CallbackSet(summary_callback, analysis_callback)
26+
27+
###############################################################################
28+
# run the simulation
29+
30+
sol = solve(ode, RDPK3SpFSAL49();
31+
ode_default_options()..., callback = callbacks);

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
1212
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
1313
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1414
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
15+
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
1516
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
1617
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
1718
OrdinaryDiffEqFeagin = "101fe9f7-ebb6-4678-b671-3a81e7194747"
@@ -43,6 +44,7 @@ ECOS = "1.1.2"
4344
ExplicitImports = "1.0.1"
4445
ForwardDiff = "0.10.36, 1"
4546
LinearAlgebra = "1"
47+
Measurements = "2.14.0"
4648
MPI = "0.20.6"
4749
NLsolve = "4.5.1"
4850
OrdinaryDiffEqFeagin = "1"

test/test_tree_1d_advection.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ end
169169
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
170170
end
171171
end
172+
173+
@trixi_testset "elixir_advection_uncertainty.jl" begin
174+
# Run this first to collect LoopVectorization warnings before error-check run
175+
@test_nowarn_mod trixi_include(joinpath(examples_dir(), "tree_1d_dgsem",
176+
"elixir_advection_uncertainty.jl"))
177+
178+
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_uncertainty.jl"),
179+
l2=[0.0012576893000440965 ± 0.017581020765034417],
180+
linf=[0.004425204509676317 ± 0.0633672486044246])
181+
# Using Measurements.jl actually allocates quite significantly
182+
let
183+
t = sol.t[end]
184+
u_ode = sol.u[end]
185+
du_ode = similar(u_ode)
186+
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 100_000
187+
end
188+
end
172189
end
173190

174191
end # module

test/test_trixi.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ macro test_nowarn_mod(expr, additional_ignore_content = [])
120120
# Warnings from third party packages
121121
r"┌ Warning: Problem status ALMOST_INFEASIBLE; solution may be inaccurate.\n└ @ Convex ~/.julia/packages/Convex/.*\n",
122122
r"┌ Warning: Problem status ALMOST_OPTIMAL; solution may be inaccurate.\n└ @ Convex ~/.julia/packages/Convex/.*\n",
123-
# Warnings for higher-precision floating data types
123+
# Warnings for higher-precision floating data types or Measurements.jl
124124
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",
125125
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"
126126
]

0 commit comments

Comments
 (0)