OGS
MapBulkElementPoint.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <array>
7
8namespace
9{
14MathLib::Point3d getBulkElementPointLine(std::size_t const face_id)
15{
16 switch (face_id)
17 {
18 case 0:
19 return MathLib::Point3d{{-1, 0, 0}};
20 case 1:
21 return MathLib::Point3d{{1, 0, 0}};
22 default:
23 OGS_FATAL("Invalid face id '{:d}' for a line.", face_id);
24 }
25}
26
35MathLib::Point3d getBulkElementPointTri(std::size_t const face_id,
36 MathLib::WeightedPoint const& wp)
37{
38 // wp is a local coordinate of the 1D line face of the triangle. I.e., wp
39 // has only one relevant coordinate. This coordinate runs from -1 to 1.
40 auto const r = 0.5 * (wp[0] + 1); // in [0, 1]
41
42 switch (face_id)
43 {
44 case 0:
45 return MathLib::Point3d{{r, 0, 0}};
46 case 1:
47 return MathLib::Point3d{{1 - r, r, 0}};
48 case 2:
49 return MathLib::Point3d{{0, 1 - r, 0}};
50 default:
51 OGS_FATAL("Invalid face id '{:d}' for the tri.", face_id);
52 }
53}
54
63MathLib::Point3d getBulkElementPointQuad(std::size_t const face_id,
64 MathLib::WeightedPoint const& wp)
65{
66 auto const r = wp[0];
67
68 switch (face_id)
69 {
70 case 0:
71 return MathLib::Point3d{{-r, +1, 0}};
72 case 1:
73 return MathLib::Point3d{{-1, -r, 0}};
74 case 2:
75 return MathLib::Point3d{{+r, -1, 0}};
76 case 3:
77 return MathLib::Point3d{{+1, +r, 0}};
78 default:
79 OGS_FATAL("Invalid face id '{:d}' for the quad.", face_id);
80 }
81}
82
88MathLib::Point3d getBulkElementPointHex(std::size_t const face_id,
89 MathLib::WeightedPoint const& wp)
90{
91 auto const r = wp[0];
92 auto const s = wp[1];
93
94 switch (face_id)
95 {
96 case 0:
97 return MathLib::Point3d{{-s, -r, -1}};
98 case 1:
99 return MathLib::Point3d{{-r, -1, -s}};
100 case 2:
101 return MathLib::Point3d{{+1, -r, -s}};
102 case 3:
103 return MathLib::Point3d{{+r, +1, -s}};
104 case 4:
105 return MathLib::Point3d{{-1, +r, -s}};
106 case 5:
107 return MathLib::Point3d{{-r, -s, +1}};
108 default:
109 OGS_FATAL("Invalid face id '{:d}' for the hexahedron.", face_id);
110 }
111}
112
117 MathLib::WeightedPoint const& wp)
118{
119 auto const r = wp[0];
120 auto const s = wp[1];
121
122 switch (face_id)
123 {
124 case 0:
125 // tri, top; r, s in [0, 1]
126 return MathLib::Point3d{{s, r, -1}};
127 case 1:
128 {
129 // quad; r, s in [-1, 1]
130 auto const r01 = 0.5 * (r + 1); // in [0, 1]
131 return MathLib::Point3d{{1 - r01, 0, -s}};
132 }
133 case 2:
134 {
135 // quad; r, s in [-1, 1]
136 auto const r01 = 0.5 * (r + 1); // in [0, 1]
137 return MathLib::Point3d{{r01, 1 - r01, -s}};
138 }
139 case 3:
140 {
141 // quad; r, s in [-1, 1]
142 auto const r01 = 0.5 * (r + 1); // in [0, 1]
143 return MathLib::Point3d{{0, r01, -s}};
144 }
145 case 4:
146 // tri, bottom; r, s in [0, 1]
147 return MathLib::Point3d{{r, s, 1}};
148 default:
149 OGS_FATAL("Invalid face id '{:d}' for the prism.", face_id);
150 }
151}
152
157 MathLib::WeightedPoint const& wp)
158{
159 auto const r = wp[0]; // in [0, 1] on tri faces, in [-1, 1] on quad face
160 auto const s = wp[1]; // in [0, 1] on tri faces, in [-1, 1] on quad face
161
162 // for tri phases, note: there r + s == 1, i.e., s == 1 => r == 0
163 auto const z = 2 * s - 1; // in [-1, 1] on tri faces
164 auto const w = s == 1 ? -1 : 2 * r / (1 - s) - 1;
165
166 switch (face_id)
167 {
168 case 0:
169 return MathLib::Point3d{{+w, -1.0, z}};
170 case 1:
171 return MathLib::Point3d{{+1.0, +w, z}};
172 case 2:
173 return MathLib::Point3d{{-w, +1.0, z}};
174 case 3:
175 return MathLib::Point3d{{-1.0, -w, z}};
176 case 4:
177 return MathLib::Point3d{{-s, -r, -1.0}};
178 default:
179 OGS_FATAL("Invalid face id '{:d}' for the pyramid.", face_id);
180 }
181}
182
186MathLib::Point3d getBulkElementPointTet(std::size_t const face_id,
187 MathLib::WeightedPoint const& wp)
188{
189 auto const r = wp[0];
190 auto const s = wp[1];
191 auto const t = 1 - r - s;
192
193 switch (face_id)
194 {
195 case 0:
196 return MathLib::Point3d{{s, r, 0}};
197 case 1:
198 return MathLib::Point3d{{r, 0, s}};
199 case 2:
200 return MathLib::Point3d{{t, r, s}};
201 case 3:
202 return MathLib::Point3d{{0, t, s}};
203 default:
204 OGS_FATAL("Invalid face id '{:d}' for the tetrahedron.", face_id);
205 }
206}
207
208} // namespace
209
210namespace MeshLib
211{
213 MeshLib::CellType const bulk_element_cell_type,
214 std::size_t const bulk_face_id,
215 MathLib::WeightedPoint const& point_on_face)
216{
217 if (point_on_face.getDimension() == 3)
218 {
219 // TODO disable the 3d elements in the local assembler creator
220 return MathLib::ORIGIN;
221 }
222
223 switch (bulk_element_cell_type)
224 {
225 // 3D bulk elements
226 case CellType::HEX8:
227 return getBulkElementPointHex(bulk_face_id, point_on_face);
228 case CellType::PRISM6:
229 return getBulkElementPointPrism(bulk_face_id, point_on_face);
231 return getBulkElementPointPyramid(bulk_face_id, point_on_face);
232 case CellType::TET4:
233 return getBulkElementPointTet(bulk_face_id, point_on_face);
234 // 2D bulk elements
235 case CellType::QUAD4:
236 return getBulkElementPointQuad(bulk_face_id, point_on_face);
237 case CellType::TRI3:
238 return getBulkElementPointTri(bulk_face_id, point_on_face);
239 // 1D bulk elements
240 case CellType::LINE2:
241 return getBulkElementPointLine(bulk_face_id);
242 default:
243 OGS_FATAL(
244 "Wrong cell type '{:s}' or functionality not yet implemented.",
245 CellType2String(bulk_element_cell_type));
246 }
247}
248} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:19
constexpr std::size_t getDimension() const
The point dimension, i.e., the number of its coordinates.
const Point3d ORIGIN
Definition Point3d.h:89
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:53
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)