CryptSimulation2d.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "CryptSimulation2d.hpp"
00037 #include "WntConcentration.hpp"
00038 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisOne.hpp"
00039 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisTwo.hpp"
00040 #include "CellBetaCateninWriter.hpp"
00041 #include "MeshBasedCellPopulation.hpp"
00042 #include "SmartPointers.hpp"
00043
00044 CryptSimulation2d::CryptSimulation2d(AbstractCellPopulation<2>& rCellPopulation,
00045 bool deleteCellPopulationInDestructor,
00046 bool initialiseCells)
00047 : OffLatticeSimulation<2>(rCellPopulation,
00048 deleteCellPopulationInDestructor,
00049 initialiseCells),
00050 mUsingMeshBasedCellPopulation(false)
00051 {
00052
00053
00054
00055
00056 if ( (dynamic_cast<VertexBasedCellPopulation<2>*>(&rCellPopulation) == NULL)
00057 &&(dynamic_cast<MeshBasedCellPopulation<2>*>(&rCellPopulation) == NULL) )
00058 {
00059 EXCEPTION("CryptSimulation2d is to be used with MeshBasedCellPopulation or VertexBasedCellPopulation (or subclasses) only");
00060 }
00061
00062 if (dynamic_cast<MeshBasedCellPopulation<2>*>(&mrCellPopulation))
00063 {
00064 mUsingMeshBasedCellPopulation = true;
00065 }
00066
00067 if (!mDeleteCellPopulationInDestructor)
00068 {
00069
00070 MAKE_PTR_ARGS(CryptSimulationBoundaryCondition<2>, p_bc, (&rCellPopulation));
00071 AddCellPopulationBoundaryCondition(p_bc);
00072 }
00073 }
00074
00075 CryptSimulation2d::~CryptSimulation2d()
00076 {
00077 }
00078
00079 c_vector<double, 2> CryptSimulation2d::CalculateCellDivisionVector(CellPtr pParentCell)
00080 {
00081 if (mUsingMeshBasedCellPopulation)
00082 {
00083
00084 c_vector<double, 2> parent_coords = mrCellPopulation.GetLocationOfCellCentre(pParentCell);
00085 c_vector<double, 2> daughter_coords;
00086
00087
00088 double separation =
00089 static_cast<MeshBasedCellPopulation<2>*>(&mrCellPopulation)->GetMeinekeDivisionSeparation();
00090
00091
00092 c_vector<double, 2> random_vector;
00093
00094
00095
00096
00097
00098
00099 double random_angle = RandomNumberGenerator::Instance()->ranf();
00100 random_angle *= 2.0*M_PI;
00101
00102 random_vector(0) = 0.5*separation*cos(random_angle);
00103 random_vector(1) = 0.5*separation*sin(random_angle);
00104
00105 c_vector<double, 2> proposed_new_parent_coords = parent_coords - random_vector;
00106 c_vector<double, 2> proposed_new_daughter_coords = parent_coords + random_vector;
00107
00108 if ((proposed_new_parent_coords(1) >= 0.0) && (proposed_new_daughter_coords(1) >= 0.0))
00109 {
00110
00111 parent_coords = proposed_new_parent_coords;
00112 daughter_coords = proposed_new_daughter_coords;
00113 }
00114 else
00115 {
00116 proposed_new_daughter_coords = parent_coords + 2.0*random_vector;
00117 while (proposed_new_daughter_coords(1) < 0.0)
00118 {
00119 random_angle = RandomNumberGenerator::Instance()->ranf();
00120 random_angle *= 2.0*M_PI;
00121
00122 random_vector(0) = separation*cos(random_angle);
00123 random_vector(1) = separation*sin(random_angle);
00124 proposed_new_daughter_coords = parent_coords + random_vector;
00125 }
00126 daughter_coords = proposed_new_daughter_coords;
00127 }
00128
00129 assert(daughter_coords(1) >= 0.0);
00130 assert(parent_coords(1) >= 0.0);
00131
00132
00133 ChastePoint<2> parent_coords_point(parent_coords);
00134
00135 unsigned node_index = mrCellPopulation.GetLocationIndexUsingCell(pParentCell);
00136 mrCellPopulation.SetNode(node_index, parent_coords_point);
00137
00138 return daughter_coords;
00139 }
00140 else
00141 {
00142
00143 assert(dynamic_cast<VertexBasedCellPopulation<2>*>(&(this->mrCellPopulation)));
00144
00145 VertexBasedCellPopulation<2>* p_vertex_population = dynamic_cast<VertexBasedCellPopulation<2>*>(&(this->mrCellPopulation));
00146 c_vector<double, 2> axis_of_division = p_vertex_population->
00147 GetVertexBasedDivisionRule()->CalculateCellDivisionVector(pParentCell, *p_vertex_population);
00148
00149
00150 bool is_wnt_included = WntConcentration<2>::Instance()->IsWntSetUp();
00151 if (!is_wnt_included)
00152 {
00153 WntConcentration<2>::Destroy();
00154 if (pParentCell->GetCellProliferativeType()->IsType<StemCellProliferativeType>())
00155 {
00156 axis_of_division(0) = 1.0;
00157 axis_of_division(1) = 0.0;
00158 }
00159 }
00160 return axis_of_division;
00161 }
00162 }
00163
00164 void CryptSimulation2d::SetupSolve()
00165 {
00166
00167 OffLatticeSimulation<2>::SetupSolve();
00168
00169
00170
00171
00172
00173
00174
00175 if (dynamic_cast<AbstractVanLeeuwen2009WntSwatCellCycleModel*>(this->mrCellPopulation.Begin()->GetCellCycleModel()))
00176 {
00177 mrCellPopulation.AddCellWriter<CellBetaCateninWriter>();
00178 }
00179
00180 if (dynamic_cast<AbstractVanLeeuwen2009WntSwatCellCycleModel*>(mrCellPopulation.Begin()->GetCellCycleModel()))
00181 {
00182 *mpVizSetupFile << "BetaCatenin\n";
00183 }
00184 }
00185
00186 void CryptSimulation2d::UseJiggledBottomCells()
00187 {
00188
00189 boost::static_pointer_cast<CryptSimulationBoundaryCondition<2> >(mBoundaryConditions[0])->SetUseJiggledBottomCells(true);
00190 }
00191
00192 void CryptSimulation2d::SetBottomCellAncestors()
00193 {
00194
00195
00196
00197
00198
00199 double threshold_height = 1.0;
00200 if (mUsingMeshBasedCellPopulation)
00201 {
00202 threshold_height = 0.5;
00203 }
00204
00205 unsigned index = 0;
00206 for (AbstractCellPopulation<2>::Iterator cell_iter = mrCellPopulation.Begin();
00207 cell_iter != mrCellPopulation.End();
00208 ++cell_iter)
00209 {
00210 if (mrCellPopulation.GetLocationOfCellCentre(*cell_iter)[1] < threshold_height)
00211 {
00212 MAKE_PTR_ARGS(CellAncestor, p_cell_ancestor, (index++));
00213 cell_iter->SetAncestor(p_cell_ancestor);
00214 }
00215 }
00216 }
00217
00218 void CryptSimulation2d::OutputSimulationParameters(out_stream& rParamsFile)
00219 {
00220 double width = mrCellPopulation.GetWidth(0);
00221 bool use_jiggled_bottom_cells = boost::static_pointer_cast<CryptSimulationBoundaryCondition<2> >(mBoundaryConditions[0])->GetUseJiggledBottomCells();
00222
00223 *rParamsFile << "\t\t<CryptCircumference>" << width << "</CryptCircumference>\n";
00224 *rParamsFile << "\t\t<UseJiggledBottomCells>" << use_jiggled_bottom_cells << "</UseJiggledBottomCells>\n";
00225
00226
00227 OffLatticeSimulation<2>::OutputSimulationParameters(rParamsFile);
00228 }
00229
00230
00231 #include "SerializationExportWrapperForCpp.hpp"
00232 CHASTE_CLASS_EXPORT(CryptSimulation2d)