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 #include "CardiacSimulationArchiver.hpp"
00030 #include "CardiacSimulation.hpp"
00031
00032
00033 boost::shared_ptr<AbstractUntemplatedCardiacProblem> CardiacSimulation::GetSavedProblem()
00034 {
00035 return mSavedProblem;
00036 }
00037
00038 std::string CardiacSimulation::BoolToString(bool yesNo)
00039 {
00040 std::string result;
00041 if (yesNo)
00042 {
00043 result = "yes";
00044 }
00045 else
00046 {
00047 result = "no";
00048 }
00049 return result;
00050 }
00051
00052 void CardiacSimulation::CreateResumeXmlFile(const std::string& rOutputDirectory, const std::string& rArchiveDirectory)
00053 {
00054 OutputFileHandler handler(rOutputDirectory, false);
00055 if (PetscTools::AmMaster())
00056 {
00057 out_stream p_file = handler.OpenOutputFile("ResumeParameters.xml");
00058 (*p_file) << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
00059 (*p_file) << "<ChasteParameters xmlns='https://chaste.comlab.ox.ac.uk/nss/parameters/2_2' "
00060 << "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
00061 << "xsi:schemaLocation='https://chaste.comlab.ox.ac.uk/nss/parameters/2_2 ChasteParameters_2_2.xsd'>" << std::endl;
00062 (*p_file) << std::endl;
00063 (*p_file) << " <ResumeSimulation>" << std::endl;
00064 (*p_file) << " <ArchiveDirectory relative_to='chaste_test_output'>" << rArchiveDirectory << "</ArchiveDirectory>" << std::endl;
00065 (*p_file) << " <SpaceDimension>" << HeartConfig::Instance()->GetSpaceDimension() << "</SpaceDimension>" << std::endl;
00066 (*p_file) << " <SimulationDuration unit='ms'>0.0</SimulationDuration> <!-- Edit with new simulation duration. Please "
00067 << "note that the simulation does not restart at t=0 but at the time where the checkpoint was created.-->" << std::endl;
00068 (*p_file) << " <Domain>" << HeartConfig::Instance()->GetDomain() << "</Domain>" << std::endl;
00069 (*p_file) << " <CheckpointSimulation timestep='" << HeartConfig::Instance()->GetCheckpointTimestep()
00070 << "' unit='ms' max_checkpoints_on_disk='" << HeartConfig::Instance()->GetMaxCheckpointsOnDisk()
00071 << "'/> <!-- This is optional; if not given, the loaded simulation will NOT itself be checkpointed -->" << std::endl;
00072 (*p_file) << " <OutputVisualizer meshalyzer='" << BoolToString(HeartConfig::Instance()->GetVisualizeWithMeshalyzer())
00073 << "' vtk='" << BoolToString(HeartConfig::Instance()->GetVisualizeWithVtk())
00074 << "' parallel_vtk='" << BoolToString(HeartConfig::Instance()->GetVisualizeWithParallelVtk())
00075 << "' cmgui='" << BoolToString(HeartConfig::Instance()->GetVisualizeWithCmgui()) << "'/>" << std::endl;
00076 (*p_file) << " </ResumeSimulation>" << std::endl;
00077 (*p_file) << std::endl;
00078 (*p_file) << " <!-- These elements must exist, but their contents are ignored -->" << std::endl;
00079 (*p_file) << " <Physiological/>" << std::endl;
00080 (*p_file) << " <Numerical/>" << std::endl;
00081 (*p_file) << "</ChasteParameters>" << std::endl;
00082 p_file->close();
00083 }
00084 HeartConfig::Instance()->CopySchema(handler.GetOutputDirectoryFullPath());
00085 }
00086
00087 CardiacSimulation::CardiacSimulation(std::string parameterFileName,
00088 bool writeProvenanceInfo,
00089 bool saveProblemInstance)
00090 : mSaveProblemInstance(saveProblemInstance)
00091 {
00092
00093 if (parameterFileName == "")
00094 {
00095 EXCEPTION("No XML file name given");
00096 }
00097 ReadParametersFromFile(parameterFileName);
00098 Run();
00099 HeartEventHandler::Headings();
00100 HeartEventHandler::Report();
00101 if (writeProvenanceInfo)
00102 {
00103 ExecutableSupport::SetOutputDirectory(HeartConfig::Instance()->GetOutputDirectory());
00104 ExecutableSupport::WriteProvenanceInfoFile();
00105 ExecutableSupport::WriteMachineInfoFile("machine_info");
00106 }
00107 }
00108
00109 void CardiacSimulation::ReadParametersFromFile(std::string parameterFileName)
00110 {
00111
00112 HeartConfig::Reset();
00113 try
00114 {
00115
00116 HeartConfig::Instance()->SetUseFixedSchemaLocation(true);
00117 HeartConfig::Instance()->SetParametersFile(parameterFileName);
00118 }
00119 catch (Exception& e)
00120 {
00121 if (e.CheckShortMessageContains("Missing file parsing configuration") == "")
00122 {
00123
00124 HeartConfig::Reset();
00125 HeartConfig::Instance()->SetUseFixedSchemaLocation(false);
00126 HeartConfig::Instance()->SetParametersFile(parameterFileName);
00127 }
00128 else
00129 {
00130 throw e;
00131 }
00132 }
00133 }
00134
00135
00136 #define DOMAIN_CASE(VALUE, CLASS, DIM) \
00137 case VALUE: \
00138 { \
00139 CreateAndRun<CLASS<DIM>, DIM>(); \
00140 break; \
00141 }
00142
00143 #define DOMAIN_SWITCH(DIM) \
00144 switch (HeartConfig::Instance()->GetDomain()) \
00145 { \
00146 DOMAIN_CASE(cp::domain_type::Mono, MonodomainProblem, DIM) \
00147 DOMAIN_CASE(cp::domain_type::Bi, BidomainProblem, DIM) \
00148 DOMAIN_CASE(cp::domain_type::BiWithBath, BidomainWithBathProblem, DIM) \
00149 default: \
00150 NEVER_REACHED; \
00151 } \
00152 break
00153
00154
00155
00156 void CardiacSimulation::Run()
00157 {
00158 switch (HeartConfig::Instance()->GetSpaceDimension())
00159 {
00160 case 3:
00161 {
00162 DOMAIN_SWITCH(3);
00163 }
00164 case 2:
00165 {
00166 DOMAIN_SWITCH(2);
00167 }
00168 case 1:
00169 {
00170 DOMAIN_SWITCH(1);
00171 }
00172 default:
00173
00174 EXCEPTION("Space dimension not supported: should be 1, 2 or 3");
00175 }
00176 }
00177
00178
00179 #undef DOMAIN_SWITCH
00180 #undef DOMAIN_CASE
00181