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


Main Page   Class Hierarchy   Compound List   File List  

DCoords.h

Go to the documentation of this file.
00001 #ifndef _included_DCoords_h
00002 #define _included_DCoords_h
00003 
00009 #include "DAGHDefaults.h"
00010 
00011 #include "lparx_copyright.h"
00012 #include <iostream.h>
00013 #include <assert.h>
00014 
00015 #ifndef DCoordsMaxDim
00016 #define DCoordsMaxDim   (3)
00017 #endif
00018 
00019 #define DCoordsNULL     ((DCoords *)NULL)
00020 
00028 class DCoords
00029   {
00030    friend istream& operator >> (istream& s, DCoords& c);
00031    friend ostream& operator << (ostream& s, const DCoords& c);
00032 
00033    double c[DCoordsMaxDim];
00034 
00035 public:
00036    int rank;
00037    static class DCoords _empty_dcoords;
00038 
00039 public:
00040    inline DCoords(void) : rank(0) 
00041      { c[0] = 0.0; c[1] = 0.0; c[2] = 0.0; }
00042    inline DCoords(int const r) : rank(r) 
00043      { c[0] = 0.0; c[1] = 0.0; c[2] = 0.0; }
00044    inline DCoords(int const r, double const val) : rank(r)
00045      { c[0] = val; c[1] = val; c[2] = val; }
00046 
00047    inline DCoords(int const r, double const *val) : rank(r)
00048      { register int i; for (i=0; i<rank; i++) c[i] = val[i]; }
00049 
00050    inline DCoords(DCoords const &other) : rank(other.rank)
00051      { c[0] = other.c[0]; c[1] = other.c[1]; c[2] = other.c[2]; }
00052 
00053    /* Specific constructors for 2 & 3 D */
00054    inline DCoords(int const r, double const i, double const j) : rank(r) 
00055      { assert(r == 2); c[0] = i; c[1] = j; }
00056    inline DCoords(int const r, double const i, double const j, double const k) : rank(r) 
00057      { assert(r == 3); c[0] = i; c[1] = j; c[2] = k; }
00058 
00059    inline DCoords &operator = (DCoords const &rhs)
00060      {
00061        rank = rhs.rank;
00062        c[0] = rhs.c[0]; c[1] = rhs.c[1]; c[2] = rhs.c[2];
00063        return *this;
00064      }
00065 
00066    inline ~DCoords() {}
00067 
00068    /* Some simple operators on DCoords -- const and non-const ones */
00069    
00070    inline double& operator () (int const i) { return(c[i]); }
00071    inline double operator () (int const i) const { return(c[i]); }
00072 
00073    inline double * operator () (void) { return(c); }
00074    inline double const *operator () (void) const { return(c); }
00075 
00076    inline operator double * () { return(c); }
00077    inline operator const double * () const { return(c); }
00078 
00079    /* Define all of the operators between two DCoords */
00080 #define Point_Point_Operator(ope,op)                            \
00081    DCoords& operator ope (DCoords const &rhs)                   \
00082      {                                                          \
00083       c[0] ope rhs.c[0];                                        \
00084       if (rank>1) c[1] ope rhs.c[1];                            \
00085       if (rank>2) c[2] ope rhs.c[2];                            \
00086       return(*this);                                            \
00087      }                                                          \
00088    DCoords operator op (DCoords const &rhs) const               \
00089      {                                                          \
00090       DCoords coords(*this);                                    \
00091       coords ope rhs;                                           \
00092       return(coords);                                           \
00093      }
00094    Point_Point_Operator(+=,+)
00095    Point_Point_Operator(-=,-)
00096    Point_Point_Operator(*=,*)
00097    Point_Point_Operator(/=,/)
00098 #undef Point_Point_Operator
00099 
00100    /* Define all of the operators between a DCoords and an integer */
00101 #define Point_Scalar_Operator(ope,op)                           \
00102    DCoords& operator ope (double const rhs)                     \
00103      {                                                          \
00104       c[0] ope rhs;                                             \
00105       if (rank>1) c[1] ope rhs;                                 \
00106       if (rank>2) c[2] ope rhs;                                 \
00107       return(*this);                                            \
00108      }                                                          \
00109    DCoords operator op (double const rhs) const                 \
00110      {                                                          \
00111       DCoords coords(*this);                                    \
00112       coords ope rhs;                                           \
00113       return(coords);                                           \
00114      }
00115    Point_Scalar_Operator(+=,+)
00116    Point_Scalar_Operator(-=,-)
00117    Point_Scalar_Operator(*=,*)
00118    Point_Scalar_Operator(/=,/)
00119 #undef Point_Scalar_Operator
00120 
00121    /* Define the negation operator for a DCoords */
00122    inline DCoords operator - () const
00123      {
00124        DCoords coords(rank);
00125        coords.c[0] = -c[0]; coords.c[1] = -c[1]; coords.c[2] = -c[2];
00126        return(coords);
00127      }
00128 
00129    /* Define the equality and inequality operators for DCoords */
00130    inline int operator != (DCoords const &rhs) const
00131      {
00132       return ( ((rank > 0) && (c[0] != rhs.c[0])) ||
00133                ((rank > 1) && (c[1] != rhs.c[1])) ||
00134                ((rank > 2) && (c[2] != rhs.c[2]))
00135              ) ;
00136      }
00137    inline int operator == (DCoords const &rhs) const
00138      { return(!(*this != rhs)); }
00139 
00140    /* Define the greater-than & less-than operators for DCoords */
00141    inline int operator > (DCoords const &rhs) const
00142      {
00143       return (!(((rank > 0) && (c[0] <= rhs.c[0])) ||
00144                ((rank > 1) && (c[1] <= rhs.c[1])) ||
00145                ((rank > 2) && (c[2] <= rhs.c[2])))
00146              ) ;
00147      }
00148    inline int operator < (DCoords const &rhs) const
00149      {
00150       return (!(((rank > 0) && (c[0] >= rhs.c[0])) ||
00151                ((rank > 1) && (c[1] >= rhs.c[1])) ||
00152                ((rank > 2) && (c[2] >= rhs.c[2])))
00153              ) ;
00154      }
00155 
00156    inline void setval(double const val)
00157      { c[0] = val; c[1] = val; c[2] = val; }
00158    inline void setval(DCoords const &rhs)
00159      { c[0] = rhs.c[0]; c[1] = rhs.c[1]; c[2] = rhs.c[2]; }
00160 
00161    /* Define elementwise minimum and maximum functions for DCoords */
00162    inline void min(DCoords const &rhs)
00163      {
00164        c[0] = (rhs.c[0] < c[0]) ? rhs.c[0] : c[0];
00165        c[1] = (rank > 1 && rhs.c[1] < c[1]) ? rhs.c[1] : c[1];
00166        c[2] = (rank > 2 && rhs.c[2] < c[2]) ? rhs.c[2] : c[2];
00167      }
00168 
00169    inline void max(DCoords const &rhs)
00170      {
00171        c[0] = (rhs.c[0] > c[0]) ? rhs.c[0] : c[0];
00172        c[1] = (rank > 1 && rhs.c[1] > c[1]) ? rhs.c[1] : c[1];
00173        c[2] = (rank > 2 && rhs.c[2] > c[2]) ? rhs.c[2] : c[2];
00174      }
00175 
00176    inline DCoords getmin(DCoords const &rhs) const
00177      { DCoords other(*this); other.min(rhs); return other; }
00178    inline DCoords getmax(DCoords const &rhs) const
00179      { DCoords other(*this); other.max(rhs); return other; }
00180   };
00181 
00182 inline DCoords Max(const DCoords& a, const DCoords &b)
00183        { return(a.getmax(b)); }
00184 inline DCoords Min(const DCoords& a, const DCoords &b)
00185        { return(a.getmin(b)); }
00186 
00187 ostream& operator << (ostream& s, const DCoords& c);
00188 istream& operator >> (istream& s, DCoords& c);
00189 
00190 #endif


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



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