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