Chaste  Release::2017.1
CryptCentreBasedDivisionRule.cpp
1 /*
2 
3 Copyright (c) 2005-2017, 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 = rCellPopulation.GetLocationOfCellCentre(pParentCell);
52  c_vector<double, SPACE_DIM> daughter_coords;
53 
54  switch (SPACE_DIM)
55  {
56  case 1:
57  {
58  double random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
59  random_vector(0) = 0.5*separation*random_direction;
60  c_vector<double, SPACE_DIM> proposed_new_parent_coords = parent_coords - random_vector;
61  c_vector<double, SPACE_DIM> proposed_new_daughter_coords = parent_coords + random_vector;
62 
63  if ((proposed_new_parent_coords(0) >= 0.0) && (proposed_new_daughter_coords(0) >= 0.0))
64  {
65  // We are not too close to the bottom of the cell population, so move parent
66  parent_coords = proposed_new_parent_coords;
67  daughter_coords = proposed_new_daughter_coords;
68  }
69  else
70  {
71  proposed_new_daughter_coords = parent_coords + 2.0*random_vector;
72  while (proposed_new_daughter_coords(0) < 0.0)
73  {
74  double fresh_random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
75  random_vector(0) = 0.5*separation*fresh_random_direction;
76  proposed_new_daughter_coords = parent_coords + random_vector;
77  }
78  daughter_coords = proposed_new_daughter_coords;
79  }
80 
81  // To make sure that dividing cells stay in the cell population
82  assert(daughter_coords(0) >= 0.0);
83  assert(parent_coords(0) >= 0.0);
84 
85  break;
86  }
87  case 2:
88  {
89  /*
90  * Pick a random direction and move the parent cell backwards by 0.5*separation
91  * in that direction and return the position of the daughter cell 0.5*separation
92  * forwards in that direction.
93  */
94  double random_angle = RandomNumberGenerator::Instance()->ranf();
95  random_angle *= 2.0*M_PI;
96 
97  random_vector(0) = 0.5*separation*cos(random_angle);
98  random_vector(1) = 0.5*separation*sin(random_angle);
99 
100  c_vector<double, 2> proposed_new_parent_coords = parent_coords - random_vector;
101  c_vector<double, 2> proposed_new_daughter_coords = parent_coords + random_vector;
102 
103  if ((proposed_new_parent_coords(1) >= 0.0) && (proposed_new_daughter_coords(1) >= 0.0))
104  {
105  // We are not too close to the bottom of the cell population, so move parent
106  parent_coords = proposed_new_parent_coords;
107  daughter_coords = proposed_new_daughter_coords;
108  }
109  else
110  {
111  proposed_new_daughter_coords = parent_coords + 2.0*random_vector;
112  while (proposed_new_daughter_coords(1) < 0.0)
113  {
114  random_angle = RandomNumberGenerator::Instance()->ranf();
115  random_angle *= 2.0*M_PI;
116 
117  random_vector(0) = separation*cos(random_angle);
118  random_vector(1) = separation*sin(random_angle);
119  proposed_new_daughter_coords = parent_coords + random_vector;
120  }
121  daughter_coords = proposed_new_daughter_coords;
122  }
123 
124  // To make sure that dividing cells stay in the cell population
125  assert(daughter_coords(1) >= 0.0);
126  assert(parent_coords(1) >= 0.0);
127  break;
128  }
129  case 3:
130  {
131  EXCEPTION("CryptCentreBasedDivisionRule is not implemented for SPACE_DIM == 3");
132  break;
133  }
134  default:
135  // This can't happen
137  }
138 
139  std::pair<c_vector<double, SPACE_DIM>, c_vector<double, SPACE_DIM> > positions(parent_coords, daughter_coords);
140  return positions;
141 }
142 
143 // Explicit instantiation
144 template class CryptCentreBasedDivisionRule<1,1>;
145 template class CryptCentreBasedDivisionRule<1,2>;
146 template class CryptCentreBasedDivisionRule<2,2>;
147 template class CryptCentreBasedDivisionRule<1,3>;
148 template class CryptCentreBasedDivisionRule<2,3>;
149 template class CryptCentreBasedDivisionRule<3,3>;
150 
151 // Serialization for Boost >= 1.36
154 
155 
#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)