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()
105 if (!
mesh->parallelMng()->isParallel())
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;
120 AllEnvCell all_env_cell = cell_converter[*icell];
121 _fillPresence(all_env_cell, presence);
124 bool has_changed =
false;
126 mat_presence.synchronize();
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);
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()) {
void fill(const T &o) noexcept
Fills the array with the value o.
void fill(ConstReferenceType value)
Fills the array with the value value.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
constexpr bool isOwn() const
true if the entity belongs to the subdomain
Arcane cell with material and environment information.
Conversion of 'Cell' to 'AllEnvCell'.
Interface for the material and environment manager of a mesh.
Object allowing modification of materials or media.
void addCells(IMeshMaterial *mat, SmallSpan< const Int32 > ids)
Adds the cells with local indices ids to the material mat.
void removeCells(IMeshMaterial *mat, SmallSpan< const Int32 > ids)
Removes the cells with local indices ids from the material mat.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
Parameters necessary for building a variable.
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.
std::int32_t Int32
Signed integer type of 32 bits.