CryptSimulation1d.cpp

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

Generated by  doxygen 1.6.2