Path: blob/main/examples/structured_2d_dgsem/elixir_advection_free_stream.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_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)3334# A semidiscretization collects data structures and functions for the spatial discretization35semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)3637###############################################################################38# ODE solvers, callbacks etc.3940# Create ODE problem with time span from 0.0 to 1.041ode = semidiscretize(semi, (0.0, 1.0))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_callback = AnalysisCallback(semi, interval = 100)4950# The SaveSolutionCallback allows to save the solution to a file in regular intervals51save_solution = SaveSolutionCallback(interval = 100,52solution_variables = cons2prim)5354# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted55save_restart = SaveRestartCallback(interval = 100,56save_final_restart = true)5758# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step59stepsize_callback = StepsizeCallback(cfl = 2.0)6061# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver62callbacks = CallbackSet(summary_callback, analysis_callback, save_restart, save_solution,63stepsize_callback)6465###############################################################################66# run the simulation6768# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks69sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);70dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback71ode_default_options()..., callback = callbacks);727374