Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:11

0001 #pragma once
0002 /**
0003 QState.hh
0004 ===========
0005 
0006 TODO: revisit this, should shrink it down to almost nothing 
0007 TODO: demote this down to sysrap, perhaps down into sstate.h
0008 
0009 
0010 Only user of this is QDebug.cc::
0011 
0012     epsilon:opticks blyth$ opticks-f QState.hh
0013     ./qudarap/CMakeLists.txt:    QState.hh
0014     ./qudarap/QState.cc:#include "QState.hh"
0015     ./qudarap/QState.hh:QState.hh
0016     ./qudarap/tests/QStateTest.cc:#include "QState.hh"
0017 
0018     ./qudarap/QDebug.cc:#include "QState.hh"
0019 
0020 
0021 **/
0022 
0023 #include <iostream>
0024 #include <iomanip>
0025 #include <sstream>
0026 
0027 #include "QUDARAP_API_EXPORT.hh"
0028 #include "vector_functions.h"
0029 #include "scuda.h"
0030 #include "squad.h"
0031 #include "sstate.h"
0032 #include "NP.hh"
0033 
0034 struct QUDARAP_API QState
0035 {
0036     static sstate Make();     
0037     static void Convert(quad6& ss, const sstate& s); 
0038     static void Convert(sstate& s, const quad6&  ss); 
0039     static void Read( sstate& s,   const NP* a ); 
0040     static void Save(const sstate& s, const char* dir, const char* name ); 
0041     static void Load(      sstate& s, const char* dir, const char* name ); 
0042     static void Save(const sstate& s, const char* path ); 
0043     static void Load(      sstate& s, const char* path ); 
0044     static std::string Desc( const sstate& s ) ; 
0045 };
0046 
0047 inline sstate QState::Make()
0048 {
0049     float m1_refractive_index = qenvfloat("M1_REFRACTIVE_INDEX", "1" ) ; 
0050     float m1_absorption_length = 1000.f ; 
0051     float m1_scattering_length = 1000.f ; 
0052     float m1_reemission_prob = 0.f ; 
0053     float m1_group_velocity = 300.f ; 
0054 
0055     float m2_refractive_index = qenvfloat("M2_REFRACTIVE_INDEX", "1.5" ) ; 
0056     float m2_absorption_length = 1000.f ; 
0057     float m2_scattering_length = 1000.f ; 
0058     float m2_reemission_prob = 0.f ; 
0059 
0060     float su_detect = 0.f ; 
0061     float su_absorb = 0.f ; 
0062     float su_reflect_specular = 0.f ; 
0063     float su_reflect_diffuse = 0.f ; 
0064 
0065     sstate s ; 
0066     s.material1 = make_float4( m1_refractive_index, m1_absorption_length, m1_scattering_length, m1_reemission_prob ); 
0067     s.material2 = make_float4( m2_refractive_index, m2_absorption_length, m2_scattering_length, m2_reemission_prob );  
0068     s.m1group2  = make_float4( m1_group_velocity, 0.f, 0.f, 0.f ); 
0069     s.surface   = make_float4( su_detect, su_absorb, su_reflect_specular, su_reflect_diffuse ); 
0070     s.optical   = make_uint4( 0u, 0u, 0u, 0u );  // x/y/z/w index/type/finish/value  
0071     s.index     = make_uint4( 0u, 0u, 0u, 0u );  // indices of m1/m2/surf/sensor
0072     return s ; 
0073 }
0074 
0075 
0076 // HMM: so long as keep sstate simple quad block such that there are no alignmnet 
0077 // complications then this kind of conversion is not necessary : can simply 
0078 inline void QState::Convert(quad6& ss, const sstate& s)
0079 {
0080     ss.q0.f = s.material1 ; 
0081     ss.q1.f = s.material2 ; 
0082     ss.q2.f = s.m1group2 ; 
0083     ss.q3.f = s.surface ;
0084     ss.q4.u = s.optical ; 
0085     ss.q5.u = s.index ; 
0086 }
0087 
0088 inline void QState::Convert(sstate& s, const quad6& ss)
0089 {
0090     s.material1 = ss.q0.f ; 
0091     s.material2 = ss.q1.f ; 
0092     s.m1group2  = ss.q2.f ; 
0093     s.surface   = ss.q3.f ; 
0094     s.optical   = ss.q4.u ; 
0095     s.index     = ss.q5.u ; 
0096 }
0097 
0098 inline void QState::Read( sstate& s, const NP* a )
0099 {
0100     assert( a->has_shape(1,6,4) ); 
0101     quad6 ss ; 
0102     a->write((float*)&ss.q0.f.x); 
0103     Convert(s, ss); 
0104 }
0105 
0106 inline void QState::Save(const sstate& s, const char* dir, const char* name )
0107 {
0108     quad6 ss ; 
0109     Convert(ss, s); 
0110     NP::Write( dir, name, (float*)&ss.q0.f.x,  1, 6, 4 ); 
0111 }
0112 
0113 inline void QState::Save(const sstate& s, const char* path )
0114 {
0115     quad6 ss ; 
0116     Convert(ss, s); 
0117     NP::Write( path, (float*)&ss.q0.f.x,  1, 6, 4 ); 
0118 }
0119 
0120 inline void QState::Load(      sstate& s, const char* dir, const char* name )
0121 {
0122     NP* a = NP::Load(dir, name); 
0123     Read(s, a ); 
0124     delete a ; 
0125 }
0126 
0127 inline void QState::Load(sstate& s, const char* path )
0128 {
0129     NP* a = NP::Load(path); 
0130     Read(s, a ); 
0131     delete a ; 
0132 }
0133 
0134 inline std::string QState::Desc( const sstate& s ) 
0135 {
0136     std::stringstream ss ; 
0137     ss << "QState::Desc" << std::endl
0138        << std::setw(10) << "material1 " <<  s.material1  << std::endl
0139        << std::setw(10) << "material2 " <<  s.material2  << std::endl
0140        << std::setw(10) << "m1group2  " <<  s.m1group2   << std::endl
0141        << std::setw(10) << "surface   " <<  s.surface    << std::endl
0142        << std::setw(10) << "optical   " <<  s.optical    << std::endl
0143        ;
0144     std::string repr = ss.str(); 
0145     return repr ; 
0146 }
0147 
0148