Chaste Commit::6e4f5fe395bca70eb7641cf6e0e87f450383ca5a
DiffusionForce.cpp
1/*
2
3Copyright (c) 2005-2026, 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 "DiffusionForce.hpp"
37
38//Static constant is instantiated here.
39template<unsigned DIM>
40const double DiffusionForce<DIM>::msBoltzmannConstant = 4.97033568e-7;
41
42template<unsigned DIM>
44 : AbstractForce<DIM>(),
45 mAbsoluteTemperature(296.0), // default to room temperature
46 mViscosity(3.204e-6) // default to viscosity of water at room temperature in (using 10 microns and hours)
47{
48}
49
50template<unsigned DIM>
54
55template<unsigned DIM>
57{
58 assert(newValue > 0.0);
59 mAbsoluteTemperature = newValue;
60}
61
62template<unsigned DIM>
64{
65 return mAbsoluteTemperature;
66}
67
68template<unsigned DIM>
70{
71 assert(newValue > 0.0);
72 mViscosity = newValue;
73}
74
75template<unsigned DIM>
77{
78 return mViscosity;
79}
80
81template<unsigned DIM>
83{
84 return msBoltzmannConstant*mAbsoluteTemperature/(6.0*mViscosity*M_PI);
85}
86
87template<unsigned DIM>
89{
91
92 // Iterate over the nodes
93 for (typename AbstractMesh<DIM, DIM>::NodeIterator node_iter = rCellPopulation.rGetMesh().GetNodeIteratorBegin();
94 node_iter != rCellPopulation.rGetMesh().GetNodeIteratorEnd();
95 ++node_iter)
96 {
97 // Get the index, radius and damping constant of this node
98 unsigned node_index = node_iter->GetIndex();
99 double node_radius = node_iter->GetRadius();
100
101 // If the node radius is zero, then it has not been set...
102 if (node_radius == 0.0)
103 {
104 // ...so throw an exception to avoid dividing by zero when we compute diffusion_constant below
105 EXCEPTION("SetRadius() must be called on each Node before calling DiffusionForce::AddForceContribution() to avoid a division by zero error");
106 }
107
108 double nu = dynamic_cast<AbstractOffLatticeCellPopulation<DIM>*>(&rCellPopulation)->GetDampingConstant(node_index);
109
110 /*
111 * Compute the diffusion coefficient D as D = k*T/(6*pi*eta*r), where
112 *
113 * k = Boltzmann's constant,
114 * T = absolute temperature,
115 * eta = dynamic viscosity,
116 * r = cell radius.
117 */
118 double diffusion_const_scaling = GetDiffusionScalingConstant();
119 double diffusion_constant = diffusion_const_scaling/node_radius;
120
121 c_vector<double, DIM> force_contribution;
122 for (unsigned i=0; i<DIM; i++)
123 {
124 /*
125 * The force on this cell is scaled with the timestep such that when it is
126 * used in the discretised equation of motion for the cell, we obtain the
127 * correct formula
128 *
129 * x_new = x_old + sqrt(2*D*dt)*W
130 *
131 * where W is a standard normal random variable.
132 */
134
135 force_contribution[i] = (nu*sqrt(2.0*diffusion_constant*dt)/dt)*xi;
136 }
137 node_iter->AddAppliedForceContribution(force_contribution);
138 }
139}
140
141template<unsigned DIM>
143{
144 *rParamsFile << "\t\t\t<AbsoluteTemperature>" << mAbsoluteTemperature << "</AbsoluteTemperature> \n";
145 *rParamsFile << "\t\t\t<Viscosity>" << mViscosity << "</Viscosity> \n";
146
147 // Call direct parent class
149}
150
151// Explicit instantiation
152template class DiffusionForce<1>;
153template class DiffusionForce<2>;
154template class DiffusionForce<3>;
155
156// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
AbstractMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
virtual void OutputForceParameters(out_stream &rParamsFile)=0
double GetDiffusionScalingConstant()
void SetViscosity(double viscosity)
double GetAbsoluteTemperature()
void AddForceContribution(AbstractCellPopulation< DIM > &rCellPopulation)
void SetAbsoluteTemperature(double absoluteTemperature)
void OutputForceParameters(out_stream &rParamsFile)
static RandomNumberGenerator * Instance()
double GetTimeStep() const
static SimulationTime * Instance()