Chaste Release::3.1
DiffusionForce.cpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #include "DiffusionForce.hpp"
00037 #include "NodeBasedCellPopulation.hpp"
00038 
00039 template<unsigned DIM>
00040 DiffusionForce<DIM>::DiffusionForce()
00041     : AbstractForce<DIM>(),
00042       mDiffusionConstant(0.01),
00043       mAbsoluteTemperature(296.0), // default to room temperature
00044       mViscosity(3.204e-6), // default to viscosity of water at room temperature in (using microns and hours)
00045       mMechanicsCutOffLength(10.0)
00046 {
00047 }
00048 
00049 template<unsigned DIM>
00050 DiffusionForce<DIM>::~DiffusionForce()
00051 {
00052 }
00053 
00054 template<unsigned DIM>
00055 void DiffusionForce<DIM>::SetCutOffLength(double cutOffLength)
00056 {
00057     assert(cutOffLength > 0.0);
00058     mMechanicsCutOffLength=cutOffLength;
00059 }
00060 
00061 
00062 template<unsigned DIM>
00063 double DiffusionForce<DIM>::GetCutOffLength()
00064 {
00065     return mMechanicsCutOffLength;
00066 }
00067 
00068 template<unsigned DIM>
00069 void DiffusionForce<DIM>::SetDiffusionConstant(double diffusionConstant)
00070 {
00071     assert(diffusionConstant > 0.0);
00072     mDiffusionConstant = diffusionConstant;
00073 }
00074 
00075 template<unsigned DIM>
00076 double DiffusionForce<DIM>::GetDiffusionConstant()
00077 {
00078     return mDiffusionConstant;
00079 }
00080 
00081 template<unsigned DIM>
00082 void DiffusionForce<DIM>::SetAbsoluteTemperature(double newValue)
00083 {
00084     assert(newValue > 0.0);
00085     mAbsoluteTemperature = newValue;
00086 }
00087 
00088 template<unsigned DIM>
00089 double DiffusionForce<DIM>::GetAbsoluteTemperature()
00090 {
00091     return mAbsoluteTemperature;
00092 }
00093 
00094 template<unsigned DIM>
00095 void DiffusionForce<DIM>::SetViscosity(double newValue)
00096 {
00097     assert(newValue > 0.0);
00098     mViscosity = newValue;
00099 }
00100 
00101 template<unsigned DIM>
00102 double DiffusionForce<DIM>::GetViscosity()
00103 {
00104     return mViscosity;
00105 }
00106 
00107 template<unsigned DIM>
00108 void DiffusionForce<DIM>::AddForceContribution(std::vector<c_vector<double, DIM> >& rForces,
00109                           AbstractCellPopulation<DIM>& rCellPopulation)
00110 {
00111     double dt = SimulationTime::Instance()->GetTimeStep();
00112 
00113     // Loop over the cells
00114     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = rCellPopulation.Begin();
00115          cell_iter != rCellPopulation.End();
00116          ++cell_iter)
00117     {
00118         // Get the radius, damping constant and node index associated with this cell
00119         unsigned node_index = rCellPopulation.GetLocationIndexUsingCell(*cell_iter);
00120         double nu = dynamic_cast<AbstractOffLatticeCellPopulation<DIM>*>(&rCellPopulation)->GetDampingConstant(node_index);
00121         double cell_radius = dynamic_cast<NodeBasedCellPopulation<DIM>*>(&rCellPopulation)->rGetMesh().GetCellRadius(node_index);
00122 
00123         /*
00124          * Compute the diffusion coefficient D as D = k*T/(6*pi*eta*r), where
00125          *
00126          * k = Boltzmann's constant,
00127          * T = absolute temperature,
00128          * eta = dynamic viscosity,
00129          * r = cell radius.
00130          */
00131         double boltzmann_constant = 1.3806488e-23;
00132         double diffusion_const_scaling = boltzmann_constant*mAbsoluteTemperature/(6.0*mViscosity*M_PI);
00133         double diffusion_constant = diffusion_const_scaling/cell_radius;
00134 
00135         c_vector<double, DIM> force_contribution;
00136         for (unsigned i=0; i<DIM; i++)
00137         {
00138             /*
00139              * The force on this cell is scaled with the timestep such that when it is
00140              * used in the discretised equation of motion for the cell, we obtain the
00141              * correct formula
00142              *
00143              * x_new = x_old + sqrt(2*D*dt)*W
00144              *
00145              * where W is a standard normal random variable.
00146              */
00147             double xi = RandomNumberGenerator::Instance()->StandardNormalRandomDeviate();
00148 
00149             force_contribution[i] = (nu*sqrt(2.0*diffusion_constant*dt)/dt)*xi;
00150         }
00151         rForces[node_index] += force_contribution;
00152     }
00153 }
00154 
00155 template<unsigned DIM>
00156 void DiffusionForce<DIM>::OutputForceParameters(out_stream& rParamsFile)
00157 {
00158     *rParamsFile << "\t\t\t<DiffusionConstant>" << mDiffusionConstant << "</DiffusionConstant> \n";
00159     *rParamsFile << "\t\t\t<MechanicsCutOffLength>" << mMechanicsCutOffLength << "</MechanicsCutOffLength> \n";
00160 
00161     // Call direct parent class
00162     AbstractForce<DIM>::OutputForceParameters(rParamsFile);
00163 }
00164 
00166 // Explicit instantiation
00168 
00169 template class DiffusionForce<1>;
00170 template class DiffusionForce<2>;
00171 template class DiffusionForce<3>;
00172 
00173 // Serialization for Boost >= 1.36
00174 #include "SerializationExportWrapperForCpp.hpp"
00175 EXPORT_TEMPLATE_CLASS_SAME_DIMS(DiffusionForce)