ESyS-Particle  4.0.1
pp_array.h
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 #ifndef __PARALLEL_PARTICLE_ARRAY_H
00014 #define __PARALLEL_PARTICLE_ARRAY_H
00015 
00016 //--- MPI ---
00017 #include <mpi.h>
00018 
00019 //--- project includes ---
00020 #include "ntable/src/ntable.h"
00021 #include "ntable/src/nt_block.h"
00022 #include "tml/comm/comm.h"
00023 #include "tml/comm/cart_comm.h"
00024 #include "Foundation/vec3.h"
00025 #include "Geometry/Triangle.h"
00026 #include "Geometry/AEdge.h"
00027 
00028 //--- STL includes ---
00029 #include <vector>
00030 #include <set>
00031 
00032 using std::vector;
00033 using std::set;
00034 
00035 //--- IO includes ---
00036 
00041 class AParallelParticleArray
00042 {
00043  protected:
00044   TML_CartComm m_comm;
00045   int m_timestamp;
00046 
00047  public:
00048   AParallelParticleArray(TML_Comm *comm, const std::vector<unsigned int> &dims);
00049   AParallelParticleArray(TML_Comm *comm, const std::vector<unsigned int> &dims, const std::vector<bool> &circ);
00050   // virtual destructor
00051   virtual ~AParallelParticleArray(){};
00052 
00053   // get communicator
00054   TML_CartComm getComm() const {return m_comm;};
00055 
00057   int getTimeStamp(){return m_timestamp;}; 
00058 
00059   // get ids of boundary particles 
00060   virtual set<int> getBoundarySlabIds(int,int) const=0;
00061   virtual set<int> get2ndSlabIds(int,int) const=0;
00062  
00063   // check if pos is in inner part
00064   virtual bool isInInner(const Vec3&)=0;
00065 };
00066 
00067 
00073 template<typename T>
00074 class ParallelParticleArray : public AParallelParticleArray
00075 {
00076  public: // types
00077   typedef T_Handle<typename NeighborTable<T>::pairlist> PairListHandle;
00078   typedef typename NeighborTable<T>::pairlist::iterator PairListIterator;
00079   typedef T_Handle<typename NeighborTable<T>::particlelist> ParticleListHandle;
00080   typedef typename NeighborTable<T>::particlelist::iterator ParticleListIterator;
00081 
00082  private:
00083   NeighborTable<T>* m_nt;
00084   Vec3 m_minpos,m_maxpos; 
00085   double m_xshift,m_yshift,m_zshift; 
00086   bool m_circ_edge_x_up,m_circ_edge_x_down; 
00087   static const int m_exchg_tag;
00088   
00089   // helper fnc
00090   template<typename P> void exchange_single(P (T::*rdf)(),void (T::*wrtf)(const P&),NTSlab<T>,NTSlab<T>,int,int);
00091 
00092  protected:
00093 
00094  public:
00095   ParallelParticleArray(TML_Comm *comm, const vector<unsigned int> &dims,const Vec3 &min,const Vec3 &max, double rmax,double alpha);
00096   ParallelParticleArray(TML_Comm *comm, const vector<unsigned int> &dims, const vector<bool> &circ,const Vec3 &min,const Vec3 &max, double rmax,double alpha);
00097   ~ParallelParticleArray();
00098 
00099   // info func
00100   Vec3 getMinPos()const {return m_minpos;};
00101   Vec3 getMaxPos()const {return m_maxpos;};
00102   vector<int> getCommCoords() const {return m_comm.get_coords();};
00103   vector<int> getCommDims() const {return m_comm.get_all_dims();}; 
00104   int size(){return m_nt->size();};
00105   int getInnerSize(){return (m_nt->inner()).size();};
00106 
00107   // particle insert ops
00108   void insert(const T&); 
00109   void insert(const vector<T>&); 
00110 
00111   // check if pos is in inner part
00112   virtual bool isInInner(const Vec3&);
00113 
00114   // particle access (ugly!)
00115   T* getParticlePtrByIndex(int);
00116   T* getParticlePtrByPosition(const Vec3&);
00117 
00118   // rebuild
00119   void rebuild();
00120 
00121   //--- collective particle ops ---
00122   // variable exchange 
00123   template<typename P> void exchange(P (T::*rdf)(),void (T::*wrtf)(const P&));
00124 
00125   // call member func for single particle by id
00126   void forParticle(int,void (T::*rdf)());
00127   template <typename P> void forParticle(int,void (T::*rdf)(P),const P&);
00128 
00129   // call member func for single particle by tag
00130   void forParticleTag(int,void (T::*rdf)());
00131   template <typename P> void forParticleTag(int,void (T::*rdf)(P),const P&);
00132   void forParticleTagMask(int,int,void (T::*rdf)());
00133   template <typename P> void forParticleTagMask(int,int,void (T::*rdf)(P),const P&);
00134 
00135   // call member func for all particles, different nr. of params
00136   void forAllParticles(void (T::*rdf)()); 
00137   void forAllParticles(void (T::*rdf)()const); 
00138   template <typename P> void forAllParticles(void (T::*rdf)(P),const P&);
00139   
00140   // call member func for all inner particles
00141   template <typename P> void forAllInnerParticles(void (T::*rdf)(P&),P&);
00142 
00143   class ParticleIterator
00144   {
00145   public:
00146     typedef NTBlock<T> NtBlock;
00147     typedef T Particle;
00148     typedef typename NtBlock::iterator BlockIterator;
00149 
00150     ParticleIterator(const NtBlock &ntBlock);
00151 
00152     bool hasNext() const;
00153 
00154     Particle &next();
00155 
00156     int getNumRemaining() const;
00157 
00158   private:
00159     NtBlock       m_ntBlock;
00160     BlockIterator m_it;
00161     int           m_numRemaining;
00162   };
00163 
00164   ParticleIterator getInnerParticleIterator();
00165 
00166   // particle data access functions
00167   template <typename P> void forAllParticlesGet(P&,typename P::value_type (T::*rdf)() const);
00168   template <typename P> void forAllInnerParticlesGet(P&,typename P::value_type (T::*rdf)() const);
00169   template <typename P> vector<pair<int,P> > forAllParticlesGetIndexed(P (T::*rdf)() const);
00170   template <typename P> vector<pair<int,P> > forAllInnerParticlesGetIndexed(P (T::*rdf)() const);
00171 
00172   // particle data access functions with tag check
00173   template <typename P> void forAllTaggedParticlesGet(P&,typename P::value_type (T::*rdf)() const,int,int);
00174   template <typename P> void forAllTaggedInnerParticlesGet(P&,typename P::value_type (T::*rdf)() const,int,int);
00175   template <typename P> vector<pair<int,P> > forAllTaggedParticlesGetIndexed(P (T::*rdf)() const,int,int);
00176   template <typename P> vector<pair<int,P> > forAllInnerTaggedParticlesGetIndexed(P (T::*rdf)() const,int,int);
00177 
00178   // geometric data access function 
00179   template <typename P> void forPointsGetNearest(P&,typename P::value_type (T::*rdf)() const,const Vec3&,double,double,double,int,int,int);
00180 
00181   // get ids of boundary particles 
00182   virtual set<int> getBoundarySlabIds(int,int) const;
00183   virtual set<int> get2ndSlabIds(int,int) const;
00184  
00185   //--- get neigborlist stuff ---
00187   PairListHandle getFullPairList(){return m_nt->getFullList();};
00189   PairListHandle getNewPairList(){return m_nt->getNewList();};
00191   ParticleListHandle getParticlesAtPlane(Vec3 o,Vec3 n){return m_nt->getParticlesAtPlane(o,n);};
00193   ParticleListHandle getParticlesNearTriangle(const Triangle& t){return m_nt->getParticlesNearTriangle(t);};
00195   ParticleListHandle getParticlesNearEdge(const AEdge* e){return m_nt->getParticlesNearEdge(e);};
00197   ParticleListHandle getParticlesNearPoint(const Vec3& v){return m_nt->getParticlesNearPoint(v);};
00199   ParticleListHandle getAllParticles(){return m_nt->getAllParticles();};
00200   
00202   void getAllInnerParticles(vector<T>&);
00203 
00204   //--- checkpointing ---
00205   void saveCheckPointData(std::ostream&); 
00206   void loadCheckPointData(std::istream&); 
00207 
00208   //--- output (for debugging)---
00209   template <typename TT>
00210   friend ostream& operator<<(ostream &, const ParallelParticleArray<TT> &);
00211 };
00212 
00213 #include "ppa/src/pp_array.hpp"
00214 
00215 #endif //__PARALLEL_PARTICLE_ARRAY_H