File: GrainCollection.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 (162 lines) | stat: -rw-r--r-- 4,577 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
/////////////////////////////////////////////////////////////
//                                                         //
// 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_LSMGRAINCOLLECTION_H
#define ESYS_LSMGRAINCOLLECTION_H

#include "Foundation/StlIterator.h"
#include <boost/shared_ptr.hpp>
#include <boost/pool/object_pool.hpp>

#include <vector>

namespace esys
{
  namespace lsm
  {
    /**
     *
     */
    template <typename TmplGrain>
    class GrainCollection
    {
    public:
      typedef TmplGrain                                    Grain;
      typedef typename Grain::Particle                     Particle;
      typedef typename Grain::ParticleCollection           ParticleCollection;
      typedef typename ParticleCollection::ParticlePool    ParticlePool;
      typedef typename ParticleCollection::ParticlePoolPtr ParticlePoolPtr;
      typedef typename ParticleCollection::ParticleIterator      ParticleIterator;
      typedef typename ParticleCollection::ParticleConstIterator ParticleConstIterator;
      typedef boost::object_pool<Grain>                    GrainPool;
      typedef boost::shared_ptr<GrainPool>                 GrainPoolPtr;
      typedef std::vector<Grain *>                         GrainVector;

    protected:
      typedef ForwardIterator<GrainVector>                 VectorIterator;
      typedef ForwardConstIterator<GrainVector>            VectorConstIterator;

    public:

      class GrainIterator : public VectorIterator
      {
      public:
        typedef Grain& value_type;
        GrainIterator(const VectorIterator &it)
         : VectorIterator(it)
        {
        }

        value_type next()
        {
          return *(VectorIterator::next());
        }

        value_type current() const
        {
          return *(VectorIterator::current());
        }
      };

      class GrainConstIterator : public VectorConstIterator
      {
      public:
        typedef const Grain& value_type;
        GrainConstIterator (const VectorConstIterator &it)
         : VectorConstIterator(it)
        {
        }

        GrainConstIterator (const VectorIterator &it)
         : VectorConstIterator(it)
        {
        }

        value_type next()
        {
          return *(VectorConstIterator::next());
        }

        value_type current() const
        {
          return *(VectorConstIterator::current());
        }
      };

      GrainCollection();

      GrainCollection(ParticlePoolPtr particlePoolPtr);

      GrainCollection(ParticlePoolPtr particlePoolPtr, GrainPoolPtr grainPoolPtr);

      virtual ~GrainCollection();

      /**
       * Returns the number of grains in this collection.
       */
      int getNumGrains() const;

      /**
       * Returns the number of particles contained in all
       * grains of this collection.
       */
      int getNumParticles() const;

      /**
       * Stores reference to specified grain.
       *
       * @param g Inserts reference to grain g in this collection.
       * @throws std::runtime_error if g was not created by this
       *   collection's GrainPool.
       */
      void insertRef(Grain &g);
      
      /**
       * Creates an empty grain.
       * @return reference to new grain.
       */
      Grain &createGrain();

      /**
       * Creates an empty (no particles) grain.
       * @param id Create a grain with this id.
       * @return reference to new grain.
       */
      Grain &createGrain(typename Grain::Id id);

      /**
       * Returns a copy-constructed grain.
       * @param g Copy created from this argument.
       * @return reference to new grain.
       */
      Grain &createGrain(const Grain &g);

      GrainIterator getGrainIterator();

      GrainConstIterator getGrainIterator() const;

    protected:
      ParticlePoolPtr getParticlePoolPtr();

      GrainPoolPtr getGrainPoolPtr();

    private:
      ParticlePoolPtr m_particlePoolPtr;
      GrainPoolPtr    m_grainPoolPtr;
      GrainVector     m_grainVector;
    };
  };
};

#include "Geometry/GrainCollection.hpp"

#endif