14#include "arcane/utils/NotImplementedException.h"
15#include "arcane/utils/ITraceMng.h"
16#include "arcane/utils/FunctorUtils.h"
17#include "arcane/utils/ArgumentException.h"
18#include "arcane/utils/OStringStream.h"
19#include "arcane/utils/MemoryUtils.h"
20#include "arcane/utils/ValueConvert.h"
21#include "arcane/utils/ArraySimdPadder.h"
23#include "arcane/core/IMesh.h"
24#include "arcane/core/IItemFamily.h"
25#include "arcane/core/ItemPrinter.h"
26#include "arcane/core/VariableBuildInfo.h"
27#include "arcane/core/internal/ItemGroupImplInternal.h"
28#include "arcane/core/materials/internal/IMeshMaterialVariableInternal.h"
30#include "arcane/materials/IMeshMaterialVariable.h"
31#include "arcane/materials/CellToAllEnvCellConverter.h"
33#include "arcane/materials/internal/MeshMaterialMng.h"
34#include "arcane/materials/internal/AllEnvData.h"
35#include "arcane/materials/internal/MaterialModifierOperation.h"
36#include "arcane/materials/internal/ConstituentConnectivityList.h"
37#include "arcane/materials/internal/ComponentItemListBuilder.h"
39#include "arcane/accelerator/Scan.h"
74AllEnvData(MeshMaterialMng* mmg)
77, m_item_internal_data(mmg)
81 m_component_connectivity_list =
new ConstituentConnectivityList(m_material_mng);
82 m_component_connectivity_list_ref = m_component_connectivity_list->toSourceReference();
85 m_verbose_debug_level = v.value();
95endCreate(
bool is_continue)
97 m_item_internal_data.endCreate();
98 m_component_connectivity_list->endCreate(is_continue);
105_isFullVerbose()
const
107 return (m_verbose_debug_level > 1 || traceMng()->verbosityLevel() >= 5);
114_computeNbEnvAndNbMatPerCell()
116 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
120 for (MeshEnvironment* env : true_environments) {
121 env->computeNbMatPerCell();
129_computeAndResizeEnvItemsInternal()
133 IMesh* mesh = m_material_mng->mesh();
134 const IItemFamily* cell_family = mesh->cellFamily();
135 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
137 Integer nb_env = true_environments.size();
140 info(4) <<
"NB_ENV = " << nb_env;
141 for (
const MeshEnvironment* env : true_environments) {
143 Integer env_nb_cell = cells.size();
144 info(4) <<
"EnvName=" << cells.name() <<
" nb_env_cell=" << env_nb_cell <<
" nb_mat_cell=" << env->totalNbCellMat();
145 total_env_cell += env_nb_cell;
146 total_mat_cell += env->totalNbCellMat();
150 Int32 max_local_id = cell_family->maxLocalId();
151 info(4) <<
"RESIZE TotalEnvCell=" << total_env_cell
152 <<
" TotalMatCell=" << total_mat_cell
153 <<
" MaxLocalId=" << max_local_id;
158 m_item_internal_data.resizeComponentItemInternals(max_local_id, total_env_cell);
161 Int32 computed_nb_mat = 0;
162 Int32 computed_nb_env = 0;
163 ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
164 ConstArrayView<Int16> cells_nb_mat = m_component_connectivity_list->cellsNbMaterial();
165 ENUMERATE_ (Cell, icell, cell_family->allItems()) {
166 Int32 lid = icell.itemLocalId();
167 computed_nb_env += cells_nb_env[lid];
168 computed_nb_mat += cells_nb_mat[lid];
170 Int32 computed_size = computed_nb_mat + computed_nb_env;
171 Int32 storage_size = total_mat_cell + total_env_cell;
172 info(4) <<
"storage_size=" << storage_size <<
" computed=" << computed_size
173 <<
" max_local_id=" << max_local_id <<
" internal_nb_mat=" << total_mat_cell <<
" internal_nb_env=" << total_env_cell
174 <<
" computed_nb_mat=" << computed_nb_mat <<
" computed_nb_env=" << computed_nb_env;
175 if (storage_size != computed_size)
176 ARCANE_FATAL(
"BAD STORAGE SIZE internal={0} connectivity={1}", storage_size, computed_size);
186_rebuildIncrementalConnectivitiesFromGroups()
188 RunQueue queue(
makeQueue(m_material_mng->runner()));
189 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
190 auto clist = m_component_connectivity_list;
191 clist->removeAllConnectivities();
192 for (MeshEnvironment* env : true_environments) {
193 clist->addCellsToEnvironment(env->componentId(), env->cells().view().localIds(), queue);
194 for (MeshMaterial* mat : env->trueMaterials())
195 clist->addCellsToMaterial(mat->componentId(), mat->cells().view().localIds(), queue);
203_rebuildMaterialsAndEnvironmentsFromGroups()
205 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
206 const bool is_full_verbose = _isFullVerbose();
207 ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
208 for (
const MeshEnvironment* env : true_environments) {
209 MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
210 ComponentItemListBuilderOld list_builder(var_indexer, 0);
212 Integer var_nb_cell = cells.size();
213 info(4) <<
"ENV_INDEXER (V2) i=" << var_indexer->index() <<
" NB_CELL=" << var_nb_cell <<
" name=" << cells.name()
214 <<
" index=" << var_indexer->index();
216 info(5) <<
"ENV_INDEXER (V2) name=" << cells.name() <<
" cells=" << cells.view().localIds();
219 if (cells_nb_env[icell.itemLocalId()] > 1)
220 list_builder.addPartialItem(icell.itemLocalId());
223 list_builder.addPureItem(icell.itemLocalId());
226 info() <<
"MAT_NB_MULTIPLE_CELL (V2) mat=" << var_indexer->name()
227 <<
" nb_in_global=" << list_builder.pureMatVarIndexes().size()
228 <<
" (ids=" << list_builder.pureMatVarIndexes() <<
")"
229 <<
" nb_in_multiple=" << list_builder.partialMatVarIndexes().size()
230 <<
" (ids=" << list_builder.partialLocalIds() <<
")";
231 var_indexer->endUpdate(list_builder);
234 for (MeshEnvironment* env : true_environments)
235 env->computeItemListForMaterials(*m_component_connectivity_list);
242_computeInfosForAllEnvCells1(RecomputeConstituentCellInfos& work_info)
244 IMesh* mesh = m_material_mng->mesh();
245 IItemFamily* cell_family = mesh->cellFamily();
246 CellGroup all_cells = cell_family->allItems();
247 const Int32 nb_cell = all_cells.
size();
248 const Int32 max_local_id = cell_family->maxLocalId();
250 SmallSpan<const Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
256 work_info.env_cell_indexes.resize(cells_nb_env.size());
258 bool do_old = (max_local_id != nb_cell);
262 Int32 lid = icell.itemLocalId();
263 Int32 nb_env = cells_nb_env[lid];
264 work_info.env_cell_indexes[lid] = env_cell_index;
265 env_cell_index += nb_env;
271 Accelerator::GenericScanner scanner(work_info.m_queue);
272 SmallSpan<Int32> env_cell_indexes_view(work_info.env_cell_indexes);
273 Accelerator::ScannerSumOperator<Int32> op;
274 scanner.applyExclusive(0, cells_nb_env, env_cell_indexes_view, op, A_FUNCINFO);
282_computeInfosForAllEnvCells2(RecomputeConstituentCellInfos& work_info)
286 SmallSpan<const Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
289 ComponentItemSharedInfo* all_env_shared_info = m_item_internal_data.allEnvSharedInfo();
291 SmallSpan<Int32> env_cell_indexes_view(work_info.env_cell_indexes);
295 Int16 n = cells_nb_env[lid];
296 matimpl::ConstituentItemBase ref_ii(all_env_shared_info, ConstituentItemIndex(lid));
297 ref_ii._setSuperAndGlobalItem({}, cell_id);
298 ref_ii._setVariableIndex(MatVarIndex(0, lid));
299 ref_ii._setNbSubItem(n);
301 ref_ii._setFirstSubItem(ConstituentItemIndex(env_cell_indexes_view[lid]));
311_computeInfosForEnvCells(RecomputeConstituentCellInfos& work_info)
313 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
314 RunQueue queue(m_material_mng->runQueue());
316 IMesh* mesh = m_material_mng->mesh();
317 IItemFamily* cell_family = mesh->cellFamily();
318 const Int32 max_local_id = cell_family->maxLocalId();
320 for (MeshEnvironment* env : true_environments) {
321 const Int16 env_id = env->componentId();
322 const MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
325 env->resizeItemsInternal(var_indexer->nbItem());
327 info(4) <<
"COMPUTE (V2) env_cells env=" << env->
name() <<
" nb_cell=" << cells.size()
328 <<
" index=" << var_indexer->index()
329 <<
" max_multiple_index=" << var_indexer->maxIndexInMultipleArray();
331 SmallSpan<const MatVarIndex> matvar_indexes(var_indexer->matvarIndexes());
335 const bool is_mono_mat = env->isMonoMaterial();
337 work_info.cells_nb_material.resize(max_local_id);
339 SmallSpan<Int16> cells_nb_mat_view = work_info.cells_nb_material.view();
342 m_component_connectivity_list->fillCellsNbMaterial(local_ids, env_id, cells_nb_mat_view, queue);
345 SmallSpan<Int32> current_pos_view(work_info.env_cell_indexes);
346 const Int32 nb_id = matvar_indexes.size();
347 ComponentItemSharedInfo* env_shared_info = m_item_internal_data.envSharedInfo();
349 Span<Int32> env_cells_local_id = cells._internalApi()->itemsLocalId();
350 SmallSpan<ConstituentItemIndex> env_id_list = env->componentData()->m_constituent_local_id_list.mutableLocalIds();
354 MatVarIndex mvi = matvar_indexes[z];
356 Int32 lid = local_ids[z];
357 Int32 pos = current_pos_view[lid];
358 ++current_pos_view[lid];
359 Int16 nb_mat = (is_mono_mat) ? 1 : cells_nb_mat_view[z];
361 ConstituentItemIndex cii_pos(pos);
362 matimpl::ConstituentItemBase ref_ii(env_shared_info, cii_pos);
363 ConstituentItemIndex cii_lid(lid);
364 env_id_list[z] = cii_pos;
366 ref_ii._setSuperAndGlobalItem(cii_lid, ItemLocalId(lid));
367 ref_ii._setNbSubItem(nb_mat);
368 ref_ii._setVariableIndex(mvi);
369 ref_ii._setComponent(env_id);
372 ArraySimdPadder::applySimdPaddingView(env_cells_local_id);
374 cells._internalApi()->notifySimdPaddingDone();
379 Accelerator::RunQueuePool& queue_pool = m_material_mng->_internalApi()->asyncRunQueuePool();
380 for (MeshEnvironment* env : true_environments) {
381 env->computeMaterialIndexes(&m_item_internal_data, queue_pool[env->id()]);
383 queue_pool.barrier();
394_checkLocalIdsCoherency()
const
396 for (MeshEnvironment* env : m_material_mng->trueEnvironments()) {
400 ComponentCell cc = *icitem;
401 Int32 matvar_lid = cc.globalCell().localId();
402 Int32 direct_lid = indexer_local_ids[index];
403 if (matvar_lid != direct_lid)
404 ARCANE_FATAL(
"Incoherent localId() matvar_lid={0} direct_lid={1} index={2}",
405 matvar_lid, direct_lid, index);
430forceRecompute(
bool compute_all)
432 m_material_mng->incrementTimestamp();
434 ConstArrayView<MeshMaterialVariableIndexer*> vars_idx = m_material_mng->_internalApi()->variablesIndexer();
435 Integer nb_var = vars_idx.size();
436 Int64 mesh_timestamp = m_material_mng->mesh()->timestamp();
437 info(4) <<
"ForceRecompute NB_VAR_IDX=" << nb_var <<
" compute_all?=" << compute_all
438 <<
" mesh_timestamp=" << mesh_timestamp <<
" current_mesh_timestamp=" << m_current_mesh_timestamp;
441 bool has_mesh_changed = m_current_mesh_timestamp != mesh_timestamp;
442 m_current_mesh_timestamp = mesh_timestamp;
444 const bool is_verbose_debug = m_verbose_debug_level > 0;
448 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
451 _rebuildIncrementalConnectivitiesFromGroups();
455 if (compute_all || has_mesh_changed)
456 _computeNbEnvAndNbMatPerCell();
458 _computeAndResizeEnvItemsInternal();
460 bool is_full_verbose = _isFullVerbose();
463 _rebuildMaterialsAndEnvironmentsFromGroups();
465 for (
const MeshEnvironment* env : true_environments) {
466 const MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
468 Integer var_nb_cell = cells.size();
469 info(4) <<
"FINAL_INDEXER i=" << var_indexer->index() <<
" NB_CELL=" << var_nb_cell <<
" name=" << cells.name()
470 <<
" index=" << var_indexer->index();
471 if (is_full_verbose) {
473 info(5) <<
"FINAL_INDEXER (V2) name=" << cells.name() <<
" cells=" << my_array;
474 info(4) <<
"FINAL_MAT_NB_MULTIPLE_CELL (V2) mat=" << var_indexer->name()
475 <<
" ids=" << var_indexer->matvarIndexes();
479 RunQueue& queue(m_material_mng->runQueue());
482 RecomputeConstituentCellInfos work_info(queue);
483 _computeInfosForAllEnvCells1(work_info);
484 _computeInfosForAllEnvCells2(work_info);
485 _computeInfosForEnvCells(work_info);
488 if (is_verbose_debug) {
489 _printAllEnvCells(m_material_mng->mesh()->allCells().view());
490 for (IMeshMaterial* material : m_material_mng->materials()) {
492 MatCell pmc = *imatcell;
493 info() <<
"CELL IN MAT vindex=" << pmc._varIndex();
499 for (MeshEnvironment* env : true_environments) {
500 env->componentData()->_rebuildPartData(queue);
501 for (MeshMaterial* mat : env->trueMaterials())
502 mat->componentData()->_rebuildPartData(queue);
507 m_material_mng->checkValid();
509 m_material_mng->syncVariablesReferences(compute_all);
511 if (is_verbose_debug) {
513 m_material_mng->dumpInfos2(ostr());
514 info() << ostr.str();
520 _checkLocalIdsCoherency();
523 if (m_material_mng->isCellToAllEnvCellForRunCommand()) {
524 auto* all_cell_to_all_env_cell(m_material_mng->_internalApi()->getAllCellToAllEnvCell());
525 if (all_cell_to_all_env_cell)
526 all_cell_to_all_env_cell->bruteForceUpdate();
528 m_material_mng->_internalApi()->createAllCellToAllEnvCell();
536recomputeIncremental()
538 forceRecompute(
false);
540 _checkConnectivityCoherency();
549 ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
551 AllEnvCell all_env_cell = *iallenvcell;
552 Integer cell_nb_env = all_env_cell.nbEnvironment();
553 Cell cell = all_env_cell.globalCell();
554 info() <<
"CELL2 uid=" << ItemPrinter(cell)
555 <<
" nb_env=" << cells_nb_env[cell.localId()]
556 <<
" direct_nb_env=" << cell_nb_env;
557 for (Integer z = 0; z < cell_nb_env; ++z) {
558 EnvCell ec = all_env_cell.cell(z);
559 Integer cell_nb_mat = ec.nbMaterial();
560 info() <<
"CELL3 nb_mat=" << cell_nb_mat <<
" env_id=" << ec.environmentId();
561 for (Integer k = 0; k < cell_nb_mat; ++k) {
562 MatCell mc = ec.cell(k);
563 info() <<
"CELL4 mat_item=" << mc._varIndex() <<
" mat_id=" << mc.materialId();
573_checkConnectivityCoherency()
575 info() <<
"AllEnvData: checkCoherency()";
576 ConstArrayView<Int16> nb_mat_v2 = m_component_connectivity_list->cellsNbMaterial();
577 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
579 ItemGroup all_cells = m_material_mng->mesh()->allCells();
585 Int32 ref_nb_mat = 0;
586 for (MeshEnvironment* env : true_environments) {
587 Int16 env_id = env->componentId();
588 ref_nb_mat += m_component_connectivity_list->cellNbMaterial(icell, env_id);
590 Int32 current_nb_mat = nb_mat_v2[icell.itemLocalId()];
591 if (ref_nb_mat != current_nb_mat) {
594 error() <<
"Invalid values for nb_material cell=" << icell->uniqueId()
595 <<
" ref=" << ref_nb_mat <<
" current=" << current_nb_mat;
600 ARCANE_FATAL(
"Invalid values for component connectivity nb_error={0}", nb_error);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Types et macros pour gérer les énumérations des entités sur les accélérateurs.
#define RUNCOMMAND_ENUMERATE(ItemTypeName, iter_name, item_group,...)
Macro pour itérer sur accélérateur sur un groupe d'entités.
Types et macros pour gérer les boucles sur les accélérateurs.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
Boucle sur accélérateur avec arguments supplémentaires pour les réductions.
File d'exécution pour un accélérateur.
MemoryAllocationOptions allocationOptions() const
Options d'allocation associée à cette file.
virtual CellGroup allCells()=0
Groupe de toutes les mailles.
const String & name() const
Nom du groupe.
Integer size() const
Nombre d'éléments du groupe.
IMesh * mesh() const
Maillage auquel appartient ce groupe (0 pour le group nul)
Classe d'accès aux traces.
Vecteur 1D de données avec sémantique par valeur (style STL).
ItemGroupT< Cell > CellGroup
Groupe de mailles.
ItemVectorViewT< Cell > CellVectorView
Vue sur un vecteur de mailles.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
RunQueue makeQueue(const Runner &runner)
Créé une file associée à runner.
Active toujours les traces dans les parties Arcane concernant les matériaux.
bool arcaneIsCheck()
Vrai si on est en mode vérification.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Int32 Integer
Type représentant un entier.