Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mapbasic.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: mapbasic.h,v 1.16 2008/12/06 08:43:21 mtcampbe Exp $
24 
25 #ifndef __MAP_BASIC_H_
26 #define __MAP_BASIC_H_
27 
28 #define MAP_BEGIN_NAMESPACE namespace MAP {
29 #define MAP_END_NAMESPACE }
30 #define USE_MAP_NAMESPACE using namespace MAP;
31 
32 #include <cstdlib>
33 #include <iostream>
34 #include <cmath>
35 
36 #include "Element_accessors.h"
37 
39 
40 using COM::Element_node_enumerator;
41 using COM::Element_node_enumerator_str_2;
42 using COM::Element_node_enumerator_uns;
43 using COM::Facet_node_enumerator;
44 using COM::Element_vectors_k_const;
45 using COM::Element_vectors_k;
46 using COM::Element_node_vectors_k_const;
47 using COM::Element_node_vectors_k;
48 
49 class Origin {};
50 class Null_vector {};
51 
53 template <class Type>
54 class Vector_3 {
55 public:
56  Vector_3() {}
57  explicit Vector_3( Type t) : _x(t), _y(t), _z(t) {}
58  Vector_3( Null_vector) : _x(0), _y(0), _z(0) {}
59  Vector_3( Type a, Type b, Type c) : _x(a), _y(b), _z(c) {}
60  Type &operator[](const int i) { return (&_x)[i]; }
61  const Type &operator[](const int i) const { return (&_x)[i]; }
62 
63  Type x() const { return _x; }
64  Type y() const { return _y; }
65  Type z() const { return _z; }
66 
68  Vector_3 &operator+=( const Type t)
69  { _x+=t; _y+=t; _z+=t; return *this; }
71  { _x+=v._x; _y+=v._y; _z+=v._z; return *this; }
72  Vector_3 &operator-=( const Type t)
73  { _x-=t; _y-=t; _z-=t; return *this; }
75  { _x-=v._x; _y-=v._y; _z-=v._z; return *this; }
76  Vector_3 &operator*=( const Type t)
77  { _x*=t; _y*=t; _z*=t; return *this; }
79  { _x*=v._x; _y*=v._y; _z*=v._z; return *this; }
80  Vector_3 &operator/=( const Type t)
81  { _x/=t; _y/=t; _z/=t; return *this; }
83  { _x/=v._x; _y/=v._y; _z/=v._z; return *this; }
84 
86  Vector_3 operator+( const Type t) const
87  { return Vector_3(_x+t, _y+t, _z+t); }
88  Vector_3 operator+( const Vector_3 &v) const
89  { return Vector_3(_x+v._x, _y+v._y, _z+v._z); }
90  Vector_3 operator-( const Type t) const
91  { return Vector_3(_x-t, _y-t, _z-t); }
92  Vector_3 operator-( const Vector_3 &v) const
93  { return Vector_3(_x-v._x, _y-v._y, _z-v._z); }
94  Vector_3 operator*( const Type t) const
95  { return Vector_3(_x*t, _y*t, _z*t); }
96  Vector_3 operator/( const Type t) const
97  { return Vector_3(_x/t, _y/t, _z/t); }
98  Type operator*( const Vector_3 &v) const
99  { return _x*v._x + _y*v._y + _z*v._z; }
100 
102  { return Vector_3(-_x, -_y, -_z); }
103 
104  static Vector_3 cross_product( const Vector_3 &v, const Vector_3 &w) {
105  return Vector_3( v._y * w._z - v._z * w._y ,
106  v._z * w._x - v._x * w._z ,
107  v._x * w._y - v._y * w._x );
108  }
109 
110  Type squared_norm() const { return *this * *this; }
111 
112  Type norm() const { return std::sqrt(*this * *this); }
113 
115  Type s=squared_norm();
116  if ( s != Type(0)) { s=std::sqrt(s); _x/=s; _y/=s; _z/=s; }
117  return *this;
118  }
119 
120  Vector_3 &neg() {
121  _x = -_x; _y = -_y; _z = -_z; return *this;
122  }
123 
124  bool operator==( const Vector_3 &p) const
125  { return x()==p.x() && y()==p.y() && z()==p.z(); }
126  bool operator!=( const Vector_3 &p) const
127  { return x()!=p.x() || y()!=p.y() || z()!=p.z(); }
128 
129  bool operator<( const Vector_3 &v) const
130  { return _x<v._x || _x==v._x && _y<v._y ||
131  _x==v._x && _y==v._y && _z<v._z; }
132 
133  bool is_null() const { return _x==0&&_y==0&&_z==0; }
134 protected:
135  Type _x, _y, _z;
136 };
137 
138 template <class T>
139 Vector_3<T> operator*( T t, const Vector_3<T> &v) { return v*t; }
140 
141 template <class Type>
142 std::ostream &operator<<( std::ostream &os, const Vector_3<Type> &p) {
143  return os << '(' << p.x() << ',' << p.y() << ',' << p.z() << ')';
144 }
145 
146 template <class T>
147 class Point_3 : protected Vector_3 <T> {
148 public:
149  Point_3() {}
150  explicit Point_3( T t) : Vector_3<T>(t) {}
151  Point_3( Origin) : Vector_3<T>(0, 0, 0) {}
152 
153  Point_3( T a, T b, T c) : Vector_3<T>(a, b, c) {}
154  T &operator[](const int i) { return (&_x)[i]; }
155  const T &operator[](const int i) const { return (&_x)[i]; }
156  using Vector_3<T>::x;
157  using Vector_3<T>::y;
158  using Vector_3<T>::z;
159 
162  { _x+=v.x(); _y+=v.y(); _z+=v.z(); return *this; }
164  { _x-=v.x(); _y-=v.y(); _z-=v.z(); return *this; }
165 
167  Point_3 operator+( const Vector_3<T> &v) const
168  { return Point_3(_x+v.x(), _y+v.y(), _z+v.z()); }
169  Point_3 operator-( const Vector_3<T> &v) const
170  { return Point_3(_x-v.x(), _y-v.y(), _z-v.z()); }
171  Vector_3<T> operator-( const Point_3 &v) const
172  { return Vector_3<T>(_x-v.x(), _y-v.y(), _z-v.z()); }
173 
174  bool operator==( const Point_3 &p) const
175  { return x()==p.x() && y()==p.y() && z()==p.z(); }
176 
177  bool operator!=( const Point_3 &p) const
178  { return x()!=p.x() || y()!=p.y() || z()!=p.z(); }
179 
180  bool operator<( const Point_3 &v) const
181  { return Vector_3<T>::operator<(v); }
182 
183  bool is_origin() const { return _x==0&&_y==0&&_z==0; }
184 
185 #ifndef __SUNPRO_CC
186 protected:
187  using Vector_3<T>::_x;
188  using Vector_3<T>::_y;
189  using Vector_3<T>::_z;
190 #endif
191 };
192 
193 template <class Type>
194 std::ostream &operator<<( std::ostream &os, const Point_3<Type> &p) {
195  return os << '(' << p.x() << ',' << p.y() << ',' << p.z() << ')';
196 }
197 
198 template <class Type>
199 class Vector_2 {
200 public:
201  Vector_2() {}
202  explicit Vector_2( Type t) : _x(t), _y(t) {}
203  Vector_2( Null_vector) : _x(0), _y(0) {}
204  Vector_2( Type a, Type b) : _x(a), _y(b) {}
205  Type &operator[](const int i) { return i==0?_x:_y; }
206  const Type &operator[](const int& i) const { return i==0?_x:_y; }
207 
208  Type x() const { return _x; }
209  Type y() const { return _y; }
210 
213  { _x+=v._x; _y+=v._y; return *this; }
215  { _x-=v._x; _y-=v._y; return *this; }
216  Vector_2 &operator*=( const Type t)
217  { _x*=t; _y*=t; return *this; }
218  Vector_2 &operator/=( const Type t)
219  { _x/=t; _y/=t; return *this; }
220 
222  Vector_2 operator+( const Vector_2 &v) const
223  { return Vector_2(_x+v._x, _y+v._y); }
224  Vector_2 operator-( const Vector_2 &v) const
225  { return Vector_2(_x-v._x, _y-v._y); }
226  Vector_2 operator*( const Type t) const
227  { return Vector_2(_x*t, _y*t); }
228  Vector_2 operator/( const Type t) const
229  { return Vector_2(_x/t, _y/t); }
230  Type operator*( const Vector_2 &v) const
231  { return _x*v._x + _y*v._y; }
232 
234  { return Vector_2(-_x, -_y); }
235 
236  Type squared_norm() const { return *this * *this; }
237 
238  Type norm() const { return std::sqrt(*this * *this); }
239 
241  Type s=squared_norm();
242  if ( s != Type(0)) { s=std::sqrt(s); _x/=s; _y/=s; }
243  return *this;
244  }
245 
246  Vector_2 &neg() {
247  _x = -_x; _y = -_y; return *this;
248  }
249 
250  bool operator==( const Vector_2 &p) const
251  { return x()==p.x() && y()==p.y(); }
252 
253  bool operator!=( const Vector_2 &p) const
254  { return x()!=p.x() || y()!=p.y(); }
255 
256  bool operator<( const Vector_2 &v) const
257  { return _x<v._x || _x==v._x && _y<v._y; }
258 
259  bool is_null() const { return _x==0&&_y==0; }
260 
261 protected:
262  Type _x, _y;
263 };
264 
265 template <class T>
266 Vector_2<T> operator*( T t, const Vector_2<T> &v) { return v*t; }
267 
268 template <class Type>
269 std::ostream &operator<<( std::ostream &os, const Vector_2<Type> &p) {
270  return os << '(' << p.x() << ',' << p.y() << ')';
271 }
272 
273 template <class T>
274 class Point_2 : protected Vector_2<T> {
275 public:
276  Point_2() {}
277  Point_2( Origin) : Vector_2<T>( 0, 0) {}
278  explicit Point_2( T t) : Vector_2<T>(t) {}
279  Point_2( T a, T b) : Vector_2<T>(a, b) {}
280  T &operator[](const int i) { return (&_x)[i]; }
281  const T &operator[](const int i) const { return (&_x)[i]; }
282  using Vector_2<T>::x;
283  using Vector_2<T>::y;
284 
287  { _x+=v.x(); _y+=v.y(); return *this; }
289  { _x-=v.x(); _y-=v.y(); return *this; }
290 
292  Point_2 operator+( const Vector_2<T> &v) const
293  { return Point_2(_x+v.x(), _y+v.y()); }
294  Point_2 operator-( const Vector_2<T> &v) const
295  { return Point_2(_x-v.x(), _y-v.y()); }
296  Vector_2<T> operator-( const Point_2 &v) const
297  { return Vector_2<T>(_x-v.x(), _y-v.y()); }
298 
299  bool operator==( const Point_2 &p) const
300  { return x()==p.x() && y()==p.y(); }
301 
302  bool operator!=( const Point_2 &p) const
303  { return x()!=p.x() || y()!=p.y(); }
304 
305  bool operator<( const Point_2 &v) const
306  { return Vector_2<T>::operator<(v); }
307 
308  bool is_origin() const { return _x==0&&_y==0; }
309 
310 #ifndef __SUNPRO_CC
311 protected:
312  using Vector_2<T>::_x;
313  using Vector_2<T>::_y;
314 #endif
315 };
316 
317 template <class Type>
318 std::ostream &operator<<( std::ostream &os, const Point_2<Type> &p) {
319  return os << '(' << p.x() << ',' << p.y() << ')';
320 }
321 
322 typedef double Real;
323 
324 // Modes of element_to_nodes.
325 enum { E2N_USER=0, E2N_ONE=1, E2N_AREA=2, E2N_ANGLE=3};
326 
328 
329 #endif
330 
331 
332 
333 
334 
335 
Point_2(Origin)
Definition: mapbasic.h:277
Type norm() const
Definition: mapbasic.h:238
const Type & operator[](const int &i) const
Definition: mapbasic.h:206
Point_3 operator+(const Vector_3< T > &v) const
Arithmatic operators.
Definition: mapbasic.h:167
Vector_2 & normalize()
Definition: mapbasic.h:240
bool operator==(const Vector_2 &p) const
Definition: mapbasic.h:250
#define MAP_END_NAMESPACE
Definition: mapbasic.h:29
bool operator!=(const Vector_3 &p) const
Definition: mapbasic.h:126
Vector_2 operator+(const Vector_2 &v) const
Arithmatic operators.
Definition: mapbasic.h:222
Vector_3 operator-() const
Definition: mapbasic.h:101
Point_2 operator-(const Vector_2< T > &v) const
Definition: mapbasic.h:294
Point_2 & operator-=(const Vector_2< T > &v)
Definition: mapbasic.h:288
T & operator[](const int i)
Definition: mapbasic.h:280
Vector_2 & operator/=(const Type t)
Definition: mapbasic.h:218
Vector_3< T > operator*(T t, const Vector_3< T > &v)
Definition: mapbasic.h:139
Vector_3 & operator/=(const Vector_3 &v)
Definition: mapbasic.h:82
Type _z
Definition: mapbasic.h:135
Vector_3 operator+(const Type t) const
Arithmatic operators.
Definition: mapbasic.h:86
FT y() const
Definition: Point_2.h:144
Point_3()
Definition: mapbasic.h:149
Vector_2(Null_vector)
Definition: mapbasic.h:203
Vector_3(Type t)
Definition: mapbasic.h:57
double s
Definition: blastest.C:80
Vector_3 operator-(const Vector_3 &v) const
Definition: mapbasic.h:92
Type _y
Definition: plot3d.C:51
Point_3(T t)
Definition: mapbasic.h:150
bool operator<(const Vector_3 &v) const
Definition: mapbasic.h:129
Type x() const
Definition: mapbasic.h:208
Vector_3 & operator-=(const Vector_3 &v)
Definition: mapbasic.h:74
double Real
Definition: mapbasic.h:322
Vector_2 & operator+=(const Vector_2 &v)
Assign operators.
Definition: mapbasic.h:212
Type z() const
Definition: mapbasic.h:65
const Type & operator[](const int i) const
Definition: mapbasic.h:61
FT x() const
Definition: Point_2.h:139
double sqrt(double d)
Definition: double.h:73
Vector_3 & normalize()
Definition: mapbasic.h:114
Type y() const
Definition: mapbasic.h:64
Vector_3 & neg()
Definition: mapbasic.h:120
Type y() const
Definition: mapbasic.h:209
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
Vector_2 operator-() const
Definition: mapbasic.h:233
const T & operator[](const int i) const
Definition: mapbasic.h:155
bool operator==(const Point_2 &p) const
Definition: mapbasic.h:299
Vector_3 & operator*=(const Type t)
Definition: mapbasic.h:76
bool operator!=(const Point_3 &p) const
Definition: mapbasic.h:177
Vector_3(Null_vector)
Definition: mapbasic.h:58
Type squared_norm() const
Definition: mapbasic.h:236
T & operator[](const int i)
Definition: mapbasic.h:154
Vector_2()
Definition: mapbasic.h:201
Point_3 operator-(const Vector_3< T > &v) const
Definition: mapbasic.h:169
Vector_2(Type a, Type b)
Definition: mapbasic.h:204
Vector_2< T > operator-(const Point_2 &v) const
Definition: mapbasic.h:296
Vector_2 operator/(const Type t) const
Definition: mapbasic.h:228
Point_2()
Definition: mapbasic.h:276
Vector_3 operator+(const Vector_3 &v) const
Definition: mapbasic.h:88
Vector_2 & operator-=(const Vector_2 &v)
Definition: mapbasic.h:214
Vector_3(Type a, Type b, Type c)
Definition: mapbasic.h:59
blockLoc i
Definition: read.cpp:79
Type x() const
Definition: mapbasic.h:63
bool is_origin() const
Definition: mapbasic.h:308
Vector_2 operator*(const Type t) const
Definition: mapbasic.h:226
Type squared_norm() const
Definition: mapbasic.h:110
Point_2(T a, T b)
Definition: mapbasic.h:279
static Vector_3 cross_product(const Vector_3 &v, const Vector_3 &w)
Definition: mapbasic.h:104
Type _x
Definition: mapbasic.h:262
Vector_3 & operator+=(const Type t)
Assign operators.
Definition: mapbasic.h:68
bool operator<(const Vector_2 &v) const
Definition: mapbasic.h:256
bool operator<(const Point_2 &v) const
Definition: mapbasic.h:305
Point_2(T t)
Definition: mapbasic.h:278
bool operator<(const Point_3 &v) const
Definition: mapbasic.h:180
FT x() const
Definition: Point_3.h:129
Type _z
Definition: plot3d.C:51
Vector_2(Type t)
Definition: mapbasic.h:202
Type operator*(const Vector_2 &v) const
Definition: mapbasic.h:230
Vector_3 operator/(const Type t) const
Definition: mapbasic.h:96
Point_3(T a, T b, T c)
Definition: mapbasic.h:153
Type operator*(const Vector_3 &v) const
Definition: mapbasic.h:98
FT y() const
Definition: Point_3.h:132
Vector_2 & neg()
Definition: mapbasic.h:246
Vector_3 & operator/=(const Type t)
Definition: mapbasic.h:80
Type _y
Definition: mapbasic.h:262
Vector_2 & operator*=(const Type t)
Definition: mapbasic.h:216
Point_2 operator+(const Vector_2< T > &v) const
Arithmatic operators.
Definition: mapbasic.h:292
Point_2 & operator+=(const Vector_2< T > &v)
Assign operators.
Definition: mapbasic.h:286
Vector_3 & operator-=(const Type t)
Definition: mapbasic.h:72
Vector_3()
Definition: mapbasic.h:56
bool operator==(const Vector_3 &p) const
Definition: mapbasic.h:124
Vector_2 operator-(const Vector_2 &v) const
Definition: mapbasic.h:224
#define MAP_BEGIN_NAMESPACE
Definition: mapbasic.h:28
bool operator!=(const Vector_2 &p) const
Definition: mapbasic.h:253
bool is_null() const
Definition: mapbasic.h:133
Point_3 & operator+=(const Vector_3< T > &v)
Assign operators.
Definition: mapbasic.h:161
Type _x
Definition: plot3d.C:51
Vector_3 operator*(const Type t) const
Definition: mapbasic.h:94
Some basic geometric data types.
Definition: mapbasic.h:54
bool operator==(const Point_3 &p) const
Definition: mapbasic.h:174
Type _x
Definition: mapbasic.h:135
Vector_3 & operator+=(const Vector_3 &v)
Definition: mapbasic.h:70
Type & operator[](const int i)
Definition: mapbasic.h:60
Vector_3 operator-(const Type t) const
Definition: mapbasic.h:90
Point_3(Origin)
Definition: mapbasic.h:151
bool operator!=(const Point_2 &p) const
Definition: mapbasic.h:302
Type & operator[](const int i)
Definition: mapbasic.h:205
Vector_3< T > operator-(const Point_3 &v) const
Definition: mapbasic.h:171
Type norm() const
Definition: mapbasic.h:112
FT z() const
Definition: Point_3.h:135
const T & operator[](const int i) const
Definition: mapbasic.h:281
bool is_null() const
Definition: mapbasic.h:259
Type _y
Definition: mapbasic.h:135
Vector_3 & operator*=(const Vector_3 &v)
Definition: mapbasic.h:78
bool is_origin() const
Definition: mapbasic.h:183
Point_3 & operator-=(const Vector_3< T > &v)
Definition: mapbasic.h:163