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(); 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 SolutionDataStorage::~SolutionDataStorage() { cleanup(); } template void SolutionDataStorage::setFixFESpace(typename SolutionHelper::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 void SolutionDataStorage::push(T *solution, double timestamp, bool cleanupSolution) { // 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); lastPos++; } template void SolutionDataStorage::push(T *solution, double timestamp, typename SolutionHelper::type feSpace, bool cleanupSolution, bool cleanupFeSpace) { push(solution, timestamp, cleanupSolution, cleanupFeSpace); // Store fe space only, if we do not have a fixed fe space. if (!fixedFESpace) { feSpaces.push_back(feSpace); cleanupFeSpaces.push_back(cleanupFeSpace); } } 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, double *timestep, typename SolutionHelper::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 void SolutionDataStorage::cleanup() { for (int i = 0; i < static_cast(cleanupSolutions.size()); i++) { if (cleanupSolutions[i]) { DELETE solutions[i]; } } for (int i = 0; i < static_cast(cleanupFeSpaces.size()); i++) { if (cleanupFeSpaces[i]) { deleteFeSpace(feSpaces[i]); } } cleanupSolutions.empty(); cleanupFeSpaces.empty(); solutions.empty(); feSpaces.empty(); timestamps.empty(); lastPos = -1; } }