Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/solvers/dgsem_tree/container_parabolic_3d.jl
5591 views
1
mutable struct ParabolicContainer3D{uEltype <: Real}
2
u_transformed::Array{uEltype, 5}
3
gradients::NTuple{3, Array{uEltype, 5}}
4
flux_parabolic::NTuple{3, Array{uEltype, 5}}
5
6
# internal `resize!`able storage
7
_u_transformed::Vector{uEltype}
8
# Use Tuple for outer, fixed-size datastructure
9
_gradients::Tuple{Vector{uEltype}, Vector{uEltype}, Vector{uEltype}}
10
_flux_parabolic::Tuple{Vector{uEltype}, Vector{uEltype}, Vector{uEltype}}
11
12
function ParabolicContainer3D{uEltype}(n_vars::Integer, n_nodes::Integer,
13
n_elements::Integer) where {uEltype <: Real}
14
return new(Array{uEltype, 5}(undef, n_vars, n_nodes, n_nodes, n_nodes, n_elements), # `u_transformed`
15
# `gradients`
16
(Array{uEltype, 5}(undef, n_vars, n_nodes, n_nodes, n_nodes, n_elements),
17
Array{uEltype, 5}(undef, n_vars, n_nodes, n_nodes, n_nodes, n_elements),
18
Array{uEltype, 5}(undef, n_vars, n_nodes, n_nodes, n_nodes, n_elements)),
19
# `flux_parabolic`
20
(Array{uEltype, 5}(undef, n_vars, n_nodes, n_nodes, n_nodes, n_elements),
21
Array{uEltype, 5}(undef, n_vars, n_nodes, n_nodes, n_nodes, n_elements),
22
Array{uEltype, 5}(undef, n_vars, n_nodes, n_nodes, n_nodes, n_elements)),
23
# `u_transformed`
24
Vector{uEltype}(undef, n_vars * n_nodes^3 * n_elements),
25
# `_gradients`
26
(Vector{uEltype}(undef, n_vars * n_nodes^3 * n_elements),
27
Vector{uEltype}(undef, n_vars * n_nodes^3 * n_elements),
28
Vector{uEltype}(undef, n_vars * n_nodes^3 * n_elements)),
29
# `_flux_parabolic`
30
(Vector{uEltype}(undef, n_vars * n_nodes^3 * n_elements),
31
Vector{uEltype}(undef, n_vars * n_nodes^3 * n_elements),
32
Vector{uEltype}(undef, n_vars * n_nodes^3 * n_elements)))
33
end
34
end
35
36
function init_parabolic_container_3d(n_vars::Integer, n_nodes::Integer,
37
n_elements::Integer,
38
::Type{uEltype}) where {uEltype <: Real}
39
return ParabolicContainer3D{uEltype}(n_vars, n_nodes, n_elements)
40
end
41
42
# Only one-dimensional `Array`s are `resize!`able in Julia.
43
# Hence, we use `Vector`s as internal storage and `resize!`
44
# them whenever needed. Then, we reuse the same memory by
45
# `unsafe_wrap`ping multi-dimensional `Array`s around the
46
# internal storage.
47
function Base.resize!(parabolic_container::ParabolicContainer3D, equations, dg, cache)
48
capacity = nvariables(equations) * nnodes(dg)^3 * nelements(dg, cache)
49
resize!(parabolic_container._u_transformed, capacity)
50
for dim in 1:3
51
resize!(parabolic_container._gradients[dim], capacity)
52
resize!(parabolic_container._flux_parabolic[dim], capacity)
53
end
54
55
parabolic_container.u_transformed = unsafe_wrap(Array,
56
pointer(parabolic_container._u_transformed),
57
(nvariables(equations),
58
nnodes(dg), nnodes(dg), nnodes(dg),
59
nelements(dg, cache)))
60
61
gradients_1 = unsafe_wrap(Array,
62
pointer(parabolic_container._gradients[1]),
63
(nvariables(equations),
64
nnodes(dg), nnodes(dg), nnodes(dg),
65
nelements(dg, cache)))
66
gradients_2 = unsafe_wrap(Array,
67
pointer(parabolic_container._gradients[2]),
68
(nvariables(equations),
69
nnodes(dg), nnodes(dg), nnodes(dg),
70
nelements(dg, cache)))
71
gradients_3 = unsafe_wrap(Array,
72
pointer(parabolic_container._gradients[3]),
73
(nvariables(equations),
74
nnodes(dg), nnodes(dg), nnodes(dg),
75
nelements(dg, cache)))
76
77
parabolic_container.gradients = (gradients_1, gradients_2, gradients_3)
78
79
flux_parabolic_1 = unsafe_wrap(Array,
80
pointer(parabolic_container._flux_parabolic[1]),
81
(nvariables(equations),
82
nnodes(dg), nnodes(dg), nnodes(dg),
83
nelements(dg, cache)))
84
flux_parabolic_2 = unsafe_wrap(Array,
85
pointer(parabolic_container._flux_parabolic[2]),
86
(nvariables(equations),
87
nnodes(dg), nnodes(dg), nnodes(dg),
88
nelements(dg, cache)))
89
flux_parabolic_3 = unsafe_wrap(Array,
90
pointer(parabolic_container._flux_parabolic[3]),
91
(nvariables(equations),
92
nnodes(dg), nnodes(dg), nnodes(dg),
93
nelements(dg, cache)))
94
95
parabolic_container.flux_parabolic = (flux_parabolic_1, flux_parabolic_2,
96
flux_parabolic_3)
97
98
return nothing
99
end
100
101