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
00076 else if (makeCvodeCell != mUseCvode)
00077 {
00078 EXCEPTION("You cannot call both LoadCvodeCell and LoadCardiacCell on the same CellMLLoader.");
00079 }
00080
00081
00082 DynamicCellModelLoaderPtr p_loader = mpConverter->Convert(copied_model);
00083
00084
00085 boost::shared_ptr<AbstractStimulusFunction> p_stimulus;
00086 boost::shared_ptr<EulerIvpOdeSolver> p_solver;
00087 if (!makeCvodeCell)
00088 {
00089
00090 p_solver.reset(new EulerIvpOdeSolver);
00091 }
00092 AbstractCardiacCellInterface* p_loaded_cell = p_loader->CreateCell(p_solver, p_stimulus);
00093
00094
00095 if (p_loaded_cell->HasCellMLDefaultStimulus())
00096 {
00097 p_loaded_cell->UseCellMLDefaultStimulus();
00098 }
00099 return p_loaded_cell;
00100 }
00101
00102 boost::shared_ptr<AbstractCardiacCell> CellMLLoader::LoadCardiacCell(void)
00103 {
00104 AbstractCardiacCellInterface* p_loaded_cell = LoadCellMLFile(false);
00105 boost::shared_ptr<AbstractCardiacCell> p_model(dynamic_cast<AbstractCardiacCell*>(p_loaded_cell));
00106 return p_model;
00107 }
00108
00109 #ifdef CHASTE_CVODE
00110 boost::shared_ptr<AbstractCvodeCell> CellMLLoader::LoadCvodeCell(void)
00111 {
00112 AbstractCardiacCellInterface* p_loaded_cell = LoadCellMLFile(true);
00113 boost::shared_ptr<AbstractCvodeCell> p_model(dynamic_cast<AbstractCvodeCell*>(p_loaded_cell));
00114 return p_model;
00115 }
00116 #endif
00117
00118