namespace AMDiS { template SolutionDataStorage::SolutionDataStorage(std::string name) : maxMemoryUsage(100), useDisk(true), writeDirectory(""), fixedFESpace(false), lastPos(-1), poped(false) { solutions.empty(); feSpaces.empty(); timestamps.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 SolutionDataStorage::~SolutionDataStorage() { clear(); } template void SolutionDataStorage::setFixFESpace(typename SolutionHelper::type feSpace) { FUNCNAME("SolutionDataStorage::setFixFESpace()"); TEST_EXIT(solutions.size() == 0)("Cannot set FE Space, if solutions already stored!\n"); fixedFESpace = true; feSpaces.push_back(feSpace); addMemoryUsage(feSpace); } template void SolutionDataStorage::push(T *solution, double timestamp) { // If pop was the last operation, cleanup and reset the data storage. if (poped) { clear(); poped = false; } solutions.push_back(solution); timestamps.push_back(timestamp); std::cout << "STACK SIZE = " << solutions.size() << std::endl; lastPos++; // memoryUsage += solution->calcMemoryUsage(); } template void SolutionDataStorage::push(T *solution, typename SolutionHelper::type feSpace, double timestamp) { FUNCNAME("SolutionDataStorage::push()"); push(solution, timestamp); // Store fe space only, if we do not have a fixed fe space. TEST_EXIT(!fixedFESpace)("push wit fe space not possible!\n"); if (!fixedFESpace) { feSpaces.push_back(feSpace); } } template bool SolutionDataStorage::pop(T **solution, double *timestamp) { if (lastPos < 0) { return false; } *solution = solutions[lastPos]; *timestamp = timestamps[lastPos]; lastPos--; poped = true; return true; } template bool SolutionDataStorage::pop(T **solution, typename SolutionHelper::type feSpace, double *timestep) { 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 void SolutionDataStorage::clear() { for (int i = 1; i < static_cast(solutions.size()); i++) { DELETE solutions[i]; } if (!fixedFESpace) { for (int i = 0; i < static_cast(feSpaces.size()); i++) { deleteFeSpace(feSpaces[i]); } } solutions.clear(); feSpaces.clear(); timestamps.clear(); lastPos = -1; } template void SolutionDataStorage::deleteFeSpace(FiniteElemSpace *feSpace) { if (feSpace) { DELETE feSpace->getMesh(); DELETE feSpace; } } }