14#include "arcane/tests/MeshMaterialTesterModule.h"
16#include "arcane/utils/List.h"
17#include "arcane/utils/OStringStream.h"
18#include "arcane/utils/ValueChecker.h"
19#include "arcane/utils/SimdOperation.h"
21#include "arcane/core/ITimeLoopMng.h"
22#include "arcane/core/ITimeLoop.h"
23#include "arcane/core/TimeLoopEntryPointInfo.h"
24#include "arcane/core/IMesh.h"
25#include "arcane/core/IItemFamily.h"
26#include "arcane/core/ItemPrinter.h"
27#include "arcane/core/IParallelMng.h"
28#include "arcane/core/IMeshModifier.h"
29#include "arcane/core/IMeshUtilities.h"
30#include "arcane/core/IMeshPartitioner.h"
31#include "arcane/core/VariableDependInfo.h"
35#include "arcane/core/materials/IMeshMaterialMng.h"
36#include "arcane/core/materials/IMeshMaterial.h"
37#include "arcane/core/materials/IMeshEnvironment.h"
38#include "arcane/core/materials/IMeshBlock.h"
39#include "arcane/core/materials/MaterialVariableBuildInfo.h"
40#include "arcane/core/materials/CellToAllEnvCellConverter.h"
41#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
43#include "arcane/materials/MeshMaterialModifier.h"
44#include "arcane/materials/MeshBlockBuildInfo.h"
45#include "arcane/materials/MeshEnvironmentBuildInfo.h"
46#include "arcane/materials/MeshMaterialVariableDependInfo.h"
47#include "arcane/materials/MatCellVector.h"
48#include "arcane/materials/EnvCellVector.h"
49#include "arcane/materials/MatConcurrency.h"
50#include "arcane/materials/MeshMaterialIndirectModifier.h"
51#include "arcane/materials/MeshMaterialVariableSynchronizerList.h"
53#include "arcane/materials/MeshMaterialInfo.h"
55#include "arcane/accelerator/core/RunQueue.h"
58#include "arcane/tests/StdMeshVariables.cc"
73void MeshMaterialTesterModule::
76 info() <<
"Test checkRunQueues";
77 IMeshMaterialMngInternal* mng = m_material_mng->_internalApi();
79 eExecutionPolicy def_policy = mng->runQueue(eExecutionPolicy::None).executionPolicy();
80 eExecutionPolicy seq_policy = mng->runQueue(eExecutionPolicy::Sequential).executionPolicy();
81 eExecutionPolicy thread_policy = mng->runQueue(eExecutionPolicy::Thread).executionPolicy();
83 if (def_policy != mng_policy)
84 ARCANE_FATAL(
"Bad default execution policy '{0}' '{1}'", def_policy, mng_policy);
85 if (seq_policy != eExecutionPolicy::Sequential)
86 ARCANE_FATAL(
"Bad sequential execution policy '{0}'", seq_policy);
87 if (thread_policy != eExecutionPolicy::Thread)
88 ARCANE_FATAL(
"Bad thread execution policy '{0}'", thread_policy);
94void MeshMaterialTesterModule::
95_checkNullComponentItem()
97 EnvCell null_env_cell;
98 info() <<
"NullEnvCell global_cell_id=" << null_env_cell.globalCell().localId();
100 info() <<
"NullEnvCell var_index =" << null_env_cell._varIndex();
102 info() <<
"NullEnvCell component_id =" << null_env_cell.componentId();
103 info() <<
"NullEnvCell null =" << null_env_cell.null();
104 info() <<
"NullEnvCell super_cell =" << null_env_cell.superCell();
105 info() <<
"NullEnvCell level =" << null_env_cell.level();
106 info() <<
"NullEnvCell nb_sub_item=" << null_env_cell.nbSubItem();
107 info() <<
"NullEnvCell component_unique_id=" << null_env_cell.componentUniqueId();
110 info() <<
"NullEnvCell all_env_cell =" << null_env_cell.allEnvCell().null();
116void MeshMaterialTesterModule::
119 IMesh* mesh = defaultMesh();
122 Int32 p0 = v0.variable()->property();
123 Int32 p1 = v1.globalVariable().variable()->property();
124 info() <<
"PROP1 = " << p0 <<
" " << p1;
128 Int32 p2 = v2.globalVariable().variable()->property();
129 Int32 p3 = v3.variable()->property();
130 info() <<
"PROP2 = " << p2 <<
" " << p3;
133 Int32 p4 = v4.globalVariable().variable()->property();
134 info() <<
"PROP4 = " << p4;
142 ARCANE_FATAL(
"Bad property value p0={0}. Should be Dump",p0);
144 ARCANE_FATAL(
"Bad property value p2={0}. Should be Dump",p2);
155 auto* x = options()->additionalEosService();
162 info() <<
"EOS: mat=" << mat->
name();
168 x->initEOS(mat,m_mat_pressure,m_mat_density,m_mat_internal_energy,m_mat_sound_speed);
170 x->applyEOS(mat,m_mat_density,m_mat_internal_energy,m_mat_pressure,m_mat_sound_speed);
178void MeshMaterialTesterModule::
181 IUnitTest* unit_test = options()->additionalTestService();
189void MeshMaterialTesterModule::
192 info() <<
"MESH_MATERIAL_TESTER :: continueInit()";
194 _dumpNoDumpRealValues();
201void MeshMaterialTesterModule::
204 info() <<
"SET_DEPENDENCIES";
206 m_mat_density.setMaterialComputeFunction(
this,&MeshMaterialTesterModule::_computeMaterialDepend);
208 m_mat_density.addMaterialDepend(m_pressure);
210 UniqueArray<VariableDependInfo> infos;
211 UniqueArray<MeshMaterialVariableDependInfo> mat_infos;
212 m_mat_density.materialVariable()->dependInfos(infos,mat_infos);
214 for(
Integer k=0, n=infos.size(); k<n; ++k )
215 info() <<
"Global depend v=" << infos[k].variable()->fullName();
217 for(
Integer k=0, n=mat_infos.size(); k<n; ++k )
218 info() <<
"Material depend v=" << mat_infos[k].variable()->name();
241 test_var[iccell] = index;
246 Int32 total_full = 0;
247 Int32 total_pure = 0;
248 Int32 total_impure = 0;
251 Int32 v = test_var[iccell];
258 info() <<
"COMPONENT=" << component->
name() <<
" TOTAL PURE=" << total_pure <<
" IMPURE=" << total_impure
259 <<
" FULL=" << total_full;
267 total += test_var[imc];
269 vc.
areEqual(total,total_full,
"TotalFull1");
275 total += test_var[imc];
277 vc.
areEqual(total,total_impure,
"TotalImpure1");
282 total += test_var[imc];
284 vc.
areEqual(total,total_pure,
"TotalPure1");
289 total += test_var[imc];
291 vc.
areEqual(total,total_impure,
"TotalImpure2");
296 total += test_var[imc];
298 vc.
areEqual(total,total_pure,
"TotalPure2");
306 total += test_var[imc];
308 vc.
areEqual(total,total_full,
"TotalFull1");
314 total += test_var[imc];
316 vc.
areEqual(total,total_impure,
"TotalImpure1");
321 total += test_var[imc];
323 vc.
areEqual(total,total_pure,
"TotalPure1");
328 total += test_var[imc];
330 vc.
areEqual(total,total_impure,
"TotalImpure2");
335 total += test_var[imc];
337 vc.
areEqual(total,total_pure,
"TotalPure2");
344 total += test_var[imc];
346 vc.
areEqual(total,total_impure,
"TotalImpure3");
351 total += test_var[imc];
353 vc.
areEqual(total,total_pure,
"TotalPure3");
360void MeshMaterialTesterModule::
363 m_pressure.fill(0.0);
367 double v = (double)mat->
id();
370 m_mat_density.update(mat);
375 IMeshMaterial* mat = *imat;
376 double v = (double)mat->
id();
378 if (m_mat_density[imc]!=v)
379 ARCANE_FATAL(
"Bad value for mat depend v={0} expected={1}",m_mat_density[imc],v);
382 if (m_mat_density[imc]!=v)
383 ARCANE_FATAL(
"Bad value for mat depend v={0} expected={1}",m_mat_density[imc],v);
388 m_pressure.fill(1.0);
389 m_pressure.setUpToDate();
391 IMeshMaterial* mat = *imat;
392 double v0 = (double)mat->id();
394 m_mat_density.update(mat);
397 if (m_mat_density[imc]!=v)
398 ARCANE_FATAL(
"Bad value (1) for global depend v={0} expected={1}",m_mat_density[imc],v);
401 if (m_mat_density[imc]!=v)
402 ARCANE_FATAL(
"Bad value (2) for global depend v={0} expected={1}",m_mat_density[imc],v);
405 if (m_mat_density[imc]!=v)
406 ARCANE_FATAL(
"Bad value (2) for global depend v={0} expected={1}",m_mat_density[imc],v);
414void MeshMaterialTesterModule::
417 info() <<
"Compute material depend mat=" << mat->name();
421 Cell cell = mc.globalCell();
424 info() <<
"Cell=" << ItemPrinter(cell) <<
" density=" << m_mat_density[mc]
426 <<
" pressure=" << m_pressure[cell];
430 m_mat_density.setUpToDate(mat);
436void MeshMaterialTesterModule::
439 info() <<
"_dumpAverageValues()";
441 IMeshEnvironment* env = *ienv;
443 IMeshMaterial* mat = *imat;
444 Real sum_density = 0.0;
447 sum_density += m_mat_density[imatcell];
449 info() <<
"SumMat ITER=" << m_global_iteration() <<
" MAT=" << mat->name()
450 <<
" density=" << sum_density;
458void MeshMaterialTesterModule::
461 info() <<
"_doSimd()";
466 IMeshEnvironment* env = *ienv;
467 auto out_var_tmp =
viewOut(var_tmp);
468 Real value = (
Real)(env->id()) * 4.3;
470 out_var_tmp[ienvcell] = value;
473 if (var_tmp[ienvcell]!=value)
474 ARCANE_FATAL(
"Bad value v={0} expected={1}",var_tmp[ienvcell],value);
482void MeshMaterialTesterModule::
483_dumpNoDumpRealValues()
487 info() << ostr.str();
489 UniqueArray<IMeshMaterialVariable*> vars;
490 m_material_mng->fillWithUsedVariables(vars);
491 info() <<
"NB_USED_MATERIAL_VAR=" << vars.size();
492 for(
Integer i=0, n=vars.size(); i<n; ++i )
493 info() <<
"USED_MATERIAL_VAR name=" << vars[i]->name();
499template<
typename VectorType>
void MeshMaterialTesterModule::
500_checkVectorCopy(VectorType& vec_cells)
502 ValueChecker vc(A_FUNCINFO);
506 VectorType vec_cells_copy(vec_cells);
507 if (!vec_cells_copy.view()._isSamePointerData(vec_cells.view()))
510 VectorType vec_cells_copy2(vec_cells);
511 vc.areEqual(vec_cells_copy2.view()._matvarIndexes(),vec_cells.view()._matvarIndexes(),
"bad copy 2");
513 VectorType move_vec_cells(std::move(vec_cells_copy2));
514 vc.areEqual(move_vec_cells.view()._matvarIndexes().data(),vec_cells.view()._matvarIndexes().data(),
"bad move 1");
519 VectorType clone_vec(vec_cells_copy.clone());
520 vc.areEqual(clone_vec.view()._matvarIndexes(),vec_cells.view()._matvarIndexes(),
"bad clone 1");
521 if (clone_vec.view()._constituentItemListView() != vec_cells.view()._constituentItemListView())
523 if (clone_vec.view()._matvarIndexes().data()==vec_cells.view()._matvarIndexes().data())
525 if (clone_vec.view()._isSamePointerData(vec_cells.view()))
533void MeshMaterialTesterModule::
534_checkTemporaryVectors(
const CellGroup& test_group)
538 MatCellVector mat_cells(test_group,m_mat1);
539 const MatCellVector& mcref(mat_cells);
540 info() <<
"SET_DENSITY ON SUB GROUP for material";
542 MatCell mc = *imatcell;
543 info() <<
"REF_IDX MAT1 " << mc._varIndex() <<
" " << mc.globalCell().uniqueId();
546 MatCell mc = *imatcell;
547 info() <<
"REF_IDX MAT2 " << mc._varIndex() <<
" " << mc.globalCell().uniqueId();
549 info() <<
"SET_DENSITY";
551 MatCell mc = *imatcell;
552 m_mat_density[mc] = 3.2;
553 info() <<
"SET_MAT_DENSITY " << mc._varIndex() <<
" " << mc.globalCell().uniqueId();
555 _checkVectorCopy(mat_cells);
557 _checkVectorCopy(component_mat_cells);
561 MatCellVector mat_cells(test_group.view(),m_mat1);
562 const MatCellVector& mcref(mat_cells);
563 info() <<
"SET_DENSITY ON SUB GROUP for material";
565 MatCell mc = *imatcell;
566 info() <<
"REF_IDX MAT1 " << mc._varIndex() <<
" " << mc.globalCell().uniqueId();
569 MatCell mc = *imatcell;
570 info() <<
"REF_IDX MAT2 " << mc._varIndex() <<
" " << mc.globalCell().uniqueId();
572 info() <<
"SET_DENSITY";
574 MatCell mc = *imatcell;
575 m_mat_density[mc] = 3.2;
576 info() <<
"SET_MAT_DENSITY " << mc._varIndex() <<
" " << mc.globalCell().uniqueId();
579 MatCell mc = *imatcell;
580 m_mat_density[mc] = 3.2;
581 info() <<
"SET_MAT_DENSITY (VIEW) " << mc._varIndex() <<
" " << mc.globalCell().uniqueId();
586 IMeshEnvironment* env1 = m_mat1->environment();
587 EnvCellVector env_cells(test_group,env1);
588 const EnvCellVector& ecref(env_cells);
589 info() <<
"SET_DENSITY ON SUB GROUP for environment";
591 EnvCell mc = *ienvcell;
592 info() <<
"REF_IDX ENV1 " << mc._varIndex() <<
" uid=" << mc.globalCell().uniqueId();
594 info() <<
"SET_DENSITY";
596 EnvCell mc = *ienvcell;
597 m_mat_density[ienvcell] = 3.2;
598 info() <<
"SET_ENV_DENSITY " << mc._varIndex() <<
" uid=" << mc.globalCell().uniqueId();
601 EnvCell mc = *ienvcell;
602 m_mat_density[ienvcell] = 3.2;
603 info() <<
"SET_ENV_DENSITY (VIEW)" << mc._varIndex() <<
" uid=" << mc.globalCell().uniqueId();
605 _checkVectorCopy(env_cells);
607 _checkVectorCopy(component_env_cells);
611 IMeshEnvironment* env1 = m_mat1->environment();
612 EnvCellVector env_cells(test_group.view(),env1);
613 const EnvCellVector& ecref(env_cells);
614 info() <<
"SET_DENSITY ON SUB GROUP for environment";
616 EnvCell mc = *ienvcell;
617 info() <<
"REF_IDX ENV1 " << mc._varIndex() <<
" uid=" << mc.globalCell().uniqueId();
619 info() <<
"SET_DENSITY";
621 EnvCell mc = *ienvcell;
622 m_mat_density[ienvcell] = 3.2;
623 info() <<
"SET_ENV_DENSITY " << mc._varIndex() <<
" uid=" << mc.globalCell().uniqueId();
632void MeshMaterialTesterModule::
635 if (value!=expected_value){
636 ARCANE_FATAL(
"Bad value v={0} expected={1}",value,expected_value);
643Integer MeshMaterialTesterModule::
659Integer MeshMaterialTesterModule::
675Integer MeshMaterialTesterModule::
678 std::atomic<Integer> new_total;
679 auto func = [&](MatItemVectorView view)
681 info() <<
"ParallelLoop with MatItemVectorView size=" << view.nbItem();
683 new_total += (
Integer)var[iccell];
695void MeshMaterialTesterModule::
696_checkSubViews(
const CellGroup& test_group)
698 IMeshEnvironment* env1 = m_mat1->environment();
699 EnvCellVector env_cells(test_group.view(),env1);
700 MatCellVector mat_cells(test_group.view(),m_mat1);
704 ComponentItemVectorView test_group_view(env_cells.view());
705 Integer nb_item = test_group_view.nbItem();
712 ComponentItemVectorView v2 = test_group_view._subView(begin,size);
714 ComponentCell ccell = *iccell;
715 info() <<
" ComponentCell c=" << ccell.
_varIndex();
726 mat_test_sub_view[imcell] = index;
731 mat_test_sub_view[iecell] = index;
732 direct_total += index;
736 direct_mat_total += (
Integer)mat_test_sub_view[imcell];
738 info() <<
"DIRECT_ENV_TOTAL = " << direct_total
739 <<
"DIRECT_MAT_TOTAL = " << direct_mat_total;
743 ComponentItemVectorView test_group_view(env_cells.view());
744 Integer nb_item = test_group_view.nbItem();
746 for(
Integer block_size=1; block_size<20; ++block_size){
748 for(
Integer begin=0; begin<nb_item; begin += block_size ){
753 ComponentItemVectorView v2 = test_group_view._subView(begin,size);
755 new_total += (
Integer)mat_test_sub_view[iccell];
758 if (new_total!=direct_total){
759 ARCANE_FATAL(
"Bad total v={0} expected={1} block_size={2}",
760 new_total,direct_total,block_size);
767 ComponentItemVectorView test_group_view(env_cells.view());
769 ParallelLoopOptions options;
770 options.setGrainSize(10);
772 Integer nb_item = test_group_view.nbItem();
773 info() <<
"ParallelTest with lambda full_size=" << nb_item;
777 std::atomic<Integer> new_total;
779 auto func = [&](ComponentItemVectorView view)
781 info() <<
"ParallelLoop with component size=" << view.nbItem();
783 new_total += (
Integer)mat_test_sub_view[iccell];
788 if (new_total!=direct_total){
795 EnvItemVectorView env_test_group_view(env_cells.view());
796 std::atomic<Integer> new_total;
798 auto func = [&](EnvItemVectorView view)
800 info() <<
"ParallelLoop with environment size=" << view.nbItem();
802 new_total += (
Integer)mat_test_sub_view[iccell];
807 if (new_total!=direct_total){
814 MatItemVectorView mat_view(mat_cells.view());
815 Integer ref_val = _fillTestVar(mat_view,mat_test_sub_view);
816 Integer new_val = _checkParallelMatItem(mat_view,mat_test_sub_view);
817 _checkEqual(ref_val,new_val);
822 Integer ref_val = _fillTestVar(m_mat1,mat_test_sub_view);
823 Integer new_val = _checkParallelMatItem(m_mat1->matView(),mat_test_sub_view);
824 _checkEqual(ref_val,new_val);
829 MatCellVector empty_mat_cells(
CellGroup(),m_mat1);
830 MatItemVectorView mat_view(empty_mat_cells.view());
831 Integer ref_val = _fillTestVar(mat_view,mat_test_sub_view);
832 Integer new_val = _checkParallelMatItem(mat_view,mat_test_sub_view);
833 _checkEqual(ref_val,new_val);
841 ComponentItemVectorView test_group_view(env_cells.view());
842 Integer nb_item = test_group_view.nbItem();
843 info() <<
"NB_ITEM=" << nb_item;
844 auto f0 = std::bind(std::mem_fn(&MeshMaterialTesterModule::_subViewFunctor),
this,std::placeholders::_1);
848 [&](ComponentItemVectorView view){ this->_subViewFunctor(view); }
856void MeshMaterialTesterModule::
866void MeshMaterialTesterModule::
869 ValueChecker vc(A_FUNCINFO);
877 values.resize(nb_cell);
878 var.fillToArray(mat,values);
880 vc.areEqual(var[imatcell],values[index],
"Bad value for fillToArray()");
886 var_tmp.fillFromArray(mat,values);
888 vc.areEqual(values[index],var_tmp[imatcell],
"Bad value for fillFromArray()");
894 std::map<Int32,MatCell> matvar_indexes;
900 if (iterator_index==wanted_index){
901 matvar_indexes.insert(std::make_pair(iterator_index,*imatcell));
902 indexes.add(iterator_index);
906 info() <<
"Indexes=" << indexes;
913 values.resize(nb_index);
915 var.fillToArray(mat,values,indexes);
916 for(
Integer i=0; i<nb_index; ++i )
917 vc.areEqual(var[matvar_indexes[i]],values[i],
"Bad value for fillToArray() (2)");
921 var_tmp.fillFromArray(mat,values,indexes);
922 for(
Integer i=0; i<nb_index; ++i )
923 vc.areEqual(values[i],var_tmp[matvar_indexes[i]],
"Bad value for fillFromArray() (2)");
930template <
typename ContainerType>
void MeshMaterialTesterModule::
934 var[igencell] = value;
941void MeshMaterialTesterModule::
944 IUnitTest* unit_test = options()->additionalTestService();
949 if (m_check_spectral_values_iteration!=0){
950 info() <<
"Check spectral values after loadbalancing";
951 _setOrCheckSpectralValues(m_check_spectral_values_iteration,
true);
952 m_check_spectral_values_iteration = 0;
959 _dumpAverageValues();
971 using namespace Materials;
973 mat_pressure.fill(0.0);
975 FaceGroup xmin_group = defaultMesh()->faceFamily()->findGroup(
"XMIN");
978 Cell c = face.boundaryCell();
979 Real d = m_density[c];
980 m_density[c] = d + 1.0;
986 if (mat_pressure2.materialVariable()!=mat_pressure.materialVariable())
993 mat_test_refersto.refersTo(mat_pressure);
994 if (mat_test_refersto.materialVariable()!=mat_pressure.materialVariable())
997 Real total_ref = 0.0;
999 total += mat_test_refersto[imatcell];
1000 total_ref += mat_pressure[imatcell];
1002 if (total!=total_ref)
1009 MatCellVector mat_cells(ownCells(),m_mat1);
1010 const MatCellVector& mcref(mat_cells);
1012 applyGeneric(mcref,var,4.5);
1014 if (var[imatcell]!=4.5)
1017 applyGeneric(allCells(),var,3.2);
1019 if (var[icell]!=3.2)
1022 applyGeneric(m_mat1,var,7.6);
1024 if (var[imatcell]!=7.6)
1027 applyGeneric(m_mat1->environment(),var,4.2);
1029 if (var[imatcell]!=4.2)
1035 _checkFillPartialValues();
1037 IMeshMaterialVariable* nv = m_material_mng->findVariable(m_pressure.variable()->fullName());
1039 fatal() <<
"Can not find MeshVariable (F1)";
1041 IMeshMaterialVariable* nv2 = m_material_mng->findVariable(
"Pressure");
1043 fatal() <<
"Can not find MeshVariable (F2)";
1046 MatCell mmc = *imatcell;
1047 MatVarIndex mvi = mmc._varIndex();
1048 info() <<
"CELL IN MAT1 i=" << imatcell.index() <<
" vindex=" << mvi.arrayIndex() <<
" i=" << mvi.valueIndex();
1049 mat_pressure[mmc] += 0.2;
1054 MatCell mmc = *imatcell;
1055 MatVarIndex mvi = mmc._varIndex();
1056 info() <<
"CELL IN MAT2 vindex=" << mvi.arrayIndex() <<
" i=" << mvi.valueIndex();
1058 mat_pressure[imatcell] -= 0.2;
1062 _checkFillArrayFromTo(m_mat1,mat_pressure);
1064 _checkFillArrayFromTo(m_mat2,mat_pressure);
1067 IMeshEnvironment* env = *ienv;
1069 EnvCell ev = *ienvcell;
1070 MatVarIndex mvi = ev._varIndex();
1071 info() <<
"CELL IN ENV vindex=" << mvi.arrayIndex() <<
" i=" << mvi.valueIndex();
1072 mat_pressure[ev] += 3.0;
1073 mat_pressure[ienvcell] += 3.0;
1076 ComponentCell cv = *icmpcell;
1078 info() <<
"CELL IN ENV WITH COMPONENT vindex=" << mvi.
arrayIndex() <<
" i=" << mvi.valueIndex();
1079 mat_pressure[cv] += 3.0;
1080 EnvCell env_cell(cv);
1081 if (env_cell._varIndex()!=cv._varIndex())
1086 _checkArrayVariableSynchronize();
1088 for(
Integer i=0, n=m_material_mng->materials().size(); i<n; ++i ){
1089 IMeshMaterial* mat = m_material_mng->materials()[i];
1090 m_density_post_processing[i]->copy(m_mat_density.globalVariable());
1091 _copyPartialToGlobal(mat,*m_density_post_processing[i],m_mat_density);
1096 info() <<
"CheckRemove: Cells in MAT1=" << m_mat1->cells().size();
1098 MatCell mmc = *imatcell;
1099 MatVarIndex mvi = mmc._varIndex();
1100 info() <<
"CheckRemove: CELL IN MAT1 i=" << imatcell.index() <<
" vindex=" << mvi.arrayIndex() <<
" i=" << mvi.valueIndex()
1101 <<
" lid=" << mmc.envCell().globalCell();
1105 info() <<
"Cells in MAT2=" << m_mat2->cells().size();
1109 Int64 last_uid = m_nb_starting_cell() - (m_global_iteration()*30);
1110 info() <<
"LAST_UID_TO_REMOVE=" << last_uid;
1114 if (c.uniqueId()>last_uid)
1115 remove_lids.
add(c.localId());
1118 info() <<
"Removing cells n=" << remove_lids.size();
1119 mesh()->modifier()->setDynamic(
true);
1120 mesh()->modifier()->removeCells(remove_lids);
1121 if (parallelMng()->isParallel()){
1125 Integer check_level = mesh()->checkLevel();
1126 mesh()->setCheckLevel(0);
1127 mesh()->modifier()->endUpdate();
1129 MeshMaterialIndirectModifier mmim(m_material_mng);
1131 info() <<
"MESH_MATERIAL_TEST: UpdateGhostLayers";
1132 mesh()->modifier()->updateGhostLayers();
1133 if ((m_global_iteration() % 2)==0){
1134 mmim.endUpdateWithSort();
1140 mesh()->setCheckLevel(check_level);
1144 mesh()->modifier()->endUpdate();
1146 info() <<
"End removing cells nb_cell=" << mesh()->nbCell();
1149 Integer iteration = m_global_iteration();
1151 if ((iteration%3)==0){
1152 info() <<
"Registering mesh partition";
1154 m_check_spectral_values_iteration = (iteration*2)+1;
1155 _setOrCheckSpectralValues(m_check_spectral_values_iteration,
false);
1161 Materials::IMeshMaterial* mat = *imat;
1163 MatCell mc = *icell;
1164 if (m_mat_density[mc] == 0.0)
1165 m_mat_density[mc] = 50.0;
1166 if (m_mat_internal_energy[mc] == 0.0)
1167 m_mat_internal_energy[mc] = 1.0;
1177void MeshMaterialTesterModule::
1178_checkFillPartialValues()
1181 info() <<
"Check MaterialVariableCellReal";
1183 _checkFillPartialValuesHelper(mat_var);
1185 info() <<
"Check EnvironmentVariableCellReal";
1187 _checkFillPartialValuesHelper(env_var);
1188 if (m_material_mng->isAllocateScalarEnvironmentVariableAsMaterial()){
1190 info() <<
"Ok for creating Material variable with same name as Environment variable";
1193 info() <<
"Check MaterialVariableCellReal";
1196 _checkFillPartialValuesHelper(mat_var2);
1198 info() <<
"Check EnvironmentVariableCellArrayReal";
1200 env_var2.resize(12);
1201 _checkFillPartialValuesHelper(env_var2);
1207template<
typename VarType>
void MeshMaterialTesterModule::
1208_checkFillPartialValuesHelper(VarType& mat_var)
1210 info() <<
"Check fillPartialValuesWithGlobalValues()";
1211 _fillVar(mat_var,3.0);
1212 mat_var.materialVariable()->fillPartialValuesWithGlobalValues();
1213 _checkFillPartialValuesWithGlobal(mat_var,m_material_mng->components());
1215 info() <<
"Check fillPartialValuesWithSuperValues(LEVEL_ALLENVIRONMENT)";
1216 _fillVar(mat_var,7.0);
1217 mat_var.fillPartialValuesWithSuperValues(LEVEL_ALLENVIRONMENT);
1218 _checkFillPartialValuesWithGlobal(mat_var,m_material_mng->components());
1220 info() <<
"Check fillPartialValuesWithSuperValues(LEVEL_ENVIRONMENT)";
1221 _fillVar(mat_var,-2.0);
1222 mat_var.fillPartialValuesWithSuperValues(LEVEL_ENVIRONMENT);
1223 _checkFillPartialValuesWithSuper(mat_var,m_material_mng->environmentsAsComponents());
1225 info() <<
"Check fillPartialValuesWithSuperValues(LEVEL_MATERIAl)";
1226 _fillVar(mat_var,-25.0);
1227 mat_var.fillPartialValuesWithSuperValues(LEVEL_MATERIAL);
1228 _checkFillPartialValuesWithSuper(mat_var,m_material_mng->materialsAsComponents());
1236void _setValue(
Real& var_ref,
Real value)
1244 var_ref[i] = value*((
Real)(i+1));
1248template<
typename VarType>
void MeshMaterialTesterModule::
1249_fillVar(VarType& var_type,
Real base_value)
1255 IMeshComponent* c = *ic;
1256 if (!c->hasSpace(var_space))
1260 _setValue(var_type[iccell],(base_value + (
Real)index));
1268template<
typename VarType>
void MeshMaterialTesterModule::
1269_checkFillPartialValuesWithGlobal(
const VarType& var_type,
MeshComponentList components)
1271 ValueChecker vc(A_FUNCINFO);
1275 IMeshComponent* c = *ic;
1276 if (!c->hasSpace(var_space))
1279 Cell c = (*iccell).globalCell();
1280 auto ref_value = var_type[c];
1281 auto my_value = var_type[iccell];
1282 vc.areEqual(my_value,ref_value,
"Bad fill value with global");
1290template<
typename VarType>
void MeshMaterialTesterModule::
1291_checkFillPartialValuesWithSuper(
const VarType& var_type,
MeshComponentList components)
1293 ValueChecker vc(A_FUNCINFO);
1297 IMeshComponent* c = *ic;
1298 if (!c->hasSpace(var_space))
1301 ComponentCell c = (*iccell).
superCell();
1302 auto ref_value = var_type[c];
1303 auto my_value = var_type[iccell];
1304 vc.areEqual(my_value,ref_value,
"Bad fill value with super");
1312template<
typename VarType1,
typename VarType2,
typename VarType3>
void MeshMaterialTesterModule::
1313_setOrCheckSpectralValues2(VarType1& var_real,VarType2& var_int32,VarType3& var_scalar_int32,
1314 Int64 iteration,
bool is_check)
1316 typedef std::function<void(
Int64,
Int64,ComponentItemLocalId)> FunctorType;
1318 Int32 spectral1_dim2 = var_real.globalVariable().arraySize();
1319 Int32 spectral2_dim2 = var_int32.globalVariable().arraySize();
1320 info() <<
"SET_OR_CHECK size1=" << spectral1_dim2 <<
" size2=" << spectral2_dim2;
1321 FunctorType set_func = [&](
Int64 uid,
Int64 iteration,ComponentItemLocalId var_index)
1323 Int64 component_idx = var_index.localId().arrayIndex();
1324 Int64 base = uid + iteration + (component_idx+1);
1325 for(
Integer i=0; i<spectral1_dim2; ++i )
1327 for(
Integer i=0; i<spectral2_dim2; ++i )
1328 var_int32[var_index][i] = (
Int32)(3 + (base * spectral2_dim2 + i*2 ));
1329 var_scalar_int32[var_index] = (
Int32)(3 + (base * spectral2_dim2));
1332 ValueChecker vc(A_FUNCINFO);
1333 vc.setThrowOnError(
false);
1335 FunctorType check_func = [&](
Int64 uid,
Int64 iteration,ComponentItemLocalId var_index)
1337 Int64 component_idx = var_index.localId().arrayIndex();
1338 Int64 base = uid + iteration + (component_idx+1);
1339 for(
Integer i=0; i<spectral1_dim2; ++i ){
1342 vc.areEqual(ref1,var_real[var_index][i],String::format(
"spectral1:{0}",var_real.name()));
1344 for(
Integer i=0; i<spectral2_dim2; ++i ){
1345 Int32 ref2 = (
Int32)(3 + (base * spectral2_dim2 + i*2 ));
1347 vc.areEqual(ref2,var_int32[var_index][i],String::format(
"spectral2:{0}",var_int32.name()));
1349 Int32 ref3 = (
Int32)(3 + (base * spectral2_dim2));
1350 vc.areEqual(ref3,var_scalar_int32[var_index],
"scalar1");
1351 if (vc.nbError()!=0){
1352 error() <<
"Error for cell uid=" << uid <<
" var_index=" << var_index;
1357 FunctorType func = (is_check) ? check_func : set_func;
1359 bool has_mat = var_real.materialVariable()->space()!=MatVarSpace::Environment;
1361 AllEnvCell all_env_cell = *iallenvcell;
1362 Cell global_cell = all_env_cell.globalCell();
1363 Int64 cell_uid = global_cell.uniqueId();
1365 func(cell_uid,iteration,ienvcell);
1368 func(cell_uid,iteration,imatcell);
1372 func(cell_uid,iteration,all_env_cell);
1379void MeshMaterialTesterModule::
1380_setOrCheckSpectralValues(
Int64 iteration,
bool is_check)
1382 _setOrCheckSpectralValues2(m_mat_spectral1,m_mat_spectral2,m_mat_int32,iteration,is_check);
1383 _setOrCheckSpectralValues2(m_env_spectral1,m_env_spectral2,m_env_int32,iteration,is_check);
1389void MeshMaterialTesterModule::
1390_checkArrayVariableSynchronize()
1392 info() <<
"_checkArrayVariableSynchronize(): SYNCHRONIZE_MATERIALS";
1393 m_material_mng->synchronizeMaterialsInCells();
1394 m_material_mng->checkMaterialsInCells();
1396 Int64 iteration = m_global_iteration();
1398 _setOrCheckSpectralValues(iteration,
false);
1401 if ((iteration % 2)==0){
1402 MeshMaterialVariableSynchronizerList mlist(m_material_mng);
1403 m_mat_spectral1.synchronize(mlist);
1404 m_mat_spectral2.synchronize(mlist);
1405 m_env_spectral1.synchronize(mlist);
1406 m_env_spectral2.synchronize(mlist);
1407 m_mat_int32.synchronize();
1408 m_env_int32.synchronize();
1412 m_mat_spectral1.synchronize();
1413 m_mat_spectral2.synchronize();
1414 m_env_spectral1.synchronize();
1415 m_env_spectral2.synchronize();
1416 m_mat_int32.synchronize();
1417 m_env_int32.synchronize();
1420 _setOrCheckSpectralValues(iteration,
true);
1426void MeshMaterialTesterModule::
1429 VariableCellReal tmp_cell_mat_density(VariableBuildInfo(defaultMesh(),
"TmpCellMatDensity"));
1430 VariableNodeReal tmp_node_mat_density(VariableBuildInfo(defaultMesh(),
"TmpNodeMatDensity"));
1436 Materials::MeshMaterialModifier modifier(m_material_mng);
1438 IMeshEnvironment* env = *ienv;
1440 IMeshMaterial* mat = *imat;
1441 mat_to_add_array.clear();
1442 mat_to_remove_array.clear();
1443 _fillDensity(*imat,tmp_cell_mat_density,tmp_node_mat_density,mat_to_add_array,mat_to_remove_array,
true);
1444 info() <<
"FILL_DENSITY_INFO ITER=" << m_global_iteration()
1445 <<
" mat=" << mat->name()
1446 <<
" nb_to_add=" << mat_to_add_array.size()
1447 <<
" nb_to_remove=" << mat_to_remove_array.size();
1449 modifier.removeCells(mat,mat_to_remove_array);
1450 modifier.addCells(mat,mat_to_add_array);
1458 IMeshEnvironment* env = *ienv;
1460 _fillDensity(*imat,tmp_cell_mat_density,tmp_node_mat_density,mat_to_add_array,mat_to_remove_array,
false);
1466 m_material_mng->synchronizeMaterialsInCells();
1467 info() <<
"Synchronize density";
1468 m_mat_density.synchronize();
1474void MeshMaterialTesterModule::
1479 MatCell mc = *imatcell;
1480 Cell global_cell = mc.globalCell();
1481 global_density[global_cell] = partial_variable[mc];
1504 bool is_compute_mat)
1507 tmp_cell_mat_density.fill(0.0);
1508 tmp_node_mat_density.fill(0.0);
1509 info() <<
"FILL MAT=" << mat->
name();
1512 _copyPartialToGlobal(mat,tmp_cell_mat_density,m_mat_density);
1517 for( CellLocalId icell : inode->cellIds() )
1518 v += tmp_cell_mat_density[icell];
1519 v /= (
Real)inode->nbCell();
1521 tmp_node_mat_density[inode] = v;
1526 if (is_compute_mat){
1529 Real current_density = tmp_cell_mat_density[icell];
1530 Real new_density = 0.0;
1531 bool has_material = (m_present_material[cell] & (1<<mat_id));
1532 for( NodeLocalId inode : cell.
nodeIds() )
1533 new_density += tmp_node_mat_density[inode];
1535 if (new_density>=0.5 && !has_material && current_density==0.0){
1537 info() <<
"NEW CELL FOR MAT " << mat_id <<
" uid=" <<
ItemPrinter(cell) <<
" new=" << new_density;
1539 else if (new_density<0.4 && has_material && current_density>0.4){
1541 info() <<
"REMOVE CELL FOR MAT " << mat_id <<
" uid=" <<
ItemPrinter(cell) <<
" new=" << new_density
1542 <<
" old=" << current_density;
1544 tmp_cell_mat_density[icell] = new_density;
1553 Real new_density = 0.0;
1554 for( NodeLocalId inode : cell.
nodeIds() )
1555 new_density += tmp_node_mat_density[inode];
1557 tmp_cell_mat_density[icell] = new_density;
1565 m_mat_density[mc] = tmp_cell_mat_density[global_cell];
1569 StdMeshVariables<MeshMaterialVariableTraits> xm(meshHandle(),
"Base1",
"Base2");
1576void MeshMaterialTesterModule::
1580 info() <<
"I=" << a <<
" N=" << n;
1583 z += mat_pressure.materialVariable()->name().length();
1585 info() <<
"Z=" << z;
1601 info() <<
"CHECK CREATE N=" << n;
1605 mat_pressure.
fill(0.0);
1608 mat_pressure[mmc] += 0.2;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define ENUMERATE_COMPONENTITEM_LAMBDA(iter_type, iter, container)
Macro pour itérer sur les entités d'un composant via une fonction lambda du C++11.
Classes, Types et macros pour gérer la concurrence.
void _applyEos(bool is_init)
Appelle le service d'EOS s'il est disponible.
MaterialVariableCellReal m_mat_nodump_real
Variable pour tester la bonne prise en compte du PNoDump.
void _checkCreation()
Test la création à la volée des variables, avec multi-threading.
MaterialVariableCellReal m_mat_not_used_real
Variable pour tester la bonne prise en compte de setUsed(false)
void _fillDensity(IMeshMaterial *mat, VariableCellReal &tmp_cell_mat_density, VariableNodeReal &tmp_node_mat_density, Int32Array &mat_to_add_array, Int32Array &mat_to_remove_array, bool is_compute_mat)
void _testComponentPart(IMeshMaterial *mat, IMeshEnvironment *env)
Teste les itérateurs par partie.
IMeshPartitioner * m_mesh_partitioner
Partitioner en cas d'équilibrage. Est géré par une option du JDD.
Integer size() const
Nombre d'éléments du vecteur.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
Interface d'un service de test unitaire.
virtual void initializeTest()=0
Méthode appelée après lecture du jeu de données pour initialiser le test.
virtual void executeTest()=0
Méthode appelée pour exécuter le test.
@ PNoDump
Indique que la variable ne doit pas être sauvegardée.
Classe utilitaire pour imprimer les infos sur une entité.
Int32 nbNode() const
Nombre de noeuds de l'entité
NodeLocalIdView nodeIds() const
Liste des noeuds de l'entité
constexpr Int32 localId() const
Identifiant local de l'entité dans le sous-domaine du processeur.
ItemUniqueId uniqueId() const
Identifiant unique sur tous les domaines.
void fill(const DataType &value)
Remplit les valeurs partielles et globales de la variable avec la valeur value.
Vue sur un vecteur sur les entités d'un composant.
Cell globalCell() const
Maille globale.
__host__ __device__ ComponentCell superCell() const
Maille de niveau supérieur dans la hiérarchie.
__host__ __device__ MatVarIndex _varIndex() const
Maille arcane d'un milieu.
Interface d'un composant (matériau ou milieu) d'un maillage.
virtual String name() const =0
Nom du composant.
virtual Int32 id() const =0
Identifiant du composant.
virtual ComponentImpurePartItemVectorView impureItems() const =0
Vue sur la liste des entités impures (partielles) partielles du composant.
virtual ComponentPurePartItemVectorView pureItems() const =0
Vue sur la liste des entités pures (associées à la maille globale) du composant.
Interface d'un milieu d'un maillage.
virtual EnvImpurePartItemVectorView impureEnvItems() const =0
Vue sur la liste des entités impures (partielles) partielles du milieu.
virtual EnvPurePartItemVectorView pureEnvItems() const =0
Vue sur la liste des entités pures (associées à la maille globale) du milieu.
Interface d'un matériau d'un maillage.
virtual MatImpurePartItemVectorView impureMatItems() const =0
Vue sur la liste des entités impures (partielles) partielles du matériau.
virtual MatPurePartItemVectorView pureMatItems() const =0
Vue sur la liste des entités pures (associées à la maille globale) du matériau.
Représente un matériau d'une maille multi-matériau.
Vue sur un vecteur sur les entités d'un matériau.
Représente un index sur les variables matériaux et milieux.
constexpr __host__ __device__ Int32 arrayIndex() const
Retourne l'indice du tableau de valeur dans la liste des variables.
Options d'exécution d'une boucle parallèle en multi-thread.
void setGrainSize(Integer v)
Positionne la taille (approximative) d'un intervalle d'itération.
Vérification de la validité de certaines valeurs.
void areEqual(const T1 &value, const T2 &expected_value, const String &message)
void arcaneParallelFor(Integer i0, Integer size, InstanceType *itype, void(InstanceType::*lambda_function)(Integer i0, Integer size))
Applique en concurrence la fonction lambda lambda_function sur l'intervalle d'itération [i0,...
__host__ __device__ Real2 min(Real2 a, Real2 b)
Retourne le minimum de deux Real2.
ItemGroupT< Cell > CellGroup
Groupe de mailles.
ItemGroupT< Face > FaceGroup
Groupe de faces.
MeshVariableScalarRefT< Cell, Real > VariableCellReal
Grandeur au centre des mailles de type réel.
MeshVariableScalarRefT< Node, Real > VariableNodeReal
Grandeur au noeud de type réel.
auto viewOut(const ViewBuildInfo &vbi, CellMaterialVariableScalarRef< DataType > &var)
Vue en écriture pour les variables materiaux scalaire.
eExecutionPolicy
Politique d'exécution pour un Runner.
Real toReal(Real r)
Converti r en un Real.
ComponentItemVector ComponentCellVector
Liste de ComponentCell issues d'un IMeshComponent.
ConstArrayView< IMeshComponent * > MeshComponentList
Liste de composants multi-matériaux du maillage.
CellEnvironmentVariableArrayRef< Real > EnvironmentVariableCellArrayReal
Variable milieu de type tableau de Real
CellMaterialVariableScalarRef< Int64 > MaterialVariableCellInt64
Variable matériau de type Int64
CellEnvironmentVariableScalarRef< Real > EnvironmentVariableCellReal
Variable milieu de type Real
CellMaterialVariableScalarRef< Real > MaterialVariableCellReal
Variable matériau de type Real
MatVarSpace
Espace de définition d'une variable matériau.
CellMaterialVariableScalarRef< Int32 > MaterialVariableCellInt32
Variable matériau de type Int32
CellMaterialVariableArrayRef< Real > MaterialVariableCellArrayReal
Variable matériau de type tableau de Real
void Foreach(const ItemVectorView &items_view, const ParallelLoopOptions &options, InstanceType *instance, void(InstanceType::*function)(ItemVectorViewT< ItemType > items))
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
UniqueArray< Real > RealUniqueArray
Tableau dynamique à une dimension de réels.
double Real
Type représentant un réel.
Array< Int32 > Int32Array
Tableau dynamique à une dimension d'entiers 32 bits.
ArrayView< Real > RealArrayView
Equivalent C d'un tableau à une dimension de réels.
@ Cell
Le maillage est AMR par maille.
std::int32_t Int32
Type entier signé sur 32 bits.