Skip to content

Commit 6f478bc

Browse files
More abstract containers (#2632)
* More `AbstractContainers` * fmt * fmt * fix * bb * bf * bf * bf * rm --------- Co-authored-by: Hendrik Ranocha <[email protected]>
1 parent e5a3186 commit 6f478bc

File tree

9 files changed

+83
-51
lines changed

9 files changed

+83
-51
lines changed

src/solvers/dgsem/containers.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
2+
# Since these FMAs can increase the performance of many numerical algorithms,
3+
# we need to opt-in explicitly.
4+
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
5+
@muladd begin
6+
#! format: noindent
7+
8+
abstract type AbstractElementContainer <: AbstractContainer end
9+
function nelements end
10+
11+
abstract type AbstractInterfaceContainer <: AbstractContainer end
12+
function ninterfaces end
13+
abstract type AbstractMPIInterfaceContainer <: AbstractContainer end
14+
function nmpiinterfaces end
15+
16+
abstract type AbstractBoundaryContainer <: AbstractContainer end
17+
function nboundaries end
18+
19+
abstract type AbstractMortarContainer <: AbstractContainer end
20+
function nmortars end
21+
abstract type AbstractMPIMortarContainer <: AbstractContainer end
22+
function nmpimortars end
23+
end # @muladd

src/solvers/dgsem/dgsem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,6 @@ end
132132
return u_mean / total_volume # normalize with the total volume
133133
end
134134

135+
include("containers.jl")
135136
include("calc_volume_integral.jl")
136137
end # @muladd

src/solvers/dgsem_p4est/containers.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mutable struct P4estElementContainer{NDIMS, RealT <: Real, uEltype <: Real,
1414
ArrayuEltypeNDIMSP2 <:
1515
DenseArray{uEltype, NDIMSP2},
1616
VectoruEltype <: DenseVector{uEltype}} <:
17-
AbstractContainer
17+
AbstractElementContainer
1818
# Physical coordinates at each node
1919
node_coordinates::ArrayRealTNDIMSP2 # [orientation, node_i, node_j, node_k, element]
2020

@@ -222,7 +222,7 @@ mutable struct P4estInterfaceContainer{NDIMS, uEltype <: Real, NDIMSP2,
222222
IdsVector <: DenseVector{Int},
223223
IndicesVector <:
224224
DenseVector{NTuple{NDIMS, Symbol}}} <:
225-
AbstractContainer
225+
AbstractInterfaceContainer
226226
u::uArray # [primary/secondary, variable, i, j, interface]
227227
neighbor_ids::IdsMatrix # [primary/secondary, interface]
228228
node_indices::IndicesMatrix # [primary/secondary, interface]
@@ -344,7 +344,7 @@ mutable struct P4estBoundaryContainer{NDIMS, uEltype <: Real, NDIMSP1,
344344
IndicesVector <:
345345
DenseVector{NTuple{NDIMS, Symbol}},
346346
uVector <: DenseVector{uEltype}} <:
347-
AbstractContainer
347+
AbstractBoundaryContainer
348348
u::uArray # [variables, i, j, boundary]
349349
neighbor_ids::IdsVector # [boundary]
350350
node_indices::IndicesVector # [boundary]
@@ -510,7 +510,7 @@ mutable struct P4estMortarContainer{NDIMS, uEltype <: Real, NDIMSP1, NDIMSP3,
510510
IdsVector <: DenseVector{Int},
511511
IndicesVector <:
512512
DenseVector{NTuple{NDIMS, Symbol}}} <:
513-
AbstractContainer
513+
AbstractMortarContainer
514514
u::uArray # [small/large side, variable, position, i, j, mortar]
515515
neighbor_ids::IdsMatrix # [position, mortar]
516516
node_indices::IndicesMatrix # [small/large, mortar]

src/solvers/dgsem_p4est/containers_parallel.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mutable struct P4estMPIInterfaceContainer{NDIMS, uEltype <: Real, NDIMSP2,
1111
IndicesVector <:
1212
DenseVector{NTuple{NDIMS, Symbol}},
1313
uVector <: DenseVector{uEltype}} <:
14-
AbstractContainer
14+
AbstractMPIInterfaceContainer
1515
u::uArray # [primary/secondary, variable, i, j, interface]
1616
local_neighbor_ids::VecInt # [interface]
1717
node_indices::IndicesVector # [interface]
@@ -124,7 +124,7 @@ mutable struct P4estMPIMortarContainer{NDIMS, uEltype <: Real, RealT <: Real, ND
124124
NDIMSP2, NDIMSP3,
125125
uArray <: DenseArray{uEltype, NDIMSP3},
126126
uVector <: DenseVector{uEltype}} <:
127-
AbstractContainer
127+
AbstractMPIMortarContainer
128128
u::uArray # [small/large side, variable, position, i, j, mortar]
129129
local_neighbor_ids::Vector{Vector{Int}} # [mortar][ids]
130130
local_neighbor_positions::Vector{Vector{Int}} # [mortar][positions]

src/solvers/dgsem_structured/containers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#! format: noindent
77

88
struct StructuredElementContainer{NDIMS, RealT <: Real, uEltype <: Real,
9-
NDIMSP1, NDIMSP2, NDIMSP3}
9+
NDIMSP1, NDIMSP2, NDIMSP3} <: AbstractElementContainer
1010
# Physical coordinates at each node
1111
node_coordinates::Array{RealT, NDIMSP2} # [orientation, node_i, node_j, node_k, element]
1212
# ID of neighbor element in negative direction in orientation

