Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
IMeshUtilities.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/* IMeshUtilities.h (C) 2000-2025 */
9/* */
10/* Interface of a class providing utility functions on meshes. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_IMESHUTILITIES_H
13#define ARCANE_CORE_IMESHUTILITIES_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Real3.h"
18
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32/*!
33 * \brief Interface of a class providing utility functions on meshes.
34 */
35class ARCANE_CORE_EXPORT IMeshUtilities
36{
37 public:
38
39 virtual ~IMeshUtilities() = default; //!< Frees resources.
40
41 public:
42
43 /*!
44 * \brief Searches for the local IDs of entities based on their
45 * connectivity.
46 *
47 * This method is only implemented for order 1 faces.
48 *
49 * \deprecated Use getFacesLocalIdFromConnectivity() instead.
50 */
51 ARCANE_DEPRECATED_REASON("Y2025: Use getFacesLocalIdFromConnectivity() instead")
52 virtual void localIdsFromConnectivity(eItemKind item_kind,
53 IntegerConstArrayView items_nb_node,
54 Int64ConstArrayView items_connectivity,
55 Int32ArrayView local_ids,
56 bool allow_null = false) = 0;
57
58 /*!
59 * \brief Searches for the local IDs of faces based on their connectivity.
60 *
61 * Takes as input a list of entities described by the unique IDs
62 * (Item::uniqueId()) of their nodes and searches for the local IDs
63 * (Item::localId())
64 * of these entities.
65 *
66 * \param items_type array of ItemTypeId of the entities
67 * \param items_connectivity array containing the unique indices of the
68 * entities' nodes.
69 * \param local_ids in return, contains the local IDs of the entities.
70 * The number of elements in \a local_ids must be equal to that
71 * of \a items_nb_node.
72 *
73 * The array \a items_connectivity contains the node IDs of the faces,
74 * listed consecutively. For example, if \c items_type[0]==IT_Triangle3 and
75 * \c items_type[1]==IT_Quad4, then \a items_connectivity[0..2] will contain the
76 * nodes of entity 0, and items_connectivity[3..6] those of entity 1.
77 *
78 * If \a allow_null is false, a fatal error is generated if
79 * an entity is not found; otherwise, NULL_ITEM_LOCAL_ID is
80 * returned for the corresponding entity.
81 */
83 ConstArrayView<Int64> items_connectivity,
84 ArrayView<Int32> local_ids,
85 bool allow_null = false) = 0;
86
87 /*!
88 * \brief Calculates the normal of a face group.
89 *
90 * This method calculates the normal of a face group by assuming that
91 * this surface is a plane. For the calculation, the algorithm attempts to
92 * determine the nodes at the ends of this surface and calculates a
93 * normal from these nodes. The orientation of the normal (inward
94 * or outward) is undefined.
95 *
96 * If the surface is not planar, the result is undefined.
97 *
98 * The current algorithm does not always work on a surface composed
99 * only of triangles.
100 *
101 * This method is collective. The algorithm used guarantees the
102 * same results in sequential and parallel execution.
103 *
104 * The variable \a nodes_coord is used as coordinates for the nodes.
105 * Generally, this is IMesh::nodesCoordinates().
106 */
107 virtual Real3 computeNormal(const FaceGroup& face_group,
108 const VariableNodeReal3& nodes_coord) = 0;
109
110 /*!
111 * \brief Calculates the direction vector of a line.
112 *
113 * This method calculates the direction vector of a group of nodes
114 * by assuming that it forms a line. For the calculation, the algorithm attempts to
115 * determine the nodes at the ends of this line and calculates a
116 * vector from these nodes. The direction of the vector is undefined.
117 *
118 * If the group does not form a line, the result is undefined.
119 *
120 * This method is collective. The algorithm used guarantees the
121 * same results in sequential and parallel execution.
122 *
123 * If \a n1 and \a n2 are not null, they will contain the extreme coordinates
124 * from which the direction is calculated.
125 *
126 * The variable \a nodes_coord is used as coordinates for the nodes.
127 * Generally, this is IMesh::nodesCoordinates().
128 */
129 virtual Real3 computeDirection(const NodeGroup& node_group,
130 const VariableNodeReal3& nodes_coord,
131 Real3* n1, Real3* n2) = 0;
132
133 //! Calculates adjacencies, stored in \a adjacency_array
134 ARCANE_DEPRECATED_REASON("Y2020: Use computeAdjacency() instead")
135 virtual void computeAdjency(ItemPairGroup adjacency_array, eItemKind link_kind,
136 Integer nb_layer) = 0;
137
138 //! Calculates adjacencies, stored in \a adjacency_array
139 virtual void computeAdjacency(const ItemPairGroup& adjacency_array, eItemKind link_kind,
140 Integer nb_layer);
141
142 /*!
143 * \brief Positions the new owners of nodes, edges, and faces based
144 * on the cells.
145 *
146 * Assuming the new owners of the cells are known (and synchronized),
147 * it determines the new owners of other entities and synchronizes them.
148 *
149 * This method is collective.
150 *
151 * \note This method requires that the synchronization information be valid.
152 * If you want to determine the owners of entities without prior
153 * information, you must use computeAndSetOwnersForNodes()
154 * or computeAndSetOwnersForFaces().
155 */
156 virtual void changeOwnersFromCells() = 0;
157
158 /*!
159 * \brief Determines the owners of the nodes.
160 *
161 * The determination is based on the owners of the cells.
162 * There must be no ghost cell layers.
163 *
164 * This operation is collective.
165 */
166 ARCANE_DEPRECATED_REASON("Y2025: Use MeshUtils::computeAndSetOwnerForNodes() instead")
167 virtual void computeAndSetOwnersForNodes() = 0;
168
169 /*!
170 * \brief Determines the owners of the edges.
171 *
172 * The determination is based on the owners of the cells.
173 * There must be no ghost cell layers.
174 *
175 * This operation is collective.
176 */
177 ARCANE_DEPRECATED_REASON("Y2025: Use MeshUtils::computeAndSetOwnerForEdges() instead")
178 virtual void computeAndSetOwnersForEdges() = 0;
179
180 /*!
181 * \brief Determines the owners of the faces.
182 *
183 * The determination is based on the owners of the cells.
184 * There must be no ghost cell layers.
185 *
186 * This operation is collective.
187 */
188 ARCANE_DEPRECATED_REASON("Y2025: Use MeshUtils::computeAndSetOwnerForFaces() instead")
189 virtual void computeAndSetOwnersForFaces() = 0;
190
191 /*!
192 * \brief Writes the mesh to a file.
193 *
194 * Writes the mesh to the file \a file_name using the service implementing
195 * the 'IMeshWriter' interface and named \a service_name.
196 *
197 * \retval true if the specified service is not available.
198 * \retval false if everything is ok.
199 */
200 virtual bool writeToFile(const String& file_name, const String& service_name) = 0;
201
202 /*!
203 * \brief Repartitions and exchanges the mesh while managing replication.
204 *
205 * This method performs a mesh repartitioning via
206 * the call to IMeshPartitioner::partitionMesh(bool) and proceeds to exchange
207 * entities via IPrimaryMesh::exchangeItems().
208 *
209 * It also manages replication by ensuring that all replicas
210 * have the same mesh.
211 * The principle is as follows:
212 * - only the master replica performs the repartitioning by calling
213 * IMeshPartitioner::partitionMesh() with \a partitioner as the partitioner
214 * - the values of IItemFamily::itemsNewOwner() are then
215 * synchronized with the other replicas.
216 * - entity exchanges are performed via IPrimaryMesh::exchangeItems().
217 *
218 * This method is collective across all replicas.
219 *
220 * \pre All replicas must have the same mesh, meaning that all entity families
221 * must be identical except for particle families which are not concerned.
222 * \pre The mesh must be an instance of IPrimaryMesh.
223 *
224 * \post All replicas have the same mesh except for particle families.
225 *
226 * \param partitioner Instance of the partitioner to be used
227 * \param initial_partition Indicates if it is the initial partitioning.
228 */
230 bool initial_partition) = 0;
231
232 /*!
233 * \brief Merges nodes.
234 */
235 virtual void mergeNodes(Int32ConstArrayView nodes_local_id,
236 Int32ConstArrayView nodes_to_merge_local_id)
237 {
238 this->mergeNodes(nodes_local_id, nodes_to_merge_local_id, false);
239 }
240
241 /*!
242 * \brief Merges nodes.
243 *
244 * Merges nodes in pairs from \a nodes_to_merge_local_id with those
245 * from \a nodes_local_id. Each node \a nodes_to_merge_local_id[i] is
246 * merged with \a nodes_local_id[i].
247 *
248 * The nodes \a nodes_to_merge_local_id are destroyed after merging. Entities
249 * entirely resting on these merged nodes are also destroyed.
250 *
251 * It is forbidden to merge two nodes from the same cell or the same face
252 * (after merging, a face or a cell cannot have the same node twice).
253 *
254 * Once the merge is performed, the faces containing the merged nodes
255 * (\a nodes_to_merge_local_id) are destroyed. If \a allow_non_corresponding_face
256 * is false, then for each destroyed face, there must correspond an existing face
257 * with the merged nodes (\a nodes_local_id).
258 */
259 virtual void mergeNodes(Int32ConstArrayView nodes_local_id,
260 Int32ConstArrayView nodes_to_merge_local_id,
261 bool allow_non_corresponding_face) = 0;
262 /*!
263 * \brief Recalculates the uniqueId() of edges, faces, and cells based on the
264 * uniqueId() of the nodes.
265 *
266 * \warning This method is experimental and should only be used within Arcane.
267 * It assumes that the uniqueId() of the entities are constructed from
268 * generateHashUniqueId().
269 */
271};
272
273/*---------------------------------------------------------------------------*/
274/*---------------------------------------------------------------------------*/
275
276} // End namespace Arcane
277
278/*---------------------------------------------------------------------------*/
279/*---------------------------------------------------------------------------*/
280
281#endif
Declarations of Arcane's general types.
Declarations of types on entities.
Modifiable view of an array of type T.
Constant view of an array of type T.
Interface of a mesh partitioner.
Interface of a class providing utility functions on meshes.
virtual void changeOwnersFromCells()=0
Positions the new owners of nodes, edges, and faces based on the cells.
virtual ~IMeshUtilities()=default
Frees resources.
virtual void mergeNodes(Int32ConstArrayView nodes_local_id, Int32ConstArrayView nodes_to_merge_local_id)
Merges nodes.
virtual Real3 computeNormal(const FaceGroup &face_group, const VariableNodeReal3 &nodes_coord)=0
Calculates the normal of a face group.
virtual void computeAdjency(ItemPairGroup adjacency_array, eItemKind link_kind, Integer nb_layer)=0
Calculates adjacencies, stored in adjacency_array.
virtual void mergeNodes(Int32ConstArrayView nodes_local_id, Int32ConstArrayView nodes_to_merge_local_id, bool allow_non_corresponding_face)=0
Merges nodes.
virtual void computeAndSetOwnersForFaces()=0
Determines the owners of the faces.
virtual void computeAdjacency(const ItemPairGroup &adjacency_array, eItemKind link_kind, Integer nb_layer)
Calculates adjacencies, stored in adjacency_array.
virtual void computeAndSetOwnersForEdges()=0
Determines the owners of the edges.
virtual void computeAndSetOwnersForNodes()=0
Determines the owners of the nodes.
virtual void localIdsFromConnectivity(eItemKind item_kind, IntegerConstArrayView items_nb_node, Int64ConstArrayView items_connectivity, Int32ArrayView local_ids, bool allow_null=false)=0
Searches for the local IDs of entities based on their connectivity.
virtual void getFacesLocalIdFromConnectivity(ConstArrayView< ItemTypeId > items_type, ConstArrayView< Int64 > items_connectivity, ArrayView< Int32 > local_ids, bool allow_null=false)=0
Searches for the local IDs of faces based on their connectivity.
virtual void partitionAndExchangeMeshWithReplication(IMeshPartitionerBase *partitioner, bool initial_partition)=0
Repartitions and exchanges the mesh while managing replication.
virtual Real3 computeDirection(const NodeGroup &node_group, const VariableNodeReal3 &nodes_coord, Real3 *n1, Real3 *n2)=0
Calculates the direction vector of a line.
virtual bool writeToFile(const String &file_name, const String &service_name)=0
Writes the mesh to a file.
virtual void recomputeItemsUniqueIdFromNodesUniqueId()=0
Recalculates the uniqueId() of edges, faces, and cells based on the uniqueId() of the nodes.
Table of entity lists.
Type of an entity (Item).
Definition ItemTypeId.h:33
Class managing a 3-dimensional real vector.
Definition Real3.h:132
ItemGroupT< Face > FaceGroup
Group of faces.
Definition ItemTypes.h:179
ItemGroupT< Node > NodeGroup
Group of nodes.
Definition ItemTypes.h:168
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:480
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:453
eItemKind
Mesh entity type.
ConstArrayView< Integer > IntegerConstArrayView
C equivalent of a 1D array of integers.
Definition UtilsTypes.h:486
std::int32_t Int32
Signed integer type of 32 bits.