Path: blob/main/examples/t8code_3d_dgsem/elixir_euler_ec.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible Euler equations56equations = CompressibleEulerEquations3D(5 / 3)78initial_condition = initial_condition_weak_blast_wave910boundary_conditions = Dict(:all => boundary_condition_slip_wall)1112# Get the DG approximation space1314volume_flux = flux_ranocha15solver = DGSEM(polydeg = 5, surface_flux = flux_ranocha,16volume_integral = VolumeIntegralFluxDifferencing(volume_flux))1718# Get the curved quad mesh from a file1920# Mapping as described in https://arxiv.org/abs/2012.1204021function mapping(xi_, eta_, zeta_)22# Transform input variables between -1 and 1 onto [0,3]23xi = 1.5 * xi_ + 1.524eta = 1.5 * eta_ + 1.525zeta = 1.5 * zeta_ + 1.52627y = eta +283 / 8 * (cos(1.5 * pi * (2 * xi - 3) / 3) *29cos(0.5 * pi * (2 * eta - 3) / 3) *30cos(0.5 * pi * (2 * zeta - 3) / 3))3132x = xi +333 / 8 * (cos(0.5 * pi * (2 * xi - 3) / 3) *34cos(2 * pi * (2 * y - 3) / 3) *35cos(0.5 * pi * (2 * zeta - 3) / 3))3637z = zeta +383 / 8 * (cos(0.5 * pi * (2 * x - 3) / 3) *39cos(pi * (2 * y - 3) / 3) *40cos(0.5 * pi * (2 * zeta - 3) / 3))4142return SVector(x, y, z)43end4445# Unstructured mesh with 48 cells of the cube domain [-1, 1]^346mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/b8df0033798e4926dec515fc045e8c2c/raw/b9254cde1d1fb64b6acc8416bc5ccdd77a240227/cube_unstructured_2.inp",47joinpath(@__DIR__, "cube_unstructured_2.inp"))4849mesh = T8codeMesh(mesh_file, 3; polydeg = 5,50mapping = mapping,51initial_refinement_level = 0)5253# Create the semidiscretization object.54semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,55boundary_conditions = boundary_conditions)5657###############################################################################58# ODE solvers, callbacks etc.5960tspan = (0.0, 2.0)61ode = semidiscretize(semi, tspan)6263summary_callback = SummaryCallback()6465analysis_interval = 10066analysis_callback = AnalysisCallback(semi, interval = analysis_interval)6768alive_callback = AliveCallback(analysis_interval = analysis_interval)6970# Add `:thermodynamic_entropy` to `extra_node_variables` tuple ...71extra_node_variables = (:thermodynamic_entropy,)7273# ... and specify the function `get_node_variable` for this symbol,74# with first argument matching the symbol (turned into a type via `Val`) for dispatching.75function Trixi.get_node_variable(::Val{:thermodynamic_entropy}, u, mesh, equations,76dg, cache)77n_nodes = nnodes(dg)78n_elements = nelements(dg, cache)79# By definition, the variable must be provided at every node of every element!80# Otherwise, the `SaveSolutionCallback` will crash.81entropy_array = zeros(eltype(cache.elements),82ntuple(_ -> n_nodes, ndims(mesh))..., # equivalent: `n_nodes, n_nodes, n_nodes`83n_elements)8485# We can accelerate the computation by thread-parallelizing the loop over elements86# by using the `@threaded` macro.87Trixi.@threaded for element in eachelement(dg, cache)88for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)89u_node = get_node_vars(u, equations, dg, i, j, k, element)9091entropy_array[i, j, k, element] = Trixi.entropy_thermodynamic(u_node, equations)92end93end9495return entropy_array96end97save_solution = SaveSolutionCallback(interval = 100,98save_initial_solution = true,99save_final_solution = true,100extra_node_variables = extra_node_variables) # Supply the additional `extra_node_variables` here101102stepsize_callback = StepsizeCallback(cfl = 1.0)103104callbacks = CallbackSet(summary_callback,105analysis_callback,106alive_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