Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
PolyhedralMesh.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/* PolyhedralMesh.h (C) 2000-2026 */
9/* */
10/* Polyhedral mesh implementation using Neo data structure */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_POLYHEDRALMESH_H
14#define ARCANE_POLYHEDRALMESH_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/core/MeshHandle.h"
19#include "arcane/core/ItemGroup.h"
20#include "arcane/core/MeshItemInternalList.h"
21#include "arcane/core/ISubDomain.h"
22#include "arcane/core/Properties.h"
24
25#include "arcane/mesh/EmptyMesh.h"
26#include "arcane/mesh/EmptyMeshModifier.h"
27#include "arcane/mesh/MeshEventsImpl.h"
28
29#include "arcane/core/ItemAllocationInfo.h"
31#include "arcane/utils/Collection.h"
32#include "arcane/utils/String.h"
33#include "arcane/utils/List.h"
34#include "arcane/core/IMeshInitialAllocator.h"
35#include "arcane/core/IParallelMng.h"
36#include "arcane/core/MeshKind.h"
37
38#include <memory>
39
40#ifdef ARCANE_HAS_POLYHEDRAL_MESH_TOOLS
41#include <vector>
42#include <array>
43
44#include "arcane/core/IVariableMng.h"
45#include "arcane/mesh/DynamicMeshChecker.h"
46#include "arcane/mesh/GhostLayerBuilder.h"
47#endif
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
52namespace Arcane
53{
54class ISubDomain;
56class IGhostLayerMng;
58class GhostLayerBuilder;
59} // namespace Arcane
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64namespace Arcane::mesh
65{
66
68class PolyhedralFamily;
69class PolyhedralFamilySerializer;
70class PolyhedralFamilySerializerMng;
71namespace PolyhedralTools
72{
73 class ItemLocalIds;
74}
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
78class PolyhedralMesh
79: public EmptyMesh
80, public EmptyMeshModifier
82{
83
84 friend class PolyhedralFamily;
85 friend class PolyhedralFamilySerializer;
86
87 private:
88
89 String m_name;
90 ISubDomain* m_subdomain;
91 MeshItemInternalList m_mesh_item_internal_list;
92 inline static const String m_mesh_handle_name = "polyhedral_mesh_handle";
93 MeshHandle m_mesh_handle;
94 std::unique_ptr<Properties> m_properties;
95 std::unique_ptr<PolyhedralMeshImpl> m_mesh; // using pimpl to limit dependency to neo lib to cc file
96 IParallelMng* m_parallel_mng;
97 MeshPartInfo m_mesh_part_info;
98 bool m_is_allocated = false;
99 ItemTypeMng* m_item_type_mng = nullptr;
100 MeshKind m_mesh_kind;
101 MeshEventsImpl m_mesh_events;
102 std::unique_ptr<PolyhedralFamilySerializerMng> m_polyhedral_family_serializer_mng;
103 VariableScalarInteger m_connectivity; // todo use MeshVariables (when adding dump handling)
104 std::unique_ptr<GhostLayerBuilder> m_ghost_layer_builder = nullptr;
105
106 public:
107
108 // IPolyhedralMeshInitialAllocator interface
109 void allocateItems(const Arcane::ItemAllocationInfo& item_allocation_info) override;
110 // Get items local ids after creation. Argument family_ids will be resized in the method
111 void allocateItems(const Arcane::ItemAllocationInfo& item_allocation_info, ArrayView<Int32UniqueArray> family_lids);
112 void scheduleAllocateItems(const Arcane::ItemAllocationInfo::FamilyInfo& family_info, PolyhedralTools::ItemLocalIds& future_item_local_ids);
113 void applyScheduledAllocateItems(UniqueArray<std::shared_ptr<PolyhedralTools::ItemLocalIds>> item_lids);
114 void removeNeedRemoveMarkedItems();
115 PolyhedralFamilySerializerMng* polyhedralFamilySerializerMng();
116
117 public:
118
119 PolyhedralMesh(ISubDomain* subDomain, const MeshBuildInfo& mbi);
120 ~PolyhedralMesh(); // for pimpl idiom
121
122 public:
123
124 static String handleName() { return m_mesh_handle_name; }
125
126 void read(String const& filename);
127
128 void endUpdate();
129
130 const MeshKind meshKind() const override { return m_mesh_kind; }
131
133 {
134 return m_mesh_events.eventObservable(type);
135 }
136
137#ifdef ARCANE_HAS_POLYHEDRAL_MESH_TOOLS
138
139 class InitialAllocator : public IMeshInitialAllocator
140 {
141 PolyhedralMesh& m_mesh;
142
143 public:
144
145 explicit InitialAllocator(PolyhedralMesh& mesh)
146 : m_mesh(mesh)
147 {}
148 IPolyhedralMeshInitialAllocator* polyhedralMeshAllocator() override { return &m_mesh; }
149 };
150
151 class InternalApi;
152 class PolyhedralMeshModifier;
153 class NoCompactionMeshCompacter;
154 class NoCompactionMeshCompactMng;
155
156 private:
157
158 std::vector<std::unique_ptr<PolyhedralFamily>> m_arcane_families;
159 std::array<std::unique_ptr<PolyhedralFamily>, NB_ITEM_KIND> m_empty_arcane_families;
160 std::array<PolyhedralFamily*, NB_ITEM_KIND> m_default_arcane_families;
161 std::vector<std::unique_ptr<VariableItemReal3>> m_arcane_item_coords;
162 std::unique_ptr<VariableNodeReal3> m_arcane_node_coords = nullptr;
163 ItemGroupList m_all_groups;
164 InitialAllocator m_initial_allocator;
165 IVariableMng* m_variable_mng = nullptr;
166 DynamicMeshChecker m_mesh_checker;
167 List<IItemFamily*> m_item_family_collection;
168 std::unique_ptr<InternalApi> m_internal_api;
169 std::unique_ptr<IMeshCompactMng> m_compact_mng;
170 std::unique_ptr<IMeshUtilities> m_mesh_utilities;
171 std::unique_ptr<IMeshExchangeMng> m_mesh_exchange_mng;
172 std::unique_ptr<IItemFamilyNetwork> m_item_family_network;
173 std::unique_ptr<IGhostLayerMng> m_ghost_layer_mng;
174 bool m_is_dynamic = false;
175
176 // IPrimaryMeshBase interface
177 IMeshInitialAllocator* initialAllocator() override { return &m_initial_allocator; }
178
179 void _allocateItems(const Arcane::ItemAllocationInfo& item_allocation_info, ArrayView<Int32UniqueArray> family_lids);
180
181 // IMeshBase interface
182 public:
183
184 MeshHandle handle() const override;
185
186 public:
187
188 void build() override {}
189
190 String name() const override;
191
192 Integer nbNode() override;
193
194 Integer nbEdge() override;
195
196 Integer nbFace() override;
197
198 Integer nbCell() override;
199
200 Integer nbItem(eItemKind ik) override;
201
202 ITraceMng* traceMng() override;
203
204 Integer dimension() override;
205
206 NodeGroup allNodes() override;
207
208 EdgeGroup allEdges() override;
209
210 FaceGroup allFaces() override;
211
212 CellGroup allCells() override;
213
214 NodeGroup ownNodes() override;
215
216 EdgeGroup ownEdges() override;
217
218 FaceGroup ownFaces() override;
219
220 CellGroup ownCells() override;
221
222 FaceGroup outerFaces() override;
223
224 IItemFamily* createItemFamily(eItemKind ik, const String& name) override;
225
226 ISubDomain* subDomain() override { return m_subdomain; }
227 MeshItemInternalList* meshItemInternalList() override { return &m_mesh_item_internal_list; }
228
229 Properties* properties() override { return m_properties.get(); }
230
231 const MeshPartInfo& meshPartInfo() const override { return m_mesh_part_info; };
232
233 IItemFamily* nodeFamily() override;
234 IItemFamily* edgeFamily() override;
235 IItemFamily* faceFamily() override;
236 IItemFamily* cellFamily() override;
237
239
240 IParallelMng* parallelMng() override { return m_subdomain->parallelMng(); }
241
242 bool isAllocated() override { return m_is_allocated; }
243
244 bool isAmrActivated() const override { return false; }
245
246 IItemFamily* itemFamily(eItemKind ik) override;
247
248 ItemTypeMng* itemTypeMng() const override;
249
250 IItemFamily* findItemFamily(eItemKind ik, const String& name, bool create_if_needed, bool register_modifier_if_created) override;
251
252 IMesh* parentMesh() const override { return nullptr; }
253
254 PolyhedralFamily* arcaneDefaultFamily(eItemKind ik);
255
257
258 ItemGroup findGroup(const String& name) override;
259
260 ItemGroupCollection groups() override;
261
262 void destroyGroups() override;
263
264 IGhostLayerMng* ghostLayerMng() const override;
265
266 void checkValidMesh() override
267 {
268 if (!m_is_allocated)
269 return;
270 m_mesh_checker.checkValidMesh();
271 }
272
273 IVariableMng* variableMng() const override { return m_variable_mng; }
274
275 IItemFamilyCollection itemFamilies() override;
276
277 String factoryName() const override;
278
279 IMeshInternal* _internalApi() override;
280
281 IMeshCompactMng* _compactMng() override;
282
283 void exchangeItems() override;
284
285 void updateGhostLayers(bool remove_old_ghost) override;
286
287 // For now, use _internalAPI()->polyhedralMeshModifier instead of IMeshModifier not implemented yet
288 IMeshModifier* modifier() override { return this; }
289 bool isDynamic() const override { return m_is_dynamic; }
290 void setDynamic(bool is_dynamic) override { m_is_dynamic = is_dynamic; }
291 void addExtraGhostCellsBuilder(IExtraGhostCellsBuilder*) override
292 {
293 // not yet implemented : must exit in parallel
294 if (m_subdomain->parallelMng()->isParallel()) {
295 ARCANE_NOT_YET_IMPLEMENTED("Parallel for polyhedral mesh is WIP");
296 }
297 }
298 void removeExtraGhostCellsBuilder(IExtraGhostCellsBuilder*) override
299 {
300 // not yet implemented : must exit in parallel
301 if (m_subdomain->parallelMng()->isParallel()) {
302 ARCANE_NOT_YET_IMPLEMENTED("Parallel for polyhedral mesh is WIP");
303 }
304 }
305 void endUpdate(bool, bool) override
306 {
307 // not yet implemented : must exit in parallel
308 if (m_subdomain->parallelMng()->isParallel()) {
309 ARCANE_NOT_YET_IMPLEMENTED("Parallel for polyhedral mesh is WIP");
310 }
311 }
312
313 IMeshUtilities* utilities() override;
314
315 void addNodes(Int64ConstArrayView nodes_uid, Int32ArrayView nodes_lid) override; // wip: add IMeshModifierAPI
316
317 // AMR is not activated with Polyhedral mesh. All items are thus active.
318 CellGroup allActiveCells() override;
319 CellGroup ownActiveCells() override;
320 CellGroup allLevelCells(const Integer& level) override;
321 CellGroup ownLevelCells(const Integer& level) override;
322 FaceGroup allActiveFaces() override;
323 FaceGroup ownActiveFaces() override;
324 FaceGroup innerActiveFaces() override;
325 FaceGroup outerActiveFaces() override;
326
327 IMeshPartitionConstraintMng* partitionConstraintMng() override { return nullptr; }
328
330
331 IItemFamilyNetwork* itemFamilyNetwork() override;
332
333 Integer checkLevel() const override;
334
335 IUserDataList* userDataList() override { return m_mesh_handle.meshUserDataList(); }
336 const IUserDataList* userDataList() const override { return m_mesh_handle.meshUserDataList(); }
337
338 void prepareForDump() override;
339
340 bool useMeshItemFamilyDependencies() const override { return false; }
341
342 IMeshModifierInternal* _modifierInternalApi() override;
343
344 IItemFamilyModifier* findItemFamilyModifier(eItemKind, const String&) override { return nullptr; }
345
346 VariableScalarInteger connectivity() override { return m_connectivity; }
347
348 void connectivities(IItemFamily* source_family);
349
350 private:
351
352 void addItems(Int64ConstArrayView unique_ids, Int32ArrayView local_ids, eItemKind ik, const String& family_name);
353 void addItems(Int64ConstArrayView unique_ids, Int32ArrayView local_ids, Int32ConstArrayView owners, eItemKind ik, const String& family_name);
354 void removeItems(Int32ConstArrayView local_ids, eItemKind ik, const String& family_name);
355 void removeItems(Int32ConstArrayView local_ids, IItemFamily* family);
356
357 PolyhedralFamily* _createItemFamily(eItemKind ik, const String& name);
358 PolyhedralFamily* _itemFamily(eItemKind ik);
359 PolyhedralFamily* _findItemFamily(eItemKind ik, const String& name, bool create_if_needed = false);
360
361 void _internalUpdateGhost(bool update_ghost_layer, bool remove_old_ghost);
362 void _finalizeMeshChanged();
363 void _internalEndUpdateInit(bool cond);
364 void _synchronizeGroups();
365 void _internalEndUpdateResizeVariables();
366 void _synchronizeVariables();
367 void _internalEndUpdateFinal(bool print_stat);
368 void _removeGhostItems();
369
370 const char* _className() const { return "PolyhedralMesh"; }
371
372 void _exchangeItems();
373
374 void _endUpdateFamilies();
375
376 void _computeFamilySynchronizeInfos();
377
378 void _notifyEndUpdateForFamilies();
379
380 void _computeGroupSynchronizeInfos();
381
382#endif // ARCANE_HAS_POLYHEDRAL_MESH_TOOLS
383
384 private:
385
386 [[noreturn]] void _errorEmptyMesh() const;
387
388 void _createUnitMesh();
389 void _updateMeshInternalList(eItemKind kind);
390 PolyhedralMeshImpl* _impl();
391};
392
393/*---------------------------------------------------------------------------*/
394/*---------------------------------------------------------------------------*/
395
396} // End namespace Arcane::mesh
397
398/*---------------------------------------------------------------------------*/
399/*---------------------------------------------------------------------------*/
400
401#endif
Arcane configuration file.
Declarations of Arcane's general types.
Modifiable view of an array of type T.
virtual String name() const =0
Mesh name.
Interface for managing mesh exchanges between subdomains.
Interface for allocating mesh entities.
Interface of the parallelism manager for a subdomain.
virtual IMeshInitialAllocator * initialAllocator()
Specific initial allocator.
Interface of the subdomain manager.
Definition ISubDomain.h:78
Mesh entity type manager.
Definition ItemTypeMng.h:64
Parameters necessary for building a mesh.
Handle on a mesh.
Definition MeshHandle.h:48
Indirection tables for mesh entities.
Characteristics of a mesh.
Definition MeshKind.h:113
Information about a partitioned mesh.
bool get(const String &name, bool &value) const
Value of the property named name.
1D data vector with value semantics (STL style).
void addNodes(Int64ConstArrayView, Int32ArrayView) override
Adds nodes.
void updateGhostLayers() override
Updates the ghost layer.
IMeshModifierInternal * _modifierInternalApi() override
Internal API for Arcane.
void setDynamic(bool) override
Sets the property indicating whether the mesh can evolve.
void addExtraGhostCellsBuilder(IExtraGhostCellsBuilder *) override
addition of the "extraordinary" ghost cells addition algorithm.
void removeExtraGhostCellsBuilder(IExtraGhostCellsBuilder *) override
Removes the association with the builder instance.
CellGroup ownLevelCells(const Integer &) override
Group of all cells specific to the domain of level level.
Definition EmptyMesh.h:323
void destroyGroups() override
Destroys all groups of all families.
Definition EmptyMesh.h:361
Integer nbNode() override
Number of mesh nodes.
Definition EmptyMesh.h:115
ITraceMng * traceMng() override
Associated message manager.
Definition EmptyMesh.h:140
FaceGroup ownFaces() override
Group of all domain-specific faces.
Definition EmptyMesh.h:180
IItemFamily * createItemFamily(eItemKind, const String &) override
Create a particle family named name.
Definition EmptyMesh.h:198
IUserDataList * userDataList() override
Associated user data manager.
Definition EmptyMesh.h:465
IItemFamily * itemFamily(eItemKind) override
Returns the entity family of type ik.
Definition EmptyMesh.h:218
IItemFamily * faceFamily() override
Returns the face family.
Definition EmptyMesh.h:233
VariableItemInt32 & itemsNewOwner(eItemKind) override
Variable containing the identifier of the owning subdomain.
Definition EmptyMesh.h:97
ItemTypeMng * itemTypeMng() const override
Associated entity type manager.
Definition EmptyMesh.h:540
VariableNodeReal3 & nodesCoordinates() override
Node coordinates.
Definition EmptyMesh.h:86
IMeshPartitionConstraintMng * partitionConstraintMng() override
Manager of partitioning constraints associated with this mesh.
Definition EmptyMesh.h:407
FaceGroup outerFaces() override
Group of all faces on the boundary.
Definition EmptyMesh.h:190
Integer dimension() override
Mesh dimension (1D, 2D, or 3D).
Definition EmptyMesh.h:145
IGhostLayerMng * ghostLayerMng() const override
Associated ghost layer manager.
Definition EmptyMesh.h:478
bool useMeshItemFamilyDependencies() const override
check if the network itemFamily dependencies is activated
Definition EmptyMesh.h:499
IMeshModifier * modifier() override
Associated modifier interface.
Definition EmptyMesh.h:428
IMeshCompactMng * _compactMng() override
Definition EmptyMesh.h:517
Integer nbCell() override
Number of mesh cells.
Definition EmptyMesh.h:130
IParallelMng * parallelMng() override
Parallelism manager.
Definition EmptyMesh.h:294
void exchangeItems() override
Changes the owning subdomains of entities.
Definition EmptyMesh.h:103
IItemFamily * edgeFamily() override
Returns the edge family.
Definition EmptyMesh.h:228
VariableScalarInteger connectivity() override
Connectivity descriptor.
Definition EmptyMesh.h:302
InternalConnectivityPolicy _connectivityPolicy() const override
Connectivity usage policy.
Definition EmptyMesh.h:522
FaceGroup allActiveFaces() override
Group of all active faces.
Definition EmptyMesh.h:328
void checkValidMesh() override
Check for the validity of internal mesh structures (internal).
Definition EmptyMesh.h:267
void prepareForDump() override
Prepares the instance for dumping.
Definition EmptyMesh.h:375
ItemGroupCollection groups() override
List of groups.
Definition EmptyMesh.h:351
IItemFamilyModifier * findItemFamilyModifier(eItemKind, const String &) override
Returns the IItemFamilyModifier interface for the family named name and of type ik.
Definition EmptyMesh.h:213
CellGroup allActiveCells() override
Definition EmptyMesh.h:308
Properties * properties() override
Properties associated with this mesh.
Definition EmptyMesh.h:420
Integer nbEdge() override
Number of mesh edges.
Definition EmptyMesh.h:120
FaceGroup innerActiveFaces() override
Group of all active faces.
Definition EmptyMesh.h:338
IItemFamily * cellFamily() override
Returns the cell family.
Definition EmptyMesh.h:238
CellGroup ownActiveCells() override
Group of all active cells specific to the domain.
Definition EmptyMesh.h:313
FaceGroup allFaces() override
Group of all faces.
Definition EmptyMesh.h:160
const MeshPartInfo & meshPartInfo() const override
Mesh part information.
Definition EmptyMesh.h:493
IVariableMng * variableMng() const override
Associated variable manager.
Definition EmptyMesh.h:535
MeshHandle handle() const override
Handle on this mesh.
Definition EmptyMesh.h:77
ItemGroup findGroup(const String &) override
Returns the group with name name or a null group if none exists.
Definition EmptyMesh.h:356
IMeshUtilities * utilities() override
Associated utility functions interface.
Definition EmptyMesh.h:415
IItemFamily * nodeFamily() override
Returns the node family.
Definition EmptyMesh.h:223
Integer checkLevel() const override
Current check level.
Definition EmptyMesh.h:378
Integer nbFace() override
Number of mesh faces.
Definition EmptyMesh.h:125
EdgeGroup allEdges() override
Group of all edges.
Definition EmptyMesh.h:155
IItemFamily * findItemFamily(eItemKind, const String &, bool, bool) override
Returns the family named name.
Definition EmptyMesh.h:203
IItemFamilyNetwork * itemFamilyNetwork() override
Family network interface (connected families).
Definition EmptyMesh.h:504
CellGroup ownCells() override
Group of all domain-specific cells.
Definition EmptyMesh.h:185
CellGroup allLevelCells(const Integer &) override
Group of all cells of level level.
Definition EmptyMesh.h:318
NodeGroup ownNodes() override
Group of all domain-specific nodes.
Definition EmptyMesh.h:170
IMeshInternal * _internalApi() override
Internal Arcane API.
Definition EmptyMesh.h:551
NodeGroup allNodes() override
Group of all nodes.
Definition EmptyMesh.h:150
FaceGroup ownActiveFaces() override
Group of all active faces specific to the domain.
Definition EmptyMesh.h:333
bool isDynamic() const override
Indicates if the mesh is dynamic (can evolve).
Definition EmptyMesh.h:383
String name() const override
Mesh name.
Definition EmptyMesh.h:110
bool isAllocated() override
True if the mesh is allocated.
Definition EmptyMesh.h:273
FaceGroup outerActiveFaces() override
Group of all active faces on the boundary.
Definition EmptyMesh.h:343
IMesh * parentMesh() const override
Access to the parent mesh.
Definition EmptyMesh.h:437
CellGroup allCells() override
Group of all cells.
Definition EmptyMesh.h:165
String factoryName() const override
Name of the factory used to create the mesh.
Definition EmptyMesh.h:252
EdgeGroup ownEdges() override
Group of all domain-specific edges.
Definition EmptyMesh.h:175
Integer nbItem(eItemKind) override
Number of elements of type ik.
Definition EmptyMesh.h:135
Implementation of mesh events.
EventObservable< const MeshEventArgs & > & eventObservable(eMeshEventType type) override
Observable for an event.
void endUpdate()
Notifies the instance that mesh modification is finished.
const MeshKind meshKind() const override
Mesh characteristics.
ItemGroupT< Cell > CellGroup
Group of cells.
Definition ItemTypes.h:184
ItemGroupT< Face > FaceGroup
Group of faces.
Definition ItemTypes.h:179
ItemGroupT< Edge > EdgeGroup
Group of edges.
Definition ItemTypes.h:174
ItemGroupT< Node > NodeGroup
Group of nodes.
Definition ItemTypes.h:168
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
ItemVariableScalarRefT< Int32 > VariableItemInt32
32-bit integer type quantity
VariableRefScalarT< Integer > VariableScalarInteger
Scalar variable of integer type.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Collection< ItemGroup > ItemGroupCollection
Collection of mesh item groups.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:476
List< ItemGroup > ItemGroupList
Array of mesh item groups.
Collection< IItemFamily * > IItemFamilyCollection
Collection of item families.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:474
eMeshEventType
Events generated by IMesh.
Definition MeshEvents.h:30
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:447
eItemKind
Mesh entity type.
InternalConnectivityPolicy
Connectivity usage policy.
Definition ItemTypes.h:517
@ NewOnly
Allocates only the new connectivities.
Definition ItemTypes.h:554