Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
BarycentricGeomShapeComputer.h
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.h (C) 2000-2026 */
9/* */
10/* Calculation of GeomShapes using barycenters. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_GEOMETRIC_BARYCENTRICGEOMSHAPECOMPUTER_H
13#define ARCANE_GEOMETRIC_BARYCENTRICGEOMSHAPECOMPUTER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/VariableTypes.h"
18
19#include "arcane/geometry/GeomShapeView.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::geometric
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30/*!
31 * \ingroup ArcaneGeometric
32 * \brief Calculates GeomShapes using barycenters.
33 *
34 * This class allows updating the coordinates of the nodes
35 * of a GeomShape and calculating its center and the center of its faces
36 * using the barycenter formula. These coordinates must
37 * be updated as soon as one of the mesh nodes moves.
38 *
39 * All methods of this class are static and it is therefore
40 * not useful to create instances.
41 *
42 * There are several ways to update:
43 * - via computeAll(GeomShapeMng& shape_mng,VariableNodeReal3& coords,const CellGroup& cells),
44 * in which case all GeomShapes of the cells in \a cells are updated. This is
45 * the most performant method if a large number of
46 * cells must be updated.
47 * - via computeAll(GeomShapeMutableView elem,const VariableNodeReal3& coords,Cell cell)
48 * if you wish to update cell by cell.
49 */
50class ARCANE_GEOMETRY_EXPORT BarycentricGeomShapeComputer
51{
52 public:
53
54 //! Calculates the information for the cell \a cell
55 static void computeAll(GeomShapeMutableView elem, const VariableNodeReal3& coords, Cell cell);
56
57 //! Calculates the information for the cells in the group \a cells
58 static void computeAll(GeomShapeMng& shape_mng, VariableNodeReal3& coords, const CellGroup& cells);
59
60 /*!
61 * \name Calculation of the center and face centers by cell type
62 *
63 * The coordinates of the nodes of \a elem must already have been positioned.
64 */
65 ///@{
66 static void computeTriangle3(GeomShapeMutableView elem);
67 static void computeQuad4(GeomShapeMutableView elem);
69 static void computePyramid5(GeomShapeMutableView elem);
74 ///@}
75
76 /*!
77 * \brief Template method.
78 *
79 * The template parameter \a ItemType must correspond to one of the following types: GeomType::Triangle3, GeomType::Quad4, GeomType::Tetraedron4, GeomType::Pyramid5,
80 * GeomType::Pentaedron6, GeomType::Hexaedron8, GeomType::Heptaedron10, GeomType::Octaedron12.
81 *
82 * The coordinates of the nodes of \a elem must already have been positioned,
83 * for example via the call to setNodes().
84 *
85 * The call is made by specifying the cell type as defined in ArcaneTypes.h.
86 * For example, for a Quad4:
87 \code
88 Cell cell = ...;
89 GeomShapeMng shape_mng = ...;
90 GeomShapeMutableView shape_view(shape_mng.mutableShapeView(cell));
91 BarycentricGeomShapeComputer::compute<GeomType::Quad4>(shape_view);
92 \endcode
93 */
94 template <GeomType ItemType> static void compute(GeomShapeMutableView elem);
95
96 //! Fills the node information of the cell \a cell with the coordinates of \a node_coord.
97 static void setNodes(GeomShapeMutableView elem, const VariableNodeReal3& node_coord, Cell cell)
98 {
99 Integer nb_node = cell.nbNode();
100 for (Integer node_id = 0; node_id < nb_node; ++node_id) {
101 elem.setNode(node_id, node_coord[cell.node(node_id)]);
102 }
103 }
104
105 private:
106
107 inline static void
108 _setFace3D(Integer fid, GeomShapeMutableView& elem, Integer id1, Integer id2, Integer id3, Integer id4)
109 {
110 elem.setFace(fid, 0.25 * (elem.node(id1) + elem.node(id2) + elem.node(id3) + elem.node(id4)));
111 }
112
113 inline static void
114 _setFace3D(Integer fid, GeomShapeMutableView& elem, Integer id1, Integer id2, Integer id3)
115 {
116 elem.setFace(fid, (1.0 / 3.0) * (elem.node(id1) + elem.node(id2) + elem.node(id3)));
117 }
118
119 inline static void
120 _setFace2D(Integer fid, GeomShapeMutableView& elem, Integer id1, Integer id2)
121 {
122 elem.setFace(fid,
123 Real3(0.5 * (elem.node(id1).x + elem.node(id2).x),
124 0.5 * (elem.node(id1).y + elem.node(id2).y),
125 0.0));
126 }
127};
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
131
132} // namespace Arcane::geometric
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
137#endif
Cell of a mesh.
Definition Item.h:1300
Node node(Int32 i) const
i-th node of the entity
Definition Item.h:840
Int32 nbNode() const
Number of nodes of the entity.
Definition Item.h:837
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.
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.