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