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

Prepatation for Lagrange ReferenceSpace + correct consteness + cleaning some...

Prepatation for Lagrange ReferenceSpace + correct consteness + cleaning some tabs -- replaced by spaces
parent 6ba9a24a
No related branches found
No related tags found
No related merge requests found
#include "Exception.h" #include "Exception.h"
#include "BasisLagrange.h" #include "BasisLagrange.h"
using namespace std;
BasisLagrange::BasisLagrange(void){ BasisLagrange::BasisLagrange(void){
scalar = true; scalar = true;
} }
...@@ -10,30 +12,40 @@ BasisLagrange::~BasisLagrange(void){ ...@@ -10,30 +12,40 @@ BasisLagrange::~BasisLagrange(void){
unsigned int BasisLagrange:: unsigned int BasisLagrange::
getNOrientation(void) const{ getNOrientation(void) const{
throw Exception("BasisLagrange::Not Implemented"); return refSpace->getNPermutation();
} }
unsigned int BasisLagrange:: unsigned int BasisLagrange::
getOrientation(const MElement& element) const{ getOrientation(const MElement& element) const{
throw Exception("BasisLagrange::Not Implemented"); return refSpace->getPermutation(element);
} }
fullMatrix<double>* BasisLagrange:: fullMatrix<double>* BasisLagrange::
getFunctions(const MElement& element, getFunctions(const MElement& element,
double u, double v, double w) const{ double u, double v, double w) const{
throw Exception("BasisLagrange::Not Implemented");
// Fill Matrix //
fullMatrix<double> tmp;
fullMatrix<double> point(1, 3);
point(0, 0) = u;
point(0, 1) = v;
point(0, 2) = w;
lBasis->f(point, tmp);
// Transpose 'tmp': otherwise not coherent with df !!
fullMatrix<double> values = tmp.transpose();
// Get Inorder & Return //
return inorder(refSpace->getPermutation(element), values);
} }
fullMatrix<double>* BasisLagrange::getFunctions(unsigned int orientation, fullMatrix<double>* BasisLagrange::
getFunctions(unsigned int orientation,
double u, double v, double w) const{ double u, double v, double w) const{
throw Exception("BasisLagrange::Not Implemented");
/*
// Alloc Memory //
fullMatrix<double> tmp(nFunction, 1);
fullMatrix<double>* values = new fullMatrix<double>(nFunction, 1);
// Fill Matrix // // Fill Matrix //
fullMatrix<double> tmp;
fullMatrix<double> point(1, 3); fullMatrix<double> point(1, 3);
point(0, 0) = u; point(0, 0) = u;
point(0, 1) = v; point(0, 1) = v;
...@@ -41,18 +53,19 @@ fullMatrix<double>* BasisLagrange::getFunctions(unsigned int orientation, ...@@ -41,18 +53,19 @@ fullMatrix<double>* BasisLagrange::getFunctions(unsigned int orientation,
lBasis->f(point, tmp); lBasis->f(point, tmp);
*values = tmp.transpose(); // Otherwise not coherent with df !! // Transpose 'tmp': otherwise not coherent with df !!
fullMatrix<double> values = tmp.transpose();
// Return // // Get Inorder & Return //
return values; return inorder(orientation, values);
*/
} }
void BasisLagrange::preEvaluateFunctions(const fullMatrix<double>& point) const{ void BasisLagrange::preEvaluateFunctions(const fullMatrix<double>& point) const{
throw Exception("BasisLagrange::Not Implemented"); throw Exception("BasisLagrange::Not Implemented");
} }
void BasisLagrange::preEvaluateDerivatives(const fullMatrix<double>& point) const{ void BasisLagrange::
preEvaluateDerivatives(const fullMatrix<double>& point) const{
throw Exception("BasisLagrange::Not Implemented"); throw Exception("BasisLagrange::Not Implemented");
} }
...@@ -76,14 +89,14 @@ BasisLagrange::getPreEvaluatedDerivatives(unsigned int orientation) const{ ...@@ -76,14 +89,14 @@ BasisLagrange::getPreEvaluatedDerivatives(unsigned int orientation) const{
throw Exception("BasisLagrange::Not Implemented"); throw Exception("BasisLagrange::Not Implemented");
} }
std::vector<double> BasisLagrange:: vector<double> BasisLagrange::
project(const MElement& element, project(const MElement& element,
const std::vector<double>& coef, const vector<double>& coef,
const FunctionSpaceScalar& fSpace){ const FunctionSpaceScalar& fSpace){
// Init New Coefs // // Init New Coefs //
const unsigned int size = lPoint->size1(); const unsigned int size = lPoint->size1();
std::vector<double> newCoef(size); vector<double> newCoef(size);
// Interpolation at Lagrange Points // // Interpolation at Lagrange Points //
for(unsigned int i = 0; i < size; i++){ for(unsigned int i = 0; i < size; i++){
...@@ -101,14 +114,14 @@ project(const MElement& element, ...@@ -101,14 +114,14 @@ project(const MElement& element,
return newCoef; return newCoef;
} }
std::vector<fullVector<double> > BasisLagrange:: vector<fullVector<double> > BasisLagrange::
project(const MElement& element, project(const MElement& element,
const std::vector<double>& coef, const vector<double>& coef,
const FunctionSpaceVector& fSpace){ const FunctionSpaceVector& fSpace){
// Init New Coefs // // Init New Coefs //
const unsigned int size = lPoint->size1(); const unsigned int size = lPoint->size1();
std::vector<fullVector<double> > newCoef(size); vector<fullVector<double> > newCoef(size);
// Interpolation at Lagrange Points // // Interpolation at Lagrange Points //
for(unsigned int i = 0; i < size; i++){ for(unsigned int i = 0; i < size; i++){
...@@ -125,3 +138,25 @@ project(const MElement& element, ...@@ -125,3 +138,25 @@ project(const MElement& element,
// Return ; // Return ;
return newCoef; return newCoef;
} }
fullMatrix<double>* BasisLagrange::inorder(unsigned int orientation,
fullMatrix<double>& mat) const{
// Matrix Size //
const int nRow = mat.size1();
const int nCol = mat.size2();
// Order //
const vector<unsigned int>* order =
refSpace->getAllLagrangeNode()[orientation];
// Alloc new matrix //
fullMatrix<double>* ret = new fullMatrix<double>(nRow, nCol);
// Populate //
for(int i = 0; i < nRow; i++)
for(int j = 0; j < nCol; j++)
(*ret)(i, j) = mat((*order)[i], j);
// Return //
return ret;
}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "FunctionSpaceVector.h" #include "FunctionSpaceVector.h"
#include "fullMatrix.h" #include "fullMatrix.h"
#include "polynomialBasis.h" #include "polynomialBasis.h"
#include "ReferenceSpaceLagrange.h"
/** /**
@interface BasisLagrange @interface BasisLagrange
...@@ -27,6 +28,7 @@ class BasisLagrange: public BasisLocal{ ...@@ -27,6 +28,7 @@ class BasisLagrange: public BasisLocal{
protected: protected:
polynomialBasis* lBasis; // Lagrange Basis polynomialBasis* lBasis; // Lagrange Basis
fullMatrix<double>* lPoint; // Lagrange Points fullMatrix<double>* lPoint; // Lagrange Points
ReferenceSpaceLagrange* refSpace; // Reference Space
public: public:
virtual ~BasisLagrange(void); virtual ~BasisLagrange(void);
...@@ -70,6 +72,9 @@ class BasisLagrange: public BasisLocal{ ...@@ -70,6 +72,9 @@ class BasisLagrange: public BasisLocal{
protected: protected:
BasisLagrange(void); BasisLagrange(void);
fullMatrix<double>* inorder(unsigned int orientation,
fullMatrix<double>& mat) const;
}; };
......
...@@ -13,6 +13,9 @@ set(SRC ...@@ -13,6 +13,9 @@ set(SRC
QuadReferenceSpace.cpp QuadReferenceSpace.cpp
TetReferenceSpace.cpp TetReferenceSpace.cpp
ReferenceSpaceLagrange.cpp
TriLagrangeReferenceSpace.cpp
Basis.cpp Basis.cpp
BasisLocal.cpp BasisLocal.cpp
BasisGenerator.cpp BasisGenerator.cpp
......
...@@ -449,3 +449,16 @@ string ReferenceSpace::toString(const node* node) const{ ...@@ -449,3 +449,16 @@ string ReferenceSpace::toString(const node* node) const{
return stream.str(); return stream.str();
} }
string ReferenceSpace::toLatex(void) const{
stringstream stream;
stream << "\\documentclass{article}" << endl << endl
<< "\\begin{document}" << endl
<< "\texttt{toLatex} not implemented" << endl
<< "\\end{document}" << endl;
return stream.str();
}
...@@ -67,15 +67,15 @@ class ReferenceSpace{ ...@@ -67,15 +67,15 @@ class ReferenceSpace{
unsigned int getPermutation(const MElement& element) const; unsigned int getPermutation(const MElement& element) const;
std::vector<const std::vector<const std::vector<unsigned int>*>*>& const std::vector<const std::vector<const std::vector<unsigned int>*>*>&
getAllEdge(void) const; getAllEdge(void) const;
std::vector<const std::vector<const std::vector<unsigned int>*>*>& const std::vector<const std::vector<const std::vector<unsigned int>*>*>&
getAllFace(void) const ; getAllFace(void) const ;
std::string toString(void) const; virtual std::string toString(void) const;
virtual std::string toLatex(void) const = 0; virtual std::string toLatex(void) const;
protected: protected:
ReferenceSpace(void); ReferenceSpace(void);
...@@ -188,13 +188,13 @@ ReferenceSpace::getNPermutation(void) const{ ...@@ -188,13 +188,13 @@ ReferenceSpace::getNPermutation(void) const{
} }
inline inline
std::vector<const std::vector<const std::vector<unsigned int>*>*>& const std::vector<const std::vector<const std::vector<unsigned int>*>*>&
ReferenceSpace::getAllEdge(void) const{ ReferenceSpace::getAllEdge(void) const{
return *edge; return *edge;
} }
inline inline
std::vector<const std::vector<const std::vector<unsigned int>*>*>& const std::vector<const std::vector<const std::vector<unsigned int>*>*>&
ReferenceSpace::getAllFace(void) const{ ReferenceSpace::getAllFace(void) const{
return *face; return *face;
} }
......
#include <sstream>
#include "ReferenceSpaceLagrange.h"
using namespace std;
ReferenceSpaceLagrange::ReferenceSpaceLagrange(void){
// Init to NULL //
node = NULL;
}
ReferenceSpaceLagrange::~ReferenceSpaceLagrange(void){
// If 'node' allocated //
if(node){
for(unsigned int p = 0; p < nPerm; p++)
delete (*node)[p];
delete node;
}
}
void ReferenceSpaceLagrange::getLagrangeNode(void){
// Alloc //
vector<unsigned int>* tmp;
node = new vector<const vector<unsigned int>*>(nPerm);
// Populate //
for(unsigned int p = 0; p < nPerm; p++){
// Alloc Temp //
tmp = new vector<unsigned int>(nNode);
// Vertex based node
for(unsigned int i = 0; i < nVertex; i++)
(*tmp)[i] = i;
// Edge based node
for(unsigned int e = 0; e < nEdge; e++)
edgeSeq(*tmp,
nVertex + nNodePerEdge * e,
nVertex + nNodePerEdge * e,
nVertex + nNodePerEdge * (e + 1),
refEdge[e],
*(*(*edge)[p])[e]);
// Face based node
for(unsigned int f = 0; f < nFace; f++)
faceSeq(*tmp,
nVertex + nNodePerEdge * nEdge + nNodePerFace * f,
nVertex + nNodePerEdge * nEdge + nNodePerFace * f,
nVertex + nNodePerEdge * nEdge + nNodePerFace * (f + 1),
refFace[f],
*(*(*face)[p])[f],
nNodePerEdge);
// Insert in node
(*node)[p] = tmp;
}
}
void ReferenceSpaceLagrange::edgeSeq(vector<unsigned int>& vec,
unsigned int startIdx,
unsigned int startVal,
unsigned int stopVal,
unsigned int* refEdge,
const vector<unsigned int>& edge){
// Is reverted ? //
const bool isRevert = (edge[0] != refEdge[0]);
// Index //
unsigned int val = startVal;
unsigned int idx;
// Depending if edge is reverted ...
if(isRevert)
idx = startIdx + stopVal - startVal - 1;
else
idx = startIdx;
// Populate //
for(; val < stopVal; val++){
vec[idx] = val;
if(isRevert)
idx--;
else
idx++;
}
}
void ReferenceSpaceLagrange::faceSeq(vector<unsigned int>& vec,
unsigned int startIdx,
unsigned int startVal,
unsigned int stopVal,
unsigned int* refFace,
const vector<unsigned int>& face,
unsigned int nNodePerEdge){
// Index //
unsigned int val = startVal;
unsigned int idx = startIdx;
// Populate //
for(; val < stopVal; val++){
vec[idx] = val;
idx++;
}
}
string ReferenceSpaceLagrange::toString(void) const{
const unsigned int nNodeMinus = nNode - 1;
stringstream stream;
stream << ReferenceSpace::toString();
stream << "Lagrange Nodes Permutations:" << endl;
for(unsigned int i = 0; i < nPerm; i++){
stream << " * RefSpace #" << i + 1 << ":" << endl
<< " -- [";
for(unsigned int j = 0; j < nNodeMinus; j++)
stream << node->at(i)->at(j) << ", ";
stream << node->at(i)->at(nNodeMinus) << "]" << endl;
}
return stream.str();
}
#ifndef _REFERENCESPACELAGRANGE_H_
#define _REFERENCESPACELAGRANGE_H_
#include "ReferenceSpace.h"
/**
@interface ReferenceSpaceLagrange
@brief Base interface for all Lagrange ReferenceSpace%s
This class is a particular ReferenceSpace for
@em Lagrange Basis.@n
This class adds the notion of Lagrange points and
their permutations depending on the orientation
of a MElement.@n
Lagrange points are ordered in a way such that
Lagrange function must be taken in that order in order
to have an oriented basis.@n
Because the number of Lagrange Points depends on
the the order of the Lagrange Basis,
a ReferenceSpaceLagrange shall depend on the order.
*/
class ReferenceSpaceLagrange: public ReferenceSpace{
protected:
// Lagrange Node Permutation //
unsigned int nNode;
unsigned int nNodePerEdge;
unsigned int nNodePerFace;
unsigned int nNodePerCell;
std::vector<const std::vector<unsigned int>*>* node;
public:
virtual ~ReferenceSpaceLagrange(void);
const std::vector<const std::vector<unsigned int>*>&
getAllLagrangeNode(void) const;
virtual std::string toString(void) const;
protected:
ReferenceSpaceLagrange(void);
void getLagrangeNode(void);
static void edgeSeq(std::vector<unsigned int>& vec,
unsigned int startIdx,
unsigned int startVal,
unsigned int stopVal,
unsigned int* refEdge,
const std::vector<unsigned int>& edge);
static void faceSeq(std::vector<unsigned int>& vec,
unsigned int startIdx,
unsigned int startVal,
unsigned int stopVal,
unsigned int* refFace,
const std::vector<unsigned int>& face,
unsigned int nNodePerEdge);
};
/////////////////////
// Inline Function //
/////////////////////
inline
const std::vector<const std::vector<unsigned int>*>&
ReferenceSpaceLagrange::getAllLagrangeNode(void) const{
return *node;
}
#endif
#include "Exception.h" #include "Exception.h"
#include "TriLagrangeBasis.h" #include "TriLagrangeBasis.h"
#include "pointsGenerators.h" #include "pointsGenerators.h"
#include "TriLagrangeReferenceSpace.h"
#include <iostream>
TriLagrangeBasis::TriLagrangeBasis(unsigned int order){ TriLagrangeBasis::TriLagrangeBasis(unsigned int order){
// If order 0 (Nedelec): use order 1 // If order 0 (Nedelec): use order 1
...@@ -25,11 +28,16 @@ TriLagrangeBasis::TriLagrangeBasis(unsigned int order){ ...@@ -25,11 +28,16 @@ TriLagrangeBasis::TriLagrangeBasis(unsigned int order){
// Init Lagrange Point // // Init Lagrange Point //
lPoint = new fullMatrix<double> lPoint = new fullMatrix<double>
(gmshGeneratePointsTriangle(order, false)); (gmshGeneratePointsTriangle(order, false));
// ReferenceSpace //
refSpace = new TriLagrangeReferenceSpace(order);
std::cout << refSpace->toString() << std::endl;
} }
TriLagrangeBasis::~TriLagrangeBasis(void){ TriLagrangeBasis::~TriLagrangeBasis(void){
delete lBasis; delete lBasis;
delete lPoint; delete lPoint;
delete refSpace;
} }
unsigned int TriLagrangeBasis::getTag(unsigned int order){ unsigned int TriLagrangeBasis::getTag(unsigned int order){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment