ESyS-Particle  4.0.1
CubicBoxPacker.hpp
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 namespace esys
15 {
16  namespace lsm
17  {
18  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
19  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::CubicBoxPacker(
20  ParticleGeneratorPtr particleGeneratorPtr,
21  ParticlePoolPtr particlePoolPtr,
22  NTablePtr nTablePtr,
23  const BoundingBox &bBox,
24  const BoolVector &periodicDimensions,
25  double tolerance,
26  double cubicPackRadius
27  ) : Inherited(
28  particlePoolPtr,
29  nTablePtr,
30  bBox,
31  periodicDimensions,
32  tolerance
33  ),
34  m_cubicPackRadius(cubicPackRadius),
35  m_particleGeneratorPtr(particleGeneratorPtr),
36  m_pParticleGenerator(particleGeneratorPtr.get())
37  {
38  }
39 
40  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
41  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::~CubicBoxPacker()
42  {
43  }
44 
45  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
46  const typename CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::ParticleGenerator &
47  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::getParticleGenerator() const
48  {
49  return *m_pParticleGenerator;
50  }
51 
52  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
53  typename CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::ParticleGenerator &
54  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::getParticleGenerator()
55  {
56  return *m_pParticleGenerator;
57  }
58 
59  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
60  void
61  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::setParticleGenerator(
62  ParticleGenerator &particleGenerator
63  )
64  {
65  m_pParticleGenerator = &particleGenerator;
66  m_particleGeneratorPtr = ParticleGeneratorPtr();
67  }
68 
69  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
70  void
71  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::setParticleGenerator(
72  ParticleGeneratorPtr particleGeneratorPtr
73  )
74  {
75  m_particleGeneratorPtr = particleGeneratorPtr;
76  m_pParticleGenerator = m_particleGeneratorPtr.get();
77  }
78 
79  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
80  double
81  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::getCubicPackingRadius() const
82  {
83  return m_cubicPackRadius;
84  }
85 
86  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
87  typename CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::Particle
88  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::getCandidateParticle(
89  const Vec3 &point,
90  double radius
91  )
92  {
93  return getParticleGenerator().getParticle(point, radius);
94  }
95 
96  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
97  typename CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::Particle
98  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::getCandidateParticle(
99  const Vec3 &point
100  )
101  {
102  return getParticleGenerator().getParticle(point);
103  }
104 
105  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
106  void
107  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::generateCubicPacking()
108  {
109  GridIterator pointIt = GridIterator(this->getBBox(), getCubicPackingRadius());
110  while (pointIt.hasNext()) {
111  const Particle candidate =
112  getCandidateParticle(pointIt.next(), getCubicPackingRadius());
113  if (this->particleFitsInBBoxWithNeighbours(candidate)) {
114  this->createAndInsertParticle(candidate);
115  }
116  }
117  }
118 
119  template <typename TmplParticleGenerator, typename TmplBoxPackerBase>
120  void
121  CubicBoxPacker<TmplParticleGenerator,TmplBoxPackerBase>::generate()
122  {
123  generateCubicPacking();
124  }
125  };
126 };