Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

feVector.txx

Go to the documentation of this file.
00001 
00002 template <typename T>
00003 feVector<T>::feVector() {
00004   m_daType = PETSC;
00005   m_DA          = NULL;
00006   m_octDA       = NULL;
00007   m_stencil     = NULL;
00008   m_uiDof       = 1;
00009   m_ucpLut      = NULL;
00010 
00011   // initialize the stencils ...
00012   initStencils();
00013 }
00014 
00015 template <typename T>
00016 feVector<T>::feVector(daType da) {
00017 #ifdef __DEBUG__
00018   assert ( ( da == PETSC ) || ( da == OCT ) );
00019 #endif
00020   m_daType = da;
00021   m_DA          = NULL;
00022   m_octDA       = NULL;
00023   m_stencil     = NULL;
00024   m_ucpLut      = NULL;
00025 
00026   // initialize the stencils ...
00027   initStencils();
00028   if (da == OCT)
00029     initOctLut();
00030 }
00031 
00032 template <typename T>
00033 void feVector<T>::initOctLut() {
00034   //Note: It is not symmetric.
00035   unsigned char tmp[8][8]={
00036     {0,1,2,3,4,5,6,7},
00037     {1,3,0,2,5,7,4,6},
00038     {2,0,3,1,6,4,7,5},
00039     {3,2,1,0,7,6,5,4},
00040     {4,5,0,1,6,7,2,3},
00041     {5,7,1,3,4,6,0,2},
00042     {6,4,2,0,7,5,3,1},
00043     {7,6,3,2,5,4,1,0}
00044   };
00045 
00046   //Is Stored in  ROW_MAJOR Format.  
00047   typedef unsigned char* charPtr;
00048   m_ucpLut = new charPtr[8];
00049   for (int i=0;i<8;i++) {
00050     m_ucpLut[i] = new unsigned char[8]; 
00051     for (int j=0;j<8;j++) {
00052       m_ucpLut[i][j] = tmp[i][j];
00053     }
00054   }
00055 }
00056 
00057 template <typename T>
00058 feVector<T>::~feVector() {
00059 }
00060 
00061 
00075 /*#undef __FUNCT__
00076 #define __FUNCT__ "feVector_AddVec"
00077 template <typename T>
00078 bool feVector<T>::addVec(Vec _in, double scale){
00079 PetscFunctionBegin;
00080 
00081 #ifdef __DEBUG__
00082 assert ( ( m_daType == PETSC ) || ( m_daType == OCT ) );
00083 #endif
00084 
00085 int ierr;
00086 // PetscScalar zero=0.0;
00087 
00088 if (m_daType == PETSC) {
00089 
00090 PetscInt x,y,z,m,n,p;
00091 PetscInt mx,my,mz;
00092 int xne,yne,zne;
00093 
00094 PetscScalar ***in;
00095 Vec inlocal;
00096 
00097 // Get all corners
00098 if (m_DA == NULL)
00099 std::cerr << "Da is null" << std::endl;
00100 ierr = DAGetCorners(m_DA, &x, &y, &z, &m, &n, &p); CHKERRQ(ierr); 
00101 // Get Info
00102 ierr = DAGetInfo(m_DA,0, &mx, &my, &mz, 0,0,0,0,0,0,0); CHKERRQ(ierr); 
00103 
00104 if (x+m == mx) {
00105 xne=m-1;
00106 } else {
00107 xne=m;
00108 }
00109 if (y+n == my) {
00110 yne=n-1;
00111 } else {
00112 yne=n;
00113 }
00114 if (z+p == mz) {
00115 zne=p-1;
00116 } else {
00117 zne=p;
00118 }
00119 
00120 double norm;
00121 
00122 #ifdef __DEBUG__
00123 VecNorm(_in, NORM_INFINITY, &norm);
00124 std::cout << " norm of _in in feVector.cpp before adding force = " << norm << std::endl;
00125 #endif
00126 
00127 ierr = DAGetLocalVector(m_DA,&inlocal); CHKERRQ(ierr);
00128 
00129 ierr = VecZeroEntries(inlocal); CHKERRQ(ierr);
00130 
00131 ierr = DAVecGetArray(m_DA,inlocal, &in);
00132 
00133 // Any derived class initializations ...
00134 preAddVec();
00135 
00136 // loop through all elements ...
00137 for (int k=z; k<z+zne; k++){
00138 for (int j=y; j<y+yne; j++){
00139 for (int i=x; i<x+xne; i++){
00140 // std::cout << i <<"," << j << "," << k << std::endl;
00141 ElementalAddVec(i, j, k, in, scale);
00142 } // end i
00143 } // end j
00144 } // end k
00145 
00146 postAddVec();
00147 
00148 ierr = DAVecRestoreArray(m_DA, inlocal, &in);
00149 
00150 ierr = DALocalToGlobalBegin(m_DA,inlocal,_in); CHKERRQ(ierr);
00151 ierr = DALocalToGlobalEnd(m_DA,inlocal,_in); CHKERRQ(ierr);
00152 
00153 ierr = DARestoreLocalVector(m_DA,&inlocal); CHKERRQ(ierr);
00154 
00155 #ifdef __DEBUG__
00156 VecNorm(_in, NORM_INFINITY, &norm);
00157 std::cout << " norm of _in in feVector.cpp after adding force = " << norm << std::endl;
00158 #endif
00159 // ierr = VecDestroy(outlocal); CHKERRQ(ierr);  
00160 
00161 } else {
00162   // loop for octree DA.
00163 
00164 
00165   PetscScalar *out=NULL;
00166   PetscScalar *in=NULL; 
00167 
00168   // get Buffers ...
00169   //Nodal,Non-Ghosted,Read,1 dof, Get in array and get ghosts during computation
00170   m_octDA->vecGetBuffer(_in,   in, false, false, false,  m_uiDof);
00171 
00172 
00173   // start comm for in ...
00174   //m_octDA->updateGhostsBegin<PetscScalar>(in, false, m_uiDof);
00175   m_octDA->ReadFromGhostsBegin<PetscScalar>(in, false, m_uiDof);
00176   preAddVec();
00177 
00178   // Independent loop, loop through the nodes this processor owns..
00179   for ( m_octDA->init<ot::DA::INDEPENDENT>(), m_octDA->init<ot::DA::WRITABLE>(); m_octDA->curr() < m_octDA->end<ot::DA::INDEPENDENT>(); m_octDA->next<ot::DA::INDEPENDENT>() ) {
00180     ElementalAddVec( m_octDA->curr(), in, scale); 
00181   }//end INDEPENDENT
00182 
00183   // Wait for communication to end.
00184   //m_octDA->updateGhostsEnd<PetscScalar>(in);
00185   m_octDA->ReadFromGhostsEnd<PetscScalar>(in);
00186 
00187   // Dependent loop ...
00188   for ( m_octDA->init<ot::DA::DEPENDENT>(), m_octDA->init<ot::DA::WRITABLE>();m_octDA->curr() < m_octDA->end<ot::DA::DEPENDENT>(); m_octDA->next<ot::DA::DEPENDENT>() ) {
00189     ElementalAddVec( m_octDA->curr(), in, scale); 
00190   }//end DEPENDENT
00191 
00192   postAddVec();
00193 
00194   // Restore Vectors ...
00195   m_octDA->vecRestoreBuffer(_in,   in, false, false, false,  m_uiDof);
00196 
00197 }
00198 
00199 PetscFunctionReturn(0);
00200 }
00201 */
00202 
00216 #undef __FUNCT__
00217 #define __FUNCT__ "feVector_AddVec_Indx"
00218 template <typename T>
00219 bool feVector<T>::addVec(Vec _in, double scale, int indx){
00220   PetscFunctionBegin;
00221 
00222 #ifdef __DEBUG__
00223   assert ( ( m_daType == PETSC ) || ( m_daType == OCT ) );
00224 #endif
00225 
00226   int ierr;
00227   // PetscScalar zero=0.0;
00228 
00229   m_iCurrentDynamicIndex = indx;
00230 
00231   if (m_daType == PETSC) {
00232 
00233     PetscInt x,y,z,m,n,p;
00234     PetscInt mx,my,mz;
00235     int xne,yne,zne;
00236 
00237     PetscScalar ***in;
00238     Vec inlocal;
00239 
00240     /* Get all corners*/
00241     if (m_DA == NULL)
00242       std::cerr << "Da is null" << std::endl;
00243     ierr = DAGetCorners(m_DA, &x, &y, &z, &m, &n, &p); CHKERRQ(ierr); 
00244     /* Get Info*/
00245     ierr = DAGetInfo(m_DA,0, &mx, &my, &mz, 0,0,0,0,0,0,0); CHKERRQ(ierr); 
00246 
00247     if (x+m == mx) {
00248       xne=m-1;
00249     } else {
00250       xne=m;
00251     }
00252     if (y+n == my) {
00253       yne=n-1;
00254     } else {
00255       yne=n;
00256     }
00257     if (z+p == mz) {
00258       zne=p-1;
00259     } else {
00260       zne=p;
00261     }
00262 
00263     double norm;
00264 
00265 #ifdef __DEBUG__
00266     VecNorm(_in, NORM_INFINITY, &norm);
00267     std::cout << " norm of _in in feVector.cpp before adding force = " << norm << std::endl;
00268 #endif
00269 
00270     ierr = DAGetLocalVector(m_DA,&inlocal); CHKERRQ(ierr);
00271 
00272     ierr = VecZeroEntries(inlocal); CHKERRQ(ierr);
00273 
00274     ierr = DAVecGetArray(m_DA,inlocal, &in);
00275 
00276     // Any derived class initializations ...
00277     // std::cout << __func__ << " -> preAddVec " << std::endl; 
00278     preAddVec();
00279 
00280     // std::cout << __func__ << " -> Elemental Loop " << std::endl;
00281     // loop through all elements ...
00282     for (int k=z; k<z+zne; k++){
00283       for (int j=y; j<y+yne; j++){
00284         for (int i=x; i<x+xne; i++){
00285           // std::cout << i <<"," << j << "," << k << std::endl;
00286           ElementalAddVec(i, j, k, in, scale);
00287         } // end i
00288       } // end j
00289     } // end k
00290 
00291     // std::cout << __func__ << " -> postAddVec " << std::endl;
00292     postAddVec();
00293 
00294     ierr = DAVecRestoreArray(m_DA, inlocal, &in);
00295 
00296     ierr = DALocalToGlobalBegin(m_DA,inlocal,_in); CHKERRQ(ierr);
00297     ierr = DALocalToGlobalEnd(m_DA,inlocal,_in); CHKERRQ(ierr);
00298 
00299     ierr = DARestoreLocalVector(m_DA,&inlocal); CHKERRQ(ierr);
00300 
00301 #ifdef __DEBUG__
00302     VecNorm(_in, NORM_INFINITY, &norm);
00303     std::cout << " norm of _in in feVector.cpp after adding force = " << norm << std::endl;
00304 #endif
00305     // ierr = VecDestroy(outlocal); CHKERRQ(ierr);  
00306 
00307   } else {
00308     // loop for octree DA.
00309 
00310 
00311     PetscScalar *out=NULL;
00312     PetscScalar *in=NULL; 
00313 
00314     // get Buffers ...
00315     //Nodal,Non-Ghosted,Read,1 dof, Get in array and get ghosts during computation
00316     m_octDA->vecGetBuffer(_in,   in, false, false, false,  m_uiDof);
00317 
00318 
00319     // start comm for in ...
00320     //m_octDA->updateGhostsBegin<PetscScalar>(in, false, m_uiDof);
00321     //m_octDA->ReadFromGhostsBegin<PetscScalar>(in, false, m_uiDof);
00322     m_octDA->ReadFromGhostsBegin<PetscScalar>(in, m_uiDof);
00323     preAddVec();
00324 
00325     // Independent loop, loop through the nodes this processor owns..
00326     for ( m_octDA->init<ot::DA::INDEPENDENT>(), m_octDA->init<ot::DA::WRITABLE>(); m_octDA->curr() < m_octDA->end<ot::DA::INDEPENDENT>(); m_octDA->next<ot::DA::INDEPENDENT>() ) {
00327       ElementalAddVec( m_octDA->curr(), in, scale); 
00328     }//end INDEPENDENT
00329 
00330     // Wait for communication to end.
00331     //m_octDA->updateGhostsEnd<PetscScalar>(in);
00332     m_octDA->ReadFromGhostsEnd<PetscScalar>(in);
00333 
00334     // Dependent loop ...
00335     for ( m_octDA->init<ot::DA::DEPENDENT>(), m_octDA->init<ot::DA::WRITABLE>();m_octDA->curr() < m_octDA->end<ot::DA::DEPENDENT>(); m_octDA->next<ot::DA::DEPENDENT>() ) {
00336       ElementalAddVec( m_octDA->curr(), in, scale); 
00337     }//end DEPENDENT
00338 
00339     postAddVec();
00340 
00341     // Restore Vectors ...
00342     m_octDA->vecRestoreBuffer(_in,   in, false, false, false,  m_uiDof);
00343 
00344   }
00345 
00346   PetscFunctionReturn(0);
00347 }
00348 
00360 #undef __FUNCT__
00361 #define __FUNCT__ "feVector_ComputeVec"
00362 template <typename T>
00363 bool feVector<T>::computeVec(Vec _in, Vec _out,double scale){
00364   PetscFunctionBegin;
00365 
00366 #ifdef __DEBUG__
00367   assert ( ( m_daType == PETSC ) || ( m_daType == OCT ) );
00368 #endif
00369 
00370   int ierr;
00371   // PetscScalar zero=0.0;
00372 
00373   if (m_daType == PETSC) {
00374 
00375     PetscInt x,y,z,m,n,p;
00376     PetscInt mx,my,mz;
00377     int xne,yne,zne;
00378 
00379     PetscScalar ***in;
00380     PetscScalar ***out;
00381 
00382 
00383     /* Get all corners*/
00384     if (m_DA == NULL)
00385       std::cerr << "Da is null" << std::endl;
00386 
00387     ierr = DAGetCorners(m_DA,&x,&y,&z,&m,&n,&p); CHKERRQ(ierr);
00388     ierr = DAVecGetArray(m_DA,_in,&in); CHKERRQ(ierr);
00389     ierr = DAVecGetArray(m_DA,_out,&out); CHKERRQ(ierr);
00390     // Any derived class initializations ...
00391     preComputeVec();
00392 
00393     // loop through all elements ...
00394     for (int k=z; k<z+p; k++){
00395       for (int j=y; j<y+n; j++){
00396         for (int i=x; i<x+m; i++){
00397           // std::cout << i <<"," << j << "," << k << std::endl;
00398           ComputeNodalFunction(i, j, k, in, out,scale);
00399         } // end i
00400       } // end j
00401     } // end k
00402 
00403     postComputeVec();
00404 
00405 
00406     ierr = DAVecRestoreArray(m_DA,_in,&in); CHKERRQ(ierr);
00407     ierr = DAVecRestoreArray(m_DA,_out,&out); CHKERRQ(ierr);
00408 
00409   } else {
00410     // loop for octree DA.
00411 
00412 
00413     PetscScalar *out=NULL;
00414     PetscScalar *in=NULL; 
00415 
00416     // get Buffers ...
00417     //Nodal,Non-Ghosted,Read,1 dof, Get in array 
00418     m_octDA->vecGetBuffer(_in,   in, false, false, true,  m_uiDof);
00419     m_octDA->vecGetBuffer(_in,   out, false, false, false,m_uiDof);
00420 
00421     preAddVec();
00422 
00423     // Independent loop, loop through the nodes this processor owns..
00424     for ( m_octDA->init<ot::DA::INDEPENDENT>(), m_octDA->init<ot::DA::WRITABLE>(); m_octDA->curr() < m_octDA->end<ot::DA::INDEPENDENT>(); m_octDA->next<ot::DA::INDEPENDENT>() ) {
00425       ComputeNodalFunction(in, out,scale); 
00426     }//end INDEPENDENT
00427 
00428 
00429     postAddVec();
00430 
00431     // Restore Vectors ...
00432     m_octDA->vecRestoreBuffer(_in,   in, false, false, true,  m_uiDof);
00433     m_octDA->vecRestoreBuffer(_out,  out,false, false, false, m_uiDof);
00434 
00435   }
00436 
00437   PetscFunctionReturn(0);
00438 }
00439 
00440 #undef __FUNCT__
00441 #define __FUNCT__ "alignElementAndVertices"
00442 template <typename T>
00443 PetscErrorCode feVector<T>::alignElementAndVertices(ot::DA * da, 
00444     stdElemType & sType, ot::index* indices) {
00445   PetscFunctionBegin;
00446 
00447   sType = ST_0;
00448   da->getNodeIndices(indices); 
00449 
00450   // not required ....
00451   // int rank;
00452   // MPI_Comm_rank(da->getComm(), &rank);
00453 
00454   if (da->isHanging(da->curr())) {
00455 
00456     int childNum = da->getChildNumber();
00457     Point pt = da->getCurrentOffset();   
00458 
00459     unsigned char hangingMask = da->getHangingNodeIndex(da->curr());    
00460 
00461     //Change HangingMask and indices based on childNum
00462     mapVtxAndFlagsToOrientation(childNum, indices, hangingMask);    
00463 
00464     unsigned char eType = ((126 & hangingMask)>>1);
00465 
00466     reOrderIndices(eType, indices);
00467   }//end if hangingElem.
00468   PetscFunctionReturn(0);
00469 }//end function.
00470 
00471 #undef __FUNCT__
00472 #define __FUNCT__ "mapVtxAndFlagsToOrientation"
00473 template <typename T>
00474 PetscErrorCode feVector<T>::mapVtxAndFlagsToOrientation(int childNum, 
00475 ot::index* indices, unsigned char & mask) {
00476   PetscFunctionBegin;
00477   ot::index tmp[8];
00478   unsigned char tmpFlags = 0;
00479   for (int i = 0; i < 8; i++) {
00480     tmp[i] = indices[m_ucpLut[childNum][i]];
00481     tmpFlags = ( tmpFlags | ( ( (1 << (m_ucpLut[childNum][i])) & mask ) ? (1 << i) : 0 ) );
00482   }
00483   for (int i=0;i<8;i++) {
00484     indices[i] = tmp[i];
00485   }
00486   mask = tmpFlags;
00487   PetscFunctionReturn(0);
00488 }//end function
00489 
00490 #undef __FUNCT__
00491 #define __FUNCT__ "reOrderIndices"
00492 template <typename T>
00493 PetscErrorCode feVector<T>::reOrderIndices(unsigned char eType, ot::index* indices) {
00494 #ifdef __DEBUG_1
00495   std::cout << "Entering " << __func__ << std::endl;
00496 #endif
00497   PetscFunctionBegin;
00498   ot::index tmp;
00499   switch (eType) {
00500     case  ET_N: 
00501       break;
00502     case  ET_Y:
00503       break;
00504     case  ET_X:
00505       //Swap 1 & 2, Swap 5 & 6
00506       tmp = indices[1];
00507       indices[1] = indices[2];
00508       indices[2] = tmp;
00509       tmp = indices[5];
00510       indices[5] = indices[6];
00511       indices[6] = tmp;
00512       break;
00513     case  ET_XY:
00514       break;
00515     case  ET_Z:
00516       //Swap 2 & 4, Swap 3 & 5
00517       tmp = indices[2];
00518       indices[2] = indices[4];
00519       indices[4] = tmp;
00520       tmp = indices[3];
00521       indices[3] = indices[5];
00522       indices[5] = tmp;
00523       break;
00524     case  ET_ZY:
00525       //Swap 1 & 4, Swap 3 & 6
00526       tmp = indices[1];
00527       indices[1] = indices[4];
00528       indices[4] = tmp;
00529       tmp = indices[3];
00530       indices[3] = indices[6];
00531       indices[6] = tmp;
00532       break;
00533     case  ET_ZX:
00534       //Swap 2 & 4, Swap 3 & 5
00535       tmp = indices[2];
00536       indices[2] = indices[4];
00537       indices[4] = tmp;
00538       tmp = indices[3];
00539       indices[3] = indices[5];
00540       indices[5] = tmp;
00541       break;
00542     case  ET_ZXY:
00543       break;
00544     case  ET_XY_XY:
00545       break;
00546     case  ET_XY_ZXY:
00547       break;
00548     case  ET_YZ_ZY:
00549       //Swap 1 & 4, Swap 3 & 6
00550       tmp = indices[1];
00551       indices[1] = indices[4];
00552       indices[4] = tmp;
00553       tmp = indices[3];
00554       indices[3] = indices[6];
00555       indices[6] = tmp;
00556       break;
00557     case  ET_YZ_ZXY:
00558       //Swap 1 & 4, Swap 3 & 6
00559       tmp = indices[1];
00560       indices[1] = indices[4];
00561       indices[4] = tmp;
00562       tmp = indices[3];
00563       indices[3] = indices[6];
00564       indices[6] = tmp;
00565       break;
00566     case  ET_YZ_XY_ZXY:
00567       break;
00568     case  ET_ZX_ZX:
00569       //Swap 2 & 4, Swap 3 & 5
00570       tmp = indices[2];
00571       indices[2] = indices[4];
00572       indices[4] = tmp;
00573       tmp = indices[3];
00574       indices[3] = indices[5];
00575       indices[5] = tmp;
00576       break;
00577     case  ET_ZX_ZXY:
00578       //Swap 2 & 4, Swap 3 & 5
00579       tmp = indices[2];
00580       indices[2] = indices[4];
00581       indices[4] = tmp;
00582       tmp = indices[3];
00583       indices[3] = indices[5];
00584       indices[5] = tmp;
00585       break;
00586     case  ET_ZX_XY_ZXY:
00587       //Swap 1 & 2, Swap 5 & 6
00588       tmp = indices[1];
00589       indices[1] = indices[2];
00590       indices[2] = tmp;
00591       tmp = indices[5];
00592       indices[5] = indices[6];
00593       indices[6] = tmp;
00594       break;
00595     case  ET_ZX_YZ_ZXY:
00596       //Swap 2 & 4, Swap 3 & 5
00597       tmp = indices[2];
00598       indices[2] = indices[4];
00599       indices[4] = tmp;
00600       tmp = indices[3];
00601       indices[3] = indices[5];
00602       indices[5] = tmp;
00603       break;
00604     case  ET_ZX_YZ_XY_ZXY:
00605       break;
00606     default:
00607       std::cout<<"in reOrder Etype: "<< (int) eType << std::endl;
00608       assert(false);
00609   }
00610 #ifdef __DEBUG_1
00611   std::cout << "Leaving " << __func__ << std::endl;
00612 #endif
00613   PetscFunctionReturn(0);
00614 }
00615 

Generated on Tue Mar 24 16:14:01 2009 for DENDRO by  doxygen 1.3.9.1