CellBasedSimulation.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 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 "AbstractCellPopulationBoundaryCondition.hpp"
00040 #include "AbstractCellPopulation.hpp"
00041 #include "RandomNumberGenerator.hpp"
00042 #include "Identifiable.hpp"
00043 
00064 template<unsigned DIM>
00065 class CellBasedSimulation : public Identifiable
00066 {
00067     // Allow tests to access private members, in order to test computation of
00068     // private functions eg. DoCellBirth
00069     friend class TestCryptSimulation2d;
00070     friend class TestCellBasedSimulation3d;
00071     friend class TestCellBasedSimulation;
00072 
00073 protected:
00074 
00076     double mDt;
00077 
00079     double mEndTime;
00080 
00082     AbstractCellPopulation<DIM>& mrCellPopulation;
00083 
00085     bool mDeleteCellPopulationAndForcesAndBCsInDestructor;
00086 
00088     bool mInitialiseCells;
00089 
00091     bool mNoBirth;
00092 
00094     bool mUpdateCellPopulation;
00095 
00097     std::string mOutputDirectory;
00098 
00100     std::string mSimulationOutputDirectory;
00101 
00103     out_stream mpVizSetupFile;
00104 
00106     out_stream mpNodeVelocitiesFile;
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     std::vector<AbstractCellPopulationBoundaryCondition<DIM>*> mBoundaryConditions;
00131 
00133     bool mOutputNodeVelocities;
00134 
00136     friend class boost::serialization::access;
00148     template<class Archive>
00149     void serialize(Archive & archive, const unsigned int version)
00150     {
00151         mpRandomGenerator = RandomNumberGenerator::Instance();
00152         archive & *mpRandomGenerator;
00153         archive & mpRandomGenerator;
00154 
00155         // If Archive is an output archive, then & resolves to <<
00156         // If Archive is an input archive, then & resolves to >>
00157         archive & mDt;
00158         archive & mEndTime;
00159         archive & mNoBirth;
00160         archive & mUpdateCellPopulation;
00161         archive & mOutputDirectory;
00162         archive & mNumBirths;
00163         archive & mNumDeaths;
00164         archive & mCellKillers;
00165         archive & mSamplingTimestepMultiple;
00166         archive & mForceCollection;
00167         archive & mBoundaryConditions;
00168         archive & mOutputNodeVelocities;
00169     }
00170 
00174     virtual void WriteVisualizerSetupFile()
00175     {
00176     }
00177 
00185     virtual unsigned DoCellBirth();
00186 
00204     virtual c_vector<double, DIM> CalculateCellDivisionVector(CellPtr pParentCell);
00205 
00214     unsigned DoCellRemoval();
00215 
00223     virtual void UpdateNodePositions(const std::vector< c_vector<double, DIM> >& rNodeForces);
00224 
00231     virtual void ApplyCellPopulationBoundaryConditions(const std::vector< c_vector<double, DIM> >& rOldLocations)
00232     {
00233     }
00234 
00238     virtual void PostSolve()
00239     {
00240     }
00241 
00245     virtual void SetupSolve()
00246     {
00247     }
00248 
00253     virtual void AfterSolve()
00254     {
00255     }
00256 
00262     virtual bool StoppingEventHasOccurred();
00263 
00267     void UpdateCellPopulation();
00268 
00272     void OutputSimulationSetup();
00273 
00274 public:
00275 
00283     CellBasedSimulation(AbstractCellPopulation<DIM>& rCellPopulation,
00284                         bool deleteCellPopulationAndForceCollection=false,
00285                         bool initialiseCells=true);
00286 
00292     virtual ~CellBasedSimulation();
00293 
00300     std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
00301 
00305     double GetDt();
00306 
00310     unsigned GetNumBirths();
00311 
00315     unsigned GetNumDeaths();
00316 
00320     std::string GetOutputDirectory();
00321 
00327     void SetDt(double dt);
00328 
00334     void SetEndTime(double endTime);
00335 
00341     void SetOutputDirectory(std::string outputDirectory);
00342 
00349     void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
00350 
00356     void SetNoBirth(bool noBirth);
00357 
00363     void SetUpdateCellPopulationRule(bool updateCellPopulation);
00364 
00370     void AddCellKiller(AbstractCellKiller<DIM>* pCellKiller);
00371 
00377     void AddForce(AbstractForce<DIM>* pForce);
00378 
00384     void AddCellPopulationBoundaryCondition(AbstractCellPopulationBoundaryCondition<DIM>* pBoundaryCondition);
00385 
00396     void Solve();
00397 
00401     AbstractCellPopulation<DIM>& rGetCellPopulation();
00402 
00406     const AbstractCellPopulation<DIM>& rGetCellPopulation() const;
00407 
00411     bool GetOutputNodeVelocities();
00412 
00418     void SetOutputNodeVelocities(bool outputNodeVelocities);
00419 
00428     virtual void OutputSimulationParameters(out_stream& rParamsFile);
00429 };
00430 
00431 
00432 #include "SerializationExportWrapper.hpp"
00433 EXPORT_TEMPLATE_CLASS_SAME_DIMS(CellBasedSimulation)
00434 
00435 
00436 namespace boost
00437 {
00438 namespace serialization
00439 {
00444 template<class Archive, unsigned DIM>
00445 inline void save_construct_data(
00446     Archive & ar, const CellBasedSimulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00447 {
00448     // Save data required to construct instance
00449     const AbstractCellPopulation<DIM>* p_cell_population = &(t->rGetCellPopulation());
00450     ar & p_cell_population;
00451 }
00452 
00456 template<class Archive, unsigned DIM>
00457 inline void load_construct_data(
00458     Archive & ar, CellBasedSimulation<DIM> * t, const unsigned int file_version)
00459 {
00460     // Retrieve data from archive required to construct new instance
00461     AbstractCellPopulation<DIM>* p_cell_population;
00462     ar >> p_cell_population;
00463 
00464     // Invoke inplace constructor to initialise instance
00465     ::new(t)CellBasedSimulation<DIM>(*p_cell_population, true, false);
00466 }
00467 }
00468 } // namespace
00469 
00470 
00471 #endif /*CELLBASEDSIMULATION_HPP_*/

Generated on Tue May 31 14:31:41 2011 for Chaste by  doxygen 1.5.5