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" 50 #include "LegacyCellProliferativeTypesWriter.hpp" 53 #include "CellMutationStatesCountWriter.hpp" 54 #include "CellProliferativePhasesCountWriter.hpp" 55 #include "CellProliferativeTypesCountWriter.hpp" 56 #include "NodeLocationWriter.hpp" 59 #include "WildTypeCellMutationState.hpp" 60 #include "ApcOneHitCellMutationState.hpp" 61 #include "ApcTwoHitCellMutationState.hpp" 62 #include "BetaCateninOneHitCellMutationState.hpp" 63 #include "DefaultCellProliferativeType.hpp" 64 #include "StemCellProliferativeType.hpp" 65 #include "TransitCellProliferativeType.hpp" 66 #include "DifferentiatedCellProliferativeType.hpp" 68 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
70 std::vector<CellPtr>& rCells,
71 const std::vector<unsigned> locationIndices)
73 mCells(rCells.begin(), rCells.end()),
74 mCentroid(zero_vector<
double>(SPACE_DIM)),
76 mOutputResultsForChasteVisualizer(true)
83 std::vector<CellPtr>().swap(rCells);
86 if (!locationIndices.empty())
88 if (
mCells.size() != locationIndices.size())
90 EXCEPTION(
"There is not a one-one correspondence between cells and location indices");
98 std::list<CellPtr>::iterator it =
mCells.begin();
99 for (
unsigned i=0; it !=
mCells.end(); ++it, ++i)
106 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
112 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
117 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
121 cell_iter!=this->
End();
124 cell_iter->InitialiseCellCycleModel();
125 cell_iter->InitialiseSrnModel();
129 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
133 cell_iter!=this->
End();
136 cell_iter->GetCellData()->SetItem(rDataName, dataValue);
140 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
146 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
152 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
155 unsigned counter = 0;
157 cell_iter!=this->
End();
165 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
171 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
177 cell_iter->SetAncestor(p_cell_ancestor);
181 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
184 std::set<unsigned> remaining_ancestors;
187 remaining_ancestors.insert(cell_iter->GetAncestor());
189 return remaining_ancestors;
192 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
195 std::vector<unsigned> mutation_state_count;
196 const std::vector<boost::shared_ptr<AbstractCellProperty> >& r_cell_properties
200 for (
unsigned i=0; i<r_cell_properties.size(); i++)
202 if (r_cell_properties[i]->IsSubType<AbstractCellMutationState>())
204 mutation_state_count.push_back(r_cell_properties[i]->GetCellCount());
212 unsigned local_size = mutation_state_count.size();
213 unsigned global_size;
215 assert(local_size == global_size);
217 std::vector<unsigned> mutation_counts(global_size);
218 MPI_Allreduce(&mutation_state_count[0], &mutation_counts[0], mutation_counts.size(), MPI_UNSIGNED, MPI_SUM,
PetscTools::GetWorld());
220 mutation_state_count = mutation_counts;
223 return mutation_state_count;
226 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
229 std::vector<unsigned> proliferative_type_count;
230 const std::vector<boost::shared_ptr<AbstractCellProperty> >& r_cell_properties
234 for (
unsigned i=0; i<r_cell_properties.size(); i++)
236 if (r_cell_properties[i]->IsSubType<AbstractCellProliferativeType>())
238 proliferative_type_count.push_back(r_cell_properties[i]->GetCellCount());
246 unsigned local_size = proliferative_type_count.size();
247 unsigned global_size;
250 assert(local_size == global_size);
252 std::vector<unsigned> total_types_counts(global_size);
253 MPI_Allreduce(&proliferative_type_count[0], &total_types_counts[0], total_types_counts.size(), MPI_UNSIGNED, MPI_SUM,
PetscTools::GetWorld());
255 proliferative_type_count = total_types_counts;
258 return proliferative_type_count;
261 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
264 std::vector<unsigned> cell_cycle_phase_count(5);
265 for (
unsigned i=0; i<5; i++)
267 cell_cycle_phase_count[i] = 0;
276 if (dynamic_cast<AbstractPhaseBasedCellCycleModel*>((*(this->
Begin()))->GetCellCycleModel()) ==
nullptr)
278 EXCEPTION(
"You are trying to record the cell cycle phase of cells with a non phase based cell cycle model.");
282 cell_iter != this->
End();
285 switch (static_cast<AbstractPhaseBasedCellCycleModel*>((*cell_iter)->GetCellCycleModel())->GetCurrentCellCyclePhase())
288 cell_cycle_phase_count[0]++;
291 cell_cycle_phase_count[1]++;
294 cell_cycle_phase_count[2]++;
297 cell_cycle_phase_count[3]++;
300 cell_cycle_phase_count[4]++;
311 std::vector<unsigned> phase_counts(cell_cycle_phase_count.size(), 0u);
312 MPI_Allreduce(&cell_cycle_phase_count[0], &phase_counts[0], phase_counts.size(), MPI_UNSIGNED, MPI_SUM,
PetscTools::GetWorld());
314 cell_cycle_phase_count = phase_counts;
317 return cell_cycle_phase_count;
320 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
327 if (cells.size() == 1)
329 return *(cells.begin());
333 EXCEPTION(
"Location index input argument does not correspond to a Cell");
337 EXCEPTION(
"Multiple cells are attached to a single location index.");
341 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
348 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
355 return !(cells.empty());
358 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
363 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
377 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
384 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
387 std::set<CellPtr>::iterator cell_iter =
mLocationCellMap[index].find(pCell);
391 EXCEPTION(
"Tried to remove a cell which is not attached to the given location index");
400 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
410 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
419 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
425 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
429 if (!p_registry->HasOrderingBeenSpecified())
431 std::vector<boost::shared_ptr<AbstractCellProperty> > mutations_and_proliferative_types;
442 p_registry->SpecifyOrdering(mutations_and_proliferative_types);
446 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
449 mCentroid = zero_vector<double>(SPACE_DIM);
451 cell_iter != this->
End();
461 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
466 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
470 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
482 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
486 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
504 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
510 *
mpVtkMetaFile <<
"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\" compressor=\"vtkZLibDataCompressor\">\n";
516 if (!HasWriter<NodeLocationWriter>())
518 AddPopulationWriter<NodeLocationWriter>();
520 if (!HasWriter<BoundaryNodeWriter>())
522 AddPopulationWriter<BoundaryNodeWriter>();
524 if (!HasWriter<CellProliferativeTypesWriter>())
526 AddCellWriter<CellProliferativeTypesWriter>();
528 if (!HasWriter<LegacyCellProliferativeTypesWriter>())
530 AddCellWriter<LegacyCellProliferativeTypesWriter>();
536 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
546 p_pop_writer->WriteHeader(
this);
554 p_count_writer->WriteHeader(
this);
558 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
563 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
569 p_pop_writer->OpenOutputFileForAppend(rOutputFileHandler);
573 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
592 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
594 p_cell_writer->WriteTimeStamp();
598 p_pop_writer->WriteTimeStamp();
614 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer,
mCellWriters)
616 p_cell_writer->WriteNewline();
620 p_pop_writer->WriteNewline();
636 p_count_writer->WriteTimeStamp();
651 p_count_writer->WriteNewline();
652 p_count_writer->CloseFile();
664 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
668 cell_iter != this->
End();
680 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
685 *rParamsFile <<
"\t<" << cell_population_type <<
">\n";
687 *rParamsFile <<
"\t</" << cell_population_type <<
">\n";
688 *rParamsFile <<
"\n";
689 *rParamsFile <<
"\t<CellCycleModels>\n";
697 std::set<std::string> unique_cell_cycle_models;
698 std::vector<CellPtr> first_cell_with_unique_CCM;
700 cell_iter != this->
End();
703 std::string identifier = cell_iter->GetCellCycleModel()->GetIdentifier();
704 if (unique_cell_cycle_models.count(identifier) == 0)
706 unique_cell_cycle_models.insert(identifier);
707 first_cell_with_unique_CCM.push_back((*cell_iter));
712 for (
unsigned i=0; i<first_cell_with_unique_CCM.size(); i++)
715 first_cell_with_unique_CCM[i]->GetCellCycleModel()->OutputCellCycleModelInfo(rParamsFile);
717 *rParamsFile <<
"\t</CellCycleModels>\n";
719 *rParamsFile <<
"\n";
720 *rParamsFile <<
"\t<SrnModels>\n";
728 std::set<std::string> unique_srn_models;
729 std::vector<CellPtr> first_cell_with_unique_SRN;
731 cell_iter != this->
End();
734 std::string identifier = cell_iter->GetSrnModel()->GetIdentifier();
735 if (unique_srn_models.count(identifier) == 0)
737 unique_srn_models.insert(identifier);
738 first_cell_with_unique_SRN.push_back((*cell_iter));
743 for (
unsigned i=0; i<first_cell_with_unique_SRN.size(); i++)
746 first_cell_with_unique_SRN[i]->GetSrnModel()->OutputSrnModelInfo(rParamsFile);
749 *rParamsFile <<
"\t</SrnModels>\n";
752 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
758 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
763 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
769 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
775 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
781 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
788 c_vector<double,SPACE_DIM> max_distance_from_centre = zero_vector<double>(SPACE_DIM);
790 cell_iter != this->
End();
796 c_vector<double,SPACE_DIM> displacement;
797 displacement = centre - cell_location;
799 for (
unsigned i=0; i<SPACE_DIM; i++)
801 if (displacement[i] > max_distance_from_centre[i])
803 max_distance_from_centre[i] = displacement[i];
808 return max_distance_from_centre;
811 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
814 assert(index1 != index2);
816 std::pair<unsigned, unsigned> ordered_pair;
819 ordered_pair.first = index1;
820 ordered_pair.second = index2;
824 ordered_pair.first = index2;
825 ordered_pair.second = index1;
830 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
833 bool non_apoptotic_cell_present =
false;
837 non_apoptotic_cell_present = !(
GetCellUsingLocationIndex(pdeNodeIndex)->template HasCellProperty<ApoptoticCellProperty>());
840 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()
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
std::string GetIdentifier() const
boost::shared_ptr< CellPropertyRegistry > GetCellPropertyRegistry()
void OpenRoundRobinWritersFilesForAppend(OutputFileHandler &rOutputFileHandler)
out_stream OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const
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()
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()