MeshBasedTissue.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 "MeshArchiveInfo.hpp"
00036 
00037 #include <boost/serialization/access.hpp>
00038 #include <boost/serialization/base_object.hpp>
00039 #include <boost/serialization/set.hpp>
00040 #include <boost/serialization/vector.hpp>
00041 
00042 
00050 template<unsigned DIM>
00051 class MeshBasedTissue : public AbstractCellCentreBasedTissue<DIM>
00052 {
00053     friend class TestMeshBasedTissue;
00054 
00055 protected:
00056 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00057 
00058     MutableMesh<DIM, DIM>& mrMesh;
00059 
00064     VoronoiTessellation<DIM>* mpVoronoiTessellation;
00065 
00070     bool mDeleteMesh;
00071 
00077     std::set<std::set<TissueCell*> > mMarkedSprings;
00078 
00080     bool mWriteVoronoiData;
00081 
00083     bool mFollowLoggedCell;
00084 
00086     bool mWriteTissueAreas;
00087 
00089     out_stream mpElementFile;
00090 
00092     out_stream mpVoronoiFile;
00093 
00095     out_stream mpTissueAreasFile;
00096 
00098     std::set<TissueCell*> CreateCellPair(TissueCell&, TissueCell&);
00099 
00101     bool mUseAreaBasedDampingConstant;
00102 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00103 
00105     friend class boost::serialization::access;
00117     template<class Archive>
00118     void serialize(Archive & archive, const unsigned int version)
00119     {
00120         archive & boost::serialization::base_object<AbstractCellCentreBasedTissue<DIM> >(*this);
00121 
00122         // The Voronoi stuff can't be archived yet
00123         //archive & mpVoronoiTessellation
00124         delete mpVoronoiTessellation;
00125         mpVoronoiTessellation = NULL;
00126 
00127         archive & mMarkedSprings;
00128         archive & mWriteVoronoiData;
00129         archive & mFollowLoggedCell;
00130         archive & mWriteTissueAreas;
00131         archive & mUseAreaBasedDampingConstant;
00132 
00133         // In its present form, a call to MeshBasedTissue::Validate() here
00134         // would result in a seg fault in the situation where we are actually loading
00135         // a MeshBasedTissueWithGhostNodes. Commenting out this call breaks no tests.
00136 
00137         // Validate();
00138     }
00139 
00145     virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
00146 
00151     virtual void Validate();
00152 
00153 public:
00154 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00155 
00167     MeshBasedTissue(MutableMesh<DIM, DIM>& rMesh,
00168                     const std::vector<TissueCell>& rCells,
00169                     const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00170                     bool deleteMesh=false,
00171                     bool validate=true);
00172 
00178     MeshBasedTissue(MutableMesh<DIM, DIM>& rMesh);
00179 
00183     ~MeshBasedTissue();
00184 
00188     MutableMesh<DIM, DIM>& rGetMesh();
00189 
00193     const MutableMesh<DIM, DIM>& rGetMesh() const;
00194 
00196     bool GetWriteVoronoiData();
00197 
00199     bool GetWriteTissueAreas();
00200 
00202     bool UseAreaBasedDampingConstant();
00203 
00209     void SetWriteVoronoiData(bool writeVoronoiData, bool followLoggedCell);
00210 
00219     unsigned AddNode(Node<DIM> *pNewNode);
00220 
00229     void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00230 
00239     virtual bool IsGhostNode(unsigned index);
00240 
00248     double GetDampingConstant(unsigned nodeIndex);
00249 
00255     void SetWriteTissueAreas(bool writeTissueAreas);
00256 
00262     void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
00263 
00276     virtual unsigned RemoveDeadCells();
00277 
00289     virtual TissueCell* AddCell(TissueCell& rNewCell, c_vector<double,DIM> newLocation, TissueCell* pParentCell=NULL);
00290 
00298     void WriteMeshToFile(const std::string &rArchiveDirectory, const std::string &rMeshFileName);
00299 
00311     void CreateOutputFiles(const std::string &rDirectory,
00312                            bool rCleanOutputDirectory,
00313                            bool outputCellMutationStates,
00314                            bool outputCellTypes,
00315                            bool outputCellVariables,
00316                            bool outputCellCyclePhases,
00317                            bool outputCellAncestors);
00327     void CloseOutputFiles(bool outputCellMutationStates,
00328                           bool outputCellTypes,
00329                           bool outputCellVariables,
00330                           bool outputCellCyclePhases,
00331                           bool outputCellAncestors);
00332 
00342     void WriteResultsToFiles(bool outputCellMutationStates,
00343                              bool outputCellTypes,
00344                              bool outputCellVariables,
00345                              bool outputCellCyclePhases,
00346                              bool outputCellAncestors);
00347 
00352     virtual void Update();
00353 
00361     Node<DIM>* GetNode(unsigned index);
00362 
00368     unsigned GetNumNodes();
00369 
00374     void SetBottomCellAncestors();
00375 
00379     void WriteVoronoiResultsToFile();
00380 
00384     void WriteTissueAreaResultsToFile();
00385 
00389     void CreateVoronoiTessellation();
00390 
00394     VoronoiTessellation<DIM>& rGetVoronoiTessellation();
00395 
00401     class SpringIterator
00402     {
00403     public:
00404 
00408         Node<DIM>* GetNodeA();
00409 
00413         Node<DIM>* GetNodeB();
00414 
00418         TissueCell& rGetCellA();
00419 
00423         TissueCell& rGetCellB();
00424 
00430         bool operator!=(const SpringIterator& other);
00431 
00435         SpringIterator& operator++();
00436 
00443         SpringIterator(MeshBasedTissue& rTissue, typename MutableMesh<DIM,DIM>::EdgeIterator edgeIter);
00444 
00445     private:
00446 
00448         std::set<std::set<unsigned> > mSpringsVisited;
00449 
00451         MeshBasedTissue& mrTissue;
00452 
00454         typename MutableMesh<DIM, DIM>::EdgeIterator mEdgeIter;
00455     };
00456 
00460     SpringIterator SpringsBegin();
00461 
00465     SpringIterator SpringsEnd();
00466 
00470     void CheckTissueCellPointers();
00471 
00475     bool IsMarkedSpring(TissueCell&, TissueCell&);
00476 
00480     void MarkSpring(TissueCell&, TissueCell&);
00481 
00485     void UnmarkSpring(TissueCell&, TissueCell&);
00486 
00487 };
00488 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00489 
00490 
00491 #include "TemplatedExport.hpp"
00492 EXPORT_TEMPLATE_CLASS_SAME_DIMS(MeshBasedTissue)
00493 
00494 namespace boost
00495 {
00496 namespace serialization
00497 {
00501 template<class Archive, unsigned DIM>
00502 inline void save_construct_data(
00503     Archive & ar, const MeshBasedTissue<DIM> * t, const BOOST_PFTO unsigned int file_version)
00504 {
00505     // Save data required to construct instance
00506     const MutableMesh<DIM,DIM>* p_mesh = &(t->rGetMesh());
00507     ar & p_mesh;
00508 }
00509 
00514 template<class Archive, unsigned DIM>
00515 inline void load_construct_data(
00516     Archive & ar, MeshBasedTissue<DIM> * t, const unsigned int file_version)
00517 {
00518     // Retrieve data from archive required to construct new instance
00519     assert(MeshArchiveInfo::meshPathname.length() > 0);
00520     MutableMesh<DIM,DIM>* p_mesh;
00521     ar >> p_mesh;
00522 
00523     // Re-initialise the mesh
00524     p_mesh->Clear();
00525     TrianglesMeshReader<DIM,DIM> mesh_reader(MeshArchiveInfo::meshPathname);
00526     p_mesh->ConstructFromMeshReader(mesh_reader);
00527 
00528     // Needed for cylindrical meshes at present; should be safe in any case.
00529     NodeMap map(p_mesh->GetNumNodes());
00530     p_mesh->ReMesh(map);
00531 
00532     // Invoke inplace constructor to initialise instance
00533     ::new(t)MeshBasedTissue<DIM>(*p_mesh);
00534 }
00535 }
00536 } // namespace ...
00537 
00538 #endif /*MESHBASEDTISSUE_HPP_*/

Generated on Wed Mar 18 12:51:50 2009 for Chaste by  doxygen 1.5.5