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 #ifndef CELLBASEDSIMULATION_HPP_
00029 #define CELLBASEDSIMULATION_HPP_
00030
00031 #include "ChasteSerialization.hpp"
00032 #include <boost/serialization/vector.hpp>
00033 #include <boost/serialization/string.hpp>
00034
00035 #include <vector>
00036
00037 #include "AbstractForce.hpp"
00038 #include "AbstractCellKiller.hpp"
00039 #include "AbstractCellPopulation.hpp"
00040 #include "RandomNumberGenerator.hpp"
00041 #include "Identifiable.hpp"
00042
00058 template<unsigned DIM>
00059 class CellBasedSimulation : public Identifiable
00060 {
00061
00062
00063 friend class TestCryptSimulation2d;
00064 friend class TestCellBasedSimulation3d;
00065 friend class TestCellBasedSimulation;
00066
00067 protected:
00068
00070 double mDt;
00071
00073 double mEndTime;
00074
00076 AbstractCellPopulation<DIM>& mrCellPopulation;
00077
00079 bool mDeleteCellPopulation;
00080
00082 bool mAllocatedMemoryForForceCollection;
00083
00085 bool mInitialiseCells;
00086
00088 bool mNoBirth;
00089
00091 bool mUpdateCellPopulation;
00092
00094 std::string mOutputDirectory;
00095
00097 std::string mSimulationOutputDirectory;
00098
00100 out_stream mpVizSetupFile;
00101
00103 out_stream mpNodeVelocitiesFile;
00104
00106 RandomNumberGenerator* mpRandomGenerator;
00107
00109 unsigned mNumBirths;
00110
00112 unsigned mNumDeaths;
00113
00118 unsigned mSamplingTimestepMultiple;
00119
00121 std::vector<AbstractCellKiller<DIM>*> mCellKillers;
00122
00124 std::vector<AbstractForce<DIM>*> mForceCollection;
00125
00127 bool mOutputNodeVelocities;
00128
00130 friend class boost::serialization::access;
00142 template<class Archive>
00143 void serialize(Archive & archive, const unsigned int version)
00144 {
00145 mpRandomGenerator = RandomNumberGenerator::Instance();
00146 archive & *mpRandomGenerator;
00147 archive & mpRandomGenerator;
00148
00149
00150
00151 archive & mDt;
00152 archive & mEndTime;
00153 archive & mNoBirth;
00154 archive & mUpdateCellPopulation;
00155 archive & mOutputDirectory;
00156 archive & mNumBirths;
00157 archive & mNumDeaths;
00158 archive & mCellKillers;
00159 archive & mSamplingTimestepMultiple;
00160 archive & mForceCollection;
00161 archive & mOutputNodeVelocities;
00162 }
00163
00167 virtual void WriteVisualizerSetupFile()
00168 {
00169 }
00170
00178 virtual unsigned DoCellBirth();
00179
00197 virtual c_vector<double, DIM> CalculateCellDivisionVector(CellPtr pParentCell);
00198
00207 unsigned DoCellRemoval();
00208
00216 virtual void UpdateNodePositions(const std::vector< c_vector<double, DIM> >& rNodeForces);
00217
00223 virtual void ApplyCellPopulationBoundaryConditions(const std::vector< c_vector<double, DIM> >& rOldLocations)
00224 {
00225 }
00226
00230 virtual void PostSolve()
00231 {
00232 }
00233
00237 virtual void SetupSolve()
00238 {
00239 }
00240
00245 virtual void AfterSolve()
00246 {
00247 }
00248
00254 virtual bool StoppingEventHasOccurred();
00255
00259 void UpdateCellPopulation();
00260
00264 void OutputSimulationSetup();
00265
00266
00267 public:
00268
00276 CellBasedSimulation(AbstractCellPopulation<DIM>& rCellPopulation,
00277 bool deleteCellPopulationAndForceCollection=false,
00278 bool initialiseCells=true);
00279
00285 virtual ~CellBasedSimulation();
00286
00293 std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
00294
00298 double GetDt();
00299
00303 unsigned GetNumBirths();
00304
00308 unsigned GetNumDeaths();
00309
00313 std::string GetOutputDirectory();
00314
00320 void SetDt(double dt);
00321
00327 void SetEndTime(double endTime);
00328
00334 void SetOutputDirectory(std::string outputDirectory);
00335
00342 void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
00343
00349 void SetNoBirth(bool noBirth);
00350
00356 void SetUpdateCellPopulationRule(bool updateCellPopulation);
00357
00363 void AddCellKiller(AbstractCellKiller<DIM>* pCellKiller);
00364
00370 void AddForce(AbstractForce<DIM>* pForce);
00371
00382 void Solve();
00383
00387 AbstractCellPopulation<DIM>& rGetCellPopulation();
00388
00392 const AbstractCellPopulation<DIM>& rGetCellPopulation() const;
00393
00397 const std::vector<AbstractForce<DIM>*> rGetForceCollection() const;
00398
00402 bool GetOutputNodeVelocities();
00403
00409 void SetOutputNodeVelocities(bool outputNodeVelocities);
00410
00419 virtual void OutputSimulationParameters(out_stream& rParamsFile);
00420 };
00421
00422
00423 #include "SerializationExportWrapper.hpp"
00424 EXPORT_TEMPLATE_CLASS_SAME_DIMS(CellBasedSimulation)
00425
00426
00427 namespace boost
00428 {
00429 namespace serialization
00430 {
00435 template<class Archive, unsigned DIM>
00436 inline void save_construct_data(
00437 Archive & ar, const CellBasedSimulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00438 {
00439
00440 const AbstractCellPopulation<DIM>* p_cell_population = &(t->rGetCellPopulation());
00441 ar & p_cell_population;
00442 }
00443
00447 template<class Archive, unsigned DIM>
00448 inline void load_construct_data(
00449 Archive & ar, CellBasedSimulation<DIM> * t, const unsigned int file_version)
00450 {
00451
00452 AbstractCellPopulation<DIM>* p_cell_population;
00453 ar >> p_cell_population;
00454
00455
00456 ::new(t)CellBasedSimulation<DIM>(*p_cell_population, true, false);
00457 }
00458 }
00459 }
00460
00461
00462 #endif