36 #include "HeartConfigRelatedCellFactory.hpp"
39 #include "HeartGeometryInformation.hpp"
40 #include "ChasteNodesList.hpp"
41 #include "HeartFileFinder.hpp"
42 #include "CellMLToSharedLibraryConverter.hpp"
43 #include "AbstractCardiacCellInterface.hpp"
44 #include "Warnings.hpp"
47 #include "AbstractCvodeCell.hpp"
49 template<
unsigned SPACE_DIM>
52 mDefaultIonicModel(
HeartConfig::Instance()->GetDefaultIonicModel())
64 EXCEPTION(
"Simulation needs a stimulus (either <Stimuli> or <Electrodes>).");
78 template<
unsigned SPACE_DIM>
81 if (mDefaultIonicModel.Dynamic().present())
83 LoadDynamicModel(mDefaultIonicModel,
true);
85 for (
unsigned i=0; i<mIonicModelsDefined.size(); i++)
87 if (mIonicModelsDefined[i].Dynamic().present())
89 LoadDynamicModel(mIonicModelsDefined[i],
true);
94 template<
unsigned SPACE_DIM>
96 const cp::ionic_model_selection_type& rModel,
99 assert(rModel.Dynamic().present());
102 return converter.
Convert(file_finder, isCollective);
105 template<
unsigned SPACE_DIM>
110 template<
unsigned SPACE_DIM>
112 boost::shared_ptr<AbstractStimulusFunction> intracellularStimulus,
115 cp::ionic_model_selection_type ionic_model = mDefaultIonicModel;
117 for (
unsigned ionic_model_region_index = 0;
118 ionic_model_region_index < mIonicModelRegions.size();
119 ++ionic_model_region_index)
121 if (mIonicModelRegions[ionic_model_region_index]->DoesContain(this->GetMesh()->GetNode(nodeIndex)->GetPoint()))
123 ionic_model = mIonicModelsDefined[ionic_model_region_index];
130 if (ionic_model.Dynamic().present())
132 #ifndef CHASTE_CAN_CHECKPOINT_DLLS
135 EXCEPTION(
"Checkpointing is not compatible with dynamically loaded cell models on Mac OS X.");
137 #endif // CHASTE_CAN_CHECKPOINT_DLLS
139 DynamicCellModelLoaderPtr p_loader = LoadDynamicModel(ionic_model,
false);
140 p_cell = p_loader->CreateCell(this->mpSolver, intracellularStimulus);
144 assert(ionic_model.Hardcoded().present());
145 switch(ionic_model.Hardcoded().get())
147 case(cp::ionic_models_available_type::LuoRudyI):
149 p_cell =
new CellLuoRudy1991FromCellML(this->mpSolver, intracellularStimulus);
153 case(cp::ionic_models_available_type::LuoRudyIBackwardEuler):
155 p_cell =
new CellLuoRudy1991FromCellMLBackwardEuler(this->mpSolver, intracellularStimulus);
159 case(cp::ionic_models_available_type::Fox2002):
161 p_cell =
new CellFoxModel2002FromCellML(this->mpSolver, intracellularStimulus);
165 case(cp::ionic_models_available_type::Fox2002BackwardEuler):
167 p_cell =
new CellFoxModel2002FromCellMLBackwardEuler(this->mpSolver, intracellularStimulus);
171 case(cp::ionic_models_available_type::DifrancescoNoble):
173 p_cell =
new CellDiFrancescoNoble1985FromCellML(this->mpSolver, intracellularStimulus);
177 case(cp::ionic_models_available_type::MahajanShiferaw):
179 p_cell =
new CellMahajan2008FromCellML(this->mpSolver, intracellularStimulus);
183 case(cp::ionic_models_available_type::MahajanShiferawBackwardEuler):
185 p_cell =
new CellMahajan2008FromCellMLBackwardEuler(this->mpSolver, intracellularStimulus);
189 case(cp::ionic_models_available_type::tenTusscher2006):
191 p_cell =
new CellTenTusscher2006EpiFromCellML(this->mpSolver, intracellularStimulus);
195 case(cp::ionic_models_available_type::tenTusscher2006BackwardEuler):
197 p_cell =
new CellTenTusscher2006EpiFromCellMLBackwardEuler(this->mpSolver, intracellularStimulus);
201 case(cp::ionic_models_available_type::Maleckar):
203 p_cell =
new CellMaleckar2008FromCellML(this->mpSolver, intracellularStimulus);
207 case(cp::ionic_models_available_type::HodgkinHuxley):
209 p_cell =
new CellHodgkinHuxley1952FromCellML(this->mpSolver, intracellularStimulus);
213 case(cp::ionic_models_available_type::FaberRudy2000):
215 p_cell =
new CellFaberRudy2000FromCellML(this->mpSolver, intracellularStimulus);
219 case(cp::ionic_models_available_type::FaberRudy2000Optimised):
221 p_cell =
new CellFaberRudy2000FromCellMLOpt(this->mpSolver, intracellularStimulus);
236 SetCellParameters(p_cell, nodeIndex);
249 template<
unsigned SPACE_DIM>
254 for (
unsigned ht_index = 0;
255 ht_index < mCellHeterogeneityAreas.size();
258 if (mCellHeterogeneityAreas[ht_index]->DoesContain(this->GetMesh()->GetNode(nodeIndex)->GetPoint()))
262 pCell->
SetParameter(
"ScaleFactorGks", mScaleFactorGks[ht_index]);
263 pCell->
SetParameter(
"ScaleFactorGkr", mScaleFactorGkr[ht_index]);
264 pCell->
SetParameter(
"ScaleFactorIto", mScaleFactorIto[ht_index]);
278 for (std::map<std::string, std::pair<double, double> >::iterator it = ic50_values.begin();
279 it != ic50_values.end();
282 const std::string param_name = it->first +
"_conductance";
283 if (dynamic_cast<AbstractUntemplatedParameterisedSystem*>(pCell)->HasParameter(param_name))
285 const double original_conductance = pCell->
GetParameter(param_name);
286 const double ic50 = it->second.first;
287 const double hill = it->second.second;
288 const double new_conductance = original_conductance/(1.0 + pow(drug_dose/ic50, hill));
293 WARNING(
"Cannot apply drug to cell at node " << nodeIndex <<
" as it has no parameter named '" << param_name <<
"'.");
299 for (
unsigned ht_index = 0;
300 ht_index < mCellHeterogeneityAreas.size();
303 if (mCellHeterogeneityAreas[ht_index]->DoesContain(this->GetMesh()->GetNode(nodeIndex)->GetPoint()))
305 for (std::map<std::string, double>::iterator param_it = mParameterSettings[ht_index].begin();
306 param_it != mParameterSettings[ht_index].end();
315 template<
unsigned SPACE_DIM>
319 boost::shared_ptr<MultiStimulus> node_specific_stimulus(
new MultiStimulus());
321 for (
unsigned stimulus_index = 0;
322 stimulus_index < mStimuliApplied.size();
325 if (mStimulatedAreas[stimulus_index]->DoesContain(this->GetMesh()->GetNode(nodeIndex)->GetPoint()))
327 node_specific_stimulus->AddStimulus(mStimuliApplied[stimulus_index]);
333 template<
unsigned SPACE_DIM>
336 boost::shared_ptr<MultiStimulus> node_specific_stimulus(
new MultiStimulus());
339 for (
unsigned stimulus_index = 0;
340 stimulus_index < mStimuliApplied.size();
343 if (mStimulatedAreas[stimulus_index]->DoesContain(pNode->
GetPoint()))
345 node_specific_stimulus->AddStimulus(mStimuliApplied[stimulus_index]);
349 unsigned node_index = pNode->
GetIndex();
350 return CreateCellWithIntracellularStimulus(node_specific_stimulus, node_index);
354 template<
unsigned SPACE_DIM>
366 std::string epi_surface = mesh_file_name +
".epi";
367 std::string lv_surface = mesh_file_name +
".lv";
368 std::string rv_surface = mesh_file_name +
".rv";
382 std::vector<unsigned> heterogeneity_node_list;
383 for (
unsigned index=0; index<this->GetMesh()->GetNumNodes(); index++)
388 std::vector<Node<3u>*> epi_nodes;
389 std::vector<Node<3u>*> mid_nodes;
390 std::vector<Node<3u>*> endo_nodes;
393 for (
unsigned node_index = 0; node_index < this->GetMesh()->GetNumNodes(); node_index++)
395 if (this->GetMesh()->GetDistributedVectorFactory()->IsGlobalIndexLocal(node_index) )
397 switch (heterogeneity_node_list[node_index])
402 epi_nodes.push_back(this->GetMesh()->GetNode(node_index));
408 mid_nodes.push_back(this->GetMesh()->GetNode(node_index));
414 endo_nodes.push_back(this->GetMesh()->GetNode(node_index));
434 assert(user_supplied_epi_index<3);
435 assert(user_supplied_mid_index<3);
436 assert(user_supplied_endo_index<3);
439 std::vector<unsigned> user_supplied_indices;
440 user_supplied_indices.push_back(user_supplied_epi_index);
441 user_supplied_indices.push_back(user_supplied_mid_index);
442 user_supplied_indices.push_back(user_supplied_endo_index);
447 for (
unsigned layer_index=0; layer_index<3; layer_index++)
449 unsigned counter = 0;
451 for (
unsigned supplied_index = 0; supplied_index<user_supplied_indices.size(); supplied_index++)
453 if (user_supplied_indices[supplied_index] == layer_index)
475 assert(mCellHeterogeneityAreas.size()==3);
void GetIonicModelRegions(std::vector< boost::shared_ptr< AbstractChasteRegion< DIM > > > &rDefinedRegions, std::vector< cp::ionic_model_selection_type > &rIonicModels) const
void GetCellHeterogeneities(std::vector< boost::shared_ptr< AbstractChasteRegion< DIM > > > &rCellHeterogeneityRegions, std::vector< double > &rScaleFactorGks, std::vector< double > &rScaleFactorIto, std::vector< double > &rScaleFactorGkr, std::vector< std::map< std::string, double > > *pParameterSettings)
virtual void SetParameter(const std::string &rParameterName, double value)=0
#define EXCEPTION(message)
unsigned GetEndoLayerIndex()
void SetIntracellularStimulusFunction(boost::shared_ptr< AbstractStimulusFunction > pStimulus)
DynamicCellModelLoaderPtr Convert(const FileFinder &rFilePath, bool isCollective=true)
std::string GetMeshName() const
double GetEpiLayerFraction()
virtual double GetParameter(const std::string &rParameterName)=0
double GetDrugDose() const
virtual AbstractLookupTableCollection * GetLookupTableCollection()
unsigned GetEpiLayerIndex()
bool IsElectrodesPresent() const
double GetEndoLayerFraction()
unsigned GetMidLayerIndex()
bool GetCheckpointSimulation() const
ChastePoint< SPACE_DIM > GetPoint() const
unsigned GetIndex() const
void GetStimuli(std::vector< boost::shared_ptr< AbstractStimulusFunction > > &rStimuliApplied, std::vector< boost::shared_ptr< AbstractChasteRegion< DIM > > > &rStimulatedAreas) const
static HeartConfig * Instance()
std::map< std::string, std::pair< double, double > > GetIc50Values()