Path: blob/main/examples/p4est_3d_dgsem/elixir_euler_free_stream.jl
5586 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"))5758# Mesh polydeg of 2 (half the solver polydeg) to ensure FSP (see above).59mesh = P4estMesh{3}(mesh_file, polydeg = 2,60mapping = mapping)6162# Refine bottom left quadrant of each second tree to level 263function refine_fn(p8est, which_tree, quadrant)64quadrant_obj = unsafe_load(quadrant)65if iseven(convert(Int, which_tree)) && quadrant_obj.x == 0 && quadrant_obj.y == 0 &&66quadrant_obj.z == 0 && quadrant_obj.level < 267# return true (refine)68return Cint(1)69else70# return false (don't refine)71return Cint(0)72end73end7475# Refine recursively until each bottom left quadrant of every second tree has level 2.76# The mesh will be rebalanced before the simulation starts.77refine_fn_c = @cfunction(refine_fn, Cint,78(Ptr{Trixi.p8est_t}, Ptr{Trixi.p4est_topidx_t},79Ptr{Trixi.p8est_quadrant_t}))80Trixi.refine_p4est!(mesh.p4est, true, refine_fn_c, C_NULL)8182semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;83boundary_conditions = boundary_conditions)8485###############################################################################86# ODE solvers, callbacks etc.8788tspan = (0.0, 1.0)89ode = semidiscretize(semi, tspan)9091summary_callback = SummaryCallback()9293analysis_interval = 10094analysis_callback = AnalysisCallback(semi, interval = analysis_interval)9596alive_callback = AliveCallback(analysis_interval = analysis_interval)9798save_solution = SaveSolutionCallback(interval = 100,99save_initial_solution = true,100save_final_solution = true,101solution_variables = cons2prim)102103stepsize_callback = StepsizeCallback(cfl = 1.2)104105callbacks = CallbackSet(summary_callback,106analysis_callback, alive_callback,107save_solution,108stepsize_callback)109110###############################################################################111# run the simulation112113sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);114dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback115ode_default_options()..., callback = callbacks);116117118