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
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 )
00316 {
00317
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 )
00330 {
00331
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
00363 const unsigned index = t->GetIndex();
00364 ar << index;
00365
00366
00367 const bool is_boundary = t->IsBoundaryNode();
00368 ar << is_boundary;
00369
00370
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
00386 unsigned index;
00387 ar >> index;
00388
00389
00390 bool is_boundary;
00391 ar >> is_boundary;
00392
00393
00394 c_vector<double, DIM> loc;
00395 for (unsigned i=0; i<DIM; i++)
00396 {
00397 ar >> loc[i];
00398 }
00399
00400
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
00413
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
00425 std::vector<Node<DIM>* > nodes;
00426 ar >> nodes;
00427
00428
00429 double cut_off_length = 1.0;
00430
00431
00432
00433 ::new(t)NodeBasedCellPopulation<DIM>(nodes, cut_off_length);
00434 }
00435
00436 }}
00437
00438 #endif