Commit ba3f98b2 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Implemented iterator interface for ParallelDOFMapping.

parent 37868ad3
...@@ -170,6 +170,63 @@ namespace AMDiS { ...@@ -170,6 +170,63 @@ namespace AMDiS {
} }
void ComponentDataEqFeSpace::init(vector<const FiniteElemSpace*> &f0,
vector<const FiniteElemSpace*> &f1,
bool isNonLocal,
MeshLevelData &levelData)
{
feSpaces = f1;
feSpacesUnique = f0;
for (vector<const FiniteElemSpace*>::iterator it = feSpacesUnique.begin();
it != feSpacesUnique.end(); ++it) {
addFeSpace(*it, levelData);
componentData[*it].setNeedGlobalMapping(isNonLocal);
componentData[*it].setNonLocal(isNonLocal);
}
}
void ComponentDataEqFeSpace::addFeSpace(const FiniteElemSpace* feSpace,
MeshLevelData &levelData)
{
if (componentData.count(feSpace))
componentData.find(feSpace)->second.clear();
else
componentData.insert(make_pair(feSpace, ComponentDofMap(&levelData)));
componentData.find(feSpace)->second.setFeSpace(feSpace);
}
void ComponentDataDiffFeSpace::init(vector<const FiniteElemSpace*> &f0,
vector<const FiniteElemSpace*> &f1,
bool isNonLocal,
MeshLevelData &levelData)
{
feSpaces = f1;
feSpacesUnique = f0;
for (unsigned int component = 0; component < feSpaces.size(); component++) {
addComponent(component, feSpaces[component], levelData);
componentData[component].setNeedGlobalMapping(isNonLocal);
componentData[component].setNonLocal(isNonLocal);
}
}
void ComponentDataDiffFeSpace::addComponent(unsigned int component,
const FiniteElemSpace* feSpace,
MeshLevelData &levelData)
{
if (componentData.count(component))
componentData.find(component)->second.clear();
else
componentData.insert(make_pair(component, ComponentDofMap(&levelData)));
componentData.find(component)->second.setFeSpace(feSpace);
}
void ParallelDofMapping::init(MeshLevelData &ldata, void ParallelDofMapping::init(MeshLevelData &ldata,
vector<const FiniteElemSpace*> &fe, vector<const FiniteElemSpace*> &fe,
vector<const FiniteElemSpace*> &uniqueFe, vector<const FiniteElemSpace*> &uniqueFe,
...@@ -180,7 +237,7 @@ namespace AMDiS { ...@@ -180,7 +237,7 @@ namespace AMDiS {
levelData = &ldata; levelData = &ldata;
isNonLocal = b; isNonLocal = b;
data->init(fe, uniqueFe, isNonLocal); data->init(fe, uniqueFe, isNonLocal, ldata);
} }
......
...@@ -94,7 +94,6 @@ namespace AMDiS { ...@@ -94,7 +94,6 @@ namespace AMDiS {
private: private:
/// The mapping data. For each system component there is a specific map that /// The mapping data. For each system component there is a specific map that
/// maps global DOF indices to global matrix indices. /// maps global DOF indices to global matrix indices.
// map<int, map<DegreeOfFreedom, int> > data;
map<int, boost::container::flat_map<DegreeOfFreedom, int> > data; map<int, boost::container::flat_map<DegreeOfFreedom, int> > data;
}; };
...@@ -291,6 +290,7 @@ namespace AMDiS { ...@@ -291,6 +290,7 @@ namespace AMDiS {
int nRankDofs, nLocalDofs, nOverallDofs, rStartDofs; int nRankDofs, nLocalDofs, nOverallDofs, rStartDofs;
}; };
class ComponentIterator { class ComponentIterator {
public: public:
virtual ComponentDofMap& operator*() = 0; virtual ComponentDofMap& operator*() = 0;
...@@ -304,6 +304,7 @@ namespace AMDiS { ...@@ -304,6 +304,7 @@ namespace AMDiS {
virtual void reset() = 0; virtual void reset() = 0;
}; };
class ComponentDataInterface class ComponentDataInterface
{ {
public: public:
...@@ -319,7 +320,8 @@ namespace AMDiS { ...@@ -319,7 +320,8 @@ namespace AMDiS {
virtual void init(vector<const FiniteElemSpace*> &f0, virtual void init(vector<const FiniteElemSpace*> &f0,
vector<const FiniteElemSpace*> &f1, vector<const FiniteElemSpace*> &f1,
bool isNonLocal) = 0; bool isNonLocal,
MeshLevelData &levelData) = 0;
vector<const FiniteElemSpace*>& getFeSpaces() vector<const FiniteElemSpace*>& getFeSpaces()
{ {
...@@ -339,6 +341,11 @@ namespace AMDiS { ...@@ -339,6 +341,11 @@ namespace AMDiS {
class ComponentDataEqFeSpace : ComponentDataInterface class ComponentDataEqFeSpace : ComponentDataInterface
{ {
public: public:
ComponentDataEqFeSpace()
: iterData(this),
iterComponent(this)
{}
ComponentDofMap& operator[](int compNumber) ComponentDofMap& operator[](int compNumber)
{ {
const FiniteElemSpace *feSpace = feSpaces[compNumber]; const FiniteElemSpace *feSpace = feSpaces[compNumber];
...@@ -372,78 +379,87 @@ namespace AMDiS { ...@@ -372,78 +379,87 @@ namespace AMDiS {
void init(vector<const FiniteElemSpace*> &f0, void init(vector<const FiniteElemSpace*> &f0,
vector<const FiniteElemSpace*> &f1, vector<const FiniteElemSpace*> &f1,
bool isNonLocal) bool isNonLocal,
{ MeshLevelData &levelData);
// === Init the mapping for all different FE spaces. ===
// for (vector<const FiniteElemSpace*>::iterator it = feSpacesUnique.begin();
// it != feSpacesUnique.end(); ++it) {
// addFeSpace(*it);
// data[*it].setNeedGlobalMapping(isNonLocal);
// data[*it].setNonLocal(isNonLocal);
// }
// void ParallelDofMapping::addFeSpace(const FiniteElemSpace* feSpace)
// {
// FUNCNAME("ParallelDofMapping::addFeSpace()");
// if (data.count(feSpace))
// data.find(feSpace)->second.clear();
// else
// data.insert(make_pair(feSpace, ComponentDofMap(levelData)));
// data.find(feSpace)->second.setFeSpace(feSpace);
// }
} protected:
void addFeSpace(const FiniteElemSpace* feSpace,
MeshLevelData &levelData);
protected:
class IteratorData : public ComponentIterator { class IteratorData : public ComponentIterator {
public: public:
IteratorData(ComponentDataEqFeSpace *d)
: data(d)
{}
ComponentDofMap& operator*() ComponentDofMap& operator*()
{ {
(*data)[*it];
} }
ComponentDofMap* operator->() ComponentDofMap* operator->()
{ {
&((*data)[*it]);
} }
bool end() bool end()
{ {
return (it != data->feSpacesUnique.end());
} }
void next() void next()
{ {
++it;
} }
void reset() void reset()
{ {
it = data->feSpacesUnique.begin();
} }
protected:
ComponentDataEqFeSpace *data;
vector<const FiniteElemSpace*>::iterator it;
}; };
class IteratorComponent : public ComponentIterator { class IteratorComponent : public ComponentIterator {
public: public:
IteratorComponent(ComponentDataEqFeSpace *d)
: data(d)
{}
ComponentDofMap& operator*() ComponentDofMap& operator*()
{ {
(*data)[*it];
} }
ComponentDofMap* operator->() ComponentDofMap* operator->()
{ {
&((*data)[*it]);
} }
bool end() bool end()
{ {
return (it != data->feSpaces.end());
} }
void next() void next()
{ {
++it;
} }
void reset() void reset()
{ {
it = data->feSpaces.begin();
} }
protected:
ComponentDataEqFeSpace *data;
vector<const FiniteElemSpace*>::iterator it;
}; };
...@@ -452,12 +468,20 @@ namespace AMDiS { ...@@ -452,12 +468,20 @@ namespace AMDiS {
IteratorData iterData; IteratorData iterData;
IteratorComponent iterComponent; IteratorComponent iterComponent;
friend class IteratorData;
friend class IteratorComponent;
}; };
class ComponentDataDiffFeSpace : ComponentDataInterface class ComponentDataDiffFeSpace : ComponentDataInterface
{ {
public: public:
ComponentDataDiffFeSpace()
: iter(this)
{}
ComponentDofMap& operator[](int compNumber) ComponentDofMap& operator[](int compNumber)
{ {
TEST_EXIT_DBG(componentData.count(compNumber))("No data for component %d!\n", compNumber); TEST_EXIT_DBG(componentData.count(compNumber))("No data for component %d!\n", compNumber);
...@@ -472,14 +496,14 @@ namespace AMDiS { ...@@ -472,14 +496,14 @@ namespace AMDiS {
ComponentIterator& getIteratorData() ComponentIterator& getIteratorData()
{ {
iterData.reset(); iter.reset();
return iterData; return iter;
} }
ComponentIterator& getIteratorComponent() ComponentIterator& getIteratorComponent()
{ {
iterComponent.reset(); iter.reset();
return iterComponent; return iter;
} }
bool isDefinedFor(int compNumber) const bool isDefinedFor(int compNumber) const
...@@ -487,60 +511,67 @@ namespace AMDiS { ...@@ -487,60 +511,67 @@ namespace AMDiS {
return (static_cast<unsigned int>(compNumber) < componentData.size()); return (static_cast<unsigned int>(compNumber) < componentData.size());
} }
void init(vector<const FiniteElemSpace*> &f0,
vector<const FiniteElemSpace*> &f1,
bool isNonLocal,
MeshLevelData &levelData);
protected: protected:
class IteratorData : public ComponentIterator { void addComponent(unsigned int component,
const FiniteElemSpace* feSpace,
MeshLevelData &levelData);
class Iterator : public ComponentIterator {
public: public:
Iterator(ComponentDataDiffFeSpace *d)
: data(d),
componentCounter(-1)
{}
ComponentDofMap& operator*() ComponentDofMap& operator*()
{ {
(*data)[componentCounter];
} }
ComponentDofMap* operator->() ComponentDofMap* operator->()
{ {
&((*data)[componentCounter]);
} }
bool end() bool end()
{ {
return (it != data->feSpaces.end());
} }
void next() void next()
{ {
} ++it;
++componentCounter;
void reset()
{
}
};
class IteratorComponent : public ComponentIterator { if (it == data->feSpaces.end())
public: componentCounter = -1;
ComponentDofMap& operator*()
{
} }
ComponentDofMap* operator->() void reset()
{ {
it = data->feSpaces.begin();
componentCounter = 0;
} }
protected:
bool end() ComponentDataDiffFeSpace *data;
{
}
void next() vector<const FiniteElemSpace*>::iterator it;
{
}
void reset() int componentCounter;
{
}
}; };
map<unsigned int, ComponentDofMap> componentData; map<unsigned int, ComponentDofMap> componentData;
IteratorData iterData; Iterator iter;
IteratorComponent iterComponent; friend class Iterator;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment