Path: blob/main/examples/t8code_3d_dgsem/elixir_euler_free_stream.jl
5585 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible Euler equations56equations = CompressibleEulerEquations3D(1.4)78initial_condition = initial_condition_constant910boundary_conditions = (; 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)6061# Note: This is actually a `p8est_quadrant_t` which is much bigger than the62# following struct. But we only need the first four fields for our purpose.63struct t8_dhex_t64x::Int3265y::Int3266z::Int3267level::Int868# [...] # See `p8est.h` in `p4est` for more info.69end7071# Refine bottom left quadrant of each second tree to level 272function adapt_callback(forest, ltreeid, eclass_scheme, lelemntid, elements, is_family,73user_data)74el = unsafe_load(Ptr{t8_dhex_t}(elements[1]))7576if iseven(convert(Int, ltreeid)) && el.x == 0 && el.y == 0 && el.z == 0 &&77el.level < 278# return true (refine)79return 180else81# return false (don't refine)82return 083end84end8586Trixi.adapt!(mesh, adapt_callback)8788semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;89boundary_conditions = boundary_conditions)9091###############################################################################92# ODE solvers, callbacks etc.9394tspan = (0.0, 1.0)95ode = semidiscretize(semi, tspan)9697summary_callback = SummaryCallback()9899analysis_interval = 100100analysis_callback = AnalysisCallback(semi, interval = analysis_interval)101102alive_callback = AliveCallback(analysis_interval = analysis_interval)103104save_solution = SaveSolutionCallback(interval = 100,105save_initial_solution = true,106save_final_solution = true,107solution_variables = cons2prim)108109stepsize_callback = StepsizeCallback(cfl = 1.2)110111callbacks = CallbackSet(summary_callback,112analysis_callback, alive_callback,113save_solution,114stepsize_callback)115116###############################################################################117# run the simulation118119sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);120dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback121ode_default_options()..., callback = callbacks);122123124