NodeBasedCellPopulation.hpp
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
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef NODEBASEDCELLPOPULATION_HPP_
00037 #define NODEBASEDCELLPOPULATION_HPP_
00038
00039 #include "ChasteSerialization.hpp"
00040 #include <boost/serialization/base_object.hpp>
00041
00042 #include <boost/version.hpp>
00043 #if BOOST_VERSION >= 103700
00044 #include "ObjectCommunicator.hpp"
00045 #endif
00046
00047 #include "AbstractCentreBasedCellPopulation.hpp"
00048 #include "NodesOnlyMesh.hpp"
00049 #include "BoxCollection.hpp"
00050
00055 template<unsigned DIM>
00056 class NodeBasedCellPopulation : public AbstractCentreBasedCellPopulation<DIM>
00057 {
00058 friend class TestNodeBasedCellPopulation;
00059 friend class TestNodeBasedCellPopulationParallelMethods;
00060 friend class TestBoxCollection;
00061
00062 protected:
00063
00065 NodesOnlyMesh<DIM>* mpNodesOnlyMesh;
00066
00067 private:
00068
00070 c_vector<double, DIM> mMinSpatialPositions;
00071
00073 c_vector<double, DIM> mMaxSpatialPositions;
00074
00076 std::vector< std::pair<Node<DIM>*, Node<DIM>* > > mNodePairs;
00077
00079 std::map<unsigned, std::set<unsigned> > mNodeNeighbours;
00080
00082 bool mDeleteMesh;
00083
00085 bool mUseVariableRadii;
00086
00088 std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendRight;
00089
00091 std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendLeft;
00092
00094 boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvRight;
00095
00097 boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvLeft;
00098
00100 ObjectCommunicator<std::vector<std::pair<CellPtr, Node<DIM>* > > > mRightCommunicator;
00101
00103 ObjectCommunicator<std::vector<std::pair<CellPtr, Node<DIM>* > > > mLeftCommunicator;
00104
00106 static const unsigned mCellCommunicationTag = 123;
00107
00109 std::vector<CellPtr> mHaloCells;
00110
00112 std::map<unsigned, CellPtr> mLocationHaloCellMap;
00113
00115 std::map<CellPtr, unsigned> mHaloCellLocationMap;
00116
00118 bool mLoadBalanceMesh;
00119
00121 unsigned mLoadBalanceFrequency;
00122
00124 friend class boost::serialization::access;
00134 template<class Archive>
00135 void serialize(Archive & archive, const unsigned int version)
00136 {
00137 archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<DIM> >(*this);
00138 archive & mUseVariableRadii;
00139
00140 this->Validate();
00141 }
00142
00151 unsigned AddNode(Node<DIM>* pNewNode);
00152
00158 void AddMovedCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
00159
00164 void DeleteMovedCell(unsigned index);
00165
00169 void RefreshHaloCells();
00170
00177 void AddNodeAndCellToSendRight(unsigned nodeIndex);
00178
00185 void AddNodeAndCellToSendLeft(unsigned nodeIndex);
00186
00191 void AddCellsToSendRight(std::vector<unsigned>& cellLocationIndices);
00192
00197 void AddCellsToSendLeft(std::vector<unsigned>& cellLocationIndices);
00198
00202 void AddReceivedHaloCells();
00203
00209 void AddHaloCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
00210
00216 void UpdateMapsAfterRemesh(NodeMap& map);
00217
00218 protected:
00219
00220 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
00221
00226 virtual void UpdateParticlesAfterReMesh(NodeMap& rMap);
00227
00231 virtual void Validate();
00232
00233 private:
00234
00240 virtual void WriteVtkResultsToFile(const std::string& rDirectory);
00241
00242 public:
00243
00250 void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00251
00263 NodeBasedCellPopulation(NodesOnlyMesh<DIM>& rMesh,
00264 std::vector<CellPtr>& rCells,
00265 const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00266 bool deleteMesh=false,
00267 bool validate=true);
00268
00274 NodeBasedCellPopulation(NodesOnlyMesh<DIM>& rMesh);
00275
00281 virtual ~NodeBasedCellPopulation();
00282
00286 NodesOnlyMesh<DIM>& rGetMesh();
00287
00291 const NodesOnlyMesh<DIM>& rGetMesh() const;
00292
00296 unsigned GetNumNodes();
00297
00305 virtual CellPtr GetCellUsingLocationIndex(unsigned index);
00306
00314 Node<DIM>* GetNode(unsigned index);
00315
00325 unsigned RemoveDeadCells();
00326
00330 void Clear();
00331
00337 void Update(bool hasHadBirthsOrDeaths=true);
00338
00344 std::vector< std::pair<Node<DIM>*, Node<DIM>* > >& rGetNodePairs();
00345
00354 void OutputCellPopulationParameters(out_stream& rParamsFile);
00355
00362 virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<DIM, DIM> > pPopulationWriter);
00363
00371 virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<DIM, DIM> > pCellWriter, CellPtr pCell);
00372
00376 double GetMechanicsCutOffLength();
00377
00381 bool GetUseVariableRadii();
00382
00388 void SetUseVariableRadii(bool useVariableRadii=true);
00389
00394 void SetLoadBalanceMesh(bool loadBalanceMesh);
00395
00400 void SetLoadBalanceFrequency(unsigned loadBalanceFrequency);
00401
00411 double GetWidth(const unsigned& rDimension);
00412
00418 c_vector<double, DIM> GetSizeOfCellPopulation();
00419
00428 std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
00429
00442 virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell);
00443
00450 double GetVolumeOfCell(CellPtr pCell);
00451
00453
00455
00461 void SendCellsToNeighbourProcesses();
00462
00469 void NonBlockingSendCellsToNeighbourProcesses();
00470
00475 void GetReceivedCells();
00476
00483 std::pair<CellPtr, Node<DIM>* > GetCellNodePair(unsigned nodeIndex);
00484
00488 void AddReceivedCells();
00489
00493 virtual void UpdateCellProcessLocation();
00494 };
00495
00496 #include "SerializationExportWrapper.hpp"
00497 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodeBasedCellPopulation)
00498
00499 namespace boost
00500 {
00501 namespace serialization
00502 {
00506 template<class Archive, unsigned DIM>
00507 inline void save_construct_data(
00508 Archive & ar, const NodeBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00509 {
00510
00511 const NodesOnlyMesh<DIM>* p_mesh = &(t->rGetMesh());
00512 ar & p_mesh;
00513 }
00514
00519 template<class Archive, unsigned DIM>
00520 inline void load_construct_data(
00521 Archive & ar, NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
00522 {
00523
00524 NodesOnlyMesh<DIM>* p_mesh;
00525 ar >> p_mesh;
00526
00527
00528 ::new(t)NodeBasedCellPopulation<DIM>(*p_mesh);
00529 }
00530 }
00531 }
00532
00533 #endif