diff --git a/FunctionSpace/ReferenceSpace.cpp b/FunctionSpace/ReferenceSpace.cpp index e40f04788b3a513f5e4f491424bdbd0d2259b95a..241d87bd2dbf9bab6740b796289693375b63f4cf 100644 --- a/FunctionSpace/ReferenceSpace.cpp +++ b/FunctionSpace/ReferenceSpace.cpp @@ -23,13 +23,13 @@ ReferenceSpace::ReferenceSpace(void){ nEdge = 0; refEdge = NULL; - permutedRefEdge = NULL; + //permutedRefEdge = NULL; edge = NULL; nFace = 0; nNodeInFace = NULL; refFace = NULL; - permutedRefFace = NULL; + //permutedRefFace = NULL; face = NULL; // Defining Ref Edge and Face in // @@ -44,29 +44,29 @@ ReferenceSpace::~ReferenceSpace(void){ // Delete Permutated Edge // for(unsigned int p = 0; p < nPerm; p++){ for(unsigned int i = 0; i < nEdge; i++){ - delete[] permutedRefEdge[p][i]; + //delete[] permutedRefEdge[p][i]; delete (*(*edge)[p])[i]; } - delete[] permutedRefEdge[p]; + //delete[] permutedRefEdge[p]; delete (*edge)[p]; } - delete[] permutedRefEdge; + //delete[] permutedRefEdge; delete edge; // Delete Permutated Face // for(unsigned int p = 0; p < nPerm; p++){ for(unsigned int i = 0; i < nFace; i++){ - delete[] permutedRefFace[p][i]; + //delete[] permutedRefFace[p][i]; delete (*(*face)[p])[i]; } - delete[] permutedRefFace[p]; + //delete[] permutedRefFace[p]; delete (*face)[p]; } - delete[] permutedRefFace; + //delete[] permutedRefFace; delete face; } @@ -102,30 +102,6 @@ void ReferenceSpace::init(void){ // Get Edges & Faces // getEdge(); getFace(); - - for(unsigned int p = 0; p < nPerm; p++){ - cout << "Permutation " << p << ":" << endl; - - for(unsigned int e = 0; e < nEdge; e++){ - cout << " " << "Edge " << e << ": ["; - - for(unsigned int n = 0; n < 2 - 1; n++) - cout << permutedRefEdge[p][e][n] << ", "; - - cout << permutedRefEdge[p][e][2 - 1] << "]" - << endl; - } - - for(unsigned int f = 0; f < nFace; f++){ - cout << " " << "Face " << f << ": ["; - - for(unsigned int n = 0; n < nNodeInFace[f] - 1; n++) - cout << permutedRefFace[p][f][n] << ", "; - - cout << permutedRefFace[p][f][nNodeInFace[f] - 1] << "]" - << endl; - } - } } void ReferenceSpace::populate(node* pTreeRoot){ @@ -205,7 +181,7 @@ void ReferenceSpace::getEdge(void){ // Alloc vector<const vector<unsigned int>*>* tmp; edge = new vector<const vector<const vector<unsigned int>*>*>(nPerm); - + /* // All Edges have two nodes unsigned int* nNodeInEdge = new unsigned int[nEdge]; @@ -221,7 +197,7 @@ void ReferenceSpace::getEdge(void){ nEdge); delete[] nNodeInEdge; - + */ // Populate Edge for(unsigned int p = 0; p < nPerm; p++){ tmp = new vector<const vector<unsigned int>*>(nEdge); @@ -237,7 +213,7 @@ void ReferenceSpace::getFace(void){ // Alloc vector<const vector<unsigned int>*>* tmp; face = new vector<const vector<const vector<unsigned int>*>*>(nPerm); - + /* // Get Face nodes depending on the orientation // (face 1 = [1 2 3 4] for orientation 1) // ( = [4 1 2 3] for orientation 2) @@ -245,7 +221,7 @@ void ReferenceSpace::getFace(void){ refFace, nNodeInFace, nFace); - + */ // Populate Face for(unsigned int p = 0; p < nPerm; p++){ tmp = new vector<const vector<unsigned int>*>(nFace); @@ -267,7 +243,7 @@ void ReferenceSpace::getFace(void){ (*face)[p] = tmp; } } - +/* void ReferenceSpace::getPermutedRefEntity(unsigned int**** permutedRefEntity, unsigned int** refEntity, unsigned int* nNodeInEntity, @@ -282,52 +258,33 @@ void ReferenceSpace::getPermutedRefEntity(unsigned int**** permutedRefEntity, (*permutedRefEntity)[p][e] = new unsigned int[nNodeInEntity[e]]; } - // Alloc Idx - unsigned int** idx = new unsigned int*[nEntity]; - - for(unsigned int e = 0; e < nEntity; e++) - idx[e] = new unsigned int[nNodeInEntity[e]]; - - // Get Reference Index - // Use refEntity and perm[0] as reference element - for(unsigned int e = 0; e < nEntity; e++) - getIndex(nNodeInEntity[e], refEntity[e], nVertex, perm[0], &idx[e]); - // Generate Permuted Ref Entity for(unsigned int p = 0; p < nPerm; p++){ for(unsigned int e = 0; e < nEntity; e++){ for(unsigned int n = 0; n < nNodeInEntity[e]; n++) - (*permutedRefEntity)[p][e][n] = perm[p][idx[e][n]]; + (*permutedRefEntity)[p][e][n] = perm[p][refEntity[e][n]]; } } - - // Delete Temp - for(unsigned int e = 0; e < nEntity; e++) - delete[] idx[e]; - - delete[] idx; } - +*/ const vector<unsigned int>* ReferenceSpace:: getOrderedEdge(unsigned int permutation, unsigned int edge){ - /************************************************************************* - * Let say we have we have permutedRefEdge[4][2] = [0 1]. * - * I want to get back to same node ID than refEdge[2] = [2 0]. * - * That is, I want to return [0 2]. * - * * - * I need to sort permutedRefEdge and keep the index swaping. * - * I can use this index swaping to get the right permutation of refEdge. * - *************************************************************************/ + /************************************************************************** + * I want to know how I need to take the values of refEdge[edge] * + * (i.e the node *index* of a given edge) so that the corresponding * + * values in permutation (i.e perm[permutation][refEdge[edge]]) are going * + * from the smallest value to the biggest. * + **************************************************************************/ // Alloc vector<unsigned int>* ordered = new vector<unsigned int>(2); - // Sort & Swap - sortAndSwap(permutedRefEdge[permutation][edge], - refEdge[edge], - *ordered); + // Order refEdge + orderRefEntityForGivenPermutation(refEdge[edge], + perm[permutation], + *ordered); // Return ordered return ordered; @@ -337,17 +294,17 @@ const std::vector<unsigned int>* ReferenceSpace:: getOrderedTriFace(unsigned int permutation, unsigned int face){ - /****************************************************** - * Same as getOrderedEdge, but I need to use 3 nodes. * - ******************************************************/ + /*********************************************** + * Same as getOrderedEdge, but I with refFace. * + ***********************************************/ // Alloc vector<unsigned int>* ordered = new vector<unsigned int>(3); - // Sort & Swap - sortAndSwap(permutedRefFace[permutation][face], - refFace[face], - *ordered); + // Order refFace + orderRefEntityForGivenPermutation(refFace[face], + perm[permutation], + *ordered); // Return ordered return ordered; @@ -358,9 +315,9 @@ getOrderedQuadFace(unsigned int permutation, unsigned int face){ /********************************************************************* - * Same as getOrderedEdge, but I need to use 4 nodes. * + * Same as getOrderedFace, but refFace has 4 nodes. * * * - * Moreover, * + * In that case, * * I need node at ordered[2] to be *opposite* to node at ordered[0]. * * --> If not make a permutation such * * that node opposite at ordered[2] * @@ -370,10 +327,10 @@ getOrderedQuadFace(unsigned int permutation, // Alloc vector<unsigned int>* ordered = new vector<unsigned int>(4); - // Sort & Swap - sortAndSwap(permutedRefFace[permutation][face], - refFace[face], - *ordered); + // Order refFace + orderRefEntityForGivenPermutation(refFace[face], + perm[permutation], + *ordered); // Get ordered[2] opposite to ordered[0] unsigned int opposite = ((*ordered)[0] + 2) % 4; @@ -395,18 +352,19 @@ getOrderedQuadFace(unsigned int permutation, return ordered; } -void ReferenceSpace::sortAndSwap(unsigned int* srcSort, - unsigned int* srcSwap, - vector<unsigned int>& dest){ +void ReferenceSpace:: +orderRefEntityForGivenPermutation(unsigned int* refEntity, + unsigned int* permutation, + vector<unsigned int>& orderedEntity){ // Get Size - const unsigned int size = dest.size(); + const unsigned int size = orderedEntity.size(); // Copy srcSort in sorted vector<pair<unsigned int, unsigned int> > sorted(size); for(unsigned int i = 0; i < size; i++){ sorted[i].first = i; - sorted[i].second = srcSort[i]; + sorted[i].second = permutation[refEntity[i]]; } // Sort it with repsect to second entry @@ -414,7 +372,7 @@ void ReferenceSpace::sortAndSwap(unsigned int* srcSort, // Swap with respect to srcSwap for(unsigned int i = 0; i < size; i++) - dest[i] = srcSwap[sorted[i].first]; + orderedEntity[i] = refEntity[sorted[i].first]; } unsigned int ReferenceSpace::getPermutation(const MElement& elem) const{ diff --git a/FunctionSpace/ReferenceSpace.h b/FunctionSpace/ReferenceSpace.h index e4ce84e31383d49d7e2340ed4a5028b7f2d088b8..e0dafe6441ea0803c300262a2c129b13db36e2c4 100644 --- a/FunctionSpace/ReferenceSpace.h +++ b/FunctionSpace/ReferenceSpace.h @@ -35,7 +35,7 @@ class ReferenceSpace{ typedef node_s node; protected: - // Permutation (Tree + Leaf) // + // Permutation (Tree + Leaf) of Reduced IDs // unsigned int nVertex; unsigned int nextLeafId; @@ -45,17 +45,44 @@ class ReferenceSpace{ node pTreeRoot; + ////////////////////////////////////////////////////////////////////////// + // !!! CHANGE VARIABLES NAME !!! // + // // + // perm = nodeReducedGlobalId // + // refEntity = entityNodeIndex // + // entity = orientedEntityNodeIndex // + // // + // !!! I'm Working on *BOTH* indexes and global IDs !!! // + // // + // 16 + // + // |\ ---> NodeIndex = [v0 v1 v2] // + // | \ ---> GlobalID = [17 42 16] // + // | \ ---> ReducedGlobalId = [1 2 0 ] ---> Permutation = 3 // + // 17 +---+ 42 // + // // + // * refEdge[e][i] = ith INDEX of edge[e] // + // For example refEdge[1] = [1 2] because edge[1] // + // - - // + // is made of nodes v1 and v2 // + // - - // + // // + // * edge[p][e][i] = ith INDEX of edge[e] in orientation[p] // + // such that GlobalID[edge[p][e][0]] > GlobalId[edge[p][e][0]] // + // For example edge[3][1] = [2 1] because edge[1] goes from v2 to v1 // + // - - - - // + ////////////////////////////////////////////////////////////////////////// + // Edge Permutation // unsigned int nEdge; unsigned int** refEdge; - unsigned int*** permutedRefEdge; + //unsigned int*** permutedRefEdge; std::vector<const std::vector<const std::vector<unsigned int>*>*>* edge; // Face Permutation // unsigned int nFace; unsigned int* nNodeInFace; unsigned int** refFace; - unsigned int*** permutedRefFace; + //unsigned int*** permutedRefFace; std::vector<const std::vector<const std::vector<unsigned int>*>*>* face; public: @@ -84,12 +111,12 @@ class ReferenceSpace{ void getEdge(void); void getFace(void); - + /* void getPermutedRefEntity(unsigned int**** permutedRefEntity, unsigned int** refEntity, unsigned int* nNodeInEntity, unsigned int nEntity); - + */ const std::vector<unsigned int>* getOrderedEdge(unsigned int permutation, unsigned int edge); @@ -99,19 +126,10 @@ class ReferenceSpace{ const std::vector<unsigned int>* getOrderedQuadFace(unsigned int permutation, unsigned int face); - static void sortAndSwap(unsigned int* srcSort, - unsigned int* srcSwap, - std::vector<unsigned int>& dest); - - static unsigned int whereIsIncluded(unsigned int elem, - unsigned int* vec, - unsigned int size); - - static void getIndex(unsigned int sizeRef, - unsigned int* ref, - unsigned int sizeVec, - unsigned int* vec, - unsigned int** idx); + static void + orderRefEntityForGivenPermutation(unsigned int* refEntity, + unsigned int* permutation, + std::vector<unsigned int>& orderedEntity); static bool sortPredicate(const std::pair<unsigned int, unsigned int>& a, const std::pair<unsigned int, unsigned int>& b); @@ -204,28 +222,6 @@ ReferenceSpace::getAllFace(void) const{ return *face; } -inline -void ReferenceSpace::getIndex(unsigned int sizeRef, - unsigned int* ref, - unsigned int sizeVec, - unsigned int* vec, - unsigned int** idx){ - - for(unsigned int i = 0; i < sizeRef; i++) - (*idx)[i] = whereIsIncluded(ref[i], vec, sizeVec); -} - -inline -unsigned int ReferenceSpace::whereIsIncluded(unsigned int elem, - unsigned int* vec, - unsigned int size){ - - for(unsigned int i = 0; i < size; i++) - if(vec[i] == elem) - return i; - - return -1; -} inline bool