AbstractCellBasedSimulation.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2014, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef ABSTRACTCELLBASEDSIMULATION_HPP_
00037 #define ABSTRACTCELLBASEDSIMULATION_HPP_
00038 
00039 #include "ChasteSerialization.hpp"
00040 #include <boost/serialization/vector.hpp>
00041 #include <boost/serialization/string.hpp>
00042 
00043 #include <vector>
00044 
00045 #include "CellBasedPdeHandler.hpp"
00046 #include "AbstractCellKiller.hpp"
00047 #include "AbstractCellBasedSimulationModifier.hpp"
00048 #include "AbstractForce.hpp"
00049 #include "RandomNumberGenerator.hpp"
00050 
00065 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM=ELEMENT_DIM>
00066 class AbstractCellBasedSimulation : public Identifiable
00067 {
00068     // Allow tests to access private members, in order to test computation of private functions e.g. DoCellBirth()
00069     friend class TestCryptSimulation2d;
00070     friend class TestOffLatticeSimulation3d;
00071     friend class TestOffLatticeSimulation;
00072 
00073 private:
00074 
00076     friend class boost::serialization::access;
00077 
00084     template<class Archive>
00085     void serialize(Archive & archive, const unsigned int version)
00086     {
00087         SerializableSingleton<SimulationTime>* p_time_wrapper = SimulationTime::Instance()->GetSerializationWrapper();
00088         archive & p_time_wrapper;
00089 
00090         SerializableSingleton<RandomNumberGenerator>* p_rng_wrapper = RandomNumberGenerator::Instance()->GetSerializationWrapper();
00091         archive & p_rng_wrapper;
00092 
00093         archive & mDt;
00094         archive & mEndTime;
00095         archive & mNoBirth;
00096         archive & mUpdateCellPopulation;
00097         archive & mOutputDirectory;
00098         archive & mNumBirths;
00099         archive & mNumDeaths;
00100         archive & mOutputDivisionLocations;
00101         archive & mOutputCellVelocities;
00102         archive & mCellKillers;
00103         archive & mSimulationModifiers;
00104         archive & mSamplingTimestepMultiple;
00105         archive & mpCellBasedPdeHandler;
00106     }
00107 
00108 protected:
00109 
00111     double mDt;
00112 
00114     double mEndTime;
00115 
00117     AbstractCellPopulation<ELEMENT_DIM, SPACE_DIM>& mrCellPopulation;
00118 
00120     bool mDeleteCellPopulationInDestructor;
00121 
00123     bool mInitialiseCells;
00124 
00126     bool mNoBirth;
00127 
00129     bool mUpdateCellPopulation;
00130 
00132     std::string mOutputDirectory;
00133 
00135     std::string mSimulationOutputDirectory;
00136 
00138     out_stream mpVizSetupFile;
00139 
00141     unsigned mNumBirths;
00142 
00144     unsigned mNumDeaths;
00145 
00147     bool mOutputDivisionLocations;
00148 
00150     out_stream mpDivisionLocationFile;
00151 
00156     bool mOutputCellVelocities;
00157 
00159     out_stream mpCellVelocitiesFile;
00160 
00162     std::vector<boost::shared_ptr<AbstractCellKiller<SPACE_DIM> > > mCellKillers;
00163 
00165     std::vector<boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM, SPACE_DIM> > > mSimulationModifiers;
00166 
00171     unsigned mSamplingTimestepMultiple;
00172 
00176     CellBasedPdeHandler<SPACE_DIM>* mpCellBasedPdeHandler;
00177 
00181     virtual void WriteVisualizerSetupFile()
00182     {
00183     }
00184 
00192     virtual unsigned DoCellBirth();
00193 
00205     virtual c_vector<double, SPACE_DIM> CalculateCellDivisionVector(CellPtr pParentCell)=0;
00206 
00215     unsigned DoCellRemoval();
00216 
00220     virtual void SetupSolve()
00221     {
00222     }
00223 
00230     virtual bool StoppingEventHasOccurred();
00231 
00235     virtual void UpdateCellPopulation();
00236 
00249     virtual void UpdateCellLocationsAndTopology()=0;
00250 
00254     void OutputSimulationSetup();
00255 
00262     virtual void OutputAdditionalSimulationSetup(out_stream& rParamsFile)
00263     {
00264     }
00265 
00266 public:
00267 
00276     AbstractCellBasedSimulation(AbstractCellPopulation<ELEMENT_DIM,SPACE_DIM>& rCellPopulation,
00277                                 bool deleteCellPopulationInDestructor=false,
00278                                 bool initialiseCells=true);
00279 
00285     virtual ~AbstractCellBasedSimulation();
00286 
00292     void SetCellBasedPdeHandler(CellBasedPdeHandler<SPACE_DIM>* pCellBasedPdeHandler);
00293 
00297     CellBasedPdeHandler<SPACE_DIM>* GetCellBasedPdeHandler();
00298 
00305     std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
00306 
00310     double GetDt();
00311 
00315     unsigned GetNumBirths();
00316 
00320     unsigned GetNumDeaths();
00321 
00325     std::string GetOutputDirectory();
00326 
00332     void SetDt(double dt);
00333 
00339     void SetEndTime(double endTime);
00340 
00346     void SetOutputDirectory(std::string outputDirectory);
00347 
00354     void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
00355 
00361     void SetNoBirth(bool noBirth);
00362 
00368     void SetUpdateCellPopulationRule(bool updateCellPopulation);
00369 
00375     bool GetUpdateCellPopulationRule();
00376 
00382     void AddCellKiller(boost::shared_ptr<AbstractCellKiller<SPACE_DIM> > pCellKiller);
00383 
00387     void RemoveAllCellKillers();
00388 
00394     void AddSimulationModifier(boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM,SPACE_DIM> > pSimulationModifier);
00395 
00442     void Solve();
00443 
00447     AbstractCellPopulation<ELEMENT_DIM,SPACE_DIM>& rGetCellPopulation();
00448 
00452     const AbstractCellPopulation<ELEMENT_DIM,SPACE_DIM>& rGetCellPopulation() const;
00453 
00457     bool GetOutputDivisionLocations();
00458 
00464     void SetOutputDivisionLocations(bool outputDivisionLocations);
00465 
00469     bool GetOutputCellVelocities();
00470 
00476     void SetOutputCellVelocities(bool outputCellVelocities);
00477 
00486     virtual void OutputSimulationParameters(out_stream& rParamsFile)=0;
00487 };
00488 
00489 #endif /*ABSTRACTCELLBASEDSIMULATION_HPP_*/

Generated by  doxygen 1.6.2