src/solvers/dgsem_tree/containers.jl

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Dimension independent code related to containers of the DG solver
99
# with the mesh type TreeMesh
1010

11-
abstract type AbstractTreeElementContainer <: AbstractContainer end
11+
abstract type AbstractTreeElementContainer <: AbstractElementContainer end
1212

1313
# Return number of elements
1414
@inline nelements(elements::AbstractTreeElementContainer) = length(elements.cell_ids)
@@ -30,7 +30,7 @@ In particular, not the elements themselves are returned.
3030
@inline Base.real(elements::AbstractTreeElementContainer) = eltype(elements.node_coordinates)
3131
@inline Base.eltype(elements::AbstractTreeElementContainer) = eltype(elements.surface_flux_values)
3232

33-
abstract type AbstractTreeInterfaceContainer <: AbstractContainer end
33+
abstract type AbstractTreeInterfaceContainer <: AbstractInterfaceContainer end
3434

3535
# Return number of interfaces
3636
@inline ninterfaces(interfaces::AbstractTreeInterfaceContainer) = length(interfaces.orientations)
@@ -39,7 +39,19 @@ abstract type AbstractTreeInterfaceContainer <: AbstractContainer end
3939
# Return number of equation variables
4040
@inline nvariables(interfaces::AbstractTreeInterfaceContainer) = size(interfaces.u, 2)
4141

42-
abstract type AbstractTreeBoundaryContainer <: AbstractContainer end
42+
abstract type AbstractTreeMPIInterfaceContainer <: AbstractMPIInterfaceContainer end
43+
44+
# Return number of interfaces
45+
@inline function nmpiinterfaces(mpi_interfaces::AbstractTreeMPIInterfaceContainer)
46+
return length(mpi_interfaces.orientations)
47+
end
48+
# Return number of interface nodes for 2D and 3D. For 1D hard-coded to 1 interface node.
49+
@inline nnodes(interfaces::AbstractTreeMPIInterfaceContainer) = size(interfaces.u, 3)
50+
# Return number of equation variables
51+
@inline nvariables(interfaces::AbstractTreeMPIInterfaceContainer) = size(interfaces.u,
52+
2)
53+
54+
abstract type AbstractTreeBoundaryContainer <: AbstractBoundaryContainer end
4355

4456
# Return number of boundaries
4557
@inline nboundaries(boundaries::AbstractTreeBoundaryContainer) = length(boundaries.orientations)
@@ -48,11 +60,18 @@ abstract type AbstractTreeBoundaryContainer <: AbstractContainer end
4860
# Return number of equation variables
4961
@inline nvariables(boundaries::AbstractTreeBoundaryContainer) = size(boundaries.u, 2)
5062

51-
abstract type AbstractTreeL2MortarContainer <: AbstractContainer end
63+
abstract type AbstractTreeL2MortarContainer <: AbstractMortarContainer end
5264

5365
# Return number of L2 mortars
5466
@inline nmortars(l2mortars::AbstractTreeL2MortarContainer) = length(l2mortars.orientations)
5567

68+
abstract type AbstractTreeL2MPIMortarContainer <: AbstractMPIMortarContainer end
69+
70+
# Return number of L2 mortars
71+
@inline function nmpimortars(mpi_l2mortars::AbstractTreeL2MPIMortarContainer)
72+
length(mpi_l2mortars.orientations)
73+
end
74+
5675
function reinitialize_containers!(mesh::TreeMesh, equations, dg::DGSEM, cache)
5776
# Get new list of leaf cells
5877
leaf_cell_ids = local_leaf_cells(mesh.tree)

src/solvers/dgsem_tree/containers_2d.jl

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,6 @@ function init_boundaries!(boundaries, elements, mesh::TreeMesh2D)
471471
return boundaries.n_boundaries_per_direction
472472
end
473473

