ESyS-Particle  4.0.1
pi_storage.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_INTERACTION_STORAGE_H
14 #define __PARALLEL_INTERACTION_STORAGE_H
15 
16 //--- MPI includes ---
17 #include <mpi.h>
18 
19 //--- STL includes ---
20 #include <list>
21 #include <vector>
22 #include <iostream>
23 #include <stdexcept>
24 
25 using std::list;
26 using std::vector;
27 using std::pair;
28 
29 //--- Project includes ---
30 #include "Foundation/vec3.h"
31 #include "Foundation/quintuple.h"
32 #include "Foundation/triplet.h"
33 #include "Parallel/CheckPointable.h"
34 #include "tml/comm/comm.h"
35 
36 // forward declared class to avoid circular include
37 class AFieldSlave;
39 
45 {
46  protected:
48 
49  public:
51  virtual ~AParallelInteractionStorage(){};
52 
53  virtual void exchange()=0;
54  virtual void rebuild()=0;
55  virtual bool update()=0;
56  // virtual void tryInsert(const vector<int>&)=0;
57  virtual bool isIn(const vector<int>&)=0;
58  virtual void calcForces()=0;
59  virtual void calcHeatFrict() {}
60  virtual void calcHeatTrans() {}
61  virtual void setTimeStepSize(double dt)=0;
62  virtual void addExIG(AParallelInteractionStorage*){}; // do nothing
63  virtual AFieldSlave* generateNewScalarFieldSlave(TML_Comm*,const string&,int,int,int,int)=0;
64  virtual AFieldSlave* generateNewVectorFieldSlave(TML_Comm*,const string&,int,int,int,int)=0;
65 
66  virtual void saveCheckPointData(std::ostream &oStream)
67  {
68  throw std::runtime_error("saveCheckPointData not implemented in subclass.");
69  }
70 
71  virtual void loadCheckPointData(std::istream &iStream)
72  {
73  throw std::runtime_error("loadCheckPointData not implemented in subclass.");
74  }
75 
76  virtual void saveSnapShotData(std::ostream&)
77  {
78  throw std::runtime_error(" saveSnapShotData not implemented in subclass.");
79  }
80 
81  virtual bool willSave(){ return false;};
82 };
83 
89 template <typename I>
91 {
92  public:
93  typedef I interaction_type;
94 
95  protected:
96  list<I> m_interactions;
97 
98  public:
100  virtual ~TParallelInteractionStorage(){};
101 
103  public:
104  typedef I Interaction;
105  typedef typename list<I>::iterator Iterator;
106 
107  InteractionIterator(Iterator begin, Iterator end, AParallelParticleArray* ppa);
108 
109  bool hasNext();
110 
111  Interaction &next();
112 
113  int getNumRemaining();
114 
115  protected:
116  bool isInner(const Iterator &it);
117 
118  private:
119  int m_numRemaining;
120  Iterator m_it;
121  Iterator m_end;
122  AParallelParticleArray *m_ppa;
123  };
124 
126 
131 
133  template <typename P> vector<pair<Vec3,P> > forAllInnerInteractionsGetWithPos(P (I::*rdf)() const);
134  template <typename P> vector<pair<Raw2Data,P> > forAllInnerInteractionsGetRaw2(P (I::*rdf)() const);
135  template <typename P> vector<pair<DataWithID,P> > forAllInnerInteractionsGetDataWithID(P (I::*rdf)() const);
136  template <typename P> vector<pair<DataWithPosID,P> > forAllInnerInteractionsGetDataWithPosID(P (I::*rdf)() const);
137  template <typename P> void forAllInnerInteractionsGet(P&,typename P::value_type (I::*rdf)() const);
138 
140  template <typename P> vector<pair<Vec3,P> > forAllTaggedInnerInteractionsGetWithPos(P (I::*rdf)() const,int,int);
141  template <typename P> void forAllTaggedInnerInteractionsGet(P&,typename P::value_type (I::*rdf)() const,int,int);
142 
144  virtual AFieldSlave* generateNewScalarFieldSlave(TML_Comm*,const string&,int,int,int,int); // const ?
145  virtual AFieldSlave* generateNewVectorFieldSlave(TML_Comm*,const string&,int,int,int,int);
146 
147 };
148 
149 #include "pis/pi_storage.hpp"
150 
151 #endif //__PARALLEL_INTERACTION_STORAGE_H