Skip to content

Commit

Permalink
change dt_opt to be that of b_opt and add a new example
Browse files Browse the repository at this point in the history
  • Loading branch information
warisa-r committed Oct 14, 2024
1 parent 7fd60c7 commit 9d56c93
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 10 additions & 6 deletions examples/tree_1d_dgsem/elixir_advection_embedded_perk3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9d56c93

Please sign in to comment.