00001 /* 00002 00003 Copyright (C) University of Oxford, 2005-2011 00004 00005 University of Oxford means the Chancellor, Masters and Scholars of the 00006 University of Oxford, having an administrative office at Wellington 00007 Square, Oxford OX1 2JD, UK. 00008 00009 This file is part of Chaste. 00010 00011 Chaste is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU Lesser General Public License as published 00013 by the Free Software Foundation, either version 2.1 of the License, or 00014 (at your option) any later version. 00015 00016 Chaste is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00019 License for more details. The offer of Chaste under the terms of the 00020 License is subject to the License being interpreted in accordance with 00021 English Law and subject to any action against the University of Oxford 00022 being under the jurisdiction of the English Courts. 00023 00024 You should have received a copy of the GNU Lesser General Public License 00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>. 00026 00027 */ 00028 00029 #include "DiffusionCaUpdateRule.hpp" 00030 00031 #include "RandomNumberGenerator.hpp" 00032 00033 template<unsigned DIM> 00034 DiffusionCaUpdateRule<DIM>::DiffusionCaUpdateRule(double diffusionConstant) 00035 : AbstractCaUpdateRule<DIM>(), 00036 mDiffusionConstant(diffusionConstant) 00037 { 00038 } 00039 00040 template<unsigned DIM> 00041 DiffusionCaUpdateRule<DIM>::~DiffusionCaUpdateRule() 00042 { 00043 } 00044 00045 template<unsigned DIM> 00046 unsigned DiffusionCaUpdateRule<DIM>::GetNewLocationOfCell(unsigned currentLocationIndex, 00047 CaBasedCellPopulation<DIM>& rCellPopulation, 00048 double dt) 00049 { 00050 assert(DIM == 2); // this method only works in 2D at present 00051 00052 // Make sure we have a cell at this node 00053 if (rCellPopulation.IsEmptySite(currentLocationIndex)) 00054 { 00055 EXCEPTION("There is no cell at the current location."); 00056 } 00057 00058 unsigned new_location_index = currentLocationIndex; 00059 00060 double probability_of_moving = dt*mDiffusionConstant; 00061 00062 if (RandomNumberGenerator::Instance()->ranf() < probability_of_moving) 00063 { 00064 // Find a random site from all of the available neighbouring nodes to move into 00065 std::set<unsigned> free_neighbour_indices = rCellPopulation.GetFreeNeighbouringNodeIndices(currentLocationIndex); 00066 00067 if (!free_neighbour_indices.empty()) // only move if there is any free space 00068 { 00069 unsigned num_free_neighbours = free_neighbour_indices.size(); 00070 unsigned chosen_neighbour = RandomNumberGenerator::Instance()->randMod(num_free_neighbours); 00071 00072 std::set<unsigned>::iterator neighbour_iter = free_neighbour_indices.begin(); 00073 for (unsigned i=0; i<chosen_neighbour; i++) 00074 { 00075 neighbour_iter++; 00076 } 00077 new_location_index = *neighbour_iter; 00078 } 00079 } 00080 00081 return new_location_index; 00082 } 00083 00084 template<unsigned DIM> 00085 double DiffusionCaUpdateRule<DIM>::GetDiffusionConstant() 00086 { 00087 return mDiffusionConstant; 00088 } 00089 00090 template<unsigned DIM> 00091 void DiffusionCaUpdateRule<DIM>::OutputUpdateRuleParameters(out_stream& rParamsFile) 00092 { 00093 *rParamsFile << "\t\t\t<DiffusionConstant>" << mDiffusionConstant << "</DiffusionConstant>\n"; 00094 00095 // Call method on direct parent class 00096 AbstractCaUpdateRule<DIM>::OutputUpdateRuleParameters(rParamsFile); 00097 } 00098 00100 // Explicit instantiation 00102 00103 template class DiffusionCaUpdateRule<1>; 00104 template class DiffusionCaUpdateRule<2>; 00105 template class DiffusionCaUpdateRule<3>; 00106 00107 // Serialization for Boost >= 1.36 00108 #include "SerializationExportWrapperForCpp.hpp" 00109 EXPORT_TEMPLATE_CLASS_SAME_DIMS(DiffusionCaUpdateRule)