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(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
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
00609 MutableMesh<ELEMENT_DIM, SPACE_DIM>* p_mesh;
00610 ar >> p_mesh;
00611
00612
00613 ::new(t)MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>(*p_mesh);
00614 }
00615 }
00616 }
00617
00618 #endif