Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
AbstractCellPopulation.hpp
1/*
2
3Copyright (c) 2005-2024, 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#include <boost/foreach.hpp>
57
58#include "AbstractMesh.hpp"
59#include "TetrahedralMesh.hpp"
60#include "CellPropertyRegistry.hpp"
61#include "Identifiable.hpp"
62#include "AbstractCellPopulationEventWriter.hpp"
63#include "AbstractCellPopulationCountWriter.hpp"
64#include "AbstractCellPopulationWriter.hpp"
65#include "AbstractCellWriter.hpp"
66
67// Forward declaration prevents circular include chain
68template<unsigned ELEMENT_DIM, unsigned SPACE_DIM> class AbstractCellBasedSimulation;
77#ifdef DOXYGEN_CHASTE_ISSUE_199 // See https://github.com/Chaste/Chaste/issues/199
78template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
79#else
80template<unsigned ELEMENT_DIM, unsigned SPACE_DIM = ELEMENT_DIM>
81#endif
83{
84private:
85
88
95 template<class Archive>
96 void serialize(Archive & archive, const unsigned int version)
97 {
98 archive & mCells;
99 archive & mLocationCellMap;
100 archive & mCellLocationMap;
101 archive & mpCellPropertyRegistry;
103 archive & mCellWriters;
104 archive & mCellPopulationWriters;
106 }
107
117
126
127protected:
128
130 std::map<unsigned, std::set<CellPtr> > mLocationCellMap;
131
133 std::map<Cell*, unsigned> mCellLocationMap;
134
137
139 std::list<CellPtr> mCells;
140
142 c_vector<double, SPACE_DIM> mCentroid;
143
145 out_stream mpVtkMetaFile;
146
148 boost::shared_ptr<CellPropertyRegistry> mpCellPropertyRegistry;
149
152
154 std::vector<boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > > mCellWriters;
155
157 std::vector<boost::shared_ptr<AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM> > > mCellPopulationWriters;
158
160 std::vector<boost::shared_ptr<AbstractCellPopulationCountWriter<ELEMENT_DIM, SPACE_DIM> > > mCellPopulationCountWriters;
161
163 std::vector<boost::shared_ptr<AbstractCellPopulationEventWriter<ELEMENT_DIM, SPACE_DIM> > > mCellPopulationEventWriters;
164
169 std::vector<std::string> mDivisionsInformation;
170
175 std::vector<std::string> mRemovalsInformation;
176
183 virtual void Validate()=0;
184
193 virtual void WriteVtkResultsToFile(const std::string& rDirectory)=0;
194
201
209
210public:
211
224 std::vector<CellPtr>& rCells,
225 const std::vector<unsigned> locationIndices=std::vector<unsigned>());
226
230 virtual ~AbstractCellPopulation();
231
235 void InitialiseCells();
236
242 void SetDataOnAllCells(const std::string& rDataName, double dataValue);
243
248
257
268 virtual bool IsPdeNodeAssociatedWithNonApoptoticCell(unsigned pdeNodeIndex);
269
286 virtual double GetCellDataItemAtPdeNode(unsigned pdeNodeIndex,
287 std::string& rVariableName,
288 bool dirichletBoundaryConditionApplies=false,
289 double dirichletBoundaryValue=0.0)=0;
290
294 std::list<CellPtr>& rGetCells();
295
302 virtual unsigned GetNumNodes()=0;
303
313 virtual c_vector<double, SPACE_DIM> GetLocationOfCellCentre(CellPtr pCell)=0;
314
324 virtual Node<SPACE_DIM>* GetNode(unsigned index)=0;
325
335 virtual void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM>& rNewLocation)=0;
336
347 virtual bool IsCellAssociatedWithADeletedLocation(CellPtr pCell)=0;
348
355 virtual void WriteDataToVisualizerSetupFile(out_stream& pVizSetupFile);
356
368 virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell=CellPtr())=0;
369
380 virtual double GetDefaultTimeStep()=0;
381
382 class Iterator; // Forward declaration; see below
383
392 virtual unsigned RemoveDeadCells()=0;
393
403 virtual void Update(bool hasHadBirthsOrDeaths=true)=0;
404
414 std::vector<unsigned> GetCellMutationStateCount();
415
425 std::vector<unsigned> GetCellProliferativeTypeCount();
426
437 std::vector<unsigned> GetCellCyclePhaseCount();
438
445 unsigned GetNumRealCells();
446
453 unsigned GetNumAllCells();
454
460
467 std::set<unsigned> GetCellAncestors();
468
479 virtual CellPtr GetCellUsingLocationIndex(unsigned index);
480
490 std::set<CellPtr> GetCellsUsingLocationIndex(unsigned index);
491
499 virtual bool IsCellAttachedToLocationIndex(unsigned index);
500
511 void SetCellUsingLocationIndex(unsigned index, CellPtr pCell);
512
519 virtual void AddCellUsingLocationIndex(unsigned index, CellPtr pCell);
520
527 virtual void RemoveCellUsingLocationIndex(unsigned index, CellPtr pCell);
528
536 void MoveCellInLocationMap(CellPtr pCell, unsigned old_index, unsigned new_index);
537
547 unsigned GetLocationIndexUsingCell(CellPtr pCell);
548
552 boost::shared_ptr<CellPropertyRegistry> GetCellPropertyRegistry();
553
559
569 virtual double GetWidth(const unsigned& rDimension)=0;
570
578 virtual double GetVolumeOfCell(CellPtr pCell)=0;
579
589 virtual std::set<unsigned> GetNeighbouringNodeIndices(unsigned index)=0;
590
600 virtual std::set<unsigned> GetNeighbouringLocationIndices(CellPtr pCell)=0;
601
608 virtual std::set<std::pair<unsigned, unsigned>> GetNeighbouringEdgeIndices(CellPtr pCell, unsigned pEdgeIndex);
609
613 c_vector<double, SPACE_DIM> GetCentroidOfCellPopulation();
614
618 virtual void UpdateCellProcessLocation();
619
633 virtual void OpenWritersFiles(OutputFileHandler& rOutputFileHandler);
634
641 virtual void CloseWritersFiles();
642
648 virtual void WriteResultsToFiles(const std::string& rDirectory);
649
658 virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationWriter)=0;
659
668 virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationCountWriter)=0;
669
678 virtual void AcceptPopulationEventWriter(boost::shared_ptr<AbstractCellPopulationEventWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationEventWriter)=0;
679
689 virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > pCellWriter, CellPtr pCell) = 0;
690
696 std::vector<std::string> GetDivisionsInformation();
697
705 void AddDivisionInformation(std::string divisionInformation);
706
711
717 std::vector<std::string> GetRemovalsInformation();
718
724 void AddRemovalInformation(std::string removalInformation);
725
730
737 void GenerateRemovalInformation(CellPtr pCell, std::string killerInfo);
738
745 void KillCell(CellPtr pCell, std::string killerInfo);
746
753 void StartApoptosisOnCell(CellPtr pCell, std::string killerInfo);
754
760 void OutputCellPopulationInfo(out_stream& rParamsFile);
761
770 virtual void OutputCellPopulationParameters(out_stream& rParamsFile)=0;
771
787
792
798 template<template <unsigned, unsigned> class T>
800 {
801 mCellPopulationWriters.push_back(boost::shared_ptr< T<ELEMENT_DIM, SPACE_DIM> >(new T<ELEMENT_DIM, SPACE_DIM> ));
802 }
803
809 template<template <unsigned, unsigned> class T>
811 {
812 mCellWriters.push_back(boost::shared_ptr< T<ELEMENT_DIM, SPACE_DIM> >(new T<ELEMENT_DIM, SPACE_DIM> ));
813 }
814
820 template<template <unsigned, unsigned> class T>
822 {
823 mCellPopulationCountWriters.push_back(boost::shared_ptr< T<ELEMENT_DIM, SPACE_DIM> >(new T<ELEMENT_DIM, SPACE_DIM> ));
824 }
825
831 template<template <unsigned, unsigned> class T>
833 {
834 mCellPopulationEventWriters.push_back(boost::shared_ptr< T<ELEMENT_DIM, SPACE_DIM> >(new T<ELEMENT_DIM, SPACE_DIM> ));
835 }
836
846 {
847 mCellPopulationWriters.push_back(pPopulationWriter);
848 }
849
858 void AddCellWriter(boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > pCellWriter)
859 {
860 mCellWriters.push_back(pCellWriter);
861 }
862
872 {
873 mCellPopulationCountWriters.push_back(pCellPopulationCountWriter);
874 }
875
885 {
886 mCellPopulationEventWriters.push_back(pCellPopulationEventWriter);
887 }
888
894 template<template <unsigned, unsigned> class T>
895 bool HasWriter() const
896 {
898 BOOST_FOREACH(boost::shared_ptr<population_writer_t> p_pop_writer, mCellPopulationWriters)
899 {
900 if (dynamic_cast<T<ELEMENT_DIM, SPACE_DIM>* >(p_pop_writer.get()))
901 {
902 return true;
903 }
904 }
905 typedef AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> cell_writer_t;
906 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer, mCellWriters)
907 {
908 if (dynamic_cast<T<ELEMENT_DIM, SPACE_DIM>* >(p_cell_writer.get()))
909 {
910 return true;
911 }
912 }
914 BOOST_FOREACH(boost::shared_ptr<count_writer_t> p_count_writer, mCellPopulationCountWriters)
915 {
916 if (dynamic_cast<T<ELEMENT_DIM, SPACE_DIM>* >(p_count_writer.get()))
917 {
918 return true;
919 }
920 }
922 BOOST_FOREACH(boost::shared_ptr<event_writer_t> p_event_writer, mCellPopulationEventWriters)
923 {
924 if (dynamic_cast<T<ELEMENT_DIM, SPACE_DIM>* >(p_event_writer.get()))
925 {
926 return true;
927 }
928 }
929 return false;
930 }
931
937 void SetOutputResultsForChasteVisualizer(bool outputResultsForChasteVisualizer);
938
943 c_vector<double,SPACE_DIM> GetSizeOfCellPopulation();
944
951 virtual bool IsRoomToDivide(CellPtr pCell);
952
960 std::pair<unsigned,unsigned> CreateOrderedPair(unsigned index1, unsigned index2);
961
969 {
970 public:
971
976 inline CellPtr operator*();
977
983 inline CellPtr operator->();
984
992
997 inline Iterator& operator++();
998
1005 Iterator(AbstractCellPopulation& rCellPopulation, std::list<CellPtr>::iterator cellIter);
1006
1010 virtual ~Iterator()
1011 {}
1012
1013 private:
1014
1022 virtual inline bool IsRealCell();
1023
1028 inline bool IsAtEnd();
1029
1032
1034 std::list<CellPtr>::iterator mCellIter;
1035 };
1036
1040 Iterator Begin();
1041
1045 Iterator End();
1046};
1047
1049
1050
1051// Iterator class implementation - most methods are inlined //
1053
1054template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1060
1061template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1063{
1064 assert(!IsAtEnd());
1065 return *mCellIter;
1066}
1067
1068template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1073
1074template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1076{
1077 do
1078 {
1079 ++mCellIter;
1080 }
1081 while (!IsAtEnd() && !IsRealCell());
1082
1083 return (*this);
1084}
1085
1086template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1088{
1089 return !( mrCellPopulation.IsCellAssociatedWithADeletedLocation(*mCellIter) || (*this)->IsDead() );
1090}
1091
1092template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1094{
1095 return mCellIter == mrCellPopulation.rGetCells().end();
1096}
1097
1098template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1100 : mrCellPopulation(rCellPopulation),
1101 mCellIter(cellIter)
1102{
1103 // The cell population can now return empty if it only has ghost nodes
1104 if (mrCellPopulation.rGetCells().empty())
1105 {
1107 }
1108 else
1109 {
1110 // Make sure we start at a real cell
1111 if (mCellIter == mrCellPopulation.rGetCells().begin() && !IsRealCell())
1112 {
1113 ++(*this);
1114 }
1115 }
1116}
1117
1118template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1123
1124template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
1129
1130#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