Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/p4est_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() = 1 / 17
8
advection_velocity = (1.0, 0.0, 0.0)
9
equations = LinearScalarAdvectionEquation3D(advection_velocity)
10
equations_parabolic = LaplaceDiffusion3D(diffusivity(), equations)
11
12
polydeg = 3
13
solver = DGSEM(polydeg = polydeg, surface_flux = flux_lax_friedrichs)
14
15
coordinates_min = (-1.0, -0.5, -0.5)
16
coordinates_max = (0.0, 0.5, 0.5)
17
18
# Affine type mapping to take the [-1,1]^3 domain
19
# and warp it as described in https://arxiv.org/abs/2012.12040
20
function mapping(xi, eta, zeta)
21
y_ = eta + 1 / 6 * (cos(1.5 * pi * xi) * cos(0.5 * pi * eta) * cos(0.5 * pi * zeta))
22
x_ = xi + 1 / 6 * (cos(0.5 * pi * xi) * cos(2 * pi * y_) * cos(0.5 * pi * zeta))
23
z_ = zeta + 1 / 6 * (cos(0.5 * pi * x_) * cos(pi * y_) * cos(0.5 * pi * zeta))
24
25
# Map from [-1, 1]^3 to [-1, -0.5, -0.5] x [0, 0.5, 0.5]
26
x = 0.5 * (x_ - 1)
27
y = 0.5 * y_
28
z = 0.5 * z_
29
30
return SVector(x, y, z)
31
end
32
33
trees_per_dimension = (5, 3, 3)
34
mesh = P4estMesh(trees_per_dimension, polydeg = polydeg,
35
mapping = mapping, periodicity = false)
36
37
# Example setup taken from
38
# - Truman Ellis, Jesse Chan, and Leszek Demkowicz (2016).
39
# Robust DPG methods for transient convection-diffusion.
40
# In: Building bridges: connections and challenges in modern approaches
41
# to numerical partial differential equations.
42
# [DOI](https://doi.org/10.1007/978-3-319-41640-3_6).
43
function initial_condition_eriksson_johnson(x, t, equations)
44
l = 4
45
epsilon = diffusivity() # NOTE: this requires epsilon <= 1/16 due to sqrt
46
lambda_1 = (-1 + sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
47
lambda_2 = (-1 - sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
48
r1 = (1 + sqrt(1 + 4 * pi^2 * epsilon^2)) / (2 * epsilon)
49
s1 = (1 - sqrt(1 + 4 * pi^2 * epsilon^2)) / (2 * epsilon)
50
u = exp(-l * t) * (exp(lambda_1 * x[1]) - exp(lambda_2 * x[1])) +
51
cos(pi * x[2]) * (exp(s1 * x[1]) - exp(r1 * x[1])) / (exp(-s1) - exp(-r1))
52
return SVector(u)
53
end
54
initial_condition = initial_condition_eriksson_johnson
55
56
boundary_conditions = BoundaryConditionDirichlet(initial_condition)
57
58
semi = SemidiscretizationHyperbolicParabolic(mesh,
59
(equations, equations_parabolic),
60
initial_condition, solver;
61
solver_parabolic = ParabolicFormulationBassiRebay1(),
62
boundary_conditions = (boundary_conditions,
63
boundary_conditions))
64
65
###############################################################################
66
# ODE solvers, callbacks etc.
67
68
tspan = (0.0, 0.5)
69
ode = semidiscretize(semi, tspan)
70
71
summary_callback = SummaryCallback()
72
73
analysis_interval = 100
74
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
75
76
alive_callback = AliveCallback(analysis_interval = analysis_interval)
77
78
stepsize_callback = StepsizeCallback(cfl = 1.6,
79
cfl_parabolic = 0.25)
80
81
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback,
82
stepsize_callback)
83
84
###############################################################################
85
# run the simulation
86
87
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
88
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
89
save_everystep = false, callback = callbacks);
90
91