1 #ifndef AMREX_PARTICLE_LOCATOR_H_
2 #define AMREX_PARTICLE_LOCATOR_H_
3 #include <AMReX_Config.H>
12 template <
class BinIteratorFactory>
35 m_plo(a_geom.ProbLoArray()),
m_dxi(a_geom.InvCellSizeArray())
47 template <
typename P,
typename Assignor = DefaultAssignor>
49 int operator() (
const P& p,
int nGrow=0, Assignor
const& assignor = Assignor{})
const noexcept
61 const auto lo = iv.
dim3();
70 for (
int ii = ix_lo; ii <= ix_hi; ++ii) {
71 for (
int jj = iy_lo; jj <= iy_hi; ++jj) {
72 for (
int kk = iz_lo; kk <= iz_hi; ++kk) {
74 for (
const auto& nbor :
m_bif.getBinIterator(index)) {
86 for (
int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
88 gdbx.
grow(dir, nGrow);
102 template <
class Bins>
116 int num_boxes =
static_cast<int>(ba.
size());
118 for (
int i = 0; i < num_boxes; ++i) {
m_host_boxes.push_back(ba[i]); }
123 if (num_boxes == 0) {
138 using ReduceTuple =
typename decltype(reduce_data)::Type;
141 reduce_op.
eval(num_boxes, reduce_data,
144 const Box& box = boxes_ptr[i];
153 ReduceTuple hv = reduce_data.
value(reduce_op);
159 amrex::get< AMREX_SPACEDIM+1>(hv),
160 amrex::get< AMREX_SPACEDIM+2>(hv)));
162 amrex::get<2*AMREX_SPACEDIM+1>(hv),
163 amrex::get<2*AMREX_SPACEDIM+2>(hv)));
170 m_bins.build(num_boxes, boxes_ptr, bins_box,
173 return (box.
smallEnd() - bins_lo) / bin_size;
214 template <
class BinIteratorFactory>
224 template <
typename P,
typename Assignor = DefaultAssignor>
227 Assignor
const& assignor = {})
const noexcept
229 lev_min = (lev_min == -1) ? 0 : lev_min;
230 lev_max = (lev_max == -1) ?
m_size - 1 : lev_max;
232 for (
int lev = lev_max; lev >= lev_min; --lev)
234 int grid =
m_funcs[lev](p, 0, assignor);
235 if (grid >= 0) {
return makeTuple(grid, lev); }
238 for (
int lev = lev_min; lev >= lev_min; --lev)
240 int grid =
m_funcs[lev](p, nGrow, assignor);
241 if (grid >= 0) {
return makeTuple(grid, lev); }
248 template <
class Bins>
278 int num_levels =
static_cast<int>(a_ba.
size());
283 for (
int lev = 0; lev < num_levels; ++lev)
285 m_locators[lev].build(a_ba[lev], a_geom[lev]);
286 h_grid_assignors[lev] =
m_locators[lev].getGridAssignor();
292 for (
int lev = 0; lev < num_levels; ++lev)
294 m_locators[lev].build(a_ba[lev], a_geom[lev]);
305 for (
int lev = 0; lev < num_levels; ++lev)
308 geom.push_back(a_gdb->
Geom(lev));
317 bool all_valid =
true;
319 for (
int lev = 0; lev < num_levels; ++lev) {
320 all_valid = all_valid &&
m_locators[lev].isValid(a_ba[lev]);
329 for (
int lev = 0; lev < num_levels; ++lev) {
340 for (
int lev = 0; lev < num_levels; ++lev)
343 h_grid_assignors[lev] =
m_locators[lev].getGridAssignor();
349 for (
int lev = 0; lev < num_levels; ++lev)
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_DEVICE
Definition: AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_D_TERM(a, b, c)
Definition: AMReX_SPACE.H:129
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
Definition: AMReX_ParticleLocator.H:250
void build(const ParGDBBase *a_gdb)
Definition: AMReX_ParticleLocator.H:300
AmrParticleLocator(const ParGDBBase *a_gdb)
Definition: AMReX_ParticleLocator.H:269
Gpu::DeviceVector< AssignGrid< BinIteratorFactory > > m_grid_assignors
Definition: AMReX_ParticleLocator.H:256
bool m_defined
Definition: AMReX_ParticleLocator.H:257
typename Bins::BinIteratorFactory BinIteratorFactory
Definition: AMReX_ParticleLocator.H:252
AmrAssignGrid< BinIteratorFactory > getGridAssignor() const noexcept
Definition: AMReX_ParticleLocator.H:357
bool isValid(const Vector< BoxArray > &a_ba) const
Definition: AMReX_ParticleLocator.H:313
void setGeometry(const ParGDBBase *a_gdb)
Definition: AMReX_ParticleLocator.H:335
AmrParticleLocator(const Vector< BoxArray > &a_ba, const Vector< Geometry > &a_geom)
Definition: AMReX_ParticleLocator.H:263
bool isValid(const ParGDBBase *a_gdb) const
Definition: AMReX_ParticleLocator.H:325
void build(const Vector< BoxArray > &a_ba, const Vector< Geometry > &a_geom)
Definition: AMReX_ParticleLocator.H:274
AmrParticleLocator()=default
Vector< ParticleLocator< Bins > > m_locators
Definition: AMReX_ParticleLocator.H:255
A collection of Boxes stored in an Array.
Definition: AMReX_BoxArray.H:550
static bool SameRefs(const BoxArray &lhs, const BoxArray &rhs)
whether two BoxArrays share the same data
Definition: AMReX_BoxArray.H:820
Long size() const noexcept
Return the number of boxes in the BoxArray.
Definition: AMReX_BoxArray.H:597
AMREX_GPU_HOST_DEVICE const IntVectND< dim > & smallEnd() const &noexcept
Get the smallend of the BoxND.
Definition: AMReX_Box.H:105
AMREX_GPU_HOST_DEVICE BoxND & grow(int i) noexcept
Definition: AMReX_Box.H:627
AMREX_GPU_HOST_DEVICE const IntVectND< dim > & bigEnd() const &noexcept
Get the bigend.
Definition: AMReX_Box.H:116
AMREX_GPU_HOST_DEVICE IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition: AMReX_Box.H:146
AMREX_GPU_HOST_DEVICE bool contains(const IntVectND< dim > &p) const noexcept
Returns true if argument is contained within BoxND.
Definition: AMReX_Box.H:204
Rectangular problem domain geometry.
Definition: AMReX_Geometry.H:73
Definition: AMReX_Tuple.H:93
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 dim3() const noexcept
Definition: AMReX_IntVect.H:163
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE IntVectND< dim > TheUnitVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition: AMReX_IntVect.H:682
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE IntVectND< dim > TheZeroVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition: AMReX_IntVect.H:672
Definition: AMReX_PODVector.H:246
T * data() noexcept
Definition: AMReX_PODVector.H:593
Definition: AMReX_ParGDB.H:13
virtual const Geometry & Geom(int level) const =0
virtual int finestLevel() const =0
virtual const BoxArray & ParticleBoxArray(int level) const =0
Definition: AMReX_ParticleLocator.H:104
ParticleLocator()=default
IntVect m_bin_size
Definition: AMReX_ParticleLocator.H:205
IntVect m_bins_hi
Definition: AMReX_ParticleLocator.H:204
BoxArray m_ba
Definition: AMReX_ParticleLocator.H:200
Geometry m_geom
Definition: AMReX_ParticleLocator.H:201
Gpu::HostVector< Box > m_host_boxes
Definition: AMReX_ParticleLocator.H:210
IntVect m_bins_lo
Definition: AMReX_ParticleLocator.H:203
Bins m_bins
Definition: AMReX_ParticleLocator.H:208
IntVect m_num_bins
Definition: AMReX_ParticleLocator.H:206
typename Bins::BinIteratorFactory BinIteratorFactory
Definition: AMReX_ParticleLocator.H:107
Gpu::DeviceVector< Box > m_device_boxes
Definition: AMReX_ParticleLocator.H:211
AssignGrid< BinIteratorFactory > getGridAssignor() const noexcept
Definition: AMReX_ParticleLocator.H:183
bool isValid(const BoxArray &ba) const noexcept
Definition: AMReX_ParticleLocator.H:190
void setGeometry(const Geometry &a_geom) noexcept
Definition: AMReX_ParticleLocator.H:177
bool m_defined
Definition: AMReX_ParticleLocator.H:198
void build(const BoxArray &ba, const Geometry &geom)
Definition: AMReX_ParticleLocator.H:111
Definition: AMReX_Reduce.H:249
Type value()
Definition: AMReX_Reduce.H:281
Definition: AMReX_Reduce.H:364
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition: AMReX_Reduce.H:441
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition: AMReX_Vector.H:27
Long size() const noexcept
Definition: AMReX_Vector.H:50
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition: AMReX_GpuContainers.H:233
static constexpr HostToDevice hostToDevice
Definition: AMReX_GpuContainers.H:98
void streamSynchronize() noexcept
Definition: AMReX_GpuDevice.H:237
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition: AMReX_GpuDevice.H:251
static constexpr int P
Definition: AMReX_OpenBC.H:14
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:35
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & min(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:21
constexpr AMREX_GPU_HOST_DEVICE GpuTuple< detail::tuple_decay_t< Ts >... > makeTuple(Ts &&... args)
Definition: AMReX_Tuple.H:252
IntVectND< AMREX_SPACEDIM > IntVect
Definition: AMReX_BaseFwd.H:30
Definition: AMReX_ParticleLocator.H:216
std::size_t m_size
Definition: AMReX_ParticleLocator.H:218
AmrAssignGrid(const AssignGrid< BinIteratorFactory > *a_funcs, std::size_t a_size)
Definition: AMReX_ParticleLocator.H:220
const AssignGrid< BinIteratorFactory > * m_funcs
Definition: AMReX_ParticleLocator.H:217
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuTuple< int, int > operator()(const P &p, int lev_min=-1, int lev_max=-1, int nGrow=0, Assignor const &assignor={}) const noexcept
Definition: AMReX_ParticleLocator.H:226
Definition: AMReX_ParticleLocator.H:14
Dim3 m_hi
Definition: AMReX_ParticleLocator.H:18
AMREX_GPU_HOST_DEVICE AssignGrid()=default
AssignGrid(BinIteratorFactory a_bif, const IntVect &a_bins_lo, const IntVect &a_bins_hi, const IntVect &a_bin_size, const IntVect &a_num_bins, const Geometry &a_geom)
Definition: AMReX_ParticleLocator.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(const P &p, int nGrow=0, Assignor const &assignor=Assignor{}) const noexcept
Definition: AMReX_ParticleLocator.H:49
Dim3 m_bin_size
Definition: AMReX_ParticleLocator.H:19
Box m_domain
Definition: AMReX_ParticleLocator.H:22
Dim3 m_num_bins
Definition: AMReX_ParticleLocator.H:20
BinIteratorFactory m_bif
Definition: AMReX_ParticleLocator.H:15
GpuArray< Real, AMREX_SPACEDIM > m_dxi
Definition: AMReX_ParticleLocator.H:24
Dim3 m_lo
Definition: AMReX_ParticleLocator.H:17
GpuArray< Real, AMREX_SPACEDIM > m_plo
Definition: AMReX_ParticleLocator.H:23
Definition: AMReX_Dim3.H:12
int x
Definition: AMReX_Dim3.H:12
int z
Definition: AMReX_Dim3.H:12
int y
Definition: AMReX_Dim3.H:12
Definition: AMReX_Reduce.H:147
Definition: AMReX_Reduce.H:114