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