AbstractCentreBasedCellPopulation.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "AbstractCentreBasedCellPopulation.hpp"
00030
00031 template<unsigned DIM>
00032 AbstractCentreBasedCellPopulation<DIM>::AbstractCentreBasedCellPopulation(std::vector<CellPtr>& rCells,
00033 const std::vector<unsigned> locationIndices)
00034 : AbstractOffLatticeCellPopulation<DIM>(rCells, locationIndices),
00035 mMeinekeDivisionSeparation(0.3)
00036 {
00037 }
00038
00039 template<unsigned DIM>
00040 AbstractCentreBasedCellPopulation<DIM>::AbstractCentreBasedCellPopulation()
00041 : AbstractOffLatticeCellPopulation<DIM>(),
00042 mMeinekeDivisionSeparation(0.3)
00043 {
00044 }
00045
00046 template<unsigned DIM>
00047 c_vector<double, DIM> AbstractCentreBasedCellPopulation<DIM>::GetLocationOfCellCentre(CellPtr pCell)
00048 {
00049 return GetNodeCorrespondingToCell(pCell)->rGetLocation();
00050 }
00051
00052 template<unsigned DIM>
00053 Node<DIM>* AbstractCentreBasedCellPopulation<DIM>::GetNodeCorrespondingToCell(CellPtr pCell)
00054 {
00055 assert(this->mCellLocationMap.find(pCell.get()) != this->mCellLocationMap.end());
00056
00057 return this->GetNode(this->mCellLocationMap[pCell.get()]);
00058 }
00059
00060 template<unsigned DIM>
00061 CellPtr AbstractCentreBasedCellPopulation<DIM>::AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell)
00062 {
00063
00064 Node<DIM>* p_new_node = new Node<DIM>(this->GetNumNodes(), rCellDivisionVector, false);
00065 unsigned new_node_index = AddNode(p_new_node);
00066
00067
00068 this->mCells.push_back(pNewCell);
00069
00070
00071 this->mLocationCellMap[new_node_index] = pNewCell;
00072 this->mCellLocationMap[pNewCell.get()] = new_node_index;
00073
00074 return pNewCell;
00075 }
00076
00077 template<unsigned DIM>
00078 bool AbstractCentreBasedCellPopulation<DIM>::IsCellAssociatedWithADeletedLocation(CellPtr pCell)
00079 {
00080 return GetNodeCorrespondingToCell(pCell)->IsDeleted();
00081 }
00082
00083 template<unsigned DIM>
00084 void AbstractCentreBasedCellPopulation<DIM>::UpdateNodeLocations(const std::vector< c_vector<double, DIM> >& rNodeForces, double dt)
00085 {
00086
00087 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->Begin();
00088 cell_iter != this->End();
00089 ++cell_iter)
00090 {
00091
00092 unsigned node_index = this->mCellLocationMap[(*cell_iter).get()];
00093
00094
00095 double damping_const = this->GetDampingConstant(node_index);
00096
00097
00098 c_vector<double, DIM> new_node_location = this->GetNode(node_index)->rGetLocation() + dt*rNodeForces[node_index]/damping_const;
00099
00100
00101 ChastePoint<DIM> new_point(new_node_location);
00102
00103
00104 this->SetNode(node_index, new_point);
00105 }
00106 }
00107
00108 template<unsigned DIM>
00109 double AbstractCentreBasedCellPopulation<DIM>::GetDampingConstant(unsigned nodeIndex)
00110 {
00111 CellPtr p_cell = this->GetCellUsingLocationIndex(nodeIndex);
00112 if (p_cell->GetMutationState()->IsType<WildTypeCellMutationState>() && !p_cell->HasCellProperty<CellLabel>())
00113 {
00114 return this->GetDampingConstantNormal();
00115 }
00116 else
00117 {
00118 return this->GetDampingConstantMutant();
00119 }
00120 }
00121
00122 template<unsigned DIM>
00123 bool AbstractCentreBasedCellPopulation<DIM>::IsGhostNode(unsigned index)
00124 {
00125 return false;
00126 }
00127
00128 template<unsigned DIM>
00129 void AbstractCentreBasedCellPopulation<DIM>::GenerateCellResults(unsigned locationIndex,
00130 std::vector<unsigned>& rCellProliferativeTypeCounter,
00131 std::vector<unsigned>& rCellCyclePhaseCounter)
00132 {
00133 if (IsGhostNode(locationIndex) == true)
00134 {
00135 *(this->mpVizCellProliferativeTypesFile) << INVISIBLE_COLOUR << " ";
00136 }
00137 else
00138 {
00139 AbstractOffLatticeCellPopulation<DIM>::GenerateCellResults(locationIndex,
00140 rCellProliferativeTypeCounter,
00141 rCellCyclePhaseCounter);
00142 }
00143 }
00144
00145 template<unsigned DIM>
00146 void AbstractCentreBasedCellPopulation<DIM>::GenerateCellResultsAndWriteToFiles()
00147 {
00148
00149 unsigned num_cell_types = this->mCellProliferativeTypeCount.size();
00150 std::vector<unsigned> cell_type_counter(num_cell_types);
00151 for (unsigned i=0; i<num_cell_types; i++)
00152 {
00153 cell_type_counter[i] = 0;
00154 }
00155
00156
00157 unsigned num_cell_cycle_phases = this->mCellCyclePhaseCount.size();
00158 std::vector<unsigned> cell_cycle_phase_counter(num_cell_cycle_phases);
00159 for (unsigned i=0; i<num_cell_cycle_phases; i++)
00160 {
00161 cell_cycle_phase_counter[i] = 0;
00162 }
00163
00164
00165 for (unsigned node_index=0; node_index<this->GetNumNodes(); node_index++)
00166 {
00167
00168 bool node_corresponds_to_dead_cell = false;
00169 if (this->mLocationCellMap[node_index])
00170 {
00171 node_corresponds_to_dead_cell = this->mLocationCellMap[node_index]->IsDead();
00172 }
00173
00174
00175 if (!(this->GetNode(node_index)->IsDeleted()) && !node_corresponds_to_dead_cell)
00176 {
00177 this->GenerateCellResults(node_index, cell_type_counter, cell_cycle_phase_counter);
00178 }
00179 }
00180
00181 this->WriteCellResultsToFiles(cell_type_counter, cell_cycle_phase_counter);
00182 }
00183
00184 template<unsigned DIM>
00185 void AbstractCentreBasedCellPopulation<DIM>::WriteTimeAndNodeResultsToFiles()
00186 {
00187 double time = SimulationTime::Instance()->GetTime();
00188
00189 *this->mpVizNodesFile << time << "\t";
00190 *this->mpVizBoundaryNodesFile << time << "\t";
00191
00192
00193 for (unsigned node_index=0; node_index<this->GetNumNodes(); node_index++)
00194 {
00195
00196 bool node_corresponds_to_dead_cell = false;
00197 if (this->mLocationCellMap[node_index])
00198 {
00199 node_corresponds_to_dead_cell = this->mLocationCellMap[node_index]->IsDead();
00200 }
00201
00202
00203 if (!(this->GetNode(node_index)->IsDeleted()) && !node_corresponds_to_dead_cell)
00204 {
00205 const c_vector<double,DIM>& position = this->GetNode(node_index)->rGetLocation();
00206
00207 for (unsigned i=0; i<DIM; i++)
00208 {
00209 *this->mpVizNodesFile << position[i] << " ";
00210 }
00211 *this->mpVizBoundaryNodesFile << this->GetNode(node_index)->IsBoundaryNode() << " ";
00212 }
00213 }
00214 *this->mpVizNodesFile << "\n";
00215 *this->mpVizBoundaryNodesFile << "\n";
00216 }
00217
00218 template<unsigned DIM>
00219 double AbstractCentreBasedCellPopulation<DIM>::GetMeinekeDivisionSeparation()
00220 {
00221 return mMeinekeDivisionSeparation;
00222 }
00223
00224 template<unsigned DIM>
00225 void AbstractCentreBasedCellPopulation<DIM>::SetMeinekeDivisionSeparation(double divisionSeparation)
00226 {
00227 assert(divisionSeparation <= 1.0);
00228 assert(divisionSeparation >= 0.0);
00229 mMeinekeDivisionSeparation = divisionSeparation;
00230 }
00231
00232 template<unsigned DIM>
00233 void AbstractCentreBasedCellPopulation<DIM>::OutputCellPopulationParameters(out_stream& rParamsFile)
00234 {
00235 *rParamsFile << "\t\t<MeinekeDivisionSeparation>" << mMeinekeDivisionSeparation << "</MeinekeDivisionSeparation>\n";
00236
00237
00238 AbstractOffLatticeCellPopulation<DIM>::OutputCellPopulationParameters(rParamsFile);
00239 }
00240
00242
00244
00245 template class AbstractCentreBasedCellPopulation<1>;
00246 template class AbstractCentreBasedCellPopulation<2>;
00247 template class AbstractCentreBasedCellPopulation<3>;