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 
00032 
00033 CryptSimulation1d::CryptSimulation1d(AbstractCellPopulation<1>& rCellPopulation,
00034                   bool deleteCellPopulationAndForceCollection,
00035                   bool initialiseCells)
00036     : CellBasedSimulation<1>(rCellPopulation,
00037                           deleteCellPopulationAndForceCollection,
00038                           initialiseCells)
00039 {
00040     mpStaticCastCellPopulation = static_cast<MeshBasedCellPopulation<1>*>(&mrCellPopulation);
00041 }
00042 
00043 
00044 c_vector<double, 1> CryptSimulation1d::CalculateCellDivisionVector(CellPtr pParentCell)
00045 {
00046     // Location of parent and daughter cells
00047     c_vector<double, 1> parent_coords = mpStaticCastCellPopulation->GetLocationOfCellCentre(pParentCell);
00048     c_vector<double, 1> daughter_coords;
00049 
00050     // Get separation parameter
00051     double separation = mpStaticCastCellPopulation->GetMeinekeDivisionSeparation();
00052 
00053     // Make a random direction vector of the required length
00054     c_vector<double, 1> random_vector;
00055 
00056     /*
00057      * Pick a random direction and move the parent cell backwards by 0.5*separation
00058      * in that direction and return the position of the daughter cell 0.5*separation
00059      * forwards in that direction.
00060      */
00061 
00062     double random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
00063     random_vector(0) = 0.5*separation*random_direction;
00064     c_vector<double, 1> proposed_new_parent_coords = parent_coords - random_vector;
00065     c_vector<double, 1> proposed_new_daughter_coords = parent_coords + random_vector;
00066 
00067     if (   (proposed_new_parent_coords(0) >= 0.0)
00068         && (proposed_new_daughter_coords(0) >= 0.0))
00069     {
00070         // We are not too close to the bottom of the cell population, so move parent
00071         parent_coords = proposed_new_parent_coords;
00072         daughter_coords = proposed_new_daughter_coords;
00073     }
00074     else
00075     {
00076         proposed_new_daughter_coords = parent_coords + 2.0*random_vector;
00077         while (proposed_new_daughter_coords(0) < 0.0)
00078         {
00079             double random_direction = -1.0 + 2.0*(RandomNumberGenerator::Instance()->ranf() < 0.5);
00080             random_vector(0) = 0.5*separation*random_direction;
00081             proposed_new_daughter_coords = parent_coords + random_vector;
00082         }
00083         daughter_coords = proposed_new_daughter_coords;
00084     }
00085 
00086     assert(daughter_coords(0) >= 0.0); // to make sure dividing cells stay in the cell population
00087     assert(parent_coords(0) >= 0.0);   // to make sure dividing cells stay in the cell population
00088 
00089     // Set the parent to use this location
00090     ChastePoint<1> parent_coords_point(parent_coords);
00091 
00092     unsigned node_index = mpStaticCastCellPopulation->GetLocationIndexUsingCell(pParentCell);
00093     mrCellPopulation.SetNode(node_index, parent_coords_point);
00094 
00095     return daughter_coords;
00096 }
00097 
00098 
00099 void CryptSimulation1d::ApplyCellPopulationBoundaryConditions(const std::vector< c_vector<double, 1> >& rOldLocations)
00100 {
00101     bool is_wnt_included = WntConcentration<1>::Instance()->IsWntSetUp();
00102     if (!is_wnt_included)
00103     {
00104         WntConcentration<1>::Destroy();
00105     }
00106 
00107     // Iterate over all nodes associated with real cells to update their positions
00108     // according to any cell population boundary conditions
00109     for (AbstractCellPopulation<1>::Iterator cell_iter = mrCellPopulation.Begin();
00110          cell_iter != mrCellPopulation.End();
00111          ++cell_iter)
00112     {
00113         // Get index of node associated with cell
00114         unsigned node_index = mpStaticCastCellPopulation->GetLocationIndexUsingCell(*cell_iter);
00115 
00116         // Get pointer to this node
00117         Node<1>* p_node = mpStaticCastCellPopulation->GetNodeCorrespondingToCell(*cell_iter);
00118 
00119         if (!is_wnt_included)
00120         {
00125             if (cell_iter->GetCellCycleModel()->GetCellProliferativeType()==STEM)
00126             {
00127                 // Get old node location
00128                 c_vector<double, 1> old_node_location = rOldLocations[node_index];
00129 
00130                 // Return node to old location
00131                 p_node->rGetModifiableLocation()[0] = old_node_location[0];
00132             }
00133         }
00134 
00135         // Any cell that has moved below the bottom of the crypt must be moved back up
00136         if (p_node->rGetLocation()[0] < 0.0)
00137         {
00138             p_node->rGetModifiableLocation()[0] = 0.0;
00139         }
00140         assert(p_node->rGetLocation()[0] >= 0.0);
00141     }
00142 }
00143 
00144 void CryptSimulation1d::OutputSimulationParameters(out_stream& rParamsFile)
00145 {
00146     // No parameters to output
00147 
00148     // Call method on direct parent class
00149     CellBasedSimulation<1>::OutputSimulationParameters(rParamsFile);
00150 }
00151 
00152 // Serialization for Boost >= 1.36
00153 #include "SerializationExportWrapperForCpp.hpp"
00154 CHASTE_CLASS_EXPORT(CryptSimulation1d)

Generated on Mon Apr 18 11:35:28 2011 for Chaste by  doxygen 1.5.5