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
00370 virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<DIM, DIM> > pPopulationCountWriter);
00371
00379 virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<DIM, DIM> > pCellWriter, CellPtr pCell);
00380
00384 double GetMechanicsCutOffLength();
00385
00389 bool GetUseVariableRadii();
00390
00396 void SetUseVariableRadii(bool useVariableRadii=true);
00397
00402 void SetLoadBalanceMesh(bool loadBalanceMesh);
00403
00408 void SetLoadBalanceFrequency(unsigned loadBalanceFrequency);
00409
00419 double GetWidth(const unsigned& rDimension);
00420
00426 c_vector<double, DIM> GetSizeOfCellPopulation();
00427
00436 std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
00437
00450 virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell);
00451
00458 double GetVolumeOfCell(CellPtr pCell);
00459
00461
00463
00469 void SendCellsToNeighbourProcesses();
00470
00477 void NonBlockingSendCellsToNeighbourProcesses();
00478
00483 void GetReceivedCells();
00484
00491 std::pair<CellPtr, Node<DIM>* > GetCellNodePair(unsigned nodeIndex);
00492
00496 void AddReceivedCells();
00497
00501 virtual void UpdateCellProcessLocation();
00502 };
00503
00504 #include "SerializationExportWrapper.hpp"
00505 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodeBasedCellPopulation)
00506
00507 namespace boost
00508 {
00509 namespace serialization
00510 {
00514 template<class Archive, unsigned DIM>
00515 inline void save_construct_data(
00516 Archive & ar, const NodeBasedCellPopulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00517 {
00518
00519 const NodesOnlyMesh<DIM>* p_mesh = &(t->rGetMesh());
00520 ar & p_mesh;
00521 }
00522
00527 template<class Archive, unsigned DIM>
00528 inline void load_construct_data(
00529 Archive & ar, NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
00530 {
00531
00532 NodesOnlyMesh<DIM>* p_mesh;
00533 ar >> p_mesh;
00534
00535
00536 ::new(t)NodeBasedCellPopulation<DIM>(*p_mesh);
00537 }
00538 }
00539 }
00540
00541 #endif