From 424772c7bb85b3135539ea20c1bced6af982dd87 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Thu, 23 Nov 2023 13:57:23 +0100 Subject: [PATCH 01/14] Make error norm calculation optional --- src/callbacks_step/analysis.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index e5b4a01a885..46012def62d 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -377,8 +377,14 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi) println() end - # Calculate L2/Linf errors, which are also returned - l2_error, linf_error = calc_error_norms(u_ode, t, analyzer, semi, cache_analysis) + if :l2_error in analysis_errors || :linf_error in analysis_errors + # Calculate L2/Linf errors, which are also returned + l2_error, linf_error = calc_error_norms(u_ode, t, analyzer, semi, + cache_analysis) + else # Need something to be returned + l2_error = nothing + linf_error = nothing + end if mpi_isroot() # L2 error From f1df5feb8b9a9f5a4b242ae47da1172be91dc355 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Thu, 23 Nov 2023 16:10:37 +0100 Subject: [PATCH 02/14] test no errors --- test/test_tree_1d_advection.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test_tree_1d_advection.jl b/test/test_tree_1d_advection.jl index 7cfd78e0ade..1bd3847f302 100644 --- a/test/test_tree_1d_advection.jl +++ b/test/test_tree_1d_advection.jl @@ -54,6 +54,20 @@ end end end +@trixi_testset "elixir_advection_basic.jl" begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic.jl"), + analysis_callback=AnalysisCallback(semi, interval = 42, + analysis_errors = Symbol[])) + # Ensure that we do not have excessive memory allocations + # (e.g., from type instabilities) + 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)) < 1000 + end +end + @trixi_testset "elixir_advection_finite_volume.jl" begin @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_finite_volume.jl"), l2=[0.011662300515980219], From bbe3db03175033f8efe0a65ce637d04aeaf3a0dd Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Thu, 23 Nov 2023 16:10:51 +0100 Subject: [PATCH 03/14] no errors --- 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 1bd3847f302..a580a3b5600 100644 --- a/test/test_tree_1d_advection.jl +++ b/test/test_tree_1d_advection.jl @@ -54,7 +54,7 @@ end end end -@trixi_testset "elixir_advection_basic.jl" begin +@trixi_testset "elixir_advection_basic.jl (No errors)" begin @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic.jl"), analysis_callback=AnalysisCallback(semi, interval = 42, analysis_errors = Symbol[])) From 694ed8ad446e45db2bb40750eb9e6b438b9c04dd Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Mon, 27 Nov 2023 08:54:09 +0100 Subject: [PATCH 04/14] comment more clear --- src/callbacks_step/analysis.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index 46012def62d..a204aa3047b 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -381,7 +381,8 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi) # Calculate L2/Linf errors, which are also returned l2_error, linf_error = calc_error_norms(u_ode, t, analyzer, semi, cache_analysis) - else # Need something to be returned + else + # Names `l2_error`, `linf_error` need to be defined l2_error = nothing linf_error = nothing end From a29625d592aca0ca651d274f19e68662884b07b1 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Sat, 2 Dec 2023 14:44:19 +0100 Subject: [PATCH 05/14] shorter version? --- src/callbacks_step/analysis.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index a204aa3047b..6d32c90084d 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -383,8 +383,9 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi) cache_analysis) else # Names `l2_error`, `linf_error` need to be defined - l2_error = nothing - linf_error = nothing + #l2_error = nothing + #linf_error = nothing + return nothing, nothing end if mpi_isroot() From d9023a7a8cdd5b3e8252f75eba84e732abaa8bb5 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Mon, 4 Dec 2023 15:48:02 +0100 Subject: [PATCH 06/14] add text --- src/callbacks_step/analysis.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index 6d32c90084d..26092ffb890 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -23,6 +23,12 @@ Additional errors can be computed, e.g. by passing `extra_analysis_errors = (:l2_error_primitive, :linf_error_primitive)` or `extra_analysis_errors = (:conservation_error,)`. +If you want to omit the computation (to safe compute-time) of the [`default_analysis_errors`](@ref), specify +`analysis_errors = Symbol[]`. +Note: `default_analysis_errors` are `:l2_error`, `:linf_error` for all equations. +If you want to include an `extra_analysis_error` such as `:conservation_error` you need to specify +`analysis_errors = [:conservation_error]` instead of `extra_analysis_errors = [:conservation_error]`. + Further scalar functions `func` in `extra_analysis_integrals` are applied to the numerical solution and integrated over the computational domain. Some examples for this are [`entropy`](@ref), [`energy_kinetic`](@ref), [`energy_internal`](@ref), and [`energy_total`](@ref). @@ -382,9 +388,6 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi) l2_error, linf_error = calc_error_norms(u_ode, t, analyzer, semi, cache_analysis) else - # Names `l2_error`, `linf_error` need to be defined - #l2_error = nothing - #linf_error = nothing return nothing, nothing end From 4e2ec38bcc11a8218767d574dd22a264f76b55a9 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Mon, 4 Dec 2023 15:49:36 +0100 Subject: [PATCH 07/14] update docstring --- src/callbacks_step/analysis.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index 26092ffb890..fa9f5f294e1 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -26,7 +26,8 @@ or `extra_analysis_errors = (:conservation_error,)`. If you want to omit the computation (to safe compute-time) of the [`default_analysis_errors`](@ref), specify `analysis_errors = Symbol[]`. Note: `default_analysis_errors` are `:l2_error`, `:linf_error` for all equations. -If you want to include an `extra_analysis_error` such as `:conservation_error` you need to specify +If you want to compute `extra_analysis_errors` such as `:conservation_error` solely, i.e., +without `:l2_error, :linf_error` you need to specify `analysis_errors = [:conservation_error]` instead of `extra_analysis_errors = [:conservation_error]`. Further scalar functions `func` in `extra_analysis_integrals` are applied to the numerical From 51d585cfc3736af10eb441c8af4b0bbb6b814da0 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Tue, 5 Dec 2023 08:49:42 +0100 Subject: [PATCH 08/14] cut error passing --- src/callbacks_step/analysis.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index fa9f5f294e1..db0e7350924 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -339,7 +339,8 @@ function (analysis_callback::AnalysisCallback)(u_ode, du_ode, integrator, semi) @notimeit timer() integrator.f(du_ode, u_ode, semi, t) u = wrap_array(u_ode, mesh, equations, solver, cache) du = wrap_array(du_ode, mesh, equations, solver, cache) - l2_error, linf_error = analysis_callback(io, du, u, u_ode, t, semi) + # Compute l2_error, linf_error + analysis_callback(io, du, u, u_ode, t, semi) mpi_println("─"^100) mpi_println() @@ -361,8 +362,7 @@ function (analysis_callback::AnalysisCallback)(u_ode, du_ode, integrator, semi) analysis_callback.start_time_last_analysis = time_ns() analysis_callback.ncalls_rhs_last_analysis = ncalls(semi.performance_counter) - # Return errors for EOC analysis - return l2_error, linf_error + return nothing end # This method is just called internally from `(analysis_callback::AnalysisCallback)(integrator)` @@ -389,7 +389,7 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi) l2_error, linf_error = calc_error_norms(u_ode, t, analyzer, semi, cache_analysis) else - return nothing, nothing + return nothing end if mpi_isroot() @@ -489,7 +489,7 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi) # additional integrals analyze_integrals(analysis_integrals, io, du, u, t, semi) - return l2_error, linf_error + return nothing end # Print level information only if AMR is enabled From 4e324c790728960ddcbdce5be2f73179a995b2d4 Mon Sep 17 00:00:00 2001 From: Daniel Doehring Date: Tue, 5 Dec 2023 09:30:54 +0100 Subject: [PATCH 09/14] Update src/callbacks_step/analysis.jl Co-authored-by: Hendrik Ranocha --- src/callbacks_step/analysis.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index db0e7350924..7091a8f9bce 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -25,7 +25,7 @@ or `extra_analysis_errors = (:conservation_error,)`. If you want to omit the computation (to safe compute-time) of the [`default_analysis_errors`](@ref), specify `analysis_errors = Symbol[]`. -Note: `default_analysis_errors` are `:l2_error`, `:linf_error` for all equations. +Note: `default_analysis_errors` are `:l2_error` and `:linf_error` for all equations. If you want to compute `extra_analysis_errors` such as `:conservation_error` solely, i.e., without `:l2_error, :linf_error` you need to specify `analysis_errors = [:conservation_error]` instead of `extra_analysis_errors = [:conservation_error]`. From b48d6af2722a87ff636c31a3f17ed96b3a4a268d Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Tue, 5 Dec 2023 09:34:39 +0100 Subject: [PATCH 10/14] print in if clause --- src/callbacks_step/analysis.jl | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index 7091a8f9bce..96874530da8 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -388,30 +388,30 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi) # Calculate L2/Linf errors, which are also returned l2_error, linf_error = calc_error_norms(u_ode, t, analyzer, semi, cache_analysis) - else - return nothing - end - if mpi_isroot() - # L2 error - if :l2_error in analysis_errors - print(" L2 error: ") - for v in eachvariable(equations) - @printf(" % 10.8e", l2_error[v]) - @printf(io, " % 10.8e", l2_error[v]) + if mpi_isroot() + # L2 error + if :l2_error in analysis_errors + print(" L2 error: ") + for v in eachvariable(equations) + @printf(" % 10.8e", l2_error[v]) + @printf(io, " % 10.8e", l2_error[v]) + end + println() end - println() - end - # Linf error - if :linf_error in analysis_errors - print(" Linf error: ") - for v in eachvariable(equations) - @printf(" % 10.8e", linf_error[v]) - @printf(io, " % 10.8e", linf_error[v]) + # Linf error + if :linf_error in analysis_errors + print(" Linf error: ") + for v in eachvariable(equations) + @printf(" % 10.8e", linf_error[v]) + @printf(io, " % 10.8e", linf_error[v]) + end + println() end - println() end + else + return nothing end # Conservation error From dd93e8f9c88eba677dd5116e13d4746478f38991 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Tue, 5 Dec 2023 09:36:30 +0100 Subject: [PATCH 11/14] shorten --- src/callbacks_step/analysis.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index 96874530da8..f17d3c61759 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -410,8 +410,6 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi) println() end end - else - return nothing end # Conservation error From 63abc06fde607b6860fc54bc7da51ef391bf1e1b Mon Sep 17 00:00:00 2001 From: Daniel Doehring Date: Tue, 5 Dec 2023 16:03:16 +0100 Subject: [PATCH 12/14] Update src/callbacks_step/analysis.jl Co-authored-by: Hendrik Ranocha --- src/callbacks_step/analysis.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index f17d3c61759..ba232032951 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -385,7 +385,7 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi) end if :l2_error in analysis_errors || :linf_error in analysis_errors - # Calculate L2/Linf errors, which are also returned + # Calculate L2/Linf errors l2_error, linf_error = calc_error_norms(u_ode, t, analyzer, semi, cache_analysis) From 826bdf512a166026f7fee8ecb01b08cc56c8a254 Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Tue, 5 Dec 2023 16:10:09 +0100 Subject: [PATCH 13/14] Add docstring for default_analysis_errors --- src/equations/equations.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/equations/equations.jl b/src/equations/equations.jl index ba2ad1cd1cd..c4eecdc251d 100644 --- a/src/equations/equations.jl +++ b/src/equations/equations.jl @@ -260,7 +260,13 @@ combined with certain solvers (e.g., subcell limiting). function n_nonconservative_terms end have_constant_speed(::AbstractEquations) = False() +""" + default_analysis_errors(equations) + +Default analysis errors (l2_error and linf_error) used by the [`AnalysisCallback`](@ref). +""" default_analysis_errors(::AbstractEquations) = (:l2_error, :linf_error) + """ default_analysis_integrals(equations) From 32172b065eb4e876cb93b20c73e996b25406c45d Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Wed, 6 Dec 2023 20:53:32 +0100 Subject: [PATCH 14/14] Update src/equations/equations.jl --- src/equations/equations.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/equations/equations.jl b/src/equations/equations.jl index c4eecdc251d..582d672b756 100644 --- a/src/equations/equations.jl +++ b/src/equations/equations.jl @@ -263,7 +263,8 @@ have_constant_speed(::AbstractEquations) = False() """ default_analysis_errors(equations) -Default analysis errors (l2_error and linf_error) used by the [`AnalysisCallback`](@ref). +Default analysis errors (`:l2_error` and `:linf_error`) used by the +[`AnalysisCallback`](@ref). """ default_analysis_errors(::AbstractEquations) = (:l2_error, :linf_error)