Chaste Commit::675f9facbe008c5eacb9006feaeb6423206579ea
NodeBasedCellPopulation.hpp
1/*
2
3Copyright (c) 2005-2025, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
40#include <boost/serialization/base_object.hpp>
41
42
43#include "ObjectCommunicator.hpp"
44#include "AbstractCentreBasedCellPopulation.hpp"
45#include "NodesOnlyMesh.hpp"
46
51template<unsigned DIM>
53{
54 friend class TestNodeBasedCellPopulation;
55 friend class TestNodeBasedCellPopulationParallelMethods;
56 friend class TestPeriodicNodeBasedCellPopulationParallelMethods;
57
58protected:
59
62
63private:
64
66 c_vector<double, DIM> mMinSpatialPositions;
67
69 c_vector<double, DIM> mMaxSpatialPositions;
70
73
76
78 std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendRight;
79
81 std::vector<std::pair<CellPtr, Node<DIM>* > > mCellsToSendLeft;
82
84 boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvRight;
85
87 boost::shared_ptr<std::vector<std::pair<CellPtr, Node<DIM>* > > > mpCellsRecvLeft;
88
91
94
96 static const unsigned mCellCommunicationTag = 123;
97
99 std::vector<CellPtr> mHaloCells;
100
102 std::map<unsigned, CellPtr> mLocationHaloCellMap;
103
105 std::map<CellPtr, unsigned> mHaloCellLocationMap;
106
109
112
124 template<class Archive>
125 void serialize(Archive & archive, const unsigned int version)
126 {
127 archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<DIM> >(*this);
128 archive & mUseVariableRadii;
129
130 this->Validate();
131 }
132
141 unsigned AddNode(Node<DIM>* pNewNode);
142
148 void AddMovedCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
149
154 void DeleteMovedCell(unsigned index);
155
159 void RefreshHaloCells();
160
167 void AddNodeAndCellToSendRight(unsigned nodeIndex);
168
175 void AddNodeAndCellToSendLeft(unsigned nodeIndex);
176
181 void AddCellsToSendRight(std::vector<unsigned>& cellLocationIndices);
182
187 void AddCellsToSendLeft(std::vector<unsigned>& cellLocationIndices);
188
193
199 void AddHaloCell(CellPtr pCell, boost::shared_ptr<Node<DIM> > pNode);
200
207
208protected:
209
215 virtual void UpdateParticlesAfterReMesh(NodeMap& rMap);
216
220 virtual void Validate();
221
222private:
223
229 virtual void WriteVtkResultsToFile(const std::string& rDirectory);
230
240 unsigned CalculateMessageTag(unsigned senderI, unsigned receiverJ);
241
242public:
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
301
305 unsigned GetNumNodes();
306
314 virtual CellPtr GetCellUsingLocationIndex(unsigned index);
315
323 Node<DIM>* GetNode(unsigned index);
324
334 unsigned RemoveDeadCells();
335
339 void Clear();
340
346 void Update(bool hasHadBirthsOrDeaths=true);
347
356 void OutputCellPopulationParameters(out_stream& rParamsFile);
357
364 virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<DIM, DIM> > pPopulationWriter);
365
372 virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<DIM, DIM> > pPopulationCountWriter);
373
380 virtual void AcceptPopulationEventWriter(boost::shared_ptr<AbstractCellPopulationEventWriter<DIM, DIM> > pPopulationEventWriter);
381
389 virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<DIM, DIM> > pCellWriter, CellPtr pCell);
390
395
399 bool GetUseVariableRadii();
400
406 void SetUseVariableRadii(bool useVariableRadii=true);
407
412 void SetLoadBalanceMesh(bool loadBalanceMesh);
413
418 void SetLoadBalanceFrequency(unsigned loadBalanceFrequency);
419
429 double GetWidth(const unsigned& rDimension);
430
436 c_vector<double, DIM> GetSizeOfCellPopulation();
437
449 std::set<unsigned> GetNodesWithinNeighbourhoodRadius(unsigned index, double neighbourhoodRadius);
450
459 std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
460
472 virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell);
473
480 double GetVolumeOfCell(CellPtr pCell);
481
483 // Parallel methods
485
492
500
505 void GetReceivedCells();
506
513 std::pair<CellPtr, Node<DIM>* > GetCellNodePair(unsigned nodeIndex);
514
518 void AddReceivedCells();
519
523 virtual void UpdateCellProcessLocation();
524};
525
528
529namespace boost
530{
531namespace serialization
532{
536template<class Archive, unsigned DIM>
537inline void save_construct_data(
538 Archive & ar, const NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
539{
540 // Save data required to construct instance
541 const NodesOnlyMesh<DIM>* p_mesh = &(t->rGetMesh());
542 ar & p_mesh;
543}
544
549template<class Archive, unsigned DIM>
550inline void load_construct_data(
551 Archive & ar, NodeBasedCellPopulation<DIM> * t, const unsigned int file_version)
552{
553 // Retrieve data from archive required to construct new instance
554 NodesOnlyMesh<DIM>* p_mesh;
555 ar >> p_mesh;
556
557 // Invoke inplace constructor to initialise instance
558 ::new(t)NodeBasedCellPopulation<DIM>(*p_mesh);
559}
560}
561} // namespace ...
562
563#endif /*NODEBASEDCELLPOPULATION_HPP_*/
gcov doesn't like this file...
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
boost::shared_ptr< std::vector< std::pair< CellPtr, Node< DIM > * > > > mpCellsRecvLeft
c_vector< double, DIM > GetSizeOfCellPopulation()
unsigned CalculateMessageTag(unsigned senderI, unsigned receiverJ)
c_vector< double, DIM > mMaxSpatialPositions
void SetNode(unsigned nodeIndex, ChastePoint< DIM > &rNewLocation)
ObjectCommunicator< std::vector< std::pair< CellPtr, Node< DIM > * > > > mLeftCommunicator
ObjectCommunicator< std::vector< std::pair< CellPtr, Node< DIM > * > > > mRightCommunicator
void AddCellsToSendRight(std::vector< unsigned > &cellLocationIndices)
void AddHaloCell(CellPtr pCell, boost::shared_ptr< Node< DIM > > pNode)
static const unsigned mCellCommunicationTag
Node< DIM > * GetNode(unsigned index)
virtual void AcceptPopulationCountWriter(boost::shared_ptr< AbstractCellPopulationCountWriter< DIM, DIM > > pPopulationCountWriter)
void OutputCellPopulationParameters(out_stream &rParamsFile)
void AddNodeAndCellToSendLeft(unsigned nodeIndex)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
NodesOnlyMesh< DIM > & rGetMesh()
void serialize(Archive &archive, const unsigned int version)
void SetUseVariableRadii(bool useVariableRadii=true)
std::vector< CellPtr > mHaloCells
std::pair< CellPtr, Node< DIM > * > GetCellNodePair(unsigned nodeIndex)
c_vector< double, DIM > mMinSpatialPositions
void SetLoadBalanceMesh(bool loadBalanceMesh)
virtual void WriteVtkResultsToFile(const std::string &rDirectory)
void AddCellsToSendLeft(std::vector< unsigned > &cellLocationIndices)
virtual void AcceptCellWriter(boost::shared_ptr< AbstractCellWriter< DIM, DIM > > pCellWriter, CellPtr pCell)
unsigned AddNode(Node< DIM > *pNewNode)
std::set< unsigned > GetNodesWithinNeighbourhoodRadius(unsigned index, double neighbourhoodRadius)
double GetWidth(const unsigned &rDimension)
virtual TetrahedralMesh< DIM, DIM > * GetTetrahedralMeshForPdeModifier()
NodesOnlyMesh< DIM > * mpNodesOnlyMesh
void SetLoadBalanceFrequency(unsigned loadBalanceFrequency)
std::map< CellPtr, unsigned > mHaloCellLocationMap
boost::shared_ptr< std::vector< std::pair< CellPtr, Node< DIM > * > > > mpCellsRecvRight
double GetVolumeOfCell(CellPtr pCell)
void Update(bool hasHadBirthsOrDeaths=true)
virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell)
friend class boost::serialization::access
std::vector< std::pair< CellPtr, Node< DIM > * > > mCellsToSendLeft
void AddNodeAndCellToSendRight(unsigned nodeIndex)
std::map< unsigned, CellPtr > mLocationHaloCellMap
void AddMovedCell(CellPtr pCell, boost::shared_ptr< Node< DIM > > pNode)
std::set< unsigned > GetNeighbouringNodeIndices(unsigned index)
virtual void UpdateParticlesAfterReMesh(NodeMap &rMap)
virtual void AcceptPopulationEventWriter(boost::shared_ptr< AbstractCellPopulationEventWriter< DIM, DIM > > pPopulationEventWriter)
std::vector< std::pair< CellPtr, Node< DIM > * > > mCellsToSendRight
virtual void AcceptPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< DIM, DIM > > pPopulationWriter)
Definition Node.hpp:59