AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

Vector13.h

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


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04