MeshBasedTissue.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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         // The Voronoi stuff can't be archived yet
00075         //archive & mpVoronoiTessellation
00076         delete mpVoronoiTessellation;
00077         mpVoronoiTessellation = NULL;
00078 
00079         archive & mMarkedSprings;
00080         archive & mUseAreaBasedDampingConstant;
00081 
00082         // In its present form, a call to MeshBasedTissue::Validate() here
00083         // would result in a seg fault in the situation where we are actually loading
00084         // a MeshBasedTissueWithGhostNodes. Commenting out this call breaks no tests.
00085 
00086         //this->Update();
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     // Save data required to construct instance
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     // Retrieve data from archive required to construct new instance
00484     MutableMesh<DIM,DIM>* p_mesh;
00485     ar >> p_mesh;
00486 
00487     // Invoke inplace constructor to initialise instance
00488     ::new(t)MeshBasedTissue<DIM>(*p_mesh);
00489 }
00490 }
00491 } // namespace ...
00492 
00493 #endif /*MESHBASEDTISSUE_HPP_*/

Generated by  doxygen 1.6.2