Chaste  Release::2018.1
AbstractMesh.hpp
1 /*
2 
3 Copyright (c) 2005-2018, 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 ABSTRACTMESH_HPP_
37 #define ABSTRACTMESH_HPP_
38 
39 #include "ChasteSerialization.hpp"
40 #include "ClassIsAbstract.hpp"
41 
42 #include "UblasVectorInclude.hpp"
43 #include "UblasMatrixInclude.hpp"
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 
59 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
60 class 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 
66 private:
76  virtual unsigned SolveNodeMapping(unsigned index) const = 0;
77 
79  friend class boost::serialization::access;
86  template<class Archive>
87  void serialize(Archive & archive, const unsigned int version)
88  {
91  }
92 
93 protected: // 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 
141 public:
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:
466  inline Node<SPACE_DIM>& operator*();
467 
472  inline Node<SPACE_DIM>* operator->();
473 
479  inline bool operator!=(const typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther);
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 // NodeIterator class implementation - most methods are inlined //
529 
530 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
531 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorBegin(
532  bool skipDeletedNodes)
533 {
534  return NodeIterator(*this, mNodes.begin(), skipDeletedNodes);
535 }
536 
537 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
539 {
540  return NodeIterator(*this, mNodes.end());
541 }
542 
543 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
545 {
546  assert(!IsAtEnd());
547  return **mNodeIter;
548 }
549 
550 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
552 {
553  assert(!IsAtEnd());
554  return *mNodeIter;
555 }
556 
557 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
559 {
560  return mNodeIter != rOther.mNodeIter;
561 }
562 
563 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
565 {
566  do
567  {
568  ++mNodeIter;
569  }
570  while (!IsAtEnd() && !IsAllowedNode());
571 
572  return (*this);
573 }
574 
575 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
578  typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
579  bool skipDeletedNodes)
580  : mrMesh(rMesh),
581  mNodeIter(nodeIter),
582  mSkipDeletedNodes(skipDeletedNodes)
583 {
584  if (mrMesh.mNodes.size() == 0)
585  {
586  // Cope with empty meshes
587  mNodeIter = mrMesh.mNodes.end();
588  }
589  else
590  {
591  // Make sure we start at an allowed node
592  if (mNodeIter == mrMesh.mNodes.begin() && !IsAllowedNode())
593  {
594  ++(*this);
595  }
596  }
597 }
598 
599 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
601 {
602  return mNodeIter == mrMesh.mNodes.end();
603 }
604 
605 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
607 {
608  return !(mSkipDeletedNodes && (*this)->IsDeleted());
609 }
610 
611 
612 #endif /*ABSTRACTMESH_HPP_*/
virtual DistributedVectorFactory * GetDistributedVectorFactory()
#define TEMPLATED_CLASS_IS_ABSTRACT_2_UNSIGNED(T)
std::vector< Node< SPACE_DIM > * > mBoundaryNodes
virtual void ReadNodesPerProcessorFile(const std::string &rNodesPerProcessorFile)
virtual unsigned GetNearestNodeIndex(const ChastePoint< SPACE_DIM > &rTestPoint)
Definition: Node.hpp:58
virtual void RefreshMesh()
virtual Node< SPACE_DIM > * GetNodeOrHaloNode(unsigned index) const
virtual unsigned SolveNodeMapping(unsigned index) const =0
const std::vector< unsigned > & rGetNodePermutation() const
Node< SPACE_DIM > * operator->()
bool IsMeshChanging() const
virtual void Translate(const c_vector< double, SPACE_DIM > &rDisplacement)
std::vector< unsigned > mNodePermutation
Node< SPACE_DIM > * GetNode(unsigned index) const
std::vector< Node< SPACE_DIM > * >::iterator mNodeIter
void serialize(Archive &archive, const unsigned int version)
NodeIterator GetNodeIteratorEnd()
unsigned CalculateMaximumContainingElementsPerProcess() const
std::string GetMeshFileBaseName() const
virtual ChasteCuboid< SPACE_DIM > CalculateBoundingBox() const
virtual unsigned GetNumNodes() const
virtual void PermuteNodes()
Node< SPACE_DIM > & operator*()
BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const
virtual unsigned GetNumAllNodes() const
NodeIterator & operator++()
virtual void SetElementOwnerships()
std::string mMeshFileBaseName
static Archive * Get(void)
double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB)
bool mMeshChangesDuringSimulation
std::vector< Node< SPACE_DIM > * > mNodes
DistributedVectorFactory * mpDistributedVectorFactory
unsigned GetNumBoundaryNodes() const
bool operator!=(const typename AbstractMesh< ELEMENT_DIM, SPACE_DIM >::NodeIterator &rOther)
unsigned GetNumNodeAttributes() const
std::vector< Node< SPACE_DIM > * >::const_iterator BoundaryNodeIterator
NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true)
bool IsMeshOnDisk() const
virtual ~AbstractMesh()
void SetMeshHasChangedSinceLoading()
virtual double GetWidth(const unsigned &rDimension) const
virtual void Rotate(c_matrix< double, SPACE_DIM, SPACE_DIM > rotationMatrix)
virtual c_vector< double, SPACE_DIM > GetVectorFromAtoB(const c_vector< double, SPACE_DIM > &rLocationA, const c_vector< double, SPACE_DIM > &rLocationB)
BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const
virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0)
NodeIterator(AbstractMesh< ELEMENT_DIM, SPACE_DIM > &rMesh, typename std::vector< Node< SPACE_DIM > * >::iterator nodeIter, bool skipDeletedNodes=true)
virtual void SetDistributedVectorFactory(DistributedVectorFactory *pFactory)
void RotateY(const double theta)
void RotateZ(const double theta)
Node< SPACE_DIM > * GetNodeFromPrePermutationIndex(unsigned index) const
void RotateX(const double theta)