MeshBasedTissue.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 #ifndef MESHBASEDTISSUE_HPP_
00029 #define MESHBASEDTISSUE_HPP_
00030
00031 #include "AbstractCellCentreBasedTissue.hpp"
00032 #include "MutableMesh.hpp"
00033 #include "VoronoiTessellation.hpp"
00034 #include "Exception.hpp"
00035 #include "ArchiveLocationInfo.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 MeshBasedTissue : public AbstractCellCentreBasedTissue<DIM>
00053 {
00054 friend class TestMeshBasedTissue;
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<AbstractCellCentreBasedTissue<DIM> >(*this);
00073
00074
00075
00076 delete mpVoronoiTessellation;
00077 mpVoronoiTessellation = NULL;
00078
00079 archive & mMarkedSprings;
00080 archive & mUseAreaBasedDampingConstant;
00081
00082
00083
00084
00085
00086
00087 this->Validate();
00088 }
00089
00090 protected:
00091 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00092
00093 MutableMesh<DIM, DIM>& mrMesh;
00094
00099 VoronoiTessellation<DIM>* mpVoronoiTessellation;
00100
00105 bool mDeleteMesh;
00106
00112 std::set<std::set<TissueCell*> > mMarkedSprings;
00113
00115 out_stream mpElementFile;
00116
00118 out_stream mpVoronoiFile;
00119
00121 out_stream mpTissueAreasFile;
00122
00124 out_stream mpCellAreasFile;
00125
00127 bool mUseAreaBasedDampingConstant;
00128 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00129
00135 virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
00136
00141 virtual void Validate();
00142
00143 public:
00144 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00145
00157 MeshBasedTissue(MutableMesh<DIM, DIM>& rMesh,
00158 std::vector<TissueCell>& rCells,
00159 const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00160 bool deleteMesh=false,
00161 bool validate=true);
00162
00168 MeshBasedTissue(MutableMesh<DIM, DIM>& rMesh);
00169
00173 ~MeshBasedTissue();
00174
00178 MutableMesh<DIM, DIM>& rGetMesh();
00179
00183 const MutableMesh<DIM, DIM>& rGetMesh() const;
00184
00186 bool UseAreaBasedDampingConstant();
00187
00193 void SetOutputVoronoiData(bool writeVoronoiData);
00194
00203 unsigned AddNode(Node<DIM>* pNewNode);
00204
00213 void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00214
00222 double GetDampingConstant(unsigned nodeIndex);
00223
00230 void SetOutputTissueAreas(bool writeTissueAreas);
00231
00237 void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
00238
00251 virtual unsigned RemoveDeadCells();
00252
00264 virtual TissueCell* AddCell(TissueCell& rNewCell, const c_vector<double,DIM>& rCellDivisionVector, TissueCell* pParentCell=NULL);
00265
00272 void CreateOutputFiles(const std::string& rDirectory, bool cleanOutputDirectory);
00273
00277 void CloseOutputFiles();
00278
00282 void WriteResultsToFiles();
00283
00291 virtual void Update(bool hasHadBirthsOrDeaths=true);
00292
00300 Node<DIM>* GetNode(unsigned index);
00301
00307 unsigned GetNumNodes();
00308
00312 void WriteVoronoiResultsToFile();
00313
00321 void WriteTissueAreaResultsToFile();
00322
00332 void WriteCellAreaResultsToFile();
00333
00339 void CreateVoronoiTessellation(const std::vector<unsigned> locationIndices=std::vector<unsigned>());
00340
00344 VoronoiTessellation<DIM>& rGetVoronoiTessellation();
00345
00351 class SpringIterator
00352 {
00353 public:
00354
00358 Node<DIM>* GetNodeA();
00359
00363 Node<DIM>* GetNodeB();
00364
00368 TissueCell& rGetCellA();
00369
00373 TissueCell& rGetCellB();
00374
00380 bool operator!=(const MeshBasedTissue<DIM>::SpringIterator& rOther);
00381
00385 SpringIterator& operator++();
00386
00393 SpringIterator(MeshBasedTissue<DIM>& rTissue, typename MutableMesh<DIM,DIM>::EdgeIterator edgeIter);
00394
00395 private:
00396
00398 std::set<std::set<unsigned> > mSpringsVisited;
00399
00401 MeshBasedTissue<DIM>& mrTissue;
00402
00404 typename MutableMesh<DIM, DIM>::EdgeIterator mEdgeIter;
00405 };
00406
00410 SpringIterator SpringsBegin();
00411
00415 SpringIterator SpringsEnd();
00416
00420 void CheckTissueCellPointers();
00421
00429 std::set<TissueCell*> CreateCellPair(TissueCell& rCell1, TissueCell& rCell2);
00430
00436 bool IsMarkedSpring(const std::set<TissueCell*>& rCellPair);
00437
00443 void MarkSpring(std::set<TissueCell*>& rCellPair);
00444
00450 void UnmarkSpring(std::set<TissueCell*>& rCellPair);
00451
00452 };
00453 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00454
00455
00456 #include "SerializationExportWrapper.hpp"
00457 EXPORT_TEMPLATE_CLASS_SAME_DIMS(MeshBasedTissue)
00458
00459 namespace boost
00460 {
00461 namespace serialization
00462 {
00466 template<class Archive, unsigned DIM>
00467 inline void save_construct_data(
00468 Archive & ar, const MeshBasedTissue<DIM> * t, const BOOST_PFTO unsigned int file_version)
00469 {
00470
00471 const MutableMesh<DIM,DIM>* p_mesh = &(t->rGetMesh());
00472 ar & p_mesh;
00473 }
00474
00479 template<class Archive, unsigned DIM>
00480 inline void load_construct_data(
00481 Archive & ar, MeshBasedTissue<DIM> * t, const unsigned int file_version)
00482 {
00483
00484 MutableMesh<DIM,DIM>* p_mesh;
00485 ar >> p_mesh;
00486
00487
00488 ::new(t)MeshBasedTissue<DIM>(*p_mesh);
00489 }
00490 }
00491 }
00492
00493 #endif