Chaste Release::3.1
PottsBasedCellPopulation.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 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 // Needed here to avoid serialization errors (on Boost<1.37)
00050 #include "WildTypeCellMutationState.hpp"
00051 
00052 template<unsigned DIM>
00053 class AbstractPottsUpdateRule; // Circular definition
00054 
00065 template<unsigned DIM>
00066 class PottsBasedCellPopulation : public AbstractOnLatticeCellPopulation<DIM>
00067 {
00068     friend class TestPottsBasedCellPopulation;
00069 
00070 private:
00071 
00077     VertexMesh<DIM,DIM>* mpElementTessellation;
00078 
00083     PottsMesh<DIM>* mpPottsMesh;
00084 
00089     MutableMesh<DIM,DIM>* mpMutableMesh;
00090 
00092     out_stream mpVizElementsFile;
00093 
00095     std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > > mUpdateRuleCollection;
00096 
00098     double mTemperature;
00099 
00104     unsigned mNumSweepsPerTimestep;
00105 
00106     friend class boost::serialization::access;
00118     template<class Archive>
00119     void serialize(Archive & archive, const unsigned int version)
00120     {
00121 #define COVERAGE_IGNORE
00122         archive & boost::serialization::base_object<AbstractOnLatticeCellPopulation<DIM> >(*this);
00123 
00124         /*
00125          * In its current form the code does not allow the direct serialization
00126          * of the VertexMesh class, so instead we delete mpVoronoiTessellation.
00127          */
00128         delete mpElementTessellation;
00129         mpElementTessellation = NULL;
00130 
00131         archive & mUpdateRuleCollection;
00132         archive & mTemperature;
00133         archive & mNumSweepsPerTimestep;
00134 
00135 #undef COVERAGE_IGNORE
00136     }
00137 
00142     void Validate();
00143 
00147     void WriteVtkResultsToFile();
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     c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell);
00231 
00239     PottsElement<DIM>* GetElementCorrespondingToCell(CellPtr pCell);
00240 
00251     CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr());
00252 
00262     unsigned RemoveDeadCells();
00263 
00269     void UpdateCellLocations(double dt);
00270 
00277     bool IsCellAssociatedWithADeletedLocation(CellPtr pCell);
00278 
00285     void Update(bool hasHadBirthsOrDeaths=true);
00286 
00293     void CreateOutputFiles(const std::string& rDirectory, bool cleanOutputDirectory);
00294 
00298     void CloseOutputFiles();
00299 
00303     void WriteResultsToFiles();
00304 
00308     void WriteCellVolumeResultsToFile();
00309 
00315     double GetVolumeOfCell(CellPtr pCell);
00316 
00320     virtual void GenerateCellResultsAndWriteToFiles();
00321 
00331     double GetWidth(const unsigned& rDimension);
00332 
00338     void AddUpdateRule(boost::shared_ptr<AbstractPottsUpdateRule<DIM> > pUpdateRule);
00339 
00343     void RemoveAllUpdateRules();
00344 
00350     const std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > >& rGetUpdateRuleCollection() const;
00351 
00360     void OutputCellPopulationParameters(out_stream& rParamsFile);
00361 
00371     std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
00372 
00378     void SetTemperature(double temperature);
00379 
00383     double GetTemperature();
00384 
00390     void SetNumSweepsPerTimestep(unsigned numSweepsPerTimestep);
00391 
00395     unsigned GetNumSweepsPerTimestep();
00396 
00400     void CreateElementTessellation();
00401 
00405     VertexMesh<DIM,DIM>* GetElementTessellation();
00406 
00410     void CreateMutableMesh();
00411 
00415     MutableMesh<DIM,DIM>* GetMutableMesh();
00416 };
00417 
00418 #include "SerializationExportWrapper.hpp"
00419 EXPORT_TEMPLATE_CLASS_SAME_DIMS(PottsBasedCellPopulation)
00420 
00421 namespace boost
00422 {
00423 namespace serialization
00424 {
00428 template<class Archive, unsigned DIM>
00429 inline void save_construct_data(
00430     Archive & ar, const PottsBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00431 {
00432     // Save data required to construct instance
00433     const PottsMesh<DIM>* p_mesh = &(t->rGetMesh());
00434     ar & p_mesh;
00435 }
00436 
00441 template<class Archive, unsigned DIM>
00442 inline void load_construct_data(
00443     Archive & ar, PottsBasedCellPopulation<DIM> * t, const unsigned int file_version)
00444 {
00445     // Retrieve data from archive required to construct new instance
00446     PottsMesh<DIM>* p_mesh;
00447     ar >> p_mesh;
00448 
00449     // Invoke inplace constructor to initialise instance
00450     ::new(t)PottsBasedCellPopulation<DIM>(*p_mesh);
00451 }
00452 }
00453 } // namespace ...
00454 
00455 #endif /*POTTSBASEDCELLPOPULATION_HPP_*/