Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/docs/literate/src/files/parabolic_terms.jl
5591 views
1
#src # Parabolic terms (advection-diffusion).
2
3
# Experimental support for parabolic diffusion terms is available in Trixi.jl.
4
# This demo illustrates parabolic terms for the advection-diffusion equation.
5
6
using OrdinaryDiffEqLowStorageRK
7
using Trixi
8
9
# ## Splitting a system into hyperbolic and parabolic parts
10
11
# For a mixed hyperbolic-parabolic system, we represent the hyperbolic and parabolic
12
# parts of the system separately. We first define the hyperbolic (advection) part of
13
# the advection-diffusion equation.
14
15
advection_velocity = (1.5, 1.0)
16
equations_hyperbolic = LinearScalarAdvectionEquation2D(advection_velocity);
17
18
# Next, we define the parabolic diffusion term. The constructor requires knowledge of
19
# `equations_hyperbolic` to be passed in because the [`LaplaceDiffusion2D`](@ref) applies
20
# diffusion to every variable of the hyperbolic system.
21
22
diffusivity = 5.0e-2
23
equations_parabolic = LaplaceDiffusion2D(diffusivity, equations_hyperbolic);
24
25
# ## Boundary conditions
26
27
# As with the equations, we define boundary conditions separately for the hyperbolic and
28
# parabolic part of the system. For this example, we impose inflow BCs for the hyperbolic
29
# system (no condition is imposed on the outflow), and we impose Dirichlet boundary conditions
30
# for the parabolic equations. Both `BoundaryConditionDirichlet` and `BoundaryConditionNeumann`
31
# are defined for `LaplaceDiffusion2D`.
32
#
33
# The hyperbolic and parabolic boundary conditions are assumed to be consistent with each other.
34
35
boundary_condition_zero_dirichlet = BoundaryConditionDirichlet((x, t, equations) -> SVector(0.0))
36
37
boundary_conditions_hyperbolic = (;
38
x_neg = BoundaryConditionDirichlet((x, t, equations) -> SVector(1 +
39
0.5 *
40
x[2])),
41
y_neg = boundary_condition_zero_dirichlet,
42
y_pos = boundary_condition_do_nothing,
43
x_pos = boundary_condition_do_nothing)
44
45
boundary_conditions_parabolic = (;
46
x_neg = BoundaryConditionDirichlet((x, t, equations) -> SVector(1 +
47
0.5 *
48
x[2])),
49
y_neg = boundary_condition_zero_dirichlet,
50
y_pos = boundary_condition_zero_dirichlet,
51
x_pos = boundary_condition_zero_dirichlet);
52
53
# ## Defining the solver and mesh
54
55
# The process of creating the DG solver and mesh is the same as for a purely
56
# hyperbolic system of equations.
57
58
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
59
coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
60
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))
61
mesh = TreeMesh(coordinates_min, coordinates_max,
62
initial_refinement_level = 4,
63
periodicity = false, n_cells_max = 30_000) # set maximum capacity of tree data structure
64
65
initial_condition = (x, t, equations) -> SVector(0.0);
66
67
# ## Semidiscretizing and solving
68
69
# To semidiscretize a hyperbolic-parabolic system, we create a [`SemidiscretizationHyperbolicParabolic`](@ref).
70
# This differs from a [`SemidiscretizationHyperbolic`](@ref) in that we pass in a `Tuple` containing both the
71
# hyperbolic and parabolic equation, as well as a `Tuple` containing the hyperbolic and parabolic
72
# boundary conditions.
73
74
semi = SemidiscretizationHyperbolicParabolic(mesh,
75
(equations_hyperbolic, equations_parabolic),
76
initial_condition, solver;
77
boundary_conditions = (boundary_conditions_hyperbolic,
78
boundary_conditions_parabolic))
79
80
# The rest of the code is identical to the hyperbolic case. We create a system of ODEs through
81
# `semidiscretize`, defining callbacks, and then passing the system to OrdinaryDiffEq.jl.
82
83
tspan = (0.0, 1.5)
84
ode = semidiscretize(semi, tspan)
85
callbacks = CallbackSet(SummaryCallback())
86
time_int_tol = 1.0e-6
87
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
88
ode_default_options()..., callback = callbacks);
89
90
# We can now visualize the solution, which develops a boundary layer at the outflow boundaries.
91
92
using Plots
93
plot(sol)
94
95
# ## Package versions
96
97
# These results were obtained using the following versions.
98
99
using InteractiveUtils
100
versioninfo()
101
102
using Pkg
103
Pkg.status(["Trixi", "OrdinaryDiffEqLowStorageRK", "Plots"],
104
mode = PKGMODE_MANIFEST)
105
106