Chaste  Release::2017.1
CryptSimulationBoundaryCondition.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 "CryptSimulationBoundaryCondition.hpp"
37 #include "WntConcentration.hpp"
38 #include "AbstractCentreBasedCellPopulation.hpp"
39 #include "RandomNumberGenerator.hpp"
40 #include "StemCellProliferativeType.hpp"
41 
42 template<unsigned DIM>
44  : AbstractCellPopulationBoundaryCondition<DIM>(pCellPopulation),
45  mUseJiggledBottomCells(false)
46 {
47 }
48 
49 template<unsigned DIM>
50 void CryptSimulationBoundaryCondition<DIM>::ImposeBoundaryCondition(const std::map<Node<DIM>*, c_vector<double, DIM> >& rOldLocations)
51 {
52  // We only allow jiggling of bottom cells in 2D
53  if (DIM == 1)
54  {
55  mUseJiggledBottomCells = false;
56  }
57 
58  // Check whether a WntConcentration singleton has been set up
59  bool is_wnt_included = WntConcentration<DIM>::Instance()->IsWntSetUp();
60  if (!is_wnt_included)
61  {
63  }
64 
65  // We iterate differently depending on whether we are using a centre- or vertex-based model
67  {
68  // Iterate over all nodes associated with real cells to update their positions
69  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
70  cell_iter != this->mpCellPopulation->End();
71  ++cell_iter)
72  {
73  // Get index of node associated with cell
74  unsigned node_index = this->mpCellPopulation->GetLocationIndexUsingCell(*cell_iter);
75 
76  // Get pointer to this node
77  Node<DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
78 
79  if (!is_wnt_included)
80  {
81  /*
82  * If WntConcentration is not set up then stem cells must be pinned,
83  * so we reset the location of each stem cell.
84  */
85  if (cell_iter->GetCellProliferativeType()->template IsType<StemCellProliferativeType>())
86  {
87  // Get old node location
88  c_vector<double, DIM> old_node_location = rOldLocations.find(p_node)->second;
89 
90  // Return node to old location
91  p_node->rGetModifiableLocation() = old_node_location;
92  }
93  }
94 
95  // Any cell that has moved below the bottom of the crypt must be moved back up
96  if (p_node->rGetLocation()[DIM-1] < 0.0)
97  {
98  p_node->rGetModifiableLocation()[DIM-1] = 0.0;
99 
101  {
102  /*
103  * Here we give the cell a push upwards so that it doesn't
104  * get stuck on the bottom of the crypt (as per #422).
105  *
106  * Note that all stem cells may get moved to the same height, so
107  * we use a random perturbation to help ensure we are not simply
108  * faced with the same problem at a different height!
109  */
110  p_node->rGetModifiableLocation()[DIM-1] = 0.05*RandomNumberGenerator::Instance()->ranf();
111  }
112  }
113  assert(p_node->rGetLocation()[DIM-1] >= 0.0);
114  }
115  }
116  else
117  {
118  // Iterate over all nodes to update their positions
119  for (unsigned node_index=0; node_index<this->mpCellPopulation->GetNumNodes(); node_index++)
120  {
121  // Get pointer to this node
122  Node<DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
123 
124  if (!is_wnt_included)
125  {
126  /*
127  * If WntConcentration is not set up then stem cells must be pinned,
128  * so we reset the location of each node whose height was close to zero.
129  */
130  double node_height = rOldLocations.find(p_node)->second[DIM-1];
131  if (node_height < DBL_EPSILON)
132  {
133  // Return node to its old height, but allow it to slide left or right
134  p_node->rGetModifiableLocation()[DIM-1] = node_height;
135  }
136  }
137 
138  // Any node that has moved below the bottom of the crypt must be moved back up
139  if (p_node->rGetLocation()[DIM-1] < 0.0)
140  {
141  p_node->rGetModifiableLocation()[DIM-1] = 0.0;
142 
144  {
145  /*
146  * Here we give the node a push upwards so that it doesn't
147  * get stuck on the bottom of the crypt.
148  */
149  p_node->rGetModifiableLocation()[DIM-1] = 0.05*RandomNumberGenerator::Instance()->ranf();
150  }
151  }
152  assert(p_node->rGetLocation()[DIM-1] >= 0.0);
153  }
154  }
155 }
156 
157 template<unsigned DIM>
159 {
160  bool boundary_condition_satisfied = true;
161 
162  /*
163  * Here we verify that the boundary condition is still satisfied by simply
164  * checking that no cells lies below the y=0 boundary.
165  */
166  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
167  cell_iter != this->mpCellPopulation->End();
168  ++cell_iter)
169  {
170  // Get index of node associated with cell
171  unsigned node_index = this->mpCellPopulation->GetLocationIndexUsingCell(*cell_iter);
172 
173  // Get pointer to this node
174  Node<DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
175 
176  // If this node lies below the y=0 boundary, break and return false
177  if (p_node->rGetLocation()[DIM-1] < 0.0)
178  {
179  boundary_condition_satisfied = false;
180  break;
181  }
182  }
183 
184  return boundary_condition_satisfied;
185 }
186 
187 template<unsigned DIM>
189 {
190  mUseJiggledBottomCells = useJiggledBottomCells;
191 }
192 
193 template<unsigned DIM>
195 {
196  return mUseJiggledBottomCells;
197 }
198 
199 template<unsigned DIM>
201 {
202  *rParamsFile << "\t\t<UseJiggledBottomCells>" << mUseJiggledBottomCells << "</UseJiggledBottomCells>\n";
204  // Call method on direct parent class
206 }
207 
208 // Explicit instantiation
212 
213 // Serialization for Boost >= 1.36
virtual Node< SPACE_DIM > * GetNode(unsigned index)=0
AbstractCellPopulation< ELEMENT_DIM, ELEMENT_DIM > * mpCellPopulation
Definition: Node.hpp:58
unsigned GetLocationIndexUsingCell(CellPtr pCell)
static void Destroy()
void ImposeBoundaryCondition(const std::map< Node< DIM > *, c_vector< double, DIM > > &rOldLocations)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
static WntConcentration * Instance()
CryptSimulationBoundaryCondition(AbstractCellPopulation< DIM > *pCellPopulation)
static RandomNumberGenerator * Instance()
const c_vector< double, SPACE_DIM > & rGetLocation() const
Definition: Node.cpp:139
void SetUseJiggledBottomCells(bool useJiggledBottomCells)
void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
Definition: Node.cpp:151
virtual void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)=0
virtual unsigned GetNumNodes()=0