OGS
MapBulkElementPoint.cpp
Go to the documentation of this file.
1
11#include "MapBulkElementPoint.h"
12
13#include <array>
14
15namespace
16{
21MathLib::Point3d getBulkElementPointLine(std::size_t const face_id)
22{
23 switch (face_id)
24 {
25 case 0:
26 return MathLib::Point3d{{-1, 0, 0}};
27 case 1:
28 return MathLib::Point3d{{1, 0, 0}};
29 default:
30 OGS_FATAL("Invalid face id '{:d}' for a line.", face_id);
31 }
32}
33
42MathLib::Point3d getBulkElementPointTri(std::size_t const face_id,
43 MathLib::WeightedPoint const& wp)
44{
45 // wp is a local coordinate of the 1D line face of the triangle. I.e., wp
46 // has only one relevant coordinate. This coordinate runs from -1 to 1.
47 auto const r = 0.5 * (wp[0] + 1); // in [0, 1]
48
49 switch (face_id)
50 {
51 case 0:
52 return MathLib::Point3d{{r, 0, 0}};
53 case 1:
54 return MathLib::Point3d{{1 - r, r, 0}};
55 case 2:
56 return MathLib::Point3d{{0, 1 - r, 0}};
57 default:
58 OGS_FATAL("Invalid face id '{:d}' for the tri.", face_id);
59 }
60}
61
70MathLib::Point3d getBulkElementPointQuad(std::size_t const face_id,
71 MathLib::WeightedPoint const& wp)
72{
73 auto const r = wp[0];
74
75 switch (face_id)
76 {
77 case 0:
78 return MathLib::Point3d{{-r, +1, 0}};
79 case 1:
80 return MathLib::Point3d{{-1, -r, 0}};
81 case 2:
82 return MathLib::Point3d{{+r, -1, 0}};
83 case 3:
84 return MathLib::Point3d{{+1, +r, 0}};
85 default:
86 OGS_FATAL("Invalid face id '{:d}' for the quad.", face_id);
87 }
88}
89
95MathLib::Point3d getBulkElementPointHex(std::size_t const face_id,
96 MathLib::WeightedPoint const& wp)
97{
98 auto const r = wp[0];
99 auto const s = wp[1];
100
101 switch (face_id)
102 {
103 case 0:
104 return MathLib::Point3d{{-s, -r, -1}};
105 case 1:
106 return MathLib::Point3d{{-r, -1, -s}};
107 case 2:
108 return MathLib::Point3d{{+1, -r, -s}};
109 case 3:
110 return MathLib::Point3d{{+r, +1, -s}};
111 case 4:
112 return MathLib::Point3d{{-1, +r, -s}};
113 case 5:
114 return MathLib::Point3d{{-r, -s, +1}};
115 default:
116 OGS_FATAL("Invalid face id '{:d}' for the hexahedron.", face_id);
117 }
118}
119
124 MathLib::WeightedPoint const& wp)
125{
126 auto const r = wp[0];
127 auto const s = wp[1];
128
129 switch (face_id)
130 {
131 case 0:
132 // tri, top; r, s in [0, 1]
133 return MathLib::Point3d{{s, r, -1}};
134 case 1:
135 {
136 // quad; r, s in [-1, 1]
137 auto const r01 = 0.5 * (r + 1); // in [0, 1]
138 return MathLib::Point3d{{1 - r01, 0, -s}};
139 }
140 case 2:
141 {
142 // quad; r, s in [-1, 1]
143 auto const r01 = 0.5 * (r + 1); // in [0, 1]
144 return MathLib::Point3d{{r01, 1 - r01, -s}};
145 }
146 case 3:
147 {
148 // quad; r, s in [-1, 1]
149 auto const r01 = 0.5 * (r + 1); // in [0, 1]
150 return MathLib::Point3d{{0, r01, -s}};
151 }
152 case 4:
153 // tri, bottom; r, s in [0, 1]
154 return MathLib::Point3d{{r, s, 1}};
155 default:
156 OGS_FATAL("Invalid face id '{:d}' for the prism.", face_id);
157 }
158}
159
164 MathLib::WeightedPoint const& wp)
165{
166 auto const r = wp[0]; // in [0, 1] on tri faces, in [-1, 1] on quad face
167 auto const s = wp[1]; // in [0, 1] on tri faces, in [-1, 1] on quad face
168
169 // for tri phases, note: there r + s == 1, i.e., s == 1 => r == 0
170 auto const z = 2 * s - 1; // in [-1, 1] on tri faces
171 auto const w = s == 1 ? -1 : 2 * r / (1 - s) - 1;
172
173 switch (face_id)
174 {
175 case 0:
176 return MathLib::Point3d{{+w, -1.0, z}};
177 case 1:
178 return MathLib::Point3d{{+1.0, +w, z}};
179 case 2:
180 return MathLib::Point3d{{-w, +1.0, z}};
181 case 3:
182 return MathLib::Point3d{{-1.0, -w, z}};
183 case 4:
184 return MathLib::Point3d{{-s, -r, -1.0}};
185 default:
186 OGS_FATAL("Invalid face id '{:d}' for the pyramid.", face_id);
187 }
188}
189
193MathLib::Point3d getBulkElementPointTet(std::size_t const face_id,
194 MathLib::WeightedPoint const& wp)
195{
196 auto const r = wp[0];
197 auto const s = wp[1];
198 auto const t = 1 - r - s;
199
200 switch (face_id)
201 {
202 case 0:
203 return MathLib::Point3d{{s, r, 0}};
204 case 1:
205 return MathLib::Point3d{{r, 0, s}};
206 case 2:
207 return MathLib::Point3d{{t, r, s}};
208 case 3:
209 return MathLib::Point3d{{0, t, s}};
210 default:
211 OGS_FATAL("Invalid face id '{:d}' for the tetrahedron.", face_id);
212 }
213}
214
215} // namespace
216
217namespace MeshLib
218{
220 MeshLib::CellType const bulk_element_cell_type,
221 std::size_t const bulk_face_id,
222 MathLib::WeightedPoint const& point_on_face)
223{
224 if (point_on_face.getDimension() == 3)
225 {
226 // TODO disable the 3d elements in the local assembler creator
227 return MathLib::ORIGIN;
228 }
229
230 switch (bulk_element_cell_type)
231 {
232 // 3D bulk elements
233 case CellType::HEX8:
234 return getBulkElementPointHex(bulk_face_id, point_on_face);
235 case CellType::PRISM6:
236 return getBulkElementPointPrism(bulk_face_id, point_on_face);
238 return getBulkElementPointPyramid(bulk_face_id, point_on_face);
239 case CellType::TET4:
240 return getBulkElementPointTet(bulk_face_id, point_on_face);
241 // 2D bulk elements
242 case CellType::QUAD4:
243 return getBulkElementPointQuad(bulk_face_id, point_on_face);
244 case CellType::TRI3:
245 return getBulkElementPointTri(bulk_face_id, point_on_face);
246 // 1D bulk elements
247 case CellType::LINE2:
248 return getBulkElementPointLine(bulk_face_id);
249 default:
250 OGS_FATAL(
251 "Wrong cell type '{:s}' or functionality not yet implemented.",
252 CellType2String(bulk_element_cell_type));
253 }
254}
255} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:26
std::size_t getDimension() const
The point dimension, i.e., the number of its coordinates.
const Point3d ORIGIN
Definition Point3d.h:97
MathLib::Point3d getBulkElementPoint(MeshLib::CellType const bulk_element_cell_type, std::size_t const bulk_face_id, MathLib::WeightedPoint const &point_on_face)
CellType
Types of mesh elements supported by OpenGeoSys.
Definition MeshEnums.h:43
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
MathLib::Point3d getBulkElementPointLine(std::size_t const face_id)
MathLib::Point3d getBulkElementPointTri(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointTet(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointQuad(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointPrism(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointHex(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointPyramid(std::size_t const face_id, MathLib::WeightedPoint const &wp)