MeshBasedCellPopulation.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2014, 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 MESHBASEDCELLPOPULATION_HPP_
00037 #define MESHBASEDCELLPOPULATION_HPP_
00038 
00039 #include <map>
00040 #include "AbstractCentreBasedCellPopulation.hpp"
00041 #include "MutableMesh.hpp"
00042 #include "VertexMesh.hpp"
00043 #include "TrianglesMeshReader.hpp"
00044 
00045 #include "ChasteSerialization.hpp"
00046 #include <boost/serialization/base_object.hpp>
00047 #include <boost/serialization/set.hpp>
00048 #include <boost/serialization/vector.hpp>
00049 
00056 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM=ELEMENT_DIM>
00057 class MeshBasedCellPopulation : public AbstractCentreBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>
00058 {
00059     friend class TestMeshBasedCellPopulation;
00060 private:
00062     friend class boost::serialization::access;
00074     template<class Archive>
00075     void serialize(Archive & archive, const unsigned int version)
00076     {
00077         archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> >(*this);
00078 
00079         /*
00080          * In its current form the code does not allow the direct serialization
00081          * of the VertexMesh class, so instead we delete mpVoronoiTessellation.
00082          */
00083         delete mpVoronoiTessellation;
00084         mpVoronoiTessellation = NULL;
00085 
00086         archive & mSpringRestLengths;
00087         archive & mUseAreaBasedDampingConstant;
00088         archive & mAreaBasedDampingConstantParameter;
00089         archive & mWriteVtkAsPoints;
00090         archive & mOutputMeshInVtk;
00091         archive & mHasVariableRestLength;
00092 
00093         this->Validate();
00094     }
00095 
00096 protected:
00097 #define COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00098 
00114     VertexMesh<ELEMENT_DIM, SPACE_DIM>* mpVoronoiTessellation;
00115 
00117     MutableMesh<ELEMENT_DIM, SPACE_DIM>* mpMutableMesh;
00118 
00123     bool mDeleteMesh;
00124 
00128     std::map<std::pair<unsigned,unsigned>, double> mSpringRestLengths;
00129 
00131     bool mUseAreaBasedDampingConstant;
00132 
00134     double mAreaBasedDampingConstantParameter;
00135 
00137     bool mWriteVtkAsPoints;
00138 
00140     bool mOutputMeshInVtk;
00141 
00143     bool mHasVariableRestLength;
00144 
00146     std::vector< std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > > mNodePairs;
00147 
00148 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00149 
00155     virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
00156 
00161     virtual void Validate();
00162 
00163 public:
00164 #define COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00165 
00177     MeshBasedCellPopulation(MutableMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00178                     std::vector<CellPtr>& rCells,
00179                     const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00180                     bool deleteMesh=false,
00181                     bool validate=true);
00182 
00188     MeshBasedCellPopulation(MutableMesh<ELEMENT_DIM, SPACE_DIM>& rMesh);
00189 
00193     virtual ~MeshBasedCellPopulation();
00194 
00198     MutableMesh<ELEMENT_DIM, SPACE_DIM>& rGetMesh();
00199 
00203     const MutableMesh<ELEMENT_DIM, SPACE_DIM>& rGetMesh() const;
00204 
00206     bool UseAreaBasedDampingConstant();
00207 
00216     unsigned AddNode(Node<SPACE_DIM>* pNewNode);
00217 
00226     void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM>& rNewLocation);
00227 
00235     double GetDampingConstant(unsigned nodeIndex);
00236 
00242     void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
00243 
00251     virtual void OpenWritersFiles(const std::string& rDirectory);
00252 
00265     virtual unsigned RemoveDeadCells();
00266 
00279     virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,SPACE_DIM>& rCellDivisionVector, CellPtr pParentCell);
00280 
00286     virtual void WriteResultsToFiles(const std::string& rDirectory);
00287 
00294     virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationWriter);
00295 
00303     virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > pCellWriter, CellPtr pCell);
00304 
00312     virtual void Update(bool hasHadBirthsOrDeaths=true);
00313 
00320     void TessellateIfNeeded();
00321 
00327     void DivideLongSprings(double springDivisionThreshold);
00328 
00336     Node<SPACE_DIM>* GetNode(unsigned index);
00337 
00343     unsigned GetNumNodes();
00344 
00350     virtual void WriteVtkResultsToFile(const std::string& rDirectory);
00351 
00358     double GetVolumeOfCell(CellPtr pCell);
00359 
00363     void CreateVoronoiTessellation();
00364 
00368     VertexMesh<ELEMENT_DIM, SPACE_DIM>* GetVoronoiTessellation();
00369 
00382     double GetVolumeOfVoronoiElement(unsigned index);
00383 
00394     double GetSurfaceAreaOfVoronoiElement(unsigned index);
00395 
00407     double GetVoronoiEdgeLength(unsigned index1, unsigned index2);
00408 
00418     double GetWidth(const unsigned& rDimension);
00419 
00425     class SpringIterator
00426     {
00427     public:
00428 
00432         Node<SPACE_DIM>* GetNodeA();
00433 
00437         Node<SPACE_DIM>* GetNodeB();
00438 
00442         CellPtr GetCellA();
00443 
00447         CellPtr GetCellB();
00448 
00455         bool operator!=(const typename MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>::SpringIterator& rOther);
00456 
00461         SpringIterator& operator++();
00462 
00469         SpringIterator(MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>& rCellPopulation, typename MutableMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator edgeIter);
00470 
00471     private:
00472 
00474         std::set<std::set<unsigned> > mSpringsVisited;
00475 
00477         MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>& mrCellPopulation;
00478 
00480         typename MutableMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator mEdgeIter;
00481     };
00482 
00486     SpringIterator SpringsBegin();
00487 
00491     SpringIterator SpringsEnd();
00492 
00496     void CheckCellPointers();
00497 
00501     double GetAreaBasedDampingConstantParameter();
00502 
00508     void SetAreaBasedDampingConstantParameter(double areaBasedDampingConstantParameter);
00509 
00515     std::vector< std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > >& rGetNodePairs();
00516 
00522     void OutputCellPopulationParameters(out_stream& rParamsFile);
00523 
00529     void SetWriteVtkAsPoints(bool writeVtkAsPoints);
00530 
00534     bool GetWriteVtkAsPoints();
00535 
00541     void SetOutputMeshInVtk(bool outputMeshInVtk);
00542 
00546     bool GetOutputMeshInVtk();
00547 
00554     std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
00555 
00559     void CalculateRestLengths();
00560 
00567     double GetRestLength(unsigned indexA, unsigned indexB);
00568 
00576     void SetRestLength(unsigned indexA, unsigned indexB, double restLength);
00577 
00578 };
00579 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00580 
00581 #include "SerializationExportWrapper.hpp"
00582 EXPORT_TEMPLATE_CLASS_ALL_DIMS(MeshBasedCellPopulation)
00583 
00584 namespace boost
00585 {
00586 namespace serialization
00587 {
00591 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00592 inline void save_construct_data(
00593     Archive & ar, const MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> * t, const BOOST_PFTO unsigned int file_version)
00594 {
00595     // Save data required to construct instance
00596     const MutableMesh<ELEMENT_DIM, SPACE_DIM>* p_mesh = &(t->rGetMesh());
00597     ar & p_mesh;
00598 }
00599 
00604 template<class Archive,  unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00605 inline void load_construct_data(
00606     Archive & ar, MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> * t, const unsigned int file_version)
00607 {
00608     // Retrieve data from archive required to construct new instance
00609     MutableMesh<ELEMENT_DIM, SPACE_DIM>* p_mesh;
00610     ar >> p_mesh;
00611 
00612     // Invoke inplace constructor to initialise instance
00613     ::new(t)MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>(*p_mesh);
00614 }
00615 }
00616 } // namespace ...
00617 
00618 #endif /*MESHBASEDCELLPOPULATION_HPP_*/

Generated by  doxygen 1.6.2