Chaste  Release::2017.1
NodeBasedCellPopulation.hpp
1 /*
2 
3 Copyright (c) 2005-2017, 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 
57 protected:
58 
61 
62 private:
63 
65  c_vector<double, DIM> mMinSpatialPositions;
66 
68  c_vector<double, DIM> mMaxSpatialPositions;
69 
71  std::vector< std::pair<Node<DIM>*, Node<DIM>* > > mNodePairs;
72 
75 
78 
80  std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendRight;
81 
83  std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendLeft;
84 
86  boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvRight;
87 
89  boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvLeft;
90 
93 
96 
98  static const unsigned mCellCommunicationTag = 123;
99 
101  std::vector<CellPtr> mHaloCells;
102 
104  std::map<unsigned, CellPtr> mLocationHaloCellMap;
105 
107  std::map<CellPtr, unsigned> mHaloCellLocationMap;
108 
111 
114 
126  template<class Archive>
127  void serialize(Archive & archive, const unsigned int version)
128  {
129  archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<DIM> >(*this);
130  archive & mUseVariableRadii;
131 
132  this->Validate();
133  }
134 
143  unsigned AddNode(Node<DIM>* pNewNode);
144 
150  void AddMovedCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
151 
156  void DeleteMovedCell(unsigned index);
157 
161  void RefreshHaloCells();
162 
169  void AddNodeAndCellToSendRight(unsigned nodeIndex);
170 
177  void AddNodeAndCellToSendLeft(unsigned nodeIndex);
178 
183  void AddCellsToSendRight(std::vector<unsigned>& cellLocationIndices);
184 
189  void AddCellsToSendLeft(std::vector<unsigned>& cellLocationIndices);
190 
194  void AddReceivedHaloCells();
195 
201  void AddHaloCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
202 
208  void UpdateMapsAfterRemesh(NodeMap& map);
209 
210 protected:
211 
217  virtual void UpdateParticlesAfterReMesh(NodeMap& rMap);
218 
222  virtual void Validate();
223 
224 private:
225 
231  virtual void WriteVtkResultsToFile(const std::string& rDirectory);
232 
233 public:
234 
241  void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
242 
255  std::vector<CellPtr>& rCells,
256  const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
257  bool deleteMesh=false,
258  bool validate=true);
259 
266 
272  virtual ~NodeBasedCellPopulation();
273 
278 
282  const NodesOnlyMesh<DIM>& rGetMesh() const;
283 
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 
462  virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell);
463 
470  double GetVolumeOfCell(CellPtr pCell);
471 
473  // Parallel methods
475 
482 
490 
495  void GetReceivedCells();
496 
503  std::pair<CellPtr, Node<DIM>* > GetCellNodePair(unsigned nodeIndex);
504 
508  void AddReceivedCells();
509 
513  virtual void UpdateCellProcessLocation();
514 };
515 
518 
519 namespace boost
520 {
521 namespace serialization
522 {
526 template<class Archive, unsigned DIM>
527 inline void save_construct_data(
528  Archive & ar, const NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
529 {
530  // Save data required to construct instance
531  const NodesOnlyMesh<DIM>* p_mesh = &(t->rGetMesh());
532  ar & p_mesh;
533 }
534 
539 template<class Archive, unsigned DIM>
540 inline void load_construct_data(
541  Archive & ar, NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
542 {
543  // Retrieve data from archive required to construct new instance
544  NodesOnlyMesh<DIM>* p_mesh;
545  ar >> p_mesh;
546 
547  // Invoke inplace constructor to initialise instance
548  ::new(t)NodeBasedCellPopulation<DIM>(*p_mesh);
549 }
550 }
551 } // namespace ...
552 
553 #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)
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)
virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell)
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)
gcov doesn&#39;t like this file...
void SetLoadBalanceFrequency(unsigned loadBalanceFrequency)
void AddNodeAndCellToSendLeft(unsigned nodeIndex)
void AddNodeAndCellToSendRight(unsigned nodeIndex)
virtual void UpdateParticlesAfterReMesh(NodeMap &rMap)