| 1687 | } |
| 1688 | |
| 1689 | void SPH::SimulatorBase::saveState(const std::string& stateFile) |
| 1690 | { |
| 1691 | std::string stateFilePath; |
| 1692 | std::string exportFileName; |
| 1693 | const Real time = TimeManager::getCurrent()->getTime(); |
| 1694 | const std::string timeStr = StringTools::real2String(time); |
| 1695 | if (stateFile == "") |
| 1696 | { |
| 1697 | stateFilePath = FileSystem::normalizePath(m_outputPath + "/state"); |
| 1698 | exportFileName = FileSystem::normalizePath(stateFilePath + "/state_" + timeStr); |
| 1699 | } |
| 1700 | else |
| 1701 | { |
| 1702 | stateFilePath = FileSystem::getFilePath(stateFile); |
| 1703 | exportFileName = FileSystem::normalizePath(stateFilePath + "/" + FileSystem::getFileName(stateFile)); |
| 1704 | } |
| 1705 | FileSystem::makeDirs(stateFilePath); |
| 1706 | |
| 1707 | const std::string& sceneFile = SceneConfiguration::getCurrent()->getSceneFile(); |
| 1708 | string md5Str = FileSystem::getFileMD5(sceneFile); |
| 1709 | |
| 1710 | Simulation *sim = Simulation::getCurrent(); |
| 1711 | |
| 1712 | // Save additional data |
| 1713 | BinaryFileWriter binWriter; |
| 1714 | binWriter.openFile(exportFileName + ".bin"); |
| 1715 | binWriter.write(md5Str); |
| 1716 | |
| 1717 | binWriter.write(m_nextFrameTime); |
| 1718 | binWriter.write(m_nextFrameTimeState); |
| 1719 | binWriter.write(m_frameCounter); |
| 1720 | binWriter.write(m_isFirstFrame); |
| 1721 | binWriter.write(m_isFirstFrameVTK); |
| 1722 | |
| 1723 | writeParameterState(binWriter); |
| 1724 | TimeManager::getCurrent()->saveState(binWriter); |
| 1725 | Simulation::getCurrent()->saveState(binWriter); |
| 1726 | |
| 1727 | // fluid models |
| 1728 | for (unsigned int i = 0; i < sim->numberOfFluidModels(); i++) |
| 1729 | { |
| 1730 | FluidModel *model = sim->getFluidModel(i); |
| 1731 | std::string fileName = "particle"; |
| 1732 | fileName = fileName + "_" + model->getId(); // +"_" + std::to_string(m_frameCounter); |
| 1733 | |
| 1734 | // Save particle data |
| 1735 | std::string expFileName = FileSystem::normalizePath(exportFileName + "_" + fileName); |
| 1736 | writeFluidParticlesState(expFileName + ".bgeo", model); |
| 1737 | } |
| 1738 | |
| 1739 | // boundary models |
| 1740 | if (m_firstState) |
| 1741 | { |
| 1742 | for (unsigned int i = 0; i < sim->numberOfBoundaryModels(); i++) |
| 1743 | { |
| 1744 | BoundaryModel *model = sim->getBoundaryModel(i); |
| 1745 | std::string fileName = "boundary"; |
| 1746 | fileName = fileName + "_" + to_string(i); // +"_" + std::to_string(m_frameCounter); |
no test coverage detected