Path: blob/main/examples/p4est_2d_dgsem/elixir_advection_diffusion_periodic.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection-diffusion equation56diffusivity() = 5.0e-27advection_velocity = (1.0, 0.0)8equations = LinearScalarAdvectionEquation2D(advection_velocity)9equations_parabolic = LaplaceDiffusion2D(diffusivity(), equations)1011function x_trans_periodic(x, domain_length = SVector(2 * pi), center = SVector(0.0))12x_normalized = x .- center13x_shifted = x_normalized .% domain_length14x_offset = ((x_shifted .< -0.5 * domain_length) - (x_shifted .> 0.5 * domain_length)) .*15domain_length16return center + x_shifted + x_offset17end1819# Define initial condition (copied from "examples/tree_1d_dgsem/elixir_advection_diffusion.jl")20function initial_condition_diffusive_convergence_test(x, t,21equation::LinearScalarAdvectionEquation2D)22# Store translated coordinate for easy use of exact solution23# Assumes that advection_velocity[2] = 0 (effectively that we are solving a 1D equation)24x_trans = x_trans_periodic(x[1] - equation.advection_velocity[1] * t)2526nu = diffusivity()27c = 0.028A = 1.029omega = 1.030scalar = c + A * sin(omega * sum(x_trans)) * exp(-nu * omega^2 * t)31return SVector(scalar)32end33initial_condition = initial_condition_diffusive_convergence_test3435# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux36solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)3738coordinates_min = (-pi, -pi) # minimum coordinates (min(x), min(y))39coordinates_max = (pi, pi) # maximum coordinates (max(x), max(y))4041trees_per_dimension = (4, 4)42mesh = P4estMesh(trees_per_dimension,43polydeg = 3, initial_refinement_level = 2,44coordinates_min = coordinates_min, coordinates_max = coordinates_max,45periodicity = true)4647# A semidiscretization collects data structures and functions for the spatial discretization48semi = SemidiscretizationHyperbolicParabolic(mesh,49(equations, equations_parabolic),50initial_condition, solver)5152###############################################################################53# ODE solvers, callbacks etc.5455# Create ODE problem with time span `tspan`56tspan = (0.0, 1.0)57ode = semidiscretize(semi, tspan)5859# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup60# and resets the timers61summary_callback = SummaryCallback()6263# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results64analysis_interval = 10065analysis_callback = AnalysisCallback(semi, interval = analysis_interval)6667# The AliveCallback prints short status information in regular intervals68alive_callback = AliveCallback(analysis_interval = analysis_interval)6970# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver71callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback)7273###############################################################################74# run the simulation7576# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks77time_int_tol = 1.0e-1178sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,79ode_default_options()..., callback = callbacks)808182