chombo-discharge
Loading...
Searching...
No Matches
CD_ParticleGhostMask.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13#ifndef CD_PARTICLEGHOSTMASK_H
14#define CD_PARTICLEGHOSTMASK_H
15
16// Std includes
17#include <vector>
18
19// Chombo includes
20#include <CH_assert.H>
21#include <Box.H>
22#include <BaseFab.H>
23#include <BoxIterator.H>
24#include <LayoutData.H>
25#include <RefCountedPtr.H>
26#include <Vector.H>
27
28// Our includes
29#include <CD_LevelTiles.H>
30#include <CD_NamespaceHeader.H>
31
53{
54public:
58 ParticleGhostMask() = default;
59
63 ~ParticleGhostMask() = default;
64
69 inline void
70 define(const Box& a_box) noexcept;
71
76 inline void
77 incrementCount(const IntVect& a_iv) noexcept;
78
83 inline void
84 allocate() noexcept;
85
91 inline void
92 allocateTargetBoxes() noexcept;
93
101 inline void
102 addTarget(const IntVect& a_iv, const LevelTiles::BoxIDs& a_target) noexcept;
103
112 inline void
113 addTarget(const IntVect& a_iv, const LevelTiles::BoxIDs& a_target, const Box& a_targetBox) noexcept;
114
118 inline void
119 finalize() noexcept;
120
125 inline const Box&
126 box() const noexcept;
127
133 inline int
134 numTargets(const IntVect& a_iv) const noexcept;
135
142 inline const LevelTiles::BoxIDs&
143 target(const IntVect& a_iv, const int a_i) const noexcept;
144
151 inline unsigned int
152 targetGridIndex(const IntVect& a_iv, const int a_i) const noexcept;
153
160 inline unsigned int
161 targetRank(const IntVect& a_iv, const int a_i) const noexcept;
162
170 inline const Box&
171 targetBox(const IntVect& a_iv, const int a_i) const noexcept;
172
177 inline bool
178 hasTargetBoxes() const noexcept;
179
180protected:
184 Box m_box;
185
189 BaseFab<int> m_start;
190
194 BaseFab<int> m_count;
195
199 std::vector<LevelTiles::BoxIDs> m_flat;
200
204 std::vector<Box> m_flatBox;
205};
206
210using AMRParticleGhostMask = Vector<RefCountedPtr<LayoutData<ParticleGhostMask>>>;
211
212#include <CD_NamespaceFooter.H>
213
215
216#endif
Declaration of LevelTiles.
Implementation of CD_ParticleGhostMask.H.
Vector< RefCountedPtr< LayoutData< ParticleGhostMask > > > AMRParticleGhostMask
AMR-wide particle ghost-target lookup: one per-box CSR table per level, indexed by SOURCE level.
Definition CD_ParticleGhostMask.H:210
Class for storing the AMR hierarchy as a collection of tiles.
Definition CD_LevelTiles.H:43
Per-box CSR lookup from a source cell to the destination boxes whose ghosted region covers it.
Definition CD_ParticleGhostMask.H:53
void define(const Box &a_box) noexcept
Reset to an empty table over a box (every cell has zero targets).
Definition CD_ParticleGhostMaskImplem.H:21
const Box & box() const noexcept
Get the box that the source cells live on.
Definition CD_ParticleGhostMaskImplem.H:90
unsigned int targetGridIndex(const IntVect &a_iv, const int a_i) const noexcept
Get the destination grid index of the i-th target for a cell.
Definition CD_ParticleGhostMaskImplem.H:116
const Box & targetBox(const IntVect &a_iv, const int a_i) const noexcept
Get the acceptance box of the i-th target for a cell.
Definition CD_ParticleGhostMaskImplem.H:128
ParticleGhostMask()=default
Default constructor. Leaves the table undefined; call define() before use.
int numTargets(const IntVect &a_iv) const noexcept
Get the number of scatter targets for a cell.
Definition CD_ParticleGhostMaskImplem.H:100
void allocate() noexcept
Build step between the passes: turn the per-cell counts into CSR offsets and size the packed target a...
Definition CD_ParticleGhostMaskImplem.H:39
const LevelTiles::BoxIDs & target(const IntVect &a_iv, const int a_i) const noexcept
Get the i-th scatter target for a cell.
Definition CD_ParticleGhostMaskImplem.H:108
unsigned int targetRank(const IntVect &a_iv, const int a_i) const noexcept
Get the receiving rank of the i-th target for a cell.
Definition CD_ParticleGhostMaskImplem.H:122
void allocateTargetBoxes() noexcept
Optional build step: size the per-target acceptance-box array to match the packed target array.
Definition CD_ParticleGhostMaskImplem.H:53
std::vector< LevelTiles::BoxIDs > m_flat
Packed targets, size == sum(m_count).
Definition CD_ParticleGhostMask.H:199
bool hasTargetBoxes() const noexcept
Whether this mask carries per-target acceptance boxes.
Definition CD_ParticleGhostMaskImplem.H:137
~ParticleGhostMask()=default
Destructor.
void addTarget(const IntVect &a_iv, const LevelTiles::BoxIDs &a_target) noexcept
Build pass 2: append one target for cell a_iv.
Definition CD_ParticleGhostMaskImplem.H:59
BaseFab< int > m_start
Per cell: first index into m_flat, or -1 if the cell has no targets.
Definition CD_ParticleGhostMask.H:189
BaseFab< int > m_count
Per cell: number of targets.
Definition CD_ParticleGhostMask.H:194
void finalize() noexcept
Finish the build: rewind m_start (advanced by addTarget) back to the CSR start offsets.
Definition CD_ParticleGhostMaskImplem.H:82
Box m_box
Box that the source cells (and m_start/m_count) live on.
Definition CD_ParticleGhostMask.H:184
void incrementCount(const IntVect &a_iv) noexcept
Build pass 1: register that cell a_iv gains one more target.
Definition CD_ParticleGhostMaskImplem.H:33
std::vector< Box > m_flatBox
Packed per-target acceptance boxes, parallel to m_flat. Empty unless the mask carries them.
Definition CD_ParticleGhostMask.H:204