Commit 7854212b authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Further development of SolutionDataStorage

parent 929d4333
...@@ -76,28 +76,28 @@ namespace AMDiS { ...@@ -76,28 +76,28 @@ namespace AMDiS {
*/ */
inline std::string getName() const { inline std::string getName() const {
return name; return name;
}; }
/** \brief /** \brief
* Returns \ref admin * Returns \ref admin
*/ */
inline DOFAdmin* getAdmin() const { inline DOFAdmin* getAdmin() const {
return admin; return admin;
}; }
/** \brief /** \brief
* Returns \ref basFcts * Returns \ref basFcts
*/ */
inline const BasisFunction* getBasisFcts() const { inline const BasisFunction* getBasisFcts() const {
return basFcts; return basFcts;
}; }
/** \brief /** \brief
* Returns \ref mesh * Returns \ref mesh
*/ */
inline Mesh* getMesh() const { inline Mesh* getMesh() const {
return mesh; return mesh;
}; }
protected: protected:
/** \brief /** \brief
...@@ -107,7 +107,7 @@ namespace AMDiS { ...@@ -107,7 +107,7 @@ namespace AMDiS {
FiniteElemSpace(DOFAdmin* admin_, FiniteElemSpace(DOFAdmin* admin_,
const BasisFunction* basisFcts, const BasisFunction* basisFcts,
Mesh* mesh, Mesh* mesh,
const std::string& name_=""); const std::string& name_ = "");
protected: protected:
/** \brief /** \brief
......
...@@ -25,8 +25,14 @@ namespace AMDiS { ...@@ -25,8 +25,14 @@ namespace AMDiS {
class SolutionDataStorage class SolutionDataStorage
{ {
public: public:
/** \brief
*
*/
SolutionDataStorage(std::string name); SolutionDataStorage(std::string name);
/** \brief
*
*/
~SolutionDataStorage(); ~SolutionDataStorage();
/** \brief /** \brief
...@@ -35,17 +41,60 @@ namespace AMDiS { ...@@ -35,17 +41,60 @@ namespace AMDiS {
void setFixFESpace(typename SolutionHelper<T>::type feSpace, void setFixFESpace(typename SolutionHelper<T>::type feSpace,
bool cleanupFeSpace = false); bool cleanupFeSpace = false);
/** \brief
*
*/
void push(T *solution,
double timestamp,
bool cleanupSolution = true);
/** \brief
*
*/
void push(T *solution, void push(T *solution,
double timestamp, double timestamp,
FiniteElemSpace *feSpace = NULL, typename SolutionHelper<T>::type feSpace,
bool cleanupSolution = true, bool cleanupSolution = true,
bool cleanupFeSpace = true); bool cleanupFeSpace = true);
bool pop(T *solution, /** \brief
*
*/
bool pop(T **solution,
double *timestep);
bool pop(T **solution,
double *timestep, double *timestep,
FiniteElemSpace *feSpace = NULL); typename SolutionHelper<T>::type feSpace);
/** \brief
* Returns for a given solution number the corresponding fe Space. If the
* the fe Space is fixed, the fe Space for all solutions is stored at
* position 0.
*/
typename SolutionHelper<T>::type getFeSpace(int i = 0) {
return feSpaces[i];
}
protected: protected:
/** \brief
* Auxiliary function for deleting either a single fe space, or a
* vector of fe spaces.
*/
void deleteFeSpace(FiniteElemSpace* feSpace) {
DELETE feSpace;
}
void deleteFeSpace(std::vector<FiniteElemSpace*> feSpaces) {
for (int i = 0; i < static_cast<int>(feSpaces.size()); i++)
DELETE feSpaces[i];
feSpaces.empty();
}
/** \brief
* Deletes all pointers and empties all internal vectors.
*/
void cleanup(); void cleanup();
/** \brief /** \brief
...@@ -72,7 +121,7 @@ namespace AMDiS { ...@@ -72,7 +121,7 @@ namespace AMDiS {
* Here, all the solutions (i.e. either DOFVectors or SystemVectors) * Here, all the solutions (i.e. either DOFVectors or SystemVectors)
* are stored. * are stored.
*/ */
std::vector<T> solutions; std::vector<T*> solutions;
/** \brief /** \brief
* Stores to every solution its FE Space. If \ref fixedFESpace is set * Stores to every solution its FE Space. If \ref fixedFESpace is set
......
...@@ -44,9 +44,7 @@ namespace AMDiS { ...@@ -44,9 +44,7 @@ namespace AMDiS {
template<typename T> template<typename T>
void SolutionDataStorage<T>::push(T *solution, void SolutionDataStorage<T>::push(T *solution,
double timestamp, double timestamp,
FiniteElemSpace *feSpace, bool cleanupSolution)
bool cleanupSolution,
bool cleanupFeSpace)
{ {
// If pop was the last operation, cleanup and reset the data storage. // If pop was the last operation, cleanup and reset the data storage.
if (poped) { if (poped) {
...@@ -58,29 +56,35 @@ namespace AMDiS { ...@@ -58,29 +56,35 @@ namespace AMDiS {
timestamps.push_back(timestamp); timestamps.push_back(timestamp);
cleanupSolutions.push_back(cleanupSolution); cleanupSolutions.push_back(cleanupSolution);
lastPos++;
}
template<typename T>
void SolutionDataStorage<T>::push(T *solution,
double timestamp,
typename SolutionHelper<T>::type feSpace,
bool cleanupSolution,
bool cleanupFeSpace)
{
push(solution, timestamp, cleanupSolution, cleanupFeSpace);
// Store fe space only, if we do not have a fixed fe space. // Store fe space only, if we do not have a fixed fe space.
if (!fixedFESpace) { if (!fixedFESpace) {
feSpaces.push_back(feSpace); feSpaces.push_back(feSpace);
cleanupFeSpaces.push_back(cleanupFeSpace); cleanupFeSpaces.push_back(cleanupFeSpace);
} }
lastPos++;
} }
template<typename T> template<typename T>
bool SolutionDataStorage<T>::pop(T *solution, bool SolutionDataStorage<T>::pop(T **solution,
double *timestamp, double *timestamp)
FiniteElemSpace *feSpace)
{ {
if (lastPos < 0) { if (lastPos < 0) {
return false; return false;
} }
solution = solutions[lastPos]; *solution = solutions[lastPos];
*timestamp = timestamps[lastPos]; *timestamp = timestamps[lastPos];
if (!fixedFESpace) {
feSpace = feSpaces[lastPos];
}
lastPos--; lastPos--;
poped = true; poped = true;
...@@ -88,6 +92,24 @@ namespace AMDiS { ...@@ -88,6 +92,24 @@ namespace AMDiS {
return true; return true;
} }
template<typename T>
bool SolutionDataStorage<T>::pop(T **solution,
double *timestep,
typename SolutionHelper<T>::type feSpace)
{
if (!pop(solution, timestep))
return false;
if (!fixedFESpace) {
feSpace = feSpaces[lastPos + 1]; // + 1, because lastPos was decremented in pop call above
} else {
feSpace = feSpaces[0];
}
return true;
}
template<typename T> template<typename T>
void SolutionDataStorage<T>::cleanup() void SolutionDataStorage<T>::cleanup()
{ {
...@@ -99,7 +121,7 @@ namespace AMDiS { ...@@ -99,7 +121,7 @@ namespace AMDiS {
for (int i = 0; i < static_cast<int>(cleanupFeSpaces.size()); i++) { for (int i = 0; i < static_cast<int>(cleanupFeSpaces.size()); i++) {
if (cleanupFeSpaces[i]) { if (cleanupFeSpaces[i]) {
DELETE feSpaces[i]; deleteFeSpace(feSpaces[i]);
} }
} }
......
...@@ -124,7 +124,7 @@ namespace AMDiS { ...@@ -124,7 +124,7 @@ namespace AMDiS {
{ {
vectors.set(NULL); vectors.set(NULL);
}; }
/** \brief /** \brief
* Copy Constructor. * Copy Constructor.
...@@ -136,11 +136,19 @@ namespace AMDiS { ...@@ -136,11 +136,19 @@ namespace AMDiS {
{ {
for (int i = 0; i < vectors.getSize(); i++) { for (int i = 0; i < vectors.getSize(); i++) {
vectors[i] = new DOFVector<double>(*rhs.vectors[i]); vectors[i] = NEW DOFVector<double>(*rhs.vectors[i]);
} }
}; }
virtual ~SystemVector()
{}
virtual ~SystemVector() {}; void createNewDOFVectors(std::string name)
{
for (int i = 0; i < vectors.getSize(); i++) {
vectors[i] = NEW DOFVector<double>(feSpace[i], "tmp");
}
}
/** \brief /** \brief
* Sets \ref vectors[index] = vec. * Sets \ref vectors[index] = vec.
...@@ -148,7 +156,7 @@ namespace AMDiS { ...@@ -148,7 +156,7 @@ namespace AMDiS {
inline void setDOFVector(int index, DOFVector<double> *vec) { inline void setDOFVector(int index, DOFVector<double> *vec) {
TEST_EXIT_DBG(index < vectors.getSize())("invalid index\n"); TEST_EXIT_DBG(index < vectors.getSize())("invalid index\n");
vectors[index] = vec; vectors[index] = vec;
}; }
/** \brief /** \brief
* Returns \ref vectors[index]. * Returns \ref vectors[index].
...@@ -156,7 +164,7 @@ namespace AMDiS { ...@@ -156,7 +164,7 @@ namespace AMDiS {
inline DOFVector<double> *getDOFVector(int index) { inline DOFVector<double> *getDOFVector(int index) {
TEST_EXIT_DBG(index < vectors.getSize())("invalid index\n"); TEST_EXIT_DBG(index < vectors.getSize())("invalid index\n");
return vectors[index]; return vectors[index];
}; }
/** \brief /** \brief
* Returns \ref vectors[index]. * Returns \ref vectors[index].
...@@ -164,7 +172,7 @@ namespace AMDiS { ...@@ -164,7 +172,7 @@ namespace AMDiS {
inline const DOFVector<double> *getDOFVector(int index) const { inline const DOFVector<double> *getDOFVector(int index) const {
TEST_EXIT_DBG(index < vectors.getSize())("invalid index\n"); TEST_EXIT_DBG(index < vectors.getSize())("invalid index\n");
return vectors[index]; return vectors[index];
}; }
/** \brief /** \brief
* Returns sum of used vector sizes. * Returns sum of used vector sizes.
...@@ -176,25 +184,25 @@ namespace AMDiS { ...@@ -176,25 +184,25 @@ namespace AMDiS {
totalSize += vectors[i]->getUsedSize(); totalSize += vectors[i]->getUsedSize();
} }
return totalSize; return totalSize;
}; }
/** \brief /** \brief
* Returns number of contained vectors. * Returns number of contained vectors.
*/ */
inline int getNumVectors() const { inline int getNumVectors() const {
return vectors.getSize(); return vectors.getSize();
}; }
inline int getSize() const { inline int getSize() const {
return vectors.getSize(); return vectors.getSize();
}; }
/** \brief /** \brief
* Returns \ref feSpace. * Returns \ref feSpace.
*/ */
inline FiniteElemSpace *getFESpace(int i) const { inline FiniteElemSpace *getFESpace(int i) const {
return feSpace[i]; return feSpace[i];
}; }
/** \brief /** \brief
* Here the system vector is interpreted as one large vector. The given * Here the system vector is interpreted as one large vector. The given
...@@ -211,7 +219,7 @@ namespace AMDiS { ...@@ -211,7 +219,7 @@ namespace AMDiS {
} }
return (*(vectors[vectorIndex]))[localIndex]; return (*(vectors[vectorIndex]))[localIndex];
}; }
/** \brief /** \brief
* For const access. * For const access.
...@@ -225,7 +233,7 @@ namespace AMDiS { ...@@ -225,7 +233,7 @@ namespace AMDiS {
} }
return (*(vectors[vectorIndex]))[localIndex]; return (*(vectors[vectorIndex]))[localIndex];
}; }
/** \brief /** \brief
* Sets all entries in all vectors to value. * Sets all entries in all vectors to value.
...@@ -235,7 +243,7 @@ namespace AMDiS { ...@@ -235,7 +243,7 @@ namespace AMDiS {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
vectors[i]->set(value); vectors[i]->set(value);
} }
}; }
/** \brief /** \brief
* Sets all entries in all vectors to value. * Sets all entries in all vectors to value.
...@@ -246,7 +254,7 @@ namespace AMDiS { ...@@ -246,7 +254,7 @@ namespace AMDiS {
(*(vectors[i])) = value; (*(vectors[i])) = value;
} }
return *this; return *this;
}; }
/** \brief /** \brief
* Assignement operator. * Assignement operator.
...@@ -258,7 +266,7 @@ namespace AMDiS { ...@@ -258,7 +266,7 @@ namespace AMDiS {
(*(vectors[i])) = (*(rhs.getDOFVector(i))); (*(vectors[i])) = (*(rhs.getDOFVector(i)));
} }
return *this; return *this;
}; }
void serialize(std::ostream &out) { void serialize(std::ostream &out) {
int size = vectors.getSize(); int size = vectors.getSize();
...@@ -266,7 +274,7 @@ namespace AMDiS { ...@@ -266,7 +274,7 @@ namespace AMDiS {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
vectors[i]->serialize(out); vectors[i]->serialize(out);
} }
}; }
void deserialize(std::istream &in) { void deserialize(std::istream &in) {
int size, oldSize = vectors.getSize(); int size, oldSize = vectors.getSize();
...@@ -278,7 +286,7 @@ namespace AMDiS { ...@@ -278,7 +286,7 @@ namespace AMDiS {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
vectors[i]->deserialize(in); vectors[i]->deserialize(in);
} }
}; }
void copy(const SystemVector& rhs) { void copy(const SystemVector& rhs) {
int size = vectors.getSize(); int size = vectors.getSize();
...@@ -286,21 +294,27 @@ namespace AMDiS { ...@@ -286,21 +294,27 @@ namespace AMDiS {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
vectors[i]->copy(*(const_cast<SystemVector&>(rhs).getDOFVector(i))); vectors[i]->copy(*(const_cast<SystemVector&>(rhs).getDOFVector(i)));
} }
}; }
void interpol(std::vector<AbstractFunction<double, WorldVector<double> >*> *f) { void interpol(std::vector<AbstractFunction<double, WorldVector<double> >*> *f) {
int size = vectors.getSize(); int size = vectors.getSize();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
vectors[i]->interpol((*f)[i]); vectors[i]->interpol((*f)[i]);
} }
}; }
void interpol(SystemVector *v, double factor) {
for (int i = 0; i < v->getSize(); i++) {
vectors[i]->interpol(v->getDOFVector(i), factor);
}
}
void print() { void print() {
int size = vectors.getSize(); int size = vectors.getSize();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
vectors[i]->print(); vectors[i]->print();
} }
}; }
...@@ -330,7 +344,7 @@ namespace AMDiS { ...@@ -330,7 +344,7 @@ namespace AMDiS {
*(x.getDOFVector(i)) *= d; *(x.getDOFVector(i)) *= d;
} }
return x; return x;
}; }
/** \brief /** \brief
* scalar product * scalar product
...@@ -342,9 +356,9 @@ namespace AMDiS { ...@@ -342,9 +356,9 @@ namespace AMDiS {
int size = x.getNumVectors(); int size = x.getNumVectors();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
result += (*x.getDOFVector(i)) * (*y.getDOFVector(i)); result += (*x.getDOFVector(i)) * (*y.getDOFVector(i));
}; }
return result; return result;
}; }
/** \brief /** \brief
* addition of two system vectors * addition of two system vectors
...@@ -359,7 +373,7 @@ namespace AMDiS { ...@@ -359,7 +373,7 @@ namespace AMDiS {
(*(x.getDOFVector(i))) += (*(y.getDOFVector(i))); (*(x.getDOFVector(i))) += (*(y.getDOFVector(i)));
} }
return x; return x;
}; }
/** /**
* subtraction of two system vectors. * subtraction of two system vectors.
...@@ -374,7 +388,7 @@ namespace AMDiS { ...@@ -374,7 +388,7 @@ namespace AMDiS {
(*(x.getDOFVector(i))) -= (*(y.getDOFVector(i))); (*(x.getDOFVector(i))) -= (*(y.getDOFVector(i)));
} }
return x; return x;
}; }
/** \brief /** \brief
* multiplication with a scalar * multiplication with a scalar
...@@ -386,7 +400,7 @@ namespace AMDiS { ...@@ -386,7 +400,7 @@ namespace AMDiS {
(*(result.getDOFVector(i))) *= d; (*(result.getDOFVector(i))) *= d;
} }
return result; return result;
}; }
/** \brief /** \brief
* multiplication with a scalar * multiplication with a scalar
...@@ -398,7 +412,7 @@ namespace AMDiS { ...@@ -398,7 +412,7 @@ namespace AMDiS {
(*(result.getDOFVector(i))) *= d; (*(result.getDOFVector(i))) *= d;