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;
87 #define COVERAGE_IGNORE //don't really know how to cover this...
97 delete (*cell_iterator);
100 #undef COVERAGE_IGNORE
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];
184 #define COVERAGE_IGNORE
187 #undef COVERAGE_IGNORE
192 template <
unsigned SPACE_DIM>
198 if (this->mpConfig->IsMeshProvided() && this->mpConfig->GetLoadMesh())
200 assert(this->mFibreFilePathNoExtension !=
"");
202 switch (this->mpConfig->GetConductivityMedia())
204 case cp::media_type::Orthotropic:
208 assert(ortho_file.
Exists());
209 mpIntracellularConductivityTensorsSecondCell->SetFibreOrientationFile(ortho_file);
213 case cp::media_type::Axisymmetric:
217 assert(axi_file.
Exists());
218 mpIntracellularConductivityTensorsSecondCell->SetFibreOrientationFile(axi_file);
222 case cp::media_type::NoFibreOrientation:
237 unsigned num_elements = this->mpMesh->GetNumElements();
238 std::vector<c_vector<double, SPACE_DIM> > hetero_intra_conductivities;
240 c_vector<double, SPACE_DIM> intra_conductivities;
241 this->mpConfig->GetIntracellularConductivities(intra_conductivities);
243 if (this->mpConfig->GetConductivityHeterogeneitiesProvided())
247 assert(hetero_intra_conductivities.size()==0);
248 hetero_intra_conductivities.resize(num_elements, intra_conductivities);
250 catch(std::bad_alloc &badAlloc)
252 #define COVERAGE_IGNORE
253 std::cout <<
"Failed to allocate std::vector of size " << num_elements << std::endl;
256 #undef COVERAGE_IGNORE
260 std::vector<boost::shared_ptr<AbstractChasteRegion<SPACE_DIM> > > conductivities_heterogeneity_areas;
261 std::vector< c_vector<double,3> > intra_h_conductivities;
262 std::vector< c_vector<double,3> > extra_h_conductivities;
264 intra_h_conductivities,
265 extra_h_conductivities);
266 unsigned local_element_index = 0;
268 it != this->mpMesh->GetElementIteratorEnd();
274 for (
unsigned region_index=0; region_index< conductivities_heterogeneity_areas.size(); region_index++)
276 if ( conductivities_heterogeneity_areas[region_index]->DoesContain(element_centroid) )
279 for (
unsigned i=0; i<SPACE_DIM; i++)
281 hetero_intra_conductivities[local_element_index][i] = intra_h_conductivities[region_index][i];
285 local_element_index++;
288 mpIntracellularConductivityTensorsSecondCell->SetNonConstantConductivities(&hetero_intra_conductivities);
292 mpIntracellularConductivityTensorsSecondCell->SetConstantConductivities(mIntracellularConductivitiesSecondCell);
295 mpIntracellularConductivityTensorsSecondCell->Init(this->mpMesh);
299 template <
unsigned SPACE_DIM>
302 return mUserSuppliedExtracellularStimulus;
305 template <
unsigned SPACE_DIM>
308 mUserSuppliedExtracellularStimulus = flag;
311 template <
unsigned SPACE_DIM>
314 return mCellsDistributedSecondCell;
317 template <
unsigned SPACE_DIM>
320 return mGgapDistributed;
323 template <
unsigned SPACE_DIM>
326 return mExtracellularStimuliDistributed;
330 template <
unsigned SPACE_DIM>
333 if (this->mpConfig->IsMeshProvided() && this->mpConfig->GetLoadMesh())
335 assert(this->mFibreFilePathNoExtension !=
"");
336 switch (this->mpConfig->GetConductivityMedia())
338 case cp::media_type::Orthotropic:
342 assert(ortho_file.
Exists());
343 mpExtracellularConductivityTensors->SetFibreOrientationFile(ortho_file);
347 case cp::media_type::Axisymmetric:
351 assert(axi_file.
Exists());
352 mpExtracellularConductivityTensors->SetFibreOrientationFile(axi_file);
356 case cp::media_type::NoFibreOrientation:
369 c_vector<double, SPACE_DIM> extra_conductivities;
370 this->mpConfig->GetExtracellularConductivities(extra_conductivities);
374 unsigned num_elements = this->mpMesh->GetNumElements();
375 std::vector<c_vector<double, SPACE_DIM> > hetero_extra_conductivities;
377 if (this->mpConfig->GetConductivityHeterogeneitiesProvided())
381 assert(hetero_extra_conductivities.size()==0);
383 hetero_extra_conductivities.resize(num_elements, extra_conductivities);
385 catch(std::bad_alloc &badAlloc)
387 #define COVERAGE_IGNORE
388 std::cout <<
"Failed to allocate std::vector of size " << num_elements << std::endl;
391 #undef COVERAGE_IGNORE
395 std::vector<boost::shared_ptr<AbstractChasteRegion<SPACE_DIM> > > conductivities_heterogeneity_areas;
396 std::vector< c_vector<double,3> > intra_h_conductivities;
397 std::vector< c_vector<double,3> > extra_h_conductivities;
399 intra_h_conductivities,
400 extra_h_conductivities);
401 unsigned local_element_index = 0;
403 iter != (this->mpMesh)->GetElementIteratorEnd();
409 for (
unsigned region_index=0; region_index< conductivities_heterogeneity_areas.size(); region_index++)
412 if ( conductivities_heterogeneity_areas[region_index]->DoesContain( element_centroid ) )
415 for (
unsigned i=0; i<SPACE_DIM; i++)
417 hetero_extra_conductivities[local_element_index][i] = extra_h_conductivities[region_index][i];
421 local_element_index++;
424 mpExtracellularConductivityTensors->SetNonConstantConductivities(&hetero_extra_conductivities);
428 mpExtracellularConductivityTensors->SetConstantConductivities(extra_conductivities);
430 mpExtracellularConductivityTensors->Init(this->mpMesh);
433 template <
unsigned SPACE_DIM>
437 for (std::vector<AbstractCardiacCellInterface*>::iterator cell_iterator = mCellsDistributedSecondCell.begin();
438 cell_iterator != mCellsDistributedSecondCell.end();
441 delete (*cell_iterator);
444 if (mpExtracellularConductivityTensors)
446 delete mpExtracellularConductivityTensors;
449 if (mpIntracellularConductivityTensorsSecondCell)
451 delete mpIntracellularConductivityTensorsSecondCell;
455 template <
unsigned SPACE_DIM>
458 for (
unsigned i = 0; i < SPACE_DIM; i++)
460 mIntracellularConductivitiesSecondCell[i] = conductivities[i];
464 template <
unsigned SPACE_DIM>
467 return mIntracellularConductivitiesSecondCell;
470 template <
unsigned SPACE_DIM>
473 assert(mpExtracellularConductivityTensors);
474 if (this->mpConductivityModifier==NULL)
476 return (*mpExtracellularConductivityTensors)[elementIndex];
480 return this->mpConductivityModifier->rGetModifiedConductivityTensor(elementIndex, (*mpExtracellularConductivityTensors)[elementIndex], 1u);
484 template <
unsigned SPACE_DIM>
487 assert(mpIntracellularConductivityTensorsSecondCell);
488 if (this->mpConductivityModifier==NULL)
490 return (*mpIntracellularConductivityTensorsSecondCell)[elementIndex];
494 return this->mpConductivityModifier->rGetModifiedConductivityTensor(elementIndex, (*mpIntracellularConductivityTensorsSecondCell)[elementIndex], 2u);
498 template <
unsigned SPACE_DIM>
501 return mCellsDistributedSecondCell[globalIndex - this->mpDistributedVectorFactory->GetLow()];
504 template <
unsigned SPACE_DIM>
507 return mExtracellularStimuliDistributed[globalIndex - this->mpDistributedVectorFactory->GetLow()];
510 template <
unsigned SPACE_DIM>
515 DistributedVector dist_solution = this->mpDistributedVectorFactory->CreateDistributedVector(existingSolution);
521 index != dist_solution.
End();
525 this->mCellsDistributed[index.Local]->SetVoltage( V_first_cell[index] );
526 mCellsDistributedSecondCell[index.Local]->SetVoltage( V_second_cell[index] );
532 this->mCellsDistributed[index.Local]->ComputeExceptVoltage(time, nextTime);
533 mCellsDistributedSecondCell[index.Local]->ComputeExceptVoltage(time, nextTime);
537 #define COVERAGE_IGNORE
540 #undef COVERAGE_IGNORE
544 this->UpdateCaches(index.Global, index.Local, nextTime);
545 UpdateAdditionalCaches(index.Global, index.Local, nextTime);
551 if ( this->mDoCacheReplication )
553 this->ReplicateCaches();
554 ReplicateAdditionalCaches();
559 template <
unsigned SPACE_DIM>
562 mIionicCacheReplicatedSecondCell[globalIndex] = mCellsDistributedSecondCell[localIndex]->GetIIonic();
563 mIntracellularStimulusCacheReplicatedSecondCell[globalIndex] = mCellsDistributedSecondCell[localIndex]->GetIntracellularStimulus(nextTime);
564 mExtracellularStimulusCacheReplicated[globalIndex] = mExtracellularStimuliDistributed[localIndex]->GetStimulus(nextTime);
565 mGgapCacheReplicated[globalIndex] = mGgapDistributed[localIndex];
568 template <
unsigned SPACE_DIM>
571 mIionicCacheReplicatedSecondCell.Replicate(this->mpDistributedVectorFactory->GetLow(), this->mpDistributedVectorFactory->GetHigh());
572 mIntracellularStimulusCacheReplicatedSecondCell.Replicate(this->mpDistributedVectorFactory->GetLow(), this->mpDistributedVectorFactory->GetHigh());
573 mExtracellularStimulusCacheReplicated.Replicate(this->mpDistributedVectorFactory->GetLow(), this->mpDistributedVectorFactory->GetHigh());
574 mGgapCacheReplicated.Replicate(this->mpDistributedVectorFactory->GetLow(), this->mpDistributedVectorFactory->GetHigh());
577 template <
unsigned SPACE_DIM>
580 return mIionicCacheReplicatedSecondCell;
583 template <
unsigned SPACE_DIM>
586 return mIntracellularStimulusCacheReplicatedSecondCell;
589 template <
unsigned SPACE_DIM>
592 return mExtracellularStimulusCacheReplicated;
595 template <
unsigned SPACE_DIM>
598 return mGgapCacheReplicated;
601 template <
unsigned SPACE_DIM>
607 template <
unsigned SPACE_DIM>
610 return mAmSecondCell;
613 template <
unsigned SPACE_DIM>
619 template <
unsigned SPACE_DIM>
625 template <
unsigned SPACE_DIM>
628 return mCmSecondCell;
631 template <
unsigned SPACE_DIM>
637 template <
unsigned SPACE_DIM>
640 mAmFirstCell = value;
643 template <
unsigned SPACE_DIM>
646 mAmSecondCell = value;
649 template <
unsigned SPACE_DIM>
655 template <
unsigned SPACE_DIM>
661 template <
unsigned SPACE_DIM>
664 mCmFirstCell = value;
667 template <
unsigned SPACE_DIM>
670 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)