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


Main Page   Class Hierarchy   Compound List   File List  

Vector12.h

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


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



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