NodeBasedTissue.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 NODEBASEDTISSUE_HPP_
00029 #define NODEBASEDTISSUE_HPP_
00030 
00031 #include "AbstractCellCentreBasedTissue.hpp"
00032 #include "AbstractTetrahedralMesh.hpp" // for constructor which takes in a mesh
00033 #include "NodeBoxCollection.hpp"
00034 
00035 #include <boost/serialization/access.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 TestNodeBoxCollection;
00049 private:
00050 
00052     std::vector<Node<DIM>* > mNodes;
00053 
00055     std::vector<unsigned> mDeletedNodeIndices;
00056 
00058     bool mAddedNodes;
00059 
00061     NodeBoxCollection<DIM> *mpNodeBoxCollection;
00062 
00064     c_vector<double, DIM> mMinSpatialPositions;
00065 
00067     c_vector<double, DIM> mMaxSpatialPositions;
00068 
00070     std::set< std::pair<Node<DIM>*, Node<DIM>* > > mNodePairs;
00071 
00075     bool mDeleteNodes;
00076 
00078     friend class boost::serialization::access;
00088     template<class Archive>
00089     void serialize(Archive & archive, const unsigned int version)
00090     {
00091         archive & boost::serialization::base_object<AbstractCellCentreBasedTissue<DIM> >(*this);
00092 
00093         Validate(); // paranoia
00094     }
00095 
00104     unsigned AddNode(Node<DIM>* pNewNode);
00105 
00112     void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00113 
00117     void Validate();
00118 
00125     void SplitUpIntoBoxes(double cutOffLength, c_vector<double, 2*DIM> domainSize);
00126 
00130     void FindMaxAndMin();
00131 
00132 public:
00133 
00144     NodeBasedTissue(const std::vector<Node<DIM>* > nodes,
00145                     const std::vector<TissueCell>& rCells,
00146                     const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00147                     bool deleteNodes=true);
00148 
00158     NodeBasedTissue(const std::vector<Node<DIM>* > nodes, bool deleteNodes=true);
00159 
00170     NodeBasedTissue(const AbstractMesh<DIM,DIM>& rMesh,
00171                     const std::vector<TissueCell>& rCells);
00172 
00178     ~NodeBasedTissue();
00179 
00183     unsigned GetNumNodes();
00184 
00192     Node<DIM>* GetNode(unsigned index);
00193 
00203     unsigned RemoveDeadCells();
00204 
00209     void Clear();
00210 
00216     void Update(bool hasHadBirthsOrDeaths=true);
00217 
00223     std::vector<Node<DIM>* >& rGetNodes();
00224 
00230     const std::vector<Node<DIM>* >& rGetNodes() const;
00231 
00235     NodeBoxCollection<DIM>* GetNodeBoxCollection();
00236 
00240     std::set< std::pair<Node<DIM>*, Node<DIM>* > >& rGetNodePairs();
00241 };
00242 
00243 
00244 #include "TemplatedExport.hpp"
00245 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodeBasedTissue)
00246 
00247 namespace boost {
00248 namespace serialization {
00249 
00253 template<class Archive, unsigned SPACE_DIM>
00254 inline void save(
00255     Archive & ar,
00256     const Node<SPACE_DIM>& rNode,
00257     const unsigned int /* file_version */)
00258 {
00259     // Save deleted flag
00260     const bool is_deleted = rNode.IsDeleted();
00261     ar << is_deleted;
00262 }
00263 
00267 template<class Archive, unsigned SPACE_DIM>
00268 inline void load(
00269     Archive & ar,
00270     Node<SPACE_DIM>& rNode,
00271     const unsigned int /* file_version */)
00272 {
00273     // Load deleted flag
00274     bool is_deleted;
00275     ar >> is_deleted;
00276     #define COVERAGE_IGNORE
00277     if (is_deleted)
00278     {
00279         rNode.MarkAsDeleted();
00280     }
00281     #undef COVERAGE_IGNORE
00282 }
00283 
00284 
00289 template<class Archive, unsigned SPACE_DIM>
00290 inline void serialize(
00291     Archive & ar,
00292     Node<SPACE_DIM>& rNode,
00293     const unsigned int file_version)
00294 {
00295     boost::serialization::split_free(ar, rNode, file_version);
00296 }
00297 
00298 
00302 template<class Archive, unsigned DIM>
00303 inline void save_construct_data(
00304     Archive & ar, const Node<DIM> * t, const BOOST_PFTO unsigned int file_version)
00305 {
00306     // Save the global index of the node
00307     const unsigned index = t->GetIndex();
00308     ar << index;
00309 
00310     // Save whether the node is a boundary node
00311     const bool is_boundary = t->IsBoundaryNode();
00312     ar << is_boundary;
00313 
00314     // Save the location of the node
00315     const c_vector<double, DIM>& r_loc = t->rGetLocation();
00316     for (unsigned i=0; i<DIM; i++)
00317     {
00318         ar << r_loc[i];
00319     }
00320 }
00321 
00325 template<class Archive, unsigned DIM>
00326 inline void load_construct_data(
00327     Archive & ar, Node<DIM> * t, const unsigned int file_version)
00328 {
00329     // Load the global index of the node
00330     unsigned index;
00331     ar >> index;
00332 
00333     // Load whether the node is a boundary node
00334     bool is_boundary;
00335     ar >> is_boundary;
00336 
00337     // Load the location of the node
00338     c_vector<double, DIM> loc;
00339     for (unsigned i=0; i<DIM; i++)
00340     {
00341         ar >> loc[i];
00342     }
00343 
00344     // Invoke inplace constructor to initialise instance
00345     ::new(t)Node<DIM>(index, loc, is_boundary);
00346 }
00347 
00348 
00352 template<class Archive, unsigned DIM>
00353 inline void save_construct_data(
00354     Archive & ar, const NodeBasedTissue<DIM> * t, const BOOST_PFTO unsigned int file_version)
00355 {
00356     ar & t->rGetNodes();
00357 }
00358 
00362 template<class Archive, unsigned DIM>
00363 inline void load_construct_data(
00364     Archive & ar, NodeBasedTissue<DIM> * t, const unsigned int file_version)
00365 {
00366     // Load the nodes
00367     std::vector<Node<DIM>* > nodes;
00368     ar >> nodes;
00369 
00370     // Invoke inplace constructor to initialize instance
00371     ::new(t)NodeBasedTissue<DIM>(nodes);
00372 }
00373 
00374 }} // close namespaces
00375 
00376 
00377 #endif /*NODEBASEDTISSUE_HPP_*/

Generated on Tue Aug 4 16:10:21 2009 for Chaste by  doxygen 1.5.5