@@ -70,7 +70,8 @@ apply(MaterialModifierOperation* operation)
7070{
7171 bool is_add = operation->isAdd ();
7272 IMeshMaterial* mat = operation->material ();
73- Int32ConstArrayView ids = operation->ids ();
73+ ConstArrayView<Int32> orig_ids = operation->ids ();
74+ ConstArrayView<Int32> ids = orig_ids;
7475
7576 auto * true_mat = ARCANE_CHECK_POINTER (dynamic_cast <MeshMaterial*>(mat));
7677
@@ -82,8 +83,6 @@ apply(MaterialModifierOperation* operation)
8283
8384 ConstituentConnectivityList* connectivity = m_all_env_data->componentConnectivityList ();
8485
85- Int32UniqueArray cells_changed_in_env;
86-
8786 if (nb_mat != 1 ) {
8887
8988 // S'il est possible d'avoir plusieurs matériaux par milieu, il faut gérer
@@ -94,12 +93,18 @@ apply(MaterialModifierOperation* operation)
9493 // - en cas de suppression, le milieu évolue dans la maille s'il y avait
9594 // 1 seul matériau avant. Dans ce cas le milieu est supprimé de la maille.
9695
97- Int32UniqueArray cells_unchanged_in_env;
96+ UniqueArray<Int32>& cells_changed_in_env = m_work_info.cells_changed_in_env ;
97+ UniqueArray<Int32>& cells_unchanged_in_env = m_work_info.cells_unchanged_in_env ;
98+ const Int32 nb_id = ids.size ();
99+ cells_unchanged_in_env.clear ();
100+ cells_unchanged_in_env.reserve (nb_id);
101+ cells_changed_in_env.clear ();
102+ cells_changed_in_env.reserve (nb_id);
98103 const Int32 ref_nb_mat = is_add ? 0 : 1 ;
99104 const Int16 env_id = true_env->componentId ();
100105 info (4 ) << " Using optimisation updateMaterialDirect is_add?=" << is_add;
101106
102- for (Integer i = 0 , n = ids. size () ; i < n ; ++i) {
107+ for (Integer i = 0 ; i < nb_id ; ++i) {
103108 Int32 lid = ids[i];
104109 Int32 current_cell_nb_mat = connectivity->cellNbMaterial (CellLocalId (lid), env_id);
105110 if (current_cell_nb_mat != ref_nb_mat) {
@@ -153,9 +158,9 @@ apply(MaterialModifierOperation* operation)
153158 // d'ajout) ou les mailles partielles en mailles pures (en cas de
154159 // suppression).
155160 info (4 ) << " Transform PartialPure for material name=" << true_mat->name ();
156- _switchComponentItemsForMaterials (true_mat);
161+ _switchCellsForMaterials (true_mat, orig_ids );
157162 info (4 ) << " Transform PartialPure for environment name=" << env->name ();
158- _switchComponentItemsForEnvironments (env);
163+ _switchCellsForEnvironments (env, orig_ids );
159164
160165 // Si je suis mono-mat, alors mat->cells()<=>env->cells() et il ne faut
161166 // mettre à jour que l'un des deux groupes.
@@ -190,7 +195,8 @@ apply(MaterialModifierOperation* operation)
190195 * (suppression d'un matériau)
191196 */
192197void IncrementalComponentModifier::
193- _switchComponentItemsForMaterials (const MeshMaterial* modified_mat)
198+ _switchCellsForMaterials (const MeshMaterial* modified_mat,
199+ ConstArrayView<Int32> ids)
194200{
195201 const bool is_add = m_work_info.isAdd ();
196202
@@ -203,16 +209,13 @@ _switchComponentItemsForMaterials(const MeshMaterial* modified_mat)
203209 m_work_info.pure_local_ids .clear ();
204210 m_work_info.partial_indexes .clear ();
205211
206- const MeshEnvironment* env = mat->trueEnvironment ();
207- if (env != true_env)
208- ARCANE_FATAL (" BAD ENV" );
209212 MeshMaterialVariableIndexer* indexer = mat->variableIndexer ();
210213
211214 info (4 ) << " TransformCells (V3) is_add?=" << is_add << " indexer=" << indexer->name ();
212215
213- _computeCellsToTransform (mat);
214-
216+ _computeCellsToTransformForMaterial (mat, ids);
215217 indexer->transformCellsV2 (m_work_info);
218+ m_work_info.resetTransformedCells (ids);
216219
217220 info (4 ) << " NB_MAT_TRANSFORM=" << m_work_info.pure_local_ids .size () << " name=" << mat->name ();
218221
@@ -238,7 +241,8 @@ _switchComponentItemsForMaterials(const MeshMaterial* modified_mat)
238241 * en pure (dans le cas de suppression d'un matériau)
239242 */
240243void IncrementalComponentModifier::
241- _switchComponentItemsForEnvironments (const IMeshEnvironment* modified_env)
244+ _switchCellsForEnvironments (const IMeshEnvironment* modified_env,
245+ ConstArrayView<Int32> ids)
242246{
243247 const bool is_add = m_work_info.isAdd ();
244248
@@ -260,8 +264,9 @@ _switchComponentItemsForEnvironments(const IMeshEnvironment* modified_env)
260264
261265 info (4 ) << " TransformCells (V2) is_add?=" << is_add << " indexer=" << indexer->name ();
262266
263- _computeCellsToTransform ( );
267+ _computeCellsToTransformForEnvironments (ids );
264268 indexer->transformCellsV2 (m_work_info);
269+ m_work_info.resetTransformedCells (ids);
265270
266271 info (4 ) << " NB_ENV_TRANSFORM=" << m_work_info.pure_local_ids .size ()
267272 << " name=" << env->name ();
@@ -279,7 +284,7 @@ _switchComponentItemsForEnvironments(const IMeshEnvironment* modified_env)
279284 * \brief Calcule les mailles à transformer pour le matériau \at mat.
280285 */
281286void IncrementalComponentModifier::
282- _computeCellsToTransform (const MeshMaterial* mat)
287+ _computeCellsToTransformForMaterial (const MeshMaterial* mat, ConstArrayView<Int32> ids )
283288{
284289 const MeshEnvironment* env = mat->trueEnvironment ();
285290 const Int16 env_id = env->componentId ();
@@ -289,23 +294,25 @@ _computeCellsToTransform(const MeshMaterial* mat)
289294 ConstituentConnectivityList* connectivity = m_all_env_data->componentConnectivityList ();
290295 ConstArrayView<Int16> cells_nb_env = connectivity->cellsNbEnvironment ();
291296
292- ENUMERATE_ (Cell, icell, all_cells ) {
297+ for (Int32 local_id : ids ) {
293298 bool do_transform = false ;
299+ CellLocalId cell_id (local_id);
294300 // En cas d'ajout on passe de pure à partiel s'il y a plusieurs milieux ou
295301 // plusieurs matériaux dans le milieu.
296302 // En cas de supression, on passe de partiel à pure si on est le seul matériau
297303 // et le seul milieu.
304+ const Int16 nb_env = cells_nb_env[local_id];
298305 if (is_add) {
299- do_transform = cells_nb_env[icell. itemLocalId ()] > 1 ;
306+ do_transform = (nb_env > 1 ) ;
300307 if (!do_transform)
301- do_transform = connectivity->cellNbMaterial (icell , env_id) > 1 ;
308+ do_transform = connectivity->cellNbMaterial (cell_id , env_id) > 1 ;
302309 }
303310 else {
304- do_transform = cells_nb_env[icell. itemLocalId ()] == 1 ;
311+ do_transform = (nb_env == 1 ) ;
305312 if (do_transform)
306- do_transform = connectivity->cellNbMaterial (icell , env_id) == 1 ;
313+ do_transform = connectivity->cellNbMaterial (cell_id , env_id) == 1 ;
307314 }
308- m_work_info.setTransformedCell (icell , do_transform);
315+ m_work_info.setTransformedCell (cell_id , do_transform);
309316 }
310317}
311318
@@ -316,22 +323,22 @@ _computeCellsToTransform(const MeshMaterial* mat)
316323 * d'un milieu.
317324 */
318325void IncrementalComponentModifier::
319- _computeCellsToTransform ( )
326+ _computeCellsToTransformForEnvironments (ConstArrayView<Int32> ids )
320327{
321328 ConstituentConnectivityList* connectivity = m_all_env_data->componentConnectivityList ();
322329 ConstArrayView<Int16> cells_nb_env = connectivity->cellsNbEnvironment ();
323330 CellGroup all_cells = m_material_mng->mesh ()->allCells ();
324331 const bool is_add = m_work_info.isAdd ();
325332
326- ENUMERATE_ (Cell, icell, all_cells ) {
333+ for (Int32 lid : ids ) {
327334 bool do_transform = false ;
328335 // En cas d'ajout on passe de pure à partiel s'il y a plusieurs milieux.
329336 // En cas de supression, on passe de partiel à pure si on est le seul milieu.
330337 if (is_add)
331- do_transform = cells_nb_env[icell. itemLocalId () ] > 1 ;
338+ do_transform = cells_nb_env[lid ] > 1 ;
332339 else
333- do_transform = cells_nb_env[icell. itemLocalId () ] == 1 ;
334- m_work_info.setTransformedCell (icell , do_transform);
340+ do_transform = cells_nb_env[lid ] == 1 ;
341+ m_work_info.setTransformedCell (CellLocalId (lid) , do_transform);
335342 }
336343}
337344
0 commit comments