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

Adding ReferenceSpace notion

parent 614f0a27
No related branches found
No related tags found
No related merge requests found
......@@ -15,25 +15,29 @@ string BasisScalar::toString(void) const{
stream << "Vertex Based:" << endl;
for(int i = 0; i < nVertex; i++)
stream << " f(" << i << ") = "
stream << " # " << i + 1 << "\t"
<< "f(" << i + 1 << ") = "
<< (*node)[i]->toString() << endl;
stream << "Edge Based:" << endl;
for(int i = 0; i < nEdge; i++)
for(int j = 0; j < nEdgeClosure; j++)
stream << " f_" << j << "(" << i << ") = "
stream << " # " << i + 1 + nVertex << "\t"
<< "f_" << j << "(" << i + 1 << ") = "
<< (*(*edge)[j])[i]->toString() << endl;
stream << "Face Based:" << endl;
for(int i = 0; i < nFace; i++)
for(int j = 0; j < nFaceClosure; j++)
stream << " f_" << j << "(" << i << ") = "
<< (*(*face)[j])[i]->toString() << endl;
stream << " # " << i + 1 + nVertex + nEdge << "\t"
<< "f_" << j << "(" << i + 1 << ") = "
<< (*(*face)[j])[i]->toString() << endl;
stream << "Cell Based:" << endl;
for(int i = 0; i < nCell; i++)
stream << " f(" << i << ") = "
<< (*cell)[i]->toString() << endl;
stream << " # " << i + 1 + nVertex + nEdge + nFace << "\t"
<< "f(" << i + 1 << ") = "
<< (*cell)[i]->toString() << endl;
return stream.str();
}
......@@ -15,33 +15,37 @@ string BasisVector::toString(void) const{
stream << "Vertex Based:" << endl;
for(int i = 0; i < nVertex; i++)
stream << " f(" << i << ") = " << endl
<< " [ " <<(*(*node)[i])[0].toString() << " ]" << endl
<< " [ " <<(*(*node)[i])[1].toString() << " ]" << endl
<< " [ " <<(*(*node)[i])[2].toString() << " ]" << endl;
stream << " # " << i + 1 << "\t"
<< "f(" << i + 1 << ") = " << endl
<< "\t [ " <<(*(*node)[i])[0].toString() << " ]" << endl
<< "\t [ " <<(*(*node)[i])[1].toString() << " ]" << endl
<< "\t [ " <<(*(*node)[i])[2].toString() << " ]" << endl;
stream << "Edge Based:" << endl;
for(int i = 0; i < nEdge; i++)
for(int j = 0; j < nEdgeClosure; j++)
stream << " f_" << j << "(" << i << ") = " << endl
<< " [ " << (*(*(*edge)[j])[i])[0].toString() << " ]" << endl
<< " [ " << (*(*(*edge)[j])[i])[1].toString() << " ]" << endl
<< " [ " << (*(*(*edge)[j])[i])[2].toString() << " ]" << endl;
stream << " # " << i + 1 + nVertex << "\t"
<< " f_" << j << "(" << i + 1 << ") = " << endl
<< "\t [ " << (*(*(*edge)[j])[i])[0].toString() << " ]" << endl
<< "\t [ " << (*(*(*edge)[j])[i])[1].toString() << " ]" << endl
<< "\t [ " << (*(*(*edge)[j])[i])[2].toString() << " ]" << endl;
stream << "Face Based:" << endl;
for(int i = 0; i < nFace; i++)
for(int j = 0; j < nFaceClosure; j++)
stream << " f_" << j << "(" << i << ") = " << endl
<< " [ " << (*(*(*face)[j])[i])[0].toString() << " ]" << endl
<< " [ " << (*(*(*face)[j])[i])[1].toString() << " ]" << endl
<< " [ " << (*(*(*face)[j])[i])[2].toString() << " ]" << endl;
stream << " # " << i + 1 + nVertex + nEdge << "\t"
<< " f_" << j << "(" << i + 1 << ") = " << endl
<< "\t [ " << (*(*(*face)[j])[i])[0].toString() << " ]" << endl
<< "\t [ " << (*(*(*face)[j])[i])[1].toString() << " ]" << endl
<< "\t [ " << (*(*(*face)[j])[i])[2].toString() << " ]" << endl;
stream << "Cell Based:" << endl;
for(int i = 0; i < nCell; i++)
stream << " f(" << i << ") = "
<< " [ " << (*(*cell)[i])[0].toString() << " ]" << endl
<< " [ " << (*(*cell)[i])[1].toString() << " ]" << endl
<< " [ " << (*(*cell)[i])[2].toString() << " ]" << endl;
stream << " # " << i + 1 + nVertex + nEdge << "\t"
<< " f(" << i + 1 << ") = " << endl
<< "\t [ " << (*(*cell)[i])[0].toString() << " ]" << endl
<< "\t [ " << (*(*cell)[i])[1].toString() << " ]" << endl
<< "\t [ " << (*(*cell)[i])[2].toString() << " ]" << endl;
return stream.str();
}
#include <sstream>
#include "ReferenceSpace.h"
using namespace std;
ReferenceSpace::ReferenceSpace(void){
}
ReferenceSpace::~ReferenceSpace(void){
// Destroy Tree //
destroy(&pTreeRoot);
delete[] perm;
// Delete Permutated Edge //
for(unsigned int p = 0; p < nPerm; p++){
for(unsigned int i = 0; i < nEdge; i++)
delete (*(*edge)[p])[i];
delete (*edge)[p];
}
delete edge;
// Delete Permutated Face //
for(unsigned int p = 0; p < nPerm; p++){
for(unsigned int i = 0; i < nFace; i++)
delete (*(*face)[p])[i];
delete (*face)[p];
}
delete face;
}
void ReferenceSpace::init(void){
// Init Root //
nPerm = 0;
pTreeRoot.depth = 0;
pTreeRoot.last = NULL;
pTreeRoot.number = nVertex;
pTreeRoot.possible = new unsigned int[pTreeRoot.number];
pTreeRoot.next = NULL;
for(unsigned int i = 0; i < pTreeRoot.number; i++)
pTreeRoot.possible[i] = i;
// Generate Tree //
lPerm = new list<unsigned int*>;
generate(&pTreeRoot);
perm = new unsigned int*[nPerm];
for(unsigned int i = 0; i < nPerm; i++){
perm[i] = lPerm->front();
lPerm->pop_front();
}
delete lPerm;
// Get Edges & Faces //
getEdge();
getFace();
}
void ReferenceSpace::generate(node* pTreeRoot){
const unsigned int number = pTreeRoot->number;
const unsigned int depth = pTreeRoot->depth;
if(!number){
pTreeRoot->next = NULL;
nPerm++;
lPerm->push_back(pTreeRoot->last);
}
else{
pTreeRoot->next = new node[number];
for(unsigned int i = 0; i < number; i++){
unsigned int nextDepth = pTreeRoot->depth + 1;
unsigned int nextLast = pTreeRoot->possible[i];
unsigned int nextNumber = number - 1;
unsigned int offset = 0;
pTreeRoot->next[i].depth = nextDepth;
pTreeRoot->next[i].last = new unsigned int[nextDepth];
pTreeRoot->next[i].last[depth] = nextLast;
for(unsigned int j = 0; j < depth; j++)
pTreeRoot->next[i].last[j] = pTreeRoot->last[j];
pTreeRoot->next[i].number = nextNumber;
pTreeRoot->next[i].possible = new unsigned int[nextNumber];
for(unsigned int j = 0; j < nextNumber; j++){
if(pTreeRoot->possible[j] == nextLast)
offset = 1;
pTreeRoot->next[i].possible[j] = pTreeRoot->possible[j + offset];
}
generate(&pTreeRoot->next[i]);
}
}
}
void ReferenceSpace::destroy(node* node){
const unsigned int number = node->number;
for(unsigned int i = 0; i < number; i++){
destroy(&node->next[i]);
node->number--;
}
delete[] node->possible;
delete[] node->last;
delete[] node->next;
}
void ReferenceSpace::getEdge(void){
vector<const vector<unsigned int>*>* tmp;
edge = new vector<const vector<const vector<unsigned int>*>*>(nPerm);
for(unsigned int p = 0; p < nPerm; p++){
tmp = new vector<const vector<unsigned int>*>(nEdge);
for(unsigned int i = 0; i < nEdge; i++)
(*tmp)[i] = inOrder(p,
refEdge[i][0],
refEdge[i][1]);
(*edge)[p] = tmp;
}
}
void ReferenceSpace::getFace(void){
vector<const vector<unsigned int>*>* tmp;
face = new vector<const vector<const vector<unsigned int>*>*>(nPerm);
for(unsigned int p = 0; p < nPerm; p++){
tmp = new vector<const vector<unsigned int>*>(nFace);
for(unsigned int i = 0; i < nFace; i++)
(*tmp)[i] = inOrder(p,
refFace[i][0],
refFace[i][1],
refFace[i][2]);
(*face)[p] = tmp;
}
}
const vector<unsigned int>* ReferenceSpace::
inOrder(unsigned int permutation,
unsigned int a,
unsigned int b){
unsigned int v;
unsigned int k = 0;
vector<unsigned int>* inorder =
new vector<unsigned int>(2);
for(unsigned int i = 0; i < nVertex; i++){
v = perm[permutation][i];
if(v == a || v == b){
(*inorder)[k] = v;
k++;
}
}
return inorder;
}
const std::vector<unsigned int>* ReferenceSpace::
inOrder(unsigned int permutation,
unsigned int a,
unsigned int b,
unsigned int c){
unsigned int v;
unsigned int k = 0;
vector<unsigned int>* inorder =
new vector<unsigned int>(3);
for(unsigned int i = 0; i < nVertex; i++){
v = perm[permutation][i];
if(v == a || v == b || v == c){
(*inorder)[k] = v;
k++;
}
}
return inorder;
}
string ReferenceSpace::toString(void) const{
stringstream stream;
// Tree //
stream << "Tree:" << endl;
stream << toString(&pTreeRoot) << endl;
// ReferenceSpaces //
stream << "ReferenceSpace:" << endl;
for(unsigned int i = 0; i < nPerm; i++){
stream << " * ";
for(unsigned int j = 0; j < nVertex; j++)
stream << perm[i][j] << " ";
stream << " (# " << i + 1 << ")" << endl;
}
return stream.str();
}
string ReferenceSpace::toString(const node* node) const{
const unsigned int number = node->number;
stringstream stream;
if(node->last)
stream << "(" << node->last[node->depth - 1] << " ";
else
stream << "(root ";
for(unsigned int i = 0; i < number; i++)
stream << toString(&node->next[i]);
stream << ")";
return stream.str();
}
#ifndef _REFERENCESPACE_H_
#define _REFERENCESPACE_H_
#include <vector>
#include <list>
#include <string>
class ReferenceSpace{
protected:
// Permuation Tree Structure //
struct node_s{
unsigned int depth; // Depth
unsigned int* last; // Last Choises
unsigned int number; // Number of Next Choise
unsigned int* possible; // Possible Next Choise
node_s* next; // Next Choise
};
typedef node_s node;
// Permutation (Tree + Leaf) //
unsigned int nVertex;
unsigned int nPerm;
unsigned int** perm;
node pTreeRoot;
mutable std::list<unsigned int*>* lPerm;
// Edge Permutation //
unsigned int nEdge;
unsigned int** refEdge;
std::vector<const std::vector<const std::vector<unsigned int>*>*>* edge;
// Face Permutation //
unsigned int nFace;
unsigned int** refFace;
std::vector<const std::vector<const std::vector<unsigned int>*>*>* face;
public:
virtual ~ReferenceSpace(void);
unsigned int getNReferenceSpace(void) const;
std::vector<const std::vector<const std::vector<unsigned int>*>*>&
getAllEdge(void) const;
std::vector<const std::vector<const std::vector<unsigned int>*>*>&
getAllFace(void) const ;
std::string toString(void) const;
protected:
ReferenceSpace(void);
void init(void);
void generate(node* pTreeRoot);
void destroy(node* node);
void getEdge(void);
void getFace(void);
const std::vector<unsigned int>* inOrder(unsigned int permutation,
unsigned int a,
unsigned int b);
const std::vector<unsigned int>* inOrder(unsigned int permutation,
unsigned int a,
unsigned int b,
unsigned int c);
std::string toString(const node* node) const;
};
//////////////////////
// Inline Functions //
//////////////////////
inline
unsigned int
ReferenceSpace::getNReferenceSpace(void) const{
return nPerm;
}
inline
std::vector<const std::vector<const std::vector<unsigned int>*>*>&
ReferenceSpace::getAllEdge(void) const{
return *edge;
}
inline
std::vector<const std::vector<const std::vector<unsigned int>*>*>&
ReferenceSpace::getAllFace(void) const{
return *face;
}
#endif
#include <sstream>
#include "TetReferenceSpace.h"
using namespace std;
TetReferenceSpace::TetReferenceSpace(void){
// Vertex Definition //
nVertex = 4;
// Edge Definition //
nEdge = 6;
refEdge = new unsigned int*[nEdge];
for(unsigned int i = 0; i < nEdge; i++)
refEdge[i] = new unsigned int[2];
refEdge[0][0] = 0; refEdge[0][1] = 1;
refEdge[1][0] = 1; refEdge[1][1] = 2;
refEdge[2][0] = 2; refEdge[2][1] = 0;
refEdge[3][0] = 0; refEdge[3][1] = 3;
refEdge[4][0] = 1; refEdge[4][1] = 3;
refEdge[5][0] = 2; refEdge[5][1] = 3;
// Face Definition //
nFace = 4;
refFace = new unsigned int*[nFace];
for(unsigned int i = 0; i < nFace; i++)
refFace[i] = new unsigned int[3];
refFace[0][0] = 0; refFace[0][1] = 1; refFace[0][2] = 2;
refFace[1][0] = 0; refFace[1][1] = 1; refFace[1][2] = 3;
refFace[2][0] = 1; refFace[2][1] = 2; refFace[2][2] = 3;
refFace[3][0] = 2; refFace[3][1] = 0; refFace[3][2] = 3;
// Init All //
init();
}
TetReferenceSpace::~TetReferenceSpace(void){
// Delete Ref Edge //
for(unsigned int i = 0; i < nEdge; i++)
delete[] refEdge[i];
delete[] refEdge;
// Delete Ref Face //
for(unsigned int i = 0; i < nFace; i++)
delete[] refFace[i];
delete[] refFace;
}
string TetReferenceSpace::toLatex(void) const{
stringstream stream;
stream << "\\documentclass{article}" << endl << endl
<< "\\usepackage{longtable}" << endl
<< "\\usepackage{tikz}" << endl
<< "\\usetikzlibrary{arrows}" << endl << endl
<< "\\begin{document}" << endl
<< "\\tikzstyle{vertex} = [circle, fill = black!25]" << endl
<< "\\tikzstyle{line} = [draw, thick, black, -latex']" << endl << endl
<< "\\begin{longtable}{ccc}" << endl << endl;
for(unsigned int p = 0; p < nPerm; p++){
stream << "\\begin{tikzpicture}" << endl
<< "\\node[vertex] (n0) at(0, 0) {$0$};" << endl
<< "\\node[vertex] (n1) at(3, 0) {$1$};" << endl
<< "\\node[vertex] (n2) at(0, 3) {$2$};" << endl
<< "\\node[vertex] (n3) at(1, 1) {$3$};" << endl << endl;
for(unsigned int i = 0; i < 6; i++)
stream << "\\path[line]"
<< " (n" << (*(*(*edge)[p])[i])[0] << ")"
<< " -- "
<< " (n" << (*(*(*edge)[p])[i])[1] << ");"
<< endl;
if((p + 1) % 3)
stream << "\\end{tikzpicture} & " << endl << endl;
else
stream << "\\end{tikzpicture} \\\\ \\\\" << endl << endl;
}
stream << "\\end{longtable}" << endl
<< "\\end{document}" << endl;
return stream.str();
}
/*
#include <iostream>
int main(void){
TetReferenceSpace p;
cout << p.toLatex() << endl;
return 0;
}
*/
#ifndef _TETREFERENCESPACE_H_
#define _TETREFERENCESPACE_H_
#include <string>
#include "ReferenceSpace.h"
class TetReferenceSpace: public ReferenceSpace{
public:
TetReferenceSpace(void);
virtual ~TetReferenceSpace(void);
std::string toLatex(void) const;
};
#endif
#include <sstream>
#include "TriReferenceSpace.h"
using namespace std;
TriReferenceSpace::TriReferenceSpace(void){
// Vertex Definition //
nVertex = 3;
// Edge Definition //
nEdge = 3;
refEdge = new unsigned int*[nEdge];
for(unsigned int i = 0; i < nEdge; i++)
refEdge[i] = new unsigned int[2];
refEdge[0][0] = 0; refEdge[0][1] = 1;
refEdge[1][0] = 1; refEdge[1][1] = 2;
refEdge[2][0] = 2; refEdge[2][1] = 0;
// Face Definition //
nFace = 0;
refFace = NULL;
// Init All //
init();
}
TriReferenceSpace::~TriReferenceSpace(void){
// Delete Ref Edge //
for(unsigned int i = 0; i < nEdge; i++)
delete[] refEdge[i];
delete[] refEdge;
}
string TriReferenceSpace::toLatex(void) const{
stringstream stream;
stream << "\\documentclass{article}" << endl << endl
<< "\\usepackage{longtable}" << endl
<< "\\usepackage{tikz}" << endl
<< "\\usetikzlibrary{arrows}" << endl << endl
<< "\\begin{document}" << endl
<< "\\tikzstyle{vertex} = [circle, fill = black!25]" << endl
<< "\\tikzstyle{line} = [draw, thick, black, -latex']" << endl << endl
<< "\\begin{longtable}{ccc}" << endl << endl;
for(unsigned int p = 0; p < nPerm; p++){
stream << "\\begin{tikzpicture}" << endl
<< "\\node[vertex] (n0) at(0, 0) {$0$};" << endl
<< "\\node[vertex] (n1) at(3, 0) {$1$};" << endl
<< "\\node[vertex] (n2) at(0, 3) {$2$};" << endl << endl;
for(unsigned int i = 0; i < 3; i++)
stream << "\\path[line]"
<< " (n" << (*(*(*edge)[p])[i])[0] << ")"
<< " -- "
<< " (n" << (*(*(*edge)[p])[i])[1] << ");"
<< endl;
if((p + 1) % 3)
stream << "\\end{tikzpicture} & " << endl << endl;
else
stream << "\\end{tikzpicture} \\\\ \\\\" << endl << endl;
}
stream << "\\end{longtable}" << endl
<< "\\end{document}" << endl;
return stream.str();
}
/*
#include <iostream>
int main(void){
TriReferenceSpace p;
cout << p.toLatex() << endl;
return 0;
}
*/
#ifndef _TRIREFERENCESPACE_H_
#define _TRIREFERENCESPACE_H_
#include <string>
#include "ReferenceSpace.h"
class TriReferenceSpace: public ReferenceSpace{
public:
TriReferenceSpace(void);
virtual ~TriReferenceSpace(void);
std::string toLatex(void) const;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment