ESyS-Particle  2.3.2
GrainRandomBoxPacker.hpp
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 #include "Foundation/console.h"
16 #include "Geometry/SphereFitter.h"
17 
18 #include <algorithm>
19 #include <stdexcept>
20 #include <float.h>
21 
22 namespace esys
23 {
24  namespace lsm
25  {
26  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
28  ParticleGrainGenPtr particleGrainGenPtr,
29  ParticlePoolPtr particlePoolPtr,
30  NTablePtr nTablePtr,
31  const BoundingBox &bBox,
32  const BoolVector &periodicDimensions,
33  double tolerance,
34  double cubicPackRadius,
35  int maxInsertionFailures,
36  const PlaneVector &fitPlaneVector,
37  GrainPoolPtr grainPoolPtr
38  )
39  : Inherited(
40  particleGrainGenPtr,
41  particlePoolPtr,
42  nTablePtr,
43  bBox,
44  periodicDimensions,
45  tolerance,
46  cubicPackRadius,
47  maxInsertionFailures,
48  fitPlaneVector
49  ),
50  m_grainCollectionPtr(new GrainCollection(particlePoolPtr, grainPoolPtr))
51  {
52  }
53 
54  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
56  ParticleGrainGenPtr particleGrainGenPtr,
57  ParticlePoolPtr particlePoolPtr,
58  NTablePtr nTablePtr,
59  const BoundingBox &bBox,
60  const BoolVector &periodicDimensions,
61  double tolerance,
62  double cubicPackRadius,
63  int maxInsertionFailures
64  )
65  : Inherited(
66  particleGrainGenPtr,
67  particlePoolPtr,
68  nTablePtr,
69  bBox,
70  periodicDimensions,
71  tolerance,
72  cubicPackRadius,
73  maxInsertionFailures
74  ),
75  m_grainCollectionPtr(new GrainCollection(particlePoolPtr))
76  {
77  }
78 
79  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
81  {
82  }
83 
84  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
87  {
88  return *(m_grainCollectionPtr.get());
89  }
90 
91  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
94  {
95  return *(m_grainCollectionPtr.get());
96  }
97 
98  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
101  {
102  return getGrainCollection().getGrainIterator();
103  }
104 
105  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
108  {
109  return getGrainCollection().getGrainIterator();
110  }
111 
112  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
113  int
115  {
116  return getGrainCollection().getNumGrains();
117  }
118 
119  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
122  {
123  return Inherited::getParticleGenerator();
124  }
125 
126  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
129  {
130  return Inherited::getParticleGenerator();
131  }
132 
133  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
134  void
136  ParticleGrainGen &particleGrainGen
137  )
138  {
139  this->setParticleGenerator(particleGrainGen);
140  }
141 
142  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
143  void
145  ParticleGrainGenPtr particleGrainGenPtr
146  )
147  {
148  setParticleGenerator(particleGrainGenPtr);
149  }
150 
151  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
154  {
155  return m_grainCollectionPtr->getNumGrains();
156  }
157 
158  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
161  {
162  return m_grainCollectionPtr->createGrain();
163  }
164 
165  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
168  const Grain &grain
169  )
170  {
171  Grain &g = constructGrain();
172  g.setId(getNextGrainId());
173  typename Grain::ParticleConstIterator it = grain.getParticleIterator();
174  while (it.hasNext())
175  {
176  g.insertRef(this->createAndInsertParticle(it.next()));
177  }
178  return g;
179  }
180 
181  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
183  {
184  GridIterator pointIt = GridIterator(this->getBBox(), this->getCubicPackingRadius());
185  while (pointIt.hasNext()) {
186  const Particle candidate =
187  this->getCandidateParticle(pointIt.next(), this->getCubicPackingRadius());
188  if (this->particleFitsInBBoxWithNeighbours(candidate)) {
189  createAndInsertGrain(getParticleGrainGen().getGrain(candidate));
190  }
191  }
192  }
193 
194  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
196  {
199  *this,
200  this->getMaxInsertionFailures(),
201  this->getFitPlaneVector()
202  );
203  while (it.hasNext())
204  {
205  createAndInsertGrain(getParticleGrainGen().getGrain(it.next()));
206  }
207  it.logInfo();
208  }
209 
210  template <typename TGrainGen, typename TGrainCol, template <typename TTGrainGen> class TRndPackWrap>
212  {
213  generateCubicPackingGrains();
214  generateRandomFillGrains();
215  }
216  }
217 }