Path: blob/main/examples/structured_3d_dgsem/elixir_advection_free_stream.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56advection_velocity = (0.2, -0.7, 0.5)7equations = LinearScalarAdvectionEquation3D(advection_velocity)89# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux10solver = DGSEM(3, flux_lax_friedrichs)1112# Mapping as described in https://arxiv.org/abs/2012.1204013function mapping(xi_, eta_, zeta_)14# Transform input variables between -1 and 1 onto [0,3]15xi = 1.5 * xi_ + 1.516eta = 1.5 * eta_ + 1.517zeta = 1.5 * zeta_ + 1.51819y = eta +203 / 8 * (cos(1.5 * pi * (2 * xi - 3) / 3) *21cos(0.5 * pi * (2 * eta - 3) / 3) *22cos(0.5 * pi * (2 * zeta - 3) / 3))2324x = xi +253 / 8 * (cos(0.5 * pi * (2 * xi - 3) / 3) *26cos(2 * pi * (2 * y - 3) / 3) *27cos(0.5 * pi * (2 * zeta - 3) / 3))2829z = zeta +303 / 8 * (cos(0.5 * pi * (2 * x - 3) / 3) *31cos(pi * (2 * y - 3) / 3) *32cos(0.5 * pi * (2 * zeta - 3) / 3))3334return SVector(x, y, z)35end3637cells_per_dimension = (8, 8, 8)3839# Create curved mesh with 8 x 8 x 8 elements40mesh = StructuredMesh(cells_per_dimension, mapping)4142# A semidiscretization collects data structures and functions for the spatial discretization43semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_constant, solver)4445###############################################################################46# ODE solvers, callbacks etc.4748# Create ODE problem with time span from 0.0 to 1.049ode = semidiscretize(semi, (0.0, 1.0))5051# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup52# and resets the timers53summary_callback = SummaryCallback()5455# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results56analysis_callback = AnalysisCallback(semi, interval = 100)5758# The SaveSolutionCallback allows to save the solution to a file in regular intervals59save_solution = SaveSolutionCallback(interval = 100,60solution_variables = cons2prim)6162# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step63stepsize_callback = StepsizeCallback(cfl = 2.0)6465# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver66callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,67stepsize_callback)6869###############################################################################70# run the simulation7172# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks73sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);74dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback75ode_default_options()..., callback = callbacks);767778