AbstractCellBasedSimulation.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, 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 
00200     virtual unsigned DoCellBirth();
00201 
00213     virtual c_vector<double, SPACE_DIM> CalculateCellDivisionVector(CellPtr pParentCell)=0;
00214 
00223     unsigned DoCellRemoval();
00224 
00228     virtual void SetupSolve()
00229     {
00230     }
00231 
00238     virtual bool StoppingEventHasOccurred();
00239 
00243     virtual void UpdateCellPopulation();
00244 
00257     virtual void UpdateCellLocationsAndTopology()=0;
00258 
00262     void OutputSimulationSetup();
00263 
00270     virtual void OutputAdditionalSimulationSetup(out_stream& rParamsFile)
00271     {
00272     }
00273 
00274 public:
00275 
00284     AbstractCellBasedSimulation(AbstractCellPopulation<ELEMENT_DIM,SPACE_DIM>& rCellPopulation,
00285                                 bool deleteCellPopulationInDestructor=false,
00286                                 bool initialiseCells=true);
00287 
00293     virtual ~AbstractCellBasedSimulation();
00294 
00300     void SetCellBasedPdeHandler(CellBasedPdeHandler<SPACE_DIM>* pCellBasedPdeHandler);
00301 
00305     CellBasedPdeHandler<SPACE_DIM>* GetCellBasedPdeHandler();
00306 
00313     std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
00314 
00318     double GetDt();
00319 
00323     unsigned GetNumBirths();
00324 
00328     unsigned GetNumDeaths();
00329 
00333     std::string GetOutputDirectory();
00334 
00340     void SetDt(double dt);
00341 
00347     void SetEndTime(double endTime);
00348 
00354     void SetOutputDirectory(std::string outputDirectory);
00355 
00362     void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
00363 
00369     void SetNoBirth(bool noBirth);
00370 
00376     void SetUpdateCellPopulationRule(bool updateCellPopulation);
00377 
00383     bool GetUpdateCellPopulationRule();
00384 
00390     void AddCellKiller(boost::shared_ptr<AbstractCellKiller<SPACE_DIM> > pCellKiller);
00391 
00395     void RemoveAllCellKillers();
00396 
00402     void AddSimulationModifier(boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM,SPACE_DIM> > pSimulationModifier);
00403 
00407     std::vector<boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM, SPACE_DIM> > >* GetSimulationModifiers();
00408 
00463     void Solve();
00464 
00468     AbstractCellPopulation<ELEMENT_DIM,SPACE_DIM>& rGetCellPopulation();
00469 
00473     const AbstractCellPopulation<ELEMENT_DIM,SPACE_DIM>& rGetCellPopulation() const;
00474 
00478     bool GetOutputDivisionLocations();
00479 
00485     void SetOutputDivisionLocations(bool outputDivisionLocations);
00486 
00490     bool GetOutputCellVelocities();
00491 
00497     void SetOutputCellVelocities(bool outputCellVelocities);
00498 
00507     virtual void OutputSimulationParameters(out_stream& rParamsFile)=0;
00508 };
00509 
00510 #endif /*ABSTRACTCELLBASEDSIMULATION_HPP_*/

Generated by  doxygen 1.6.2