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