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

New structure: Works but need cleaning and new doc

parent 67dfca4f
No related branches found
No related tags found
No related merge requests found
#include <sstream> #include <sstream>
#include "FunctionSpace.h" #include "FunctionSpace.h"
#include "BasisGenerator.h" #include "BasisGenerator.h"
#include "Exception.h"
using namespace std; using namespace std;
FunctionSpace::FunctionSpace(void){ FunctionSpace::FunctionSpace(void){
// No Dof //
dof = NULL;
group = NULL;
eToGod = NULL;
} }
FunctionSpace::~FunctionSpace(void){ FunctionSpace::~FunctionSpace(void){
map<const MElement*, vector<bool>*>::iterator it // Basis //
delete basis;
// Closure //
map<const MElement*, vector<bool>*>::iterator cIt
= edgeClosure->begin(); = edgeClosure->begin();
map<const MElement*, vector<bool>*>::iterator stop map<const MElement*, vector<bool>*>::iterator cStop
= edgeClosure->end(); = edgeClosure->end();
for(; it != stop; it++) for(; cIt != cStop; cIt++)
delete it->second; delete cIt->second;
delete edgeClosure; 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, void FunctionSpace::build(const GroupOfElement& goe,
...@@ -58,16 +88,21 @@ void FunctionSpace::build(const GroupOfElement& goe, ...@@ -58,16 +88,21 @@ void FunctionSpace::build(const GroupOfElement& goe,
fPerCell = basis->getNCellBased(); // We always got 1 cell fPerCell = basis->getNCellBased(); // We always got 1 cell
// Build Closure // Build Closure //
edgeClosure = new map<const MElement*, vector<bool>*>; buildClosure();
closure();
// Build Dof //
buildDof();
} }
void FunctionSpace::closure(void){ void FunctionSpace::buildClosure(void){
// Get Elements // // Get Elements //
const vector<const MElement*>& element = goe->getAll(); const vector<const MElement*>& element = goe->getAll();
const unsigned int size = element.size(); const unsigned int size = element.size();
// Init //
edgeClosure = new map<const MElement*, vector<bool>*>;
// Iterate on elements // // Iterate on elements //
for(unsigned int i = 0; i < size; i++){ for(unsigned int i = 0; i < size; i++){
// Get Element data // Get Element data
...@@ -119,6 +154,59 @@ void FunctionSpace::closure(void){ ...@@ -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{ vector<Dof> FunctionSpace::getKeys(const MElement& elem) const{
// Const_Cast // // Const_Cast //
MElement& element = const_cast<MElement&>(elem); MElement& element = const_cast<MElement&>(elem);
...@@ -193,6 +281,18 @@ vector<Dof> FunctionSpace::getKeys(const MElement& elem) const{ ...@@ -193,6 +281,18 @@ vector<Dof> FunctionSpace::getKeys(const MElement& elem) const{
return myDof; 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{ string FunctionSpace::toString(void) const{
return basis->toString(); return basis->toString();
} }
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#include <string> #include <string>
#include "Basis.h" #include "Basis.h"
#include "Comparators.h"
#include "Dof.h" #include "Dof.h"
#include "GroupOfDof.h"
#include "Mesh.h" #include "Mesh.h"
#include "GroupOfElement.h" #include "GroupOfElement.h"
...@@ -38,24 +40,33 @@ ...@@ -38,24 +40,33 @@
class FunctionSpace{ class FunctionSpace{
protected: protected:
// Geometry //
const Mesh* mesh; const Mesh* mesh;
const GroupOfElement* goe; const GroupOfElement* goe;
const Basis* basis;
std::map<const MElement*, std::vector<bool>*>* edgeClosure;
// Basis //
const Basis* basis;
unsigned int fPerVertex; unsigned int fPerVertex;
unsigned int fPerEdge; unsigned int fPerEdge;
unsigned int fPerFace; unsigned int fPerFace;
unsigned int fPerCell; unsigned int fPerCell;
unsigned int type; 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: public:
virtual ~FunctionSpace(void); virtual ~FunctionSpace(void);
const GroupOfElement& getSupport(void) const; const GroupOfElement& getSupport(void) const;
int getType(void) const; unsigned int getType(void) const;
unsigned int getNFunctionPerVertex(const MElement& element) const; unsigned int getNFunctionPerVertex(const MElement& element) const;
unsigned int getNFunctionPerEdge(const MElement& element) const; unsigned int getNFunctionPerEdge(const MElement& element) const;
...@@ -67,6 +78,14 @@ class FunctionSpace{ ...@@ -67,6 +78,14 @@ class FunctionSpace{
std::vector<Dof> getKeys(const MEdge& edge) const; std::vector<Dof> getKeys(const MEdge& edge) const;
std::vector<Dof> getKeys(const MFace& face) 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; std::string toString(void) const;
protected: protected:
...@@ -75,7 +94,10 @@ class FunctionSpace{ ...@@ -75,7 +94,10 @@ class FunctionSpace{
void build(const GroupOfElement& goe, void build(const GroupOfElement& goe,
int basisType, int order); 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{ ...@@ -178,7 +200,7 @@ inline const GroupOfElement& FunctionSpace::getSupport(void) const{
return *goe; return *goe;
} }
inline int FunctionSpace::getType(void) const{ inline unsigned int FunctionSpace::getType(void) const{
return type; return type;
} }
...@@ -198,4 +220,20 @@ inline unsigned int FunctionSpace::getNFunctionPerCell(const MElement& element) ...@@ -198,4 +220,20 @@ inline unsigned int FunctionSpace::getNFunctionPerCell(const MElement& element)
return fPerCell; 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 #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment