36 #include <boost/bind.hpp> 41 #include "AbstractCellPopulation.hpp" 42 #include "AbstractPhaseBasedCellCycleModel.hpp" 44 #include "CellAncestor.hpp" 45 #include "ApoptoticCellProperty.hpp" 48 #include "BoundaryNodeWriter.hpp" 49 #include "CellProliferativeTypesWriter.hpp" 52 #include "CellMutationStatesCountWriter.hpp" 53 #include "CellProliferativePhasesCountWriter.hpp" 54 #include "CellProliferativeTypesCountWriter.hpp" 55 #include "NodeLocationWriter.hpp" 58 #include "WildTypeCellMutationState.hpp" 59 #include "ApcOneHitCellMutationState.hpp" 60 #include "ApcTwoHitCellMutationState.hpp" 61 #include "BetaCateninOneHitCellMutationState.hpp" 62 #include "DefaultCellProliferativeType.hpp" 63 #include "StemCellProliferativeType.hpp" 64 #include "TransitCellProliferativeType.hpp" 65 #include "DifferentiatedCellProliferativeType.hpp" 67 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
69 std::vector<CellPtr>& rCells,
70 const std::vector<unsigned> locationIndices)
72 mCells(rCells.begin(), rCells.end()),
73 mCentroid(zero_vector<
double>(SPACE_DIM)),
75 mOutputResultsForChasteVisualizer(true)
82 std::vector<CellPtr>().swap(rCells);
85 if (!locationIndices.empty())
87 if (
mCells.size() != locationIndices.size())
89 EXCEPTION(
"There is not a one-one correspondence between cells and location indices");
97 std::list<CellPtr>::iterator it =
mCells.begin();
98 for (
unsigned i=0; it !=
mCells.end(); ++it, ++i)
105 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
111 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
116 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
120 cell_iter!=this->
End();
123 cell_iter->InitialiseCellCycleModel();
124 cell_iter->InitialiseSrnModel();
128 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
132 cell_iter!=this->
End();
135 cell_iter->GetCellData()->SetItem(rDataName, dataValue);
139 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
145 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
151 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
154 unsigned counter = 0;
156 cell_iter!=this->
End();
164 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
170 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
176 cell_iter->SetAncestor(p_cell_ancestor);
180 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
183 std::set<unsigned> remaining_ancestors;
186 remaining_ancestors.insert(cell_iter->GetAncestor());
188 return remaining_ancestors;
191 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
194 std::vector<unsigned> mutation_state_count;
195 const std::vector<boost::shared_ptr<AbstractCellProperty> >& r_cell_properties
199 for (
unsigned i=0; i<r_cell_properties.size(); i++)
201 if (r_cell_properties[i]->IsSubType<AbstractCellMutationState>())
203 mutation_state_count.push_back(r_cell_properties[i]->GetCellCount());
211 unsigned local_size = mutation_state_count.size();
212 unsigned global_size;
214 assert(local_size == global_size);
216 std::vector<unsigned> mutation_counts(global_size);
217 MPI_Allreduce(&mutation_state_count[0], &mutation_counts[0], mutation_counts.size(), MPI_UNSIGNED, MPI_SUM,
PetscTools::GetWorld());
219 mutation_state_count = mutation_counts;
222 return mutation_state_count;
225 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
228 std::vector<unsigned> proliferative_type_count;
229 const std::vector<boost::shared_ptr<AbstractCellProperty> >& r_cell_properties
233 for (
unsigned i=0; i<r_cell_properties.size(); i++)
235 if (r_cell_properties[i]->IsSubType<AbstractCellProliferativeType>())
237 proliferative_type_count.push_back(r_cell_properties[i]->GetCellCount());
245 unsigned local_size = proliferative_type_count.size();
246 unsigned global_size;
249 assert(local_size == global_size);
251 std::vector<unsigned> total_types_counts(global_size);
252 MPI_Allreduce(&proliferative_type_count[0], &total_types_counts[0], total_types_counts.size(), MPI_UNSIGNED, MPI_SUM,
PetscTools::GetWorld());
254 proliferative_type_count = total_types_counts;
257 return proliferative_type_count;
260 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
263 std::vector<unsigned> cell_cycle_phase_count(5);
264 for (
unsigned i=0; i<5; i++)
266 cell_cycle_phase_count[i] = 0;
275 if (dynamic_cast<AbstractPhaseBasedCellCycleModel*>((*(this->
Begin()))->GetCellCycleModel()) ==
nullptr)
277 EXCEPTION(
"You are trying to record the cell cycle phase of cells with a non phase based cell cycle model.");
281 cell_iter != this->
End();
284 switch (static_cast<AbstractPhaseBasedCellCycleModel*>((*cell_iter)->GetCellCycleModel())->GetCurrentCellCyclePhase())
287 cell_cycle_phase_count[0]++;
290 cell_cycle_phase_count[1]++;
293 cell_cycle_phase_count[2]++;
296 cell_cycle_phase_count[3]++;
299 cell_cycle_phase_count[4]++;
310 std::vector<unsigned> phase_counts(cell_cycle_phase_count.size(), 0u);
311 MPI_Allreduce(&cell_cycle_phase_count[0], &phase_counts[0], phase_counts.size(), MPI_UNSIGNED, MPI_SUM,
PetscTools::GetWorld());
313 cell_cycle_phase_count = phase_counts;
316 return cell_cycle_phase_count;
319 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
326 if (cells.size() == 1)
328 return *(cells.begin());
332 EXCEPTION(
"Location index input argument does not correspond to a Cell");
336 EXCEPTION(
"Multiple cells are attached to a single location index.");
340 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
347 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
354 return !(cells.empty());
357 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
362 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
376 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
383 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
386 std::set<CellPtr>::iterator cell_iter =
mLocationCellMap[index].find(pCell);
390 EXCEPTION(
"Tried to remove a cell which is not attached to the given location index");
399 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
409 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
418 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
424 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
428 if (!p_registry->HasOrderingBeenSpecified())
430 std::vector<boost::shared_ptr<AbstractCellProperty> > mutations_and_proliferative_types;
441 p_registry->SpecifyOrdering(mutations_and_proliferative_types);
445 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
448 mCentroid = zero_vector<double>(SPACE_DIM);
450 cell_iter != this->
End();
460 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
465 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
469 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
481 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
485 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
503 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
509 *
mpVtkMetaFile <<
"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\" compressor=\"vtkZLibDataCompressor\">\n";
515 if (!HasWriter<NodeLocationWriter>())
517 AddPopulationWriter<NodeLocationWriter>();
519 if (!HasWriter<BoundaryNodeWriter>())
521 AddPopulationWriter<BoundaryNodeWriter>();
523 if (!HasWriter<CellProliferativeTypesWriter>())
525 AddCellWriter<CellProliferativeTypesWriter>();
531 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
541 p_pop_writer->WriteHeader(
this);
549 p_count_writer->WriteHeader(
this);
553 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
558 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
564 p_pop_writer->OpenOutputFileForAppend(rOutputFileHandler);
568 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
587 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
589 p_cell_writer->WriteTimeStamp();
593 p_pop_writer->WriteTimeStamp();
609 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
611 p_cell_writer->WriteNewline();
615 p_pop_writer->WriteNewline();
631 p_count_writer->WriteTimeStamp();
646 p_count_writer->WriteNewline();
647 p_count_writer->CloseFile();
659 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
663 cell_iter != this->
End();
675 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
680 *rParamsFile <<
"\t<" << cell_population_type <<
">\n";
682 *rParamsFile <<
"\t</" << cell_population_type <<
">\n";
683 *rParamsFile <<
"\n";
684 *rParamsFile <<
"\t<CellCycleModels>\n";
692 std::set<std::string> unique_cell_cycle_models;
693 std::vector<CellPtr> first_cell_with_unique_CCM;
695 cell_iter != this->
End();
698 std::string identifier = cell_iter->GetCellCycleModel()->GetIdentifier();
699 if (unique_cell_cycle_models.count(identifier) == 0)
701 unique_cell_cycle_models.insert(identifier);
702 first_cell_with_unique_CCM.push_back((*cell_iter));
707 for (
unsigned i=0; i<first_cell_with_unique_CCM.size(); i++)
710 first_cell_with_unique_CCM[i]->GetCellCycleModel()->OutputCellCycleModelInfo(rParamsFile);
712 *rParamsFile <<
"\t</CellCycleModels>\n";
714 *rParamsFile <<
"\n";
715 *rParamsFile <<
"\t<SrnModels>\n";
723 std::set<std::string> unique_srn_models;
724 std::vector<CellPtr> first_cell_with_unique_SRN;
726 cell_iter != this->
End();
729 std::string identifier = cell_iter->GetSrnModel()->GetIdentifier();
730 if (unique_srn_models.count(identifier) == 0)
732 unique_srn_models.insert(identifier);
733 first_cell_with_unique_SRN.push_back((*cell_iter));
738 for (
unsigned i=0; i<first_cell_with_unique_SRN.size(); i++)
741 first_cell_with_unique_SRN[i]->GetSrnModel()->OutputSrnModelInfo(rParamsFile);
744 *rParamsFile <<
"\t</SrnModels>\n";
747 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
753 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
758 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
764 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
770 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
776 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
783 c_vector<double,SPACE_DIM> max_distance_from_centre = zero_vector<double>(SPACE_DIM);
785 cell_iter != this->
End();
791 c_vector<double,SPACE_DIM> displacement;
792 displacement = centre - cell_location;
794 for (
unsigned i=0; i<SPACE_DIM; i++)
796 if (displacement[i] > max_distance_from_centre[i])
798 max_distance_from_centre[i] = displacement[i];
803 return max_distance_from_centre;
806 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
809 assert(index1 != index2);
811 std::pair<unsigned, unsigned> ordered_pair;
814 ordered_pair.first = index1;
815 ordered_pair.second = index2;
819 ordered_pair.first = index2;
820 ordered_pair.second = index1;
825 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
828 bool non_apoptotic_cell_present =
false;
832 non_apoptotic_cell_present = !(
GetCellUsingLocationIndex(pdeNodeIndex)->template HasCellProperty<ApoptoticCellProperty>());
835 return non_apoptotic_cell_present;
virtual void AcceptPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationWriter)=0
virtual void SimulationSetupHook(AbstractCellBasedSimulation< ELEMENT_DIM, SPACE_DIM > *pSimulation)
c_vector< double, SPACE_DIM > GetCentroidOfCellPopulation()
std::vector< boost::shared_ptr< AbstractCellPopulationWriter< ELEMENT_DIM, SPACE_DIM > > > mCellPopulationWriters
void OpenOutputFileForAppend(OutputFileHandler &rOutputFileHandler)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
void SetDefaultCellMutationStateAndProliferativeTypeOrdering()
unsigned GetLocationIndexUsingCell(CellPtr pCell)
virtual void UpdateCellProcessLocation()
std::vector< boost::shared_ptr< AbstractCellWriter< ELEMENT_DIM, SPACE_DIM > > > mCellWriters
void SetDataOnAllCells(const std::string &rDataName, double dataValue)
boost::shared_ptr< CellPropertyRegistry > mpCellPropertyRegistry
virtual void RemoveCellUsingLocationIndex(unsigned index, CellPtr pCell)
c_vector< double, SPACE_DIM > mCentroid
virtual void OutputCellPopulationParameters(out_stream &rParamsFile)=0
#define EXCEPTION(message)
std::vector< boost::shared_ptr< AbstractCellPopulationCountWriter< ELEMENT_DIM, SPACE_DIM > > > mCellPopulationCountWriters
void SetCellAncestorsToLocationIndices()
std::set< CellPtr > GetCellsUsingLocationIndex(unsigned index)
unsigned GetNumRealCells()
virtual bool IsCellAttachedToLocationIndex(unsigned index)
unsigned GetNumAllCells()
virtual void WriteResultsToFiles(const std::string &rDirectory)
void SetOutputResultsForChasteVisualizer(bool outputResultsForChasteVisualizer)
void MoveCellInLocationMap(CellPtr pCell, unsigned old_index, unsigned new_index)
bool mOutputResultsForChasteVisualizer
std::list< CellPtr > & rGetCells()
std::vector< unsigned > GetCellCyclePhaseCount()
out_stream OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const
virtual void AcceptPopulationCountWriter(boost::shared_ptr< AbstractCellPopulationCountWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationCountWriter)=0
c_vector< double, SPACE_DIM > GetSizeOfCellPopulation()
virtual void AcceptCellWritersAcrossPopulation()
std::pair< unsigned, unsigned > CreateOrderedPair(unsigned index1, unsigned index2)
std::map< unsigned, std::set< CellPtr > > mLocationCellMap
void SetCellUsingLocationIndex(unsigned index, CellPtr pCell)
std::map< Cell *, unsigned > mCellLocationMap
virtual void AcceptCellWriter(boost::shared_ptr< AbstractCellWriter< ELEMENT_DIM, SPACE_DIM > > pCellWriter, CellPtr pCell)=0
boost::shared_ptr< CellPropertyRegistry > GetCellPropertyRegistry()
void OpenRoundRobinWritersFilesForAppend(OutputFileHandler &rOutputFileHandler)
virtual bool IsPdeNodeAssociatedWithNonApoptoticCell(unsigned pdeNodeIndex)
virtual c_vector< double, SPACE_DIM > GetLocationOfCellCentre(CellPtr pCell)=0
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)
std::list< CellPtr > mCells
void OutputCellPopulationInfo(out_stream &rParamsFile)
virtual bool IsRoomToDivide(CellPtr pCell)
AbstractMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
virtual void WriteDataToVisualizerSetupFile(out_stream &pVizSetupFile)
bool GetOutputResultsForChasteVisualizer()
std::string GetIdentifier() const
virtual void OpenOutputFile(OutputFileHandler &rOutputFileHandler)
AbstractCellPopulation(AbstractMesh< ELEMENT_DIM, SPACE_DIM > &rMesh)
virtual void AddCellUsingLocationIndex(unsigned index, CellPtr pCell)
std::vector< unsigned > GetCellProliferativeTypeCount()
AbstractMesh< ELEMENT_DIM, SPACE_DIM > & mrMesh
virtual ~AbstractCellPopulation()
#define MAKE_PTR_ARGS(TYPE, NAME, ARGS)
virtual void WriteVtkResultsToFile(const std::string &rDirectory)=0
void CloseRoundRobinWritersFiles()
std::vector< unsigned > GetCellMutationStateCount()
std::set< unsigned > GetCellAncestors()