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"
36MeshMaterialSynchronizer::
37MeshMaterialSynchronizer(IMeshMaterialMng* material_mng)
38: TraceAccessor(material_mng->traceMng())
39, m_material_mng(material_mng)
41 if (Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_ACC_MAT_SYNCHRONIZER",
true)) {
42 m_synchronizer =
new AcceleratorMeshMaterialSynchronizerImpl(material_mng);
43 info() <<
"using ACC material synchronizer";
46 m_synchronizer =
new LegacyMeshMaterialSynchronizerImpl(material_mng);
47 info() <<
"using DEFAULT material synchronizer";
54MeshMaterialSynchronizer::
55~MeshMaterialSynchronizer()
57 delete m_synchronizer;
63bool MeshMaterialSynchronizer::
64synchronizeMaterialsInCells()
66 return m_synchronizer->synchronizeMaterialsInCells();
76void MeshMaterialSynchronizer::
77checkMaterialsInCells(Integer max_print)
90 IMesh* mesh = m_material_mng->mesh();
91 if (!mesh->parallelMng()->isParallel())
93 m_material_mng->checkValid();
95 info(4) <<
"CheckMaterialsInCells";
97 VariableCellInt32 indexes(VariableBuildInfo(mesh,
"ArcaneMaterialPresenceIndexes"));
98 _checkComponents(indexes, m_material_mng->materialsAsComponents(), max_print);
99 _checkComponents(indexes, m_material_mng->environmentsAsComponents(), max_print);
102 _checkComponentsInGhostCells(hashes, max_print);
108void MeshMaterialSynchronizer::
109_checkComponents(VariableCellInt32& indexes,
110 ConstArrayView<IMeshComponent*> components,
113 IMesh* mesh = m_material_mng->mesh();
114 Integer nb_component = components.size();
117 info() <<
"Checking components nb=" << nb_component;
119 CellToAllEnvCellConverter all_env_cell_converter(m_material_mng);
121 for( Integer i=0; i<nb_component; ++i ){
123 IMeshComponent* c = components[i];
125 ComponentCell cc = *iccell;
126 indexes[cc.globalCell()] = i;
129 indexes.synchronize();
132 AllEnvCell all_env_cell = *iallenvcell;
133 Cell cell = all_env_cell.globalCell();
134 bool has_sync_mat = (indexes[cell]==i);
135 ComponentCell cc = c->findComponentCell(all_env_cell);
136 bool has_component = !cc.
null();
137 if (has_sync_mat!=has_component){
139 if (max_print<0 || nb_error<max_print)
140 error() <<
"Bad component synchronisation for i=" << i
141 <<
" name=" << c->name()
142 <<
" cell_uid=" << cell.uniqueId()
143 <<
" sync_mat=" << has_sync_mat
144 <<
" has_component=" << has_component;
152void MeshMaterialSynchronizer::
153_checkComponentsInGhostCells(VariableCellInt64& hashes, Integer max_print)
155 IMesh* mesh = m_material_mng->mesh();
159 AllEnvCell all_env_cell = *iallenvcell;
160 Cell cell = all_env_cell.globalCell();
162 IntegerHashSuite hash_suite;
164 Int32 nb_env = all_env_cell.nbEnvironment();
165 hash_suite.add(nb_env);
167 for (Integer i = 0; i < nb_env; ++i) {
168 EnvCell env_cell = all_env_cell.cell(i);
169 Int32 nb_matt = env_cell.nbMaterial();
170 hash_suite.add(nb_matt);
172 for (Integer j = 0; j < nb_matt; ++j) {
173 MatCell mat = env_cell.cell(j);
174 Int32 id = mat.materialId();
179 hashes[cell] = hash_suite.hash();
182 hashes.synchronize();
185 AllEnvCell all_env_cell = *iallenvcell;
186 Cell cell = all_env_cell.globalCell();
190 IntegerHashSuite hash_suite;
192 Int32 nb_env = all_env_cell.nbEnvironment();
193 hash_suite.add(nb_env);
195 for (Integer i = 0; i < nb_env; ++i) {
196 EnvCell env_cell = all_env_cell.cell(i);
197 Int32 nb_matt = env_cell.nbMaterial();
198 hash_suite.add(nb_matt);
200 for (Integer j = 0; j < nb_matt; ++j) {
201 MatCell mat = env_cell.cell(j);
202 Int32 id = mat.materialId();
206 if (hashes[cell] != hash_suite.hash()) {
208 if (max_print < 0 || nb_error < max_print) {
209 error() <<
"Bad components synchronization -- Cell : " << cell <<
" -- Hash : " << hash_suite.hash();
214 ARCANE_FATAL(
"Bad components synchronization -- Nb error : {0}", nb_error);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
__host__ __device__ bool null() const
Indique s'il s'agit de la maille nulle.
Référence à une instance.
MeshVariableScalarRefT< Cell, Int64 > VariableCellInt64
Grandeur au centre des mailles de type entier 64 bits.
MeshVariableScalarRefT< Cell, Int32 > VariableCellInt32
Grandeur au centre des mailles de type entier 32 bits.
Active toujours les traces dans les parties Arcane concernant les matériaux.
Int32 Integer
Type représentant un entier.