14#include "arcane/materials/internal/MeshMaterialSynchronizer.h"
16#include "arcane/materials/CellToAllEnvCellConverter.h"
17#include "arcane/materials/MatItemEnumerator.h"
18#include "arcane/materials/MeshMaterialModifier.h"
20#include "arcane/utils/HashSuite.h"
22#include "arcane/core/VariableTypes.h"
23#include "arcane/core/IParallelMng.h"
24#include "arcane/core/ItemPrinter.h"
25#include "arcane/core/IMesh.h"
26#include "arcane/core/ItemGenericInfoListView.h"
37MeshMaterialSynchronizer::
39: TraceAccessor(material_mng->traceMng())
40, m_material_mng(material_mng)
42 if (Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_ACC_MAT_SYNCHRONIZER",
true)) {
43 m_synchronizer =
new AcceleratorMeshMaterialSynchronizerImpl(material_mng);
44 info() <<
"using ACC material synchronizer";
47 m_synchronizer =
new LegacyMeshMaterialSynchronizerImpl(material_mng);
48 info() <<
"using DEFAULT material synchronizer";
55MeshMaterialSynchronizer::
56~MeshMaterialSynchronizer()
58 delete m_synchronizer;
64bool MeshMaterialSynchronizer::
65synchronizeMaterialsInCells()
67 return m_synchronizer->synchronizeMaterialsInCells();
77void MeshMaterialSynchronizer::
78checkMaterialsInCells(
Integer max_print)
92 if (!
mesh->parallelMng()->isParallel())
94 m_material_mng->checkValid();
96 info(4) <<
"CheckMaterialsInCells";
99 _checkComponents(indexes, m_material_mng->materialsAsComponents(), max_print);
100 _checkComponents(indexes, m_material_mng->environmentsAsComponents(), max_print);
103 _checkComponentsInGhostCells(hashes, max_print);
109void MeshMaterialSynchronizer::
118 info() <<
"Checking components nb=" << nb_component;
122 for (
Integer i = 0; i < nb_component; ++i) {
126 ComponentCell cc = *iccell;
130 indexes.synchronize();
135 bool has_sync_mat = (indexes[cell] == i);
137 bool has_component = !cc.
null();
138 if (has_sync_mat != has_component) {
140 if (max_print < 0 || nb_error < max_print)
141 error() <<
"Bad component synchronisation for i=" << i
142 <<
" name=" << c->
name()
144 <<
" sync_mat=" << has_sync_mat
145 <<
" has_component=" << has_component;
153void MeshMaterialSynchronizer::
154_checkComponentsInGhostCells(VariableCellInt64& hashes, Integer max_print)
156 IMesh* mesh = m_material_mng->mesh();
160 AllEnvCell all_env_cell = *iallenvcell;
161 Cell cell = all_env_cell.globalCell();
163 IntegerHashSuite hash_suite;
165 Int32 nb_env = all_env_cell.nbEnvironment();
166 hash_suite.add(nb_env);
168 for (Integer i = 0; i < nb_env; ++i) {
169 EnvCell env_cell = all_env_cell.cell(i);
170 Int32 nb_matt = env_cell.nbMaterial();
171 hash_suite.add(nb_matt);
173 for (Integer j = 0; j < nb_matt; ++j) {
174 MatCell mat = env_cell.cell(j);
175 Int32
id = mat.materialId();
180 hashes[cell] = hash_suite.hash();
183 hashes.synchronize();
186 AllEnvCell all_env_cell = *iallenvcell;
187 Cell cell = all_env_cell.globalCell();
191 IntegerHashSuite hash_suite;
193 Int32 nb_env = all_env_cell.nbEnvironment();
194 hash_suite.add(nb_env);
196 for (Integer i = 0; i < nb_env; ++i) {
197 EnvCell env_cell = all_env_cell.cell(i);
198 Int32 nb_matt = env_cell.nbMaterial();
199 hash_suite.add(nb_matt);
201 for (Integer j = 0; j < nb_matt; ++j) {
202 MatCell mat = env_cell.cell(j);
203 Int32
id = mat.materialId();
207 if (hashes[cell] != hash_suite.hash()) {
209 if (max_print < 0 || nb_error < max_print) {
210 error() <<
"Bad components synchronization -- Cell : " << cell <<
" -- Hash : " << hash_suite.hash();
215 ARCANE_FATAL(
"Bad components synchronization -- Nb error : {0}", nb_error);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
ItemUniqueId uniqueId() const
Unique identifier across all domains.
Arcane cell with material and environment information.
Conversion of 'Cell' to 'AllEnvCell'.
__host__ __device__ bool null() const
Indicates if it is the null cell.
Cell globalCell() const
Global cell.
Interface of a component (material or environment) of a mesh.
virtual String name() const =0
Component name.
virtual ComponentCell findComponentCell(AllEnvCell c) const =0
Cell of this component for cell c.
Interface for the material and environment manager of a mesh.
TraceMessage info() const
Flow for an information message.
Parameters necessary for building a variable.
MeshVariableScalarRefT< Cell, Int64 > VariableCellInt64
Quantity at the cell center of 64-bit integer type.
MeshVariableScalarRefT< Cell, Int32 > VariableCellInt32
Quantity at the cell center of 32-bit integer type.
Always enables tracing in Arcane parts concerning materials.
Int32 Integer
Type representing an integer.
@ Cell
The mesh is AMR by cell.