diff --git a/FunctionSpace/Basis.h b/FunctionSpace/Basis.h index 6b45a5bfa524c8f9439331b3735836b17ec15e26..71742ae3d8cb872bba1eeec0c9caabfae6b18102 100644 --- a/FunctionSpace/Basis.h +++ b/FunctionSpace/Basis.h @@ -17,8 +17,6 @@ class Basis{ int order; int type; - int size; - int nodeNbr; int dim; int nVertex; @@ -26,6 +24,8 @@ class Basis{ int nFace; int nCell; + int size; + public: //! Deletes this Basis //! @@ -55,33 +55,29 @@ class Basis{ //! @todo Check if the 'form numbering' is good 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 - //! (1D, 2D or 3D) of the Basis + //! (2D or 3D) of the Basis int getDim(void) const; //! @return Returns the number of @em Vertex //! @em Based functions of this Basis - int getNVertex(void) const; + int getNVertexBased(void) const; //! @return Returns the number of @em Edge //! @em Based functions of this Basis - int getNEdge(void) const; + int getNEdgeBased(void) const; //! @return Returns the number of @em Face //! @em Based functions of this Basis - int getNFace(void) const; + int getNFaceBased(void) const; //! @return Returns the number of @em Cell //! @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: //! Instantiate a new Basis @@ -105,32 +101,28 @@ inline int Basis::getType(void) const{ return type; } -inline int Basis::getSize(void) const{ - return size; -} - -inline int Basis::getNodeNbr(void) const{ - return nodeNbr; -} - inline int Basis::getDim(void) const{ return dim; } -inline int Basis::getNVertex(void) const{ +inline int Basis::getNVertexBased(void) const{ return nVertex; } -inline int Basis::getNEdge(void) const{ +inline int Basis::getNEdgeBased(void) const{ return nEdge; } -inline int Basis::getNFace(void) const{ +inline int Basis::getNFaceBased(void) const{ return nFace; } -inline int Basis::getNCell(void) const{ +inline int Basis::getNCellBased(void) const{ return nCell; } +inline int Basis::getSize(void) const{ + return size; +} + #endif diff --git a/FunctionSpace/BasisGenerator.cpp b/FunctionSpace/BasisGenerator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b93b9cb4cc80ac0398efd176e81735503c36b27 --- /dev/null +++ b/FunctionSpace/BasisGenerator.cpp @@ -0,0 +1,72 @@ +#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); + } +} diff --git a/FunctionSpace/BasisGenerator.h b/FunctionSpace/BasisGenerator.h new file mode 100644 index 0000000000000000000000000000000000000000..b524b25ce9bbac88bd62630387c21649c133d1ea --- /dev/null +++ b/FunctionSpace/BasisGenerator.h @@ -0,0 +1,27 @@ +#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 diff --git a/FunctionSpace/CMakeLists.txt b/FunctionSpace/CMakeLists.txt index 6630f7738bbcf2f6e3323069826171fe991f4bb3..a6b8edc4745fb69b3118df60581773f14fbcc71f 100644 --- a/FunctionSpace/CMakeLists.txt +++ b/FunctionSpace/CMakeLists.txt @@ -10,6 +10,9 @@ set(SRC Basis.cpp BasisScalar.cpp BasisVector.cpp + BasisTest.cpp + BasisGenerator.cpp + QuadNodeBasis.cpp QuadEdgeBasis.cpp TriNodeBasis.cpp @@ -19,8 +22,6 @@ set(SRC HexEdgeBasis.cpp FunctionSpace.cpp - - BasisTest.cpp ) file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) diff --git a/FunctionSpace/FunctionSpace.cpp b/FunctionSpace/FunctionSpace.cpp index ec6f1e1a1c1a1be901aed3db4a8a52419eed26da..b3e0d44b8c84e8cdd9ebae48c4a612f8860ff4b1 100644 --- a/FunctionSpace/FunctionSpace.cpp +++ b/FunctionSpace/FunctionSpace.cpp @@ -1,12 +1,41 @@ #include "FunctionSpace.h" +#include "BasisGenerator.h" using namespace std; -FunctionSpace::FunctionSpace(void){ - ebLookUp = new map<MElement*, Basis*, ElementComparator>; +FunctionSpace::FunctionSpace(const GroupOfElement& goe, int basisType, int order){ + // 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){ - delete ebLookUp; + delete basis; } diff --git a/FunctionSpace/FunctionSpace.h b/FunctionSpace/FunctionSpace.h index bd6858cf368c6f1a248698b3d6c91c5f5b26b4af..50ba5165e84eadd93f03ca87b646efc32424693e 100644 --- a/FunctionSpace/FunctionSpace.h +++ b/FunctionSpace/FunctionSpace.h @@ -1,59 +1,70 @@ #ifndef _FUNCTIONSPACE_H_ #define _FUNCTIONSPACE_H_ -#include <map> -#include "MElement.h" -#include "Mapper.h" #include "Basis.h" +#include "GroupOfElement.h" +#include "MElement.h" /** @class FunctionSpace @brief A Function Space - + This class represents a Function Space - @todo Add interpolation @n - --> 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 + @todo Hybrid Mesh */ class FunctionSpace{ private: - - class ElementComparator{ - public: - bool operator()(const MElement* a, const MElement* b) const; - }; - - std::map<MElement*, Basis*, ElementComparator>* ebLookUp; // Element to Basis Lookup + const Basis* basis; + const GroupOfElement* goe; + + int fPerVertex; + int fPerEdge; + int fPerFace; + int fPerCell; public: - FunctionSpace(void); + FunctionSpace(const GroupOfElement& goe, + int basisType, int order); + ~FunctionSpace(void); - void associate(MElement& element, Basis& basis); - void associate(int physical, Basis& basis); - - Basis& getBasis(MElement& element) const; + const GroupOfElement& getSupport(void) const; + 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 void FunctionSpace::associate(MElement& element, Basis& basis){ - ebLookUp->insert(std::pair<MElement*, Basis*>(&element, &basis)); +inline const GroupOfElement& FunctionSpace::getSupport(void) const{ + 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{ - return *(ebLookUp->find(&element)->second); +inline int FunctionSpace::getNFunctionPerFace(MElement& element) const{ + return fPerFace; } -inline bool FunctionSpace::ElementComparator::operator() -(const MElement* a, const MElement* b) const{ - return a->getNum() < b->getNum(); +inline int FunctionSpace::getNFunctionPerCell(MElement& element) const{ + return fPerCell; } #endif diff --git a/FunctionSpace/HexEdgeBasis.cpp b/FunctionSpace/HexEdgeBasis.cpp index 505655ebf5e2bb898faeaf83e1f2f9f3e3b342b0..c9a57d09c97b3b66cbee08a73aef7ef6622470ac 100644 --- a/FunctionSpace/HexEdgeBasis.cpp +++ b/FunctionSpace/HexEdgeBasis.cpp @@ -8,16 +8,16 @@ HexEdgeBasis::HexEdgeBasis(const int order){ // Set Basis Type // this->order = order; - type = 1; - size = 3 * (order + 2) * (order + 2) * (order + 1); - nodeNbr = 8; - dim = 3; + type = 1; + dim = 3; nVertex = 0 ; nEdge = 12 * (order + 1); nFace = 12 * order * (order + 1); nCell = 3 * order * order * (order + 1); + size = 3 * (order + 2) * (order + 2) * (order + 1); + // Alloc Temporary Space // const int orderPlus = order + 1; Polynomial* legendre = new Polynomial[orderPlus]; diff --git a/FunctionSpace/HexNodeBasis.cpp b/FunctionSpace/HexNodeBasis.cpp index c026845b3ec1ebf4f2db40e19d31e8fc13cfa6c2..89f3331cec1a6d883a9f1ecf839335256ee84bc7 100644 --- a/FunctionSpace/HexNodeBasis.cpp +++ b/FunctionSpace/HexNodeBasis.cpp @@ -5,16 +5,16 @@ HexNodeBasis::HexNodeBasis(const int order){ // Set Basis Type // this->order = order; - type = 0; - size = (order + 1) * (order + 1) * (order + 1); - nodeNbr = 8; - dim = 3; + type = 0; + dim = 3; nVertex = 8; nEdge = 12 * (order - 1); nFace = 6 * (order - 1) * (order - 1); nCell = (order - 1) * (order - 1) * (order - 1); + size = (order + 1) * (order + 1) * (order + 1); + // Alloc Temporary Space // Polynomial* legendre = new Polynomial[order]; Polynomial* lifting = new Polynomial[8]; diff --git a/FunctionSpace/QuadEdgeBasis.cpp b/FunctionSpace/QuadEdgeBasis.cpp index c2ac4bfb66227f4b35b0fca52ede769a7410bf97..91d530f5e1c952698240ffdb676aa71be3b0f1d5 100644 --- a/FunctionSpace/QuadEdgeBasis.cpp +++ b/FunctionSpace/QuadEdgeBasis.cpp @@ -5,16 +5,16 @@ QuadEdgeBasis::QuadEdgeBasis(const int order){ // Set Basis Type // this->order = order; - type = 1; - size = 2 * (order + 2) * (order + 1); - nodeNbr = 4; - dim = 2; + type = 1; + dim = 2; nVertex = 0 ; nEdge = 4 * (order + 1) ; nFace = 0 ; nCell = 2 * (order + 1) * order; + size = 2 * (order + 2) * (order + 1); + // Alloc Temporary Space // const int orderPlus = order + 1; Polynomial* legendre = new Polynomial[orderPlus]; diff --git a/FunctionSpace/QuadNodeBasis.cpp b/FunctionSpace/QuadNodeBasis.cpp index 6c86298c4ea4746caa09fc7f2ef2a25f36686bbd..281bc6624ff1bbab1309b939c8a1cd16dff6055a 100644 --- a/FunctionSpace/QuadNodeBasis.cpp +++ b/FunctionSpace/QuadNodeBasis.cpp @@ -5,16 +5,16 @@ QuadNodeBasis::QuadNodeBasis(const int order){ // Set Basis Type // this->order = order; - type = 0; - size = (order + 1) * (order + 1); - nodeNbr = 4; - dim = 2; + type = 0; + dim = 2; nVertex = 4 ; nEdge = 4 * (order - 1) ; nFace = 0 ; nCell = (order - 1) * (order - 1); + size = (order + 1) * (order + 1); + // Alloc Temporary Space // Polynomial* legendre = new Polynomial[order]; Polynomial* lifting = new Polynomial[4]; diff --git a/FunctionSpace/TriEdgeBasis.cpp b/FunctionSpace/TriEdgeBasis.cpp index 01d0287d2ff7075f556744a4f5e17c55df947907..aa1492858fc8f2ad9e53e414ba88f226d112886f 100644 --- a/FunctionSpace/TriEdgeBasis.cpp +++ b/FunctionSpace/TriEdgeBasis.cpp @@ -5,16 +5,16 @@ TriEdgeBasis::TriEdgeBasis(const int order){ // Set Basis Type // this->order = order; - type = 1; - size = (order + 1) * (order + 2); - nodeNbr = 3; - dim = 2; + type = 1; + dim = 2; nVertex = 0; nEdge = 3 * (order + 1); nFace = 0; nCell = ((order - 1) * order + order - 1); + size = (order + 1) * (order + 2); + // Alloc Temporary Space // const int orderPlus = order + 1; const int orderMinus = order - 1; diff --git a/FunctionSpace/TriNedelecBasis.cpp b/FunctionSpace/TriNedelecBasis.cpp index c419b060c5b8f8f7d0b9af0f8dc2f1791c35b77e..0e0beb05deba9a9403cfea5ce305cecd036ab11e 100644 --- a/FunctionSpace/TriNedelecBasis.cpp +++ b/FunctionSpace/TriNedelecBasis.cpp @@ -2,17 +2,18 @@ TriNedelecBasis::TriNedelecBasis(void){ // Set Basis Type // - order = 1; - type = 1; - size = 3; - nodeNbr = 3; - dim = 2; + order = 1; + + type = 1; + dim = 2; nVertex = 0; nEdge = 3; nFace = 0; nCell = 0; + size = 3; + // Lagrange // Polynomial* lagrange = new Polynomial[3]; diff --git a/FunctionSpace/TriNodeBasis.cpp b/FunctionSpace/TriNodeBasis.cpp index c0856f2b30f2529711a38746abaf34e6d41efbb6..d034614cbc98799a8046353c919bf8d67d890ec5 100644 --- a/FunctionSpace/TriNodeBasis.cpp +++ b/FunctionSpace/TriNodeBasis.cpp @@ -5,16 +5,16 @@ TriNodeBasis::TriNodeBasis(const int order){ // Set Basis Type // this->order = order; - type = 0; - size = (order + 1) * (order + 2) / 2; - nodeNbr = 3; - dim = 2; + type = 0; + dim = 2; nVertex = 3; nEdge = 3 * (order - 1); nFace = 0; nCell = (order - 1) * (order - 2) / 2; + size = (order + 1) * (order + 2) / 2; + // Alloc Temporary Space // Polynomial* legendre = new Polynomial[order]; Polynomial* intLegendre = new Polynomial[order];