TissueSimulation.hpp

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 #ifndef TISSUESIMULATION_HPP_
00029 #define TISSUESIMULATION_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 "AbstractTissue.hpp"
00040 #include "RandomNumberGenerator.hpp"
00041 #include "ChastePoint.hpp"
00042 
00043 
00059 template<unsigned DIM>
00060 class TissueSimulation
00061 {
00062     // Allow tests to access private members, in order to test computation of
00063     // private functions eg. DoCellBirth
00064     friend class TestCryptSimulation2d;
00065     friend class TestTissueSimulation3d;
00066 
00067 protected:
00068 
00070     double mDt;
00071 
00073     double mEndTime;
00074 
00076     AbstractTissue<DIM>& mrTissue;
00077 
00079     bool mDeleteTissue;
00080 
00082     bool mAllocatedMemoryForForceCollection;
00083 
00085     bool mInitialiseCells;
00086 
00088     bool mNoBirth;
00089 
00091     bool mUpdateTissue;
00092 
00094     std::string mOutputDirectory;
00095 
00097     std::string mSimulationOutputDirectory;
00098 
00100     out_stream mpSetupFile;
00101 
00103     out_stream mpNodeVelocitiesFile;
00104 
00106     TissueConfig* mpConfig;
00107 
00109     RandomNumberGenerator* mpRandomGenerator;
00110 
00112     unsigned mNumBirths;
00113 
00115     unsigned mNumDeaths;
00116 
00121     unsigned mSamplingTimestepMultiple;
00122 
00124     std::vector<AbstractCellKiller<DIM>*> mCellKillers;
00125 
00127     std::vector<AbstractForce<DIM>*> mForceCollection;
00128 
00130     friend class boost::serialization::access;
00142     template<class Archive>
00143     void serialize(Archive & archive, const unsigned int version)
00144     {
00145         mpConfig = TissueConfig::Instance();
00146         archive & *mpConfig;
00147         archive & mpConfig;
00148 
00149         mpRandomGenerator = RandomNumberGenerator::Instance();
00150         archive & *mpRandomGenerator;
00151         archive & mpRandomGenerator;
00152 
00153         // If Archive is an output archive, then & resolves to <<
00154         // If Archive is an input archive, then & resolves to >>
00155         archive & mDt;
00156         archive & mEndTime;
00157         archive & mNoBirth;
00158         archive & mUpdateTissue;
00159         archive & mOutputDirectory;
00160         archive & mNumBirths;
00161         archive & mNumDeaths;
00162         archive & mCellKillers;
00163         archive & mSamplingTimestepMultiple;
00164         archive & mForceCollection;
00165     }
00166 
00170     virtual void WriteVisualizerSetupFile()
00171     {
00172     }
00173 
00181     virtual unsigned DoCellBirth();
00182 
00200     virtual c_vector<double, DIM> CalculateCellDivisionVector(TissueCell& rParentCell);
00201 
00210     unsigned DoCellRemoval();
00211 
00219     virtual void UpdateNodePositions(const std::vector< c_vector<double, DIM> >& rNodeForces);
00220 
00226     virtual void ApplyTissueBoundaryConditions(const std::vector< c_vector<double, DIM> >& rOldLocations)
00227     {
00228     }
00229 
00233     virtual void PostSolve()
00234     {
00235     }
00236 
00240     virtual void SetupSolve()
00241     {
00242     }
00243 
00248     virtual void AfterSolve()
00249     {
00250     }
00251 
00257     virtual bool StoppingEventHasOccurred();
00258 
00262     void UpdateTissue();
00263 
00264 public:
00265 
00274     TissueSimulation(AbstractTissue<DIM>& rTissue,
00275                      std::vector<AbstractForce<DIM>*> forceCollection,
00276                      bool deleteTissueAndForceCollection=false,
00277                      bool initialiseCells=true);
00278 
00284     virtual ~TissueSimulation();
00285 
00292     std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
00293 
00297     double GetDt();
00298 
00302     unsigned GetNumBirths();
00303 
00307     unsigned GetNumDeaths();
00308 
00312     std::string GetOutputDirectory();
00313 
00319     void SetDt(double dt);
00320 
00326     void SetEndTime(double endTime);
00327 
00333     void SetOutputDirectory(std::string outputDirectory);
00334 
00341     void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
00342 
00348     void SetNoBirth(bool noBirth);
00349 
00355     void SetUpdateTissueRule(bool updateTissue);
00356 
00362     void AddCellKiller(AbstractCellKiller<DIM>* pCellKiller);
00363 
00374     void Solve();
00375 
00379     AbstractTissue<DIM>& rGetTissue();
00380 
00384     const AbstractTissue<DIM>& rGetTissue() const;
00385 
00389     const std::vector<AbstractForce<DIM>*> rGetForceCollection() const;
00390 };
00391 
00392 
00393 namespace boost
00394 {
00395 namespace serialization
00396 {
00401 template<class Archive, unsigned DIM>
00402 inline void save_construct_data(
00403     Archive & ar, const TissueSimulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00404 {
00405     // Save data required to construct instance
00406     const AbstractTissue<DIM>* p_tissue = &(t->rGetTissue());
00407     ar & p_tissue;
00408     const std::vector<AbstractForce<DIM>*> force_collection = t->rGetForceCollection();
00409     ar & force_collection;
00410 }
00411 
00415 template<class Archive, unsigned DIM>
00416 inline void load_construct_data(
00417     Archive & ar, TissueSimulation<DIM> * t, const unsigned int file_version)
00418 {
00419     // Retrieve data from archive required to construct new instance
00420     AbstractTissue<DIM>* p_tissue;
00421     ar >> p_tissue;
00422     std::vector<AbstractForce<DIM>*> force_collection;
00423     ar >> force_collection;
00424 
00425     // Invoke inplace constructor to initialise instance
00426     ::new(t)TissueSimulation<DIM>(*p_tissue, force_collection, true);
00427 }
00428 }
00429 } // namespace
00430 
00431 
00432 #endif /*TISSUESIMULATION_HPP_*/

Generated by  doxygen 1.6.2