Block-Structured AMR Software Framework
AMReX_ArrayOfStructs.H
Go to the documentation of this file.
1 #ifndef AMREX_ARRAYOFSTRUCTS_H_
2 #define AMREX_ARRAYOFSTRUCTS_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_Particle.H>
6 #include <AMReX_GpuContainers.H>
7 #include <AMReX_Vector.H>
8 
9 namespace amrex {
10 
11 template <typename T_ParticleType,
12  template<class> class Allocator=DefaultAllocator>
14 public:
15  using ParticleType = T_ParticleType;
16  using RealType = typename ParticleType::RealType;
17 
19 
22 
23  static constexpr int SizeInReal = sizeof(ParticleType) / sizeof(RealType);
24 
25  [[nodiscard]] const ParticleVector& operator() () const { return m_data; }
26  [[nodiscard]] ParticleVector& operator() () { return m_data; }
27 
32  [[nodiscard]] std::size_t size () const { return m_data.size(); }
33 
38  [[nodiscard]] int numParticles () const { return numRealParticles(); }
39 
44  [[nodiscard]] int numRealParticles () const { return numTotalParticles()-m_num_neighbor_particles; }
45 
50  [[nodiscard]] int numNeighborParticles () const { return m_num_neighbor_particles; }
51 
56  [[nodiscard]] int numTotalParticles () const { return m_data.size(); }
57 
58  void setNumNeighbors (int num_neighbors)
59  {
60  auto nrp = numRealParticles();
61  m_num_neighbor_particles = num_neighbors;
62  resize(nrp + num_neighbors);
63  }
64 
65  [[nodiscard]] int getNumNeighbors () const { return m_num_neighbor_particles; }
66 
67  [[nodiscard]] bool empty () const { return m_data.empty(); }
68 
69  [[nodiscard]] const ParticleType* data () const { return m_data.data(); }
70  [[nodiscard]] ParticleType* data () { return m_data.data(); }
71 
72  [[nodiscard]] const ParticleType* dataPtr () const { return data(); }
73  [[nodiscard]] ParticleType* dataPtr () { return data(); }
74 
75  [[nodiscard]] std::pair<int,int> dataShape () const {
76  return std::make_pair(SizeInReal, static_cast<int>(m_data.size()));
77  }
78 
79  void push_back (const ParticleType& p) { return m_data.push_back(p); }
80  void pop_back() {m_data.pop_back(); }
81  [[nodiscard]] bool empty() {return m_data.empty(); }
82 
83  [[nodiscard]] const ParticleType& back() const {return m_data.back(); }
84  [[nodiscard]] ParticleType& back() {return m_data.back(); }
85 
86  [[nodiscard]] const ParticleType& operator[] (int i) const { return m_data[i]; }
87  [[nodiscard]] ParticleType& operator[] (int i) { return m_data[i]; }
88 
89  void swap (ArrayOfStructs& other) noexcept
90  {
91  m_data.swap(other.m_data);
92  }
93 
94  void resize (size_t count) { m_data.resize(count); }
95 
97 
98  template< class InputIt >
99  void insert ( Iterator pos, InputIt first, InputIt last ) { m_data.insert(pos, first, last); }
100 
101  [[nodiscard]] typename ParticleVector::iterator begin () { return m_data.begin(); }
102  [[nodiscard]] typename ParticleVector::const_iterator begin () const { return m_data.begin(); }
103  [[nodiscard]] typename ParticleVector::const_iterator cbegin () const { return m_data.cbegin(); }
104 
105  [[nodiscard]] typename ParticleVector::iterator end () { return m_data.end(); }
106  [[nodiscard]] typename ParticleVector::const_iterator end () const { return m_data.end(); }
107  [[nodiscard]] typename ParticleVector::const_iterator cend () const { return m_data.cend(); }
108 
110 
111 private:
113 };
114 
115 #if __cplusplus < 201703L
116 template <typename ParticleType,
117  template<class> class Allocator>
119 #endif
120 
121 } // namespace amrex
122 
123 #endif // AMREX_ARRAYOFSTRUCTS_H_
Definition: AMReX_ArrayOfStructs.H:13
typename ParticleVector::const_iterator ConstIterator
Definition: AMReX_ArrayOfStructs.H:21
ParticleVector::const_iterator begin() const
Definition: AMReX_ArrayOfStructs.H:102
bool empty()
Definition: AMReX_ArrayOfStructs.H:81
int numNeighborParticles() const
Returns the number of neighbor particles (excluding reals)
Definition: AMReX_ArrayOfStructs.H:50
int m_num_neighbor_particles
Definition: AMReX_ArrayOfStructs.H:109
bool empty() const
Definition: AMReX_ArrayOfStructs.H:67
ParticleVector::const_iterator cbegin() const
Definition: AMReX_ArrayOfStructs.H:103
void setNumNeighbors(int num_neighbors)
Definition: AMReX_ArrayOfStructs.H:58
ParticleType & back()
Definition: AMReX_ArrayOfStructs.H:84
T_ParticleType ParticleType
Definition: AMReX_ArrayOfStructs.H:15
typename ParticleType::RealType RealType
Definition: AMReX_ArrayOfStructs.H:16
static constexpr int SizeInReal
Definition: AMReX_ArrayOfStructs.H:23
ParticleType * data()
Definition: AMReX_ArrayOfStructs.H:70
void push_back(const ParticleType &p)
Definition: AMReX_ArrayOfStructs.H:79
int numTotalParticles() const
Returns the total number of particles (real and neighbor)
Definition: AMReX_ArrayOfStructs.H:56
ParticleVector::iterator begin()
Definition: AMReX_ArrayOfStructs.H:101
ParticleVector::iterator end()
Definition: AMReX_ArrayOfStructs.H:105
ParticleVector::const_iterator cend() const
Definition: AMReX_ArrayOfStructs.H:107
int numParticles() const
Returns the number of real particles (excluding neighbors)
Definition: AMReX_ArrayOfStructs.H:38
void pop_back()
Definition: AMReX_ArrayOfStructs.H:80
ParticleVector::const_iterator end() const
Definition: AMReX_ArrayOfStructs.H:106
const ParticleType & back() const
Definition: AMReX_ArrayOfStructs.H:83
ParticleVector m_data
Definition: AMReX_ArrayOfStructs.H:112
ParticleType * dataPtr()
Definition: AMReX_ArrayOfStructs.H:73
void insert(Iterator pos, InputIt first, InputIt last)
Definition: AMReX_ArrayOfStructs.H:99
typename ParticleVector::iterator Iterator
Definition: AMReX_ArrayOfStructs.H:20
int numRealParticles() const
Returns the number of real particles (excluding neighbors)
Definition: AMReX_ArrayOfStructs.H:44
void resize(size_t count)
Definition: AMReX_ArrayOfStructs.H:94
const ParticleType * dataPtr() const
Definition: AMReX_ArrayOfStructs.H:72
const ParticleType * data() const
Definition: AMReX_ArrayOfStructs.H:69
int getNumNeighbors() const
Definition: AMReX_ArrayOfStructs.H:65
Iterator erase(ConstIterator first, ConstIterator second)
Definition: AMReX_ArrayOfStructs.H:96
const ParticleVector & operator()() const
Definition: AMReX_ArrayOfStructs.H:25
const ParticleType & operator[](int i) const
Definition: AMReX_ArrayOfStructs.H:86
std::size_t size() const
Returns the total number of particles (real and neighbor)
Definition: AMReX_ArrayOfStructs.H:32
void swap(ArrayOfStructs &other) noexcept
Definition: AMReX_ArrayOfStructs.H:89
std::pair< int, int > dataShape() const
Definition: AMReX_ArrayOfStructs.H:75
Definition: AMReX_PODVector.H:246
const_iterator cbegin() const noexcept
Definition: AMReX_PODVector.H:617
iterator insert(const_iterator a_pos, const T &a_item)
Definition: AMReX_PODVector.H:426
iterator erase(const_iterator a_pos)
Definition: AMReX_PODVector.H:405
size_type size() const noexcept
Definition: AMReX_PODVector.H:575
void swap(PODVector< T, Allocator > &a_vector) noexcept
Definition: AMReX_PODVector.H:677
T & back() noexcept
Definition: AMReX_PODVector.H:589
void pop_back() noexcept
Definition: AMReX_PODVector.H:571
T * data() noexcept
Definition: AMReX_PODVector.H:593
T * iterator
Definition: AMReX_PODVector.H:262
iterator begin() noexcept
Definition: AMReX_PODVector.H:601
iterator end() noexcept
Definition: AMReX_PODVector.H:605
const_iterator cend() const noexcept
Definition: AMReX_PODVector.H:619
const T * const_iterator
Definition: AMReX_PODVector.H:267
void resize(size_type a_new_size)
Definition: AMReX_PODVector.H:625
bool empty() const noexcept
Definition: AMReX_PODVector.H:579
void push_back(const T &a_value)
Definition: AMReX_PODVector.H:556
Definition: AMReX_Amr.cpp:49
amrex::ArenaAllocator< T > DefaultAllocator
Definition: AMReX_GpuAllocators.H:194
double second() noexcept
Definition: AMReX_Utility.cpp:922