libMesh
Loading...
Searching...
No Matches
face_tri6.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18// Local includes
19#include "libmesh/edge_edge3.h"
20#include "libmesh/face_tri6.h"
21#include "libmesh/enum_io_package.h"
22#include "libmesh/enum_order.h"
23
24namespace libMesh
25{
26
27
28
29
30// ------------------------------------------------------------
31// Tri6 class static member initializations
32const int Tri6::num_nodes;
33const int Tri6::nodes_per_side;
34
35
36#ifdef LIBMESH_ENABLE_AMR
37
39 {
40 // embedding matrix for child 0
41 {
42 // 0 1 2 3 4 5
43 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, // 0
44 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, // 1
45 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, // 2
46 {.375, -.125, 0.0, .75, 0.0, 0.0}, // 3
47 { 0.0, -.125, -.125, 0.5, .25, 0.5}, // 4
48 {.375, 0.0, -.125, 0.0, 0.0, .75} // 5
49 },
50
51 // embedding matrix for child 1
52 {
53 // 0 1 2 3 4 5
54 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, // 0
55 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, // 1
56 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, // 2
57 {-.125, .375, 0.0, .75, 0.0, 0.0}, // 3
58 { 0.0, .375, -.125, 0.0, .75, 0.0}, // 4
59 {-.125, 0.0, -.125, 0.5, 0.5, .25} // 5
60 },
61
62 // embedding matrix for child 2
63 {
64 // 0 1 2 3 4 5
65 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, // 0
66 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, // 1
67 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, // 2
68 {-.125, -.125, 0.0, .25, 0.5, 0.5}, // 3
69 { 0.0, -.125, .375, 0.0, .75, 0.0}, // 4
70 {-.125, 0.0, .375, 0.0, 0.0, .75} // 5
71 },
72
73 // embedding matrix for child 3
74 {
75 // 0 1 2 3 4 5
76 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, // 0
77 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, // 1
78 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, // 2
79 {-.125, 0.0, -.125, 0.5, 0.5, .25}, // 3
80 {-.125, -.125, 0.0, .25, 0.5, 0.5}, // 4
81 { 0.0, -.125, -.125, 0.5, .25, 0.5} // 5
82 }
83 };
84
85#endif
86
87
88
89// ------------------------------------------------------------
90// Tri6 class member functions
91
92bool Tri6::is_vertex(const unsigned int i) const
93{
94 if (i < 3)
95 return true;
96 return false;
97}
98
99bool Tri6::is_edge(const unsigned int i) const
100{
101 if (i < 3)
102 return false;
103 return true;
104}
105
106bool Tri6::is_face(const unsigned int) const
107{
108 return false;
109}
110
111bool Tri6::is_node_on_side(const unsigned int n,
112 const unsigned int s) const
113{
114 libmesh_assert_less (s, n_sides());
115 return std::find(std::begin(side_nodes_map[s]),
116 std::end(side_nodes_map[s]),
117 n) != std::end(side_nodes_map[s]);
118}
119
120std::vector<unsigned>
121Tri6::nodes_on_side(const unsigned int s) const
122{
123 libmesh_assert_less(s, n_sides());
124 return {std::begin(side_nodes_map[s]), std::end(side_nodes_map[s])};
125}
126
127std::vector<unsigned>
128Tri6::nodes_on_edge(const unsigned int e) const
129{
130 return nodes_on_side(e);
131}
132
134{
135 // Make sure edges are straight
136 Point v = this->point(1) - this->point(0);
138 ((this->point(3) - this->point(0))*2, affine_tol))
139 return false;
140 v = this->point(2) - this->point(1);
142 ((this->point(4) - this->point(1))*2, affine_tol))
143 return false;
144 v = this->point(2) - this->point(0);
146 ((this->point(5) - this->point(0))*2, affine_tol))
147 return false;
148
149 return true;
150}
151
152
153
155{
156 return SECOND;
157}
158
159
160
161dof_id_type Tri6::key (const unsigned int s) const
162{
163 libmesh_assert_less (s, this->n_sides());
164
165 switch (s)
166 {
167 case 0:
168
169 return
170 this->compute_key (this->node_id(3));
171
172 case 1:
173
174 return
175 this->compute_key (this->node_id(4));
176
177 case 2:
178
179 return
180 this->compute_key (this->node_id(5));
181
182 default:
183 libmesh_error_msg("Invalid side s = " << s);
184 }
185}
186
187
188
189unsigned int Tri6::local_side_node(unsigned int side,
190 unsigned int side_node) const
191{
192 libmesh_assert_less (side, this->n_sides());
193 libmesh_assert_less (side_node, Tri6::nodes_per_side);
194
195 return Tri6::side_nodes_map[side][side_node];
196}
197
198
199
200std::unique_ptr<Elem> Tri6::build_side_ptr (const unsigned int i)
201{
202 return this->simple_build_side_ptr<Edge3, Tri6>(i);
203}
204
205
206
207void Tri6::build_side_ptr (std::unique_ptr<Elem> & side,
208 const unsigned int i)
209{
210 this->simple_build_side_ptr<Tri6>(side, i, EDGE3);
211}
212
213
214
215void Tri6::connectivity(const unsigned int sf,
216 const IOPackage iop,
217 std::vector<dof_id_type> & conn) const
218{
219 libmesh_assert_less (sf, this->n_sub_elem());
220 libmesh_assert_not_equal_to (iop, INVALID_IO_PACKAGE);
221
222 switch (iop)
223 {
224 case TECPLOT:
225 {
226 conn.resize(4);
227 switch(sf)
228 {
229 case 0:
230 // linear sub-triangle 0
231 conn[0] = this->node_id(0)+1;
232 conn[1] = this->node_id(3)+1;
233 conn[2] = this->node_id(5)+1;
234 conn[3] = this->node_id(5)+1;
235
236 return;
237
238 case 1:
239 // linear sub-triangle 1
240 conn[0] = this->node_id(3)+1;
241 conn[1] = this->node_id(1)+1;
242 conn[2] = this->node_id(4)+1;
243 conn[3] = this->node_id(4)+1;
244
245 return;
246
247 case 2:
248 // linear sub-triangle 2
249 conn[0] = this->node_id(5)+1;
250 conn[1] = this->node_id(4)+1;
251 conn[2] = this->node_id(2)+1;
252 conn[3] = this->node_id(2)+1;
253
254 return;
255
256 case 3:
257 // linear sub-triangle 3
258 conn[0] = this->node_id(3)+1;
259 conn[1] = this->node_id(4)+1;
260 conn[2] = this->node_id(5)+1;
261 conn[3] = this->node_id(5)+1;
262
263 return;
264
265 default:
266 libmesh_error_msg("Invalid sf = " << sf);
267 }
268 }
269
270 case VTK:
271 {
272 // VTK_QUADRATIC_TRIANGLE has same numbering as libmesh TRI6
273 conn.resize(Tri6::num_nodes);
274 for (auto i : index_range(conn))
275 conn[i] = this->node_id(i);
276 return;
277 }
278
279 default:
280 libmesh_error_msg("Unsupported IO package " << iop);
281 }
282}
283
284
285
287{
288 // This might have curved edges, or might be a curved surface in
289 // 3-space, in which case the full bounding box can be larger than
290 // the bounding box of just the nodes.
291 //
292 //
293 // FIXME - I haven't yet proven the formula below to be correct for
294 // quadratics in 2D - RHS
295 Point pmin, pmax;
296
297 for (unsigned d=0; d<LIBMESH_DIM; ++d)
298 {
299 Real center = this->point(0)(d);
300 for (unsigned int p=1; p != 6; ++p)
301 center += this->point(p)(d);
302 center /= 6;
303
304 Real hd = std::abs(center - this->point(0)(d));
305 for (unsigned int p=1; p != 6; ++p)
306 hd = std::max(hd, std::abs(center - this->point(p)(d)));
307
308 pmin(d) = center - hd;
309 pmax(d) = center + hd;
310 }
311
312 return BoundingBox(pmin, pmax);
313}
314
315
316
318{
319 // This specialization is good for Lagrange mappings only in general
320 if (this->mapping_type() != LAGRANGE_MAP)
321 return this->Elem::volume();
322
323 Real vol=0.;
324
325#if LIBMESH_DIM > 1
326 // Make copies of our points. It makes the subsequent calculations a bit
327 // shorter and avoids dereferencing the same pointer multiple times.
328 Point
329 x0 = point(0), x1 = point(1), x2 = point(2),
330 x3 = point(3), x4 = point(4), x5 = point(5);
331
332 // Construct constant data vectors.
333 // \vec{x}_{\xi} = \vec{a1}*xi + \vec{b1}*eta + \vec{c1}
334 // \vec{x}_{\eta} = \vec{a2}*xi + \vec{b2}*eta + \vec{c2}
335 Point
336 a1 = 4*x0 + 4*x1 - 8*x3,
337 b1 = 4*x0 - 4*x3 + 4*x4 - 4*x5, /*=a2*/
338 c1 = -3*x0 - 1*x1 + 4*x3,
339 b2 = 4*x0 + 4*x2 - 8*x5,
340 c2 = -3*x0 - 1*x2 + 4*x5;
341
342 // If a1 == b1 == a2 == b2 == 0, this is a TRI6 with straight sides,
343 // and we can use the TRI3 formula to compute the volume.
344 if (a1.relative_fuzzy_equals(Point(0,0,0)) &&
345 b1.relative_fuzzy_equals(Point(0,0,0)) &&
346 b2.relative_fuzzy_equals(Point(0,0,0)))
347 return 0.5 * cross_norm(c1, c2);
348
349 // 7-point rule, exact for quintics.
350 const unsigned int N = 7;
351
352 // Parameters of the quadrature rule
353 static const Real
354 w1 = Real(31)/480 + std::sqrt(Real(15))/2400,
355 w2 = Real(31)/480 - std::sqrt(Real(15))/2400,
356 q1 = Real(2)/7 + std::sqrt(Real(15))/21,
357 q2 = Real(2)/7 - std::sqrt(Real(15))/21;
358
359 static const Real xi[N] = {Real(1)/3, q1, q1, 1-2*q1, q2, q2, 1-2*q2};
360 static const Real eta[N] = {Real(1)/3, q1, 1-2*q1, q1, q2, 1-2*q2, q2};
361 static const Real wts[N] = {Real(9)/80, w1, w1, w1, w2, w2, w2};
362
363 // Approximate the area with quadrature
364 for (unsigned int q=0; q<N; ++q)
365 vol += wts[q] * cross_norm(xi[q]*a1 + eta[q]*b1 + c1,
366 xi[q]*b1 + eta[q]*b2 + c2);
367#endif // LIBMESH_DIM > 1
368
369 return vol;
370}
371
372
373
374unsigned short int Tri6::second_order_adjacent_vertex (const unsigned int n,
375 const unsigned int v) const
376{
377 libmesh_assert_greater_equal (n, this->n_vertices());
378 libmesh_assert_less (n, this->n_nodes());
379 libmesh_assert_less (v, 2);
380 return _second_order_adjacent_vertices[n-this->n_vertices()][v];
381}
382
383
384
385const unsigned short int Tri6::_second_order_adjacent_vertices[Tri6::num_sides][2] =
386 {
387 {0, 1}, // vertices adjacent to node 3
388 {1, 2}, // vertices adjacent to node 4
389 {0, 2} // vertices adjacent to node 5
390 };
391
392
393
394std::pair<unsigned short int, unsigned short int>
395Tri6::second_order_child_vertex (const unsigned int n) const
396{
397 libmesh_assert_greater_equal (n, this->n_vertices());
398 libmesh_assert_less (n, this->n_nodes());
399 return std::pair<unsigned short int, unsigned short int>
402}
403
404
405
407 {
408 99,99,99, // Vertices
409 0,1,0 // Edges
410 };
411
412
413
415 {
416 99,99,99, // Vertices
417 1,2,2 // Edges
418 };
419
420
421void Tri6::permute(unsigned int perm_num)
422{
423 libmesh_assert_less (perm_num, 3);
424
425 for (unsigned int i = 0; i != perm_num; ++i)
426 {
427 swap3nodes(0,1,2);
428 swap3nodes(3,4,5);
429 swap3neighbors(0,1,2);
430 }
431}
432
433
434void Tri6::flip(BoundaryInfo * boundary_info)
435{
436 libmesh_assert(boundary_info);
437
438 swap2nodes(0,1);
439 swap2nodes(4,5);
440 swap2neighbors(1,2);
441 swap2boundarysides(1,2,boundary_info);
442 swap2boundaryedges(1,2,boundary_info);
443}
444
445
446unsigned int Tri6::center_node_on_side(const unsigned short side) const
447{
448 libmesh_assert_less (side, Tri6::num_sides);
449 return side + 3;
450}
451
452
454Tri6::side_type (const unsigned int libmesh_dbg_var(s)) const
455{
456 libmesh_assert_less (s, 3);
457 return EDGE3;
458}
459
460
461} // namespace libMesh
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
Defines a Cartesian bounding box by the two corner extremum.
static constexpr Real affine_tol
Default tolerance to use in has_affine_map().
Definition elem.h:2191
const Point & point(const unsigned int i) const
Definition elem.h:2583
void swap2nodes(unsigned int n1, unsigned int n2)
Swaps two node_ptrs.
Definition elem.h:2222
void swap3neighbors(unsigned int n1, unsigned int n2, unsigned int n3)
Swaps three neighbor_ptrs, "rotating" them.
Definition elem.h:2263
void swap2neighbors(unsigned int n1, unsigned int n2)
Swaps two neighbor_ptrs.
Definition elem.h:2232
void swap2boundarysides(unsigned short s1, unsigned short s2, BoundaryInfo *boundary_info) const
Swaps two sides in boundary_info, if it is non-null.
Definition elem.C:3982
ElemMappingType mapping_type() const
Definition elem.h:3258
static dof_id_type compute_key(dof_id_type n0)
Definition elem.h:3432
void swap3nodes(unsigned int n1, unsigned int n2, unsigned int n3)
Swaps three node_ptrs, "rotating" them.
Definition elem.h:2254
virtual Real volume() const
Definition elem.C:3865
void swap2boundaryedges(unsigned short e1, unsigned short e2, BoundaryInfo *boundary_info) const
Swaps two edges in boundary_info, if it is non-null.
Definition elem.C:3998
dof_id_type node_id(const unsigned int i) const
Definition elem.h:2605
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:41
virtual std::vector< unsigned int > nodes_on_edge(const unsigned int e) const override
Definition face_tri6.C:128
virtual void flip(BoundaryInfo *) override final
Flips the element (by swapping node and neighbor pointers) to have a mapping Jacobian of opposite sig...
Definition face_tri6.C:434
virtual bool has_affine_map() const override
Definition face_tri6.C:133
virtual bool is_node_on_side(const unsigned int n, const unsigned int s) const override
Definition face_tri6.C:111
virtual bool is_edge(const unsigned int i) const override
Definition face_tri6.C:99
static const int nodes_per_side
Definition face_tri6.h:203
virtual bool is_vertex(const unsigned int i) const override
Definition face_tri6.C:92
unsigned int center_node_on_side(const unsigned short side) const override final
Definition face_tri6.C:446
ElemType side_type(const unsigned int s) const override final
Definition face_tri6.C:454
virtual void permute(unsigned int perm_num) override final
Permutes the element (by swapping node and neighbor pointers) according to the specified index.
Definition face_tri6.C:421
static const unsigned short int _second_order_adjacent_vertices[num_sides][2]
Matrix that tells which vertices define the location of mid-side (or second-order) nodes.
Definition face_tri6.h:269
virtual unsigned int local_side_node(unsigned int side, unsigned int side_node) const override
Definition face_tri6.C:189
virtual bool is_face(const unsigned int i) const override
Definition face_tri6.C:106
static const unsigned short int _second_order_vertex_child_index[num_nodes]
Vector that names the child vertex index for each second order node.
Definition face_tri6.h:279
virtual dof_id_type key() const
Don't hide Elem::key() defined in the base class.
Definition elem.C:678
virtual BoundingBox loose_bounding_box() const override
Definition face_tri6.C:286
static const Real _embedding_matrix[num_children][num_nodes][num_nodes]
Matrix that computes new nodal locations/solution values from current nodes/solution.
Definition face_tri6.h:257
static const int num_nodes
Geometric constants for Tri6.
Definition face_tri6.h:202
virtual std::vector< unsigned int > nodes_on_side(const unsigned int s) const override
Definition face_tri6.C:121
static const unsigned short int _second_order_vertex_child_number[num_nodes]
Vector that names a child sharing each second order node.
Definition face_tri6.h:274
virtual unsigned short int second_order_adjacent_vertex(const unsigned int n, const unsigned int v) const override
Definition face_tri6.C:374
virtual Real volume() const override
An optimized method for approximating the area of a TRI6 using quadrature.
Definition face_tri6.C:317
virtual unsigned int n_nodes() const override
Definition face_tri6.h:88
virtual unsigned int n_sub_elem() const override
Definition face_tri6.h:93
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i) override
Definition face_tri6.C:200
virtual Order default_order() const override
Definition face_tri6.C:154
static constexpr const unsigned int(& side_nodes_map)[num_sides][nodes_per_side]
Definition face_tri6.h:212
virtual void connectivity(const unsigned int sf, const IOPackage iop, std::vector< dof_id_type > &conn) const override
Definition face_tri6.C:215
virtual std::pair< unsigned short int, unsigned short int > second_order_child_vertex(const unsigned int n) const override
Definition face_tri6.C:395
virtual unsigned int n_vertices() const override final
Definition face_tri.h:103
static const int num_children
Definition face_tri.h:87
virtual unsigned int n_sides() const override final
Definition face_tri.h:98
static const int num_sides
Geometric constants for all Tris.
Definition face_tri.h:86
bool relative_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
The libMesh namespace provides an interface to certain functionality in the library.
LIBMESH_DEVICE_INLINE T cross_norm(const TypeVector< T > &b, const TypeVector< T > &c)
Calls cross_norm_sq() and takes the square root of the result.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
IOPackage
libMesh interfaces with several different software packages for the purposes of creating,...
ElemType
Defines an enum for geometric element types.
libmesh_assert(ctx)
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real