File indexing completed on 2026-04-09 07:49:49
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #if defined(__CUDACC__) || defined(__CUDABE__)
0012 # define STAG_METHOD __device__ __forceinline__
0013 #else
0014 # define STAG_METHOD inline
0015 #endif
0016
0017 enum {
0018 stag_undef = 0,
0019 stag_to_sci = 1,
0020 stag_to_bnd = 2,
0021 stag_to_sca = 3,
0022 stag_to_abs = 4,
0023 stag_at_burn_sf_sd = 5,
0024 stag_at_ref = 6,
0025 stag_sf_burn = 7,
0026 stag_sc = 8,
0027 stag_to_ree = 9,
0028 stag_re_wl = 10,
0029 stag_re_mom_ph = 11,
0030 stag_re_mom_ct = 12,
0031 stag_re_pol_ph = 13,
0032 stag_re_pol_ct = 14,
0033 stag_hp_ph = 15
0034
0035 };
0036
0037 #if defined(__CUDACC__) || defined(__CUDABE__)
0038 #else
0039
0040 #include <string>
0041 #include <sstream>
0042 #include <iomanip>
0043 #include <bitset>
0044
0045 struct stagc
0046 {
0047 static const char* Name(unsigned tag);
0048 static const char* Note(unsigned tag);
0049 static std::string Desc() ;
0050
0051 static constexpr const char* undef_ = "_" ;
0052 static constexpr const char* undef_note = "undef" ;
0053
0054 static constexpr const char* to_sci_ = "to_sci" ;
0055 static constexpr const char* to_sci_note = "qsim::propagate_to_boundary u_to_sci burn" ;
0056
0057 static constexpr const char* to_bnd_ = "to_bnd" ;
0058 static constexpr const char* to_bnd_note = "qsim::propagate_to_boundary u_to_bnd burn" ;
0059
0060 static constexpr const char* to_sca_ = "to_sca" ;
0061 static constexpr const char* to_sca_note = "qsim::propagate_to_boundary u_scattering" ;
0062
0063 static constexpr const char* to_abs_ = "to_abs" ;
0064 static constexpr const char* to_abs_note = "qsim::propagate_to_boundary u_absorption" ;
0065
0066 static constexpr const char* at_burn_sf_sd_ = "at_burn_sf_sd" ;
0067 static constexpr const char* at_burn_sf_sd_note = "at_boundary_burn at_surface ab/sd " ;
0068
0069 static constexpr const char* at_ref_ = "at_ref" ;
0070 static constexpr const char* at_ref_note = "u_reflect > TransCoeff" ;
0071
0072 static constexpr const char* sf_burn_ = "sf_burn" ;
0073 static constexpr const char* sf_burn_note = "qsim::propagate_at_surface burn" ;
0074
0075 static constexpr const char* sc_ = "sc" ;
0076 static constexpr const char* sc_note = "qsim::rayleigh_scatter" ;
0077
0078 static constexpr const char* to_ree_ = "to_ree" ;
0079 static constexpr const char* to_ree_note = "qsim::propagate_to_boundary u_reemit" ;
0080
0081 static constexpr const char* re_wl_ = "re_wl" ;
0082 static constexpr const char* re_wl_note = "qsim::propagate_to_boundary u_wavelength " ;
0083
0084 static constexpr const char* re_mom_ph_ = "re_mom_ph" ;
0085 static constexpr const char* re_mom_ph_note = "qsim::propagate_to_boundary re mom uniform_sphere ph " ;
0086
0087 static constexpr const char* re_mom_ct_ = "re_mom_ct" ;
0088 static constexpr const char* re_mom_ct_note = "qsim::propagate_to_boundary re mom uniform_sphere ct " ;
0089
0090 static constexpr const char* re_pol_ph_ = "re_pol_ph" ;
0091 static constexpr const char* re_pol_ph_note = "qsim::propagate_to_boundary re pol uniform_sphere ph " ;
0092
0093 static constexpr const char* re_pol_ct_ = "re_pol_ct" ;
0094 static constexpr const char* re_pol_ct_note = "qsim::propagate_to_boundary re pol uniform_sphere ct " ;
0095
0096 static constexpr const char* hp_ph_ = "hp_ph" ;
0097 static constexpr const char* hp_ph_note = "qsim::hemisphere_polarized u_hemipol_phi" ;
0098
0099
0100
0101
0102
0103
0104 };
0105
0106 STAG_METHOD const char* stagc::Name(unsigned tag)
0107 {
0108 const char* s = nullptr ;
0109 switch(tag)
0110 {
0111 case stag_undef: s = undef_ ; break ;
0112 case stag_to_sci: s = to_sci_ ; break ;
0113 case stag_to_bnd: s = to_bnd_ ; break ;
0114 case stag_to_sca: s = to_sca_ ; break ;
0115 case stag_to_abs: s = to_abs_ ; break ;
0116 case stag_at_burn_sf_sd: s = at_burn_sf_sd_ ; break ;
0117 case stag_at_ref: s = at_ref_ ; break ;
0118 case stag_sf_burn: s = sf_burn_ ; break ;
0119 case stag_sc: s = sc_ ; break ;
0120 case stag_to_ree: s = to_ree_ ; break ;
0121 case stag_re_wl: s = re_wl_ ; break ;
0122 case stag_re_mom_ph: s = re_mom_ph_ ; break ;
0123 case stag_re_mom_ct: s = re_mom_ct_ ; break ;
0124 case stag_re_pol_ph: s = re_pol_ph_ ; break ;
0125 case stag_re_pol_ct: s = re_pol_ct_ ; break ;
0126 case stag_hp_ph: s = hp_ph_ ; break ;
0127
0128 }
0129 return s ;
0130 }
0131 STAG_METHOD const char* stagc::Note(unsigned tag)
0132 {
0133 const char* s = nullptr ;
0134 switch(tag)
0135 {
0136 case stag_undef: s = undef_note ; break ;
0137 case stag_to_sci: s = to_sci_note ; break ;
0138 case stag_to_bnd: s = to_bnd_note ; break ;
0139 case stag_to_sca: s = to_sca_note ; break ;
0140 case stag_to_abs: s = to_abs_note ; break ;
0141 case stag_at_burn_sf_sd: s = at_burn_sf_sd_note ; break ;
0142 case stag_at_ref: s = at_ref_note ; break ;
0143 case stag_sf_burn: s = sf_burn_note ; break ;
0144 case stag_sc: s = sc_note ; break ;
0145 case stag_to_ree: s = to_ree_note ; break ;
0146 case stag_re_wl: s = re_wl_note ; break ;
0147 case stag_re_mom_ph: s = re_mom_ph_note ; break ;
0148 case stag_re_mom_ct: s = re_mom_ct_note ; break ;
0149 case stag_re_pol_ph: s = re_pol_ph_note ; break ;
0150 case stag_re_pol_ct: s = re_pol_ct_note ; break ;
0151 case stag_hp_ph: s = hp_ph_note ; break ;
0152
0153 }
0154 return s ;
0155 }
0156
0157 STAG_METHOD std::string stagc::Desc()
0158 {
0159 std::stringstream ss ;
0160 for(unsigned i=0 ; i <= 31 ; i++)
0161 {
0162 unsigned tag = i ;
0163 const char* name = Name(tag) ;
0164 const char* note = Note(tag) ;
0165 ss
0166 << " i " << std::setw(2) << i
0167 << " tag " << std::setw(2) << tag
0168 << " name " << std::setw(15) << ( name ? name : "-" )
0169 << " note " << ( note ? note : "-" )
0170 << std::endl
0171 ;
0172 }
0173 std::string s = ss.str();
0174 return s ;
0175 }
0176
0177 #endif
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 struct stag
0202 {
0203 static constexpr const unsigned NSEQ = 4 ;
0204 static constexpr const unsigned BITS = 4 ;
0205 static constexpr const unsigned long long MASK = ( 0x1ull << BITS ) - 1ull ;
0206 static constexpr const unsigned SLOTMAX = 64/BITS ;
0207 static constexpr const unsigned SLOTS = SLOTMAX*NSEQ ;
0208
0209 unsigned long long seqtag[NSEQ] ;
0210
0211 STAG_METHOD void zero();
0212 STAG_METHOD void set(unsigned slot, unsigned tag );
0213 STAG_METHOD unsigned get(unsigned slot_) const ;
0214
0215 #if defined(__CUDACC__) || defined(__CUDABE__)
0216 #else
0217 static std::string Desc() ;
0218 std::string desc(unsigned slot) const ;
0219 std::string desc() const ;
0220 #endif
0221
0222 };
0223
0224 struct sflat
0225 {
0226 static constexpr const unsigned SLOTS = stag::SLOTS ;
0227 float flat[SLOTS] ;
0228 };
0229
0230
0231 struct stagr
0232 {
0233 static constexpr const unsigned SLOTS = stag::SLOTS ;
0234
0235 unsigned slot = 0 ;
0236 stag tag = {} ;
0237 sflat flat = {} ;
0238
0239 STAG_METHOD void add(unsigned tag_, float flat_ );
0240
0241 #if defined(__CUDACC__) || defined(__CUDABE__)
0242 #else
0243 STAG_METHOD void zero();
0244 STAG_METHOD std::string desc(unsigned slot_) const ;
0245 STAG_METHOD std::string desc() const ;
0246 #endif
0247 };
0248
0249 STAG_METHOD void stagr::add(unsigned tag_, float flat_)
0250 {
0251
0252 if(slot < SLOTS)
0253 {
0254 tag.set(slot, tag_);
0255 flat.flat[slot] = flat_ ;
0256 }
0257 slot += 1 ;
0258 }
0259
0260
0261 #if defined(__CUDACC__) || defined(__CUDABE__)
0262 #else
0263 STAG_METHOD void stagr::zero(){ *this = {} ; }
0264 STAG_METHOD std::string stagr::desc(unsigned slot_) const
0265 {
0266 std::stringstream ss ;
0267 ss << std::setw(10) << std::fixed << std::setprecision(5) << flat.flat[slot_] << " : " << tag.desc(slot_) ;
0268 std::string s = ss.str();
0269 return s ;
0270 }
0271 STAG_METHOD std::string stagr::desc() const
0272 {
0273 std::stringstream ss ;
0274 ss << "stagr::desc " << std::endl ;
0275 for(unsigned i=0 ; i < SLOTS ; i++) ss << desc(i) << std::endl ;
0276 std::string s = ss.str();
0277 return s ;
0278 }
0279 #endif
0280
0281
0282
0283 #if defined(__CUDACC__) || defined(__CUDABE__)
0284 #else
0285 STAG_METHOD std::string stag::Desc()
0286 {
0287 std::stringstream ss ;
0288 ss << "stag::Desc "
0289 << " BITS " << BITS
0290 << " MASK " << MASK
0291 << " MASK 0x" << std::hex << MASK << std::dec
0292 << " MASK 0b" << std::bitset<64>(MASK)
0293 << " 64/BITS " << 64/BITS
0294 << " SLOTMAX " << SLOTMAX
0295 << std::endl
0296 ;
0297 std::string s = ss.str();
0298 return s ;
0299 }
0300
0301 STAG_METHOD std::string stag::desc(unsigned slot) const
0302 {
0303 unsigned tag = get(slot);
0304 const char* name = stagc::Name(tag) ;
0305 const char* note = stagc::Note(tag) ;
0306 std::stringstream ss ;
0307 ss
0308 << " slot " << std::setw(2) << slot
0309 << " tag " << std::setw(2) << tag
0310 << " name " << std::setw(15) << ( name ? name : "-" )
0311 << " note " << ( note ? note : "-" )
0312 ;
0313 std::string s = ss.str();
0314 return s ;
0315 }
0316
0317 STAG_METHOD std::string stag::desc() const
0318 {
0319 std::stringstream ss ;
0320 ss << "stag::desc " << std::endl ;
0321 for(unsigned i=0 ; i < NSEQ ; i++) ss << std::hex << std::setw(16) << seqtag[i] << std::dec << " : " << std::endl ;
0322 for(unsigned i=0 ; i < SLOTS ; i++) ss << desc(i) << std::endl ;
0323 std::string s = ss.str();
0324 return s ;
0325 }
0326 #endif
0327
0328
0329 STAG_METHOD void stag::zero()
0330 {
0331 for(unsigned i=0 ; i < NSEQ ; i++) seqtag[i] = 0ull ;
0332 }
0333 STAG_METHOD void stag::set(unsigned slot, unsigned tag)
0334 {
0335 unsigned iseq = slot/SLOTMAX ;
0336 if(iseq < NSEQ) seqtag[iseq] |= (( tag & MASK ) << BITS*(slot - iseq*SLOTMAX) );
0337
0338
0339
0340
0341
0342
0343 }
0344 STAG_METHOD unsigned stag::get(unsigned slot) const
0345 {
0346 unsigned iseq = slot/SLOTMAX ;
0347 return iseq < NSEQ ? ( seqtag[iseq] >> BITS*(slot - iseq*SLOTMAX) ) & MASK : 0 ;
0348 }
0349
0350