Chaste  Release::2018.1
TetrahedralMesh.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 _TETRAHEDRALMESH_HPP_
37 #define _TETRAHEDRALMESH_HPP_
38 
39 #include "ChasteSerialization.hpp"
40 #include <boost/serialization/base_object.hpp>
41 
42 #include "UblasVectorInclude.hpp"
43 #include "UblasMatrixInclude.hpp"
44 
45 #include <vector>
46 #include <string>
47 #include <set>
48 
49 #include "AbstractTetrahedralMesh.hpp"
50 #include "AbstractMeshReader.hpp"
51 #include "ChastePoint.hpp"
52 
53 
54 struct triangulateio;
56 // DECLARATION
59 
63 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
64 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
65 {
66  friend class TestTetrahedralMesh; // to give access to private methods (not variables)
67  friend class TestCryptSimulation2d; // to give access to private methods (not variables)
68 private:
70  friend class boost::serialization::access;
77  template<class Archive>
78  void serialize(Archive & archive, const unsigned int version)
79  {
80  archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
81  }
82 
83 protected:
84 
91  unsigned SolveNodeMapping(unsigned index) const;
92 
99  unsigned SolveElementMapping(unsigned index) const;
100 
107  unsigned SolveBoundaryElementMapping(unsigned index) const;
108 
110  std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections;
111 
113  std::vector< c_matrix<double, SPACE_DIM, ELEMENT_DIM> > mElementJacobians;
114 
116  std::vector< c_matrix<double, ELEMENT_DIM, SPACE_DIM> > mElementInverseJacobians;
117 
119  std::vector<double> mElementJacobianDeterminants;
120 
122  std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
123 
126 
143  template <class MESHER_IO>
144  void ExportToMesher(NodeMap& map, MESHER_IO& mesherInput, int *elementList=nullptr);
145 
163  template <class MESHER_IO>
164  void ImportFromMesher(MESHER_IO& mesherOutput, unsigned numberOfElements, int *elementList, unsigned numberOfFaces, int *faceList, int *edgeMarkerList);
165 
166 
171  void InitialiseTriangulateIo(triangulateio& mesherIo);
172 
177  void FreeTriangulateIo(triangulateio& mesherIo);
178 
179 public:
180 
184  TetrahedralMesh();
185 
192 
198  void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
199 
212  bool CheckIsConforming();
213 
218  double GetVolume();
219 
223  double GetSurfaceArea();
224 
228  void RefreshMesh();
229 
234  void PermuteNodes();
235 
241  void PermuteNodes(const std::vector<unsigned>& perm);
242 
252  unsigned GetContainingElementIndexWithInitialGuess(const ChastePoint<SPACE_DIM>& rTestPoint, unsigned startingElementGuess, bool strict=false);
253 
262  unsigned GetNearestElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint);
263 
269  std::vector<unsigned> GetContainingElementIndices(const ChastePoint<SPACE_DIM>& rTestPoint);
270 
274  virtual void Clear();
275 
283  double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
284 
286  virtual void RefreshJacobianCachedData();
287 
295  virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
296 
305  virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
306 
314  virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
315 
323  virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
324 
332  {
333  public:
342 
349 
355 
362  EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
363 
364  private:
369  std::set< std::pair<unsigned, unsigned> > mEdgesVisited;
370 
373  unsigned mElemIndex;
374  unsigned mNodeALocalIndex;
375  unsigned mNodeBLocalIndex;
376  };
377 
382 
388 };
389 
392 
393 #endif //_TETRAHEDRALMESH_HPP_
std::vector< c_matrix< double, SPACE_DIM, ELEMENT_DIM > > mElementJacobians
double GetAngleBetweenNodes(unsigned indexA, unsigned indexB)
void ImportFromMesher(MESHER_IO &mesherOutput, unsigned numberOfElements, int *elementList, unsigned numberOfFaces, int *faceList, int *edgeMarkerList)
Definition: Node.hpp:58
std::vector< unsigned > GetContainingElementIndices(const ChastePoint< SPACE_DIM > &rTestPoint)
virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector< double, SPACE_DIM > &rWeightedDirection, double &rJacobianDeterminant) const
unsigned GetContainingElementIndexWithInitialGuess(const ChastePoint< SPACE_DIM > &rTestPoint, unsigned startingElementGuess, bool strict=false)
virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix< double, SPACE_DIM, ELEMENT_DIM > &rJacobian, double &rJacobianDeterminant, c_matrix< double, ELEMENT_DIM, SPACE_DIM > &rInverseJacobian) const
virtual void RefreshJacobianCachedData()
std::vector< c_matrix< double, ELEMENT_DIM, SPACE_DIM > > mElementInverseJacobians
void ConstructFromMeshReader(AbstractMeshReader< ELEMENT_DIM, SPACE_DIM > &rMeshReader)
virtual void GetJacobianForElement(unsigned elementIndex, c_matrix< double, SPACE_DIM, SPACE_DIM > &rJacobian, double &rJacobianDeterminant) const
Node< SPACE_DIM > * GetNodeA()
void ExportToMesher(NodeMap &map, MESHER_IO &mesherInput, int *elementList=nullptr)
EdgeIterator(TetrahedralMesh &rMesh, unsigned elemIndex)
Node< SPACE_DIM > * GetNodeB()
void ReadNodesPerProcessorFile(const std::string &rNodesPerProcessorFile)
unsigned SolveBoundaryElementMapping(unsigned index) const
void InitialiseTriangulateIo(triangulateio &mesherIo)
unsigned SolveElementMapping(unsigned index) const
std::vector< double > mElementJacobianDeterminants
unsigned GetNearestElementIndex(const ChastePoint< SPACE_DIM > &rTestPoint)
std::vector< c_vector< double, SPACE_DIM > > mBoundaryElementWeightedDirections
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
bool operator!=(const typename TetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::EdgeIterator &rOther)
void serialize(Archive &archive, const unsigned int version)
virtual void Clear()
EdgeIterator EdgesBegin()
unsigned SolveNodeMapping(unsigned index) const
std::vector< double > mBoundaryElementJacobianDeterminants
virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector< double, SPACE_DIM > &rWeightedDirection, double &rJacobianDeterminant) const
std::vector< c_vector< double, SPACE_DIM > > mElementWeightedDirections
EdgeIterator EdgesEnd()
std::set< std::pair< unsigned, unsigned > > mEdgesVisited
gcov doesn't like this file...
void FreeTriangulateIo(triangulateio &mesherIo)