File indexing completed on 2026-04-09 07:49:15
0001
0002
0003 #include "OPTICKS_LOG.hh"
0004 #include "SSys.hh"
0005 #include "SSim.hh"
0006 #include "SBnd.h"
0007 #include "SPath.hh"
0008 #include "sproplist.h"
0009
0010 #include "NPFold.h"
0011
0012 void test_descBoundary(const SBnd& sb)
0013 {
0014 unsigned num_boundary = sb.getNumBoundary();
0015 LOG(info)
0016 << " num_boundary " << num_boundary
0017 << " sb.descBoundary "
0018 << std::endl
0019 << sb.descBoundary()
0020 ;
0021 }
0022
0023
0024 void test_getBoundarySpec(const SBnd& sb)
0025 {
0026 unsigned num_boundary = sb.getNumBoundary();
0027 LOG(info)
0028 << " num_boundary " << num_boundary
0029 ;
0030 for(unsigned i=0 ; i < num_boundary ; i++)
0031 {
0032 std::cout
0033 << std::setw(4) << i
0034 << " : "
0035 << sb.getBoundarySpec(i)
0036 << std::endl
0037 ;
0038 }
0039 }
0040
0041
0042 void test_getBoundaryLine(SBnd& sb)
0043 {
0044 const char* spec = SSys::getenvvar("QCTX_SPEC", "Acrylic///LS" );
0045 int idx = sb.getBoundaryIndex(spec);
0046 if( idx == SBnd::MISSING )
0047 {
0048 LOG(error) << " SBnd MISSING spec " << spec ;
0049 return ;
0050 }
0051
0052 int num_boundary = sb.getNumBoundary();
0053
0054 enum { IMAT = 3 } ;
0055 int line = sb.getBoundaryLine(spec, IMAT);
0056 int xline = idx*4 + IMAT ;
0057 LOG(info)
0058 << " spec " << spec
0059 << " idx " << idx
0060 << " line " << line
0061 << " xline " << xline
0062 ;
0063
0064 assert( xline == line );
0065
0066 int line_max = (num_boundary-1)*4 + IMAT ;
0067 int linek_max = 2*line_max + 1 ;
0068
0069 LOG(info)
0070 << " line_max " << line_max
0071 << " linek_max " << linek_max
0072 << " linek_max+1 " << linek_max+1
0073 ;
0074
0075 }
0076
0077
0078 void test_getMaterialLine(SBnd& sb)
0079 {
0080 std::vector<std::string> materials ;
0081 sstr::Split( SSys::getenvvar("QCTX_MATERIALS", "Water,LS,Pyrex,Acrylic,NonExisting" ), ',', materials );
0082 LOG(info) << " materials.size " << materials.size() ;
0083
0084 for(unsigned i=0 ; i < materials.size() ; i++)
0085 {
0086 const char* material = materials[i].c_str() ;
0087 unsigned line = sb.getMaterialLine(material);
0088 std::cout
0089 << " material " << std::setw(50) << material
0090 << " line " << line
0091 << std::endl
0092 ;
0093 }
0094 }
0095
0096
0097 void test_getBoundaryIndices_0(const SBnd& sb)
0098 {
0099 const char* bnd_fallback = "Acrylic///LS,Water///Acrylic,Water///Pyrex,Pyrex/NNVTMCPPMT_PMT_20inch_photocathode_logsurf2/NNVTMCPPMT_PMT_20inch_photocathode_logsurf1/Vacuum" ;
0100 const char* bnd_sequence = SSys::getenvvar("BND_SEQUENCE", bnd_fallback );
0101 LOG(info) << " bnd_sequence " << bnd_sequence ;
0102
0103 bool has_all = sb.hasAllBoundaryIndices( bnd_sequence, ',') ;
0104 LOG_IF(error, !has_all) << " GEOMETRY DOES NOT CONTAIN ALL THE BOUNDARIES " ;
0105 if(!has_all) return ;
0106
0107 std::vector<int> bnd_idx ;
0108 sb.getBoundaryIndices( bnd_idx, bnd_sequence, ',' );
0109
0110
0111 LOG(info) << "sb.descBoundaryIndices" << std::endl << sb.descBoundaryIndices( bnd_idx );
0112 }
0113
0114
0115 void test_getBoundaryIndices_1(const SBnd& sb)
0116 {
0117 const char* bnd_fallback = R"LITERAL(
0118 Acrylic///LS
0119 Water///Acrylic
0120 Water///Pyrex
0121 Pyrex/NNVTMCPPMT_PMT_20inch_photocathode_logsurf2/NNVTMCPPMT_PMT_20inch_photocathode_logsurf1/Vacuum
0122 )LITERAL" ;
0123
0124 const char* bnd_sequence = SSys::getenvvar("BND_SEQUENCE", bnd_fallback );
0125 LOG(info) << " bnd_sequence " << bnd_sequence ;
0126
0127 std::vector<int> bnd_idx ;
0128 sb.getBoundaryIndices( bnd_idx, bnd_sequence, '\n' );
0129 LOG(info) << "sb.descBoundaryIndices" << std::endl << sb.descBoundaryIndices( bnd_idx );
0130 }
0131
0132
0133
0134 void test_desc(const SBnd& sb )
0135 {
0136 LOG(info) << std::endl << sb.desc() ;
0137 }
0138
0139 void test_getMaterialNames( const SBnd& sb )
0140 {
0141 std::vector<std::string> names ;
0142 sb.getMaterialNames(names);
0143
0144 LOG(info) << std::endl << SBnd::DescNames(names) ;
0145 }
0146
0147 void test_getPropertyGroup(const SBnd& sb)
0148 {
0149 std::vector<std::string> names ;
0150 sb.getMaterialNames(names);
0151
0152 NPFold* fold = new NPFold ;
0153 for(unsigned i=0 ; i < names.size() ; i++)
0154 {
0155 const char* material = names[i].c_str();
0156 NP* a = sb.getPropertyGroup( material) ;
0157 std::cout << std::setw(20) << material << " " << a->brief() << std::endl;
0158 fold->add( material, a );
0159 }
0160 const char* dir = SPath::Resolve("$TMP/SBndTest/test_getPropertyGroup", DIRPATH);
0161 fold->save(dir);
0162 LOG(info) << dir ;
0163 }
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178 void test_getProperty_Q(const SBnd& sb)
0179 {
0180 const char* q = SSys::getenvvar("Q", "Water/GROUPVEL");
0181
0182 std::vector<std::string> elem ;
0183 sstr::Split(q, '/' , elem);
0184 assert( elem.size() == 2);
0185 const char* qname = elem[0].c_str();
0186 const char* pname = elem[1].c_str();
0187
0188 std::vector<double> out ;
0189 sb.getProperty(out, qname, pname );
0190
0191 std::cout
0192 << " Q " << q << std::endl
0193 << NP::DescSlice(out, 5)
0194 ;
0195 }
0196
0197
0198 void test_getProperty(const SBnd& sb)
0199 {
0200 const sproplist* pl = sproplist::Material();
0201
0202 std::vector<std::string> pnames ;
0203
0204 pl->getNames(pnames) ;
0205
0206 for(unsigned i=0 ; i < pnames.size() ; i++) std::cout << pnames[i] << std::endl ;
0207
0208 std::vector<std::string> mnames ;
0209 sb.getMaterialNames(mnames);
0210
0211
0212 for(unsigned i=0 ; i < mnames.size() ; i++)
0213 {
0214 const char* mname = mnames[i].c_str();
0215 for(unsigned j=0 ; j < pnames.size() ; j++)
0216 {
0217 const char* pname = pnames[j].c_str();
0218
0219 std::vector<double> out ;
0220 sb.getProperty(out, mname, pname);
0221
0222 std::cout
0223 << " Q " << mname << "/" << pname << std::endl
0224 << NP::DescSlice(out, 5)
0225 ;
0226
0227 }
0228 }
0229 }
0230
0231
0232 int main(int argc, char** argv)
0233 {
0234 OPTICKS_LOG(argc, argv);
0235
0236 SSim* sim = SSim::Load();
0237 const NP* bnd = sim->get_bnd();
0238 LOG_IF(fatal, !bnd) << " NO bnd : nothing to do " ;
0239 if(!bnd) return 0 ;
0240
0241
0242 SBnd sb(bnd) ;
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258 test_getBoundaryIndices_0(sb);
0259
0260 return 0 ;
0261 }
0262
0263
0264