AbstractCellCentreBasedTissue.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 
00032 template<unsigned DIM>
00033 AbstractCellCentreBasedTissue<DIM>::AbstractCellCentreBasedTissue(const std::vector<TissueCell>& rCells,
00034                                                                   const std::vector<unsigned> locationIndices)
00035     : AbstractTissue<DIM>(rCells, locationIndices)
00036 {
00037 }
00038 
00039 
00040 template<unsigned DIM>
00041 AbstractCellCentreBasedTissue<DIM>::AbstractCellCentreBasedTissue()
00042     : AbstractTissue<DIM>()
00043 {
00044 }
00045 
00046 
00047 template<unsigned DIM>
00048 c_vector<double, DIM> AbstractCellCentreBasedTissue<DIM>::GetLocationOfCellCentre(TissueCell* pCell)
00049 {
00050     return GetNodeCorrespondingToCell(pCell)->rGetLocation();
00051 }
00052 
00053 
00054 template<unsigned DIM>
00055 Node<DIM>* AbstractCellCentreBasedTissue<DIM>::GetNodeCorrespondingToCell(TissueCell* pCell)
00056 {
00057     return this->GetNode(this->mCellLocationMap[pCell]);
00058 }
00059 
00060 
00061 template<unsigned DIM>
00062 TissueCell* AbstractCellCentreBasedTissue<DIM>::AddCell(TissueCell& rNewCell, c_vector<double,DIM> newLocation, TissueCell* pParentCell)
00063 {
00064     // Create a new node
00065     Node<DIM>* p_new_node = new Node<DIM>(this->GetNumNodes(), newLocation, false);   // never on boundary
00066     unsigned new_node_index = AddNode(p_new_node); // use copy constructor so it doesn't matter that new_node goes out of scope
00067 
00068     // Update cells vector
00069     this->mCells.push_back(rNewCell);
00070 
00071     // Update mappings between cells and location indices
00072     TissueCell* p_created_cell = &(this->mCells.back());
00073     this->mLocationCellMap[new_node_index] = p_created_cell;
00074     this->mCellLocationMap[p_created_cell] = new_node_index;
00075 
00076     return p_created_cell;
00077 }
00078 
00079 
00080 template<unsigned DIM>
00081 bool AbstractCellCentreBasedTissue<DIM>::IsCellAssociatedWithADeletedNode(TissueCell& rCell)
00082 {
00083     return this->GetNode(this->mCellLocationMap[&rCell])->IsDeleted();
00084 }
00085 
00086 
00087 template<unsigned DIM>
00088 void AbstractCellCentreBasedTissue<DIM>::UpdateNodeLocations(const std::vector< c_vector<double, DIM> >& rNodeForces, double dt)
00089 {
00090     // Iterate over all nodes associated with real cells to update their positions
00091     for (typename AbstractTissue<DIM>::Iterator cell_iter = this->Begin();
00092          cell_iter != this->End();
00093          ++cell_iter)
00094     {
00095         // Get index of node associated with cell
00096         unsigned node_index = this->mCellLocationMap[&(*cell_iter)];
00097 
00098         // Get damping constant for node
00099         double damping_const = this->GetDampingConstant(node_index);
00100 
00101         // Get new node location
00102         c_vector<double, DIM> new_node_location = this->GetNode(node_index)->rGetLocation() + dt*rNodeForces[node_index]/damping_const;
00103 
00104         // Create ChastePoint for new node location
00105         ChastePoint<DIM> new_point(new_node_location);
00106 
00107         // Move the node
00108         this->SetNode(node_index, new_point);
00109     }
00110 }
00111 
00112 
00113 template<unsigned DIM>
00114 double AbstractCellCentreBasedTissue<DIM>::GetDampingConstant(unsigned nodeIndex)
00115 {
00116     double damping_multiplier = 1.0;
00117 
00118     if (   (this->rGetCellUsingLocationIndex(nodeIndex).GetMutationState() != HEALTHY)
00119         && (this->rGetCellUsingLocationIndex(nodeIndex).GetMutationState() != APC_ONE_HIT) )
00120     {
00121         return CancerParameters::Instance()->GetDampingConstantMutant()*damping_multiplier;
00122     }
00123     else
00124     {
00125         return CancerParameters::Instance()->GetDampingConstantNormal()*damping_multiplier;
00126     }
00127 }
00128 
00129 
00130 template<unsigned DIM>
00131 void AbstractCellCentreBasedTissue<DIM>::WriteResultsToFiles(bool outputCellMutationStates,
00132                                                              bool outputCellTypes,
00133                                                              bool outputCellVariables,
00134                                                              bool outputCellCyclePhases,
00135                                                              bool outputCellAncestors)
00136 {
00137     std::vector<unsigned> cell_type_counter, cell_mutation_state_counter, cell_cycle_phase_counter;
00138 
00139     this->WriteTimeAndNodeResultsToFiles(outputCellMutationStates,
00140                                          outputCellTypes,
00141                                          outputCellVariables,
00142                                          outputCellCyclePhases,
00143                                          outputCellAncestors,
00144                                          cell_type_counter,
00145                                          cell_mutation_state_counter,
00146                                          cell_cycle_phase_counter);
00147 
00148     for (unsigned node_index=0; node_index<this->GetNumNodes(); node_index++)
00149     {
00150         if ( !(this->GetNode(node_index)->IsDeleted()) )
00151         {
00152             this->GenerateCellResults(node_index,
00153                                       outputCellMutationStates,
00154                                       outputCellTypes,
00155                                       outputCellVariables,
00156                                       outputCellCyclePhases,
00157                                       outputCellAncestors,
00158                                       cell_type_counter,
00159                                       cell_mutation_state_counter,
00160                                       cell_cycle_phase_counter);
00161         }
00162     }
00163 
00164     this->WriteCellResultsToFiles(outputCellMutationStates,
00165                                   outputCellTypes,
00166                                   outputCellVariables,
00167                                   outputCellCyclePhases,
00168                                   outputCellAncestors,
00169                                   cell_type_counter,
00170                                   cell_mutation_state_counter,
00171                                   cell_cycle_phase_counter);
00172 }
00173 
00174 
00176 // Explicit instantiation
00178 
00179 template class AbstractCellCentreBasedTissue<1>;
00180 template class AbstractCellCentreBasedTissue<2>;
00181 template class AbstractCellCentreBasedTissue<3>;

Generated on Wed Mar 18 12:51:49 2009 for Chaste by  doxygen 1.5.5