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 "CellwiseData.hpp"
00041 #include "ArchiveLocationInfo.hpp"
00042 #include "ArchiveOpener.hpp"
00043 #include "FileFinder.hpp"
00044
00050 template<unsigned DIM, class SIM>
00051 class CellBasedSimulationArchiver
00052 {
00053 public:
00054
00063 static SIM* Load(const std::string& rArchiveDirectory, const double& rTimeStamp);
00064
00077 static void Save(SIM* pSim);
00078 };
00079
00080
00081 template<unsigned DIM, class SIM>
00082 SIM* CellBasedSimulationArchiver<DIM, SIM>::Load(const std::string& rArchiveDirectory, const double& rTimeStamp)
00083 {
00092 std::ostringstream time_stamp;
00093 time_stamp << rTimeStamp;
00094 std::string archive_filename = "cell_population_sim_at_time_" + time_stamp.str() + ".arch";
00095 std::string mesh_filename = "mesh_" + time_stamp.str();
00096 FileFinder archive_dir(rArchiveDirectory + "/archive/", RelativeTo::ChasteTestOutput);
00097 ArchiveLocationInfo::SetMeshPathname(archive_dir, mesh_filename);
00098
00099
00100 ArchiveOpener<boost::archive::text_iarchive, std::ifstream> arch_opener(archive_dir, archive_filename);
00101 boost::archive::text_iarchive* p_arch = arch_opener.GetCommonArchive();
00102
00103
00104
00105 SimulationTime* p_simulation_time = SimulationTime::Instance();
00106 assert(p_simulation_time->IsStartTimeSetUp());
00107 (*p_arch) & *p_simulation_time;
00108
00109
00110 bool archive_cellwise_data;
00111 (*p_arch) & archive_cellwise_data;
00112 if (archive_cellwise_data)
00113 {
00114 CellwiseData<DIM>* p_cellwise_data = CellwiseData<DIM>::Instance();
00115 (*p_arch) & *p_cellwise_data;
00116 }
00117
00118
00119 SIM* p_sim;
00120 (*p_arch) >> p_sim;
00121 return p_sim;
00122 }
00123
00124 template<unsigned DIM, class SIM>
00125 void CellBasedSimulationArchiver<DIM, SIM>::Save(SIM* pSim)
00126 {
00127
00128 const SimulationTime* p_sim_time = SimulationTime::Instance();
00129 assert(p_sim_time->IsStartTimeSetUp());
00130 std::ostringstream time_stamp;
00131 time_stamp << p_sim_time->GetTime();
00132
00133
00134 FileFinder archive_dir(pSim->GetOutputDirectory() + "/archive/", RelativeTo::ChasteTestOutput);
00135 std::string archive_filename = "cell_population_sim_at_time_" + time_stamp.str() + ".arch";
00136 ArchiveLocationInfo::SetMeshFilename(std::string("mesh_") + time_stamp.str());
00137
00138
00139 ArchiveOpener<boost::archive::text_oarchive, std::ofstream> arch_opener(archive_dir, archive_filename);
00140 boost::archive::text_oarchive* p_arch = arch_opener.GetCommonArchive();
00141
00142
00143
00144 (*p_arch) << *p_sim_time;
00145
00146
00147 bool archive_cellwise_data = CellwiseData<DIM>::Instance()->IsSetUp();
00148 (*p_arch) & archive_cellwise_data;
00149 if (archive_cellwise_data)
00150 {
00151 CellwiseData<DIM>* p_cellwise_data = CellwiseData<DIM>::Instance();
00152 (*p_arch) & *p_cellwise_data;
00153 }
00154
00155
00156 (*p_arch) & pSim;
00157 }
00158
00159 #endif