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 #include <climits>
00033
00034
00035 #include <boost/archive/text_oarchive.hpp>
00036 #include <boost/archive/text_iarchive.hpp>
00037
00038 #include <string>
00039 #include <iostream>
00040
00041 #include "OutputFileHandler.hpp"
00042 #include "SimulationTime.hpp"
00043 #include "WntConcentration.hpp"
00044 #include "CellwiseData.hpp"
00045 #include "ArchiveLocationInfo.hpp"
00046
00052 template<unsigned DIM, class SIM>
00053 class TissueSimulationArchiver
00054 {
00055 public:
00056
00065 static SIM* Load(const std::string& rArchiveDirectory, const double& rTimeStamp);
00066
00079 static void Save(SIM* pSim);
00080
00081 private:
00082
00096 static std::string GetArchivePathname(const std::string& rArchiveDirectory, const double& rTimeStamp);
00097 };
00098
00099
00100 template<unsigned DIM, class SIM>
00101 std::string TissueSimulationArchiver<DIM, SIM>::GetArchivePathname(const std::string& rArchiveDirectory, const double& rTimeStamp)
00102 {
00103
00104 std::ostringstream time_stamp;
00105 time_stamp << rTimeStamp;
00106
00107 std::string test_output_directory = OutputFileHandler::GetChasteTestOutputDirectory();
00108
00109 std::string archive_filename = test_output_directory + rArchiveDirectory + "/archive/tissue_sim_at_time_"+time_stamp.str() +".arch";
00110 std::string mesh_filename = "mesh_" + time_stamp.str();
00111 ArchiveLocationInfo::SetMeshPathname(test_output_directory + rArchiveDirectory + "/archive/", mesh_filename);
00112 return archive_filename;
00113 }
00114
00115 template<unsigned DIM, class SIM>
00116 SIM* TissueSimulationArchiver<DIM, SIM>::Load(const std::string& rArchiveDirectory, const double& rTimeStamp)
00117 {
00118 std::string archive_filename = TissueSimulationArchiver<DIM, SIM>::GetArchivePathname(rArchiveDirectory, rTimeStamp);
00119
00120
00121 std::ifstream ifs(archive_filename.c_str(), std::ios::binary);
00122 boost::archive::text_iarchive input_arch(ifs);
00123
00124
00125
00126 SimulationTime *p_simulation_time = SimulationTime::Instance();
00127 assert(p_simulation_time->IsStartTimeSetUp());
00128 input_arch & *p_simulation_time;
00129
00130
00131 bool archive_wnt;
00132 input_arch & archive_wnt;
00133 if (archive_wnt)
00134 {
00135 WntConcentration<DIM> *p_wnt = WntConcentration<DIM>::Instance();
00136 input_arch & *p_wnt;
00137 }
00138
00139
00140 bool archive_cellwise_data;
00141 input_arch & archive_cellwise_data;
00142 if (archive_cellwise_data)
00143 {
00144 CellwiseData<DIM> *p_cellwise_data = CellwiseData<DIM>::Instance();
00145 input_arch & *p_cellwise_data;
00146 }
00147
00148
00149 SIM *p_sim;
00150 input_arch >> p_sim;
00151 return p_sim;
00152 }
00153
00154 template<unsigned DIM, class SIM>
00155 void TissueSimulationArchiver<DIM, SIM>::Save(SIM* pSim)
00156 {
00157
00158 const SimulationTime *p_sim_time = SimulationTime::Instance();
00159 assert(p_sim_time->IsStartTimeSetUp());
00160 std::ostringstream time_stamp;
00161 time_stamp << p_sim_time->GetTime();
00162
00163
00164
00165
00166 std::string archive_directory = pSim->GetOutputDirectory() + "/archive/";
00167 OutputFileHandler handler(archive_directory, false);
00168 ArchiveLocationInfo::SetArchiveDirectory(handler.GetOutputDirectoryFullPath());
00169 std::string archive_filename = handler.GetOutputDirectoryFullPath() + "tissue_sim_at_time_" + time_stamp.str() + ".arch";
00170 ArchiveLocationInfo::SetMeshFilename(std::string("mesh_") + time_stamp.str());
00171
00172
00173 std::ofstream ofs(archive_filename.c_str());
00174 boost::archive::text_oarchive output_arch(ofs);
00175
00176
00177
00178 output_arch << *p_sim_time;
00179
00180
00181 bool archive_wnt = WntConcentration<DIM>::Instance()->IsWntSetUp();
00182 output_arch & archive_wnt;
00183 if (archive_wnt)
00184 {
00185 WntConcentration<DIM> *p_wnt = WntConcentration<DIM>::Instance();
00186 output_arch & *p_wnt;
00187 }
00188
00189
00190 bool archive_cellwise_data = CellwiseData<DIM>::Instance()->IsSetUp();
00191 output_arch & archive_cellwise_data;
00192 if (archive_cellwise_data)
00193 {
00194 CellwiseData<DIM> *p_cellwise_data = CellwiseData<DIM>::Instance();
00195 output_arch & *p_cellwise_data;
00196 }
00197
00198
00199 output_arch & pSim;
00200 }
00201
00202 #endif