ESyS-Particle  2.3.2
ParticleCollection.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 
14 #include <stdexcept>
15 #include <fstream>
16 #include <sstream>
17 #include <iomanip>
18 
19 #include <stdexcept>
20 #include <boost/limits.hpp>
21 
22 namespace esys
23 {
24  namespace lsm
25  {
26  template <typename TmplParticle>
28  : m_particlePoolPtr(),
29  m_particleVector()
30  {
32  }
33 
34  template <typename TmplParticle>
36  ParticlePoolPtr particlePoolPtr
37  )
38  : m_particlePoolPtr(particlePoolPtr),
39  m_particleVector()
40  {
41  }
42 
43  template <typename TmplParticle>
45  : m_particlePoolPtr(p.m_particlePoolPtr),
46  m_particleVector(p.m_particleVector)
47  {
48  }
49 
50  template <typename TmplParticle>
53  {
54  m_particlePoolPtr = p.m_particlePoolPtr;
55  m_particleVector = p.m_particleVector;
56  }
57 
58  template <typename TmplParticle>
59  void
61  {
62  m_particleVector.push_back(&p);
63  }
64 
65  template <typename TmplParticle>
66  void
68  {
69  if (m_particlePoolPtr->is_from(&p))
70  {
71  noCheckInsertRef(p);
72  }
73  else
74  {
75  throw
76  std::runtime_error(
77  "ParticleCollection<TmplParticle>::insertRef: Tried to insert"
78  " reference to non-created particle."
79  );
80  }
81  }
82 
83  template <typename TmplParticle>
86  {
87  Particle *newP = m_particlePoolPtr->construct(p);
88  noCheckInsertRef(*newP);
89  return *newP;
90  }
91 
92  template <typename TmplParticle>
94  {
95  }
96 
97  template <typename TmplParticle>
99  {
100  return m_particleVector.size();
101  }
102 
103  template <typename TmplParticle>
105  {
106  ParticleIterator it = getParticleIterator();
107  while (it.hasNext())
108  {
109  it.next().translateBy(vec);
110  }
111  }
112 
113  template <typename TmplParticle>
115  const Vec3 &rotation,
116  const Vec3 &posn
117  )
118  {
119  ParticleIterator it = getParticleIterator();
120  while (it.hasNext())
121  {
122  it.next().rotate(rotation, posn);
123  }
124  }
125 
126  template <typename TmplParticle>
128  typename Particle::Id idIncr
129  )
130  {
131  ParticleIterator it = getParticleIterator();
132  while (it.hasNext())
133  {
134  Particle &p = it.next();
135  p.setId(p.getId() + idIncr);
136  }
137  }
138 
139  template <typename TmplParticle>
141  {
142  Vec3 minPt = Vec3(std::numeric_limits<double>::max());
143  Vec3 maxPt = -minPt;
144  ParticleConstIterator it = getParticleIterator();
145  while (it.hasNext())
146  {
147  const Particle &next = it.next();
148  minPt = cmin(minPt, next.getPos() - next.getRad());
149  maxPt = cmax(maxPt, next.getPos() + next.getRad());
150  }
151  return BoundingBox(minPt, maxPt);
152  }
153  }
154 }