Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/solvers/dgsem_p4est/dg.jl
5616 views
1
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
2
# Since these FMAs can increase the performance of many numerical algorithms,
3
# we need to opt-in explicitly.
4
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
5
@muladd begin
6
#! format: noindent
7
8
# This method is called when a SemidiscretizationHyperbolic is constructed.
9
# It constructs the basic `cache` used throughout the simulation to compute
10
# the RHS etc.
11
function create_cache(mesh::P4estMesh, equations::AbstractEquations, dg::DG, ::Any,
12
::Type{uEltype}) where {uEltype <: Real}
13
# Make sure to balance the `p4est` before creating any containers
14
# in case someone has tampered with the `p4est` after creating the mesh
15
balance!(mesh)
16
17
elements = init_elements(mesh, equations, dg.basis, uEltype)
18
interfaces = init_interfaces(mesh, equations, dg.basis, elements)
19
boundaries = init_boundaries(mesh, equations, dg.basis, elements)
20
mortars = init_mortars(mesh, equations, dg.basis, elements)
21
22
# Container cache
23
cache = (; elements, interfaces, boundaries, mortars)
24
25
# Add Volume-Integral cache
26
cache = (; cache...,
27
create_cache(mesh, equations, dg.volume_integral, dg, cache, uEltype)...)
28
# Add Mortar cache
29
cache = (; cache..., create_cache(mesh, equations, dg.mortar, uEltype)...)
30
31
return cache
32
end
33
34
# This method is called when a SemidiscretizationHyperbolic is constructed.
35
# It constructs the basic `cache` used throughout the simulation to compute
36
# the RHS etc.
37
function create_cache(mesh::P4estMeshView, equations::AbstractEquations, dg::DG, ::Any,
38
::Type{uEltype}) where {uEltype <: Real}
39
# Make sure to balance the `p4est` before creating any containers
40
# in case someone has tampered with the `p4est` after creating the mesh
41
balance!(mesh.parent)
42
43
elements_parent = init_elements(mesh.parent, equations, dg.basis, uEltype)
44
interfaces_parent = init_interfaces(mesh.parent, equations, dg.basis,
45
elements_parent)
46
boundaries_parent = init_boundaries(mesh.parent, equations, dg.basis,
47
elements_parent)
48
mortars_parent = init_mortars(mesh.parent, equations, dg.basis, elements_parent)
49
50
# Extract data for views.
51
elements, interfaces, boundaries, mortars, neighbor_ids_parent = extract_p4est_mesh_view(elements_parent,
52
interfaces_parent,
53
boundaries_parent,
54
mortars_parent,
55
mesh,
56
equations,
57
dg,
58
uEltype)
59
60
cache = (; elements, interfaces, boundaries, mortars, neighbor_ids_parent)
61
62
# Add Volume-Integral cache
63
cache = (; cache...,
64
create_cache(mesh, equations, dg.volume_integral, dg, uEltype)...)
65
# Add Mortar cache
66
cache = (; cache..., create_cache(mesh, equations, dg.mortar, uEltype)...)
67
68
return cache
69
end
70
71
# Extract outward-pointing normal direction
72
# (contravariant vector ±Ja^i, i = index)
73
# Note that this vector is not normalized
74
@inline function get_normal_direction(direction, contravariant_vectors, indices...)
75
orientation = (direction + 1) >> 1
76
normal = get_contravariant_vector(orientation, contravariant_vectors, indices...)
77
78
# Contravariant vectors at interfaces in negative coordinate direction are pointing inwards,
79
# flip sign to make them point outwards
80
if isodd(direction)
81
return -normal
82
else
83
return normal
84
end
85
end
86
87
include("containers.jl")
88
89
include("dg_2d.jl")
90
include("dg_2d_parabolic.jl")
91
92
include("dg_3d.jl")
93
include("dg_3d_parabolic.jl")
94
include("dg_parallel.jl")
95
96
# Subcell limiters
97
include("subcell_limiters.jl")
98
include("subcell_limiters_2d.jl")
99
include("subcell_limiters_3d.jl")
100
include("dg_3d_subcell_limiters.jl")
101
end # @muladd
102
103