DeltaNotchOffLatticeSimulation.cpp
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 "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
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
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
00077 unsigned node_a_index = spring_iterator.GetNodeA()->GetIndex();
00078 unsigned node_b_index = spring_iterator.GetNodeB()->GetIndex();
00079
00080
00081 CellPtr p_cell_a = this->mrCellPopulation.GetCellUsingLocationIndex(node_a_index);
00082 CellPtr p_cell_b = this->mrCellPopulation.GetCellUsingLocationIndex(node_b_index);
00083
00084
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
00089 mean_delta[node_a_index] += delta_b;
00090 mean_delta[node_b_index] += delta_a;
00091
00092
00093 num_neighbours[node_a_index]++;
00094 num_neighbours[node_b_index]++;
00095 }
00096 }
00097 else
00098 {
00099
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
00108 CellPtr p_cell_a = this->mrCellPopulation.GetCellUsingLocationIndex(node_a_index);
00109 CellPtr p_cell_b = this->mrCellPopulation.GetCellUsingLocationIndex(node_b_index);
00110
00111
00112
00113 double delta_b = static_cast<DeltaNotchCellCycleModel*>(p_cell_b->GetCellCycleModel())->GetDelta();
00114
00115
00116 mean_delta[node_a_index] += delta_b;
00117
00118
00119 num_neighbours[node_a_index]++;
00120 }
00121 }
00122 }
00123 }
00124
00125
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
00135 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mrCellPopulation.Begin();
00136 cell_iter != this->mrCellPopulation.End();
00137 ++cell_iter)
00138 {
00139
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
00149 {
00150
00151 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mrCellPopulation.Begin();
00152 cell_iter != this->mrCellPopulation.End();
00153 ++cell_iter)
00154 {
00155
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
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
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
00190 CellwiseData<DIM>::Instance()->SetValue(mean_delta, p_element->GetIndex(), 0);
00191
00192
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
00204
00205 template class DeltaNotchOffLatticeSimulation<1>;
00206 template class DeltaNotchOffLatticeSimulation<2>;
00207 template class DeltaNotchOffLatticeSimulation<3>;
00208
00209
00210 #include "SerializationExportWrapperForCpp.hpp"
00211 EXPORT_TEMPLATE_CLASS_SAME_DIMS(DeltaNotchOffLatticeSimulation)