ESyS-Particle  4.0.1
pi_storage.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_INTERACTION_STORAGE_H
00014 #define __PARALLEL_INTERACTION_STORAGE_H
00015 
00016 //--- MPI includes ---
00017 #include <mpi.h>
00018 
00019 //--- STL includes ---
00020 #include <list>
00021 #include <vector>
00022 #include <iostream>
00023 #include <stdexcept>
00024 
00025 using std::list;
00026 using std::vector;
00027 using std::pair;
00028 
00029 //--- Project includes ---
00030 #include "Foundation/vec3.h"
00031 #include "Foundation/quintuple.h"
00032 #include "Foundation/triplet.h"
00033 #include "Parallel/CheckPointable.h"
00034 #include "tml/comm/comm.h"
00035 
00036 // forward declared class to avoid circular include
00037 class AFieldSlave; 
00038 class AParallelParticleArray;
00039 
00044 class AParallelInteractionStorage : public esys::lsm::CheckPointable
00045 {
00046  protected:
00047   AParallelParticleArray* m_ppa;
00048 
00049  public:
00050   AParallelInteractionStorage(AParallelParticleArray* ppa){m_ppa=ppa;};
00051   virtual ~AParallelInteractionStorage(){};
00052 
00053   virtual void exchange()=0;
00054   virtual void rebuild()=0;
00055   virtual bool update()=0;
00056   //  virtual void tryInsert(const vector<int>&)=0;
00057   virtual bool isIn(const vector<int>&)=0;
00058   virtual void calcForces()=0;
00059   virtual void calcHeatFrict() {}
00060   virtual void calcHeatTrans() {}
00061   virtual void setTimeStepSize(double dt)=0;
00062   virtual void addExIG(AParallelInteractionStorage*){}; // do nothing
00063   virtual AFieldSlave* generateNewScalarFieldSlave(TML_Comm*,const string&,int,int,int,int)=0;
00064   virtual AFieldSlave* generateNewVectorFieldSlave(TML_Comm*,const string&,int,int,int,int)=0;
00065 
00066   virtual void saveCheckPointData(std::ostream &oStream)
00067   {
00068     throw std::runtime_error("saveCheckPointData not implemented in subclass.");
00069   }
00070   
00071   virtual void loadCheckPointData(std::istream &iStream)
00072   {
00073     throw std::runtime_error("loadCheckPointData not implemented in subclass.");
00074   }
00075 
00076   virtual void saveSnapShotData(std::ostream&)
00077   {
00078     throw std::runtime_error(" saveSnapShotData not implemented in subclass.");
00079   }
00080 
00081   virtual bool willSave(){ return false;};
00082 };
00083 
00089 template <typename I>
00090 class TParallelInteractionStorage : public AParallelInteractionStorage
00091 {
00092  public:
00093   typedef I interaction_type;
00094 
00095  protected:
00096   list<I> m_interactions;
00097 
00098  public:
00099   TParallelInteractionStorage(AParallelParticleArray* ppa):AParallelInteractionStorage(ppa){};
00100   virtual ~TParallelInteractionStorage(){};
00101 
00102   class InteractionIterator {
00103   public:
00104     typedef I Interaction;
00105     typedef typename list<I>::iterator Iterator;
00106 
00107     InteractionIterator(Iterator begin, Iterator end, AParallelParticleArray* ppa);
00108 
00109     bool hasNext();
00110 
00111     Interaction &next();
00112 
00113     int getNumRemaining();
00114     
00115   protected:
00116     bool isInner(const Iterator &it);
00117 
00118   private:
00119     int                    m_numRemaining;
00120     Iterator               m_it;
00121     Iterator               m_end;
00122     AParallelParticleArray *m_ppa;
00123   };
00124 
00125   InteractionIterator getInnerInteractionIterator();
00126 
00128   typedef esys::lsm::quintuple<Vec3,double,Vec3,double,Vec3> Raw2Data;
00129   typedef esys::lsm::triplet<int,int,Vec3> DataWithID;
00130   typedef esys::lsm::quintuple<int,int,Vec3,Vec3,Vec3> DataWithPosID;
00131 
00133   template <typename P> vector<pair<Vec3,P> > forAllInnerInteractionsGetWithPos(P (I::*rdf)() const);
00134   template <typename P> vector<pair<Raw2Data,P> > forAllInnerInteractionsGetRaw2(P (I::*rdf)() const);
00135   template <typename P> vector<pair<DataWithID,P> > forAllInnerInteractionsGetDataWithID(P (I::*rdf)() const);
00136   template <typename P> vector<pair<DataWithPosID,P> > forAllInnerInteractionsGetDataWithPosID(P (I::*rdf)() const);
00137   template <typename P> void forAllInnerInteractionsGet(P&,typename P::value_type (I::*rdf)() const);
00138 
00140   template <typename P> vector<pair<Vec3,P> > forAllTaggedInnerInteractionsGetWithPos(P (I::*rdf)() const,int,int);
00141   template <typename P> void forAllTaggedInnerInteractionsGet(P&,typename P::value_type (I::*rdf)() const,int,int);
00142 
00144   virtual AFieldSlave* generateNewScalarFieldSlave(TML_Comm*,const string&,int,int,int,int); // const ?
00145   virtual AFieldSlave* generateNewVectorFieldSlave(TML_Comm*,const string&,int,int,int,int);
00146 
00147 };
00148 
00149 #include "pis/pi_storage.hpp"
00150 
00151 #endif //__PARALLEL_INTERACTION_STORAGE_H