ESyS-Particle  4.0.1
pp_array.h
1 
2 // //
3 // Copyright (c) 2003-2011 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 #ifndef __PARALLEL_PARTICLE_ARRAY_H
14 #define __PARALLEL_PARTICLE_ARRAY_H
15 
16 //--- MPI ---
17 #include <mpi.h>
18 
19 //--- project includes ---
20 #include "ntable/src/ntable.h"
21 #include "ntable/src/nt_block.h"
22 #include "tml/comm/comm.h"
23 #include "tml/comm/cart_comm.h"
24 #include "Foundation/vec3.h"
25 #include "Geometry/Triangle.h"
26 #include "Geometry/AEdge.h"
27 
28 //--- STL includes ---
29 #include <vector>
30 #include <set>
31 
32 using std::vector;
33 using std::set;
34 
35 //--- IO includes ---
36 
42 {
43  protected:
44  TML_CartComm m_comm;
45  int m_timestamp;
46 
47  public:
48  AParallelParticleArray(TML_Comm *comm, const std::vector<unsigned int> &dims);
49  AParallelParticleArray(TML_Comm *comm, const std::vector<unsigned int> &dims, const std::vector<bool> &circ);
50  // virtual destructor
51  virtual ~AParallelParticleArray(){};
52 
53  // get communicator
54  TML_CartComm getComm() const {return m_comm;};
55 
57  int getTimeStamp(){return m_timestamp;};
58 
59  // get ids of boundary particles
60  virtual set<int> getBoundarySlabIds(int,int) const=0;
61  virtual set<int> get2ndSlabIds(int,int) const=0;
62 
63  // check if pos is in inner part
64  virtual bool isInInner(const Vec3&)=0;
65 };
66 
67 
73 template<typename T>
75 {
76  public: // types
77  typedef T_Handle<typename NeighborTable<T>::pairlist> PairListHandle;
78  typedef typename NeighborTable<T>::pairlist::iterator PairListIterator;
79  typedef T_Handle<typename NeighborTable<T>::particlelist> ParticleListHandle;
80  typedef typename NeighborTable<T>::particlelist::iterator ParticleListIterator;
81 
82  private:
83  NeighborTable<T>* m_nt;
84  Vec3 m_minpos,m_maxpos;
85  double m_xshift,m_yshift,m_zshift;
86  bool m_circ_edge_x_up,m_circ_edge_x_down;
87  static const int m_exchg_tag;
88 
89  // helper fnc
90  template<typename P> void exchange_single(P (T::*rdf)(),void (T::*wrtf)(const P&),NTSlab<T>,NTSlab<T>,int,int);
91 
92  protected:
93 
94  public:
95  ParallelParticleArray(TML_Comm *comm, const vector<unsigned int> &dims,const Vec3 &min,const Vec3 &max, double rmax,double alpha);
96  ParallelParticleArray(TML_Comm *comm, const vector<unsigned int> &dims, const vector<bool> &circ,const Vec3 &min,const Vec3 &max, double rmax,double alpha);
98 
99  // info func
100  Vec3 getMinPos()const {return m_minpos;};
101  Vec3 getMaxPos()const {return m_maxpos;};
102  vector<int> getCommCoords() const {return m_comm.get_coords();};
103  vector<int> getCommDims() const {return m_comm.get_all_dims();};
104  int size(){return m_nt->size();};
105  int getInnerSize(){return (m_nt->inner()).size();};
106 
107  // particle insert ops
108  void insert(const T&);
109  void insert(const vector<T>&);
110 
111  // check if pos is in inner part
112  virtual bool isInInner(const Vec3&);
113 
114  // particle access (ugly!)
115  T* getParticlePtrByIndex(int);
116  T* getParticlePtrByPosition(const Vec3&);
117 
118  // rebuild
119  void rebuild();
120 
121  //--- collective particle ops ---
122  // variable exchange
123  template<typename P> void exchange(P (T::*rdf)(),void (T::*wrtf)(const P&));
124 
125  // call member func for single particle by id
126  void forParticle(int,void (T::*rdf)());
127  template <typename P> void forParticle(int,void (T::*rdf)(P),const P&);
128 
129  // call member func for single particle by tag
130  void forParticleTag(int,void (T::*rdf)());
131  template <typename P> void forParticleTag(int,void (T::*rdf)(P),const P&);
132  void forParticleTagMask(int,int,void (T::*rdf)());
133  template <typename P> void forParticleTagMask(int,int,void (T::*rdf)(P),const P&);
134 
135  // call member func for all particles, different nr. of params
136  void forAllParticles(void (T::*rdf)());
137  void forAllParticles(void (T::*rdf)()const);
138  template <typename P> void forAllParticles(void (T::*rdf)(P),const P&);
139 
140  // call member func for all inner particles
141  template <typename P> void forAllInnerParticles(void (T::*rdf)(P&),P&);
142 
144  {
145  public:
146  typedef NTBlock<T> NtBlock;
147  typedef T Particle;
148  typedef typename NtBlock::iterator BlockIterator;
149 
150  ParticleIterator(const NtBlock &ntBlock);
151 
152  bool hasNext() const;
153 
154  Particle &next();
155 
156  int getNumRemaining() const;
157 
158  private:
159  NtBlock m_ntBlock;
160  BlockIterator m_it;
161  int m_numRemaining;
162  };
163 
164  ParticleIterator getInnerParticleIterator();
165 
166  // particle data access functions
167  template <typename P> void forAllParticlesGet(P&,typename P::value_type (T::*rdf)() const);
168  template <typename P> void forAllInnerParticlesGet(P&,typename P::value_type (T::*rdf)() const);
169  template <typename P> vector<pair<int,P> > forAllParticlesGetIndexed(P (T::*rdf)() const);
170  template <typename P> vector<pair<int,P> > forAllInnerParticlesGetIndexed(P (T::*rdf)() const);
171 
172  // particle data access functions with tag check
173  template <typename P> void forAllTaggedParticlesGet(P&,typename P::value_type (T::*rdf)() const,int,int);
174  template <typename P> void forAllTaggedInnerParticlesGet(P&,typename P::value_type (T::*rdf)() const,int,int);
175  template <typename P> vector<pair<int,P> > forAllTaggedParticlesGetIndexed(P (T::*rdf)() const,int,int);
176  template <typename P> vector<pair<int,P> > forAllInnerTaggedParticlesGetIndexed(P (T::*rdf)() const,int,int);
177 
178  // geometric data access function
179  template <typename P> void forPointsGetNearest(P&,typename P::value_type (T::*rdf)() const,const Vec3&,double,double,double,int,int,int);
180 
181  // get ids of boundary particles
182  virtual set<int> getBoundarySlabIds(int,int) const;
183  virtual set<int> get2ndSlabIds(int,int) const;
184 
185  //--- get neigborlist stuff ---
187  PairListHandle getFullPairList(){return m_nt->getFullList();};
189  PairListHandle getNewPairList(){return m_nt->getNewList();};
191  ParticleListHandle getParticlesAtPlane(Vec3 o,Vec3 n){return m_nt->getParticlesAtPlane(o,n);};
193  ParticleListHandle getParticlesNearTriangle(const Triangle& t){return m_nt->getParticlesNearTriangle(t);};
195  ParticleListHandle getParticlesNearEdge(const AEdge* e){return m_nt->getParticlesNearEdge(e);};
197  ParticleListHandle getParticlesNearPoint(const Vec3& v){return m_nt->getParticlesNearPoint(v);};
199  ParticleListHandle getAllParticles(){return m_nt->getAllParticles();};
200 
202  void getAllInnerParticles(vector<T>&);
203 
204  //--- checkpointing ---
205  void saveCheckPointData(std::ostream&);
206  void loadCheckPointData(std::istream&);
207 
208  //--- output (for debugging)---
209  template <typename TT>
210  friend ostream& operator<<(ostream &, const ParallelParticleArray<TT> &);
211 };
212 
213 #include "ppa/src/pp_array.hpp"
214 
215 #endif //__PARALLEL_PARTICLE_ARRAY_H