Arcane  4.1.12.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-2025 */
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 "DynamicMeshChecker.h"
46#endif
47
48/*---------------------------------------------------------------------------*/
49/*---------------------------------------------------------------------------*/
50
51namespace Arcane
52{
53class ISubDomain;
55class IGhostLayerMng;
57} // namespace Arcane
58
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
62namespace Arcane::mesh
63{
64
66class PolyhedralFamily;
67class PolyhedralFamilySerializer;
68class PolyhedralFamilySerializerMng;
69namespace PolyhedralTools
70{
71 class ItemLocalIds;
72}
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
75
76class PolyhedralMesh
77: public EmptyMesh
78, public EmptyMeshModifier
80{
81
82 friend class PolyhedralFamily;
83 friend class PolyhedralFamilySerializer;
84
85 private:
86
87 String m_name;
88 ISubDomain* m_subdomain;
89 MeshItemInternalList m_mesh_item_internal_list;
90 inline static const String m_mesh_handle_name = "polyhedral_mesh_handle";
91 MeshHandle m_mesh_handle;
92 std::unique_ptr<Properties> m_properties;
93 std::unique_ptr<PolyhedralMeshImpl> m_mesh; // using pimpl to limit dependency to neo lib to cc file
94 IParallelMng* m_parallel_mng;
95 MeshPartInfo m_mesh_part_info;
96 bool m_is_allocated = false;
97 ItemTypeMng* m_item_type_mng = nullptr;
98 MeshKind m_mesh_kind;
99 MeshEventsImpl m_mesh_events;
100 std::unique_ptr<PolyhedralFamilySerializerMng> m_polyhedral_family_serializer_mng;
101 VariableScalarInteger m_connectivity; // todo use MeshVariables (when adding dump handling)
102
103 public:
104
105 // IPolyhedralMeshInitialAllocator interface
106 void allocateItems(const Arcane::ItemAllocationInfo& item_allocation_info) override;
107 // Get items local ids after creation. Argument family_ids will be resized in the method
108 void allocateItems(const Arcane::ItemAllocationInfo& item_allocation_info, ArrayView<Int32UniqueArray> family_lids);
109 void scheduleAllocateItems(const Arcane::ItemAllocationInfo::FamilyInfo& family_info, PolyhedralTools::ItemLocalIds& future_item_local_ids);
110 void applyScheduledAllocateItems(UniqueArray<std::shared_ptr<PolyhedralTools::ItemLocalIds>> item_lids);
111 void removeNeedRemoveMarkedItems();
112 PolyhedralFamilySerializerMng* polyhedralFamilySerializerMng();
113
114 public:
115
116 PolyhedralMesh(ISubDomain* subDomain, const MeshBuildInfo& mbi);
117 ~PolyhedralMesh(); // for pimpl idiom
118
119 public:
120
121 static String handleName() { return m_mesh_handle_name; }
122
123 void read(String const& filename);
124
125 void endUpdate();
126
127 const MeshKind meshKind() const override { return m_mesh_kind; }
128
130 {
131 return m_mesh_events.eventObservable(type);
132 }
133
134#ifdef ARCANE_HAS_POLYHEDRAL_MESH_TOOLS
135
136 class InitialAllocator : public IMeshInitialAllocator
137 {
138 PolyhedralMesh& m_mesh;
139
140 public:
141
142 explicit InitialAllocator(PolyhedralMesh& mesh)
143 : m_mesh(mesh)
144 {}
145 IPolyhedralMeshInitialAllocator* polyhedralMeshAllocator() override { return &m_mesh; }
146 };
147
148 class InternalApi;
149 class PolyhedralMeshModifier;
150 class NoCompactionMeshCompacter;
151 class NoCompactionMeshCompactMng;
152
153 private:
154
155 std::vector<std::unique_ptr<PolyhedralFamily>> m_arcane_families;
156 std::array<std::unique_ptr<PolyhedralFamily>, NB_ITEM_KIND> m_empty_arcane_families;
157 std::array<PolyhedralFamily*, NB_ITEM_KIND> m_default_arcane_families;
158 std::vector<std::unique_ptr<VariableItemReal3>> m_arcane_item_coords;
159 std::unique_ptr<VariableNodeReal3> m_arcane_node_coords = nullptr;
160 ItemGroupList m_all_groups;
161 InitialAllocator m_initial_allocator;
162 IVariableMng* m_variable_mng = nullptr;
163 DynamicMeshChecker m_mesh_checker;
164 List<IItemFamily*> m_item_family_collection;
165 std::unique_ptr<InternalApi> m_internal_api;
166 std::unique_ptr<IMeshCompactMng> m_compact_mng;
167 std::unique_ptr<IMeshUtilities> m_mesh_utilities;
168 std::unique_ptr<IMeshExchangeMng> m_mesh_exchange_mng;
169 std::unique_ptr<IItemFamilyNetwork> m_item_family_network;
170 std::unique_ptr<IGhostLayerMng> m_ghost_layer_mng;
171 bool m_is_dynamic = false;
172
173 // IPrimaryMeshBase interface
174 IMeshInitialAllocator* initialAllocator() override { return &m_initial_allocator; }
175
176 void _allocateItems(const Arcane::ItemAllocationInfo& item_allocation_info, ArrayView<Int32UniqueArray> family_lids);
177
178 // IMeshBase interface
179 public:
180
181 MeshHandle handle() const override;
182
183 public:
184
185 void build() override {}
186
187 String name() const override;
188
189 Integer nbNode() override;
190
191 Integer nbEdge() override;
192
193 Integer nbFace() override;
194
195 Integer nbCell() override;
196
197 Integer nbItem(eItemKind ik) override;
198
199 ITraceMng* traceMng() override;
200
201 Integer dimension() override;
202
203 NodeGroup allNodes() override;
204
205 EdgeGroup allEdges() override;
206
207 FaceGroup allFaces() override;
208
209 CellGroup allCells() override;
210
211 NodeGroup ownNodes() override;
212
213 EdgeGroup ownEdges() override;
214
215 FaceGroup ownFaces() override;
216
217 CellGroup ownCells() override;
218
219 FaceGroup outerFaces() override;
220
221 IItemFamily* createItemFamily(eItemKind ik, const String& name) override;
222
223 ISubDomain* subDomain() override { return m_subdomain; }
224 MeshItemInternalList* meshItemInternalList() override { return &m_mesh_item_internal_list; }
225
226 Properties* properties() override { return m_properties.get(); }
227
228 const MeshPartInfo& meshPartInfo() const override { return m_mesh_part_info; };
229
230 IItemFamily* nodeFamily() override;
231 IItemFamily* edgeFamily() override;
232 IItemFamily* faceFamily() override;
233 IItemFamily* cellFamily() override;
234
236
237 IParallelMng* parallelMng() override { return m_subdomain->parallelMng(); }
238
239 bool isAllocated() override { return m_is_allocated; }
240
241 bool isAmrActivated() const override { return false; }
242
243 IItemFamily* itemFamily(eItemKind ik) override;
244
245 ItemTypeMng* itemTypeMng() const override;
246
247 IItemFamily* findItemFamily(eItemKind ik, const String& name, bool create_if_needed, bool register_modifier_if_created) override;
248
249 IMesh* parentMesh() const override { return nullptr; }
250
251 PolyhedralFamily* arcaneDefaultFamily(eItemKind ik);
252
254
255 ItemGroup findGroup(const String& name) override;
256
257 ItemGroupCollection groups() override;
258
259 void destroyGroups() override;
260
261 IGhostLayerMng* ghostLayerMng() const override;
262
263 void checkValidMesh() override
264 {
265 if (!m_is_allocated)
266 return;
267 m_mesh_checker.checkValidMesh();
268 }
269
270 IVariableMng* variableMng() const override { return m_variable_mng; }
271
272 IItemFamilyCollection itemFamilies() override;
273
274 String factoryName() const override;
275
276 IMeshInternal* _internalApi() override;
277
278 IMeshCompactMng* _compactMng() override;
279
280 void exchangeItems() override;
281
282 // For now, use _internalAPI()->polyhedralMeshModifier instead of IMeshModifier not implemented yet
283 IMeshModifier* modifier() override { return this; }
284 bool isDynamic() const override { return m_is_dynamic; }
285 void setDynamic(bool is_dynamic) override { m_is_dynamic = is_dynamic; }
286 void addExtraGhostCellsBuilder(IExtraGhostCellsBuilder*) override
287 {
288 // not yet implemented : must exit in parallel
289 if (m_subdomain->parallelMng()->isParallel()) {
290 ARCANE_NOT_YET_IMPLEMENTED("Parallel for polyhedral mesh is WIP");
291 }
292 }
293 void removeExtraGhostCellsBuilder(IExtraGhostCellsBuilder*) override
294 {
295 // not yet implemented : must exit in parallel
296 if (m_subdomain->parallelMng()->isParallel()) {
297 ARCANE_NOT_YET_IMPLEMENTED("Parallel for polyhedral mesh is WIP");
298 }
299 }
300 void endUpdate(bool, bool) override
301 {
302 // not yet implemented : must exit in parallel
303 if (m_subdomain->parallelMng()->isParallel()) {
304 ARCANE_NOT_YET_IMPLEMENTED("Parallel for polyhedral mesh is WIP");
305 }
306 }
307
308 IMeshUtilities* utilities() override;
309
310 void addNodes(Int64ConstArrayView nodes_uid, Int32ArrayView nodes_lid) override; // wip: add IMeshModifierAPI
311
312 // AMR is not activated with Polyhedral mesh. All items are thus active.
313 CellGroup allActiveCells() override;
314 CellGroup ownActiveCells() override;
315 CellGroup allLevelCells(const Integer& level) override;
316 CellGroup ownLevelCells(const Integer& level) override;
317 FaceGroup allActiveFaces() override;
318 FaceGroup ownActiveFaces() override;
319 FaceGroup innerActiveFaces() override;
320 FaceGroup outerActiveFaces() override;
321
322 IMeshPartitionConstraintMng* partitionConstraintMng() override { return nullptr; }
323
325
326 IItemFamilyNetwork* itemFamilyNetwork() override;
327
328 Integer checkLevel() const override;
329
330 IUserDataList* userDataList() override { return m_mesh_handle.meshUserDataList(); }
331 const IUserDataList* userDataList() const override { return m_mesh_handle.meshUserDataList(); }
332
333 void prepareForDump() override;
334
335 bool useMeshItemFamilyDependencies() const override { return false; }
336
337 IMeshModifierInternal* _modifierInternalApi() override;
338
339 IItemFamilyModifier* findItemFamilyModifier(eItemKind, const String&) override { return nullptr; }
340
341 VariableScalarInteger connectivity() override { return m_connectivity; }
342
343 void connectivities(IItemFamily* source_family);
344
345 private:
346
347 void addItems(Int64ConstArrayView unique_ids, Int32ArrayView local_ids, eItemKind ik, const String& family_name);
348 void addItems(Int64ConstArrayView unique_ids, Int32ArrayView local_ids, Int32ConstArrayView owners, eItemKind ik, const String& family_name);
349 void removeItems(Int32ConstArrayView local_ids, eItemKind ik, const String& family_name);
350 void removeItems(Int32ConstArrayView local_ids, IItemFamily* family);
351
352 PolyhedralFamily* _createItemFamily(eItemKind ik, const String& name);
353 PolyhedralFamily* _itemFamily(eItemKind ik);
354 PolyhedralFamily* _findItemFamily(eItemKind ik, const String& name, bool create_if_needed = false);
355 const char* _className() const { return "PolyhedralMesh"; }
356
357 void _exchangeItems();
358
359 void _endUpdateFamilies();
360
361 void _computeFamilySynchronizeInfos();
362
363 void _notifyEndUpdateForFamilies();
364
365 void _computeGroupSynchronizeInfos();
366
367#endif // ARCANE_HAS_POLYHEDRAL_MESH_TOOLS
368
369 private:
370
371 [[noreturn]] void _errorEmptyMesh() const;
372
373 void _createUnitMesh();
374 void _updateMeshInternalList(eItemKind kind);
375 PolyhedralMeshImpl* _impl();
376};
377
378/*---------------------------------------------------------------------------*/
379/*---------------------------------------------------------------------------*/
380
381} // End namespace Arcane::mesh
382
383/*---------------------------------------------------------------------------*/
384/*---------------------------------------------------------------------------*/
385
386#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:75
Mesh entity type manager.
Definition ItemTypeMng.h:66
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.
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:482
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:480
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:453
eItemKind
Mesh entity type.
InternalConnectivityPolicy
Connectivity usage policy.
Definition ItemTypes.h:517
@ NewOnly
Allocates only the new connectivities.
Definition ItemTypes.h:554