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


Main Page   Class Hierarchy   Compound List   File List  

GridUnitList.C

Go to the documentation of this file.
00001 
00006 #ifdef DEBUG_PRINT
00007 #include "CommServer.h" 
00008 #endif
00009 
00010 #include "GridUnitList.h"
00011 
00012 
00013 /*
00014 *************************************************************************
00015 *                                                                       *
00016 * GridUnitList constructors from an array of GridUnitLists per level    *
00017 * (The other constructors are in the GridUnitList.inline file)          *
00018 *                                                                       *
00019 *************************************************************************
00020 */
00021 GridUnitList::GridUnitList(GridUnitList**& levarray)
00022         : Bucket<GridUnit>(DefBucketSize), num(0)
00023   {
00024    register GridUnitList *gul = levarray[0];
00025    if (gul == GridUnitListNULL) return;
00026    register GridUnit const *tmpgu = gul->first();
00027    register const int nlev = tmpgu->guLevels();
00028 
00029    for (;tmpgu;tmpgu=gul->next()) add(*tmpgu);
00030 
00031    for (register int i=1;i<nlev;i++) {
00032      if (levarray[i])  {
00033        gul = levarray[i];
00034        tmpgu = gul->first();
00035        register GridUnit const *gu = first();
00036        for (;tmpgu;tmpgu=gul->next()) {
00037          //assert (tmpgu && gu);
00038          GridUnit helptmpgu = *tmpgu;
00039          for (;gu;gu=next()) {
00040            GridUnit helpgu = *gu;
00041            if (helptmpgu == helpgu)
00042              { refine(); gu=next(); break; }
00043            else if (helpgu >= helptmpgu) {
00044              if (helpgu.guExtent(helpgu.crslev) <= 0) {
00045                refine(); break;
00046              }
00047              else {  
00048                decompose(helptmpgu.baselev - helpgu.baselev);
00049              }
00050            }
00051            else if (helpgu <= helptmpgu)
00052              { gul->decompose(helpgu.baselev - helptmpgu.baselev); break; }
00053          }
00054          if (tmpgu && !gu) gu = first();
00055        }
00056      }
00057    }
00058   }
00059 
00060 /*
00061 *************************************************************************
00062 *                                                                       *
00063 * The overloaded assignment operator                                    *
00064 *                                                                       *
00065 *************************************************************************
00066 */
00067 
00068 GridUnitList& GridUnitList::operator = (const GridUnitList& cother)
00069   {
00070     GridUnitList &other = (GridUnitList &)cother;
00071     union record *tmpcur == other.currec();
00072     if (num != 0) empty();
00073     GridUnit *gu = 0;
00074     for (gu=other.first();gu;gu=other.next()) {
00075       add(*gu);
00076     }
00077 #ifdef DEBUG_PRINT
00078     assert(num==other.num);
00079 #endif
00080     other.setcurrec(tmpcur);
00081     return *this;
00082   }
00083 
00084 /*
00085 *************************************************************************
00086 *                                                                       *
00087 * Operate between GridUnitLists !                                       *
00088 * -= : difference (deletes all overlaps with the rhs)                   *
00089 * *= : intersetion                                                      *
00090 * The following allocate a new GUL and returns a pointer to it          *
00091 * -  : abs difference (returns a GUl with all GU in lhs or rhs but      *
00092        not both)                                                        *
00093 * *  : intersection                                                     *
00094 * +  : union                                                            *
00095 *                                                                       *
00096 *************************************************************************
00097 */
00098 
00099 void GridUnitList::operator -= (GridUnitList const &rhs)
00100   {
00101    GridUnitList *diff = this;
00102    GridUnitList r(rhs);
00103    register GridUnit const *rhsgu = r.first();
00104    register GridUnit *gu = diff->first();
00105    for (;rhsgu;rhsgu=r.next())  {
00106      GridUnit helprhsgu = *rhsgu;
00107      for (;gu;gu=diff->next()) {
00108        GridUnit helpgu = *gu;
00109        if (helprhsgu == helpgu)
00110          { diff->remove(); break; }
00111        else if (helpgu >= helprhsgu)
00112          diff->decompose(helprhsgu.baselev - helpgu.baselev);
00113        else if (helpgu <= helprhsgu)
00114          { r.decompose(helpgu.baselev - helprhsgu.baselev); break; }
00115      }
00116      if (!gu) {
00117        gu=diff->first();
00118      }
00119    }
00120   }
00121 
00122 GridUnitList *GridUnitList::operator - (GridUnitList const &rhs)
00123   {
00124    GridUnitList *diff = new GridUnitList(*this);
00125    GridUnitList r(rhs);
00126    GridUnitList tmpd;
00127    register GridUnit const *rhsgu = r.first();
00128    register GridUnit *gu = diff->first();
00129    for (;rhsgu;rhsgu=r.next())  {
00130      GridUnit helprhsgu = *rhsgu;
00131      for (;gu;gu=diff->next()) {
00132        GridUnit helpgu = *gu;
00133        if (helprhsgu == helpgu)
00134          { diff->remove(); break; }
00135        else if (helpgu >= helprhsgu)
00136          diff->decompose(helprhsgu.baselev - helpgu.baselev);
00137        else if (helpgu <= helprhsgu)
00138          { r.decompose(helpgu.baselev - helprhsgu.baselev); break; }
00139      }
00140      if (!gu) {
00141        tmpd.add(helprhsgu);
00142        gu=diff->first();
00143      }
00144    }
00145    register GridUnit const *tmpgu = tmpd.first();
00146    gu=diff->first();
00147    for (;tmpgu;tmpgu=tmpd.next()) {
00148      for (;gu;gu=diff->next()) {
00149        if (tmpgu->guBaseIndex() < gu->guBaseIndex())
00150          { diff->prev(); diff->insert(*tmpgu); gu = diff->next(); break; }
00151      }
00152      if (!gu) diff->add(*tmpgu);
00153    }
00154    
00155    return diff;
00156   }
00157 
00158 void GridUnitList::operator *= (GridUnitList const &rhs)
00159   {
00160    GridUnitList *intersect = this;
00161    GridUnitList r(rhs);
00162    register GridUnit const *rhsgu = r.first();
00163    register GridUnit *gu = intersect->first();
00164    for (;gu;gu=intersect->next()) {
00165      GridUnit helpgu = *gu;
00166      for (;rhsgu;rhsgu=r.next())  {
00167        GridUnit helprhsgu = *rhsgu;
00168        if (helprhsgu == helpgu) break;
00169        else if (helpgu >= helprhsgu)
00170          { intersect->decompose(helprhsgu.baselev - helpgu.baselev); break; }
00171        else if (helpgu <= helprhsgu)
00172          { r.decompose(helpgu.baselev - helprhsgu.baselev); }
00173      }
00174      if (!rhsgu) {
00175        intersect->remove();
00176        rhsgu = r.first();
00177      }
00178    }
00179   }
00180 
00181 GridUnitList *GridUnitList::operator * (GridUnitList const &rhs)
00182   {
00183    GridUnitList *intersect = new GridUnitList(*this);
00184    GridUnitList r(rhs);
00185    register GridUnit const *rhsgu = r.first();
00186    register GridUnit *gu = intersect->first();
00187    for (;gu;gu=intersect->next()) {
00188      GridUnit helpgu = *gu;
00189      for (;rhsgu;rhsgu=r.next())  {
00190        GridUnit helprhsgu = *rhsgu;
00191        if (helprhsgu == helpgu) break;
00192        else if (helpgu >= helprhsgu)
00193          { intersect->decompose(helprhsgu.baselev - helpgu.baselev); break; }
00194        else if (helpgu <= helprhsgu)
00195          { r.decompose(helpgu.baselev - helprhsgu.baselev); }
00196      }
00197      if (!rhsgu) {
00198        intersect->remove();
00199        rhsgu = r.first();
00200      }
00201    }
00202    
00203    return intersect;
00204   }
00205 
00206 GridUnitList *GridUnitList::operator + (GridUnitList const &rhs)
00207   {
00208    GridUnitList *sum = new GridUnitList(*this);
00209    GridUnitList r(rhs);
00210    GridUnitList tmpu;
00211    register GridUnit const *rhsgu = r.first();
00212    register GridUnit *gu = sum->first();
00213    for (;rhsgu;rhsgu=r.next())  {
00214      GridUnit helprhsgu = *rhsgu;
00215      for (;gu;gu=sum->next()) {
00216        GridUnit helpgu = *gu;
00217        if (helprhsgu == helpgu) break;
00218        else if (helpgu >= helprhsgu)
00219          sum->decompose(helprhsgu.baselev - helpgu.baselev);
00220        else if (helpgu <= helprhsgu)
00221          { r.decompose(helpgu.baselev - helprhsgu.baselev); break; }
00222      }
00223      if (!gu) {
00224        tmpu.add(helprhsgu);
00225        gu=sum->first();
00226      }
00227    }
00228 
00229    register GridUnit const *tmpgu = tmpu.first();
00230    gu=sum->first();
00231    for (;tmpgu;tmpgu=tmpu.next()) {
00232      for (;gu;gu=sum->next()) {
00233        if (tmpgu->guBaseIndex() < gu->guBaseIndex())
00234          { sum->prev(); sum->insert(*tmpgu); gu = sum->next(); break; }
00235      }
00236      if (!gu) sum->add(*tmpgu);
00237    }
00238    
00239    return sum;
00240   }
00241 
00242 /*
00243 *************************************************************************
00244 *                                                                       *
00245 * Operations with a BBox & BBoxList                                     *
00246 * *= : intersetion                                                      *
00247 * *  : intersection                                                     *
00248 * intersect : a more specialized intersection                           *
00249 * Note: * allocates a new GUL and returns a pointer to it               *
00250 *                                                                       *
00251 *************************************************************************
00252 */
00253 
00254 void GridUnitList::operator *= (BBox const &rhs)
00255   {
00256    if (rhs.empty()) {
00257      empty();
00258    }
00259    else {
00260      register GridUnit *gu = first();
00261      BBox bb;
00262      for (;gu;gu=next()) {
00263        int lev = gu->guFineLev();
00264        bb = gu->guBBox(lev);
00265        if (bb <= rhs) ;
00266        else if (!(bb*rhs).empty()) decompose();
00267        else remove(); 
00268      }
00269    }
00270   }
00271 
00272 GridUnitList *GridUnitList::operator * (BBox const &rhs)
00273   {
00274    GridUnitList *intersect = new GridUnitList;
00275 
00276    if (!rhs.empty()) {
00277      register GridUnit *gu = first();
00278      BBox bb;
00279      for (;gu;gu=next()) {
00280       int lev = gu->guFineLev();
00281        bb = gu->guBBox(lev);
00282        if (!(rhs * bb).empty()) {
00283           intersect->add(*gu);
00284        }
00285      }
00286    }
00287    return intersect;
00288   }
00289 
00290 GridUnitList *GridUnitList::operator * (BBoxList const &crhs)
00291   {
00292    BBoxList &rhs = (BBoxList &) crhs;
00293    union record *tmpcur == rhs.currec();
00294 
00295    GridUnitList *intersect = new GridUnitList;
00296 
00297    register BBox *rhsbb = 0;
00298 
00299    BBox bb;
00300    int lev = 0;
00301    register GridUnit *gu = first();
00302    for (;gu;gu=next()) {
00303      lev = gu->guFineLev();
00304      bb = gu->guBBox(lev);
00305      for (rhsbb=rhs.first();rhsbb;rhsbb=rhs.next()) {
00306        if (!rhsbb->empty() && !(*rhsbb * bb).empty()) {
00307          intersect->add(*gu);
00308          break;
00309        }
00310      }
00311    }
00312    rhs.setcurrec(tmpcur);
00313    return intersect;
00314   }
00315 
00316 void GridUnitList::intersect(BBox const &rhs, const int lev,
00317                              GridUnitList &gul, const int olap,
00318                              const int extgh)
00319   {
00320    gul.empty();
00321    if (!rhs.empty()) {
00322      register GridUnit *gu = first();
00323      BBox bb;
00324      for (;gu;gu=next()) {
00325        bb = gu->guBBox(lev,olap,extgh);
00326        if (!(rhs * bb).empty()) {
00327           gul.add(*gu);
00328        }
00329      }
00330    }
00331   }
00332 
00333 void GridUnitList::intersect(BBoxList const &crhs, const int lev,
00334                              GridUnitList &gul, const int olap, 
00335                              const int extgh)
00336   {
00337    BBoxList &rhs = (BBoxList &) crhs;
00338    union record *tmpcur == rhs.currec();
00339 
00340    gul.empty();
00341 
00342    register BBox *rhsbb = 0;
00343 
00344    BBox bb;
00345    register GridUnit *gu = first();
00346    for (;gu;gu=next()) {
00347      bb = gu->guBBox(lev,olap,extgh);
00348      if(!bb.empty()) { 
00349        for (rhsbb=rhs.first();rhsbb;rhsbb=rhs.next()) {
00350          if (!rhsbb->empty() && !(*rhsbb * bb).empty()) {
00351            gul.add(*gu);
00352            break;
00353          }
00354        }
00355      }
00356    }
00357 
00358    rhs.setcurrec(tmpcur);
00359   }
00360 
00361 void GridUnitList::intersect(BBox const &rhs, const int lev,
00362                              GridUnitList &gul, const short* olap,
00363                              const int extgh)
00364   {
00365    gul.empty();
00366    if (!rhs.empty()) {
00367      register GridUnit *gu = first();
00368      BBox bb;
00369      for (;gu;gu=next()) {
00370        bb = gu->guBBox(lev,olap,extgh);
00371        if (!(rhs * bb).empty()) {
00372           gul.add(*gu);
00373        }
00374      }
00375    }
00376   }
00377 
00378 void GridUnitList::intersect(BBoxList const &crhs, const int lev,
00379                              GridUnitList &gul, const short* olap, 
00380                              const int extgh)
00381   {
00382    BBoxList &rhs = (BBoxList &) crhs;
00383    union record *tmpcur == rhs.currec();
00384 
00385    gul.empty();
00386 
00387    register BBox *rhsbb = 0;
00388 
00389    BBox bb;
00390    register GridUnit *gu = first();
00391    for (;gu;gu=next()) {
00392      bb = gu->guBBox(lev,olap,extgh);
00393      if(!bb.empty()) { 
00394        for (rhsbb=rhs.first();rhsbb;rhsbb=rhs.next()) {
00395          if (!rhsbb->empty() && !(*rhsbb * bb).empty()) {
00396            gul.add(*gu);
00397            break;
00398          }
00399        }
00400      }
00401    }
00402 
00403    rhs.setcurrec(tmpcur);
00404   }
00405 
00406 /*
00407 *************************************************************************
00408 *                                                                       *
00409 * Set GridUnit information based on a sub GUL                           *
00410 *                                                                       *
00411 *************************************************************************
00412 */
00413 
00414 void GridUnitList::setindex(const GridUnitList& cgul, const int idx)
00415   {
00416    GridUnitList &gul = (GridUnitList &) cgul;
00417    union record *rhstmpcur == gul.currec();
00418    union record *tmpcur == currec();
00419 
00420    register GridUnit *rhsg = 0;
00421    for ( rhsg = gul.first(); rhsg != GridUnitNULL;  rhsg = gul.next() ) {
00422      register GridUnit *g = first();
00423      for ( ; g != GridUnitNULL;  g = next() )
00424        if (*g == *rhsg) { g->index = idx; break; }
00425    }
00426 
00427    gul.setcurrec(rhstmpcur);
00428    setcurrec(tmpcur);
00429   }
00430 
00431 void GridUnitList::setowner(const GridUnitList& cgul, const int p)
00432   {
00433    GridUnitList &gul = (GridUnitList &) cgul;
00434    union record *rhstmpcur == gul.currec();
00435    union record *tmpcur == currec();
00436 
00437    register GridUnit *rhsg = 0;
00438    for ( rhsg = gul.first(); rhsg != GridUnitNULL;  rhsg = gul.next() ) {
00439      register GridUnit *g = first();
00440      for ( ; g != GridUnitNULL;  g = next() )
00441        if (*g == *rhsg) { g->owner = p; break; }
00442    }
00443 
00444    gul.setcurrec(rhstmpcur);
00445    setcurrec(tmpcur);
00446   }
00447 
00448     
00449 /*
00450 *************************************************************************
00451 *                                                                       *
00452 * Get GUL for the levels                                                *
00453 * levellist : GUL for a paticular level                                 *
00454 * levelarray : An array of GULs for the levels                          *
00455 *                                                                       *
00456 *************************************************************************
00457 */
00458 
00459 void GridUnitList::levellist(GridUnitList &gul, const int lev)
00460   { 
00461     if(!gul.isempty()) gul.empty();
00462 
00463     register GridUnit *tmpgu = first();
00464     for (;tmpgu;tmpgu=next()) {
00465       if (tmpgu->guContains(lev)) {
00466         tmpgu->guSetLevels(*(gul.add(*tmpgu)),lev);
00467       }
00468     }
00469   }
00470 
00471 void GridUnitList::levellist(GridUnitList &gul, 
00472                              const int minlev,
00473                              const int maxlev)
00474   { 
00475     if(!gul.isempty()) gul.empty();
00476 
00477     register int flev = 0;
00478     register int clev = 0;
00479     register GridUnit *tmpgu = first();
00480     for (;tmpgu;tmpgu=next()) {
00481       flev = tmpgu->guFineLev();
00482       clev = tmpgu->guCrsLev();
00483       if (minlev > flev || maxlev < clev) continue;
00484       else if (maxlev >= flev) {
00485         tmpgu->guSetLevels(*(gul.add(*tmpgu)),flev);
00486       }
00487       else if (maxlev < flev) {
00488         tmpgu->guSetLevels(*(gul.add(*tmpgu)),maxlev);
00489       }
00490     }
00491   }
00492     
00493 void GridUnitList::levelarray(GridUnitList**& levarray, const int levels)
00494   { 
00495     if (!levarray) {
00496       levarray = new GridUnitList *[levels];
00497       for (register int i=0;i<levels;i++)
00498         levarray[i] = GridUnitListNULL;
00499     }
00500     else {
00501       for (register int i=0;i<levels;i++)
00502         if (levarray[i]) levarray[i]->empty();
00503     }
00504 
00505     register int idx = 0;
00506     register GridUnit *tmpgu = first();
00507     for (;tmpgu;tmpgu=next()) {
00508       for (register int l=tmpgu->crslev;
00509            l<=tmpgu->finelev;l+=tmpgu->levstep) {
00510         idx = tmpgu->guLevIndex(l);
00511         if (!levarray[idx]) 
00512           levarray[idx] = new GridUnitList(SimpleBucketVoid::blks(),0);
00513         tmpgu->guSetLevels(*(levarray[idx]->add(*tmpgu)),l);
00514       }
00515     }
00516   }
00517     
00518 /*
00519 *************************************************************************
00520 *                                                                       *
00521 * Get a BBoxList corresponding to a particular level                    *
00522 *                                                                       *
00523 *************************************************************************
00524 */
00525 void GridUnitList::bboxlistfinest(BBoxList &bbl, 
00526                                   const int lev) 
00527   {
00528     if(!bbl.isempty()) bbl.empty();
00529 
00530     register GridUnit *tmpgu = first();
00531     for (;tmpgu;tmpgu=next()) {
00532       if (tmpgu->guFineLev() == lev)
00533         bbl.add(tmpgu->guBBox());
00534     }
00535   }
00536 
00537 void GridUnitList::bboxlist(BBoxList &bbl, const int lev, 
00538                             const int olap) //, const int extgh)
00539   {
00540     const int extgh = 0;
00541     if(!bbl.isempty()) bbl.empty();
00542 
00543     register GridUnit *tmpgu = first();
00544     for (;tmpgu;tmpgu=next()) {
00545       bbl.add(tmpgu->guBBox(lev,olap,extgh));
00546     }
00547   }
00548 
00549 /* I actually want the bboxlist for the shadow (i.e. lev-levid) but only
00550    if the main (i.e. lev) exits */
00551 void GridUnitList::bboxlist(BBoxList &bbl, const int lev,
00552                             const int olap, const int levid)
00553                             //,const int extgh)
00554   {
00555     const int extgh = 0;
00556     if(!bbl.isempty()) bbl.empty();
00557 
00558     register GridUnit *tmpgu = first();
00559     for (;tmpgu;tmpgu=next()) {
00560       if (tmpgu->guContains(lev))
00561         bbl.add(tmpgu->guBBoxAbs(lev-levid,olap,extgh));
00562       else {
00563         (bbl.add())->setempty();
00564       }
00565     }
00566   }
00567 
00568 void GridUnitList::bboxlist(BBoxList &bbl, const int lev, 
00569                             const short* olap, const int extgh)
00570   {
00571     if(!bbl.isempty()) bbl.empty();
00572 
00573     GridUnit levgu;
00574     register GridUnit *tmpgu = first();
00575     for (;tmpgu;tmpgu=next()) {
00576       bbl.add(tmpgu->guBBox(lev,olap,extgh));
00577     }
00578   }
00579 
00580 /* I actually want the bboxlist for the shadow (i.e. lev-levid) but only
00581    if the main (i.e. lev) exits */
00582 void GridUnitList::bboxlist(BBoxList &bbl, const int lev,
00583                             const short* olap, const int levid, 
00584                             const int extgh)
00585   {
00586     if(!bbl.isempty()) bbl.empty();
00587 
00588     GridUnit levgu;
00589     register GridUnit *tmpgu = first();
00590     for (;tmpgu;tmpgu=next()) {
00591       if (tmpgu->guContains(lev))
00592         bbl.add(tmpgu->guBBoxAbs(lev-levid,olap,extgh));
00593       else {
00594         (bbl.add())->setempty();
00595       }
00596     }
00597   }
00598 
00599 /*
00600 *************************************************************************
00601 *                                                                       *
00602 * Refine the GUL                                                        *
00603 *                                                                       *
00604 *************************************************************************
00605 */
00606 
00607 GridUnitList *GridUnitList::refinelist(const int atlev, const int levs)
00608   {
00609    GridUnitList *refgul = new GridUnitList;
00610 
00611    GridUnitList levgul;
00612    levellist(levgul,atlev);
00613    register GridUnit *levgu = levgul.first();
00614    for (;levgu;levgu=levgul.next()) {
00615      levgu->guSetRefine(*(refgul->add(*levgu)),levs); 
00616    }
00617    return refgul;
00618   }
00619 
00620 GridUnitList *GridUnitList::refinelist(const BBoxList &cbblist, 
00621                                        const int atlev, 
00622                                        const int minw)
00623   {
00624    BBoxList bblist = cbblist;
00625    union record *tmpcur == bblist.currec();
00626 
00627    GridUnitList *refgul = new GridUnitList;
00628 
00629    GridUnitList levgul;
00630    levellist(levgul,atlev);
00631    register GridUnit *levgu = levgul.first();
00632    register BBox *bb = 0;
00633 
00634    for (;levgu;levgu=levgul.next()) {
00635      BBox levbb = levgu->guBBox(atlev);
00636      for (bb=bblist.first();bb;bb=bblist.next()) {
00637        BBox helpbb = *bb;
00638        if (!helpbb.empty()) {
00639          BBox interestion(helpbb * levbb);
00640          if (interestion.empty() ) { 
00641          }
00642          else if (helpbb == levbb) { 
00643            levgu->guSetRefine(*(refgul->add(*levgu))); 
00644            levgul.remove();
00645            break;
00646          }
00647          else if (interestion == levbb) { 
00648            levgu->guSetRefine(*(refgul->add(*levgu))); 
00649            levgul.remove();
00650            break;
00651          }
00652          else if (interestion < levbb && 
00653                   (levgu->guExtent(atlev) <= DefMinimumGUExtent || 
00654                    levgu->guExtentAbs(levgu->minlev) <= minw)) {
00655            levgu->guSetRefine(*(refgul->add(*levgu))); 
00656            levgul.remove();
00657            BBox bbhelp = helpbb+levbb;
00658            bb = bblist.insert(bbhelp);
00659            bblist.prev();
00660            // Changed --- RD
00661            // bblist.remove();
00662            // bblist.next();
00663            break;
00664          }
00665          else if (interestion < levbb && 
00666                   levgu->guExtent(atlev) > DefMinimumGUExtent &&
00667                   levgu->guExtentAbs(levgu->minlev) > minw) {
00668            levgul.decompose();
00669            break;
00670          }
00671        } 
00672      }
00673    }
00674    bblist.setcurrec(tmpcur);
00675    return refgul;
00676   }
00677 
00678 void GridUnitList::refinethislist(const BBoxList &cbblist, 
00679                                   const int atlev, 
00680                                   const int minw)
00681   {
00682    if (num == 0) return;
00683 
00684    BBoxList bblist = cbblist;
00685    union record *tmpcur == bblist.currec();
00686 
00687    register GridUnit *levgu = first();
00688    const int levstep = levgu->guLevStep();
00689 
00690    register BBox *bb = 0;
00691    register int fl = 0;
00692    register int levs = 0;
00693 
00694    for (;levgu;levgu=next()) {
00695      if ((fl=levgu->guFineLev()) > atlev) {
00696        levgu->guCoarsen((fl-atlev)/levstep);
00697        fl = levgu->guFineLev();
00698      }
00699      levs = 1 + (atlev-fl)/levstep;
00700      BBox levbb = levgu->guBBox(atlev);
00701 
00702      for (bb=bblist.first();bb;bb=bblist.next()) {
00703        BBox helpbb = *bb;
00704        if (!helpbb.empty()) {
00705          BBox interestion(helpbb * levbb);
00706          if (interestion.empty() ) { 
00707          }
00708          else if (helpbb == levbb) {     
00709            refine(levs); 
00710            break;
00711          }
00712          else if (interestion == levbb) { 
00713            refine(levs); 
00714            break;
00715          }
00716          else if (interestion < levbb && 
00717                   (levgu->guExtent(atlev) <= DefMinimumGUExtent || 
00718                    levgu->guExtentAbs(levgu->minlev) <= minw)) {
00719            refine(levs); 
00720            BBox bbhelp = helpbb+levbb;
00721            bb = bblist.insert(bbhelp);
00722            bblist.prev();
00723            // Changed --- RD
00724            // bblist.prev();
00725            // bblist.next();
00726            break;
00727          }
00728          else if (interestion < levbb && 
00729                   levgu->guExtent(atlev) > DefMinimumGUExtent &&
00730                   levgu->guExtentAbs(levgu->minlev) > minw) {
00731            decompose();
00732            break;
00733          }
00734        } 
00735      }
00736    }
00737    bblist.setcurrec(tmpcur);
00738   }
00739 
00740 /*
00741 *************************************************************************
00742 *                                                                       *
00743 * Operations on the current GU                                          *
00744 * decompose                                                             *
00745 *                                                                       *
00746 *************************************************************************
00747 */
00748 void GridUnitList::decompose(const int lev)
00749   {
00750    GridUnit *tmpgu = current();
00751    if (tmpgu == GridUnitNULL) return;
00752 
00753    const int cnt = 
00754      (tmpgu->guBaseIndex()).GetCardinality(lev);
00755 
00756    GridUnit helptmpgu = *tmpgu;
00757    if (cnt > 0) {
00758      for(register int i=cnt-1;i>=0;i--) {
00759        GridUnit* workgu = insert(helptmpgu);
00760        assert(workgu->extent>0 && workgu->levstep>0);
00761        helptmpgu.guSetDecompose(*workgu,lev,i);
00762        prev(); 
00763      }
00764      remove();
00765    }
00766   }
00767 
00768 /*
00769 *************************************************************************
00770 *                                                                       *
00771 *  The originally inlined methods                   *
00772 *                                                                       *
00773 *************************************************************************
00774 */
00775 unsigned long GridUnitList::load(const int olap)
00776   {
00777    unsigned long ld = 0;
00778    union record *tmpcur == currec();
00779    register GridUnit *g = first();
00780    for ( ; g != GridUnitNULL;  g = next() ) 
00781      { ld += g->guWork(olap); }
00782    setcurrec(tmpcur);
00783    return ld;
00784   }
00785 
00786 unsigned long GridUnitList::load(const int lev, const int olap) 
00787   {
00788    unsigned long ld = 0;
00789    union record *tmpcur == currec();
00790    register GridUnit *g = first();
00791    for ( ; g != GridUnitNULL;  g = next() ) 
00792      { ld += g->guWork(lev,olap); }
00793    setcurrec(tmpcur);
00794    return ld;
00795   }
00796 
00797 unsigned long GridUnitList::numelems(const int olap)
00798   {
00799    unsigned long gelem = 0;
00800    union record *tmpcur == currec();
00801    register GridUnit *g = first();
00802    for ( ; g != GridUnitNULL;  g = next() ) 
00803      { gelem += g->guNum(olap); }
00804    setcurrec(tmpcur);
00805    return gelem;
00806   }
00807 
00808 unsigned long GridUnitList::numelems(const int lev, const int olap)
00809   {
00810    unsigned long gelem = 0;
00811    union record *tmpcur == currec();
00812    register GridUnit *g = first();
00813    for ( ; g != GridUnitNULL;  g = next() ) 
00814      { gelem += g->guNum(lev,olap); }
00815    setcurrec(tmpcur);
00816    return gelem;
00817   }
00818 
00819 unsigned long GridUnitList::load(const short* olap)
00820   {
00821    unsigned long ld = 0;
00822    union record *tmpcur == currec();
00823    register GridUnit *g = first();
00824    for ( ; g != GridUnitNULL;  g = next() ) 
00825      { ld += g->guWork(olap); }
00826    setcurrec(tmpcur);
00827    return ld;
00828   }
00829 
00830 unsigned long GridUnitList::load(const int lev, const short* olap) 
00831   {
00832    unsigned long ld = 0;
00833    union record *tmpcur == currec();
00834    register GridUnit *g = first();
00835    for ( ; g != GridUnitNULL;  g = next() ) 
00836      { ld += g->guWork(lev,olap); }
00837    setcurrec(tmpcur);
00838    return ld;
00839   }
00840 
00841 unsigned long GridUnitList::numelems(const short* olap)
00842   {
00843    unsigned long gelem = 0;
00844    union record *tmpcur == currec();
00845    register GridUnit *g = first();
00846    for ( ; g != GridUnitNULL;  g = next() ) 
00847      { gelem += g->guNum(olap); }
00848    setcurrec(tmpcur);
00849    return gelem;
00850   }
00851 
00852 unsigned long GridUnitList::numelems(const int lev, const short* olap)
00853   {
00854    unsigned long gelem = 0;
00855    union record *tmpcur == currec();
00856    register GridUnit *g = first();
00857    for ( ; g != GridUnitNULL;  g = next() ) 
00858      { gelem += g->guNum(lev,olap); }
00859    setcurrec(tmpcur);
00860    return gelem;
00861   }
00862 
00863 int GridUnitList::levels(void)
00864   {
00865    int levels = 0;
00866    union record *tmpcur == currec();
00867    register GridUnit *g = first();
00868    if (g) levels = g->guLevels();
00869    setcurrec(tmpcur);
00870    return (levels);
00871   }
00872 
00873 int GridUnitList::finest(void)
00874   {
00875    int flev = 0;
00876    union record *tmpcur == currec();
00877    register GridUnit *g = first();
00878    for ( ; g != GridUnitNULL;  g = next() ) 
00879      { flev = (g->finelev > flev) ? g->finelev : flev; }
00880    setcurrec(tmpcur);
00881    return (flev);
00882   }
00883 
00884 int GridUnitList::smallest(const int level)
00885   {
00886    union record *tmpcur == currec();
00887    register GridUnit *g = first();
00888    int sext = 0;
00889    int e = 0;
00890    if (g) sext = g->guExtentAbs(level);
00891    for ( ; g != GridUnitNULL; g = next() ) 
00892      { sext = ((e=g->guExtentAbs(level)) < sext) ? e : sext; }
00893    setcurrec(tmpcur);
00894    return (sext);
00895   }
00896 
00897 int GridUnitList::highestbaselevel(void)
00898   {
00899    register int low=0;
00900    union record *tmpcur == currec();
00901    register GridUnit *g = first();
00902    if (g) low = g->baselev;
00903    for ( ; g != GridUnitNULL;  g = next() ) 
00904      { if (g->baselev > low)  low = g->baselev; }
00905    setcurrec(tmpcur);
00906    return (low);
00907   }
00908 
00909 dMapIndex GridUnitList::lowest(void)
00910   {
00911    dMapIndex low;
00912    union record *tmpcur == currec();
00913    register GridUnit *g = first();
00914    if (g) low = g->baseindex;
00915    for ( ; g != GridUnitNULL;  g = next() ) 
00916      { if (g->baseindex < low)  low = g->baseindex; }
00917    setcurrec(tmpcur);
00918    return (low);
00919   }
00920 
00921 dMapIndex GridUnitList::lowest(const int level, const int owner, const int index)
00922   {
00923    dMapIndex low;
00924    union record *tmpcur == currec();
00925    register GridUnit *g = first();
00926    for ( ; g != GridUnitNULL;  g = next() ) 
00927      if (g->owner == owner && g->index == index  &&
00928          g->guContains(level)) 
00929        { low = g->baseindex; break; }
00930    for ( ; g != GridUnitNULL;  g = next() )
00931      { if (g->owner == owner &&
00932            g->index == index  &&
00933            g->guContains(level) &&
00934            g->baseindex < low)  low = g->baseindex; }
00935    setcurrec(tmpcur);
00936    return (low);
00937   }
00938 
00939 int GridUnitList::maxindex()
00940   {
00941    union record *tmpcur == currec();
00942    register GridUnit *g = first();
00943    int mi = g->index;
00944    int i = 0;
00945    for ( ; g != GridUnitNULL;  g = next() ) 
00946      { mi = ((i=g->index) > mi) ? i : mi; }
00947    setcurrec(tmpcur);
00948    return (mi);
00949   }
00950 
00951 void GridUnitList::setindex(void)
00952   {
00953    register int idx = 0;
00954    union record *tmpcur == currec();
00955    register GridUnit *g = first();
00956    for ( ; g != GridUnitNULL;  idx++, g = next() ) 
00957      { g->index = idx; }
00958    setcurrec(tmpcur);
00959   }
00960 
00961 void GridUnitList::setindex(const int idx)
00962   {
00963    union record *tmpcur == currec();
00964    register GridUnit *g = first();
00965    for ( ; g != GridUnitNULL;  g = next() ) 
00966      { g->index = idx; }
00967    setcurrec(tmpcur);
00968   }
00969 
00970 void GridUnitList::setowner(const int p)
00971   {
00972    union record *tmpcur == currec();
00973    register GridUnit *g = first();
00974    for ( ; g != GridUnitNULL;  g = next() ) 
00975      { g->owner = p; }
00976    setcurrec(tmpcur);
00977   }
00978 
00979 void GridUnitList::setbbox()
00980   {
00981    union record *tmpcur == currec();
00982    register GridUnit *g = first();
00983    for ( ; g != GridUnitNULL;  g = next() ) 
00984      { g->guSetBBox(); }
00985    setcurrec(tmpcur);
00986   }
00987 
00988 void GridUnitList::split(GridUnitList& gul)
00989   {
00990    Bucket<GridUnit>::split((Bucket<GridUnit> &) gul); 
00991    gul.setstats();
00992    num -= gul.num;
00993   }
00994 
00995 
00996 /*
00997 *************************************************************************
00998 *                                                                       *
00999 * And overload << for the GUL class....                                 *
01000 *                                                                       *
01001 *************************************************************************
01002 */
01003 ostream&  operator << (ostream& os, const GridUnitList& cgul)
01004   {
01005    if (&cgul == GridUnitListNULL) return os;
01006 
01007    GridUnitList &gul = (GridUnitList &) cgul;
01008    union record *tmpcur == gul.currec();
01009  
01010    os << "Num:" << gul.num << " ";
01011    os <<  "\n";
01012 
01013    if (gul.num == 0) return os;
01014 
01015    GridUnit *g = 0;
01016    os << *gul.first();
01017    os << "\n**********************************\n";
01018 
01019    while ( (g=gul.next()) != GridUnitNULL ) {
01020         os << *g;
01021         os << "\n**********************************\n";
01022         os << flush;
01023    }
01024 
01025    gul.setcurrec(tmpcur);
01026 
01027    return os;
01028   }
01029 
01030 /*
01031 *************************************************************************
01032 *                                                                       *
01033 * And overload BINARY << for the GUL class....                                  *
01034 *                                                                       *
01035 *************************************************************************
01036 */
01037 
01038 ofstream&  operator << (ofstream& ofs, const GridUnitList& cgul)
01039   {
01040    if (&cgul == GridUnitListNULL) return ofs;
01041 
01042    GridUnitList &gul = (GridUnitList &) cgul;
01043    union record *tmpcur == gul.currec();
01044  
01045    ofs.write((char*)&gul.num,sizeof(int));
01046 
01047    if (gul.num == 0) return ofs;
01048    
01049    GridUnit *g = 0;
01050    for (g = gul.first(); g != GridUnitNULL; g = gul.next())
01051      ofs << *g;
01052 
01053    gul.setcurrec(tmpcur);
01054 
01055    return ofs;
01056   }
01057 
01058 ifstream&  operator >> (ifstream& ifs, GridUnitList& cgul)
01059   {
01060    if (&cgul == GridUnitListNULL) return ifs;
01061 
01062    GridUnitList &gul = (GridUnitList &) cgul;
01063    union record *tmpcur == gul.currec();
01064  
01065    int numin;
01066    ifs.read((char*)&numin,sizeof(int));
01067 
01068    if (numin == 0) return ifs;
01069 
01070    register GridUnit* gu = 0;
01071    for (register int n=0; n<numin; n++) {
01072      gu = gul.add();
01073      ifs >> *gu;
01074    }
01075 
01076    gul.setcurrec(tmpcur);
01077 
01078    return ifs;
01079   }
01080 
01081 strstream&  operator << (strstream& ofs, const GridUnitList& cgul)
01082   {
01083    if (&cgul == GridUnitListNULL) return ofs;
01084 
01085    GridUnitList &gul = (GridUnitList &) cgul;
01086    union record *tmpcur == gul.currec();
01087  
01088    ofs.write((char*)&gul.num,sizeof(int));
01089 
01090    if (gul.num == 0) return ofs;
01091    
01092    GridUnit *g = 0;
01093    for (g = gul.first(); g != GridUnitNULL; g = gul.next())
01094      ofs << *g;
01095 
01096    gul.setcurrec(tmpcur);
01097 
01098    return ofs;
01099   }
01100 
01101 strstream&  operator >> (strstream& ifs, GridUnitList& cgul)
01102   {
01103    if (&cgul == GridUnitListNULL) return ifs;
01104 
01105    GridUnitList &gul = (GridUnitList &) cgul;
01106    union record *tmpcur == gul.currec();
01107  
01108    int numin;
01109    ifs.read((char*)&numin,sizeof(int));
01110 
01111    if (numin == 0) return ifs;
01112 
01113    register GridUnit* gu = 0;
01114    for (register int n=0; n<numin; n++) {
01115      gu = gul.add();
01116      ifs >> *gu;
01117    }
01118 
01119    gul.setcurrec(tmpcur);
01120 
01121    return ifs;
01122   }


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



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