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


Main Page   Class Hierarchy   Compound List   File List  

DAGHGhostInteraction.C

Go to the documentation of this file.
00001 
00006 #include "DAGHGhostInteraction.h"
00007 
00008 static int ipow(int b, int p)
00009  {
00010    register int tmpr = 1;
00011    while (p--) tmpr *= b;
00012    return tmpr;
00013  }
00014 
00015 GhostInteraction::GhostInteraction( const int rank, 
00016                                     const int type,
00017                                     const int width )
00018         : Irank(rank), Itype(type), Iwidth(2*width+1),
00019           Iinside(DAGHNull),
00020           FaceFlag(0), CornerFlag(0), EdgeFlag(0),
00021           SimpleFlag(DAGHFalse)
00022   {
00023    assert( Itype == DAGHGhostInteraction );
00024 
00025    Itotal = ipow( Iwidth , Irank ); 
00026 
00027    /* Initialise.... */
00028    for (register int a=0 ; a<DAGHMaxAxis ; a++ ) {
00029      for (register int d=0 ; d<DAGHMaxDirs ; d++ ) {
00030        if (a < rank || a == DAGH_All) {
00031          Ilists[a][d] = new short [Itotal];
00032          for (register int i=0 ; i<Itotal ; i++ ) {
00033             Ilists[a][d][i] = DAGHFalse;
00034          }
00035        }
00036        else {
00037          Ilists[a][d] = 0;
00038        }
00039      }
00040    }
00041    Iface_cnt = 2*Irank;
00042    Ifaces = new short[Iface_cnt];
00043   }
00044 
00045 GhostInteraction::GhostInteraction( const int rank, 
00046                                     const int fflag,
00047                                     const int cflag, 
00048                                     const int eflag,
00049                                     const int type,
00050                                     const int width,
00051                                     const int simple )
00052         : Irank(rank), Itype(type), Iwidth(2*width+1),
00053           Iinside(DAGHNull),
00054           FaceFlag(fflag), CornerFlag(cflag), EdgeFlag(eflag),
00055           SimpleFlag(simple)
00056   {
00057    assert( Itype == DAGHGhostInteraction );
00058 
00059    Itotal = ipow( Iwidth , Irank ); 
00060 
00061    /* Initialise.... */
00062    for (register int a=0 ; a<DAGHMaxAxis ; a++ ) {
00063      for (register int d=0 ; d<DAGHMaxDirs ; d++ ) {
00064        if (a < Irank || a == DAGH_All) {
00065          Ilists[a][d] = new short [Itotal];
00066          for (register int i=0 ; i<Itotal ; i++ ) {
00067             Ilists[a][d][i] = DAGHFalse;
00068          }
00069        }
00070        else {
00071          Ilists[a][d] = 0;
00072        }
00073      }
00074    }
00075    Iface_cnt = 2*Irank;
00076    Ifaces = new short[Iface_cnt];
00077 
00078    /* Setup Counts */
00079    int all_axis_cnt = 0;
00080    /* DAGH_X, DAGH_Y, & DAGH_Z */
00081    register int i;
00082    for (i=0 ; i<Irank ; i++ ) {
00083      /* FORWARD & BACKWARD */
00084      Icounts[i][DAGH_Backward] =  Icounts[i][DAGH_Forward] 
00085        = ipow( Iwidth , Irank-1 );
00086      /* BOTH */
00087      Icounts[i][DAGH_Both] =  2*ipow( Iwidth , Irank-1 );
00088      all_axis_cnt += ipow( Iwidth , Irank-1-i ) * ipow( Iwidth-1 , i );
00089    }
00090    /* DAGH_All */
00091    Icounts[DAGH_All][0] = all_axis_cnt;
00092    Icounts[DAGH_All][1] = all_axis_cnt;
00093    Icounts[DAGH_All][2] =  Itotal-1;
00094 
00095    register int x, y, z;
00096    /* Fill In */
00097    const int Ir = width;
00098    for (i=0 ; i<Itotal ; i++ ) {
00099       x = (Irank == 3) ? (i/ipow(Iwidth,Irank-1))%Iwidth : 
00100           (Irank == 2) ? (i/Iwidth)%Iwidth : i%Iwidth;
00101       y = (Irank == 3) ? (i/Iwidth)%Iwidth : (Irank == 2) ? i%Iwidth : Ir;
00102       z = (Irank == 3) ? i%Iwidth : Ir;
00103 
00104       if ( is_inside(x,y,z) ) {
00105          Iinside = i;
00106          continue;
00107       }
00108 
00109       if (is_face(x,y,z)) {
00110          int idx = (x!=1) ? (2*DAGH_X)+(x/2) : 
00111                    (y!=1) ? (2*DAGH_Y)+(y/2) : 
00112                             (2*DAGH_Z)+(z/2) ;
00113          Ifaces[idx] = i;
00114       }
00115 
00116       if ( !FaceFlag && is_face(x,y,z)) continue;
00117       if ( !CornerFlag && is_corner(x,y,z)) continue;
00118       if ( !EdgeFlag && is_edge(x,y,z)) continue;
00119 
00120       if ( x==0 ) {
00121         Ilists[DAGH_X][DAGH_Backward][i] = DAGHTrue;
00122         Ilists[DAGH_X][DAGH_Both][i] = DAGHTrue;
00123         Ilists[DAGH_All][DAGH_Backward][i] = DAGHTrue;
00124         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00125       }
00126       else if ( x==2 ) {
00127         Ilists[DAGH_X][DAGH_Forward][i] = DAGHTrue;
00128         Ilists[DAGH_X][DAGH_Both][i] = DAGHTrue;
00129         Ilists[DAGH_All][DAGH_Forward][i] = DAGHTrue;
00130         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00131       }
00132 
00133       if ( y==0 ) {
00134         Ilists[DAGH_Y][DAGH_Backward][i] = DAGHTrue;
00135         Ilists[DAGH_Y][DAGH_Both][i] = DAGHTrue;
00136         Ilists[DAGH_All][DAGH_Backward][i] = DAGHTrue;
00137         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00138       }
00139       else if ( y==2 ) {
00140         Ilists[DAGH_Y][DAGH_Forward][i] = DAGHTrue;
00141         Ilists[DAGH_Y][DAGH_Both][i] = DAGHTrue;
00142         Ilists[DAGH_All][DAGH_Forward][i] = DAGHTrue;
00143         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00144       }
00145 
00146       if ( z==0 ) {
00147         Ilists[DAGH_Z][DAGH_Backward][i] = DAGHTrue;
00148         Ilists[DAGH_Z][DAGH_Both][i] = DAGHTrue;
00149         Ilists[DAGH_All][DAGH_Backward][i] = DAGHTrue;
00150         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00151       }
00152       else if ( z==2 ) {
00153         Ilists[DAGH_Z][DAGH_Forward][i] = DAGHTrue;
00154         Ilists[DAGH_Z][DAGH_Both][i] = DAGHTrue;
00155         Ilists[DAGH_All][DAGH_Forward][i] = DAGHTrue;
00156         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00157       }
00158    }
00159   }
00160 
00161 GhostInteraction::GhostInteraction( const GhostInteraction &other)
00162         : Irank(other.Irank), Itype(other.Itype), Iwidth(other.Iwidth),
00163           Itotal(other.Itotal), Iinside(other.Iinside),
00164           Iface_cnt(other.Iface_cnt), Ifaces(0),
00165           //Iface_cnt(other.Iface_cnt), Ifaces(0),
00166           //Icorner_cnt(other.Icorner_cnt), Icorners(0),
00167           //Iedge_cnt(other.Iedge_cnt), Iedges(0),
00168           FaceFlag(other.FaceFlag), 
00169           CornerFlag(other.CornerFlag), 
00170           EdgeFlag(other.EdgeFlag),
00171           SimpleFlag(other.SimpleFlag)
00172   {  
00173    register int a;
00174    for (a=0 ; a<DAGHMaxAxis ; a++ ) {
00175      for (register int d=0 ; d<DAGHMaxDirs ; d++ ) {
00176        Icounts[a][d] = other.Icounts[a][d];
00177        if (other.Ilists[a][d]) {
00178          Ilists[a][d] = new short [Itotal];
00179          for (register int i=0 ; i<Itotal ; i++ )
00180             Ilists[a][d][i] = other.Ilists[a][d][i];
00181        }
00182        else {
00183          Ilists[a][d] = 0;
00184        }
00185      }
00186    }
00187    Ifaces = new short[Iface_cnt];
00188    for (a=0 ; a<Iface_cnt ; a++) {
00189      Ifaces[a] = other.Ifaces[a];
00190    }
00191   }
00192 
00193 GhostInteraction::~GhostInteraction( )
00194  {
00195    for (register int a=0 ; a<DAGHMaxAxis ; a++ ) {
00196      for (register int d=0 ; d<DAGHMaxDirs ; d++ ) {
00197        if (Ilists[a][d]) delete [] Ilists[a][d];  
00198      }
00199    }
00200    if (Ifaces) delete [] Ifaces;
00201  }
00202 
00203 void GhostInteraction::compute_interactions( const int fflag,
00204                                              const int cflag, 
00205                                              const int eflag,
00206                                              const int simple)
00207   {
00208    FaceFlag = fflag;
00209    CornerFlag = cflag;
00210    EdgeFlag = eflag;
00211 
00212    SimpleFlag = simple;
00213 
00214    /* Setup Counts */
00215    int all_axis_cnt = 0;
00216    /* DAGH_X, DAGH_Y, & DAGH_Z */
00217    register int i;
00218    for (i=0 ; i<Irank ; i++ ) {
00219      /* FORWARD & BACKWARD */
00220      Icounts[i][DAGH_Backward] = Icounts[i][DAGH_Forward]
00221        = ipow( Iwidth , Irank-1 );
00222      /* BOTH */
00223      Icounts[i][DAGH_Both] =  2*ipow( Iwidth , Irank-1 );
00224      all_axis_cnt += ipow( Iwidth , Irank-1-i ) * ipow( Iwidth-1 , i );
00225    }
00226    /* DAGH_All */
00227    Icounts[DAGH_All][0] = all_axis_cnt;
00228    Icounts[DAGH_All][1] = all_axis_cnt;
00229    Icounts[DAGH_All][2] =  Itotal-1;
00230 
00231    register int x, y, z;
00232    /* Fill In */
00233    const int Ir = (Iwidth-1)/2;
00234    for (i=0 ; i<Itotal ; i++ ) {
00235       x = (Irank == 3) ? (i/ipow(Iwidth,Irank-1))%Iwidth : 
00236           (Irank == 2) ? (i/Iwidth)%Iwidth : i%Iwidth;
00237       y = (Irank == 3) ? (i/Iwidth)%Iwidth : (Irank == 2) ? i%Iwidth : Ir;
00238       z = (Irank == 3) ? i%Iwidth : Ir;
00239 
00240       if ( is_inside(x,y,z) ) {
00241          Iinside = i;
00242          continue;
00243       }
00244 
00245       if (is_face(x,y,z)) {
00246          int idx = (x!=1) ? (2*DAGH_X)+(x/2) : 
00247                    (y!=1) ? (2*DAGH_Y)+(y/2) : 
00248                             (2*DAGH_Z)+(z/2) ;
00249          Ifaces[idx] = i;
00250       }
00251 
00252       if ( !FaceFlag && is_face(x,y,z)) continue;
00253       if ( !CornerFlag && is_corner(x,y,z)) continue;
00254       if ( !EdgeFlag && is_edge(x,y,z)) continue;
00255 
00256       if ( x==0 ) {
00257         Ilists[DAGH_X][DAGH_Backward][i] = DAGHTrue;
00258         Ilists[DAGH_X][DAGH_Both][i] = DAGHTrue;
00259         Ilists[DAGH_All][DAGH_Backward][i] = DAGHTrue;
00260         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00261       }
00262       else if ( x==2 ) {
00263         Ilists[DAGH_X][DAGH_Forward][i] = DAGHTrue;
00264         Ilists[DAGH_X][DAGH_Both][i] = DAGHTrue;
00265         Ilists[DAGH_All][DAGH_Forward][i] = DAGHTrue;
00266         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00267       }
00268 
00269       if ( y==0 ) {
00270         Ilists[DAGH_Y][DAGH_Backward][i] = DAGHTrue;
00271         Ilists[DAGH_Y][DAGH_Both][i] = DAGHTrue;
00272         Ilists[DAGH_All][DAGH_Backward][i] = DAGHTrue;
00273         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00274       }
00275       else if ( y==2 ) {
00276         Ilists[DAGH_Y][DAGH_Forward][i] = DAGHTrue;
00277         Ilists[DAGH_Y][DAGH_Both][i] = DAGHTrue;
00278         Ilists[DAGH_All][DAGH_Forward][i] = DAGHTrue;
00279         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00280       }
00281 
00282       if ( z==0 ) {
00283         Ilists[DAGH_Z][DAGH_Backward][i] = DAGHTrue;
00284         Ilists[DAGH_Z][DAGH_Both][i] = DAGHTrue;
00285         Ilists[DAGH_All][DAGH_Backward][i] = DAGHTrue;
00286         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00287       }
00288       else if ( z==2 ) {
00289         Ilists[DAGH_Z][DAGH_Forward][i] = DAGHTrue;
00290         Ilists[DAGH_Z][DAGH_Both][i] = DAGHTrue;
00291         Ilists[DAGH_All][DAGH_Forward][i] = DAGHTrue;
00292         Ilists[DAGH_All][DAGH_Both][i] = DAGHTrue;
00293       }
00294    }
00295   }
00296 
00297 BBox GhostInteraction::Ibbox(BBox const &mybb, const int dir, short const *rad) const
00298  {
00299    if (mybb.empty()) return mybb;
00300 
00301    const int Ir = (Iwidth-1)/2;
00302    const int x = -Ir + ((Irank == 3) ? (dir/ipow(Iwidth,Irank-1))%Iwidth : 
00303                         (Irank == 2) ? (dir/Iwidth)%Iwidth : dir%Iwidth);
00304    const int y = -Ir + ((Irank == 3) ? (dir/Iwidth)%Iwidth : 
00305                         (Irank == 2) ? dir%Iwidth : Ir);
00306    const int z = -Ir + ((Irank == 3) ? dir%Iwidth : Ir);
00307 
00308    Coords const step = mybb.stepsize();
00309    BBox gbb(mybb);
00310 
00311    if ( x < 0 ) {
00312      gbb.lower(0) += x * rad[2*DAGH_X] * step(0);
00313      gbb.upper(0) = mybb.lower(0) - step(0);
00314    }
00315    else if ( x > 0 ) {
00316      gbb.lower(0) = mybb.upper(0) + step(0);
00317      gbb.upper(0) += x * rad[2*DAGH_X+1] * step(0);
00318    }
00319    
00320    if ( y < 0 ) {
00321      gbb.lower(1) += y * rad[2*DAGH_Y] * step(1);
00322      gbb.upper(1) = mybb.lower(1) - step(1);
00323    }
00324    else if ( y > 0 ) {
00325      gbb.lower(1) = mybb.upper(1) + step(1);
00326      gbb.upper(1) += y * rad[2*DAGH_Y+1] * step(1);
00327    }
00328    
00329    if ( z < 0 ) {
00330      gbb.lower(2) += z * rad[2*DAGH_Z] * step(2);
00331      gbb.upper(2) = mybb.lower(2) - step(2);
00332    }
00333    else if ( z > 0 ) {
00334      gbb.lower(2) = mybb.upper(2) + step(2);
00335      gbb.upper(2) += z * rad[2*DAGH_Z+1] * step(2);
00336    }
00337 
00338    return gbb;
00339  }
00340 
00341 BBox GhostInteraction::Ibbox(BBox const &mybb, 
00342                              const int Axis, const int Dir, 
00343                              short const *rad) const
00344  {
00345    if (mybb.empty()) return mybb;
00346 
00347    const short* ll = Ilists[Axis][Dir];
00348    BBox whole_gbb;
00349 
00350    for ( register int idir = 0 ; idir < Itotal ; idir++ ) {
00351 
00352    if ( ll[idir] != DAGHTrue ) continue;
00353 
00354    const int dir = idir;
00355    
00356    const int Ir = (Iwidth-1)/2;
00357    const int x = -Ir + ((Irank == 3) ? (dir/ipow(Iwidth,Irank-1))%Iwidth : 
00358                         (Irank == 2) ? (dir/Iwidth)%Iwidth : dir%Iwidth);
00359    const int y = -Ir + ((Irank == 3) ? (dir/Iwidth)%Iwidth : 
00360                         (Irank == 2) ? dir%Iwidth : Ir);
00361    const int z = -Ir + ((Irank == 3) ? dir%Iwidth : Ir);
00362 
00363    Coords const step = mybb.stepsize();
00364    BBox gbb(mybb);
00365 
00366    if ( x < 0 ) {
00367      gbb.lower(0) += x * rad[2*DAGH_X] * step(0);
00368      gbb.upper(0) = mybb.lower(0) - step(0);
00369    }
00370    else if ( x > 0 ) {
00371      gbb.lower(0) = mybb.upper(0) + step(0);
00372      gbb.upper(0) += x * rad[2*DAGH_X+1] * step(0);
00373    }
00374    
00375    if ( y < 0 ) {
00376      gbb.lower(1) += y * rad[2*DAGH_Y] * step(1);
00377      gbb.upper(1) = mybb.lower(1) - step(1);
00378    }
00379    else if ( y > 0 ) {
00380      gbb.lower(1) = mybb.upper(1) + step(1);
00381      gbb.upper(1) += y * rad[2*DAGH_Y+1] * step(1);
00382    }
00383    
00384    if ( z < 0 ) {
00385      gbb.lower(2) += z * rad[2*DAGH_Z] * step(2);
00386      gbb.upper(2) = mybb.lower(2) - step(2);
00387    }
00388    else if ( z > 0 ) {
00389      gbb.lower(2) = mybb.upper(2) + step(2);
00390      gbb.upper(2) += z * rad[2*DAGH_Z+1] * step(2);
00391    }
00392 
00393    whole_gbb += gbb;
00394 
00395    }
00396    return whole_gbb;
00397  }
00398 
00399 BBox GhostInteraction::IbboxFrom(BBox const &mybb, const int dir, 
00400                                  short const *rad, const short* olap) const
00401  {
00402    if (mybb.empty()) return mybb;
00403 
00404    const int Ir = (Iwidth-1)/2;
00405    const int x = -Ir + ((Irank == 3) ? (dir/ipow(Iwidth,Irank-1))%Iwidth : 
00406                         (Irank == 2) ? (dir/Iwidth)%Iwidth : dir%Iwidth);
00407    const int y = -Ir + ((Irank == 3) ? (dir/Iwidth)%Iwidth : 
00408                         (Irank == 2) ? dir%Iwidth : Ir);
00409    const int z = -Ir + ((Irank == 3) ? dir%Iwidth : Ir);
00410 
00411    Coords const step = mybb.stepsize();
00412    Coords const cl = mybb.lower();
00413    Coords const cu = mybb.upper();
00414 
00415    BBox gbb(mybb);
00416 
00417    if ( x < 0 ) {
00418      gbb.lower(0) += olap[0] * step(0);
00419      gbb.upper(0) = cl(0) - (x * rad[2*DAGH_X+1] * step(0)) - (1-olap[0]) * step(0);
00420    }
00421    else if ( x > 0 ) {
00422      gbb.lower(0) = cu(0) - (x * rad[2*DAGH_X] * step(0)) + (1-olap[0]) * step(0);
00423      gbb.upper(0) -= olap[0] * step(0);
00424    }
00425    
00426    if ( y < 0 ) {
00427      gbb.lower(1) += olap[1] * step(1);
00428      gbb.upper(1) = cl(1) - (y * rad[2*DAGH_Y+1] * step(1)) - (1-olap[1]) * step(1);
00429    }
00430    if ( y > 0 ) {
00431      gbb.lower(1) = cu(1) - (y * rad[2*DAGH_Y] * step(1)) + (1-olap[1]) * step(1);
00432      gbb.upper(1) -= olap[1] * step(1);
00433    }
00434    
00435    if ( z < 0 ) {
00436      gbb.lower(2) += olap[2] * step(2);
00437      gbb.upper(2) = cl(2) - (z * rad[2*DAGH_Z+1] * step(2)) - (1-olap[2]) * step(2);
00438    }
00439    if ( z > 0 ) {
00440      gbb.lower(2) = cu(2) - (z * rad[2*DAGH_Z] * step(2)) + (1-olap[2]) * step(2);
00441      gbb.upper(2) -= olap[2] * step(2);
00442    }
00443 
00444    return gbb;
00445  }
00446 
00447 ostream& operator << (ostream& os, GhostInteraction const & gi)
00448  {
00449    os << "[IRank:" << gi.Irank << "]"; 
00450    os << "[IWidth:" << gi.Iwidth << "]"; 
00451    os << "[ITotal:" << gi.Itotal << "]"; 
00452    os << "[IInside:" << gi.Iinside << "]"; 
00453    os << endl;
00454    os << "***** FACES *****" << endl;
00455    register int r;
00456    for(r=0;r<gi.Irank;r++) {
00457      os << "[AXIS: " << r << "] "; 
00458      os << "[ ";
00459      os << gi.Ifaces[2*r] << " ";
00460      os << gi.Ifaces[2*r+1] << " ";
00461      os << "]" << endl;
00462    }
00463    os << "***** BACKWARD *****" << endl;
00464    for(r=0;r<DAGHMaxAxis;r++) {
00465      if (!gi.Ilists[r][DAGH_Backward]) continue;
00466      os << "[AXIS: " << r << "] "; 
00467      os << "[CNT: " << gi.Icounts[r][DAGH_Backward] << "] "; 
00468      os << "[ ";
00469      for(register int i=0;i<gi.Itotal;i++) 
00470        if (gi.Ilists[r][DAGH_Backward][i]) os << i << " ";
00471      os << "]" << endl;
00472    }
00473    os << "***** FORWARD *****" << endl;
00474    for(r=0;r<DAGHMaxAxis;r++) {
00475      if (!gi.Ilists[r][DAGH_Forward]) continue;
00476      os << "[AXIS: " << r << "] "; 
00477      os << "[CNT: " << gi.Icounts[r][DAGH_Forward] << "] "; 
00478      os << "[ ";
00479      for(register int i=0;i<gi.Itotal;i++) 
00480        if (gi.Ilists[r][DAGH_Forward][i]) os << i << " ";
00481      os << "]" << endl;
00482    }
00483    os << "***** BOTH *****" << endl;
00484    for(r=0;r<DAGHMaxAxis;r++) {
00485      if (!gi.Ilists[r][DAGH_Both]) continue;
00486      os << "[AXIS: " << r << "] "; 
00487      os << "[CNT: " << gi.Icounts[r][DAGH_Both] << "] "; 
00488      os << "[ ";
00489      for(register int i=0;i<gi.Itotal;i++) 
00490        if (gi.Ilists[r][DAGH_Both][i]) os << i << " ";
00491      os << "]" << endl;
00492    }
00493 
00494    return os;
00495  }


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



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