Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

IntVect.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #ifndef CH_INTVECT_H
00029 #define CH_INTVECT_H
00030 
00031 //
00032 // $Id: IntVect.H,v 1.8 2003/08/01 02:27:09 petermc Exp $
00033 //
00034 
00035 #ifndef WRAPPER
00036 #include <cstddef>
00037 #include <cstdlib>
00038 #include <cstring>
00039 #include <iostream>
00040 
00041 
00042 class HDF5Handle;
00043 
00044 #include "Misc.H"
00045 #include <cassert>
00046 
00047 #endif
00048 
00049 #include "SPACE.H"
00050 
00052 
00060 class IntVect
00061 {
00062 public:
00063 
00068 
00070 
00073   IntVect (){;}
00074 
00076 
00079   ~IntVect() {;}
00080 
00082 
00087   IntVect (D_DECL(int i, int j, int k));
00088 
00090 
00094   explicit IntVect (const int* a);
00095 
00097 
00100   IntVect (const IntVect& rhs);
00101 
00102   IntVect copy() const {return *this;}
00104 
00107   IntVect& operator= (const IntVect& rhs);
00108 
00110 
00114   inline
00115   int& operator[] (int i);
00116 
00118 
00121   inline
00122   int operator[] (int i) const;
00123 
00125 
00128   void setVal (int i,
00129                int val);
00130   
00137 
00139 
00143   const int* getVect () const;
00144 
00146 
00149   const int*  dataPtr() const;
00150 
00152 
00155   int*  dataPtr();
00156 
00163 
00165 
00169   bool operator== (const IntVect& p) const;
00170 
00172 
00176   bool operator!= (const IntVect& p) const;
00177 
00179 
00186   bool operator< (const IntVect& p) const;
00187 
00189 
00196   bool operator<= (const IntVect& p) const;
00197 
00199 
00206   bool operator> (const IntVect& p) const;
00207 
00209 
00217   bool operator>= (const IntVect& p) const;
00218 
00220 
00233   bool lexLT (const IntVect& s) const;
00234 
00236 
00249   bool lexGT (const IntVect& s) const;
00250 
00257 
00259 
00262   IntVect operator+ () const;
00263 
00265 
00268   IntVect operator- () const;
00269 
00276 
00278 
00281   IntVect& operator+= (int s);
00282 
00284 
00287   IntVect& operator+= (const IntVect& p);
00288 
00290 
00293   IntVect operator+ (const IntVect& p) const;
00294 
00296 
00300   IntVect operator+ (int s) const;
00301 
00303 
00307   friend inline IntVect operator+ (int            s,
00308                                    const IntVect& p);
00309 
00316 
00318 
00322   IntVect& operator-= (int s);
00323 
00325 
00328   IntVect& operator-= (const IntVect& p);
00329 
00331 
00335   IntVect operator- (const IntVect& p) const;
00336 
00338 
00342   IntVect operator- (int s) const;
00343 
00345 
00348   friend inline IntVect operator- (int            s,
00349                                    const IntVect& p);
00350 
00357 
00359 
00363   IntVect& operator*= (int s);
00364 
00366 
00369   IntVect& operator*= (const IntVect& p);
00370 
00372 
00375   IntVect operator* (const IntVect& p) const;
00376 
00378 
00382   IntVect operator* (int s) const;
00383 
00385 
00389   friend inline IntVect operator* (int            s,
00390                                    const IntVect& p);
00391 
00398 
00400 
00403   IntVect& operator/= (int s);
00404 
00406 
00410   IntVect& operator/= (const IntVect& p);
00411 
00413 
00416   IntVect operator/ (const IntVect& p) const;
00417 
00419 
00423   IntVect operator/ (int s) const;
00424 
00431 
00433 
00437   IntVect& min (const IntVect& p);
00438 
00440 
00444   friend inline IntVect min (const IntVect& p1,
00445                              const IntVect& p2);
00446 
00448 
00452   IntVect& max (const IntVect& p);
00453 
00455 
00459   friend inline IntVect max (const IntVect& p1,
00460                              const IntVect& p2);
00461 
00463 
00466   IntVect& scale (int s);
00467 
00469 
00473   friend inline IntVect scale (const IntVect& p,
00474                                int            s);
00475 
00477 
00482   IntVect& reflect (int ref_ix,
00483                     int idir);
00484   
00486 
00491   friend inline IntVect reflect(const IntVect& a,
00492                                 int            ref_ix,
00493                                 int            idir);
00494 
00496 
00500   IntVect& shift (int coord,
00501                   int s);
00502 
00504 
00508   IntVect& shift (const IntVect& iv);
00509 
00511 
00515   IntVect& diagShift (int s);
00516 
00518 
00522   friend inline IntVect diagShift (const IntVect& p,
00523                                    int            s);
00524 
00526 
00529   IntVect& coarsen (const IntVect& p);
00530 
00532 
00535   IntVect& coarsen (int p);
00536 
00538 
00542   friend inline IntVect coarsen (const IntVect& p,
00543                                  int            s);
00544 
00546 
00550   friend inline IntVect coarsen (const IntVect& p1,
00551                                  const IntVect& p2);
00552 
00559 
00561 
00564   void printOn (std::ostream& os) const;
00565 
00567 
00570   void p() const;
00571 
00573 
00576   void dumpOn (std::ostream& os) const;
00577 
00579 
00582   friend std::ostream& operator<< (std::ostream&       os,
00583                                    const IntVect& iv);
00584 
00586 
00589   friend std::istream& operator>> (std::istream& os,
00590                                    IntVect& iv);
00591 
00598 
00600 
00608   friend inline IntVect BASISV (int dir);
00609 
00613   static const IntVect Zero;
00614 
00618   static const IntVect Unit;
00619 
00620 #ifndef WRAPPER
00621 
00624   static const IntVect TheZeroVector () {return Zero;}
00625 
00629   static const IntVect TheUnitVector () {return Unit;}
00630 #endif
00631 
00634 protected:
00635   //
00636   // Box is a friend of ours.
00637   //
00638   friend class Box;
00639 
00640   friend class HDF5Handle;
00641   friend class VolIndex;
00642   friend class FaceIndex;
00643 
00647   int vect[SpaceDim];
00648 
00652   static const size_t IntVectSize;
00653 };
00654 
00655 IntVect UnitVector();
00656 IntVect ZeroVector();
00657 
00658 #ifndef WRAPPER
00659 //
00660 // Inlines.
00661 //
00662 
00663 // try uninitialized IntVect null construction for now.....
00664 
00665 // inline
00666 // IntVect::IntVect ()
00667 // {
00668 //     D_EXPR(vect[0] = 0, vect[1] = 0, vect[2] = 0);
00669 // }
00670 
00671 
00672 
00673 inline
00674 IntVect::IntVect (D_DECL(int i, int j, int k))
00675 {
00676   D_EXPR(vect[0] = i, vect[1] = j, vect[2] = k);
00677 }
00678 
00679 inline
00680 IntVect::IntVect (const int *a)
00681 {
00682   D_EXPR(vect[0] = a[0], vect[1] = a[1], vect[2] = a[2]);
00683 }
00684 
00685 inline
00686 IntVect::IntVect (const IntVect &iv)
00687 {
00688   //D_EXPR(vect[0]=iv.vect[0], vect[1]=iv.vect[1], vect[2]=iv.vect[2]);
00689   memcpy(vect, iv.vect, IntVectSize);
00690 }
00691 
00692 inline
00693 IntVect&
00694 IntVect::operator= (const IntVect &iv)
00695 {
00696   D_EXPR(vect[0]=iv.vect[0], vect[1]=iv.vect[1], vect[2]=iv.vect[2]);
00697   return *this;
00698 }
00699 
00700 inline
00701 int&
00702 IntVect::operator[] (int i)
00703 {
00704   assert(i>=0 && i < SpaceDim);
00705   return vect[i];
00706 }
00707 
00708 inline
00709 int
00710 IntVect::operator[] (int i) const
00711 {
00712   assert(i>=0 && i < SpaceDim);
00713   return vect[i];
00714 }
00715 
00716 inline
00717 void
00718 IntVect::setVal (int i,
00719                  int val)
00720 {
00721   assert(i >=0 && i < SpaceDim);
00722   vect[i] = val;
00723   //  return *this;
00724 }
00725 
00726 inline
00727 const int* 
00728 IntVect::dataPtr() const
00729 {
00730   return vect;
00731 }
00732 
00733 inline
00734 int* 
00735 IntVect::dataPtr()
00736 {
00737   return vect;
00738 }
00739 
00740 inline
00741 const int*
00742 IntVect::getVect () const
00743 {
00744   return vect;
00745 }
00746 
00747 inline
00748 bool
00749 IntVect::operator== (const IntVect& p) const
00750 {
00751   return D_TERM(vect[0] == p[0], && vect[1] == p[1], && vect[2] == p[2]);
00752 }
00753 
00754 inline
00755 bool
00756 IntVect::operator!= (const IntVect& p) const
00757 {
00758   return D_TERM(vect[0] != p[0], || vect[1] != p[1], || vect[2] != p[2]);
00759 }
00760 
00761 inline
00762 bool
00763 IntVect::operator< (const IntVect& p) const
00764 {
00765   return D_TERM(vect[0] < p[0], && vect[1] < p[1], && vect[2] < p[2]);
00766 }
00767 
00768 inline
00769 bool
00770 IntVect::operator<= (const IntVect& p) const
00771 {
00772   return D_TERM(vect[0] <= p[0], && vect[1] <= p[1], && vect[2] <= p[2]);
00773 }
00774 
00775 inline
00776 bool
00777 IntVect::operator> (const IntVect& p) const
00778 {
00779   return D_TERM(vect[0] > p[0], && vect[1] > p[1], && vect[2] > p[2]);
00780 }
00781 
00782 inline
00783 bool
00784 IntVect::operator>= (const IntVect& p) const
00785 {
00786   return D_TERM(vect[0] >= p[0], && vect[1] >= p[1], && vect[2] >= p[2]);
00787 }
00788 
00789 inline
00790 bool
00791 IntVect::lexLT (const IntVect &s) const
00792 {
00793 #define LLT0 (vect[0] < s[0])
00794 #define LLT1 ((vect[0] == s[0]) && (vect[1] < s[1]))
00795 #define LLT2 ((vect[1] == s[1]) && (vect[2] < s[2]))
00796 #if   CH_SPACEDIM == 1
00797   return LLT0;
00798 #elif CH_SPACEDIM == 2
00799   return LLT0 || LLT1;
00800 #elif CH_SPACEDIM == 3
00801   return LLT0 || (vect[0]==s[0] && ((vect[1] < s[1] || LLT2)));
00802 #endif
00803 #undef LLT0
00804 #undef LLT1
00805 #undef LLT2
00806 }
00807 
00808 inline
00809 bool
00810 IntVect::lexGT (const IntVect& s) const
00811 {
00812 #define LGT0 (vect[0] > s[0])
00813 #define LGT1 ((vect[0] == s[0]) && (vect[1] > s[1]))
00814 #define LGT2 ((vect[1] == s[1]) && (vect[2] > s[2]))
00815 #if   CH_SPACEDIM == 1
00816   return LGT0;
00817 #elif CH_SPACEDIM == 2
00818   return LGT0 || LGT1;
00819 #elif CH_SPACEDIM == 3
00820   return LGT0 || (vect[0] == s[0] && ((vect[1] > s[1] || LGT2)));
00821 #endif
00822 #undef LGT0
00823 #undef LGT1
00824 #undef LGT2
00825 }
00826 
00827 inline
00828 IntVect
00829 IntVect::operator+ () const
00830 {
00831   return IntVect(*this);
00832 }
00833 
00834 inline
00835 IntVect
00836 IntVect::operator- () const
00837 {
00838   return IntVect(D_DECL(-vect[0], -vect[1], -vect[2] ));
00839 }
00840 
00841 inline
00842 IntVect&
00843 IntVect::operator+= (int s)
00844 {
00845   D_EXPR(vect[0] += s, vect[1] += s, vect[2] += s);
00846   return *this;
00847 }
00848 
00849 inline
00850 IntVect&
00851 IntVect::operator+= (const IntVect& p)
00852 {
00853   D_EXPR(vect[0] += p[0], vect[1] += p[1], vect[2] += p[2]);
00854   return *this;
00855 }
00856 
00857 inline
00858 IntVect&
00859 IntVect::operator*= (int s)
00860 {
00861   D_EXPR(vect[0] *= s, vect[1] *= s, vect[2] *= s);
00862   return *this;
00863 }
00864 
00865 inline
00866 IntVect&
00867 IntVect::operator*= (const IntVect &p)
00868 {
00869   D_EXPR(vect[0] *= p[0], vect[1] *= p[1], vect[2] *= p[2]);
00870   return *this;
00871 }
00872 
00873 inline
00874 IntVect&
00875 IntVect::operator/= (int s)
00876 {
00877   D_EXPR(vect[0] /= s, vect[1] /= s, vect[2] /= s);
00878   return *this;
00879 }
00880 
00881 inline
00882 IntVect&
00883 IntVect::operator/= (const IntVect& p)
00884 {
00885   D_EXPR(vect[0] /= p[0], vect[1] /= p[1], vect[2] /= p[2]);
00886   return *this;
00887 }
00888 
00889 inline
00890 IntVect&
00891 IntVect::operator-= (int s)
00892 {
00893   D_EXPR(vect[0] -= s, vect[1] -= s, vect[2] -= s);
00894   return *this;
00895 }
00896 
00897 inline
00898 IntVect&
00899 IntVect::operator-= (const IntVect& p)
00900 {
00901   D_EXPR(vect[0] -= p[0], vect[1] -= p[1], vect[2] -= p[2]);
00902   return *this;
00903 }
00904 
00905 inline
00906 IntVect
00907 IntVect::operator+ (const IntVect& p) const
00908 {
00909   return IntVect(D_DECL(vect[0] + p[0], vect[1] + p[1], vect[2] + p[2]));
00910 }
00911 
00912 inline
00913 IntVect
00914 IntVect::operator+ (int s) const
00915 {
00916   return IntVect(D_DECL(vect[0] + s, vect[1] + s, vect[2] + s));
00917 }
00918 
00919 inline
00920 IntVect
00921 IntVect::operator- (const IntVect& p) const
00922 {
00923   return IntVect(D_DECL(vect[0] - p[0], vect[1] - p[1], vect[2] - p[2]));
00924 }
00925 
00926 inline
00927 IntVect
00928 IntVect::operator- (int s) const
00929 {
00930   return IntVect(D_DECL(vect[0] - s, vect[1] - s, vect[2] - s));
00931 }
00932 
00933 inline
00934 IntVect
00935 IntVect::operator* (const IntVect& p) const
00936 {
00937   return IntVect(D_DECL(vect[0] * p[0], vect[1] * p[1], vect[2] * p[2]));
00938 }
00939 
00940 inline
00941 IntVect
00942 IntVect::operator* (int s) const
00943 {
00944   return IntVect(D_DECL(vect[0] * s, vect[1] * s, vect[2] * s));
00945 }
00946 
00947 inline
00948 IntVect
00949 IntVect::operator/ (const IntVect& p) const
00950 {
00951   return IntVect(D_DECL(vect[0] / p[0], vect[1] / p[1], vect[2] / p[2]));
00952 }
00953 
00954 inline
00955 IntVect
00956 IntVect::operator/ (int s) const
00957 {
00958   return IntVect(D_DECL(vect[0] / s, vect[1] / s, vect[2] / s));
00959 }
00960 
00961 inline
00962 IntVect&
00963 IntVect::min (const IntVect& p)
00964 {
00965   D_EXPR(vect[0] = Min(vect[0], p.vect[0]),
00966          vect[1] = Min(vect[1], p.vect[1]),
00967          vect[2] = Min(vect[2], p.vect[2]));
00968   return *this;
00969 }
00970 
00971 inline
00972 IntVect&
00973 IntVect::max (const IntVect& p)
00974 {
00975   D_EXPR(vect[0] = Max(vect[0], p.vect[0]),
00976          vect[1] = Max(vect[1], p.vect[1]),
00977          vect[2] = Max(vect[2], p.vect[2]));
00978   return *this;
00979 }
00980 
00981 inline
00982 IntVect&
00983 IntVect::scale (int s)
00984 {
00985   D_EXPR(vect[0] *= s, vect[1] *= s, vect[2] *= s);
00986   return *this;
00987 }
00988 
00989 inline
00990 IntVect&
00991 IntVect::reflect (int ref_ix,
00992                   int idir)
00993 {
00994   assert(idir >= 0 && idir < SpaceDim);
00995   vect[idir] = -vect[idir] + 2*ref_ix;
00996   return *this;
00997 }
00998 
00999 inline
01000 IntVect&
01001 IntVect::shift (int coord,
01002                 int s)
01003 {
01004   assert(coord >= 0 && coord < SpaceDim);
01005   vect[coord] += s;
01006   return *this;
01007 }
01008 
01009 inline
01010 IntVect&
01011 IntVect::shift (const IntVect& iv)
01012 {
01013   *this += iv;
01014   return *this;
01015 }
01016 
01017 inline
01018 IntVect&
01019 IntVect::diagShift (int s)
01020 {
01021   D_EXPR(vect[0] += s, vect[1] += s, vect[2] += s);
01022   return *this;
01023 }
01024 
01025 inline
01026 IntVect
01027 operator+ (int            s,
01028            const IntVect& p)
01029 {
01030   return IntVect(D_DECL(p[0] + s, p[1] + s, p[2] + s));
01031 }
01032 
01033 inline
01034 IntVect
01035 operator- (int            s,
01036            const IntVect& p)
01037 {
01038   return IntVect(D_DECL(s - p[0], s - p[1], s - p[2]));
01039 }
01040 
01041 inline
01042 IntVect
01043 operator* (int            s,
01044            const IntVect& p)
01045 {
01046   return IntVect(D_DECL(s * p[0], s * p[1], s * p[2]));
01047 }
01048 
01049 inline
01050 IntVect
01051 scale (const IntVect& p,
01052        int            s)
01053 {
01054   return IntVect(D_DECL(s * p[0], s * p[1], s * p[2]));
01055 }
01056 
01057 inline
01058 IntVect
01059 diagShift (const IntVect &p, int s)
01060 {
01061   return IntVect(D_DECL(p[0] + s, p[1] + s, p[2] + s));
01062 }
01063 
01064 inline
01065 IntVect
01066 min (const IntVect& p1,
01067      const IntVect& p2)
01068 {
01069   IntVect p(p1);
01070   return p.min(p2);
01071 }
01072 
01073 inline
01074 IntVect
01075 max (const IntVect& p1,
01076      const IntVect& p2)
01077 {
01078   IntVect p(p1);
01079   return p.max(p2);
01080 }
01081 
01082 inline
01083 IntVect
01084 BASISV (int dir)
01085 {
01086   assert(dir >= 0 && dir < SpaceDim);
01087   IntVect tmp = IntVect::TheZeroVector() ;
01088   tmp.vect[dir] = 1;
01089   return tmp;
01090 }
01091 
01092 inline
01093 IntVect
01094 reflect (const IntVect& a,
01095          int            ref_ix,
01096          int            idir)
01097 {
01098   assert(idir >= 0 && idir < SpaceDim);
01099   IntVect b(a);
01100   b.vect[idir] = -b.vect[idir] + 2*ref_ix;
01101   return b;
01102 }
01103 
01104 inline
01105 IntVect
01106 coarsen (const IntVect& p,
01107          int            s)
01108 {
01109   assert(s > 0);
01110   return IntVect(
01111                  D_DECL((p.vect[0]<0) ? -abs(p.vect[0]+1)/s-1 : p.vect[0]/s ,
01112                         (p.vect[1]<0) ? -abs(p.vect[1]+1)/s-1 : p.vect[1]/s ,
01113                         (p.vect[2]<0) ? -abs(p.vect[2]+1)/s-1 : p.vect[2]/s ));
01114 }
01115 
01116 inline
01117 IntVect
01118 coarsen (const IntVect& p1,
01119          const IntVect& p2)
01120 {
01121   assert(p2 > IntVect::TheZeroVector());
01122   return IntVect(
01123                  D_DECL(
01124                         (p1.vect[0]<0)?-abs(p1.vect[0]+1)/p2.vect[0]-1:p1.vect[0]/p2.vect[0],
01125                         (p1.vect[1]<0)?-abs(p1.vect[1]+1)/p2.vect[1]-1:p1.vect[1]/p2.vect[1],
01126                         (p1.vect[2]<0)?-abs(p1.vect[2]+1)/p2.vect[2]-1:p1.vect[2]/p2.vect[2])
01127                  );
01128 }
01129 
01130 inline
01131 IntVect&
01132 IntVect::coarsen (int s)
01133 {
01134   assert(s > 0);
01135   for (int i = 0; i < SpaceDim; ++i)
01136     vect[i] = ((vect[i]<0) ? -abs(vect[i]+1)/s-1 : vect[i]/s);
01137   return *this;
01138 }
01139 
01140 inline
01141 IntVect&
01142 IntVect::coarsen (const IntVect& p)
01143 {
01144   assert(p > IntVect::TheZeroVector());
01145   for (int i = 0; i <SpaceDim; ++i)
01146     {
01147       const int s = p.vect[i];
01148       vect[i] = ((vect[i]<0) ? -abs(vect[i]+1)/s-1 : vect[i]/s);
01149     }
01150   return *this;
01151 }
01152 
01153 #endif /* WRAPPER */
01154 
01155 #endif /*CH_INTVECT_H*/
01156 

Generated on Wed Jun 2 13:53:33 2004 for Chombo&INSwithParticles by doxygen 1.3.2