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)
78, m_item_internal_data(mmg)
83 m_component_connectivity_list_ref = m_component_connectivity_list->toSourceReference();
98 m_item_internal_data.endCreate();
99 m_component_connectivity_list->endCreate(is_continue);
106_isFullVerbose()
const
115_computeNbEnvAndNbMatPerCell()
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);
192 auto clist = m_component_connectivity_list;
193 clist->removeAllConnectivities();
195 clist->addCellsToEnvironment(env->componentId(), env->cells().view().localIds(), queue);
197 clist->addCellsToMaterial(mat->componentId(), mat->cells().view().localIds(), queue);
205_rebuildMaterialsAndEnvironmentsFromGroups()
208 const bool is_full_verbose = _isFullVerbose();
215 info(4) <<
"ENV_INDEXER (V2) i=" << var_indexer->index() <<
" NB_CELL=" << var_nb_cell <<
" name=" << cells.
name()
216 <<
" index=" << var_indexer->index();
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() <<
")";
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]));
317 RunQueue queue(m_material_mng->runQueue());
324 const Int16 env_id = env->componentId();
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()
338 const bool is_mono_mat = env->isMonoMaterial();
340 work_info.cells_nb_material.
resize(max_local_id);
345 m_component_connectivity_list->fillCellsNbMaterial(local_ids, env_id, cells_nb_mat_view, queue);
349 const Int32 nb_id = matvar_indexes.
size();
350 ComponentItemSharedInfo* env_shared_info = m_item_internal_data.envSharedInfo();
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];
367 env_id_list[z] = cii_pos;
369 ref_ii._setSuperAndGlobalItem(cii_lid,
ItemLocalId(lid));
372 ref_ii._setComponent(env_id);
375 ArraySimdPadder::applySimdPaddingView(env_cells_local_id);
384 env->computeMaterialIndexes(&m_item_internal_data, queue_pool[env->id()]);
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);
436 m_material_mng->incrementTimestamp();
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;
459 if (compute_all || has_mesh_changed)
460 _computeNbEnvAndNbMatPerCell();
462 _computeAndResizeEnvItemsInternal();
464 bool is_full_verbose = _isFullVerbose();
467 _rebuildMaterialsAndEnvironmentsFromGroups();
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);
492 if (is_verbose_debug) {
493 _printAllEnvCells(m_material_mng->mesh()->allCells().view());
494 for (
IMeshMaterial* material : m_material_mng->materials()) {
504 env->componentData()->_rebuildPartData(queue);
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();
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()
544 _checkConnectivityCoherency();
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) {
563 Integer cell_nb_mat = ec.nbMaterial();
565 for (
Integer k = 0; k < cell_nb_mat; ++k) {
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.
void barrier() const
Forces waiting for all RunQueues.
Execution queue for an accelerator.
MemoryAllocationOptions allocationOptions() const
Allocation options associated with this queue.
void resize(Int64 s)
Changes the number of elements in the array to s.
ArrayView< T > view() const
Mutable view of this array.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Template class for converting a type.
Interface of an entity family.
virtual Int32 maxLocalId() const =0
virtual CellGroup allCells()=0
Group of all cells.
void notifySimdPaddingDone()
Indicates that the SIMD padding of the entities has been performed.
SmallSpan< Int32 > itemsLocalId()
List of localId() of the group's entities.
const String & name() const
Group name.
ItemVectorView view() const
View of the group entities.
Integer size() const
Number of elements in the group.
ItemGroupImplInternal * _internalApi() const
Internal Arcane API.
IMesh * mesh() const
Mesh to which this group belongs (0 for the null group).
Index of an Item in a variable.
Utility class for printing information about an entity.
Int32ConstArrayView localIds() const
Array of local IDs of entities.
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
Arcane cell with material and environment information.
__host__ __device__ Int32 nbEnvironment() const
Number of environments present in the cell.
EnvCell cell(Int32 i) const
i-th environment cell
void _checkLocalIdsCoherency() const
Checks the coherence of variableIndexer().localIds() with the global cell associated with the environ...
Int32 m_verbose_debug_level
Verbosity level.
void _rebuildIncrementalConnectivitiesFromGroups()
Rebuilds the incremental connectivities for groups.
void endCreate(bool is_continue)
Notification of the end of environment/material creation.
void forceRecompute(bool compute_all)
Updates structures following a modification of material or environment cells.
void _computeInfosForEnvCells(RecomputeConstituentCellInfos &work_info)
Positions the info for EnvCells.
Helper class for building a list of ComponentItems for a MeshMaterialVariableIndexer.
Management of constituent connectivity lists.
Index of a constituent entity in the list of constituent entities.
Cell globalCell() const
Global cell.
__host__ __device__ MatVarIndex _varIndex() const
Arcane cell of an environment.
__host__ __device__ MatCell cell(Integer i) const
i-th material cell of this cell
__host__ __device__ Int32 environmentId() const
Environment identifier.
Interface of a mesh material.
Represents a material in a multi-material cell.
__host__ __device__ Int32 materialId() const
Material identifier.
Represents an index on material and environment variables.
Implementation of a material manager.
AllEnvCellVectorView view(const CellGroup &cells) final
View of environment cells corresponding to the group cells.
Indexer for material variables.
void endUpdate(const ComponentItemListBuilderOld &builder)
Private functions but accessible to 'friend' classes.
Integer maxIndexInMultipleArray() const
const String & name() const
Name of the indexer.
General information about a constituent entity.
__host__ __device__ void _setVariableIndex(MatVarIndex index)
Positions the indexer in material variables.
__host__ __device__ void _setNbSubItem(Int16 nb_sub_item)
Positions the number of sub-components.
Output stream linked to a String.
View of an array of elements of type T.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
View of an array of elements of type T.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessage info() const
Flow for an information message.
TraceMessage error() const
Flow for an error message.
ITraceMng * traceMng() const
Trace manager.
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.