DeltaNotchOffLatticeSimulation.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 "DeltaNotchOffLatticeSimulation.hpp"
00030 #include "NodeBasedCellPopulation.hpp"
00031 #include "VertexBasedCellPopulation.hpp"
00032 #include "MeshBasedCellPopulation.hpp"
00033 #include "CellwiseData.hpp"
00034 #include "DeltaNotchCellCycleModel.hpp"
00035 
00036 template<unsigned DIM>
00037 DeltaNotchOffLatticeSimulation<DIM>::DeltaNotchOffLatticeSimulation(AbstractCellPopulation<DIM>& rCellPopulation,
00038                                                                   bool deleteCellPopulationInDestructor,
00039                                                                   bool initialiseCells)
00040     : OffLatticeSimulation<DIM>(rCellPopulation, deleteCellPopulationInDestructor, initialiseCells)
00041 {
00042 }
00043 
00044 template<unsigned DIM>
00045 DeltaNotchOffLatticeSimulation<DIM>::~DeltaNotchOffLatticeSimulation()
00046 {
00047 }
00048 
00049 template<unsigned DIM>
00050 void DeltaNotchOffLatticeSimulation<DIM>::PostSolve()
00051 {
00052     this->mrCellPopulation.Update();
00053     CellwiseData<DIM>::Instance()->ReallocateMemory();
00054 
00055     if (dynamic_cast<AbstractCentreBasedCellPopulation<DIM>*>(&(this->mrCellPopulation)))
00056     {
00057         // Create and initialize vector of mean Delta concentrations
00058         unsigned num_cells = this->mrCellPopulation.GetNumRealCells();
00059         std::vector<double> mean_delta(num_cells);
00060         std::vector<unsigned> num_neighbours(num_cells);
00061         for (unsigned i=0; i<num_cells; i++)
00062         {
00063             mean_delta[i] = 0.0;
00064             num_neighbours[i] = 0;
00065         }
00066         if (dynamic_cast<MeshBasedCellPopulation<DIM>*>(&(this->mrCellPopulation)))
00067         {
00069 
00070             // Iterate over all springs (i.e. neighbouring cells)
00071             MeshBasedCellPopulation<DIM>* p_static_cast_cell_population = static_cast<MeshBasedCellPopulation<DIM>*>(&(this->mrCellPopulation));
00072             for (typename MeshBasedCellPopulation<DIM>::SpringIterator spring_iterator = p_static_cast_cell_population->SpringsBegin();
00073                  spring_iterator != p_static_cast_cell_population->SpringsEnd();
00074                  ++spring_iterator)
00075             {
00076                 // Get the index of each node on this edge
00077                 unsigned node_a_index = spring_iterator.GetNodeA()->GetIndex();
00078                 unsigned node_b_index = spring_iterator.GetNodeB()->GetIndex();
00079 
00080                 // Get the cell associated with each node
00081                 CellPtr p_cell_a = this->mrCellPopulation.GetCellUsingLocationIndex(node_a_index);
00082                 CellPtr p_cell_b = this->mrCellPopulation.GetCellUsingLocationIndex(node_b_index);
00083 
00084                 // Get the Delta concentration at each cell
00085                 double delta_a = static_cast<DeltaNotchCellCycleModel*>(p_cell_a->GetCellCycleModel())->GetDelta();
00086                 double delta_b = static_cast<DeltaNotchCellCycleModel*>(p_cell_b->GetCellCycleModel())->GetDelta();
00087 
00088                 // Add each cell's neighbour's Delta concentration to mean_delta
00089                 mean_delta[node_a_index] += delta_b;
00090                 mean_delta[node_b_index] += delta_a;
00091 
00092                 // Increment the number of neighbours found for each cell
00093                 num_neighbours[node_a_index]++;
00094                 num_neighbours[node_b_index]++;
00095             }
00096         }
00097         else // assume a NodeBasedCellPopulation
00098         {
00099             // Get a set of all neighbouring node pairs
00100             for (unsigned node_a_index=0; node_a_index<this->mrCellPopulation.GetNumNodes(); node_a_index++)
00101             {
00102                 for (unsigned node_b_index=0; node_b_index<this->mrCellPopulation.GetNumNodes(); node_b_index++)
00103                 {
00104                      bool neighbours = (norm_2(this->mrCellPopulation.GetNode(node_a_index)->rGetLocation() - this->mrCellPopulation.GetNode(node_b_index)->rGetLocation()) <= 1.5);
00105                      if ((node_a_index!= node_b_index) && (neighbours == true))
00106                      {
00107                         // Get the cell associated with each node
00108                         CellPtr p_cell_a = this->mrCellPopulation.GetCellUsingLocationIndex(node_a_index);
00109                         CellPtr p_cell_b = this->mrCellPopulation.GetCellUsingLocationIndex(node_b_index);
00110 
00111                         // Get the Delta concentration at each cell
00112                         //double delta_a = static_cast<DeltaNotchCellCycleModel*>(p_cell_a->GetCellCycleModel())->GetDelta();
00113                         double delta_b = static_cast<DeltaNotchCellCycleModel*>(p_cell_b->GetCellCycleModel())->GetDelta();
00114 
00115                         // Add each cell's neighbour's Delta concentration to mean_delta
00116                         mean_delta[node_a_index] += delta_b;
00117 
00118                         // Increment the number of neighbours found for each cell
00119                         num_neighbours[node_a_index]++;
00120                     }
00121                 }
00122             }
00123         }
00124 
00125         // Make mean_delta a vector of mean (rather than total) concentrations and store in CellwiseData
00126         for (unsigned i=0; i<num_cells; i++)
00127         {
00128             if (num_neighbours[i] != 0)
00129             {
00130                 mean_delta[i] /= num_neighbours[i];
00131             }
00132         }
00133 
00134         // Loop over cells
00135         for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mrCellPopulation.Begin();
00136              cell_iter != this->mrCellPopulation.End();
00137              ++cell_iter)
00138         {
00139             // Also store this cell's Delta and Notch concentrations
00140             unsigned node_index = this->mrCellPopulation.GetLocationIndexUsingCell(*cell_iter);
00141             double this_delta = static_cast<DeltaNotchCellCycleModel*>(cell_iter->GetCellCycleModel())->GetDelta();
00142             double this_notch = static_cast<DeltaNotchCellCycleModel*>(cell_iter->GetCellCycleModel())->GetNotch();
00143             CellwiseData<DIM>::Instance()->SetValue(mean_delta[node_index], node_index, 0);
00144             CellwiseData<DIM>::Instance()->SetValue(this_delta, node_index, 1);
00145             CellwiseData<DIM>::Instance()->SetValue(this_notch, node_index, 2);
00146         }
00147     }
00148     else // assume a VertexBasedCellPopulation
00149     {
00150         // Loop over cells
00151         for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mrCellPopulation.Begin();
00152              cell_iter != this->mrCellPopulation.End();
00153              ++cell_iter)
00154         {
00155             // Get the vertex element corresponding to this cell
00156             unsigned element_index = this->mrCellPopulation.GetLocationIndexUsingCell(*cell_iter);
00157             VertexElement<DIM,DIM>* p_element = static_cast<VertexBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->GetElement(element_index);
00158 
00159             // Get a set of neighbouring element indices
00160             std::set<unsigned> neighbour_indices;
00161             for (unsigned local_index=0; local_index<p_element->GetNumNodes(); local_index++)
00162             {
00163                 Node<DIM>* p_node = p_element->GetNode(local_index);
00164                 std::set<unsigned> elements = p_node->rGetContainingElementIndices();
00165                 std::set<unsigned> all_elements;
00166                 std::set_union(neighbour_indices.begin(), neighbour_indices.end(),
00167                                elements.begin(), elements.end(),
00168                                std::inserter(all_elements, all_elements.begin()));
00169 
00170                 neighbour_indices = all_elements;
00171             }
00172             neighbour_indices.erase(element_index);
00173             unsigned num_neighbours = neighbour_indices.size();
00174 
00175             // Compute mean Delta concentration, averaged over neighbours
00176             double mean_delta = 0.0;
00177             for (std::set<unsigned>::iterator iter = neighbour_indices.begin();
00178                  iter != neighbour_indices.end();
00179                  ++iter)
00180             {
00181                 CellPtr p_cell = this->mrCellPopulation.GetCellUsingLocationIndex(*iter);
00182                 double delta = static_cast<DeltaNotchCellCycleModel*>(p_cell->GetCellCycleModel())->GetDelta();
00183                 if (num_neighbours != 0)
00184                 {
00185                     mean_delta += delta/num_neighbours;
00186                 }
00187             }
00188 
00189             // Store this value in CellwiseData
00190             CellwiseData<DIM>::Instance()->SetValue(mean_delta, p_element->GetIndex(), 0);
00191 
00192             // Also store this cell's Delta and Notch concentrations
00193             double this_delta = static_cast<DeltaNotchCellCycleModel*>(cell_iter->GetCellCycleModel())->GetDelta();
00194             double this_notch = static_cast<DeltaNotchCellCycleModel*>(cell_iter->GetCellCycleModel())->GetNotch();
00195             CellwiseData<DIM>::Instance()->SetValue(this_delta, p_element->GetIndex(), 1);
00196             CellwiseData<DIM>::Instance()->SetValue(this_notch, p_element->GetIndex(), 2);
00197         }
00198     }
00199 }
00200 
00202 // Explicit instantiation
00204 
00205 template class DeltaNotchOffLatticeSimulation<1>;
00206 template class DeltaNotchOffLatticeSimulation<2>;
00207 template class DeltaNotchOffLatticeSimulation<3>;
00208 
00209 // Serialization for Boost >= 1.36
00210 #include "SerializationExportWrapperForCpp.hpp"
00211 EXPORT_TEMPLATE_CLASS_SAME_DIMS(DeltaNotchOffLatticeSimulation)
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3