Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef AMROC_VECTOR7_H 00002 #define AMROC_VECTOR7_H 00003 00011 #include "CompConf.h" 00012 #include "generic.h" 00013 #include <iostream.h> 00014 #include <assert.h> 00015 00016 #ifndef VectorName 00017 #define Vector(dim) name2(Vector,dim) 00018 #define VectorName 00019 #endif 00020 00028 template <class DataType> 00029 class Vector(7) { 00030 typedef Vector(7)<DataType> TVector; 00031 00032 public: 00033 typedef DataType InternalDataType; 00034 00035 Vector(7)() {} 00036 Vector(7)(const TVector& x) { 00037 memcpy((void *) data_, (void *) x.data_, sizeof(TVector)); 00038 } 00039 Vector(7)(const DataType& v) { 00040 data_[0] = v; 00041 data_[1] = v; 00042 data_[2] = v; 00043 data_[3] = v; 00044 data_[4] = v; 00045 data_[5] = v; 00046 data_[6] = v; 00047 } 00048 00049 ~Vector(7)() {} 00050 00051 DataType * data() { return data_; } 00052 const DataType * data() const { return data_; } 00053 int length() const { return 7; } 00054 static int Length() { return 7; } 00055 00056 inline DataType operator()(int i) const { 00057 #ifdef DEBUG_PRINT 00058 assert((i >= 0) && (i < 7)); 00059 #endif 00060 return data_[i]; 00061 } 00062 inline DataType& operator()(int i) { 00063 #ifdef DEBUG_PRINT 00064 assert((i >= 0) && (i < 7)); 00065 #endif 00066 return data_[i]; 00067 } 00068 00069 inline DataType operator[](int i) const { 00070 #ifdef DEBUG_PRINT 00071 assert((i >= 0) && (i < 7)); 00072 #endif 00073 return data_[i]; 00074 } 00075 inline DataType& operator[](int i) { 00076 #ifdef DEBUG_PRINT 00077 assert((i >= 0) && (i < 7)); 00078 #endif 00079 return data_[i]; 00080 } 00081 00082 inline TVector& operator=(const TVector& x) { 00083 memcpy((void *) data_, (void *) x.data_, sizeof(TVector)); 00084 return *this; 00085 } 00086 inline TVector& operator=(const DataType& v) { 00087 data_[0] = v; 00088 data_[1] = v; 00089 data_[2] = v; 00090 data_[3] = v; 00091 data_[4] = v; 00092 data_[5] = v; 00093 data_[6] = v; 00094 return *this; 00095 } 00096 00097 #define Vector_Vector_Operator(ope,op) \ 00098 inline TVector& operator ope (const TVector &x) \ 00099 { \ 00100 data_[0] ope x.data_[0]; \ 00101 data_[1] ope x.data_[1]; \ 00102 data_[2] ope x.data_[2]; \ 00103 data_[3] ope x.data_[3]; \ 00104 data_[4] ope x.data_[4]; \ 00105 data_[5] ope x.data_[5]; \ 00106 data_[6] ope x.data_[6]; \ 00107 return(*this); \ 00108 } \ 00109 inline TVector operator op (const TVector &x) const \ 00110 { \ 00111 TVector ret(*this); \ 00112 ret.data_[0] ope x.data_[0]; \ 00113 ret.data_[1] ope x.data_[1]; \ 00114 ret.data_[2] ope x.data_[2]; \ 00115 ret.data_[3] ope x.data_[3]; \ 00116 ret.data_[4] ope x.data_[4]; \ 00117 ret.data_[5] ope x.data_[5]; \ 00118 ret.data_[6] ope x.data_[6]; \ 00119 return(ret); \ 00120 } 00121 Vector_Vector_Operator(+=,+) 00122 Vector_Vector_Operator(-=,-) 00123 Vector_Vector_Operator(*=,*) 00124 Vector_Vector_Operator(/=,/) 00125 #undef Vector_Vector_Operator 00126 00127 #define Vector_Scalar_Operator(ope,op) \ 00128 inline TVector& operator ope (const DataType &v) \ 00129 { \ 00130 data_[0] ope v; \ 00131 data_[1] ope v; \ 00132 data_[2] ope v; \ 00133 data_[3] ope v; \ 00134 data_[4] ope v; \ 00135 data_[5] ope v; \ 00136 data_[6] ope v; \ 00137 return(*this); \ 00138 } \ 00139 inline TVector operator op (const DataType &v) const \ 00140 { \ 00141 TVector ret(*this); \ 00142 ret.data_[0] ope v; \ 00143 ret.data_[1] ope v; \ 00144 ret.data_[2] ope v; \ 00145 ret.data_[3] ope v; \ 00146 ret.data_[4] ope v; \ 00147 ret.data_[5] ope v; \ 00148 ret.data_[6] ope v; \ 00149 return(ret); \ 00150 } 00151 Vector_Scalar_Operator(+=,+) 00152 Vector_Scalar_Operator(-=,-) 00153 Vector_Scalar_Operator(*=,*) 00154 Vector_Scalar_Operator(/=,/) 00155 #undef Vector_Scalar_Operator 00156 00157 /* Define the negation operator */ 00158 inline TVector operator - () const 00159 { 00160 TVector ret; 00161 ret.data_[0] = -data_[0]; 00162 ret.data_[1] = -data_[1]; 00163 ret.data_[2] = -data_[2]; 00164 ret.data_[3] = -data_[3]; 00165 ret.data_[4] = -data_[4]; 00166 ret.data_[5] = -data_[5]; 00167 ret.data_[6] = -data_[6]; 00168 return(ret); 00169 } 00170 00171 #define Vector_Vector_RelOperator(op) \ 00172 inline int operator op (const TVector &x) const \ 00173 { return( \ 00174 (data_[0] op x.data_[0]) \ 00175 && (data_[1] op x.data_[1]) \ 00176 && (data_[2] op x.data_[2]) \ 00177 && (data_[3] op x.data_[3]) \ 00178 && (data_[4] op x.data_[4]) \ 00179 && (data_[5] op x.data_[5]) \ 00180 && (data_[6] op x.data_[6]) \ 00181 ) ; } 00182 00183 Vector_Vector_RelOperator(==) 00184 Vector_Vector_RelOperator(!=) 00185 #undef Vector_Vector_RelOperator 00186 00187 #define Vector_Vector_RelOperator(op) \ 00188 inline int operator op (const TVector &x) const \ 00189 { return( \ 00190 (data_[0] op x.data_[0]) \ 00191 || (data_[1] op x.data_[1]) \ 00192 || (data_[2] op x.data_[2]) \ 00193 || (data_[3] op x.data_[3]) \ 00194 || (data_[4] op x.data_[4]) \ 00195 || (data_[5] op x.data_[5]) \ 00196 || (data_[6] op x.data_[6]) \ 00197 ) ; } 00198 00199 Vector_Vector_RelOperator(>) 00200 Vector_Vector_RelOperator(<) 00201 Vector_Vector_RelOperator(>=) 00202 Vector_Vector_RelOperator(<=) 00203 #undef Vector_Vector_RelOperator 00204 00205 #define Vector_Scalar_RelOperator(op) \ 00206 inline int operator op (const DataType &v) const \ 00207 { return( \ 00208 (data_[0] op v) \ 00209 && (data_[1] op v) \ 00210 && (data_[2] op v) \ 00211 && (data_[3] op v) \ 00212 && (data_[4] op v) \ 00213 && (data_[5] op v) \ 00214 && (data_[6] op v) \ 00215 ); } 00216 00217 Vector_Scalar_RelOperator(==) 00218 Vector_Scalar_RelOperator(!=) 00219 #undef Vector_Scalar_RelOperator 00220 00221 #define Vector_Scalar_RelOperator(op) \ 00222 inline int operator op (const DataType &v) const \ 00223 { return( \ 00224 (data_[0] op v) \ 00225 || (data_[1] op v) \ 00226 || (data_[2] op v) \ 00227 || (data_[3] op v) \ 00228 || (data_[4] op v) \ 00229 || (data_[5] op v) \ 00230 || (data_[6] op v) \ 00231 ); } 00232 00233 Vector_Scalar_RelOperator(>) 00234 Vector_Scalar_RelOperator(<) 00235 Vector_Scalar_RelOperator(>=) 00236 Vector_Scalar_RelOperator(<=) 00237 #undef Vector_Scalar_RelOperator 00238 00239 /* Define elementwise minimum and maximum functions for Vectors */ 00240 inline void min(const TVector &x) { 00241 data_[0] = (data_[0] < x.data_[0]) ? data_[0] : x.data_[0]; 00242 data_[1] = (data_[1] < x.data_[1]) ? data_[1] : x.data_[1]; 00243 data_[2] = (data_[2] < x.data_[2]) ? data_[2] : x.data_[2]; 00244 data_[3] = (data_[3] < x.data_[3]) ? data_[3] : x.data_[3]; 00245 data_[4] = (data_[4] < x.data_[4]) ? data_[4] : x.data_[4]; 00246 data_[5] = (data_[5] < x.data_[5]) ? data_[5] : x.data_[5]; 00247 data_[6] = (data_[6] < x.data_[6]) ? data_[6] : x.data_[6]; 00248 } 00249 inline void max(const TVector &x) { 00250 data_[0] = (data_[0] > x.data_[0]) ? data_[0] : x.data_[0]; 00251 data_[1] = (data_[1] > x.data_[1]) ? data_[1] : x.data_[1]; 00252 data_[2] = (data_[2] > x.data_[2]) ? data_[2] : x.data_[2]; 00253 data_[3] = (data_[3] > x.data_[3]) ? data_[3] : x.data_[3]; 00254 data_[4] = (data_[4] > x.data_[4]) ? data_[4] : x.data_[4]; 00255 data_[5] = (data_[5] > x.data_[5]) ? data_[5] : x.data_[5]; 00256 data_[6] = (data_[6] > x.data_[6]) ? data_[6] : x.data_[6]; 00257 } 00258 00259 /* Define minimum and maximum of components */ 00260 inline DataType mincomp() const { 00261 DataType min; 00262 min = data_[0]; 00263 if (data_[1] < min) min = data_[1]; 00264 if (data_[2] < min) min = data_[2]; 00265 if (data_[3] < min) min = data_[3]; 00266 if (data_[4] < min) min = data_[4]; 00267 if (data_[5] < min) min = data_[5]; 00268 if (data_[6] < min) min = data_[6]; 00269 return min; 00270 } 00271 inline DataType maxcomp() const { 00272 DataType max; 00273 max = data_[0]; 00274 if (data_[1] > max) max = data_[1]; 00275 if (data_[2] > max) max = data_[2]; 00276 if (data_[3] > max) max = data_[3]; 00277 if (data_[4] > max) max = data_[4]; 00278 if (data_[5] > max) max = data_[5]; 00279 if (data_[6] > max) max = data_[6]; 00280 return max; 00281 } 00282 00283 inline double abs() const { 00284 DataType s = data_[0]*data_[0]; 00285 s += data_[1]*data_[1]; 00286 s += data_[2]*data_[2]; 00287 s += data_[3]*data_[3]; 00288 s += data_[4]*data_[4]; 00289 s += data_[5]*data_[5]; 00290 s += data_[6]*data_[6]; 00291 return (sqrt(double(s))); 00292 } 00293 00294 inline TVector getmin(const TVector &x) const 00295 { TVector ret(*this); ret.min(x); return(ret); } 00296 inline TVector getmax(const TVector &x) const 00297 { TVector ret(*this); ret.max(x); return(ret); } 00298 00299 public: 00300 DataType data_[7]; 00301 }; 00302 00303 00304 template <class DataType> 00305 inline ostream& operator << (ostream& os, const Vector(7)<DataType> &v) { 00306 os << "(" 00307 << v.data_[0] 00308 << "," << v.data_[1] 00309 << "," << v.data_[2] 00310 << "," << v.data_[3] 00311 << "," << v.data_[4] 00312 << "," << v.data_[5] 00313 << "," << v.data_[6] 00314 << ")"; 00315 return os; 00316 } 00317 00318 template <class DataType> 00319 inline Vector(7)<DataType> Min(const Vector(7)<DataType> &x, 00320 const Vector(7)<DataType> &y) 00321 { Vector(7)<DataType> ret(x); ret.min(y); return(ret); } 00322 00323 template <class DataType> 00324 inline Vector(7)<DataType> Max(const Vector(7)<DataType> &x, 00325 const Vector(7)<DataType> &y) 00326 { Vector(7)<DataType> ret(x); ret.max(y); return(ret); } 00327 00328 template <class DataType> 00329 inline double abs(const Vector(7)<DataType> &x) 00330 { return (x.abs()); } 00331 00332 template <class DataType> 00333 inline DataType mincomp(const Vector(7)<DataType> &x) 00334 { return(x.mincomp()); } 00335 00336 template <class DataType> 00337 inline DataType maxcomp(const Vector(7)<DataType> &x) 00338 { return(x.maxcomp()); } 00339 00340 00341 #define Global_Vector_Scalar_Operator(op) \ 00342 template <class DataType> \ 00343 inline Vector(7)<DataType> operator op (const DataType &v, \ 00344 const Vector(7)<DataType> &x) \ 00345 { return(x op v); } 00346 00347 Global_Vector_Scalar_Operator(+) 00348 Global_Vector_Scalar_Operator(-) 00349 Global_Vector_Scalar_Operator(*) 00350 Global_Vector_Scalar_Operator(/) 00351 #undef Global_Vector_Scalar_Operator 00352 00353 00354 #define Global_Vector_Function(fct) \ 00355 template <class DataType> \ 00356 inline Vector(7)<DataType> fct(const Vector(7)<DataType> &x) \ 00357 { \ 00358 Vector(7)<DataType> ret; \ 00359 ret[0] = fct(x[0]); \ 00360 ret[1] = fct(x[1]); \ 00361 ret[2] = fct(x[2]); \ 00362 ret[3] = fct(x[3]); \ 00363 ret[4] = fct(x[4]); \ 00364 ret[5] = fct(x[5]); \ 00365 ret[6] = fct(x[6]); \ 00366 return(ret); \ 00367 } 00368 00369 Global_Vector_Function(fabs) 00370 Global_Vector_Function(sqrt) 00371 #undef Global_Vector_Function 00372 00373 00374 #define Vector_Vector_Functions(NameTo,NameFrom,ope) \ 00375 template <class DataType, class VectorType> \ 00376 inline void NameTo (Vector(7)<DataType> &x, const VectorType &y) \ 00377 { \ 00378 x(0) ope y(0); \ 00379 x(1) ope y(1); \ 00380 x(2) ope y(2); \ 00381 x(3) ope y(3); \ 00382 x(4) ope y(4); \ 00383 x(5) ope y(5); \ 00384 x(6) ope y(6); \ 00385 } \ 00386 template <class DataType, class VectorType> \ 00387 inline void NameFrom (VectorType &x, const Vector(7)<DataType> &y) \ 00388 { \ 00389 x(0) ope y(0); \ 00390 x(1) ope y(1); \ 00391 x(2) ope y(2); \ 00392 x(3) ope y(3); \ 00393 x(4) ope y(4); \ 00394 x(5) ope y(5); \ 00395 x(6) ope y(6); \ 00396 } 00397 00398 Vector_Vector_Functions(equals_to,equals_from,=) 00399 Vector_Vector_Functions(plus_to,plus_from,+=) 00400 Vector_Vector_Functions(minus_to,minus_from,-=) 00401 Vector_Vector_Functions(multiply_to,multiply_from,*=) 00402 Vector_Vector_Functions(divide_to,divide_from,/=) 00403 #undef Vector_Vector_Functions 00404 00405 00406 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04