48 assert( NULL != impl );
77 const Tag* file_id_tag )
99 result =
load_one_file( filename, input_meshset, options, average );
103 std::string root_filename( filename );
104 int length = root_filename.length();
105 root_filename.erase(
length -
sizeof(
".meshtal" ) );
109 for(
int i = 2; i <= n_files; i++ )
111 std::stringstream index;
113 std::string subsequent_filename = root_filename + index.str() +
".meshtal";
114 result =
load_one_file( subsequent_filename.c_str(), input_meshset, options, average );
122 result =
load_one_file( filename, input_meshset, options, average );
137 if(
debug ) std::cout <<
"begin ReadMCNP5::load_one_file" << std::endl;
141 file.open( fname, std::fstream::in );
145 Tag date_and_time_tag, title_tag, nps_tag, tally_number_tag, tally_comment_tag, tally_particle_tag,
146 tally_coord_sys_tag, tally_tag, error_tag;
148 result =
create_tags( date_and_time_tag, title_tag, nps_tag, tally_number_tag, tally_comment_tag,
149 tally_particle_tag, tally_coord_sys_tag, tally_tag, error_tag );
157 char date_and_time[100] =
"";
158 char title[100] =
"";
160 unsigned long int nps;
162 unsigned long int new_nps;
169 file.getline( line, 10000 );
173 if( !average && 0 != input_meshset )
175 result =
set_header_tags( *input_meshset, date_and_time, title, nps, date_and_time_tag, title_tag, nps_tag );
187 unsigned int tally_number;
188 char tally_comment[100] =
"";
191 std::vector< double > planes[3];
192 unsigned int n_chopped_x0_planes;
193 unsigned int n_chopped_x2_planes;
200 file.getline( line, 10000 );
201 std::string l = line;
203 if( std::string::npos != l.find(
"This mesh tally is modified by a dose response function." ) )
205 file.getline( line, 10000 );
213 file.getline( line, 10000 );
214 std::string a = line;
215 if(
debug ) std::cout <<
"Energy bin boundaries:=| " << a << std::endl;
218 file.getline( line, 10000 );
221 file.getline( line, 10000 );
231 planes[2].pop_back();
232 n_chopped_x2_planes = 1;
233 if(
debug ) std::cout <<
"remove last cylindrical plane option found" << std::endl;
237 n_chopped_x2_planes = 0;
246 std::vector< double >::iterator front = planes[0].begin();
247 planes[0].erase( front );
248 n_chopped_x0_planes = 1;
249 if(
debug ) std::cout <<
"remove first radial plane option found" << std::endl;
253 n_chopped_x0_planes = 0;
258 unsigned int n_elements = ( planes[0].size() - 1 ) * ( planes[1].
size() - 1 ) * ( planes[2].
size() - 1 );
259 double* values =
new double[n_elements];
260 double* errors =
new double[n_elements];
262 tally_particle, values, errors );
266 file.getline( line, 10000 );
280 result =
set_tally_tags( tally_meshset, tally_number, tally_comment, tally_particle, tally_coord_sys,
281 tally_number_tag, tally_comment_tag, tally_particle_tag, tally_coord_sys_tag );
292 result =
create_elements(
debug, planes, n_chopped_x0_planes, n_chopped_x2_planes, start_vert, values,
293 errors, tally_tag, error_tag, tally_meshset, tally_coord_sys );
297 if(
debug ) std::cout <<
"not averaging tally" << std::endl;
303 if(
debug ) std::cout <<
"averaging tally" << std::endl;
305 tally_tag, error_tag, values, errors, n_elements );
319 Range matching_nps_sets;
322 if(
debug ) std::cout <<
"number of matching nps meshsets=" << matching_nps_sets.
size() << std::endl;
323 assert( 1 == matching_nps_sets.
size() );
338 Tag& tally_number_tag,
339 Tag& tally_comment_tag,
340 Tag& tally_particle_tag,
341 Tag& tally_coord_sys_tag,
376 char date_and_time[100],
378 unsigned long int& nps )
383 file.getline( line, 100 );
384 date_and_time = line;
385 if(
debug ) std::cout <<
"date_and_time=| " << date_and_time << std::endl;
389 file.getline( line, 100 );
391 if(
debug ) std::cout <<
"title=| " << title << std::endl;
395 file.getline( line, 100 );
396 std::string a = line;
397 std::string::size_type b = a.find(
"Number of histories used for normalizing tallies =" );
398 if( std::string::npos != b )
400 std::istringstream nps_ss(
401 a.substr( b +
sizeof(
"Number of histories used for normalizing tallies =" ), 100 ) );
403 if(
debug ) std::cout <<
"nps=| " << nps << std::endl;
412 char date_and_time[100],
414 unsigned long int nps,
415 Tag data_and_time_tag,
420 result =
MBI->
tag_set_data( data_and_time_tag, &output_meshset, 1, &date_and_time );
432 unsigned int& tally_number,
433 char tally_comment[100],
440 file.getline( line, 100 );
441 std::string a = line;
442 std::string::size_type b = a.find(
"Mesh Tally Number" );
443 if( std::string::npos != b )
445 std::istringstream tally_number_ss( a.substr( b +
sizeof(
"Mesh Tally Number" ), 100 ) );
446 tally_number_ss >> tally_number;
447 if(
debug ) std::cout <<
"tally_number=| " << tally_number << std::endl;
451 std::cout <<
"tally number not found" << std::endl;
461 file.getline( line, 100 );
464 if( MB_FAILURE == result )
468 tally_comment = line;
469 file.getline( line, 100 );
474 if(
debug ) std::cout <<
"tally_comment=| " << tally_comment << std::endl;
481 if( std::string::npos != a.find(
"This is a neutron mesh tally." ) )
485 else if( std::string::npos != a.find(
"This is a photon mesh tally." ) )
489 else if( std::string::npos != a.find(
"This is an electron mesh tally." ) )
496 if(
debug ) std::cout <<
"tally_particle=| " << tally_particle << std::endl;
503 std::vector< double > planes[3],
509 file.getline( line, 10000 );
510 std::string a = line;
511 if( std::string::npos == a.find(
"Tally bin boundaries:" ) )
return MB_FAILURE;
515 file.getline( line, 10000 );
517 std::string::size_type b = a.find(
"Cylinder origin at" );
518 if( std::string::npos != b )
521 if(
debug ) std::cout <<
"origin, axis, direction=| " << a << std::endl;
522 std::istringstream ss( a.substr( b +
sizeof(
"Cylinder origin at" ), 10000 ) );
530 if(
debug ) std::cout <<
"origin=| ";
531 for(
int i = 0; i < 3; i++ )
534 if(
debug ) std::cout << origin[i] <<
" ";
536 if(
debug ) std::cout << std::endl;
537 int length_of_string = 10;
538 ss.ignore( length_of_string,
' ' );
539 ss.ignore( length_of_string,
' ' );
540 ss.ignore( length_of_string,
' ' );
543 if(
debug ) std::cout <<
"axis=| ";
544 for(
int i = 0; i < 3; i++ )
547 if(
debug ) std::cout << axis[i] <<
" ";
549 if(
debug ) std::cout << std::endl;
550 file.getline( line, 10000 );
554 if(
debug ) std::cout <<
"R direction:=| ";
555 b = a.find(
"R direction:" );
556 if( std::string::npos != b )
558 std::istringstream ss2( a.substr( b +
sizeof(
"R direction" ), 10000 ) );
566 file.getline( line, 10000 );
568 if(
debug ) std::cout <<
"Z direction:=| ";
569 b = a.find(
"Z direction:" );
570 if( std::string::npos != b )
572 std::istringstream ss2( a.substr( b +
sizeof(
"Z direction" ), 10000 ) );
580 file.getline( line, 10000 );
582 if(
debug ) std::cout <<
"Theta direction:=| ";
583 b = a.find(
"Theta direction (revolutions):" );
584 if( std::string::npos != b )
586 std::istringstream ss2( a.substr( b +
sizeof(
"Theta direction (revolutions):" ), 10000 ) );
595 else if( std::string::npos != a.find(
"X direction:" ) )
599 if(
debug ) std::cout <<
"X direction:=| ";
600 b = a.find(
"X direction:" );
601 if( std::string::npos != b )
603 std::istringstream ss2( a.substr( b +
sizeof(
"X direction" ), 10000 ) );
611 file.getline( line, 10000 );
613 if(
debug ) std::cout <<
"Y direction:=| ";
614 b = a.find(
"Y direction:" );
615 if( std::string::npos != b )
617 std::istringstream ss2( a.substr( b +
sizeof(
"Y direction" ), 10000 ) );
625 file.getline( line, 10000 );
627 if(
debug ) std::cout <<
"Z direction:=| ";
628 b = a.find(
"Z direction:" );
629 if( std::string::npos != b )
631 std::istringstream ss2( a.substr( b +
sizeof(
"Z direction" ), 10000 ) );
654 plane.push_back( value );
655 if(
debug ) std::cout << value <<
" ";
657 if(
debug ) std::cout << std::endl;
664 std::vector< double > planes[3],
665 unsigned int n_chopped_x0_planes,
666 unsigned int n_chopped_x2_planes,
671 unsigned int index = 0;
673 for(
unsigned int i = 0; i < planes[0].size() - 1 + n_chopped_x0_planes; i++ )
675 for(
unsigned int j = 0; j < planes[1].size() - 1; j++ )
677 for(
unsigned int k = 0; k < planes[2].size() - 1 + n_chopped_x2_planes; k++ )
680 file.getline( line, 100 );
682 if( i < n_chopped_x0_planes )
continue;
683 if( k >= planes[2].
size() - 1 && k < planes[2].
size() - 1 + n_chopped_x2_planes )
continue;
684 std::string a = line;
685 std::stringstream ss( a );
689 if(
PHOTON == tally_particle ) ss >> energy;
701 std::cerr <<
"found nan error while reading file" << std::endl;
706 std::cerr <<
"found nan value while reading file" << std::endl;
719 unsigned int tally_number,
720 char tally_comment[100],
723 Tag tally_number_tag,
724 Tag tally_comment_tag,
725 Tag tally_particle_tag,
726 Tag tally_coord_sys_tag )
729 result =
MBI->
tag_set_data( tally_number_tag, &tally_meshset, 1, &tally_number );
731 result =
MBI->
tag_set_data( tally_comment_tag, &tally_meshset, 1, &tally_comment );
733 result =
MBI->
tag_set_data( tally_particle_tag, &tally_meshset, 1, &tally_particle );
735 result =
MBI->
tag_set_data( tally_coord_sys_tag, &tally_meshset, 1, &tally_coord_sys );
749 int n_verts = planes[0].size() * planes[1].size() * planes[2].size();
750 if(
debug ) std::cout <<
"n_verts=" << n_verts << std::endl;
751 std::vector< double* > coord_arrays( 3 );
754 assert( 0 != start_vert );
756 for(
unsigned int k = 0; k < planes[2].size(); k++ )
758 for(
unsigned int j = 0; j < planes[1].size(); j++ )
760 for(
unsigned int i = 0; i < planes[0].size(); i++ )
762 unsigned int idx = ( k * planes[0].size() * planes[1].size() + j * planes[0].size() + i );
763 double in[3], out[3];
765 in[0] = planes[0][i];
766 in[1] = planes[1][j];
767 in[2] = planes[2][k];
773 coord_arrays[0][idx] = out[0];
774 coord_arrays[1][idx] = out[1];
775 coord_arrays[2][idx] = out[2];
779 Range vert_range( start_vert, start_vert + n_verts - 1 );
794 std::vector< double > planes[3],
808 unsigned int n_elements = ( planes[0].size() - 1 ) * ( planes[1].
size() - 1 ) * ( planes[2].
size() - 1 );
812 assert( 0 != start_element );
814 unsigned int counter = 0;
815 for(
unsigned int i = 0; i < planes[0].size() - 1; i++ )
817 for(
unsigned int j = 0; j < planes[1].size() - 1; j++ )
819 for(
unsigned int k = 0; k < planes[2].size() - 1; k++ )
821 index = start_vert + i + j * planes[0].size() + k * planes[0].size() * planes[1].size();
829 connect[1] = index + 1;
830 connect[2] = index + 1 + planes[0].size();
831 connect[3] = index + planes[0].size();
832 connect[4] = index + planes[0].size() * planes[1].size();
833 connect[5] = index + 1 + planes[0].size() * planes[1].size();
834 connect[6] = index + 1 + planes[0].size() + planes[0].size() * planes[1].size();
835 connect[7] = index + planes[0].size() + planes[0].size() * planes[1].size();
842 connect[1] = index + 1;
843 connect[2] = index + 1 + planes[0].size() * planes[1].size();
844 connect[3] = index + planes[0].size() * planes[1].size();
845 connect[4] = index + planes[0].size();
846 connect[5] = index + 1 + planes[0].size();
847 connect[6] = index + 1 + planes[0].size() + planes[0].size() * planes[1].size();
848 connect[7] = index + planes[0].size() + planes[0].size() * planes[1].size();
858 if( counter != n_elements ) std::cout <<
"counter=" << counter <<
" n_elements=" << n_elements << std::endl;
860 Range element_range( start_element, start_element + n_elements - 1 );
869 if(
debug ) std::cout <<
"Read " << n_elements <<
" elements from tally." << std::endl;
884 unsigned long int& new_nps,
885 unsigned long int nps1,
886 unsigned int tally_number,
887 Tag tally_number_tag,
893 unsigned int n_elements )
899 Range matching_tally_number_sets;
900 const void*
const tally_number_val[] = { &tally_number };
902 matching_tally_number_sets );
904 if(
debug ) std::cout <<
"number of matching meshsets=" << matching_tally_number_sets.
size() << std::endl;
905 assert( 1 == matching_tally_number_sets.
size() );
909 existing_meshset = matching_tally_number_sets.
front();
912 Range existing_elements;
915 assert( existing_elements.
size() == n_elements );
918 unsigned long int nps0;
919 Range sets_with_this_tag;
922 if(
debug ) std::cout <<
"number of nps sets=" << sets_with_this_tag.
size() << std::endl;
923 assert( 1 == sets_with_this_tag.
size() );
926 if(
debug ) std::cout <<
"nps0=" << nps0 <<
" nps1=" << nps1 << std::endl;
927 new_nps = nps0 + nps1;
930 double* values0 =
new double[existing_elements.
size()];
931 double* errors0 =
new double[existing_elements.
size()];
991 out[0] = in[0] * cos( 2 *
PI * in[2] );
992 out[1] = in[0] * sin( 2 *
PI * in[2] );
1007 const unsigned long int nps1,
1009 const double* values1,
1011 const double* errors1,
1012 const unsigned long int n_values )
1014 for(
unsigned long int i = 0; i < n_values; i++ )
1019 errors0[i] = sqrt( pow( values0[i] * errors0[i] * nps0, 2 ) + pow( values1[i] * errors1[i] * nps1, 2 ) ) /
1020 ( values0[i] * nps0 + values1[i] * nps1 );
1025 values0[i] = ( values0[i] * nps0 + values1[i] * nps1 ) / ( nps0 + nps1 );