Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemFamily.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/* ItemFamily.h (C) 2000-2026 */
9/* */
10/* Entity Family. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MESH_ITEMFAMILY_H
13#define ARCANE_MESH_ITEMFAMILY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/List.h"
18#include "arcane/utils/String.h"
19#include "arcane/utils/TraceAccessor.h"
20
21#include "arcane/core/IItemFamily.h"
22#include "arcane/core/ItemPairGroup.h"
23#include "arcane/core/ObserverPool.h"
24#include "arcane/core/IItemConnectivity.h"
25#include "arcane/core/IIncrementalItemConnectivity.h"
26#include "arcane/core/ItemSharedInfo.h"
27#include "arcane/core/ItemGroup.h"
28
29#include <map>
30#include <set>
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35namespace Arcane
36{
37class Timer;
39class Properties;
43class IMeshCompacter;
45class ItemDataList;
46template <typename T> class ItemScalarProperty;
47} // namespace Arcane
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
52namespace Arcane::mesh
53{
54class ItemInternalMap;
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
73class ARCANE_MESH_EXPORT ItemFamily
74: public TraceAccessor
75, public IItemFamily
76{
77 private:
78
79 class Variables;
80 class InternalApi;
81 class AdjacencyInfo
82 {
83 public:
84
85 AdjacencyInfo(const ItemGroup& item_group, const ItemGroup& sub_item_group,
86 eItemKind link_kind, Integer nb_layer)
87 : m_item_group(item_group)
88 , m_sub_item_group(sub_item_group)
89 , m_link_kind(link_kind)
90 , m_nb_layer(nb_layer)
91 {
92 }
93
94 public:
95
96 ItemGroup m_item_group;
97 ItemGroup m_sub_item_group;
98 eItemKind m_link_kind;
99 Integer m_nb_layer;
100
101 public:
102
103 bool operator<(const AdjacencyInfo& rhs) const
104 {
105 if (m_item_group != rhs.m_item_group)
106 return m_item_group < rhs.m_item_group;
107 if (m_sub_item_group != rhs.m_sub_item_group)
108 return m_sub_item_group < rhs.m_sub_item_group;
109 if (m_link_kind != rhs.m_link_kind)
110 return m_link_kind < rhs.m_link_kind;
111 return m_nb_layer < rhs.m_nb_layer;
112 }
113 };
114 using AdjacencyGroupMap = std::map<AdjacencyInfo, ItemPairGroup>;
115 // Keeps the misspelled version for compatibility reasons
116 // TODO: to be removed by mid 2025
117 using AdjencyGroupMap = AdjacencyGroupMap;
118
123 static bool _cmpIVariablePtr(const IVariable* a, const IVariable* b);
124
125 public:
126
127 using ItemInternalMap = ::Arcane::mesh::ItemInternalMap;
128
129 public:
130
131 ItemFamily(IMesh* mesh, eItemKind ik, const String& name);
132 ~ItemFamily() override; //<! Frees resources
133
134 public:
135
136 void build() override;
137
138 public:
139
140 String name() const override { return m_name; }
141 String fullName() const override { return m_full_name; }
142 eItemKind itemKind() const override;
143 Integer nbItem() const override;
144 Int32 maxLocalId() const override;
145 ItemInternalList itemsInternal() override;
146 ItemInfoListView itemInfoListView() override;
147 VariableItemInt32& itemsNewOwner() override;
148 IItemFamily* parentFamily() const override;
149 void setParentFamily(IItemFamily* parent) override;
150 Integer parentFamilyDepth() const override;
151 void addChildFamily(IItemFamily* family) override;
152 IItemFamilyCollection childFamilies() override;
153
154 void checkValid() override;
155 void checkValidConnectivity() override;
156 void checkUniqueIds(Int64ConstArrayView unique_ids) override;
157
158 public:
159
160 ItemInternalMap& itemsMap();
161
162 public:
163
164 void endUpdate() override;
165 void partialEndUpdate() override;
166 void partialEndUpdateGroup(const ItemGroup& group) override;
167 void partialEndUpdateVariable(IVariable* variable) override;
168
169 public:
170
171 void itemsUniqueIdToLocalId(ArrayView<Int64> ids, bool do_fatal = true) const;
172 void itemsUniqueIdToLocalId(Int32ArrayView local_ids,
173 Int64ConstArrayView unique_ids,
174 bool do_fatal) const override;
175 void itemsUniqueIdToLocalId(Int32ArrayView local_ids,
177 bool do_fatal) const override;
178
179 public:
180
181 ISubDomain* subDomain() const override;
182 ITraceMng* traceMng() const override;
183 IMesh* mesh() const override;
184 IParallelMng* parallelMng() const override;
185
186 public:
187
188 IItemConnectivityInfo* localConnectivityInfos() const override;
189 IItemConnectivityInfo* globalConnectivityInfos() const override;
190
191 public:
192
193 void internalRemoveItems(Int32ConstArrayView local_ids, bool keep_ghost = false) override;
194 void removeItems2(ItemDataList& item_data_list) override; // Remove items based on family dependencies (ItemFamilyNetwork)
195 void removeNeedRemoveMarkedItems() override;
196
197 ItemVectorView view(Int32ConstArrayView local_ids) override;
198 ItemVectorView view() override;
199
200 ItemInternal* findOneItem(Int64 uid) override;
201
202 public:
203
204 ItemGroup allItems() const override;
205
206 public:
207
208 void notifyItemsOwnerChanged() override;
209 ItemGroup findGroup(const String& name) const override;
210 ItemGroup findGroup(const String& name, bool create_if_needed) override;
211 ItemGroup createGroup(const String& name, Int32ConstArrayView elements, bool do_override = false) override;
212 ItemGroup createGroup(const String& name) override;
213 ItemGroup createGroup(const String& name, const ItemGroup& parent, bool do_override = false) override;
214 ItemGroupCollection groups() const override;
215 void notifyItemsUniqueIdChanged() override;
216 void destroyGroups() override;
217
218 public:
219
220 IVariable* findVariable(const String& name, bool throw_exception) override;
221 void usedVariables(VariableCollection collection) override;
222
223 public:
224
225 void prepareForDump() override;
226 void readFromDump() override;
227 void copyItemsValues(Int32ConstArrayView source, Int32ConstArrayView destination) override;
228 void copyItemsMeanValues(Int32ConstArrayView first_source,
229 Int32ConstArrayView second_source,
230 Int32ConstArrayView destination) override;
231 void compactItems(bool do_sort) override;
232 void clearItems() override;
233
234 Int64ArrayView* uniqueIds();
235
236 ItemSharedInfo* commonItemSharedInfo() { return m_common_item_shared_info; }
237
238 public:
239
240 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane. Use _infos() instead.")
241 const DynamicMeshKindInfos& infos() const;
242
243 public:
244
245 void setHasUniqueIdMap(bool v) override;
246 bool hasUniqueIdMap() const override;
247
248 public:
249
250 void computeSynchronizeInfos() override;
251 void getCommunicatingSubDomains(Int32Array& sub_domains) const override;
252 void synchronize(VariableCollection variables) override;
253 void synchronize(VariableCollection variables, Int32ConstArrayView local_ids) override;
254 IVariableSynchronizer* allItemsSynchronizer() override;
255
256 void reduceFromGhostItems(IVariable* v, IDataOperation* operation) override;
257 void reduceFromGhostItems(IVariable* v, Parallel::eReduceType operation) override;
258
259 public:
260
261 ARCANE_DEPRECATED_REASON("Y2024: use findAdjacencyItems() instead")
262 ItemPairGroup findAdjencyItems(const ItemGroup& group,
263 const ItemGroup& sub_group, eItemKind link_kind,
264 Integer layer) override;
265 ItemPairGroup findAdjacencyItems(const ItemGroup& group,
266 const ItemGroup& sub_group, eItemKind link_kind,
267 Integer layer) override;
268 IParticleFamily* toParticleFamily() override { return nullptr; }
269 void setItemSortFunction(IItemInternalSortFunction* sort_function) override;
270 IItemInternalSortFunction* itemSortFunction() const override;
271
272 public:
273
274 void addSourceConnectivity(IItemConnectivity* connectivity) override;
275 void addTargetConnectivity(IItemConnectivity* connectivity) override;
276 void removeSourceConnectivity(IItemConnectivity* connectivity) override;
277 void removeTargetConnectivity(IItemConnectivity* connectivity) override;
278 void setConnectivityMng(IItemConnectivityMng* connectivity_mng) override;
279
280 void addGhostItems(Int64ConstArrayView unique_ids, Int32ArrayView items, Int32ConstArrayView owners) override;
282 void experimentalChangeUniqueId(ItemLocalId local_id, ItemUniqueId unique_id) override;
283
284 IItemFamilyPolicyMng* policyMng() override { return m_policy_mng; }
285 Properties* properties() override { return m_properties; }
286 IItemFamilyInternal* _internalApi() override;
287
288 public:
289
290 //NOTE: This method must be virtual for PolyhedralMesh to set the policy.
291 virtual void setPolicyMng(IItemFamilyPolicyMng* policy_mng);
292
293 public:
294
295 void beginCompactItems(ItemFamilyCompactInfos& compact_infos);
298 void compactVariablesAndGroups(const ItemFamilyCompactInfos& compact_infos);
299 void finishCompactItems(ItemFamilyCompactInfos& compact_infos);
300 void removeItem(Item item)
301 {
302 _removeOne(item);
303 }
309
310 protected:
311
312 void _removeOne(Item item);
313 void _detachOne(Item item);
314 ItemInternalList _itemsInternal();
315 ItemInternal* _itemInternal(Int32 local_id);
316 ItemInternal* _allocOne(Int64 unique_id);
317 ItemInternal* _allocOne(Int64 unique_id, bool& need_alloc);
318 ItemInternal* _findOrAllocOne(Int64 uid, bool& is_alloc);
319 void _setHasUniqueIdMap(bool v);
320 void _removeMany(Int32ConstArrayView local_ids);
321 void _removeDetachedOne(Item item);
322 const DynamicMeshKindInfos& _infos() const;
323
324 void _detachCells2(Int32ConstArrayView local_ids);
325
326 virtual void _endAllocate();
327 virtual void _notifyEndUpdateFromMesh();
328
329 protected:
330
331 String m_name;
332 String m_full_name;
333 IMesh* m_mesh = nullptr;
334 InternalApi* m_internal_api = nullptr;
335 ISubDomain* m_sub_domain = nullptr;
336 IItemFamily* m_parent_family = nullptr;
337 Integer m_parent_family_depth = 0;
338
339 private:
340
341 std::unique_ptr<DynamicMeshKindInfos> m_infos;
342
343 protected:
344
345 ItemGroupList m_item_groups;
346 bool m_need_prepare_dump = true;
347 MeshItemInternalList* m_item_internal_list = nullptr;
348
349 private:
350
351 ItemSharedInfo* m_common_item_shared_info = nullptr;
352
353 protected:
354
355 ItemSharedInfoList* m_item_shared_infos = nullptr;
356 ObserverPool m_observers;
357 Ref<IVariableSynchronizer> m_variable_synchronizer;
358 Integer m_current_variable_item_size = 0;
359 IItemInternalSortFunction* m_item_sort_function = nullptr;
360 std::set<IVariable*, decltype(&_cmpIVariablePtr)> m_used_variables;
361 std::set<IVariable*, decltype(&_cmpIVariablePtr)> m_used_shmem_variables;
362 UniqueArray<ItemFamily*> m_child_families;
363 ItemConnectivityInfo* m_local_connectivity_info = nullptr;
364 ItemConnectivityInfo* m_global_connectivity_info = nullptr;
365 Properties* m_properties = nullptr;
366 typedef std::set<IItemConnectivity*> ItemConnectivitySet;
367 ItemConnectivitySet m_source_item_connectivities;
368 ItemConnectivitySet m_target_item_connectivities;
370
371 private:
372
373 UniqueArray<Ref<IIncrementalItemSourceConnectivity>> m_source_incremental_item_connectivities;
374 UniqueArray<Ref<IIncrementalItemTargetConnectivity>> m_target_incremental_item_connectivities;
375
376 protected:
377
378 IItemFamilyPolicyMng* m_policy_mng = nullptr;
379
380 protected:
381
382 void _checkNeedEndUpdate() const;
383 void _updateSharedInfo();
384
385 void _allocateInfos(ItemInternal* item, Int64 uid, ItemSharedInfoWithType* isi);
386 void _allocateInfos(ItemInternal* item, Int64 uid, ItemTypeInfo* type);
387 void _endUpdate(bool need_check_remove);
388 bool _partialEndUpdate();
389 void _updateGroup(ItemGroup group, bool need_check_remove);
390 void _updateVariable(IVariable* var);
391
392 void _addConnectivitySelector(ItemConnectivitySelector* selector);
393 void _buildConnectivitySelectors();
394 void _preAllocate(Int32 nb_item, bool pre_alloc_connectivity);
395 ItemInternalConnectivityList* _unstructuredItemInternalConnectivityList()
396 {
398 }
399
400 public:
401
402 IItemFamilyTopologyModifier* _topologyModifier() override { return m_topology_modifier; }
403 void resizeVariables(bool force_resize) override
404 {
405 _resizeShMemVariables();
406 _resizeVariables(force_resize);
407 }
408
409 private:
410
411 Int64Array* m_items_unique_id = nullptr;
412 Int32Array* m_items_owner = nullptr;
413 Int32Array* m_items_flags = nullptr;
414 Int16Array* m_items_type_id = nullptr;
415 Int32Array* m_items_nb_parent = nullptr;
416 // TODO: to be deleted because it is redundant with the corresponding field in ItemSharedInfo
417 Int64ArrayView m_items_unique_id_view;
418 Variables* m_internal_variables = nullptr;
419 Int32 m_default_sub_domain_owner = A_NULL_RANK;
420
421 protected:
422
423 Int32 m_sub_domain_id = A_NULL_RANK;
424
425 private:
426
427 bool m_is_parallel = false;
428
440
441 bool m_item_need_prepare_dump = false;
442
443 private:
444
445 Int64 m_nb_allocate_info = 0;
446
447 private:
448
449 AdjacencyGroupMap m_adjacency_groups;
450 UniqueArray<ItemConnectivitySelector*> m_connectivity_selector_list;
451 IItemFamilyTopologyModifier* m_topology_modifier = nullptr;
454
455 UniqueArray<ItemConnectivitySelector*> m_connectivity_selector_list_by_item_kind;
456 bool m_use_legacy_compact_item = false;
457
458 private:
459
460 ItemTypeMng* m_item_type_mng = nullptr;
461 bool m_do_shrink_after_allocate = false;
462
463 protected:
464
465 ItemTypeMng* _itemTypeMng() const { return m_item_type_mng; }
466 virtual IItemInternalSortFunction* _defaultItemSortFunction();
467
468 ARCANE_DEPRECATED_REASON("Y2022: This method is a now a no-operation")
469 void _reserveInfosMemory(Integer memory);
470 ARCANE_DEPRECATED_REASON("Y2022: This method is a now a no-operation")
471 void _resizeInfos(Integer memory);
472
473 ItemSharedInfoWithType* _findSharedInfo(ItemTypeInfo* type);
474
475 ARCANE_DEPRECATED_REASON("Y2022: This method always return 0")
476 Integer _allocMany(Integer memory);
477 void _setSharedInfosPtr(Integer* ptr);
478 void _checkValid();
479 void _checkValidConnectivity();
480 void _notifyDataIndexChanged();
481 void _processNewGroup(ItemGroup group);
482 String _variableName(const String& base_name) const;
483 template <class Type> void
484 _synchronizeVariable(IVariable* var, Type* var_value, Integer nb_elem);
485 void _updateGroups(bool check_need_remove);
486 void _compactFromParentFamily(const ItemFamilyCompactInfos& compact_infos);
487 void _checkComputeSynchronizeInfos(Int32 changed);
488 void _readGroups();
489 void _invalidateComputedGroups();
490 void _compactItems(bool do_sort);
491 void _compactOnlyItems(bool do_sort);
492 void _applyCheckNeedUpdateOnGroups();
493 void _setTopologyModifier(IItemFamilyTopologyModifier* tm);
494
495 private:
496
497 void _updateItemsSharedFlag();
498
499 protected:
500
501 void _checkValidItem(ItemInternal* item)
502 {
503#ifdef ARCANE_CHECK
504 arcaneThrowIfNull(item, "item", "Invalid null item");
505#else
506 ARCANE_UNUSED(item);
507#endif
508 }
509 void _checkValidSourceTargetItems(ItemInternal* source, ItemInternal* target)
510 {
511#ifdef ARCANE_CHECK
512 arcaneThrowIfNull(source, "source", "Invalid null source item");
513 arcaneThrowIfNull(target, "target", "Invalid null target item");
514#else
515 ARCANE_UNUSED(source);
516 ARCANE_UNUSED(target);
517#endif
518 }
519 void _checkValidItem(Item item) { _checkValidItem(ItemCompatibility::_itemInternal(item)); }
520 void _checkValidSourceTargetItems(Item source, Item target)
521 {
522 _checkValidItem(ItemCompatibility::_itemInternal(source));
523 _checkValidItem(ItemCompatibility::_itemInternal(target));
524 }
525
526 private:
527
528 void _getConnectedItems(IIncrementalItemConnectivity* parent_connectivity, ItemVector& target_family_connected_items);
529 void _fillHasExtraParentProperty(ItemScalarProperty<bool>& child_families_has_extra_parent, ItemVectorView connected_items);
530 void _computeConnectivityInfo(ItemConnectivityInfo* ici);
531 void _updateItemViews();
532 void _resizeItemVariables(Int32 new_size, bool force_resize);
533 void _handleOldCheckpoint();
534
535 void _addSourceConnectivity(IIncrementalItemSourceConnectivity* c);
536 void _addTargetConnectivity(IIncrementalItemTargetConnectivity* c);
537 void _addVariable(IVariable* var);
538 void _removeVariable(IVariable* var);
539 void _resizeVariables(bool force_resize);
540 void _resizeShMemVariables();
541 void _shrinkConnectivityAndPrintInfos();
542 void _addOnSizeChangedObservable(VariableRef& var_ref);
543};
544
545/*---------------------------------------------------------------------------*/
546/*---------------------------------------------------------------------------*/
547
548} // namespace Arcane::mesh
549
550/*---------------------------------------------------------------------------*/
551/*---------------------------------------------------------------------------*/
552#endif
Modifiable view of an array of type T.
Constant view of an array of type T.
Class managing observers associated with an event.
Interface of an operation on a data.
Interface for managing an incremental connectivity.
Interface for connectivity information by entity type.
Interface to manage connectivity.
Internal part of IItemFamily.
Interface for entity family policies.
Interface for modifying the topology of entities within a family.
Interface of an entity family.
Definition IItemFamily.h:83
Interface of an entity sorting function.
Management of mesh family compaction.
Interface of the parallelism manager for a subdomain.
Interface of a particle family.
Interface of the subdomain manager.
Definition ISubDomain.h:75
Interface of a variable synchronization service.
Interface of a variable.
Definition IVariable.h:40
Information to manage the compaction of entities of a family.
Mesh entity group.
Definition ItemGroup.h:51
View of a list to obtain information about entities.
Connectivity information, for an entity family, allowing transition between old and new connectivity ...
Internal structure of a mesh entity.
Index of an Item in a variable.
Definition ItemLocalId.h:42
Table of entity lists.
Internal shared structure of a mesh entity.
Info on a mesh entity type.
Mesh entity type manager.
Definition ItemTypeMng.h:66
Unique identifier of an entity.
View on a vector of entities.
Base class for a mesh element.
Definition Item.h:84
Indirection tables for mesh entities.
List of observers.
List of properties.
Definition Properties.h:65
Reference to an instance.
Management of a timer.
Definition Timer.h:63
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
1D data vector with value semantics (STL style).
Mesh information for a given entity kind.
Information on connectivity by entity type.
Selection between historical and on-demand connectivities.
IMesh * mesh() const override
Associated mesh.
String fullName() const override
Full family name (with the mesh's name).
Definition ItemFamily.h:141
ItemInternalConnectivityList m_item_connectivity_list
Accessor for connectivities via Item and ItemInternal.
Definition ItemFamily.h:453
IParticleFamily * toParticleFamily() override
Returns the interface of the particle family for this family.
Definition ItemFamily.h:268
Integer m_current_id
Family identifier.
Definition ItemFamily.h:439
ItemInternalConnectivityList * itemInternalConnectivityList()
Accessor for connectivities via Item and ItemInternal.
Definition ItemFamily.h:305
IItemFamilyTopologyModifier * _topologyModifier() override
Topology modifier interface.
Definition ItemFamily.h:402
ItemConnectivitySet m_target_item_connectivities
connectivite ou ItemFamily == SourceFamily
Definition ItemFamily.h:368
static bool _cmpIVariablePtr(const IVariable *a, const IVariable *b)
Function to compare two variable names (strcmp).
IItemConnectivityMng * m_connectivity_mng
connectivite ou ItemFamily == TargetFamily
Definition ItemFamily.h:369
Properties * properties() override
Properties associated with this family.
Definition ItemFamily.h:285
void resizeVariables(bool force_resize) override
Resizes the variables of this family.
Definition ItemFamily.h:403
String name() const override
Family name.
Definition ItemFamily.h:140
IItemFamilyPolicyMng * policyMng() override
Interface of behaviors/policies associated with this family.
Definition ItemFamily.h:284
Associative array of ItemInternal.
Mesh info for a given entity type.
Temporary class to hold an ItemSharedInfo and an entity type.
ItemVariableScalarRefT< Int32 > VariableItemInt32
32-bit integer type quantity
eReduceType
Supported reduction types.
Concurrency implementation.
-- 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:125
ArrayView< Int64 > Int64ArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:451
Collection< ItemGroup > ItemGroupCollection
Collection of mesh item groups.
std::int64_t Int64
Signed integer type of 64 bits.
Array< Int16 > Int16Array
Dynamic one-dimensional array of 16-bit integers.
Definition UtilsTypes.h:129
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.
ConstArrayView< ItemInternal * > ItemInternalList
Type of the internal list of entities.
Definition ItemTypes.h:466
Collection< IItemFamily * > IItemFamilyCollection
Collection of item families.
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.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
Definition UtilsTypes.h:127
std::int32_t Int32
Signed integer type of 32 bits.
Type
Type of JSON value.
Definition rapidjson.h:730