Chaste  Release::3.4
NodeBasedCellPopulation.hpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef NODEBASEDCELLPOPULATION_HPP_
37 #define NODEBASEDCELLPOPULATION_HPP_
38 
39 #include "ChasteSerialization.hpp"
40 #include <boost/serialization/base_object.hpp>
41 
42 #include <boost/version.hpp>
43 #if BOOST_VERSION >= 103700
44 #include "ObjectCommunicator.hpp"
45 #endif
46 
47 #include "AbstractCentreBasedCellPopulation.hpp"
48 #include "NodesOnlyMesh.hpp"
49 #include "BoxCollection.hpp"
50 
55 template<unsigned DIM>
57 {
58  friend class TestNodeBasedCellPopulation;
59  friend class TestNodeBasedCellPopulationParallelMethods;
60  friend class TestBoxCollection;
61 
62 protected:
63 
66 
67 private:
68 
70  c_vector<double, DIM> mMinSpatialPositions;
71 
73  c_vector<double, DIM> mMaxSpatialPositions;
74 
76  std::vector< std::pair<Node<DIM>*, Node<DIM>* > > mNodePairs;
77 
79  std::map<unsigned, std::set<unsigned> > mNodeNeighbours;
80 
83 
86 
88  std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendRight;
89 
91  std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendLeft;
92 
94  boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvRight;
95 
97  boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvLeft;
98 
101 
104 
106  static const unsigned mCellCommunicationTag = 123;
107 
109  std::vector<CellPtr> mHaloCells;
110 
112  std::map<unsigned, CellPtr> mLocationHaloCellMap;
113 
115  std::map<CellPtr, unsigned> mHaloCellLocationMap;
116 
119 
122 
134  template<class Archive>
135  void serialize(Archive & archive, const unsigned int version)
136  {
137  archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<DIM> >(*this);
138  archive & mUseVariableRadii;
139 
140  this->Validate();
141  }
142 
151  unsigned AddNode(Node<DIM>* pNewNode);
152 
158  void AddMovedCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
159 
164  void DeleteMovedCell(unsigned index);
165 
169  void RefreshHaloCells();
170 
177  void AddNodeAndCellToSendRight(unsigned nodeIndex);
178 
185  void AddNodeAndCellToSendLeft(unsigned nodeIndex);
186 
191  void AddCellsToSendRight(std::vector<unsigned>& cellLocationIndices);
192 
197  void AddCellsToSendLeft(std::vector<unsigned>& cellLocationIndices);
198 
202  void AddReceivedHaloCells();
203 
209  void AddHaloCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
210 
216  void UpdateMapsAfterRemesh(NodeMap& map);
217 
218 protected:
219 
220 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
221 
226  virtual void UpdateParticlesAfterReMesh(NodeMap& rMap);
227 
231  virtual void Validate();
232 
233 private:
234 
240  virtual void WriteVtkResultsToFile(const std::string& rDirectory);
241 
242 public:
243 
250  void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
251 
264  std::vector<CellPtr>& rCells,
265  const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
266  bool deleteMesh=false,
267  bool validate=true);
268 
275 
281  virtual ~NodeBasedCellPopulation();
282 
287 
291  const NodesOnlyMesh<DIM>& rGetMesh() const;
292 
296  unsigned GetNumNodes();
297 
305  virtual CellPtr GetCellUsingLocationIndex(unsigned index);
306 
314  Node<DIM>* GetNode(unsigned index);
315 
325  unsigned RemoveDeadCells();
326 
330  void Clear();
331 
337  void Update(bool hasHadBirthsOrDeaths=true);
338 
344  std::vector< std::pair<Node<DIM>*, Node<DIM>* > >& rGetNodePairs();
345 
354  void OutputCellPopulationParameters(out_stream& rParamsFile);
355 
362  virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<DIM, DIM> > pPopulationWriter);
363 
370  virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<DIM, DIM> > pPopulationCountWriter);
371 
379  virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<DIM, DIM> > pCellWriter, CellPtr pCell);
380 
384  double GetMechanicsCutOffLength();
385 
389  bool GetUseVariableRadii();
390 
396  void SetUseVariableRadii(bool useVariableRadii=true);
397 
402  void SetLoadBalanceMesh(bool loadBalanceMesh);
403 
408  void SetLoadBalanceFrequency(unsigned loadBalanceFrequency);
409 
419  double GetWidth(const unsigned& rDimension);
420 
426  c_vector<double, DIM> GetSizeOfCellPopulation();
427 
439  std::set<unsigned> GetNodesWithinNeighbourhoodRadius(unsigned index, double neighbourhoodRadius);
440 
449  std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
450 
463  virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell);
464 
471  double GetVolumeOfCell(CellPtr pCell);
472 
474  // Parallel methods
476 
483 
491 
496  void GetReceivedCells();
497 
504  std::pair<CellPtr, Node<DIM>* > GetCellNodePair(unsigned nodeIndex);
505 
509  void AddReceivedCells();
510 
514  virtual void UpdateCellProcessLocation();
515 };
516 
519 
520 namespace boost
521 {
522 namespace serialization
523 {
527 template<class Archive, unsigned DIM>
528 inline void save_construct_data(
529  Archive & ar, const NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
530 {
531  // Save data required to construct instance
532  const NodesOnlyMesh<DIM>* p_mesh = &(t->rGetMesh());
533  ar & p_mesh;
534 }
535 
540 template<class Archive, unsigned DIM>
541 inline void load_construct_data(
542  Archive & ar, NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
543 {
544  // Retrieve data from archive required to construct new instance
545  NodesOnlyMesh<DIM>* p_mesh;
546  ar >> p_mesh;
547 
548  // Invoke inplace constructor to initialise instance
549  ::new(t)NodeBasedCellPopulation<DIM>(*p_mesh);
550 }
551 }
552 } // namespace ...
553 
554 #endif /*NODEBASEDCELLPOPULATION_HPP_*/
void AddCellsToSendRight(std::vector< unsigned > &cellLocationIndices)
void OutputCellPopulationParameters(out_stream &rParamsFile)
std::set< unsigned > GetNodesWithinNeighbourhoodRadius(unsigned index, double neighbourhoodRadius)
NodesOnlyMesh< DIM > & rGetMesh()
boost::shared_ptr< std::vector< std::pair< CellPtr, Node< DIM > * > > > mpCellsRecvLeft
NodeBasedCellPopulation(NodesOnlyMesh< DIM > &rMesh, std::vector< CellPtr > &rCells, const std::vector< unsigned > locationIndices=std::vector< unsigned >(), bool deleteMesh=false, bool validate=true)
Definition: Node.hpp:58
c_vector< double, DIM > GetSizeOfCellPopulation()
Node< DIM > * GetNode(unsigned index)
void serialize(Archive &archive, const unsigned int version)
void AddCellsToSendLeft(std::vector< unsigned > &cellLocationIndices)
static const unsigned mCellCommunicationTag
std::map< CellPtr, unsigned > mHaloCellLocationMap
ObjectCommunicator< std::vector< std::pair< CellPtr, Node< DIM > * > > > mRightCommunicator
void SetNode(unsigned nodeIndex, ChastePoint< DIM > &rNewLocation)
std::vector< std::pair< Node< DIM > *, Node< DIM > * > > mNodePairs
void SetUseVariableRadii(bool useVariableRadii=true)
ObjectCommunicator< std::vector< std::pair< CellPtr, Node< DIM > * > > > mLeftCommunicator
std::vector< CellPtr > mHaloCells
boost::shared_ptr< std::vector< std::pair< CellPtr, Node< DIM > * > > > mpCellsRecvRight
void AddMovedCell(CellPtr pCell, boost::shared_ptr< Node< DIM > > pNode)
std::pair< CellPtr, Node< DIM > * > GetCellNodePair(unsigned nodeIndex)
double GetVolumeOfCell(CellPtr pCell)
virtual void AcceptPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< DIM, DIM > > pPopulationWriter)
virtual void WriteVtkResultsToFile(const std::string &rDirectory)
std::vector< std::pair< CellPtr, Node< DIM > * > > mCellsToSendRight
std::set< unsigned > GetNeighbouringNodeIndices(unsigned index)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void UpdateMapsAfterRemesh(NodeMap &map)
void SetLoadBalanceMesh(bool loadBalanceMesh)
friend class boost::serialization::access
c_vector< double, DIM > mMaxSpatialPositions
virtual void AcceptCellWriter(boost::shared_ptr< AbstractCellWriter< DIM, DIM > > pCellWriter, CellPtr pCell)
void AddHaloCell(CellPtr pCell, boost::shared_ptr< Node< DIM > > pNode)
double GetWidth(const unsigned &rDimension)
unsigned AddNode(Node< DIM > *pNewNode)
c_vector< double, DIM > mMinSpatialPositions
std::vector< std::pair< Node< DIM > *, Node< DIM > * > > & rGetNodePairs()
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
NodesOnlyMesh< DIM > * mpNodesOnlyMesh
std::map< unsigned, CellPtr > mLocationHaloCellMap
std::vector< std::pair< CellPtr, Node< DIM > * > > mCellsToSendLeft
void DeleteMovedCell(unsigned index)
void Update(bool hasHadBirthsOrDeaths=true)
virtual void AcceptPopulationCountWriter(boost::shared_ptr< AbstractCellPopulationCountWriter< DIM, DIM > > pPopulationCountWriter)
void SetLoadBalanceFrequency(unsigned loadBalanceFrequency)
void AddNodeAndCellToSendLeft(unsigned nodeIndex)
std::map< unsigned, std::set< unsigned > > mNodeNeighbours
void AddNodeAndCellToSendRight(unsigned nodeIndex)
virtual void UpdateParticlesAfterReMesh(NodeMap &rMap)
virtual CellPtr AddCell(CellPtr pNewCell, const c_vector< double, DIM > &rCellDivisionVector, CellPtr pParentCell)