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 #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
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
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
00588 MutableMesh<DIM,DIM>* p_mesh;
00589 ar >> p_mesh;
00590
00591
00592 ::new(t)MeshBasedCellPopulation<DIM>(*p_mesh);
00593 }
00594 }
00595 }
00596
00597 #endif