Chaste  Release::2024.1
NodeBasedCellPopulation.hpp
1 /*
2 
3 Copyright (c) 2005-2021, 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 
43 #include "ObjectCommunicator.hpp"
44 #include "AbstractCentreBasedCellPopulation.hpp"
45 #include "NodesOnlyMesh.hpp"
46 
51 template<unsigned DIM>
53 {
54  friend class TestNodeBasedCellPopulation;
55  friend class TestNodeBasedCellPopulationParallelMethods;
56  friend class TestPeriodicNodeBasedCellPopulationParallelMethods;
57 
58 protected:
59 
62 
63 private:
64 
66  c_vector<double, DIM> mMinSpatialPositions;
67 
69  c_vector<double, DIM> mMaxSpatialPositions;
70 
72  std::vector< std::pair<Node<DIM>*, Node<DIM>* > > mNodePairs;
73 
76 
79 
81  std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendRight;
82 
84  std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendLeft;
85 
87  boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvRight;
88 
90  boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvLeft;
91 
94 
97 
99  static const unsigned mCellCommunicationTag = 123;
100 
102  std::vector<CellPtr> mHaloCells;
103 
105  std::map<unsigned, CellPtr> mLocationHaloCellMap;
106 
108  std::map<CellPtr, unsigned> mHaloCellLocationMap;
109 
112 
115 
127  template<class Archive>
128  void serialize(Archive & archive, const unsigned int version)
129  {
130  archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<DIM> >(*this);
131  archive & mUseVariableRadii;
132 
133  this->Validate();
134  }
135 
144  unsigned AddNode(Node<DIM>* pNewNode);
145 
151  void AddMovedCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
152 
157  void DeleteMovedCell(unsigned index);
158 
162  void RefreshHaloCells();
163 
170  void AddNodeAndCellToSendRight(unsigned nodeIndex);
171 
178  void AddNodeAndCellToSendLeft(unsigned nodeIndex);
179 
184  void AddCellsToSendRight(std::vector<unsigned>& cellLocationIndices);
185 
190  void AddCellsToSendLeft(std::vector<unsigned>& cellLocationIndices);
191 
195  void AddReceivedHaloCells();
196 
202  void AddHaloCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
203 
209  void UpdateMapsAfterRemesh(NodeMap& map);
210 
211 protected:
212 
218  virtual void UpdateParticlesAfterReMesh(NodeMap& rMap);
219 
223  virtual void Validate();
224 
225 private:
226 
232  virtual void WriteVtkResultsToFile(const std::string& rDirectory);
233 
243  unsigned CalculateMessageTag(unsigned senderI, unsigned receiverJ);
244 
245 public:
246 
253  void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
254 
267  std::vector<CellPtr>& rCells,
268  const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
269  bool deleteMesh=false,
270  bool validate=true);
271 
278 
284  virtual ~NodeBasedCellPopulation();
285 
290 
294  const NodesOnlyMesh<DIM>& rGetMesh() const;
295 
304 
308  unsigned GetNumNodes();
309 
317  virtual CellPtr GetCellUsingLocationIndex(unsigned index);
318 
326  Node<DIM>* GetNode(unsigned index);
327 
337  unsigned RemoveDeadCells();
338 
342  void Clear();
343 
349  void Update(bool hasHadBirthsOrDeaths=true);
350 
356  std::vector< std::pair<Node<DIM>*, Node<DIM>* > >& rGetNodePairs();
357 
366  void OutputCellPopulationParameters(out_stream& rParamsFile);
367 
374  virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<DIM, DIM> > pPopulationWriter);
375 
382  virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<DIM, DIM> > pPopulationCountWriter);
383 
391  virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<DIM, DIM> > pCellWriter, CellPtr pCell);
392 
396  double GetMechanicsCutOffLength();
397 
401  bool GetUseVariableRadii();
402 
408  void SetUseVariableRadii(bool useVariableRadii=true);
409 
414  void SetLoadBalanceMesh(bool loadBalanceMesh);
415 
420  void SetLoadBalanceFrequency(unsigned loadBalanceFrequency);
421 
431  double GetWidth(const unsigned& rDimension);
432 
438  c_vector<double, DIM> GetSizeOfCellPopulation();
439 
451  std::set<unsigned> GetNodesWithinNeighbourhoodRadius(unsigned index, double neighbourhoodRadius);
452 
461  std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
462 
474  virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell);
475 
482  double GetVolumeOfCell(CellPtr pCell);
483 
485  // Parallel methods
487 
494 
502 
507  void GetReceivedCells();
508 
515  std::pair<CellPtr, Node<DIM>* > GetCellNodePair(unsigned nodeIndex);
516 
520  void AddReceivedCells();
521 
525  virtual void UpdateCellProcessLocation();
526 };
527 
530 
531 namespace boost
532 {
533 namespace serialization
534 {
538 template<class Archive, unsigned DIM>
539 inline void save_construct_data(
540  Archive & ar, const NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
541 {
542  // Save data required to construct instance
543  const NodesOnlyMesh<DIM>* p_mesh = &(t->rGetMesh());
544  ar & p_mesh;
545 }
546 
551 template<class Archive, unsigned DIM>
552 inline void load_construct_data(
553  Archive & ar, NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
554 {
555  // Retrieve data from archive required to construct new instance
556  NodesOnlyMesh<DIM>* p_mesh;
557  ar >> p_mesh;
558 
559  // Invoke inplace constructor to initialise instance
560  ::new(t)NodeBasedCellPopulation<DIM>(*p_mesh);
561 }
562 }
563 } // namespace ...
564 
565 #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
virtual TetrahedralMesh< DIM, DIM > * GetTetrahedralMeshForPdeModifier()
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)
double GetVolumeOfCell(CellPtr pCell)
virtual void AcceptPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< DIM, DIM > > pPopulationWriter)
virtual void WriteVtkResultsToFile(const std::string &rDirectory)
virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell)
std::pair< CellPtr, Node< DIM > *> GetCellNodePair(unsigned nodeIndex)
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)
unsigned CalculateMessageTag(unsigned senderI, unsigned receiverJ)
std::vector< std::pair< Node< DIM > *, Node< DIM > *> > & rGetNodePairs()
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
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)
gcov doesn&#39;t like this file...
void SetLoadBalanceFrequency(unsigned loadBalanceFrequency)
void AddNodeAndCellToSendLeft(unsigned nodeIndex)
void AddNodeAndCellToSendRight(unsigned nodeIndex)
virtual void UpdateParticlesAfterReMesh(NodeMap &rMap)