14#include "arcane/tests/MeshMaterialTesterModule.h"
16#include "arcane/utils/ValueChecker.h"
18#include "arcane/core/IMesh.h"
19#include "arcane/core/IItemFamily.h"
20#include "arcane/core/ITimeLoopMng.h"
21#include "arcane/core/ITimeLoop.h"
22#include "arcane/core/IParallelMng.h"
23#include "arcane/core/TimeLoopEntryPointInfo.h"
24#include "arcane/core/ItemPrinter.h"
25#include "arcane/core/materials/IMeshBlock.h"
27#include "arcane/materials/MeshBlockBuildInfo.h"
28#include "arcane/materials/MeshEnvironmentBuildInfo.h"
29#include "arcane/materials/MeshMaterialInfo.h"
30#include "arcane/materials/MeshMaterialModifier.h"
31#include "arcane/core/materials/CellToAllEnvCellConverter.h"
43MeshMaterialTesterModule::
45: ArcaneMeshMaterialTesterObject(mbi)
61MeshMaterialTesterModule::
62~MeshMaterialTesterModule()
64 for (VariableCellReal* v : m_density_post_processing)
71void MeshMaterialTesterModule::
72staticInitialize(ISubDomain* sd)
74 String time_loop_name(
"MeshMaterialTestLoop");
76 ITimeLoopMng* tlm = sd->timeLoopMng();
77 ITimeLoop* time_loop = tlm->createTimeLoop(time_loop_name);
80 List<TimeLoopEntryPointInfo> clist;
81 clist.add(TimeLoopEntryPointInfo(
"MeshMaterialTester.buildInit"));
82 time_loop->setEntryPoints(ITimeLoop::WBuild, clist);
86 List<TimeLoopEntryPointInfo> clist;
87 clist.add(TimeLoopEntryPointInfo(
"MeshMaterialTester.startInit"));
88 clist.add(TimeLoopEntryPointInfo(
"MeshMaterialTester.continueInit"));
89 time_loop->setEntryPoints(ITimeLoop::WInit, clist);
93 List<TimeLoopEntryPointInfo> clist;
94 clist.add(TimeLoopEntryPointInfo(
"MeshMaterialTester.compute"));
95 time_loop->setEntryPoints(ITimeLoop::WComputeLoop, clist);
100 clist.add(
"MeshMaterialTester");
101 time_loop->setRequiredModulesName(clist);
103 clist.add(
"ArcanePostProcessing");
104 clist.add(
"ArcaneCheckpoint");
105 time_loop->setOptionalModulesName(clist);
108 tlm->registerTimeLoop(time_loop);
114void MeshMaterialTesterModule::
120 info() <<
"MESH_MATERIAL_TESTER :: buildInit()";
122 Materials::IMeshMaterialMng* mm = IMeshMaterialMng::getReference(defaultMesh());
124 m_material_mng->setModificationFlags(options()->modificationFlags());
126 m_material_mng->setMeshModificationNotified(
true);
129 if (parallelMng()->isParallel())
130 m_material_mng->setAllocateScalarEnvironmentVariableAsMaterial(
true);
132 if (subDomain()->isContinue() && options()->recreateFromDump()) {
133 mm->recreateFromDump();
136 UniqueArray<MeshMaterialInfo*> materials_info;
138 for (Integer i = 0, n = options()->material().size(); i < n; ++i) {
139 String mat_name = options()->material[i].name;
140 info() <<
"Found material name=" << mat_name;
141 materials_info.add(mm->registerMaterialInfo(mat_name));
144 MeshBlockBuildInfo mbbi(
"BLOCK1", allCells());
145 UniqueArray<IMeshEnvironment*> saved_envs;
148 for (Integer i = 0, n = options()->environment().size(); i < n; ++i) {
149 String env_name = options()->environment[i].name;
150 info() <<
"Found environment name=" << env_name;
151 Materials::MeshEnvironmentBuildInfo env_build(env_name);
152 for (Integer k = 0, kn = options()->environment[i].material.size(); k < kn; ++k) {
153 String mat_name = options()->environment[i].material[k];
154 info() <<
"Add material " << mat_name <<
" for environment " << env_name;
155 env_build.addMaterial(mat_name);
157 IMeshEnvironment* env = mm->createEnvironment(env_build);
161 info() <<
"Add environment " << env_name <<
" to block1";
162 mbbi.addEnvironment(env);
168 m_block1 = mm->createBlock(mbbi);
172 Integer nb_env = saved_envs.size();
174 MeshBlockBuildInfo mbbi2(
"BLOCK2", allCells());
175 mbbi2.addEnvironment(saved_envs[0]);
176 IMeshBlock* block2 = mm->createBlock(mbbi2);
177 Integer nb_env1 = block2->nbEnvironment();
178 mm->addEnvironmentToBlock(block2, saved_envs[1]);
179 info() <<
"Finished incremental creation of block";
180 Integer nb_env2 = block2->nbEnvironment();
181 if (nb_env2 != (nb_env1 + 1))
183 if (block2->environments()[nb_env1] != saved_envs[1])
186 IMeshEnvironment* first_env = block2->environments()[0];
187 IMeshEnvironment* second_env = block2->environments()[1];
188 mm->removeEnvironmentToBlock(block2, first_env);
189 nb_env2 = block2->nbEnvironment();
190 if (nb_env2 != nb_env1)
192 if (block2->environments()[0] != second_env)
197 mm->endCreate(subDomain()->isContinue());
199 info() <<
"List of materials:";
200 for (MeshMaterialInfo* m : materials_info) {
201 info() <<
"MAT=" << m->name();
202 for (String s : m->environmentsName())
203 info() <<
" In ENV=" << s;
208 ConstArrayView<Materials::IMeshEnvironment*> envs = mm->environments();
210 m_mat1 = mm->environments()[0]->materials()[0];
212 m_mat2 = mm->environments()[1]->materials()[0];
214 m_global_deltat.assign(1.0);
216 for (Integer i = 0, n = m_material_mng->materials().size(); i < n; ++i) {
217 IMeshMaterial* mat = m_material_mng->materials()[i];
219 m_density_post_processing.add(var);
222 m_mesh_partitioner = options()->loadBalanceService();
223 if (m_mesh_partitioner)
224 info() <<
"Activating load balance test";
230void MeshMaterialTesterModule::
233 m_mat_not_used_real.globalVariable().setUsed(
false);
235 info() <<
"MESH_MATERIAL_TESTER :: startInit()";
236 m_material_mng->forceRecompute();
238 ValueChecker vc(A_FUNCINFO);
240 m_nb_starting_cell.assign(parallelMng()->reduce(Parallel::ReduceSum, ownCells().size()));
245 Integer nb_cell = ownCells().size();
246 IParallelMng* pm = parallelMng();
247 Int64 total_nb_cell = pm->reduce(Parallel::ReduceMax, nb_cell);
250 Int64 cell_index = cell.uniqueId();
251 if (cell_index > (total_nb_cell / 2))
253 if (cell_index < (total_nb_cell / 5)) {
254 env1_indexes.add(icell.itemLocalId());
256 if (cell_index < (total_nb_cell / 3) && cell_index > (total_nb_cell / 6)) {
257 mat2_indexes.add(icell.itemLocalId());
259 if ((cell_index % 2) == 0)
260 sub_group_indexes.add(icell.itemLocalId());
265 Materials::MeshMaterialModifier modifier(m_material_mng);
266 modifier.setDoCopyBetweenPartialAndPure(
false);
267 modifier.setDoInitNewItems(
false);
268 modifier.setPersistantWorkBuffer(
false);
269 Materials::IMeshEnvironment* env = m_mat1->environment();
274 Integer nb_cell = env1_indexes.size();
275 for (Integer z = 0; z < nb_cell; ++z) {
276 bool add_to_mat1 = (z < (nb_cell / 2) && z > (nb_cell / 4));
277 bool add_to_mat2 = (z >= (nb_cell / 2) || z < (nb_cell / 3));
279 mat1_indexes.add(env1_indexes[z]);
282 mat2_indexes.add(env1_indexes[z]);
285 modifier.addCells(m_mat1, mat1_indexes);
286 Integer nb_mat = env->nbMaterial();
289 modifier.addCells(env->materials()[1], mat2_indexes);
291 CellGroup test_group = defaultMesh()->cellFamily()->createGroup(
"SUB_GROUP_TEST", sub_group_indexes);
294 Materials::MeshMaterialModifier modifier(m_material_mng);
296 modifier.addCells(m_mat2, mat2_indexes);
299 const Integer spectral_size = 5;
300 m_mat_spectral1.resize(spectral_size);
301 m_mat_spectral2.resize(spectral_size * 2);
302 m_env_spectral1.resize(spectral_size * 3);
303 m_env_spectral2.resize(spectral_size * 4);
308 m_mat_density.fillPartialValues(3.0);
309 m_env_int32.fillPartialValues(5);
310 m_mat_int32.fillPartialValues(8);
312 info() <<
"Liste des mailles de test_group";
314 info(6) <<
"Cell=" << ItemPrinter(*icell);
318 m_density[icell] = 1.0;
319 m_mat_density[icell] = 2.0;
320 Integer idx2 = icell.itemLocalId() % spectral_size;
321 m_mat_spectral1[icell][idx2] = 3.0 + (Real)(icell.itemLocalId() * spectral_size);
326 m_density[icell] = 2.0;
330 info() <<
"GVAR_NAME = " << gvar.
name();
332 if (gvar[icell] != 2.0)
333 fatal() <<
"Bad value for global variable v=" << gvar[icell];
340 m_density[icell] = 1.5;
344 _checkTemporaryVectors(test_group);
345 _checkSubViews(test_group);
349 m_material_mng->dumpInfos(oss());
356 m_present_material.fill(0);
357 m_mat_density.fill(0.0);
358 m_mat_nodump_real.fill(0.0);
360 constexpr IMeshMaterial* null_mat =
nullptr;
361 constexpr IMeshEnvironment* null_env =
nullptr;
365 IMeshEnvironment* env = *ienv;
366 info() <<
"ENV name=" << env->name();
367 vc.areEqual(env->isEnvironment(),
true,
"IsEnvEnvOK");
368 vc.areEqual(env->isMaterial(),
false,
"IsEnvMatOK");
369 vc.areEqual(env->asEnvironment(), env,
"ToEnvEnvOK");
370 vc.areEqual(env->asMaterial(), null_mat,
"ToEnvMatOK");
372 Materials::IMeshMaterial* mat = *imat;
373 info() <<
"MAT name=" << mat->name();
374 vc.areEqual(mat->isEnvironment(),
false,
"IsMatEnvOK");
375 vc.areEqual(mat->isMaterial(),
true,
"IsMatMatOK");
376 vc.areEqual(mat->asEnvironment(), null_env,
"ToMatEnvOK");
377 vc.areEqual(mat->asMaterial(), mat,
"ToMatMatOK");
379 MatCell mmcell = *icell;
381 m_mat_density[mmcell] = 200.0;
382 m_mat_nodump_real[mmcell] = 1.2;
383 ComponentCell x1(mmcell);
384 if (x1._varIndex() != mmcell._varIndex())
385 ARCANE_FATAL(
"Bad convertsion MatCell -> ComponentCell");
387 if (x1._varIndex() != x2._varIndex())
388 ARCANE_FATAL(
"Bad convertsion ComponentCell -> MatCell");
395 IMeshEnvironment* env = *ienv;
396 info() <<
"BLOCK_ENV name=" << env->name();
398 Materials::IMeshMaterial* mat = *imat;
399 info() <<
"BLOCK_MAT name=" << mat->name();
405 IMeshComponent* cmp = *icmp;
406 info() <<
"ENV COMPONENT name=" << cmp->name();
411 IMeshComponent* cmp = *icmp;
412 info() <<
"MAT COMPONENT name=" << cmp->name();
417 Materials::IMeshMaterial* mat = *imat;
418 info() <<
"MAT name=" << mat->name()
419 <<
" density_var_name=" << m_mat_density.materialVariable()->materialVariable(mat)->name();
421 MatCell mmcell = *icell;
422 m_mat_density[mmcell] = 200.0;
428 IMeshEnvironment* env = *ienv;
429 info() <<
"Env name=" << env->name();
431 EnvCell ev = *ienvcell;
432 info() <<
"EnvCell nb_mat=" << ev.nbMaterial() <<
" cell_uid=" << ItemPrinter(ev.globalCell())
433 <<
" component_uid=" << ev.componentUniqueId()
434 <<
" var_index=" << ev._varIndex();
440 CellToAllEnvCellConverter all_env_cell_converter(m_material_mng);
443 Cell back_cell = face.backCell();
444 if (!back_cell.null()) {
445 AllEnvCell all_env_back_cell = all_env_cell_converter[back_cell];
446 info() <<
"NB_ENV=" << all_env_back_cell.nbEnvironment();
447 ComponentCell x1 = all_env_back_cell;
449 if (x1._varIndex() != all_env_back_cell._varIndex())
450 ARCANE_FATAL(
"Bad convertsion AllEnvCell -> ComponentCell");
451 if (x1._varIndex() != x2._varIndex())
452 ARCANE_FATAL(
"Bad convertsion ComponentCell -> EnvCell");
459 AllEnvCell all_env_cell = *iallenvcell;
460 Cell global_cell = all_env_cell.globalCell();
462 Real env_density = 0.0;
464 MatCell mc = *imatcell;
465 env_density += m_mat_density[imatcell];
466 Int32 idx = mc.materialId();
467 m_present_material[global_cell] = m_present_material[global_cell] | (1 << idx);
469 m_mat_density[ienvcell] = env_density;
470 m_mat_nodump_real[ienvcell] = 3.5;
476 AllEnvCell all_env_cell = *iallenvcell;
477 info() <<
"Cell uid=" << ItemPrinter(all_env_cell.globalCell()) <<
" nb_env=" << all_env_cell.nbEnvironment();
479 EnvCell ec = *ienvcell;
480 info() <<
"Cell nb_mat=" << ec.nbMaterial()
481 <<
" env=" << ec.environment()->name()
482 <<
" (id=" << ec.environmentId() <<
")";
484 MatCell mc = *imatcell;
485 info() <<
"Cell mat=" << mc.material()->name()
486 <<
" (id=" << mc.materialId() <<
")"
487 <<
" density=" << m_mat_density[imatcell]
488 <<
" index=" << mc._varIndex()
489 <<
" component_uid=" << mc.componentUniqueId();
492 for (ComponentCell mc : ec.subItems()) {
493 info() <<
"Cell mat=" << mc.component()->name()
494 <<
" (id=" << mc.componentId() <<
")"
495 <<
" density=" << m_mat_density[mc]
496 <<
" index=" << mc._varIndex()
497 <<
" component_uid=" << mc.componentUniqueId();
504 ComponentCell ec = *ienvcell;
505 info() <<
"Cell nb_mat=" << ec.
nbSubItem()
506 <<
" env=" << ec.component()->name()
507 <<
" (id=" << ec.componentId() <<
")";
511 const bool test_depend =
false;
514 m_mat_density.addDependCurrentTime(m_density);
515 m_mat_density.addDependCurrentTime(m_mat_density2);
516 m_mat_density.addDependPreviousTime(m_mat_density2);
517 m_mat_density.removeDepend(m_mat_density2);
518 m_mat_density.setComputeFunction(
this, &MeshMaterialTesterModule::startInit);
524 CellToAllEnvCellConverter all_env_cell_converter(m_material_mng);
527 IMeshMaterial* mm = *imat;
531 AllEnvCell all_env_cell = all_env_cell_converter[cell];
532 Real density = m_mat_density.matValue(all_env_cell,
id);
533 info() <<
"IndirectMatAccess Cell uid=" << cell.uniqueId() <<
" mat_id=" <<
id <<
" density=" << density;
538 IMeshEnvironment* me = *ienv;
542 AllEnvCell all_env_cell = all_env_cell_converter[cell];
543 Real density = m_mat_density.envValue(all_env_cell,
id);
544 info() <<
"IndirectEnvAccess Cell uid=" << cell.uniqueId() <<
" env_id=" <<
id <<
" density=" << density;
551 _dumpNoDumpRealValues();
556 _testDumpProperties();
557 _checkNullComponentItem();
563ARCANE_REGISTER_MODULE_MESHMATERIALTESTER(MeshMaterialTesterModule);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Interface d'une variable.
__host__ __device__ Int32 nbSubItem() const
Nombre de sous-éléments.
Interface du gestionnaire des matériaux et des milieux d'un maillage.
Informations pour construire un module.
Paramètres nécessaires à la construction d'une variable.
String name() const
Nom de la variable.
ItemGroupT< Cell > CellGroup
Groupe de mailles.
MeshVariableScalarRefT< Cell, Real > VariableCellReal
Grandeur au centre des mailles de type réel.
Int32 Integer
Type représentant un entier.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
List< String > StringList
Tableau de chaînes de caractères unicode.
@ Cell
Le maillage est AMR par maille.