Skip to content

Commit 31461a2

Browse files
Merge pull request #1188 from arcaneframework/dev/gg-fix-missing-nbmat-computation-after-mesh-change
Fix missing re-computation of number of materials after mesh change
2 parents 0660716 + 504b0ff commit 31461a2

File tree

2 files changed

+73
-46
lines changed

2 files changed

+73
-46
lines changed

arcane/src/arcane/materials/AllEnvData.cc

+72-46
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ _computeAndResizeEnvItemsInternal()
114114
for (const MeshEnvironment* env : true_environments) {
115115
CellGroup cells = env->cells();
116116
Integer env_nb_cell = cells.size();
117-
info(4) << "NB_CELL=" << env_nb_cell << " env_name=" << cells.name();
117+
info(4) << "EnvName=" << cells.name() << " nb_env_cell=" << env_nb_cell << " nb_mat_cell=" << env->totalNbCellMat();
118118
total_env_cell += env_nb_cell;
119119
total_mat_cell += env->totalNbCellMat();
120120
}
@@ -129,6 +129,25 @@ _computeAndResizeEnvItemsInternal()
129129
// ATTENTION : ils ne doivent plus être redimensionnés par la suite sous peine
130130
// de tout invalider.
131131
m_item_internal_data.resizeComponentItemInternals(max_local_id, total_env_cell);
132+
133+
if (arcaneIsCheck()) {
134+
Int32 computed_nb_mat = 0;
135+
Int32 computed_nb_env = 0;
136+
ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
137+
ConstArrayView<Int16> cells_nb_mat = m_component_connectivity_list->cellsNbMaterial();
138+
ENUMERATE_ (Cell, icell, cell_family->allItems()) {
139+
Int32 lid = icell.itemLocalId();
140+
computed_nb_env += cells_nb_env[lid];
141+
computed_nb_mat += cells_nb_mat[lid];
142+
}
143+
Int32 computed_size = computed_nb_mat + computed_nb_env;
144+
Int32 storage_size = total_mat_cell + total_env_cell;
145+
info(4) << "storage_size=" << storage_size << " computed=" << computed_size
146+
<< " max_local_id=" << max_local_id << " internal_nb_mat=" << total_mat_cell << " internal_nb_env=" << total_env_cell
147+
<< " computed_nb_mat=" << computed_nb_mat << " computed_nb_env=" << computed_nb_env;
148+
if (storage_size != computed_size)
149+
ARCANE_FATAL("BAD STORAGE SIZE internal={0} connectivity={1}", storage_size, computed_size);
150+
}
132151
}
133152

134153
/*---------------------------------------------------------------------------*/
@@ -142,10 +161,10 @@ _rebuildIncrementalConnectivitiesFromGroups()
142161
ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
143162
auto clist = m_component_connectivity_list;
144163
clist->removeAllConnectivities();
145-
for( MeshEnvironment* env : true_environments ){
146-
clist->addCellsToEnvironment(env->componentId(),env->cells().view().localIds());
147-
for( MeshMaterial* mat : env->trueMaterials() )
148-
clist->addCellsToMaterial(mat->componentId(),mat->cells().view().localIds());
164+
for (MeshEnvironment* env : true_environments) {
165+
clist->addCellsToEnvironment(env->componentId(), env->cells().view().localIds());
166+
for (MeshMaterial* mat : env->trueMaterials())
167+
clist->addCellsToMaterial(mat->componentId(), mat->cells().view().localIds());
149168
}
150169
}
151170

