Path: blob/main/examples/p4est_2d_dgsem/elixir_advection_extended.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56advection_velocity = (0.2, -0.7)7equations = LinearScalarAdvectionEquation2D(advection_velocity)89initial_condition = initial_condition_convergence_test1011# BCs must be passed as Dict12boundary_condition = BoundaryConditionDirichlet(initial_condition)13boundary_conditions = Dict(:x_neg => boundary_condition,14:x_pos => boundary_condition,15:y_neg => boundary_condition,16:y_pos => boundary_condition)1718# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux19solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)2021# The initial condition is 2-periodic22coordinates_min = (-1.5, 1.3) # minimum coordinates (min(x), min(y))23coordinates_max = (0.5, 5.3) # maximum coordinates (max(x), max(y))2425trees_per_dimension = (19, 37)2627# Create curved mesh with 19 x 37 elements28mesh = P4estMesh(trees_per_dimension, polydeg = 3,29coordinates_min = coordinates_min, coordinates_max = coordinates_max,30periodicity = false)3132# A semidiscretization collects data structures and functions for the spatial discretization33semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,34boundary_conditions = boundary_conditions)3536###############################################################################37# ODE solvers, callbacks etc.3839# Create ODE problem with time span from 0.0 to 1.040tspan = (0.0, 1.0)41ode = semidiscretize(semi, tspan)4243# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup44# and resets the timers45summary_callback = SummaryCallback()4647# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results48analysis_interval = 10049analysis_callback = AnalysisCallback(semi, interval = analysis_interval,50extra_analysis_integrals = (entropy, energy_total))5152# The AliveCallback prints short status information in regular intervals53alive_callback = AliveCallback(analysis_interval = analysis_interval)5455# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted56save_restart = SaveRestartCallback(interval = 100,57save_final_restart = true)5859# The SaveSolutionCallback allows to save the solution to a file in regular intervals60save_solution = SaveSolutionCallback(interval = 100,61save_initial_solution = true,62save_final_solution = true,63solution_variables = cons2prim)6465# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step66stepsize_callback = StepsizeCallback(cfl = 1.6)6768# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver69callbacks = CallbackSet(summary_callback,70analysis_callback, alive_callback,71save_restart, save_solution,72stepsize_callback)7374###############################################################################75# run the simulation7677# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks78sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);79dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback80ode_default_options()..., callback = callbacks);818283