MeshBasedCellPopulation.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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         // The Voronoi stuff can't be archived yet
00076         //archive & mpVoronoiTessellation
00077         delete mpVoronoiTessellation;
00078         mpVoronoiTessellation = NULL;
00079 
00080         archive & mMarkedSprings;
00081         archive & mUseAreaBasedDampingConstant;
00082         archive & mAreaBasedDampingConstantParameter;
00083         archive & mOutputVoronoiData;
00084         archive & mOutputCellPopulationVolumes;
00085 
00086         this->Validate();
00087     }
00088 
00089 protected:
00090 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00091 
00092     MutableMesh<DIM, DIM>& mrMesh;
00093 
00111     VertexMesh<DIM, DIM>* mpVoronoiTessellation;
00112 
00114     std::string mDirPath;
00115 
00117     out_stream mpVtkMetaFile;
00118 
00123     bool mDeleteMesh;
00124 
00130     std::set<std::pair<CellPtr,CellPtr> > mMarkedSprings;
00131 
00133     out_stream mpVizElementsFile;
00134 
00136     out_stream mpVoronoiFile;
00137 
00139     out_stream mpCellPopulationVolumesFile;
00140 
00142     out_stream mpCellVolumesFile;
00143 
00145     bool mUseAreaBasedDampingConstant;
00146 
00148     double mAreaBasedDampingConstantParameter;
00149 
00151     bool mOutputVoronoiData;
00152 
00154     bool mOutputCellPopulationVolumes;
00155 
00156 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00157 
00163     virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
00164 
00169     virtual void Validate();
00170 
00171 public:
00172 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00173 
00185     MeshBasedCellPopulation(MutableMesh<DIM, DIM>& rMesh,
00186                     std::vector<CellPtr>& rCells,
00187                     const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00188                     bool deleteMesh=false,
00189                     bool validate=true);
00190 
00196     MeshBasedCellPopulation(MutableMesh<DIM, DIM>& rMesh);
00197 
00201     ~MeshBasedCellPopulation();
00202 
00206     MutableMesh<DIM, DIM>& rGetMesh();
00207 
00211     const MutableMesh<DIM, DIM>& rGetMesh() const;
00212 
00214     bool UseAreaBasedDampingConstant();
00215 
00221     void SetOutputVoronoiData(bool outputVoronoiData);
00222 
00231     unsigned AddNode(Node<DIM>* pNewNode);
00232 
00241     void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00242 
00250     double GetDampingConstant(unsigned nodeIndex);
00251 
00257     void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
00258 
00271     virtual unsigned RemoveDeadCells();
00272 
00285     virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell);
00286 
00293     void CreateOutputFiles(const std::string& rDirectory, bool cleanOutputDirectory);
00294 
00298     void CloseOutputFiles();
00299 
00303     void WriteResultsToFiles();
00304 
00312     virtual void Update(bool hasHadBirthsOrDeaths=true);
00313 
00321     Node<DIM>* GetNode(unsigned index);
00322 
00328     unsigned GetNumNodes();
00329 
00333     virtual void WriteVtkResultsToFile();
00334 
00340     void WriteVoronoiResultsToFile();
00341 
00346     void WriteCellPopulationVolumeResultsToFile();
00347 
00353     void WriteCellVolumeResultsToFile();
00354 
00358     void CreateVoronoiTessellation();
00359 
00363     VertexMesh<DIM, DIM>* GetVoronoiTessellation();
00364 
00375     double GetVolumeOfVoronoiElement(unsigned index);
00376 
00387     double GetSurfaceAreaOfVoronoiElement(unsigned index);
00388 
00400     double GetVoronoiEdgeLength(unsigned index1, unsigned index2);
00401 
00411     double GetWidth(const unsigned& rDimension);
00412 
00418     class SpringIterator
00419     {
00420     public:
00421 
00425         Node<DIM>* GetNodeA();
00426 
00430         Node<DIM>* GetNodeB();
00431 
00435         CellPtr GetCellA();
00436 
00440         CellPtr GetCellB();
00441 
00447         bool operator!=(const MeshBasedCellPopulation<DIM>::SpringIterator& rOther);
00448 
00452         SpringIterator& operator++();
00453 
00460         SpringIterator(MeshBasedCellPopulation<DIM>& rCellPopulation, typename MutableMesh<DIM,DIM>::EdgeIterator edgeIter);
00461 
00462     private:
00463 
00465         std::set<std::set<unsigned> > mSpringsVisited;
00466 
00468         MeshBasedCellPopulation<DIM>& mrCellPopulation;
00469 
00471         typename MutableMesh<DIM, DIM>::EdgeIterator mEdgeIter;
00472     };
00473 
00477     SpringIterator SpringsBegin();
00478 
00482     SpringIterator SpringsEnd();
00483 
00487     void CheckCellPointers();
00488 
00498     std::pair<CellPtr,CellPtr> CreateCellPair(CellPtr pCell1, CellPtr pCell2);
00499 
00505     bool IsMarkedSpring(const std::pair<CellPtr,CellPtr>& rCellPair);
00506 
00512     void MarkSpring(std::pair<CellPtr,CellPtr>& rCellPair);
00513 
00519     void UnmarkSpring(std::pair<CellPtr,CellPtr>& rCellPair);
00520 
00524     double GetAreaBasedDampingConstantParameter();
00525 
00531     void SetAreaBasedDampingConstantParameter(double areaBasedDampingConstantParameter);
00532 
00536     bool GetOutputVoronoiData();
00537 
00541     bool GetOutputCellPopulationVolumes();
00542 
00548     void SetOutputCellPopulationVolumes(bool outputCellPopulationVolumes);
00549 
00555     void OutputCellPopulationParameters(out_stream& rParamsFile);
00556 };
00557 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00558 
00559 
00560 #include "SerializationExportWrapper.hpp"
00561 EXPORT_TEMPLATE_CLASS_SAME_DIMS(MeshBasedCellPopulation)
00562 
00563 namespace boost
00564 {
00565 namespace serialization
00566 {
00570 template<class Archive, unsigned DIM>
00571 inline void save_construct_data(
00572     Archive & ar, const MeshBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00573 {
00574     // Save data required to construct instance
00575     const MutableMesh<DIM,DIM>* p_mesh = &(t->rGetMesh());
00576     ar & p_mesh;
00577 }
00578 
00583 template<class Archive, unsigned DIM>
00584 inline void load_construct_data(
00585     Archive & ar, MeshBasedCellPopulation<DIM> * t, const unsigned int file_version)
00586 {
00587     // Retrieve data from archive required to construct new instance
00588     MutableMesh<DIM,DIM>* p_mesh;
00589     ar >> p_mesh;
00590 
00591     // Invoke inplace constructor to initialise instance
00592     ::new(t)MeshBasedCellPopulation<DIM>(*p_mesh);
00593 }
00594 }
00595 } // namespace ...
00596 
00597 #endif /*MESHBASEDCELLPOPULATION_HPP_*/

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5