File: ClosePackIterator.hpp

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 (195 lines) | stat: -rw-r--r-- 4,574 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/////////////////////////////////////////////////////////////
//                                                         //
// 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_LSMCLOSEPACKITERATOR_HPP
#define ESYS_LSMCLOSEPACKITERATOR_HPP

namespace esys
{
  namespace lsm
  {
    template <int NI, int NJ, int NK>
    TmplMatrix<NI,NJ,NK>::TmplMatrix()
    {
      for (int i = 0; i < NI; i++)
      {
        for (int j = 0; j < NJ; j++)
        {
          for (int k = 0; k < NJ; k++)
          {
            m_matrix[i][j][k] = 0.0;
          }
        }
      }
    }

    template <int NI, int NJ, int NK>
    TmplMatrix<NI,NJ,NK>::TmplMatrix(const TmplMatrix &m)
    {
      for (int i = 0; i < NI; i++)
      {
        for (int j = 0; j < NJ; j++)
        {
          for (int k = 0; k < NJ; k++)
          {
            m_matrix[i][j][k] = m(i,j,k);
          }
        }
      }
    }

    template <int NI, int NJ, int NK>
    TmplMatrix<NI,NJ,NK> &
    TmplMatrix<NI,NJ,NK>::TmplMatrix::operator=(const TmplMatrix &m)
    {
      for (int i = 0; i < NI; i++)
      {
        for (int j = 0; j < NJ; j++)
        {
          for (int k = 0; k < NJ; k++)
          {
            m_matrix[i][j][k] = m(i,j,k);
          }
        }
      }
      return *this;
    }

    template <int NI, int NJ, int NK>
    const double &TmplMatrix<NI,NJ,NK>::operator()(int i, int j, int k) const
    {
      return m_matrix[i][j][k];
    }

    template <int NI, int NJ, int NK>
    double &TmplMatrix<NI,NJ,NK>::operator()(int i, int j, int k)
    {
      return m_matrix[i][j][k];
    }

    template <int NI, int NJ, int NK>
    int TmplMatrix<NI,NJ,NK>::getNumI() const
    {
      return NI;
    }

    template <int NI, int NJ, int NK>
    int TmplMatrix<NI,NJ,NK>::getNumJ() const
    {
      return NJ;
    }

    template <int NI, int NJ, int NK>
    int TmplMatrix<NI,NJ,NK>::getNumK() const
    {
      return NK;
    }

    ClosePackIterator::ClosePackIterator()
      : m_radius(),
        m_minPt(),
        m_offsetMatrix(),
        m_dimRepeat(),
        m_dimCount(),
        m_dimIdx(),
        m_dim()
    {
    }

    ClosePackIterator::ClosePackIterator(
      int numI,
      int numJ,
      int numK,
      double sphereRadius,
      ClosePackOrientation orientation
    )
      : m_radius(sphereRadius),
        m_minPt(),
        m_offsetMatrix(),
        m_dimRepeat(),
        m_dimCount(numI, numJ, numK),
        m_dimIdx(),
        m_dim(s_orientationDimMap[orientation])
    {
      for (int i = 0; i < 3; i++)
      {
        if (m_dimCount[i] <= 0)
        {
          m_dimCount[i] = 1;
        }
      }
    }

    void ClosePackIterator::setDimRepeat(const Vec3L &dimRepeat)
    {
      m_dimRepeat = dimRepeat;
    }

    void ClosePackIterator::setOffsetMatrix(const OffsetMatrix &offsetMatrix)
    {
      m_offsetMatrix = offsetMatrix;
    }

    double ClosePackIterator::getRadius() const
    {
      return m_radius;
    }
    
    bool ClosePackIterator::hasNext() const
    {
       return (m_dimIdx[2] < m_dimCount[2]);
    }

    const Vec3 &ClosePackIterator::getMinPt() const
    {
      return m_minPt;
    }

    double ClosePackIterator::getOffset(int i) const
    {
      return
        m_offsetMatrix(
          i,
          (m_dimIdx[(i+1) % 3]) % m_dimRepeat[i],
          (m_dimIdx[(i+2) % 3]) % m_dimRepeat[i]
        );
    }

    void ClosePackIterator::incrementDimIndex()
    {
      (m_dimIdx[0])++;
      if (m_dimIdx[0] >= m_dimCount[0])
      {
        m_dimIdx[0] = 0;
        (m_dimIdx[1])++;
        if (m_dimIdx[1] >= m_dimCount[1])
        {
          m_dimIdx[1] = 0;
          (m_dimIdx[2])++;
        }
      }
    }
    
    Vec3 ClosePackIterator::next()
    {
      Vec3 centre;
      centre[m_dim[0]] = getOffset(0) + m_dimIdx[0]*(m_radius*2.0);
      centre[m_dim[1]] = getOffset(1) + m_dimIdx[1]*(m_radius*SQRT_3);
      centre[m_dim[2]] = getOffset(2) + m_dimIdx[2]*(m_radius*SQRT_8_OVER_3);
      incrementDimIndex();
      return (getMinPt() + centre);
    }
  }
}

#endif