474-
abstract type AbstractTreeL2MortarContainer2D <: AbstractTreeL2MortarContainer end
475-
476-
# Return number of mortar nodes (L2 mortars are only h-adaptive, not p-adaptive)
477-
@inline nnodes(mortars::AbstractTreeL2MortarContainer2D) = size(mortars.u_upper, 3)
478-
# Return number of equation variables
479-
@inline nvariables(mortars::AbstractTreeL2MortarContainer2D) = size(mortars.u_upper, 2)
480-
481474
# Container data structure (structure-of-arrays style) for DG L2 mortars
482475
# Positions/directions for orientations = 1, large_sides = 2:
483476
# mortar is orthogonal to x-axis, large side is in positive coordinate direction wrt mortar
@@ -489,7 +482,7 @@ abstract type AbstractTreeL2MortarContainer2D <: AbstractTreeL2MortarContainer e
489482
# lower = 1 | |
490483
# | |
491484
mutable struct TreeL2MortarContainer2D{uEltype <: Real} <:
492-
AbstractTreeL2MortarContainer2D
485+
AbstractTreeL2MortarContainer
493486
u_upper::Array{uEltype, 4} # [leftright, variables, i, mortars]
494487
u_lower::Array{uEltype, 4} # [leftright, variables, i, mortars]
495488
neighbor_ids::Array{Int, 2} # [position, mortars]
@@ -502,6 +495,11 @@ mutable struct TreeL2MortarContainer2D{uEltype <: Real} <:
502495
_neighbor_ids::Vector{Int}
503496
end
504497

498+
# Return number of mortar nodes (L2 mortars are only h-adaptive, not p-adaptive)
499+
@inline nnodes(mortars::TreeL2MortarContainer2D) = size(mortars.u_upper, 3)
500+
# Return number of equation variables
501+
@inline nvariables(mortars::TreeL2MortarContainer2D) = size(mortars.u_upper, 2)
502+
505503
# See explanation of Base.resize! for the element container
506504
function Base.resize!(mortars::TreeL2MortarContainer2D, capacity)
507505
n_nodes = nnodes(mortars)
@@ -741,7 +739,7 @@ end
741739

742740
# Container data structure (structure-of-arrays style) for DG MPI interfaces
743741
mutable struct TreeMPIInterfaceContainer2D{uEltype <: Real} <:
744-
AbstractTreeInterfaceContainer
742+
AbstractTreeMPIInterfaceContainer
745743
u::Array{uEltype, 4} # [leftright, variables, i, interfaces]
746744
# Note: `local_neighbor_ids` stores the MPI-local neighbors, but with globally valid index!
747745
local_neighbor_ids::Vector{Int} # [interfaces]
@@ -789,12 +787,6 @@ function TreeMPIInterfaceContainer2D{uEltype}(capacity::Integer, n_variables,
789787
remote_sides, _u)
790788
end
791789

792-
# TODO: Taal, rename to ninterfaces?
793-
# Return number of interfaces
794-
@inline function nmpiinterfaces(mpi_interfaces::TreeMPIInterfaceContainer2D)
795-
length(mpi_interfaces.orientations)
796-
end
797-
798790
# Create MPI interface container and initialize MPI interface data in `elements`.
799791
function init_mpi_interfaces(cell_ids, mesh::TreeMesh2D,
800792
elements::TreeElementContainer2D)
@@ -913,7 +905,7 @@ end
913905
# lower = 1 | |
914906
# | |
915907
mutable struct TreeMPIL2MortarContainer2D{uEltype <: Real} <:
916-
AbstractTreeL2MortarContainer2D
908+
AbstractTreeL2MPIMortarContainer
917909
u_upper::Array{uEltype, 4} # [leftright, variables, i, mortars]
918910
u_lower::Array{uEltype, 4} # [leftright, variables, i, mortars]
919911
# Note: `local_neighbor_ids` stores the MPI-local neighbors, but with globally valid index!
@@ -927,6 +919,11 @@ mutable struct TreeMPIL2MortarContainer2D{uEltype <: Real} <:
927919
_u_lower::Vector{uEltype}
928920
end
929921

922+
# Return number of mortar nodes (L2 mortars are only h-adaptive, not p-adaptive)
923+
@inline nnodes(mortars::TreeMPIL2MortarContainer2D) = size(mortars.u_upper, 3)
924+
# Return number of equation variables
925+
@inline nvariables(mortars::TreeMPIL2MortarContainer2D) = size(mortars.u_upper, 2)
926+
930927
# See explanation of Base.resize! for the element container
931928
function Base.resize!(mpi_mortars::TreeMPIL2MortarContainer2D, capacity)
932929
n_nodes = nnodes(mpi_mortars)
@@ -979,11 +976,6 @@ function TreeMPIL2MortarContainer2D{uEltype}(capacity::Integer, n_variables,
979976
_u_upper, _u_lower)
980977
end
981978

