14#include "arcane/mesh/IncrementalItemConnectivity.h"
16#include "arcane/utils/StringBuilder.h"
17#include "arcane/utils/ArgumentException.h"
18#include "arcane/utils/PlatformUtils.h"
19#include "arcane/utils/ValueConvert.h"
21#include "arcane/core/IMesh.h"
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/ConnectivityItemVector.h"
25#include "arcane/core/ObserverPool.h"
26#include "arcane/core/Properties.h"
27#include "arcane/core/IndexedItemConnectivityView.h"
28#include "arcane/core/internal/IDataInternal.h"
29#include "arcane/core/internal/IItemFamilyInternal.h"
30#include "arcane/core/internal/IIncrementalItemConnectivityInternal.h"
32#include "arcane/mesh/IndexedItemConnectivityAccessor.h"
33#include "arcane/mesh/internal/LazyMemoryPool.h"
44IndexedItemConnectivityAccessor::
45IndexedItemConnectivityAccessor(IndexedItemConnectivityViewBase view, IItemFamily* target_item_family)
46: IndexedItemConnectivityViewBase(view)
47, m_item_shared_info(target_item_family->_internalApi()->commonItemSharedInfo())
53IndexedItemConnectivityAccessor::
54IndexedItemConnectivityAccessor(IIncrementalItemConnectivity* connectivity)
55: m_item_shared_info(connectivity->targetFamily()->_internalApi()->commonItemSharedInfo())
57 auto* ptr =
dynamic_cast<mesh::IncrementalItemConnectivityBase*
>(connectivity);
59 IndexedItemConnectivityViewBase::set(ptr->connectivityView());
65AbstractIncrementalItemConnectivity::
66AbstractIncrementalItemConnectivity(IItemFamily* source_family,
67 IItemFamily* target_family,
68 const String& connectivity_name)
69: TraceAccessor(source_family->traceMng())
70, m_source_family(source_family)
71, m_target_family(target_family)
72, m_name(connectivity_name)
74 m_families.add(m_source_family);
75 m_families.add(m_target_family);
78 source_family->_internalApi()->addSourceConnectivity(
this);
79 target_family->_internalApi()->addTargetConnectivity(
this);
106class IncrementalItemConnectivityContainer
110 IncrementalItemConnectivityContainer(
IMesh*
mesh,
const String& var_name)
111 : m_var_name(var_name)
115 , m_connectivity_nb_item_array(m_connectivity_nb_item_variable._internalTrueData()->_internalDeprecatedValue())
116 , m_connectivity_index_array(m_connectivity_index_variable._internalTrueData()->_internalDeprecatedValue())
117 , m_connectivity_list_array(m_connectivity_list_variable._internalTrueData()->_internalDeprecatedValue())
122 String tag_name =
"ArcaneConnectivity";
123 m_connectivity_nb_item_variable.addTag(tag_name,
"1");
124 m_connectivity_index_variable.addTag(tag_name,
"1");
125 m_connectivity_list_variable.addTag(tag_name,
"1");
151 Integer size()
const {
return m_connectivity_nb_item_array.size(); }
153 bool isAllocated()
const {
return size() > 0; }
155 void _checkResize(
Int32 lid)
158 Integer size = m_connectivity_nb_item_array.
size();
160 if (wanted_size < size)
163 if (wanted_size < capacity) {
167 Integer reserve_size = 1000;
168 while (lid > reserve_size) {
171 m_connectivity_nb_item_array.
reserve(reserve_size);
172 m_connectivity_index_array.
reserve(reserve_size);
174 m_connectivity_nb_item_array.
resize(wanted_size);
175 m_connectivity_index_array.
resize(wanted_size);
178 void reserveForItems(Int32 capacity)
180 m_connectivity_nb_item_array.
reserve(capacity);
181 m_connectivity_index_array.
reserve(capacity);
229 explicit InternalApi(IncrementalItemConnectivityBase* v)
235 void shrinkMemory()
override {
return m_internal_api->_shrinkMemory(); }
238 m_internal_api->_addMemoryInfos(mem_info);
244 IncrementalItemConnectivityBase* m_internal_api =
nullptr;
250IncrementalItemConnectivityBase::
254, m_internal_api(std::make_unique<InternalApi>(this))
258 var_name += source_family->
name();
259 var_name += target_family->
name();
266 m_p->m_observers.addObserver(
this, &ThatClass::_notifyConnectivityNbItemChangedFromObservable,
267 m_p->m_connectivity_nb_item_variable.variable()->readObservable());
269 m_p->m_observers.addObserver(
this, &ThatClass::_notifyConnectivityIndexChanged,
270 m_p->m_connectivity_index_variable.variable()->readObservable());
272 m_p->m_observers.addObserver(
this, &ThatClass::_notifyConnectivityListChanged,
273 m_p->m_connectivity_list_variable.variable()->readObservable());
278 m_p->m_observers.addObserver(
this, &ThatClass::_checkMaterialize,
279 m_p->m_connectivity_nb_item_variable.variable()->writeObservable());
280 m_p->m_observers.addObserver(
this, &ThatClass::_checkMaterialize,
281 m_p->m_connectivity_index_variable.variable()->writeObservable());
286 _notifyConnectivityListChanged();
287 _notifyConnectivityIndexChanged();
294IncrementalItemConnectivityBase::
295~IncrementalItemConnectivityBase()
310 m_p->reserveForItems(n);
311 _notifyConnectivityIndexChanged();
312 _notifyConnectivityNbItemChanged();
314 if (pre_alloc_connectivity) {
316 if (pre_alloc_size > 0) {
317 m_p->m_connectivity_list_array.reserve(n * pre_alloc_size);
318 _notifyConnectivityListChanged();
326void IncrementalItemConnectivityBase::
327_notifyConnectivityListChanged()
329 m_connectivity_list = m_p->m_connectivity_list_array.
view();
330 if (m_item_connectivity_list)
337void IncrementalItemConnectivityBase::
338_lazyNotifySourceItemAdded(
Int32 lid)
343 if (n <= m_connectivity_nb_item.
size())
363 _setLazyViews(zeros);
369void IncrementalItemConnectivityBase::
375 if (m_item_connectivity_list) {
395 Int32 nb_zero = m_p->m_lazy_nb_source;
397 nb_zero =
math::max(nb_zero, family->maxLocalId());
412 Int32 n = m_p->m_lazy_nb_source;
415 m_p->m_connectivity_nb_item_array.resize(n);
416 m_p->m_connectivity_index_array.resize(n);
417 m_p->m_connectivity_nb_item_array.fill(0);
418 m_p->m_connectivity_index_array.fill(0);
419 _notifyConnectivityIndexChanged();
420 _notifyConnectivityNbItemChanged();
426void IncrementalItemConnectivityBase::
427_notifyConnectivityIndexChanged()
435 m_connectivity_index = m_p->m_connectivity_index_array.
view();
436 if (m_item_connectivity_list)
443void IncrementalItemConnectivityBase::
444_notifyConnectivityNbItemChanged()
450 m_connectivity_nb_item = m_p->m_connectivity_nb_item_array.view();
451 if (m_item_connectivity_list)
452 m_item_connectivity_list->_setConnectivityNbItem(m_item_connectivity_index, m_connectivity_nb_item);
458void IncrementalItemConnectivityBase::
459_setMaxNbConnectedItemsInConnectivityList()
461 if (m_item_connectivity_list)
462 m_item_connectivity_list->_setMaxNbConnectedItem(m_item_connectivity_index, m_p->m_max_nb_item);
476 if (
m_is_lazy && m_p->m_connectivity_nb_item_array.size() > 0) {
479 m_p->m_lazy_nb_source = m_p->m_connectivity_nb_item_array.size();
480 _notifyConnectivityIndexChanged();
482 _notifyConnectivityNbItemChanged();
483 _computeMaxNbConnectedItem();
489void IncrementalItemConnectivityBase::
490_setNewMaxNbConnectedItems(
Int32 new_max)
494 _setMaxNbConnectedItemsInConnectivityList();
501void IncrementalItemConnectivityBase::
502_computeMaxNbConnectedItem()
506 Int32 max_nb_item = 0;
507 for (Int32 x : m_connectivity_nb_item)
510 _setNewMaxNbConnectedItems(max_nb_item);
519 return m_p->m_max_nb_item;
534 info(4) <<
"setItemConnectivityList name=" <<
name() <<
" ilist=" << ilist <<
" index=" << index;
535 m_item_connectivity_list = ilist;
536 m_item_connectivity_index = index;
537 _notifyConnectivityListChanged();
538 _notifyConnectivityIndexChanged();
539 _notifyConnectivityNbItemChanged();
540 _setMaxNbConnectedItemsInConnectivityList();
551 m_p->m_lazy_nb_source = new_to_old_ids.
size();
554 if (m_p->isAllocated()) {
555 m_p->m_connectivity_nb_item_variable.variable()->compact(new_to_old_ids);
556 m_p->m_connectivity_index_variable.variable()->compact(new_to_old_ids);
557 _notifyConnectivityNbItemChanged();
558 _notifyConnectivityIndexChanged();
570 for (
Integer i = 0; i < n; ++i)
571 if (ids[i] != NULL_ITEM_LOCAL_ID)
572 ids[i] = old_to_new_ids[ids[i]];
581 return con_items.
resizeAndCopy(_connectedItemsLocalId(item));
588connectivityContainerView()
const
590 return { m_connectivity_list, m_connectivity_index, m_connectivity_nb_item };
596IndexedItemConnectivityViewBase IncrementalItemConnectivityBase::
597connectivityView()
const
599 return { connectivityContainerView(), _sourceFamily()->
itemKind(), _targetFamily()->
itemKind() };
605IndexedItemConnectivityAccessor IncrementalItemConnectivityBase::
606connectivityAccessor()
const
608 return IndexedItemConnectivityAccessor(connectivityView(), _targetFamily());
617 return m_internal_api.get();
623void IncrementalItemConnectivityBase::
626 info() <<
"Infos index=" << m_connectivity_index;
627 info() <<
"Infos nb_item=" << m_connectivity_nb_item;
628 info() <<
"Infos list=" << m_connectivity_list;
637IncrementalItemConnectivity::
640: IncrementalItemConnectivityBase(source_family, target_family, aname)
644, m_pre_allocated_size(0)
647 info(4) <<
"PreallocSize1 var=" << m_p->m_var_name <<
" v=" << m_pre_allocated_size;
652 m_is_lazy = is_lazy && is_lazy.value() != 0;
661IncrementalItemConnectivity::
662~IncrementalItemConnectivity()
666 info(4) <<
" connectivity name=" <<
name()
667 <<
" prealloc_size=" << m_pre_allocated_size
668 <<
" nb_add=" << m_nb_add
669 <<
" nb_remove=" << m_nb_remove
670 <<
" nb_memcopy=" << m_nb_memcopy;
676inline Integer IncrementalItemConnectivity::
677_increaseConnectivityList(
Int32 new_lid)
679 Integer pos_in_list = m_connectivity_list.size();
680 m_p->m_connectivity_list_array.add(new_lid);
681 _notifyConnectivityListChanged();
688inline Integer IncrementalItemConnectivity::
689_increaseConnectivityList(
Int32 new_lid,
Integer nb_value)
691 Integer pos_in_list = m_connectivity_list.size();
692 m_p->m_connectivity_list_array.addRange(new_lid, nb_value);
693 _notifyConnectivityListChanged();
700void IncrementalItemConnectivity::
701_resetConnectivityList()
703 m_p->m_connectivity_list_array.clear();
704 _notifyConnectivityListChanged();
711void IncrementalItemConnectivity::
714 Integer added_range = (m_pre_allocated_size > 0) ? m_pre_allocated_size : 1;
716 Integer pos_in_index = m_connectivity_index[lid];
717 Integer new_pos_in_list = _increaseConnectivityList(NULL_ITEM_LOCAL_ID, size + added_range);
718 ArrayView<Int32> current_list(size, &(m_connectivity_list[pos_in_index]));
719 ArrayView<Int32> new_list(size + 1, &(m_connectivity_list[new_pos_in_list]));
720 new_list.copy(current_list);
723 new_list[size] = target_lid;
724 m_connectivity_index[lid] = new_pos_in_list;
735 const Int32 lid = source_item.localId();
736 const Int32 target_lid = target_item.localId();
737 Integer size = m_connectivity_nb_item[lid];
747 if (m_pre_allocated_size != 0) {
751 Integer new_pos_in_list = _increaseConnectivityList(NULL_ITEM_LOCAL_ID, m_pre_allocated_size);
752 m_connectivity_index[lid] = new_pos_in_list;
753 m_connectivity_list[new_pos_in_list] = target_lid;
756 if (size < m_pre_allocated_size || (size % m_pre_allocated_size) != 0) {
757 Integer index = m_connectivity_index[lid];
758 m_connectivity_list[index + size] = target_lid;
761 _increaseIndexList(lid, size, target_lid);
767 Integer new_pos_in_list = _increaseConnectivityList(target_lid);
768 m_connectivity_index[lid] = new_pos_in_list;
771 _increaseIndexList(lid, size, target_lid);
774 ++(m_connectivity_nb_item[lid]);
775 _setNewMaxNbConnectedItems(m_connectivity_nb_item[lid]);
781Integer IncrementalItemConnectivity::
782_computeAllocSize(
Integer nb_item)
784 if (m_pre_allocated_size != 0) {
786 Integer alloc_size = nb_item / m_pre_allocated_size;
788 return m_pre_allocated_size;
789 if ((nb_item % m_pre_allocated_size) == 0)
791 return m_pre_allocated_size * (alloc_size + 1);
799void IncrementalItemConnectivity::
800addConnectedItems(ItemLocalId source_item,
Integer nb_item)
803 const Int32 lid = source_item.localId();
804 Integer size = m_connectivity_nb_item[lid];
806 ARCANE_FATAL(
"source_item already have connected items");
807 Integer alloc_size = _computeAllocSize(nb_item);
808 Integer new_pos_in_list = _increaseConnectivityList(NULL_ITEM_LOCAL_ID, alloc_size);
809 m_connectivity_index[lid] = new_pos_in_list;
810 m_connectivity_nb_item[lid] += nb_item;
811 _setNewMaxNbConnectedItems(m_connectivity_nb_item[lid]);
822 addConnectedItems(source_item, target_local_ids.
size());
835 if (indexes.
size() != nb_source)
836 ARCANE_FATAL(
"Incoherent sizes nb_items={0} indexes={1}", nb_source, indexes.
size());
837 m_p->m_connectivity_nb_item_array.resize(nb_source);
838 m_p->m_connectivity_index_array.resize(nb_source);
839 m_p->m_connectivity_list_array.resize(list.
size());
840 _notifyConnectivityNbItemChanged();
841 _notifyConnectivityIndexChanged();
842 _notifyConnectivityListChanged();
843 m_connectivity_nb_item.copy(nb_items);
844 m_connectivity_index.copy(indexes);
845 m_connectivity_list.copy(list);
846 m_p->m_max_nb_item = 0;
847 _computeMaxNbConnectedItem();
858 m_p->m_connectivity_nb_item_array.resize(nb_source);
859 m_p->m_connectivity_index_array.resize(nb_source);
860 m_p->m_connectivity_list_array.resize(list_size);
861 _notifyConnectivityNbItemChanged();
862 _notifyConnectivityIndexChanged();
863 _notifyConnectivityListChanged();
864 nb_items = m_connectivity_nb_item;
865 indexes = m_connectivity_index;
866 list = m_connectivity_list;
875 m_p->m_max_nb_item = 0;
876 _computeMaxNbConnectedItem();
886 Int32 lid = source_item.localId();
887 m_connectivity_nb_item[lid] = 0;
898 Int32 lid = source_item.localId();
899 Int32 target_lid = target_item.localId();
900 Integer size = m_connectivity_nb_item[lid];
901 Int32* items = &(m_connectivity_list[m_connectivity_index[lid]]);
903 --(m_connectivity_nb_item[lid]);
913 Int32 lid = source_item.localId();
914 Int32 target_lid = target_item.localId();
915 ARCANE_CHECK_AT(index, m_connectivity_nb_item[lid]);
916 m_connectivity_list[m_connectivity_index[lid] + index] = target_lid;
926 Int32 lid = source_item.localId();
929 ARCANE_CHECK_AT(n - 1, m_connectivity_nb_item[lid]);
930 const Int32 pos = m_connectivity_index[lid];
931 for (
Integer i = 0; i < n; ++i)
932 m_connectivity_list[pos + i] = target_local_ids[i];
942 bool has_connection =
false;
943 auto connected_items = _connectedItemsLocalId(source_item);
944 if (std::find(connected_items.begin(), connected_items.end(), target_local_id) != connected_items.end())
945 has_connection =
true;
946 return has_connection;
955 Int32 lid = item.localId();
957 _lazyNotifySourceItemAdded(lid);
960 m_p->_checkResize(lid);
961 _notifyConnectivityIndexChanged();
962 _notifyConnectivityNbItemChanged();
964 m_connectivity_nb_item[lid] = 0;
965 m_connectivity_index[lid] = 0;
971void IncrementalItemConnectivity::
978 Int32 max_lid = local_ids[0];
979 for (
Int32 lid : local_ids)
984 _lazyNotifySourceItemAdded(max_lid);
987 m_p->_checkResize(max_lid);
988 _notifyConnectivityIndexChanged();
989 _notifyConnectivityNbItemChanged();
991 for (
Int32 lid : local_ids) {
992 m_connectivity_nb_item[lid] = 0;
993 m_connectivity_index[lid] = 0;
1007 Int32 max_local_id = _sourceFamily()->maxLocalId();
1008 if (max_local_id > 0)
1009 _lazyNotifySourceItemAdded(max_local_id - 1);
1011 m_pre_allocated_size = _sourceFamily()->properties()->getIntegerWithDefault(
name() +
"PreallocSize", 0);
1012 info(4) <<
"PreallocSize2 var=" << m_p->m_var_name <<
" v=" << m_pre_allocated_size;
1025 if (m_pre_allocated_size < 0)
1027 String::format(
"Invalid prealloc_size v={0}",
1035 Integer nb_source =
m_is_lazy ? m_p->m_lazy_nb_source : m_connectivity_nb_item.size();
1039 m_pre_allocated_size = prealloc_size;
1040 _sourceFamily()->properties()->setInteger(
name() +
"PreallocSize", prealloc_size);
1045 _resetConnectivityList();
1054 Int64 mem1 = m_p->m_connectivity_list_array.capacity();
1055 Int64 mem2 = m_p->m_connectivity_index_array.capacity();
1056 Int64 mem3 = m_p->m_connectivity_nb_item_array.capacity();
1057 Int64 allocated_size = mem1 + mem2 + mem3;
1058 allocated_size *=
sizeof(
Int32);
1060 out <<
" connectiviy name=" <<
name()
1061 <<
" prealloc_size=" << m_pre_allocated_size
1062 <<
" nb_add=" << m_nb_add
1063 <<
" nb_remove=" << m_nb_remove
1064 <<
" nb_memcopy=" << m_nb_memcopy
1065 <<
" list_size=" << m_connectivity_list.size()
1066 <<
" list_capacity=" << mem1
1067 <<
" index_size=" << m_connectivity_index.size()
1068 <<
" index_capacity=" << mem2
1069 <<
" nb_item_size=" << m_connectivity_nb_item.size()
1070 <<
" nb_item_capacity=" << mem3
1071 <<
" allocated_size=" << allocated_size;
1077void IncrementalItemConnectivityBase::
1080 m_p->m_connectivity_list_array.
shrink();
1081 m_p->m_connectivity_index_array.
shrink();
1082 m_p->m_connectivity_nb_item_array.
shrink();
1083 _notifyConnectivityIndexChanged();
1084 _notifyConnectivityNbItemChanged();
1085 _notifyConnectivityListChanged();
1091void IncrementalItemConnectivityBase::
1094 Int64 s1 = m_p->m_connectivity_list_array.
size();
1095 Int64 s2 = m_p->m_connectivity_index_array.
size();
1096 Int64 s3 = m_p->m_connectivity_nb_item_array.
size();
1108void IncrementalItemConnectivity::
1115 if (m_connectivity_list.
size() == 0) {
1116 if (m_pre_allocated_size > 0) {
1117 _increaseConnectivityList(NULL_ITEM_LOCAL_ID, m_pre_allocated_size);
1120 _increaseConnectivityList(NULL_ITEM_LOCAL_ID);
1142 info(4) <<
"Begin Compacting IncrementalItemConnectivity name=" <<
name()
1143 <<
" new_size=" << m_connectivity_list.size()
1144 <<
" prealloc_size=" << m_pre_allocated_size;
1150 Integer nb_item = m_connectivity_nb_item.size();
1151 m_p->m_connectivity_list_array.clear();
1152 _notifyConnectivityListChanged();
1153 _checkAddNullItem();
1154 Integer new_pos_in_list = m_p->m_connectivity_list_array.size();
1155 Int32 pre_allocated_size = m_pre_allocated_size;
1156 for (
Integer i = 0; i < nb_item; ++i) {
1158 Int32 nb = m_connectivity_nb_item[lid];
1160 m_connectivity_index[lid] = 0;
1163 Int32 index = m_connectivity_index[lid];
1165 Integer alloc_size = _computeAllocSize(nb);
1166 m_connectivity_index[lid] = new_pos_in_list;
1167 new_pos_in_list += alloc_size;
1170 if (pre_allocated_size != 0) {
1171 Int32 pos_modulo = new_pos_in_list % pre_allocated_size;
1172 if (pos_modulo != 0)
1173 ARCANE_FATAL(
"Bad position i={0} pos={1} pre_alloc_size={2} modulo={3}",
1174 i, new_pos_in_list, pre_allocated_size, pos_modulo);
1176 m_p->m_connectivity_list_array.addRange(con_list);
1178 if (alloc_size != nb)
1179 m_p->m_connectivity_list_array.addRange(NULL_ITEM_LOCAL_ID, alloc_size - nb);
1180 if (m_pre_allocated_size == 0 && nb == 0)
1181 m_connectivity_index[lid] = 0;
1183 _notifyConnectivityListChanged();
1184 _computeMaxNbConnectedItem();
1185 info(4) <<
"Compacting IncrementalItemConnectivity name=" <<
name()
1186 <<
" nb_item=" << nb_item <<
" old_size=" << old_size
1187 <<
" new_size=" << m_connectivity_list.size()
1188 <<
" prealloc_size=" << m_pre_allocated_size;
1200OneItemIncrementalItemConnectivity::
1205 info(4) <<
"Using fixed OneItem connectivity for name=" <<
name();
1211OneItemIncrementalItemConnectivity::
1212~OneItemIncrementalItemConnectivity()
1222 Int32 lid = source_item.localId();
1223 Integer size = m_connectivity_nb_item[lid];
1225 ARCANE_FATAL(
"source_item already have connected items");
1226 Int32 target_lid = target_item.localId();
1227 m_connectivity_list[lid] = target_lid;
1228 m_connectivity_nb_item[lid] = 1;
1229 _setNewMaxNbConnectedItems(1);
1238 Int32 lid = source_item.localId();
1239 m_connectivity_nb_item[lid] = 0;
1248 Int32 lid = source_item.localId();
1249 Int32 target_local_id = target_item.localId();
1250 Integer size = m_connectivity_nb_item[lid];
1253 Int32 target_lid = m_connectivity_list[lid];
1254 if (target_lid != target_local_id)
1255 ARCANE_FATAL(
"source_item is not connected to item with wanted_lid={0} current_lid={1}",
1256 target_local_id, target_lid);
1257 m_connectivity_nb_item[lid] = 0;
1258 m_connectivity_list[lid] = NULL_ITEM_LOCAL_ID;
1269 Int32 lid = source_item.localId();
1270 Int32 target_lid = target_item.localId();
1271 m_connectivity_list[lid] = target_lid;
1280 Int32 lid = source_item.localId();
1285 ARCANE_FATAL(
"Invalid size for target_list. value={0} (expected 1)", n);
1286 m_connectivity_list[lid] = target_local_ids[0];
1296 if (m_connectivity_list[source_item.localId()] == target_local_id.localId())
1305void OneItemIncrementalItemConnectivity::
1306_checkResizeConnectivityList()
1310 Integer wanted_size = m_connectivity_nb_item.size();
1312 if (list_size == wanted_size)
1315 if (wanted_size >= capacity) {
1316 m_p->m_connectivity_list_array.
reserve(m_p->m_connectivity_nb_item_array.
capacity());
1318 m_p->m_connectivity_list_array.
resize(wanted_size);
1319 _notifyConnectivityListChanged();
1328 Int32 lid = item.localId();
1329 m_p->_checkResize(lid);
1330 _notifyConnectivityIndexChanged();
1331 _notifyConnectivityNbItemChanged();
1332 _checkResizeConnectivityList();
1334 m_connectivity_nb_item[lid] = 0;
1335 m_connectivity_index[lid] = lid;
1336 m_connectivity_list[lid] = NULL_ITEM_LOCAL_ID;
1347 m_p->m_lazy_nb_source = new_to_old_ids.
size();
1357 m_p->m_connectivity_nb_item_variable.variable()->compact(new_to_old_ids);
1358 _notifyConnectivityNbItemChanged();
1363 m_p->m_connectivity_list_variable.variable()->compact(new_to_old_ids);
1364 _notifyConnectivityListChanged();
1368 m_p->m_connectivity_index_array.resize(m_connectivity_nb_item.size());
1369 _notifyConnectivityIndexChanged();
1386 size_t allocated_size = m_p->m_connectivity_list_array.capacity() + m_p->m_connectivity_index_array.capacity() + m_p->m_connectivity_nb_item_array.capacity();
1387 allocated_size *=
sizeof(
Int32);
1389 out <<
" connectiviy name=" <<
name()
1390 <<
" list_size=" << m_connectivity_list.size()
1391 <<
" index_size=" << m_connectivity_index.size()
1392 <<
" nb_item_size=" << m_connectivity_nb_item.size()
1393 <<
" allocated_size=" << allocated_size;
1399void OneItemIncrementalItemConnectivity::
1400compactConnectivityList()
1402 _computeMaxNbConnectedItem();
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Utility functions for the mesh.
void removeItemAndKeepOrder(Int32ArrayView items, Int32 local_id)
Removes an entity while preserving order.
Integer capacity() const
Capacity (number of allocated elements) of the vector.
Integer size() const
Number of elements in the vector.
Exception when an argument is invalid.
constexpr Integer size() const noexcept
Returns the size of the array.
void shrink()
Reallocates to free unused memory.
void resize(Int64 s)
Changes the number of elements in the array to s.
const T * data() const
Access to the root of the array without any protection.
void reserve(Int64 new_capacity)
Reserves memory for new_capacity elements.
ArrayView< T > view() const
Mutable view of this array.
ItemVectorView resizeAndCopy(Int32ConstArrayView ids)
Positions the connectivity list with the entities specified by ids.
Constant view of an array of type T.
constexpr const_pointer data() const noexcept
Pointer to the allocated memory.
constexpr Integer size() const noexcept
Number of elements in the array.
Template class for converting a type.
Internal Arcane API for IIncrementalItemConnectivity.
virtual Integer preAllocatedSize() const =0
Number of entities pre-allocated for the connectivity of each entity.
Interface of an entity family.
virtual String name() const =0
Family name.
virtual eItemKind itemKind() const =0
Entity kind.
virtual IMesh * mesh() const =0
Associated mesh.
virtual Properties * properties()=0
Properties associated with this family.
@ PPrivate
Indicates that the variable is private.
Views of containers holding connectivity. This class allows the containers used to be opaque outside ...
Memory usage information for connectivities.
Int64 m_total_capacity
Total number of Int32 allocated (corresponds to the sum of capacity()).
Int64 m_total_size
Total number of Int32 used (corresponds to the sum of size()).
Connectivity information, for an entity family, allowing transition between old and new connectivity ...
void _setConnectivityNbItem(Int32 item_kind, ConstArrayView< Int32 > v)
Positions the array containing the number of connected entities.
void _setConnectivityList(Int32 item_kind, ArrayView< Int32 > v)
Positions the array containing the connectivity list.
void _setConnectivityIndex(Int32 item_kind, ConstArrayView< Int32 > v)
Positions the connectivity index array.
Index of an Item in a variable.
View on a vector of entities.
Integer getIntegerWithDefault(const String &name, Integer default_value) const
Value of the property named name.
Reference to an instance.
Unicode character string constructor.
Unicode character string.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
Parameters necessary for building a variable.
Array< DataType > ContainerType
Abstract class for managing connectivities.
String name() const final
Name of the connectivity.
void notifyEndUpdateFromMesh() override
Notifies that the mesh has just been updated.
void addMemoryInfos(ItemConnectivityMemoryInfo &mem_info) override
Adds the instance's memory information to mem_info.
void shrinkMemory() override
Minimally reduces memory usage for connectivities.
Base class for incremental item->item[] connectivities.
bool m_is_lazy
True while this connectivity has never had a connected item.
void _checkMaterialize()
Leaves the lazy state if this connectivity is still in it.
void notifySourceFamilyLocalIdChanged(Int32ConstArrayView new_to_old_ids) override
Notifies the connectivity that the source family has been compacted.
void _notifyConnectivityNbItemChangedFromObservable()
Int32 maxNbConnectedItem() const override
Maximum number of entities connected to a source entity.
void setItemConnectivityList(ItemInternalConnectivityList *ilist, Int32 index)
Indicates that this connectivity is associated with one of the connectivities of ItemInternal.
void reserveMemoryForNbSourceItems(Int32 n, bool pre_alloc_connectivity) override
Reserves memory for n source entities.
ItemVectorView _connectedItems(ItemLocalId item, ConnectivityItemVector &con_items) const final
Fills con_items with the entities connected to item.
void _publishLazyViews(Int32 nb_source)
Points both per-source views at the shared zero buffer, so a reader of nbConnectedItem() gets 0 for e...
IIncrementalItemConnectivityInternal * _internalApi() override
Internal Arcane API.
void _trimLazyViews()
Moves the lazy views to one zero buffer of the size of the mesh.
void _materialize()
Leaves the lazy state: allocates the two per-source arrays for real.
void notifyTargetFamilyLocalIdChanged(Int32ConstArrayView old_to_new_ids) override
Notifies the connectivity that the target family has been compacted.
Int32 m_lazy_nb_source
Lazy state: this connectivity has never had a connected item.
Int32 m_max_nb_item
Maximum number of connected items.
static LazyMemoryPool m_lazy_pool
Zero buffers read by the lazy views.
LazyMemoryPool::Buffer * m_lazy_buffer
Buffer of m_lazy_pool the lazy views point into.
void resizeBulkConnectivity(Int32 nb_source, Int64 list_size, Int32ArrayView &nb_items, Int32ArrayView &indexes, Int32ArrayView &list)
Sizes the storage for a bulk fill and hands out the arrays to write.
bool hasConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) const override
Tests the existence of a connectivity between source_item and the entity with localId() target_local_...
void setConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override
Allocates and positions entities connected to source_item.
void compactConnectivityList()
Compresses the connectivity list.
void removeConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override
Removes the entity with localId() target_local_id from the connectivity of source_item.
void endBulkConnectivity()
Closes a fill started by resizeBulkConnectivity().
void notifySourceItemAdded(ItemLocalId item) override
Notifies the connectivity that an entity has been added to the source family.
void addConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override
Adds the entity with localId() target_local_id to the connectivity of source_item.
void removeConnectedItems(ItemLocalId source_item) override
Removes all entities connected to source_item.
void notifyReadFromDump() override
Notifies the connectivity that a read has been performed from a dump.
void setBulkConnectivity(Int32ConstArrayView nb_items, Int32ConstArrayView indexes, Int32ConstArrayView list)
Replaces the whole connectivity with one the caller already knows.
void dumpStats(std::ostream &out) const override
Dumps statistics on usage and memory used to the stream out.
void replaceConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override
Replaces the entities of source_item with the entities with localId() target_local_ids.
void replaceConnectedItem(ItemLocalId source_item, Integer index, ItemLocalId target_local_id) override
Replaces the entity at index index of source_item with the entity with localId() target_local_id.
void setPreAllocatedSize(Integer value) final
Sets the number of entities to pre-allocate for the connectivity of each entity.
Zeros backing every lazy connectivity view of the process.
void release(Buffer *&buffer)
Stops reading buffer, and frees it if nothing else reads it.
void removeConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override
Removes the entity with localId() target_local_id from the connectivity of source_item.
void replaceConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override
Replaces the entities of source_item with the entities with localId() target_local_ids.
void addConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override
Adds the entity with localId() target_local_id to the connectivity of source_item.
void notifyReadFromDump() override
Notifies the connectivity that a read has been performed from a dump.
bool hasConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) const override
Tests the existence of a connectivity between source_item and the entity with localId() target_local_...
void notifySourceFamilyLocalIdChanged(Int32ConstArrayView new_to_old_ids) override
Notifies the connectivity that the source family has been compacted.
void replaceConnectedItem(ItemLocalId source_item, Integer index, ItemLocalId target_local_id) override
Replaces the entity at index index of source_item with the entity with localId() target_local_id.
void notifySourceItemAdded(ItemLocalId item) override
Notifies the connectivity that an entity has been added to the source family.
void removeConnectedItems(ItemLocalId source_item) override
Removes all entities connected to source_item.
void dumpStats(std::ostream &out) const override
Dumps statistics on usage and memory used to the stream out.
T max(const T &a, const T &b, const T &c)
Returns the maximum of three elements.
VariableRefArrayT< Int32 > VariableArrayInt32
Array variable of 32-bit integer type.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
std::int32_t Int32
Signed integer type of 32 bits.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
One zero buffer and the number of connectivities reading it.