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 Boost<1.37.");
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);
250 template<
unsigned SPACE_DIM>
255 for (
unsigned ht_index = 0;
256 ht_index < mCellHeterogeneityAreas.size();
259 if ( mCellHeterogeneityAreas[ht_index]->DoesContain(this->GetMesh()->GetNode(nodeIndex)->GetPoint()) )
263 pCell->
SetParameter(
"ScaleFactorGks", mScaleFactorGks[ht_index]);
264 pCell->
SetParameter(
"ScaleFactorGkr", mScaleFactorGkr[ht_index]);
265 pCell->
SetParameter(
"ScaleFactorIto", mScaleFactorIto[ht_index]);
279 for (std::map<std::string, std::pair<double, double> >::iterator it = ic50_values.begin();
280 it != ic50_values.end();
283 const std::string param_name = it->first +
"_conductance";
284 if (dynamic_cast<AbstractUntemplatedParameterisedSystem*>(pCell)->HasParameter(param_name))
286 const double original_conductance = pCell->
GetParameter(param_name);
287 const double ic50 = it->second.first;
288 const double hill = it->second.second;
289 const double new_conductance = original_conductance/(1.0 + pow(drug_dose/ic50, hill));
294 WARNING(
"Cannot apply drug to cell at node " << nodeIndex <<
" as it has no parameter named '" << param_name <<
"'.");
300 for (
unsigned ht_index = 0;
301 ht_index < mCellHeterogeneityAreas.size();
304 if ( mCellHeterogeneityAreas[ht_index]->DoesContain(this->GetMesh()->GetNode(nodeIndex)->GetPoint()) )
306 for (std::map<std::string, double>::iterator param_it = mParameterSettings[ht_index].begin();
307 param_it != mParameterSettings[ht_index].end();
317 template<
unsigned SPACE_DIM>
321 boost::shared_ptr<MultiStimulus> node_specific_stimulus(
new MultiStimulus());
323 for (
unsigned stimulus_index = 0;
324 stimulus_index < mStimuliApplied.size();
327 if ( mStimulatedAreas[stimulus_index]->DoesContain(this->GetMesh()->GetNode(nodeIndex)->GetPoint()) )
329 node_specific_stimulus->AddStimulus(mStimuliApplied[stimulus_index]);
336 template<
unsigned SPACE_DIM>
339 boost::shared_ptr<MultiStimulus> node_specific_stimulus(
new MultiStimulus());
342 for (
unsigned stimulus_index = 0;
343 stimulus_index < mStimuliApplied.size();
346 if ( mStimulatedAreas[stimulus_index]->DoesContain(pNode->
GetPoint()) )
348 node_specific_stimulus->AddStimulus(mStimuliApplied[stimulus_index]);
352 unsigned node_index = pNode->
GetIndex();
353 return CreateCellWithIntracellularStimulus(node_specific_stimulus, node_index);
356 template<
unsigned SPACE_DIM>
367 std::string epi_surface = mesh_file_name +
".epi";
368 std::string lv_surface = mesh_file_name +
".lv";
369 std::string rv_surface = mesh_file_name +
".rv";
383 std::vector<unsigned> heterogeneity_node_list;
384 for (
unsigned index=0; index<this->GetMesh()->GetNumNodes(); index++)
389 std::vector<Node<3u>*> epi_nodes;
390 std::vector<Node<3u>*> mid_nodes;
391 std::vector<Node<3u>*> endo_nodes;
394 for (
unsigned node_index = 0; node_index < this->GetMesh()->GetNumNodes(); node_index++)
396 if (this->GetMesh()->GetDistributedVectorFactory()->IsGlobalIndexLocal(node_index) )
398 switch (heterogeneity_node_list[node_index])
403 epi_nodes.push_back(this->GetMesh()->GetNode(node_index));
409 mid_nodes.push_back(this->GetMesh()->GetNode(node_index));
415 endo_nodes.push_back(this->GetMesh()->GetNode(node_index));
435 assert(user_supplied_epi_index<3);
436 assert(user_supplied_mid_index<3);
437 assert(user_supplied_endo_index<3);
440 std::vector<unsigned> user_supplied_indices;
441 user_supplied_indices.push_back(user_supplied_epi_index);
442 user_supplied_indices.push_back(user_supplied_mid_index);
443 user_supplied_indices.push_back(user_supplied_endo_index);
448 for (
unsigned layer_index=0; layer_index<3; layer_index++)
450 unsigned counter = 0;
452 for (
unsigned supplied_index = 0; supplied_index<user_supplied_indices.size(); supplied_index++)
454 if (user_supplied_indices[supplied_index] == layer_index)
476 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()