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_1d.jl
5591 views
1
mutable struct ParabolicContainer1D{uEltype <: Real}
2
u_transformed::Array{uEltype, 3}
3
gradients::Array{uEltype, 3}
4
flux_parabolic::Array{uEltype, 3}
5
6
# internal `resize!`able storage
7
_u_transformed::Vector{uEltype}
8
_gradients::Vector{uEltype}
9
_flux_parabolic::Vector{uEltype}
10
11
function ParabolicContainer1D{uEltype}(n_vars::Integer, n_nodes::Integer,
12
n_elements::Integer) where {uEltype <: Real}
13
return new(Array{uEltype, 3}(undef, n_vars, n_nodes, n_elements),
14
Array{uEltype, 3}(undef, n_vars, n_nodes, n_elements),
15
Array{uEltype, 3}(undef, n_vars, n_nodes, n_elements),
16
Vector{uEltype}(undef, n_vars * n_nodes * n_elements),
17
Vector{uEltype}(undef, n_vars * n_nodes * n_elements),
18
Vector{uEltype}(undef, n_vars * n_nodes * n_elements))
19
end
20
end
21
22
function init_parabolic_container_1d(n_vars::Integer, n_nodes::Integer,
23
n_elements::Integer,
24
::Type{uEltype}) where {uEltype <: Real}
25
return ParabolicContainer1D{uEltype}(n_vars, n_nodes, n_elements)
26
end
27
28
# Only one-dimensional `Array`s are `resize!`able in Julia.
29
# Hence, we use `Vector`s as internal storage and `resize!`
30
# them whenever needed. Then, we reuse the same memory by
31
# `unsafe_wrap`ping multi-dimensional `Array`s around the
32
# internal storage.
33
function Base.resize!(parabolic_container::ParabolicContainer1D, equations, dg, cache)
34
capacity = nvariables(equations) * nnodes(dg) * nelements(dg, cache)
35
resize!(parabolic_container._u_transformed, capacity)
36
resize!(parabolic_container._gradients, capacity)
37
resize!(parabolic_container._flux_parabolic, capacity)
38
39
parabolic_container.u_transformed = unsafe_wrap(Array,
40
pointer(parabolic_container._u_transformed),
41
(nvariables(equations),
42
nnodes(dg),
43
nelements(dg, cache)))
44
45
parabolic_container.gradients = unsafe_wrap(Array,
46
pointer(parabolic_container._gradients),
47
(nvariables(equations),
48
nnodes(dg),
49
nelements(dg, cache)))
50
51
parabolic_container.flux_parabolic = unsafe_wrap(Array,
52
pointer(parabolic_container._flux_parabolic),
53
(nvariables(equations),
54
nnodes(dg),
55
nelements(dg, cache)))
56
57
return nothing
58
end
59
60