FEMTIC
MeshDataTetraElement.h
Go to the documentation of this file.
1 //-------------------------------------------------------------------------------------------------------
2 // The MIT License (MIT)
3 //
4 // Copyright (c) 2021 Yoshiya Usui
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //-------------------------------------------------------------------------------------------------------
24 #ifndef DBLDEF_MESHDATA_TETRA_ELEMENT
25 #define DBLDEF_MESHDATA_TETRA_ELEMENT
26 
27 #include <vector>
28 #include "MeshData.h"
29 #include "CommonParameters.h"
30 
31 // Class of FEM mesh for tetrahedral element
33 
34 public:
35 
36  // Default constructer
38 
39  // Destructer
40  virtual ~MeshDataTetraElement();
41 
42  // Input mesh data from "mesh.dat"
43  virtual void inputMeshData();
44 
45  // Find element including a point
46  int findElementIncludingPoint( const double locX, const double locY, const double locZ, CommonParameters::VolumeCoords& localCoord ) const;
47 
48  // Find element including a point on the surface of the earth
49  int findElementIncludingPointOnSurface( const double locX, const double locY, int& faceID, CommonParameters::AreaCoords& localCoord, const bool useUpperElem,
50  const bool modLoc, double& locXMod, double& locYMod ) const;
51 
52  // Find element including a point on the Y-Z plane and return element ID of 2D mesh
53  int findElementIncludingPointOnYZPlaneAndReturnElemID2D( const int iPlane, const double locY, const double locZ, CommonParameters::AreaCoords& localCoord ) const;
54 
55  // Find element including a point on the Z-X plane and return element ID of 2D mesh
56  int findElementIncludingPointOnZXPlaneAndReturnElemID2D( const int iPlane, const double locZ, const double locX, CommonParameters::AreaCoords& localCoord ) const;
57 
58  // Find elements including dipole on the surface of the earth
59  void findElementsIncludingDipoleOnSurface( const double locXStart, const double locYStart, const double locXEnd, const double locYEnd, std::vector<int>& elements, std::vector<int>& faces,
60  std::vector<CommonParameters::AreaCoords>& areaCoordsdStartPoint, std::vector<CommonParameters::AreaCoords>& areaCoordsdEndPoint ) const;
61 
62  // Decide whether specified elements share same edges
63  virtual bool shareSameEdges( const int elemID1, const int elemID2 ) const;
64 
65  // Calculate volume of a specified element
66  virtual double calcVolume( const int elemID ) const;
67 
68  // Output mesh data to VTK file
69  virtual void outputMeshDataToVTK() const;
70 
71  // Output mesh data to binary file
72  virtual void outputMeshDataToBinary() const;
73 
74  // Get ID of the nodes of elements belonging to the boundary planes
75  virtual int getNodesOfElementsBoundaryPlanes( const int iPlane, const int iElem, const int iNode ) const;
76 
77  // Get mesh type
78  int getMeshType() const;
79 
80  // Get local face ID of elements belonging to the boundary planes
81  int getFaceIDLocalFromElementBoundaryPlanes( const int iPlane, const int iElem ) const;
82 
83  // Get local node ID from local face ID
84  int getNodeIDLocalFromFaceIDLocal( const int iFace, const int num ) const;
85 
86  // Get local node ID from local edge ID
87  int getNodeIDLocalFromEdgeIDLocal( const int iEdge, const int num ) const;
88 
89  // Get global node ID of specified element and edge
90  int getNodeIDGlobalFromElementAndEdge( const int iElem, const int iEdge, const int num ) const;
91 
92  // Get global node ID of specified element and face
93  int getNodeIDGlobalFromElementAndFace( const int iElem, const int iFace, const int num ) const;
94 
95  // Get global node ID of specified element belonging to the boundary planes
96  int getNodeIDGlobalFromElementBoundaryPlanes( const int iPlane, const int iElem, const int num ) const;
97 
98  // Get X coordinate of node of specified element belonging to the boundary planes
99  double getCoordXFromElementBoundaryPlanes( const int iPlane, const int iElem, const int num ) const;
100 
101  // Get Y coordinate of node of specified element belonging to the boundary planes
102  double getCoordYFromElementBoundaryPlanes( const int iPlane, const int iElem, const int num ) const;
103 
104  // Get Z coordinate of node of specified element belonging to the boundary planes
105  double getCoordZFromElementBoundaryPlanes( const int iPlane, const int iElem, const int num ) const;
106 
107  // Get global node ID from ID of element belonging to the boundary planes and its edge ID
108  // [note] : node ID is outputed as they make a clockwise turn around +X or +Y direction
109  int getNodeIDGlobalFromElementAndEdgeBoundaryPlanes( const int iPlane, const int iElem, const int iEdge, const int num ) const;
110 
111  // Get local edge ID from local face ID
112  int getEdgeIDLocalFromFaceIDLocal( const int iFace, const int num ) const;
113 
114  // Calculate length of edges of elements
115  double calcEdgeLengthFromElementAndEdge( const int iElem, const int iEdge ) const;
116 
117  // Calculate length projected on the horizontal plane of edges of elements
118  double calcEdgeLengthProjectedOnHorizontalPlaneFromElementAndEdge( const int iElem, const int iEdge ) const;
119 
120  // Calculate length of edges of elements on boundary planes
121  double calcEdgeLengthFromElementAndEdgeBoundaryPlanes( const int iPlane, const int iElem, const int iEdge ) const;
122 
123  // Calculate horizontal coordinate differences of edges of the elements on boundary planes
124  double calcHorizontalCoordDifferenceBoundaryPlanes( const int iPlane, const int iElem, const int iEdge ) const;
125 
126  // Calculate X coordinate of points on element face
127  double calcXCoordOfPointOnFace( const int iElem, const int iFace, const CommonParameters::AreaCoords& areaCoord ) const;
128 
129  // Calculate Y coordinate of points on element face
130  double calcYCoordOfPointOnFace( const int iElem, const int iFace, const CommonParameters::AreaCoords& areaCoord ) const;
131 
132  // Calculate Z coordinate of points on element face
133  double calcZCoordOfPointOnFace( const int iElem, const int iFace, const CommonParameters::AreaCoords& areaCoord ) const;
134 
135  // Calculate volume coordinates from area coordinates
136  void calcVolumeCoordFromAreaCoord( const int iFace, const CommonParameters::AreaCoords& areaCoord, CommonParameters::VolumeCoords& volumeCoord ) const;
137 
138  // Calculate area projected on X-Y plane with sign of triangle from area coordinate.
139  // If rotation direction is plus Z, area value is plus. Otherwise, area value is minus.
140  double calcAreaOnXYPlaneWithSignFromAreaCoords( const int elemID, const int faceID, const CommonParameters::AreaCoords& coord0, const CommonParameters::AreaCoords& coord1, const CommonParameters::AreaCoords& coord2 ) const;
141 
142  // Calculate area with sign of triangle from area coordinate.
143  // If rotation direction is plus Z, area value is plus. Otherwise, area value is minus.
144  double calcAreaWithSignFromAreaCoords( const int elemID, const int faceID, const CommonParameters::AreaCoords& coord0, const CommonParameters::AreaCoords& coord1, const CommonParameters::AreaCoords& coord2 ) const;
145 
146  // Calculate area of face
147  double calcAreaOfFace( const int iElem, const int iFace ) const;
148 
149  // Calculate area of face at bottom of mesh
150  double calcAreaOfFaceAtBottomOfMesh( const int iElem ) const;
151 
152 #ifdef _DEBUG_WRITE
153  // Function for debug
154  void testFuction() const;
155 #endif
156 
157 private:
158 
159  // Copy constructer
161 
162  // Copy assignment operator
164 
165  static const double m_eps;
166 
167  // Array of faces of elements belonging to the boundary planes
168  // m_facesOfElementsBoundaryPlanes[0] : Y-Z Plane ( Minus Side )
169  // m_facesOfElementsBoundaryPlanes[1] : Y-Z Plane ( Plus Side )
170  // m_facesOfElementsBoundaryPlanes[2] : Z-X Plane ( Minus Side )
171  // m_facesOfElementsBoundaryPlanes[3] : Z-X Plane ( Plus Side )
172  // m_facesOfElementsBoundaryPlanes[4] : X-Y Plane ( Minus Side )
173  // m_facesOfElementsBoundaryPlanes[5] : X-Y Plane ( Plus Side )
175 
176  // Number of elements belonging to the land surface
178 
179  // Array of elements belonging to the land surface
181 
182  // Array of faces belonging to the land surface
184 
185  // Array converting from face ID to node ID
186  int m_faceID2NodeID[4][3];
187 
188  // Array converting from face ID to edge ID
189  int m_faceID2EdgeID[4][3];
190 
191  // Array converting from edge ID to node ID
192  int m_edgeID2NodeID[6][2];
193 
194  // Function determine if two segments intersect or not
196  const CommonParameters::locationXY& startPointOfSegment, const CommonParameters::locationXY& endPointOfSegment ) const;
197 
198  // Function determine if then inputed point locate at the left of the segment on the surface of the upper element
200  const CommonParameters::locationXY& startPointOfSegment, const CommonParameters::locationXY& endPointOfSegment ) const;
201 
202  // Function determine if then inputed point locate at the left of the segment on the Y-Z plane of boundary
203  bool locateLeftOfSegmentOnYZPlaneOfBoundary( const int iPlane, const int iElem, const int iEdge, const CommonParameters::locationYZ& point ) const;
204 
205  // Function determine if then inputed point locate at the left of the segment on the Z-X plane of boundary
206  bool locateLeftOfSegmentOnZXPlaneOfBoundary( const int iPlane, const int iElem, const int iEdge, const CommonParameters::locationZX& point ) const;
207 
208  // Calculate volume of tetrahedron
209  double calcVolume( const CommonParameters::locationXYZ& point1, const CommonParameters::locationXYZ& point2,
210  const CommonParameters::locationXYZ& point3, const CommonParameters::locationXYZ& point4 ) const;
211 
212  // Calculate volume coordinates of point on the land surface
213  void calcVolumeCoordsOfPointOnLandSurface( const int elemID, const int faceID, const CommonParameters::locationXY& pointCoord, CommonParameters::VolumeCoords& coords ) const;
214 
215  // Calculate volume coordinates of the nputed point
216  void calcVolumeCoordsOfPoint( const int elemID, const CommonParameters::locationXYZ& pointCoord, CommonParameters::VolumeCoords& coords ) const;
217 
218  // Calculate area coordinates of point on the land surface
219  void calcAreaCoordsOfPointOnLandSurface( const int elemID, const int faceID, const CommonParameters::locationXY& pointCoord, CommonParameters::AreaCoords& coords ) const;
220 
221  // Calculate area of triangle from two dimensinal coordinates
222  double calcArea( const CommonParameters::CoordPair& point1, const CommonParameters::CoordPair& point2, const CommonParameters::CoordPair& point3 ) const;
223 
224  // Calculate area coordinates of the specified point on the Y-Z plane of boundary
225  void calcAreaCoordsOfPointOnYZPlaneOfBoundary( const int iPlane, const int iElem, const CommonParameters::CoordPair& point, CommonParameters::AreaCoords& coords ) const;
226 
227  // Calculate area coordinates of the specified point on the Z-X plane of boundary
228  void calcAreaCoordsOfPointOnZXPlaneOfBoundary( const int iPlane, const int iElem, const CommonParameters::CoordPair& point, CommonParameters::AreaCoords& coords ) const;
229 
230  // Decide whether specified point locate inside of face
231  bool locateInsideOfFace( const int elemID, const int faceID, const CommonParameters::locationXYZ& loc ) const;
232 
233 };
234 #endif
Definition: MeshDataTetraElement.h:32
virtual void inputMeshData()
Definition: MeshDataTetraElement.cpp:137
virtual void outputMeshDataToBinary() const
Definition: MeshDataTetraElement.cpp:1132
double getCoordZFromElementBoundaryPlanes(const int iPlane, const int iElem, const int num) const
Definition: MeshDataTetraElement.cpp:1429
double calcAreaWithSignFromAreaCoords(const int elemID, const int faceID, const CommonParameters::AreaCoords &coord0, const CommonParameters::AreaCoords &coord1, const CommonParameters::AreaCoords &coord2) const
Definition: MeshDataTetraElement.cpp:2012
int getNodeIDGlobalFromElementAndEdge(const int iElem, const int iEdge, const int num) const
Definition: MeshDataTetraElement.cpp:1344
int * m_elemOnLandSurface
Definition: MeshDataTetraElement.h:180
int getNodeIDGlobalFromElementAndEdgeBoundaryPlanes(const int iPlane, const int iElem, const int iEdge, const int num) const
Definition: MeshDataTetraElement.cpp:1438
double calcAreaOfFaceAtBottomOfMesh(const int iElem) const
Definition: MeshDataTetraElement.cpp:2070
double calcAreaOfFace(const int iElem, const int iFace) const
Definition: MeshDataTetraElement.cpp:2047
void calcVolumeCoordsOfPoint(const int elemID, const CommonParameters::locationXYZ &pointCoord, CommonParameters::VolumeCoords &coords) const
! :
Definition: MeshDataTetraElement.cpp:2115
void calcVolumeCoordFromAreaCoord(const int iFace, const CommonParameters::AreaCoords &areaCoord, CommonParameters::VolumeCoords &volumeCoord) const
Definition: MeshDataTetraElement.cpp:1941
virtual bool shareSameEdges(const int elemID1, const int elemID2) const
Definition: MeshDataTetraElement.cpp:1050
int getMeshType() const
Definition: MeshDataTetraElement.cpp:1278
double calcHorizontalCoordDifferenceBoundaryPlanes(const int iPlane, const int iElem, const int iEdge) const
Definition: MeshDataTetraElement.cpp:1812
static const double m_eps
Definition: MeshDataTetraElement.h:165
virtual int getNodesOfElementsBoundaryPlanes(const int iPlane, const int iElem, const int iNode) const
Definition: MeshDataTetraElement.cpp:1244
double calcXCoordOfPointOnFace(const int iElem, const int iFace, const CommonParameters::AreaCoords &areaCoord) const
Definition: MeshDataTetraElement.cpp:1839
int m_faceID2EdgeID[4][3]
Definition: MeshDataTetraElement.h:189
bool locateLeftOfSegmentOnZXPlaneOfBoundary(const int iPlane, const int iElem, const int iEdge, const CommonParameters::locationZX &point) const
Definition: MeshDataTetraElement.cpp:1646
virtual void outputMeshDataToVTK() const
Definition: MeshDataTetraElement.cpp:1097
int findElementIncludingPointOnSurface(const double locX, const double locY, int &faceID, CommonParameters::AreaCoords &localCoord, const bool useUpperElem, const bool modLoc, double &locXMod, double &locYMod) const
Definition: MeshDataTetraElement.cpp:388
void calcAreaCoordsOfPointOnZXPlaneOfBoundary(const int iPlane, const int iElem, const CommonParameters::CoordPair &point, CommonParameters::AreaCoords &coords) const
Definition: MeshDataTetraElement.cpp:2250
MeshDataTetraElement & operator=(const MeshDataTetraElement &rhs)
Definition: MeshDataTetraElement.cpp:1572
int m_edgeID2NodeID[6][2]
Definition: MeshDataTetraElement.h:192
int getNodeIDGlobalFromElementBoundaryPlanes(const int iPlane, const int iElem, const int num) const
Definition: MeshDataTetraElement.cpp:1383
double getCoordYFromElementBoundaryPlanes(const int iPlane, const int iElem, const int num) const
Definition: MeshDataTetraElement.cpp:1421
MeshDataTetraElement()
Definition: MeshDataTetraElement.cpp:44
int findElementIncludingPointOnYZPlaneAndReturnElemID2D(const int iPlane, const double locY, const double locZ, CommonParameters::AreaCoords &localCoord) const
Definition: MeshDataTetraElement.cpp:553
bool locateInsideOfFace(const int elemID, const int faceID, const CommonParameters::locationXYZ &loc) const
! :
Definition: MeshDataTetraElement.cpp:2339
bool locateLeftOfSegmentOnSeaSurface(const CommonParameters::locationXY &point, const CommonParameters::locationXY &startPointOfSegment, const CommonParameters::locationXY &endPointOfSegment) const
Definition: MeshDataTetraElement.cpp:1598
int findElementIncludingPoint(const double locX, const double locY, const double locZ, CommonParameters::VolumeCoords &localCoord) const
Definition: MeshDataTetraElement.cpp:356
double calcEdgeLengthProjectedOnHorizontalPlaneFromElementAndEdge(const int iElem, const int iEdge) const
Definition: MeshDataTetraElement.cpp:1747
void calcVolumeCoordsOfPointOnLandSurface(const int elemID, const int faceID, const CommonParameters::locationXY &pointCoord, CommonParameters::VolumeCoords &coords) const
Definition: MeshDataTetraElement.cpp:1700
double calcAreaOnXYPlaneWithSignFromAreaCoords(const int elemID, const int faceID, const CommonParameters::AreaCoords &coord0, const CommonParameters::AreaCoords &coord1, const CommonParameters::AreaCoords &coord2) const
Definition: MeshDataTetraElement.cpp:1981
int findElementIncludingPointOnZXPlaneAndReturnElemID2D(const int iPlane, const double locZ, const double locX, CommonParameters::AreaCoords &localCoord) const
Definition: MeshDataTetraElement.cpp:601
double getCoordXFromElementBoundaryPlanes(const int iPlane, const int iElem, const int num) const
Definition: MeshDataTetraElement.cpp:1413
int getNodeIDLocalFromEdgeIDLocal(const int iEdge, const int num) const
Definition: MeshDataTetraElement.cpp:1324
double calcEdgeLengthFromElementAndEdgeBoundaryPlanes(const int iPlane, const int iElem, const int iEdge) const
Definition: MeshDataTetraElement.cpp:1755
double calcEdgeLengthFromElementAndEdge(const int iElem, const int iEdge) const
Definition: MeshDataTetraElement.cpp:1738
void findElementsIncludingDipoleOnSurface(const double locXStart, const double locYStart, const double locXEnd, const double locYEnd, std::vector< int > &elements, std::vector< int > &faces, std::vector< CommonParameters::AreaCoords > &areaCoordsdStartPoint, std::vector< CommonParameters::AreaCoords > &areaCoordsdEndPoint) const
Definition: MeshDataTetraElement.cpp:648
int * m_facesOfElementsBoundaryPlanes[6]
Definition: MeshDataTetraElement.h:174
virtual ~MeshDataTetraElement()
Definition: MeshDataTetraElement.cpp:110
int * m_faceLandSurface
Definition: MeshDataTetraElement.h:183
double calcArea(const CommonParameters::CoordPair &point1, const CommonParameters::CoordPair &point2, const CommonParameters::CoordPair &point3) const
Definition: MeshDataTetraElement.cpp:1727
int getNodeIDGlobalFromElementAndFace(const int iElem, const int iFace, const int num) const
Definition: MeshDataTetraElement.cpp:1370
void calcAreaCoordsOfPointOnLandSurface(const int elemID, const int faceID, const CommonParameters::locationXY &pointCoord, CommonParameters::AreaCoords &coords) const
Definition: MeshDataTetraElement.cpp:2161
bool locateLeftOfSegmentOnYZPlaneOfBoundary(const int iPlane, const int iElem, const int iEdge, const CommonParameters::locationYZ &point) const
Definition: MeshDataTetraElement.cpp:1614
int m_faceID2NodeID[4][3]
Definition: MeshDataTetraElement.h:186
int m_numElemOnLandSurface
Definition: MeshDataTetraElement.h:177
double calcZCoordOfPointOnFace(const int iElem, const int iFace, const CommonParameters::AreaCoords &areaCoord) const
Definition: MeshDataTetraElement.cpp:1907
void calcAreaCoordsOfPointOnYZPlaneOfBoundary(const int iPlane, const int iElem, const CommonParameters::CoordPair &point, CommonParameters::AreaCoords &coords) const
Definition: MeshDataTetraElement.cpp:2209
double calcYCoordOfPointOnFace(const int iElem, const int iFace, const CommonParameters::AreaCoords &areaCoord) const
Definition: MeshDataTetraElement.cpp:1873
virtual double calcVolume(const int elemID) const
Definition: MeshDataTetraElement.cpp:1081
bool locateLeftOfSegmentOnLandSurface(const CommonParameters::locationXY &point, const CommonParameters::locationXY &startPointOfSegment, const CommonParameters::locationXY &endPointOfSegment) const
Definition: MeshDataTetraElement.cpp:1582
int getEdgeIDLocalFromFaceIDLocal(const int iFace, const int num) const
Definition: MeshDataTetraElement.cpp:1499
int getNodeIDLocalFromFaceIDLocal(const int iFace, const int num) const
Definition: MeshDataTetraElement.cpp:1304
int getFaceIDLocalFromElementBoundaryPlanes(const int iPlane, const int iElem) const
Definition: MeshDataTetraElement.cpp:1281
Definition: MeshData.h:31
Definition: CommonParameters.h:99
Definition: CommonParameters.h:112
Definition: CommonParameters.h:105
Definition: CommonParameters.h:53
Definition: CommonParameters.h:38
Definition: CommonParameters.h:43
Definition: CommonParameters.h:48