From af398f9140cd40eb6e689ecdbc7dc76b92d76efa Mon Sep 17 00:00:00 2001 From: Nicolas Marsic <nicolas.marsic@gmail.com> Date: Wed, 29 Jan 2014 12:42:34 +0000 Subject: [PATCH] Remove getGoDFromElement -- Use getKeys instead + Preparing FunctionSpace for multiple basis --- FunctionSpace/FunctionSpace.cpp | 70 ++++++++++----------------- FunctionSpace/FunctionSpace.h | 64 +++++------------------- FunctionSpace/FunctionSpaceScalar.cpp | 8 +-- FunctionSpace/FunctionSpaceVector.cpp | 4 +- 4 files changed, 43 insertions(+), 103 deletions(-) diff --git a/FunctionSpace/FunctionSpace.cpp b/FunctionSpace/FunctionSpace.cpp index eea1a54c03..48297d445e 100644 --- a/FunctionSpace/FunctionSpace.cpp +++ b/FunctionSpace/FunctionSpace.cpp @@ -13,10 +13,8 @@ FunctionSpace::FunctionSpace(void){ } FunctionSpace::~FunctionSpace(void){ - // Delete Vector of Basis // - // (FunctionSpace is not responsible for - // 'true' Basis Deletion) - delete basis; + // Delete Vector of Basis + // (FunctionSpace is not responsible for 'true' Basis Deletion) } void FunctionSpace::build(GroupOfElement& goe, @@ -36,26 +34,30 @@ void FunctionSpace::build(GroupOfElement& goe, int nFace = myElement.getNumFaces(); // Init Struct // - this->nBasis = 1; - this->basis = new vector<const Basis*>(nBasis); - (*this->basis)[0] = &basis; + this->basis.resize(1); + this->basis[0] = &basis; // Number of *Per* Entity functions // - fPerVertex = (*this->basis)[0]->getNVertexBased() / nVertex; - // NB: fPreVertex = 0 *or* 1 + // Init + fPerVertex.resize(1); + fPerEdge.resize(1); + fPerFace.resize(1); + fPerCell.resize(1); + + // Populate + fPerVertex[0] = this->basis[0]->getNVertexBased() / nVertex; if(nEdge) - fPerEdge = (*this->basis)[0]->getNEdgeBased() / nEdge; + fPerEdge[0] = this->basis[0]->getNEdgeBased() / nEdge; else - fPerEdge = 0; + fPerEdge[0] = 0; if(nFace) - fPerFace = (*this->basis)[0]->getNFaceBased() / nFace; + fPerFace[0] = this->basis[0]->getNFaceBased() / nFace; else - fPerFace = 0; + fPerFace[0] = 0; - fPerCell = (*this->basis)[0]->getNCellBased(); - // We always got 1 cell + fPerCell[0] = this->basis[0]->getNCellBased(); // Build Dof // buildDof(); @@ -79,12 +81,8 @@ void FunctionSpace::buildDof(void){ for(size_t j = 0; j < nDof; j++) dof.insert(myDof[j]); - // Save vectorCreate new GroupOfDof + // Save vector group[i] = myDof; - - // Map GOD - eToGod.insert - (pair<const MElement*, const vector<Dof>*>(element[i], &group[i])); } } @@ -119,10 +117,10 @@ vector<Dof> FunctionSpace::getUnorderedKeys(const MElement& elem) const{ // Create Dof // size_t nDof = - fPerVertex * nVertex + - fPerEdge * nEdge + - fPerFace * nFace + - fPerCell * nCell; + fPerVertex[0] * nVertex + + fPerEdge[0] * nEdge + + fPerFace[0] * nFace + + fPerCell[0] * nCell; vector<Dof> myDof(nDof); @@ -130,7 +128,7 @@ vector<Dof> FunctionSpace::getUnorderedKeys(const MElement& elem) const{ // Add Vertex Based Dof // for(size_t i = 0; i < nVertex; i++){ - for(size_t j = 0; j < fPerVertex; j++){ + for(size_t j = 0; j < fPerVertex[0]; j++){ myDof[it].setDof(mesh->getGlobalId(*vertex[i]), j); it++; } @@ -138,7 +136,7 @@ vector<Dof> FunctionSpace::getUnorderedKeys(const MElement& elem) const{ // Add Edge Based Dof // for(size_t i = 0; i < nEdge; i++){ - for(size_t j = 0; j < fPerEdge; j++){ + for(size_t j = 0; j < fPerEdge[0]; j++){ myDof[it].setDof(mesh->getGlobalId(edge[i]), j); it++; } @@ -146,7 +144,7 @@ vector<Dof> FunctionSpace::getUnorderedKeys(const MElement& elem) const{ // Add Face Based Dof // for(size_t i = 0; i < nFace; i++){ - for(size_t j = 0; j < fPerFace; j++){ + for(size_t j = 0; j < fPerFace[0]; j++){ myDof[it].setDof(mesh->getGlobalId(face[i]), j); it++; } @@ -154,7 +152,7 @@ vector<Dof> FunctionSpace::getUnorderedKeys(const MElement& elem) const{ // Add Cell Based Dof // for(size_t i = 0; i < nCell; i++){ - for(size_t j = 0; j < fPerCell; j++){ + for(size_t j = 0; j < fPerCell[0]; j++){ myDof[it].setDof(mesh->getGlobalId(element), j); it++; } @@ -211,19 +209,3 @@ void FunctionSpace::getKeys(const GroupOfElement& goe, dof.insert(myDof[d]); } } - -const std::vector<Dof>& FunctionSpace:: -getGoDFromElement(const MElement& element) const{ - - const map<const MElement*, - const std::vector<Dof>*, - ElementComparator>::const_iterator it = eToGod.find(&element); - - if(it == eToGod.end()) - throw - Exception("Their is no GroupOfDof associated with the given MElement: %d", - element.getNum()); - - else - return *(it->second); -} diff --git a/FunctionSpace/FunctionSpace.h b/FunctionSpace/FunctionSpace.h index 5bf23dbc81..6f27b6c38b 100644 --- a/FunctionSpace/FunctionSpace.h +++ b/FunctionSpace/FunctionSpace.h @@ -4,18 +4,11 @@ #include <map> #include <vector> -#include "Basis.h" - -#include "Comparators.h" #include "Dof.h" - #include "Mesh.h" -#include "GroupOfElement.h" - +#include "Basis.h" #include "MElement.h" -#include "MVertex.h" -#include "MEdge.h" -#include "MFace.h" +#include "GroupOfElement.h" /** @interface FunctionSpace @@ -29,11 +22,10 @@ Those MElement%s must belong to the same Mesh. A FunctionSpace is also responsible for the generation of all - the Dof%s and GroupOfDof%s related to its geometrical Support. + the Dof%s related to its geometrical Support. @todo Allow Hybrid Mesh - Remove call to GroupOfElement::orientAllElements() */ class Mesh; @@ -46,12 +38,11 @@ class FunctionSpace{ GroupOfElement* goe; // Basis // - std::vector<const Basis*>* basis; - size_t nBasis; - size_t fPerVertex; - size_t fPerEdge; - size_t fPerFace; - size_t fPerCell; + std::vector<const Basis*> basis; + std::vector<size_t> fPerVertex; + std::vector<size_t> fPerEdge; + std::vector<size_t> fPerFace; + std::vector<size_t> fPerCell; // Scalar Field ? // bool scalar; @@ -59,33 +50,24 @@ class FunctionSpace{ // Dofs // std::set<Dof> dof; std::vector<std::vector<Dof> > group; - std::map< - const MElement*, - const std::vector<Dof>*, ElementComparator> eToGod; public: virtual ~FunctionSpace(void); const std::vector<const Basis*>& getBasis(const MElement& element) const; const Basis& getBasis(size_t i) const; - size_t getNBasis(void) const; GroupOfElement& getSupport(void) const; bool isScalar(void) const; std::vector<Dof> getUnorderedKeys(const MElement& element) const; std::vector<Dof> getKeys(const MElement& element) const; - std::vector<Dof> getKeys(const MVertex& vertex) const; - std::vector<Dof> getKeys(const MEdge& edge) const; - std::vector<Dof> getKeys(const MFace& face) const; void getKeys(const GroupOfElement& goe, std::set<Dof>& dof) const; const std::set<Dof>& getAllDofs(void) const; const std::vector<std::vector<Dof> >& getAllGroups(void) const; - const std::vector<Dof>& getGoDFromElement(const MElement& element) const; - protected: FunctionSpace(void); @@ -142,28 +124,8 @@ class FunctionSpace{ ** @fn FunctionSpace::getAllGroups - @return Returns all the GroupOfDof%s associated to every Element%s + @return Returns all the Dof%s associated to every Element%s of this FunctionSpace support - ** - - @fn FunctionSpace::getGoDFromElement - @param element An Element of the FunctionSpace Support - @return Returns the GroupOfDof%s associated to - the given Element - - If the given Element is not in the FunctionSpace Support, - an Exception is thrown - ** - - @fn FunctionSpace::dofNumber - @return Returns the number of Dof%s - given by FunctionSpace::getAllDofs() - ** - - @fn FunctionSpace::groupNumber - @return Returns the number of GroupOfDof%s - given by FunctionSpace::getAllGroups() - ** */ @@ -173,15 +135,11 @@ class FunctionSpace{ inline const std::vector<const Basis*>& FunctionSpace::getBasis(const MElement& element) const{ - return *basis; + return basis; } inline const Basis& FunctionSpace::getBasis(size_t i) const{ - return *(*basis)[i]; -} - -inline size_t FunctionSpace::getNBasis(void) const{ - return nBasis; + return *basis[i]; } inline GroupOfElement& FunctionSpace::getSupport(void) const{ diff --git a/FunctionSpace/FunctionSpaceScalar.cpp b/FunctionSpace/FunctionSpaceScalar.cpp index 4808c53a72..737def17af 100644 --- a/FunctionSpace/FunctionSpaceScalar.cpp +++ b/FunctionSpace/FunctionSpaceScalar.cpp @@ -17,10 +17,10 @@ interpolateInABC(const MElement& element, double abc[3]) const{ // Get Basis Functions // - const size_t nFun = (*basis)[0]->getNFunction(); + const size_t nFun = basis[0]->getNFunction(); fullMatrix<double> fun(nFun, 1); - (*basis)[0]->getFunctions(fun, element, abc[0], abc[1], abc[2]); + basis[0]->getFunctions(fun, element, abc[0], abc[1], abc[2]); // Interpolate (in Reference Place) // double val = 0; @@ -42,10 +42,10 @@ interpolateDerivativeInABC(const MElement& element, invJac.invertInPlace(); // Get Basis Functions // - const size_t nFun = (*basis)[0]->getNFunction(); + const size_t nFun = basis[0]->getNFunction(); fullMatrix<double> fun(nFun, 3); - (*basis)[0]->getDerivative(fun, element, abc[0], abc[1], abc[2]); + basis[0]->getDerivative(fun, element, abc[0], abc[1], abc[2]); // Interpolate (in Reference Place) // fullMatrix<double> val(1, 3); diff --git a/FunctionSpace/FunctionSpaceVector.cpp b/FunctionSpace/FunctionSpaceVector.cpp index 0cd0f96a95..b2c2d6dabd 100644 --- a/FunctionSpace/FunctionSpaceVector.cpp +++ b/FunctionSpace/FunctionSpaceVector.cpp @@ -22,10 +22,10 @@ interpolateInABC(const MElement& element, invJac.invertInPlace(); // Get Basis Functions // - const size_t nFun = (*basis)[0]->getNFunction(); + const size_t nFun = basis[0]->getNFunction(); fullMatrix<double> fun(nFun, 3); - (*basis)[0]->getFunctions(fun, element, abc[0], abc[1], abc[2]); + basis[0]->getFunctions(fun, element, abc[0], abc[1], abc[2]); // Interpolate (in Reference Place) // fullMatrix<double> val(1, 3); -- GitLab