Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_3d_dgsem/elixir_advection_diffusion_nonperiodic.jl
5586 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear advection-diffusion equation
6
7
diffusivity() = 5.0e-2
8
advection_velocity = (1.0, 0.0, 0.0)
9
equations = LinearScalarAdvectionEquation3D(advection_velocity)
10
equations_parabolic = LaplaceDiffusion3D(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 = (-1.0, -0.5, -0.5) # minimum coordinates (min(x), min(y), min(z))
16
coordinates_max = (0.0, 0.5, 0.5) # maximum coordinates (max(x), max(y), max(z))
17
18
mesh = TreeMesh(coordinates_min, coordinates_max,
19
initial_refinement_level = 3,
20
periodicity = false,
21
n_cells_max = 30_000) # set maximum capacity of tree data structure
22
23
# Example setup taken from
24
# - Truman Ellis, Jesse Chan, and Leszek Demkowicz (2016).
25
# Robust DPG methods for transient convection-diffusion.
26
# In: Building bridges: connections and challenges in modern approaches
27
# to numerical partial differential equations.
28
# [DOI](https://doi.org/10.1007/978-3-319-41640-3_6).
29
function initial_condition_eriksson_johnson(x, t, equations)
30
l = 4
31
epsilon = diffusivity() # NOTE: this requires epsilon <= 1/16 due to sqrt
32
lambda_1 = (-1 + sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
33
lambda_2 = (-1 - sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
34
r1 = (1 + sqrt(1 + 4 * pi^2 * epsilon^2)) / (2 * epsilon)
35
s1 = (1 - sqrt(1 + 4 * pi^2 * epsilon^2)) / (2 * epsilon)
36
u = exp(-l * t) * (exp(lambda_1 * x[1]) - exp(lambda_2 * x[1])) +
37
cos(pi * x[2]) * (exp(s1 * x[1]) - exp(r1 * x[1])) / (exp(-s1) - exp(-r1))
38
return SVector{1}(u)
39
end
40
initial_condition = initial_condition_eriksson_johnson
41
42
boundary_conditions = (; x_neg = BoundaryConditionDirichlet(initial_condition),
43
y_neg = BoundaryConditionDirichlet(initial_condition),
44
z_neg = boundary_condition_do_nothing,
45
y_pos = BoundaryConditionDirichlet(initial_condition),
46
x_pos = boundary_condition_do_nothing,
47
z_pos = boundary_condition_do_nothing)
48
49
boundary_conditions_parabolic = BoundaryConditionDirichlet(initial_condition)
50
51
# A semidiscretization collects data structures and functions for the spatial discretization
52
semi = SemidiscretizationHyperbolicParabolic(mesh,
53
(equations, equations_parabolic),
54
initial_condition, solver;
55
solver_parabolic = ParabolicFormulationBassiRebay1(),
56
boundary_conditions = (boundary_conditions,
57
boundary_conditions_parabolic))
58
59
###############################################################################
60
# ODE solvers, callbacks etc.
61
62
# Create ODE problem with time span `tspan`
63
tspan = (0.0, 0.5)
64
ode = semidiscretize(semi, tspan)
65
66
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
67
# and resets the timers
68
summary_callback = SummaryCallback()
69
70
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
71
analysis_interval = 100
72
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
73
74
# The AliveCallback prints short status information in regular intervals
75
alive_callback = AliveCallback(analysis_interval = analysis_interval)
76
77
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
78
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback)
79
80
###############################################################################
81
# run the simulation
82
83
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
84
time_int_tol = 1.0e-11
85
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
86
ode_default_options()..., callback = callbacks)
87
88