Chaste  Release::2024.1
CryptCentreBasedDivisionRule.cpp
1 /*
2 
3 Copyright (c) 2005-2021, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF 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 
40 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
41 std::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;
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
151 template class CryptCentreBasedDivisionRule<1,1>;
152 template class CryptCentreBasedDivisionRule<1,2>;
153 template class CryptCentreBasedDivisionRule<2,2>;
154 template class CryptCentreBasedDivisionRule<1,3>;
155 template class CryptCentreBasedDivisionRule<2,3>;
156 template class CryptCentreBasedDivisionRule<3,3>;
157 
158 // Serialization for Boost >= 1.36
161 
162 
#define EXCEPTION(message)
Definition: Exception.hpp:143
#define NEVER_REACHED
Definition: Exception.hpp:206
static RandomNumberGenerator * Instance()
virtual std::pair< c_vector< double, SPACE_DIM >, c_vector< double, SPACE_DIM > > CalculateCellDivisionVector(CellPtr pParentCell, AbstractCentreBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation)
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
c_vector< double, SPACE_DIM > GetLocationOfCellCentre(CellPtr pCell)