diff --git a/FunctionSpace/CMakeLists.txt b/FunctionSpace/CMakeLists.txt index 7700ce8a55a8794c73f10757589eb0b64da527de..dfb3356e84ceccba25d156548b48f94b6c050c9d 100644 --- a/FunctionSpace/CMakeLists.txt +++ b/FunctionSpace/CMakeLists.txt @@ -41,8 +41,6 @@ set(SRC FunctionSpace.cpp FunctionSpaceScalar.cpp FunctionSpaceVector.cpp - FunctionSpaceNode.cpp - FunctionSpaceEdge.cpp ) file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) diff --git a/FunctionSpace/FunctionSpace.cpp b/FunctionSpace/FunctionSpace.cpp index 0391d6d0fa30317d23bb6f8a91a27872be807922..f19ded802a9f13e9967b6dfe48ed46dc27450933 100644 --- a/FunctionSpace/FunctionSpace.cpp +++ b/FunctionSpace/FunctionSpace.cpp @@ -13,10 +13,9 @@ FunctionSpace::FunctionSpace(void){ } FunctionSpace::~FunctionSpace(void){ - // Basis // - for(unsigned int i = 0; i < nBasis; i++) - delete (*basis)[i]; - + // Delete Vector of Basis // + // (FunctionSpace is not responsible for + // 'true' Basis Deletion) delete basis; // Dof // @@ -44,7 +43,8 @@ FunctionSpace::~FunctionSpace(void){ } void FunctionSpace::build(const GroupOfElement& goe, - int basisType, int order){ + const Basis& basis){ + // Save GroupOfElement & Mesh // this->goe = &goe; this->mesh = &(goe.getMesh()); @@ -54,33 +54,31 @@ void FunctionSpace::build(const GroupOfElement& goe, MElement& myElement = const_cast<MElement&>(element); - int elementType = myElement.getType(); - int nVertex = myElement.getNumPrimaryVertices(); - int nEdge = myElement.getNumEdges(); - int nFace = myElement.getNumFaces(); + int nVertex = myElement.getNumPrimaryVertices(); + int nEdge = myElement.getNumEdges(); + int nFace = myElement.getNumFaces(); // Init Struct // - nBasis = 1; - basis = new vector<const Basis*>(nBasis); - (*basis)[0] = BasisGenerator::generate(elementType, - basisType, - order, "hierarchical"); + this->nBasis = 1; + this->basis = new vector<const Basis*>(nBasis); + (*this->basis)[0] = &basis; // Number of *Per* Entity functions // - fPerVertex = (*basis)[0]->getNVertexBased() / nVertex; + fPerVertex = (*this->basis)[0]->getNVertexBased() / nVertex; // NB: fPreVertex = 0 *or* 1 if(nEdge) - fPerEdge = (*basis)[0]->getNEdgeBased() / nEdge; + fPerEdge = (*this->basis)[0]->getNEdgeBased() / nEdge; else fPerEdge = 0; if(nFace) - fPerFace = (*basis)[0]->getNFaceBased() / nFace; + fPerFace = (*this->basis)[0]->getNFaceBased() / nFace; else fPerFace = 0; - fPerCell = (*basis)[0]->getNCellBased(); // We always got 1 cell + fPerCell = (*this->basis)[0]->getNCellBased(); + // We always got 1 cell // Build Dof // buildDof(); diff --git a/FunctionSpace/FunctionSpace.h b/FunctionSpace/FunctionSpace.h index 85c89cb3de34086ed6a7c6cd21695253816e3dda..1978f54baf262c8e709dc8fe52ea21c73f5cee8e 100644 --- a/FunctionSpace/FunctionSpace.h +++ b/FunctionSpace/FunctionSpace.h @@ -89,7 +89,7 @@ class FunctionSpace{ FunctionSpace(void); void build(const GroupOfElement& goe, - int basisType, int order); + const Basis& basis); // Dof void buildDof(void); diff --git a/FunctionSpace/FunctionSpaceEdge.cpp b/FunctionSpace/FunctionSpaceEdge.cpp deleted file mode 100644 index e9000069a11aac2af15306e47db256228adcdc81..0000000000000000000000000000000000000000 --- a/FunctionSpace/FunctionSpaceEdge.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include <vector> - -#include "Mapper.h" -#include "FunctionSpaceEdge.h" - -using namespace std; - -FunctionSpaceEdge::FunctionSpaceEdge(const GroupOfElement& goe, - int order){ - // Build 1Form Basis // - build(goe, 1, order); -} - -FunctionSpaceEdge::~FunctionSpaceEdge(void){ -} - -fullVector<double> FunctionSpaceEdge:: -interpolate(const MElement& element, - const std::vector<double>& coef, - const fullVector<double>& xyz) const{ - - // Const Cast For MElement // - MElement& eelement = - const_cast<MElement&>(element); - - // Get Reference coordinate // - double phys[3] = {xyz(0), xyz(1), xyz(2)}; - double uvw[3]; - - eelement.xyz2uvw(phys, uvw); - - // Get Jacobian // - fullMatrix<double> invJac(3, 3); - eelement.getJacobian(uvw[0], uvw[1], uvw[2], invJac); - invJac.invertInPlace(); - - // Get Basis Functions // - fullMatrix<double>* fun = - (*basis)[0]->getFunctions(element, uvw[0], uvw[1], uvw[2]); - - const unsigned int nFun = fun->size1(); - - // Interpolate (in Reference Place) // - fullVector<double> val(3); - val(0) = 0; - val(1) = 0; - val(2) = 0; - - for(unsigned int i = 0; i < nFun; i++){ - val(0) += (*fun)(i, 0) * coef[i]; - val(1) += (*fun)(i, 1) * coef[i]; - val(2) += (*fun)(i, 2) * coef[i]; - } - - // Return Interpolated Value // - delete fun; - return Mapper::grad(val, invJac); -} - -fullVector<double> FunctionSpaceEdge:: -interpolateInRefSpace(const MElement& element, - const std::vector<double>& coef, - const fullVector<double>& uvw) const{ - - // Const Cast For MElement // - MElement& eelement = - const_cast<MElement&>(element); - - // Get Jacobian // - fullMatrix<double> invJac(3, 3); - eelement.getJacobian(uvw(0), uvw(1), uvw(2), invJac); - invJac.invertInPlace(); - - // Get Basis Functions // - fullMatrix<double>* fun = - (*basis)[0]->getFunctions(element, uvw(0), uvw(1), uvw(2)); - - const unsigned int nFun = fun->size1(); - - - // Interpolate (in Reference Place) // - fullVector<double> val(3); - val(0) = 0; - val(1) = 0; - val(2) = 0; - - for(unsigned int i = 0; i < nFun; i++){ - val(0) += (*fun)(i, 0) * coef[i]; - val(1) += (*fun)(i, 1) * coef[i]; - val(2) += (*fun)(i, 2) * coef[i]; - } - - // Return Interpolated Value // - delete fun; - return Mapper::grad(val, invJac); -} diff --git a/FunctionSpace/FunctionSpaceEdge.h b/FunctionSpace/FunctionSpaceEdge.h deleted file mode 100644 index 0fbbaf9b11e7efec5a8a10cd1abe7b8b18ffd50c..0000000000000000000000000000000000000000 --- a/FunctionSpace/FunctionSpaceEdge.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef _FUNCTIONSPACEEDGE_H_ -#define _FUNCTIONSPACEEDGE_H_ - -#include "FunctionSpaceVector.h" - -/** - @class FunctionSpaceEdge - @brief An Edge based Function Space - - This class is an Edge based (1-Form) Function Space. -*/ - - -class FunctionSpaceEdge : public FunctionSpaceVector{ - public: - FunctionSpaceEdge(const GroupOfElement& goe, int order); - - virtual ~FunctionSpaceEdge(void); - - virtual fullVector<double> - interpolate(const MElement& element, - const std::vector<double>& coef, - const fullVector<double>& xyz) const; - - virtual fullVector<double> - interpolateInRefSpace(const MElement& element, - const std::vector<double>& coef, - const fullVector<double>& uvw) const; -}; - - -/** - @fn FunctionSpaceEdge::FunctionSpaceEdge - @param goe The GroupOfElement defining the - @em support of this FunctionSpace - @param order The order of this FunctionSpace - - Instantiates a new Edge based Function Space - (FunctionSpaceEdge) with the given parameters - ** - - @fn FunctionSpaceEdge::~FunctionSpaceEdge - Deletes this FunctionSpaceEdge - ** - */ - -#endif diff --git a/FunctionSpace/FunctionSpaceNode.cpp b/FunctionSpace/FunctionSpaceNode.cpp deleted file mode 100644 index 0ad52444ce44091d1cf3d01d86f1c89dd8c39e0d..0000000000000000000000000000000000000000 --- a/FunctionSpace/FunctionSpaceNode.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include <vector> - -#include "Mapper.h" -#include "FunctionSpaceNode.h" - -using namespace std; - -FunctionSpaceNode::FunctionSpaceNode(const GroupOfElement& goe, - int order){ - // Build 0Form Basis // - build(goe, 0, order); -} - -FunctionSpaceNode::~FunctionSpaceNode(void){ -} - -double FunctionSpaceNode:: -interpolate(const MElement& element, - const std::vector<double>& coef, - const fullVector<double>& xyz) const{ - - // Const Cast For MElement // - MElement& eelement = - const_cast<MElement&>(element); - - // Get Reference coordinate // - double phys[3] = {xyz(0), xyz(1), xyz(2)}; - double uvw[3]; - - eelement.xyz2uvw(phys, uvw); - - // Get Basis Functions // - fullMatrix<double>* fun = - (*basis)[0]->getFunctions(element, uvw[0], uvw[1], uvw[2]); - - const unsigned int nFun = fun->size1(); - - // Interpolate (in Reference Place) // - double val = 0; - - for(unsigned int i = 0; i < nFun; i++) - val += (*fun)(i, 0) * coef[i]; - - // Return Interpolated Value // - delete fun; - return val; -} - -double FunctionSpaceNode:: -interpolateInRefSpace(const MElement& element, - const std::vector<double>& coef, - const fullVector<double>& uvw) const{ - - // Get Basis Functions // - fullMatrix<double>* fun = - (*basis)[0]->getFunctions(element, uvw(0), uvw(1), uvw(2)); - - const unsigned int nFun = fun->size1(); - - // Interpolate (in Reference Place) // - double val = 0; - - for(unsigned int i = 0; i < nFun; i++) - val += (*fun)(i, 0) * coef[i]; - - // Return Interpolated Value // - delete fun; - return val; -} diff --git a/FunctionSpace/FunctionSpaceNode.h b/FunctionSpace/FunctionSpaceNode.h deleted file mode 100644 index d682c7da9e63da2c7f9f443c197f1d29a3ed49e0..0000000000000000000000000000000000000000 --- a/FunctionSpace/FunctionSpaceNode.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef _FUNCTIONSPACENODE_H_ -#define _FUNCTIONSPACENODE_H_ - -#include "FunctionSpaceScalar.h" - -/** - @class FunctionSpaceNode - @brief A Nodal Function Space - - This class is a Nodal (0-Form) Function Space. -*/ - - -class FunctionSpaceNode : public FunctionSpaceScalar{ - public: - FunctionSpaceNode(const GroupOfElement& goe, int order); - - virtual ~FunctionSpaceNode(void); - - virtual double - interpolate(const MElement& element, - const std::vector<double>& coef, - const fullVector<double>& xyz) const; - - virtual double - interpolateInRefSpace(const MElement& element, - const std::vector<double>& coef, - const fullVector<double>& uvw) const; -}; - - -/** - @fn FunctionSpaceNode::FunctionSpaceNode - @param goe The GroupOfElement defining the - @em support of this FunctionSpace - @param order The order of this FunctionSpace - - Instantiates a new Nodal Function Space - (FunctionSpaceNode) with the given parameters - ** - - @fn FunctionSpaceNode::~FunctionSpaceNode - Deletes this FunctionSpaceNode - ** - */ - -#endif diff --git a/FunctionSpace/FunctionSpaceScalar.cpp b/FunctionSpace/FunctionSpaceScalar.cpp index ea56e27434709722f5fc718b1b505635dac5044e..c1fd8bcf0abc05281b67eeed641382504e2921f7 100644 --- a/FunctionSpace/FunctionSpaceScalar.cpp +++ b/FunctionSpace/FunctionSpaceScalar.cpp @@ -1,8 +1,65 @@ #include "FunctionSpaceScalar.h" -FunctionSpaceScalar::FunctionSpaceScalar(void){ +FunctionSpaceScalar::FunctionSpaceScalar(const GroupOfElement& goe, + const Basis& basis){ scalar = true; + build(goe, basis); } FunctionSpaceScalar::~FunctionSpaceScalar(void){ + // Done by FunctionSpace +} + +double FunctionSpaceScalar:: +interpolate(const MElement& element, + const std::vector<double>& coef, + const fullVector<double>& xyz) const{ + + // Const Cast For MElement // + MElement& eelement = + const_cast<MElement&>(element); + + // Get Reference coordinate // + double phys[3] = {xyz(0), xyz(1), xyz(2)}; + double uvw[3]; + + eelement.xyz2uvw(phys, uvw); + + // Get Basis Functions // + fullMatrix<double>* fun = + (*basis)[0]->getFunctions(element, uvw[0], uvw[1], uvw[2]); + + const unsigned int nFun = fun->size1(); + + // Interpolate (in Reference Place) // + double val = 0; + + for(unsigned int i = 0; i < nFun; i++) + val += (*fun)(i, 0) * coef[i]; + + // Return Interpolated Value // + delete fun; + return val; +} + +double FunctionSpaceScalar:: +interpolateInRefSpace(const MElement& element, + const std::vector<double>& coef, + const fullVector<double>& uvw) const{ + + // Get Basis Functions // + fullMatrix<double>* fun = + (*basis)[0]->getFunctions(element, uvw(0), uvw(1), uvw(2)); + + const unsigned int nFun = fun->size1(); + + // Interpolate (in Reference Place) // + double val = 0; + + for(unsigned int i = 0; i < nFun; i++) + val += (*fun)(i, 0) * coef[i]; + + // Return Interpolated Value // + delete fun; + return val; } diff --git a/FunctionSpace/FunctionSpaceScalar.h b/FunctionSpace/FunctionSpaceScalar.h index e52ec5de9f29a8d00f2908f10ae1f519063406a0..d6f85c50139d873fc3348b3d96b45214ffedf044 100644 --- a/FunctionSpace/FunctionSpaceScalar.h +++ b/FunctionSpace/FunctionSpaceScalar.h @@ -4,42 +4,44 @@ #include "FunctionSpace.h" /** - @interface FunctionSpaceScalar - @brief Common Interface of all Scalar FunctionSpaces + @class FunctionSpaceScalar + @brief A Scalar FunctionSpaces - This is the @em common @em interface of - all @em Scalar FunctionSpaces.@n + This class is a @em Scalar FunctionSpaces.@n - A FunctionSpaceScalar can be @em interpolated, - and can return a @em Local Basis associated - to an Element of the Support. + A FunctionSpaceScalar can be @em interpolated. - @note - A ScalarFunctionSpace is an @em interface, so it - can't be instantiated. + @todo + Allow interpolation with multiple basis */ class FunctionSpaceScalar : public FunctionSpace{ public: + FunctionSpaceScalar(const GroupOfElement& goe, const Basis& basis); virtual ~FunctionSpaceScalar(void); - virtual double + double interpolate(const MElement& element, const std::vector<double>& coef, - const fullVector<double>& xyz) const = 0; + const fullVector<double>& xyz) const; - virtual double + double interpolateInRefSpace(const MElement& element, const std::vector<double>& coef, - const fullVector<double>& uvw) const = 0; - - protected: - FunctionSpaceScalar(void); + const fullVector<double>& uvw) const; }; /** + @fn FunctionSpaceScalar::FunctionSpaceScalar + @param goe A GroupOfElement + @em of @em the @em same @em geomtrical @emtype + @param basis A Basis (with a meaning on @c goe) + Instanciates a new FunctionSpaceScalar with the + given Basis on the given GroupOfElement + ** + @fn FunctionSpaceScalar::~FunctionSpaceScalar Deletes this FunctionSpaceScalar ** diff --git a/FunctionSpace/FunctionSpaceVector.cpp b/FunctionSpace/FunctionSpaceVector.cpp index b4a3784290a30c5613212e968f082b1823e6b12f..86fb96a70a12db74b44b07e291c1c4b151a7609b 100644 --- a/FunctionSpace/FunctionSpaceVector.cpp +++ b/FunctionSpace/FunctionSpaceVector.cpp @@ -1,10 +1,93 @@ +#include "Mapper.h" #include "FunctionSpaceVector.h" -FunctionSpaceVector::FunctionSpaceVector(void){ +FunctionSpaceVector::FunctionSpaceVector(const GroupOfElement& goe, + const Basis& basis){ scalar = false; + build(goe, basis); } FunctionSpaceVector::~FunctionSpaceVector(void){ + // Done by FunctionSpace } +fullVector<double> FunctionSpaceVector:: +interpolate(const MElement& element, + const std::vector<double>& coef, + const fullVector<double>& xyz) const{ + // Const Cast For MElement // + MElement& eelement = + const_cast<MElement&>(element); + + // Get Reference coordinate // + double phys[3] = {xyz(0), xyz(1), xyz(2)}; + double uvw[3]; + + eelement.xyz2uvw(phys, uvw); + + // Get Jacobian // + fullMatrix<double> invJac(3, 3); + eelement.getJacobian(uvw[0], uvw[1], uvw[2], invJac); + invJac.invertInPlace(); + + // Get Basis Functions // + fullMatrix<double>* fun = + (*basis)[0]->getFunctions(element, uvw[0], uvw[1], uvw[2]); + + const unsigned int nFun = fun->size1(); + + // Interpolate (in Reference Place) // + fullVector<double> val(3); + val(0) = 0; + val(1) = 0; + val(2) = 0; + + for(unsigned int i = 0; i < nFun; i++){ + val(0) += (*fun)(i, 0) * coef[i]; + val(1) += (*fun)(i, 1) * coef[i]; + val(2) += (*fun)(i, 2) * coef[i]; + } + + // Return Interpolated Value // + delete fun; + return Mapper::grad(val, invJac); +} + +fullVector<double> FunctionSpaceVector:: +interpolateInRefSpace(const MElement& element, + const std::vector<double>& coef, + const fullVector<double>& uvw) const{ + + // Const Cast For MElement // + MElement& eelement = + const_cast<MElement&>(element); + + // Get Jacobian // + fullMatrix<double> invJac(3, 3); + eelement.getJacobian(uvw(0), uvw(1), uvw(2), invJac); + invJac.invertInPlace(); + + // Get Basis Functions // + fullMatrix<double>* fun = + (*basis)[0]->getFunctions(element, uvw(0), uvw(1), uvw(2)); + + const unsigned int nFun = fun->size1(); + + + // Interpolate (in Reference Place) // + fullVector<double> val(3); + val(0) = 0; + val(1) = 0; + val(2) = 0; + + for(unsigned int i = 0; i < nFun; i++){ + val(0) += (*fun)(i, 0) * coef[i]; + val(1) += (*fun)(i, 1) * coef[i]; + val(2) += (*fun)(i, 2) * coef[i]; + } + + // Return Interpolated Value // + delete fun; + return Mapper::grad(val, invJac); +} diff --git a/FunctionSpace/FunctionSpaceVector.h b/FunctionSpace/FunctionSpaceVector.h index dd0b2e770574e6abcdd14f19ff49816e51eab091..560f17ab3d23792e95956f1f12c6fb8c506e2098 100644 --- a/FunctionSpace/FunctionSpaceVector.h +++ b/FunctionSpace/FunctionSpaceVector.h @@ -1,46 +1,48 @@ #ifndef _FUNCTIONSPACEVECTOR_H_ #define _FUNCTIONSPACEVECTOR_H_ -#include "Exception.h" +#include "fullMatrix.h" #include "FunctionSpace.h" /** - @interface FunctionSpaceVector - @brief Common Interface of all Vectorial FunctionSpaces + @class FunctionSpaceVector + @brief A Vectorial FunctionSpaces - This is the @em common @em interface of - all @em Vectorial FunctionSpaces.@n + This class is a @em Vectorial FunctionSpaces.@n - A FunctionSpaceVector can be @em interpolated, - and can return a @em Local Basis associated - to an Element of the Support. + A FunctionSpaceVector can be @em interpolated. - @note - A VectorFunctionSpace is an @em interface, so it - can't be instantiated. + @todo + Allow interpolation with multiple basis */ class FunctionSpaceVector : public FunctionSpace{ public: + FunctionSpaceVector(const GroupOfElement& goe, const Basis& basis); virtual ~FunctionSpaceVector(void); - virtual fullVector<double> + fullVector<double> interpolate(const MElement& element, const std::vector<double>& coef, - const fullVector<double>& xyz) const = 0; + const fullVector<double>& xyz) const; - virtual fullVector<double> + fullVector<double> interpolateInRefSpace(const MElement& element, const std::vector<double>& coef, - const fullVector<double>& uvw) const = 0; - - protected: - FunctionSpaceVector(void); + const fullVector<double>& uvw) const; }; /** + @fn FunctionSpaceVector::FunctionSpaceVector + @param goe A GroupOfElement + @em of @em the @em same @em geomtrical @emtype + @param basis A Basis (with a meaning on @c goe) + Instanciates a new FunctionSpaceVector with the + given Basis on the given GroupOfElement + ** + @fn FunctionSpaceVector::~FunctionSpaceVector Deletes this FunctionSpaceVector **