14#include "arcane/materials/internal/MaterialModifierOperation.h"
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/FatalErrorException.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()
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);
71Int32 MaterialModifierOperation::
72_checkMaterialPresence(MaterialModifierOperation* operation)
74 IMeshMaterial* mat = operation->material();
75 SmallSpan<const Int32> ids = operation->ids();
77 const MeshMaterialVariableIndexer* indexer = mat->_internalApi()->variableIndexer();
78 IItemFamily* item_family = mat->cells().itemFamily();
79 ItemInfoListView items_internal(item_family);
80 Integer max_local_id = item_family->maxLocalId();
81 UniqueArray<bool> presence_flags(max_local_id,
false);
82 SmallSpan<const Int32> mat_local_ids = indexer->localIds();
84 String name = mat->name();
85 ITraceMng* tm = mat->traceMng();
87 for (Int32 lid : ids) {
88 if (presence_flags[lid]) {
89 tm->info() <<
"ERROR: item " << ItemPrinter(items_internal[lid])
90 <<
" is present several times in add/remove list for material mat=" << name;
93 presence_flags[lid] =
true;
96 if (operation->isAdd()) {
97 for (Int32 lid : mat_local_ids) {
98 if (presence_flags[lid]) {
99 tm->info() <<
"ERROR: item " << ItemPrinter(items_internal[lid])
100 <<
" is already in material mat=" << name;
106 for (Int32 lid : mat_local_ids) {
107 presence_flags[lid] =
false;
110 for (Int32 lid : ids) {
111 if (presence_flags[lid]) {
112 tm->info() <<
"ERROR: item " << ItemPrinter(items_internal[lid])
113 <<
" is not in material mat=" << name;
135void MaterialModifierOperation::
136_filterValidIds(MaterialModifierOperation* operation, Int32Array& valid_ids)
138 IMeshMaterial* mat = operation->material();
139 const bool do_add = operation->isAdd();
140 SmallSpan<const Int32> ids = operation->ids();
141 const MeshMaterialVariableIndexer* indexer = mat->_internalApi()->variableIndexer();
142 const IItemFamily* item_family = mat->cells().itemFamily();
143 Integer max_local_id = item_family->maxLocalId();
144 UniqueArray<bool> presence_flags(max_local_id,
false);
145 SmallSpan<const Int32> mat_local_ids = indexer->localIds();
146 ITraceMng* tm = mat->traceMng();
148 UniqueArray<Int32> unique_occurence_lids;
149 unique_occurence_lids.reserve(ids.size());
151 for (Int32 lid : ids) {
152 if (!presence_flags[lid]) {
153 unique_occurence_lids.add(lid);
154 presence_flags[lid] =
true;
161 for (Int32 lid : mat_local_ids) {
162 if (presence_flags[lid]) {
170 for (Int32 lid : mat_local_ids)
171 presence_flags[lid] =
false;
173 for (Int32 lid : unique_occurence_lids) {
174 if (presence_flags[lid]) {
181 tm->info(4) <<
"FILTERED_IDS n=" << valid_ids.size() <<
" ids=" << valid_ids;
187void MaterialModifierOperation::
191 const bool filter_invalid =
true;
192 Integer nb_error = _checkMaterialPresence(
this);
194 if (filter_invalid) {
195 UniqueArray<Int32> filtered_ids;
196 _filterValidIds(
this, filtered_ids);
197 m_ids.swap(filtered_ids);
200 ARCANE_FATAL(
"Invalid values for adding items in material name={0} nb_error={1}",
201 m_mat->name(), nb_error);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Memory and allocator management functions.
Always enables tracing in Arcane parts concerning materials.
Int32 Integer
Type representing an integer.