ESyS-Particle  2.3.2
GougeConfig.h
Go to the documentation of this file.
1 
2 // //
3 // Copyright (c) 2003-2014 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
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 
14 #ifndef ESYS_LSMGOUGECONFIG_H
15 #define ESYS_LSMGOUGECONFIG_H
16 
17 #include "Foundation/BoundingBox.h"
19 #include "Geometry/Plane3D.h"
24 
25 #include <boost/shared_ptr.hpp>
26 
27 #include <vector>
28 #include <float.h>
29 
30 namespace esys
31 {
32  namespace lsm
33  {
34  typedef std::vector<Plane3D> PlaneVector;
36  {
37  XY,
38  XZ,
39  YZ
40  };
41 
43  {
44  public:
45  inline ParticleRndPackPrms();
46 
47  inline ParticleRndPackPrms(double size, double minRadius, double maxRadius);
48 
49  inline ~ParticleRndPackPrms();
50 
51  inline double getSize() const;
52 
53  inline double getMinParticleRadius() const;
54 
55  inline double getMaxParticleRadius() const;
56 
57  private:
58  double m_size;
61  };
62 
63  template <typename TmplParticleGrainGen>
65  {
66  public:
67  typedef TmplParticleGrainGen ParticleGrainGen;
69 
71 
73  double size,
74  ParticleGrainGen &particleGrainGen,
75  int connectionTag=0
76  );
77 
78  double getMinGrainRadius();
79 
80  double getMaxGrainRadius();
81 
83 
84  int getConnectionTag() const;
85  private:
88  };
89 
90  typedef std::vector<bool> BoolVector;
91  typedef std::vector<BoundingBox> BoundingBoxVector;
92 
93  class PackingInfo
94  {
95  public:
96  inline PackingInfo(
97  const BoundingBox &bBox,
98  const BoolVector &periodicDimensions,
99  Orientation orientation,
100  double minRadius,
101  double maxRadius
102  );
103 
104  inline bool is3d() const;
105 
106  inline void initialiseFitPlaneVector();
107 
108  inline const BoundingBox &getBBox() const;
109 
110  inline const PlaneVector &getFitPlaneVector() const;
111 
112  inline double getMinParticleRadius() const;
113 
114  inline double getMaxParticleRadius() const;
115 
116  inline const BoolVector &getPeriodicDimensions() const;
117  private:
121  double m_minRadius;
122  double m_maxRadius;
124  };
125 
126  template <typename TmplParticleGrainGen>
128  {
129  public:
130  typedef TmplParticleGrainGen ParticleGrainGen;
132 
134  const BoundingBox &bBox,
135  const BoolVector &periodicDimensions,
136  Orientation orientation,
137  ParticleGrainGen &particleGrainGen
138  );
139 
140  double getMinGrainRadius() const;
141 
142  double getMaxGrainRadius() const;
143 
145 
146  private:
148  };
149 
150  typedef std::vector<PackingInfo> PackingInfoVector;
151 
152  template <typename TmplParticleGrainGen>
154  {
155  public:
156  typedef TmplParticleGrainGen ParticleGrainGen;
160  typedef std::vector<GougePackInfo> GougePackingInfoVector;
161 
162  GougeConfigPrms();
167  const BoundingBox &bBox,
168  double padRadius,
169  Orientation orientation,
170  const ParticleRndPackPrms &faultRegionPrms,
171  const GrainRPackPrms &gougeRegionPrms,
172  const BoolVector &peridicDimensions=BoolVector(3, false),
173  int maxInsertionFailures=100,
174  double tolerance = DBL_EPSILON*128,
175  double connectionTolerance = DBL_EPSILON*128*10,
176  int blockConnectionTag = 0
177  );
178 
180 
181  double getTolerance() const;
182 
183  double getConnectionTolerance() const;
184 
185  const BoundingBox &getBBox() const;
186 
187  int getMaxInsertionFailures() const;
188 
189  double getRegularBlockRadius() const;
190 
191  double getFaultMinRadius() const;
192 
193  double getFaultMaxRadius() const;
194 
195  double getGougeMinRadius() const;
196 
197  double getGougeMaxRadius() const;
198 
199  int getGougeConnectionTag() const;
200 
201  int getBlockConnectionTag() const;
202 
203  const BoolVector &getPeriodicDimensions() const;
204 
206 
208 
210 
211  BoundingBox cutFromCentre(double d1, double d2) const;
212 
213  Orientation getOrientation() const;
214 
215  int getOrientationIndex() const;
216 
217  double getOrientationSize() const;
218 
219  double getMaxRadius() const;
220 
221  double getMinRadius() const;
222 
223  bool is2d() const;
224 
225  private:
227  double m_padRadius;
233  double m_tolerance;
236  };
237 
241  template <
242  typename TmplGrainRandomBoxPacker,
243  typename TmplParticleRandomBoxPacker,
244  typename TmplConnection
245  >
247  {
248  public:
249  typedef TmplConnection Connection;
250  typedef TmplGrainRandomBoxPacker GrainRandomPacker;
251  typedef boost::shared_ptr<GrainRandomPacker> GrainRandomPackerPtr;
256  typedef typename GrainRandomPacker::ParticleIterator ParticleIterator;
257  typedef typename GrainRandomPacker::ParticleConstIterator ParticleConstIterator;
258  typedef typename GrainRandomPacker::ParticleCollection ParticleCollection;
259  typedef typename GrainRandomPacker::Grain Grain;
263 
264  typedef typename GrainRandomPacker::PackerBase APacker;
265  typedef typename GrainRandomPacker::BoxPackerBase ABoxPacker;
266 
270 
271  typedef TmplParticleRandomBoxPacker RndBoxPacker;
274 
277  typedef boost::shared_ptr<APacker> GeneratorPtr;
278  typedef std::vector<GeneratorPtr> GeneratorPtrVector;
279  typedef std::vector<GrainRandomPackerPtr> GrainRndPackerPtrVector;
284 
286  {
287  public:
288  bool operator()(const Connection &i1, const Connection &i2) const
289  {
290  return
291  (
292  (i1.getP1Id() < i2.getP1Id())
293  ||
294  (
295  (i1.getP1Id() == i2.getP1Id())
296  &&
297  (
298  (i1.getP2Id() < i2.getP2Id())
299  ||
300  (
301  (i1.getP2Id() == i2.getP2Id())
302  &&
303  (i1.getTag() < i2.getTag())
304  )
305  )
306  )
307  );
308  }
309 
310  bool operator()(const Connection *i1, const Connection *i2) const
311  {
312  return (*this)(*i1, *i2);
313  }
314  };
315  typedef std::set<Connection,ConnectionCmp> ConnectionSet;
317 
318  GougeConfig(const GougeConfPrms &prms);
319 
320  virtual ~GougeConfig();
321 
322  virtual void generate();
323 
324  int getNumParticles() const;
325 
326  int getNumGrains() const;
327 
328  int getNumConnections() const;
329 
331 
333 
335 
336  bool isGougeParticle(const Particle &particle) const;
337 
339  const Particle &p1,
340  const Particle &p2
341  ) const;
342 
343  virtual void write(std::ostream &oStream) const;
344 
345  void writeToFile(const std::string &fileName) const;
346 
347  void tagGougeParticles(int tag);
348 
349  void tagRndBlockParticles(int tag);
350 
352  int minDrivingTag,
353  int maxDrivingTag,
354  double distanceFromBBoxEdge
355  );
356 
357  virtual void createConnectionSet();
358 
359  const ConnectionSet &getConnectionSet() const;
360 
362 
364 
365  template <typename TmplVisitor>
366  void visitParticles(TmplVisitor &visitor)
367  {
368  for (
369  typename GeneratorPtrVector::iterator it = m_genPtrVector.begin();
370  it != m_genPtrVector.end();
371  it++
372  )
373  {
374  ParticleIterator particleIt = (*it)->getParticleIterator();
375  while (particleIt.hasNext()) {
376  particleIt.next().visit(visitor);
377  }
378  }
379  }
380 
381  template <typename TmplVisitor>
382  void visitParticles(const TmplVisitor &visitor) const
383  {
384  for (
385  typename GeneratorPtrVector::const_iterator it = m_genPtrVector.begin();
386  it != m_genPtrVector.end();
387  it++
388  )
389  {
390  ParticleIterator particleIt = (*it)->getParticleIterator();
391  while (particleIt.hasNext()) {
392  particleIt.next().visit(visitor);
393  }
394  }
395  }
396 
397  template <typename TmplVisitor>
398  void visitConnections(TmplVisitor &visitor) const
399  {
400  const ConnectionSet &connectionSet = getConnectionSet();
401  for (
402  typename ConnectionSet::const_iterator it = connectionSet.begin();
403  it != connectionSet.end();
404  it++
405  )
406  {
407  it->visit(visitor);
408  }
409  }
410 
411  const GougeConfPrms &getPrms() const
412  {
413  return m_prms;
414  }
415 
416  class IdCompare
417  {
418  public:
419  bool operator()(const Particle *p1, const Particle *p2) const
420  {
421  return (p1->getID() < p2->getID());
422  }
423  };
424 
426  {
427  public:
428  inline ConnectionValidator(const GougeConfig &gougeBlock, double tolerance)
429  : m_pGougeConfig(&gougeBlock),
430  m_tolerance(tolerance)
431  {
432  }
433 
434  inline bool isValid(const Particle &p1, const Particle &p2) const
435  {
436  return
437  (
438  (p1.getID() < p2.getID())
439  &&
440  ((p1.getPos() - p2.getPos()).norm() < (m_tolerance + (p1.getRad() + p2.getRad())))
441  &&
443  &&
445  );
446  }
447 
448  private:
450  double m_tolerance;
451  };
452 
454  {
455  public:
456  GeoParticleWriter(std::ostream &oStream, int precision)
457  : m_pOStream(&oStream),
458  m_precision(precision)
459  {
460  }
461 
462  void visitParticle(const Particle &particle) const
463  {
464  (*m_pOStream)
465  << std::setprecision(m_precision)
466  << particle.getPos() << " "
467  << particle.getRad() << " "
468  << particle.getID() << " "
469  << particle.getTag() << "\n";
470  }
471 
472  private:
473  std::ostream *m_pOStream;
475  };
476 
478  {
479  public:
480  GeoConnectionWriter(std::ostream &oStream)
481  : m_pOStream(&oStream)
482  {
483  }
484 
485  void visitBasicInteraction(const BasicInteraction &connection)
486  {
487  (*m_pOStream)
488  << connection.first() << " "
489  << connection.second() << " "
490  << 0 << "\n";
491  }
492 
493  private:
494  std::ostream *m_pOStream;
496  };
497 
498  protected:
506 
509  virtual void createGougeConfigGenerators();
510 
511  private:
514  };
515  }
516 }
517 
518 #include "Geometry/GougeConfig.hpp"
519 
520 #endif