~esys-p-dev/esys-particle/2.1

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
/////////////////////////////////////////////////////////////
//                                                         //
// 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          //
//                                                         //
/////////////////////////////////////////////////////////////


namespace esys
{
  namespace lsm
  {
    template <typename TmplParticleCollection>
    Packer<TmplParticleCollection>::Packer(NTablePtr nTablePtr)
      : m_nTablePtr(nTablePtr),
        m_particlePoolPtr(new ParticlePool),
        m_particleCollectionPtr(
          new ParticleCollection(m_particlePoolPtr)
        ),
        m_idSet()
    {
    }

    template <typename TmplParticleCollection>
    Packer<TmplParticleCollection>::Packer(
      ParticlePoolPtr particlePoolPtr,
      NTablePtr       nTablePtr
    )
      : m_nTablePtr(nTablePtr),
        m_particlePoolPtr(particlePoolPtr),
        m_particleCollectionPtr(
          new ParticleCollection(m_particlePoolPtr)
        ),
        m_idSet()
    {
    }

    template <typename TmplParticleCollection>
    Packer<TmplParticleCollection>::~Packer()
    {
    }

    template <typename TmplParticleCollection>
    void Packer<TmplParticleCollection>::setNTablePtr(NTablePtr nTablePtr)
    {
      m_nTablePtr = nTablePtr;
    }

    template <typename TmplParticleCollection>
    typename Packer<TmplParticleCollection>::NTable &Packer<TmplParticleCollection>::getNTable()
    {
      return *(m_nTablePtr);
    }

    template <typename TmplParticleCollection>
    const typename Packer<TmplParticleCollection>::NTable &
    Packer<TmplParticleCollection>::getNTable() const
    {
      return *m_nTablePtr;
    }

    template <typename TmplParticleCollection>
    typename Packer<TmplParticleCollection>::ParticlePool &
    Packer<TmplParticleCollection>::getParticlePool()
    {
      return *m_particlePoolPtr;
    }

    template <typename TmplParticleCollection>
    typename Packer<TmplParticleCollection>::ParticlePoolPtr
    Packer<TmplParticleCollection>::getParticlePoolPtr()
    {
      return m_particlePoolPtr;
    }

    template <typename TmplParticleCollection>
    const typename Packer<TmplParticleCollection>::ParticlePool &
    Packer<TmplParticleCollection>::getParticlePool() const
    {
      return *m_particlePoolPtr;
    }

    template <typename TmplParticleCollection>
    typename Packer<TmplParticleCollection>::ParticleCollection &
    Packer<TmplParticleCollection>::getParticleCollection()
    {
      return *m_particleCollectionPtr;
    }

    template <typename TmplParticleCollection>
    const typename Packer<TmplParticleCollection>::ParticleCollection &
    Packer<TmplParticleCollection>::getParticleCollection() const
    {
      return *m_particleCollectionPtr;
    }

    template <typename TmplParticleCollection>
    typename Packer<TmplParticleCollection>::Particle &
    Packer<TmplParticleCollection>::constructParticle(const Particle &particle)
    {
      return getParticleCollection().createParticle(particle);
    }

    template <typename TmplParticleCollection>
    typename Packer<TmplParticleCollection>::ParticleIterator
    Packer<TmplParticleCollection>::getParticleIterator()
    {
      return getParticleCollection().getParticleIterator();
    }

    template <typename TmplParticleCollection>
    typename Packer<TmplParticleCollection>::ParticleConstIterator
    Packer<TmplParticleCollection>::getParticleIterator() const
    {
      return getParticleCollection().getParticleIterator();
    }

    template <typename TmplParticleCollection>
    int
    Packer<TmplParticleCollection>::getNumParticles() const
    {
      return getParticleCollection().getNumParticles();
    }

    template <typename TmplParticleCollection>
    int Packer<TmplParticleCollection>::getNextParticleId()
    {
      return static_cast<int>(getNTable().getNumParticles());
    }


    template <typename TmplParticleCollection>
    typename Packer<TmplParticleCollection>::Particle &
    Packer<TmplParticleCollection>::createAndInsertParticle(
      const Particle &particle
    )
    {
      Particle *pParticle = &(constructParticle(particle));
      pParticle->setId(getNextParticleId());
      m_idSet.insert(pParticle->getId());
      getNTable().insert(pParticle);
      return *pParticle;
    }

    template <typename TmplParticleCollection>
    bool Packer<TmplParticleCollection>::contains(const Particle &particle) const
    {
      return (m_idSet.find(particle.getID()) != m_idSet.end());
    }
  }
}