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_2d.jl
5590 views
1
mutable struct ParabolicContainer2D{uEltype <: Real}
2
u_transformed::Array{uEltype, 4}
3
gradients::NTuple{2, Array{uEltype, 4}}
4
flux_parabolic::NTuple{2, Array{uEltype, 4}}
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}}
10
_flux_parabolic::Tuple{Vector{uEltype}, Vector{uEltype}}
11
12
function ParabolicContainer2D{uEltype}(n_vars::Integer, n_nodes::Integer,
13
n_elements::Integer) where {uEltype <: Real}
14
return new(Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements), # `u_transformed`
15
# `gradients`
16
(Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements),
17
Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements)),
18
# `flux_parabolic`
19
(Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements),
20
Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements)),
21
# `_u_transformed`
22
Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements),
23
# `_gradients`
24
(Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements),
25
Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements)),
26
# `_flux_parabolic`
27
(Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements),
28
Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements)))
29
end
30
end
31
32
function init_parabolic_container_2d(n_vars::Integer, n_nodes::Integer,
33
n_elements::Integer,
34
::Type{uEltype}) where {uEltype <: Real}
35
return ParabolicContainer2D{uEltype}(n_vars, n_nodes, n_elements)
36
end
37
38
# Only one-dimensional `Array`s are `resize!`able in Julia.
39
# Hence, we use `Vector`s as internal storage and `resize!`
40
# them whenever needed. Then, we reuse the same memory by
41
# `unsafe_wrap`ping multi-dimensional `Array`s around the
42
# internal storage.
43
function Base.resize!(parabolic_container::ParabolicContainer2D, equations, dg, cache)
44
capacity = nvariables(equations) * nnodes(dg)^2 * nelements(dg, cache)
45
resize!(parabolic_container._u_transformed, capacity)
46
for dim in 1:2
47
resize!(parabolic_container._gradients[dim], capacity)
48
resize!(parabolic_container._flux_parabolic[dim], capacity)
49
end
50
51
parabolic_container.u_transformed = unsafe_wrap(Array,
52
pointer(parabolic_container._u_transformed),
53
(nvariables(equations),
54
nnodes(dg), nnodes(dg),
55
nelements(dg, cache)))
56
57
gradients_1 = unsafe_wrap(Array,
58
pointer(parabolic_container._gradients[1]),
59
(nvariables(equations),
60
nnodes(dg), nnodes(dg),
61
nelements(dg, cache)))
62
gradients_2 = unsafe_wrap(Array,
63
pointer(parabolic_container._gradients[2]),
64
(nvariables(equations),
65
nnodes(dg), nnodes(dg),
66
nelements(dg, cache)))
67
68
parabolic_container.gradients = (gradients_1, gradients_2)
69
70
flux_parabolic_1 = unsafe_wrap(Array,
71
pointer(parabolic_container._flux_parabolic[1]),
72
(nvariables(equations),
73
nnodes(dg), nnodes(dg),
74
nelements(dg, cache)))
75
flux_parabolic_2 = unsafe_wrap(Array,
76
pointer(parabolic_container._flux_parabolic[2]),
77
(nvariables(equations),
78
nnodes(dg), nnodes(dg),
79
nelements(dg, cache)))
80
81
parabolic_container.flux_parabolic = (flux_parabolic_1, flux_parabolic_2)
82
83
return nothing
84
end
85
86