File indexing completed on 2026-04-09 07:49:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <vector>
0013 #include <iostream>
0014
0015 #include "ssys.h"
0016 #include "NPX.h"
0017 #include "S4MaterialPropertyVector.h"
0018
0019
0020 struct S4MaterialPropertyVector_test
0021 {
0022 static constexpr const char* CETHETA = R"LITERAL(
0023 array([[0. , 0.911 ],
0024 [0.226893, 0.911 ],
0025 [0.488692, 0.9222 ],
0026 [0.715585, 0.9294 ],
0027 [0.959931, 0.9235 ],
0028 [1.151917, 0.93 ],
0029 [1.37881 , 0.9095 ],
0030 [1.48353 , 0.6261 ],
0031 [1.570796, 0.2733 ]])
0032 )LITERAL" ;
0033
0034
0035 static void Populate( std::vector<G4MaterialPropertyVector*>& vv, int ni );
0036 static int VV();
0037 static int VV_CombinedArray();
0038 static int ConvertToArray();
0039
0040 static int Main();
0041 };
0042
0043
0044
0045
0046 void S4MaterialPropertyVector_test::Populate( std::vector<G4MaterialPropertyVector*>& vv, int ni )
0047 {
0048 vv.resize(ni) ;
0049 for( int i=0 ; i < ni ; i++) vv[i] = S4MaterialPropertyVector::Make_V(double(i*10.)) ;
0050 }
0051
0052
0053 int S4MaterialPropertyVector_test::VV()
0054 {
0055 std::vector<G4MaterialPropertyVector*> vv ;
0056 Populate(vv,10);
0057
0058 NPFold* fold = S4MaterialPropertyVector::Serialize_VV(vv) ;
0059
0060 std::cout << fold->desc() ;
0061
0062 std::vector<G4MaterialPropertyVector*> qq ;
0063 S4MaterialPropertyVector::Import_VV(qq, fold );
0064
0065 std::cout
0066 << "vv.size " << vv.size() << "\n"
0067 << "qq.size " << qq.size() << "\n"
0068 ;
0069 return 0 ;
0070 }
0071
0072 int S4MaterialPropertyVector_test::VV_CombinedArray()
0073 {
0074 std::vector<G4MaterialPropertyVector*> vv ;
0075 Populate(vv,10);
0076
0077 NP* vvcom = S4MaterialPropertyVector::Serialize_VV_CombinedArray(vv) ;
0078
0079 std::cout << "S4MaterialPropertyVector_test::VV_CombinedArray vvcom " << vvcom->desc() << "\n" ;
0080
0081 std::vector<G4MaterialPropertyVector*> qq ;
0082 S4MaterialPropertyVector::Import_VV_CombinedArray(qq, vvcom );
0083
0084 std::cout
0085 << "vv.size " << vv.size() << "\n"
0086 << "qq.size " << qq.size() << "\n"
0087 ;
0088
0089 vvcom->save("$FOLD/VV_CombinedArray.npy");
0090
0091 return 0 ;
0092 }
0093
0094
0095 int S4MaterialPropertyVector_test::ConvertToArray()
0096 {
0097 std::cout << "[ConvertToArray\n" ;
0098
0099 NP* cetheta = NPX::FromNumpyString<double>(CETHETA);
0100 G4MaterialPropertyVector* prop = S4MaterialPropertyVector::FromArray( cetheta );
0101 NP* cetheta_1 = S4MaterialPropertyVector::ConvertToArray(prop);
0102 bool same = NP::SameData(cetheta, cetheta_1);
0103
0104 std::cout
0105 << "-ConvertToArray"
0106 << " cetheta " << ( cetheta ? cetheta->sstr() : "-" )
0107 << " cetheta_1 " << ( cetheta_1 ? cetheta_1->sstr() : "-" )
0108 << " same " << ( same ? "YES" : "NO " )
0109 << "\n"
0110 ;
0111
0112 assert( same );
0113
0114 bool reverse = true ;
0115 NP* cecosth = NP::MakeWithCosineDomain(cetheta, reverse);
0116
0117 NPFold* fold = new NPFold ;
0118 fold->add("cetheta", cetheta );
0119 fold->add("cecosth", cecosth );
0120 fold->save("$FOLD/ConvertToArray");
0121
0122 std::cout << "]ConvertToArray\n" ;
0123 return 0 ;
0124 }
0125
0126
0127
0128
0129
0130
0131 int S4MaterialPropertyVector_test::Main()
0132 {
0133 const char* test = "ALL" ;
0134 const char* TEST = ssys::getenvvar("TEST", test);
0135 bool ALL = strcmp(TEST, "ALL") == 0 ;
0136 int rc = 0 ;
0137 if(ALL || strcmp(TEST, "VV") == 0 ) rc += VV();
0138 if(ALL || strcmp(TEST, "VV_CombinedArray") == 0 ) rc += VV_CombinedArray();
0139 if(ALL || strcmp(TEST, "ConvertToArray") == 0 ) rc += ConvertToArray();
0140
0141 std::cout << "S4MaterialPropertyVector_test::Main TEST [" << ( TEST ? TEST : "-" ) << "] rc " << rc << "\n" ;
0142
0143 return rc ;
0144 }
0145
0146 int main()
0147 {
0148 return S4MaterialPropertyVector_test::Main() ;
0149 }
0150