PottsBasedCellPopulation.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 POTTSBASEDCELLPOPULATION_HPP_
00030 #define POTTSBASEDCELLPOPULATION_HPP_
00031 
00032 #include "AbstractOnLatticeCellPopulation.hpp"
00033 #include "PottsMesh.hpp"
00034 #include "VertexMesh.hpp"
00035 #include "AbstractPottsUpdateRule.hpp"
00036 
00037 #include "ChasteSerialization.hpp"
00038 #include <boost/serialization/base_object.hpp>
00039 #include <boost/serialization/vector.hpp>
00040 
00041 // Needed here to avoid serialization errors (on Boost<1.37)
00042 #include "WildTypeCellMutationState.hpp"
00043 
00044 template<unsigned DIM>
00045 class AbstractPottsUpdateRule; // Circular definition
00046 
00057 template<unsigned DIM>
00058 class PottsBasedCellPopulation : public AbstractOnLatticeCellPopulation<DIM>
00059 {
00060     friend class TestPottsBasedCellPopulation;
00061 
00062 private:
00063 
00065     PottsMesh<DIM>& mrMesh;
00066 
00072     VertexMesh<DIM,DIM>* mpElementTessellation;
00073 
00075     out_stream mpVizElementsFile;
00076 
00078     std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > > mUpdateRuleCollection;
00079 
00081     double mTemperature;
00082 
00087     unsigned mNumSweepsPerTimestep;
00088 
00089     friend class boost::serialization::access;
00101     template<class Archive>
00102     void serialize(Archive & archive, const unsigned int version)
00103     {
00104 #define COVERAGE_IGNORE
00105         archive & boost::serialization::base_object<AbstractOnLatticeCellPopulation<DIM> >(*this);
00106 
00107         /*
00108          * In its current form the code does not allow the direct serialization
00109          * of the VertexMesh class, so instead we delete mpVoronoiTessellation.
00110          */
00111         delete mpElementTessellation;
00112         mpElementTessellation = NULL;
00113 
00114         archive & mUpdateRuleCollection;
00115         archive & mTemperature;
00116         archive & mNumSweepsPerTimestep;
00117 
00118 #undef COVERAGE_IGNORE
00119     }
00120 
00125     void Validate();
00126 
00130     void WriteVtkResultsToFile();
00131 
00132 public:
00133 
00147     PottsBasedCellPopulation(PottsMesh<DIM>& rMesh,
00148                              std::vector<CellPtr>& rCells,
00149                              bool deleteMesh=false,
00150                              bool validate=true,
00151                              const std::vector<unsigned> locationIndices=std::vector<unsigned>());
00152 
00158     PottsBasedCellPopulation(PottsMesh<DIM>& rMesh);
00159 
00163     virtual ~PottsBasedCellPopulation();
00164 
00168     PottsMesh<DIM>& rGetMesh();
00169 
00173     const PottsMesh<DIM>& rGetMesh() const;
00174 
00182     PottsElement<DIM>* GetElement(unsigned elementIndex);
00183 
00187     unsigned GetNumElements();
00188 
00196     Node<DIM>* GetNode(unsigned index);
00197 
00203     unsigned GetNumNodes();
00204 
00213     c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell);
00214 
00222     PottsElement<DIM>* GetElementCorrespondingToCell(CellPtr pCell);
00223 
00234     CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr());
00235 
00245     unsigned RemoveDeadCells();
00246 
00252     void UpdateCellLocations(double dt);
00253 
00260     bool IsCellAssociatedWithADeletedLocation(CellPtr pCell);
00261 
00268     void Update(bool hasHadBirthsOrDeaths=true);
00269 
00276     void CreateOutputFiles(const std::string& rDirectory, bool cleanOutputDirectory);
00277 
00281     void CloseOutputFiles();
00282 
00286     void WriteResultsToFiles();
00287 
00291     void WriteCellVolumeResultsToFile();
00292 
00296     virtual void GenerateCellResultsAndWriteToFiles();
00297 
00307     double GetWidth(const unsigned& rDimension);
00308 
00314     void AddUpdateRule(boost::shared_ptr<AbstractPottsUpdateRule<DIM> > pUpdateRule);
00315 
00321     const std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > >& rGetUpdateRuleCollection() const;
00322 
00331     void OutputCellPopulationParameters(out_stream& rParamsFile);
00332 
00342     std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
00343 
00349     void SetTemperature(double temperature);
00350 
00354     double GetTemperature();
00355 
00361     void SetNumSweepsPerTimestep(unsigned numSweepsPerTimestep);
00362 
00366     unsigned GetNumSweepsPerTimestep();
00367 
00371     void CreateElementTessellation();
00372 
00376     VertexMesh<DIM,DIM>* GetElementTessellation();
00377 };
00378 
00379 #include "SerializationExportWrapper.hpp"
00380 EXPORT_TEMPLATE_CLASS_SAME_DIMS(PottsBasedCellPopulation)
00381 
00382 // No archiving yet so untested
00383 #define COVERAGE_IGNORE
00384 namespace boost
00385 {
00386 namespace serialization
00387 {
00391 template<class Archive, unsigned DIM>
00392 inline void save_construct_data(
00393     Archive & ar, const PottsBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00394 {
00395     // Save data required to construct instance
00396     const PottsMesh<DIM>* p_mesh = &(t->rGetMesh());
00397     ar & p_mesh;
00398 }
00399 
00404 template<class Archive, unsigned DIM>
00405 inline void load_construct_data(
00406     Archive & ar, PottsBasedCellPopulation<DIM> * t, const unsigned int file_version)
00407 {
00408     // Retrieve data from archive required to construct new instance
00409     PottsMesh<DIM>* p_mesh;
00410     ar >> p_mesh;
00411 
00412     // Invoke inplace constructor to initialise instance
00413     ::new(t)PottsBasedCellPopulation<DIM>(*p_mesh);
00414 }
00415 }
00416 } // namespace ...
00417 #undef COVERAGE_IGNORE
00418 
00419 #endif /*POTTSBASEDCELLPOPULATION_HPP_*/
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3