982-
# Return number of L2 mortars
983-
@inline function nmpimortars(mpi_l2mortars::TreeMPIL2MortarContainer2D)
984-
length(mpi_l2mortars.orientations)
985-
end
986-
987979
# Create MPI mortar container and initialize MPI mortar data in `elements`.
988980
function init_mpi_mortars(cell_ids, mesh::TreeMesh2D,
989981
elements::TreeElementContainer2D,

src/solvers/dgsem_unstructured/containers_2d.jl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#! format: noindent
77

88
# Container data structure (structure-of-arrays style) for DG elements on curved unstructured mesh
9-
struct UnstructuredElementContainer2D{RealT <: Real, uEltype <: Real}
9+
struct UnstructuredElementContainer2D{RealT <: Real, uEltype <: Real} <:
10+
AbstractElementContainer
1011
node_coordinates::Array{RealT, 4} # [ndims, nnodes, nnodes, nelement]
1112
jacobian_matrix::Array{RealT, 5} # [ndims, ndims, nnodes, nnodes, nelement]
1213
inverse_jacobian::Array{RealT, 3} # [nnodes, nnodes, nelement]
@@ -117,12 +118,13 @@ function init_element!(elements, element, basis::LobattoLegendreBasis,
117118
end
118119

119120
# generic container for the interior interfaces of an unstructured mesh
120-
struct UnstructuredInterfaceContainer2D{uEltype <: Real}
121-
u::Array{uEltype, 4} # [primary/secondary, variables, i, interfaces]
122-
start_index::Vector{Int} # [interfaces]
123-
index_increment::Vector{Int} # [interfaces]
124-
element_ids::Array{Int, 2} # [primary/secondary, interfaces]
125-
element_side_ids::Array{Int, 2} # [primary/secondary, interfaces]
121+
struct UnstructuredInterfaceContainer2D{uEltype <: Real} <:
122+
AbstractInterfaceContainer
123+
u::Array{uEltype, 4} # [primary/secondary, variables, i, interfaces]
124+
start_index::Vector{Int} # [interfaces]
125+
index_increment::Vector{Int} # [interfaces]
126+
element_ids::Array{Int, 2} # [primary/secondary, interfaces]
127+
element_side_ids::Array{Int, 2} # [primary/secondary, interfaces]
126128
end
127129

128130
# Construct an empty curved interface container to be filled later with neighbour
@@ -255,12 +257,13 @@ end
255257

256258
# TODO: Clean-up meshes. Find a better name since it's also used for other meshes
257259
# generic container for the boundary interfaces of an unstructured mesh
258-
struct UnstructuredBoundaryContainer2D{RealT <: Real, uEltype <: Real}
259-
u::Array{uEltype, 3} # [variables, i, boundaries]
260-
element_id::Vector{Int} # [boundaries]
261-
element_side_id::Vector{Int} # [boundaries]
262-
node_coordinates::Array{RealT, 3} # [ndims, nnodes, boundaries]
263-
name::Vector{Symbol} # [boundaries]
260+
struct UnstructuredBoundaryContainer2D{RealT <: Real, uEltype <: Real} <:
261+
AbstractBoundaryContainer
262+
u::Array{uEltype, 3} # [variables, i, boundaries]
263+
element_id::Vector{Int} # [boundaries]
264+
element_side_id::Vector{Int} # [boundaries]
265+
node_coordinates::Array{RealT, 3} # [ndims, nnodes, boundaries]
266+
name::Vector{Symbol} # [boundaries]
264267
end
265268

266269
# construct an empty curved boundary container to be filled later with neighbour

test/test_unstructured_2d.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ isdir(outdir) && rm(outdir, recursive = true)
2828
# Ensure that we do not have excessive memory allocations
2929
# (e.g., from type instabilities)
3030
@test_allocations(Trixi.rhs!, semi, sol, 1000)
31-
semi32 = Trixi.trixi_adapt(Array, Float32, semi)
32-
@test real(semi32.solver) == Float32
33-
@test real(semi32.solver.basis) == Float32
34-
@test real(semi32.solver.mortar) == Float32
35-
# TODO: remake ignores the mesh as well
36-
@test real(semi32.mesh) == Float64
3731
end
3832

3933
@trixi_testset "elixir_euler_free_stream.jl" begin

0 commit comments

Comments
 (0)