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 "MeshArchiveInfo.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 = test_output_directory + rArchiveDirectory + "/archive/mesh_" + time_stamp.str();
00111 MeshArchiveInfo::meshPathname = mesh_filename;
00112
00113 return archive_filename;
00114 }
00115
00116 template<unsigned DIM, class SIM>
00117 SIM* TissueSimulationArchiver<DIM, SIM>::Load(const std::string& rArchiveDirectory, const double& rTimeStamp)
00118 {
00119 std::string archive_filename = TissueSimulationArchiver<DIM, SIM>::GetArchivePathname(rArchiveDirectory, rTimeStamp);
00120
00121
00122 std::ifstream ifs(archive_filename.c_str(), std::ios::binary);
00123 boost::archive::text_iarchive input_arch(ifs);
00124
00125
00126
00127 SimulationTime* p_simulation_time = SimulationTime::Instance();
00128 assert(p_simulation_time->IsStartTimeSetUp());
00129 input_arch & *p_simulation_time;
00130
00131 bool archive_wnt;
00132 input_arch & archive_wnt;
00133 if (archive_wnt)
00134 {
00135 WntConcentration* p_wnt = WntConcentration::Instance();
00136 input_arch & *p_wnt;
00137 }
00138
00139 bool archive_cellwise_data;
00140 input_arch & archive_cellwise_data;
00141 if (archive_cellwise_data)
00142 {
00143 CellwiseData<DIM>* p_cellwise_data = CellwiseData<DIM>::Instance();
00144 input_arch & *p_cellwise_data;
00145 }
00146
00147
00148 SIM* p_sim;
00149 input_arch >> p_sim;
00150
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 std::string archive_filename = handler.GetOutputDirectoryFullPath() + "tissue_sim_at_time_" + time_stamp.str() + ".arch";
00169 std::string mesh_filename = std::string("mesh_") + time_stamp.str();
00170
00171
00172
00173 pSim->rGetTissue().Update();
00174 if (pSim->rGetTissue().HasMesh())
00175 {
00176 pSim->rGetTissue().WriteMeshToFile(archive_directory, mesh_filename);
00177 }
00178
00179
00180 std::ofstream ofs(archive_filename.c_str());
00181 boost::archive::text_oarchive output_arch(ofs);
00182
00183
00184
00185 output_arch << *p_sim_time;
00186
00187
00188 bool archive_wnt = WntConcentration::Instance()->IsWntSetUp();
00189 output_arch & archive_wnt;
00190 if (archive_wnt)
00191 {
00192 WntConcentration* p_wnt = WntConcentration::Instance();
00193 output_arch & *p_wnt;
00194 }
00195
00196
00197 bool archive_cellwise_data = CellwiseData<DIM>::Instance()->IsSetUp();
00198 output_arch & archive_cellwise_data;
00199 if (archive_cellwise_data)
00200 {
00201 CellwiseData<DIM>* p_cellwise_data = CellwiseData<DIM>::Instance();
00202 output_arch & *p_cellwise_data;
00203 }
00204
00205
00206 output_arch & pSim;
00207 }
00208
00209 #endif