Path: blob/main/examples/tree_3d_dgsem/elixir_advection_extended.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56advection_velocity = (0.2, -0.7, 0.5)7equations = LinearScalarAdvectionEquation3D(advection_velocity)89initial_condition = initial_condition_convergence_test1011# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux12solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1314coordinates_min = (-1.0, -1.0, -1.0) # minimum coordinates (min(x), min(y), min(z))15coordinates_max = (1.0, 1.0, 1.0) # maximum coordinates (max(x), max(y), max(z))1617# Create a uniformly refined mesh with periodic boundaries18mesh = TreeMesh(coordinates_min, coordinates_max,19initial_refinement_level = 3,20n_cells_max = 30_000, # set maximum capacity of tree data structure21periodicity = true)2223# you can either use a single function to impose the BCs weakly in all24# 2*ndims == 6 directions or you can pass a named tuple containing BCs for25# each direction26boundary_conditions = boundary_condition_periodic2728# A semidiscretization collects data structures and functions for the spatial discretization29semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;30boundary_conditions = boundary_conditions)3132###############################################################################33# ODE solvers, callbacks etc.3435# Create ODE problem with time span from 0.0 to 1.036tspan = (0.0, 1.0)37ode = semidiscretize(semi, tspan)3839# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup40# and resets the timers41summary_callback = SummaryCallback()4243# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results44analysis_interval = 10045analysis_callback = AnalysisCallback(semi, interval = analysis_interval,46extra_analysis_integrals = (entropy, energy_total))4748# The AliveCallback prints short status information in regular intervals49alive_callback = AliveCallback(analysis_interval = analysis_interval)5051# The SaveRestartCallback allows to save a file from which a Trixi simulation can be restarted52save_restart = SaveRestartCallback(interval = 100,53save_final_restart = true)5455# The SaveSolutionCallback allows to save the solution to a file in regular intervals56save_solution = SaveSolutionCallback(interval = 100,57save_initial_solution = true,58save_final_solution = true,59solution_variables = cons2prim)6061# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step62stepsize_callback = StepsizeCallback(cfl = 1.2)6364# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver65callbacks = CallbackSet(summary_callback,66analysis_callback, alive_callback,67save_restart, save_solution,68stepsize_callback)6970###############################################################################71# run the simulation7273# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks74sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);75dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback76ode_default_options()..., callback = callbacks);777879