TissueSimulation.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 #ifndef TISSUESIMULATION_HPP_
00029 #define TISSUESIMULATION_HPP_
00030 
00031 #include <climits> // work around boost bug
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     // Allow tests to access private members, in order to test computation of
00064     // private functions eg. DoCellBirth
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         // If Archive is an output archive, then & resolves to <<
00152         // If Archive is an input archive, then & resolves to >>
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     // Save data required to construct instance
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     // Retrieve data from archive required to construct new instance
00411     AbstractTissue<DIM> *p_tissue;
00412     ar >> p_tissue;
00413     std::vector<AbstractForce<DIM>*> force_collection;
00414     ar >> force_collection;
00415 
00416     // Invoke inplace constructor to initialise instance
00417     ::new(t)TissueSimulation<DIM>(*p_tissue, force_collection, true);
00418 }
00419 }
00420 } // namespace
00421 
00422 
00423 #endif /*TISSUESIMULATION_HPP_*/

Generated on Tue Aug 4 16:10:21 2009 for Chaste by  doxygen 1.5.5