#ifndef AMDIS_SOLUTION_DATA_STORAGE_H #define AMDIS_SOLUTION_DATA_STORAGE_H #include #include #include #include "DOFVector.h" #include "SystemVector.h" #include "Parameters.h" namespace AMDiS { template struct SolutionHelper { typedef FiniteElemSpace* type; }; template <> struct SolutionHelper { typedef std::vector type; }; class DataContainer { public: }; template class SolutionDataStorage { public: /** \brief * */ SolutionDataStorage(std::string name); /** \brief * */ ~SolutionDataStorage(); /** \brief * Set one fix FE Space. All solutions are defined only on the given FE Space. */ void setFixFESpace(typename SolutionHelper::type feSpace); /** \brief * */ void push(T *solution, double timestamp); /** \brief * */ void push(T *solution, typename SolutionHelper::type feSpace, double timestamp); /** \brief * */ bool pop(T **solution, double *timestep); /** \brief * */ bool pop(T **solution, typename SolutionHelper::type feSpace, double *timestep); /** \brief * Deletes all pointers and empties all internal vectors. */ void clear(); /** \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::type getFeSpace(int i = 0) { return feSpaces[i]; } bool isPoped() { return poped; } void addContainer(std::string name); void push(std::string name, WorldVector value); void pop(std::string name, WorldVector &value); void reset(std::string name); void clear(std::string name); protected: /** \brief * Deletes the fe space and all it content, i.e., also the dof admin, * mesh, etc. */ void deleteFeSpace(FiniteElemSpace* feSpace); /** \brief * Deletes a list of fe spaces. */ void deleteFeSpace(std::vector feSpaces) { for (int i = 0; i < static_cast(feSpaces.size()); i++) { deleteFeSpace(feSpaces[i]); } feSpaces.clear(); } int addMemoryUsage(FiniteElemSpace* feSpace) { memoryUsage += feSpace->getMesh()->calcMemoryUsage(); } int addMemoryUsage(std::vector feSpaces) { // Is used to determine equal meshes for different components. std::vector meshes; for (int i = 0; i < static_cast(feSpaces.size()); i++) { if (find(meshes.begin(), meshes.end(), feSpaces[i]->getMesh()) != meshes.end()) { memoryUsage += feSpaces[i]->getMesh()->calcMemoryUsage(); meshes.push_back(feSpaces[i]->getMesh()); } } } /** \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 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::type > feSpaces; /** \brief * Stores to every solutions the timestamp at which the solution was * created in the adaption loop. */ std::vector timestamps; /** \brief * Position of the latest valid solution. */ int lastPos; /** \brief * If true, the last operation on the data storage was pop. */ bool poped; /** \brief * Counts the memory usage of all solutions stored in memory. */ int memoryUsage; std::map > > containers; std::map containersPos; }; } #include "SolutionDataStorage.hh" #endif // AMDIS_SOLUTION_DATA_STORAGE_H