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

Grad/Curl/Div of Basis and Function Space

parent 85b08109
No related branches found
No related tags found
No related merge requests found
...@@ -295,6 +295,143 @@ vector<int> FunctionSpace::getFaceClosure(const MElement& element){ ...@@ -295,6 +295,143 @@ vector<int> FunctionSpace::getFaceClosure(const MElement& element){
return faceClosure; return faceClosure;
} }
const vector<const Polynomial*>
FunctionSpace::locBasis(const MElement& element,
const BasisScalar& basis){
// Get Basis //
const unsigned int nFNode = basis.getNVertexBased();
const unsigned int nFEdge = basis.getNEdgeBased();
const unsigned int nFFace = basis.getNFaceBased();
const unsigned int nFCell = basis.getNCellBased();
// Get Closure //
vector<int> edgeClosure = getEdgeClosure(element);
vector<int> faceClosure = getFaceClosure(element);
// Get Functions //
vector<const Polynomial*> fun(basis.getSize());
unsigned int i = 0;
// Vertex Based
for(unsigned int j = 0; j < nFNode; j++){
fun[i] = &basis.getNodeFunction(j);
i++;
}
// Edge Based
// Number of basis function *per* edge
// --> should always be an integer !
const unsigned int nEdge = edgeClosure.size();
const unsigned int nFPerEdge = nFEdge / nEdge;
unsigned int fEdge = 0;
for(unsigned int j = 0; j < nFPerEdge; j++){
for(unsigned int k = 0; k < nEdge; k++){
fun[i] =
&basis.getEdgeFunction(edgeClosure[k], fEdge);
fEdge++;
i++;
}
}
// Face Based
// Number of basis function *per* face
// --> should always be an integer !
const unsigned int nFace = faceClosure.size();
const unsigned int nFPerFace = nFFace / nFace;
unsigned int fFace = 0;
for(unsigned int j = 0; j < nFPerFace; j++){
for(unsigned int k = 0; k < nFace; k++){
fun[i] =
&basis.getFaceFunction(faceClosure[k], fFace);
fFace++;
i++;
}
}
// Cell Based
for(unsigned int j = 0; j < nFCell; j++){
fun[i] = &basis.getCellFunction(j);
i++;
}
// Return //
return fun;
}
const vector<const vector<Polynomial>*>
FunctionSpace::locBasis(const MElement& element,
const BasisVector& basis){
// Get Basis //
const unsigned int nFNode = basis.getNVertexBased();
const unsigned int nFEdge = basis.getNEdgeBased();
const unsigned int nFFace = basis.getNFaceBased();
const unsigned int nFCell = basis.getNCellBased();
// Get Closure //
vector<int> edgeClosure = getEdgeClosure(element);
vector<int> faceClosure = getFaceClosure(element);
// Get Functions //
vector<const vector<Polynomial>*> fun(basis.getSize());
unsigned int i = 0;
// Vertex Based
for(unsigned int j = 0; j < nFNode; j++){
fun[i] = &basis.getNodeFunction(j);
i++;
}
// Edge Based
// Number of basis function *per* edge
// --> should always be an integer !
const unsigned int nEdge = edgeClosure.size();
const unsigned int nFPerEdge = nFEdge / nEdge;
unsigned int fEdge = 0;
for(unsigned int j = 0; j < nFPerEdge; j++){
for(unsigned int k = 0; k < nEdge; k++){
fun[i] =
&basis.getEdgeFunction(edgeClosure[k], fEdge);
fEdge++;
i++;
}
}
// Face Based
// Number of basis function *per* face
// --> should always be an integer !
const unsigned int nFace = faceClosure.size();
const unsigned int nFPerFace = nFFace / nFace;
unsigned int fFace = 0;
for(unsigned int j = 0; j < nFPerFace; j++){
for(unsigned int k = 0; k < nFace; k++){
fun[i] =
&basis.getFaceFunction(faceClosure[k], fFace);
fFace++;
i++;
}
}
// Cell Based
for(unsigned int j = 0; j < nFCell; j++){
fun[i] = &basis.getCellFunction(j);
i++;
}
// Return //
return fun;
}
string FunctionSpace::toString(void) const{ string FunctionSpace::toString(void) const{
return basis->toString(); return basis->toString();
} }
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#include <string> #include <string>
#include "Basis.h" #include "Basis.h"
#include "BasisScalar.h"
#include "BasisVector.h"
#include "Comparators.h" #include "Comparators.h"
#include "Dof.h" #include "Dof.h"
#include "GroupOfDof.h" #include "GroupOfDof.h"
...@@ -99,6 +102,16 @@ class FunctionSpace{ ...@@ -99,6 +102,16 @@ class FunctionSpace{
// Closure // Closure
static std::vector<int> getEdgeClosure(const MElement& element); static std::vector<int> getEdgeClosure(const MElement& element);
static std::vector<int> getFaceClosure(const MElement& element); static std::vector<int> getFaceClosure(const MElement& element);
// Local Basis
static
const std::vector<const Polynomial*>
locBasis(const MElement& element,
const BasisScalar& basis);
static
const std::vector<const std::vector<Polynomial>*>
locBasis(const MElement& element,
const BasisVector& basis);
}; };
......
...@@ -10,6 +10,10 @@ FunctionSpaceEdge::FunctionSpaceEdge(const GroupOfElement& goe, ...@@ -10,6 +10,10 @@ FunctionSpaceEdge::FunctionSpaceEdge(const GroupOfElement& goe,
int order){ int order){
// Build 1Form Basis // // Build 1Form Basis //
build(goe, 1, order); build(goe, 1, order);
// Init BasisVector //
basisVector =
static_cast<const BasisVector*>(basis);
} }
FunctionSpaceEdge::~FunctionSpaceEdge(void){ FunctionSpaceEdge::~FunctionSpaceEdge(void){
......
#include "FunctionSpaceScalar.h" #include "FunctionSpaceScalar.h"
#include "Exception.h"
using namespace std; using namespace std;
...@@ -12,147 +11,3 @@ FunctionSpaceScalar::~FunctionSpaceScalar(void){ ...@@ -12,147 +11,3 @@ FunctionSpaceScalar::~FunctionSpaceScalar(void){
if(hasGrad) if(hasGrad)
delete gradBasis; delete gradBasis;
} }
const vector<const Polynomial*> FunctionSpaceScalar::
getLocalFunctions(const MElement& element) const{
// Get Basis //
const unsigned int nFNode = basisScalar->getNVertexBased();
const unsigned int nFEdge = basisScalar->getNEdgeBased();
const unsigned int nFFace = basisScalar->getNFaceBased();
const unsigned int nFCell = basisScalar->getNCellBased();
// Get Closure //
vector<int> edgeClosure = getEdgeClosure(element);
vector<int> faceClosure = getFaceClosure(element);
// Get Functions //
vector<const Polynomial*> fun(basisScalar->getSize());
unsigned int i = 0;
// Vertex Based
for(unsigned int j = 0; j < nFNode; j++){
fun[i] = &basisScalar->getNodeFunction(j);
i++;
}
// Edge Based
// Number of basis function *per* edge
// --> should always be an integer !
const unsigned int nEdge = edgeClosure.size();
const unsigned int nFPerEdge = nFEdge / nEdge;
unsigned int fEdge = 0;
for(unsigned int j = 0; j < nFPerEdge; j++){
for(unsigned int k = 0; k < nEdge; k++){
fun[i] =
&basisScalar->getEdgeFunction(edgeClosure[k], fEdge);
fEdge++;
i++;
}
}
// Face Based
// Number of basis function *per* face
// --> should always be an integer !
const unsigned int nFace = faceClosure.size();
const unsigned int nFPerFace = nFFace / nFace;
unsigned int fFace = 0;
for(unsigned int j = 0; j < nFPerFace; j++){
for(unsigned int k = 0; k < nFace; k++){
fun[i] =
&basisScalar->getFaceFunction(faceClosure[k], fFace);
fFace++;
i++;
}
}
// Cell Based
for(unsigned int j = 0; j < nFCell; j++){
fun[i] = &basisScalar->getCellFunction(j);
i++;
}
// Return //
return fun;
}
const vector<const vector<Polynomial>*> FunctionSpaceScalar::
getGradLocalFunctions(const MElement& element) const{
// Got Grad Basis ? //
// --> mutable data
// --> Just a 'cache memory'
if(!hasGrad){
gradBasis = new GradBasis(*basisScalar);
hasGrad = true;
}
// Get Basis //
const unsigned int nFNode = gradBasis->getNVertexBased();
const unsigned int nFEdge = gradBasis->getNEdgeBased();
const unsigned int nFFace = gradBasis->getNFaceBased();
const unsigned int nFCell = gradBasis->getNCellBased();
// Get Closure //
vector<int> edgeClosure = getEdgeClosure(element);
vector<int> faceClosure = getFaceClosure(element);
// Get Functions //
vector<const vector<Polynomial>*> fun(gradBasis->getSize());
unsigned int i = 0;
// Vertex Based
for(unsigned int j = 0; j < nFNode; j++){
fun[i] = &gradBasis->getNodeFunction(j);
i++;
}
// Edge Based
// Number of basis function *per* edge
// --> should always be an integer !
const unsigned int nEdge = edgeClosure.size();
const unsigned int nFPerEdge = nFEdge / nEdge;
unsigned int fEdge = 0;
for(unsigned int j = 0; j < nFPerEdge; j++){
for(unsigned int k = 0; k < nEdge; k++){
fun[i] =
&gradBasis->getEdgeFunction(edgeClosure[k], fEdge);
fEdge++;
i++;
}
}
// Face Based
// Number of basis function *per* face
// --> should always be an integer !
const unsigned int nFace = faceClosure.size();
const unsigned int nFPerFace = nFFace / nFace;
unsigned int fFace = 0;
for(unsigned int j = 0; j < nFPerFace; j++){
for(unsigned int k = 0; k < nFace; k++){
fun[i] =
&gradBasis->getFaceFunction(faceClosure[k], fFace);
fFace++;
i++;
}
}
// Cell Based
for(unsigned int j = 0; j < nFCell; j++){
fun[i] = &gradBasis->getCellFunction(j);
i++;
}
// Return //
return fun;
}
...@@ -41,8 +41,6 @@ class FunctionSpaceScalar : public FunctionSpace{ ...@@ -41,8 +41,6 @@ class FunctionSpaceScalar : public FunctionSpace{
const std::vector<const std::vector<Polynomial>*> const std::vector<const std::vector<Polynomial>*>
getGradLocalFunctions(const MElement& element) const; getGradLocalFunctions(const MElement& element) const;
const BasisScalar& getBasis(const MElement& element) const;
protected: protected:
FunctionSpaceScalar(void); FunctionSpaceScalar(void);
...@@ -77,23 +75,29 @@ class FunctionSpaceScalar : public FunctionSpace{ ...@@ -77,23 +75,29 @@ class FunctionSpaceScalar : public FunctionSpace{
@param element A MElement @param element A MElement
@return Returns the basis functions associated @return Returns the basis functions associated
to the given element (with correct @em closure) to the given element (with correct @em closure)
**
@fn FunctionSpaceScalar::getBasis
@param element A MElement of the support
of this FunctionSpace
@return Returns the Basis (BasisScalar) associated
to the given MElement
*/ */
////////////////////// //////////////////////
// Inline Functions // // Inline Functions //
////////////////////// //////////////////////
/*
inline const BasisScalar& FunctionSpaceScalar:: inline const std::vector<const Polynomial*>
getBasis(const MElement& element) const{ FunctionSpaceScalar::getLocalFunctions(const MElement& element) const{
return *basisScalar; return locBasis(element, *basisScalar);
} }
*/
inline const std::vector<const std::vector<Polynomial>*>
FunctionSpaceScalar::getGradLocalFunctions(const MElement& element) const{
// Got Grad Basis ? //
// --> mutable data
// --> Just a 'cache memory'
if(!hasGrad){
gradBasis = new GradBasis(*basisScalar);
hasGrad = true;
}
return locBasis(element, *gradBasis);
}
#endif #endif
#include "FunctionSpaceVector.h" #include "FunctionSpaceVector.h"
#include "Exception.h"
using namespace std; using namespace std;
FunctionSpaceVector::~FunctionSpaceVector(void){ FunctionSpaceVector::FunctionSpaceVector(void){
} hasCurl = false;
curlBasis = NULL;
const vector<const vector<Polynomial>*> FunctionSpaceVector::
getLocalFunctions(const MElement& element) const{
// Get Basis //
const BasisVector& basis = getBasis(element);
const unsigned int nFNode = basis.getNVertexBased();
const unsigned int nFEdge = basis.getNEdgeBased();
const unsigned int nFFace = basis.getNFaceBased();
const unsigned int nFCell = basis.getNCellBased();
// Get Closure //
vector<int> edgeClosure = getEdgeClosure(element);
vector<int> faceClosure = getFaceClosure(element);
// Get Functions //
vector<const vector<Polynomial>*> fun(basis.getSize());
unsigned int i = 0;
// Vertex Based
for(unsigned int j = 0; j < nFNode; j++){
fun[i] = &basis.getNodeFunction(j);
i++;
}
// Edge Based hasDiv = false;
// Number of basis function *per* edge divBasis = NULL;
// --> should always be an integer ! }
const unsigned int nEdge = edgeClosure.size();
const unsigned int nFPerEdge = nFEdge / nEdge;
unsigned int fEdge = 0;
for(unsigned int j = 0; j < nFPerEdge; j++){
for(unsigned int k = 0; k < nEdge; k++){
fun[i] =
&basis.getEdgeFunction(edgeClosure[k], fEdge);
fEdge++;
i++;
}
}
// Face Based
// Number of basis function *per* face
// --> should always be an integer !
const unsigned int nFace = faceClosure.size();
const unsigned int nFPerFace = nFFace / nFace;
unsigned int fFace = 0;
for(unsigned int j = 0; j < nFPerFace; j++){
for(unsigned int k = 0; k < nFace; k++){
fun[i] =
&basis.getFaceFunction(faceClosure[k], fFace);
fFace++;
i++;
}
}
// Cell Based
for(unsigned int j = 0; j < nFCell; j++){
fun[i] = &basis.getCellFunction(j);
i++;
}
FunctionSpaceVector::~FunctionSpaceVector(void){
if(hasCurl)
delete curlBasis;
// Return // if(hasDiv)
return fun; delete divBasis;
} }
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include "fullMatrix.h" #include "fullMatrix.h"
#include "BasisVector.h" #include "BasisVector.h"
#include "CurlBasis.h"
#include "DivBasis.h"
#include "FunctionSpace.h" #include "FunctionSpace.h"
/** /**
...@@ -21,6 +23,15 @@ ...@@ -21,6 +23,15 @@
class FunctionSpaceVector : public FunctionSpace{ class FunctionSpaceVector : public FunctionSpace{
protected:
const BasisVector* basisVector;
mutable bool hasCurl;
mutable CurlBasis* curlBasis;
mutable bool hasDiv;
mutable DivBasis* divBasis;
public: public:
virtual ~FunctionSpaceVector(void); virtual ~FunctionSpaceVector(void);
...@@ -32,7 +43,14 @@ class FunctionSpaceVector : public FunctionSpace{ ...@@ -32,7 +43,14 @@ class FunctionSpaceVector : public FunctionSpace{
const std::vector<const std::vector<Polynomial>*> const std::vector<const std::vector<Polynomial>*>
getLocalFunctions(const MElement& element) const; getLocalFunctions(const MElement& element) const;
const BasisVector& getBasis(const MElement& element) const; const std::vector<const std::vector<Polynomial>*>
getCurlLocalFunctions(const MElement& element) const;
const std::vector<const Polynomial*>
getDivLocalFunctions(const MElement& element) const;
protected:
FunctionSpaceVector(void);
}; };
...@@ -64,23 +82,43 @@ class FunctionSpaceVector : public FunctionSpace{ ...@@ -64,23 +82,43 @@ class FunctionSpaceVector : public FunctionSpace{
@param element A MElement @param element A MElement
@return Returns the basis functions associated @return Returns the basis functions associated
to the given element (with correct @em closure) to the given element (with correct @em closure)
** */
@fn FunctionSpaceVector::getBasis
@param element A MElement of the support
of this FunctionSpace
@return Returns the Basis (BasisVector) associated
to the given MElement
*/
////////////////////// //////////////////////
// Inline Functions // // Inline Functions //
////////////////////// //////////////////////
inline const BasisVector& FunctionSpaceVector:: inline const std::vector<const std::vector<Polynomial>*>
getBasis(const MElement& element) const{ FunctionSpaceVector::getLocalFunctions(const MElement& element) const{
return static_cast<const BasisVector&>(*basis); return locBasis(element, *basisVector);
}
inline const std::vector<const std::vector<Polynomial>*>
FunctionSpaceVector::getCurlLocalFunctions(const MElement& element) const{
// Got Curl Basis ? //
// --> mutable data
// --> Just a 'cache memory'
if(!hasCurl){
curlBasis = new CurlBasis(*basisVector);
hasCurl = true;
}
return locBasis(element, *curlBasis);
}
inline const std::vector<const Polynomial*>
FunctionSpaceVector::getDivLocalFunctions(const MElement& element) const{
// Got Div Basis ? //
// --> mutable data
// --> Just a 'cache memory'
if(!hasDiv){
divBasis = new DivBasis(*basisVector);
hasDiv = true;
}
return locBasis(element, *divBasis);
} }
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment