Path: blob/main/examples/t8code_3d_dgsem/elixir_euler_free_stream.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible Euler equations56equations = CompressibleEulerEquations3D(1.4)78initial_condition = initial_condition_constant910boundary_conditions = Dict(:all => BoundaryConditionDirichlet(initial_condition))1112# Solver with polydeg=4 to ensure free stream preservation (FSP) on non-conforming meshes.13# The polydeg of the solver must be at least twice as big as the polydeg of the mesh.14# See https://doi.org/10.1007/s10915-018-00897-9, Section 6.1516# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of17# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.18# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.19# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.20# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.21# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the22# `StepsizeCallback` (CFL-Condition) and less diffusion.23solver = DGSEM(polydeg = 4, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive),24volume_integral = VolumeIntegralWeakForm())2526# Mapping as described in https://arxiv.org/abs/2012.12040 but with less warping.27# The mapping will be interpolated at tree level, and then refined without changing28# the geometry interpolant. This can yield problematic geometries if the unrefined mesh29# is not fine enough.30function mapping(xi_, eta_, zeta_)31# Transform input variables between -1 and 1 onto [0,3]32xi = 1.5 * xi_ + 1.533eta = 1.5 * eta_ + 1.534zeta = 1.5 * zeta_ + 1.53536y = eta +371 / 6 * (cos(1.5 * pi * (2 * xi - 3) / 3) *38cos(0.5 * pi * (2 * eta - 3) / 3) *39cos(0.5 * pi * (2 * zeta - 3) / 3))4041x = xi +421 / 6 * (cos(0.5 * pi * (2 * xi - 3) / 3) *43cos(2 * pi * (2 * y - 3) / 3) *44cos(0.5 * pi * (2 * zeta - 3) / 3))4546z = zeta +471 / 6 * (cos(0.5 * pi * (2 * x - 3) / 3) *48cos(pi * (2 * y - 3) / 3) *49cos(0.5 * pi * (2 * zeta - 3) / 3))5051return SVector(x, y, z)52end5354# Unstructured mesh with 68 cells of the cube domain [-1, 1]^355mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/d45c8ac1e248618885fa7cc31a50ab40/raw/37fba24890ab37cfa49c39eae98b44faf4502882/cube_unstructured_1.inp",56joinpath(@__DIR__, "cube_unstructured_1.inp"))5758mesh = T8codeMesh(mesh_file, 3; polydeg = 2,59mapping = mapping,60initial_refinement_level = 0)6162# Note: This is actually a `p8est_quadrant_t` which is much bigger than the63# following struct. But we only need the first four fields for our purpose.64struct t8_dhex_t65x::Int3266y::Int3267z::Int3268level::Int869# [...] # See `p8est.h` in `p4est` for more info.70end7172# Refine bottom left quadrant of each second tree to level 273function adapt_callback(forest, ltreeid, eclass_scheme, lelemntid, elements, is_family,74user_data)75el = unsafe_load(Ptr{t8_dhex_t}(elements[1]))7677if iseven(convert(Int, ltreeid)) && el.x == 0 && el.y == 0 && el.z == 0 &&78el.level < 279# return true (refine)80return 181else82# return false (don't refine)83return 084end85end8687Trixi.adapt!(mesh, adapt_callback)8889semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,90boundary_conditions = boundary_conditions)9192###############################################################################93# ODE solvers, callbacks etc.9495tspan = (0.0, 1.0)96ode = semidiscretize(semi, tspan)9798summary_callback = SummaryCallback()99100analysis_interval = 100101analysis_callback = AnalysisCallback(semi, interval = analysis_interval)102103alive_callback = AliveCallback(analysis_interval = analysis_interval)104105save_solution = SaveSolutionCallback(interval = 100,106save_initial_solution = true,107save_final_solution = true,108solution_variables = cons2prim)109110stepsize_callback = StepsizeCallback(cfl = 1.2)111112callbacks = CallbackSet(summary_callback,113analysis_callback, alive_callback,114save_solution,115stepsize_callback)116117###############################################################################118# run the simulation119120sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);121dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback122ode_default_options()..., callback = callbacks);123124125