14#include "arcane/materials/internal/MaterialModifierOperation.h"
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/MemoryUtils.h"
19#include "arcane/utils/IMemoryRessourceMng.h"
21#include "arcane/core/ItemPrinter.h"
22#include "arcane/core/ItemGroup.h"
23#include "arcane/core/IItemFamily.h"
24#include "arcane/core/materials/IMeshMaterial.h"
25#include "arcane/core/materials/internal/IMeshComponentInternal.h"
27#include "arcane/materials/internal/MeshMaterialVariableIndexer.h"
38MaterialModifierOperation::
39MaterialModifierOperation()
40: m_ids(MemoryUtils::getDefaultDataAllocator())
47MaterialModifierOperation::
48MaterialModifierOperation(IMeshMaterial* mat, SmallSpan<const Int32> ids,
bool is_add)
49: MaterialModifierOperation()
53 m_ids.resize(ids.size());
54 MemoryUtils::copy<Int32>(m_ids, ids);
70Int32 MaterialModifierOperation::
71_checkMaterialPresence(MaterialModifierOperation* operation)
73 IMeshMaterial* mat = operation->material();
74 SmallSpan<const Int32> ids = operation->ids();
76 const MeshMaterialVariableIndexer* indexer = mat->_internalApi()->variableIndexer();
77 IItemFamily* item_family = mat->cells().itemFamily();
78 ItemInfoListView items_internal(item_family);
79 Integer max_local_id = item_family->maxLocalId();
80 UniqueArray<bool> presence_flags(max_local_id,
false);
81 SmallSpan<const Int32> mat_local_ids = indexer->localIds();
83 String name = mat->name();
84 ITraceMng* tm = mat->traceMng();
86 for (Int32 lid : ids) {
87 if (presence_flags[lid]) {
88 tm->info() <<
"ERROR: item " << ItemPrinter(items_internal[lid])
89 <<
" is present several times in add/remove list for material mat=" << name;
92 presence_flags[lid] =
true;
95 if (operation->isAdd()) {
96 for (Int32 lid : mat_local_ids) {
97 if (presence_flags[lid]) {
98 tm->info() <<
"ERROR: item " << ItemPrinter(items_internal[lid])
99 <<
" is already in material mat=" << name;
105 for (Int32 lid : mat_local_ids) {
106 presence_flags[lid] =
false;
109 for (Int32 lid : ids) {
110 if (presence_flags[lid]) {
111 tm->info() <<
"ERROR: item " << ItemPrinter(items_internal[lid])
112 <<
" is not in material mat=" << name;
133void MaterialModifierOperation::
134_filterValidIds(MaterialModifierOperation* operation, Int32Array& valid_ids)
136 IMeshMaterial* mat = operation->material();
137 const bool do_add = operation->isAdd();
138 SmallSpan<const Int32> ids = operation->ids();
139 const MeshMaterialVariableIndexer* indexer = mat->_internalApi()->variableIndexer();
140 const IItemFamily* item_family = mat->cells().itemFamily();
141 Integer max_local_id = item_family->maxLocalId();
142 UniqueArray<bool> presence_flags(max_local_id,
false);
143 SmallSpan<const Int32> mat_local_ids = indexer->localIds();
144 ITraceMng* tm = mat->traceMng();
146 UniqueArray<Int32> unique_occurence_lids;
147 unique_occurence_lids.reserve(ids.size());
149 for (Int32 lid : ids) {
150 if (!presence_flags[lid]) {
151 unique_occurence_lids.add(lid);
152 presence_flags[lid] =
true;
159 for (Int32 lid : mat_local_ids) {
160 if (presence_flags[lid]) {
168 for (Int32 lid : mat_local_ids)
169 presence_flags[lid] = false;
171 for (Int32 lid : unique_occurence_lids) {
172 if (presence_flags[lid]) {
179 tm->info(4) <<
"FILTERED_IDS n=" << valid_ids.size() <<
" ids=" << valid_ids;
185void MaterialModifierOperation::
189 const bool filter_invalid =
true;
190 Integer nb_error = _checkMaterialPresence(
this);
192 if (filter_invalid) {
193 UniqueArray<Int32> filtered_ids;
194 _filterValidIds(
this, filtered_ids);
195 m_ids.swap(filtered_ids);
198 ARCANE_FATAL(
"Invalid values for adding items in material name={0} nb_error={1}",
199 m_mat->name(), nb_error);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Active toujours les traces dans les parties Arcane concernant les matériaux.
Int32 Integer
Type représentant un entier.