File: RandomBoxPacker.h

package info (click to toggle)
esys-particle 2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,284 kB
  • sloc: cpp: 77,304; python: 5,647; makefile: 1,176; sh: 10
file content (190 lines) | stat: -rw-r--r-- 6,279 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2003-2011 by The University of Queensland //
// Earth Systems Science Computational Centre (ESSCC)      //
// http://www.uq.edu.au/esscc                              //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.opensource.org/licenses/osl-3.0.php          //
//                                                         //
/////////////////////////////////////////////////////////////


#ifndef ESYS_LSMRANDOMBOXPACKER_H
#define ESYS_LSMRANDOMBOXPACKER_H

#include "Foundation/console.h"
#include "Foundation/Rng.h"
#include "Geometry/CubicBoxPacker.h"
#include "Geometry/SphereFitter.h"
#include "Geometry/Plane.h"

#include <vector>
#include <boost/shared_ptr.hpp>

namespace esys
{
  namespace lsm
  {
    template <typename TmplFitterTraits>
    class FittedParticleIterator
    {
    public:
      typedef TmplFitterTraits                   FitterTraits;
      typedef typename FitterTraits::Plane       Plane;
      typedef typename FitterTraits::PlaneVector PlaneVector;
      typedef typename FitterTraits::Packer      Packer;
      typedef typename Packer::Particle          Particle;
      typedef typename Packer::ParticleVector    ParticleVector;
      
      class FitTraits
      {
      public:
        typedef Packer                           Validator;
        typedef typename Packer::Particle        Particle;
        typedef typename Packer::ParticleVector  ParticleVector;
        typedef typename FitterTraits::Plane     Plane;
      };

      typedef SphereFitter<FitTraits>            Fitter;
      typedef boost::shared_ptr<Fitter>          FitterPtr;
      typedef std::vector<FitterPtr>             FitterPtrVector;
      typedef MoveToSurfaceFitter<FitTraits>     Move2SurfaceFitter;
      typedef ThreeDSphereFitter<FitTraits>      ThreeDFitter;
      typedef TwoDSphereFitter<FitTraits>        TwoDFitter;
      typedef TwoDPlaneSphereFitter<FitTraits>   TwoDPlaneFitter;
      typedef ThreeDPlaneSphereFitter<FitTraits> ThreeDPlaneFitter;

      FittedParticleIterator(
        Packer            &packer,
        int               maxInsertionFailures,
        const PlaneVector &fitPlaneVector
      );

      void initialiseFitterPtrVector();

      int getMaxInsertionFailures() const;

      const FitterPtrVector &getFitterPtrVector() const;

      FitterPtrVector &getFitterPtrVector();

      const PlaneVector &getFitPlaneVector() const;

      const Packer &getPacker() const;

      Packer &getPacker();

      Plane getClosestFitPlane(const Particle &particle) const;

      double getRandom(double min, double max) const;

      Vec3 getRandomPoint() const;

      Particle getCandidateParticle(const Vec3 &point);

      ParticleVector getClosestNeighbours(const Particle& particle, int numClosest);

      Particle &generateNext();

      bool hasNext();

      Particle next();

      void logInfo();

    private:
      Packer          *m_pPacker;
      PlaneVector     m_fitPlaneVector;
      int             m_maxInsertionFailures;      
      int             m_lastFailCount;
      int             m_successCount;
      Particle        m_next;
      FitterPtrVector m_fitterPtrVector;
    };

    /**
     *
     */
    template <typename TmplParticleGenerator,template <typename TmplPartGen> class TmplCubicBoxPackerWrap>
    class RandomBoxPacker : public TmplCubicBoxPackerWrap<TmplParticleGenerator>::CubicBoxPackerBase
    {
    public:
      typedef
        typename TmplCubicBoxPackerWrap<TmplParticleGenerator>::CubicBoxPackerBase
        Inherited;
      typedef typename Inherited::ParticleGenerator     ParticleGenerator;
      typedef typename Inherited::ParticleGeneratorPtr  ParticleGeneratorPtr;
      typedef typename Inherited::Particle              Particle;
      typedef typename Inherited::NTable                NTable;
      typedef typename Inherited::NTablePtr             NTablePtr;
      typedef typename NTable::ParticleVector           ParticleVector;
      typedef typename Inherited::ParticlePool          ParticlePool;
      typedef typename Inherited::ParticlePoolPtr       ParticlePoolPtr;
      typedef std::vector<Plane>                        PlaneVector;

      class StufferTraits
      {
      public:
        typedef RandomBoxPacker              Packer;
        typedef esys::lsm::Plane             Plane;
        typedef typename Packer::PlaneVector PlaneVector;
      };
      typedef FittedParticleIterator<StufferTraits> StuffedParticleIterator;

      RandomBoxPacker(
        ParticleGeneratorPtr particleGeneratorPtr,
        ParticlePoolPtr      particlePoolPtr,
        NTablePtr            nTablePtr,
        const BoundingBox    &bBox,
        const BoolVector     &periodicDimensions,
        double               tolerance,
        double               cubicPackRadius,
        int                  maxInsertionFailures
      );

      RandomBoxPacker(
        ParticleGeneratorPtr particleGeneratorPtr,
        ParticlePoolPtr      particlePoolPtr,
        NTablePtr            nTablePtr,
        const BoundingBox    &bBox,
        const BoolVector     &periodicDimensions,
        double               tolerance,
        double               cubicPackRadius,
        int                  maxInsertionFailures,
        const PlaneVector    &fitPlaneVector
      );

      virtual ~RandomBoxPacker();

      PlaneVector getDefaultFitPlaneVector() const;

      bool particleIsValid(const Particle &particle) const;

      virtual void generate();

      double getRandom(double min, double max) const;

      Vec3 getRandomPoint() const;

      ParticleVector getClosestNeighbours(const Particle& particle, int numClosest);

      int getMaxInsertionFailures() const;

      void generateRandomFill();

      const PlaneVector &getFitPlaneVector() const;

      Plane getClosestFitPlane(const Particle &particle) const;

    private:
      PlaneVector  m_fitPlaneVector;
      int          m_maxInsertionFailures;
    };
  };
};

#include "Geometry/RandomBoxPacker.hpp"

#endif