Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemConnectivity.cc
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/* ItemConnectivity.cc (C) 2000-2024 */
9/* */
10/* External connectivities. First version with DoF */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/mesh/ItemConnectivity.h"
15#include "arcane/mesh/ExtraGhostItemsManager.h"
16
17#include <set>
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28void ItemConnectivity::
29compute()
30{
31 ItemVectorView from_items = _sourceFamily()->allItems().own().view();
32 ItemVectorView to_items = _targetFamily()->allItems().own().view();
33 ARCANE_ASSERT((from_items.size() == to_items.size()),
34 ("Connected families must have the same number of items "))
35 m_item_property.resize(_sourceFamily(), NULL_ITEM_LOCAL_ID);
36 // Link from and to items
37 Integer i = 0;
38 ENUMERATE_ITEM (iitem, from_items) {
39 m_item_property[iitem] = to_items[i++].localId();
40 }
41}
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
46void ItemArrayConnectivity::
47compute()
48{
49 ItemVectorView from_items = _sourceFamily()->allItems().own().view();
50 ItemVectorView to_items = _targetFamily()->allItems().own().view();
51 ARCANE_ASSERT((from_items.size() * m_nb_dof_per_item == to_items.size()),
52 ("Incorrect connected family size. Should be FromFamily.own.size * nb_element_per_item"))
53 m_item_property.resize(_sourceFamily(), m_nb_dof_per_item, NULL_ITEM_LOCAL_ID);
54 Integer i = 0;
55 ENUMERATE_ITEM (iitem, from_items) {
56 for (Integer j = 0; j < m_nb_dof_per_item; ++j)
57 m_item_property[iitem][j] = to_items[i++].localId();
58 }
59}
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64void ItemMultiArrayConnectivity::
65compute(IntegerConstArrayView nb_dof_per_item)
66{
67 ItemVectorView from_items = _sourceFamily()->allItems().own().view();
68 DoFVectorView to_items = _targetFamily()->allItems().own().view();
69 Integer total_nb_dof_per_item = 0;
70 for (Integer i = 0; i < nb_dof_per_item.size(); ++i)
71 total_nb_dof_per_item += nb_dof_per_item[i];
72
73 ARCANE_ASSERT((total_nb_dof_per_item == to_items.size()),
74 ("Incorrect connected family size. Should be equal to the sum of array nb_element_per_item elements"))
75
76 m_item_property.resize(_sourceFamily(), nb_dof_per_item, NULL_ITEM_LOCAL_ID);
77
78 Integer i = 0;
79 ENUMERATE_ITEM (iitem, from_items) {
80 for (Integer j = 0; j < nb_dof_per_item[iitem->localId()]; ++j)
81 m_item_property[iitem][j] = to_items[i++].localId();
82 }
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
90{
91 ARCANE_ASSERT((from_items.size() == to_items.size()), ("from_items and to_items arrays must have the same size to update connectivity"))
92 // Adapt to possible evolution of from family size
93 m_item_property.resize(_sourceFamily(), NULL_ITEM_LOCAL_ID);
94 ItemVectorView from_items_view = _sourceFamily()->view(from_items);
95 for (Integer i = 0; i < from_items_view.size(); ++i)
96 m_item_property[from_items_view[i]] = to_items[i];
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
104{
105 ARCANE_ASSERT((from_items.size() == to_items.size()), ("from_items and to_items arrays must have the same size to update connectivity"))
106 // Adapt to possible evolution of from family size
107 m_item_property.resize(_sourceFamily(), m_nb_dof_per_item, NULL_ITEM_LOCAL_ID);
108 IntegerSharedArray to_items_index(_sourceFamily()->maxLocalId(), 0); // index in the connection: from 0 to nb_dof_per_item -1. Fill with 0
109 std::set<Int32> from_items_set;
110 ItemVectorView from_items_view = _sourceFamily()->view(from_items);
111 for (Integer i = 0; i < from_items.size(); ++i) {
112 if (!from_items_set.insert(from_items[i]).second)
113 ++to_items_index[from_items[i]]; // update the index in the connection
114 m_item_property[from_items_view[i]][to_items_index[from_items[i]]] = to_items[i];
115 }
116}
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
123{
124 ARCANE_ASSERT((from_items.size() == to_items.size()),
125 ("from_items and to_items arrays must have the same size to update connectivity"))
126 // Resize item property
127 IntegerSharedArray nb_connected_element_per_item(m_item_property.dim2Sizes()); // Array indexed by lids
128
129 // Adapt to possible evolution of from family size
130 nb_connected_element_per_item.resize(_sourceFamily()->maxLocalId(), 0);
131
132 // Remove history
133 for (Integer i = 0; i < from_items.size(); ++i)
134 nb_connected_element_per_item[from_items[i]] = 0;
135 for (Integer i = 0; i < from_items.size(); ++i)
136 ++nb_connected_element_per_item[from_items[i]];
137 m_item_property.resize(_sourceFamily(), nb_connected_element_per_item, NULL_ITEM_LOCAL_ID);
138
139 // Update item property
140 IntegerSharedArray to_items_index(_sourceFamily()->maxLocalId(), 0); // index in the connection: from 0 to nb_dof_per_item -1. Fill with 0
141 std::set<Int32> from_items_set;
142 ItemVectorView from_items_view = _sourceFamily()->view(from_items);
143 for (Integer i = 0; i < from_items.size(); ++i) {
144 if (!from_items_set.insert(from_items[i]).second)
145 ++to_items_index[from_items[i]]; // update the index in the connection
146 m_item_property[from_items_view[i]][to_items_index[from_items[i]]] = to_items[i];
147 }
148}
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
155{
156 m_item_property.resize(_sourceFamily(), NULL_ITEM_LOCAL_ID);
157 ENUMERATE_ITEM (item, _sourceFamily()->allItems()) {
158 if (m_item_property[item] != NULL_ITEM_LOCAL_ID)
159 m_item_property[item] = old_to_new_ids[m_item_property[item]];
160 }
161}
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
168{
169 ENUMERATE_ITEM (item, _sourceFamily()->allItems()) {
170 for (Integer i = 0; i < m_nb_dof_per_item; ++i) {
171 if (m_item_property[item][i] != NULL_ITEM_LOCAL_ID)
172 m_item_property[item][i] = old_to_new_ids[m_item_property[item][i]];
173 }
174 }
175}
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
182{
183 ENUMERATE_ITEM (item, _sourceFamily()->allItems()) {
184 for (Integer i = 0; i < m_item_property.dim2Sizes()[item.localId()]; ++i) {
185 if (m_item_property[item][i] != NULL_ITEM_LOCAL_ID)
186 m_item_property[item][i] = old_to_new_ids[m_item_property[item][i]];
187 }
188 }
189}
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
193
194} // namespace Arcane
195
196/*---------------------------------------------------------------------------*/
197/*---------------------------------------------------------------------------*/
#define ENUMERATE_ITEM(name, group)
Generic enumerator for a node group.
void resize(Int64 s)
Changes the number of elements in the array to s.
constexpr Integer size() const noexcept
Number of elements in the array.
virtual void updateConnectivity(Int32ConstArrayView from_items, Int32ConstArrayView to_items)
Update of the connectivity.
virtual void notifyTargetFamilyLocalIdChanged(Int32ConstArrayView old_to_new_ids)
Notifies the connectivity that the target family has been compacted.
virtual void notifyTargetFamilyLocalIdChanged(Int32ConstArrayView old_to_new_ids)
Notifies the connectivity that the target family has been compacted.
virtual void updateConnectivity(Int32ConstArrayView from_items, Int32ConstArrayView to_items)
Update of the connectivity.
virtual void notifyTargetFamilyLocalIdChanged(Int32ConstArrayView old_to_new_ids)
Notifies the connectivity that the target family has been compacted.
virtual void updateConnectivity(Int32ConstArrayView from_items, Int32ConstArrayView to_items)
Update of the connectivity.
View on a vector of entities.
Int32 size() const
Number of elements in the vector.
ItemVectorViewT< DoF > DoFVectorView
View over a vector of degrees of freedom.
Definition ItemTypes.h:316
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
SharedArray< Integer > IntegerSharedArray
Dynamic 1D array of integers.
Definition UtilsTypes.h:387
ConstArrayView< Integer > IntegerConstArrayView
C equivalent of a 1D array of integers.
Definition UtilsTypes.h:486