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"
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"
38#include "arcane/materials/internal/AllCellToAllEnvCellContainer.h"
40#include "arcane/accelerator/Scan.h"
41#include "arcane/accelerator/RunCommandLoop.h"
57 explicit RecomputeConstituentCellInfos(
RunQueue& q)
75AllEnvData(MeshMaterialMng* mmg)
78, m_item_internal_data(mmg)
82 m_component_connectivity_list =
new ConstituentConnectivityList(m_material_mng);
83 m_component_connectivity_list_ref = m_component_connectivity_list->toSourceReference();
86 m_verbose_debug_level = v.value();
96endCreate(
bool is_continue)
98 m_item_internal_data.endCreate();
99 m_component_connectivity_list->endCreate(is_continue);
106_isFullVerbose()
const
108 return (m_verbose_debug_level > 1 || traceMng()->verbosityLevel() >= 5);
115_computeNbEnvAndNbMatPerCell()
117 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
121 for (MeshEnvironment* env : true_environments) {
122 env->computeNbMatPerCell();
130_computeAndResizeEnvItemsInternal()
134 IMesh* mesh = m_material_mng->mesh();
135 const IItemFamily* cell_family = mesh->cellFamily();
136 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
138 Integer nb_env = true_environments.size();
141 info(4) <<
"NB_ENV = " << nb_env;
142 for (
const MeshEnvironment* env : true_environments) {
145 info(4) <<
"EnvName=" << cells.name() <<
" nb_env_cell=" << env_nb_cell <<
" nb_mat_cell=" << env->totalNbCellMat();
146 total_env_cell += env_nb_cell;
147 total_mat_cell += env->totalNbCellMat();
151 Int32 max_local_id = cell_family->maxLocalId();
152 info(4) <<
"RESIZE TotalEnvCell=" << total_env_cell
153 <<
" TotalMatCell=" << total_mat_cell
154 <<
" MaxLocalId=" << max_local_id;
159 m_item_internal_data.resizeComponentItemInternals(max_local_id, total_env_cell);
162 Int32 computed_nb_mat = 0;
163 Int32 computed_nb_env = 0;
164 ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
165 ConstArrayView<Int16> cells_nb_mat = m_component_connectivity_list->cellsNbMaterial();
167 Int32 lid = icell.itemLocalId();
168 computed_nb_env += cells_nb_env[lid];
169 computed_nb_mat += cells_nb_mat[lid];
171 Int32 computed_size = computed_nb_mat + computed_nb_env;
172 Int32 storage_size = total_mat_cell + total_env_cell;
173 info(4) <<
"storage_size=" << storage_size <<
" computed=" << computed_size
174 <<
" max_local_id=" << max_local_id <<
" internal_nb_mat=" << total_mat_cell <<
" internal_nb_env=" << total_env_cell
175 <<
" computed_nb_mat=" << computed_nb_mat <<
" computed_nb_env=" << computed_nb_env;
176 if (storage_size != computed_size)
177 ARCANE_FATAL(
"BAD STORAGE SIZE internal={0} connectivity={1}", storage_size, computed_size);
188_rebuildIncrementalConnectivitiesFromGroups()
190 RunQueue queue(
makeQueue(m_material_mng->runner()));
191 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
192 auto clist = m_component_connectivity_list;
193 clist->removeAllConnectivities();
194 for (MeshEnvironment* env : true_environments) {
195 clist->addCellsToEnvironment(env->componentId(), env->cells().view().localIds(), queue);
196 for (MeshMaterial* mat : env->trueMaterials())
197 clist->addCellsToMaterial(mat->componentId(), mat->cells().view().localIds(), queue);
205_rebuildMaterialsAndEnvironmentsFromGroups()
207 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
208 const bool is_full_verbose = _isFullVerbose();
209 ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
210 for (
const MeshEnvironment* env : true_environments) {
211 MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
212 ComponentItemListBuilderOld list_builder(var_indexer, 0);
215 info(4) <<
"ENV_INDEXER (V2) i=" << var_indexer->index() <<
" NB_CELL=" << var_nb_cell <<
" name=" << cells.name()
216 <<
" index=" << var_indexer->index();
218 info(5) <<
"ENV_INDEXER (V2) name=" << cells.name() <<
" cells=" << cells.view().localIds();
221 if (cells_nb_env[icell.itemLocalId()] > 1)
222 list_builder.addPartialItem(icell.itemLocalId());
225 list_builder.addPureItem(icell.itemLocalId());
228 info() <<
"MAT_NB_MULTIPLE_CELL (V2) mat=" << var_indexer->name()
229 <<
" nb_in_global=" << list_builder.pureMatVarIndexes().size()
230 <<
" (ids=" << list_builder.pureMatVarIndexes() <<
")"
231 <<
" nb_in_multiple=" << list_builder.partialMatVarIndexes().size()
232 <<
" (ids=" << list_builder.partialLocalIds() <<
")";
233 var_indexer->endUpdate(list_builder);
236 for (MeshEnvironment* env : true_environments)
237 env->computeItemListForMaterials(*m_component_connectivity_list);
246 IMesh* mesh = m_material_mng->mesh();
247 IItemFamily* cell_family = mesh->cellFamily();
248 CellGroup all_cells = cell_family->allItems();
250 const Int32 max_local_id = cell_family->maxLocalId();
252 SmallSpan<const Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
260 bool do_old = (max_local_id != nb_cell);
264 Int32 lid = icell.itemLocalId();
265 Int32 nb_env = cells_nb_env[lid];
266 work_info.env_cell_indexes[lid] = env_cell_index;
267 env_cell_index += nb_env;
273 Accelerator::GenericScanner scanner(work_info.m_queue);
274 SmallSpan<Int32> env_cell_indexes_view(work_info.env_cell_indexes);
275 Accelerator::ScannerSumOperator<Int32> op;
276 scanner.applyExclusive(0, cells_nb_env, env_cell_indexes_view, op, A_FUNCINFO);
288 SmallSpan<const Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
291 ComponentItemSharedInfo* all_env_shared_info = m_item_internal_data.allEnvSharedInfo();
293 SmallSpan<Int32> env_cell_indexes_view(work_info.env_cell_indexes);
297 Int16 n = cells_nb_env[lid];
298 matimpl::ConstituentItemBase ref_ii(all_env_shared_info, ConstituentItemIndex(lid));
299 ref_ii._setSuperAndGlobalItem({}, cell_id);
300 ref_ii._setVariableIndex(MatVarIndex(0, lid));
301 ref_ii._setNbSubItem(n);
303 ref_ii._setFirstSubItem(ConstituentItemIndex(env_cell_indexes_view[lid]));
316 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
317 RunQueue queue(m_material_mng->runQueue());
319 IMesh* mesh = m_material_mng->mesh();
320 IItemFamily* cell_family = mesh->cellFamily();
321 const Int32 max_local_id = cell_family->maxLocalId();
323 for (MeshEnvironment* env : true_environments) {
324 const Int16 env_id = env->componentId();
325 const MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
328 env->resizeItemsInternal(var_indexer->nbItem());
330 info(4) <<
"COMPUTE (V2) env_cells env=" << env->
name() <<
" nb_cell=" << cells.size()
331 <<
" index=" << var_indexer->index()
332 <<
" max_multiple_index=" << var_indexer->maxIndexInMultipleArray();
334 SmallSpan<const MatVarIndex> matvar_indexes(var_indexer->matvarIndexes());
338 const bool is_mono_mat = env->isMonoMaterial();
340 work_info.cells_nb_material.resize(max_local_id);
342 SmallSpan<Int16> cells_nb_mat_view = work_info.cells_nb_material.view();
345 m_component_connectivity_list->fillCellsNbMaterial(local_ids, env_id, cells_nb_mat_view, queue);
348 SmallSpan<Int32> current_pos_view(work_info.env_cell_indexes);
349 const Int32 nb_id = matvar_indexes.size();
350 ComponentItemSharedInfo* env_shared_info = m_item_internal_data.envSharedInfo();
352 Span<Int32> env_cells_local_id = cells._internalApi()->itemsLocalId();
353 SmallSpan<ConstituentItemIndex> env_id_list = env->componentData()->m_constituent_local_id_list.mutableLocalIds();
357 MatVarIndex mvi = matvar_indexes[z];
359 Int32 lid = local_ids[z];
360 Int32 pos = current_pos_view[lid];
361 ++current_pos_view[lid];
362 Int16 nb_mat = (is_mono_mat) ? 1 : cells_nb_mat_view[z];
364 ConstituentItemIndex cii_pos(pos);
365 matimpl::ConstituentItemBase ref_ii(env_shared_info, cii_pos);
366 ConstituentItemIndex cii_lid(lid);
367 env_id_list[z] = cii_pos;
369 ref_ii._setSuperAndGlobalItem(cii_lid, ItemLocalId(lid));
370 ref_ii._setNbSubItem(nb_mat);
371 ref_ii._setVariableIndex(mvi);
372 ref_ii._setComponent(env_id);
375 ArraySimdPadder::applySimdPaddingView(env_cells_local_id);
377 cells._internalApi()->notifySimdPaddingDone();
382 Accelerator::RunQueuePool& queue_pool = m_material_mng->_internalApi()->asyncRunQueuePool();
383 for (MeshEnvironment* env : true_environments) {
384 env->computeMaterialIndexes(&m_item_internal_data, queue_pool[env->id()]);
386 queue_pool.barrier();
398_checkLocalIdsCoherency()
const
400 for (MeshEnvironment* env : m_material_mng->trueEnvironments()) {
404 ComponentCell cc = *icitem;
406 Int32 direct_lid = indexer_local_ids[index];
407 if (matvar_lid != direct_lid)
408 ARCANE_FATAL(
"Incoherent localId() matvar_lid={0} direct_lid={1} index={2}",
409 matvar_lid, direct_lid, index);
434forceRecompute(
bool compute_all)
436 m_material_mng->incrementTimestamp();
438 ConstArrayView<MeshMaterialVariableIndexer*> vars_idx = m_material_mng->_internalApi()->variablesIndexer();
439 Integer nb_var = vars_idx.size();
440 Int64 mesh_timestamp = m_material_mng->mesh()->timestamp();
441 info(4) <<
"ForceRecompute NB_VAR_IDX=" << nb_var <<
" compute_all?=" << compute_all
442 <<
" mesh_timestamp=" << mesh_timestamp <<
" current_mesh_timestamp=" << m_current_mesh_timestamp;
445 bool has_mesh_changed = m_current_mesh_timestamp != mesh_timestamp;
446 m_current_mesh_timestamp = mesh_timestamp;
448 const bool is_verbose_debug = m_verbose_debug_level > 0;
452 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
455 _rebuildIncrementalConnectivitiesFromGroups();
459 if (compute_all || has_mesh_changed)
460 _computeNbEnvAndNbMatPerCell();
462 _computeAndResizeEnvItemsInternal();
464 bool is_full_verbose = _isFullVerbose();
467 _rebuildMaterialsAndEnvironmentsFromGroups();
469 for (
const MeshEnvironment* env : true_environments) {
470 const MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
473 info(4) <<
"FINAL_INDEXER i=" << var_indexer->index() <<
" NB_CELL=" << var_nb_cell <<
" name=" << cells.name()
474 <<
" index=" << var_indexer->index();
475 if (is_full_verbose) {
477 info(5) <<
"FINAL_INDEXER (V2) name=" << cells.name() <<
" cells=" << my_array;
478 info(4) <<
"FINAL_MAT_NB_MULTIPLE_CELL (V2) mat=" << var_indexer->name()
479 <<
" ids=" << var_indexer->matvarIndexes();
483 RunQueue& queue(m_material_mng->runQueue());
487 _computeInfosForAllEnvCells1(work_info);
488 _computeInfosForAllEnvCells2(work_info);
489 _computeInfosForEnvCells(work_info);
492 if (is_verbose_debug) {
493 _printAllEnvCells(m_material_mng->mesh()->allCells().view());
494 for (IMeshMaterial* material : m_material_mng->materials()) {
496 MatCell pmc = *imatcell;
497 info() <<
"CELL IN MAT vindex=" << pmc._varIndex();
503 for (MeshEnvironment* env : true_environments) {
504 env->componentData()->_rebuildPartData(queue);
505 for (MeshMaterial* mat : env->trueMaterials())
506 mat->componentData()->_rebuildPartData(queue);
511 m_material_mng->checkValid();
513 m_material_mng->syncVariablesReferences(compute_all);
515 if (is_verbose_debug) {
517 m_material_mng->dumpInfos2(ostr());
518 info() << ostr.str();
524 _checkLocalIdsCoherency();
527 if (m_material_mng->isCellToAllEnvCellForRunCommand()) {
528 auto* all_cell_to_all_env_cell(m_material_mng->_internalApi()->getAllCellToAllEnvCellContainer());
529 if (all_cell_to_all_env_cell)
530 all_cell_to_all_env_cell->bruteForceUpdate();
532 m_material_mng->_internalApi()->createAllCellToAllEnvCell();
540recomputeIncremental()
542 forceRecompute(
false);
544 _checkConnectivityCoherency();
553 ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
555 AllEnvCell all_env_cell = *iallenvcell;
556 Integer cell_nb_env = all_env_cell.nbEnvironment();
557 Cell cell = all_env_cell.globalCell();
558 info() <<
"CELL2 uid=" << ItemPrinter(cell)
559 <<
" nb_env=" << cells_nb_env[cell.localId()]
560 <<
" direct_nb_env=" << cell_nb_env;
561 for (
Integer z = 0; z < cell_nb_env; ++z) {
562 EnvCell ec = all_env_cell.cell(z);
563 Integer cell_nb_mat = ec.nbMaterial();
564 info() <<
"CELL3 nb_mat=" << cell_nb_mat <<
" env_id=" << ec.environmentId();
565 for (
Integer k = 0; k < cell_nb_mat; ++k) {
566 MatCell mc = ec.cell(k);
567 info() <<
"CELL4 mat_item=" << mc._varIndex() <<
" mat_id=" << mc.materialId();
577_checkConnectivityCoherency()
579 info() <<
"AllEnvData: checkCoherency()";
580 ConstArrayView<Int16> nb_mat_v2 = m_component_connectivity_list->cellsNbMaterial();
581 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
583 ItemGroup all_cells = m_material_mng->mesh()->allCells();
589 Int32 ref_nb_mat = 0;
590 for (MeshEnvironment* env : true_environments) {
591 Int16 env_id = env->componentId();
592 ref_nb_mat += m_component_connectivity_list->cellNbMaterial(icell, env_id);
594 Int32 current_nb_mat = nb_mat_v2[icell.itemLocalId()];
595 if (ref_nb_mat != current_nb_mat) {
598 error() <<
"Invalid values for nb_material cell=" << icell->uniqueId()
599 <<
" ref=" << ref_nb_mat <<
" current=" << current_nb_mat;
604 ARCANE_FATAL(
"Invalid values for component connectivity nb_error={0}", nb_error);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Types and macros to manage enumerations of entities on accelerators.
#define RUNCOMMAND_ENUMERATE(ItemTypeName, iter_name, item_group,...)
Macro to iterate over an accelerator on a group of entities.
Memory and allocator management functions.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
1D loop on accelerator with additional arguments.
Execution queue for an accelerator.
MemoryAllocationOptions allocationOptions() const
Allocation options associated with this queue.
Template class for converting a type.
virtual CellGroup allCells()=0
Group of all cells.
const String & name() const
Group name.
Integer size() const
Number of elements in the group.
IMesh * mesh() const
Mesh to which this group belongs (0 for the null group).
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
Cell globalCell() const
Global cell.
1D data vector with value semantics (STL style).
ItemGroupT< Cell > CellGroup
Group of cells.
ItemVectorViewT< Cell > CellVectorView
View over a vector of cells.
RunCommand makeCommand(const RunQueue &run_queue)
Creates a command associated with the queue run_queue.
RunQueue makeQueue(const Runner &runner)
Creates a queue associated with runner.
Always enables tracing in Arcane parts concerning materials.
Int32 checkResizeArrayWithCapacity(Array< DataType > &array, Int64 new_size, bool force_resize)
Resizes an array by adding a memory reserve.
bool arcaneIsCheck()
True if running in check mode.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
std::int16_t Int16
Signed integer type of 16 bits.
@ Cell
The mesh is AMR by cell.
std::int32_t Int32
Signed integer type of 32 bits.