CryptSimulation1d.cpp

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 "CryptSimulation1d.hpp"
00030 #include "WntConcentration.hpp"
00031 #include "SmartPointers.hpp"
00032 
00033 CryptSimulation1d::CryptSimulation1d(AbstractCellPopulation<1>& rCellPopulation,
00034                   bool deleteCellPopulationInDestructor,
00035                   bool initialiseCells)
00036     : OffLatticeSimulation<1>(rCellPopulation,
00037                           deleteCellPopulationInDestructor,
00038                           initialiseCells)
00039 {
00040     mpStaticCastCellPopulation = static_cast<MeshBasedCellPopulation<1>*>(&mrCellPopulation);
00041 
00042     if (!mDeleteCellPopulationInDestructor)
00043     {
00044         // Pass a CryptSimulationBoundaryCondition object into mBoundaryConditions
00045         MAKE_PTR_ARGS(CryptSimulationBoundaryCondition<1>, p_bc, (&rCellPopulation));
00046         AddCellPopulationBoundaryCondition(p_bc);
00047     }
00048 }
00049 
00050 CryptSimulation1d::~CryptSimulation1d()
00051 {
00052 }
00053 
00054 c_vector<double, 1> CryptSimulation1d::CalculateCellDivisionVector(CellPtr pParentCell)
00055 {
00056     // Location of parent and daughter cells
00057     c_vector<double, 1> parent_coords = mpStaticCastCellPopulation->GetLocationOfCellCentre(pParentCell);
00058     c_vector<double, 1> daughter_coords;
00059 
00060     // Get separation parameter
00061     double separation = mpStaticCastCellPopulation->GetMeinekeDivisionSeparation();
00062 
00063     // Make a random direction vector of the required length
00064     c_vector<double, 1> random_vector;
00065 
00066     /*
00067      * Pick a random direction and move the parent cell backwards by 0.5*separation
00068      * in that direction and return the position of the daughter cell 0.5*separation
00069      * forwards in that direction.
00070      */
00071 
00072     double random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
00073     random_vector(0) = 0.5*separation*random_direction;
00074     c_vector<double, 1> proposed_new_parent_coords = parent_coords - random_vector;
00075     c_vector<double, 1> proposed_new_daughter_coords = parent_coords + random_vector;
00076 
00077     if (   (proposed_new_parent_coords(0) >= 0.0)
00078         && (proposed_new_daughter_coords(0) >= 0.0))
00079     {
00080         // We are not too close to the bottom of the cell population, so move parent
00081         parent_coords = proposed_new_parent_coords;
00082         daughter_coords = proposed_new_daughter_coords;
00083     }
00084     else
00085     {
00086         proposed_new_daughter_coords = parent_coords + 2.0*random_vector;
00087         while (proposed_new_daughter_coords(0) < 0.0)
00088         {
00089             double random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
00090             random_vector(0) = 0.5*separation*random_direction;
00091             proposed_new_daughter_coords = parent_coords + random_vector;
00092         }
00093         daughter_coords = proposed_new_daughter_coords;
00094     }
00095 
00096     assert(daughter_coords(0) >= 0.0); // to make sure dividing cells stay in the cell population
00097     assert(parent_coords(0) >= 0.0);   // to make sure dividing cells stay in the cell population
00098 
00099     // Set the parent to use this location
00100     ChastePoint<1> parent_coords_point(parent_coords);
00101 
00102     unsigned node_index = mpStaticCastCellPopulation->GetLocationIndexUsingCell(pParentCell);
00103     mrCellPopulation.SetNode(node_index, parent_coords_point);
00104 
00105     return daughter_coords;
00106 }
00107 
00108 void CryptSimulation1d::OutputSimulationParameters(out_stream& rParamsFile)
00109 {
00110     // No parameters to output
00111 
00112     // Call method on direct parent class
00113     OffLatticeSimulation<1>::OutputSimulationParameters(rParamsFile);
00114 }
00115 
00116 // Serialization for Boost >= 1.36
00117 #include "SerializationExportWrapperForCpp.hpp"
00118 CHASTE_CLASS_EXPORT(CryptSimulation1d)
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3