ESyS-Particle  4.0.1
RandomBoxPacker.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 
14 #ifndef ESYS_LSMRANDOMBOXPACKER_H
15 #define ESYS_LSMRANDOMBOXPACKER_H
16 
17 #include "Foundation/console.h"
18 #include "Foundation/Rng.h"
19 #include "Geometry/CubicBoxPacker.h"
20 #include "Geometry/SphereFitter.h"
21 #include "Geometry/Plane.h"
22 
23 #include <vector>
24 #include <boost/shared_ptr.hpp>
25 
26 namespace esys
27 {
28  namespace lsm
29  {
30  template <typename TmplFitterTraits>
32  {
33  public:
34  typedef TmplFitterTraits FitterTraits;
35  typedef typename FitterTraits::Plane Plane;
36  typedef typename FitterTraits::PlaneVector PlaneVector;
37  typedef typename FitterTraits::Packer Packer;
38  typedef typename Packer::Particle Particle;
39  typedef typename Packer::ParticleVector ParticleVector;
40 
41  class FitTraits
42  {
43  public:
44  typedef Packer Validator;
45  typedef typename Packer::Particle Particle;
46  typedef typename Packer::ParticleVector ParticleVector;
47  typedef typename FitterTraits::Plane Plane;
48  };
49 
51  typedef boost::shared_ptr<Fitter> FitterPtr;
52  typedef std::vector<FitterPtr> FitterPtrVector;
58 
60  Packer &packer,
61  int maxInsertionFailures,
62  const PlaneVector &fitPlaneVector
63  );
64 
65  void initialiseFitterPtrVector();
66 
67  int getMaxInsertionFailures() const;
68 
69  const FitterPtrVector &getFitterPtrVector() const;
70 
71  FitterPtrVector &getFitterPtrVector();
72 
73  const PlaneVector &getFitPlaneVector() const;
74 
75  const Packer &getPacker() const;
76 
77  Packer &getPacker();
78 
79  Plane getClosestFitPlane(const Particle &particle) const;
80 
81  double getRandom(double min, double max) const;
82 
83  Vec3 getRandomPoint() const;
84 
85  Particle getCandidateParticle(const Vec3 &point);
86 
87  ParticleVector getClosestNeighbours(const Particle& particle, int numClosest);
88 
89  Particle &generateNext();
90 
91  bool hasNext();
92 
93  Particle next();
94 
95  void logInfo();
96 
97  private:
98  Packer *m_pPacker;
99  PlaneVector m_fitPlaneVector;
100  int m_maxInsertionFailures;
101  int m_lastFailCount;
102  int m_successCount;
103  Particle m_next;
104  FitterPtrVector m_fitterPtrVector;
105  };
106 
110  template <typename TmplParticleGenerator,template <typename TmplPartGen> class TmplCubicBoxPackerWrap>
111  class RandomBoxPacker : public TmplCubicBoxPackerWrap<TmplParticleGenerator>::CubicBoxPackerBase
112  {
113  public:
114  typedef
115  typename TmplCubicBoxPackerWrap<TmplParticleGenerator>::CubicBoxPackerBase
116  Inherited;
117  typedef typename Inherited::ParticleGenerator ParticleGenerator;
118  typedef typename Inherited::ParticleGeneratorPtr ParticleGeneratorPtr;
119  typedef typename Inherited::Particle Particle;
120  typedef typename Inherited::NTable NTable;
121  typedef typename Inherited::NTablePtr NTablePtr;
122  typedef typename NTable::ParticleVector ParticleVector;
123  typedef typename Inherited::ParticlePool ParticlePool;
124  typedef typename Inherited::ParticlePoolPtr ParticlePoolPtr;
125  typedef std::vector<Plane> PlaneVector;
126 
128  {
129  public:
130  typedef RandomBoxPacker Packer;
131  typedef esys::lsm::Plane Plane;
132  typedef typename Packer::PlaneVector PlaneVector;
133  };
135 
137  ParticleGeneratorPtr particleGeneratorPtr,
138  ParticlePoolPtr particlePoolPtr,
139  NTablePtr nTablePtr,
140  const BoundingBox &bBox,
141  const BoolVector &periodicDimensions,
142  double tolerance,
143  double cubicPackRadius,
144  int maxInsertionFailures
145  );
146 
148  ParticleGeneratorPtr particleGeneratorPtr,
149  ParticlePoolPtr particlePoolPtr,
150  NTablePtr nTablePtr,
151  const BoundingBox &bBox,
152  const BoolVector &periodicDimensions,
153  double tolerance,
154  double cubicPackRadius,
155  int maxInsertionFailures,
156  const PlaneVector &fitPlaneVector
157  );
158 
159  virtual ~RandomBoxPacker();
160 
161  PlaneVector getDefaultFitPlaneVector() const;
162 
163  bool particleIsValid(const Particle &particle) const;
164 
165  virtual void generate();
166 
167  double getRandom(double min, double max) const;
168 
169  Vec3 getRandomPoint() const;
170 
171  ParticleVector getClosestNeighbours(const Particle& particle, int numClosest);
172 
173  int getMaxInsertionFailures() const;
174 
175  void generateRandomFill();
176 
177  const PlaneVector &getFitPlaneVector() const;
178 
179  Plane getClosestFitPlane(const Particle &particle) const;
180 
181  private:
182  PlaneVector m_fitPlaneVector;
183  int m_maxInsertionFailures;
184  };
185  };
186 };
187 
188 #include "Geometry/RandomBoxPacker.hpp"
189 
190 #endif