Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
GeomShapeMng.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/* GeomShapeMng.h (C) 2000-2026 */
9/* */
10/* Class managing the GeomShapes of a mesh. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_GEOMETRIC_GEOMSHAPEMNG_H
13#define ARCANE_GEOMETRIC_GEOMSHAPEMNG_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 * \ingroup ArcaneGeometric
31 * \brief Class managing the GeomShapes of a mesh.
32 *
33 * This class stores the information of the geometric shapes (GeomShape) associated
34 * to the mesh cells. For a cell, retrieving a view is done
35 * via the initShape() method:
36 \code
37 GeomShapeMng shape_mng;
38 Cell cell;
39 GeomShapeView shape_view;
40 // Initializes the view \a shape_view on the cell \a cell
41 shape_mng.initShape(shape_view,cell);
42 \endcode
43 *
44 * A view can be used multiple times. For example, if you want
45 * to iterate over multiple cells:
46 \code
47 * GeomShapeMng shape_mng;
48 * GeomShapeView shape_view;
49 * ENUMERATE_CELL(icell,allCells()){
50 * Cell cell = *icell;
51 * // Initializes the view \a shape_view on the cell \a cell
52 * shape_mng.initShape(shape_view,cell);
53 * info() << "Node0=" << shape_view.node(0);
54 * }
55 \endcode
56
57 * The view retrieved by GeomShapeView is constant. To retrieve a
58 * mutable view, you must use mutableShapeView(). The mutable view
59 * is only used to update the different
60 * coordinates (nodes, face centers, ...).
61 *
62 * Before being able to use one of the initShape() or mutableShapeView() methods,
63 * you must initialize one of the instances by calling initialize().
64 * Initialization only performs memory allocation but does not update
65 * the coordinates.
66 * \warning The initialize() method must also be called when the topology
67 * of the mesh changes, for example after adding or deleting a cell.
68 *
69 * This class only manages the data on the geometric shapes and
70 * these are independent of other variables. This means
71 * that if the coordinates of a cell node change, you must explicitly
72 * update the geometric shape information. %Arcane provides
73 * the BarycentricGeomShapeComputer class for this, but the user
74 * can calculate this information in another way than using the barycenter.
75 *
76 * All instances of this class whose name name() is identical
77 * are implicitly shared and therefore provide the same GeomShapeView.
78 * For example:
79 \code
80 IMesh* mesh;
81 GeomShapeMng shape_mng(mesh,"GenericElement");
82 GeomShapeMng shape_mng2(shape_mng);
83 // shape_mng and shape_mng2 share the same GeomShapeView
84
85 GeomShapeMng shape_mng3(mesh,"AleGenericElement");
86 // shape_mng and shape_mng3 use different values.
87 \endcode
88 *
89 */
90class ARCANE_GEOMETRY_EXPORT GeomShapeMng
91{
92 // NOTE:
93 // Since this class can be used by copy or created directly
94 // via variable names, it should not contain fields
95 // other than Arcane variables so that there are no inconsistencies
96 // between the different instances.
97
98 public:
99
100 //! Initializes for the mesh \a mesh with the name \a name
101 GeomShapeMng(IMesh* mesh, const String& name);
102 //! Initializes for the mesh \a mesh with the default name \a GenericElement
103 GeomShapeMng(IMesh* mesh);
104 //! Copy constructor.
105 GeomShapeMng(const GeomShapeMng& rhs);
106
107 public:
108
109 //! Indicates if the instance is initialized.
110 bool isInitialized() const { return m_cell_shape_nodes.arraySize() != 0; }
111
112 /*!
113 * \brief Initializes the instance.
114 *
115 * Only instances with the same name need to be initialized once.
116 */
117 void initialize();
118
119 //! Initializes the view \a ge with the information of the cell \a cell
120 void initShape(GeomShapeView& ge, Cell cell) const
121 {
122 ge._setArray(m_cell_shape_nodes[cell].data(), m_cell_shape_faces[cell].data(), &m_cell_shape_centers[cell]);
123 ge._setItem(cell);
124 }
125
126 //! Returns a mutable view on the GeomShape of the cell \a cell
128 {
129 return GeomShapeMutableView(m_cell_shape_nodes[cell].data(), m_cell_shape_faces[cell].data(), &m_cell_shape_centers[cell]);
130 }
131
132 //! Manager name.
133 const String& name() const { return m_name; }
134
135 private:
136
137 String m_name;
138 VariableCellArrayReal3 m_cell_shape_nodes; //!< Generic elements nodes
139 VariableCellArrayReal3 m_cell_shape_faces; //!< Generic elements face
140 VariableCellReal3 m_cell_shape_centers; //!< Generic elements center
141};
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146typedef GeomShapeMng GeomCellMng;
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151} // namespace Arcane::geometric
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156#endif
Cell of a mesh.
Definition Item.h:1300
GeomShapeMng(IMesh *mesh, const String &name)
Initializes for the mesh mesh with the name name.
GeomShapeMutableView mutableShapeView(Cell cell)
Returns a mutable view on the GeomShape of the cell cell.
bool isInitialized() const
Indicates if the instance is initialized.
void initShape(GeomShapeView &ge, Cell cell) const
Initializes the view ge with the information of the cell cell.
const String & name() const
Manager name.
Constant view on a geometric shape GeomShape.
MeshVariableScalarRefT< Cell, Real3 > VariableCellReal3
Coordinate type quantity at cell center.
MeshVariableArrayRefT< Cell, Real3 > VariableCellArrayReal3
Quantity at the cell center of coordinate array type.