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