vtf-logo

GridUnit.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #ifndef _included_GridUnit_h
00004 #define _included_GridUnit_h
00005 
00011 #include "DAGHParams.h"
00012 #include "DAGHSfc.h"
00013 #include "BBox.h"
00014 
00015 #include <iosfwd>
00016 #include <cstdlib>
00017 
00018 #define GridUnitNULL ((GridUnit *) 0)
00019 
00036 class GridUnit 
00037   {
00038    friend std::ostream& operator<<(std::ostream&, const GridUnit&);
00039    friend std::ofstream& operator<<(std::ofstream&, const GridUnit&);
00040    friend std::ifstream& operator>>(std::ifstream&, GridUnit&);
00041    friend std::stringstream& operator<<(std::stringstream&, const GridUnit&);
00042    friend std::stringstream& operator>>(std::stringstream&, GridUnit&);
00043    friend class GridUnitList;
00044 
00045 protected:
00047    short int owner;
00049    short int index;
00051    short int rank;
00053    short int baselev;
00055    short int crslev;
00057    short int finelev;
00059    short int maxlev;
00061    short int minlev;
00063    short int levstep;
00064 
00066    short int extent;
00068    int work;                      
00070    dMapIndex baseindex;         
00072    BBox fbb;                   
00073 
00074 public:
00076    inline GridUnit(void)
00077         : owner(DAGHNoBody), index(DAGHNull), rank(0), 
00078           baselev(0), crslev(0), finelev(0), 
00079           maxlev(0), minlev(0), levstep(0), 
00080           extent(0), work(0) { }
00081 
00091    GridUnit(const int nrank, const int clev, const int* bcoords,
00092             const int ext, const int mlev, const int lstep, 
00093             const int reflev);
00094 
00095    GridUnit(const int nrank, const int clev, const int bindex, 
00096             const int ext, const int mlev, const int lstep, 
00097             const int reflev);
00098 
00099    inline GridUnit(GridUnit const &other)
00100         : owner(other.owner), index(other.index),
00101           rank(other.rank), baselev(other.baselev),
00102           crslev(other.crslev), finelev(other.finelev),
00103           maxlev(other.maxlev), minlev(other.minlev), 
00104           levstep(other.levstep), extent(other.extent), 
00105           work(other.work), baseindex(other.baseindex),
00106           fbb(other.fbb) 
00107      { }
00108 
00109    inline ~GridUnit(void) {}
00110 
00111    GridUnit const &operator= (GridUnit const &other);
00112 
00113 public:
00115    inline int guOwner(void) const { return (owner); }
00116    inline int guIndex(void) const { return (index); }
00117    inline int guRank(void) const { return (rank); }
00118    inline int guBaseLev(void) const { return (baselev); }
00119    inline int guFineLev(void) const { return (finelev); }
00120    inline int guCrsLev(void) const { return (crslev); }
00121    inline int guNumLev(void) const { return ((finelev-crslev)/levstep+1); }
00122    inline int guMaxLev(void) const { return (maxlev); }
00123    inline int guMinLev(void) const { return (minlev); }
00124    inline int guLevStep(void) const { return (levstep); }
00125    inline int guLevels(void) const { return ((maxlev-minlev)/levstep+1); }
00126 
00127    inline int guExtent(const int lev) const
00128    { return ((lev<=finelev && lev>=crslev && extent>=(finelev-lev)) 
00129             ? extent-(finelev-lev) : 0); }
00130    inline int guExtentAbs(const int lev) const
00131    { return ((extent>=(finelev-lev)) ? extent-(finelev-lev) : 0); }
00132    
00133    inline void guSetWorkload(const int w) { work = w; }
00134    unsigned inline long guNum(const int overlap) const { return work; }
00135    unsigned inline long guWork(const int overlap) const { return work; }
00136    unsigned inline long guNum(const int lev, const int overlap) const { return work; }
00137    unsigned inline long guWork(const int lev, const int overlap) const { return work; }
00138 
00139    unsigned inline long guNum(const short* overlap) const { return work; }
00140    unsigned inline long guWork(const short* overlap) const { return work; }
00141    unsigned inline long guNum(const int lev, const short* overlap) const { return work; }
00142    unsigned inline long guWork(const int lev, const short* overlap) const { return work; }
00143 
00144    inline int guContains(const int lev) const
00145         { return (lev<=finelev && lev>=crslev); }
00146    inline int guContains(const int minlev, const int maxlev) const
00147         { return (minlev<=finelev && maxlev>=crslev); }
00148 
00149    inline int guLevIndex(const int lev) const
00150         { return ((lev-minlev)/levstep); }
00151 
00152    //inline void guSetIndex(const int idx) { index = idx; }
00153    inline void guSetOwner(const int p) { owner = p; }
00154 
00155    inline const dMapIndex& guBaseIndex(void) const { return (baseindex); }
00156 
00157    dMapIndex guTopIndex(const int lev) const;
00158    dMapIndex guMaxIndex(const int lev) const;
00159 
00160 private:
00161    void guLCoords(int *c, const int lev) const;
00162    Coords guLCoords(const int lev) const;
00163 
00164    void guUCoords(int *c, const int lev) const;
00165    Coords guUCoords(const int lev) const;
00166 
00167    void guSetBBox(); 
00168 
00169 public:
00170    const BBox& guBBox() const { return (fbb); }
00171 
00172    BBox guBBox(const int lev, const int olap=0, const int extgh=0) const;
00173    BBox guBBoxAbs(const int lev, const int olap=0, const int extgh=0) const;
00174 
00175    BBox guBBox(const int lev, const short* olap, const int extgh=0) const;
00176    BBox guBBoxAbs(const int lev, const short* olap, const int extgh=0) const;
00177 
00178    BBox guBBox(const int minl, const int maxl,
00179                const short* olap, const int extgh=0) const;
00180 
00181    int guInside(const BBox& bbox, const int lev) const;
00182 
00184    int operator== (GridUnit const &other) const;
00185    int operator>= (GridUnit const &other) const;
00186    int operator<= (GridUnit const &other) const;
00187 
00188    /* Operations on a GridUnit */
00192    void guRefine(const int levs = 1);
00193    void guRefine(GridUnit &gu, const int levs = 1);
00194 
00198    void guCoarsen(const int levs = 1);
00199    void guCoarsen(GridUnit &gu, const int levs = 1);
00200 
00203    void guDecompose(GridUnit**& gu, int& cnt, const int levs = 1) const;
00206    void guDecomposeReplicate(GridUnit**& gu, int& cnt, const int minext, 
00207                                         const int levs = 1) const;
00208    
00209    /* An operator I would like to have */
00210    //void guRecompose(GridUnit**& gu, const int cnt) const;
00211 
00215    void guGetLevels(GridUnit** &gu) const;
00216    void guGetLevels(GridUnit &gu, const int lev) const;
00217 
00219    inline void guSetDecompose(GridUnit& gu,
00220                               const int lev,
00221                               const int cnt)
00222      { gu.baselev+=lev; gu.extent-=lev; 
00223        gu.baseindex.SetIndex(cnt,gu.baselev,lev); gu.guSetBBox();
00224        gu.guSetWorkload ( gu.guWork(0)/gu.baseindex.GetCardinality(lev) );
00225      }
00226 
00227    inline void guSetLevels(GridUnit& gu,
00228                            const int lev)
00229      { gu.extent-=(gu.finelev-lev);
00230        gu.crslev=lev; gu.finelev=lev; 
00231        gu.baselev = gu.finelev-gu.extent; gu.guSetBBox(); }
00232 
00233    inline void guSetRefineLevel(GridUnit& gu,
00234                                 const int levs=1)
00235      { gu.crslev=gu.finelev+gu.levstep; gu.finelev+=(levs*gu.levstep);
00236        gu.extent+=levs*gu.levstep; gu.baselev=gu.finelev-gu.extent; 
00237        gu.guSetBBox(); }
00238 
00239    inline void guSetCoarsen(GridUnit& gu,
00240                             const int levs=1)
00241      { gu.finelev-=(levs*gu.levstep); gu.extent-=levs*gu.levstep; 
00242        gu.baselev=gu.finelev-gu.extent; gu.guSetBBox(); }
00243    inline void guSetRefine(GridUnit& gu,
00244                            const int levs=1)
00245      { gu.finelev+=(levs*gu.levstep); gu.extent+=levs*gu.levstep; 
00246        gu.baselev=gu.finelev-gu.extent; gu.guSetBBox(); }
00247   };   
00248 
00249 std::ostream&  operator << (std::ostream& os, const GridUnit& gu);
00250 std::ofstream& operator << (std::ofstream& ofs, const GridUnit& gu);
00251 std::ifstream& operator >> (std::ifstream& ifs, GridUnit& gu);
00252 std::stringstream& operator << (std::stringstream& ofs, const GridUnit& gu);
00253 std::stringstream& operator >> (std::stringstream& ifs, GridUnit& gu);
00254 
00255 #endif

Generated on Fri Aug 24 13:00:29 2007 for AMROC's Hierachical Data Structures - by  doxygen 1.4.7