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

FunctionSpace -- first test

parent 0fe54277
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,6 @@ class Basis{ ...@@ -17,8 +17,6 @@ class Basis{
int order; int order;
int type; int type;
int size;
int nodeNbr;
int dim; int dim;
int nVertex; int nVertex;
...@@ -26,6 +24,8 @@ class Basis{ ...@@ -26,6 +24,8 @@ class Basis{
int nFace; int nFace;
int nCell; int nCell;
int size;
public: public:
//! Deletes this Basis //! Deletes this Basis
//! //!
...@@ -55,33 +55,29 @@ class Basis{ ...@@ -55,33 +55,29 @@ class Basis{
//! @todo Check if the 'form numbering' is good //! @todo Check if the 'form numbering' is good
int getType(void) const; int getType(void) const;
//! @return Returns the number of Polynomial%s
//! (or Vector%s of Polynomial%s) in the Basis
int getSize(void) const;
//! @return Returns the node number of
//! the @em geometric @em reference @em element
int getNodeNbr(void) const;
//! @return Returns the @em dimension //! @return Returns the @em dimension
//! (1D, 2D or 3D) of the Basis //! (2D or 3D) of the Basis
int getDim(void) const; int getDim(void) const;
//! @return Returns the number of @em Vertex //! @return Returns the number of @em Vertex
//! @em Based functions of this Basis //! @em Based functions of this Basis
int getNVertex(void) const; int getNVertexBased(void) const;
//! @return Returns the number of @em Edge //! @return Returns the number of @em Edge
//! @em Based functions of this Basis //! @em Based functions of this Basis
int getNEdge(void) const; int getNEdgeBased(void) const;
//! @return Returns the number of @em Face //! @return Returns the number of @em Face
//! @em Based functions of this Basis //! @em Based functions of this Basis
int getNFace(void) const; int getNFaceBased(void) const;
//! @return Returns the number of @em Cell //! @return Returns the number of @em Cell
//! @em Based functions of this Basis //! @em Based functions of this Basis
int getNCell(void) const; int getNCellBased(void) const;
//! @return Returns the number of Polynomial%s
//! (or Vector%s of Polynomial%s) in the Basis
int getSize(void) const;
protected: protected:
//! Instantiate a new Basis //! Instantiate a new Basis
...@@ -105,32 +101,28 @@ inline int Basis::getType(void) const{ ...@@ -105,32 +101,28 @@ inline int Basis::getType(void) const{
return type; return type;
} }
inline int Basis::getSize(void) const{
return size;
}
inline int Basis::getNodeNbr(void) const{
return nodeNbr;
}
inline int Basis::getDim(void) const{ inline int Basis::getDim(void) const{
return dim; return dim;
} }
inline int Basis::getNVertex(void) const{ inline int Basis::getNVertexBased(void) const{
return nVertex; return nVertex;
} }
inline int Basis::getNEdge(void) const{ inline int Basis::getNEdgeBased(void) const{
return nEdge; return nEdge;
} }
inline int Basis::getNFace(void) const{ inline int Basis::getNFaceBased(void) const{
return nFace; return nFace;
} }
inline int Basis::getNCell(void) const{ inline int Basis::getNCellBased(void) const{
return nCell; return nCell;
} }
inline int Basis::getSize(void) const{
return size;
}
#endif #endif
#include "BasisGenerator.h"
#include "GmshDefines.h"
#include "Exception.h"
#include "QuadNodeBasis.h"
#include "QuadEdgeBasis.h"
#include "TriNodeBasis.h"
#include "TriEdgeBasis.h"
#include "TriNedelecBasis.h"
#include "HexNodeBasis.h"
#include "HexEdgeBasis.h"
BasisGenerator::BasisGenerator(void){
}
BasisGenerator::~BasisGenerator(void){
}
Basis* BasisGenerator::generate(int elementType,
int basisType,
int order){
switch(elementType){
case TYPE_TRI: return TriGen(basisType, order);
case TYPE_QUA: return QuaGen(basisType, order);
case TYPE_HEX: return HexGen(basisType, order);
default: throw Exception("Unknown Element Type (%d) for Basis Generation",
elementType);
}
}
Basis* BasisGenerator::TriGen(int basisType,
int order){
switch(basisType){
case 0:
if (order == 0) return new TriNedelecBasis();
else return new TriNodeBasis(order);
case 1: return new TriEdgeBasis(order);
case 2: throw Exception("2-form not implemented on Triangles");
case 3: throw Exception("3-form not implemented on Triangles");
default: throw Exception("There is no %d-form", basisType);
}
}
Basis* BasisGenerator::QuaGen(int basisType,
int order){
switch(basisType){
case 0: return new QuadNodeBasis(order);
case 1: return new QuadEdgeBasis(order);
case 2: throw Exception("2-form not implemented on Quads");
case 3: throw Exception("3-form not implemented on Quads");
default: throw Exception("There is no %d-form", basisType);
}
}
Basis* BasisGenerator::HexGen(int basisType,
int order){
switch(basisType){
case 0: return new HexNodeBasis(order);
case 1: return new HexEdgeBasis(order);
case 2: throw Exception("2-form not implemented on Hexs");
case 3: throw Exception("3-form not implemented on Hexs");
default: throw Exception("There is no %d-form", basisType);
}
}
#ifndef _BASISGENERATOR_H_
#define _BASISGENERATOR_H_
#include "Basis.h"
/**
@class BasisGenerator
@brief A bunch of static method to generate basis
A bunch of static method to generate basis
*/
class BasisGenerator{
public:
BasisGenerator(void);
~BasisGenerator(void);
static Basis* generate(int elementType,
int basisType,
int order);
static Basis* TriGen(int basisType, int order);
static Basis* QuaGen(int basisType, int order);
static Basis* HexGen(int basisType, int order);
};
#endif
...@@ -10,6 +10,9 @@ set(SRC ...@@ -10,6 +10,9 @@ set(SRC
Basis.cpp Basis.cpp
BasisScalar.cpp BasisScalar.cpp
BasisVector.cpp BasisVector.cpp
BasisTest.cpp
BasisGenerator.cpp
QuadNodeBasis.cpp QuadNodeBasis.cpp
QuadEdgeBasis.cpp QuadEdgeBasis.cpp
TriNodeBasis.cpp TriNodeBasis.cpp
...@@ -19,8 +22,6 @@ set(SRC ...@@ -19,8 +22,6 @@ set(SRC
HexEdgeBasis.cpp HexEdgeBasis.cpp
FunctionSpace.cpp FunctionSpace.cpp
BasisTest.cpp
) )
file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h)
......
#include "FunctionSpace.h" #include "FunctionSpace.h"
#include "BasisGenerator.h"
using namespace std; using namespace std;
FunctionSpace::FunctionSpace(void){ FunctionSpace::FunctionSpace(const GroupOfElement& goe, int basisType, int order){
ebLookUp = new map<MElement*, Basis*, ElementComparator>; // Save GroupOfElement //
this->goe = &goe;
// Look for 1st element to get element type //
// (We suppose only one type of Mesh !!) //
int elementType = goe.get(0).getType();
// Create Basis //
basis = BasisGenerator::generate(elementType, basisType, order);
// Count Function per Entity //
int nVertex = goe.get(0).getNumVertices();
int nEdge = goe.get(0).getNumEdges();
int nFace = goe.get(0).getNumFaces();
fPerVertex = basis->getNVertexBased() / nVertex;
// NB: fPreVertex = 0 *or* 1
if(nEdge)
fPerEdge = basis->getNEdgeBased() / nEdge;
else
fPerEdge = 0;
if(nFace)
fPerFace = basis->getNFaceBased() / nFace;
else
fPerFace = 0;
fPerCell = basis->getNCellBased(); // We always got 1 cell
} }
FunctionSpace::~FunctionSpace(void){ FunctionSpace::~FunctionSpace(void){
delete ebLookUp; delete basis;
} }
#ifndef _FUNCTIONSPACE_H_ #ifndef _FUNCTIONSPACE_H_
#define _FUNCTIONSPACE_H_ #define _FUNCTIONSPACE_H_
#include <map>
#include "MElement.h"
#include "Mapper.h"
#include "Basis.h" #include "Basis.h"
#include "GroupOfElement.h"
#include "MElement.h"
/** /**
@class FunctionSpace @class FunctionSpace
@brief A Function Space @brief A Function Space
This class represents a Function Space This class represents a Function Space
@todo Add interpolation @n @todo Hybrid Mesh
--> inheritance: FunctionSpaceScalar & FunctionSapceVector @n
"double or fullVector" interpolate(Element, pyhsical coordinate, coef) @n
"double or fullVector" interpolate(Element, ref coordinate , coef) @n
"double or fullVector" interpolate(physical coordinate, coef) --> use octree?? @n
*/ */
class FunctionSpace{ class FunctionSpace{
private: private:
const Basis* basis;
class ElementComparator{ const GroupOfElement* goe;
public:
bool operator()(const MElement* a, const MElement* b) const; int fPerVertex;
}; int fPerEdge;
int fPerFace;
std::map<MElement*, Basis*, ElementComparator>* ebLookUp; // Element to Basis Lookup int fPerCell;
public: public:
FunctionSpace(void); FunctionSpace(const GroupOfElement& goe,
int basisType, int order);
~FunctionSpace(void); ~FunctionSpace(void);
void associate(MElement& element, Basis& basis); const GroupOfElement& getSupport(void) const;
void associate(int physical, Basis& basis); const Basis& getBasis(MElement& element) const;
Basis& getBasis(MElement& element) const; int getNFunctionPerVertex(MElement& element) const;
int getNFunctionPerEdge(MElement& element) const;
int getNFunctionPerFace(MElement& element) const;
int getNFunctionPerCell(MElement& element) const;
}; };
////////////////////// //////////////////////
// Inline Functions // // Inline Functions //
////////////////////// //////////////////////
inline void FunctionSpace::associate(MElement& element, Basis& basis){ inline const GroupOfElement& FunctionSpace::getSupport(void) const{
ebLookUp->insert(std::pair<MElement*, Basis*>(&element, &basis)); return *goe;
}
inline const Basis& FunctionSpace::getBasis(MElement& element) const{
return *basis;
}
inline int FunctionSpace::getNFunctionPerVertex(MElement& element) const{
return fPerVertex;
}
inline int FunctionSpace::getNFunctionPerEdge(MElement& element) const{
return fPerEdge;
} }
inline Basis& FunctionSpace::getBasis(MElement& element) const{ inline int FunctionSpace::getNFunctionPerFace(MElement& element) const{
return *(ebLookUp->find(&element)->second); return fPerFace;
} }
inline bool FunctionSpace::ElementComparator::operator() inline int FunctionSpace::getNFunctionPerCell(MElement& element) const{
(const MElement* a, const MElement* b) const{ return fPerCell;
return a->getNum() < b->getNum();
} }
#endif #endif
...@@ -8,16 +8,16 @@ HexEdgeBasis::HexEdgeBasis(const int order){ ...@@ -8,16 +8,16 @@ HexEdgeBasis::HexEdgeBasis(const int order){
// Set Basis Type // // Set Basis Type //
this->order = order; this->order = order;
type = 1; type = 1;
size = 3 * (order + 2) * (order + 2) * (order + 1); dim = 3;
nodeNbr = 8;
dim = 3;
nVertex = 0 ; nVertex = 0 ;
nEdge = 12 * (order + 1); nEdge = 12 * (order + 1);
nFace = 12 * order * (order + 1); nFace = 12 * order * (order + 1);
nCell = 3 * order * order * (order + 1); nCell = 3 * order * order * (order + 1);
size = 3 * (order + 2) * (order + 2) * (order + 1);
// Alloc Temporary Space // // Alloc Temporary Space //
const int orderPlus = order + 1; const int orderPlus = order + 1;
Polynomial* legendre = new Polynomial[orderPlus]; Polynomial* legendre = new Polynomial[orderPlus];
......
...@@ -5,16 +5,16 @@ HexNodeBasis::HexNodeBasis(const int order){ ...@@ -5,16 +5,16 @@ HexNodeBasis::HexNodeBasis(const int order){
// Set Basis Type // // Set Basis Type //
this->order = order; this->order = order;
type = 0; type = 0;
size = (order + 1) * (order + 1) * (order + 1); dim = 3;
nodeNbr = 8;
dim = 3;
nVertex = 8; nVertex = 8;
nEdge = 12 * (order - 1); nEdge = 12 * (order - 1);
nFace = 6 * (order - 1) * (order - 1); nFace = 6 * (order - 1) * (order - 1);
nCell = (order - 1) * (order - 1) * (order - 1); nCell = (order - 1) * (order - 1) * (order - 1);
size = (order + 1) * (order + 1) * (order + 1);
// Alloc Temporary Space // // Alloc Temporary Space //
Polynomial* legendre = new Polynomial[order]; Polynomial* legendre = new Polynomial[order];
Polynomial* lifting = new Polynomial[8]; Polynomial* lifting = new Polynomial[8];
......
...@@ -5,16 +5,16 @@ QuadEdgeBasis::QuadEdgeBasis(const int order){ ...@@ -5,16 +5,16 @@ QuadEdgeBasis::QuadEdgeBasis(const int order){
// Set Basis Type // // Set Basis Type //
this->order = order; this->order = order;
type = 1; type = 1;
size = 2 * (order + 2) * (order + 1); dim = 2;
nodeNbr = 4;
dim = 2;
nVertex = 0 ; nVertex = 0 ;
nEdge = 4 * (order + 1) ; nEdge = 4 * (order + 1) ;
nFace = 0 ; nFace = 0 ;
nCell = 2 * (order + 1) * order; nCell = 2 * (order + 1) * order;
size = 2 * (order + 2) * (order + 1);
// Alloc Temporary Space // // Alloc Temporary Space //
const int orderPlus = order + 1; const int orderPlus = order + 1;
Polynomial* legendre = new Polynomial[orderPlus]; Polynomial* legendre = new Polynomial[orderPlus];
......
...@@ -5,16 +5,16 @@ QuadNodeBasis::QuadNodeBasis(const int order){ ...@@ -5,16 +5,16 @@ QuadNodeBasis::QuadNodeBasis(const int order){
// Set Basis Type // // Set Basis Type //
this->order = order; this->order = order;
type = 0; type = 0;
size = (order + 1) * (order + 1); dim = 2;
nodeNbr = 4;
dim = 2;
nVertex = 4 ; nVertex = 4 ;
nEdge = 4 * (order - 1) ; nEdge = 4 * (order - 1) ;
nFace = 0 ; nFace = 0 ;
nCell = (order - 1) * (order - 1); nCell = (order - 1) * (order - 1);
size = (order + 1) * (order + 1);
// Alloc Temporary Space // // Alloc Temporary Space //
Polynomial* legendre = new Polynomial[order]; Polynomial* legendre = new Polynomial[order];
Polynomial* lifting = new Polynomial[4]; Polynomial* lifting = new Polynomial[4];
......
...@@ -5,16 +5,16 @@ TriEdgeBasis::TriEdgeBasis(const int order){ ...@@ -5,16 +5,16 @@ TriEdgeBasis::TriEdgeBasis(const int order){
// Set Basis Type // // Set Basis Type //
this->order = order; this->order = order;
type = 1; type = 1;
size = (order + 1) * (order + 2); dim = 2;
nodeNbr = 3;
dim = 2;
nVertex = 0; nVertex = 0;
nEdge = 3 * (order + 1); nEdge = 3 * (order + 1);
nFace = 0; nFace = 0;
nCell = ((order - 1) * order + order - 1); nCell = ((order - 1) * order + order - 1);
size = (order + 1) * (order + 2);
// Alloc Temporary Space // // Alloc Temporary Space //
const int orderPlus = order + 1; const int orderPlus = order + 1;
const int orderMinus = order - 1; const int orderMinus = order - 1;
......
...@@ -2,17 +2,18 @@ ...@@ -2,17 +2,18 @@
TriNedelecBasis::TriNedelecBasis(void){ TriNedelecBasis::TriNedelecBasis(void){
// Set Basis Type // // Set Basis Type //
order = 1; order = 1;
type = 1;
size = 3; type = 1;
nodeNbr = 3; dim = 2;
dim = 2;
nVertex = 0; nVertex = 0;
nEdge = 3; nEdge = 3;
nFace = 0; nFace = 0;
nCell = 0; nCell = 0;
size = 3;
// Lagrange // // Lagrange //
Polynomial* lagrange = new Polynomial[3]; Polynomial* lagrange = new Polynomial[3];
......
...@@ -5,16 +5,16 @@ TriNodeBasis::TriNodeBasis(const int order){ ...@@ -5,16 +5,16 @@ TriNodeBasis::TriNodeBasis(const int order){
// Set Basis Type // // Set Basis Type //
this->order = order; this->order = order;
type = 0; type = 0;
size = (order + 1) * (order + 2) / 2; dim = 2;
nodeNbr = 3;
dim = 2;
nVertex = 3; nVertex = 3;
nEdge = 3 * (order - 1); nEdge = 3 * (order - 1);
nFace = 0; nFace = 0;
nCell = (order - 1) * (order - 2) / 2; nCell = (order - 1) * (order - 2) / 2;
size = (order + 1) * (order + 2) / 2;
// Alloc Temporary Space // // Alloc Temporary Space //
Polynomial* legendre = new Polynomial[order]; Polynomial* legendre = new Polynomial[order];
Polynomial* intLegendre = new Polynomial[order]; Polynomial* intLegendre = new Polynomial[order];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment