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_dirichlet.jl
5586 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the pure 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
solver_parabolic = ParabolicFormulationLocalDG()
13
14
# Create a uniformly refined mesh with nonperiodic boundaries
15
mesh = TreeMesh(0.0, 1.0,
16
initial_refinement_level = 4,
17
n_cells_max = 30_000, # set maximum capacity of tree data structure
18
periodicity = false)
19
20
function analytical_solution(x, t, equations)
21
scalar = sinpi(x[1]) * exp(-diffusivity() * pi^2 * t)
22
return SVector(scalar)
23
end
24
initial_condition = analytical_solution
25
26
boundary_conditions = (; x_neg = BoundaryConditionDirichlet(initial_condition),
27
x_pos = BoundaryConditionDirichlet(initial_condition))
28
29
# A semidiscretization collects data structures and functions for the spatial discretization
30
semi = SemidiscretizationParabolic(mesh, equations, initial_condition, solver;
31
solver_parabolic = solver_parabolic,
32
boundary_conditions = boundary_conditions)
33
34
###############################################################################
35
# ODE solvers, callbacks etc.
36
37
# Create ODE problem with time span from 0.0 to 1.0
38
tspan = (0.0, 1.0)
39
ode = semidiscretize(semi, tspan)
40
41
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
42
# and resets the timers
43
summary_callback = SummaryCallback()
44
45
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
46
analysis_callback = AnalysisCallback(semi, interval = 100)
47
48
# The AliveCallback prints short status information in regular intervals
49
alive_callback = AliveCallback(analysis_interval = 100)
50
51
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
52
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback)
53
54
###############################################################################
55
# run the simulation
56
57
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
58
# For CI purposes, we use fixed time-stepping for this elixir.
59
sol = solve(ode, RDPK3SpFSAL35(); dt = 1.0e-4, adaptive = false,
60
ode_default_options()..., callback = callbacks)
61
62