Chaste Commit::a9c8bf7350f67d7cf086e6fe3cf5461521554546
AbstractCellPopulation.hpp
1/*
2
3Copyright (c) 2005-2026, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#ifndef ABSTRACTCELLPOPULATION_HPP_
37#define ABSTRACTCELLPOPULATION_HPP_
38
39#include "Cell.hpp"
40#include "OutputFileHandler.hpp"
41
42#include <list>
43#include <map>
44#include <vector>
45#include <boost/shared_ptr.hpp>
46
48#include "ClassIsAbstract.hpp"
49
50#include <boost/serialization/vector.hpp>
51#include <boost/serialization/list.hpp>
52#include <boost/serialization/map.hpp>
53#include <boost/serialization/set.hpp>
54#include <boost/serialization/shared_ptr.hpp>
55
56
57#include "AbstractMesh.hpp"
58#include "TetrahedralMesh.hpp"
59#include "CellPropertyRegistry.hpp"
60#include "Identifiable.hpp"
61#include "AbstractCellPopulationEventWriter.hpp"
62#include "AbstractCellPopulationCountWriter.hpp"
63#include "AbstractCellPopulationWriter.hpp"
64#include "AbstractCellWriter.hpp"
65
66// Forward declaration prevents circular include chain
67template<unsigned ELEMENT_DIM, unsigned SPACE_DIM> class AbstractCellBasedSimulation;
76#ifdef DOXYGEN_CHASTE_ISSUE_199 // See https://github.com/Chaste/Chaste/issues/199
77template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
78#else
79template<unsigned ELEMENT_DIM, unsigned SPACE_DIM = ELEMENT_DIM>
80#endif
82{
83private:
84
87
94 template<class Archive>
95 void serialize(Archive & archive, const unsigned int version)
96 {
97 archive & mCells;
98 archive & mLocationCellMap;
99 archive & mCellLocationMap;
100 archive & mpCellPropertyRegistry;
102 archive & mCellWriters;
103 archive & mCellPopulationWriters;
105 }
106
116
125
126protected:
127
129 std::map<unsigned, std::set<CellPtr> > mLocationCellMap;
130
132 std::map<Cell*, unsigned> mCellLocationMap;
133
136
138 std::list<CellPtr> mCells;
139
141 c_vector<double, SPACE_DIM> mCentroid;
142
144 out_stream mpVtkMetaFile;
145
147 boost::shared_ptr<CellPropertyRegistry> mpCellPropertyRegistry;
148
151
153 std::vector<boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > > mCellWriters;
154
156 std::vector<boost::shared_ptr<AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM> > > mCellPopulationWriters;
157
159 std::vector<boost::shared_ptr<AbstractCellPopulationCountWriter<ELEMENT_DIM, SPACE_DIM> > > mCellPopulationCountWriters;
160
162 std::vector<boost::shared_ptr<AbstractCellPopulationEventWriter<ELEMENT_DIM, SPACE_DIM> > > mCellPopulationEventWriters;
163
168 std::vector<std::string> mDivisionsInformation;
169
174 std::vector<std::string> mRemovalsInformation;
175
182 virtual void Validate()=0;
183
192 virtual void WriteVtkResultsToFile(const std::string& rDirectory)=0;
193
200
208
209public:
210
223 std::vector<CellPtr>& rCells,
224 const std::vector<unsigned> locationIndices=std::vector<unsigned>());
225
229 virtual ~AbstractCellPopulation();
230
234 void InitialiseCells();
235
241 void SetDataOnAllCells(const std::string& rDataName, double dataValue);
242
247
256
267 virtual bool IsPdeNodeAssociatedWithNonApoptoticCell(unsigned pdeNodeIndex);
268
285 virtual double GetCellDataItemAtPdeNode(unsigned pdeNodeIndex,
286 std::string& rVariableName,
287 bool dirichletBoundaryConditionApplies=false,
288 double dirichletBoundaryValue=0.0)=0;
289
293 std::list<CellPtr>& rGetCells();
294
301 virtual unsigned GetNumNodes()=0;
302
312 virtual c_vector<double, SPACE_DIM> GetLocationOfCellCentre(CellPtr pCell)=0;
313
323 virtual Node<SPACE_DIM>* GetNode(unsigned index)=0;
324
334 virtual void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM>& rNewLocation)=0;
335
346 virtual bool IsCellAssociatedWithADeletedLocation(CellPtr pCell)=0;
347
354 virtual void WriteDataToVisualizerSetupFile(out_stream& pVizSetupFile);
355
367 virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell=CellPtr())=0;
368
379 virtual double GetDefaultTimeStep()=0;
380
381 class Iterator; // Forward declaration; see below
382
391 virtual unsigned RemoveDeadCells()=0;
392
402 virtual void Update(bool hasHadBirthsOrDeaths=true)=0;
403
413 std::vector<unsigned> GetCellMutationStateCount();
414
424 std::vector<unsigned> GetCellProliferativeTypeCount();
425
436 std::vector<unsigned> GetCellCyclePhaseCount();
437
444 unsigned GetNumRealCells();
445
452 unsigned GetNumAllCells();
453
459
466 std::set<unsigned> GetCellAncestors();
467
478 virtual CellPtr GetCellUsingLocationIndex(unsigned index);
479
489 std::set<CellPtr> GetCellsUsingLocationIndex(unsigned index);
490
498 virtual bool IsCellAttachedToLocationIndex(unsigned index);
499
510 void SetCellUsingLocationIndex(unsigned index, CellPtr pCell);
511
518 virtual void AddCellUsingLocationIndex(unsigned index, CellPtr pCell);
519
526 virtual void RemoveCellUsingLocationIndex(unsigned index, CellPtr pCell);
527
535 void MoveCellInLocationMap(CellPtr pCell, unsigned old_index, unsigned new_index);
536
546 unsigned GetLocationIndexUsingCell(CellPtr pCell);
547
551 boost::shared_ptr<CellPropertyRegistry> GetCellPropertyRegistry();
552
558
568 virtual double GetWidth(const unsigned& rDimension)=0;
569
577 virtual double GetVolumeOfCell(CellPtr pCell)=0;
578
588 virtual std::set<unsigned> GetNeighbouringNodeIndices(unsigned index)=0;
589
599 virtual std::set<unsigned> GetNeighbouringLocationIndices(CellPtr pCell)=0;
600
607 virtual std::set<std::pair<unsigned, unsigned>> GetNeighbouringEdgeIndices(CellPtr pCell, unsigned pEdgeIndex);
608
612 c_vector<double, SPACE_DIM> GetCentroidOfCellPopulation();
613
617 virtual void UpdateCellProcessLocation();
618
632 virtual void OpenWritersFiles(OutputFileHandler& rOutputFileHandler);
633
640 virtual void CloseWritersFiles();
641
647 virtual void WriteResultsToFiles(const std::string& rDirectory);
648
657 virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationWriter)=0;
658
667 virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationCountWriter)=0;
668
677 virtual void AcceptPopulationEventWriter(boost::shared_ptr<AbstractCellPopulationEventWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationEventWriter)=0;
678
688 virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > pCellWriter, CellPtr pCell) = 0;
689
695 std::vector<std::string> GetDivisionsInformation();
696
704 void AddDivisionInformation(std::string divisionInformation);
705
710
716 std::vector<std::string> GetRemovalsInformation();
717
723 void AddRemovalInformation(std::string removalInformation);
724
729
736 void GenerateRemovalInformation(CellPtr pCell, std::string killerInfo);
737
744 void KillCell(CellPtr pCell, std::string killerInfo);
745
752 void StartApoptosisOnCell(CellPtr pCell, std::string killerInfo);
753
759 void OutputCellPopulationInfo(out_stream& rParamsFile);
760
769 virtual void OutputCellPopulationParameters(out_stream& rParamsFile)=0;
770
786
791
797 template<template <unsigned, unsigned> class T>
799 {
800 mCellPopulationWriters.push_back(boost::shared_ptr< T<ELEMENT_DIM, SPACE_DIM> >(new T<ELEMENT_DIM, SPACE_DIM> ));
801 }
802
808 template<template <unsigned, unsigned> class T>
810 {
811 mCellWriters.push_back(boost::shared_ptr< T<ELEMENT_DIM, SPACE_DIM> >(new T<ELEMENT_DIM, SPACE_DIM> ));
812 }
813
819 template<template <unsigned, unsigned> class T>
821 {
822 mCellPopulationCountWriters.push_back(boost::shared_ptr< T<ELEMENT_DIM, SPACE_DIM> >(new T<ELEMENT_DIM, SPACE_DIM> ));
823 }
824
830 template<template <unsigned, unsigned> class T>
832 {
833 mCellPopulationEventWriters.push_back(boost::shared_ptr< T<ELEMENT_DIM, SPACE_DIM> >(new T<ELEMENT_DIM, SPACE_DIM> ));
834 }
835
845 {
846 mCellPopulationWriters.push_back(pPopulationWriter);
847 }
848
857 void AddCellWriter(boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > pCellWriter)
858 {
859 mCellWriters.push_back(pCellWriter);
860 }
861
871 {
872 mCellPopulationCountWriters.push_back(pCellPopulationCountWriter);
873 }
874
884 {
885 mCellPopulationEventWriters.push_back(pCellPopulationEventWriter);
886 }
887
893 template<template <unsigned, unsigned> class T>
894 bool HasWriter() const
895 {
897 for (boost::shared_ptr<population_writer_t> p_pop_writer : mCellPopulationWriters)
898 {
899 if (dynamic_cast<T<ELEMENT_DIM, SPACE_DIM>* >(p_pop_writer.get()))
900 {
901 return true;
902 }
903 }
904 typedef AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> cell_writer_t;
905 for (boost::shared_ptr<cell_writer_t> p_cell_writer : mCellWriters)
906 {
907 if (dynamic_cast<T<ELEMENT_DIM, SPACE_DIM>* >(p_cell_writer.get()))
908 {
909 return true;
910 }
911 }
913 for (boost::shared_ptr<count_writer_t> p_count_writer : mCellPopulationCountWriters)
914 {
915 if (dynamic_cast<T<ELEMENT_DIM, SPACE_DIM>* >(p_count_writer.get()))
916 {
917 return true;
918 }
919 }
921 for (boost::shared_ptr<event_writer_t> p_event_writer : mCellPopulationEventWriters)
922 {
923 if (dynamic_cast<T<ELEMENT_DIM, SPACE_DIM>* >(p_event_writer.get()))
924 {
925 return true;
926 }
927 }
928 return false;
929 }
930
936 void SetOutputResultsForChasteVisualizer(bool outputResultsForChasteVisualizer);
937
942 c_vector<double,SPACE_DIM> GetSizeOfCellPopulation();
943
950 virtual bool IsRoomToDivide(CellPtr pCell);
951
959 std::pair<unsigned,unsigned> CreateOrderedPair(unsigned index1, unsigned index2);
960
968 {
969 public:
970
975 inline CellPtr operator*();
976
982 inline CellPtr operator->();
983
991
996 inline Iterator& operator++();
997
1004 Iterator(AbstractCellPopulation& rCellPopulation, std::list<CellPtr>::iterator cellIter);
1005
1009 virtual ~Iterator()
1010 {}
1011
1012 private:
1013
1021 virtual inline bool IsRealCell();
1022
1027 inline bool IsAtEnd();
1028
1031
1033 std::list<CellPtr>::iterator mCellIter;
1034 };
1035
1039 Iterator Begin();
1040
1044 Iterator End();
1045};
1046
1048
1049
1050// Iterator class implementation - most methods are inlined //
1052
1053template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1059
1060template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1062{
1063 assert(!IsAtEnd());
1064 return *mCellIter;
1065}
1066
1067template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1072
1073template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1075{
1076 do
1077 {
1078 ++mCellIter;
1079 }
1080 while (!IsAtEnd() && !IsRealCell());
1081
1082 return (*this);
1083}
1084
1085template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1087{
1088 return !( mrCellPopulation.IsCellAssociatedWithADeletedLocation(*mCellIter) || (*this)->IsDead() );
1089}
1090
1091template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1093{
1094 return mCellIter == mrCellPopulation.rGetCells().end();
1095}
1096
1097template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1099 : mrCellPopulation(rCellPopulation),
1100 mCellIter(cellIter)
1101{
1102 // The cell population can now return empty if it only has ghost nodes
1103 if (mrCellPopulation.rGetCells().empty())
1104 {
1106 }
1107 else
1108 {
1109 // Make sure we start at a real cell
1110 if (mCellIter == mrCellPopulation.rGetCells().begin() && !IsRealCell())
1111 {
1112 ++(*this);
1113 }
1114 }
1115}
1116
1117template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1122
1123template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1128
1129#endif /*ABSTRACTCELLPOPULATION_HPP_*/
#define TEMPLATED_CLASS_IS_ABSTRACT_1_UNSIGNED(T)
Iterator(AbstractCellPopulation &rCellPopulation, std::list< CellPtr >::iterator cellIter)
std::list< CellPtr >::iterator mCellIter
bool operator!=(const typename AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM >::Iterator &rOther)
boost::shared_ptr< CellPropertyRegistry > mpCellPropertyRegistry
std::vector< boost::shared_ptr< AbstractCellPopulationCountWriter< ELEMENT_DIM, SPACE_DIM > > > mCellPopulationCountWriters
virtual double GetVolumeOfCell(CellPtr pCell)=0
std::vector< std::string > GetDivisionsInformation()
void OpenRoundRobinWritersFilesForAppend(OutputFileHandler &rOutputFileHandler)
void AddCellPopulationEventWriter(boost::shared_ptr< AbstractCellPopulationEventWriter< ELEMENT_DIM, SPACE_DIM > > pCellPopulationEventWriter)
void SetCellUsingLocationIndex(unsigned index, CellPtr pCell)
std::vector< std::string > GetRemovalsInformation()
virtual Node< SPACE_DIM > * GetNode(unsigned index)=0
virtual c_vector< double, SPACE_DIM > GetLocationOfCellCentre(CellPtr pCell)=0
virtual void AddCellUsingLocationIndex(unsigned index, CellPtr pCell)
void AddCellWriter(boost::shared_ptr< AbstractCellWriter< ELEMENT_DIM, SPACE_DIM > > pCellWriter)
std::vector< unsigned > GetCellMutationStateCount()
std::list< CellPtr > & rGetCells()
void SetDataOnAllCells(const std::string &rDataName, double dataValue)
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)
std::vector< boost::shared_ptr< AbstractCellWriter< ELEMENT_DIM, SPACE_DIM > > > mCellWriters
virtual bool IsCellAttachedToLocationIndex(unsigned index)
virtual void WriteVtkResultsToFile(const std::string &rDirectory)=0
virtual bool IsRoomToDivide(CellPtr pCell)
AbstractMesh< ELEMENT_DIM, SPACE_DIM > & mrMesh
virtual bool IsPdeNodeAssociatedWithNonApoptoticCell(unsigned pdeNodeIndex)
virtual double GetDefaultTimeStep()=0
std::map< unsigned, std::set< CellPtr > > mLocationCellMap
unsigned GetLocationIndexUsingCell(CellPtr pCell)
void SetOutputResultsForChasteVisualizer(bool outputResultsForChasteVisualizer)
virtual void WriteResultsToFiles(const std::string &rDirectory)
std::set< CellPtr > GetCellsUsingLocationIndex(unsigned index)
void AddCellPopulationCountWriter(boost::shared_ptr< AbstractCellPopulationCountWriter< ELEMENT_DIM, SPACE_DIM > > pCellPopulationCountWriter)
virtual void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > &rNewLocation)=0
c_vector< double, SPACE_DIM > mCentroid
virtual void AcceptPopulationCountWriter(boost::shared_ptr< AbstractCellPopulationCountWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationCountWriter)=0
virtual std::set< unsigned > GetNeighbouringLocationIndices(CellPtr pCell)=0
std::set< unsigned > GetCellAncestors()
virtual void OutputCellPopulationParameters(out_stream &rParamsFile)=0
virtual TetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * GetTetrahedralMeshForPdeModifier()=0
virtual unsigned RemoveDeadCells()=0
virtual std::set< std::pair< unsigned, unsigned > > GetNeighbouringEdgeIndices(CellPtr pCell, unsigned pEdgeIndex)
virtual void SimulationSetupHook(AbstractCellBasedSimulation< ELEMENT_DIM, SPACE_DIM > *pSimulation)
virtual void AcceptPopulationEventWriter(boost::shared_ptr< AbstractCellPopulationEventWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationEventWriter)=0
virtual double GetCellDataItemAtPdeNode(unsigned pdeNodeIndex, std::string &rVariableName, bool dirichletBoundaryConditionApplies=false, double dirichletBoundaryValue=0.0)=0
virtual bool IsCellAssociatedWithADeletedLocation(CellPtr pCell)=0
void AddPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationWriter)
boost::shared_ptr< CellPropertyRegistry > GetCellPropertyRegistry()
std::vector< boost::shared_ptr< AbstractCellPopulationWriter< ELEMENT_DIM, SPACE_DIM > > > mCellPopulationWriters
virtual void WriteDataToVisualizerSetupFile(out_stream &pVizSetupFile)
virtual void Validate()=0
std::vector< std::string > mDivisionsInformation
virtual void Update(bool hasHadBirthsOrDeaths=true)=0
void GenerateRemovalInformation(CellPtr pCell, std::string killerInfo)
std::vector< std::string > mRemovalsInformation
virtual double GetWidth(const unsigned &rDimension)=0
std::map< Cell *, unsigned > mCellLocationMap
virtual unsigned GetNumNodes()=0
virtual void AcceptPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationWriter)=0
std::vector< boost::shared_ptr< AbstractCellPopulationEventWriter< ELEMENT_DIM, SPACE_DIM > > > mCellPopulationEventWriters
void OutputCellPopulationInfo(out_stream &rParamsFile)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
std::vector< unsigned > GetCellCyclePhaseCount()
void serialize(Archive &archive, const unsigned int version)
AbstractMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
void StartApoptosisOnCell(CellPtr pCell, std::string killerInfo)
c_vector< double, SPACE_DIM > GetCentroidOfCellPopulation()
void KillCell(CellPtr pCell, std::string killerInfo)
friend class boost::serialization::access
std::vector< unsigned > GetCellProliferativeTypeCount()
virtual std::set< unsigned > GetNeighbouringNodeIndices(unsigned index)=0
virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell=CellPtr())=0
void AddRemovalInformation(std::string removalInformation)
void SetDefaultCellMutationStateAndProliferativeTypeOrdering()
std::pair< unsigned, unsigned > CreateOrderedPair(unsigned index1, unsigned index2)
void MoveCellInLocationMap(CellPtr pCell, unsigned old_index, unsigned new_index)
c_vector< double, SPACE_DIM > GetSizeOfCellPopulation()
void AddDivisionInformation(std::string divisionInformation)
virtual void AcceptCellWritersAcrossPopulation()
virtual void RemoveCellUsingLocationIndex(unsigned index, CellPtr pCell)
virtual void AcceptCellWriter(boost::shared_ptr< AbstractCellWriter< ELEMENT_DIM, SPACE_DIM > > pCellWriter, CellPtr pCell)=0
Definition Node.hpp:59