Chaste Release::3.1
MultipleCaBasedCellPopulation.hpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, 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 MULTIPLECABASEDCELLPOPULATION_HPP_
00037 #define MULTIPLECABASEDCELLPOPULATION_HPP_
00038 
00039 #include "AbstractOnLatticeCellPopulation.hpp"
00040 #include "PottsMesh.hpp"
00041 #include "VertexMesh.hpp"
00042 #include "AbstractMultipleCaUpdateRule.hpp"
00043 
00044 #include "ChasteSerialization.hpp"
00045 #include <boost/serialization/base_object.hpp>
00046 #include <boost/serialization/vector.hpp>
00047 
00048 // Needed here to avoid serialization errors (on Boost<1.37)
00049 #include "WildTypeCellMutationState.hpp"
00050 
00052 template<unsigned DIM>
00053 class AbstractMultipleCaUpdateRule; // Circular definition
00054 
00068 template<unsigned DIM>
00069 class MultipleCaBasedCellPopulation : public AbstractOnLatticeCellPopulation<DIM>
00070 {
00071     friend class TestMultipleCaBasedCellPopulation;
00072 
00073 private:
00074 
00075 
00077     unsigned mLatticeCarryingCapacity;
00078 
00080     out_stream mpVizLocationsFile;
00081 
00083     std::vector<boost::shared_ptr<AbstractMultipleCaUpdateRule<DIM> > > mUpdateRuleCollection;
00084 
00086     std::vector<unsigned> mAvailableSpaces;
00087 
00093     void SetEmptySites(const std::set<unsigned>& rEmptySiteIndices);
00094 
00095     friend class boost::serialization::access;
00107     template<class Archive>
00108     void serialize(Archive & archive, const unsigned int version)
00109     {
00110 #define COVERAGE_IGNORE
00111         archive & boost::serialization::base_object<AbstractOnLatticeCellPopulation<DIM> >(*this);
00112         archive & mLatticeCarryingCapacity;
00113         archive & mUpdateRuleCollection;
00114         archive & mAvailableSpaces;
00115 
00116 #undef COVERAGE_IGNORE
00117     }
00118 
00123     void Validate();
00124 
00128     void WriteVtkResultsToFile();
00129 
00130 public:
00131 
00146     MultipleCaBasedCellPopulation(PottsMesh<DIM>& rMesh,
00147                                   std::vector<CellPtr>& rCells,
00148                                   const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00149                                   unsigned latticeCarryingCapacity=1u,
00150                                   bool deleteMesh=false,
00151                                   bool validate=false);
00152 
00158     MultipleCaBasedCellPopulation(PottsMesh<DIM>& rMesh);
00159 
00163     virtual ~MultipleCaBasedCellPopulation();
00164 
00168     std::vector<unsigned>& rGetAvailableSpaces();
00169 
00177     bool IsSiteAvailable(unsigned index);
00178 
00179 
00183     PottsMesh<DIM>& rGetMesh();
00184 
00188     const PottsMesh<DIM>& rGetMesh() const;
00189 
00197     Node<DIM>* GetNode(unsigned index);
00198 
00204     unsigned GetNumNodes();
00205 
00214     c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell);
00215 
00223     void AddCellUsingLocationIndex(unsigned index, CellPtr pCell);
00224 
00232     void RemoveCellUsingLocationIndex(unsigned index, CellPtr pCell);
00233 
00241      Node<DIM>* GetNodeCorrespondingToCell(CellPtr pCell);
00242 
00253     CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr());
00254 
00264     unsigned RemoveDeadCells();
00265 
00266 //    /**
00267 //     * Calculated the probability of a cell moving based on the calculations provided by Owen et. al 2011
00268 //     */
00269 //    double CalculateProbabilityOfMoving(unsigned node_index, unsigned node_neighbour_index, double dt);
00270 
00276     void UpdateCellLocations(double dt);
00277 
00284     bool IsCellAssociatedWithADeletedLocation(CellPtr pCell);
00285 
00293     void Update(bool hasHadBirthsOrDeaths=true);
00294 
00301     void CreateOutputFiles(const std::string& rDirectory, bool cleanOutputDirectory);
00302 
00306     void CloseOutputFiles();
00307 
00311     void WriteResultsToFiles();
00312 
00316     void WriteCellVolumeResultsToFile();
00317 
00323     double GetVolumeOfCell(CellPtr pCell);
00324 
00328     virtual void GenerateCellResultsAndWriteToFiles();
00329 
00341     double GetWidth(const unsigned& rDimension);
00342 
00348     void AddUpdateRule(boost::shared_ptr<AbstractMultipleCaUpdateRule<DIM> > pUpdateRule);
00349 
00350 
00354     void RemoveAllUpdateRules();
00355 
00361     const std::vector<boost::shared_ptr<AbstractMultipleCaUpdateRule<DIM> > >& rGetUpdateRuleCollection() const;
00362 
00371     void OutputCellPopulationParameters(out_stream& rParamsFile);
00372 
00382     std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
00383 };
00384 
00385 #include "SerializationExportWrapper.hpp"
00386 EXPORT_TEMPLATE_CLASS_SAME_DIMS(MultipleCaBasedCellPopulation)
00387 
00388 // No archiving yet so untested
00389 #define COVERAGE_IGNORE
00390 namespace boost
00391 {
00392 namespace serialization
00393 {
00397 template<class Archive, unsigned DIM>
00398 inline void save_construct_data(
00399     Archive & ar, const MultipleCaBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00400 {
00401     // Save data required to construct instance
00402     const PottsMesh<DIM>* p_mesh = &(t->rGetMesh());
00403     ar & p_mesh;
00404 }
00405 
00410 template<class Archive, unsigned DIM>
00411 inline void load_construct_data(
00412     Archive & ar, MultipleCaBasedCellPopulation<DIM> * t, const unsigned int file_version)
00413 {
00414     // Retrieve data from archive required to construct new instance
00415     PottsMesh<DIM>* p_mesh;
00416     ar >> p_mesh;
00417 
00418     // Invoke inplace constructor to initialise instance
00419     ::new(t)MultipleCaBasedCellPopulation<DIM>(*p_mesh);
00420 }
00421 }
00422 } // namespace ...
00423 #undef COVERAGE_IGNORE
00424 
00425 #endif /*MULTIPLECABASEDCELLPOPULATION_HPP_*/