Path: blob/main/examples/structured_2d_dgsem/elixir_advection_free_stream.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_constant1011# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux12solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1314# Mapping as described in https://arxiv.org/abs/2012.12040, but reduced to 2D15function mapping(xi_, eta_)16# Transform input variables between -1 and 1 onto [0,3]17xi = 1.5 * xi_ + 1.518eta = 1.5 * eta_ + 1.51920y = eta + 3 / 8 * (cos(1.5 * pi * (2 * xi - 3) / 3) *21cos(0.5 * pi * (2 * eta - 3) / 3))2223x = xi + 3 / 8 * (cos(0.5 * pi * (2 * xi - 3) / 3) *24cos(2 * pi * (2 * y - 3) / 3))2526return SVector(x, y)27end2829cells_per_dimension = (16, 16)3031# Create curved mesh with 16 x 16 elements32mesh = StructuredMesh(cells_per_dimension, mapping, periodicity = true)3334# A semidiscretization collects data structures and functions for the spatial discretization35semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;36boundary_conditions = boundary_condition_periodic)3738###############################################################################39# ODE solvers, callbacks etc.4041# Create ODE problem with time span from 0.0 to 1.042ode = semidiscretize(semi, (0.0, 1.0))4344# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup45# and resets the timers46summary_callback = SummaryCallback()4748# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results49analysis_callback = AnalysisCallback(semi, interval = 100)5051# The SaveSolutionCallback allows to save the solution to a file in regular intervals52save_solution = SaveSolutionCallback(interval = 100,53solution_variables = cons2prim)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 StepsizeCallback handles the re-calculation of the maximum Δt after each time step60stepsize_callback = StepsizeCallback(cfl = 2.0)6162# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver63callbacks = CallbackSet(summary_callback, analysis_callback, save_restart, save_solution,64stepsize_callback)6566###############################################################################67# run the simulation6869# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks70sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);71dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback72ode_default_options()..., callback = callbacks);737475