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