@@ -171,6 +171,8 @@ class MaterialHeatTestModule
171171 RunQueue m_queue;
172172 Runner m_sequential_runner;
173173 UniqueArray<MeshMaterialVariableRef*> m_additional_variables;
174+ bool m_is_init_with_zero = false ;
175+ bool m_is_check_init_new_cells = false ;
174176
175177 private:
176178
@@ -210,6 +212,15 @@ MaterialHeatTestModule(const ModuleBuildInfo& mbi)
210212 if (auto v = Convert::Type<Int32>::tryParseFromEnvironment (" ARCANE_PROFILE_HEATTEST" , true ))
211213 if (v.value () != 0 )
212214 m_profiling_service = platform::getProfilingService ();
215+ if (auto v = Convert::Type<Int32>::tryParseFromEnvironment (" ARCANE_MATERIAL_NEW_ITEM_INIT" , true )) {
216+ Int32 vv = v.value ();
217+ // 0 -> initialisation à partir de la maille globale et pas de vérification
218+ // 1 -> initialisation à zéro et pas de vérification
219+ // 2 -> initialisation à zéro et vérification
220+ // 3 -> initialisation à partir de la maille globale et vérification
221+ m_is_init_with_zero = (vv == 1 || vv == 2 );
222+ m_is_check_init_new_cells = (vv == 2 || vv == 3 );
223+ }
213224}
214225
215226/* ---------------------------------------------------------------------------*/
@@ -248,6 +259,7 @@ buildInit()
248259 m_material_mng->setModificationFlags (flags);
249260 m_material_mng->setMeshModificationNotified (true );
250261 m_material_mng->setUseMaterialValueWhenRemovingPartialValue (true );
262+ m_material_mng->setDataInitialisationWithZero (m_is_init_with_zero);
251263 if (subDomain ()->isContinue ()) {
252264 mm->recreateFromDump ();
253265 }
@@ -305,7 +317,7 @@ buildInit()
305317 for (Int32 i = 0 ; i < nb_var_to_add; ++i) {
306318 String var_name = " MaterialAdditionalArrayVar" + String::fromNumber (i);
307319 auto * v = new MaterialVariableCellArrayInt32 (VariableBuildInfo (mesh, var_name));
308- v->resize (1 + (i% 3 ));
320+ v->resize (1 + (i % 3 ));
309321 m_additional_variables.add (v);
310322 v->globalVariable ().fill (i + 5 );
311323 v->fillPartialValuesWithSuperValues (LEVEL_ALLENVIRONMENT);
@@ -512,29 +524,56 @@ _initNewCells(const HeatObject& heat_object, MaterialWorkArray& wa)
512524{
513525 RunQueue* queue = this ->acceleratorMng ()->defaultQueue ();
514526
527+ bool init_with_zero = m_material_mng->isDataInitialisationWithZero ();
528+
515529 // Initialise les nouvelles valeurs partielles
516530 IMeshMaterial* current_mat = heat_object.material ;
517531 Int32 mat_id = current_mat->id ();
518532 CellToAllEnvCellConverter all_env_cell_converter (m_material_mng);
519533 SmallSpan<const Int32> ids (wa.mat_cells_to_add .constView ());
520534 const Int32 nb_id = ids.size ();
535+ const bool do_check = m_is_check_init_new_cells;
536+ if (do_check) {
537+ // Vérifie que la nouvelle valeur est initialisée avec 0 (si init_with_zero
538+ // est vrai) où qu'elle est initialisée avec la valeur globale
539+ auto command = makeCommand (queue);
540+ auto out_mat_temperature = viewInOut (command, m_mat_temperature);
541+ Accelerator::ReducerSum2<Int32> sum_error (command);
542+ command << RUNCOMMAND_LOOP1 (iter, nb_id, sum_error)
543+ {
544+ auto [i] = iter ();
545+ AllEnvCell all_env_cell = all_env_cell_converter[CellLocalId (ids[i])];
546+ MatCell mc = _getMatCell (all_env_cell, mat_id);
547+ MatVarIndex mvi = mc._varIndex ();
548+ if (mvi.arrayIndex () != 0 ) {
549+ Real v = out_mat_temperature[mc];
550+ if (init_with_zero) {
551+ if (v != 0.0 )
552+ sum_error.combine (1 );
553+ // ARCANE_FATAL("Bad mat temperature (should be 0) i={0} v={1} mc={2}", i, v, mc);
554+ }
555+ else {
556+ Real global_v = out_mat_temperature[CellLocalId (mc.globalCellId ())];
557+ if (v != global_v)
558+ sum_error.combine (1 );
559+ // ARCANE_FATAL("Bad mat temperature i={0} v={1} mc={2} expected_v={3}", i, v, mc, global_v);
560+ }
561+ }
562+ };
563+ Int32 nb_error = sum_error.reducedValue ();
564+ if (nb_error != 0 )
565+ ARCANE_FATAL (" Errors with new cells nb_error={0}" , nb_error);
566+ }
521567 {
522568 auto command = makeCommand (queue);
523569 auto in_value_to_add = viewIn (command, wa.mat_cells_to_add_value );
524570 auto out_mat_temperature = viewInOut (command, m_mat_temperature);
525571 command << RUNCOMMAND_LOOP1 (iter, nb_id)
526572 {
527573 auto [i] = iter ();
528-
529- // for (Int32 i = 0, n = ids.size(); i < n; ++i) {
530574 AllEnvCell all_env_cell = all_env_cell_converter[CellLocalId (ids[i])];
531575 MatCell mc = _getMatCell (all_env_cell, mat_id);
532- // Teste que la maille n'est pas nulle.
533- // Ne devrait pas arriver car on l'a ajouté juste avant
534- // if (mc.null())
535- // ARCANE_FATAL("Internal invalid null mat cell");
536576 out_mat_temperature[mc] = in_value_to_add[i];
537- // }
538577 };
539578 }
540579}
0 commit comments