Geant4 Cross Reference |
1 /* 1 /* 2 # <<BEGIN-copyright>> 2 # <<BEGIN-copyright>> 3 # <<END-copyright>> 3 # <<END-copyright>> 4 */ 4 */ 5 5 6 #include <iostream> 6 #include <iostream> 7 #include <stdlib.h> 7 #include <stdlib.h> 8 8 9 #include "GIDI_settings.hh" 9 #include "GIDI_settings.hh" 10 10 11 /* ---- GIDI_settings_flux_order ---- */ 11 /* ---- GIDI_settings_flux_order ---- */ 12 /* 12 /* 13 ============================================== 13 ========================================================= 14 */ 14 */ 15 GIDI_settings_flux_order::GIDI_settings_flux_o 15 GIDI_settings_flux_order::GIDI_settings_flux_order( int order ) { 16 16 17 if( order < 0 ) throw 1; 17 if( order < 0 ) throw 1; 18 mOrder = order; 18 mOrder = order; 19 } 19 } 20 /* 20 /* 21 ============================================== 21 ========================================================= 22 */ 22 */ 23 GIDI_settings_flux_order::GIDI_settings_flux_o 23 GIDI_settings_flux_order::GIDI_settings_flux_order( int order, int length, double const *energies, double const *fluxes ) { 24 24 25 initialize( order, length, energies, fluxe 25 initialize( order, length, energies, fluxes ); 26 } 26 } 27 /* 27 /* 28 ============================================== 28 ========================================================= 29 */ 29 */ 30 GIDI_settings_flux_order::GIDI_settings_flux_o 30 GIDI_settings_flux_order::GIDI_settings_flux_order( int order, std::vector<double> const &energies, std::vector<double> const &fluxes ) { 31 31 32 int length = (int) energies.size( ); 32 int length = (int) energies.size( ); 33 33 34 if( length != (int) fluxes.size( ) ) throw 34 if( length != (int) fluxes.size( ) ) throw 1; 35 initialize( order, length, &(energies[0]), 35 initialize( order, length, &(energies[0]), &(fluxes[0]) ); 36 } 36 } 37 /* 37 /* 38 ============================================== 38 ========================================================= 39 */ 39 */ 40 GIDI_settings_flux_order::GIDI_settings_flux_o 40 GIDI_settings_flux_order::GIDI_settings_flux_order( GIDI_settings_flux_order const &fluxOrder ) { 41 41 42 initialize( fluxOrder.mOrder, fluxOrder.si 42 initialize( fluxOrder.mOrder, fluxOrder.size( ), &(fluxOrder.mEnergies[0]), &(fluxOrder.mFluxes[0]) ); 43 } 43 } 44 /* 44 /* 45 ============================================== 45 ========================================================= 46 */ 46 */ 47 void GIDI_settings_flux_order::initialize( int 47 void GIDI_settings_flux_order::initialize( int order, int length, double const *energies, double const *fluxes ) { 48 48 49 if( order < 0 ) throw 1; 49 if( order < 0 ) throw 1; 50 mOrder = order; 50 mOrder = order; 51 mEnergies.resize( length, 0 ); 51 mEnergies.resize( length, 0 ); 52 mFluxes.resize( length, 0 ); 52 mFluxes.resize( length, 0 ); 53 for( int i1 = 0; i1 < length; ++i1 ) mEner 53 for( int i1 = 0; i1 < length; ++i1 ) mEnergies[i1] = energies[i1]; 54 for( int i1 = 0; i1 < length; ++i1 ) mFlux 54 for( int i1 = 0; i1 < length; ++i1 ) mFluxes[i1] = fluxes[i1]; 55 } 55 } 56 /* 56 /* 57 ============================================== 57 ========================================================= 58 */ 58 */ 59 GIDI_settings_flux_order& GIDI_settings_flux_o 59 GIDI_settings_flux_order& GIDI_settings_flux_order::operator=( const GIDI_settings_flux_order &fluxOrder ) { 60 if ( this != &fluxOrder ) { 60 if ( this != &fluxOrder ) { 61 initialize( fluxOrder.mOrder, fluxOrder.si 61 initialize( fluxOrder.mOrder, fluxOrder.size(), &(fluxOrder.mEnergies[0]), &(fluxOrder.mFluxes[0]) ); 62 } 62 } 63 return *this; 63 return *this; 64 } 64 } 65 /* 65 /* 66 ============================================== 66 ========================================================= 67 */ 67 */ 68 GIDI_settings_flux_order::~GIDI_settings_flux_ 68 GIDI_settings_flux_order::~GIDI_settings_flux_order( ) { 69 69 70 } 70 } 71 /* 71 /* 72 ============================================== 72 ========================================================= 73 */ 73 */ 74 void GIDI_settings_flux_order::print( int valu 74 void GIDI_settings_flux_order::print( int valuesPerLine ) const { 75 75 76 int nE = (int) mEnergies.size( ); 76 int nE = (int) mEnergies.size( ); 77 bool printIndent = true; 77 bool printIndent = true; 78 char buffer[2 * 128]; 78 char buffer[2 * 128]; 79 79 80 std::cout << " ORDER: " << mOrder << st 80 std::cout << " ORDER: " << mOrder << std::endl; 81 for( int iE = 0; iE < nE; ++iE ) { 81 for( int iE = 0; iE < nE; ++iE ) { 82 if( printIndent ) std::cout << " "; 82 if( printIndent ) std::cout << " "; 83 printIndent = false; 83 printIndent = false; 84 snprintf( buffer, sizeof buffer, " % << 84 sprintf( buffer, " %15.8e %15.8e", mEnergies[iE], mFluxes[iE] ); 85 std::cout << buffer; 85 std::cout << buffer; 86 if( ( ( iE + 1 ) % valuesPerLine ) == 86 if( ( ( iE + 1 ) % valuesPerLine ) == 0 ) { 87 std::cout << std::endl; 87 std::cout << std::endl; 88 printIndent = true; 88 printIndent = true; 89 } 89 } 90 } 90 } 91 if( nE % valuesPerLine ) std::cout << std: 91 if( nE % valuesPerLine ) std::cout << std::endl; 92 } 92 } 93 93 94 /* ---- GIDI_settings_flux ---- */ 94 /* ---- GIDI_settings_flux ---- */ 95 /* 95 /* 96 ============================================== 96 ========================================================= 97 */ 97 */ 98 GIDI_settings_flux::GIDI_settings_flux( std::s 98 GIDI_settings_flux::GIDI_settings_flux( std::string const &label, double temperature ) { 99 99 100 mLabel = label; 100 mLabel = label; 101 mTemperature = temperature; 101 mTemperature = temperature; 102 } 102 } 103 /* 103 /* 104 ============================================== 104 ========================================================= 105 */ 105 */ 106 GIDI_settings_flux::GIDI_settings_flux( char c 106 GIDI_settings_flux::GIDI_settings_flux( char const *label, double temperature ) { 107 107 108 mLabel = label; 108 mLabel = label; 109 mTemperature = temperature; 109 mTemperature = temperature; 110 } 110 } 111 /* 111 /* 112 ============================================== 112 ========================================================= 113 */ 113 */ 114 GIDI_settings_flux::GIDI_settings_flux( GIDI_s 114 GIDI_settings_flux::GIDI_settings_flux( GIDI_settings_flux const &flux ) { 115 115 116 mLabel = flux.getLabel( ); 116 mLabel = flux.getLabel( ); 117 mTemperature = flux.mTemperature; 117 mTemperature = flux.mTemperature; 118 for( std::vector<GIDI_settings_flux_order> 118 for( std::vector<GIDI_settings_flux_order>::const_iterator iter = flux.mFluxOrders.begin( ); iter < flux.mFluxOrders.end( ); ++iter ) addFluxOrder( *iter ); 119 } 119 } 120 /* 120 /* 121 ============================================== 121 ========================================================= 122 */ 122 */ 123 GIDI_settings_flux& GIDI_settings_flux::operat 123 GIDI_settings_flux& GIDI_settings_flux::operator=( const GIDI_settings_flux &flux ) { 124 if ( this != &flux ) { 124 if ( this != &flux ) { 125 mLabel = flux.getLabel(); 125 mLabel = flux.getLabel(); 126 mTemperature = flux.mTemperature; 126 mTemperature = flux.mTemperature; 127 for( std::vector<GIDI_settings_flux_order> 127 for( std::vector<GIDI_settings_flux_order>::const_iterator iter = flux.mFluxOrders.begin( ); iter < flux.mFluxOrders.end( ); ++iter ) addFluxOrder( *iter ); 128 } 128 } 129 return *this; 129 return *this; 130 } 130 } 131 /* 131 /* 132 ============================================== 132 ========================================================= 133 */ 133 */ 134 GIDI_settings_flux::~GIDI_settings_flux( ) { 134 GIDI_settings_flux::~GIDI_settings_flux( ) { 135 135 136 } 136 } 137 /* 137 /* 138 ============================================== 138 ========================================================= 139 */ 139 */ 140 GIDI_settings_flux_order const *GIDI_settings_ 140 GIDI_settings_flux_order const *GIDI_settings_flux::operator[]( int index ) const { 141 141 142 return( &(mFluxOrders[index]) ); 142 return( &(mFluxOrders[index]) ); 143 } 143 } 144 /* 144 /* 145 ============================================== 145 ========================================================= 146 */ 146 */ 147 void GIDI_settings_flux::addFluxOrder( GIDI_se 147 void GIDI_settings_flux::addFluxOrder( GIDI_settings_flux_order const &fluxOrder ) { 148 /* 148 /* 149 * Orders can only be added in sequence (e.g. 149 * Orders can only be added in sequence (e.g., 0 first, then 1, ...). 150 */ 150 */ 151 int order = fluxOrder.getOrder( ); 151 int order = fluxOrder.getOrder( ); 152 152 153 if( order > (int) mFluxOrders.size( ) ) th 153 if( order > (int) mFluxOrders.size( ) ) throw 1; 154 mFluxOrders.push_back( fluxOrder ); 154 mFluxOrders.push_back( fluxOrder ); 155 } 155 } 156 /* 156 /* 157 ============================================== 157 ========================================================= 158 */ 158 */ 159 void GIDI_settings_flux::print( bool outline, 159 void GIDI_settings_flux::print( bool outline, int valuesPerLine ) const { 160 160 161 std::cout << "FLUX: label = '" << mLabel < 161 std::cout << "FLUX: label = '" << mLabel << "': maximum order = " << ( size( ) + 1 ) << std::endl; 162 if( outline ) return; 162 if( outline ) return; 163 for( std::vector<GIDI_settings_flux_order> 163 for( std::vector<GIDI_settings_flux_order>::const_iterator iter = mFluxOrders.begin( ); iter < mFluxOrders.end( ); ++iter ) iter->print( valuesPerLine ); 164 } 164 } 165 165 166 #if 0 166 #if 0 167 /* ---- GIDI_settings_fluxes_from_bdfls ---- 167 /* ---- GIDI_settings_fluxes_from_bdfls ---- */ 168 /* 168 /* 169 ============================================== 169 ========================================================= 170 */ 170 */ 171 GIDI_settings_fluxes_from_bdfls::GIDI_settings 171 GIDI_settings_fluxes_from_bdfls::GIDI_settings_fluxes_from_bdfls( std::string const &fileName, double temperature_MeV = 0 ) { 172 172 173 initialize( fileName.c_str( ), temperature 173 initialize( fileName.c_str( ), temperature_MeV ); 174 } 174 } 175 /* 175 /* 176 ============================================== 176 ========================================================= 177 */ 177 */ 178 GIDI_settings_fluxes_from_bdfls::GIDI_settings 178 GIDI_settings_fluxes_from_bdfls::GIDI_settings_fluxes_from_bdfls( char const *fileName, double temperature_MeV = 0 ) { 179 179 180 initialize( fileName, temperature_MeV ); 180 initialize( fileName, temperature_MeV ); 181 } 181 } 182 /* 182 /* 183 ============================================== 183 ========================================================= 184 */ 184 */ 185 GIDI_settings_fluxes_from_bdfls::GIDI_settings 185 GIDI_settings_fluxes_from_bdfls::GIDI_settings_fluxes_from_bdfls( cbdfls_file const *bdfls, double temperature_MeV = 0 ) { 186 186 187 initialize2( bdfls, temperature_MeV ); 187 initialize2( bdfls, temperature_MeV ); 188 } 188 } 189 /* 189 /* 190 ============================================== 190 ========================================================= 191 */ 191 */ 192 void GIDI_settings_fluxes_from_bdfls::initiali 192 void GIDI_settings_fluxes_from_bdfls::initialize( char const *fileName, double temperature_MeV ) { 193 193 194 cbdfls_file *bdfls; 194 cbdfls_file *bdfls; 195 cbdflsErrors Error; 195 cbdflsErrors Error; 196 196 197 if( ( bdfls = cbdflsOpen( fileName, &Error 197 if( ( bdfls = cbdflsOpen( fileName, &Error ) ) == NULL ) throw Error; 198 initialize2( bdfls, temperature_MeV ); 198 initialize2( bdfls, temperature_MeV ); 199 cbdflsRelease( bdfls ); 199 cbdflsRelease( bdfls ); 200 } 200 } 201 /* 201 /* 202 ============================================== 202 ========================================================= 203 */ 203 */ 204 void GIDI_settings_fluxes_from_bdfls::initiali 204 void GIDI_settings_fluxes_from_bdfls::initialize2( cbdfls_file const *bdfls, double temperature_MeV ) { 205 205 206 int nf, length, *fids, order; 206 int nf, length, *fids, order; 207 double *energies, *fluxes; 207 double *energies, *fluxes; 208 char label[100]; 208 char label[100]; 209 209 210 nf = cbdflsFIDs( (cbdfls_file *) bdfls, &f 210 nf = cbdflsFIDs( (cbdfls_file *) bdfls, &fids ); 211 for( int if1 = 0; if1 < nf; ++if1 ) { 211 for( int if1 = 0; if1 < nf; ++if1 ) { 212 snprintf( label, sizeof label, "LLNL_f << 212 sprintf( label, "LLNL_fid_%.3d", fids[if1] ); 213 GIDI_settings_flux flux = GIDI_setting 213 GIDI_settings_flux flux = GIDI_settings_flux( label, temperature_MeV ); 214 order = cbdflsGetFluxOrder( (cbdfls_fi 214 order = cbdflsGetFluxOrder( (cbdfls_file *) bdfls, fids[if1] ); 215 for( int io = 0; io <= order; ++io ) { 215 for( int io = 0; io <= order; ++io ) { 216 length = cbdflsGetFlux( (cbdfls_fi 216 length = cbdflsGetFlux( (cbdfls_file *) bdfls, fids[if1], io, &energies, &fluxes ); 217 GIDI_settings_flux_order flux_orde 217 GIDI_settings_flux_order flux_order = GIDI_settings_flux_order( io, length, energies, fluxes ); 218 flux.addFluxOrder( flux_order ); 218 flux.addFluxOrder( flux_order ); 219 } 219 } 220 mFluxes.push_back( flux ); 220 mFluxes.push_back( flux ); 221 } 221 } 222 return; 222 return; 223 } 223 } 224 /* 224 /* 225 ============================================== 225 ========================================================= 226 */ 226 */ 227 GIDI_settings_fluxes_from_bdfls::~GIDI_setting 227 GIDI_settings_fluxes_from_bdfls::~GIDI_settings_fluxes_from_bdfls( ) { 228 228 229 } 229 } 230 /* 230 /* 231 ============================================== 231 ========================================================= 232 */ 232 */ 233 GIDI_settings_flux GIDI_settings_fluxes_from_b 233 GIDI_settings_flux GIDI_settings_fluxes_from_bdfls::getViaFID( int fid ) { 234 234 235 char label[100]; 235 char label[100]; 236 236 237 snprintf( label, sizeof label, "LLNL_fid_% << 237 sprintf( label, "LLNL_fid_%.3d", fid ); 238 for( int if1 = 0; if1 < (int) mFluxes.size 238 for( int if1 = 0; if1 < (int) mFluxes.size( ); ++if1 ) { 239 if( mFluxes[if1].isLabel( label ) ) re 239 if( mFluxes[if1].isLabel( label ) ) return( mFluxes[if1] ); 240 } 240 } 241 throw 1; 241 throw 1; 242 } 242 } 243 /* 243 /* 244 ============================================== 244 ========================================================= 245 */ 245 */ 246 std::vector<std::string> GIDI_settings_fluxes_ 246 std::vector<std::string> GIDI_settings_fluxes_from_bdfls::getLabels( void ) { 247 247 248 int size = (int) mFluxes.size( ); 248 int size = (int) mFluxes.size( ); 249 std::vector<std::string> labels( size ); 249 std::vector<std::string> labels( size ); 250 250 251 for( int if1 = 0; if1 < size; ++if1 ) labe 251 for( int if1 = 0; if1 < size; ++if1 ) labels[if1] = mFluxes[if1].getLabel( ); 252 return( labels ); 252 return( labels ); 253 } 253 } 254 /* 254 /* 255 ============================================== 255 ========================================================= 256 */ 256 */ 257 std::vector<int> GIDI_settings_fluxes_from_bdf 257 std::vector<int> GIDI_settings_fluxes_from_bdfls::getFIDs( void ) { 258 258 259 int size = (int) mFluxes.size( ); 259 int size = (int) mFluxes.size( ); 260 std::vector<int> fids( size ); 260 std::vector<int> fids( size ); 261 char *e; 261 char *e; 262 262 263 for( int if1 = 0; if1 < size; ++if1 ) { 263 for( int if1 = 0; if1 < size; ++if1 ) { 264 fids[if1] = (int) strtol( &(mFluxes[if 264 fids[if1] = (int) strtol( &(mFluxes[if1].getLabel( ).c_str( )[9]), &e, 10 ); 265 } 265 } 266 return( fids ); 266 return( fids ); 267 } 267 } 268 /* 268 /* 269 ============================================== 269 ========================================================= 270 */ 270 */ 271 void GIDI_settings_fluxes_from_bdfls::print( b 271 void GIDI_settings_fluxes_from_bdfls::print( bool outline, int valuesPerLine ) { 272 272 273 int nfs = (int) mFluxes.size( ); 273 int nfs = (int) mFluxes.size( ); 274 274 275 std::cout << "BDFLS FLUXes: number of flux 275 std::cout << "BDFLS FLUXes: number of fluxes = " << nfs << std::endl; 276 for( int if1 = 0; if1 < nfs ; ++if1 ) mFlu 276 for( int if1 = 0; if1 < nfs ; ++if1 ) mFluxes[if1].print( outline, valuesPerLine ); 277 } 277 } 278 #endif 278 #endif 279 279