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/PlatformUtils.h"
20#include "arcane/utils/ArraySimdPadder.h"
22#include "arcane/core/IMesh.h"
23#include "arcane/core/IItemFamily.h"
24#include "arcane/core/VariableBuildInfo.h"
25#include "arcane/core/ItemGroupObserver.h"
26#include "arcane/core/internal/ItemGroupImplInternal.h"
27#include "arcane/core/materials/internal/IMeshMaterialVariableInternal.h"
28#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
30#include "arcane/materials/IMeshMaterialMng.h"
31#include "arcane/materials/MatItemEnumerator.h"
32#include "arcane/materials/ComponentItemVectorView.h"
33#include "arcane/materials/IMeshMaterialVariable.h"
34#include "arcane/materials/ComponentPartItemVectorView.h"
36#include "arcane/materials/internal/MeshEnvironment.h"
37#include "arcane/materials/internal/MeshMaterial.h"
38#include "arcane/materials/internal/ComponentItemListBuilder.h"
39#include "arcane/materials/internal/ComponentItemInternalData.h"
40#include "arcane/materials/internal/ConstituentConnectivityList.h"
41#include "arcane/materials/internal/ConstituentItemVectorImpl.h"
42#include "arcane/materials/internal/MeshComponentPartData.h"
44#include "arcane/accelerator/RunQueue.h"
46#include "arcane/accelerator/Scan.h"
75 if (m_environment->materialMng()->isInMeshMaterialExchange())
76 info() <<
"EXTEND_ENV_IN_LOADBALANCE " << m_environment->name()
77 <<
" ids=" << (*info1);
84 if (m_environment->materialMng()->isInMeshMaterialExchange())
85 info() <<
"REDUCE_ENV_IN_LOADBALANCE " << m_environment->name()
86 <<
" ids=" << (*info1);
91 info(4) <<
"COMPACT_ENV " << m_environment->name();
99 info() <<
"WARNING: invalidate() is invalid on an environment group! partial values may be corrupted"
100 <<
" env=" << m_environment->name();
106 MeshEnvironment* m_environment;
117: TraceAccessor(
mm->traceMng())
121, m_internal_api(
this)
131void MeshEnvironment::
134 IMesh* mesh = m_material_mng->mesh();
135 IItemFamily* cell_family = mesh->cellFamily();
136 String group_name = m_material_mng->name() +
"_" + name();
137 CellGroup cells = cell_family->findGroup(group_name,
true);
140 if (m_material_mng->isMeshModificationNotified()) {
141 m_group_observer =
new MeshEnvironmentObserver(
this, traceMng());
142 cells.internal()->attachObserver(
this, m_group_observer);
145 m_data._setItems(cells);
151void MeshEnvironment::
152addMaterial(MeshMaterial* mm)
155 m_true_materials.add(mm);
161void MeshEnvironment::
162setVariableIndexer(MeshMaterialVariableIndexer* idx)
164 m_data._setVariableIndexer(idx);
165 idx->setCells(m_data.items());
166 idx->setIsEnvironment(
true);
173 if (m_true_materials.size() == 1)
174 m_true_materials[0]->componentData()->_setItems(m_data.items());
175 m_data._buildPartData();
176 for (MeshMaterial* mat : m_true_materials)
177 mat->componentData()->_buildPartData();
183void MeshEnvironment::
186 info(4) <<
"ComputeNbMatPerCell env=" << name();
187 Integer nb_mat = m_materials.size();
189 for (Integer i = 0; i < nb_mat; ++i) {
190 IMeshMaterial* mat = m_materials[i];
192 total += mat_cells.
size();
194 m_total_nb_cell_mat = total;
206void MeshEnvironment::
207computeMaterialIndexes(ComponentItemInternalData* item_internal_data, RunQueue& queue)
209 info(4) <<
"Compute (V2) indexes for environment name=" << name();
210 const bool is_mono_mat = isMonoMaterial();
212 _computeMaterialIndexesMonoMat(item_internal_data, queue);
215 _computeMaterialIndexes(item_internal_data, queue);
221void MeshEnvironment::
222_computeMaterialIndexes(ComponentItemInternalData* item_internal_data, RunQueue& queue)
224 IItemFamily* cell_family = cells().itemFamily();
225 Integer max_local_id = cell_family->maxLocalId();
227 ComponentItemInternalRange mat_items_internal_range = m_mat_internal_data_range;
230 cells_index.resize(max_local_id);
232 cells_pos.resize(max_local_id);
237 cells_env.resize(max_local_id);
240 ConstituentItemLocalIdListView constituent_item_list_view = m_data.constituentItemListView();
241 const bool do_old =
false;
244 for (Integer z = 0, nb = local_ids.size(); z < nb; ++z) {
245 Int32 lid = local_ids[z];
246 matimpl::ConstituentItemBase env_item = constituent_item_list_view._constituenItemBase(z);
247 Int32 nb_mat = env_item.nbSubItem();
248 cells_index[lid] = cell_index;
249 cell_index += nb_mat;
254 Int32 nb_id = local_ids.size();
256 Accelerator::GenericScanner scanner(queue);
257 auto cells_index_view =
viewOut(queue, cells_index);
259 auto getter = [=] ARCCORE_HOST_DEVICE(
Int32 index) ->
Int32 {
260 return constituent_item_list_view._constituenItemBase(index).nbSubItem();
262 auto setter = [=] ARCCORE_HOST_DEVICE(
Int32 index,
Int32 value) {
263 Int32 lid = local_ids[index];
264 cells_index_view[lid] = value;
266 Accelerator::ScannerSumOperator<Int32> op;
267 scanner.applyWithIndexExclusive(nb_id, 0, getter, setter, op, A_FUNCINFO);
272 auto cells_env_view =
viewOut(command, cells_env);
273 auto cells_index_view =
viewIn(command, cells_index);
274 auto cells_pos_view =
viewOut(command, cells_pos);
275 Int32 nb_id = local_ids.size();
279 Int32 lid = local_ids[z];
280 matimpl::ConstituentItemBase env_item = constituent_item_list_view._constituenItemBase(z);
281 Int32 nb_mat = env_item.nbSubItem();
282 Int32 cell_index = cells_index_view[lid];
283 cells_pos_view[lid] = cell_index;
285 env_item._setFirstSubItem(mat_items_internal_range[cell_index]);
287 cells_env_view[lid] = env_item.constituentItemIndex();
291 Integer nb_mat = m_true_materials.size();
292 ComponentItemInternalRange mat_item_internal_range = m_mat_internal_data_range;
293 for (Integer i = 0; i < nb_mat; ++i) {
294 MeshMaterial* mat = m_true_materials[i];
295 Int16 mat_id = mat->componentId();
296 const MeshMaterialVariableIndexer* var_indexer = mat->variableIndexer();
298 info(4) <<
"COMPUTE (V2) mat_cells mat=" << mat->
name() <<
" nb_cell=" << mat_cells.size()
299 <<
" mat_id=" << mat_id <<
" index=" << var_indexer->index();
301 mat->resizeItemsInternal(var_indexer->nbItem());
304 auto matvar_indexes =
viewIn(command, var_indexer->matvarIndexes());
305 auto local_ids =
viewIn(command, var_indexer->localIds());
306 SmallSpan<Int32> cells_pos_view(cells_pos);
307 auto cells_env_view =
viewIn(command, cells_env);
308 ComponentItemSharedInfo* mat_shared_info = item_internal_data->matSharedInfo();
309 SmallSpan<ConstituentItemIndex> mat_id_list = mat->componentData()->m_constituent_local_id_list.mutableLocalIds();
310 const Int32 nb_id = local_ids.size();
311 Span<Int32> mat_cells_local_id = mat_cells._internalApi()->itemsLocalId();
315 MatVarIndex mvi = matvar_indexes[z];
316 Int32 lid = local_ids[z];
317 Int32 pos = cells_pos_view[lid];
318 ++cells_pos_view[lid];
319 ConstituentItemIndex cii = mat_item_internal_range[pos];
320 matimpl::ConstituentItemBase ref_ii(mat_shared_info, cii);
321 mat_id_list[z] = cii;
322 ref_ii._setSuperAndGlobalItem(cells_env_view[lid], ItemLocalId(lid));
323 ref_ii._setComponent(mat_id);
324 ref_ii._setVariableIndex(mvi);
327 ArraySimdPadder::applySimdPaddingView(mat_cells_local_id);
329 mat_cells._internalApi()->notifySimdPaddingDone();
341void MeshEnvironment::
342_computeMaterialIndexesMonoMat(ComponentItemInternalData* item_internal_data, RunQueue& queue)
344 ConstituentItemLocalIdListView constituent_item_list_view = m_data.constituentItemListView();
346 MeshMaterial* mat = m_true_materials[0];
347 const Int16 mat_id = mat->componentId();
348 const MeshMaterialVariableIndexer* var_indexer = mat->variableIndexer();
350 info(4) <<
"COMPUTE (V2) mat_cells mat=" << mat->
name() <<
" nb_cell=" << mat_cells.size()
351 <<
" mat_id=" << mat_id <<
" index=" << var_indexer->index();
353 mat->resizeItemsInternal(var_indexer->nbItem());
356 auto matvar_indexes =
viewIn(command, var_indexer->matvarIndexes());
357 auto local_ids =
viewIn(command, var_indexer->localIds());
358 ComponentItemSharedInfo* mat_shared_info = item_internal_data->matSharedInfo();
359 ComponentItemInternalRange mat_item_internal_range = m_mat_internal_data_range;
360 SmallSpan<ConstituentItemIndex> mat_id_list = mat->componentData()->m_constituent_local_id_list.mutableLocalIds();
361 const Int32 nb_id = local_ids.size();
362 Span<Int32> mat_cells_local_id = mat_cells._internalApi()->itemsLocalId();
366 MatVarIndex mvi = matvar_indexes[z];
367 const Int32 lid = local_ids[z];
369 matimpl::ConstituentItemBase env_item = constituent_item_list_view._constituenItemBase(z);
370 ConstituentItemIndex cii = mat_item_internal_range[pos];
371 env_item._setFirstSubItem(cii);
373 matimpl::ConstituentItemBase ref_ii(mat_shared_info, cii);
374 mat_id_list[z] = cii;
375 ref_ii._setSuperAndGlobalItem(env_item.constituentItemIndex(), ItemLocalId(lid));
376 ref_ii._setComponent(mat_id);
377 ref_ii._setVariableIndex(mvi);
380 ArraySimdPadder::applySimdPaddingView(mat_cells_local_id);
382 mat_cells._internalApi()->notifySimdPaddingDone();
391void MeshEnvironment::
392computeItemListForMaterials(
const ConstituentConnectivityList& connectivity_list)
394 info(4) <<
"ComputeItemListForMaterials (V2)";
395 ConstArrayView<Int16> nb_env_per_cell = connectivity_list.cellsNbEnvironment();
396 const Int16 env_id = componentId();
399 for (MeshMaterial* mat : m_true_materials) {
400 MeshMaterialVariableIndexer* var_indexer = mat->variableIndexer();
402 Integer var_nb_cell = cells.size();
404 ComponentItemListBuilderOld list_builder(var_indexer, 0);
406 info(4) <<
"MAT_INDEXER mat=" << mat->name() <<
" NB_CELL=" << var_nb_cell <<
" name=" << cells.name();
408 Int32 lid = icell.itemLocalId();
411 if (nb_env_per_cell[lid] > 1 || connectivity_list.cellNbMaterial(icell, env_id) > 1)
412 list_builder.addPartialItem(lid);
414 list_builder.addPureItem(lid);
417 if (traceMng()->verbosityLevel() >= 5)
418 info() <<
"MAT_NB_MULTIPLE_CELL (V2) mat=" << var_indexer->name()
419 <<
" nb_in_global=" << list_builder.pureMatVarIndexes().size()
420 <<
" (ids=" << list_builder.pureMatVarIndexes() <<
")"
421 <<
" nb_in_multiple=" << list_builder.partialMatVarIndexes().size()
422 <<
" (ids=" << list_builder.partialLocalIds() <<
")";
423 var_indexer->endUpdate(list_builder);
430void MeshEnvironment::
445 info(4) <<
"Changing (V3) local ids references env=" << name();
446 info(4) <<
"CurrentCells name=" << cells().name()
447 <<
" n=" << cells().view().localIds().size();
448 info(4) <<
"MatVarIndex name=" << cells().name()
449 <<
" n=" << variableIndexer()->matvarIndexes().size();
450 Integer nb_mat = m_true_materials.size();
451 info(4) <<
"NotifyLocalIdsChanged env=" << name() <<
" nb_mat=" << nb_mat
452 <<
" old_to_new_ids.size=" << old_to_new_ids.size();
464 m_data._changeLocalIdsForInternalList(old_to_new_ids);
465 MeshMaterial* true_mat = m_true_materials[0];
466 _changeIds(true_mat->componentData(), old_to_new_ids);
470 for (Integer i = 0; i < nb_mat; ++i) {
471 MeshMaterial* true_mat = m_true_materials[i];
472 info(4) <<
"ChangeIds MAT i=" << i <<
" MAT=" << true_mat->name();
473 _changeIds(true_mat->componentData(), old_to_new_ids);
476 _changeIds(componentData(), old_to_new_ids);
482 RunQueue& queue = m_material_mng->_internalApi()->runQueue();
483 for (Integer i = 0; i < nb_mat; ++i) {
484 MeshMaterial* true_mat = m_true_materials[i];
485 true_mat->componentData()->_rebuildPartData(queue);
487 componentData()->_rebuildPartData(queue);
496void MeshEnvironment::
499 info(4) <<
"ChangeIds() (V4) for name=" << cdata->name();
500 info(4) <<
"Use new version for ChangeIds()";
502 cdata->_changeLocalIdsForInternalList(old_to_new_ids);
503 cdata->variableIndexer()->changeLocalIds(old_to_new_ids);
509EnvCell MeshEnvironment::
510findEnvCell(AllEnvCell c)
const
512 Int32 env_id = m_data.componentId();
514 EnvCell ec = *ienvcell;
515 Int32 eid = ec.environmentId();
525ComponentCell MeshEnvironment::
526findComponentCell(AllEnvCell c)
const
528 return findEnvCell(c);
534EnvItemVectorView MeshEnvironment::
537 return { m_non_const_this, variableIndexer()->matvarIndexes(),
538 constituentItemListView(), variableIndexer()->localIds() };
544ComponentItemVectorView MeshEnvironment::
553void MeshEnvironment::
554resizeItemsInternal(Integer nb_item)
556 m_data._resizeItemsInternal(nb_item);
562ComponentPurePartItemVectorView MeshEnvironment::
565 return m_data._partData()->pureView();
571ComponentImpurePartItemVectorView MeshEnvironment::
574 return m_data._partData()->impureView();
580ComponentPartItemVectorView MeshEnvironment::
583 return m_data._partData()->partView(part);
589EnvPurePartItemVectorView MeshEnvironment::
592 return { m_non_const_this, m_data._partData()->pureView() };
598EnvImpurePartItemVectorView MeshEnvironment::
599impureEnvItems()
const
601 return { m_non_const_this, m_data._partData()->impureView() };
607EnvPartItemVectorView MeshEnvironment::
610 return { m_non_const_this, m_data._partData()->partView(part) };
616void MeshEnvironment::
624 for (IMeshMaterial* mat : m_materials) {
632bool MeshEnvironment::
633isMonoMaterial()
const
635 bool is_mono_mat = (nbMaterial() == 1 && (cells().size() == totalNbCellMat()));
642Int32 MeshEnvironment::InternalApi::
643variableIndexerIndex()
const
645 return variableIndexer()->index();
651Ref<IConstituentItemVectorImpl> MeshEnvironment::InternalApi::
652createItemVectorImpl()
const
654 auto* x =
new ConstituentItemVectorImpl(m_environment->m_non_const_this);
655 return makeRef<IConstituentItemVectorImpl>(x);
661Ref<IConstituentItemVectorImpl> MeshEnvironment::InternalApi::
662createItemVectorImpl(ComponentItemVectorView rhs)
const
664 auto* x =
new ConstituentItemVectorImpl(rhs);
665 return makeRef<IConstituentItemVectorImpl>(x);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions de gestion mémoire et des allocateurs.
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.
const String & name() const
Nom du groupe.
Integer size() const
Nombre d'éléments du groupe.
ItemGroupImplInternal * _internalApi() const
API interne à Arcane.
Interface du gestionnaire des matériaux et des milieux d'un maillage.
bool needInfo() const override
Indique si l'observer aura besoin d'information de transition.
void executeReduce(const Int32ConstArrayView *info1) override
Execute l'action associée à l'extension.
void executeInvalidate() override
Execute l'action associée à l'invalidation.
void executeExtend(const Int32ConstArrayView *info1) override
Execute l'action associée à l'extension.
void executeCompact(const Int32ConstArrayView *info1) override
Execute l'action associée au compactage.
Vue constante d'un tableau de type T.
Interface du gestionnaire de traces.
Référence à une instance.
Chaîne de caractères unicode.
ItemGroupT< Cell > CellGroup
Groupe de mailles.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
Active toujours les traces dans les parties Arcane concernant les matériaux.
eMatPart
Partie d'un composant.
auto viewOut(MeshVariableScalarRefT< ItemType, DataType > &var)
Vue en écriture.
bool arcaneIsCheck()
Vrai si on est en mode vérification.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
auto viewIn(const MeshVariableScalarRefT< ItemType, DataType > &var)
Vue en lecture.
Int32 Integer
Type représentant un entier.