MeshBasedCellPopulation.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 #ifndef MESHBASEDCELLPOPULATION_HPP_
00029 #define MESHBASEDCELLPOPULATION_HPP_
00030 
00031 #include <map>
00032 #include "AbstractCentreBasedCellPopulation.hpp"
00033 #include "MutableMesh.hpp"
00034 #include "VertexMesh.hpp"
00035 #include "Exception.hpp"
00036 #include "ArchiveLocationInfo.hpp"
00037 #include "TrianglesMeshReader.hpp"
00038 
00039 #include "ChasteSerialization.hpp"
00040 #include <boost/serialization/base_object.hpp>
00041 #include <boost/serialization/set.hpp>
00042 #include <boost/serialization/vector.hpp>
00043 
00044 
00052 template<unsigned DIM>
00053 class MeshBasedCellPopulation : public AbstractCentreBasedCellPopulation<DIM>
00054 {
00055     friend class TestMeshBasedCellPopulation;
00056 private:
00058     friend class boost::serialization::access;
00070     template<class Archive>
00071     void serialize(Archive & archive, const unsigned int version)
00072     {
00073         archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<DIM> >(*this);
00074 
00075         /*
00076          * In its current form the code does not allow the direct serialization
00077          * of the VertexMesh class, so instead we delete mpVoronoiTessellation.
00078          */
00079         delete mpVoronoiTessellation;
00080         mpVoronoiTessellation = NULL;
00081 
00082         archive & mMarkedSprings;
00083         archive & mUseAreaBasedDampingConstant;
00084         archive & mAreaBasedDampingConstantParameter;
00085         archive & mOutputVoronoiData;
00086         archive & mOutputCellPopulationVolumes;
00087         archive & mWriteVtkAsPoints;
00088 
00089         this->Validate();
00090     }
00091 
00092 protected:
00093 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00094 
00095     MutableMesh<DIM, DIM>& mrMesh;
00096 
00112     VertexMesh<DIM, DIM>* mpVoronoiTessellation;
00113 
00118     bool mDeleteMesh;
00119 
00125     std::set<std::pair<CellPtr,CellPtr> > mMarkedSprings;
00126 
00128     out_stream mpVizElementsFile;
00129 
00131     out_stream mpVoronoiFile;
00132 
00134     out_stream mpCellPopulationVolumesFile;
00135 
00137     out_stream mpCellVolumesFile;
00138 
00140     bool mUseAreaBasedDampingConstant;
00141 
00143     double mAreaBasedDampingConstantParameter;
00144 
00146     bool mOutputVoronoiData;
00147 
00149     bool mOutputCellPopulationVolumes;
00150 
00152     bool mWriteVtkAsPoints;
00153 
00154 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00155 
00161     virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
00162 
00167     virtual void Validate();
00168 
00169 public:
00170 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00171 
00183     MeshBasedCellPopulation(MutableMesh<DIM, DIM>& rMesh,
00184                     std::vector<CellPtr>& rCells,
00185                     const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00186                     bool deleteMesh=false,
00187                     bool validate=true);
00188 
00194     MeshBasedCellPopulation(MutableMesh<DIM, DIM>& rMesh);
00195 
00199     ~MeshBasedCellPopulation();
00200 
00204     MutableMesh<DIM, DIM>& rGetMesh();
00205 
00209     const MutableMesh<DIM, DIM>& rGetMesh() const;
00210 
00212     bool UseAreaBasedDampingConstant();
00213 
00219     void SetOutputVoronoiData(bool outputVoronoiData);
00220 
00229     unsigned AddNode(Node<DIM>* pNewNode);
00230 
00239     void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00240 
00248     double GetDampingConstant(unsigned nodeIndex);
00249 
00255     void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
00256 
00269     virtual unsigned RemoveDeadCells();
00270 
00283     virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell);
00284 
00291     void CreateOutputFiles(const std::string& rDirectory, bool cleanOutputDirectory);
00292 
00296     void CloseOutputFiles();
00297 
00301     void WriteResultsToFiles();
00302 
00310     virtual void Update(bool hasHadBirthsOrDeaths=true);
00311 
00319     Node<DIM>* GetNode(unsigned index);
00320 
00326     unsigned GetNumNodes();
00327 
00331     virtual void WriteVtkResultsToFile();
00332 
00338     void WriteVoronoiResultsToFile();
00339 
00344     void WriteCellPopulationVolumeResultsToFile();
00345 
00351     void WriteCellVolumeResultsToFile();
00352 
00356     void CreateVoronoiTessellation();
00357 
00361     VertexMesh<DIM, DIM>* GetVoronoiTessellation();
00362 
00373     double GetVolumeOfVoronoiElement(unsigned index);
00374 
00385     double GetSurfaceAreaOfVoronoiElement(unsigned index);
00386 
00398     double GetVoronoiEdgeLength(unsigned index1, unsigned index2);
00399 
00409     double GetWidth(const unsigned& rDimension);
00410 
00416     class SpringIterator
00417     {
00418     public:
00419 
00423         Node<DIM>* GetNodeA();
00424 
00428         Node<DIM>* GetNodeB();
00429 
00433         CellPtr GetCellA();
00434 
00438         CellPtr GetCellB();
00439 
00445         bool operator!=(const MeshBasedCellPopulation<DIM>::SpringIterator& rOther);
00446 
00450         SpringIterator& operator++();
00451 
00458         SpringIterator(MeshBasedCellPopulation<DIM>& rCellPopulation, typename MutableMesh<DIM,DIM>::EdgeIterator edgeIter);
00459 
00460     private:
00461 
00463         std::set<std::set<unsigned> > mSpringsVisited;
00464 
00466         MeshBasedCellPopulation<DIM>& mrCellPopulation;
00467 
00469         typename MutableMesh<DIM, DIM>::EdgeIterator mEdgeIter;
00470     };
00471 
00475     SpringIterator SpringsBegin();
00476 
00480     SpringIterator SpringsEnd();
00481 
00485     void CheckCellPointers();
00486 
00496     std::pair<CellPtr,CellPtr> CreateCellPair(CellPtr pCell1, CellPtr pCell2);
00497 
00503     bool IsMarkedSpring(const std::pair<CellPtr,CellPtr>& rCellPair);
00504 
00510     void MarkSpring(std::pair<CellPtr,CellPtr>& rCellPair);
00511 
00517     void UnmarkSpring(std::pair<CellPtr,CellPtr>& rCellPair);
00518 
00522     double GetAreaBasedDampingConstantParameter();
00523 
00529     void SetAreaBasedDampingConstantParameter(double areaBasedDampingConstantParameter);
00530 
00534     bool GetOutputVoronoiData();
00535 
00539     bool GetOutputCellPopulationVolumes();
00540 
00546     void SetOutputCellPopulationVolumes(bool outputCellPopulationVolumes);
00547 
00553     void OutputCellPopulationParameters(out_stream& rParamsFile);
00554 
00560     void SetWriteVtkAsPoints(bool writeVtkAsPoints);
00561 
00565     bool GetWriteVtkAsPoints();
00566 };
00567 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00568 
00569 
00570 #include "SerializationExportWrapper.hpp"
00571 EXPORT_TEMPLATE_CLASS_SAME_DIMS(MeshBasedCellPopulation)
00572 
00573 namespace boost
00574 {
00575 namespace serialization
00576 {
00580 template<class Archive, unsigned DIM>
00581 inline void save_construct_data(
00582     Archive & ar, const MeshBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00583 {
00584     // Save data required to construct instance
00585     const MutableMesh<DIM,DIM>* p_mesh = &(t->rGetMesh());
00586     ar & p_mesh;
00587 }
00588 
00593 template<class Archive, unsigned DIM>
00594 inline void load_construct_data(
00595     Archive & ar, MeshBasedCellPopulation<DIM> * t, const unsigned int file_version)
00596 {
00597     // Retrieve data from archive required to construct new instance
00598     MutableMesh<DIM,DIM>* p_mesh;
00599     ar >> p_mesh;
00600 
00601     // Invoke inplace constructor to initialise instance
00602     ::new(t)MeshBasedCellPopulation<DIM>(*p_mesh);
00603 }
00604 }
00605 } // namespace ...
00606 
00607 #endif /*MESHBASEDCELLPOPULATION_HPP_*/

Generated on Tue May 31 14:31:41 2011 for Chaste by  doxygen 1.5.5