AbstractCellCentreBasedTissue.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 "AbstractCellCentreBasedTissue.hpp"
00030 
00031 template<unsigned DIM>
00032 AbstractCellCentreBasedTissue<DIM>::AbstractCellCentreBasedTissue(std::vector<TissueCell>& rCells,
00033                                                                   const std::vector<unsigned> locationIndices)
00034     : AbstractTissue<DIM>(rCells, locationIndices)
00035 {
00036 }
00037 
00038 
00039 template<unsigned DIM>
00040 AbstractCellCentreBasedTissue<DIM>::AbstractCellCentreBasedTissue()
00041     : AbstractTissue<DIM>()
00042 {
00043 }
00044 
00045 
00046 template<unsigned DIM>
00047 c_vector<double, DIM> AbstractCellCentreBasedTissue<DIM>::GetLocationOfCellCentre(TissueCell& rCell)
00048 {
00049     return GetNodeCorrespondingToCell(rCell)->rGetLocation();
00050 }
00051 
00052 
00053 template<unsigned DIM>
00054 Node<DIM>* AbstractCellCentreBasedTissue<DIM>::GetNodeCorrespondingToCell(TissueCell& rCell)
00055 {
00056     return this->GetNode(this->mCellLocationMap[&rCell]);
00057 }
00058 
00059 
00060 template<unsigned DIM>
00061 TissueCell* AbstractCellCentreBasedTissue<DIM>::AddCell(TissueCell& rNewCell, const c_vector<double,DIM>& rCellDivisionVector, TissueCell* pParentCell)
00062 {
00063     // Create a new node
00064     Node<DIM>* p_new_node = new Node<DIM>(this->GetNumNodes(), rCellDivisionVector, false);   // never on boundary
00065     unsigned new_node_index = AddNode(p_new_node); // use copy constructor so it doesn't matter that new_node goes out of scope
00066 
00067     // Update cells vector
00068     this->mCells.push_back(rNewCell);
00069 
00070     // Update mappings between cells and location indices
00071     TissueCell* p_created_cell = &(this->mCells.back());
00072     this->mLocationCellMap[new_node_index] = p_created_cell;
00073     this->mCellLocationMap[p_created_cell] = new_node_index;
00074 
00075     return p_created_cell;
00076 }
00077 
00078 
00079 template<unsigned DIM>
00080 bool AbstractCellCentreBasedTissue<DIM>::IsCellAssociatedWithADeletedLocation(TissueCell& rCell)
00081 {
00082     return GetNodeCorrespondingToCell(rCell)->IsDeleted();
00083 }
00084 
00085 
00086 template<unsigned DIM>
00087 void AbstractCellCentreBasedTissue<DIM>::UpdateNodeLocations(const std::vector< c_vector<double, DIM> >& rNodeForces, double dt)
00088 {
00089     // Iterate over all nodes associated with real cells to update their positions
00090     for (typename AbstractTissue<DIM>::Iterator cell_iter = this->Begin();
00091          cell_iter != this->End();
00092          ++cell_iter)
00093     {
00094         // Get index of node associated with cell
00095         unsigned node_index = this->mCellLocationMap[&(*cell_iter)];
00096 
00097         // Get damping constant for node
00098         double damping_const = this->GetDampingConstant(node_index);
00099 
00100         // Get new node location
00101         c_vector<double, DIM> new_node_location = this->GetNode(node_index)->rGetLocation() + dt*rNodeForces[node_index]/damping_const;
00102 
00103         // Create ChastePoint for new node location
00104         ChastePoint<DIM> new_point(new_node_location);
00105 
00106         // Move the node
00107         this->SetNode(node_index, new_point);
00108     }
00109 }
00110 
00111 
00112 template<unsigned DIM>
00113 double AbstractCellCentreBasedTissue<DIM>::GetDampingConstant(unsigned nodeIndex)
00114 {
00115     TissueCell& cell = this->rGetCellUsingLocationIndex(nodeIndex);
00116     if (cell.GetMutationState()->IsType<WildTypeCellMutationState>())
00117     {
00118         return TissueConfig::Instance()->GetDampingConstantNormal();
00119     }
00120     else
00121     {
00122         return TissueConfig::Instance()->GetDampingConstantMutant();
00123     }
00124 }
00125 
00126 
00127 template<unsigned DIM>
00128 bool AbstractCellCentreBasedTissue<DIM>::IsGhostNode(unsigned index)
00129 {
00130     return false;
00131 }
00132 
00133 
00134 template<unsigned DIM>
00135 void AbstractCellCentreBasedTissue<DIM>::GenerateCellResults(unsigned locationIndex,
00136                                                              std::vector<unsigned>& rCellProliferativeTypeCounter,
00137                                                              std::vector<unsigned>& rCellCyclePhaseCounter)
00138 {
00139     if (IsGhostNode(locationIndex) == true)
00140     {
00141         *(this->mpVizCellProliferativeTypesFile) << INVISIBLE_COLOUR << " ";
00142     }
00143     else
00144     {
00145         AbstractTissue<DIM>::GenerateCellResults(locationIndex,
00146                                                  rCellProliferativeTypeCounter,
00147                                                  rCellCyclePhaseCounter);
00148     }
00149 }
00150 
00151 
00152 template<unsigned DIM>
00153 void AbstractCellCentreBasedTissue<DIM>::GenerateCellResultsAndWriteToFiles()
00154 {
00155     // Set up cell type counter
00156     unsigned num_cell_types = this->mCellProliferativeTypeCount.size();
00157     std::vector<unsigned> cell_type_counter(num_cell_types);
00158     for (unsigned i=0; i<num_cell_types; i++)
00159     {
00160         cell_type_counter[i] = 0;
00161     }
00162 
00163     // Set up cell cycle phase counter
00164     unsigned num_cell_cycle_phases = this->mCellCyclePhaseCount.size();
00165     std::vector<unsigned> cell_cycle_phase_counter(num_cell_cycle_phases);
00166     for (unsigned i=0; i<num_cell_cycle_phases; i++)
00167     {
00168         cell_cycle_phase_counter[i] = 0;
00169     }
00170 
00171     // Write cell data to file
00172     for (unsigned node_index=0; node_index<this->GetNumNodes(); node_index++)
00173     {
00174         // Hack that covers the case where the node is associated with a cell that has just been killed (#1129)
00175         bool node_corresponds_to_dead_cell = false;
00176         if (this->mLocationCellMap[node_index])
00177         {
00178             node_corresponds_to_dead_cell = this->mLocationCellMap[node_index]->IsDead();
00179         }
00180 
00181         // Write cell data to file
00182         if ( !(this->GetNode(node_index)->IsDeleted()) && !node_corresponds_to_dead_cell)
00183         {
00184             this->GenerateCellResults(node_index, cell_type_counter, cell_cycle_phase_counter);
00185         }
00186     }
00187 
00188     this->WriteCellResultsToFiles(cell_type_counter, cell_cycle_phase_counter);
00189 }
00190 
00191 
00193 // Explicit instantiation
00195 
00196 template class AbstractCellCentreBasedTissue<1>;
00197 template class AbstractCellCentreBasedTissue<2>;
00198 template class AbstractCellCentreBasedTissue<3>;

Generated by  doxygen 1.6.2