Path: blob/main/src/solvers/dgsem_structured/containers.jl
5591 views
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).1# Since these FMAs can increase the performance of many numerical algorithms,2# we need to opt-in explicitly.3# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.4@muladd begin5#! format: noindent67struct StructuredElementContainer{NDIMS, RealT <: Real, uEltype <: Real,8NDIMSP1, NDIMSP2, NDIMSP3} <: AbstractElementContainer9# Physical coordinates at each node10node_coordinates::Array{RealT, NDIMSP2} # [orientation, node_i, node_j, node_k, element]1112# Physical coordinates at boundary nodes13boundary_node_coordinates::Array{RealT, NDIMSP1} # [orientation, node_i, node_j, direction/face]1415# ID of neighbor element in negative direction in orientation16left_neighbors::Array{Int, 2} # [orientation, elements]1718# Jacobian matrix of the transformation19# [jacobian_i, jacobian_j, node_i, node_j, node_k, element] where jacobian_i is the first index of the Jacobian matrix20jacobian_matrix::Array{RealT, NDIMSP3}2122# Contravariant vectors, scaled by J, in Kopriva's blue book called Ja^i_n (i index, n dimension)23contravariant_vectors::Array{RealT, NDIMSP3} # [dimension, index, node_i, node_j, node_k, element]2425# 1/J where J is the Jacobian determinant (determinant of Jacobian matrix)26inverse_jacobian::Array{RealT, NDIMSP1} # [node_i, node_j, node_k, element]2728# Buffer for solution values at interfaces (filled by `prolong2interfaces!`)29interfaces_u::Array{uEltype, NDIMSP2} # [variable, i, j, direction, element]3031# Buffer for calculated surface flux32surface_flux_values::Array{uEltype, NDIMSP2} # [variable, i, j, direction, element]33end3435# Create element container and initialize element data36function init_elements(mesh::Union{StructuredMesh{NDIMS, RealT},37StructuredMeshView{NDIMS, RealT}},38equations::AbstractEquations,39basis,40::Type{uEltype}) where {NDIMS, RealT <: Real, uEltype <: Real}41nelements = prod(size(mesh))42node_coordinates = Array{RealT, NDIMS + 2}(undef, NDIMS,43ntuple(_ -> nnodes(basis), NDIMS)...,44nelements)45boundary_node_coordinates = Array{RealT, NDIMS + 1}(undef, NDIMS,46ntuple(_ -> nnodes(basis),47NDIMS - 1)...,48NDIMS * 2)49left_neighbors = Array{Int, 2}(undef, NDIMS, nelements)50jacobian_matrix = Array{RealT, NDIMS + 3}(undef, NDIMS, NDIMS,51ntuple(_ -> nnodes(basis), NDIMS)...,52nelements)53contravariant_vectors = similar(jacobian_matrix)54inverse_jacobian = Array{RealT, NDIMS + 1}(undef,55ntuple(_ -> nnodes(basis), NDIMS)...,56nelements)57interfaces_u = Array{uEltype, NDIMS + 2}(undef, nvariables(equations),58ntuple(_ -> nnodes(basis),59NDIMS - 1)..., NDIMS * 2,60nelements)61surface_flux_values = Array{uEltype, NDIMS + 2}(undef, nvariables(equations),62ntuple(_ -> nnodes(basis),63NDIMS - 1)..., NDIMS * 2,64nelements)6566elements = StructuredElementContainer{NDIMS, RealT, uEltype,67NDIMS + 1, NDIMS + 2, NDIMS + 3}(node_coordinates,68boundary_node_coordinates,69left_neighbors,70jacobian_matrix,71contravariant_vectors,72inverse_jacobian,73interfaces_u,74surface_flux_values)7576init_elements!(elements, mesh, basis)77return elements78end7980@inline nelements(elements::StructuredElementContainer) = size(elements.left_neighbors,812)8283function Base.eltype(::StructuredElementContainer{NDIMS, RealT, uEltype}) where {NDIMS,84RealT,85uEltype86}87return uEltype88end8990# Essentially equivalent to `get_contravariant_vector` and `get_node_coords`91@inline function get_normal_vector(normal_vectors, indices...)92# Returns SVector{NDIMS} where NDIMS is 2 or 3.93# Can be deduced at compile time from (number of dims - 2) from `normal_vectors` since94# for 2d we have 4 dims (2 two dims for nodes) - 2 => 295# and for 3d we have 5 dims (3 three dims for nodes) - 2 = > 396return SVector(ntuple(@inline(dim->normal_vectors[dim, indices...]),97Val(ndims(normal_vectors) - 2)))98end99100@inline storage_type(::AbstractNormalVectorContainer) = Array101102include("containers_1d.jl")103include("containers_2d.jl")104include("containers_3d.jl")105end # @muladd106107108