PottsBasedCellPopulation.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 POTTSBASEDCELLPOPULATION_HPP_
00037 #define POTTSBASEDCELLPOPULATION_HPP_
00038 
00039 #include "AbstractOnLatticeCellPopulation.hpp"
00040 #include "PottsMesh.hpp"
00041 #include "VertexMesh.hpp"
00042 #include "AbstractPottsUpdateRule.hpp"
00043 #include "MutableMesh.hpp"
00044 
00045 #include "ChasteSerialization.hpp"
00046 #include <boost/serialization/base_object.hpp>
00047 #include <boost/serialization/vector.hpp>
00048 
00049 template<unsigned DIM>
00050 class AbstractPottsUpdateRule; // Circular definition
00051 
00062 template<unsigned DIM>
00063 class PottsBasedCellPopulation : public AbstractOnLatticeCellPopulation<DIM>
00064 {
00065     friend class TestPottsBasedCellPopulation;
00066 
00067 private:
00068 
00074     VertexMesh<DIM,DIM>* mpElementTessellation;
00075 
00080     PottsMesh<DIM>* mpPottsMesh;
00081 
00086     MutableMesh<DIM,DIM>* mpMutableMesh;
00087 
00089     std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > > mUpdateRuleCollection;
00090 
00092     double mTemperature;
00093 
00098     unsigned mNumSweepsPerTimestep;
00099 
00100     friend class boost::serialization::access;
00112     template<class Archive>
00113     void serialize(Archive & archive, const unsigned int version)
00114     {
00115 #define COVERAGE_IGNORE
00116         archive & boost::serialization::base_object<AbstractOnLatticeCellPopulation<DIM> >(*this);
00117 
00118         /*
00119          * In its current form the code does not allow the direct serialization
00120          * of the PottsMesh class, so instead we delete mpVoronoiTessellation.
00121          */
00122         delete mpElementTessellation;
00123         mpElementTessellation = NULL;
00124 
00125         archive & mUpdateRuleCollection;
00126         archive & mTemperature;
00127         archive & mNumSweepsPerTimestep;
00128 
00129 #undef COVERAGE_IGNORE
00130     }
00131 
00136     void Validate();
00137 
00147     virtual void WriteVtkResultsToFile(const std::string& rDirectory);
00148 
00149 public:
00150 
00164     PottsBasedCellPopulation(PottsMesh<DIM>& rMesh,
00165                              std::vector<CellPtr>& rCells,
00166                              bool deleteMesh=false,
00167                              bool validate=true,
00168                              const std::vector<unsigned> locationIndices=std::vector<unsigned>());
00169 
00175     PottsBasedCellPopulation(PottsMesh<DIM>& rMesh);
00176 
00180     virtual ~PottsBasedCellPopulation();
00181 
00185     PottsMesh<DIM>& rGetMesh();
00186 
00190     const PottsMesh<DIM>& rGetMesh() const;
00191 
00199     PottsElement<DIM>* GetElement(unsigned elementIndex);
00200 
00204     unsigned GetNumElements();
00205 
00213     Node<DIM>* GetNode(unsigned index);
00214 
00220     unsigned GetNumNodes();
00221 
00230     std::set<unsigned> GetNeighbouringLocationIndices(CellPtr pCell);
00231 
00240     c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell);
00241 
00249     PottsElement<DIM>* GetElementCorrespondingToCell(CellPtr pCell);
00250 
00261     CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr());
00262 
00272     unsigned RemoveDeadCells();
00273 
00279     void UpdateCellLocations(double dt);
00280 
00287     bool IsCellAssociatedWithADeletedLocation(CellPtr pCell);
00288 
00295     void Update(bool hasHadBirthsOrDeaths=true);
00296 
00304     virtual void OpenWritersFiles(OutputFileHandler& rOutputFileHandler);
00305 
00311     virtual void WriteResultsToFiles(const std::string& rDirectory);
00312 
00319     virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<DIM, DIM> > pPopulationWriter);
00320 
00327     virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<DIM, DIM> > pPopulationCountWriter);
00328 
00336     virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<DIM, DIM> > pCellWriter, CellPtr pCell);
00337 
00344     double GetVolumeOfCell(CellPtr pCell);
00345 
00355     double GetWidth(const unsigned& rDimension);
00356 
00362     void AddUpdateRule(boost::shared_ptr<AbstractPottsUpdateRule<DIM> > pUpdateRule);
00363 
00367     void RemoveAllUpdateRules();
00368 
00374     const std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > >& rGetUpdateRuleCollection() const;
00375 
00384     void OutputCellPopulationParameters(out_stream& rParamsFile);
00385 
00391     void SetTemperature(double temperature);
00392 
00396     double GetTemperature();
00397 
00403     void SetNumSweepsPerTimestep(unsigned numSweepsPerTimestep);
00404 
00408     unsigned GetNumSweepsPerTimestep();
00409 
00413     void CreateElementTessellation();
00414 
00418     VertexMesh<DIM,DIM>* GetElementTessellation();
00419 
00423     void CreateMutableMesh();
00424 
00428     MutableMesh<DIM,DIM>* GetMutableMesh();
00429 };
00430 
00431 #include "SerializationExportWrapper.hpp"
00432 EXPORT_TEMPLATE_CLASS_SAME_DIMS(PottsBasedCellPopulation)
00433 
00434 namespace boost
00435 {
00436 namespace serialization
00437 {
00441 template<class Archive, unsigned DIM>
00442 inline void save_construct_data(
00443     Archive & ar, const PottsBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00444 {
00445     // Save data required to construct instance
00446     const PottsMesh<DIM>* p_mesh = &(t->rGetMesh());
00447     ar & p_mesh;
00448 }
00449 
00454 template<class Archive, unsigned DIM>
00455 inline void load_construct_data(
00456     Archive & ar, PottsBasedCellPopulation<DIM> * t, const unsigned int file_version)
00457 {
00458     // Retrieve data from archive required to construct new instance
00459     PottsMesh<DIM>* p_mesh;
00460     ar >> p_mesh;
00461 
00462     // Invoke inplace constructor to initialise instance
00463     ::new(t)PottsBasedCellPopulation<DIM>(*p_mesh);
00464 }
00465 }
00466 } // namespace ...
00467 
00468 #endif /*POTTSBASEDCELLPOPULATION_HPP_*/

Generated by  doxygen 1.6.2