CellBasedSimulationArchiver.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef CELLBASEDSIMULATIONARCHIVER_HPP_
00037 #define CELLBASEDSIMULATIONARCHIVER_HPP_
00038
00039
00040 #include "CheckpointArchiveTypes.hpp"
00041
00042 #include <string>
00043 #include <iostream>
00044
00045 #include "OutputFileHandler.hpp"
00046 #include "SimulationTime.hpp"
00047 #include "ArchiveLocationInfo.hpp"
00048 #include "ArchiveOpener.hpp"
00049 #include "FileFinder.hpp"
00050
00056 template<unsigned ELEMENT_DIM, class SIM, unsigned SPACE_DIM=ELEMENT_DIM>
00057 class CellBasedSimulationArchiver
00058 {
00059 public:
00060
00070 static SIM* Load(const std::string& rArchiveDirectory, const double& rTimeStamp);
00071
00084 static void Save(SIM* pSim);
00085 };
00086
00087 template<unsigned ELEMENT_DIM, class SIM, unsigned SPACE_DIM>
00088 SIM* CellBasedSimulationArchiver<ELEMENT_DIM, SIM, SPACE_DIM>::Load(const std::string& rArchiveDirectory, const double& rTimeStamp)
00089 {
00098 std::ostringstream time_stamp;
00099 time_stamp << rTimeStamp;
00100 std::string archive_filename = "cell_population_sim_at_time_" + time_stamp.str() + ".arch";
00101 std::string mesh_filename = "mesh_" + time_stamp.str();
00102 FileFinder archive_dir(rArchiveDirectory + "/archive/", RelativeTo::ChasteTestOutput);
00103 ArchiveLocationInfo::SetMeshPathname(archive_dir, mesh_filename);
00104
00105
00106 ArchiveOpener<boost::archive::text_iarchive, std::ifstream> arch_opener(archive_dir, archive_filename);
00107 boost::archive::text_iarchive* p_arch = arch_opener.GetCommonArchive();
00108
00109
00110 SIM* p_sim;
00111 (*p_arch) >> p_sim;
00112 return p_sim;
00113 }
00114
00115 template<unsigned ELEMENT_DIM, class SIM, unsigned SPACE_DIM>
00116 void CellBasedSimulationArchiver<ELEMENT_DIM, SIM, SPACE_DIM>::Save(SIM* pSim)
00117 {
00118
00119 const SimulationTime* p_sim_time = SimulationTime::Instance();
00120 assert(p_sim_time->IsStartTimeSetUp());
00121 std::ostringstream time_stamp;
00122 time_stamp << p_sim_time->GetTime();
00123
00124
00125 FileFinder archive_dir(pSim->GetOutputDirectory() + "/archive/", RelativeTo::ChasteTestOutput);
00126 std::string archive_filename = "cell_population_sim_at_time_" + time_stamp.str() + ".arch";
00127 ArchiveLocationInfo::SetMeshFilename(std::string("mesh_") + time_stamp.str());
00128
00129
00130 ArchiveOpener<boost::archive::text_oarchive, std::ofstream> arch_opener(archive_dir, archive_filename);
00131 boost::archive::text_oarchive* p_arch = arch_opener.GetCommonArchive();
00132
00133
00134 (*p_arch) & pSim;
00135 }
00136
00137 #endif