14#include "arcane/materials/internal/LegacyMeshMaterialSynchronizerImpl.h"
16#include "arcane/VariableTypes.h"
17#include "arcane/IParallelMng.h"
18#include "arcane/ItemPrinter.h"
19#include "arcane/IMesh.h"
21#include "arcane/materials/CellToAllEnvCellConverter.h"
22#include "arcane/materials/MatItemEnumerator.h"
23#include "arcane/materials/MeshMaterialModifier.h"
25#include "arcane/core/ItemGenericInfoListView.h"
35LegacyMeshMaterialSynchronizerImpl::
36LegacyMeshMaterialSynchronizerImpl(IMeshMaterialMng* material_mng)
37: TraceAccessor(material_mng->traceMng())
38, m_material_mng(material_mng)
45LegacyMeshMaterialSynchronizerImpl::
46~LegacyMeshMaterialSynchronizerImpl()
53inline void LegacyMeshMaterialSynchronizerImpl::
54_setBit(ByteArrayView bytes, Integer position)
58 bytes[offset] |= (
Byte)(1 << bit);
61inline bool LegacyMeshMaterialSynchronizerImpl::
62_hasBit(ByteConstArrayView bytes, Integer position)
66 return bytes[offset] & (1 << bit);
72void LegacyMeshMaterialSynchronizerImpl::
73_fillPresence(AllEnvCell all_env_cell, ByteArrayView presence)
77 MatCell mc = *imatcell;
78 Integer mat_index = mc.materialId();
79 _setBit(presence, mat_index);
87bool LegacyMeshMaterialSynchronizerImpl::
88synchronizeMaterialsInCells()
105 IMesh* mesh = m_material_mng->mesh();
106 if (!mesh->parallelMng()->isParallel())
109 ConstArrayView<IMeshMaterial*> materials = m_material_mng->materials();
110 Integer nb_mat = materials.size();
112 Integer dim2_size = nb_mat / 8;
113 if ((nb_mat % 8) != 0)
115 mat_presence.resize(dim2_size);
116 info(4) <<
"Resize presence variable nb_mat=" << nb_mat <<
" dim2=" << dim2_size;
117 CellToAllEnvCellConverter cell_converter = m_material_mng->cellToAllEnvCellConverter();
121 AllEnvCell all_env_cell = cell_converter[*icell];
122 _fillPresence(all_env_cell, presence);
125 bool has_changed =
false;
127 mat_presence.synchronize();
130 UniqueArray<UniqueArray<Int32>> to_add(nb_mat);
131 UniqueArray<UniqueArray<Int32>> to_remove(nb_mat);
137 Int32 cell_lid = cell.localId();
138 AllEnvCell all_env_cell = cell_converter[cell];
139 before_presence.fill(0);
140 _fillPresence(all_env_cell, before_presence);
143 for (Integer imat = 0; imat < nb_mat; ++imat) {
144 bool has_before = _hasBit(before_presence, imat);
145 bool has_after = _hasBit(after_presence, imat);
146 if (has_before && !has_after) {
147 to_remove[imat].add(cell_lid);
149 else if (has_after && !has_before)
150 to_add[imat].add(cell_lid);
154 MeshMaterialModifier modifier(m_material_mng);
155 for (Integer i = 0; i < nb_mat; ++i) {
156 if (!to_add[i].empty()) {
157 modifier.addCells(materials[i], to_add[i]);
160 if (!to_remove[i].empty()) {
161 modifier.removeCells(materials[i], to_remove[i]);
void fill(const T &o) noexcept
Remplit le tableau avec la valeur o.
MeshVariableArrayRefT< Cell, Byte > VariableCellArrayByte
Grandeur au centre des mailles de type tableau d'octet.
Active toujours les traces dans les parties Arcane concernant les matériaux.
UniqueArray< Byte > ByteUniqueArray
Tableau dynamique à une dimension de caractères.
ConstArrayView< Byte > ByteConstArrayView
Equivalent C d'un tableau à une dimension de caractères.
ArrayView< Byte > ByteArrayView
Equivalent C d'un tableau à une dimension de caractères.
unsigned char Byte
Type d'un octet.
Int32 Integer
Type représentant un entier.