Path: blob/main/examples/tree_1d_dgsem/elixir_diffusion_ldg.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the (pure) linear diffusion equation56diffusivity() = 0.57equations = LinearDiffusionEquation1D(diffusivity())89# Create DG solver with polynomial degree = 310solver = DGSEM(polydeg = 3)1112coordinates_min = -convert(Float64, pi) # minimum coordinate13coordinates_max = convert(Float64, pi) # maximum coordinate1415# Create a uniformly refined mesh with periodic boundaries16mesh = TreeMesh(coordinates_min, coordinates_max,17initial_refinement_level = 4,18n_cells_max = 30_000, # set maximum capacity of tree data structure19periodicity = true)2021# Define initial condition if it is not defined already.22# For CI, the function is defined externally avoid "world age" issues that arise23# when running `Trixi.convergence_test`. The `isdefined` check is to allow the24# elixir to also be run outside of CI.25function initial_condition_pure_diffusion_1d_convergence_test(x, t,26equation)27nu = diffusivity()28c = 029A = 130omega = 131scalar = c + A * sin(omega * sum(x)) * exp(-nu * omega^2 * t)32return SVector(scalar)33end34initial_condition = initial_condition_pure_diffusion_1d_convergence_test3536# A semidiscretization collects data structures and functions for the spatial discretization37solver_parabolic = ParabolicFormulationLocalDG()38semi = SemidiscretizationParabolic(mesh, equations, initial_condition, solver;39solver_parabolic = solver_parabolic,40boundary_conditions = boundary_condition_periodic)4142###############################################################################43# ODE solvers, callbacks etc.4445# Create ODE problem with time span from 0.0 to 0.146tspan = (0.0, 0.1)47ode = semidiscretize(semi, tspan)4849# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup50# and resets the timers51summary_callback = SummaryCallback()5253# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results54analysis_callback = AnalysisCallback(semi, interval = 100)5556# The AliveCallback prints short status information in regular intervals57alive_callback = AliveCallback(analysis_interval = 100)5859# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted60save_restart = SaveRestartCallback(interval = 100,61save_final_restart = true)6263# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver64callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, save_restart)6566###############################################################################67# run the simulation6869# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks70# For CI purposes, we use fixed time-stepping for this elixir.71sol = solve(ode, RDPK3SpFSAL35(); dt = 1.0e-3, adaptive = false,72ode_default_options()..., callback = callbacks)737475