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