00001
00008 #ifndef __ODAUTILS_H__
00009 #define __ODAUTILS_H__
00010
00011 #include "mpi.h"
00012 #include <vector>
00013 #include "petscvec.h"
00014
00015 #ifdef __DEBUG__
00016 #ifndef __DEBUG_DA__
00017 #define __DEBUG_DA__
00018 #endif
00019 #endif
00020
00021 #ifdef PETSC_USE_LOG
00022
00023 #include "petscsys.h"
00024
00025 namespace ot {
00026 extern int pickGhostsEvent;
00027 extern int addBdySiblingsEvent;
00028 extern int DAaprioriCommEvent;
00029
00030 extern int daInitEvent;
00031 extern int daFinalEvent;
00032 extern int DAbPart1Event;
00033 extern int DAbPart2Event;
00034 extern int DAbPart3Event;
00035 }
00036
00037 #define PROF_DA_INIT_BEGIN PetscLogEventBegin(daInitEvent,0,0,0,0);
00038 #define PROF_DA_INIT_END PetscLogEventEnd(daInitEvent,0,0,0,0); \
00039 return ;
00040
00041 #define PROF_DA_FINAL_BEGIN PetscLogEventBegin(daFinalEvent,0,0,0,0);
00042 #define PROF_DA_FINAL_END PetscLogEventEnd(daFinalEvent,0,0,0,0); \
00043 return ;
00044
00045 #define PROF_PICK_GHOSTS_BEGIN PetscLogEventBegin(pickGhostsEvent,0,0,0,0);
00046 #define PROF_PICK_GHOSTS_END PetscLogEventEnd(pickGhostsEvent,0,0,0,0); \
00047 return ;
00048
00049 #define PROF_ADD_BDY_SIBLINGS_BEGIN PetscLogEventBegin(addBdySiblingsEvent,0,0,0,0);
00050 #define PROF_ADD_BDY_SIBLINGS_END PetscLogEventEnd(addBdySiblingsEvent,0,0,0,0); \
00051 return ;
00052
00053 #define PROF_DA_APRIORI_COMM_BEGIN PetscLogEventBegin(DAaprioriCommEvent,0,0,0,0);
00054 #define PROF_DA_APRIORI_COMM_END PetscLogEventEnd(DAaprioriCommEvent,0,0,0,0); \
00055 return ;
00056
00057 #define PROF_DA_BPART1_BEGIN PetscLogEventBegin(DAbPart1Event,0,0,0,0);
00058 #define PROF_DA_BPART1_END PetscLogEventEnd(DAbPart1Event,0,0,0,0);
00059
00060 #define PROF_DA_BPART2_BEGIN PetscLogEventBegin(DAbPart2Event,0,0,0,0);
00061 #define PROF_DA_BPART2_END PetscLogEventEnd(DAbPart2Event,0,0,0,0);
00062
00063 #define PROF_DA_BPART3_BEGIN PetscLogEventBegin(DAbPart3Event,0,0,0,0);
00064 #define PROF_DA_BPART3_END PetscLogEventEnd(DAbPart3Event,0,0,0,0);
00065
00066 #else
00067
00068 #define PROF_DA_INIT_BEGIN
00069 #define PROF_DA_INIT_END return ;
00070
00071 #define PROF_DA_FINAL_BEGIN
00072 #define PROF_DA_FINAL_END return ;
00073
00074 #define PROF_ADD_BDY_SIBLINGS_BEGIN
00075 #define PROF_ADD_BDY_SIBLINGS_END return ;
00076
00077 #define PROF_PICK_GHOSTS_BEGIN
00078 #define PROF_PICK_GHOSTS_END return;
00079
00080 #define PROF_DA_APRIORI_COMM_BEGIN
00081 #define PROF_DA_APRIORI_COMM_END return;
00082
00083 #define PROF_DA_BPART1_BEGIN
00084 #define PROF_DA_BPART1_END
00085
00086 #define PROF_DA_BPART2_BEGIN
00087 #define PROF_DA_BPART2_END
00088
00089 #define PROF_DA_BPART3_BEGIN
00090 #define PROF_DA_BPART3_END
00091
00092 #endif
00093
00094 namespace ot {
00095
00096 namespace DA_FLAGS {
00097
00102 enum SortOrderType {
00103 XYZ, YXZ, XZY, ZXY, YZX, ZYX
00104 };
00105
00110 enum ElementFlagType {
00111 DEP_ELEM=32, FOREIGN=255
00112 };
00113
00151 enum loopType {
00152 ALL, WRITABLE, DEPENDENT, INDEPENDENT, W_DEPENDENT, FROM_STORED
00153 };
00154
00155 }
00156
00157
00158 class TreeNode;
00159 class DA;
00160
00168 template<unsigned char cNum>
00169 unsigned char getElemType(unsigned char hnMask);
00170
00178 unsigned int getSortOrder(unsigned int x, unsigned int y,
00179 unsigned int z, unsigned int sz);
00180
00190 unsigned char getTouchConfig(const ot::TreeNode& curr,
00191 const ot::TreeNode& next, unsigned int maxDepth);
00192
00199 void assignBoundaryFlags(ot::DA* da,
00200 std::vector<unsigned char> & bdyFlagVec);
00201
00206 bool isRegularGrid(ot::DA* da);
00207
00224 void interpolateData(ot::DA* da, std::vector<double>& in,
00225 std::vector<double>& out, std::vector<double>* gradOut,
00226 unsigned int dof, std::vector<double>& pts);
00227
00244 void interpolateData(ot::DA* da, Vec in, Vec out, Vec* gradOut,
00245 unsigned int dof, std::vector<double>& pts);
00246
00251 unsigned int getGlobalMinLevel(ot::DA* da);
00252
00257 unsigned int getGlobalMaxLevel(ot::DA* da);
00258
00263 void writePartitionVTK(ot::DA* da, const char* outFilename);
00264
00265
00266 void pickGhostCandidates(const std::vector<ot::TreeNode> & blocks,
00267 const std::vector<ot::TreeNode> &nodes, std::vector<ot::TreeNode>& res,
00268 unsigned int dim, unsigned int maxDepth) ;
00269
00270 void includeSiblingsOfBoundary(std::vector<ot::TreeNode>& allBoundaryLeaves,
00271 const ot::TreeNode& myFirstOctant, const ot::TreeNode& myLastOctant);
00272
00273 void prepareAprioriCommMessagesInDAtype1(const std::vector<ot::TreeNode>& in,
00274 std::vector<ot::TreeNode>& allBoundaryLeaves, std::vector<ot::TreeNode>& blocks,
00275 const std::vector<ot::TreeNode>& allBlocks, int myRank, int npes, int* sendCnt,
00276 std::vector<std::vector<unsigned int> >& sendNodes);
00277
00278 void prepareAprioriCommMessagesInDAtype2(const std::vector<ot::TreeNode>& in,
00279 std::vector<ot::TreeNode>& allBoundaryLeaves, std::vector<ot::TreeNode>& blocks,
00280 const std::vector<ot::TreeNode>& minsOfBlocks, int myRank, int npes, int* sendCnt,
00281 std::vector<std::vector<unsigned int> >& sendNodes);
00282
00283
00284
00285 int addSecondRing(const std::vector<ot::TreeNode> & nodes,
00286 const std::vector<unsigned int> & firstLayer,
00287 const std::vector<ot::TreeNode> & blocks,
00288 std::vector<unsigned int> & secondRing);
00289
00290 int DA_blockPartStage2(std::vector<TreeNode> &nodes,
00291 std::vector<TreeNode> &globalCoarse,
00292 unsigned int dim, unsigned int maxDepth, MPI_Comm commActive);
00293
00294 int DA_blockPartStage3(std::vector<TreeNode> &nodes,
00295 std::vector<TreeNode>& globalCoarse, std::vector<ot::TreeNode>& minsAllBlocks,
00296 unsigned int dim, unsigned int maxDepth, MPI_Comm commActive);
00297
00301 void DA_Initialize(MPI_Comm comm);
00302
00306 void DA_Finalize();
00307
00308 int createShapeFnCoeffs_Type1(MPI_Comm comm);
00309 int createShapeFnCoeffs_Type2(MPI_Comm comm);
00310 int createShapeFnCoeffs_Type3(MPI_Comm comm);
00311
00312
00313
00314
00315
00316
00317
00318
00319 template <typename T>
00320 void injectNodalVector(ot::DA* dac, ot::DA* daf, unsigned int dof,
00321 std::vector<T>& fVec, std::vector<T>& cVec, void (*setZero)(T&));
00322
00323 }
00324
00334 #define GET_ETYPE_BLOCK(type,hnMask,cNum) {\
00335 if(hnMask) {\
00336 switch(cNum) {\
00337 case 0:{\
00338 type = ot::getElemType<0>(hnMask);\
00339 break;\
00340 }\
00341 case 1:{\
00342 type = ot::getElemType<1>(hnMask);\
00343 break;\
00344 }\
00345 case 2:{\
00346 type = ot::getElemType<2>(hnMask);\
00347 break;\
00348 }\
00349 case 3:{\
00350 type = ot::getElemType<3>(hnMask);\
00351 break;\
00352 }\
00353 case 4:{\
00354 type = ot::getElemType<4>(hnMask);\
00355 break;\
00356 }\
00357 case 5:{\
00358 type = ot::getElemType<5>(hnMask);\
00359 break;\
00360 }\
00361 case 6:{\
00362 type = ot::getElemType<6>(hnMask);\
00363 break;\
00364 }\
00365 case 7:{\
00366 type = ot::getElemType<7>(hnMask);\
00367 break;\
00368 }\
00369 default:{\
00370 assert(false);\
00371 }\
00372 }\
00373 }\
00374 }
00375
00376 #include "odaUtils.txx"
00377
00378 #endif
00379