CaBasedCellPopulation.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 CABASEDCELLPOPULATION_HPP_
00030 #define CABASEDCELLPOPULATION_HPP_
00031 
00032 #include <vector>
00033 #include <set>
00034 #include <string>
00035 
00036 #include "UblasVectorInclude.hpp"
00037 
00038 #include "ChasteSerialization.hpp"
00039 #include <boost/serialization/base_object.hpp>
00040 #include <boost/serialization/vector.hpp>
00041 
00042 // Needed here to avoid serialization errors (on Boost<1.37)
00043 #include "WildTypeCellMutationState.hpp"
00044 
00045 #include "AbstractOnLatticeCellPopulation.hpp"
00046 #include "TetrahedralMesh.hpp"
00047 #include "AbstractCaUpdateRule.hpp"
00048 
00049 template<unsigned DIM>
00050 class AbstractCaUpdateRule; // Circular definition
00051 
00058 template<unsigned DIM>
00059 class CaBasedCellPopulation : public AbstractOnLatticeCellPopulation<DIM>
00060 {
00061     friend class TestCaBasedCellPopulation;
00062 
00063 private:
00064 
00066     TetrahedralMesh<DIM, DIM>& mrMesh;
00067 
00069     std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > > mUpdateRuleCollection;
00070 
00072     std::vector<bool> mIsEmptySite;
00073 
00079     bool mOnlyUseNearestNeighboursForDivision;
00080 
00086     bool mUseVonNeumannNeighbourhoods;
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         archive & boost::serialization::base_object<AbstractOnLatticeCellPopulation<DIM> >(*this);
00111         archive & mUpdateRuleCollection;
00112         archive & mIsEmptySite;
00113         archive & mOnlyUseNearestNeighboursForDivision;
00114         archive & mUseVonNeumannNeighbourhoods;
00115     }
00116 
00121     void Validate();
00122 
00126     void WriteVtkResultsToFile();
00127 
00128 public:
00129 
00142     CaBasedCellPopulation(TetrahedralMesh<DIM, DIM>& rMesh,
00143                        std::vector<CellPtr>& rCells,
00144                        const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00145                        bool deleteMesh=false,
00146                        bool validate=true);
00147 
00153     CaBasedCellPopulation(TetrahedralMesh<DIM, DIM>& rMesh);
00154 
00158     ~CaBasedCellPopulation();
00159 
00163     TetrahedralMesh<DIM, DIM>& rGetMesh();
00164 
00168     const TetrahedralMesh<DIM, DIM>& rGetMesh() const;
00169 
00175     void UpdateCellLocations(double dt);
00176 
00183     void SetOnlyUseNearestNeighboursForDivision(bool onlyUseNearestNeighboursForDivision);
00184 
00188     bool GetOnlyUseNearestNeighboursForDivision();
00189 
00195     void AddUpdateRule(boost::shared_ptr<AbstractCaUpdateRule<DIM> > pUpdateRule);
00196 
00202     const std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > >& rGetUpdateRuleCollection() const;
00203 
00209     void SetUseVonNeumannNeighbourhoods(bool useVonNeumannNeighbourhoods);
00210 
00214     bool GetUseVonNeumannNeighbourhoods();
00215 
00219     std::vector<bool>& rGetEmptySites();
00220 
00229     bool IsEmptySite(unsigned index);
00230 
00234     std::set<unsigned> GetEmptySiteIndices();
00235 
00241     unsigned GetNumNodes();
00242 
00250     virtual Node<DIM>* GetNode(unsigned index);
00251 
00289     virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr());
00290 
00299     std::vector<unsigned> GetNeighbouringNodeIndicesVector(unsigned nodeIndex);
00300 
00312     std::set<unsigned> GetFreeNeighbouringNodeIndices(unsigned nodeIndex);
00313 
00325     std::vector<unsigned> GetMaximumDegreeInEachDirection(unsigned nodeIndex);
00326 
00338     std::set<unsigned> GetNthDegreeNeighbouringNodeIndices(unsigned nodeIndex, unsigned degree);
00339 
00352     unsigned RemoveDeadCells();
00353 
00361     void Update(bool hasHadBirthsOrDeaths=true);
00362 
00366     void WriteCellVolumeResultsToFile();
00367 
00376     void GenerateCellResults(unsigned locationIndex,
00377                              std::vector<unsigned>& rCellProliferativeTypeCounter,
00378                              std::vector<unsigned>& rCellCyclePhaseCounter);
00379 
00383     virtual void GenerateCellResultsAndWriteToFiles();
00384 
00398     bool IsCellAssociatedWithADeletedLocation(CellPtr pCell);
00399 
00406     void MoveCell(CellPtr pCell, unsigned newLocationIndex);
00407 
00415     c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell);
00416 
00425     void OutputCellPopulationParameters(out_stream& rParamsFile);
00426 
00436     double GetWidth(const unsigned& rDimension);
00437 
00448     std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
00449 };
00450 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00451 
00452 #include "SerializationExportWrapper.hpp"
00453 EXPORT_TEMPLATE_CLASS_SAME_DIMS(CaBasedCellPopulation)
00454 
00455 namespace boost
00456 {
00457 namespace serialization
00458 {
00462 template<class Archive, unsigned DIM>
00463 inline void save_construct_data(
00464     Archive & ar, const CaBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00465 {
00466     // Save data required to construct instance
00467     const TetrahedralMesh<DIM,DIM>* p_mesh = &(t->rGetMesh());
00468     ar & p_mesh;
00469 }
00470 
00475 template<class Archive, unsigned DIM>
00476 inline void load_construct_data(
00477     Archive & ar, CaBasedCellPopulation<DIM> * t, const unsigned int file_version)
00478 {
00479     // Retrieve data from archive required to construct new instance
00480     TetrahedralMesh<DIM,DIM>* p_mesh;
00481     ar >> p_mesh;
00482 
00483     // Invoke inplace constructor to initialise instance
00484     ::new(t)CaBasedCellPopulation<DIM>(*p_mesh);
00485 }
00486 }
00487 } // namespace ...
00488 
00489 #endif /*CABASEDCELLPOPULATION_HPP_*/
Generated on Thu Dec 22 13:00:04 2011 for Chaste by  doxygen 1.6.3