Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
DynamicMeshIncrementalBuilder.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/* DynamicMeshIncrementalBuilder.h (C) 2000-2025 */
9/* */
10/* Construction of a mesh incrementally. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MESH_DYNAMICMESHINCREMENTALBUILDER_H
13#define ARCANE_MESH_DYNAMICMESHINCREMENTALBUILDER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/HashTableMap.h"
18#include "arcane/utils/TraceAccessor.h"
19
20#include "arcane/core/IItemFamilyNetwork.h"
22#include "arcane/core/ItemInternal.h"
23
24#include "arcane/mesh/DynamicMeshKindInfos.h"
25#include "arcane/mesh/ItemData.h"
26#include "arcane/mesh/FullItemInfo.h"
27
28#include <list>
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane
34{
35class SerializeBuffer;
36}
37
38namespace Arcane::mesh
39{
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44class DynamicMesh;
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
56
58: public TraceAccessor
59{
60 public:
61
65
66 public:
67
68 // Add list of mesh and graph items
69
70 void addCells(Integer nb_cell, Int64ConstArrayView cell_infos,
71 Integer sub_domain_id, Int32ArrayView cells,
72 bool allow_build_face = true);
79 bool addCellsBulk(Integer nb_cell, Int64ConstArrayView cell_infos,
80 Integer sub_domain_id, Int32ArrayView cells,
81 bool allow_build_face);
82 void addCells2(Integer nb_cell, Int64ConstArrayView cell_infos,
83 Integer sub_domain_id, Int32ArrayView cells,
84 bool allow_build_face = true);
85 void addCells3(Integer nb_cell, Int64ConstArrayView cell_infos,
86 Integer sub_domain_id, Int32ArrayView cells,
87 bool allow_build_face = true);
88 void addFaces(Integer nb_face, Int64ConstArrayView face_infos,
89 Integer sub_domain_id, Int32ArrayView faces);
90 void addFaces2(Integer nb_face, Int64ConstArrayView face_infos,
91 Integer sub_domain_id, Int32ArrayView faces);
92 void addFaces3(Integer nb_face, Int64ConstArrayView face_infos,
93 Integer sub_domain_id, Int32ArrayView faces);
94 void addEdges(Integer nb_edge, Int64ConstArrayView edge_infos,
95 Integer sub_domain_id, Int32ArrayView edges);
96 void addEdges2(Integer nb_edge, Int64ConstArrayView edge_infos,
97 Integer sub_domain_id, Int32ArrayView edges);
98 void addEdges3(Integer nb_edge, Int64ConstArrayView edge_infos,
99 Integer sub_domain_id, Int32ArrayView edges);
100 void addNodes(Int64ConstArrayView nodes_uid,
101 Integer sub_domain_id, Int32ArrayView nodes);
102 void addNodes2(Int64ConstArrayView nodes_uid,
103 Integer sub_domain_id, Int32ArrayView nodes);
104
105 void addItems(ItemDataList& item_info_list);
106 void addItems(ItemDataList& item_info_list, ItemDataList& item_relation_info_list);
107 void addRelations(ItemDataList& item_relation_list);
108
109 void addFamilyItems(ItemData& item_info);
110
112 void addParentCells(const ItemVectorView& items);
114 void addParentItems(const ItemVectorView& items, const eItemKind submesh_kind);
117 void addHChildrenCells(Cell hParent_cell, Integer nb_cell, Int64ConstArrayView cells_infos,
118 Int32 sub_domain_id, Int32ArrayView cells,
119 bool allow_build_face);
121 void addGhostLayers(bool is_allocate);
123 void addGhostChildFromParent(Array<Int64>& ghost_cell_to_refine);
124
125 void removeGhostCells();
126 void removeNeedRemoveMarkedCells();
127
128 public:
129
131
132 void readFromDump();
133
135
136 void setConnectivity(Integer c);
137
140
141 public:
142
143 void printInfos();
144 void printStats(Int32 level = TraceMessage::DEFAULT_LEVEL);
145
146 public:
147
148 ItemInternalMap& itemsMap(eItemKind ik);
149 DynamicMesh* mesh() { return m_mesh; }
150 bool isVerbose() const { return m_verbose; }
151 bool hasEdge() const { return m_has_edge; }
152
153 OneMeshItemAdder* oneMeshItemAdder() const { return m_one_mesh_item_adder; }
154
155 private:
156
157 template <typename FamilyType>
158 void _allocateBulkByType(FamilyType* family, Int64ConstArrayView uids,
159 ConstArrayView<Int16> type_ids, Int32 owner, Int32ArrayView lids);
163 Int32 nb_source, ConstArrayView<Int32> offsets,
164 ConstArrayView<Int32> targets);
165
166 struct NodeInFace;
167
168 struct NodeInFacePtr
169 {
170 NodeInFacePtr(const Int64& node_uid)
171 : m_ptr(std::make_shared<NodeInFace>(node_uid))
172 {}
173 bool operator<(const NodeInFacePtr& a) const { return (*m_ptr) < (*a.m_ptr); }
174 NodeInFace* operator->() { return m_ptr.operator->(); }
175 const NodeInFace* operator->() const { return m_ptr.operator->(); }
176 bool operator==(const NodeInFacePtr& a) const { return (*m_ptr) == (*a.m_ptr); }
177 std::shared_ptr<NodeInFace> m_ptr;
178 };
179
180 struct NodeInFace
181 {
182 // typedef std::shared_ptr<NodeInFace> NodeInFacePtr;
183 // typedef std::set<NodeInFacePtr, std::function<bool(const NodeInFacePtr&, const NodeInFacePtr&)>> NodeInFaceSet; // Does not work bad function call exception (gcc 4.7.2 pb ?). Need to define NodeInFacePtr class
184 // typedef std::set<NodeInFacePtr> NodeInFaceSet;
185 typedef std::list<NodeInFacePtr> NodeInFaceSet;
186
187 NodeInFace(const Int64& node_uid)
188 : m_uid(node_uid)
189 , m_face_uid(NULL_ITEM_ID)
190 {}
191 // , m_next_node_set([](const NodeInFacePtr& a, const NodeInFacePtr& b){return (*a) < (*b);}){} // Does not work (gcc 4.7.2 pb ?). Need to define NodeInFacePtr class
192
193 friend bool operator<(const NodeInFace& a, const NodeInFace& nif)
194 {
195 return a.m_uid < nif.m_uid;
196 }
197 friend bool operator==(const NodeInFace& a, const NodeInFace& b)
198 {
199 return a.m_uid == b.m_uid;
200 }
201
202 Int64 faceUid() const { return m_face_uid; }
203 void setFaceUid(Int64 face_uid) { m_face_uid = face_uid; }
204
205 const NodeInFaceSet& nextNodeSet() const { return m_next_node_set; }
206 NodeInFaceSet& nextNodeSet() { return m_next_node_set; }
207 // void setNextNode(const NodeInFacePtr & next_node) {m_next_node_set.push_back(next_node);}
208
209 void print()
210 {
211 std::cout << "Node " << m_uid << " has set " << &m_next_node_set << " containing nodes : " << std::endl;
212 for (auto node : m_next_node_set) {
213 node->print();
214 }
215 }
216
217 public: //for DEBUG
218
219 // private:
220 Int64 m_uid;
221 Int64 m_face_uid;
222 NodeInFaceSet m_next_node_set;
223 };
224 // typedef NodeInFace::NodeInFacePtr NodeInFacePtr;
225 typedef NodeInFace::NodeInFaceSet NodeInFaceSet;
226
227 private:
228
229 void _printCellFaceInfos(ItemInternal* cell, const String& str);
230
231 void _removeNeedRemoveMarkedItems(ItemInternalMap& map, UniqueArray<Int32>& items_local_id);
232
233 void _fillFaceInfo(Integer& nb_face, Integer nb_cell, Int64Array& faces_infos, Int64ConstArrayView cells_infos, std::map<Int64, Int64SharedArray>& cell_to_face_connectivity_info);
234 void _fillEdgeInfo(Integer& nb_edge, Integer nb_face, Int64Array& edges_infos, Int64ConstArrayView faces_infos, std::map<std::pair<Int64, Int64>, Int64>& edge_uid_map);
235 void _fillNodeInfo(Integer& nb_node, Integer nb_face, Int64Array& nodes_infos, Int64ConstArrayView faces_infos);
236 void _fillNodeInfoFromEdge(Integer& nb_node, Integer nb_edge, Int64Array& nodes_infos, Int64ConstArrayView edges_infos);
237
238 void _fillCellInfo2(Integer nb_cell, Int64ConstArrayView cells_infos, Int64Array& cell_infos2, Integer& nb_face, Int64Array& faces_infos, Int64Array& node_uids, bool allow_build_face);
239 void _fillFaceInfo2(Integer nb_face, Int64ConstArrayView faces_infos, Int64ArrayView face_info2, Int64Array& node_uids);
240 void _fillEdgeInfo2(Integer nb_edge, Int64ConstArrayView edges_infos, Int64ArrayView edge_info2, Int64Array& node_uids);
241
242 void _fillEdgeNewInfoNew(Integer nb_edge, Int64ConstArrayView edges_infos, Int64ArrayView edge_new_infos);
243 void _fillNodeNewInfo(Int64ConstArrayView node_uids, Int64ArrayView node_infos2);
244 void _fillCellNewInfoNew(Integer nb_cell, Int64ConstArrayView cells_infos, Int64Array& cell_infos2, const std::map<Int64, Int64SharedArray>& cell_to_face_connectivity_info, const std::map<std::pair<Int64, Int64>, Int64>& edge_uid_map);
245 void _fillFaceNewInfoNew(Integer nb_face, Int64ConstArrayView faces_infos, Int64Array& face_infos2, const std::map<std::pair<Int64, Int64>, Int64>& edge_uid_map);
246 void _fillItemInfo2(ItemDataList& item_data_list, Int64ConstArrayView cells_infos);
247
248 void _initNodeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView faces_info);
249 void _initEdgeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView faces_info);
250 void _initFaceRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView faces_info);
251 void _appendNodeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView faces_info);
252 void _appendEdgeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView faces_info);
253 void _appendFaceRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView faces_info);
254 void _fillNodeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView nodes_info, bool is_source_item_relation_data_emtpy);
255 void _fillEdgeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView edges_info, bool is_source_item_relation_data_emtpy);
256 void _fillFaceRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView faces_info, bool is_source_item_relation_data_emtpy);
257 void _fillItemRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView source_item_types, bool is_source_item_relation_data_emtpy);
258 void _initEmptyRelationInfo(Int64Array& source_relation_info, std::map<Int64, Int64SharedArray>& source_to_target_uids, Int64ConstArrayView source_item_uids_and_types,
259 Integer approx_relation_size,
260 IItemFamily const* target_family);
261 void _appendInitializedRelationInfo(Int64Array& source_relation_info, std::map<Int64, Int64SharedArray>& source_to_target_uids, Int64ConstArrayView source_item_uids_and_types,
262 Integer approx_relation_size,
263 IItemFamily const* target_family);
264
265 Int64 _findFaceUniqueId(Int64ConstArrayView work_face_sorted_nodes, NodeInFaceSet& face_nodes_set);
266 Int64 _findFaceInFaceNodesSet(const NodeInFaceSet& face_nodes_set, Integer index, Int64ConstArrayView face_nodes, NodeInFacePtr node);
267 void _addFaceNodes(NodeInFaceSet& face_nodes_set, Int64ConstArrayView face_nodes, Int64 face_uid);
268 void _addFaceInFaceNodesSet(NodeInFaceSet& face_nodes_set, Integer index, Int64ConstArrayView face_nodes, NodeInFacePtr node, Int64 face_uid);
269 NodeInFacePtr& _insertNode(NodeInFaceSet& face_nodes_set, Int64 inserted_node_uid);
270 void _addItemsOrRelations(ItemDataList& info_list, IItemFamilyNetwork::eSchedulingOrder family_graph_traversal_order);
271
272 private:
273
275 ItemTypeMng* m_item_type_mng = nullptr;
276
278 bool m_has_edge = false;
279
282
283 bool m_verbose = false;
284 bool m_use_bulk_add_cells = false;
285
289 FaceUniqueIdBuilder* m_face_unique_id_builder = nullptr;
290 EdgeUniqueIdBuilder* m_edge_unique_id_builder = nullptr;
291
294};
295
296/*---------------------------------------------------------------------------*/
297/*---------------------------------------------------------------------------*/
298
299} // End namespace Arcane::mesh
300
301/*---------------------------------------------------------------------------*/
302/*---------------------------------------------------------------------------*/
303
304#endif
Declarations of Arcane's general types.
Base class for 1D data vectors.
Cell of a mesh.
Definition Item.h:1300
Constant view of an array of type T.
Interface of an entity family.
Definition IItemFamily.h:85
Internal structure of a mesh entity.
Mesh entity type manager.
Definition ItemTypeMng.h:64
View on a vector of entities.
Implementation of a buffer for serialization.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
1D data vector with value semantics (STL style).
void addNodes2(Int64ConstArrayView nodes_uid, Integer sub_domain_id, Int32ArrayView nodes)
Ajoute des noeuds au maillage actuel. Utilise l'ajout d'item générique basé sur dépendances entre fam...
void _fillBulkConnectivity(IncrementalItemConnectivity *c, Int32 nb_source, ConstArrayView< Int32 > offsets, ConstArrayView< Int32 > targets)
Fills a connectivity whose blocks are given in source-item order.
void computeFacesUniqueIds()
Calculates the unique IDs for each face.
void setConnectivity(Integer c)
Sets the active connectivity for the associated mesh.
void addParentCells(const ItemVectorView &items)
Add to the current mesh items coming from a parent mesh.
void addCells(Integer nb_cell, Int64ConstArrayView cell_infos, Integer sub_domain_id, Int32ArrayView cells, bool allow_build_face=true)
Adds cells to the current mesh.
void _initFaceRelationInfo(ItemData &source_item_relation_data, const ItemData &target_item_dependencies_data, Int64ConstArrayView faces_info)
Initializes face relation info.
void addParentItems(const ItemVectorView &items, const eItemKind submesh_kind)
Add to the current mesh items coming from a parent mesh.
OneMeshItemAdder * m_one_mesh_item_adder
Mesh building utilities.
void _fillFaceInfo(Integer &nb_face, Integer nb_cell, Int64Array &faces_infos, Int64ConstArrayView cells_infos, std::map< Int64, Int64SharedArray > &cell_to_face_connectivity_info)
Adds cells to the current mesh.
Int64 m_face_uid_pool
uniqueId() number used for generating faces
void resetAfterDeallocate()
Resets the structures to allow for a new allocation.
void addGhostChildFromParent(Array< Int64 > &ghost_cell_to_refine)
AMR.
void _fillBulkReverseConnectivity(IncrementalItemConnectivity *c, Int32 nb_target, Int32 nb_source, ConstArrayView< Int32 > offsets, ConstArrayView< Int32 > targets)
Fills the reverse of a connectivity given in source-item order.
bool addCellsBulk(Integer nb_cell, Int64ConstArrayView cell_infos, Integer sub_domain_id, Int32ArrayView cells, bool allow_build_face)
Same as addCells(), filling the family arrays in bulk.
void addEdges2(Integer nb_edge, Int64ConstArrayView edge_infos, Integer sub_domain_id, Int32ArrayView edges)
Adds edges to the current mesh. Uses generic item addition based on family dependencies.
Int64 m_edge_uid_pool
uniqueId() number used for generating edges
void addItems(ItemDataList &item_info_list)
Ajout générique d'items d'un ensemble de famille pour lesquelles on fournit un ItemData.
void addNodes(Int64ConstArrayView nodes_uid, Integer sub_domain_id, Int32ArrayView nodes)
Ajoute des noeuds au maillage actuel.
void addFaces(Integer nb_face, Int64ConstArrayView face_infos, Integer sub_domain_id, Int32ArrayView faces)
Ajoute des faces au maillage actuel.
void addEdges(Integer nb_edge, Int64ConstArrayView edge_infos, Integer sub_domain_id, Int32ArrayView edges)
Adds edges to the current mesh.
GhostLayerBuilder * m_ghost_layer_builder
Utility to build ghost elements.
void addHChildrenCells(Cell hParent_cell, Integer nb_cell, Int64ConstArrayView cells_infos, Int32 sub_domain_id, Int32ArrayView cells, bool allow_build_face)
Ajoute des mailles au maillage actuel.
void _allocateBulkByType(FamilyType *family, Int64ConstArrayView uids, ConstArrayView< Int16 > type_ids, Int32 owner, Int32ArrayView lids)
Allocates items in batches of one type, since a batch carries one shared info.
bool m_has_edge
Info on the presence of an edge (accelerates access to general connectivity).
void addFamilyItems(ItemData &item_info)
Ajout générique d'items d'une famille, décrite par son ItemInfo.
DynamicMeshIncrementalBuilder(DynamicMesh *mesh)
Constructs an instance for the mesh mesh.
bool m_use_bulk_add_cells
ARCANE_BULK_ADD_CELLS=1: addCells() fills the families in bulk.
void addCells3(Integer nb_cell, Int64ConstArrayView cell_infos, Integer sub_domain_id, Int32ArrayView cells, bool allow_build_face=true)
Adds cells to the current mesh. Uses generic item addition based on family dependencies.
void addFaces2(Integer nb_face, Int64ConstArrayView face_infos, Integer sub_domain_id, Int32ArrayView faces)
Ajoute des faces au maillage actuel. Utilise l'ajout d'item générique basé sur dépendances entre fami...
Integer m_connectivity
Connectivity info of the current mesh.
Implementation of a mesh.
Definition DynamicMesh.h:98
Construction of ghost layers.
Construction of ghost layers.
Construction of ghost layers.
Associative array of ItemInternal.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Dynamic one-dimensional array of 64-bit integers.
Definition UtilsTypes.h:119
ArrayView< Int64 > Int64ArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:445
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:474
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:447
eItemKind
Mesh entity type.
std::int32_t Int32
Signed integer type of 32 bits.