Path: blob/main/examples/t8code_3d_dgsem/elixir_euler_ec.jl
5585 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible Euler equations56equations = CompressibleEulerEquations3D(5 / 3)78initial_condition = initial_condition_weak_blast_wave910boundary_conditions = (; 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)5152# Create the semidiscretization object.53semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;54boundary_conditions = boundary_conditions)5556###############################################################################57# ODE solvers, callbacks etc.5859tspan = (0.0, 2.0)60ode = semidiscretize(semi, tspan)6162summary_callback = SummaryCallback()6364analysis_interval = 10065analysis_callback = AnalysisCallback(semi, interval = analysis_interval)6667alive_callback = AliveCallback(analysis_interval = analysis_interval)6869# Add `:thermodynamic_entropy` to `extra_node_variables` tuple ...70extra_node_variables = (:thermodynamic_entropy,)7172# ... and specify the function `get_node_variable` for this symbol,73# with first argument matching the symbol (turned into a type via `Val`) for dispatching.74function Trixi.get_node_variable(::Val{:thermodynamic_entropy}, u, mesh, equations,75dg, cache)76n_nodes = nnodes(dg)77n_elements = nelements(dg, cache)78# By definition, the variable must be provided at every node of every element!79# Otherwise, the `SaveSolutionCallback` will crash.80entropy_array = zeros(eltype(cache.elements),81ntuple(_ -> n_nodes, ndims(mesh))..., # equivalent: `n_nodes, n_nodes, n_nodes`82n_elements)8384# We can accelerate the computation by thread-parallelizing the loop over elements85# by using the `@threaded` macro.86Trixi.@threaded for element in eachelement(dg, cache)87for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)88u_node = get_node_vars(u, equations, dg, i, j, k, element)8990entropy_array[i, j, k, element] = entropy_thermodynamic(u_node, equations)91end92end9394return entropy_array95end96save_solution = SaveSolutionCallback(interval = 100,97save_initial_solution = true,98save_final_solution = true,99extra_node_variables = extra_node_variables) # Supply the additional `extra_node_variables` here100101stepsize_callback = StepsizeCallback(cfl = 1.0)102103callbacks = CallbackSet(summary_callback,104analysis_callback,105alive_callback,106save_solution,107stepsize_callback)108109###############################################################################110# run the simulation111112sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);113dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback114ode_default_options()..., callback = callbacks);115116117