CellMLLoader.cpp
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
00030
00031
00032
00033
00034
00035
00036 #include "CellMLLoader.hpp"
00037
00038 #include <algorithm>
00039 #include "EulerIvpOdeSolver.hpp"
00040
00041 CellMLLoader::CellMLLoader(const FileFinder& rCellMLFile, const OutputFileHandler& rOutputFileHandler, const std::vector<std::string>& rOptions)
00042 : mCellMLFile(rCellMLFile),
00043 mOutputFileHandler(rOutputFileHandler),
00044 mOptions(rOptions),
00045 mpConverter(new CellMLToSharedLibraryConverter(true)),
00046 mUseCvode(boost::logic::indeterminate)
00047 {
00048 }
00049
00050 AbstractCardiacCellInterface* CellMLLoader::LoadCellMLFile(bool makeCvodeCell)
00051 {
00052 std::string model_name = mCellMLFile.GetLeafNameNoExtension();
00053 FileFinder copied_model = mOutputFileHandler.FindFile(mCellMLFile.GetLeafName());
00054
00055
00056 if (boost::logic::indeterminate(mUseCvode))
00057 {
00058 mUseCvode = makeCvodeCell;
00059
00060
00061 std::vector<std::string>::iterator it = std::find(mOptions.begin(), mOptions.end(), "--cvode");
00062 if (!makeCvodeCell && it != mOptions.end())
00063 {
00064 mOptions.erase(it);
00065 }
00066 if (makeCvodeCell && it == mOptions.end())
00067 {
00068 mOptions.push_back("--cvode");
00069 }
00070
00071
00072 mpConverter->CreateOptionsFile(mOutputFileHandler, model_name, mOptions);
00073 mOutputFileHandler.CopyFileTo(mCellMLFile);
00074
00075 FileFinder out_file(model_name + ".out", mCellMLFile);
00076 if (out_file.Exists())
00077 {
00078 mOutputFileHandler.CopyFileTo(out_file);
00079 }
00080 }
00081
00082 else if (makeCvodeCell != mUseCvode)
00083 {
00084 EXCEPTION("You cannot call both LoadCvodeCell and LoadCardiacCell on the same CellMLLoader.");
00085 }
00086
00087
00088 DynamicCellModelLoaderPtr p_loader = mpConverter->Convert(copied_model);
00089
00090
00091 boost::shared_ptr<AbstractStimulusFunction> p_stimulus;
00092 boost::shared_ptr<EulerIvpOdeSolver> p_solver;
00093 if (!makeCvodeCell)
00094 {
00095
00096 p_solver.reset(new EulerIvpOdeSolver);
00097 }
00098 AbstractCardiacCellInterface* p_loaded_cell = p_loader->CreateCell(p_solver, p_stimulus);
00099
00100
00101 if (p_loaded_cell->HasCellMLDefaultStimulus())
00102 {
00103 p_loaded_cell->UseCellMLDefaultStimulus();
00104 }
00105 return p_loaded_cell;
00106 }
00107
00108 boost::shared_ptr<AbstractCardiacCell> CellMLLoader::LoadCardiacCell(void)
00109 {
00110 AbstractCardiacCellInterface* p_loaded_cell = LoadCellMLFile(false);
00111 boost::shared_ptr<AbstractCardiacCell> p_model(dynamic_cast<AbstractCardiacCell*>(p_loaded_cell));
00112 return p_model;
00113 }
00114
00115 #ifdef CHASTE_CVODE
00116 boost::shared_ptr<AbstractCvodeCell> CellMLLoader::LoadCvodeCell(void)
00117 {
00118 AbstractCardiacCellInterface* p_loaded_cell = LoadCellMLFile(true);
00119 boost::shared_ptr<AbstractCvodeCell> p_model(dynamic_cast<AbstractCvodeCell*>(p_loaded_cell));
00120 return p_model;
00121 }
00122 #endif
00123
00124