BoundedGrid.h

00001 #ifndef gridripper_amr1d_BoundedGrid_h
00002 #define gridripper_amr1d_BoundedGrid_h
00003 
00004 #include "Grid.h"
00005 #include <gridripper/lang/IllegalArgumentException.h>
00006 #include <gridripper/tvalarray.h>
00007 
00008 namespace gridripper { namespace amr1d {
00009 
00010 using namespace std;
00011 
00018 class BoundedGrid: public Grid
00019 {
00020 private:
00022     int marginLeft;
00023 
00025     int marginRight;
00026 
00028     int marginDecreaseLeft;
00029 
00031     int marginDecreaseRight;
00032 
00034     int leftmostI;
00035 
00037     int rightmostI;
00038 
00040     int numPointsAboveMaxX;
00041 
00042     bool insidePeriodicGrid;
00043 
00044 protected:
00049     BoundedGrid(const BoundedGrid& g);
00050 
00054     BoundedGrid(const BoundedGrid& p,
00055                 int dmargin_L, int dmargin_R, GReal_t xshift);
00056 
00068     BoundedGrid(Grid* p, int r1, int loci, int maxi, int margin,
00069                           int vmargin, int minLevel);
00070 
00071 public:
00075     BoundedGrid(GReal_t minx, GReal_t maxx, int maxi, int npabovemax,
00076                 int nc, Integrator* proto, Regridder* refproto, int r);
00077 
00082     Grid* cloneGrid() const {
00083         return new BoundedGrid(*this);
00084     }
00085 
00086     int getLeftmostI() const {
00087         return leftmostI;
00088     }
00089 
00090     int getRightmostI() const {
00091         return rightmostI;
00092     }
00093 
00094     bool isPeriodic() const {
00095         return false;
00096     }
00097 
00103     int getMarginLeft(int ir) const {
00104         return marginLeft - ir*marginDecreaseLeft;
00105     }
00106 
00112     int getMarginRight(int ir) const {
00113         return marginRight - ir*marginDecreaseRight;
00114     }
00115 
00122     int distanceFromLeft(int i) const {
00123         return i + marginLeft;
00124     }
00125 
00132     int distanceFromRight(int i) const {
00133         return getMaxI() + marginRight - i;
00134     }
00135 
00140     virtual int getNumPointsAboveMaxX() const {
00141         return numPointsAboveMaxX;
00142     }
00143 
00148     GReal_t getLocationX(int i) const;
00149 
00154     GReal_t getSizeX() const {
00155         return getMaxI()*getDeltaX();
00156     }
00157 
00158 public:
00162     void initRefinedDataExistenceArray();
00163 
00169     bool hasRefinedData(int i) const {
00170         if(refinedDataExists.size() == 0) {
00171             return false;
00172         }
00173         int ml = marginLeft;
00174         int r = getRefinementRatio();
00175         int j = r*ml + i;
00176         if(j >= 0 && j < (int)refinedDataExists.size()) {
00177             return refinedDataExists[j];
00178         } else {
00179             return false;
00180         }
00181     }
00182 
00188     void getRefinedData(int i, GReal_t yout[]) const {
00189         int ml = marginLeft;
00190         int r = getRefinementRatio();
00191         unsigned nc = getNumComponents();
00192         int k = nc*(r*ml + i);
00193         for(unsigned i = 0; i < nc; ++i) {
00194             yout[i] = theData[k + i];
00195         }
00196     }
00197 
00198     Grid* createTemporaryGrid(int dmargin_L, int dmargin_R, GReal_t xshift) {
00199         return new BoundedGrid(*this, dmargin_L, dmargin_R, xshift);
00200     }
00201 
00208     void setTemporaryGridMargins(const Grid& p, int dmargin_L, int dmargin_R);
00209 
00221     Grid* createRefinedGrid(IntervalList* iv, int margin,
00222                             int vmargin, int minLevel, int r1);
00223 
00224     void interpolateMargins(PDE* pde);
00225 
00226     int getAbsoluteIndex(int i, int mul) const;
00227 
00228 protected:
00229     int getInternalIndex(int i) const {
00230         return i + marginLeft;
00231     }
00232 
00233     int getSubgridIndexFromIndex(const Grid* g, int i) const {
00234         int r = getRefinementRatio();
00235         int j = r*i - g->getLocationI();
00236         return j;
00237     }
00238 
00239     int getIndexFromSubgridIndex(const Grid* g, int j) const {
00240         int r = getRefinementRatio();
00241         int i = (g->getLocationI() + j)/r;
00242         return i;
00243     }
00244 
00249     void fillRefinedDataArray();
00250 
00257     void blur(tvalarray<unsigned char>& pf, int i) const;
00258 
00264     int getFirstIndexForRefinement(const tvalarray<unsigned char>& pf) const {
00265         return 0;
00266     }
00267 
00274     int findIntervalEndForRefinement(const tvalarray<unsigned char>& pf, int i)
00275                                      const;
00276 
00277     int intervalRefinedSize(const IntervalList* iv, int r) const;
00278 
00279     int gridIndexLeftOf(int i, int dmax) const {
00280         return i > dmax? i - dmax : 0;
00281     }
00282 
00283     int gridIndexRightOf(int i, int dmax) const {
00284         return i < getMaxI() - dmax? i + dmax : getMaxI();
00285     }
00286 
00291     void fixSubgridNearBounds(IntervalList* left, IntervalList* right,
00292                               int margin) const;
00293 
00302     int calcNewSubSubgridLocation(int ssloc, int osloc, int nsloc) {
00303         return ssloc + getRefinementRatio()*(osloc - nsloc);
00304     }
00305 };
00306 
00307 } } // namespace gridripper::amr1d
00308 
00309 #endif /* gridripper_amr1d_BoundedGrid_h */

Generated on Wed Jun 17 18:46:47 2009 for GridRipper by  doxygen 1.5.6