Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
AbstractMesh.hpp
1/*
2
3Copyright (c) 2005-2024, 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 ABSTRACTMESH_HPP_
37#define ABSTRACTMESH_HPP_
38
40#include "ClassIsAbstract.hpp"
41
44
45#include <vector>
46#include <string>
47#include <cassert>
48
49#include "Node.hpp"
50#include "DistributedVectorFactory.hpp"
51#include "ProcessSpecificArchive.hpp"
52#include "ChasteCuboid.hpp"
53
54#include <boost/utility.hpp>
55
59template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
60class AbstractMesh : private boost::noncopyable
61{
62 friend class TestDistributedTetrahedralMesh;
63 template <unsigned A_DIMENSION> friend class NodesOnlyMesh; //NodesOnlyMesh is able to grab the node information in order to copy
64 template <unsigned A_DIMENSION> friend class QuadraticMeshHelper;
65
66private:
76 virtual unsigned SolveNodeMapping(unsigned index) const = 0;
77
86 template<class Archive>
87 void serialize(Archive & archive, const unsigned int version)
88 {
91 }
92
93protected: // Give access of these variables to subclasses
94
96 std::vector<Node<SPACE_DIM> *> mNodes;
97
99 std::vector<Node<SPACE_DIM> *> mBoundaryNodes;
100
106
114 std::vector<unsigned> mNodePermutation;
115
120 std::string mMeshFileBaseName;
121
126
130 virtual void SetElementOwnerships();
131
139 ChasteCuboid<SPACE_DIM> CalculateBoundingBox(const std::vector<Node<SPACE_DIM>* >& rNodes) const;
140
141public:
142
144 // Iterators //
146
148 typedef typename std::vector<Node<SPACE_DIM> *>::const_iterator BoundaryNodeIterator;
149
151 class NodeIterator;
152
158 inline NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true);
159
163 inline NodeIterator GetNodeIteratorEnd();
164
166 // Methods //
168
172 AbstractMesh();
173
177 virtual ~AbstractMesh();
178
184 virtual unsigned GetNumNodes() const;
185
189 unsigned GetNumBoundaryNodes() const;
190
194 virtual unsigned GetNumAllNodes() const;
195
201 unsigned GetNumNodeAttributes() const;
202
209 Node<SPACE_DIM>* GetNode(unsigned index) const;
210
217 virtual Node<SPACE_DIM>* GetNodeOrHaloNode(unsigned index) const;
218
233 Node<SPACE_DIM>* GetNodeFromPrePermutationIndex(unsigned index) const;
234
240 virtual void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
241
246
256
261 virtual void PermuteNodes();
262
267
273
277 std::string GetMeshFileBaseName() const;
278
284 bool IsMeshOnDisk() const;
285
294 const std::vector<unsigned>& rGetNodePermutation() const;
295
306 virtual c_vector<double, SPACE_DIM> GetVectorFromAtoB(const c_vector<double, SPACE_DIM>& rLocationA,
307 const c_vector<double, SPACE_DIM>& rLocationB);
308
320 double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB);
321
330 virtual double GetWidth(const unsigned& rDimension) const;
331
340
353 virtual unsigned GetNearestNodeIndex(const ChastePoint<SPACE_DIM>& rTestPoint);
354
362 virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0);
363
371 virtual void Translate(const c_vector<double, SPACE_DIM>& rDisplacement);
372
380 void Translate(const double xMovement=0.0, const double yMovement=0.0, const double zMovement=0.0);
381
389 virtual void Rotate(c_matrix<double , SPACE_DIM, SPACE_DIM> rotationMatrix);
390
397 void Rotate(c_vector<double,3> axis, double angle);
398
404 void RotateX(const double theta);
405
411 void RotateY(const double theta);
412
418 void RotateZ(const double theta);
419
425 void Rotate(double theta);
426
431 virtual void RefreshMesh();
432
436 bool IsMeshChanging() const;
437
443
450
452 // Nested classes //
454
459 {
460 public:
467
473
480
485 inline NodeIterator& operator++();
486
498 typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
499 bool skipDeletedNodes=true);
500 private:
503
505 typename std::vector<Node<SPACE_DIM> *>::iterator mNodeIter;
506
509
514 inline bool IsAtEnd();
515
520 inline bool IsAllowedNode();
521 };
522};
523
525
526
527// NodeIterator class implementation - most methods are inlined //
529
530template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
532 bool skipDeletedNodes)
533{
534 return NodeIterator(*this, mNodes.begin(), skipDeletedNodes);
535}
536
537template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
542
543
544
545template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
551
552template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
554{
555 assert(!IsAtEnd());
556 return *mNodeIter;
557}
558
559template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
564
565template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
567{
568 do
569 {
570 ++mNodeIter;
571 }
572 while (!IsAtEnd() && !IsAllowedNode());
573
574 return (*this);
575}
576
577template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
580 typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
581 bool skipDeletedNodes)
582 : mrMesh(rMesh),
583 mNodeIter(nodeIter),
584 mSkipDeletedNodes(skipDeletedNodes)
585{
586 if (mrMesh.mNodes.size() == 0)
587 {
588 // Cope with empty meshes
589 mNodeIter = mrMesh.mNodes.end();
590 }
591 else
592 {
593 // Make sure we start at an allowed node
594 if (mNodeIter == mrMesh.mNodes.begin() && !IsAllowedNode())
595 {
596 ++(*this);
597 }
598 }
599}
600
601template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
603{
604 return mNodeIter == mrMesh.mNodes.end();
605}
606
607template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
609{
610 return !(mSkipDeletedNodes && (*this)->IsDeleted());
611}
612
613
614#endif /*ABSTRACTMESH_HPP_*/
#define TEMPLATED_CLASS_IS_ABSTRACT_2_UNSIGNED(T)
NodeIterator(AbstractMesh< ELEMENT_DIM, SPACE_DIM > &rMesh, typename std::vector< Node< SPACE_DIM > * >::iterator nodeIter, bool skipDeletedNodes=true)
std::vector< Node< SPACE_DIM > * >::iterator mNodeIter
Node< SPACE_DIM > & operator*()
Node< SPACE_DIM > * operator->()
bool operator!=(const typename AbstractMesh< ELEMENT_DIM, SPACE_DIM >::NodeIterator &rOther)
virtual unsigned GetNumAllNodes() const
void RotateZ(const double theta)
virtual DistributedVectorFactory * GetDistributedVectorFactory()
void RotateY(const double theta)
virtual void Translate(const c_vector< double, SPACE_DIM > &rDisplacement)
virtual Node< SPACE_DIM > * GetNodeOrHaloNode(unsigned index) const
bool mMeshChangesDuringSimulation
void serialize(Archive &archive, const unsigned int version)
virtual void RefreshMesh()
BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const
virtual void SetElementOwnerships()
bool IsMeshChanging() const
virtual void SetDistributedVectorFactory(DistributedVectorFactory *pFactory)
void RotateX(const double theta)
std::string GetMeshFileBaseName() const
std::vector< Node< SPACE_DIM > * >::const_iterator BoundaryNodeIterator
virtual unsigned GetNumNodes() const
virtual ChasteCuboid< SPACE_DIM > CalculateBoundingBox() const
NodeIterator GetNodeIteratorEnd()
virtual void ReadNodesPerProcessorFile(const std::string &rNodesPerProcessorFile)
std::vector< Node< SPACE_DIM > * > mBoundaryNodes
virtual double GetWidth(const unsigned &rDimension) const
virtual c_vector< double, SPACE_DIM > GetVectorFromAtoB(const c_vector< double, SPACE_DIM > &rLocationA, const c_vector< double, SPACE_DIM > &rLocationB)
virtual void PermuteNodes()
double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB)
std::vector< unsigned > mNodePermutation
std::string mMeshFileBaseName
bool IsMeshOnDisk() const
Node< SPACE_DIM > * GetNode(unsigned index) const
BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const
virtual void Rotate(c_matrix< double, SPACE_DIM, SPACE_DIM > rotationMatrix)
virtual unsigned GetNearestNodeIndex(const ChastePoint< SPACE_DIM > &rTestPoint)
virtual ~AbstractMesh()
std::vector< Node< SPACE_DIM > * > mNodes
virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0)
const std::vector< unsigned > & rGetNodePermutation() const
unsigned GetNumNodeAttributes() const
unsigned CalculateMaximumContainingElementsPerProcess() const
friend class boost::serialization::access
virtual unsigned SolveNodeMapping(unsigned index) const =0
DistributedVectorFactory * mpDistributedVectorFactory
unsigned GetNumBoundaryNodes() const
NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true)
void SetMeshHasChangedSinceLoading()
Node< SPACE_DIM > * GetNodeFromPrePermutationIndex(unsigned index) const
Definition Node.hpp:59