Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
CryptSimulationBoundaryCondition.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
42template<unsigned DIM>
48
49template<unsigned DIM>
50void 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
66 if (dynamic_cast<AbstractCentreBasedCellPopulation<DIM>*>(this->mpCellPopulation))
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
100 if (mUseJiggledBottomCells)
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 */
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
143 if (mUseJiggledBottomCells)
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 */
150 }
151 }
152 assert(p_node->rGetLocation()[DIM-1] >= 0.0);
153 }
154 }
155}
156
157template<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
187template<unsigned DIM>
189{
190 mUseJiggledBottomCells = useJiggledBottomCells;
191}
192
193template<unsigned DIM>
195{
196 return mUseJiggledBottomCells;
197}
198
199template<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
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)=0
CryptSimulationBoundaryCondition(AbstractCellPopulation< DIM > *pCellPopulation)
void SetUseJiggledBottomCells(bool useJiggledBottomCells)
void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)
void ImposeBoundaryCondition(const std::map< Node< DIM > *, c_vector< double, DIM > > &rOldLocations)
Definition Node.hpp:59
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
Definition Node.cpp:151
const c_vector< double, SPACE_DIM > & rGetLocation() const
Definition Node.cpp:139
static RandomNumberGenerator * Instance()
static WntConcentration * Instance()
static void Destroy()