NodeBasedCellPopulation.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 NODEBASEDCELLPOPULATION_HPP_
00029 #define NODEBASEDCELLPOPULATION_HPP_
00030 
00031 #include "AbstractCentreBasedCellPopulation.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 NodeBasedCellPopulation : public AbstractCentreBasedCellPopulation<DIM>
00046 {
00047     friend class TestNodeBasedCellPopulation;
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 
00084     double mMechanicsCutOffLength;
00085 
00087     friend class boost::serialization::access;
00097     template<class Archive>
00098     void serialize(Archive & archive, const unsigned int version)
00099     {
00100         archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<DIM> >(*this);
00101 
00102         Validate(); // paranoia
00103     }
00104 
00113     unsigned AddNode(Node<DIM>* pNewNode);
00114 
00121     void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00122 
00126     void Validate();
00127 
00134     void SplitUpIntoBoxes(double cutOffLength, c_vector<double, 2*DIM> domainSize);
00135 
00139     void FindMaxAndMin();
00140 
00141 public:
00142 
00153     NodeBasedCellPopulation(const std::vector<Node<DIM>* > nodes,
00154                     std::vector<CellPtr>& rCells,
00155                     const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00156                     bool deleteNodes=true);
00157 
00168     NodeBasedCellPopulation(const std::vector<Node<DIM>* > nodes, double mechanicsCutOffLength, bool deleteNodes=true);
00169 
00180     NodeBasedCellPopulation(const AbstractMesh<DIM,DIM>& rMesh,
00181                     std::vector<CellPtr>& rCells);
00182 
00188     ~NodeBasedCellPopulation();
00189 
00193     unsigned GetNumNodes();
00194 
00202     Node<DIM>* GetNode(unsigned index);
00203 
00213     unsigned RemoveDeadCells();
00214 
00219     void Clear();
00220 
00226     void Update(bool hasHadBirthsOrDeaths=true);
00227 
00233     std::vector<Node<DIM>* >& rGetNodes();
00234 
00240     const std::vector<Node<DIM>* >& rGetNodes() const;
00241 
00245     BoxCollection<DIM>* GetBoxCollection();
00246 
00250     std::set< std::pair<Node<DIM>*, Node<DIM>* > >& rGetNodePairs();
00251 
00260     void OutputCellPopulationParameters(out_stream& rParamsFile);
00261 
00265     double GetMechanicsCutOffLength();
00266 
00272     void SetMechanicsCutOffLength(double mechanicsCutOffLength);
00273 
00283     double GetWidth(const unsigned& rDimension);
00284 };
00285 
00286 #include "SerializationExportWrapper.hpp"
00287 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodeBasedCellPopulation)
00288 
00289 namespace boost {
00290 namespace serialization {
00291 
00295 template<class Archive, unsigned SPACE_DIM>
00296 inline void save(
00297     Archive & ar,
00298     const Node<SPACE_DIM>& rNode,
00299     const unsigned int /* file_version */)
00300 {
00301     // Save deleted flag
00302     const bool is_deleted = rNode.IsDeleted();
00303     ar << is_deleted;
00304 }
00305 
00309 template<class Archive, unsigned SPACE_DIM>
00310 inline void load(
00311     Archive & ar,
00312     Node<SPACE_DIM>& rNode,
00313     const unsigned int /* file_version */)
00314 {
00315     // Load deleted flag
00316     bool is_deleted;
00317     ar >> is_deleted;
00318     #define COVERAGE_IGNORE
00319     if (is_deleted)
00320     {
00321         rNode.MarkAsDeleted();
00322     }
00323     #undef COVERAGE_IGNORE
00324 }
00325 
00330 template<class Archive, unsigned SPACE_DIM>
00331 inline void serialize(
00332     Archive & ar,
00333     Node<SPACE_DIM>& rNode,
00334     const unsigned int file_version)
00335 {
00336     boost::serialization::split_free(ar, rNode, file_version);
00337 }
00338 
00342 template<class Archive, unsigned DIM>
00343 inline void save_construct_data(
00344     Archive & ar, const Node<DIM> * t, const BOOST_PFTO unsigned int file_version)
00345 {
00346     // Save the global index of the node
00347     const unsigned index = t->GetIndex();
00348     ar << index;
00349 
00350     // Save whether the node is a boundary node
00351     const bool is_boundary = t->IsBoundaryNode();
00352     ar << is_boundary;
00353 
00354     // Save the location of the node
00355     const c_vector<double, DIM>& r_loc = t->rGetLocation();
00356     for (unsigned i=0; i<DIM; i++)
00357     {
00358         ar << r_loc[i];
00359     }
00360 }
00361 
00365 template<class Archive, unsigned DIM>
00366 inline void load_construct_data(
00367     Archive & ar, Node<DIM> * t, const unsigned int file_version)
00368 {
00369     // Load the global index of the node
00370     unsigned index;
00371     ar >> index;
00372 
00373     // Load whether the node is a boundary node
00374     bool is_boundary;
00375     ar >> is_boundary;
00376 
00377     // Load the location of the node
00378     c_vector<double, DIM> loc;
00379     for (unsigned i=0; i<DIM; i++)
00380     {
00381         ar >> loc[i];
00382     }
00383 
00384     // Invoke inplace constructor to initialise instance
00385     ::new(t)Node<DIM>(index, loc, is_boundary);
00386 }
00387 
00391 template<class Archive, unsigned DIM>
00392 inline void save_construct_data(
00393     Archive & ar, const NodeBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00394 {
00395     ar & t->rGetNodes();
00396 //    const double cut_off_length = t->GetMechanicsCutOffLength();
00397 //    ar << cut_off_length;
00398 
00399 }
00400 
00404 template<class Archive, unsigned DIM>
00405 inline void load_construct_data(
00406     Archive & ar, NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
00407 {
00408     // Load the nodes
00409     std::vector<Node<DIM>* > nodes;
00410     ar >> nodes;
00411 
00412     // load the cut of distance
00413     double cut_off_length = 1.0; //\todo this is temporary till we fix archiving
00414 //    ar >> cut_off_length;
00415 
00416     // Invoke inplace constructor to initialize instance
00417     ::new(t)NodeBasedCellPopulation<DIM>(nodes, cut_off_length);
00418 }
00419 
00420 }} // close namespaces
00421 
00422 #endif /*NODEBASEDCELLPOPULATION_HPP_*/

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5