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 #ifndef CELLBASEDSIMULATIONARCHIVER_HPP_
00030 #define CELLBASEDSIMULATIONARCHIVER_HPP_
00031
00032
00033 #include "CheckpointArchiveTypes.hpp"
00034
00035 #include <string>
00036 #include <iostream>
00037
00038 #include "OutputFileHandler.hpp"
00039 #include "SimulationTime.hpp"
00040 #include "ArchiveLocationInfo.hpp"
00041 #include "ArchiveOpener.hpp"
00042 #include "FileFinder.hpp"
00043
00049 template<unsigned DIM, class SIM>
00050 class CellBasedSimulationArchiver
00051 {
00052 public:
00053
00062 static SIM* Load(const std::string& rArchiveDirectory, const double& rTimeStamp);
00063
00076 static void Save(SIM* pSim);
00077 };
00078
00079
00080 template<unsigned DIM, class SIM>
00081 SIM* CellBasedSimulationArchiver<DIM, SIM>::Load(const std::string& rArchiveDirectory, const double& rTimeStamp)
00082 {
00091 std::ostringstream time_stamp;
00092 time_stamp << rTimeStamp;
00093 std::string archive_filename = "cell_population_sim_at_time_" + time_stamp.str() + ".arch";
00094 std::string mesh_filename = "mesh_" + time_stamp.str();
00095 FileFinder archive_dir(rArchiveDirectory + "/archive/", RelativeTo::ChasteTestOutput);
00096 ArchiveLocationInfo::SetMeshPathname(archive_dir, mesh_filename);
00097
00098
00099 ArchiveOpener<boost::archive::text_iarchive, std::ifstream> arch_opener(archive_dir, archive_filename);
00100 boost::archive::text_iarchive* p_arch = arch_opener.GetCommonArchive();
00101
00102
00103 SIM* p_sim;
00104 (*p_arch) >> p_sim;
00105 return p_sim;
00106 }
00107
00108 template<unsigned DIM, class SIM>
00109 void CellBasedSimulationArchiver<DIM, SIM>::Save(SIM* pSim)
00110 {
00111
00112 const SimulationTime* p_sim_time = SimulationTime::Instance();
00113 assert(p_sim_time->IsStartTimeSetUp());
00114 std::ostringstream time_stamp;
00115 time_stamp << p_sim_time->GetTime();
00116
00117
00118 FileFinder archive_dir(pSim->GetOutputDirectory() + "/archive/", RelativeTo::ChasteTestOutput);
00119 std::string archive_filename = "cell_population_sim_at_time_" + time_stamp.str() + ".arch";
00120 ArchiveLocationInfo::SetMeshFilename(std::string("mesh_") + time_stamp.str());
00121
00122
00123 ArchiveOpener<boost::archive::text_oarchive, std::ofstream> arch_opener(archive_dir, archive_filename);
00124 boost::archive::text_oarchive* p_arch = arch_opener.GetCommonArchive();
00125
00126
00127 (*p_arch) & pSim;
00128 }
00129
00130 #endif