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