Commit 929d4333 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* First version of SolutionDataStorage

parent 7bc60867
......@@ -230,6 +230,7 @@ $(SOURCE_DIR)/PeriodicInfo.h \
$(SOURCE_DIR)/OpenMP.h \
$(SOURCE_DIR)/ScalableQuadrature.h $(SOURCE_DIR)/ScalableQuadrature.cc \
$(SOURCE_DIR)/SubElInfo.h $(SOURCE_DIR)/SubElInfo.cc \
$(SOURCE_DIR)/SolutionDataStorage.h $(SOURCE_DIR)/SolutionDataStorage.hh \
$(SOURCE_DIR)/parareal/ProblemBase.h \
$(SOURCE_DIR)/parareal/AdaptParaReal.h $(SOURCE_DIR)/parareal/AdaptParaReal.cc
......
......@@ -248,7 +248,8 @@ am__libamdis_la_SOURCES_DIST = $(PARALLEL_DIR)/ConditionalEstimator.h \
$(SOURCE_DIR)/VertexInfo.h $(SOURCE_DIR)/PeriodicInfo.h \
$(SOURCE_DIR)/OpenMP.h $(SOURCE_DIR)/ScalableQuadrature.h \
$(SOURCE_DIR)/ScalableQuadrature.cc $(SOURCE_DIR)/SubElInfo.h \
$(SOURCE_DIR)/SubElInfo.cc \
$(SOURCE_DIR)/SubElInfo.cc $(SOURCE_DIR)/SolutionDataStorage.h \
$(SOURCE_DIR)/SolutionDataStorage.hh \
$(SOURCE_DIR)/parareal/ProblemBase.h \
$(SOURCE_DIR)/parareal/AdaptParaReal.h \
$(SOURCE_DIR)/parareal/AdaptParaReal.cc
......@@ -672,6 +673,7 @@ $(SOURCE_DIR)/PeriodicInfo.h \
$(SOURCE_DIR)/OpenMP.h \
$(SOURCE_DIR)/ScalableQuadrature.h $(SOURCE_DIR)/ScalableQuadrature.cc \
$(SOURCE_DIR)/SubElInfo.h $(SOURCE_DIR)/SubElInfo.cc \
$(SOURCE_DIR)/SolutionDataStorage.h $(SOURCE_DIR)/SolutionDataStorage.hh \
$(SOURCE_DIR)/parareal/ProblemBase.h \
$(SOURCE_DIR)/parareal/AdaptParaReal.h $(SOURCE_DIR)/parareal/AdaptParaReal.cc
......
......@@ -85,6 +85,7 @@
#include "RefinementManager2d.h"
#include "RefinementManager3d.h"
#include "RobinBC.h"
#include "SolutionDataStorage.h"
#include "SurfaceOperator.h"
#include "SurfaceQuadrature.h"
#include "SystemVector.h"
......
#ifndef AMDIS_SOLUTION_DATA_STORAGE_H
#define AMDIS_SOLUTION_DATA_STORAGE_H
#include <iostream>
#include <vector>
#include "DOFVector.h"
#include "SystemVector.h"
#include "Parameters.h"
namespace AMDiS {
template<typename T>
struct SolutionHelper
{
typedef FiniteElemSpace* type;
};
template <>
struct SolutionHelper<SystemVector>
{
typedef std::vector<FiniteElemSpace*> type;
};
template<typename T>
class SolutionDataStorage
{
public:
SolutionDataStorage(std::string name);
~SolutionDataStorage();
/** \brief
* Set one fix FE Space. All solutions are defined only on the given FE Space.
*/
void setFixFESpace(typename SolutionHelper<T>::type feSpace,
bool cleanupFeSpace = false);
void push(T *solution,
double timestamp,
FiniteElemSpace *feSpace = NULL,
bool cleanupSolution = true,
bool cleanupFeSpace = true);
bool pop(T *solution,
double *timestep,
FiniteElemSpace *feSpace = NULL);
protected:
void cleanup();
/** \brief
* Number of MBytes of memory that can be used for solution storage.
*/
int maxMemoryUsage;
/** \brief
* If true, it is allowed to write solutions also to disk.
*/
bool useDisk;
/** \brief
* Directory, where solutions can be written temporarly.
*/
std::string writeDirectory;
/** \brief
* If true, all solutions are defined only on one FE Space.
*/
bool fixedFESpace;
/** \brief
* Here, all the solutions (i.e. either DOFVectors or SystemVectors)
* are stored.
*/
std::vector<T> solutions;
/** \brief
* Stores to every solution its FE Space. If \ref fixedFESpace is set
* to true, only one entry exists. This is than the FE Space for all
* solutions.
*/
std::vector< typename SolutionHelper<T>::type > feSpaces;
/** \brief
* Stores to every solutions the timestamp at which the solution was
* created in the adaption loop.
*/
std::vector<double> timestamps;
/** \brief
* Stores to each solution, if the data storage is allowed to delete
* the solution by itself.
*/
std::vector<bool> cleanupSolutions;
/** \brief
* Stores to each fe space, if the data storage is allowed to delete
* the fe space by itself.
*/
std::vector<bool> cleanupFeSpaces;
/** \brief
* Position of the latest valid solution.
*/
int lastPos;
/** \brief
* If true, the last operation on the data storage was pop.
*/
bool poped;
};
}
#include "SolutionDataStorage.hh"
#endif // AMDIS_SOLUTION_DATA_STORAGE_H
namespace AMDiS {
template<typename T>
SolutionDataStorage<T>::SolutionDataStorage(std::string name)
: maxMemoryUsage(100),
useDisk(true),
writeDirectory(""),
fixedFESpace(false),
lastPos(-1),
poped(false)
{
solutions.empty();
feSpaces.empty();
timestamps.empty();
cleanupSolutions.empty();
cleanupFeSpaces.empty();
int tmp = 0;
GET_PARAMETER(0, name + "->memory usage", "%d", &maxMemoryUsage);
GET_PARAMETER(0, name + "->use disk", "%d", &tmp);
useDisk = (tmp == 0) ? false : true;
GET_PARAMETER(0, name + "->directory", &writeDirectory);
}
template<typename T>
SolutionDataStorage<T>::~SolutionDataStorage()
{
cleanup();
}
template<typename T>
void SolutionDataStorage<T>::setFixFESpace(typename SolutionHelper<T>::type feSpace,
bool cleanupFeSpace)
{
FUNCNAME("SolutionDataStorage::setFixFESpace()");
TEST_EXIT(solutions.size() == 0)("Cannot set FE Space, if solutions already stored!\n");
fixedFESpace = true;
feSpaces.push_back(feSpace);
cleanupFeSpaces.push_back(cleanupFeSpace);
}
template<typename T>
void SolutionDataStorage<T>::push(T *solution,
double timestamp,
FiniteElemSpace *feSpace,
bool cleanupSolution,
bool cleanupFeSpace)
{
// If pop was the last operation, cleanup and reset the data storage.
if (poped) {
cleanup();
poped = false;
}
solutions.push_back(solution);
timestamps.push_back(timestamp);
cleanupSolutions.push_back(cleanupSolution);
// Store fe space only, if we do not have a fixed fe space.
if (!fixedFESpace) {
feSpaces.push_back(feSpace);
cleanupFeSpaces.push_back(cleanupFeSpace);
}
lastPos++;
}
template<typename T>
bool SolutionDataStorage<T>::pop(T *solution,
double *timestamp,
FiniteElemSpace *feSpace)
{
if (lastPos < 0) {
return false;
}
solution = solutions[lastPos];
*timestamp = timestamps[lastPos];
if (!fixedFESpace) {
feSpace = feSpaces[lastPos];
}
lastPos--;
poped = true;
return true;
}
template<typename T>
void SolutionDataStorage<T>::cleanup()
{
for (int i = 0; i < static_cast<int>(cleanupSolutions.size()); i++) {
if (cleanupSolutions[i]) {
DELETE solutions[i];
}
}
for (int i = 0; i < static_cast<int>(cleanupFeSpaces.size()); i++) {
if (cleanupFeSpaces[i]) {
DELETE feSpaces[i];
}
}
cleanupSolutions.empty();
cleanupFeSpaces.empty();
solutions.empty();
feSpaces.empty();
timestamps.empty();
lastPos = -1;
}
}
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