Skip to content

Commit 1fa0dea

Browse files
AbstractTreeBoundaryContainer (#2624)
* `AbstractTreeBoundaryContainer` * test nnodes * ref * inline * Update src/solvers/dgsem_tree/containers_3d.jl * Update src/solvers/dgsem_tree/containers_3d.jl * Update test/test_unit.jl * Update test/test_unit.jl * Update src/auxiliary/containers.jl
1 parent b051a3d commit 1fa0dea

File tree

5 files changed

+60
-58
lines changed

5 files changed

+60
-58
lines changed

src/auxiliary/containers.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ function storage_type(C::Type{<:AbstractContainer})
350350
return storage_type(Adapt.unwrap_type(C))
351351
end
352352

353+
abstract type AbstractTreeBoundaryContainer <: AbstractContainer end
354+
355+
@inline nvariables(boundaries::AbstractTreeBoundaryContainer) = size(boundaries.u, 2)
356+
# Return number of boundaries
357+
@inline nboundaries(boundaries::AbstractTreeBoundaryContainer) = length(boundaries.orientations)
358+
# For 2D and 3D. 1D Hard-coded to 1
359+
@inline nnodes(boundaries::AbstractTreeBoundaryContainer) = size(boundaries.u, 3)
360+
353361
# backend handling
354362
"""
355363
trixi_backend(x)

src/solvers/dgsem_tree/containers_1d.jl

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ function init_interfaces!(interfaces, elements, mesh::TreeMesh1D)
284284
end
285285

286286
# Container data structure (structure-of-arrays style) for DG boundaries
287-
mutable struct BoundaryContainer1D{RealT <: Real, uEltype <: Real} <: AbstractContainer
287+
mutable struct TreeBoundaryContainer1D{RealT <: Real, uEltype <: Real} <:
288+
AbstractTreeBoundaryContainer
288289
u::Array{uEltype, 3} # [leftright, variables, boundaries]
289290
neighbor_ids::Vector{Int} # [boundaries]
290291
orientations::Vector{Int} # [boundaries]
@@ -296,11 +297,11 @@ mutable struct BoundaryContainer1D{RealT <: Real, uEltype <: Real} <: AbstractCo
296297
_node_coordinates::Vector{RealT}
297298
end
298299

299-
nvariables(boundaries::BoundaryContainer1D) = size(boundaries.u, 2)
300-
Base.eltype(boundaries::BoundaryContainer1D) = eltype(boundaries.u)
300+
# 1D: Only one boundary node
301+
nnodes(boundaries::TreeBoundaryContainer1D) = 1
301302

302303
# See explanation of Base.resize! for the element container
303-
function Base.resize!(boundaries::BoundaryContainer1D, capacity)
304+
function Base.resize!(boundaries::TreeBoundaryContainer1D, capacity)
304305
n_variables = nvariables(boundaries)
305306
@unpack _u, _node_coordinates,
306307
neighbor_ids, orientations, neighbor_sides = boundaries
@@ -322,9 +323,9 @@ function Base.resize!(boundaries::BoundaryContainer1D, capacity)
322323
return nothing
323324
end
324325

325-
function BoundaryContainer1D{RealT, uEltype}(capacity::Integer, n_variables,
326-
n_nodes) where {RealT <: Real,
327-
uEltype <: Real}
326+
function TreeBoundaryContainer1D{RealT, uEltype}(capacity::Integer,
327+
n_variables) where {RealT <: Real,
328+
uEltype <: Real}
328329
nan_RealT = convert(RealT, NaN)
329330
nan_uEltype = convert(uEltype, NaN)
330331

@@ -345,24 +346,20 @@ function BoundaryContainer1D{RealT, uEltype}(capacity::Integer, n_variables,
345346

346347
n_boundaries_per_direction = SVector(0, 0)
347348

348-
return BoundaryContainer1D{RealT, uEltype}(u, neighbor_ids, orientations,
349-
neighbor_sides,
350-
node_coordinates,
351-
n_boundaries_per_direction,
352-
_u, _node_coordinates)
349+
return TreeBoundaryContainer1D{RealT, uEltype}(u, neighbor_ids, orientations,
350+
neighbor_sides,
351+
node_coordinates,
352+
n_boundaries_per_direction,
353+
_u, _node_coordinates)
353354
end
354355

355-
# Return number of boundaries
356-
nboundaries(boundaries::BoundaryContainer1D) = length(boundaries.orientations)
357-
358356
# Create boundaries container and initialize boundary data in `elements`.
359357
function init_boundaries(cell_ids, mesh::TreeMesh1D,
360358
elements::ElementContainer1D)
361359
# Initialize container
362360
n_boundaries = count_required_boundaries(mesh, cell_ids)
363-
boundaries = BoundaryContainer1D{real(elements), eltype(elements)}(n_boundaries,
364-
nvariables(elements),
365-
nnodes(elements))
361+
boundaries = TreeBoundaryContainer1D{real(elements), eltype(elements)}(n_boundaries,
362+
nvariables(elements))
366363

367364
# Connect elements with boundaries
368365
init_boundaries!(boundaries, elements, mesh)

src/solvers/dgsem_tree/containers_2d.jl

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ function init_interfaces!(interfaces, elements, mesh::TreeMesh2D)
305305
end
306306

307307
# Container data structure (structure-of-arrays style) for DG boundaries
308-
mutable struct BoundaryContainer2D{RealT <: Real, uEltype <: Real} <: AbstractContainer
308+
mutable struct TreeBoundaryContainer2D{RealT <: Real, uEltype <: Real} <:
309+
AbstractTreeBoundaryContainer
309310
u::Array{uEltype, 4} # [leftright, variables, i, boundaries]
310311
neighbor_ids::Vector{Int} # [boundaries]
311312
orientations::Vector{Int} # [boundaries]
@@ -317,12 +318,8 @@ mutable struct BoundaryContainer2D{RealT <: Real, uEltype <: Real} <: AbstractCo
317318
_node_coordinates::Vector{RealT}
318319
end
319320

320-
nvariables(boundaries::BoundaryContainer2D) = size(boundaries.u, 2)
321-
nnodes(boundaries::BoundaryContainer2D) = size(boundaries.u, 3)
322-
Base.eltype(boundaries::BoundaryContainer2D) = eltype(boundaries.u)
323-
324321
# See explanation of Base.resize! for the element container
325-
function Base.resize!(boundaries::BoundaryContainer2D, capacity)
322+
function Base.resize!(boundaries::TreeBoundaryContainer2D, capacity)
326323
n_nodes = nnodes(boundaries)
327324
n_variables = nvariables(boundaries)
328325
@unpack _u, _node_coordinates,
@@ -345,9 +342,9 @@ function Base.resize!(boundaries::BoundaryContainer2D, capacity)
345342
return nothing
346343
end
347344

348-
function BoundaryContainer2D{RealT, uEltype}(capacity::Integer, n_variables,
349-
n_nodes) where {RealT <: Real,
350-
uEltype <: Real}
345+
function TreeBoundaryContainer2D{RealT, uEltype}(capacity::Integer, n_variables,
346+
n_nodes) where {RealT <: Real,
347+
uEltype <: Real}
351348
nan_RealT = convert(RealT, NaN)
352349
nan_uEltype = convert(uEltype, NaN)
353350

@@ -368,24 +365,21 @@ function BoundaryContainer2D{RealT, uEltype}(capacity::Integer, n_variables,
368365

369366
n_boundaries_per_direction = SVector(0, 0, 0, 0)
370367

371-
return BoundaryContainer2D{RealT, uEltype}(u, neighbor_ids, orientations,
372-
neighbor_sides,
373-
node_coordinates,
374-
n_boundaries_per_direction,
375-
_u, _node_coordinates)
368+
return TreeBoundaryContainer2D{RealT, uEltype}(u, neighbor_ids, orientations,
369+
neighbor_sides,
370+
node_coordinates,
371+
n_boundaries_per_direction,
372+
_u, _node_coordinates)
376373
end
377374

378-
# Return number of boundaries
379-
@inline nboundaries(boundaries::BoundaryContainer2D) = length(boundaries.orientations)
380-
381375
# Create boundaries container and initialize boundary data in `elements`.
382376
function init_boundaries(cell_ids, mesh::TreeMesh2D,
383377
elements::ElementContainer2D)
384378
# Initialize container
385379
n_boundaries = count_required_boundaries(mesh, cell_ids)
386-
boundaries = BoundaryContainer2D{real(elements), eltype(elements)}(n_boundaries,
387-
nvariables(elements),
388-
nnodes(elements))
380+
boundaries = TreeBoundaryContainer2D{real(elements), eltype(elements)}(n_boundaries,
381+
nvariables(elements),
382+
nnodes(elements))
389383

390384
# Connect elements with boundaries
391385
init_boundaries!(boundaries, elements, mesh)

src/solvers/dgsem_tree/containers_3d.jl

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ function init_interfaces!(interfaces, elements, mesh::TreeMesh3D)
302302
end
303303

304304
# Container data structure (structure-of-arrays style) for DG boundaries
305-
mutable struct BoundaryContainer3D{RealT <: Real, uEltype <: Real} <: AbstractContainer
305+
mutable struct TreeBoundaryContainer3D{RealT <: Real, uEltype <: Real} <:
306+
AbstractTreeBoundaryContainer
306307
u::Array{uEltype, 5} # [leftright, variables, i, j, boundaries]
307308
neighbor_ids::Vector{Int} # [boundaries]
308309
orientations::Vector{Int} # [boundaries]
@@ -314,12 +315,8 @@ mutable struct BoundaryContainer3D{RealT <: Real, uEltype <: Real} <: AbstractCo
314315
_node_coordinates::Vector{RealT}
315316
end
316317

317-
nvariables(boundaries::BoundaryContainer3D) = size(boundaries.u, 2)
318-
nnodes(boundaries::BoundaryContainer3D) = size(boundaries.u, 3)
319-
Base.eltype(boundaries::BoundaryContainer3D) = eltype(boundaries.u)
320-
321318
# See explanation of Base.resize! for the element container
322-
function Base.resize!(boundaries::BoundaryContainer3D, capacity)
319+
function Base.resize!(boundaries::TreeBoundaryContainer3D, capacity)
323320
n_nodes = nnodes(boundaries)
324321
n_variables = nvariables(boundaries)
325322
@unpack _u, _node_coordinates,
@@ -342,9 +339,9 @@ function Base.resize!(boundaries::BoundaryContainer3D, capacity)
342339
return nothing
343340
end
344341

345-
function BoundaryContainer3D{RealT, uEltype}(capacity::Integer, n_variables,
346-
n_nodes) where {RealT <: Real,
347-
uEltype <: Real}
342+
function TreeBoundaryContainer3D{RealT, uEltype}(capacity::Integer, n_variables,
343+
n_nodes) where {RealT <: Real,
344+
uEltype <: Real}
348345
nan_RealT = convert(RealT, NaN)
349346
nan_uEltype = convert(uEltype, NaN)
350347

@@ -365,24 +362,21 @@ function BoundaryContainer3D{RealT, uEltype}(capacity::Integer, n_variables,
365362

366363
n_boundaries_per_direction = SVector(0, 0, 0, 0, 0, 0)
367364

368-
return BoundaryContainer3D{RealT, uEltype}(u, neighbor_ids, orientations,
369-
neighbor_sides,
370-
node_coordinates,
371-
n_boundaries_per_direction,
372-
_u, _node_coordinates)
365+
return TreeBoundaryContainer3D{RealT, uEltype}(u, neighbor_ids, orientations,
366+
neighbor_sides,
367+
node_coordinates,
368+
n_boundaries_per_direction,
369+
_u, _node_coordinates)
373370
end
374371

375-
# Return number of boundaries
376-
nboundaries(boundaries::BoundaryContainer3D) = length(boundaries.orientations)
377-
378372
# Create boundaries container and initialize boundary data in `elements`.
379373
function init_boundaries(cell_ids, mesh::TreeMesh3D,
380374
elements::ElementContainer3D)
381375
# Initialize container
382376
n_boundaries = count_required_boundaries(mesh, cell_ids)
383-
boundaries = BoundaryContainer3D{real(elements), eltype(elements)}(n_boundaries,
384-
nvariables(elements),
385-
nnodes(elements))
377+
boundaries = TreeBoundaryContainer3D{real(elements), eltype(elements)}(n_boundaries,
378+
nvariables(elements),
379+
nnodes(elements))
386380

387381
# Connect elements with boundaries
388382
init_boundaries!(boundaries, elements, mesh)

test/test_unit.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,15 @@ end
452452
@test isnothing(display(c3d))
453453
end
454454

455+
@timed_testset "TreeBoundaryContainer1D nnodes" begin
456+
capacity = 42
457+
n_variables = 9
458+
boundary_container = Trixi.TreeBoundaryContainer1D{Float64, Float64}(capacity,
459+
n_variables)
460+
461+
@test nnodes(boundary_container) == 1
462+
end
463+
455464
@timed_testset "Printing indicators/controllers" begin
456465
# OBS! Constructing indicators/controllers using the parameters below doesn't make sense. It's
457466
# just useful to run basic tests of `show` methods.

0 commit comments

Comments
 (0)