TissueSimulationArchiver.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 TISSUESIMULATIONARCHIVER_HPP_
00030 #define TISSUESIMULATIONARCHIVER_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 "WntConcentration.hpp"
00041 #include "CellwiseData.hpp"
00042 #include "ArchiveLocationInfo.hpp"
00043 #include "ArchiveOpener.hpp"
00044
00050 template<unsigned DIM, class SIM>
00051 class TissueSimulationArchiver
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* TissueSimulationArchiver<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 = "tissue_sim_at_time_" + time_stamp.str() + ".arch";
00095 std::string mesh_filename = "mesh_" + time_stamp.str();
00096 ArchiveLocationInfo::SetMeshPathname(OutputFileHandler::GetChasteTestOutputDirectory()
00097 + rArchiveDirectory + "/archive/", mesh_filename);
00098
00099
00100 ArchiveOpener<boost::archive::text_iarchive, std::ifstream> arch_opener(rArchiveDirectory + "/archive/", 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_wnt;
00111 (*p_arch) & archive_wnt;
00112 if (archive_wnt)
00113 {
00114 WntConcentration<DIM>* p_wnt = WntConcentration<DIM>::Instance();
00115 (*p_arch) & *p_wnt;
00116 }
00117
00118
00119 bool archive_cellwise_data;
00120 (*p_arch) & archive_cellwise_data;
00121 if (archive_cellwise_data)
00122 {
00123 CellwiseData<DIM>* p_cellwise_data = CellwiseData<DIM>::Instance();
00124 (*p_arch) & *p_cellwise_data;
00125 }
00126
00127
00128 SIM* p_sim;
00129 (*p_arch) >> p_sim;
00130 return p_sim;
00131 }
00132
00133 template<unsigned DIM, class SIM>
00134 void TissueSimulationArchiver<DIM, SIM>::Save(SIM* pSim)
00135 {
00136
00137 const SimulationTime* p_sim_time = SimulationTime::Instance();
00138 assert(p_sim_time->IsStartTimeSetUp());
00139 std::ostringstream time_stamp;
00140 time_stamp << p_sim_time->GetTime();
00141
00142
00143 std::string archive_directory = pSim->GetOutputDirectory() + "/archive/";
00144 std::string archive_filename = "tissue_sim_at_time_" + time_stamp.str() + ".arch";
00145 ArchiveLocationInfo::SetMeshFilename(std::string("mesh_") + time_stamp.str());
00146
00147
00148 ArchiveOpener<boost::archive::text_oarchive, std::ofstream> arch_opener(archive_directory, archive_filename);
00149 boost::archive::text_oarchive* p_arch = arch_opener.GetCommonArchive();
00150
00151
00152
00153 (*p_arch) << *p_sim_time;
00154
00155
00156 bool archive_wnt = WntConcentration<DIM>::Instance()->IsWntSetUp();
00157 (*p_arch) & archive_wnt;
00158 if (archive_wnt)
00159 {
00160 WntConcentration<DIM>* p_wnt = WntConcentration<DIM>::Instance();
00161 (*p_arch) & *p_wnt;
00162 }
00163
00164
00165 bool archive_cellwise_data = CellwiseData<DIM>::Instance()->IsSetUp();
00166 (*p_arch) & archive_cellwise_data;
00167 if (archive_cellwise_data)
00168 {
00169 CellwiseData<DIM>* p_cellwise_data = CellwiseData<DIM>::Instance();
00170 (*p_arch) & *p_cellwise_data;
00171 }
00172
00173
00174 (*p_arch) & pSim;
00175 }
00176
00177 #endif