NodeBasedCellPopulation.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 
00144     void WriteVtkResultsToFile();
00145 
00146 public:
00147 
00158     NodeBasedCellPopulation(const std::vector<Node<DIM>* > nodes,
00159                     std::vector<CellPtr>& rCells,
00160                     const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00161                     bool deleteNodes=true);
00162 
00173     NodeBasedCellPopulation(const std::vector<Node<DIM>* > nodes, double mechanicsCutOffLength, bool deleteNodes=true);
00174 
00185     NodeBasedCellPopulation(const AbstractMesh<DIM,DIM>& rMesh,
00186                     std::vector<CellPtr>& rCells);
00187 
00193     ~NodeBasedCellPopulation();
00194 
00198     unsigned GetNumNodes();
00199 
00207     Node<DIM>* GetNode(unsigned index);
00208 
00218     unsigned RemoveDeadCells();
00219 
00224     void Clear();
00225 
00231     void Update(bool hasHadBirthsOrDeaths=true);
00232 
00238     std::vector<Node<DIM>* >& rGetNodes();
00239 
00245     const std::vector<Node<DIM>* >& rGetNodes() const;
00246 
00250     BoxCollection<DIM>* GetBoxCollection();
00251 
00255     std::set< std::pair<Node<DIM>*, Node<DIM>* > >& rGetNodePairs();
00256 
00265     void OutputCellPopulationParameters(out_stream& rParamsFile);
00266 
00270     double GetMechanicsCutOffLength();
00271 
00277     void SetMechanicsCutOffLength(double mechanicsCutOffLength);
00278 
00288     double GetWidth(const unsigned& rDimension);
00289 
00299     void SetOutputCellVolumes(bool outputCellVolumes);
00300 };
00301 
00302 #include "SerializationExportWrapper.hpp"
00303 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodeBasedCellPopulation)
00304 
00305 namespace boost {
00306 namespace serialization {
00307 
00311 template<class Archive, unsigned SPACE_DIM>
00312 inline void save(
00313     Archive & ar,
00314     const Node<SPACE_DIM>& rNode,
00315     const unsigned int /* file_version */)
00316 {
00317     // Save deleted flag
00318     const bool is_deleted = rNode.IsDeleted();
00319     ar << is_deleted;
00320 }
00321 
00325 template<class Archive, unsigned SPACE_DIM>
00326 inline void load(
00327     Archive & ar,
00328     Node<SPACE_DIM>& rNode,
00329     const unsigned int /* file_version */)
00330 {
00331     // Load deleted flag
00332     bool is_deleted;
00333     ar >> is_deleted;
00334     #define COVERAGE_IGNORE
00335     if (is_deleted)
00336     {
00337         rNode.MarkAsDeleted();
00338     }
00339     #undef COVERAGE_IGNORE
00340 }
00341 
00346 template<class Archive, unsigned SPACE_DIM>
00347 inline void serialize(
00348     Archive & ar,
00349     Node<SPACE_DIM>& rNode,
00350     const unsigned int file_version)
00351 {
00352     boost::serialization::split_free(ar, rNode, file_version);
00353 }
00354 
00358 template<class Archive, unsigned DIM>
00359 inline void save_construct_data(
00360     Archive & ar, const Node<DIM> * t, const BOOST_PFTO unsigned int file_version)
00361 {
00362     // Save the global index of the node
00363     const unsigned index = t->GetIndex();
00364     ar << index;
00365 
00366     // Save whether the node is a boundary node
00367     const bool is_boundary = t->IsBoundaryNode();
00368     ar << is_boundary;
00369 
00370     // Save the location of the node
00371     const c_vector<double, DIM>& r_loc = t->rGetLocation();
00372     for (unsigned i=0; i<DIM; i++)
00373     {
00374         ar << r_loc[i];
00375     }
00376 }
00377 
00381 template<class Archive, unsigned DIM>
00382 inline void load_construct_data(
00383     Archive & ar, Node<DIM> * t, const unsigned int file_version)
00384 {
00385     // Load the global index of the node
00386     unsigned index;
00387     ar >> index;
00388 
00389     // Load whether the node is a boundary node
00390     bool is_boundary;
00391     ar >> is_boundary;
00392 
00393     // Load the location of the node
00394     c_vector<double, DIM> loc;
00395     for (unsigned i=0; i<DIM; i++)
00396     {
00397         ar >> loc[i];
00398     }
00399 
00400     // Invoke inplace constructor to initialise instance
00401     ::new(t)Node<DIM>(index, loc, is_boundary);
00402 }
00403 
00407 template<class Archive, unsigned DIM>
00408 inline void save_construct_data(
00409     Archive & ar, const NodeBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00410 {
00411     ar & t->rGetNodes();
00412 //    const double cut_off_length = t->GetMechanicsCutOffLength();
00413 //    ar << cut_off_length;
00414 
00415 }
00416 
00420 template<class Archive, unsigned DIM>
00421 inline void load_construct_data(
00422     Archive & ar, NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
00423 {
00424     // Load the nodes
00425     std::vector<Node<DIM>* > nodes;
00426     ar >> nodes;
00427 
00428     // load the cut of distance
00429     double cut_off_length = 1.0; //\todo this is temporary till we fix archiving
00430 //    ar >> cut_off_length;
00431 
00432     // Invoke inplace constructor to initialize instance
00433     ::new(t)NodeBasedCellPopulation<DIM>(nodes, cut_off_length);
00434 }
00435 
00436 }} // close namespaces
00437 
00438 #endif /*NODEBASEDCELLPOPULATION_HPP_*/

Generated on Mon Apr 18 11:35:27 2011 for Chaste by  doxygen 1.5.5