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

Precomputing of FunctionSpace Dof + Unique ID for GroupOfElement + Correct...

Precomputing of FunctionSpace Dof + Unique ID for GroupOfElement + Correct Condition in Haroche (Be compy-past cursedsvn st --quiet)
parent f27add0c
No related branches found
No related tags found
No related merge requests found
...@@ -9,10 +9,18 @@ ...@@ -9,10 +9,18 @@
using namespace std; using namespace std;
const size_t FunctionSpace::nGeoType = 9; const size_t FunctionSpace::nGeoType = 9;
size_t FunctionSpace::nxtOffset = 0; size_t FunctionSpace::nxtOffset = 0;
FunctionSpace::FunctionSpace(void){ FunctionSpace::FunctionSpace(void){
// Alloc Basis Vector for all possible geomtrical types //
basis.resize(nGeoType, NULL);
// Alloc Function per Entity //
fPerVertex.resize(nGeoType, 0);
fPerEdge.resize(nGeoType , 0);
fPerFace.resize(nGeoType , 0);
fPerCell.resize(nGeoType , 0);
} }
FunctionSpace::~FunctionSpace(void){ FunctionSpace::~FunctionSpace(void){
...@@ -25,32 +33,20 @@ void FunctionSpace::build(const GroupOfElement& goe, string family){ ...@@ -25,32 +33,20 @@ void FunctionSpace::build(const GroupOfElement& goe, string family){
// Save Dof type offset // // Save Dof type offset //
offset = nxtOffset; offset = nxtOffset;
// Save GroupOfElement & Mesh // // Save Mesh //
this->goe = &goe;
this->mesh = &(goe.getMesh()); this->mesh = &(goe.getMesh());
// Alloc Basis Vector for all possible geomtrical types //
basis.resize(nGeoType, NULL);
// Generate Bases // // Generate Bases //
// Get geomtrical type statistics
const vector<size_t>& geoTypeStat = goe.getTypeStats(); const vector<size_t>& geoTypeStat = goe.getTypeStats();
const size_t nGeoType = geoTypeStat.size(); const size_t nGeoType = geoTypeStat.size();
// Buils basis for existing geomtrical type
for(size_t i = 0; i < nGeoType; i++) for(size_t i = 0; i < nGeoType; i++)
if(geoTypeStat[i]) if(geoTypeStat[i] != 0 && basis[i] == NULL)
basis[i] = BasisGenerator::generate(i, form, order, family); basis[i] = BasisGenerator::generate(i, form, order, family);
// Get Number of Function per Entity // // Get Number of Function per Entity //
fPerVertex.resize(nGeoType);
fPerEdge.resize(nGeoType);
fPerFace.resize(nGeoType);
fPerCell.resize(nGeoType);
for(size_t i = 0; i < nGeoType; i++){ for(size_t i = 0; i < nGeoType; i++){
if(geoTypeStat[i]){ if(geoTypeStat[i] != 0 && fPerVertex[i] == 0){
int nVertex = ReferenceSpaceManager::getNVertex(i); int nVertex = ReferenceSpaceManager::getNVertex(i);
int nEdge = ReferenceSpaceManager::getNEdge(i); int nEdge = ReferenceSpaceManager::getNEdge(i);
int nFace = ReferenceSpaceManager::getNFace(i); int nFace = ReferenceSpaceManager::getNFace(i);
...@@ -69,55 +65,70 @@ void FunctionSpace::build(const GroupOfElement& goe, string family){ ...@@ -69,55 +65,70 @@ void FunctionSpace::build(const GroupOfElement& goe, string family){
fPerCell[i] = this->basis[i]->getNCellBased(); fPerCell[i] = this->basis[i]->getNCellBased();
} }
else{
fPerVertex[i] = 0;
fPerEdge[i] = 0;
fPerFace[i] = 0;
fPerCell[i] = 0;
}
} }
// Build Dof // // Build Dof //
buildDof(); buildDof(goe);
// Find next offset //
nxtOffset = findMaxType() + 1;
} }
void FunctionSpace::buildDof(void){ void FunctionSpace::buildDof(const GroupOfElement& goe){
// Get Elements // // Get Elements //
const size_t nElement = goe->getNumber(); const size_t nElement = goe.getNumber();
const vector<const MElement*>& element = goe->getAll(); const vector<const MElement*>& element = goe.getAll();
vector<Dof> myDof; // Push GroupOfElement into map //
size_t nDof; pair<size_t, vector<vector<Dof> > > toInsert;
pair<map<size_t, vector<vector<Dof> > >::iterator, bool> isInserted;
toInsert.first = goe.getId();
toInsert.second = vector<vector<Dof> >(0);
isInserted = dof.insert(toInsert);
if(!isInserted.second)
throw Exception("FunctionSpace: cannot computed Dofs for GroupOfElement %d",
goe.getId());
// Reference & Allocate //
vector<vector<Dof> >& myDof = isInserted.first->second;
myDof.resize(nElement);
// Create Dofs // // Create Dofs //
for(size_t i = 0; i < nElement; i++){ for(size_t i = 0; i < nElement; i++)
// Get Dof for this Element getKeys(*(element[i]), myDof[i]);
getKeys(*(element[i]), myDof);
nDof = myDof.size();
// Add Dofs
for(size_t j = 0; j < nDof; j++)
dof.insert(myDof[j]);
}
} }
size_t FunctionSpace::findMaxType(void){ size_t FunctionSpace::findMaxType(void){
// Maximum type // // Maximum type //
size_t maxType = 0; size_t maxType = 0;
// Iterate for dof // // Iterate on GroupOfElement Id //
const set<Dof>::iterator end = dof.end(); map<size_t, vector<vector<Dof> > >::iterator it = dof.begin();
set<Dof>::iterator it = dof.begin(); map<size_t, vector<vector<Dof> > >::iterator end = dof.end();
size_t nElement;
size_t nDof;
size_t type;
for(; it != end; it++){
// Iterate on Elements of this GroupOfElement //
nElement = it->second.size();
for(; it != end; it++) for(size_t e = 0; e < nElement; e++){
// If this type is bigger, it becomes the new 'maxType' // Iterate on Dofs of this Element //
if(it->getType() > maxType) nDof = it->second[e].size();
maxType = it->getType();
for(size_t d = 0; d < nDof; d++){
// This Dof Type
type = it->second[e][d].getType();
// If this Dof type is bigger, it becomes the new 'maxType'
if(type > maxType)
maxType = type;
}
}
}
// Return maxType //
return maxType; return maxType;
} }
...@@ -243,16 +254,15 @@ void FunctionSpace::getKeys(const GroupOfElement& goe, ...@@ -243,16 +254,15 @@ void FunctionSpace::getKeys(const GroupOfElement& goe,
} }
} }
void FunctionSpace::getKeys(const GroupOfElement& goe, const std::vector<std::vector<Dof> >&
std::vector<std::vector<Dof> >& dof) const{ FunctionSpace::getKeys(const GroupOfElement& goe) const{
// Get Elements // // Find vector of Dof from map //
const size_t nElement = goe.getNumber(); map<size_t, vector<vector<Dof> > >::const_iterator it = dof.find(goe.getId());
const vector<const MElement*>& element = goe.getAll();
// Init Struct // if(it == dof.end())
dof.resize(nElement); throw Exception("FunctionSpace: cannot find Dofs of GroupOfElement %d",
goe.getId());
// Create Dofs // // Return vector //
for(size_t i = 0; i < nElement; i++) return it->second;
getKeys(*(element[i]), dof[i]);
} }
...@@ -32,15 +32,14 @@ class FunctionSpace{ ...@@ -32,15 +32,14 @@ class FunctionSpace{
protected: protected:
// Number of possible geomtrical topologies & Dof Type offset // // Number of possible geomtrical topologies & Dof Type offset //
static const size_t nGeoType; static const size_t nGeoType;
static size_t nxtOffset; static size_t nxtOffset;
protected: protected:
// Offset // // Offset //
size_t offset; size_t offset;
// Geometry // // Mesh //
const Mesh* mesh; const Mesh* mesh;
const GroupOfElement* goe;
// Basis // // Basis //
std::vector<const Basis*> basis; std::vector<const Basis*> basis;
...@@ -56,7 +55,7 @@ class FunctionSpace{ ...@@ -56,7 +55,7 @@ class FunctionSpace{
size_t order; size_t order;
// Dofs // // Dofs //
std::set<Dof> dof; std::map<size_t, std::vector<std::vector<Dof> > > dof;
public: public:
virtual ~FunctionSpace(void); virtual ~FunctionSpace(void);
...@@ -65,20 +64,17 @@ class FunctionSpace{ ...@@ -65,20 +64,17 @@ class FunctionSpace{
size_t getForm(void) const; size_t getForm(void) const;
size_t getOrder(void) const; size_t getOrder(void) const;
const Basis& getBasis(const MElement& element) const; const Basis& getBasis(const MElement& element) const;
const Basis& getBasis(size_t eType) const; const Basis& getBasis(size_t eType) const;
const GroupOfElement& getSupport(void) const;
void getKeys(const MElement& element, std::vector<Dof>& dof) const; void getKeys(const MElement& element, std::vector<Dof>& dof) const;
void getKeys(const GroupOfElement& goe, std::set<Dof>& dof) const; void getKeys(const GroupOfElement& goe, std::set<Dof>& dof) const;
void getKeys(const GroupOfElement& goe, const std::vector<std::vector<Dof> >& getKeys(const GroupOfElement& goe)const;
std::vector<std::vector<Dof> >& dof) const;
protected: protected:
FunctionSpace(void); FunctionSpace(void);
void build(const GroupOfElement& goe, std::string family); void build(const GroupOfElement& goe, std::string family);
void buildDof(void); void buildDof(const GroupOfElement& goe);
size_t findMaxType(void); size_t findMaxType(void);
void getUnorderedKeys(const MElement& element, std::vector<Dof>& dof) const; void getUnorderedKeys(const MElement& element, std::vector<Dof>& dof) const;
...@@ -120,10 +116,6 @@ class FunctionSpace{ ...@@ -120,10 +116,6 @@ class FunctionSpace{
@return Returns the Basis associated to the given geomtrical element type tag @return Returns the Basis associated to the given geomtrical element type tag
** **
@fn FunctionSpace::getSupport
@return Returns the support of this FunctionSpace
**
@fn void FunctionSpace::getKeys(const MElement&,std::vector<Dof>&) const @fn void FunctionSpace::getKeys(const MElement&,std::vector<Dof>&) const
@param element A MElement @param element A MElement
@param dof A vector of Dof%s @param dof A vector of Dof%s
...@@ -139,11 +131,9 @@ class FunctionSpace{ ...@@ -139,11 +131,9 @@ class FunctionSpace{
of the given GroupOfElement of the given GroupOfElement
** **
@fn void FunctionSpace::getKeys(const GroupOfElement&, std::vector<std::vector<Dof> >&) const @fn const std::vector<std::vector<Dof> >& FunctionSpace::getKeys(const GroupOfElement&) const
@param goe A GroupOfElement @param goe A GroupOfElement
@param dof A vector of vector of Dof%s @return Returns a vector of vector of Dof such that:
Populates the given vector such that:
dof[i][j] is the jth Dof of the ith element of the given GroupOfElement dof[i][j] is the jth Dof of the ith element of the given GroupOfElement
*/ */
...@@ -172,8 +162,4 @@ inline const Basis& FunctionSpace::getBasis(size_t eType) const{ ...@@ -172,8 +162,4 @@ inline const Basis& FunctionSpace::getBasis(size_t eType) const{
return *basis[eType]; return *basis[eType];
} }
inline const GroupOfElement& FunctionSpace::getSupport(void) const{
return *goe;
}
#endif #endif
...@@ -2,35 +2,64 @@ ...@@ -2,35 +2,64 @@
#include "Exception.h" #include "Exception.h"
#include "FunctionSpaceScalar.h" #include "FunctionSpaceScalar.h"
FunctionSpaceScalar::FunctionSpaceScalar(const GroupOfElement& goe, FunctionSpaceScalar::
size_t order){ FunctionSpaceScalar(const GroupOfElement& goe, size_t order){
if(order == 0) // Temp vector
throw Exception("%s: %s", std::vector<const GroupOfElement*> tmp(1);
"FunctionSpaceScalar", tmp[0] = &goe;
"Cannot have a order 0 scalar function space");
// Init
init(tmp, order, "hierarchical");
}
this->scalar = true; FunctionSpaceScalar::
this->form = 0; FunctionSpaceScalar(const std::vector<const GroupOfElement*>& goe,
this->order = order; size_t order){
// Init
init(goe, order, "hierarchical");
}
FunctionSpaceScalar::
FunctionSpaceScalar(const GroupOfElement& goe,
size_t order, std::string family){
// Temp vector
std::vector<const GroupOfElement*> tmp(1);
tmp[0] = &goe;
build(goe, "hierarchical"); // Init
init(tmp, order, family);
} }
FunctionSpaceScalar::FunctionSpaceScalar(const GroupOfElement& goe, FunctionSpaceScalar::
size_t order, std::string family){ FunctionSpaceScalar(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family){
// Init
init(goe, order, family);
}
FunctionSpaceScalar::~FunctionSpaceScalar(void){
// Done by FunctionSpace
}
void FunctionSpaceScalar::init(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family){
// Check
if(order == 0) if(order == 0)
throw Exception("%s: %s", throw Exception("%s: %s",
"FunctionSpaceScalar", "FunctionSpaceScalar",
"Cannot have a order 0 scalar function space"); "Cannot have a order 0 scalar function space");
// Init
this->scalar = true; this->scalar = true;
this->form = 0; this->form = 0;
this->order = order; this->order = order;
build(goe, family); // Build FunctionSpace
} const size_t nGoe = goe.size();
for(size_t i = 0; i < nGoe; i++)
build(*goe[i], family);
FunctionSpaceScalar::~FunctionSpaceScalar(void){ // Next Offset for next FunctionSpace
// Done by FunctionSpace nxtOffset = findMaxType() + 1;
} }
double FunctionSpaceScalar::interpolateInABC(const MElement& element, double FunctionSpaceScalar::interpolateInABC(const MElement& element,
......
...@@ -17,8 +17,13 @@ ...@@ -17,8 +17,13 @@
class FunctionSpaceScalar : public FunctionSpace{ class FunctionSpaceScalar : public FunctionSpace{
public: public:
FunctionSpaceScalar(const GroupOfElement& goe, size_t order); FunctionSpaceScalar(const GroupOfElement& goe, size_t order);
FunctionSpaceScalar(const std::vector<const GroupOfElement*>& goe,
size_t order);
FunctionSpaceScalar(const GroupOfElement& goe, size_t order, FunctionSpaceScalar(const GroupOfElement& goe, size_t order,
std::string family); std::string family);
FunctionSpaceScalar(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family);
virtual ~FunctionSpaceScalar(void); virtual ~FunctionSpaceScalar(void);
...@@ -38,6 +43,9 @@ class FunctionSpaceScalar : public FunctionSpace{ ...@@ -38,6 +43,9 @@ class FunctionSpaceScalar : public FunctionSpace{
const fullVector<double>& xyz) const; const fullVector<double>& xyz) const;
private: private:
void init(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family);
double interpolateInABC(const MElement& element, double interpolateInABC(const MElement& element,
const std::vector<double>& coef, const std::vector<double>& coef,
double abc[3]) const; double abc[3]) const;
...@@ -58,6 +66,15 @@ class FunctionSpaceScalar : public FunctionSpace{ ...@@ -58,6 +66,15 @@ class FunctionSpaceScalar : public FunctionSpace{
The instanciated FunctionSpace will use a hierarchical Basis The instanciated FunctionSpace will use a hierarchical Basis
** **
@fn FunctionSpaceScalar::FunctionSpaceScalar(const std::vector<const GroupOfElement*>&,size_t)
@param goe A vector of GroupOfElement
@param order A natural number
Instanciates a new FunctionSpaceScalar
on the given GroupOfElement%s and with the given order
The instanciated FunctionSpace will use a hierarchical Basis
**
@fn FunctionSpaceScalar::FunctionSpaceScalar(const GroupOfElement&,size_t,std::string) @fn FunctionSpaceScalar::FunctionSpaceScalar(const GroupOfElement&,size_t,std::string)
@param goe A GroupOfElement @param goe A GroupOfElement
@param order A natural number @param order A natural number
...@@ -72,6 +89,20 @@ class FunctionSpaceScalar : public FunctionSpace{ ...@@ -72,6 +89,20 @@ class FunctionSpaceScalar : public FunctionSpace{
@see See BasisGenerator::generate() @see See BasisGenerator::generate()
** **
@fn FunctionSpaceScalar::FunctionSpaceScalar(const std::vector<const GroupOfElement*>&,size_t,std::string)
@param goe A vector of GroupOfElement
@param order A natural number
@param family A stringr
Instanciates a new FunctionSpaceScalar
on the given GroupOfElement%s and with the given order
The instanciated FunctionSpace will use the requested Basis family:
@li If family is equal to 'lagrange' a Lagrange Basis will be used
@li If family is equal to 'hierarchical' a hierarchical Basis will be used
@see See BasisGenerator::generate()
**
@fn FunctionSpaceScalar::~FunctionSpaceScalar @fn FunctionSpaceScalar::~FunctionSpaceScalar
Deletes this FunctionSpaceScalar Deletes this FunctionSpaceScalar
** **
......
#include "Mapper.h" #include "Mapper.h"
#include "FunctionSpaceVector.h" #include "FunctionSpaceVector.h"
FunctionSpaceVector::FunctionSpaceVector(const GroupOfElement& goe, FunctionSpaceVector::
size_t order){ FunctionSpaceVector(const GroupOfElement& goe, size_t order){
this->scalar = false; // Temp vector
this->form = 1; std::vector<const GroupOfElement*> tmp(1);
this->order = order; tmp[0] = &goe;
// Init
init(tmp, order, "hierarchical");
}
build(goe, "hierarchical"); FunctionSpaceVector::
FunctionSpaceVector(const std::vector<const GroupOfElement*>& goe,
size_t order){
// Init
init(goe, order, "hierarchical");
} }
FunctionSpaceVector::FunctionSpaceVector(const GroupOfElement& goe, FunctionSpaceVector::
size_t order, std::string family){ FunctionSpaceVector(const GroupOfElement& goe,
this->scalar = false; size_t order, std::string family){
this->form = 1; // Temp vector
this->order = order; std::vector<const GroupOfElement*> tmp(1);
tmp[0] = &goe;
// Init
init(tmp, order, family);
}
build(goe, family); FunctionSpaceVector::
FunctionSpaceVector(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family){
// Init
init(goe, order, family);
} }
FunctionSpaceVector::~FunctionSpaceVector(void){ FunctionSpaceVector::~FunctionSpaceVector(void){
// Done by FunctionSpace // Done by FunctionSpace
} }
void FunctionSpaceVector::init(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family){
// Init
this->scalar = false;
this->form = 1;
this->order = order;
// Build FunctionSpace
const size_t nGoe = goe.size();
for(size_t i = 0; i < nGoe; i++)
build(*goe[i], family);
// Next Offset for next FunctionSpace
nxtOffset = findMaxType() + 1;
}
fullVector<double> FunctionSpaceVector:: fullVector<double> FunctionSpaceVector::
interpolateInABC(const MElement& element, interpolateInABC(const MElement& element,
const std::vector<double>& coef, const std::vector<double>& coef,
......
...@@ -18,8 +18,13 @@ ...@@ -18,8 +18,13 @@
class FunctionSpaceVector : public FunctionSpace{ class FunctionSpaceVector : public FunctionSpace{
public: public:
FunctionSpaceVector(const GroupOfElement& goe, size_t order); FunctionSpaceVector(const GroupOfElement& goe, size_t order);
FunctionSpaceVector(const std::vector<const GroupOfElement*>& goe,
size_t order);
FunctionSpaceVector(const GroupOfElement& goe, size_t order, FunctionSpaceVector(const GroupOfElement& goe, size_t order,
std::string family); std::string family);
FunctionSpaceVector(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family);
virtual ~FunctionSpaceVector(void); virtual ~FunctionSpaceVector(void);
...@@ -43,6 +48,9 @@ class FunctionSpaceVector : public FunctionSpace{ ...@@ -43,6 +48,9 @@ class FunctionSpaceVector : public FunctionSpace{
const std::vector<double>& coef, const std::vector<double>& coef,
const fullVector<double>& uvw) const; const fullVector<double>& uvw) const;
private: private:
void init(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family);
fullVector<double> fullVector<double>
interpolateInABC(const MElement& element, interpolateInABC(const MElement& element,
const std::vector<double>& coef, const std::vector<double>& coef,
...@@ -65,6 +73,15 @@ class FunctionSpaceVector : public FunctionSpace{ ...@@ -65,6 +73,15 @@ class FunctionSpaceVector : public FunctionSpace{
The instanciated FunctionSpace will use a hierarchical Basis The instanciated FunctionSpace will use a hierarchical Basis
** **
@fn FunctionSpaceVector::FunctionSpaceVector(const std::vector<const GroupOfElement*>&,size_t)
@param goe A vector of GroupOfElement
@param order A natural number
Instanciates a new FunctionSpaceVector
on the given GroupOfElement%s and with the given order
The instanciated FunctionSpace will use a hierarchical Basis
**
@fn FunctionSpaceVector::FunctionSpaceVector(const GroupOfElement&,size_t,std::string) @fn FunctionSpaceVector::FunctionSpaceVector(const GroupOfElement&,size_t,std::string)
@param goe A GroupOfElement @param goe A GroupOfElement
@param order A natural number @param order A natural number
...@@ -79,6 +96,20 @@ class FunctionSpaceVector : public FunctionSpace{ ...@@ -79,6 +96,20 @@ class FunctionSpaceVector : public FunctionSpace{
@see See BasisGenerator::generate() @see See BasisGenerator::generate()
** **
@fn FunctionSpaceVector::FunctionSpaceVector(const std::vector<const GroupOfElement*>&,size_t,std::string)
@param goe A vector of GroupOfElement
@param order A natural number
@param family A stringr
Instanciates a new FunctionSpaceVector
on the given GroupOfElement%s and with the given order
The instanciated FunctionSpace will use the requested Basis family:
@li If family is equal to 'lagrange' a Lagrange Basis will be used
@li If family is equal to 'hierarchical' a hierarchical Basis will be used
@see See BasisGenerator::generate()
**
@fn FunctionSpaceVector::~FunctionSpaceVector @fn FunctionSpaceVector::~FunctionSpaceVector
Deletes this FunctionSpaceVector Deletes this FunctionSpaceVector
** **
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment