39#include "AbstractCellPopulation.hpp"
40#include "AbstractPhaseBasedCellCycleModel.hpp"
42#include "CellAncestor.hpp"
43#include "ApoptoticCellProperty.hpp"
46#include "BoundaryNodeWriter.hpp"
47#include "CellProliferativeTypesWriter.hpp"
48#include "LegacyCellProliferativeTypesWriter.hpp"
49#include "CellRemovalLocationsWriter.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"
67template<
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)
109template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
115template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
120template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
124 cell_iter!=this->End();
127 cell_iter->InitialiseCellCycleModel();
128 cell_iter->InitialiseSrnModel();
132template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
136 cell_iter!=this->End();
139 cell_iter->GetCellData()->SetItem(rDataName, dataValue);
143template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
149template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
155template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
158 unsigned counter = 0;
160 cell_iter!=this->End();
168template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
171 return mCells.size();
174template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
180 cell_iter->SetAncestor(p_cell_ancestor);
184template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
187 std::set<unsigned> remaining_ancestors;
190 remaining_ancestors.insert(cell_iter->GetAncestor());
192 return remaining_ancestors;
195template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
198 std::vector<unsigned> mutation_state_count;
199 const std::vector<boost::shared_ptr<AbstractCellProperty> >& r_cell_properties
200 = mpCellPropertyRegistry->rGetAllCellProperties();
203 for (
unsigned i=0; i<r_cell_properties.size(); i++)
205 if (r_cell_properties[i]->IsSubType<AbstractCellMutationState>())
207 mutation_state_count.push_back(r_cell_properties[i]->GetCellCount());
215 unsigned local_size = mutation_state_count.size();
216 unsigned global_size;
218 assert(local_size == global_size);
220 std::vector<unsigned> mutation_counts(global_size);
221 MPI_Allreduce(&mutation_state_count[0], &mutation_counts[0], mutation_counts.size(), MPI_UNSIGNED, MPI_SUM,
PetscTools::GetWorld());
223 mutation_state_count = mutation_counts;
226 return mutation_state_count;
229template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
232 std::vector<unsigned> proliferative_type_count;
233 const std::vector<boost::shared_ptr<AbstractCellProperty> >& r_cell_properties
234 = mpCellPropertyRegistry->rGetAllCellProperties();
237 for (
unsigned i=0; i<r_cell_properties.size(); i++)
239 if (r_cell_properties[i]->IsSubType<AbstractCellProliferativeType>())
241 proliferative_type_count.push_back(r_cell_properties[i]->GetCellCount());
249 unsigned local_size = proliferative_type_count.size();
250 unsigned global_size;
253 assert(local_size == global_size);
255 std::vector<unsigned> total_types_counts(global_size);
256 MPI_Allreduce(&proliferative_type_count[0], &total_types_counts[0], total_types_counts.size(), MPI_UNSIGNED, MPI_SUM,
PetscTools::GetWorld());
258 proliferative_type_count = total_types_counts;
261 return proliferative_type_count;
264template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
267 std::vector<unsigned> cell_cycle_phase_count(5);
268 for (
unsigned i=0; i<5; i++)
270 cell_cycle_phase_count[i] = 0;
277 if (GetNumAllCells() > 0u)
281 EXCEPTION(
"You are trying to record the cell cycle phase of cells with a non phase based cell cycle model.");
285 cell_iter != this->End();
291 cell_cycle_phase_count[0]++;
294 cell_cycle_phase_count[1]++;
297 cell_cycle_phase_count[2]++;
300 cell_cycle_phase_count[3]++;
303 cell_cycle_phase_count[4]++;
314 std::vector<unsigned> phase_counts(cell_cycle_phase_count.size(), 0u);
315 MPI_Allreduce(&cell_cycle_phase_count[0], &phase_counts[0], phase_counts.size(), MPI_UNSIGNED, MPI_SUM,
PetscTools::GetWorld());
317 cell_cycle_phase_count = phase_counts;
320 return cell_cycle_phase_count;
323template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
327 std::set<CellPtr> cells = mLocationCellMap[index];
330 if (cells.size() == 1)
332 return *(cells.begin());
336 EXCEPTION(
"Location index input argument does not correspond to a Cell");
340 EXCEPTION(
"Multiple cells are attached to a single location index.");
344template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
348 return mLocationCellMap[index];
351template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
355 std::set<CellPtr> cells = mLocationCellMap[index];
358 return !(cells.empty());
361template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
366template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
370 mLocationCellMap[index].clear();
371 mCellLocationMap.erase(pCell.get());
374 mLocationCellMap[index].insert(pCell);
377 mCellLocationMap[pCell.get()] = index;
380template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
383 mLocationCellMap[index].insert(pCell);
384 mCellLocationMap[pCell.get()] = index;
387template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
390 std::set<CellPtr>::iterator cell_iter = mLocationCellMap[index].find(pCell);
392 if (cell_iter == mLocationCellMap[index].end())
394 EXCEPTION(
"Tried to remove a cell which is not attached to the given location index");
398 mLocationCellMap[index].erase(cell_iter);
399 mCellLocationMap.erase(pCell.get());
403template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
407 RemoveCellUsingLocationIndex(old_index, pCell);
410 AddCellUsingLocationIndex(new_index, pCell);
413template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
417 assert(this->mCellLocationMap.find(pCell.get()) != this->mCellLocationMap.end());
419 return mCellLocationMap[pCell.get()];
422template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
425 return mpCellPropertyRegistry;
428template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
431 boost::shared_ptr<CellPropertyRegistry> p_registry = GetCellPropertyRegistry();
432 if (!p_registry->HasOrderingBeenSpecified())
434 std::vector<boost::shared_ptr<AbstractCellProperty> > mutations_and_proliferative_types;
445 p_registry->SpecifyOrdering(mutations_and_proliferative_types);
453template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
456 return std::set<std::pair<unsigned, unsigned>>();
460template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
463 mCentroid = zero_vector<double>(SPACE_DIM);
465 cell_iter != this->End();
468 mCentroid += GetLocationOfCellCentre(*cell_iter);
470 mCentroid /= this->GetNumRealCells();
475template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
480template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
484 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer, mCellWriters)
490 BOOST_FOREACH(boost::shared_ptr<pop_writer_t> p_pop_writer, mCellPopulationWriters)
496template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
500 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer, mCellWriters)
506 BOOST_FOREACH(boost::shared_ptr<pop_writer_t> p_pop_writer, mCellPopulationWriters)
512 *mpVtkMetaFile <<
" </Collection>\n";
513 *mpVtkMetaFile <<
"</VTKFile>\n";
514 mpVtkMetaFile->close();
518template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
523 *mpVtkMetaFile <<
"<?xml version=\"1.0\"?>\n";
524 *mpVtkMetaFile <<
"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\" compressor=\"vtkZLibDataCompressor\">\n";
525 *mpVtkMetaFile <<
" <Collection>\n";
528 if (mOutputResultsForChasteVisualizer)
530 if (!HasWriter<NodeLocationWriter>())
532 AddPopulationWriter<NodeLocationWriter>();
534 if (!HasWriter<BoundaryNodeWriter>())
536 AddPopulationWriter<BoundaryNodeWriter>();
538 if (!HasWriter<CellProliferativeTypesWriter>())
540 AddCellWriter<CellProliferativeTypesWriter>();
542 if (!HasWriter<LegacyCellProliferativeTypesWriter>())
544 AddCellWriter<LegacyCellProliferativeTypesWriter>();
550 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer, mCellWriters)
557 BOOST_FOREACH(boost::shared_ptr<pop_writer_t> p_pop_writer, mCellPopulationWriters)
560 p_pop_writer->WriteHeader(
this);
565 BOOST_FOREACH(boost::shared_ptr<count_writer_t> p_count_writer, mCellPopulationCountWriters)
568 p_count_writer->WriteHeader(
this);
573 BOOST_FOREACH(boost::shared_ptr<event_writer_t> p_event_writer, mCellPopulationEventWriters)
576 p_event_writer->WriteHeader(
this);
580template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
585 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer, mCellWriters)
589 BOOST_FOREACH(boost::shared_ptr<pop_writer_t> p_pop_writer, mCellPopulationWriters)
591 p_pop_writer->OpenOutputFileForAppend(rOutputFileHandler);
595template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
602 if (!(mCellWriters.empty() && mCellPopulationWriters.empty() && mCellPopulationCountWriters.empty()))
605 SetDefaultCellMutationStateAndProliferativeTypeOrdering();
609 OpenRoundRobinWritersFilesForAppend(output_file_handler);
614 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer, mCellWriters)
616 p_cell_writer->WriteTimeStamp();
618 BOOST_FOREACH(boost::shared_ptr<pop_writer_t> p_pop_writer, mCellPopulationWriters)
620 p_pop_writer->WriteTimeStamp();
625 pop_writer_iter != mCellPopulationWriters.end();
628 AcceptPopulationWriter(*pop_writer_iter);
631 AcceptCellWritersAcrossPopulation();
636 BOOST_FOREACH(boost::shared_ptr<cell_writer_t> p_cell_writer, mCellWriters)
638 p_cell_writer->WriteNewline();
640 BOOST_FOREACH(boost::shared_ptr<pop_writer_t> p_pop_writer, mCellPopulationWriters)
642 p_pop_writer->WriteNewline();
645 CloseRoundRobinWritersFiles();
655 BOOST_FOREACH(boost::shared_ptr<count_writer_t> p_count_writer, mCellPopulationCountWriters)
658 p_count_writer->WriteTimeStamp();
662 count_writer_iter != mCellPopulationCountWriters.end();
665 AcceptPopulationCountWriter(*count_writer_iter);
671 BOOST_FOREACH(boost::shared_ptr<count_writer_t> p_count_writer, mCellPopulationCountWriters)
673 p_count_writer->WriteNewline();
674 p_count_writer->CloseFile();
685 BOOST_FOREACH(boost::shared_ptr<event_writer_t> p_event_writer, mCellPopulationEventWriters)
691 event_writer_iter != mCellPopulationEventWriters.end();
694 AcceptPopulationEventWriter(*event_writer_iter);
700 BOOST_FOREACH(boost::shared_ptr<event_writer_t> p_event_writer, mCellPopulationEventWriters)
702 p_event_writer->CloseFile();
710 WriteVtkResultsToFile(rDirectory);
714template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
718 cell_iter != this->End();
722 cell_writer_iter != mCellWriters.end();
725 AcceptCellWriter(*cell_writer_iter, *cell_iter);
730template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
733 std::string cell_population_type = GetIdentifier();
735 *rParamsFile <<
"\t<" << cell_population_type <<
">\n";
736 OutputCellPopulationParameters(rParamsFile);
737 *rParamsFile <<
"\t</" << cell_population_type <<
">\n";
738 *rParamsFile <<
"\n";
739 *rParamsFile <<
"\t<CellCycleModels>\n";
747 std::set<std::string> unique_cell_cycle_models;
748 std::vector<CellPtr> first_cell_with_unique_CCM;
750 cell_iter != this->End();
753 std::string identifier = cell_iter->GetCellCycleModel()->GetIdentifier();
754 if (unique_cell_cycle_models.count(identifier) == 0)
756 unique_cell_cycle_models.insert(identifier);
757 first_cell_with_unique_CCM.push_back((*cell_iter));
762 for (
unsigned i=0; i<first_cell_with_unique_CCM.size(); i++)
765 first_cell_with_unique_CCM[i]->GetCellCycleModel()->OutputCellCycleModelInfo(rParamsFile);
767 *rParamsFile <<
"\t</CellCycleModels>\n";
769 *rParamsFile <<
"\n";
770 *rParamsFile <<
"\t<SrnModels>\n";
778 std::set<std::string> unique_srn_models;
779 std::vector<CellPtr> first_cell_with_unique_SRN;
781 cell_iter != this->End();
784 std::string identifier = cell_iter->GetSrnModel()->GetIdentifier();
785 if (unique_srn_models.count(identifier) == 0)
787 unique_srn_models.insert(identifier);
788 first_cell_with_unique_SRN.push_back((*cell_iter));
793 for (
unsigned i=0; i<first_cell_with_unique_SRN.size(); i++)
796 first_cell_with_unique_SRN[i]->GetSrnModel()->OutputSrnModelInfo(rParamsFile);
799 *rParamsFile <<
"\t</SrnModels>\n";
802template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
805 *rParamsFile <<
"\t\t<OutputResultsForChasteVisualizer>" << mOutputResultsForChasteVisualizer <<
"</OutputResultsForChasteVisualizer>\n";
808template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
813template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
816 return mOutputResultsForChasteVisualizer;
819template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
822 mOutputResultsForChasteVisualizer = outputResultsForChasteVisualizer;
825template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
828 return mDivisionsInformation;
830template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
833 mDivisionsInformation.push_back(divisionInformation);
836template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
839 mDivisionsInformation.clear();
842template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
845 return mRemovalsInformation;
848template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
851 mRemovalsInformation.push_back(removalInformation);
854template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
857 mRemovalsInformation.clear();
860template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
864 c_vector<double, SPACE_DIM> cell_location = GetLocationOfCellCentre(pCell);
865 if (HasWriter<CellRemovalLocationsWriter>())
867 std::stringstream removal_info;
869 for (
unsigned i = 0; i < SPACE_DIM; i++)
871 removal_info << cell_location[i] <<
"\t";
873 removal_info <<
"\t" << pCell->GetAge() <<
"\t" << pCell->GetCellId() <<
"\t" << killerInfo <<
"\t";
875 AddRemovalInformation(removal_info.str());
879template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
883 GenerateRemovalInformation(pCell, killerInfo);
889template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
893 GenerateRemovalInformation(pCell, killerInfo);
896 pCell->StartApoptosis();
899template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
905template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
909 c_vector<double,SPACE_DIM> centre = GetCentroidOfCellPopulation();
912 c_vector<double,SPACE_DIM> max_distance_from_centre = zero_vector<double>(SPACE_DIM);
914 cell_iter != this->End();
917 c_vector<double,SPACE_DIM> cell_location = GetLocationOfCellCentre(*cell_iter);
920 c_vector<double,SPACE_DIM> displacement;
921 displacement = centre - cell_location;
923 for (
unsigned i=0; i<SPACE_DIM; i++)
925 if (displacement[i] > max_distance_from_centre[i])
927 max_distance_from_centre[i] = displacement[i];
932 return max_distance_from_centre;
935template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
938 assert(index1 != index2);
940 std::pair<unsigned, unsigned> ordered_pair;
943 ordered_pair.first = index1;
944 ordered_pair.second = index2;
948 ordered_pair.first = index2;
949 ordered_pair.second = index1;
954template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
957 bool non_apoptotic_cell_present =
false;
959 if (IsCellAttachedToLocationIndex(pdeNodeIndex))
961 non_apoptotic_cell_present = !(GetCellUsingLocationIndex(pdeNodeIndex)->template HasCellProperty<ApoptoticCellProperty>());
964 return non_apoptotic_cell_present;
#define EXCEPTION(message)
#define MAKE_PTR_ARGS(TYPE, NAME, ARGS)
virtual void OpenOutputFile(OutputFileHandler &rOutputFileHandler)
void OpenOutputFileForAppend(OutputFileHandler &rOutputFileHandler)
boost::shared_ptr< CellPropertyRegistry > mpCellPropertyRegistry
void ClearDivisionsInformation()
std::vector< std::string > GetDivisionsInformation()
void OpenRoundRobinWritersFilesForAppend(OutputFileHandler &rOutputFileHandler)
void SetCellUsingLocationIndex(unsigned index, CellPtr pCell)
std::vector< std::string > GetRemovalsInformation()
virtual void AddCellUsingLocationIndex(unsigned index, CellPtr pCell)
std::vector< unsigned > GetCellMutationStateCount()
std::list< CellPtr > & rGetCells()
void SetDataOnAllCells(const std::string &rDataName, double dataValue)
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)
virtual bool IsCellAttachedToLocationIndex(unsigned index)
virtual bool IsRoomToDivide(CellPtr pCell)
std::list< CellPtr > mCells
virtual bool IsPdeNodeAssociatedWithNonApoptoticCell(unsigned pdeNodeIndex)
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 ClearRemovalsInformation()
std::set< unsigned > GetCellAncestors()
virtual void OutputCellPopulationParameters(out_stream &rParamsFile)=0
virtual std::set< std::pair< unsigned, unsigned > > GetNeighbouringEdgeIndices(CellPtr pCell, unsigned pEdgeIndex)
virtual void SimulationSetupHook(AbstractCellBasedSimulation< ELEMENT_DIM, SPACE_DIM > *pSimulation)
boost::shared_ptr< CellPropertyRegistry > GetCellPropertyRegistry()
virtual void WriteDataToVisualizerSetupFile(out_stream &pVizSetupFile)
virtual void CloseWritersFiles()
void GenerateRemovalInformation(CellPtr pCell, std::string killerInfo)
unsigned GetNumAllCells()
unsigned GetNumRealCells()
void CloseRoundRobinWritersFiles()
std::map< Cell *, unsigned > mCellLocationMap
void SetCellAncestorsToLocationIndices()
bool GetOutputResultsForChasteVisualizer()
void OutputCellPopulationInfo(out_stream &rParamsFile)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
std::vector< unsigned > GetCellCyclePhaseCount()
AbstractCellPopulation(AbstractMesh< ELEMENT_DIM, SPACE_DIM > &rMesh)
AbstractMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
void StartApoptosisOnCell(CellPtr pCell, std::string killerInfo)
c_vector< double, SPACE_DIM > GetCentroidOfCellPopulation()
virtual ~AbstractCellPopulation()
void KillCell(CellPtr pCell, std::string killerInfo)
virtual void UpdateCellProcessLocation()
std::vector< unsigned > GetCellProliferativeTypeCount()
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)
CellCyclePhase GetCurrentCellCyclePhase() const
out_stream OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const
static SimulationTime * Instance()