OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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 
225  virtual inline bool isOutOfBounds() const;
226 
228  virtual inline void addState(const Mesh::Iterator& it);
229 
230  friend class Mesh;
231  friend class ThreeDGrid;
232  friend class NDGrid;
233 
234  friend Mesh::Iterator operator++(Mesh::Iterator& lhs, int);
235  friend Mesh::Iterator operator--(Mesh::Iterator& lhs, int);
238  friend Mesh::Iterator operator-
239  (const Mesh::Iterator& lhs, const int& difference);
240  friend Mesh::Iterator operator+
241  (const Mesh::Iterator& lhs, const int& difference);
242  friend Mesh::Iterator& operator-=
243  (Mesh::Iterator& lhs, const int& difference);
244  friend Mesh::Iterator& operator+=
245  (Mesh::Iterator& lhs, const int& difference);
246  friend Mesh::Iterator operator-
247  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
248  friend Mesh::Iterator operator+
249  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
250  friend Mesh::Iterator& operator-=
251  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
252  friend Mesh::Iterator& operator+=
253  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
254 
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  friend bool operator<
264  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
265  friend bool operator>
266  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
267 
268  private:
269  const Mesh* mesh_m;
270  std::vector<int> state_m;
271 };
272 
275 
278 
280 inline Mesh::Iterator operator++(Mesh::Iterator& lhs, int);
281 
283 inline Mesh::Iterator operator--(Mesh::Iterator& lhs, int);
284 
287 inline Mesh::Iterator operator-
288  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
289 
291 inline Mesh::Iterator operator+
292  (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
293 
297 inline Mesh::Iterator& operator-=
298  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
299 
303 inline Mesh::Iterator& operator+=
304  (Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
305 
307 inline Mesh::Iterator operator- (const Mesh::Iterator& lhs, const int& rhs);
308 
310 inline Mesh::Iterator operator+ (const Mesh::Iterator& lhs, const int& rhs);
311 
313 inline Mesh::Iterator& operator-=(Mesh::Iterator& lhs, const int& rhs);
314 
316 inline Mesh::Iterator& operator+=(Mesh::Iterator& lhs, const int& rhs);
317 
319 inline bool operator==(const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
320 
322 inline bool operator!=(const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
323 
327 inline bool operator>=(const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
328 
332 inline bool operator<=(const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
333 
337 inline bool operator< (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
338 
342 inline bool operator> (const Mesh::Iterator& lhs, const Mesh::Iterator& rhs);
343 
346 std::ostream& operator<<(std::ostream& out, const Mesh::Iterator& it);
347 
348 }
349 
351 
352 #endif
353 
bool operator==(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:172
Mesh::Iterator operator-(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:111
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
Definition: LICENSE:43
virtual void addState(const Mesh::Iterator &it)
Definition: Mesh-inl.icc:198
Base class for meshing routines.
Definition: Mesh.h:49
std::vector< int > state_m
Definition: Mesh.h:270
virtual Mesh::Iterator begin() const =0
virtual Mesh * dual() const =0
const Mesh * getMesh() const
Definition: Mesh-inl.icc:70
virtual bool isGreater(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const =0
Mesh::Iterator & operator+=(Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:137
virtual Mesh::Iterator & addOne(Mesh::Iterator &lhs) const =0
friend Mesh::Iterator operator++(Mesh::Iterator &lhs, int)
Definition: Mesh-inl.icc:98
Mesh::Iterator & operator--(Mesh::Iterator &lhs)
Definition: Mesh-inl.icc:94
virtual Mesh::Iterator getNearest(const double *position) const =0
bool operator>(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:164
virtual int toInteger(const Mesh::Iterator &lhs) const =0
virtual void getPosition(const Mesh::Iterator &it, double *position) const =0
Mesh::Iterator operator+(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:124
virtual std::vector< double > getPosition() const
Definition: Mesh-inl.icc:84
virtual bool isOutOfBounds() const
Definition: Mesh-inl.icc:184
friend Mesh::Iterator operator--(Mesh::Iterator &lhs, int)
Definition: Mesh-inl.icc:104
virtual Mesh::Iterator & subEquals(Mesh::Iterator &lhs, int difference) const =0
const Mesh::Iterator & operator=(const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:74
friend Mesh::Iterator operator++(Mesh::Iterator &lhs, int)
Definition: Mesh-inl.icc:98
bool operator<(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:168
virtual Mesh::Iterator & subOne(Mesh::Iterator &lhs) const =0
std::vector< int > getState() const
Definition: Mesh-inl.icc:58
std::ostream & operator<<(std::ostream &out, const Mesh::Iterator &it)
Definition: Mesh.cpp:33
Mesh::Iterator & operator-=(Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:141
virtual Mesh * clone()=0
virtual Mesh::Iterator end() const =0
bool operator!=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:178
Mesh::Iterator & operator++(Mesh::Iterator &lhs)
Definition: Mesh-inl.icc:90
virtual int getPositionDimension() const =0
virtual Mesh::Iterator & addEquals(Mesh::Iterator &lhs, int difference) const =0
bool operator<=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:159
bool operator>=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Definition: Mesh-inl.icc:154
friend Mesh::Iterator operator--(Mesh::Iterator &lhs, int)
Definition: Mesh-inl.icc:104