Path: blob/main/examples/p4est_3d_dgsem/elixir_advection_diffusion_nonperiodic.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection-diffusion equation56diffusivity() = 1 / 177advection_velocity = (1.0, 0.0, 0.0)8equations = LinearScalarAdvectionEquation3D(advection_velocity)9equations_parabolic = LaplaceDiffusion3D(diffusivity(), equations)1011polydeg = 312solver = DGSEM(polydeg = polydeg, surface_flux = flux_lax_friedrichs)1314coordinates_min = (-1.0, -0.5, -0.5)15coordinates_max = (0.0, 0.5, 0.5)1617# Affine type mapping to take the [-1,1]^3 domain18# and warp it as described in https://arxiv.org/abs/2012.1204019function mapping(xi, eta, zeta)20y_ = eta + 1 / 6 * (cos(1.5 * pi * xi) * cos(0.5 * pi * eta) * cos(0.5 * pi * zeta))21x_ = xi + 1 / 6 * (cos(0.5 * pi * xi) * cos(2 * pi * y_) * cos(0.5 * pi * zeta))22z_ = zeta + 1 / 6 * (cos(0.5 * pi * x_) * cos(pi * y_) * cos(0.5 * pi * zeta))2324# Map from [-1, 1]^3 to [-1, -0.5, -0.5] x [0, 0.5, 0.5]25x = 0.5 * (x_ - 1)26y = 0.5 * y_27z = 0.5 * z_2829return SVector(x, y, z)30end3132trees_per_dimension = (5, 3, 3)33mesh = P4estMesh(trees_per_dimension, polydeg = polydeg,34mapping = mapping, periodicity = false)3536# Example setup taken from37# - Truman Ellis, Jesse Chan, and Leszek Demkowicz (2016).38# Robust DPG methods for transient convection-diffusion.39# In: Building bridges: connections and challenges in modern approaches40# to numerical partial differential equations.41# [DOI](https://doi.org/10.1007/978-3-319-41640-3_6).42function initial_condition_eriksson_johnson(x, t, equations)43l = 444epsilon = diffusivity() # NOTE: this requires epsilon <= 1/16 due to sqrt45lambda_1 = (-1 + sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)46lambda_2 = (-1 - sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)47r1 = (1 + sqrt(1 + 4 * pi^2 * epsilon^2)) / (2 * epsilon)48s1 = (1 - sqrt(1 + 4 * pi^2 * epsilon^2)) / (2 * epsilon)49u = exp(-l * t) * (exp(lambda_1 * x[1]) - exp(lambda_2 * x[1])) +50cos(pi * x[2]) * (exp(s1 * x[1]) - exp(r1 * x[1])) / (exp(-s1) - exp(-r1))51return SVector(u)52end53initial_condition = initial_condition_eriksson_johnson5455boundary_conditions = BoundaryConditionDirichlet(initial_condition)5657semi = SemidiscretizationHyperbolicParabolic(mesh,58(equations, equations_parabolic),59initial_condition, solver;60solver_parabolic = ParabolicFormulationBassiRebay1(),61boundary_conditions = (boundary_conditions,62boundary_conditions))6364###############################################################################65# ODE solvers, callbacks etc.6667tspan = (0.0, 0.5)68ode = semidiscretize(semi, tspan)6970summary_callback = SummaryCallback()7172analysis_interval = 10073analysis_callback = AnalysisCallback(semi, interval = analysis_interval)7475alive_callback = AliveCallback(analysis_interval = analysis_interval)7677stepsize_callback = StepsizeCallback(cfl = 1.6,78cfl_parabolic = 0.25)7980callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback,81stepsize_callback)8283###############################################################################84# run the simulation8586sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),87dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback88save_everystep = false, callback = callbacks);899091