Path: blob/main/src/solvers/dgsem_tree/container_parabolic_2d.jl
5590 views
mutable struct ParabolicContainer2D{uEltype <: Real}1u_transformed::Array{uEltype, 4}2gradients::NTuple{2, Array{uEltype, 4}}3flux_parabolic::NTuple{2, Array{uEltype, 4}}45# internal `resize!`able storage6_u_transformed::Vector{uEltype}7# Use Tuple for outer, fixed-size datastructure8_gradients::Tuple{Vector{uEltype}, Vector{uEltype}}9_flux_parabolic::Tuple{Vector{uEltype}, Vector{uEltype}}1011function ParabolicContainer2D{uEltype}(n_vars::Integer, n_nodes::Integer,12n_elements::Integer) where {uEltype <: Real}13return new(Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements), # `u_transformed`14# `gradients`15(Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements),16Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements)),17# `flux_parabolic`18(Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements),19Array{uEltype, 4}(undef, n_vars, n_nodes, n_nodes, n_elements)),20# `_u_transformed`21Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements),22# `_gradients`23(Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements),24Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements)),25# `_flux_parabolic`26(Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements),27Vector{uEltype}(undef, n_vars * n_nodes^2 * n_elements)))28end29end3031function init_parabolic_container_2d(n_vars::Integer, n_nodes::Integer,32n_elements::Integer,33::Type{uEltype}) where {uEltype <: Real}34return ParabolicContainer2D{uEltype}(n_vars, n_nodes, n_elements)35end3637# Only one-dimensional `Array`s are `resize!`able in Julia.38# Hence, we use `Vector`s as internal storage and `resize!`39# them whenever needed. Then, we reuse the same memory by40# `unsafe_wrap`ping multi-dimensional `Array`s around the41# internal storage.42function Base.resize!(parabolic_container::ParabolicContainer2D, equations, dg, cache)43capacity = nvariables(equations) * nnodes(dg)^2 * nelements(dg, cache)44resize!(parabolic_container._u_transformed, capacity)45for dim in 1:246resize!(parabolic_container._gradients[dim], capacity)47resize!(parabolic_container._flux_parabolic[dim], capacity)48end4950parabolic_container.u_transformed = unsafe_wrap(Array,51pointer(parabolic_container._u_transformed),52(nvariables(equations),53nnodes(dg), nnodes(dg),54nelements(dg, cache)))5556gradients_1 = unsafe_wrap(Array,57pointer(parabolic_container._gradients[1]),58(nvariables(equations),59nnodes(dg), nnodes(dg),60nelements(dg, cache)))61gradients_2 = unsafe_wrap(Array,62pointer(parabolic_container._gradients[2]),63(nvariables(equations),64nnodes(dg), nnodes(dg),65nelements(dg, cache)))6667parabolic_container.gradients = (gradients_1, gradients_2)6869flux_parabolic_1 = unsafe_wrap(Array,70pointer(parabolic_container._flux_parabolic[1]),71(nvariables(equations),72nnodes(dg), nnodes(dg),73nelements(dg, cache)))74flux_parabolic_2 = unsafe_wrap(Array,75pointer(parabolic_container._flux_parabolic[2]),76(nvariables(equations),77nnodes(dg), nnodes(dg),78nelements(dg, cache)))7980parabolic_container.flux_parabolic = (flux_parabolic_1, flux_parabolic_2)8182return nothing83end848586