NodeBasedTissue.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 NODEBASEDTISSUE_HPP_
00029 #define NODEBASEDTISSUE_HPP_
00030 
00031 #include "AbstractCellCentreBasedTissue.hpp"
00032 #include "AbstractTetrahedralMesh.hpp" // for constructor which takes in a mesh
00033 #include "BoxCollection.hpp"
00034 
00035 #include "ChasteSerialization.hpp"
00036 #include <boost/serialization/base_object.hpp>
00037 #include <boost/serialization/set.hpp>
00038 #include <boost/serialization/vector.hpp>
00039 
00044 template<unsigned DIM>
00045 class NodeBasedTissue : public AbstractCellCentreBasedTissue<DIM>
00046 {
00047     friend class TestNodeBasedTissue;
00048     friend class TestBoxCollection;
00049 
00050 protected:
00051 
00053     std::vector<Node<DIM>* > mNodes;
00054 
00056     std::vector<unsigned> mDeletedNodeIndices;
00057 
00059     bool mAddedNodes;
00060 
00061 private:
00062 
00064     BoxCollection<DIM>* mpBoxCollection;
00065 
00067     c_vector<double, DIM> mMinSpatialPositions;
00068 
00070     c_vector<double, DIM> mMaxSpatialPositions;
00071 
00073     std::set< std::pair<Node<DIM>*, Node<DIM>* > > mNodePairs;
00074 
00078     bool mDeleteNodes;
00079 
00081     friend class boost::serialization::access;
00091     template<class Archive>
00092     void serialize(Archive & archive, const unsigned int version)
00093     {
00094         archive & boost::serialization::base_object<AbstractCellCentreBasedTissue<DIM> >(*this);
00095 
00096         Validate(); // paranoia
00097     }
00098 
00107     unsigned AddNode(Node<DIM>* pNewNode);
00108 
00115     void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00116 
00120     void Validate();
00121 
00128     void SplitUpIntoBoxes(double cutOffLength, c_vector<double, 2*DIM> domainSize);
00129 
00133     void FindMaxAndMin();
00134 
00135 public:
00136 
00147     NodeBasedTissue(const std::vector<Node<DIM>* > nodes,
00148                     std::vector<TissueCell>& rCells,
00149                     const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00150                     bool deleteNodes=true);
00151 
00161     NodeBasedTissue(const std::vector<Node<DIM>* > nodes, bool deleteNodes=true);
00162 
00173     NodeBasedTissue(const AbstractMesh<DIM,DIM>& rMesh,
00174                     std::vector<TissueCell>& rCells);
00175 
00181     ~NodeBasedTissue();
00182 
00186     unsigned GetNumNodes();
00187 
00195     Node<DIM>* GetNode(unsigned index);
00196 
00206     unsigned RemoveDeadCells();
00207 
00212     void Clear();
00213 
00219     void Update(bool hasHadBirthsOrDeaths=true);
00220 
00226     std::vector<Node<DIM>* >& rGetNodes();
00227 
00233     const std::vector<Node<DIM>* >& rGetNodes() const;
00234 
00238     BoxCollection<DIM>* GetBoxCollection();
00239 
00243     std::set< std::pair<Node<DIM>*, Node<DIM>* > >& rGetNodePairs();
00244 };
00245 
00246 
00247 #include "SerializationExportWrapper.hpp"
00248 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodeBasedTissue)
00249 
00250 namespace boost {
00251 namespace serialization {
00252 
00256 template<class Archive, unsigned SPACE_DIM>
00257 inline void save(
00258     Archive & ar,
00259     const Node<SPACE_DIM>& rNode,
00260     const unsigned int /* file_version */)
00261 {
00262     // Save deleted flag
00263     const bool is_deleted = rNode.IsDeleted();
00264     ar << is_deleted;
00265 }
00266 
00270 template<class Archive, unsigned SPACE_DIM>
00271 inline void load(
00272     Archive & ar,
00273     Node<SPACE_DIM>& rNode,
00274     const unsigned int /* file_version */)
00275 {
00276     // Load deleted flag
00277     bool is_deleted;
00278     ar >> is_deleted;
00279     #define COVERAGE_IGNORE
00280     if (is_deleted)
00281     {
00282         rNode.MarkAsDeleted();
00283     }
00284     #undef COVERAGE_IGNORE
00285 }
00286 
00287 
00292 template<class Archive, unsigned SPACE_DIM>
00293 inline void serialize(
00294     Archive & ar,
00295     Node<SPACE_DIM>& rNode,
00296     const unsigned int file_version)
00297 {
00298     boost::serialization::split_free(ar, rNode, file_version);
00299 }
00300 
00301 
00305 template<class Archive, unsigned DIM>
00306 inline void save_construct_data(
00307     Archive & ar, const Node<DIM> * t, const BOOST_PFTO unsigned int file_version)
00308 {
00309     // Save the global index of the node
00310     const unsigned index = t->GetIndex();
00311     ar << index;
00312 
00313     // Save whether the node is a boundary node
00314     const bool is_boundary = t->IsBoundaryNode();
00315     ar << is_boundary;
00316 
00317     // Save the location of the node
00318     const c_vector<double, DIM>& r_loc = t->rGetLocation();
00319     for (unsigned i=0; i<DIM; i++)
00320     {
00321         ar << r_loc[i];
00322     }
00323 }
00324 
00328 template<class Archive, unsigned DIM>
00329 inline void load_construct_data(
00330     Archive & ar, Node<DIM> * t, const unsigned int file_version)
00331 {
00332     // Load the global index of the node
00333     unsigned index;
00334     ar >> index;
00335 
00336     // Load whether the node is a boundary node
00337     bool is_boundary;
00338     ar >> is_boundary;
00339 
00340     // Load the location of the node
00341     c_vector<double, DIM> loc;
00342     for (unsigned i=0; i<DIM; i++)
00343     {
00344         ar >> loc[i];
00345     }
00346 
00347     // Invoke inplace constructor to initialise instance
00348     ::new(t)Node<DIM>(index, loc, is_boundary);
00349 }
00350 
00351 
00355 template<class Archive, unsigned DIM>
00356 inline void save_construct_data(
00357     Archive & ar, const NodeBasedTissue<DIM> * t, const BOOST_PFTO unsigned int file_version)
00358 {
00359     ar & t->rGetNodes();
00360 }
00361 
00365 template<class Archive, unsigned DIM>
00366 inline void load_construct_data(
00367     Archive & ar, NodeBasedTissue<DIM> * t, const unsigned int file_version)
00368 {
00369     // Load the nodes
00370     std::vector<Node<DIM>* > nodes;
00371     ar >> nodes;
00372 
00373     // Invoke inplace constructor to initialize instance
00374     ::new(t)NodeBasedTissue<DIM>(nodes);
00375 }
00376 
00377 }} // close namespaces
00378 
00379 
00380 #endif /*NODEBASEDTISSUE_HPP_*/

Generated by  doxygen 1.6.2