Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
BarycentricGeomShapeComputer.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* BarycentricGeomShapeComputer.cc (C) 2000-2026 */
9/* */
10/* Calculation of GeomShapes using barycenters. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/IMesh.h"
15
16#include "arcane/core/AbstractItemOperationByBasicType.h"
17
18#include "arcane/geometry/BarycentricGeomShapeComputer.h"
19#include "arcane/geometry/GeomShapeMng.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::geometric
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30/*!
31 * \brief Calculates the positions of the nodes of a quadrilateral cell.
32 */
33template <> void BarycentricGeomShapeComputer::
34compute<GeomType::Quad4>(GeomShapeMutableView elem)
35{
36 const Real3 nul_vector = Real3(0., 0., 0.);
37
38 // Calculates the center position.
39 Real3 c = nul_vector;
40
41 for (Integer i = 0; i < 4; ++i) {
42 c += elem.node(i);
43 }
44 elem.setCenter(0.25 * c);
45
46 // Calculates the position of the face centers.
47 _setFace2D(0, elem, 0, 1);
48 _setFace2D(1, elem, 1, 2);
49 _setFace2D(2, elem, 2, 3);
50 _setFace2D(3, elem, 3, 0);
51}
52
53/*!
54 * \brief Calculates the positions of the nodes of a quadrilateral cell.
55 */
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
65/*!
66 * \brief Calculates the positions of the nodes of a triangular cell.
67 *
68 * It is considered a degenerate quadrangle.
69 */
70template <> void BarycentricGeomShapeComputer::
71compute<GeomType::Triangle3>(GeomShapeMutableView elem)
72{
73 const Real3 nul_vector = Real3(0., 0., 0.);
74
75 Real3 c = nul_vector;
76
77 // Calculates the center position.
78 for (Integer i = 0; i < 3; ++i)
79 c += elem.node(i);
80
81 elem.setCenter(c / 3.0);
82
83 // Calculates the position of the face barycenters.
84 _setFace2D(0, elem, 0, 1);
85 _setFace2D(1, elem, 1, 2);
86 _setFace2D(2, elem, 2, 0);
87
88 elem.setFace(3, elem.node(0));
89}
90
91/*!
92 * \brief Calculates the positions of the nodes of a triangular cell.
93 *
94 * It is considered a degenerate quadrangle.
95 */
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
105/*!
106 * \brief Calculates the positions of the nodes of a hexahedral cell.
107 */
108template <> void BarycentricGeomShapeComputer::
109compute<GeomType::Hexaedron8>(GeomShapeMutableView elem)
110{
111 const Real3 nul_vector = Real3(0., 0., 0.);
112
113 // Calculates the center position.
114 Real3 c = nul_vector;
115
116 for (Integer i = 0; i < 8; ++i)
117 c += elem.node(i);
118
119 elem.setCenter(0.125 * c);
120
121 // Calculates the position of the face centers.
122 _setFace3D(0, elem, 0, 3, 2, 1);
123 _setFace3D(1, elem, 0, 4, 7, 3);
124 _setFace3D(2, elem, 0, 1, 5, 4);
125 _setFace3D(3, elem, 4, 5, 6, 7);
126 _setFace3D(4, elem, 1, 2, 6, 5);
127 _setFace3D(5, elem, 2, 3, 7, 6);
128}
129
130/*!
131 * \brief Calculates the positions of the nodes of a hexahedral cell.
132 */
138
139/*---------------------------------------------------------------------------*/
140/*---------------------------------------------------------------------------*/
141
142/*!
143 * \brief Calculates the positions of the nodes of a pyramidal cell.
144 */
145template <> void BarycentricGeomShapeComputer::
146compute<GeomType::Pyramid5>(GeomShapeMutableView elem)
147{
148 const Real3 nul_vector = Real3(0., 0., 0.);
149
150 // Calculates the center position.
151 Real3 c = nul_vector;
152
153 for (Integer i = 0; i < 5; ++i)
154 c += elem.node(i);
155 elem.setCenter(0.2 * c);
156
157 // Calculates the position of the face barycenters.
158 _setFace3D(0, elem, 0, 3, 2, 1);
159 _setFace3D(1, elem, 0, 4, 3);
160 _setFace3D(2, elem, 0, 1, 4);
161 _setFace3D(3, elem, 1, 2, 4);
162 _setFace3D(4, elem, 2, 3, 4);
163
164 // For compatibility with pyra_face_connectic
165 elem.setFace(5, elem.node(4));
166}
167
168/*!
169 * \brief Calculates the positions of the nodes of a pyramidal cell.
170 */
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180/*!
181 * \brief Calculates the positions of the nodes of a pentahedral cell.
182 */
183template <> void BarycentricGeomShapeComputer::
184compute<GeomType::Pentaedron6>(GeomShapeMutableView elem)
185{
186 const Real3 nul_vector = Real3(0., 0., 0.);
187
188 // Calculates the center position.
189 Real3 c = nul_vector;
190
191 for (Integer i = 0; i < 6; ++i)
192 c += elem.node(i);
193
194 elem.setCenter((1. / 6.) * c);
195
196 _setFace3D(0, elem, 0, 2, 1);
197 _setFace3D(1, elem, 0, 3, 5, 2);
198 _setFace3D(2, elem, 0, 1, 4, 3);
199 _setFace3D(3, elem, 3, 4, 5);
200 _setFace3D(4, elem, 1, 2, 5, 4);
201}
202
203/*!
204 * \brief Calculates the positions of the nodes of a pentahedral cell.
205 */
211
212/*---------------------------------------------------------------------------*/
213/*---------------------------------------------------------------------------*/
214
215/*!
216 * \brief Calculates the positions of the nodes of a tetrahedral cell.
217 */
218template <> void BarycentricGeomShapeComputer::
219compute<GeomType::Tetraedron4>(GeomShapeMutableView elem)
220{
221 const Real3 nul_vector = Real3(0., 0., 0.);
222
223 // Calculates the center position.
224 Real3 c = nul_vector;
225
226 for (Integer i = 0; i < 4; ++i) {
227 c += elem.node(i);
228 }
229
230 elem.setCenter(0.25 * c);
231
232 _setFace3D(0, elem, 0, 2, 1);
233 _setFace3D(1, elem, 0, 3, 2);
234 _setFace3D(2, elem, 0, 1, 3);
235 _setFace3D(3, elem, 3, 1, 2);
236}
237
238/*!
239 * \brief Calculates the positions of the nodes of a tetrahedral cell.
240 */
246
247/*---------------------------------------------------------------------------*/
248/*---------------------------------------------------------------------------*/
249
250/*!
251 * \brief Calculates the positions of the nodes of a prismatic cell with a pentagonal base.
252 */
253template <> void BarycentricGeomShapeComputer::
254compute<GeomType::Heptaedron10>(GeomShapeMutableView elem)
255{
256 const Real3 nul_vector = Real3(0., 0., 0.);
257
258 // Calculates the center position.
259 Real3 c = nul_vector;
260
261 for (Integer i = 0; i < 10; ++i) {
262 c += elem.node(i);
263 }
264 elem.setCenter(0.1 * c);
265
266 elem.setFace(0, 0.2 * (elem.node(0) + elem.node(4) + elem.node(3) + elem.node(2) + elem.node(1)));
267 elem.setFace(1, 0.2 * (elem.node(5) + elem.node(6) + elem.node(7) + elem.node(8) + elem.node(9)));
268
269 _setFace3D(2, elem, 0, 1, 6, 5);
270 _setFace3D(3, elem, 1, 2, 7, 6);
271 _setFace3D(4, elem, 2, 3, 8, 7);
272 _setFace3D(5, elem, 3, 4, 9, 8);
273 _setFace3D(6, elem, 4, 0, 5, 9);
274}
275
276/*!
277 * \brief Calculates the positions of the nodes of a prismatic cell with a pentagonal base.
278 */
284
285/*---------------------------------------------------------------------------*/
286/*---------------------------------------------------------------------------*/
287
288/*!
289 * \brief Calculates the positions of the nodes of a prismatic cell with a hexagonal base.
290 */
291template <> void BarycentricGeomShapeComputer::
292compute<GeomType::Octaedron12>(GeomShapeMutableView elem)
293{
294 const Real3 nul_vector = Real3(0., 0., 0.);
295
296 // Calculates the center position.
297 Real3 c = nul_vector;
298
299 for (Integer i = 0; i < 12; ++i) {
300 c += elem.node(i);
301 }
302
303 elem.setCenter((1. / 12.) * c);
304
305 elem.setFace(0, (1. / 6.) * (elem.node(0) + elem.node(5) + elem.node(4) + elem.node(3) + elem.node(2) + elem.node(1)));
306 elem.setFace(1, (1. / 6.) * (elem.node(6) + elem.node(7) + elem.node(8) + elem.node(9) + elem.node(10) + elem.node(11)));
307 _setFace3D(2, elem, 0, 1, 7, 6);
308 _setFace3D(3, elem, 1, 2, 8, 7);
309 _setFace3D(4, elem, 2, 3, 9, 8);
310 _setFace3D(5, elem, 3, 4, 10, 9);
311 _setFace3D(6, elem, 4, 5, 11, 10);
312 _setFace3D(7, elem, 5, 0, 6, 11);
313}
314
315/*!
316 * \brief Calculates the positions of the nodes of a prismatic cell with a hexagonal base.
317 */
323
324/*---------------------------------------------------------------------------*/
325/*---------------------------------------------------------------------------*/
326
328computeAll(GeomShapeMutableView elem, const VariableNodeReal3& coords, Cell cell)
329{
330 setNodes(elem, coords, cell);
331
332 switch ((GeomType)cell.type()) {
334 computeHexaedron8(elem);
335 return;
337 computePyramid5(elem);
338 return;
340 computePentaedron6(elem);
341 return;
343 computeTetraedron4(elem);
344 return;
347 return;
349 computeOctaedron12(elem);
350 return;
351 case GeomType::Quad4:
352 computeQuad4(elem);
353 return;
355 computeTriangle3(elem);
356 return;
357 default:
358 throw FatalErrorException(A_FUNCINFO, "Invalid cell type for compute");
359 }
360}
361
362/*---------------------------------------------------------------------------*/
363/*---------------------------------------------------------------------------*/
364
365class BarycentricGeomShapeComputerByType
367{
368 GeomShapeMng m_shape_mng;
369 VariableNodeReal3 m_node_coords;
370
371 public:
372
373 BarycentricGeomShapeComputerByType(GeomShapeMng& shape_mng, VariableNodeReal3& node_coords)
374 : m_shape_mng(shape_mng)
375 , m_node_coords(node_coords)
376 {
377 }
378
379 template <GeomType ItemType> void
380 _applyGeneric(ItemVectorView cells)
381 {
382 ENUMERATE_CELL (i_cell, cells) {
383 Cell cell = *i_cell;
384 GeomShapeMutableView shape_view(m_shape_mng.mutableShapeView(cell));
385 BarycentricGeomShapeComputer::setNodes(shape_view, m_node_coords, cell);
387 }
388 }
389
390 void applyVertex(ItemVectorView cells) override
391 {
392 ARCANE_UNUSED(cells);
393 throw NotImplementedException(A_FUNCINFO);
394 }
395 void applyLine2(ItemVectorView cells) override
396 {
397 ARCANE_UNUSED(cells);
398 throw NotImplementedException(A_FUNCINFO);
399 }
400 void applyPentagon5(ItemVectorView cells) override
401 {
402 ARCANE_UNUSED(cells);
403 throw NotImplementedException(A_FUNCINFO);
404 }
405 void applyHexagon6(ItemVectorView cells) override
406 {
407 ARCANE_UNUSED(cells);
408 throw NotImplementedException(A_FUNCINFO);
409 }
410
411 void applyQuad4(ItemVectorView cells) override
412 {
413 _applyGeneric<GeomType::Quad4>(cells);
414 }
415 void applyTriangle3(ItemVectorView cells) override
416 {
417 _applyGeneric<GeomType::Triangle3>(cells);
418 }
419
420 void applyHexaedron8(ItemVectorView cells) override
421 {
422 _applyGeneric<GeomType::Hexaedron8>(cells);
423 }
424
425 void applyPyramid5(ItemVectorView cells) override
426 {
427 _applyGeneric<GeomType::Pyramid5>(cells);
428 }
429
430 void applyPentaedron6(ItemVectorView cells) override
431 {
432 _applyGeneric<GeomType::Pentaedron6>(cells);
433 }
434
435 void applyTetraedron4(ItemVectorView cells) override
436 {
437 _applyGeneric<GeomType::Tetraedron4>(cells);
438 }
439
440 void applyHeptaedron10(ItemVectorView cells) override
441 {
442 _applyGeneric<GeomType::Heptaedron10>(cells);
443 }
444
445 void applyOctaedron12(ItemVectorView cells) override
446 {
447 _applyGeneric<GeomType::Octaedron12>(cells);
448 }
449};
450
451/*---------------------------------------------------------------------------*/
452/*---------------------------------------------------------------------------*/
453
455computeAll(GeomShapeMng& shape_mng, VariableNodeReal3& coords, const CellGroup& cells)
456{
457 BarycentricGeomShapeComputerByType s(shape_mng, coords);
458 cells.applyOperation(&s);
459}
460
461/*---------------------------------------------------------------------------*/
462/*---------------------------------------------------------------------------*/
463
464} // namespace Arcane::geometric
465
466/*---------------------------------------------------------------------------*/
467/*---------------------------------------------------------------------------*/
#define ENUMERATE_CELL(name, group)
Generic enumerator for a cell group.
Abstract operator on entities sorted by type.
Cell of a mesh.
Definition Item.h:1300
void applyOperation(IItemOperationByBasicType *operation) const
Applies the operation operation to the entities of the group.
Definition ItemGroup.cc:528
View on a vector of entities.
Int16 type() const
Entity type.
Definition Item.h:255
Class managing a 3-dimensional real vector.
Definition Real3.h:132
static void computeTetraedron4(GeomShapeMutableView elem)
Calculates the positions of the nodes of a tetrahedral cell.
static void computeOctaedron12(GeomShapeMutableView elem)
Calculates the positions of the nodes of a prismatic cell with a hexagonal base.
static void setNodes(GeomShapeMutableView elem, const VariableNodeReal3 &node_coord, Cell cell)
Fills the node information of the cell cell with the coordinates of node_coord.
static void computeAll(GeomShapeMutableView elem, const VariableNodeReal3 &coords, Cell cell)
Calculates the information for the cell cell.
static void computeTriangle3(GeomShapeMutableView elem)
Calculates the positions of the nodes of a triangular cell.
static void computeQuad4(GeomShapeMutableView elem)
Calculates the positions of the nodes of a quadrilateral cell.
static void computeHeptaedron10(GeomShapeMutableView elem)
Calculates the positions of the nodes of a prismatic cell with a pentagonal base.
static void compute(GeomShapeMutableView elem)
Template method.
static void computePentaedron6(GeomShapeMutableView elem)
Calculates the positions of the nodes of a pentahedral cell.
static void computePyramid5(GeomShapeMutableView elem)
Calculates the positions of the nodes of a pyramidal cell.
static void computeHexaedron8(GeomShapeMutableView elem)
Calculates the positions of the nodes of a hexahedral cell.
Class managing the GeomShapes of a mesh.
Enumeration specifying the type of polygon or polyhedron associated with a geometric element or shape...
Definition GeomType.h:42
@ Tetraedron4
Tetrahedron.
Definition GeomType.h:62
@ Octaedron12
Hexagonal prism.
Definition GeomType.h:72
@ Heptaedron10
Pentagonal prism.
Definition GeomType.h:70
ItemGroupT< Cell > CellGroup
Group of cells.
Definition ItemTypes.h:184
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
Int32 Integer
Type representing an integer.