Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
CryptShovingCaBasedDivisionRule.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "CryptShovingCaBasedDivisionRule.hpp"
37#include "RandomNumberGenerator.hpp"
38#include "StemCellProliferativeType.hpp"
39
41{
42 std::set<unsigned> neighbouring_node_indices = pPottsMesh->GetVonNeumannNeighbouringNodeIndices(NodeIndex);
43 unsigned num_neighbours = neighbouring_node_indices.size();
44
45 // No strange neighbourhoods and in 2D so need 3 or 4 neighbours
46 if (num_neighbours == 4)
47 {
48 return true;
49 }
50 else if (num_neighbours == 3)
51 {
52 // Quick and dirty check to see if cells are in bottom or top half of the domain
53 if (NodeIndex < 0.5*pPottsMesh->GetNumNodes())
54 {
55 return false;
56 }
57 else
58 {
59 EXCEPTION("Cells reaching the top of the crypt need to increase length to at least double the sloughing height.");
60 }
61 }
62 else
63 {
64 // If here then have <2 or >4 neighbours and not possible for 2d periodic crypt
66 }
67}
68
70{
71 return true;
72}
73
75 CellPtr pParentCell,
76 CaBasedCellPopulation<2>& rCellPopulation)
77{
78 // Get node index corresponding to the parent cell
79 unsigned parent_node_index = rCellPopulation.GetLocationIndexUsingCell(pParentCell);
80
81 PottsMesh<2>* static_cast_mesh = static_cast<PottsMesh<2>*>(&(rCellPopulation.rGetMesh()));
82
83 // This tracks if the cell is on the base of the crypt, and offsets the neighbours accordingly
84 bool is_not_on_base = IsNodeOnBase(parent_node_index,static_cast_mesh);
85
86 /*
87 * Select a neighbour at random.
88 * Sample random number to specify which move to make either 1 (E) 2 (W) or 3 (N)
89 * This is as they are ordered in node index and that moves from south west to north east.
90 */
92 unsigned direction = p_gen->randMod(3)+ (unsigned) is_not_on_base;
93
94 // Stem Cells only divide vertically
95 if (pParentCell->GetCellProliferativeType()->IsType<StemCellProliferativeType>())
96 {
97 direction = 2;
98 }
99
100
101 std::set<unsigned> neighbouring_node_indices = static_cast_mesh->GetVonNeumannNeighbouringNodeIndices(parent_node_index);
102
103 std::set<unsigned>::iterator neighbour_iter = neighbouring_node_indices.begin();
104 for (unsigned i=0; i<direction; i++)
105 {
106 ++neighbour_iter;
107 }
108 assert(neighbour_iter != neighbouring_node_indices.end());
109
110 unsigned daughter_node_index = *neighbour_iter;
111
112 assert(daughter_node_index < static_cast_mesh->GetNumNodes());
113
114 // If daughter node is occupied then move the cell north (which is always the last one in the set of neighbours)
115 if (!(rCellPopulation.IsSiteAvailable(daughter_node_index, pNewCell)))
116 {
117 std::list<std::pair<unsigned,unsigned> > cell_moves;
118
119 bool is_neighbour_occupied = true;
120
121 unsigned current_node_index = parent_node_index;
122 unsigned target_node_index = daughter_node_index;
123 while (is_neighbour_occupied)
124 {
125 current_node_index = target_node_index;
126
127 std::set<unsigned> neighbouring_node_indices = static_cast_mesh->GetVonNeumannNeighbouringNodeIndices(current_node_index);
128 unsigned num_neighbours = neighbouring_node_indices.size();
129
130 // Check to see if the current node is on the boundary
131 IsNodeOnBase(current_node_index, static_cast_mesh);
132
133 // Select the appropriate neighbour
134 std::set<unsigned>::iterator neighbour_iter = neighbouring_node_indices.begin();
135 for (unsigned i=0; i<num_neighbours-1; i++)
136 {
137 ++neighbour_iter;
138 }
139 assert(neighbour_iter != neighbouring_node_indices.end());
140
141 target_node_index = *neighbour_iter;
142
143 std::pair<unsigned, unsigned> new_move(current_node_index, target_node_index);
144
145 cell_moves.push_back(new_move);
146
147 // If target node is unoccupied move the cell on the current node to the target node and stop shoving cells
148 if (rCellPopulation.IsSiteAvailable(target_node_index, pNewCell))
149 {
150 is_neighbour_occupied = false;
151 }
152
153 // If target node is occupied then keep shoving the cells out of the way
154 current_node_index = target_node_index;
155 }
156
157 // Do moves to free up the daughter node index
158 for (std::list<std::pair<unsigned, unsigned> >::reverse_iterator reverse_iter = cell_moves.rbegin();
159 reverse_iter != cell_moves.rend();
160 ++reverse_iter)
161 {
162 assert(rCellPopulation.IsSiteAvailable(reverse_iter->second, pNewCell));
163 assert(!(rCellPopulation.IsSiteAvailable(reverse_iter->first, pNewCell)));
164
165 // Move cell from first() to second()
166 rCellPopulation.MoveCellInLocationMap(rCellPopulation.GetCellUsingLocationIndex(reverse_iter->first), reverse_iter->first, reverse_iter->second);
167 }
168
169 // Check daughter site is now free
170 assert(rCellPopulation.IsSiteAvailable(daughter_node_index, pNewCell));
171
172 }
173 return daughter_node_index;
174}
175
176// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define NEVER_REACHED
#define CHASTE_CLASS_EXPORT(T)
unsigned GetLocationIndexUsingCell(CellPtr pCell)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
void MoveCellInLocationMap(CellPtr pCell, unsigned old_index, unsigned new_index)
PottsMesh< DIM > & rGetMesh()
virtual bool IsSiteAvailable(unsigned index, CellPtr pCell)
bool IsNodeOnBase(unsigned NodeIndex, PottsMesh< 2 > *pPottsMesh)
virtual bool IsRoomToDivide(CellPtr pParentCell, CaBasedCellPopulation< 2 > &rCellPopulation)
virtual unsigned CalculateDaughterNodeIndex(CellPtr pNewCell, CellPtr pParentCell, CaBasedCellPopulation< 2 > &rCellPopulation)
std::set< unsigned > GetVonNeumannNeighbouringNodeIndices(unsigned nodeIndex)
static RandomNumberGenerator * Instance()
unsigned randMod(unsigned base)