OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Mesh.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Chris Rogers
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * 1. Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * 2. Redistributions in binary form must reproduce the above copyright notice,
9  * this list of conditions and the following disclaimer in the documentation
10  * and/or other materials provided with the distribution.
11  * 3. Neither the name of STFC nor the names of its contributors may be used to
12  * endorse or promote products derived from this software without specific
13  * prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <ostream>
29 #include <vector>
30 
31 #ifndef _CLASSIC_FIELDS_MESH_H_
32 #define _CLASSIC_FIELDS_MESH_H_
33 
34 namespace interpolation {
35 
36 class VectorMap;
37 
49 class Mesh {
50  public:
52  class Iterator;
53 
55  inline Mesh();
57  virtual Mesh::Iterator begin() const = 0;
58 
60  virtual Mesh::Iterator end() const = 0;
61 
63  virtual Mesh* clone() = 0;
64 
69  virtual Mesh* dual() const = 0;
70 
72  inline virtual ~Mesh();
73 
75  virtual void getPosition
76  (const Mesh::Iterator& it, double * position) const = 0;
77 
79  virtual int getPositionDimension() const = 0;
80 
82  virtual int toInteger(const Mesh::Iterator& lhs) const = 0;
83 
85  virtual Mesh::Iterator getNearest(const double* position) const = 0;
86 
87  protected:
89  virtual Mesh::Iterator& addEquals
90  (Mesh::Iterator& lhs, int difference) const = 0;
91 
93  virtual Mesh::Iterator& subEquals
94  (Mesh::Iterator& lhs, int difference) const = 0;
95 
97  virtual Mesh::Iterator& addEquals
98  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs) const = 0;
99 
101  virtual Mesh::Iterator& subEquals
102  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs) const = 0;
103 
105  virtual Mesh::Iterator& addOne(Mesh::Iterator& lhs) const = 0;
106 
108  virtual Mesh::Iterator& subOne(Mesh::Iterator& lhs) const = 0;
109 
111  virtual bool isGreater
112  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs) const = 0;
113 
114  public:
115  // Iterator needs to know about internal workings of the Mesh to work
116  // properly
117  friend Mesh::Iterator operator++(Mesh::Iterator& lhs, int);
118  friend Mesh::Iterator operator--(Mesh::Iterator& lhs, int);
121  friend Mesh::Iterator operator-
122  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
123  friend Mesh::Iterator operator+
124  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
125  friend Mesh::Iterator& operator-=
126  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
127  friend Mesh::Iterator& operator+=
128  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
129  friend Mesh::Iterator operator-
130  (const Mesh::Iterator& lhs, const int& rhs);
131  friend Mesh::Iterator operator+
132  (const Mesh::Iterator& lhs, const int& rhs);
133  friend Mesh::Iterator& operator-=
134  (Mesh::Iterator& lhs, const int& rhs);
135  friend Mesh::Iterator& operator+=
136  (Mesh::Iterator& lhs, const int& rhs);
137 
138  friend bool operator==
139  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
140  friend bool operator!=
141  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
142  friend bool operator>=
143  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
144  friend bool operator<=
145  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
146  friend bool operator<
147  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
148  friend bool operator>
149  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
150 };
151 
152 
170  public:
172  inline Iterator();
173 
175  inline Iterator(const Mesh::Iterator& in);
176 
183  inline Iterator(std::vector<int> state, const Mesh* mesh);
184 
186  inline virtual ~Iterator();
187 
189  inline const Mesh::Iterator& operator=(const Mesh::Iterator& rhs);
190 
195  inline virtual void getPosition(double* point) const;
196 
201  inline virtual std::vector<double> getPosition() const;
202 
210  inline int toInteger() const;
211 
213  inline std::vector<int> getState() const;
214 
216  inline int& operator[](int i);
217 
219  inline const int& operator[](int i) const;
220 
222  inline const Mesh* getMesh() const;
223 
224  friend class Mesh;
225  friend class TwoDGrid;
226  friend class ThreeDGrid;
227  friend class NDGrid;
228  friend class TriangularMesh;
229 
230  friend Mesh::Iterator operator++(Mesh::Iterator& lhs, int);
231  friend Mesh::Iterator operator--(Mesh::Iterator& lhs, int);
234  friend Mesh::Iterator operator-
235  (const Mesh::Iterator& lhs, const int& difference);
236  friend Mesh::Iterator operator+
237  (const Mesh::Iterator& lhs, const int& difference);
238  friend Mesh::Iterator& operator-=
239  (Mesh::Iterator& lhs, const int& difference);
240  friend Mesh::Iterator& operator+=
241  (Mesh::Iterator& lhs, const int& difference);
242  friend Mesh::Iterator operator-
243  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
244  friend Mesh::Iterator operator+
245  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
246  friend Mesh::Iterator& operator-=
247  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
248  friend Mesh::Iterator& operator+=
249  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
250 
251  friend bool operator==
252  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
253  friend bool operator!=
254  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
255  friend bool operator>=
256  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
257  friend bool operator<=
258  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
259  friend bool operator<
260  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
261  friend bool operator>
262  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
263 
264  private:
265  const Mesh* mesh_m;
266  std::vector<int> state_m;
267 };
268 
271 
274 
276 inline Mesh::Iterator operator++(Mesh::Iterator& lhs, int);
277 
279 inline Mesh::Iterator operator--(Mesh::Iterator& lhs, int);
280 
283 inline Mesh::Iterator operator-
284  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
285 
287 inline Mesh::Iterator operator+
288  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
289 
293 inline Mesh::Iterator& operator-=
294  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
295 
299 inline Mesh::Iterator& operator+=
300  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
301 
303 inline Mesh::Iterator operator- (const Mesh::Iterator& lhs, const int& rhs);
304 
306 inline Mesh::Iterator operator+ (const Mesh::Iterator& lhs, const int& rhs);
307 
309 inline Mesh::Iterator& operator-=(Mesh::Iterator& lhs, const int& rhs);
310 
312 inline Mesh::Iterator& operator+=(Mesh::Iterator& lhs, const int& rhs);
313 
315 inline bool operator==(const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
316 
318 inline bool operator!=(const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
319 
323 inline bool operator>=(const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
324 
328 inline bool operator<=(const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
329 
333 inline bool operator< (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
334 
338 inline bool operator> (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
339 
342 std::ostream& operator<<(std::ostream& out, const Mesh::Iterator& it);
343 
344 }
345 
346 #include "Fields/Interpolation/Mesh-inl.icc"
347 
348 #endif
349 
virtual void getPosition(const Mesh::Iterator &it, double *position) const =0
bool operator>=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
friend Mesh::Iterator operator--(Mesh::Iterator &lhs, int)
virtual Mesh * clone()=0
const Mesh::Iterator & operator=(const Mesh::Iterator &rhs)
virtual Mesh::Iterator getNearest(const double *position) const =0
std::vector< int > state_m
Definition: Mesh.h:266
friend Mesh::Iterator operator--(Mesh::Iterator &lhs, int)
Mesh::Iterator & operator++(Mesh::Iterator &lhs)
Mesh::Iterator & operator+=(Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
virtual Mesh::Iterator & subEquals(Mesh::Iterator &lhs, int difference) const =0
virtual Mesh::Iterator end() const =0
virtual Mesh * dual() const =0
Mesh::Iterator & operator--(Mesh::Iterator &lhs)
virtual int toInteger(const Mesh::Iterator &lhs) const =0
Mesh::Iterator & operator-=(Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
virtual Mesh::Iterator & addEquals(Mesh::Iterator &lhs, int difference) const =0
bool operator!=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Mesh::Iterator operator+(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
virtual Mesh::Iterator & addOne(Mesh::Iterator &lhs) const =0
friend Mesh::Iterator operator++(Mesh::Iterator &lhs, int)
virtual Mesh::Iterator begin() const =0
Mesh::Iterator operator-(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
bool operator>(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Base class for meshing routines.
Definition: Mesh.h:49
friend class TriangularMesh
Definition: Mesh.h:228
virtual std::vector< double > getPosition() const
std::vector< int > getState() const
virtual bool isGreater(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const =0
virtual Mesh::Iterator & subOne(Mesh::Iterator &lhs) const =0
bool operator<=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
const Mesh * getMesh() const
bool operator==(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
virtual int getPositionDimension() const =0
friend Mesh::Iterator operator++(Mesh::Iterator &lhs, int)
std::ostream & operator<<(std::ostream &out, const Mesh::Iterator &it)
Definition: Mesh.cpp:33
bool operator<(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)