Chaste  Release::3.4
GeneralisedLinearSpringForce.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 "GeneralisedLinearSpringForce.hpp"
37 #include "IsNan.hpp"
38 
39 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
41  : AbstractTwoBodyInteractionForce<ELEMENT_DIM,SPACE_DIM>(),
42  mMeinekeSpringStiffness(15.0), // denoted by mu in Meineke et al, 2001 (doi:10.1046/j.0960-7722.2001.00216.x)
43  mMeinekeDivisionRestingSpringLength(0.5),
44  mMeinekeSpringGrowthDuration(1.0)
45 {
46  if (SPACE_DIM == 1)
47  {
49  }
50 }
51 
52 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
54  unsigned nodeBGlobalIndex,
56  bool isCloserThanRestLength)
57 {
58  return 1.0;
59 }
60 
61 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
63 {
64 }
65 
66 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
67 c_vector<double, SPACE_DIM> GeneralisedLinearSpringForce<ELEMENT_DIM,SPACE_DIM>::CalculateForceBetweenNodes(unsigned nodeAGlobalIndex,
68  unsigned nodeBGlobalIndex,
70 {
71  // We should only ever calculate the force between two distinct nodes
72  assert(nodeAGlobalIndex != nodeBGlobalIndex);
73 
74  Node<SPACE_DIM>* p_node_a = rCellPopulation.GetNode(nodeAGlobalIndex);
75  Node<SPACE_DIM>* p_node_b = rCellPopulation.GetNode(nodeBGlobalIndex);
76 
77  // Get the node locations
78  c_vector<double, SPACE_DIM> node_a_location = p_node_a->rGetLocation();
79  c_vector<double, SPACE_DIM> node_b_location = p_node_b->rGetLocation();
80 
81  // Get the node radii for a NodeBasedCellPopulation
82  double node_a_radius = 0.0;
83  double node_b_radius = 0.0;
84 
85  if (bool(dynamic_cast<NodeBasedCellPopulation<SPACE_DIM>*>(&rCellPopulation)))
86  {
87  node_a_radius = p_node_a->GetRadius();
88  node_b_radius = p_node_b->GetRadius();
89  }
90 
91  // Get the unit vector parallel to the line joining the two nodes
92  c_vector<double, SPACE_DIM> unit_difference;
93  /*
94  * We use the mesh method GetVectorFromAtoB() to compute the direction of the
95  * unit vector along the line joining the two nodes, rather than simply subtract
96  * their positions, because this method can be overloaded (e.g. to enforce a
97  * periodic boundary in Cylindrical2dMesh).
98  */
99  unit_difference = rCellPopulation.rGetMesh().GetVectorFromAtoB(node_a_location, node_b_location);
100 
101  // Calculate the distance between the two nodes
102  double distance_between_nodes = norm_2(unit_difference);
103  assert(distance_between_nodes > 0);
104  assert(!std::isnan(distance_between_nodes));
105 
106  unit_difference /= distance_between_nodes;
107 
108  /*
109  * If mUseCutOffLength has been set, then there is zero force between
110  * two nodes located a distance apart greater than mMechanicsCutOffLength in AbstractTwoBodyInteractionForce.
111  */
112  if (this->mUseCutOffLength)
113  {
114  if (distance_between_nodes >= this->GetCutOffLength())
115  {
116  return zero_vector<double>(SPACE_DIM); // c_vector<double,SPACE_DIM>() is not guaranteed to be fresh memory
117  }
118  }
119 
120  /*
121  * Calculate the rest length of the spring connecting the two nodes with a default
122  * value of 1.0.
123  */
124  double rest_length_final = 1.0;
125 
126  if (bool(dynamic_cast<MeshBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>*>(&rCellPopulation)))
127  {
128  rest_length_final = static_cast<MeshBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>*>(&rCellPopulation)->GetRestLength(nodeAGlobalIndex, nodeBGlobalIndex);
129  }
130  else if (bool(dynamic_cast<NodeBasedCellPopulation<SPACE_DIM>*>(&rCellPopulation)))
131  {
132  assert(node_a_radius > 0 && node_b_radius > 0);
133  rest_length_final = node_a_radius+node_b_radius;
134  }
135 
136  double rest_length = rest_length_final;
137 
138  CellPtr p_cell_A = rCellPopulation.GetCellUsingLocationIndex(nodeAGlobalIndex);
139  CellPtr p_cell_B = rCellPopulation.GetCellUsingLocationIndex(nodeBGlobalIndex);
140 
141  double ageA = p_cell_A->GetAge();
142  double ageB = p_cell_B->GetAge();
143 
144  assert(!std::isnan(ageA));
145  assert(!std::isnan(ageB));
146 
147  /*
148  * If the cells are both newly divided, then the rest length of the spring
149  * connecting them grows linearly with time, until 1 hour after division.
150  */
151  if (ageA < mMeinekeSpringGrowthDuration && ageB < mMeinekeSpringGrowthDuration)
152  {
154 
155  std::pair<CellPtr,CellPtr> cell_pair = p_static_cast_cell_population->CreateCellPair(p_cell_A, p_cell_B);
156 
157  if (p_static_cast_cell_population->IsMarkedSpring(cell_pair))
158  {
159  // Spring rest length increases from a small value to the normal rest length over 1 hour
160  double lambda = mMeinekeDivisionRestingSpringLength;
161  rest_length = lambda + (rest_length_final - lambda) * ageA/mMeinekeSpringGrowthDuration;
162  }
163  if (ageA + SimulationTime::Instance()->GetTimeStep() >= mMeinekeSpringGrowthDuration)
164  {
165  // This spring is about to go out of scope
166  p_static_cast_cell_population->UnmarkSpring(cell_pair);
167  }
168  }
169 
170  /*
171  * For apoptosis, progressively reduce the radius of the cell
172  */
173  double a_rest_length = rest_length*0.5;
174  double b_rest_length = a_rest_length;
175 
176  if (bool(dynamic_cast<NodeBasedCellPopulation<SPACE_DIM>*>(&rCellPopulation)))
177  {
178  assert(node_a_radius > 0 && node_b_radius > 0);
179  a_rest_length = (node_a_radius/(node_a_radius+node_b_radius))*rest_length;
180  b_rest_length = (node_b_radius/(node_a_radius+node_b_radius))*rest_length;
181  }
182 
183  /*
184  * If either of the cells has begun apoptosis, then the length of the spring
185  * connecting them decreases linearly with time.
186  */
187  if (p_cell_A->HasApoptosisBegun())
188  {
189  double time_until_death_a = p_cell_A->GetTimeUntilDeath();
190  a_rest_length = a_rest_length * time_until_death_a / p_cell_A->GetApoptosisTime();
191  }
192  if (p_cell_B->HasApoptosisBegun())
193  {
194  double time_until_death_b = p_cell_B->GetTimeUntilDeath();
195  b_rest_length = b_rest_length * time_until_death_b / p_cell_B->GetApoptosisTime();
196  }
197 
198  rest_length = a_rest_length + b_rest_length;
199  //assert(rest_length <= 1.0+1e-12); ///\todo #1884 Magic number: would "<= 1.0" do?
200 
201  // Although in this class the 'spring constant' is a constant parameter, in
202  // subclasses it can depend on properties of each of the cells
203  double overlap = distance_between_nodes - rest_length;
204  bool is_closer_than_rest_length = (overlap <= 0);
205  double multiplication_factor = VariableSpringConstantMultiplicationFactor(nodeAGlobalIndex, nodeBGlobalIndex, rCellPopulation, is_closer_than_rest_length);
206  double spring_stiffness = mMeinekeSpringStiffness;
207 
208  if (bool(dynamic_cast<MeshBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>*>(&rCellPopulation)))
209  {
210  return multiplication_factor * spring_stiffness * unit_difference * overlap;
211  }
212  else
213  {
214  // A reasonably stable simple force law
215  if (is_closer_than_rest_length) //overlap is negative
216  {
217  //log(x+1) is undefined for x<=-1
218  assert(overlap > -rest_length_final);
219  c_vector<double, SPACE_DIM> temp = multiplication_factor*spring_stiffness * unit_difference * rest_length_final* log(1.0 + overlap/rest_length_final);
220  return temp;
221  }
222  else
223  {
224  double alpha = 5.0;
225  c_vector<double, SPACE_DIM> temp = multiplication_factor*spring_stiffness * unit_difference * overlap * exp(-alpha * overlap/rest_length_final);
226  return temp;
227  }
228  }
229 }
230 
231 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
233 {
234  return mMeinekeSpringStiffness;
235 }
236 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
238 {
239  return mMeinekeDivisionRestingSpringLength;
240 }
241 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
243 {
244  return mMeinekeSpringGrowthDuration;
245 }
246 
247 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
249 {
250  assert(springStiffness > 0.0);
251  mMeinekeSpringStiffness = springStiffness;
252 }
253 
254 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
256 {
257  assert(divisionRestingSpringLength <= 1.0);
258  assert(divisionRestingSpringLength >= 0.0);
259 
260  mMeinekeDivisionRestingSpringLength = divisionRestingSpringLength;
261 }
262 
263 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
265 {
266  assert(springGrowthDuration >= 0.0);
267 
268  mMeinekeSpringGrowthDuration = springGrowthDuration;
269 }
270 
271 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
273 {
274  *rParamsFile << "\t\t\t<MeinekeSpringStiffness>" << mMeinekeSpringStiffness << "</MeinekeSpringStiffness>\n";
275  *rParamsFile << "\t\t\t<MeinekeDivisionRestingSpringLength>" << mMeinekeDivisionRestingSpringLength << "</MeinekeDivisionRestingSpringLength>\n";
276  *rParamsFile << "\t\t\t<MeinekeSpringGrowthDuration>" << mMeinekeSpringGrowthDuration << "</MeinekeSpringGrowthDuration>\n";
277 
278  // Call method on direct parent class
280 }
281 
282 // Explicit instantiation
283 template class GeneralisedLinearSpringForce<1,1>;
284 template class GeneralisedLinearSpringForce<1,2>;
285 template class GeneralisedLinearSpringForce<2,2>;
286 template class GeneralisedLinearSpringForce<1,3>;
287 template class GeneralisedLinearSpringForce<2,3>;
288 template class GeneralisedLinearSpringForce<3,3>;
289 
290 // Serialization for Boost >= 1.36
virtual Node< SPACE_DIM > * GetNode(unsigned index)=0
virtual void OutputForceParameters(out_stream &rParamsFile)
void UnmarkSpring(std::pair< CellPtr, CellPtr > &rCellPair)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
Definition: Node.hpp:58
c_vector< double, SPACE_DIM > CalculateForceBetweenNodes(unsigned nodeAGlobalIndex, unsigned nodeBGlobalIndex, AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation)
static SimulationTime * Instance()
double GetTimeStep() const
std::pair< CellPtr, CellPtr > CreateCellPair(CellPtr pCell1, CellPtr pCell2)
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
void SetMeinekeDivisionRestingSpringLength(double divisionRestingSpringLength)
bool IsMarkedSpring(const std::pair< CellPtr, CellPtr > &rCellPair)
void SetMeinekeSpringGrowthDuration(double springGrowthDuration)
const c_vector< double, SPACE_DIM > & rGetLocation() const
Definition: Node.cpp:140
virtual double VariableSpringConstantMultiplicationFactor(unsigned nodeAGlobalIndex, unsigned nodeBGlobalIndex, AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation, bool isCloserThanRestLength)
AbstractMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
virtual void OutputForceParameters(out_stream &rParamsFile)
void SetMeinekeSpringStiffness(double springStiffness)
double GetRadius()
Definition: Node.cpp:249