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