Path: blob/main/examples/structured_2d_dgsem/elixir_advection_extended.jl
5586 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# you can either use a single function to impose the BCs weakly in all12# 1*ndims == 2 directions or you can pass a tuple containing BCs for13# each direction14boundary_conditions = boundary_condition_periodic1516# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux17solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1819# The initial condition is 2-periodic20coordinates_min = (-1.5, 1.3) # minimum coordinates (min(x), min(y))21coordinates_max = (0.5, 5.3) # maximum coordinates (max(x), max(y))2223cells_per_dimension = (19, 37)2425# Create curved mesh with 19 x 37 elements26mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max,27periodicity = true)2829# A semidiscretization collects data structures and functions for the spatial discretization30semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;31boundary_conditions = boundary_conditions)3233###############################################################################34# ODE solvers, callbacks etc.3536# Create ODE problem with time span from 0.0 to 1.037tspan = (0.0, 1.0)38ode = semidiscretize(semi, tspan)3940# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup41# and resets the timers42summary_callback = SummaryCallback()4344# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results45analysis_interval = 10046analysis_callback = AnalysisCallback(semi, interval = analysis_interval,47extra_analysis_integrals = (entropy, energy_total))4849# The AliveCallback prints short status information in regular intervals50alive_callback = AliveCallback(analysis_interval = analysis_interval)5152# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted53save_restart = SaveRestartCallback(interval = 100,54save_final_restart = true)5556# The SaveSolutionCallback allows to save the solution to a file in regular intervals57save_solution = SaveSolutionCallback(interval = 100,58save_initial_solution = true,59save_final_solution = true,60solution_variables = cons2prim)6162# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step63stepsize_callback = StepsizeCallback(cfl = 1.6)6465# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver66callbacks = CallbackSet(summary_callback,67analysis_callback, alive_callback,68save_restart, save_solution,69stepsize_callback)7071###############################################################################72# run the simulation7374# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks75sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);76dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback77ode_default_options()..., callback = callbacks);787980