CaBasedCellPopulation.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 CABASEDCELLPOPULATION_HPP_
00037 #define CABASEDCELLPOPULATION_HPP_
00038 
00039 #include "AbstractOnLatticeCellPopulation.hpp"
00040 #include "PottsMesh.hpp"
00041 #include "VertexMesh.hpp"
00042 #include "AbstractCaUpdateRule.hpp"
00043 
00044 #include "ChasteSerialization.hpp"
00045 #include <boost/serialization/base_object.hpp>
00046 #include <boost/serialization/vector.hpp>
00047 
00048 template<unsigned DIM>
00049 class AbstractCaUpdateRule; // Circular definition
00050 
00064 template<unsigned DIM>
00065 class CaBasedCellPopulation : public AbstractOnLatticeCellPopulation<DIM>
00066 {
00067     friend class TestCaBasedCellPopulation;
00068 
00069 private:
00070 
00072     unsigned mLatticeCarryingCapacity;
00073 
00075     std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > > mUpdateRuleCollection;
00076 
00078     std::vector<unsigned> mAvailableSpaces;
00079 
00085     void SetEmptySites(const std::set<unsigned>& rEmptySiteIndices);
00086 
00087     friend class boost::serialization::access;
00099     template<class Archive>
00100     void serialize(Archive & archive, const unsigned int version)
00101     {
00102 #define COVERAGE_IGNORE
00103         archive & boost::serialization::base_object<AbstractOnLatticeCellPopulation<DIM> >(*this);
00104         archive & mLatticeCarryingCapacity;
00105         archive & mUpdateRuleCollection;
00106         archive & mAvailableSpaces;
00107 #undef COVERAGE_IGNORE
00108     }
00109 
00115     void Validate();
00116 
00117 
00125     virtual void WriteVtkResultsToFile(const std::string& rDirectory);
00126 
00127 public:
00128 
00143     CaBasedCellPopulation(PottsMesh<DIM>& rMesh,
00144                                   std::vector<CellPtr>& rCells,
00145                                   const std::vector<unsigned> locationIndices,
00146                                   unsigned latticeCarryingCapacity=1u,
00147                                   bool deleteMesh=false,
00148                                   bool validate=false);
00149 
00155     CaBasedCellPopulation(PottsMesh<DIM>& rMesh);
00156 
00160     virtual ~CaBasedCellPopulation();
00161 
00165     std::vector<unsigned>& rGetAvailableSpaces();
00166 
00177     virtual bool IsSiteAvailable(unsigned index, CellPtr pCell);
00178 
00182     PottsMesh<DIM>& rGetMesh();
00183 
00187     const PottsMesh<DIM>& rGetMesh() const;
00188 
00196     Node<DIM>* GetNode(unsigned index);
00197 
00203     unsigned GetNumNodes();
00204 
00217     std::set<unsigned> GetNeighbouringLocationIndices(CellPtr pCell);
00218 
00227     c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell);
00228 
00236     void AddCellUsingLocationIndex(unsigned index, CellPtr pCell);
00237 
00245     void RemoveCellUsingLocationIndex(unsigned index, CellPtr pCell);
00246 
00254      Node<DIM>* GetNodeCorrespondingToCell(CellPtr pCell);
00255 
00266     CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr());
00267 
00277      double virtual EvaluateDivisionPropensity(unsigned currentNodeIndex,
00278                                         unsigned targetNodeIndex,
00279                                         CellPtr pCell);
00289     unsigned RemoveDeadCells();
00290 
00298     virtual void OpenWritersFiles(OutputFileHandler& rOutputFileHandler);
00299 
00305     void UpdateCellLocations(double dt);
00306 
00313     bool IsCellAssociatedWithADeletedLocation(CellPtr pCell);
00314 
00322     void Update(bool hasHadBirthsOrDeaths=true);
00323 
00330     virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<DIM, DIM> > pPopulationWriter);
00331 
00338     virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<DIM, DIM> > pPopulationCountWriter);
00339 
00347     virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<DIM, DIM> > pCellWriter, CellPtr pCell);
00348 
00355     double GetVolumeOfCell(CellPtr pCell);
00356 
00368     double GetWidth(const unsigned& rDimension);
00369 
00375     void AddUpdateRule(boost::shared_ptr<AbstractCaUpdateRule<DIM> > pUpdateRule);
00376 
00380     void RemoveAllUpdateRules();
00381 
00387     const std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > >& rGetUpdateRuleCollection() const;
00388 
00397     void OutputCellPopulationParameters(out_stream& rParamsFile);
00398 
00407     bool IsRoomToDivide(CellPtr pCell);
00408 };
00409 
00410 #include "SerializationExportWrapper.hpp"
00411 EXPORT_TEMPLATE_CLASS_SAME_DIMS(CaBasedCellPopulation)
00412 
00413 // No archiving yet so untested
00414 #define COVERAGE_IGNORE
00415 namespace boost
00416 {
00417 namespace serialization
00418 {
00422 template<class Archive, unsigned DIM>
00423 inline void save_construct_data(
00424     Archive & ar, const CaBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00425 {
00426     // Save data required to construct instance
00427     const PottsMesh<DIM>* p_mesh = &(t->rGetMesh());
00428     ar & p_mesh;
00429 }
00430 
00435 template<class Archive, unsigned DIM>
00436 inline void load_construct_data(
00437     Archive & ar, CaBasedCellPopulation<DIM> * t, const unsigned int file_version)
00438 {
00439     // Retrieve data from archive required to construct new instance
00440     PottsMesh<DIM>* p_mesh;
00441     ar >> p_mesh;
00442 
00443     // Invoke inplace constructor to initialise instance
00444     ::new(t)CaBasedCellPopulation<DIM>(*p_mesh);
00445 }
00446 }
00447 } // namespace ...
00448 #undef COVERAGE_IGNORE
00449 
00450 #endif /*CABASEDCELLPOPULATION_HPP_*/

Generated by  doxygen 1.6.2