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
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
00027 initStencils();
00028 if (da == OCT)
00029 initOctLut();
00030 }
00031
00032 template <typename T>
00033 void feVector<T>::initOctLut() {
00034
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
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
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
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
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
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
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
00277
00278 preAddVec();
00279
00280
00281
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
00286 ElementalAddVec(i, j, k, in, scale);
00287 }
00288 }
00289 }
00290
00291
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
00306
00307 } else {
00308
00309
00310
00311 PetscScalar *out=NULL;
00312 PetscScalar *in=NULL;
00313
00314
00315
00316 m_octDA->vecGetBuffer(_in, in, false, false, false, m_uiDof);
00317
00318
00319
00320
00321
00322 m_octDA->ReadFromGhostsBegin<PetscScalar>(in, m_uiDof);
00323 preAddVec();
00324
00325
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 }
00329
00330
00331
00332 m_octDA->ReadFromGhostsEnd<PetscScalar>(in);
00333
00334
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 }
00338
00339 postAddVec();
00340
00341
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
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
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
00391 preComputeVec();
00392
00393
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
00398 ComputeNodalFunction(i, j, k, in, out,scale);
00399 }
00400 }
00401 }
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
00411
00412
00413 PetscScalar *out=NULL;
00414 PetscScalar *in=NULL;
00415
00416
00417
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
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 }
00427
00428
00429 postAddVec();
00430
00431
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
00451
00452
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
00462 mapVtxAndFlagsToOrientation(childNum, indices, hangingMask);
00463
00464 unsigned char eType = ((126 & hangingMask)>>1);
00465
00466 reOrderIndices(eType, indices);
00467 }
00468 PetscFunctionReturn(0);
00469 }
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 }
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
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
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
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
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
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
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
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
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
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
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