ESyS-Particle  2.3.2
GrainCollection.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 <boost/limits.hpp>
20 
21 namespace esys
22 {
23  namespace lsm
24  {
25  template <typename TmplGrain>
27  : m_particlePoolPtr(new ParticlePool(4096)),
28  m_grainPoolPtr(new GrainPool(4096)),
29  m_grainVector()
30  {
31  }
32 
33  template <typename TmplGrain>
35  ParticlePoolPtr particlePoolPtr
36  )
37  : m_particlePoolPtr(particlePoolPtr),
38  m_grainPoolPtr(new GrainPool(4096)),
39  m_grainVector()
40  {
41  }
42 
43  template <typename TmplGrain>
45  ParticlePoolPtr particlePoolPtr,
46  GrainPoolPtr grainPoolPtr
47  )
48  : m_particlePoolPtr(particlePoolPtr),
49  m_grainPoolPtr(grainPoolPtr),
50  m_grainVector()
51  {
52  }
53 
54  template <typename TmplGrain>
57  {
58  return m_particlePoolPtr;
59  }
60 
61  template <typename TmplGrain>
64  {
65  return m_grainPoolPtr;
66  }
67 
68  template <typename TmplGrain>
70  {
71  }
72 
73  template <typename TmplGrain>
75  {
76  return m_grainVector.size();
77  }
78 
79  template <typename TmplGrain>
81  {
82  int i = 0;
83  for (
84  GrainConstIterator it = getGrainIterator();
85  it.hasNext();
86  i += it.next().getNumParticles()
87  )
88  {
89  }
90  return i;
91  }
92 
93  template <typename TmplGrain>
94  void
96  {
97  if (m_grainPoolPtr->is_from(&g))
98  {
99  m_grainVector.push_back(&g);
100  }
101  else
102  {
103  throw
104  std::runtime_error(
105  "GrainCollection<TmplGrain>::insertRef: Tried to insert"
106  " reference to non-created grain."
107  );
108  }
109  }
110 
111  template <typename TmplGrain>
114  {
115  Grain *pGrain = m_grainPoolPtr->construct(getParticlePoolPtr());
116  insertRef(*pGrain);
117  return *pGrain;
118  }
119 
120  template <typename TmplGrain>
123  {
124  Grain *pGrain = m_grainPoolPtr->construct(id, getParticlePoolPtr());
125  insertRef(*pGrain);
126  return *pGrain;
127  }
128 
129  template <typename TmplGrain>
132  {
133  Grain *pGrain = m_grainPoolPtr->construct(g);
134  insertRef(*pGrain);
135  return *pGrain;
136  }
137 
138  template <typename TmplGrain>
141  {
142  return GrainIterator(VectorIterator(m_grainVector));
143  }
144 
145  template <typename TmplGrain>
148  {
149  return GrainConstIterator(VectorConstIterator(m_grainVector));
150  }
151 
152  }
153 }