1 #ifndef AMREX_PARTICLE_H_
2 #define AMREX_PARTICLE_H_
3 #include <AMReX_Config.H>
17 namespace LongParticleIds {
25 using namespace LongParticleIds;
30 namespace ParticleIdCpus {
31 constexpr std::uint64_t
Invalid = 16777216;
34 using namespace ParticleIdCpus;
55 return this->operator=(Long(pidw));
61 return this->operator=(Long(pidw));
68 (*m_idata) &= 0x00FFFFFF;
71 uint64_t sign =
id >= 0;
85 (*m_idata) |= (sign << 63);
86 (*m_idata) |= (val << 24);
91 operator Long () const noexcept
95 uint64_t sign = (*m_idata) >> 63;
96 uint64_t val = (((*m_idata) >> 24) & 0x7FFFFFFFFF);
98 Long lval =
static_cast<Long
>(val);
99 r = (sign) ? lval : -lval;
112 (*m_idata) &= ~(uint64_t(1) << 63);
124 (*m_idata) |= uint64_t(1) << 63;
135 return (*m_idata) >> 63;
158 return this->operator=(
int(pcpuw));
164 return this->operator=(
int(pcpuw));
171 (*m_idata) &= (~ 0x00FFFFFF);
181 operator int () const noexcept
183 return static_cast<int>((*m_idata) & 0x00FFFFFF);
197 operator Long () const noexcept
201 uint64_t sign = (*m_idata) >> 63;
202 uint64_t val = (((*m_idata) >> 24) & 0x7FFFFFFFFF);
204 Long lval =
static_cast<Long
>(val);
205 r = (sign) ? lval : -lval;
217 return (*m_idata) >> 63;
231 operator int () const noexcept {
return static_cast<int>((*m_idata) & 0x00FFFFFF); }
241 std::uint64_t idcpu = 0;
247 template <
typename T,
int NReal,
int NInt>
250 T m_pos[AMREX_SPACEDIM];
252 uint64_t m_idcpu = 0;
256 template <
typename T,
int NInt>
259 T m_pos[AMREX_SPACEDIM];
260 uint64_t m_idcpu = 0;
264 template <
typename T,
int NReal>
267 T m_pos[AMREX_SPACEDIM];
269 uint64_t m_idcpu = 0;
272 template <
typename T>
275 T m_pos[AMREX_SPACEDIM];
276 uint64_t m_idcpu = 0;
282 static constexpr
int NReal=0;
283 static constexpr
int NInt=0;
292 template <
int T_NReal,
int T_NInt=0>
301 static constexpr
int NReal = T_NReal;
304 static constexpr
int NInt = T_NInt;
328 #if defined(AMREX_USE_OMP)
329 #pragma omp atomic write
330 this->m_idcpu = wrapper.
m_idata;
332 auto *old_ptr =
reinterpret_cast<unsigned long long*
>(&(this->m_idcpu));
344 return this->m_pos[index];
351 return this->m_pos[index];
354 template <
int U = T_NReal, std::enable_if_t<U != 0,
int> = 0>
359 return this->m_rdata[index];
362 template <
int U = T_NReal, std::enable_if_t<U == 0,
int> = 0>
370 template <
int U = T_NReal, std::enable_if_t<U != 0,
int> = 0>
375 return this->m_rdata[index];
378 template <
int U = T_NReal, std::enable_if_t<U == 0,
int> = 0>
389 template <
int U = T_NReal, std::enable_if_t<U != 0,
int> = 0>
396 this->m_rdata[indz]));
399 template <
int U = T_NReal, std::enable_if_t<U == 0,
int> = 0>
407 template <
int U = T_NReal, std::enable_if_t<U != 0,
int> = 0>
413 this->m_rdata[indices[1]],
414 this->m_rdata[indices[2]]));
417 template <
int U = T_NReal, std::enable_if_t<U == 0,
int> = 0>
425 template <
int U = T_NInt, std::enable_if_t<U != 0,
int> = 0>
430 return this->m_idata[index];
433 template <
int U = T_NInt, std::enable_if_t<U == 0,
int> = 0>
438 return this->m_idcpu;
441 template <
int U = T_NInt, std::enable_if_t<U != 0,
int> = 0>
443 const int&
idata (
int index)
const &
446 return this->m_idata[index];
449 template <
int U = T_NInt, std::enable_if_t<U == 0,
int> = 0>
454 return this->m_idcpu;
468 [[nodiscard]]
static Long NextID ();
473 [[nodiscard]]
static Long UnprotectedNextID ();
480 static void NextID (Long nextid);
485 template <
int NReal,
int NInt>
492 #if defined(AMREX_USE_OMP) && defined(_OPENMP) && _OPENMP < 201307
493 #pragma omp critical (amrex_particle_nextid)
494 #elif defined(AMREX_USE_OMP)
495 #pragma omp atomic capture
497 next = the_next_id++;
500 amrex::Abort(
"Particle<NReal, NInt>::NextID() -- too many particles");
506 template <
int NReal,
int NInt>
510 Long next = the_next_id++;
512 amrex::Abort(
"Particle<NReal, NInt>::NextID() -- too many particles");
517 template <
int NReal,
int NInt>
521 the_next_id = nextid;
524 template <
int NReal,
int NInt>
531 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
532 os << p.
pos(i) <<
' ';
535 for (
int i = 0; i < NReal; i++) {
536 os << p.
rdata(i) <<
' ';
539 for (
int i = 0; i < NInt; i++) {
540 os << p.
idata(i) <<
' ';
544 amrex::Error(
"operator<<(ostream&,Particle<NReal, NInt>&) failed");
557 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
558 os << p.
pos(i) <<
' ';
561 for (
int i = 0; i < NReal; i++) {
562 os << p.
rdata(i) <<
' ';
566 amrex::Error(
"operator<<(ostream&,Particle<NReal, NInt>&) failed");
579 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
580 os << p.
pos(i) <<
' ';
583 for (
int i = 0; i < NInt; i++) {
584 os << p.
idata(i) <<
' ';
588 amrex::Error(
"operator<<(ostream&,Particle<NReal, NInt>&) failed");
594 template <
int NReal=0,
int NInt=0>
601 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
602 os << p.
pos(i) <<
' ';
606 amrex::Error(
"operator<<(ostream&,Particle<NReal, NInt>&) failed");
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_ALWAYS_ASSERT(EX)
Definition: AMReX_BLassert.H:50
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#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
A Real vector in SpaceDim-dimensional space.
Definition: AMReX_RealVect.H:32
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T Exch(T *address, T val) noexcept
Definition: AMReX_GpuAtomic.H:485
constexpr Long GhostParticleID
Definition: AMReX_Particle.H:18
constexpr Long NoSplitParticleID
Definition: AMReX_Particle.H:22
constexpr Long VirtualParticleID
Definition: AMReX_Particle.H:19
constexpr Long DoSplitParticleID
Definition: AMReX_Particle.H:21
constexpr Long LastParticleID
Definition: AMReX_Particle.H:20
constexpr std::uint64_t Invalid
Definition: AMReX_Particle.H:31
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint64_t SetParticleIDandCPU(Long id, int cpu) noexcept
Definition: AMReX_Particle.H:240
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition: AMReX.cpp:219
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
const int[]
Definition: AMReX_BLProfiler.cpp:1664
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition: AMReX_AmrMesh.cpp:1236
Definition: AMReX_Particle.H:222
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ConstParticleCPUWrapper(const uint64_t &idata) noexcept
Definition: AMReX_Particle.H:226
const uint64_t * m_idata
Definition: AMReX_Particle.H:223
Definition: AMReX_Particle.H:188
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ConstParticleIDWrapper(const uint64_t &idata) noexcept
Definition: AMReX_Particle.H:192
const uint64_t * m_idata
Definition: AMReX_Particle.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool is_valid() const noexcept
Definition: AMReX_Particle.H:214
Definition: AMReX_Particle.H:249
Definition: AMReX_Particle.H:140
ParticleCPUWrapper(ParticleCPUWrapper &&)=delete
~ParticleCPUWrapper() noexcept=default
uint64_t * m_idata
Definition: AMReX_Particle.H:141
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleCPUWrapper(const ParticleCPUWrapper &rhs)=default
Definition: AMReX_Particle.H:37
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleIDWrapper(const ParticleIDWrapper &rhs)=default
uint64_t * m_idata
Definition: AMReX_Particle.H:38
~ParticleIDWrapper() noexcept=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool is_valid() const noexcept
Definition: AMReX_Particle.H:132
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void make_valid() const noexcept
Definition: AMReX_Particle.H:121
ParticleIDWrapper(ParticleIDWrapper &&)=delete
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void make_invalid() const noexcept
Definition: AMReX_Particle.H:109
The struct used to store particles.
Definition: AMReX_Particle.H:295
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealType pos(int index) const &
Definition: AMReX_Particle.H:348
ParticleReal RealType
The floating point type used for the particles.
Definition: AMReX_Particle.H:307
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleIDWrapper id() &
Definition: AMReX_Particle.H:315
static Long NextID()
Returns the next particle ID for this processor. Particle IDs start at 1 and are never reused....
Definition: AMReX_Particle.H:487
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealVect rvec(AMREX_D_DECL(int, int, int)) const &
Definition: AMReX_Particle.H:401
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealType rdata(int) const &
Definition: AMReX_Particle.H:380
static Long the_next_id
Definition: AMReX_Particle.H:309
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealType & rdata(int) &
Definition: AMReX_Particle.H:364
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealVect pos() const &
Definition: AMReX_Particle.H:338
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ConstParticleIDWrapper id() const &
Definition: AMReX_Particle.H:321
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealType & rdata(int index) &
Definition: AMReX_Particle.H:356
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealVect rvec(const IntVect &indices) const &
Definition: AMReX_Particle.H:409
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealVect rvec(AMREX_D_DECL(int indx, int indy, int indz)) const &
Definition: AMReX_Particle.H:391
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealType rdata(int) &&=delete
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const RealType & rdata(int index) const &
Definition: AMReX_Particle.H:372
static Long UnprotectedNextID()
This version can only be used inside omp critical.
Definition: AMReX_Particle.H:508
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealVect rvec(const IntVect &) const &
Definition: AMReX_Particle.H:419
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idata(int) const &
Definition: AMReX_Particle.H:451
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ConstParticleCPUWrapper cpu() const &
Definition: AMReX_Particle.H:318
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealType & pos(int index) &
Definition: AMReX_Particle.H:341
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealType idata(int) &&=delete
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int & idata(int index) &
Definition: AMReX_Particle.H:427
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleCPUWrapper cpu() &
Definition: AMReX_Particle.H:312
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void atomicSetID(const Long id)
Definition: AMReX_Particle.H:324
Particle const ConstType
Definition: AMReX_Particle.H:298
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE uint64_t & idata(int) &
Definition: AMReX_Particle.H:435
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const int & idata(int index) const &
Definition: AMReX_Particle.H:443
Definition: AMReX_Particle.H:281
Definition: AMReX_MakeParticle.H:11