@@ -158,17 +177,17 @@ _rebuildMaterialsAndEnvironmentsFromGroups()
158177
ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
159178
const bool is_full_verbose = _isFullVerbose();
160179
ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
161-
for( const MeshEnvironment* env : true_environments ){
180+
for (const MeshEnvironment* env : true_environments) {
162181
MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
163-
ComponentItemListBuilder list_builder(var_indexer,0);
182+
ComponentItemListBuilder list_builder(var_indexer, 0);
164183
CellGroup cells = var_indexer->cells();
165184
Integer var_nb_cell = cells.size();
166185
info(4) << "ENV_INDEXER (V2) i=" << var_indexer->index() << " NB_CELL=" << var_nb_cell << " name=" << cells.name()
167186
<< " index=" << var_indexer->index();
168187
if (is_full_verbose)
169188
info(5) << "ENV_INDEXER (V2) name=" << cells.name() << " cells=" << cells.view().localIds();
170189

171-
ENUMERATE_CELL(icell,cells){
190+
ENUMERATE_CELL (icell, cells) {
172191
if (cells_nb_env[icell.itemLocalId()] > 1)
173192
list_builder.addPartialItem(icell.itemLocalId());
174193
else
@@ -184,7 +203,7 @@ _rebuildMaterialsAndEnvironmentsFromGroups()
184203
var_indexer->endUpdate(list_builder);
185204
}
186205

187-
for( MeshEnvironment* env : true_environments )
206+
for (MeshEnvironment* env : true_environments)
188207
env->computeItemListForMaterials(*m_component_connectivity_list);
189208
}
190209

@@ -211,7 +230,7 @@ _computeInfosForEnvCells()
211230
Int32UniqueArray env_cell_indexes(cell_family->maxLocalId());
212231
{
213232
Integer env_cell_index = 0;
214-
ENUMERATE_CELL(icell,all_cells){
233+
ENUMERATE_CELL (icell, all_cells) {
215234
Int32 lid = icell.itemLocalId();
216235
Int32 nb_env = cells_nb_env[lid];
217236
env_cell_indexes[lid] = env_cell_index;
@@ -222,7 +241,7 @@ _computeInfosForEnvCells()
222241
// Positionne les infos pour les EnvCell
223242
{
224243
Int32UniqueArray current_pos(env_cell_indexes);
225-
for( MeshEnvironment* env : true_environments ){
244+
for (MeshEnvironment* env : true_environments) {
226245
const Int16 env_id = env->componentId();
227246
const MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
228247
CellGroup cells = env->cells();
@@ -238,7 +257,7 @@ _computeInfosForEnvCells()
238257
ArrayView<ComponentItemInternal*> env_items_internal_pointer = env->itemsInternalView();
239258
Int32ConstArrayView local_ids = var_indexer->localIds();
240259

241-
for( Integer z=0, nb_id = matvar_indexes.size(); z<nb_id; ++z){
260+
for (Integer z = 0, nb_id = matvar_indexes.size(); z < nb_id; ++z) {
242261
MatVarIndex mvi = matvar_indexes[z];
243262

244263
Int32 lid = local_ids[z];
@@ -253,22 +272,22 @@ _computeInfosForEnvCells()
253272
ref_ii._setComponent(env_id);
254273
}
255274
}
256-
for( MeshEnvironment* env : true_environments ){
275+
for (MeshEnvironment* env : true_environments) {
257276
env->computeMaterialIndexes(&m_item_internal_data);
258277
}
259278
}
260279

261280
// Positionne les infos pour les AllEnvCell.
262281
{
263-
ENUMERATE_CELL(icell,all_cells){
282+
ENUMERATE_CELL (icell, all_cells) {
264283
Cell c = *icell;
265284
Int32 lid = icell.itemLocalId();
266285
Int32 n = cells_nb_env[lid];
267286
ComponentItemInternal& ref_ii = all_env_items_internal[lid];
268-
ref_ii._setSuperAndGlobalItem({},c);
269-
ref_ii._setVariableIndex(MatVarIndex(0,lid));
287+
ref_ii._setSuperAndGlobalItem({}, c);
288+
ref_ii._setVariableIndex(MatVarIndex(0, lid));
270289
ref_ii._setNbSubItem(n);
271-
if (n!=0)
290+
if (n != 0)
272291
ref_ii._setFirstSubItem(env_items_internal_range[env_cell_indexes[lid]]);
273292
}
274293
}
@@ -323,65 +342,72 @@ forceRecompute(bool compute_all)
323342

324343
ConstArrayView<MeshMaterialVariableIndexer*> vars_idx = m_material_mng->_internalApi()->variablesIndexer();
325344
Integer nb_var = vars_idx.size();
326-
info(4) << "ForceRecompute NB_VAR_IDX=" << nb_var << " compute_all?=" << compute_all;
345+
Int64 mesh_timestamp = m_material_mng->mesh()->timestamp();
346+
info(4) << "ForceRecompute NB_VAR_IDX=" << nb_var << " compute_all?=" << compute_all
347+
<< " mesh_timestamp=" << mesh_timestamp << " current_mesh_timestamp=" << m_current_mesh_timestamp;
327348

328-
const bool is_verbose_debug = m_verbose_debug_level >0;
349+
// Si le maillage a changé, il y a certaines choses qu'il faut toujours recalculer
350+
bool has_mesh_changed = m_current_mesh_timestamp != mesh_timestamp;
351+
m_current_mesh_timestamp = mesh_timestamp;
352+
353+
const bool is_verbose_debug = m_verbose_debug_level > 0;
329354

330355
// Il faut compter le nombre total de mailles par milieu et par matériau
331356

332357
ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
333358

334-
if (compute_all){
359+
if (compute_all)
335360
_rebuildIncrementalConnectivitiesFromGroups();
336-
_computeNbEnvAndNbMatPerCell();
337-
}
338361

339-
// Calcul le nombre de milieux par maille, et pour chaque
362+
// Calcule le nombre de milieux par maille, et pour chaque
340363
// milieu le nombre de matériaux par maille
364+
if (compute_all || has_mesh_changed)
365+
_computeNbEnvAndNbMatPerCell();
366+
341367
_computeAndResizeEnvItemsInternal();
342368

343369
bool is_full_verbose = _isFullVerbose();
344370

345371
if (compute_all)
346372
_rebuildMaterialsAndEnvironmentsFromGroups();
347373

348-
for( const MeshEnvironment* env : true_environments ){
374+
for (const MeshEnvironment* env : true_environments) {
349375
const MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
350376
CellGroup cells = var_indexer->cells();
351377
Integer var_nb_cell = cells.size();
352378
info(4) << "FINAL_INDEXER i=" << var_indexer->index() << " NB_CELL=" << var_nb_cell << " name=" << cells.name()
353379
<< " index=" << var_indexer->index();
354-
if (is_full_verbose){
380+
if (is_full_verbose) {
355381
Int32UniqueArray my_array(cells.view().localIds());
356382
info(5) << "FINAL_INDEXER (V2) name=" << cells.name() << " cells=" << my_array;
357383
info(4) << "FINAL_MAT_NB_MULTIPLE_CELL (V2) mat=" << var_indexer->name()
358-
<< " ids=" << var_indexer->matvarIndexes();
384+
<< " ids=" << var_indexer->matvarIndexes();
359385
}
360386
}
361387

362388
_computeInfosForEnvCells();
363389

364-
if (is_verbose_debug){
390+
if (is_verbose_debug) {
365391
_printAllEnvCells(m_material_mng->mesh()->allCells().view());
366-
for( IMeshMaterial* material : m_material_mng->materials() ){
367-
ENUMERATE_COMPONENTITEM(MatCell,imatcell,material){
392+
for (IMeshMaterial* material : m_material_mng->materials()) {
393+
ENUMERATE_COMPONENTITEM (MatCell, imatcell, material) {
368394
MatCell pmc = *imatcell;
369395
info() << "CELL IN MAT vindex=" << pmc._varIndex();
370396
}
371397
}
372398
}
373399

374-
for( MeshEnvironment* env : true_environments ){
400+
for (MeshEnvironment* env : true_environments) {
375401
env->componentData()->_rebuildPartData();
376-
for( MeshMaterial* mat : env->trueMaterials() )
402+
for (MeshMaterial* mat : env->trueMaterials())
377403
mat->componentData()->_rebuildPartData();
378404
}
379405

380406
m_material_mng->checkValid();
381407

382408
m_material_mng->syncVariablesReferences();
383409

384-
if (is_verbose_debug){
410+
if (is_verbose_debug) {
385411
OStringStream ostr;
386412
m_material_mng->dumpInfos2(ostr());
387413
info() << ostr.str();
@@ -420,18 +446,18 @@ void AllEnvData::
420446
_printAllEnvCells(CellVectorView ids)
421447
{
422448
ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
423-
ENUMERATE_ALLENVCELL(iallenvcell,m_material_mng->view(ids)){
449+
ENUMERATE_ALLENVCELL (iallenvcell, m_material_mng->view(ids)) {
424450
AllEnvCell all_env_cell = *iallenvcell;
425451
Integer cell_nb_env = all_env_cell.nbEnvironment();
426452
Cell cell = all_env_cell.globalCell();
427453
info() << "CELL2 uid=" << ItemPrinter(cell)
428454
<< " nb_env=" << cells_nb_env[cell.localId()]
429455
<< " direct_nb_env=" << cell_nb_env;
430-
for( Integer z=0; z<cell_nb_env; ++z ){
456+
for (Integer z = 0; z < cell_nb_env; ++z) {
431457
EnvCell ec = all_env_cell.cell(z);
432458
Integer cell_nb_mat = ec.nbMaterial();
433459
info() << "CELL3 nb_mat=" << cell_nb_mat << " env_id=" << ec.environmentId();
434-
for( Integer k=0; k<cell_nb_mat; ++k ){
460+
for (Integer k = 0; k < cell_nb_mat; ++k) {
435461
MatCell mc = ec.cell(k);
436462
info() << "CELL4 mat_item=" << mc._varIndex() << " mat_id=" << mc.materialId();
437463
}
@@ -451,7 +477,7 @@ _printAllEnvCells(CellVectorView ids)
451477
void AllEnvData::
452478
_copyBetweenPartialsAndGlobals(Int32ConstArrayView pure_local_ids,
453479
Int32ConstArrayView partial_indexes,
454-
Int32 indexer_index,bool is_add_operation)
480+
Int32 indexer_index, bool is_add_operation)
455481
{
456482
if (pure_local_ids.empty())
457483
return;
@@ -460,13 +486,13 @@ _copyBetweenPartialsAndGlobals(Int32ConstArrayView pure_local_ids,
460486
// correspondantes pour chaque variable.
461487
//info(4) << "NB_TRANSFORM=" << nb_transform << " name=" << e->name();
462488
//Integer indexer_index = indexer->index();
463-
auto func = [=](IMeshMaterialVariable* mv){
489+
auto func = [=](IMeshMaterialVariable* mv) {
464490
if (is_add_operation)
465-
mv->_internalApi()->copyGlobalToPartial(indexer_index,pure_local_ids,partial_indexes);
491+
mv->_internalApi()->copyGlobalToPartial(indexer_index, pure_local_ids, partial_indexes);
466492
else
467-
mv->_internalApi()->copyPartialToGlobal(indexer_index,pure_local_ids,partial_indexes);
493+
mv->_internalApi()->copyPartialToGlobal(indexer_index, pure_local_ids, partial_indexes);
468494
};
469-
functor::apply(m_material_mng,&MeshMaterialMng::visitVariables,func);
495+
functor::apply(m_material_mng, &MeshMaterialMng::visitVariables, func);
470496
}
471497

472498
/*---------------------------------------------------------------------------*/
@@ -484,23 +510,23 @@ _checkConnectivityCoherency()
484510
Int32 nb_error = 0;
485511

486512
// Vérifie le nombre de matériaux par maille
487-
ENUMERATE_CELL(icell,all_cells){
513+
ENUMERATE_CELL (icell, all_cells) {
488514
Int32 ref_nb_mat = 0;
489-
for( MeshEnvironment* env : true_environments ){
515+
for (MeshEnvironment* env : true_environments) {
490516
Int16 env_id = env->componentId();
491517
ref_nb_mat += m_component_connectivity_list->cellNbMaterial(icell, env_id);
492518
}
493519
Int32 current_nb_mat = nb_mat_v2[icell.itemLocalId()];
494-
if (ref_nb_mat!=current_nb_mat){
520+
if (ref_nb_mat != current_nb_mat) {
495521
++nb_error;
496-
if (nb_error<10)
522+
if (nb_error < 10)
497523
error() << "Invalid values for nb_material cell=" << icell->uniqueId()
498524
<< " ref=" << ref_nb_mat << " current=" << current_nb_mat;
499525
}
500526
}
501527

502-
if (nb_error!=0)
503-
ARCANE_FATAL("Invalid values for component connectivity nb_error={0}",nb_error);
528+
if (nb_error != 0)
529+
ARCANE_FATAL("Invalid values for component connectivity nb_error={0}", nb_error);
504530
}
505531

506532
/*---------------------------------------------------------------------------*/

arcane/src/arcane/materials/internal/AllEnvData.h

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class AllEnvData
7878
Int32 m_verbose_debug_level = 0;
7979

8080
ComponentItemInternalData m_item_internal_data;
81+
Int64 m_current_mesh_timestamp = -1;
8182

8283
private:
8384

0 commit comments

Comments
 (0)