14#include "arcane/utils/ScopedPtr.h"
15#include "arcane/utils/PlatformUtils.h"
16#include "arcane/utils/OStringStream.h"
17#include "arcane/utils/ArithmeticException.h"
18#include "arcane/utils/ValueChecker.h"
21#include "arcane/utils/SimdOperation.h"
23#include "arcane/core/BasicUnitTest.h"
24#include "arcane/core/ServiceBuilder.h"
25#include "arcane/core/FactoryService.h"
27#include "arcane/core/materials/internal/IMeshComponentInternal.h"
30#include "arcane/materials/IMeshMaterialMng.h"
31#include "arcane/materials/IMeshMaterial.h"
32#include "arcane/materials/IMeshEnvironment.h"
33#include "arcane/materials/MeshEnvironmentBuildInfo.h"
34#include "arcane/materials/MeshMaterialModifier.h"
35#include "arcane/materials/MatCellVector.h"
36#include "arcane/materials/EnvCellVector.h"
37#include "arcane/materials/MatItemEnumerator.h"
38#include "arcane/materials/MeshMaterialVariableRef.h"
39#include "arcane/materials/MeshEnvironmentVariableRef.h"
40#include "arcane/materials/EnvItemVector.h"
42#include "arcane/tests/ArcaneTestGlobal.h"
51# define PRAGMA_IVDEP_VALUE "clang loop vectorize(enable)"
53# ifdef __INTEL_COMPILER
54# define PRAGMA_IVDEP_VALUE "ivdep"
59# pragma GCC optimize ("-ftree-vectorize")
60# define PRAGMA_IVDEP_VALUE "GCC ivdep"
67#ifdef PRAGMA_IVDEP_VALUE
68#define PRAGMA_IVDEP _Pragma(PRAGMA_IVDEP_VALUE)
71#define PRAGMA_IVDEP_VALUE ""
78MATERIALS_BEGIN_NAMESPACE
88 String compiler_name =
"Unknown";
92 compiler_name =
"Clang";
93 version_major = __clang_major__;
94 version_minor = __clang_minor__;
96#ifdef __INTEL_COMPILER
97 compiler_name =
"ICC";
98 version_major = __INTEL_COMPILER / 100;
99 version_minor = __INTEL_COMPILER % 100;
102 compiler_name =
"GCC";
103 version_major = __GNUC__;
104 version_minor = __GNUC_MINOR__;
108 ostr() << compiler_name <<
" " << version_major <<
"." << version_minor;
121#define USE_SQRT_IN_EOS 1
123#if USE_SQRT_IN_EOS == 1
124#define DO_SQRT(v) math::sqrt( v )
126#define DO_SQRT(v) (v)
135class FullComponentPartCellEnumerator
141 : m_index(0), m_component(component)
143 m_items_view[0] = pure_view;
144 m_items_view[1] = mixed_view;
156 bool hasNext()
const {
return m_index<2; }
159 return m_items_view[m_index];
171#define ENUMERATE_ENVCELL2(iname,env) \
172 for( FullComponentPartCellEnumerator iname##_part(Arcane::Materials::FullComponentPartCellEnumerator::create(env)); iname##_part . hasNext(); ++ iname##_part ) \
174 A_ENUMERATE_COMPONENTCELL(ComponentPartCellEnumerator,iname,*(iname##_part))
179MATERIALS_END_NAMESPACE
185ARCANETEST_BEGIN_NAMESPACE
201 PerfTimer(
const char* msg)
202 : m_begin_time(0.0), m_msg(msg), m_has_error(false)
209 Real true_time_v = end_time - m_begin_time;
210 double true_time = (double)(true_time_v);
211 std::cout <<
" -- -- Time: ";
213 std::cout << m_msg <<
" = ";
215 std::cout <<
"ERROR";
217 std::cout << (true_time);
221 void setError(
bool v) { m_has_error = v; }
234class MeshMaterialSimdUnitTest
235:
public BasicUnitTest
240 ~MeshMaterialSimdUnitTest()
override;
273 void _initializeVariables();
275 void _executeTest1(
Integer nb_z);
276 void _executeTest1_bis(
Integer nb_z);
277 void _executeTest2(
Integer nb_z);
278 void _executeTest2_bis(
Integer nb_z);
279 void _executeTest3(
Integer nb_z);
280 void _executeTest5(
Integer nb_z);
281 void _executeTest6(
Integer nb_z);
282 void _executeTest7(
Integer nb_z);
283 void _executeTest8(
Integer nb_z);
284 void _executeTest9(
Integer nb_z);
285 void _executeTest10(
Integer nb_z);
286 void _initForEquationOfState();
287 void _compareValues();
288 void _computeEquationOfStateReference();
289 void _computeEquationOfStateDirect1();
290 void _computeEquationOfStateIndirect1();
291 void _computeEquationOfStateV1();
292 void _computeEquationOfStateV1_bis();
293 void _computeEquationOfStateV2();
294 void _computeEquationOfStateV3();
295 void _computeEquationOfStateV4();
296 void _computeEquationOfStateV4_noview();
298 template<
typename Lambda>
299 bool _apply(
const char* message,Lambda&& lambda)
301 bool has_error =
false;
303 PerfTimer pf(message);
310 info() <<
"ArithmeticException for '" << message <<
"'";
316 template<
typename Lambda>
317 void _applyCompare(
const char* message,Lambda&& lambda)
319 _initForEquationOfState();
320 bool has_error = _apply(message,lambda);
335MeshMaterialSimdUnitTest::
361MeshMaterialSimdUnitTest::
362~MeshMaterialSimdUnitTest()
364 delete m_env1_as_vector;
377 for(
String v : mat_names ){
409 Int64 total_nb_cell = nb_cell;
413 if (cell_index<((2*total_nb_cell)/3)){
414 env1_indexes.
add(icell.itemLocalId());
416 if (cell_index<(total_nb_cell/2) && cell_index>(total_nb_cell/3)){
417 mat2_indexes.
add(icell.itemLocalId());
419 if ((cell_index%2)==0)
420 sub_group_indexes.
add(icell.itemLocalId());
432 for(
Integer z=0; z<nb_cell; ++z ){
433 bool add_to_mat1 = (z<(nb_cell/2) && z>(nb_cell/4));
434 bool add_to_mat2 = (z>=(nb_cell/2) || z<(nb_cell/3));
436 mat1_indexes.
add(env1_indexes[z]);
439 mat2_indexes.
add(env1_indexes[z]);
442 modifier.
addCells(mat1,mat1_indexes);
452 modifier.
addCells(mat2,mat2_indexes);
457 info() <<
"** ** ENV name=" << env->name() <<
" nb_item=" << env->view().nbItem();
460 if ( (*ienvcell).allEnvCell().nbEnvironment()==1 )
463 info() <<
"** ** NB_PURE=" << nb_pure_env;
473 m_env1_pure_value_index.clear();
474 m_env1_partial_value_index.clear();
482 m_env1_pure_value_index.add(mvi.
valueIndex());
484 m_env1_partial_value_index.add(mvi.
valueIndex());
489 m_env1_as_vector =
new EnvCellVector(m_env1->cells(),m_env1);
496 Int32 env_idx = m_env1->_internalApi()->variableIndexerIndex() + 1;
497 info() <<
"Using vectorisation name=" << SimdInfo::name()
498 <<
" vector_size=" << SimdReal::Length <<
" index_size=" << SimdInfo::Int32IndexSize;
499 info() <<
"Compiler=\"" << getCompilerInfo() <<
"\""
501 info() <<
"use_sqrt_in_eos?=" << USE_SQRT_IN_EOS
502 <<
" PRAGMA_IVDEP=" << PRAGMA_IVDEP_VALUE;
503 info() <<
"ENV_IDX=" << env_idx
504 <<
" nb_pure=" << m_env1_pure_value_index.size()
505 <<
" nb_partial=" << m_env1_partial_value_index.size()
506 <<
" nb_unknown=" << nb_unknown
507 <<
" nb_z=" << nb_z <<
" nb_z2=" << nb_z2;
509 _initializeVariables();
511 PerfTimer pf(
"executeDirect1");
512 _executeDirect1(nb_z);
515 PerfTimer pf(
"executeTest1 (ENVCELL)");
519 PerfTimer pf(
"executeTest1_bis (ENVCELL2)");
520 _executeTest1_bis(nb_z);
523 PerfTimer pf(
"executeTest2 (ENVCELL,IVDEP,view)");
527 PerfTimer pf(
"executeTest2_bis (ENVCELL2,view)");
528 _executeTest2_bis(nb_z);
531 PerfTimer pf(
"executeTest3 (2 loops)");
535 PerfTimer pf(
"executeTest4 (2 loops, ivdep)");
539 PerfTimer pf(
"executeTest5 (2 loops, functor)");
543 PerfTimer pf(
"executeTest6 (2 loops, functor)");
547 PerfTimer pf(
"executeTest7 (2 loops, loop functor)");
551 PerfTimer pf(
"executeTest8 (simple_env_loop)");
555 PerfTimer pf(
"executeTest9 (SIMD_ENVCELL)");
559 PerfTimer pf(
"executeTest10 (SIMD_ENVCELL, functor)");
560 _executeTest10(nb_z);
563 _initForEquationOfState();
564 _computeEquationOfStateReference();
565 _apply(
"_computeEquationOfStateDirect1",
566 [&](){_computeEquationOfStateDirect1();});
567 _apply(
"_computeEquationOfStateIndirect1",
568 [&](){_computeEquationOfStateIndirect1();});
569 _applyCompare(
"_computeEquationOfStateV1 (ENVCELL)",
570 [&](){_computeEquationOfStateV1();});
571 _applyCompare(
"_computeEquationOfStateV1_bis (ENVCELL2)",
572 [&](){_computeEquationOfStateV1_bis();});
574 _applyCompare(
"_computeEquationOfStateV2 (simple_simd_env_loop)",
575 [&](){_computeEquationOfStateV2();});
576 _applyCompare(
"_computeEquationOfStateV3 (simple_env_loop)",
577 [&](){_computeEquationOfStateV3();});
579 _applyCompare(
"_computeEquationOfStateV4 (lambda simple_env_loop2)",
580 [&](){_computeEquationOfStateV4();});
581 _applyCompare(
"_computeEquationOfStateV4_noview (lambda simple_env_loop2)",
582 [&](){_computeEquationOfStateV4_noview();});
589void MeshMaterialSimdUnitTest::
590_initializeVariables()
599 Real z = (Real)i.index();
611Real MeshMaterialSimdUnitTest::
614 Integer TRUE_SIZE = m_env1->cells().size();
615 Real ARCANE_RESTRICT *a =
new Real[TRUE_SIZE];
620#pragma omp parallel for
621 for(
Integer i=0, is=TRUE_SIZE; i<is; ++i ){
623 a[i] = b[i] = c[i] = d[i] = e[i] = z;
626 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
627 for(
Integer i=0, is=TRUE_SIZE; i<is; ++i ){
628 a[i] = b[i] + c[i] * d[i] + e[i];
643void MeshMaterialSimdUnitTest::
652 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
654 a[i] = b[i] + c[i] * d[i] + e[i];
662void MeshMaterialSimdUnitTest::
671 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
672 ENUMERATE_ENVCELL2(i,m_env1){
673 a[i] = b[i] + c[i] * d[i] + e[i];
681void MeshMaterialSimdUnitTest::
690 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
697#ifndef __INTEL_COMPILER
701 a[i] = b[i] + c[i] * d[i] + e[i];
709void MeshMaterialSimdUnitTest::
718 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
719 ENUMERATE_ENVCELL2(i,m_env1){
720 a[i] = b[i] + c[i] * d[i] + e[i];
728void MeshMaterialSimdUnitTest::
737 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
742 Int32 xi = indexes[i];
743 MatVarIndex mvi(0,xi);
744 a[mvi] = b[mvi] + c[mvi] * d[mvi] + e[mvi];
749 Int32 env_idx = m_env1->_internalApi()->variableIndexerIndex() + 1;
752 Int32 xi = indexes[i];
753 MatVarIndex mvi(env_idx,xi);
754 a[mvi] = b[mvi] + c[mvi] * d[mvi] + e[mvi];
763void MeshMaterialSimdUnitTest::
775 Int32 xi = indexes[i];
776 MatVarIndex mvi(env_idx,xi);
777 a[mvi] = b[mvi] + c[mvi] * d[mvi] + e[mvi];
781 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
782 Int32 env_idx = m_env1->_internalApi()->variableIndexerIndex() + 1;
783 func(0,m_env1_pure_value_index);
784 func(env_idx,m_env1_partial_value_index);
791void MeshMaterialSimdUnitTest::
803 Int32 xi = indexes[i];
804 MatVarIndex mvi(env_idx,xi);
805 a[mvi] = b[mvi] + c[mvi] * d[mvi] + e[mvi];
809 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
811 ComponentPartItemVectorView pv = m_env1_as_vector->pureItems();
815 ComponentPartItemVectorView pv = m_env1_as_vector->impureItems();
824template<
typename Lambda>
void
831void MeshMaterialSimdUnitTest::
840 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
841 env_loop(*m_env1_as_vector,[=](ComponentPartItemVectorView view){
843 a[mvi] = b[mvi] + c[mvi] * d[mvi] + e[mvi];
851template<
typename Lambda>
void
854 const Lambda& lambda)
857 views[0] = pure_items;
858 views[1] = impure_items;
860 for(
Integer iview=0; iview<2; ++iview ){
861 const auto& xiter = views[iview];
862 Int32 cpi = xiter.componentPartIndex();
864 Integer nb_item = xiter.nbItem();
867 for(
Integer i=0; i<nb_item; ++i ){
875template<
typename ContainerType,
typename Lambda>
void
878 simple_env_loop(ct.pureItems(),ct.impureItems(),lambda);
881template<
typename Lambda>
void
884 const Lambda& lambda)
887 views[0] = pure_items;
888 views[1] = impure_items;
891 auto view = views[0];
893 Integer nb_item = view.nbItem();
895 for(
Integer i=0; i<nb_item; ++i ){
902 auto view = views[1];
903 Int32 cpi = view.componentPartIndex();
904 Integer nb_item = view.nbItem();
907 for(
Integer i=0; i<nb_item; ++i ){
911 ComponentItemLocalId mvi(
MatVarIndex(cpi,item_indexes[i]));
917template<
typename ContainerType,
typename Lambda>
void
918simple_env_loop2(
const ContainerType& ct,
const Lambda& lambda)
920 simple_env_loop2(ct.pureItems(),ct.impureItems(),lambda);
923void MeshMaterialSimdUnitTest::
932 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
933 simple_env_loop(*m_env1_as_vector,[=](MatVarIndex mvi){
934 a[mvi] = b[mvi] + c[mvi] * d[mvi] + e[mvi];
942void MeshMaterialSimdUnitTest::
951 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
952 env_loop(*m_env1_as_vector,[=](ComponentPartItemVectorView view){
953 ENUMERATE_SIMD_COMPONENTCELL(mvi,view){
954 a[mvi] = b[mvi] + c[mvi] * d[mvi] + e[mvi];
963#define A_ENUMERATE_LAMBDA(iter_type,iter,container,...) \
964 Arcane::Materials:: LoopFunctor ## iter_type ( (container) ) << __VA_ARGS__ ( Arcane::Materials:: LoopFunctor ## iter_type :: IterType iter)
966#define A_CAPTURE(a) a
967#define A_ENUMERATE_LAMBDA2(iter_type,iter,container,lambda_capture) \
968 Arcane::Materials:: LoopFunctor ## iter_type ( (container) ) << A_CAPTURE(lambda_capture) ( Arcane::Materials:: LoopFunctor ## iter_type :: IterType iter)
970#define A_ENUMERATE_LAMBDA3(iter_type,iter,container) \
971 Arcane::Materials:: LoopFunctor ## iter_type ( (container) ) <<
976template<
typename Lambda>
void
977simple_simd_env_loop(
const EnvCellVector& env,
const Lambda& lambda)
985void MeshMaterialSimdUnitTest::
994 for(
Integer z=0, iz=nb_z; z<iz; ++z ){
995 simple_simd_env_loop(*m_env1_as_vector,[=](
const SimdMatVarIndex& mvi){
996 a[mvi] = b[mvi] + c[mvi] * d[mvi] + e[mvi];
1004void MeshMaterialSimdUnitTest::
1005_initForEquationOfState()
1008 EnvCellEnumerator vi = icell;
1009 m_mat_adiabatic_cst[vi] = 1.4;
1010 m_mat_volume[vi] = 1.2;
1011 m_mat_old_volume[vi] = 1.1;
1013 m_mat_density[vi] = 2.0;
1014 m_mat_pressure[vi] = 1.1;
1016 m_mat_internal_energy[vi] = m_mat_pressure[icell] / ((m_mat_adiabatic_cst[icell]-1.0) * m_mat_density[icell]);
1023void MeshMaterialSimdUnitTest::
1024_computeEquationOfStateDirect1()
1026 Int32 nb_z = m_nb_z;
1027 Integer TRUE_SIZE = m_env1->cells().size();
1029 auto in_adiabatic_cst =
new Real[TRUE_SIZE];
1030 auto in_volume =
new Real[TRUE_SIZE];
1031 auto in_density =
new Real[TRUE_SIZE];
1032 auto in_old_volume =
new Real[TRUE_SIZE];
1033 auto in_internal_energy =
new Real[TRUE_SIZE];
1035 auto out_internal_energy = in_internal_energy;
1036 auto out_sound_speed =
new Real[TRUE_SIZE];
1037 auto out_pressure =
new Real[TRUE_SIZE];
1039 for(
Integer i=0, is=TRUE_SIZE; i<is; ++i ){
1041 in_adiabatic_cst[vi] = 1.4;
1042 in_volume[vi] = 1.2;
1043 in_old_volume[vi] = 1.1;
1045 in_density[vi] = 2.0;
1046 Real in_pressure = 1.1;
1048 in_internal_energy[vi] = in_pressure / ((in_adiabatic_cst[vi]-1.0) * in_density[vi]);
1050 for(
Int32 iloop=0; iloop<nb_z; ++iloop){
1053 for(
Integer i=0, n=TRUE_SIZE; i<n; ++i ){
1055 Real adiabatic_cst = in_adiabatic_cst[vi];
1056 Real volume_ratio = in_volume[vi] / in_old_volume[vi];
1057 Real x = 0.5 * adiabatic_cst - 1.0;
1058 Real numer_accrois_nrj = 1.0 + x*(1.0-volume_ratio);
1059 Real denom_accrois_nrj = 1.0 + x*(1.0-(1.0/volume_ratio));
1060 Real internal_energy = in_internal_energy[vi];
1061 internal_energy = internal_energy * (numer_accrois_nrj/denom_accrois_nrj);
1062 out_internal_energy[vi] = internal_energy;
1063 Real density = in_density[vi];
1064 Real pressure = (adiabatic_cst - 1.0) * density * internal_energy;
1065 Real sound_speed = DO_SQRT((adiabatic_cst*pressure/density));
1066 out_pressure[vi] = pressure;
1067 out_sound_speed[vi] = sound_speed;
1070 delete[] in_adiabatic_cst;
1072 delete[] in_density;
1073 delete[] in_old_volume;
1074 delete[] in_internal_energy;
1075 delete[] out_sound_speed;
1076 delete[] out_pressure;
1082void MeshMaterialSimdUnitTest::
1083_computeEquationOfStateIndirect1()
1085 Int32 nb_z = m_nb_z;
1086 Integer TRUE_SIZE = m_env1->cells().size();
1088 auto in_adiabatic_cst =
new Real[TRUE_SIZE];
1089 auto in_volume =
new Real[TRUE_SIZE];
1090 auto in_density =
new Real[TRUE_SIZE];
1091 auto in_old_volume =
new Real[TRUE_SIZE];
1092 auto in_internal_energy =
new Real[TRUE_SIZE];
1094 auto out_internal_energy = in_internal_energy;
1095 auto out_sound_speed =
new Real[TRUE_SIZE];
1096 auto out_pressure =
new Real[TRUE_SIZE];
1098 ARCANE_RESTRICT
Int32* idx =
new Int32[TRUE_SIZE];
1100 for(
Integer i=0, is=TRUE_SIZE; i<is; ++i ){
1104 in_adiabatic_cst[vi] = 1.4;
1105 in_volume[vi] = 1.2;
1106 in_old_volume[vi] = 1.1;
1108 in_density[vi] = 2.0;
1109 Real in_pressure = 1.1;
1111 in_internal_energy[vi] = in_pressure / ((in_adiabatic_cst[vi]-1.0) * in_density[vi]);
1113 for(
Int32 iloop=0; iloop<nb_z; ++iloop){
1116 for(
Integer i=0, n=TRUE_SIZE; i<n; ++i ){
1118 Real adiabatic_cst = in_adiabatic_cst[vi];
1119 Real volume_ratio = in_volume[vi] / in_old_volume[vi];
1120 Real x = 0.5 * adiabatic_cst - 1.0;
1121 Real numer_accrois_nrj = 1.0 + x*(1.0-volume_ratio);
1122 Real denom_accrois_nrj = 1.0 + x*(1.0-(1.0/volume_ratio));
1123 Real internal_energy = in_internal_energy[vi];
1124 internal_energy = internal_energy * (numer_accrois_nrj/denom_accrois_nrj);
1125 out_internal_energy[vi] = internal_energy;
1126 Real density = in_density[vi];
1127 Real pressure = (adiabatic_cst - 1.0) * density * internal_energy;
1128 Real sound_speed = DO_SQRT((adiabatic_cst*pressure/density));
1129 out_pressure[vi] = pressure;
1130 out_sound_speed[vi] = sound_speed;
1134 delete[] in_adiabatic_cst;
1136 delete[] in_density;
1137 delete[] in_old_volume;
1138 delete[] in_internal_energy;
1139 delete[] out_sound_speed;
1140 delete[] out_pressure;
1146void MeshMaterialSimdUnitTest::
1147_computeEquationOfStateReference()
1149 Int32 nb_z = m_nb_z;
1151 auto in_adiabatic_cst =
viewIn(m_mat_adiabatic_cst);
1152 auto in_volume =
viewIn(m_mat_volume);
1153 auto in_density =
viewIn(m_mat_density);
1154 auto in_old_volume =
viewIn(m_mat_old_volume);
1155 auto in_internal_energy =
viewIn(m_mat_internal_energy);
1157 for(
Int32 iloop=0; iloop<nb_z; ++iloop){
1160 Real adiabatic_cst = in_adiabatic_cst[vi];
1161 Real volume_ratio = in_volume[vi] / in_old_volume[vi];
1162 Real x = 0.5 * adiabatic_cst - 1.0;
1163 Real numer_accrois_nrj = 1.0 + x*(1.0-volume_ratio);
1164 Real denom_accrois_nrj = 1.0 + x*(1.0-(1.0/volume_ratio));
1165 Real internal_energy = in_internal_energy[vi];
1166 internal_energy = internal_energy * (numer_accrois_nrj/denom_accrois_nrj);
1167 m_mat_internal_energy[vi] = internal_energy;
1168 Real density = in_density[vi];
1169 Real pressure = (adiabatic_cst - 1.0) * density * internal_energy;
1170 Real sound_speed = DO_SQRT(adiabatic_cst*pressure/density);
1171 m_mat_pressure[vi] = pressure;
1172 m_mat_sound_speed[vi] = sound_speed;
1176 m_mat_ref_internal_energy[vi] = m_mat_internal_energy[vi];
1177 m_mat_ref_pressure[vi] = m_mat_pressure[vi];
1178 m_mat_ref_sound_speed[vi] = m_mat_sound_speed[vi];
1185void MeshMaterialSimdUnitTest::
1188 ValueChecker vc(A_FUNCINFO);
1190 vc.areEqual(m_mat_internal_energy[icell],m_mat_ref_internal_energy[icell],
"Energy");
1191 vc.areEqual(m_mat_pressure[icell],m_mat_ref_pressure[icell],
"Pressure");
1192 vc.areEqual(m_mat_sound_speed[icell],m_mat_ref_sound_speed[icell],
"SoundSpeed");
1199void MeshMaterialSimdUnitTest::
1200_computeEquationOfStateV1()
1202 Int32 nb_z = m_nb_z;
1203 auto in_adiabatic_cst =
viewIn(m_mat_adiabatic_cst);
1204 auto in_volume =
viewIn(m_mat_volume);
1205 auto in_density =
viewIn(m_mat_density);
1206 auto in_old_volume =
viewIn(m_mat_old_volume);
1207 auto in_internal_energy =
viewIn(m_mat_internal_energy);
1209 auto out_internal_energy =
viewOut(m_mat_internal_energy);
1210 auto out_sound_speed =
viewOut(m_mat_sound_speed);
1211 auto out_pressure =
viewOut(m_mat_pressure);
1213 for(
Int32 iloop=0; iloop<nb_z; ++iloop){
1218 Real adiabatic_cst = in_adiabatic_cst[vi];
1219 Real volume_ratio = in_volume[vi] / in_old_volume[vi];
1220 Real x = 0.5 * adiabatic_cst - 1.0;
1221 Real numer_accrois_nrj = 1.0 + x*(1.0-volume_ratio);
1222 Real denom_accrois_nrj = 1.0 + x*(1.0-(1.0/volume_ratio));
1223 Real internal_energy = in_internal_energy[vi];
1224 internal_energy = internal_energy * (numer_accrois_nrj/denom_accrois_nrj);
1225 out_internal_energy[vi] = internal_energy;
1226 Real density = in_density[vi];
1227 Real pressure = (adiabatic_cst - 1.0) * density * internal_energy;
1228 Real sound_speed = DO_SQRT(adiabatic_cst*pressure/density);
1229 out_pressure[vi] = pressure;
1230 out_sound_speed[vi] = sound_speed;
1238void MeshMaterialSimdUnitTest::
1239_computeEquationOfStateV1_bis()
1241 Int32 nb_z = m_nb_z;
1242 auto in_adiabatic_cst =
viewIn(m_mat_adiabatic_cst);
1243 auto in_volume =
viewIn(m_mat_volume);
1244 auto in_density =
viewIn(m_mat_density);
1245 auto in_old_volume =
viewIn(m_mat_old_volume);
1246 auto in_internal_energy =
viewIn(m_mat_internal_energy);
1248 auto out_internal_energy =
viewOut(m_mat_internal_energy);
1249 auto out_sound_speed =
viewOut(m_mat_sound_speed);
1250 auto out_pressure =
viewOut(m_mat_pressure);
1252 for(
Int32 iloop=0; iloop<nb_z; ++iloop){
1254 ENUMERATE_ENVCELL2(icell,m_env1){
1256 Real adiabatic_cst = in_adiabatic_cst[vi];
1257 Real volume_ratio = in_volume[vi] / in_old_volume[vi];
1258 Real x = 0.5 * adiabatic_cst - 1.0;
1259 Real numer_accrois_nrj = 1.0 + x*(1.0-volume_ratio);
1260 Real denom_accrois_nrj = 1.0 + x*(1.0-(1.0/volume_ratio));
1261 Real internal_energy = in_internal_energy[vi];
1262 internal_energy = internal_energy * (numer_accrois_nrj/denom_accrois_nrj);
1263 out_internal_energy[vi] = internal_energy;
1264 Real density = in_density[vi];
1265 Real pressure = (adiabatic_cst - 1.0) * density * internal_energy;
1266 Real sound_speed = DO_SQRT((adiabatic_cst*pressure/density));
1267 out_pressure[vi] = pressure;
1268 out_sound_speed[vi] = sound_speed;
1276void MeshMaterialSimdUnitTest::
1277_computeEquationOfStateV3()
1279 Int32 nb_z = m_nb_z;
1280 auto in_adiabatic_cst =
viewIn(m_mat_adiabatic_cst);
1281 auto in_volume =
viewIn(m_mat_volume);
1282 auto in_density =
viewIn(m_mat_density);
1283 auto in_old_volume =
viewIn(m_mat_old_volume);
1284 auto in_internal_energy =
viewIn(m_mat_internal_energy);
1286 auto out_internal_energy =
viewOut(m_mat_internal_energy);
1287 auto out_sound_speed =
viewOut(m_mat_sound_speed);
1288 auto out_pressure =
viewOut(m_mat_pressure);
1290 for(
Int32 iloop=0; iloop<nb_z; ++iloop){
1292 auto func = [=](MatVarIndex vi){
1293 Real adiabatic_cst = in_adiabatic_cst[vi];
1294 Real volume_ratio = in_volume[vi] / in_old_volume[vi];
1295 Real x = 0.5 * adiabatic_cst - 1.0;
1296 Real numer_accrois_nrj = 1.0 + x*(1.0-volume_ratio);
1297 Real denom_accrois_nrj = 1.0 + x*(1.0-(1.0/volume_ratio));
1298 Real internal_energy = in_internal_energy[vi];
1299 internal_energy = internal_energy * (numer_accrois_nrj/denom_accrois_nrj);
1300 out_internal_energy[vi] = internal_energy;
1301 Real density = in_density[vi];
1302 Real pressure = (adiabatic_cst - 1.0) * density * internal_energy;
1303 Real sound_speed = DO_SQRT((adiabatic_cst*pressure/density));
1304 out_pressure[vi] = pressure;
1305 out_sound_speed[vi] = sound_speed;
1307 simple_env_loop(*m_env1,func);
1314void MeshMaterialSimdUnitTest::
1315_computeEquationOfStateV2()
1317 Int32 nb_z = m_nb_z;
1318 auto in_adiabatic_cst =
viewIn(m_mat_adiabatic_cst);
1319 auto in_volume =
viewIn(m_mat_volume);
1320 auto in_density =
viewIn(m_mat_density);
1321 auto in_old_volume =
viewIn(m_mat_old_volume);
1322 auto in_internal_energy =
viewIn(m_mat_internal_energy);
1324 auto out_internal_energy =
viewOut(m_mat_internal_energy);
1325 auto out_sound_speed =
viewOut(m_mat_sound_speed);
1326 auto out_pressure =
viewOut(m_mat_pressure);
1328 for(
Int32 iloop=0; iloop<nb_z; ++iloop){
1332 SimdReal adiabatic_cst = in_adiabatic_cst[vi];
1333 SimdReal volume_ratio = in_volume[vi] / in_old_volume[vi];
1334 SimdReal x = 0.5 * adiabatic_cst - 1.0;
1335 SimdReal numer_accrois_nrj = 1.0 + x*(1.0-volume_ratio);
1336 SimdReal denom_accrois_nrj = 1.0 + x*(1.0-(1.0/volume_ratio));
1337 SimdReal internal_energy = in_internal_energy[vi];
1338 internal_energy = internal_energy * (numer_accrois_nrj/denom_accrois_nrj);
1339 out_internal_energy[vi] = internal_energy;
1341 SimdReal pressure = (adiabatic_cst - 1.0) * density * internal_energy;
1342 SimdReal sound_speed = DO_SQRT((adiabatic_cst*pressure/density));
1343 out_pressure[vi] = pressure;
1344 out_sound_speed[vi] = sound_speed;
1352void MeshMaterialSimdUnitTest::
1353_computeEquationOfStateV4()
1355 Int32 nb_z = m_nb_z;
1356 auto in_adiabatic_cst =
viewIn(m_mat_adiabatic_cst);
1357 auto in_volume =
viewIn(m_mat_volume);
1358 auto in_density =
viewIn(m_mat_density);
1359 auto in_old_volume =
viewIn(m_mat_old_volume);
1360 auto in_internal_energy =
viewIn(m_mat_internal_energy);
1362 auto out_internal_energy =
viewOut(m_mat_internal_energy);
1363 auto out_sound_speed =
viewOut(m_mat_sound_speed);
1364 auto out_pressure =
viewOut(m_mat_pressure);
1366 for(
Int32 iloop=0; iloop<nb_z; ++iloop){
1368 auto func = [=](
auto vi){
1369 Real adiabatic_cst = in_adiabatic_cst[vi];
1370 Real volume_ratio = in_volume[vi] / in_old_volume[vi];
1371 Real x = 0.5 * adiabatic_cst - 1.0;
1372 Real numer_accrois_nrj = 1.0 + x*(1.0-volume_ratio);
1373 Real denom_accrois_nrj = 1.0 + x*(1.0-(1.0/volume_ratio));
1374 Real internal_energy = in_internal_energy[vi];
1375 internal_energy = internal_energy * (numer_accrois_nrj/denom_accrois_nrj);
1376 out_internal_energy[vi] = internal_energy;
1377 Real density = in_density[vi];
1378 Real pressure = (adiabatic_cst - 1.0) * density * internal_energy;
1379 Real sound_speed = DO_SQRT((adiabatic_cst*pressure/density));
1380 out_pressure[vi] = pressure;
1381 out_sound_speed[vi] = sound_speed;
1383 simple_env_loop2(*m_env1_as_vector,func);
1390void MeshMaterialSimdUnitTest::
1391_computeEquationOfStateV4_noview()
1393 Int32 nb_z = m_nb_z;
1395 for(
Int32 iloop=0; iloop<nb_z; ++iloop){
1397 auto func = [&](
auto vi){
1398 Real adiabatic_cst = m_mat_adiabatic_cst[vi];
1399 Real volume_ratio = m_mat_volume[vi] / m_mat_old_volume[vi];
1400 Real x = 0.5 * adiabatic_cst - 1.0;
1401 Real numer_accrois_nrj = 1.0 + x*(1.0-volume_ratio);
1402 Real denom_accrois_nrj = 1.0 + x*(1.0-(1.0/volume_ratio));
1403 Real internal_energy = m_mat_internal_energy[vi];
1404 internal_energy = internal_energy * (numer_accrois_nrj/denom_accrois_nrj);
1405 m_mat_internal_energy[vi] = internal_energy;
1406 Real density = m_mat_density[vi];
1407 Real pressure = (adiabatic_cst - 1.0) * density * internal_energy;
1408 Real sound_speed = DO_SQRT((adiabatic_cst*pressure/density));
1409 m_mat_pressure[vi] = pressure;
1410 m_mat_sound_speed[vi] = sound_speed;
1412 simple_env_loop2(*m_env1_as_vector,func);
1422ARCANETEST_END_NAMESPACE
#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.
#define ARCANE_REGISTER_CASE_OPTIONS_NOAXL_FACTORY(aclass, ainterface, aname)
Enregistre un service de fabrique pour la classe aclass.
Integer size() const
Nombre d'éléments du vecteur.
Exception lorsqu'une erreur arithmétique survient.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
Service basique de test unitaire.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
Interface d'un service de test unitaire.
Integer size() const
Nombre d'éléments du groupe.
ItemUniqueId uniqueId() const
Identifiant unique sur tous les domaines.
__host__ __device__ Int32 nbEnvironment() const
Nombre de milieux présents dans la maille.
ComponentPurePartItemVectorView pureItems() const
Liste des entités pures (associées à la maille globale) du composant.
ComponentImpurePartItemVectorView impureItems() const
Liste des entités impures (partielles) du composant.
Vue sur une partie pure ou partielles des entités d'un composant.
Int32ConstArrayView valueIndexes() const
Liste des valueIndex() de la partie.
__host__ __device__ MatVarIndex _varIndex() const
Vecteur sur les entités d'un milieu.
Maille arcane d'un milieu.
__host__ __device__ AllEnvCell allEnvCell() const
Maille contenant les infos sur tous les milieux.
Interface d'un composant (matériau ou milieu) d'un maillage.
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 ConstArrayView< IMeshMaterial * > materials()=0
Liste des matériaux de ce milieu.
virtual Integer nbMaterial() const =0
Nombre de matériaux dans le milieu.
Interface du gestionnaire des matériaux et des milieux d'un maillage.
virtual MeshMaterialInfo * registerMaterialInfo(const String &name)=0
Enregistre les infos du matériau de nom name.
virtual void endCreate(bool is_continue=false)=0
Indique qu'on a fini de créer les milieux.
virtual IMeshEnvironment * createEnvironment(const MeshEnvironmentBuildInfo &infos)=0
Créé un milieu avec les infos infos.
virtual ConstArrayView< IMeshEnvironment * > environments() const =0
Liste des milieux.
static IMeshMaterialMng * getReference(const MeshHandleOrMesh &mesh_handle, bool create=true)
Récupère ou créé la référence associée à mesh.
Interface d'un matériau d'un maillage.
virtual IMeshEnvironment * environment() const =0
Milieu auquel appartient ce matériau.
Représente un index sur les variables matériaux et milieux.
constexpr __host__ __device__ Int32 valueIndex() const
Retourne l'indice dans le tableau de valeur.
Informations pour la création d'un milieu.
void addMaterial(const String &name)
Ajoute le matériau de nom name au milieu.
Objet permettant de modifier les matériaux ou les milieux.
void addCells(IMeshMaterial *mat, SmallSpan< const Int32 > ids)
Ajoute les mailles d'indices locaux ids au matériau mat.
Index d'un Item matériaux pure dans une variable.
CellGroup allCells() const
Retourne le groupe contenant toutes les mailles.
CellGroup ownCells() const
Retourne le groupe contenant toutes les mailles propres à ce domaine.
Flot de sortie lié à une String.
Structure contenant les informations pour créer un service.
Chaîne de caractères unicode.
TraceMessage info() const
Flot pour un message d'information.
Vecteur 1D de données avec sémantique par valeur (style STL).
Paramètres nécessaires à la construction d'une variable.
Service de test unitaire de la vectorisation des matériaux/milieux.
void initializeTest() override
Méthode appelée après lecture du jeu de données pour initialiser le test.
void executeTest() override
Méthode appelée pour exécuter le test.
SimdInfo::SimdReal SimdReal
Vecteur SIMD de réel.
auto viewOut(const ViewBuildInfo &vbi, CellMaterialVariableScalarRef< DataType > &var)
Vue en écriture pour les variables materiaux scalaire.
auto viewIn(const ViewBuildInfo &vbi, const CellMaterialVariableScalarRef< DataType > &var)
Vue en lecture pour les variables materiaux scalaire.
CellMaterialVariableScalarRef< Real > MaterialVariableCellReal
Variable matériau de type Real
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
bool arcaneIsDebug()
Vrai si la macro ARCANE_DEBUG est définie.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
double Real
Type représentant un réel.
std::int32_t Int32
Type entier signé sur 32 bits.
Ensemble des classes assurant la gestion des matériaux et des milieux.