Path: blob/main/examples/t8code_3d_dgsem/elixir_advection_nonconforming.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# Semidiscretization of the linear advection equation.56advection_velocity = (0.2, -0.7, 0.5)7equations = LinearScalarAdvectionEquation3D(advection_velocity)89# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux.10solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1112coordinates_min = (-1.0, -1.0, -1.0) # minimum coordinates (min(x), min(y), min(z))13coordinates_max = (1.0, 1.0, 1.0) # maximum coordinates (max(x), max(y), max(z))14trees_per_dimension = (1, 1, 1)1516# Note that it is not necessary to use mesh polydeg lower than the solver polydeg17# on a Cartesian mesh.18# See https://doi.org/10.1007/s10915-018-00897-9, Section 6.19mesh = T8codeMesh(trees_per_dimension, polydeg = 3,20coordinates_min = coordinates_min, coordinates_max = coordinates_max,21initial_refinement_level = 2,22periodicity = true)2324# Note: This is actually a `p8est_quadrant_t` which is much bigger than the25# following struct. But we only need the first four fields for our purpose.26struct t8_dhex_t27x::Int3228y::Int3229z::Int3230level::Int831# [...] # See `p8est.h` in `p4est` for more info.32end3334# Refine bottom left quadrant of each second tree to level 235function adapt_callback(forest, ltreeid, eclass_scheme, lelemntid, elements, is_family,36user_data)37el = unsafe_load(Ptr{t8_dhex_t}(elements[1]))3839if iseven(convert(Int, ltreeid)) && el.x == 0 && el.y == 0 && el.z == 0 &&40el.level < 341# return true (refine)42return 143else44# return false (don't refine)45return 046end47end4849Trixi.adapt!(mesh, adapt_callback)5051# A semidiscretization collects data structures and functions for the spatial discretization52semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,53solver;54boundary_conditions = boundary_condition_periodic)5556###############################################################################57# ODE solvers, callbacks etc.5859# Create ODE problem with time span from 0.0 to 1.060tspan = (0.0, 1.0)61ode = semidiscretize(semi, tspan)6263# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup64# and resets the timers65summary_callback = SummaryCallback()6667# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results68analysis_callback = AnalysisCallback(semi, interval = 100)6970# The SaveSolutionCallback allows to save the solution to a file in regular intervals71save_solution = SaveSolutionCallback(interval = 100,72solution_variables = cons2prim)7374# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step75stepsize_callback = StepsizeCallback(cfl = 1.6)7677# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver78callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,79stepsize_callback)8081###############################################################################82# run the simulation8384# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks85sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);86dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback87ode_default_options()..., callback = callbacks);888990