Path: blob/main/examples/p4est_2d_dgsem/elixir_euler_free_stream.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible Euler equations56equations = CompressibleEulerEquations2D(1.4)78initial_condition = initial_condition_constant910# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of11# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.12# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.13# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.14# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.15# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the16# `StepsizeCallback` (CFL-Condition) and less diffusion.17solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive))1819# Mapping as described in https://arxiv.org/abs/2012.12040 but reduced to 2D20function mapping(xi_, eta_)21# Transform input variables between -1 and 1 onto [0,3]22xi = 1.5 * xi_ + 1.523eta = 1.5 * eta_ + 1.52425y = eta + 3 / 8 * (cos(1.5 * pi * (2 * xi - 3) / 3) *26cos(0.5 * pi * (2 * eta - 3) / 3))2728x = xi + 3 / 8 * (cos(0.5 * pi * (2 * xi - 3) / 3) *29cos(2 * pi * (2 * y - 3) / 3))3031return SVector(x, y)32end3334###############################################################################35# Get the uncurved mesh from a file (downloads the file if not available locally)3637# Unstructured mesh with 48 cells of the square domain [-1, 1]^n38mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/a075f8ec39a67fa9fad8f6f84342cbca/raw/a7206a02ed3a5d3cadacd8d9694ac154f9151db7/square_unstructured_1.inp",39joinpath(@__DIR__, "square_unstructured_1.inp"))4041# Map the unstructured mesh with the mapping above42mesh = P4estMesh{2}(mesh_file, polydeg = 3, mapping = mapping, initial_refinement_level = 1)4344# Refine bottom left quadrant of each tree to level 245function refine_fn(p4est, which_tree, quadrant)46quadrant_obj = unsafe_load(quadrant)47if quadrant_obj.x == 0 && quadrant_obj.y == 0 && quadrant_obj.level < 348# return true (refine)49return Cint(1)50else51# return false (don't refine)52return Cint(0)53end54end5556# Refine recursively until each bottom left quadrant of a tree has level 2.57# The mesh will be rebalanced before the simulation starts.58refine_fn_c = @cfunction(refine_fn, Cint,59(Ptr{Trixi.p4est_t}, Ptr{Trixi.p4est_topidx_t},60Ptr{Trixi.p4est_quadrant_t}))61Trixi.refine_p4est!(mesh.p4est, true, refine_fn_c, C_NULL)6263semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,64boundary_conditions = Dict(:all => BoundaryConditionDirichlet(initial_condition)))6566###############################################################################67# ODE solvers, callbacks etc.6869tspan = (0.0, 1.0)70ode = semidiscretize(semi, tspan)7172summary_callback = SummaryCallback()7374analysis_interval = 10075analysis_callback = AnalysisCallback(semi, interval = analysis_interval)7677alive_callback = AliveCallback(analysis_interval = analysis_interval)7879save_solution = SaveSolutionCallback(interval = 100,80save_initial_solution = true,81save_final_solution = true,82solution_variables = cons2prim)8384stepsize_callback = StepsizeCallback(cfl = 2.0)8586callbacks = CallbackSet(summary_callback,87analysis_callback, alive_callback,88save_solution,89stepsize_callback)9091###############################################################################92# run the simulation9394sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);95dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback96ode_default_options()..., callback = callbacks);979899