AbstractCellBasedSimulation.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 
00029 #ifndef ABSTRACTCELLBASEDSIMULATION_HPP_
00030 #define ABSTRACTCELLBASEDSIMULATION_HPP_
00031 
00032 #include "ChasteSerialization.hpp"
00033 #include <boost/serialization/vector.hpp>
00034 #include <boost/serialization/string.hpp>
00035 
00036 #include <vector>
00037 
00038 #include "CellBasedPdeHandler.hpp"
00039 #include "AbstractCellKiller.hpp"
00040 #include "CellwiseData.hpp"
00041 #include "RandomNumberGenerator.hpp"
00042 
00057 template<unsigned DIM>
00058 class AbstractCellBasedSimulation : public Identifiable
00059 {
00060     // Allow tests to access private members, in order to test computation of private functions e.g. DoCellBirth()
00061     friend class TestCryptSimulation2d;
00062     friend class TestOffLatticeSimulation3d;
00063     friend class TestOffLatticeSimulation;
00064 
00065 private:
00066 
00068     friend class boost::serialization::access;
00069 
00076     template<class Archive>
00077     void serialize(Archive & archive, const unsigned int version)
00078     {
00079         SerializableSingleton<SimulationTime>* p_time_wrapper = SimulationTime::Instance()->GetSerializationWrapper();
00080         archive & p_time_wrapper;
00081 
00082         SerializableSingleton<CellwiseData<DIM> >* p_cellwise_data_wrapper = CellwiseData<DIM>::Instance()->GetSerializationWrapper();
00083         archive & p_cellwise_data_wrapper;
00084 
00085         SerializableSingleton<RandomNumberGenerator>* p_rng_wrapper = RandomNumberGenerator::Instance()->GetSerializationWrapper();
00086         archive & p_rng_wrapper;
00087 
00088         archive & mDt;
00089         archive & mEndTime;
00090         archive & mNoBirth;
00091         archive & mUpdateCellPopulation;
00092         archive & mOutputDirectory;
00093         archive & mNumBirths;
00094         archive & mNumDeaths;
00095         archive & mCellKillers;
00096         archive & mSamplingTimestepMultiple;
00097         archive & mpCellBasedPdeHandler;
00098     }
00099 
00100 protected:
00101 
00103     double mDt;
00104 
00106     double mEndTime;
00107 
00109     AbstractCellPopulation<DIM>& mrCellPopulation;
00110 
00112     bool mDeleteCellPopulationInDestructor;
00113 
00115     bool mInitialiseCells;
00116 
00118     bool mNoBirth;
00119 
00121     bool mUpdateCellPopulation;
00122 
00124     std::string mOutputDirectory;
00125 
00127     std::string mSimulationOutputDirectory;
00128 
00130     out_stream mpVizSetupFile;
00131 
00133     unsigned mNumBirths;
00134 
00136     unsigned mNumDeaths;
00137 
00139     std::vector<boost::shared_ptr<AbstractCellKiller<DIM> > > mCellKillers;
00140 
00145     unsigned mSamplingTimestepMultiple;
00146 
00150     CellBasedPdeHandler<DIM>* mpCellBasedPdeHandler;
00151 
00155     virtual void WriteVisualizerSetupFile()
00156     {
00157     }
00158 
00166     virtual unsigned DoCellBirth();
00167 
00179     virtual c_vector<double, DIM> CalculateCellDivisionVector(CellPtr pParentCell)=0;
00180 
00189     unsigned DoCellRemoval();
00190 
00194     virtual void PostSolve();
00195 
00199     virtual void SetupSolve();
00200 
00205     virtual void AfterSolve();
00206 
00212     virtual bool StoppingEventHasOccurred();
00213 
00217     virtual void UpdateCellPopulation();
00218 
00224     virtual void UpdateCellLocationsAndTopology()=0;
00225 
00229     void OutputSimulationSetup();
00230 
00237     virtual void OutputAdditionalSimulationSetup(out_stream& rParamsFile)
00238     {
00239     }
00240 
00241 public:
00242 
00251     AbstractCellBasedSimulation(AbstractCellPopulation<DIM>& rCellPopulation,
00252                                 bool deleteCellPopulationInDestructor=false,
00253                                 bool initialiseCells=true);
00254 
00260     virtual ~AbstractCellBasedSimulation();
00261 
00267     void SetCellBasedPdeHandler(CellBasedPdeHandler<DIM>* pCellBasedPdeHandler);
00268 
00272     CellBasedPdeHandler<DIM>* GetCellBasedPdeHandler();
00273 
00280     std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
00281 
00285     double GetDt();
00286 
00290     unsigned GetNumBirths();
00291 
00295     unsigned GetNumDeaths();
00296 
00300     std::string GetOutputDirectory();
00301 
00307     void SetDt(double dt);
00308 
00314     void SetEndTime(double endTime);
00315 
00321     void SetOutputDirectory(std::string outputDirectory);
00322 
00329     void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
00330 
00336     void SetNoBirth(bool noBirth);
00337 
00343     void SetUpdateCellPopulationRule(bool updateCellPopulation);
00344 
00350     void AddCellKiller(boost::shared_ptr<AbstractCellKiller<DIM> > pCellKiller);
00351 
00362     void Solve();
00363 
00367     AbstractCellPopulation<DIM>& rGetCellPopulation();
00368 
00372     const AbstractCellPopulation<DIM>& rGetCellPopulation() const;
00373 
00382     virtual void OutputSimulationParameters(out_stream& rParamsFile)=0;
00383 };
00384 
00385 #endif /*ABSTRACTCELLBASEDSIMULATION_HPP_*/
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3