Chaste  Release::3.4
CryptSimulation1d.cpp
1 /*
2 
3 Copyright (c) 2005-2016, 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 "CryptSimulation1d.hpp"
37 #include "WntConcentration.hpp"
38 #include "SmartPointers.hpp"
39 
41  bool deleteCellPopulationInDestructor,
42  bool initialiseCells)
43  : OffLatticeSimulation<1>(rCellPopulation,
44  deleteCellPopulationInDestructor,
45  initialiseCells)
46 {
48 
50  {
51  // Pass a CryptSimulationBoundaryCondition object into mBoundaryConditions
52  MAKE_PTR_ARGS(CryptSimulationBoundaryCondition<1>, p_bc, (&rCellPopulation));
54  }
55 }
56 
58 {
59 }
60 
61 c_vector<double, 1> CryptSimulation1d::CalculateCellDivisionVector(CellPtr pParentCell)
62 {
63  // Location of parent and daughter cells
64  c_vector<double, 1> parent_coords = mpStaticCastCellPopulation->GetLocationOfCellCentre(pParentCell);
65  c_vector<double, 1> daughter_coords;
66 
67  // Get separation parameter
69 
70  // Make a random direction vector of the required length
71  c_vector<double, 1> random_vector;
72 
73  /*
74  * Pick a random direction and move the parent cell backwards by 0.5*separation
75  * in that direction and return the position of the daughter cell 0.5*separation
76  * forwards in that direction.
77  */
78 
79  double random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
80  random_vector(0) = 0.5*separation*random_direction;
81  c_vector<double, 1> proposed_new_parent_coords = parent_coords - random_vector;
82  c_vector<double, 1> proposed_new_daughter_coords = parent_coords + random_vector;
83 
84  if ( (proposed_new_parent_coords(0) >= 0.0)
85  && (proposed_new_daughter_coords(0) >= 0.0))
86  {
87  // We are not too close to the bottom of the cell population, so move parent
88  parent_coords = proposed_new_parent_coords;
89  daughter_coords = proposed_new_daughter_coords;
90  }
91  else
92  {
93  proposed_new_daughter_coords = parent_coords + 2.0*random_vector;
94  while (proposed_new_daughter_coords(0) < 0.0)
95  {
96  double fresh_random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
97  random_vector(0) = 0.5*separation*fresh_random_direction;
98  proposed_new_daughter_coords = parent_coords + random_vector;
99  }
100  daughter_coords = proposed_new_daughter_coords;
101  }
102 
103  assert(daughter_coords(0) >= 0.0); // to make sure dividing cells stay in the cell population
104  assert(parent_coords(0) >= 0.0); // to make sure dividing cells stay in the cell population
105 
106  // Set the parent to use this location
107  ChastePoint<1> parent_coords_point(parent_coords);
108 
109  unsigned node_index = mpStaticCastCellPopulation->GetLocationIndexUsingCell(pParentCell);
110  mrCellPopulation.SetNode(node_index, parent_coords_point);
111 
112  return daughter_coords;
113 }
114 
116 {
117  // No parameters to output
118 
119  // Call method on direct parent class
121 }
122 
123 // Serialization for Boost >= 1.36
MeshBasedCellPopulation< 1 > * mpStaticCastCellPopulation
unsigned GetLocationIndexUsingCell(CellPtr pCell)
static RandomNumberGenerator * Instance()
c_vector< double, 1 > CalculateCellDivisionVector(CellPtr pParentCell)
#define CHASTE_CLASS_EXPORT(T)
CryptSimulation1d(AbstractCellPopulation< 1 > &rCellPopulation, bool deleteCellPopulationInDestructor=false, bool initialiseCells=true)
c_vector< double, SPACE_DIM > GetLocationOfCellCentre(CellPtr pCell)
#define MAKE_PTR_ARGS(TYPE, NAME, ARGS)
virtual void OutputSimulationParameters(out_stream &rParamsFile)
void AddCellPopulationBoundaryCondition(boost::shared_ptr< AbstractCellPopulationBoundaryCondition< ELEMENT_DIM, ELEMENT_DIM > > pBoundaryCondition)
void OutputSimulationParameters(out_stream &rParamsFile)
AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > & mrCellPopulation