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
00030
00031
00032
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
00081
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(OutputFileHandler& rOutputFileHandler);
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
00302 virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationCountWriter);
00303
00311 virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > pCellWriter, CellPtr pCell);
00312
00320 virtual void Update(bool hasHadBirthsOrDeaths=true);
00321
00328 void TessellateIfNeeded();
00329
00335 void DivideLongSprings(double springDivisionThreshold);
00336
00344 Node<SPACE_DIM>* GetNode(unsigned index);
00345
00351 unsigned GetNumNodes();
00352
00358 virtual void WriteVtkResultsToFile(const std::string& rDirectory);
00359
00366 double GetVolumeOfCell(CellPtr pCell);
00367
00371 void CreateVoronoiTessellation();
00372
00376 VertexMesh<ELEMENT_DIM, SPACE_DIM>* GetVoronoiTessellation();
00377
00390 double GetVolumeOfVoronoiElement(unsigned index);
00391
00402 double GetSurfaceAreaOfVoronoiElement(unsigned index);
00403
00415 double GetVoronoiEdgeLength(unsigned index1, unsigned index2);
00416
00426 double GetWidth(const unsigned& rDimension);
00427
00433 class SpringIterator
00434 {
00435 public:
00436
00440 Node<SPACE_DIM>* GetNodeA();
00441
00445 Node<SPACE_DIM>* GetNodeB();
00446
00450 CellPtr GetCellA();
00451
00455 CellPtr GetCellB();
00456
00463 bool operator!=(const typename MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>::SpringIterator& rOther);
00464
00469 SpringIterator& operator++();
00470
00477 SpringIterator(MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>& rCellPopulation, typename MutableMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator edgeIter);
00478
00479 private:
00480
00482 std::set<std::set<unsigned> > mSpringsVisited;
00483
00485 MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>& mrCellPopulation;
00486
00488 typename MutableMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator mEdgeIter;
00489 };
00490
00494 SpringIterator SpringsBegin();
00495
00499 SpringIterator SpringsEnd();
00500
00504 void CheckCellPointers();
00505
00509 double GetAreaBasedDampingConstantParameter();
00510
00516 void SetAreaBasedDampingConstantParameter(double areaBasedDampingConstantParameter);
00517
00523 std::vector< std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > >& rGetNodePairs();
00524
00530 void OutputCellPopulationParameters(out_stream& rParamsFile);
00531
00537 void SetWriteVtkAsPoints(bool writeVtkAsPoints);
00538
00542 bool GetWriteVtkAsPoints();
00543
00549 void SetOutputMeshInVtk(bool outputMeshInVtk);
00550
00554 bool GetOutputMeshInVtk();
00555
00562 std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
00563
00567 void CalculateRestLengths();
00568
00575 double GetRestLength(unsigned indexA, unsigned indexB);
00576
00584 void SetRestLength(unsigned indexA, unsigned indexB, double restLength);
00585
00586 };
00587 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00588
00589 #include "SerializationExportWrapper.hpp"
00590 EXPORT_TEMPLATE_CLASS_ALL_DIMS(MeshBasedCellPopulation)
00591
00592 namespace boost
00593 {
00594 namespace serialization
00595 {
00599 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00600 inline void save_construct_data(
00601 Archive & ar, const MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> * t, const BOOST_PFTO unsigned int file_version)
00602 {
00603
00604 const MutableMesh<ELEMENT_DIM, SPACE_DIM>* p_mesh = &(t->rGetMesh());
00605 ar & p_mesh;
00606 }
00607
00612 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00613 inline void load_construct_data(
00614 Archive & ar, MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> * t, const unsigned int file_version)
00615 {
00616
00617 MutableMesh<ELEMENT_DIM, SPACE_DIM>* p_mesh;
00618 ar >> p_mesh;
00619
00620
00621 ::new(t)MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>(*p_mesh);
00622 }
00623 }
00624 }
00625
00626 #endif