36 #include "ShovingCaBasedDivisionRule.hpp"
37 #include "RandomNumberGenerator.hpp"
39 template<
unsigned SPACE_DIM>
43 bool is_central_node =
false;
46 if (numNeighbours == 8)
48 is_central_node =
true;
57 EXCEPTION(
"Cells reaching the boundary of the domain. Make the Potts mesh larger.");
61 template<
unsigned SPACE_DIM>
67 template<
unsigned SPACE_DIM>
79 unsigned num_neighbours = neighbouring_node_indices.size();
82 IsNodeOnBoundary(num_neighbours);
84 std::vector<double> neighbouring_node_propensities;
85 std::vector<unsigned> neighbouring_node_indices_vector;
87 double total_propensity = 0.0;
90 for (std::set<unsigned>::iterator neighbour_iter = neighbouring_node_indices.begin();
91 neighbour_iter != neighbouring_node_indices.end();
94 neighbouring_node_indices_vector.push_back(*neighbour_iter);
96 double propensity_dividing_into_neighbour = rCellPopulation.
EvaluateDivisionPropensity(parent_node_index,*neighbour_iter,pParentCell);
98 neighbouring_node_propensities.push_back(propensity_dividing_into_neighbour);
99 total_propensity += propensity_dividing_into_neighbour;
101 assert(total_propensity>0);
103 for (
unsigned i=0; i<num_neighbours; i++)
105 neighbouring_node_propensities[i] /= total_propensity;
110 double random_number = p_gen->
ranf();
112 double total_probability = 0.0;
116 for (counter=0; counter < num_neighbours; counter++)
118 total_probability += neighbouring_node_propensities[counter];
119 if (total_probability >= random_number)
122 daughter_node_index = neighbouring_node_indices_vector[counter];
129 assert(daughter_node_index < p_static_cast_mesh->GetNumNodes());
134 std::list<std::pair<unsigned,unsigned> > cell_moves;
136 bool is_neighbour_occupied =
true;
137 int max_moves = 1000;
139 unsigned current_node_index = parent_node_index;
140 unsigned target_node_index = daughter_node_index;
141 while (is_neighbour_occupied && move_number < max_moves)
144 current_node_index = target_node_index;
149 IsNodeOnBoundary(neighbouring_node_indices.size());
152 std::set<unsigned>::iterator neighbour_iter = neighbouring_node_indices.begin();
153 for (
unsigned i=0; i<counter; i++)
157 assert(neighbour_iter != neighbouring_node_indices.end());
159 target_node_index = *neighbour_iter;
161 std::pair<unsigned, unsigned> new_move(current_node_index, target_node_index);
163 cell_moves.push_back(new_move);
168 is_neighbour_occupied =
false;
172 current_node_index = target_node_index;
175 assert(move_number<max_moves);
178 for (std::list<std::pair<unsigned, unsigned> >::reverse_iterator reverse_iter = cell_moves.rbegin();
179 reverse_iter != cell_moves.rend();
182 assert(rCellPopulation.
IsSiteAvailable(reverse_iter->second, pNewCell));
183 assert(!(rCellPopulation.
IsSiteAvailable(reverse_iter->first, pNewCell)));
190 assert(rCellPopulation.
IsSiteAvailable(daughter_node_index, pNewCell));
193 return daughter_node_index;
virtual bool IsRoomToDivide(CellPtr pParentCell, CaBasedCellPopulation< SPACE_DIM > &rCellPopulation)
void IsNodeOnBoundary(unsigned numNeighbours)
virtual double EvaluateDivisionPropensity(unsigned currentNodeIndex, unsigned targetNodeIndex, CellPtr pCell)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
PottsMesh< DIM > & rGetMesh()
unsigned GetLocationIndexUsingCell(CellPtr pCell)
#define EXCEPTION(message)
virtual bool IsSiteAvailable(unsigned index, CellPtr pCell)
std::set< unsigned > GetMooreNeighbouringNodeIndices(unsigned nodeIndex)
void MoveCellInLocationMap(CellPtr pCell, unsigned old_index, unsigned new_index)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
const unsigned UNSIGNED_UNSET
virtual unsigned CalculateDaughterNodeIndex(CellPtr pNewCell, CellPtr pParentCell, CaBasedCellPopulation< SPACE_DIM > &rCellPopulation)
static RandomNumberGenerator * Instance()