Chaste  Release::2017.1
DiffusionForce.cpp
1 /*
2 
3 Copyright (c) 2005-2017, 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 "DiffusionForce.hpp"
37 #include "NodeBasedCellPopulation.hpp"
38 
39 //Static constant is instantiated here.
40 template<unsigned DIM>
41 const double DiffusionForce<DIM>::msBoltzmannConstant = 4.97033568e-7;
42 
43 template<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 
51 template<unsigned DIM>
53 {
54 }
55 
56 template<unsigned DIM>
58 {
59  assert(newValue > 0.0);
60  mAbsoluteTemperature = newValue;
61 }
62 
63 template<unsigned DIM>
65 {
66  return mAbsoluteTemperature;
67 }
68 
69 template<unsigned DIM>
70 void DiffusionForce<DIM>::SetViscosity(double newValue)
71 {
72  assert(newValue > 0.0);
73  mViscosity = newValue;
74 }
75 
76 template<unsigned DIM>
78 {
79  return mViscosity;
80 }
81 
82 template<unsigned DIM>
84 {
86 }
87 
88 template<unsigned DIM>
90 {
91  double dt = SimulationTime::Instance()->GetTimeStep();
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 
142 template<unsigned DIM>
143 void DiffusionForce<DIM>::OutputForceParameters(out_stream& rParamsFile)
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
153 template class DiffusionForce<1>;
154 template class DiffusionForce<2>;
155 template class DiffusionForce<3>;
156 
157 // Serialization for Boost >= 1.36
#define EXCEPTION(message)
Definition: Exception.hpp:143
static SimulationTime * Instance()
double GetAbsoluteTemperature()
NodeIterator GetNodeIteratorEnd()
double GetTimeStep() const
double GetViscosity()
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
static RandomNumberGenerator * Instance()
NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true)
double GetDiffusionScalingConstant()
static const double msBoltzmannConstant
double mAbsoluteTemperature
AbstractMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
void AddForceContribution(AbstractCellPopulation< DIM > &rCellPopulation)
void SetViscosity(double viscosity)
void OutputForceParameters(out_stream &rParamsFile)
virtual void OutputForceParameters(out_stream &rParamsFile)=0
void SetAbsoluteTemperature(double absoluteTemperature)