diff --git a/FunctionSpace/FunctionSpace.cpp b/FunctionSpace/FunctionSpace.cpp index d30040297e206cb620a0cfddba6a6aa506d9c86d..7cffb23b0d8361fd29cbe36c37780d1b7a9b77a4 100644 --- a/FunctionSpace/FunctionSpace.cpp +++ b/FunctionSpace/FunctionSpace.cpp @@ -1,23 +1,53 @@ #include <sstream> #include "FunctionSpace.h" #include "BasisGenerator.h" +#include "Exception.h" using namespace std; FunctionSpace::FunctionSpace(void){ + // No Dof // + dof = NULL; + group = NULL; + eToGod = NULL; } FunctionSpace::~FunctionSpace(void){ - map<const MElement*, vector<bool>*>::iterator it + // Basis // + delete basis; + + // Closure // + map<const MElement*, vector<bool>*>::iterator cIt = edgeClosure->begin(); - map<const MElement*, vector<bool>*>::iterator stop + map<const MElement*, vector<bool>*>::iterator cStop = edgeClosure->end(); - - for(; it != stop; it++) - delete it->second; + + for(; cIt != cStop; cIt++) + delete cIt->second; delete edgeClosure; - delete basis; + // Dof // + if(dof){ + set<const Dof*>::iterator dStop = dof->end(); + set<const Dof*>::iterator dIt = dof->begin(); + + for(; dIt != dStop; dIt++) + delete *dIt; + delete dof; + } + + // Group // + if(group){ + unsigned int nElement = group->size(); + + for(unsigned int i = 0; i < nElement; i++) + delete (*group)[i]; + delete group; + } + + // Element To GoD // + if(eToGod) + delete eToGod; } void FunctionSpace::build(const GroupOfElement& goe, @@ -58,16 +88,21 @@ void FunctionSpace::build(const GroupOfElement& goe, fPerCell = basis->getNCellBased(); // We always got 1 cell - // Build Closure - edgeClosure = new map<const MElement*, vector<bool>*>; - closure(); + // Build Closure // + buildClosure(); + + // Build Dof // + buildDof(); } -void FunctionSpace::closure(void){ +void FunctionSpace::buildClosure(void){ // Get Elements // const vector<const MElement*>& element = goe->getAll(); const unsigned int size = element.size(); + // Init // + edgeClosure = new map<const MElement*, vector<bool>*>; + // Iterate on elements // for(unsigned int i = 0; i < size; i++){ // Get Element data @@ -119,6 +154,59 @@ void FunctionSpace::closure(void){ } } +void FunctionSpace::buildDof(void){ + // Get Elements // + unsigned int nElement = goe->getNumber(); + const vector<const MElement*>& element = goe->getAll(); + + // Init Struct // + dof = new set<const Dof*, DofComparator>; + group = new vector<GroupOfDof*>(nElement); + eToGod = new map<const MElement*, + const GroupOfDof*, + ElementComparator>; + + // Create Dofs // + for(unsigned int i = 0; i < nElement; i++){ + // Get Dof for this Element + vector<Dof> myDof = getKeys(*(element[i])); + unsigned int nDof = myDof.size(); + + // Create new GroupOfDof + GroupOfDof* god = new GroupOfDof(nDof, *(element[i])); + (*group)[i] = god; + + // Add Dof + for(unsigned int j = 0; j < nDof; j++) + insertDof(myDof[j], god); + + // Map GOD + eToGod->insert(pair<const MElement*, const GroupOfDof*> + (element[i], god)); + } +} + +void FunctionSpace::insertDof(Dof& d, GroupOfDof* god){ + // Copy 'd' + const Dof* tmp = new Dof(d); + + // Try to insert Dof // + pair<set<const Dof*, DofComparator>::iterator, bool> p + = dof->insert(tmp); + + // If insertion is OK (Dof 'd' didn't exist) // + // --> Add new Dof in GoD + if(p.second) + god->add(tmp); + + // If insertion failed (Dof 'd' already exists) // + // --> delete 'd' and add existing Dof in GoD + else{ + delete tmp; + god->add(*(p.first)); + } +} + vector<Dof> FunctionSpace::getKeys(const MElement& elem) const{ // Const_Cast // MElement& element = const_cast<MElement&>(elem); @@ -193,6 +281,18 @@ vector<Dof> FunctionSpace::getKeys(const MElement& elem) const{ return myDof; } +const GroupOfDof& FunctionSpace::getGoDFromElement(const MElement& element) const{ + const map<const MElement*, const GroupOfDof*, ElementComparator>::iterator it = + eToGod->find(&element); + + if(it == eToGod->end()) + throw + Exception("Their is no GroupOfDof associated with the given MElement"); + + else + return *(it->second); +} + string FunctionSpace::toString(void) const{ return basis->toString(); } diff --git a/FunctionSpace/FunctionSpace.h b/FunctionSpace/FunctionSpace.h index e945a8dbb9646a05218c1f361cfa0779368f0ed5..0ab0758505ffb9acf0c6618df533ed00c8d06a65 100644 --- a/FunctionSpace/FunctionSpace.h +++ b/FunctionSpace/FunctionSpace.h @@ -6,7 +6,9 @@ #include <string> #include "Basis.h" +#include "Comparators.h" #include "Dof.h" +#include "GroupOfDof.h" #include "Mesh.h" #include "GroupOfElement.h" @@ -38,24 +40,33 @@ class FunctionSpace{ protected: + // Geometry // const Mesh* mesh; const GroupOfElement* goe; - const Basis* basis; - - std::map<const MElement*, std::vector<bool>*>* edgeClosure; + // Basis // + const Basis* basis; unsigned int fPerVertex; unsigned int fPerEdge; unsigned int fPerFace; unsigned int fPerCell; - unsigned int type; + // Closure // + std::map<const MElement*, std::vector<bool>*>* edgeClosure; + + // Dofs // + std::set<const Dof*, DofComparator>* dof; + std::vector<GroupOfDof*>* group; + std::map< + const MElement*, + const GroupOfDof*, ElementComparator>* eToGod; + public: virtual ~FunctionSpace(void); const GroupOfElement& getSupport(void) const; - int getType(void) const; + unsigned int getType(void) const; unsigned int getNFunctionPerVertex(const MElement& element) const; unsigned int getNFunctionPerEdge(const MElement& element) const; @@ -67,6 +78,14 @@ class FunctionSpace{ std::vector<Dof> getKeys(const MEdge& edge) const; std::vector<Dof> getKeys(const MFace& face) const; + unsigned int dofNumber(void) const; + unsigned int groupNumber(void) const; + + const std::vector<const Dof*> getAllDofs(void) const; + const std::vector<GroupOfDof*>& getAllGroups(void) const; + + const GroupOfDof& getGoDFromElement(const MElement& element) const; + std::string toString(void) const; protected: @@ -75,7 +94,10 @@ class FunctionSpace{ void build(const GroupOfElement& goe, int basisType, int order); - void closure(void); + void buildClosure(void); + void buildDof(void); + + void insertDof(Dof& d, GroupOfDof* god); }; @@ -178,7 +200,7 @@ inline const GroupOfElement& FunctionSpace::getSupport(void) const{ return *goe; } -inline int FunctionSpace::getType(void) const{ +inline unsigned int FunctionSpace::getType(void) const{ return type; } @@ -198,4 +220,20 @@ inline unsigned int FunctionSpace::getNFunctionPerCell(const MElement& element) return fPerCell; } +inline unsigned int FunctionSpace::dofNumber(void) const{ + return dof->size(); +} + +inline unsigned int FunctionSpace::groupNumber(void) const{ + return group->size(); +} + +inline const std::vector<const Dof*> FunctionSpace::getAllDofs(void) const{ + return std::vector<const Dof*>(dof->begin(), dof->end()); +} + +inline const std::vector<GroupOfDof*>& FunctionSpace::getAllGroups(void) const{ + return *group; +} + #endif