MeshBasedCellPopulation.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef MESHBASEDCELLPOPULATION_HPP_
00030 #define MESHBASEDCELLPOPULATION_HPP_
00031
00032 #include <map>
00033 #include "AbstractCentreBasedCellPopulation.hpp"
00034 #include "MutableMesh.hpp"
00035 #include "VertexMesh.hpp"
00036 #include "TrianglesMeshReader.hpp"
00037
00038 #include "ChasteSerialization.hpp"
00039 #include <boost/serialization/base_object.hpp>
00040 #include <boost/serialization/set.hpp>
00041 #include <boost/serialization/vector.hpp>
00042
00043
00051 template<unsigned DIM>
00052 class MeshBasedCellPopulation : public AbstractCentreBasedCellPopulation<DIM>
00053 {
00054 friend class TestMeshBasedCellPopulation;
00055 private:
00057 friend class boost::serialization::access;
00069 template<class Archive>
00070 void serialize(Archive & archive, const unsigned int version)
00071 {
00072 archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<DIM> >(*this);
00073
00074
00075
00076
00077
00078 delete mpVoronoiTessellation;
00079 mpVoronoiTessellation = NULL;
00080
00081 archive & mMarkedSprings;
00082 archive & mUseAreaBasedDampingConstant;
00083 archive & mAreaBasedDampingConstantParameter;
00084 archive & mOutputVoronoiData;
00085 archive & mOutputCellPopulationVolumes;
00086 archive & mWriteVtkAsPoints;
00087
00088 this->Validate();
00089 }
00090
00091 protected:
00092 #define COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00093
00094 MutableMesh<DIM, DIM>& mrMesh;
00095
00111 VertexMesh<DIM, DIM>* mpVoronoiTessellation;
00112
00117 bool mDeleteMesh;
00118
00124 std::set<std::pair<CellPtr,CellPtr> > mMarkedSprings;
00125
00127 out_stream mpVizElementsFile;
00128
00130 out_stream mpVoronoiFile;
00131
00133 out_stream mpCellPopulationVolumesFile;
00134
00136 bool mUseAreaBasedDampingConstant;
00137
00139 double mAreaBasedDampingConstantParameter;
00140
00142 bool mOutputVoronoiData;
00143
00145 bool mOutputCellPopulationVolumes;
00146
00148 bool mWriteVtkAsPoints;
00149
00150 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00151
00157 virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
00158
00163 virtual void Validate();
00164
00165 public:
00166 #define COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00167
00179 MeshBasedCellPopulation(MutableMesh<DIM, DIM>& rMesh,
00180 std::vector<CellPtr>& rCells,
00181 const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00182 bool deleteMesh=false,
00183 bool validate=true);
00184
00190 MeshBasedCellPopulation(MutableMesh<DIM, DIM>& rMesh);
00191
00195 ~MeshBasedCellPopulation();
00196
00200 MutableMesh<DIM, DIM>& rGetMesh();
00201
00205 const MutableMesh<DIM, DIM>& rGetMesh() const;
00206
00208 bool UseAreaBasedDampingConstant();
00209
00215 void SetOutputVoronoiData(bool outputVoronoiData);
00216
00225 unsigned AddNode(Node<DIM>* pNewNode);
00226
00235 void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00236
00244 double GetDampingConstant(unsigned nodeIndex);
00245
00251 void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
00252
00265 virtual unsigned RemoveDeadCells();
00266
00279 virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell);
00280
00287 void CreateOutputFiles(const std::string& rDirectory, bool cleanOutputDirectory);
00288
00292 void CloseOutputFiles();
00293
00297 void WriteResultsToFiles();
00298
00306 virtual void Update(bool hasHadBirthsOrDeaths=true);
00307
00313 void TessellateIfNeeded();
00314
00322 Node<DIM>* GetNode(unsigned index);
00323
00329 unsigned GetNumNodes();
00330
00334 virtual void WriteVtkResultsToFile();
00335
00341 void WriteVoronoiResultsToFile();
00342
00347 void WriteCellPopulationVolumeResultsToFile();
00348
00352 void WriteCellVolumeResultsToFile();
00353
00357 void CreateVoronoiTessellation();
00358
00362 VertexMesh<DIM, DIM>* GetVoronoiTessellation();
00363
00374 double GetVolumeOfVoronoiElement(unsigned index);
00375
00386 double GetSurfaceAreaOfVoronoiElement(unsigned index);
00387
00399 double GetVoronoiEdgeLength(unsigned index1, unsigned index2);
00400
00410 double GetWidth(const unsigned& rDimension);
00411
00417 class SpringIterator
00418 {
00419 public:
00420
00424 Node<DIM>* GetNodeA();
00425
00429 Node<DIM>* GetNodeB();
00430
00434 CellPtr GetCellA();
00435
00439 CellPtr GetCellB();
00440
00446 bool operator!=(const MeshBasedCellPopulation<DIM>::SpringIterator& rOther);
00447
00451 SpringIterator& operator++();
00452
00459 SpringIterator(MeshBasedCellPopulation<DIM>& rCellPopulation, typename MutableMesh<DIM,DIM>::EdgeIterator edgeIter);
00460
00461 private:
00462
00464 std::set<std::set<unsigned> > mSpringsVisited;
00465
00467 MeshBasedCellPopulation<DIM>& mrCellPopulation;
00468
00470 typename MutableMesh<DIM, DIM>::EdgeIterator mEdgeIter;
00471 };
00472
00476 SpringIterator SpringsBegin();
00477
00481 SpringIterator SpringsEnd();
00482
00486 void CheckCellPointers();
00487
00497 std::pair<CellPtr,CellPtr> CreateCellPair(CellPtr pCell1, CellPtr pCell2);
00498
00504 bool IsMarkedSpring(const std::pair<CellPtr,CellPtr>& rCellPair);
00505
00511 void MarkSpring(std::pair<CellPtr,CellPtr>& rCellPair);
00512
00518 void UnmarkSpring(std::pair<CellPtr,CellPtr>& rCellPair);
00519
00523 double GetAreaBasedDampingConstantParameter();
00524
00530 void SetAreaBasedDampingConstantParameter(double areaBasedDampingConstantParameter);
00531
00535 bool GetOutputVoronoiData();
00536
00540 bool GetOutputCellPopulationVolumes();
00541
00547 void SetOutputCellPopulationVolumes(bool outputCellPopulationVolumes);
00548
00554 void OutputCellPopulationParameters(out_stream& rParamsFile);
00555
00561 void SetWriteVtkAsPoints(bool writeVtkAsPoints);
00562
00566 bool GetWriteVtkAsPoints();
00567
00574 std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
00575 };
00576 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00577
00578 #include "SerializationExportWrapper.hpp"
00579 EXPORT_TEMPLATE_CLASS_SAME_DIMS(MeshBasedCellPopulation)
00580
00581 namespace boost
00582 {
00583 namespace serialization
00584 {
00588 template<class Archive, unsigned DIM>
00589 inline void save_construct_data(
00590 Archive & ar, const MeshBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00591 {
00592
00593 const MutableMesh<DIM,DIM>* p_mesh = &(t->rGetMesh());
00594 ar & p_mesh;
00595 }
00596
00601 template<class Archive, unsigned DIM>
00602 inline void load_construct_data(
00603 Archive & ar, MeshBasedCellPopulation<DIM> * t, const unsigned int file_version)
00604 {
00605
00606 MutableMesh<DIM,DIM>* p_mesh;
00607 ar >> p_mesh;
00608
00609
00610 ::new(t)MeshBasedCellPopulation<DIM>(*p_mesh);
00611 }
00612 }
00613 }
00614
00615 #endif