Path: blob/main/examples/p4est_3d_dgsem/elixir_advection_nonconforming.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56advection_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 flux10solver = 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 = P4estMesh(trees_per_dimension, polydeg = 3,20coordinates_min = coordinates_min, coordinates_max = coordinates_max,21initial_refinement_level = 2,22periodicity = true)2324# Refine bottom left quadrant of each tree to level 325function refine_fn(p8est, which_tree, quadrant)26quadrant_obj = unsafe_load(quadrant)27if quadrant_obj.x == 0 && quadrant_obj.y == 0 && quadrant_obj.z == 0 &&28quadrant_obj.level < 329# return true (refine)30return Cint(1)31else32# return false (don't refine)33return Cint(0)34end35end3637# Refine recursively until each bottom left quadrant of a tree has level 338# The mesh will be rebalanced before the simulation starts39refine_fn_c = @cfunction(refine_fn, Cint,40(Ptr{Trixi.p8est_t}, Ptr{Trixi.p4est_topidx_t},41Ptr{Trixi.p8est_quadrant_t}))42Trixi.refine_p4est!(mesh.p4est, true, refine_fn_c, C_NULL)4344# A semidiscretization collects data structures and functions for the spatial discretization45semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,46solver;47boundary_conditions = boundary_condition_periodic)4849###############################################################################50# ODE solvers, callbacks etc.5152# Create ODE problem with time span from 0.0 to 1.053tspan = (0.0, 1.0)54ode = semidiscretize(semi, tspan)5556# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup57# and resets the timers58summary_callback = SummaryCallback()5960# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results61analysis_callback = AnalysisCallback(semi, interval = 100)6263# The SaveSolutionCallback allows to save the solution to a file in regular intervals64save_solution = SaveSolutionCallback(interval = 100,65solution_variables = cons2prim)6667# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step68stepsize_callback = StepsizeCallback(cfl = 1.6)6970# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver71callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,72stepsize_callback)7374###############################################################################75# run the simulation7677# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks78sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);79dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback80ode_default_options()..., callback = callbacks);818283