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 TISSUESIMULATION_HPP_
00029 #define TISSUESIMULATION_HPP_
00030
00031 #include <climits>
00032 #include <boost/serialization/access.hpp>
00033 #include <boost/serialization/vector.hpp>
00034 #include <boost/serialization/string.hpp>
00035
00036 #include <vector>
00037
00038 #include "AbstractForce.hpp"
00039 #include "AbstractCellKiller.hpp"
00040 #include "AbstractTissue.hpp"
00041 #include "RandomNumberGenerator.hpp"
00042 #include "ChastePoint.hpp"
00043
00044
00060 template<unsigned DIM>
00061 class TissueSimulation
00062 {
00063
00064
00065 friend class TestCryptSimulation2d;
00066 friend class TestTissueSimulation3d;
00067
00068 protected:
00069
00071 double mDt;
00072
00074 double mEndTime;
00075
00077 AbstractTissue<DIM>& mrTissue;
00078
00080 bool mDeleteTissue;
00081
00083 bool mAllocatedMemoryForForceCollection;
00084
00086 bool mInitialiseCells;
00087
00089 bool mNoBirth;
00090
00092 bool mUpdateTissue;
00093
00095 std::string mOutputDirectory;
00096
00098 std::string mSimulationOutputDirectory;
00099
00101 out_stream mpSetupFile;
00102
00104 TissueConfig *mpConfig;
00105
00107 RandomNumberGenerator *mpRandomGenerator;
00108
00110 unsigned mNumBirths;
00111
00113 unsigned mNumDeaths;
00114
00119 unsigned mSamplingTimestepMultiple;
00120
00122 std::vector<AbstractCellKiller<DIM>*> mCellKillers;
00123
00125 std::vector<AbstractForce<DIM>*> mForceCollection;
00126
00128 friend class boost::serialization::access;
00140 template<class Archive>
00141 void serialize(Archive & archive, const unsigned int version)
00142 {
00143 mpConfig = TissueConfig::Instance();
00144 archive & *mpConfig;
00145 archive & mpConfig;
00146
00147 mpRandomGenerator = RandomNumberGenerator::Instance();
00148 archive & *mpRandomGenerator;
00149 archive & mpRandomGenerator;
00150
00151
00152
00153 archive & mDt;
00154 archive & mEndTime;
00155 archive & mNoBirth;
00156 archive & mUpdateTissue;
00157 archive & mOutputDirectory;
00158 archive & mNumBirths;
00159 archive & mNumDeaths;
00160 archive & mCellKillers;
00161 archive & mSamplingTimestepMultiple;
00162 archive & mForceCollection;
00163 }
00164
00168 virtual void WriteVisualizerSetupFile()
00169 {
00170 }
00171
00179 unsigned DoCellBirth();
00180
00193 virtual c_vector<double, DIM> CalculateDividingCellCentreLocations(TissueCell* pParentCell);
00194
00203 unsigned DoCellRemoval();
00204
00212 virtual void UpdateNodePositions(const std::vector< c_vector<double, DIM> >& rNodeForces);
00213
00219 virtual void ApplyTissueBoundaryConditions(const std::vector< c_vector<double, DIM> >& rOldLocations)
00220 {
00221 }
00222
00226 virtual void PostSolve()
00227 {
00228 }
00229
00233 virtual void SetupSolve()
00234 {
00235 }
00236
00241 virtual void AfterSolve(){};
00242
00248 virtual bool StoppingEventHasOccurred();
00249
00253 void UpdateTissue();
00254
00255 public:
00256
00265 TissueSimulation(AbstractTissue<DIM>& rTissue,
00266 std::vector<AbstractForce<DIM>*> forceCollection,
00267 bool deleteTissueAndForceCollection=false,
00268 bool initialiseCells=true);
00269
00275 virtual ~TissueSimulation();
00276
00283 std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
00284
00288 double GetDt();
00289
00293 unsigned GetNumBirths();
00294
00298 unsigned GetNumDeaths();
00299
00303 std::string GetOutputDirectory();
00304
00310 void SetDt(double dt);
00311
00317 void SetEndTime(double endTime);
00318
00324 void SetOutputDirectory(std::string outputDirectory);
00325
00332 void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
00333
00339 void SetNoBirth(bool noBirth);
00340
00346 void SetUpdateTissueRule(bool updateTissue);
00347
00353 void AddCellKiller(AbstractCellKiller<DIM>* pCellKiller);
00354
00365 void Solve();
00366
00370 AbstractTissue<DIM>& rGetTissue();
00371
00375 const AbstractTissue<DIM>& rGetTissue() const;
00376
00380 const std::vector<AbstractForce<DIM>*> rGetForceCollection() const;
00381 };
00382
00383
00384 namespace boost
00385 {
00386 namespace serialization
00387 {
00392 template<class Archive, unsigned DIM>
00393 inline void save_construct_data(
00394 Archive & ar, const TissueSimulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00395 {
00396
00397 const AbstractTissue<DIM> *p_tissue = &(t->rGetTissue());
00398 ar & p_tissue;
00399 const std::vector<AbstractForce<DIM>*> force_collection = t->rGetForceCollection();
00400 ar & force_collection;
00401 }
00402
00406 template<class Archive, unsigned DIM>
00407 inline void load_construct_data(
00408 Archive & ar, TissueSimulation<DIM> * t, const unsigned int file_version)
00409 {
00410
00411 AbstractTissue<DIM> *p_tissue;
00412 ar >> p_tissue;
00413 std::vector<AbstractForce<DIM>*> force_collection;
00414 ar >> force_collection;
00415
00416
00417 ::new(t)TissueSimulation<DIM>(*p_tissue, force_collection, true);
00418 }
00419 }
00420 }
00421
00422
00423 #endif