Skip to content
Snippets Groups Projects
Commit 80937295 authored by Nicolas Marsic's avatar Nicolas Marsic
Browse files

ReferenceSpace simplified

parent 873822eb
Branches
Tags
No related merge requests found
...@@ -23,13 +23,13 @@ ReferenceSpace::ReferenceSpace(void){ ...@@ -23,13 +23,13 @@ ReferenceSpace::ReferenceSpace(void){
nEdge = 0; nEdge = 0;
refEdge = NULL; refEdge = NULL;
permutedRefEdge = NULL; //permutedRefEdge = NULL;
edge = NULL; edge = NULL;
nFace = 0; nFace = 0;
nNodeInFace = NULL; nNodeInFace = NULL;
refFace = NULL; refFace = NULL;
permutedRefFace = NULL; //permutedRefFace = NULL;
face = NULL; face = NULL;
// Defining Ref Edge and Face in // // Defining Ref Edge and Face in //
...@@ -44,29 +44,29 @@ ReferenceSpace::~ReferenceSpace(void){ ...@@ -44,29 +44,29 @@ ReferenceSpace::~ReferenceSpace(void){
// Delete Permutated Edge // // Delete Permutated Edge //
for(unsigned int p = 0; p < nPerm; p++){ for(unsigned int p = 0; p < nPerm; p++){
for(unsigned int i = 0; i < nEdge; i++){ for(unsigned int i = 0; i < nEdge; i++){
delete[] permutedRefEdge[p][i]; //delete[] permutedRefEdge[p][i];
delete (*(*edge)[p])[i]; delete (*(*edge)[p])[i];
} }
delete[] permutedRefEdge[p]; //delete[] permutedRefEdge[p];
delete (*edge)[p]; delete (*edge)[p];
} }
delete[] permutedRefEdge; //delete[] permutedRefEdge;
delete edge; delete edge;
// Delete Permutated Face // // Delete Permutated Face //
for(unsigned int p = 0; p < nPerm; p++){ for(unsigned int p = 0; p < nPerm; p++){
for(unsigned int i = 0; i < nFace; i++){ for(unsigned int i = 0; i < nFace; i++){
delete[] permutedRefFace[p][i]; //delete[] permutedRefFace[p][i];
delete (*(*face)[p])[i]; delete (*(*face)[p])[i];
} }
delete[] permutedRefFace[p]; //delete[] permutedRefFace[p];
delete (*face)[p]; delete (*face)[p];
} }
delete[] permutedRefFace; //delete[] permutedRefFace;
delete face; delete face;
} }
...@@ -102,30 +102,6 @@ void ReferenceSpace::init(void){ ...@@ -102,30 +102,6 @@ void ReferenceSpace::init(void){
// Get Edges & Faces // // Get Edges & Faces //
getEdge(); getEdge();
getFace(); 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){ void ReferenceSpace::populate(node* pTreeRoot){
...@@ -205,7 +181,7 @@ void ReferenceSpace::getEdge(void){ ...@@ -205,7 +181,7 @@ void ReferenceSpace::getEdge(void){
// Alloc // Alloc
vector<const vector<unsigned int>*>* tmp; vector<const vector<unsigned int>*>* tmp;
edge = new vector<const vector<const vector<unsigned int>*>*>(nPerm); edge = new vector<const vector<const vector<unsigned int>*>*>(nPerm);
/*
// All Edges have two nodes // All Edges have two nodes
unsigned int* nNodeInEdge = new unsigned int[nEdge]; unsigned int* nNodeInEdge = new unsigned int[nEdge];
...@@ -221,7 +197,7 @@ void ReferenceSpace::getEdge(void){ ...@@ -221,7 +197,7 @@ void ReferenceSpace::getEdge(void){
nEdge); nEdge);
delete[] nNodeInEdge; delete[] nNodeInEdge;
*/
// Populate Edge // Populate Edge
for(unsigned int p = 0; p < nPerm; p++){ for(unsigned int p = 0; p < nPerm; p++){
tmp = new vector<const vector<unsigned int>*>(nEdge); tmp = new vector<const vector<unsigned int>*>(nEdge);
...@@ -237,7 +213,7 @@ void ReferenceSpace::getFace(void){ ...@@ -237,7 +213,7 @@ void ReferenceSpace::getFace(void){
// Alloc // Alloc
vector<const vector<unsigned int>*>* tmp; vector<const vector<unsigned int>*>* tmp;
face = new vector<const vector<const vector<unsigned int>*>*>(nPerm); face = new vector<const vector<const vector<unsigned int>*>*>(nPerm);
/*
// Get Face nodes depending on the orientation // Get Face nodes depending on the orientation
// (face 1 = [1 2 3 4] for orientation 1) // (face 1 = [1 2 3 4] for orientation 1)
// ( = [4 1 2 3] for orientation 2) // ( = [4 1 2 3] for orientation 2)
...@@ -245,7 +221,7 @@ void ReferenceSpace::getFace(void){ ...@@ -245,7 +221,7 @@ void ReferenceSpace::getFace(void){
refFace, refFace,
nNodeInFace, nNodeInFace,
nFace); nFace);
*/
// Populate Face // Populate Face
for(unsigned int p = 0; p < nPerm; p++){ for(unsigned int p = 0; p < nPerm; p++){
tmp = new vector<const vector<unsigned int>*>(nFace); tmp = new vector<const vector<unsigned int>*>(nFace);
...@@ -267,7 +243,7 @@ void ReferenceSpace::getFace(void){ ...@@ -267,7 +243,7 @@ void ReferenceSpace::getFace(void){
(*face)[p] = tmp; (*face)[p] = tmp;
} }
} }
/*
void ReferenceSpace::getPermutedRefEntity(unsigned int**** permutedRefEntity, void ReferenceSpace::getPermutedRefEntity(unsigned int**** permutedRefEntity,
unsigned int** refEntity, unsigned int** refEntity,
unsigned int* nNodeInEntity, unsigned int* nNodeInEntity,
...@@ -282,52 +258,33 @@ void ReferenceSpace::getPermutedRefEntity(unsigned int**** permutedRefEntity, ...@@ -282,52 +258,33 @@ void ReferenceSpace::getPermutedRefEntity(unsigned int**** permutedRefEntity,
(*permutedRefEntity)[p][e] = new unsigned int[nNodeInEntity[e]]; (*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 // Generate Permuted Ref Entity
for(unsigned int p = 0; p < nPerm; p++){ for(unsigned int p = 0; p < nPerm; p++){
for(unsigned int e = 0; e < nEntity; e++){ for(unsigned int e = 0; e < nEntity; e++){
for(unsigned int n = 0; n < nNodeInEntity[e]; n++) 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:: const vector<unsigned int>* ReferenceSpace::
getOrderedEdge(unsigned int permutation, getOrderedEdge(unsigned int permutation,
unsigned int edge){ unsigned int edge){
/************************************************************************* /**************************************************************************
* Let say we have we have permutedRefEdge[4][2] = [0 1]. * * I want to know how I need to take the values of refEdge[edge] *
* I want to get back to same node ID than refEdge[2] = [2 0]. * * (i.e the node *index* of a given edge) so that the corresponding *
* That is, I want to return [0 2]. * * values in permutation (i.e perm[permutation][refEdge[edge]]) are going *
* * * from the smallest value to the biggest. *
* I need to sort permutedRefEdge and keep the index swaping. * **************************************************************************/
* I can use this index swaping to get the right permutation of refEdge. *
*************************************************************************/
// Alloc // Alloc
vector<unsigned int>* ordered = new vector<unsigned int>(2); vector<unsigned int>* ordered = new vector<unsigned int>(2);
// Sort & Swap // Order refEdge
sortAndSwap(permutedRefEdge[permutation][edge], orderRefEntityForGivenPermutation(refEdge[edge],
refEdge[edge], perm[permutation],
*ordered); *ordered);
// Return ordered // Return ordered
return ordered; return ordered;
...@@ -337,17 +294,17 @@ const std::vector<unsigned int>* ReferenceSpace:: ...@@ -337,17 +294,17 @@ const std::vector<unsigned int>* ReferenceSpace::
getOrderedTriFace(unsigned int permutation, getOrderedTriFace(unsigned int permutation,
unsigned int face){ unsigned int face){
/****************************************************** /***********************************************
* Same as getOrderedEdge, but I need to use 3 nodes. * * Same as getOrderedEdge, but I with refFace. *
******************************************************/ ***********************************************/
// Alloc // Alloc
vector<unsigned int>* ordered = new vector<unsigned int>(3); vector<unsigned int>* ordered = new vector<unsigned int>(3);
// Sort & Swap // Order refFace
sortAndSwap(permutedRefFace[permutation][face], orderRefEntityForGivenPermutation(refFace[face],
refFace[face], perm[permutation],
*ordered); *ordered);
// Return ordered // Return ordered
return ordered; return ordered;
...@@ -358,9 +315,9 @@ getOrderedQuadFace(unsigned int permutation, ...@@ -358,9 +315,9 @@ getOrderedQuadFace(unsigned int permutation,
unsigned int face){ 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]. * * I need node at ordered[2] to be *opposite* to node at ordered[0]. *
* --> If not make a permutation such * * --> If not make a permutation such *
* that node opposite at ordered[2] * * that node opposite at ordered[2] *
...@@ -370,10 +327,10 @@ getOrderedQuadFace(unsigned int permutation, ...@@ -370,10 +327,10 @@ getOrderedQuadFace(unsigned int permutation,
// Alloc // Alloc
vector<unsigned int>* ordered = new vector<unsigned int>(4); vector<unsigned int>* ordered = new vector<unsigned int>(4);
// Sort & Swap // Order refFace
sortAndSwap(permutedRefFace[permutation][face], orderRefEntityForGivenPermutation(refFace[face],
refFace[face], perm[permutation],
*ordered); *ordered);
// Get ordered[2] opposite to ordered[0] // Get ordered[2] opposite to ordered[0]
unsigned int opposite = ((*ordered)[0] + 2) % 4; unsigned int opposite = ((*ordered)[0] + 2) % 4;
...@@ -395,18 +352,19 @@ getOrderedQuadFace(unsigned int permutation, ...@@ -395,18 +352,19 @@ getOrderedQuadFace(unsigned int permutation,
return ordered; return ordered;
} }
void ReferenceSpace::sortAndSwap(unsigned int* srcSort, void ReferenceSpace::
unsigned int* srcSwap, orderRefEntityForGivenPermutation(unsigned int* refEntity,
vector<unsigned int>& dest){ unsigned int* permutation,
vector<unsigned int>& orderedEntity){
// Get Size // Get Size
const unsigned int size = dest.size(); const unsigned int size = orderedEntity.size();
// Copy srcSort in sorted // Copy srcSort in sorted
vector<pair<unsigned int, unsigned int> > sorted(size); vector<pair<unsigned int, unsigned int> > sorted(size);
for(unsigned int i = 0; i < size; i++){ for(unsigned int i = 0; i < size; i++){
sorted[i].first = i; sorted[i].first = i;
sorted[i].second = srcSort[i]; sorted[i].second = permutation[refEntity[i]];
} }
// Sort it with repsect to second entry // Sort it with repsect to second entry
...@@ -414,7 +372,7 @@ void ReferenceSpace::sortAndSwap(unsigned int* srcSort, ...@@ -414,7 +372,7 @@ void ReferenceSpace::sortAndSwap(unsigned int* srcSort,
// Swap with respect to srcSwap // Swap with respect to srcSwap
for(unsigned int i = 0; i < size; i++) 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{ unsigned int ReferenceSpace::getPermutation(const MElement& elem) const{
......
...@@ -35,7 +35,7 @@ class ReferenceSpace{ ...@@ -35,7 +35,7 @@ class ReferenceSpace{
typedef node_s node; typedef node_s node;
protected: protected:
// Permutation (Tree + Leaf) // // Permutation (Tree + Leaf) of Reduced IDs //
unsigned int nVertex; unsigned int nVertex;
unsigned int nextLeafId; unsigned int nextLeafId;
...@@ -45,17 +45,44 @@ class ReferenceSpace{ ...@@ -45,17 +45,44 @@ class ReferenceSpace{
node pTreeRoot; 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 // // Edge Permutation //
unsigned int nEdge; unsigned int nEdge;
unsigned int** refEdge; unsigned int** refEdge;
unsigned int*** permutedRefEdge; //unsigned int*** permutedRefEdge;
std::vector<const std::vector<const std::vector<unsigned int>*>*>* edge; std::vector<const std::vector<const std::vector<unsigned int>*>*>* edge;
// Face Permutation // // Face Permutation //
unsigned int nFace; unsigned int nFace;
unsigned int* nNodeInFace; unsigned int* nNodeInFace;
unsigned int** refFace; unsigned int** refFace;
unsigned int*** permutedRefFace; //unsigned int*** permutedRefFace;
std::vector<const std::vector<const std::vector<unsigned int>*>*>* face; std::vector<const std::vector<const std::vector<unsigned int>*>*>* face;
public: public:
...@@ -84,12 +111,12 @@ class ReferenceSpace{ ...@@ -84,12 +111,12 @@ class ReferenceSpace{
void getEdge(void); void getEdge(void);
void getFace(void); void getFace(void);
/*
void getPermutedRefEntity(unsigned int**** permutedRefEntity, void getPermutedRefEntity(unsigned int**** permutedRefEntity,
unsigned int** refEntity, unsigned int** refEntity,
unsigned int* nNodeInEntity, unsigned int* nNodeInEntity,
unsigned int nEntity); unsigned int nEntity);
*/
const std::vector<unsigned int>* getOrderedEdge(unsigned int permutation, const std::vector<unsigned int>* getOrderedEdge(unsigned int permutation,
unsigned int edge); unsigned int edge);
...@@ -99,19 +126,10 @@ class ReferenceSpace{ ...@@ -99,19 +126,10 @@ class ReferenceSpace{
const std::vector<unsigned int>* getOrderedQuadFace(unsigned int permutation, const std::vector<unsigned int>* getOrderedQuadFace(unsigned int permutation,
unsigned int face); unsigned int face);
static void sortAndSwap(unsigned int* srcSort, static void
unsigned int* srcSwap, orderRefEntityForGivenPermutation(unsigned int* refEntity,
std::vector<unsigned int>& dest); unsigned int* permutation,
std::vector<unsigned int>& orderedEntity);
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 bool sortPredicate(const std::pair<unsigned int, unsigned int>& a, static bool sortPredicate(const std::pair<unsigned int, unsigned int>& a,
const std::pair<unsigned int, unsigned int>& b); const std::pair<unsigned int, unsigned int>& b);
...@@ -204,28 +222,6 @@ ReferenceSpace::getAllFace(void) const{ ...@@ -204,28 +222,6 @@ ReferenceSpace::getAllFace(void) const{
return *face; 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 inline
bool bool
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment