From 9d56c93a046cc6e8b9cc212144ba51e95c978a7f Mon Sep 17 00:00:00 2001 From: Warisa Date: Mon, 14 Oct 2024 20:45:54 +0200 Subject: [PATCH] change dt_opt to be that of b_opt and add a new example --- ...lixir_euler_source_terms_embedded_perk3.jl | 66 +++++++++++++++++++ .../elixir_advection_embedded_perk3.jl | 16 +++-- .../methods_embedded_PERK3.jl | 4 +- 3 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 examples/structured_1d_dgsem/elixir_euler_source_terms_embedded_perk3.jl diff --git a/examples/structured_1d_dgsem/elixir_euler_source_terms_embedded_perk3.jl b/examples/structured_1d_dgsem/elixir_euler_source_terms_embedded_perk3.jl new file mode 100644 index 00000000000..145eab169d8 --- /dev/null +++ b/examples/structured_1d_dgsem/elixir_euler_source_terms_embedded_perk3.jl @@ -0,0 +1,66 @@ +# The same setup as tree_1d_dgsem/elixir_euler_source_terms.jl +# to verify the StructuredMesh implementation against TreeMesh +using Convex, ECOS, Clarabel +using OrdinaryDiffEq +using Trixi + +############################################################################### +# semidiscretization of the compressible Euler equations + +equations = CompressibleEulerEquations1D(1.4) + +initial_condition = initial_condition_convergence_test + +# Note that the expected EOC of 5 is not reached with this flux. +# Using flux_hll instead yields the expected EOC. +solver = DGSEM(polydeg = 4, surface_flux = flux_lax_friedrichs) + +coordinates_min = (0.0,) +coordinates_max = (2.0,) +cells_per_dimension = (16,) + +mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max) + +semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, + source_terms = source_terms_convergence_test) + +############################################################################### +# ODE solvers, callbacks etc. + +tspan = (0.0, 2.0) +ode = semidiscretize(semi, tspan) + +summary_callback = SummaryCallback() + +analysis_interval = 100 +analysis_callback = AnalysisCallback(semi, interval = analysis_interval, + extra_analysis_errors = (:l2_error_primitive, + :linf_error_primitive)) + +alive_callback = AliveCallback(analysis_interval = analysis_interval) + +save_solution = SaveSolutionCallback(interval = 100, + save_initial_solution = true, + save_final_solution = true, + solution_variables = cons2prim) + + +ode_algorithm = Trixi.EmbeddedPairedRK3(10, 7, tspan, semi) +cfl_number = Trixi.calculate_cfl(ode_algorithm, ode) + +stepsize_callback = StepsizeCallback(cfl = 0.5) + +callbacks = CallbackSet(summary_callback, + alive_callback, + save_solution, + analysis_callback, + stepsize_callback) + +############################################################################### +# run the simulation + +sol = Trixi.solve(ode, ode_algorithm, + dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback + save_everystep = false, callback = callbacks); +summary_callback() # print the timer summary +println("cfl_number = ", cfl_number) \ No newline at end of file diff --git a/examples/tree_1d_dgsem/elixir_advection_embedded_perk3.jl b/examples/tree_1d_dgsem/elixir_advection_embedded_perk3.jl index a7f5eb19f06..46a2d1e7fe7 100644 --- a/examples/tree_1d_dgsem/elixir_advection_embedded_perk3.jl +++ b/examples/tree_1d_dgsem/elixir_advection_embedded_perk3.jl @@ -43,7 +43,7 @@ analysis_interval = 100 analysis_callback = AnalysisCallback(semi, interval = analysis_interval) # The StepsizeCallback handles the re-calculation of the maximum Δt after each time step -stepsize_callback = StepsizeCallback(cfl = 1.5) + alive_callback = AliveCallback(alive_interval = analysis_interval) @@ -53,11 +53,7 @@ save_solution = SaveSolutionCallback(dt = 0.1, solution_variables = cons2prim) # Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver -callbacks = CallbackSet(summary_callback, - alive_callback, - save_solution, - analysis_callback, - stepsize_callback) + ############################################################################### # run the simulation @@ -66,6 +62,14 @@ callbacks = CallbackSet(summary_callback, # Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used # in calculating the polynomial coefficients in the ODE algorithm. ode_algorithm = Trixi.EmbeddedPairedRK3(10, 7, tspan, semi) +cfl_number = Trixi.calculate_cfl(ode_algorithm, ode) +stepsize_callback = StepsizeCallback(cfl = cfl_number) + +callbacks = CallbackSet(summary_callback, + alive_callback, + save_solution, + analysis_callback, + stepsize_callback) sol = Trixi.solve(ode, ode_algorithm, dt = 1.0, # Manual time step value, will be overwritten by the stepsize_callback when it is specified. diff --git a/src/time_integration/paired_explicit_runge_kutta/methods_embedded_PERK3.jl b/src/time_integration/paired_explicit_runge_kutta/methods_embedded_PERK3.jl index e969761d58b..ecee2455a95 100644 --- a/src/time_integration/paired_explicit_runge_kutta/methods_embedded_PERK3.jl +++ b/src/time_integration/paired_explicit_runge_kutta/methods_embedded_PERK3.jl @@ -52,14 +52,14 @@ function compute_EmbeddedPairedRK3_butcher_tableau(num_stages, num_stage_evals, #TODO: something wrong when s = e - b, _ = solve_b_butcher_coeffs_unknown(num_eig_vals, eig_vals, + b, dt_opt_b = solve_b_butcher_coeffs_unknown(num_eig_vals, eig_vals, num_stages, num_stage_evals, num_stages - 1, # num_stages_embedded = num_stages - 1 num_stage_evals - 1, # num_stage_evals_embedded = num_stage_evals - 1 a_unknown, c, dtmax, dteps) - return a_matrix, b, c, dt_opt + return a_matrix, b, c, dt_opt_b end # Compute the Butcher tableau for a paired explicit Runge-Kutta method order 3