ESyS-Particle  2.2
LatticeMaster.h
Go to the documentation of this file.
1 
2 // //
3 // Copyright (c) 2003-2013 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 __LATTICEMASTER_H
14 #define __LATTICEMASTER_H
15 
16 //--- Project includes ---
17 
18 #include "Parallel/mpibuf.h"
19 #include "Parallel/mpivbuf.h"
20 #include "Parallel/LatticeParam.h"
21 #include "Parallel/RankAndComm.h"
23 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 
28 #include "Foundation/console.h"
29 #include "Foundation/Runnable.h"
30 
31 #include "Fields/FieldMaster.h"
32 #include "Fields/MaxTrigger.h"
33 
34 #include "Geometry/GeometryInfo.h"
35 
37 
38 #include "Model/Damping.h"
39 #include "Model/LocalDamping.h"
40 #include "Model/ABCDampingIGP.h"
41 #include "Model/Particle.h"
42 #include "Model/RotParticle.h"
43 #include "Model/RotParticleVi.h"
44 #include "Model/RotThermParticle.h"
47 #include "Model/FractalFriction.h"
48 #include "Model/AdhesiveFriction.h"
53 #include "Model/MeshData.h"
54 #include "Model/ETriMeshIP.h"
55 #include "Model/BTriMeshIP.h"
56 #include "Model/BMesh2DIP.h"
65 #include "Model/BodyForceGroup.h"
68 #include "Model/ViscWallIG.h"
70 
71 #include <boost/filesystem/path.hpp>
72 
73 //--- MPI includes ---
74 #include <mpi.h>
75 
76 //--- TML includes ---
77 #include "tml/comm/comm_world.h"
78 
79 // -- STL includes --
80 #include <vector>
81 #include <list>
82 #include <map>
83 #include <utility>
84 #include <string>
85 
86 // forward decls.
87 // includes are in the .cpp
89 
90 namespace esys
91 {
92  namespace lsm
93  {
94  class GeometryInfo;
95  class BodyForceIGP;
96  }
97 }
98 
106 class MpiWTimers;
107 
108 namespace esys
109 {
110  namespace lsm
111  {
112  typedef std::vector<int> IntVector;
113  }
114 }
115 
117 {
118  public:
119  typedef std::vector<esys::lsm::Runnable *> RunnableVector;
120  typedef std::pair<int, int> ParticleIdPair;
121  typedef std::vector<ParticleIdPair> ParticleIdPairVector;
122  typedef std::vector<MeshNodeData> MeshNodeDataVector;
123  typedef std::vector<MeshTriData> MeshTriDataVector;
124  typedef std::pair<MeshNodeDataVector,MeshTriDataVector> TriMeshDataPair;
125 
126  private:
127  std::string m_timingFileName;
129  CheckPointController *m_pCheckPointController; // for restart checkpoints
130  CheckPointController *m_pSnapShotController; // for viz/analysis dumps
132 
133  protected:
134  typedef std::vector<int> ConnIdVector;
135  map<int,ConnIdVector> m_temp_conn;
136  vector<AFieldMaster*> m_save_fields;
137 
138  // -- variables for global model geometry
142  // ----
143 
146  int m_max_ts;
148  double m_total_time;
149  int m_t ;
150  double m_dt;
153  std::string m_particle_type;
154 
157 
160  MPI_Group m_mpi_local_group; // needs to be member in order to free at desctruction
161 
162  void runRunnables(RunnableVector::iterator begin, RunnableVector::iterator end);
163  void runPreRunnables();
164  void runPostRunnables();
165 
166  void saveTimingData();
167  TriMeshDataPair readTriMesh(const std::string &fileName,int);
168  TriMeshDataPair readTriMesh(const std::string &fileName);
169  void readAndDistributeMesh2D(const std::string&,int);
170 
172  {
174  }
175 
176 public:
177  CLatticeMaster();
178  ~CLatticeMaster();
179 
180  std::string getLsmVersion() const
181  {
182  return std::string(PACKAGE_VERSION);
183  }
184 
185  int getNumWorkerProcesses() const;
186 
187  int getTimeStep() const {return m_t;}
188  double getTimeStepSize() const {return m_dt;}
189  void setTimeStepSize(double dt);
190 
191  void init();
192 
193  void setupWorkers(int numWorkers);
194  void run();
195  void runInit();
196  void runOneStep();
197  void runEnd();
198  void oneStep();
199  void searchNeighbors(bool);
200  bool checkNeighbors();
201  void updateInteractions();
202  void addBondedIG(const CBondedIGP&);
203  void addCappedBondedIG(int,const std::string&,double,double,double);
204  void addShortBondedIG(int,const std::string&,double,double);
205 
206  void addPairIG(const CElasticIGP &prms);
207  void addPairIG(const CFrictionIGP &prms);
208  void addPairIG(const FractalFrictionIGP &prms);
209  void addPairIG(const CAdhesiveFrictionIGP &prms);
210  void addPairIG(const CRotElasticIGP &prms);
211  void addPairIG(const CRotFrictionIGP &prms);
212  void addPairIG(const CHertzianElasticIGP &prms);
214  void addPairIG(const CHertzianViscoElasticIGP &prms);
215  void addPairIG(const CLinearDashpotIGP &prms);
216  void addPairIG(const CRotThermElasticIGP &prms);
217  void addPairIG(const CRotThermFrictionIGP &prms);
218  void addTaggedPairIG(const CRotFrictionIGP &prms,int,int,int,int);
219  void addTaggedPairIG(const CFrictionIGP &prms,int,int,int,int);
220  void addTaggedPairIG(const CHertzianElasticIGP &prms,int,int,int,int);
221  void addTaggedPairIG(const CHertzianViscoElasticFrictionIGP &prms,int,int,int,int);
222  void addTaggedPairIG(const CHertzianViscoElasticIGP &prms,int,int,int,int);
223  void addTaggedPairIG(const CLinearDashpotIGP &prms,int,int,int,int);
224  void addTaggedPairIG(const CRotElasticIGP &prms,int,int,int,int);
225  void addTaggedPairIG(const CElasticIGP &prms,int,int,int,int);
226 
227  void removeIG(const std::string&);
228 
229  void readAndDistributeTriMesh(const std::string&,const std::string&,int);
230  void readAndDistributeTriMesh(const std::string&,const std::string&);
231  void createTriMesh(
232  const std::string &meshName,
233  const MeshNodeDataVector &mndVector,
234  const MeshTriDataVector &mtdVector
235  );
236  void addMesh2D(const std::string&,const std::string&,int);
237  void addMesh2DIG(const ETriMeshIP &prms);
238  void addTriMesh(const std::string &meshName, const std::string &fileName);
239  void addTriMeshIG(const ETriMeshIP &prms);
240 
241  void addBondedTriMeshIG(const BTriMeshIP &triMeshPrms, const MeshTagBuildPrms &buildPrms);
242  void addBondedTriMeshIG(const BTriMeshIP &triMeshPrms, const MeshGapBuildPrms &buildPrms);
243 
244  void addBondedMesh2DIG(const BMesh2DIP&, const MeshTagBuildPrms&);
245  void addBondedMesh2DIG(const BMesh2DIP&, const MeshGapBuildPrms&);
246  void addDamping(const CDampingIGP &dampingIGP);
247  void addDamping(const CLocalDampingIGP &dampingIGP);
248  void addDamping(const ABCDampingIGP &dampingIGP);
249 
250  void addSingleIG(const esys::lsm::GravityIGP &gravityIGP);
251  void addSingleIG(const esys::lsm::BuoyancyIGP &buoyancyIGP);
252  void addExIG(const std::string&,const std::string&);
253  void setNumSteps(int s);
254  int getNumSteps() const {return m_max_ts;};
255  int getSteps() const {return m_t;};
256 
257  void addRotBondedIG(int,const std::string&,double,double,double,double,double,double,double,double,bool,bool,double);
258  void addRotThermBondedIG(const CRotThermBondedIGP &prms);
259 
260 // ParticleIdPairVector getBondGroupIdPairs(const std::string &groupName);
261 
262  // --- wall related fucntions ---
263  void addWall(const std::string&,const Vec3&,const Vec3&);
264  void addWallIG(const CEWallIGP&);
265  void addWallIG(const CBWallIGP&);
266  void addWallIG(const CVWallIGP&);
267  void addWallIG(const CSoftBWallIGP&);
268  Vec3 getWallPosn(const std::string&);
269  Vec3 getWallForce(const std::string&);
270 
271  // void initSoftBondedWall(const string&,const Vec3&,const Vec3&,double,double,double,int);
272 
273 
274  void moveParticleTo(int particleTag, const Vec3 &posn);
275  void moveTaggedParticlesBy(int particleTag, const Vec3 &displacement);
276  void moveSingleParticleTo(int particleId, const Vec3 &posn);
277  Vec3 getParticlePosn(int particleId);
278  void setParticleNonDynamic(int);
279  void setParticleNonRot(int);
280  void setParticleNonTrans(int);
281  void setParticleVel(int,const Vec3&);
282  void setParticleAngVel(int,const Vec3&);
283  void setParticleDensity(int tag,int mask,double rho);
284  void setTaggedParticleVel(int tag,const Vec3&);
285  void moveWallBy(const std::string&,const Vec3&);
286  void setWallNormal(const std::string&,const Vec3&);
287  void setVelocityOfWall(const std::string&,const Vec3&);
288  void tagParticleNearestTo(int,int,const Vec3&);
293  int findParticleNearestTo(const Vec3& pos);
294  void applyForceToWall(const std::string&,const Vec3&);
295  // --- Mesh movement functions ---
296  void moveSingleNodeBy(const std::string&,int,const Vec3&);
297  void moveTaggedNodesBy(const std::string&,int,const Vec3&);
298  void translateMeshBy(const std::string&,const Vec3&);
299 
300  void saveTimingDataToFile(const std::string &fileNamePrefix);
301 
305  void do2dCalculations(bool do2d);
306 
317 
319 
325  void setTimingFileName(const std::string &fileName);
326 
333  const std::string &getTimingFileName() const;
334 
335  const std::string &getParticleType() const
336  {
337  return m_particle_type;
338  }
339 
340  int getNumParticles();
341 
343  void addScalarParticleSaveField(const std::string&,const std::string&,const std::string&,int,int,int);
344  void addTaggedScalarParticleSaveField(const std::string&,const std::string&,const std::string&,int,int,int,int,int);
345  void addVectorParticleSaveField(const std::string&,const std::string&,const std::string&,int,int,int);
346  void addTaggedVectorParticleSaveField(const std::string&,const std::string&,const std::string&,int,int,int,int,int);
347  void addScalarInteractionSaveField(const std::string&,const std::string&,const std::string&,const std::string&,const std::string&,int,int,int,bool checked=false);
348  void addVectorInteractionSaveField(const std::string&,const std::string&,const std::string&,const std::string&,const std::string&,int,int,int,bool checked=false);
349  void addTaggedScalarInteractionSaveField(const std::string&,const std::string&,const std::string&,const std::string&,const std::string&,int,int,int,int,int,bool);
350  void addTaggedScalarParticleDistributionSaver(const std::string&,const std::string&,const std::string&,int,int,int,int,int,int,double,double,int);
351  void addVectorTriangleSaveField(const string&,const string&,const string&,const string&,int,int,int);
352  void addScalarTriangleSaveField(const string&,const string&,const string&,const string&,int,int,int);
353  void addVectorWallField(const string&,const string&,vector<string>,const string&,int,int,int);
354  // fields with trigger
355  void addVectorParticleSaveFieldWT(const std::string&,const std::string&,const std::string&,int,int,int,const MaxTrigParams&);
356  void addTaggedVectorParticleSaveFieldWT(const std::string&,const std::string&,const std::string&,int,int,int,int,int,const MaxTrigParams&);
357 
368  void performCheckPoints(
369  const std::string &fileNamePrefix,
370  int beginTime,
371  int endTime,
372  int timeInterval,
373  int precision
374  );
375 
389  const std::string &fileNamePrefix,
390  int beginTime,
391  int endTime,
392  int timeInterval,
393  int precision
394  );
395 
396  void initSnapShotController(const std::string&,int,int,int);
397 
399  void makeLattice(
400  const char *particleType,
401  double gridSize,
402  double verletDist
403  );
404 
405  void makeLattice(
406  const char *particleType,
407  double gridSize,
408  double verletDist,
409  double dt
410  );
411 
417 
422  {
423  return m_preRunnableVector;
424  }
425 
430  {
431  return m_preRunnableVector;
432  }
433 
439 
444  {
445  return m_postRunnableVector;
446  }
447 
452  {
453  return m_postRunnableVector;
454  }
455 
459  void setSpatialDomain(const Vec3 &minBBoxPt, const Vec3 &maxBBoxPt);
460 
464  void setSpatialDomain(
465  const Vec3 &minBBoxPt,
466  const Vec3 &maxBBoxPt,
467  const esys::lsm::IntVector &circDimVector
468  );
469 
474  //bool haveSetSpatialDomain() const;
475 
479  void getSlaveSpatialDomains();
480 
481 
489  template <class TmplParticle>
490  void readGeometry(const std::string &fileName);
491 
497  void readGeometryFile(const std::string &fileName);
498 
506  void loadCheckPointData(const std::string &checkPointFileName);
507 
516  template <class TmplIterator, class TmplParticle>
517  void addParticles(TmplIterator &it);
518 
527  template <class TmplIterator>
528  void addConnections(TmplIterator &it);
529 
530  //--- function for mesh data exchange ---
531  template <typename TmplVisitor>
532  void visitMeshFaceReferences(const string &meshName);
533 
534  template <typename TmplVisitor>
535  void visitMesh2dNodeReferences(const string &meshName, TmplVisitor &visitor);
536 
537  template <typename TmplVisitor>
538  void visitMesh2dEdgeStress(const string &meshName, TmplVisitor &visitor);
539 
540  template <typename TmplVisitor>
542  const string &meshName,
543  TmplVisitor &visitor
544  );
545 
546  typedef std::vector<int> IdVector;
547 
548  template <typename TmplVisitor, typename TmplParticle>
550  const IdVector &particleIdVector,
551  TmplVisitor &visitor
552  );
553 
554  template <typename TmplVisitor>
555  void visitParticles(const IdVector &particleIdVector, TmplVisitor &visitor);
556 
557  void setVerbosity(bool);
558 };
559 
561 
562 #endif