AbstractCentreBasedCellPopulation.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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) // educated guess
00036 {
00037 }
00038 
00039 
00040 template<unsigned DIM>
00041 AbstractCentreBasedCellPopulation<DIM>::AbstractCentreBasedCellPopulation()
00042     : AbstractCellPopulation<DIM>(),
00043       mMeinekeDivisionSeparation(0.3) // educated guess
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     // Create a new node
00068     Node<DIM>* p_new_node = new Node<DIM>(this->GetNumNodes(), rCellDivisionVector, false);   // never on boundary
00069     unsigned new_node_index = AddNode(p_new_node); // use copy constructor so it doesn't matter that new_node goes out of scope
00070 
00071     // Update cells vector
00072     this->mCells.push_back(pNewCell);
00073 
00074     // Update mappings between cells and location indices
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     // Iterate over all nodes associated with real cells to update their positions
00093     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->Begin();
00094          cell_iter != this->End();
00095          ++cell_iter)
00096     {
00097         // Get index of node associated with cell
00098         unsigned node_index = this->mCellLocationMap[(*cell_iter).get()];
00099 
00100         // Get damping constant for node
00101         double damping_const = this->GetDampingConstant(node_index);
00102 
00103         // Get new node location
00104         c_vector<double, DIM> new_node_location = this->GetNode(node_index)->rGetLocation() + dt*rNodeForces[node_index]/damping_const;
00105 
00106         // Create ChastePoint for new node location
00107         ChastePoint<DIM> new_point(new_node_location);
00108 
00109         // Move the node
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     // Set up cell type counter
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     // Set up cell cycle phase counter
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     // Write cell data to file
00175     for (unsigned node_index=0; node_index<this->GetNumNodes(); node_index++)
00176     {
00177         // Hack that covers the case where the node is associated with a cell that has just been killed (#1129)
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         // Write cell data to file
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     // Write node data to file
00203     for (unsigned node_index=0; node_index<this->GetNumNodes(); node_index++)
00204     {
00205         // Hack that covers the case where the node in an AbstractCentreBasedCellPopulation is associated with a cell that has just been killed (#1129) This breaks the vertex visualiser when apoptotic cells are involved.
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         // Write node data to file
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     // Call direct parent class
00248     AbstractCellPopulation<DIM>::OutputCellPopulationParameters(rParamsFile);
00249 
00250 }
00251 
00253 // Explicit instantiation
00255 
00256 template class AbstractCentreBasedCellPopulation<1>;
00257 template class AbstractCentreBasedCellPopulation<2>;
00258 template class AbstractCentreBasedCellPopulation<3>;

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5