Block-Structured AMR Software Framework
AMReX_ParticleBufferMap.H
Go to the documentation of this file.
1 #ifndef AMREX_PARTICLEBUFFERMAP_H_
2 #define AMREX_PARTICLEBUFFERMAP_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_BoxArray.H>
7 #include <AMReX_Gpu.H>
8 #include <AMReX_GpuContainers.H>
9 #include <AMReX_ParGDB.H>
10 
11 namespace amrex {
12 
13 struct GetPID
14 {
15  const int* m_bucket_to_pid;
16  const int* m_lev_gid_to_bucket;
17  const int* m_lev_offsets;
18 
19  GetPID (const Gpu::DeviceVector<int>& bucket_to_pid,
20  const Gpu::DeviceVector<int>& lev_gid_to_bucket,
21  const Gpu::DeviceVector<int>& lev_offsets)
22  : m_bucket_to_pid(bucket_to_pid.dataPtr()),
23  m_lev_gid_to_bucket(lev_gid_to_bucket.dataPtr()),
24  m_lev_offsets(lev_offsets.dataPtr())
25  {}
26 
28  int operator() (const int lev, const int gid) const noexcept
29  {
31  }
32 };
33 
34 struct GetBucket
35 {
36  const int* m_lev_gid_to_bucket;
37  const int* m_lev_offsets;
38 
39  GetBucket (const int* lev_gid_to_bucket_ptr,
40  const int* lev_offsets_ptr)
41  : m_lev_gid_to_bucket(lev_gid_to_bucket_ptr),
42  m_lev_offsets(lev_offsets_ptr)
43  {}
44 
46  int operator() (const int lev, const int gid) const noexcept
47  {
48  return m_lev_gid_to_bucket[m_lev_offsets[lev]+gid];
49  }
50 };
51 
53 {
54  bool m_defined{false};
57 
61 
64 
67 
71 
72 public:
73  ParticleBufferMap () = default;
74 
75  ParticleBufferMap (const ParGDBBase* a_gdb);
76 
77  void define (const ParGDBBase* a_gdb);
78 
79  bool isValid (const ParGDBBase* a_gdb) const;
80 
81  [[nodiscard]] AMREX_FORCE_INLINE
82  int numLevels () const
83  {
85  return static_cast<int>(m_lev_offsets.size()-1);
86  }
87 
88  [[nodiscard]] AMREX_FORCE_INLINE
89  int numBuckets () const
90  {
92  return static_cast<int>(m_bucket_to_gid.size());
93  }
94 
95  [[nodiscard]] AMREX_FORCE_INLINE
96  int bucketToGrid (int bid) const
97  {
99  return m_bucket_to_gid[bid];
100  }
101 
102  [[nodiscard]] AMREX_FORCE_INLINE
103  int bucketToLevel (int bid) const
104  {
106  return m_bucket_to_lev[bid];
107  }
108 
109  [[nodiscard]] AMREX_FORCE_INLINE
110  int bucketToProc (int bid) const
111  {
113  return m_bucket_to_pid[bid];
114  }
115 
116  [[nodiscard]] AMREX_FORCE_INLINE
117  int gridAndLevToBucket (int gid, int lev) const
118  {
120  return m_lev_gid_to_bucket[m_lev_offsets[lev] + gid];
121  }
122 
123  [[nodiscard]] AMREX_FORCE_INLINE
124  int firstBucketOnProc (int pid) const
125  {
127  return m_proc_box_offsets[pid];
128  }
129 
130  [[nodiscard]] AMREX_FORCE_INLINE
131  int numBoxesOnProc (int pid) const
132  {
134  return m_proc_box_counts[pid];
135  }
136 
137  [[nodiscard]] AMREX_FORCE_INLINE
139  {
141  Vector<int> buckets;
142  for (int i = 0; i < numBoxesOnProc(pid); ++i)
143  {
144  buckets.push_back(i+firstBucketOnProc(pid));
145  }
146  return buckets;
147  }
148 
149  [[nodiscard]] AMREX_FORCE_INLINE
150  int procID (int gid, int lev) const
151  {
153  return m_dm[lev][gid];
154  }
155 
156  [[nodiscard]] GetPID getPIDFunctor () const noexcept { return GetPID(d_bucket_to_pid, d_lev_gid_to_bucket, d_lev_offsets);}
157  [[nodiscard]] GetBucket getBucketFunctor () const noexcept { return GetBucket(d_lev_gid_to_bucket.data(), d_lev_offsets.data());}
158  [[nodiscard]] GetBucket getHostBucketFunctor () const noexcept { return GetBucket(m_lev_gid_to_bucket.data(), m_lev_offsets.data());}
159 
160 };
161 
162 } // namespace amrex
163 
164 #endif // AMREX_PARTICLEBUFFERMAP_H_
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Definition: AMReX_PODVector.H:246
Definition: AMReX_ParGDB.H:13
Definition: AMReX_ParticleBufferMap.H:53
Gpu::DeviceVector< int > d_lev_gid_to_bucket
Definition: AMReX_ParticleBufferMap.H:69
GetPID getPIDFunctor() const noexcept
Definition: AMReX_ParticleBufferMap.H:156
Vector< int > m_bucket_to_pid
Definition: AMReX_ParticleBufferMap.H:60
AMREX_FORCE_INLINE int numLevels() const
Definition: AMReX_ParticleBufferMap.H:82
Gpu::DeviceVector< int > d_lev_offsets
Definition: AMReX_ParticleBufferMap.H:70
bool isValid(const ParGDBBase *a_gdb) const
Definition: AMReX_ParticleBufferMap.cpp:115
AMREX_FORCE_INLINE int numBuckets() const
Definition: AMReX_ParticleBufferMap.H:89
Vector< int > m_proc_box_offsets
Definition: AMReX_ParticleBufferMap.H:66
Vector< int > m_lev_gid_to_bucket
Definition: AMReX_ParticleBufferMap.H:62
AMREX_FORCE_INLINE int bucketToProc(int bid) const
Definition: AMReX_ParticleBufferMap.H:110
AMREX_FORCE_INLINE Vector< int > allBucketsOnProc(int pid) const
Definition: AMReX_ParticleBufferMap.H:138
Vector< BoxArray > m_ba
Definition: AMReX_ParticleBufferMap.H:55
Vector< DistributionMapping > m_dm
Definition: AMReX_ParticleBufferMap.H:56
Gpu::DeviceVector< int > d_bucket_to_pid
Definition: AMReX_ParticleBufferMap.H:68
AMREX_FORCE_INLINE int firstBucketOnProc(int pid) const
Definition: AMReX_ParticleBufferMap.H:124
Vector< int > m_lev_offsets
Definition: AMReX_ParticleBufferMap.H:63
Vector< int > m_proc_box_counts
Definition: AMReX_ParticleBufferMap.H:65
AMREX_FORCE_INLINE int bucketToGrid(int bid) const
Definition: AMReX_ParticleBufferMap.H:96
AMREX_FORCE_INLINE int procID(int gid, int lev) const
Definition: AMReX_ParticleBufferMap.H:150
GetBucket getBucketFunctor() const noexcept
Definition: AMReX_ParticleBufferMap.H:157
bool m_defined
Definition: AMReX_ParticleBufferMap.H:54
AMREX_FORCE_INLINE int numBoxesOnProc(int pid) const
Definition: AMReX_ParticleBufferMap.H:131
GetBucket getHostBucketFunctor() const noexcept
Definition: AMReX_ParticleBufferMap.H:158
Vector< int > m_bucket_to_gid
Definition: AMReX_ParticleBufferMap.H:58
AMREX_FORCE_INLINE int gridAndLevToBucket(int gid, int lev) const
Definition: AMReX_ParticleBufferMap.H:117
Vector< int > m_bucket_to_lev
Definition: AMReX_ParticleBufferMap.H:59
AMREX_FORCE_INLINE int bucketToLevel(int bid) const
Definition: AMReX_ParticleBufferMap.H:103
void define(const ParGDBBase *a_gdb)
Definition: AMReX_ParticleBufferMap.cpp:10
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
Definition: AMReX_Amr.cpp:49
Definition: AMReX_ParticleBufferMap.H:35
GetBucket(const int *lev_gid_to_bucket_ptr, const int *lev_offsets_ptr)
Definition: AMReX_ParticleBufferMap.H:39
const int * m_lev_offsets
Definition: AMReX_ParticleBufferMap.H:37
const int * m_lev_gid_to_bucket
Definition: AMReX_ParticleBufferMap.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(const int lev, const int gid) const noexcept
Definition: AMReX_ParticleBufferMap.H:46
Definition: AMReX_ParticleBufferMap.H:14
const int * m_bucket_to_pid
Definition: AMReX_ParticleBufferMap.H:15
const int * m_lev_offsets
Definition: AMReX_ParticleBufferMap.H:17
GetPID(const Gpu::DeviceVector< int > &bucket_to_pid, const Gpu::DeviceVector< int > &lev_gid_to_bucket, const Gpu::DeviceVector< int > &lev_offsets)
Definition: AMReX_ParticleBufferMap.H:19
const int * m_lev_gid_to_bucket
Definition: AMReX_ParticleBufferMap.H:16
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(const int lev, const int gid) const noexcept
Definition: AMReX_ParticleBufferMap.H:28