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 "AbstractMesh.hpp" // for constructor which takes in a mesh
00033 
00034 #include <boost/serialization/access.hpp>
00035 #include <boost/serialization/base_object.hpp>
00036 #include <boost/serialization/set.hpp>
00037 #include <boost/serialization/vector.hpp>
00038 
00043 template<unsigned DIM>
00044 class NodeBasedTissue : public AbstractCellCentreBasedTissue<DIM>
00045 {
00046     friend class TestNodeBasedTissue;
00047 private:
00048 
00050     std::vector<Node<DIM>* > mNodes;
00051 
00053     std::vector<unsigned> mDeletedNodeIndices;
00054 
00056     bool mAddedNodes;
00057 
00059     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         Validate(); // paranoia
00075     }
00076 
00085     unsigned AddNode(Node<DIM>* pNewNode);
00086 
00093     void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00094 
00098     void Validate();
00099 
00103     bool mDeleteNodes;
00104 
00105 public:
00106 
00117     NodeBasedTissue(const std::vector<Node<DIM>* > nodes,
00118                     const std::vector<TissueCell>& rCells,
00119                     const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00120                     bool deleteNodes=true);
00121 
00131     NodeBasedTissue(const std::vector<Node<DIM>* > nodes, bool deleteNodes=true);
00132 
00144     NodeBasedTissue(const AbstractMesh<DIM,DIM>& rMesh,
00145                     const std::vector<TissueCell>& rCells);
00146 
00152     ~NodeBasedTissue();
00153 
00157     unsigned GetNumNodes();
00158 
00166     Node<DIM>* GetNode(unsigned index);
00167 
00177     unsigned RemoveDeadCells();
00178 
00182     void Clear();
00183 
00187     void Update();
00188 
00194     std::vector<Node<DIM>* >& rGetNodes();
00195 
00201     const std::vector<Node<DIM>* >& rGetNodes() const;
00202 
00203 };
00204 
00205 
00206 #include "TemplatedExport.hpp"
00207 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodeBasedTissue)
00208 
00209 namespace boost {
00210 namespace serialization {
00211 
00215 template<class Archive, unsigned SPACE_DIM>
00216 inline void save(
00217     Archive & ar,
00218     const Node<SPACE_DIM> &rNode,
00219     const unsigned int /* file_version */)
00220 {
00221     // Save deleted flag
00222     const bool is_deleted = rNode.IsDeleted();
00223     ar << is_deleted;
00224 }
00225 
00229 template<class Archive, unsigned SPACE_DIM>
00230 inline void load(
00231     Archive & ar,
00232     Node<SPACE_DIM> &rNode,
00233     const unsigned int /* file_version */)
00234 {
00235     // Load deleted flag
00236     bool is_deleted;
00237     ar >> is_deleted;
00238     #define COVERAGE_IGNORE
00239     if (is_deleted)
00240     {
00241         rNode.MarkAsDeleted();
00242     }
00243     #undef COVERAGE_IGNORE
00244 }
00245 
00246 
00251 template<class Archive, unsigned SPACE_DIM>
00252 inline void serialize(
00253     Archive & ar,
00254     Node<SPACE_DIM>& rNode,
00255     const unsigned int file_version)
00256 {
00257     boost::serialization::split_free(ar, rNode, file_version);
00258 }
00259 
00260 
00264 template<class Archive, unsigned DIM>
00265 inline void save_construct_data(
00266     Archive & ar, const Node<DIM> * t, const BOOST_PFTO unsigned int file_version)
00267 {
00268     // Save the global index of the node
00269     const unsigned index = t->GetIndex();
00270     ar << index;
00271 
00272     // Save whether the node is a boundary node
00273     const bool is_boundary = t->IsBoundaryNode();
00274     ar << is_boundary;
00275 
00276     // Save the location of the node
00277     const c_vector<double, DIM>& r_loc = t->rGetLocation();
00278     for (unsigned i=0; i<DIM; i++)
00279     {
00280         ar << r_loc[i];
00281     }
00282 }
00283 
00287 template<class Archive, unsigned DIM>
00288 inline void load_construct_data(
00289     Archive & ar, Node<DIM> * t, const unsigned int file_version)
00290 {
00291     // Load the global index of the node
00292     unsigned index;
00293     ar >> index;
00294 
00295     // Load whether the node is a boundary node
00296     bool is_boundary;
00297     ar >> is_boundary;
00298 
00299     // Load the location of the node
00300     c_vector<double, DIM> loc;
00301     for (unsigned i=0; i<DIM; i++)
00302     {
00303         ar >> loc[i];
00304     }
00305 
00306     // Invoke inplace constructor to initialise instance
00307     ::new(t)Node<DIM>(index, loc, is_boundary);
00308 }
00309 
00310 
00314 template<class Archive, unsigned DIM>
00315 inline void save_construct_data(
00316     Archive & ar, const NodeBasedTissue<DIM> * t, const BOOST_PFTO unsigned int file_version)
00317 {
00318     ar & t->rGetNodes();
00319 }
00320 
00324 template<class Archive, unsigned DIM>
00325 inline void load_construct_data(
00326     Archive & ar, NodeBasedTissue<DIM> * t, const unsigned int file_version)
00327 {
00328     // Load the nodes
00329     std::vector<Node<DIM>* > nodes;
00330     ar >> nodes;
00331 
00332     // Invoke inplace constructor to initialize instance
00333     ::new(t)NodeBasedTissue<DIM>(nodes);
00334 }
00335 
00336 }} // close namespaces
00337 
00338 
00339 #endif /*NODEBASEDTISSUE_HPP_*/

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