Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ItemConnectivityMng.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* ItemConnectivityMng.cc (C) 2000-2023 */
9/* */
10/* Gestionnaire des connectivités des entités. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include <algorithm>
15
16#include "arcane/mesh/ItemConnectivityMng.h"
17#include "arcane/mesh/ItemConnectivitySynchronizer.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22ARCANE_BEGIN_NAMESPACE
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27IItemConnectivitySynchronizer* ItemConnectivityMng::
29{
30 std::map<IItemConnectivity*, IItemConnectivitySynchronizer*>::iterator ite = m_synchronizers.find(connectivity);
31 IItemConnectivitySynchronizer* synchronizer = NULL;
32 if (ite == m_synchronizers.end()){
33 synchronizer = new ItemConnectivitySynchronizer(connectivity,connectivity_ghost_policy);
34 m_synchronizers[connectivity] = synchronizer;
35 }
36 else{
37 // Create a new synchronizer for this connectivity
38 delete ite->second;
39 synchronizer = new ItemConnectivitySynchronizer(connectivity,connectivity_ghost_policy);
40 m_synchronizers.erase(ite);
41 m_synchronizers[connectivity] = synchronizer;
42 }
43 return synchronizer;
44}
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49void ItemConnectivityMng::
50_register(const String& connectivity_name, const String& source_family_name, const String& target_family_name)
51{
52 std::pair<FamilyStateMap::iterator,bool> source_family_state_insertor = m_family_states.insert(std::make_pair(source_family_name,FamilyState()));
53 std::pair<FamilyStateMap::iterator,bool> target_family_state_insertor = m_family_states.insert(std::make_pair(target_family_name,FamilyState()));
54 std::pair<ConnectivityStateMap::iterator,bool> connectivity_state_insertor = m_connectivity_states.insert(std::make_pair(connectivity_name,ConnectivityState()));
58 // If insertion occurs for connectivity, set its state to the family current state
60 connectivity_state.m_state_with_source_family.m_last_family_state = source_family_state.m_state;
61 connectivity_state.m_state_with_source_family.m_last_added_item_index = source_family_state.m_added_items.size()-1;
62 connectivity_state.m_state_with_source_family.m_last_removed_item_index = source_family_state.m_removed_items.size()-1;
63 connectivity_state.m_state_with_target_family.m_last_family_state = target_family_state.m_state;
64 connectivity_state.m_state_with_target_family.m_last_added_item_index = target_family_state.m_added_items.size()-1;
65 connectivity_state.m_state_with_target_family.m_last_removed_item_index = target_family_state.m_removed_items.size()-1;
66 }
67 else
68 m_trace_mng->warning() << "Connectivity " << connectivity_name << " already registered.";
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74void ItemConnectivityMng::
76{
77 FamilyState& family_state = _findFamily(family->fullName());
78
79 // Add added items
80 family_state.m_added_items.addRange(added_items);
81 // Add removed items
82 family_state.m_removed_items.addRange(removed_items);
83 // Increment family state
84 ++family_state.m_state;
85}
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90void ItemConnectivityMng::
91getSourceFamilyModifiedItems(IItemConnectivity* connectivity, Int32ArrayView& added_items, Int32ArrayView& removed_items)
92{
93 ConnectivityState& connectivity_state = _findConnectivity(connectivity->name());
94 FamilyState& family_state = _findFamily(connectivity->sourceFamily()->fullName());
95 _getModifiedItems(connectivity_state.m_state_with_source_family,family_state,added_items,removed_items);
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101void ItemConnectivityMng::
102getTargetFamilyModifiedItems(IItemConnectivity* connectivity, Int32ArrayView& added_items, Int32ArrayView& removed_items)
103{
104 ConnectivityState& connectivity_state = _findConnectivity(connectivity->name());
105 FamilyState& family_state = _findFamily(connectivity->targetFamily()->fullName());
106 _getModifiedItems(connectivity_state.m_state_with_target_family,family_state,added_items,removed_items);
107}
108
109void ItemConnectivityMng::
110getSourceFamilyModifiedItems(IIncrementalItemConnectivity* connectivity, Int32ArrayView& added_items, Int32ArrayView& removed_items)
111{
112 ConnectivityState& connectivity_state = _findConnectivity(connectivity->name());
113 FamilyState& family_state = _findFamily(connectivity->sourceFamily()->fullName());
114 _getModifiedItems(connectivity_state.m_state_with_source_family,family_state,added_items,removed_items);
115}
116
117/*---------------------------------------------------------------------------*/
118/*---------------------------------------------------------------------------*/
119
120void ItemConnectivityMng::
121getTargetFamilyModifiedItems(IIncrementalItemConnectivity* connectivity, Int32ArrayView& added_items, Int32ArrayView& removed_items)
122{
123 ConnectivityState& connectivity_state = _findConnectivity(connectivity->name());
124 FamilyState& family_state = _findFamily(connectivity->targetFamily()->fullName());
125 _getModifiedItems(connectivity_state.m_state_with_target_family,family_state,added_items,removed_items);
126}
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
130void ItemConnectivityMng::
131_getModifiedItems(ConnectivityStateData& connectivity_state, FamilyState& family_state,
132 Int32ArrayView& added_items, Int32ArrayView& removed_items)
133{
134 if (connectivity_state.m_last_family_state == family_state.m_state)
135 return; // Connectivity is up to date
136
137 Integer first_added_item_index = connectivity_state.m_last_added_item_index +1;
138 Integer nb_added_items = family_state.m_added_items.size()-first_added_item_index;
139 auto unfiltered_added_items = family_state.m_added_items.subView(first_added_item_index,nb_added_items);
140 // Filter null lid (may occur if both add and remove actions occur before calling this method)
141 family_state.m_current_added_items.clear();
142 family_state.m_current_added_items.resize(nb_added_items);
143 auto true_size = 0;
144 std::copy_if(unfiltered_added_items.begin(),unfiltered_added_items.end(),
145 family_state.m_current_added_items.begin(),
146 [&true_size](Int32 const& item_lid){
147 auto do_copy = (item_lid != NULL_ITEM_LOCAL_ID);
148 if (do_copy) ++true_size;
149 return do_copy;
150 });
151 family_state.m_current_added_items.resize(true_size);
152 added_items = family_state.m_current_added_items.view();
153
154 Integer first_removed_item_index = connectivity_state.m_last_removed_item_index +1;
155 Integer nb_removed_items = family_state.m_removed_items.size()-first_removed_item_index;
156 removed_items = family_state.m_removed_items.subView(first_removed_item_index,nb_removed_items);
157}
158
159/*---------------------------------------------------------------------------*/
160/*---------------------------------------------------------------------------*/
161
162void ItemConnectivityMng::
163setUpToDate(IItemConnectivity* connectivity)
164{
165 ConnectivityState& connectivity_state = _findConnectivity(connectivity->name());
166 FamilyState& source_family_state = _findFamily(connectivity->sourceFamily()->fullName());
167 FamilyState& target_family_state = _findFamily(connectivity->targetFamily()->fullName());
168 _setUpToDate(connectivity_state.m_state_with_source_family,source_family_state);
169 _setUpToDate(connectivity_state.m_state_with_target_family,target_family_state);
170}
171
172void ItemConnectivityMng::
173setUpToDate(IIncrementalItemConnectivity* connectivity)
174{
175 ConnectivityState& connectivity_state = _findConnectivity(connectivity->name());
176 FamilyState& source_family_state = _findFamily(connectivity->sourceFamily()->fullName());
177 FamilyState& target_family_state = _findFamily(connectivity->targetFamily()->fullName());
178 _setUpToDate(connectivity_state.m_state_with_source_family,source_family_state);
179 _setUpToDate(connectivity_state.m_state_with_target_family,target_family_state);
180}
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
184
185void ItemConnectivityMng::
187{
188 connectivity_state.m_last_family_state = family_state.m_state;
189 connectivity_state.m_last_added_item_index = family_state.m_added_items.size()-1;
190 connectivity_state.m_last_removed_item_index = family_state.m_removed_items.size()-1;
191}
192/*---------------------------------------------------------------------------*/
193/*---------------------------------------------------------------------------*/
194
195Integer ItemConnectivityMng::
196_lastUpdateSourceFamilyState(const String& connectivity_name)
197{
198 return _findConnectivity(connectivity_name).m_state_with_source_family.m_last_family_state;
199}
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
203
204Integer ItemConnectivityMng::
205_lastUpdateTargetFamilyState(const String& connectivity_name)
206{
207 return _findConnectivity(connectivity_name).m_state_with_target_family.m_last_family_state;
208}
209
210/*---------------------------------------------------------------------------*/
211/*---------------------------------------------------------------------------*/
212
213Integer ItemConnectivityMng::
214_familyState(const String& family_full_name)
215{
216 return _findFamily(family_full_name).m_state;
217}
218
219/*---------------------------------------------------------------------------*/
220/*---------------------------------------------------------------------------*/
221
222ConnectivityState& ItemConnectivityMng::
223_findConnectivity(const String& connectivity_name)
224{
225 ConnectivityStateMap::iterator connectivity_state_iterator = m_connectivity_states.find(connectivity_name);
226 if (connectivity_state_iterator == m_connectivity_states.end())
227 throw FatalErrorException(String::format(
228 "Cannot find connectivity {0}. Use registerConnectivity(connectivity) first",connectivity_name));
229 return connectivity_state_iterator->second;
230}
231
232/*---------------------------------------------------------------------------*/
233/*---------------------------------------------------------------------------*/
234
235FamilyState& ItemConnectivityMng::
236_findFamily(const String& family_full_name)
237{
238 FamilyStateMap::iterator family_state_iterator = m_family_states.find(family_full_name);
239 if (family_state_iterator == m_family_states.end())
240 throw FatalErrorException(String::format(
241 "Cannot find family {0}. Use registerConnectivity(connectivity) first",family_full_name));
242 return family_state_iterator->second;
243}
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
247
248void ItemConnectivityMng::
249notifyLocalIdChanged(IItemFamily* family, Int32ConstArrayView old_to_new_ids, Integer nb_item)
250{
251 // Rk this is a temporary patch, connectivity update has to be refactored !
252 FamilyState& family_state = _findFamily(family->fullName());
253 // Treat added items
254 Integer new_id;
255 for (Arcane::Integer i = 0; i < family_state.m_added_items.size(); ++i)
256 {
257 if (family_state.m_added_items[i] != NULL_ITEM_LOCAL_ID)
258 {
259 new_id = old_to_new_ids[family_state.m_added_items[i]];
260 if (new_id < nb_item) family_state.m_added_items[i] = new_id;// OK valid item
261 else family_state.m_added_items[i] = NULL_ITEM_LOCAL_ID;// KO invalid item. old_to_new has no null_item_lid. it has lid > nb_item. These lids will be removed in finish compact items...
262 }
263 }
264 // Clear removed items, connectivity update is automatically launched by compaction
265 family_state.m_removed_items.clear();
266}
267
268/*---------------------------------------------------------------------------*/
269/*---------------------------------------------------------------------------*/
270
271ARCANE_END_NAMESPACE
272
273/*---------------------------------------------------------------------------*/
274/*---------------------------------------------------------------------------*/
Interface pour gérer une connectivité incrémentale.
virtual String name() const =0
Nom de la connectivité
virtual IItemFamily * targetFamily() const =0
Famille cible.
virtual IItemFamily * sourceFamily() const =0
Famille source.
Interface pour gérer une connectivité.
virtual IItemFamily * targetFamily() const =0
Famille cible.
virtual IItemFamily * sourceFamily() const =0
Famille source.
virtual const String & name() const =0
Nom de la connectivité
Interface d'une famille d'entités.
virtual String fullName() const =0
Nom complet de la famille (avec celui du maillage)
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Vue modifiable d'un tableau d'un type T.
Vue constante d'un tableau de type T.
Chaîne de caractères unicode.
Int32 Integer
Type représentant un entier.