00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef NODEBASEDCELLPOPULATION_HPP_
00029 #define NODEBASEDCELLPOPULATION_HPP_
00030
00031 #include "AbstractCentreBasedCellPopulation.hpp"
00032 #include "AbstractTetrahedralMesh.hpp"
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();
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 )
00300 {
00301
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 )
00314 {
00315
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
00347 const unsigned index = t->GetIndex();
00348 ar << index;
00349
00350
00351 const bool is_boundary = t->IsBoundaryNode();
00352 ar << is_boundary;
00353
00354
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
00370 unsigned index;
00371 ar >> index;
00372
00373
00374 bool is_boundary;
00375 ar >> is_boundary;
00376
00377
00378 c_vector<double, DIM> loc;
00379 for (unsigned i=0; i<DIM; i++)
00380 {
00381 ar >> loc[i];
00382 }
00383
00384
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
00397
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
00409 std::vector<Node<DIM>* > nodes;
00410 ar >> nodes;
00411
00412
00413 double cut_off_length = 1.0;
00414
00415
00416
00417 ::new(t)NodeBasedCellPopulation<DIM>(nodes, cut_off_length);
00418 }
00419
00420 }}
00421
00422 #endif