ESyS-Particle  4.0.1
GrainCollection.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 #include "Geometry/GrainCollection.h"
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>
26  GrainCollection<TmplGrain>::GrainCollection()
27  : m_particlePoolPtr(new ParticlePool(4096)),
28  m_grainPoolPtr(new GrainPool(4096)),
29  m_grainVector()
30  {
31  }
32 
33  template <typename TmplGrain>
34  GrainCollection<TmplGrain>::GrainCollection(
35  ParticlePoolPtr particlePoolPtr
36  )
37  : m_particlePoolPtr(particlePoolPtr),
38  m_grainPoolPtr(new GrainPool(4096)),
39  m_grainVector()
40  {
41  }
42 
43  template <typename TmplGrain>
44  GrainCollection<TmplGrain>::GrainCollection(
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>
55  typename GrainCollection<TmplGrain>::ParticlePoolPtr
56  GrainCollection<TmplGrain>::getParticlePoolPtr()
57  {
58  return m_particlePoolPtr;
59  }
60 
61  template <typename TmplGrain>
62  typename GrainCollection<TmplGrain>::GrainPoolPtr
63  GrainCollection<TmplGrain>::getGrainPoolPtr()
64  {
65  return m_grainPoolPtr;
66  }
67 
68  template <typename TmplGrain>
69  GrainCollection<TmplGrain>::~GrainCollection()
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>
112  typename GrainCollection<TmplGrain>::Grain &
114  {
115  Grain *pGrain = m_grainPoolPtr->construct(getParticlePoolPtr());
116  insertRef(*pGrain);
117  return *pGrain;
118  }
119 
120  template <typename TmplGrain>
121  typename GrainCollection<TmplGrain>::Grain &
123  {
124  Grain *pGrain = m_grainPoolPtr->construct(id, getParticlePoolPtr());
125  insertRef(*pGrain);
126  return *pGrain;
127  }
128 
129  template <typename TmplGrain>
130  typename GrainCollection<TmplGrain>::Grain &
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>
146  typename GrainCollection<TmplGrain>::GrainConstIterator
147  GrainCollection<TmplGrain>::getGrainIterator() const
148  {
149  return GrainConstIterator(VectorConstIterator(m_grainVector));
150  }
151 
152  }
153 }