36 #include "ExtendedBidomainTissue.hpp"
38 #include "DistributedVector.hpp"
39 #include "OrthotropicConductivityTensors.hpp"
40 #include "AxisymmetricConductivityTensors.hpp"
41 #include "AbstractStimulusFunction.hpp"
42 #include "ChastePoint.hpp"
43 #include "AbstractChasteRegion.hpp"
44 #include "HeartEventHandler.hpp"
46 template <
unsigned SPACE_DIM>
51 mpIntracellularConductivityTensorsSecondCell(NULL),
52 mUserSuppliedExtracellularStimulus(false)
56 assert(pCellFactorySecondCell != NULL);
57 assert(pCellFactorySecondCell->
GetMesh() != NULL);
59 assert(pExtracellularStimulusFactory != NULL);
60 assert(pExtracellularStimulusFactory->
GetMesh() != NULL);
71 for (
unsigned local_index = 0; local_index < num_local_nodes; local_index++)
73 unsigned global_index = local_index + ownership_range_low;
97 delete (*cell_iterator);
116 template <
unsigned SPACE_DIM>
118 std::vector<AbstractCardiacCellInterface*> & rSecondCellsDistributed,
119 std::vector<boost::shared_ptr<AbstractStimulusFunction> > & rExtraStimuliDistributed,
120 std::vector<double> & rGgapsDistributed,
122 c_vector<double, SPACE_DIM> intracellularConductivitiesSecondCell)
124 mpIntracellularConductivityTensorsSecondCell(NULL),
125 mIntracellularConductivitiesSecondCell(intracellularConductivitiesSecondCell),
126 mCellsDistributedSecondCell(rSecondCellsDistributed),
127 mExtracellularStimuliDistributed(rExtraStimuliDistributed),
128 mGgapDistributed(rGgapsDistributed),
129 mUserSuppliedExtracellularStimulus(false)
146 template <
unsigned SPACE_DIM>
148 std::vector<double> rGgapValues)
150 assert( rGgapHeterogeneityRegions.size() == rGgapValues.size() );
151 mGgapHeterogeneityRegions = rGgapHeterogeneityRegions;
152 mGgapValues =rGgapValues;
155 template <
unsigned SPACE_DIM>
158 assert(mGgapHeterogeneityRegions.size() == mGgapValues.size());
159 assert(this->mpMesh != NULL);
161 unsigned ownership_range_low = this->mpDistributedVectorFactory->GetLow();
162 unsigned num_local_nodes = this->mpDistributedVectorFactory->GetLocalOwnership();
163 assert(mGgapDistributed.size() == num_local_nodes);
166 for (
unsigned local_index = 0; local_index < num_local_nodes; local_index++)
168 unsigned global_index = ownership_range_low + local_index;
170 mGgapDistributed[local_index] = mGGap;
173 for (
unsigned het_index = 0; het_index < mGgapHeterogeneityRegions.size(); het_index++)
175 if (mGgapHeterogeneityRegions[het_index]->DoesContain(p_node->
GetPoint()))
177 mGgapDistributed[local_index] = mGgapValues[het_index];
193 template <
unsigned SPACE_DIM>
199 if (this->mpConfig->IsMeshProvided() && this->mpConfig->GetLoadMesh())
201 assert(this->mFibreFilePathNoExtension !=
"");
203 switch (this->mpConfig->GetConductivityMedia())
205 case cp::media_type::Orthotropic:
209 assert(ortho_file.
Exists());
210 mpIntracellularConductivityTensorsSecondCell->SetFibreOrientationFile(ortho_file);
214 case cp::media_type::Axisymmetric:
218 assert(axi_file.
Exists());
219 mpIntracellularConductivityTensorsSecondCell->SetFibreOrientationFile(axi_file);
223 case cp::media_type::NoFibreOrientation:
238 unsigned num_elements = this->mpMesh->GetNumElements();
239 std::vector<c_vector<double, SPACE_DIM> > hetero_intra_conductivities;
241 c_vector<double, SPACE_DIM> intra_conductivities;
242 this->mpConfig->GetIntracellularConductivities(intra_conductivities);
244 if (this->mpConfig->GetConductivityHeterogeneitiesProvided())
248 assert(hetero_intra_conductivities.size()==0);
249 hetero_intra_conductivities.resize(num_elements, intra_conductivities);
252 catch(std::bad_alloc &badAlloc)
255 std::cout <<
"Failed to allocate std::vector of size " << num_elements << std::endl;
263 std::vector<boost::shared_ptr<AbstractChasteRegion<SPACE_DIM> > > conductivities_heterogeneity_areas;
264 std::vector< c_vector<double,3> > intra_h_conductivities;
265 std::vector< c_vector<double,3> > extra_h_conductivities;
267 intra_h_conductivities,
268 extra_h_conductivities);
269 unsigned local_element_index = 0;
271 it != this->mpMesh->GetElementIteratorEnd();
277 for (
unsigned region_index=0; region_index< conductivities_heterogeneity_areas.size(); region_index++)
279 if (conductivities_heterogeneity_areas[region_index]->DoesContain(element_centroid))
282 for (
unsigned i=0; i<SPACE_DIM; i++)
284 hetero_intra_conductivities[local_element_index][i] = intra_h_conductivities[region_index][i];
288 local_element_index++;
291 mpIntracellularConductivityTensorsSecondCell->SetNonConstantConductivities(&hetero_intra_conductivities);
295 mpIntracellularConductivityTensorsSecondCell->SetConstantConductivities(mIntracellularConductivitiesSecondCell);
298 mpIntracellularConductivityTensorsSecondCell->Init(this->mpMesh);
302 template <
unsigned SPACE_DIM>
305 return mUserSuppliedExtracellularStimulus;
308 template <
unsigned SPACE_DIM>
311 mUserSuppliedExtracellularStimulus = flag;
314 template <
unsigned SPACE_DIM>
317 return mCellsDistributedSecondCell;
320 template <
unsigned SPACE_DIM>
323 return mGgapDistributed;
326 template <
unsigned SPACE_DIM>
329 return mExtracellularStimuliDistributed;
333 template <
unsigned SPACE_DIM>
336 if (this->mpConfig->IsMeshProvided() && this->mpConfig->GetLoadMesh())
338 assert(this->mFibreFilePathNoExtension !=
"");
339 switch (this->mpConfig->GetConductivityMedia())
341 case cp::media_type::Orthotropic:
345 assert(ortho_file.
Exists());
346 mpExtracellularConductivityTensors->SetFibreOrientationFile(ortho_file);
350 case cp::media_type::Axisymmetric:
354 assert(axi_file.
Exists());
355 mpExtracellularConductivityTensors->SetFibreOrientationFile(axi_file);
359 case cp::media_type::NoFibreOrientation:
372 c_vector<double, SPACE_DIM> extra_conductivities;
373 this->mpConfig->GetExtracellularConductivities(extra_conductivities);
377 unsigned num_elements = this->mpMesh->GetNumElements();
378 std::vector<c_vector<double, SPACE_DIM> > hetero_extra_conductivities;
380 if (this->mpConfig->GetConductivityHeterogeneitiesProvided())
384 assert(hetero_extra_conductivities.size()==0);
386 hetero_extra_conductivities.resize(num_elements, extra_conductivities);
389 catch(std::bad_alloc &badAlloc)
391 std::cout <<
"Failed to allocate std::vector of size " << num_elements << std::endl;
399 std::vector<boost::shared_ptr<AbstractChasteRegion<SPACE_DIM> > > conductivities_heterogeneity_areas;
400 std::vector< c_vector<double,3> > intra_h_conductivities;
401 std::vector< c_vector<double,3> > extra_h_conductivities;
403 intra_h_conductivities,
404 extra_h_conductivities);
405 unsigned local_element_index = 0;
407 iter != (this->mpMesh)->GetElementIteratorEnd();
413 for (
unsigned region_index=0; region_index< conductivities_heterogeneity_areas.size(); region_index++)
416 if (conductivities_heterogeneity_areas[region_index]->DoesContain(element_centroid))
419 for (
unsigned i=0; i<SPACE_DIM; i++)
421 hetero_extra_conductivities[local_element_index][i] = extra_h_conductivities[region_index][i];
425 local_element_index++;
428 mpExtracellularConductivityTensors->SetNonConstantConductivities(&hetero_extra_conductivities);
432 mpExtracellularConductivityTensors->SetConstantConductivities(extra_conductivities);
434 mpExtracellularConductivityTensors->Init(this->mpMesh);
437 template <
unsigned SPACE_DIM>
441 for (std::vector<AbstractCardiacCellInterface*>::iterator cell_iterator = mCellsDistributedSecondCell.begin();
442 cell_iterator != mCellsDistributedSecondCell.end();
445 delete (*cell_iterator);
448 if (mpExtracellularConductivityTensors)
450 delete mpExtracellularConductivityTensors;
453 if (mpIntracellularConductivityTensorsSecondCell)
455 delete mpIntracellularConductivityTensorsSecondCell;
459 template <
unsigned SPACE_DIM>
462 for (
unsigned i = 0; i < SPACE_DIM; i++)
464 mIntracellularConductivitiesSecondCell[i] = conductivities[i];
468 template <
unsigned SPACE_DIM>
471 return mIntracellularConductivitiesSecondCell;
474 template <
unsigned SPACE_DIM>
477 assert(mpExtracellularConductivityTensors);
478 if (this->mpConductivityModifier==NULL)
480 return (*mpExtracellularConductivityTensors)[elementIndex];
484 return this->mpConductivityModifier->rGetModifiedConductivityTensor(elementIndex, (*mpExtracellularConductivityTensors)[elementIndex], 1u);
488 template <
unsigned SPACE_DIM>
491 assert(mpIntracellularConductivityTensorsSecondCell);
492 if (this->mpConductivityModifier==NULL)
494 return (*mpIntracellularConductivityTensorsSecondCell)[elementIndex];
498 return this->mpConductivityModifier->rGetModifiedConductivityTensor(elementIndex, (*mpIntracellularConductivityTensorsSecondCell)[elementIndex], 2u);
502 template <
unsigned SPACE_DIM>
505 return mCellsDistributedSecondCell[globalIndex - this->mpDistributedVectorFactory->GetLow()];
508 template <
unsigned SPACE_DIM>
511 return mExtracellularStimuliDistributed[globalIndex - this->mpDistributedVectorFactory->GetLow()];
514 template <
unsigned SPACE_DIM>
519 DistributedVector dist_solution = this->mpDistributedVectorFactory->CreateDistributedVector(existingSolution);
525 index != dist_solution.
End();
529 this->mCellsDistributed[index.Local]->SetVoltage( V_first_cell[index] );
530 mCellsDistributedSecondCell[index.Local]->SetVoltage( V_second_cell[index] );
536 this->mCellsDistributed[index.Local]->ComputeExceptVoltage(time, nextTime);
537 mCellsDistributedSecondCell[index.Local]->ComputeExceptVoltage(time, nextTime);
548 this->UpdateCaches(index.Global, index.Local, nextTime);
549 UpdateAdditionalCaches(index.Global, index.Local, nextTime);
555 if (this->mDoCacheReplication)
557 this->ReplicateCaches();
558 ReplicateAdditionalCaches();
563 template <
unsigned SPACE_DIM>
566 mIionicCacheReplicatedSecondCell[globalIndex] = mCellsDistributedSecondCell[localIndex]->GetIIonic();
567 mIntracellularStimulusCacheReplicatedSecondCell[globalIndex] = mCellsDistributedSecondCell[localIndex]->GetIntracellularStimulus(nextTime);
568 mExtracellularStimulusCacheReplicated[globalIndex] = mExtracellularStimuliDistributed[localIndex]->GetStimulus(nextTime);
569 mGgapCacheReplicated[globalIndex] = mGgapDistributed[localIndex];
572 template <
unsigned SPACE_DIM>
575 mIionicCacheReplicatedSecondCell.Replicate(this->mpDistributedVectorFactory->GetLow(), this->mpDistributedVectorFactory->GetHigh());
576 mIntracellularStimulusCacheReplicatedSecondCell.Replicate(this->mpDistributedVectorFactory->GetLow(), this->mpDistributedVectorFactory->GetHigh());
577 mExtracellularStimulusCacheReplicated.Replicate(this->mpDistributedVectorFactory->GetLow(), this->mpDistributedVectorFactory->GetHigh());
578 mGgapCacheReplicated.Replicate(this->mpDistributedVectorFactory->GetLow(), this->mpDistributedVectorFactory->GetHigh());
581 template <
unsigned SPACE_DIM>
584 return mIionicCacheReplicatedSecondCell;
587 template <
unsigned SPACE_DIM>
590 return mIntracellularStimulusCacheReplicatedSecondCell;
593 template <
unsigned SPACE_DIM>
596 return mExtracellularStimulusCacheReplicated;
599 template <
unsigned SPACE_DIM>
602 return mGgapCacheReplicated;
605 template <
unsigned SPACE_DIM>
611 template <
unsigned SPACE_DIM>
614 return mAmSecondCell;
617 template <
unsigned SPACE_DIM>
623 template <
unsigned SPACE_DIM>
629 template <
unsigned SPACE_DIM>
632 return mCmSecondCell;
635 template <
unsigned SPACE_DIM>
641 template <
unsigned SPACE_DIM>
644 mAmFirstCell = value;
647 template <
unsigned SPACE_DIM>
650 mAmSecondCell = value;
653 template <
unsigned SPACE_DIM>
659 template <
unsigned SPACE_DIM>
665 template <
unsigned SPACE_DIM>
668 mCmFirstCell = value;
671 template <
unsigned SPACE_DIM>
674 mCmSecondCell = value;
virtual void FinaliseCellCreation(std::vector< AbstractCardiacCellInterface * > *pCellsDistributed, unsigned lo, unsigned hi)
ReplicatableVector mIionicCacheReplicatedSecondCell
ElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
virtual AbstractCardiacCellInterface * CreateCardiacCellForNode(Node< SPACE_DIM > *pNode)
ReplicatableVector & rGetExtracellularStimulusCacheReplicated()
void CreateIntracellularConductivityTensorSecondCell()
void SetAmGap(double value)
DistributedVectorFactory * mpDistributedVectorFactory
ReplicatableVector & rGetIionicCacheReplicatedSecondCell()
virtual unsigned GetNumberOfCells()
virtual void SolveCellSystems(Vec existingSolution, double time, double nextTime, bool updateVoltage=false)
c_vector< double, SPACE_DIM > GetIntracellularConductivitiesSecondCell() const
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * GetMesh()
std::vector< AbstractCardiacCellInterface * > mCellsDistributedSecondCell
ReplicatableVector & rGetGgapCacheReplicated()
void ReplicateAdditionalCaches()
void SetGgapHeterogeneities(std::vector< boost::shared_ptr< AbstractChasteRegion< SPACE_DIM > > > &rGgapHeterogeneityRegions, std::vector< double > rGgapValues)
AbstractCardiacCellInterface * GetCardiacSecondCell(unsigned globalIndex)
Node< SPACE_DIM > * GetNode(unsigned index) const
void CreateGGapConductivities()
const c_matrix< double, SPACE_DIM, SPACE_DIM > & rGetExtracellularConductivityTensor(unsigned elementIndex)
void CreateExtracellularConductivityTensors()
static void BeginEvent(unsigned event)
void SetAmSecondCell(double value)
virtual ~ExtendedBidomainTissue()
std::vector< double > mGgapDistributed
void UpdateAdditionalCaches(unsigned globalIndex, unsigned localIndex, double nextTime)
std::vector< boost::shared_ptr< AbstractStimulusFunction > > mExtracellularStimuliDistributed
void GetConductivityHeterogeneities(std::vector< boost::shared_ptr< AbstractChasteRegion< DIM > > > &conductivitiesHeterogeneityAreas, std::vector< c_vector< double, 3 > > &intraConductivities, std::vector< c_vector< double, 3 > > &extraConductivities) const
boost::shared_ptr< AbstractStimulusFunction > GetExtracellularStimulus(unsigned globalIndex)
void SetCmSecondCell(double value)
bool HasTheUserSuppliedExtracellularStimulus()
const std::vector< AbstractCardiacCellInterface * > & rGetSecondCellsDistributed() const
ReplicatableVector mExtracellularStimulusCacheReplicated
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
ReplicatableVector mGgapCacheReplicated
const std::vector< boost::shared_ptr< AbstractStimulusFunction > > & rGetExtracellularStimulusDistributed() const
unsigned GetProblemSize() const
void SetCmFirstCell(double value)
ReplicatableVector & rGetIntracellularStimulusCacheReplicatedSecondCell()
AbstractTetrahedralMesh< ELEMENT_DIM, ELEMENT_DIM > * mpMesh
const std::vector< double > & rGetGapsDistributed() const
virtual boost::shared_ptr< AbstractStimulusFunction > CreateStimulusForNode(Node< SPACE_DIM > *pNode)
ReplicatableVector mIntracellularStimulusCacheReplicatedSecondCell
unsigned GetLocalOwnership() const
void Resize(unsigned size)
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * GetMesh()
ChastePoint< SPACE_DIM > GetPoint() const
static void EndEvent(unsigned event)
void SetIntracellularConductivitiesSecondCell(c_vector< double, SPACE_DIM > conductivities)
void SetUserSuppliedExtracellularStimulus(bool flag)
const c_matrix< double, SPACE_DIM, SPACE_DIM > & rGetIntracellularConductivityTensorSecondCell(unsigned elementIndex)
static HeartConfig * Instance()
virtual unsigned GetNumberOfCells()
void SetAmFirstCell(double value)
void SetGGap(double value)
ExtendedBidomainTissue(AbstractCardiacCellFactory< SPACE_DIM > *pCellFactory, AbstractCardiacCellFactory< SPACE_DIM > *pCellFactorySecondCell, AbstractStimulusFactory< SPACE_DIM > *pExtracellularStimulusFactory)