Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_1d_dgsem/elixir_diffusion_ldg.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear (advection) diffusion equation
6
7
advection_velocity = 0.0 # Note: This renders the equation mathematically purely parabolic
8
equations = LinearScalarAdvectionEquation1D(advection_velocity)
9
diffusivity() = 0.5
10
equations_parabolic = LaplaceDiffusion1D(diffusivity(), equations)
11
12
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
13
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
14
15
coordinates_min = -convert(Float64, pi) # minimum coordinate
16
coordinates_max = convert(Float64, pi) # maximum coordinate
17
18
# Create a uniformly refined mesh with periodic boundaries
19
mesh = TreeMesh(coordinates_min, coordinates_max,
20
initial_refinement_level = 4,
21
n_cells_max = 30_000, # set maximum capacity of tree data structure
22
periodicity = true)
23
24
# Define initial condition if it is not defined already.
25
# For CI, the function is defined externally avoid "world age" issues that arise
26
# when running `Trixi.convergence_test`. The `isdefined` check is to allow the
27
# elixir to also be run outside of CI.
28
function initial_condition_pure_diffusion_1d_convergence_test(x, t,
29
equation)
30
nu = diffusivity()
31
c = 0
32
A = 1
33
omega = 1
34
scalar = c + A * sin(omega * sum(x)) * exp(-nu * omega^2 * t)
35
return SVector(scalar)
36
end
37
initial_condition = initial_condition_pure_diffusion_1d_convergence_test
38
39
# define periodic boundary conditions everywhere
40
boundary_conditions = boundary_condition_periodic
41
boundary_conditions_parabolic = boundary_condition_periodic
42
43
# A semidiscretization collects data structures and functions for the spatial discretization
44
solver_parabolic = ViscousFormulationLocalDG()
45
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
46
initial_condition,
47
solver; solver_parabolic,
48
boundary_conditions = (boundary_conditions,
49
boundary_conditions_parabolic))
50
51
###############################################################################
52
# ODE solvers, callbacks etc.
53
54
# Create ODE problem with time span from 0.0 to 0.1
55
tspan = (0.0, 0.1)
56
ode = semidiscretize(semi, tspan)
57
58
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
59
# and resets the timers
60
summary_callback = SummaryCallback()
61
62
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
63
analysis_callback = AnalysisCallback(semi, interval = 100)
64
65
# The AliveCallback prints short status information in regular intervals
66
alive_callback = AliveCallback(analysis_interval = 100)
67
68
# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted
69
save_restart = SaveRestartCallback(interval = 100,
70
save_final_restart = true)
71
72
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
73
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, save_restart)
74
75
###############################################################################
76
# run the simulation
77
78
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
79
# For CI purposes, we use fixed time-stepping for this elixir.
80
sol = solve(ode, RDPK3SpFSAL35(); dt = 1.0e-3, adaptive = false,
81
ode_default_options()..., callback = callbacks)
82
83