14#include "arcane/materials/internal/LegacyMeshMaterialSynchronizerImpl.h"
16#include "arcane/core/VariableTypes.h"
17#include "arcane/core/IParallelMng.h"
18#include "arcane/core/ItemPrinter.h"
19#include "arcane/core/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::
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()
104 IMesh* mesh = m_material_mng->mesh();
105 if (!mesh->parallelMng()->isParallel())
108 ConstArrayView<IMeshMaterial*> materials = m_material_mng->materials();
109 Integer nb_mat = materials.size();
111 Integer dim2_size = nb_mat / 8;
112 if ((nb_mat % 8) != 0)
114 mat_presence.resize(dim2_size);
115 info(4) <<
"Resize presence variable nb_mat=" << nb_mat <<
" dim2=" << dim2_size;
116 CellToAllEnvCellConverter cell_converter = m_material_mng->cellToAllEnvCellConverter();
120 AllEnvCell all_env_cell = cell_converter[*icell];
121 _fillPresence(all_env_cell, presence);
124 bool has_changed =
false;
126 mat_presence.synchronize();
129 UniqueArray<UniqueArray<Int32>> to_add(nb_mat);
130 UniqueArray<UniqueArray<Int32>> to_remove(nb_mat);
136 Int32 cell_lid = cell.localId();
137 AllEnvCell all_env_cell = cell_converter[cell];
138 before_presence.fill(0);
139 _fillPresence(all_env_cell, before_presence);
142 for (Integer imat = 0; imat < nb_mat; ++imat) {
143 bool has_before = _hasBit(before_presence, imat);
144 bool has_after = _hasBit(after_presence, imat);
145 if (has_before && !has_after) {
146 to_remove[imat].add(cell_lid);
148 else if (has_after && !has_before)
149 to_add[imat].add(cell_lid);
153 MeshMaterialModifier modifier(m_material_mng);
154 for (Integer i = 0; i < nb_mat; ++i) {
155 if (!to_add[i].empty()) {
156 modifier.addCells(materials[i], to_add[i]);
159 if (!to_remove[i].empty()) {
160 modifier.removeCells(materials[i], to_remove[i]);
void fill(const T &o) noexcept
Fills the array with the value o.
Interface for the material and environment manager of a mesh.
MeshVariableArrayRefT< Cell, Byte > VariableCellArrayByte
Quantity at cell centers of byte array type.
Always enables tracing in Arcane parts concerning materials.
ArrayView< Byte > ByteArrayView
C equivalent of a 1D array of characters.
Int32 Integer
Type representing an integer.
UniqueArray< Byte > ByteUniqueArray
Dynamic 1D array of characters.
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
unsigned char Byte
Type of a byte.
@ Cell
The mesh is AMR by cell.