Chaste Commit::8b5d759ac2eb95e67ae57699734101efccb0a0a9
CryptCentreBasedDivisionRule.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 "CryptCentreBasedDivisionRule.hpp"
37#include "RandomNumberGenerator.hpp"
38#include "Exception.hpp"
39
40template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
41std::pair<c_vector<double, SPACE_DIM>, c_vector<double, SPACE_DIM> > CryptCentreBasedDivisionRule<ELEMENT_DIM, SPACE_DIM>::CalculateCellDivisionVector(
42 CellPtr pParentCell,
44{
45 // Get separation parameter
46 double separation = rCellPopulation.GetMeinekeDivisionSeparation();
47
48 // Make a random direction vector of the required length
49 c_vector<double, SPACE_DIM> random_vector;
50
51 c_vector<double, SPACE_DIM> parent_coords;
52 parent_coords = rCellPopulation.GetLocationOfCellCentre(pParentCell);
53
54 c_vector<double, SPACE_DIM> daughter_coords;
55
56 switch (SPACE_DIM)
57 {
58 case 1:
59 {
60 double random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
61 random_vector(0) = 0.5*separation*random_direction;
62 c_vector<double, SPACE_DIM> proposed_new_parent_coords;
63 //proposed_new_parent_coords = parent_coords - random_vector;
64 proposed_new_parent_coords(0) = parent_coords(0) - random_vector(0);
65 c_vector<double, SPACE_DIM> proposed_new_daughter_coords = zero_vector<double>(SPACE_DIM);
66 proposed_new_daughter_coords = parent_coords + random_vector;
67
68 if ((proposed_new_parent_coords(0) >= 0.0) && (proposed_new_daughter_coords(0) >= 0.0))
69 {
70 // We are not too close to the bottom of the cell population, so move parent
71 parent_coords = proposed_new_parent_coords;
72 daughter_coords = proposed_new_daughter_coords;
73 }
74 else
75 {
76 proposed_new_daughter_coords = parent_coords + 2.0*random_vector;
77 while (proposed_new_daughter_coords(0) < 0.0)
78 {
79 double fresh_random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
80 random_vector(0) = 0.5*separation*fresh_random_direction;
81 proposed_new_daughter_coords = parent_coords + random_vector;
82 }
83 daughter_coords = proposed_new_daughter_coords;
84 }
85
86 // To make sure that dividing cells stay in the cell population
87 assert(daughter_coords(0) >= 0.0);
88 assert(parent_coords(0) >= 0.0);
89
90 break;
91 }
92 case 2:
93 {
94 /*
95 * Pick a random direction and move the parent cell backwards by 0.5*separation
96 * in that direction and return the position of the daughter cell 0.5*separation
97 * forwards in that direction.
98 */
99 double random_angle = RandomNumberGenerator::Instance()->ranf();
100 random_angle *= 2.0*M_PI;
101
102 random_vector(0) = 0.5*separation*cos(random_angle);
103 random_vector(1) = 0.5*separation*sin(random_angle);
104
105 c_vector<double, SPACE_DIM> proposed_new_parent_coords = zero_vector<double>(SPACE_DIM);
106 proposed_new_parent_coords = parent_coords - random_vector;
107 c_vector<double, SPACE_DIM> proposed_new_daughter_coords;
108 proposed_new_daughter_coords = parent_coords + random_vector;
109
110 if ((proposed_new_parent_coords(1) >= 0.0) && (proposed_new_daughter_coords(1) >= 0.0))
111 {
112 // We are not too close to the bottom of the cell population, so move parent
113 parent_coords = proposed_new_parent_coords;
114 daughter_coords = proposed_new_daughter_coords;
115 }
116 else
117 {
118 proposed_new_daughter_coords = parent_coords + 2.0*random_vector;
119 while (proposed_new_daughter_coords(1) < 0.0)
120 {
121 random_angle = RandomNumberGenerator::Instance()->ranf();
122 random_angle *= 2.0*M_PI;
123
124 random_vector(0) = separation*cos(random_angle);
125 random_vector(1) = separation*sin(random_angle);
126 proposed_new_daughter_coords = parent_coords + random_vector;
127 }
128 daughter_coords = proposed_new_daughter_coords;
129 }
130
131 // To make sure that dividing cells stay in the cell population
132 assert(daughter_coords(1) >= 0.0);
133 assert(parent_coords(1) >= 0.0);
134 break;
135 }
136 case 3:
137 {
138 EXCEPTION("CryptCentreBasedDivisionRule is not implemented for SPACE_DIM == 3");
139 break;
140 }
141 default:
142 // This can't happen
144 }
145
146 std::pair<c_vector<double, SPACE_DIM>, c_vector<double, SPACE_DIM> > positions(parent_coords, daughter_coords);
147 return positions;
148}
149
150// Explicit instantiation
157
158// Serialization for Boost >= 1.36
161
162
#define EXCEPTION(message)
#define NEVER_REACHED
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
c_vector< double, SPACE_DIM > GetLocationOfCellCentre(CellPtr pCell)
virtual std::pair< c_vector< double, SPACE_DIM >, c_vector< double, SPACE_DIM > > CalculateCellDivisionVector(CellPtr pParentCell, AbstractCentreBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation)
static RandomNumberGenerator * Instance()