Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MeshUtils.h
Go to the documentation of this file.
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/* MeshUtils.h (C) 2000-2025 */
9/* */
10/* Various utility functions for the mesh. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_MESHUTILS_H
13#define ARCANE_CORE_MESHUTILS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/FunctorUtils.h"
19
20#include "arcane/core/Item.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34namespace Arcane
35{
36class XmlNode;
38} // namespace Arcane
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43namespace Arcane::MeshUtils
44{
45extern "C++" ARCANE_CORE_EXPORT void
46writeMeshItemInfo(ISubDomain*, Cell cell, bool depend_info = true);
47extern "C++" ARCANE_CORE_EXPORT void
48writeMeshItemInfo(ISubDomain*, Node node, bool depend_info = true);
49extern "C++" ARCANE_CORE_EXPORT void
50writeMeshItemInfo(ISubDomain*, Edge edge, bool depend_info = true);
51extern "C++" ARCANE_CORE_EXPORT void
52writeMeshItemInfo(ISubDomain*, Face face, bool depend_info = true);
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
75extern "C++" ARCANE_CORE_EXPORT bool
77
78extern "C++" ARCANE_CORE_EXPORT bool
80
81/*---------------------------------------------------------------------------*/
82/*---------------------------------------------------------------------------*/
83
106extern "C++" ARCANE_CORE_EXPORT bool
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
121extern "C++" ARCANE_CORE_EXPORT Face
122getFaceFromNodesLocalId(Node node, Int32ConstArrayView face_nodes_local_id);
123
124ARCANE_DEPRECATED_REASON("Y2025: Use getFaceFromNodesLocalId() instead")
125inline Face
126getFaceFromNodesLocal(Node node, Int32ConstArrayView face_nodes_local_id)
127{
128 return getFaceFromNodesLocalId(node, face_nodes_local_id);
129}
130
131/*---------------------------------------------------------------------------*/
132/*---------------------------------------------------------------------------*/
143extern "C++" ARCANE_CORE_EXPORT Face
144getFaceFromNodesUniqueId(Node node, Int64ConstArrayView face_nodes_unique_id);
145
146ARCANE_DEPRECATED_REASON("Y2025: Use getFaceFromNodesUniqueId() instead")
147inline Face
148getFaceFromNodesUnique(Node node, Int64ConstArrayView face_nodes_unique_id)
149{
150 return getFaceFromNodesUniqueId(node, face_nodes_unique_id);
151}
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
159extern "C++" ARCANE_CORE_EXPORT Int64
160generateHashUniqueId(SmallSpan<const Int64> nodes_unique_id);
161
162/*---------------------------------------------------------------------------*/
163/*---------------------------------------------------------------------------*/
164
172extern "C++" ARCANE_CORE_EXPORT void
173removeItemAndKeepOrder(Int32ArrayView items, Int32 local_id);
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
189extern "C++" ARCANE_CORE_EXPORT void
190checkMeshProperties(IMesh* mesh, bool is_sorted, bool has_no_hole, bool check_faces);
191
197extern "C++" ARCANE_CORE_EXPORT void
198writeMeshInfosSorted(IMesh* mesh, const String& file_name);
199
200extern "C++" ARCANE_CORE_EXPORT void
201writeMeshInfos(IMesh* mesh, const String& file_name);
202
208extern "C++" ARCANE_CORE_EXPORT void
209writeMeshConnectivity(IMesh* mesh, const String& file_name);
210
211extern "C++" ARCANE_CORE_EXPORT void
212checkMeshConnectivity(IMesh* mesh, const XmlNode& root_node, bool check_sub_domain);
213
214extern "C++" ARCANE_CORE_EXPORT void
215checkMeshConnectivity(IMesh* mesh, const String& file_name, bool check_sub_domain);
216
222extern "C++" ARCANE_CORE_EXPORT void
223printItems(std::ostream& ostr, const String& name, ItemGroup item_group);
224
233extern "C++" ARCANE_CORE_EXPORT Int64
234printMeshGroupsMemoryUsage(IMesh* mesh, Int32 print_level);
235
237extern "C++" ARCANE_CORE_EXPORT void
238shrinkMeshGroups(IMesh* mesh);
239
246extern "C++" ARCANE_CORE_EXPORT void
247dumpSynchronizerTopologyJSON(IVariableSynchronizer* var_syncer, const String& filename);
248
253extern "C++" ARCANE_CORE_EXPORT void
254computeConnectivityPatternOccurence(IMesh* mesh);
255
256/*---------------------------------------------------------------------------*/
257/*---------------------------------------------------------------------------*/
258
274extern "C++" ARCANE_CORE_EXPORT void
275markMeshConnectivitiesAsMostlyReadOnly(IMesh* mesh, RunQueue* q = nullptr,
276 bool do_prefetch = false);
277
278/*---------------------------------------------------------------------------*/
279/*---------------------------------------------------------------------------*/
280
281/*
282 * \brief Returns the entity of the family \a family with unique ID \a unique_id.
283 *
284 * If no entity with this \a unique_id is found, returns the null entity.
285 *
286 * \pre family->hasUniqueIdMap() == true
287 */
288extern "C++" ARCANE_CORE_EXPORT ItemBase
289findOneItem(IItemFamily* family, Int64 unique_id);
290
291/*---------------------------------------------------------------------------*/
292/*---------------------------------------------------------------------------*/
293
294/*
295 * \brief Returns the entity of the family \a family with unique ID \a unique_id.
296 *
297 * If no entity with this \a unique_id is found, returns the null entity.
298 *
299 * \pre family->hasUniqueIdMap() == true
300 */
301extern "C++" ARCANE_CORE_EXPORT ItemBase
302findOneItem(IItemFamily* family, ItemUniqueId unique_id);
303
304/*---------------------------------------------------------------------------*/
305/*---------------------------------------------------------------------------*/
306
310extern "C++" ARCANE_CORE_EXPORT void
311visitGroups(IItemFamily* family, IFunctorWithArgumentT<ItemGroup&>* functor);
312
313/*---------------------------------------------------------------------------*/
314/*---------------------------------------------------------------------------*/
315
319extern "C++" ARCANE_CORE_EXPORT void
320visitGroups(IMesh* mesh, IFunctorWithArgumentT<ItemGroup&>* functor);
321
322/*---------------------------------------------------------------------------*/
323/*---------------------------------------------------------------------------*/
324
338template <typename LambdaType> inline void
339visitGroups(IItemFamily* family, const LambdaType& f)
340{
342 // It must be cast to the correct type so that the compiler uses the correct overload.
344 visitGroups(family, sf_addr);
345}
346
347/*---------------------------------------------------------------------------*/
348/*---------------------------------------------------------------------------*/
349
364template <typename LambdaType> inline void
365visitGroups(IMesh* mesh, const LambdaType& f)
366{
368 // It must be cast to the correct type so that the compiler uses the correct overload.
370 visitGroups(mesh, sf_addr);
371}
372
373namespace impl
374{
375 inline Int64 computeCapacity(Int64 size)
376 {
378 }
379} // namespace impl
380
381/*---------------------------------------------------------------------------*/
382/*---------------------------------------------------------------------------*/
383
400template <typename DataType> inline bool
401checkResizeArray(Array<DataType>& array, Int64 new_size, bool force_resize)
402{
403 return Arcane::MemoryUtils::checkResizeArrayWithCapacity(array, new_size, force_resize);
404}
405
406/*---------------------------------------------------------------------------*/
407/*---------------------------------------------------------------------------*/
408
415extern "C++" ARCANE_CORE_EXPORT ItemUniqueId
416getMaxItemUniqueIdCollective(IMesh* mesh);
417
418/*---------------------------------------------------------------------------*/
419/*---------------------------------------------------------------------------*/
420
439extern "C++" ARCANE_CORE_EXPORT void
440checkUniqueIdsHashCollective(IItemFamily* family, IHashAlgorithm* hash_algo,
441 const String& expected_hash, bool print_hash_value,
442 bool include_ghost);
443
444/*---------------------------------------------------------------------------*/
445/*---------------------------------------------------------------------------*/
446
450extern "C++" ARCANE_CORE_EXPORT void
451fillUniqueIds(ItemVectorView items, Array<Int64>& uids);
452
453/*---------------------------------------------------------------------------*/
454/*---------------------------------------------------------------------------*/
455
461extern "C++" ARCANE_CORE_EXPORT Ref<IIndexedIncrementalItemConnectivity>
462computeNodeNodeViaEdgeConnectivity(IMesh* mesh, const String& connectivity_name);
463
464/*---------------------------------------------------------------------------*/
465/*---------------------------------------------------------------------------*/
466
473extern "C++" ARCANE_CORE_EXPORT Ref<IIndexedIncrementalItemConnectivity>
474computeBoundaryNodeNodeViaEdgeConnectivity(IMesh* mesh, const String& connectivity_name);
475
476/*---------------------------------------------------------------------------*/
477/*---------------------------------------------------------------------------*/
478
487extern "C++" ARCANE_CORE_EXPORT void
488computeAndSetOwnerForNodes(IMesh* mesh);
489
490/*---------------------------------------------------------------------------*/
491/*---------------------------------------------------------------------------*/
492
501extern "C++" ARCANE_CORE_EXPORT void
502computeAndSetOwnerForEdges(IMesh* mesh);
503
504/*---------------------------------------------------------------------------*/
505/*---------------------------------------------------------------------------*/
506
515extern "C++" ARCANE_CORE_EXPORT void
516computeAndSetOwnerForFaces(IMesh* mesh);
517
518/*---------------------------------------------------------------------------*/
519/*---------------------------------------------------------------------------*/
520
521} // namespace Arcane::MeshUtils
522
523/*---------------------------------------------------------------------------*/
524/*---------------------------------------------------------------------------*/
525
526namespace Arcane::mesh_utils
527{
528// Used for compatibility with existing code.
529// These usings were added for Arcane version 3.10 (June 2023).
530// They can be deprecated starting in early 2024.
531using MeshUtils::checkMeshConnectivity;
532using MeshUtils::checkMeshProperties;
533using MeshUtils::computeConnectivityPatternOccurence;
534using MeshUtils::dumpSynchronizerTopologyJSON;
535using MeshUtils::getFaceFromNodesLocal;
536using MeshUtils::getFaceFromNodesUnique;
537using MeshUtils::printItems;
538using MeshUtils::printMeshGroupsMemoryUsage;
539using MeshUtils::removeItemAndKeepOrder;
540using MeshUtils::reorderNodesOfFace;
541using MeshUtils::reorderNodesOfFace2;
542using MeshUtils::shrinkMeshGroups;
543using MeshUtils::writeMeshConnectivity;
544using MeshUtils::writeMeshInfos;
545using MeshUtils::writeMeshInfosSorted;
546using MeshUtils::writeMeshItemInfo;
547
548/*---------------------------------------------------------------------------*/
549/*---------------------------------------------------------------------------*/
550
551} // namespace Arcane::mesh_utils
552
553/*---------------------------------------------------------------------------*/
554/*---------------------------------------------------------------------------*/
555
556#endif
bool checkResizeArray(Array< DataType > &array, Int64 new_size, bool force_resize)
Resizes an array that is indexed by 'ItemLocalId'.
Definition MeshUtils.h:401
bool reorderNodesOfFace(Int64ConstArrayView before_ids, Int64ArrayView after_ids)
Reorders the nodes of a face.
void visitGroups(IItemFamily *family, IFunctorWithArgumentT< ItemGroup & > *functor)
Visits all groups of family using the functor functor.
bool reorderNodesOfFace2(Int64ConstArrayView nodes_unique_id, Int32ArrayView new_index)
Reorders the nodes of a face.
Face getFaceFromNodesLocalId(Node node, Int32ConstArrayView face_nodes_local_id)
Searches for a face entity using the local numbers of these nodes.
Memory and allocator management functions.
Int64 computeCapacity(Int64 size)
Calculates an appropriate capacity for a size size.
Base class for 1D data vectors.
Face of a cell.
Definition Item.h:1032
Interface of a functor with an argument but without a return value.
Interface of a hashing algorithm.
Interface of an entity family.
Definition IItemFamily.h:83
Interface of a variable synchronization service.
Unique identifier of an entity.
View on a vector of entities.
Node of a mesh.
Definition Item.h:598
Reference to an instance.
Generic Functor using the std::function class.
Node of a DOM tree.
Definition XmlNode.h:51
Int32 checkResizeArrayWithCapacity(Array< DataType > &array, Int64 new_size, bool force_resize)
Resizes an array by adding a memory reserve.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ArrayView< Int64 > Int64ArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:451
std::int64_t Int64
Signed integer type of 64 bits.
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
@ Cell
The mesh is AMR by cell.
Definition MeshKind.h:53