moab
|
00001 00016 //---------------------------------------------------------------------- 00017 // Filename : ReadMCNP5.hpp 00018 // Purpose : Read a meshtal file created by MCNP5 into MOAB 00019 // Creator : Brandon Smith 00020 // Date : 07/2009 00021 //---------------------------------------------------------------------- 00022 00040 #include "moab/Interface.hpp" 00041 #include "moab/ReaderIface.hpp" 00042 #include <iostream> 00043 #include <fstream> 00044 #include <sstream> 00045 #include <vector> 00046 00047 namespace moab { 00048 00049 class ReadUtilIface; 00050 00051 class ReadMCNP5 : public ReaderIface 00052 { 00053 00054 public: 00055 // factory method 00056 static ReaderIface* factory( Interface* ); 00057 00058 ErrorCode load_file( const char* file_name, 00059 const EntityHandle* file_set, 00060 const FileOptions& opts, 00061 const SubsetList* subset_list = 0, 00062 const Tag* file_id_tag = 0 ); 00063 00064 ErrorCode read_tag_values( const char* file_name, 00065 const char* tag_name, 00066 const FileOptions& opts, 00067 std::vector<int>& tag_values_out, 00068 const SubsetList* subset_list = 0 ); 00069 00070 // constructor 00071 ReadMCNP5(Interface* impl = NULL); 00072 00073 // destructor 00074 virtual ~ReadMCNP5(); 00075 00076 protected: 00077 00078 private: 00079 // constants 00080 static const double PI; 00081 static const double C2PI; 00082 static const double CPI; 00083 00084 enum coordinate_system { NO_SYSTEM, 00085 CARTESIAN, 00086 CYLINDRICAL, 00087 SPHERICAL }; 00088 enum particle { NEUTRON, 00089 PHOTON, 00090 ELECTRON }; 00091 00092 // read mesh interface 00093 ReadUtilIface* readMeshIface; 00094 00095 // MOAB Interface 00096 Interface* MBI; 00097 00098 const Tag* fileIDTag; 00099 int nodeId, elemId; 00100 00101 // reads the meshtal file 00102 ErrorCode load_one_file( const char *fname, 00103 const EntityHandle *input_meshset, 00104 const FileOptions &options, 00105 const bool average ); 00106 00107 ErrorCode create_tags( Tag &date_and_time_tag, 00108 Tag &title_tag, 00109 Tag &nps_tag, 00110 Tag &tally_number_tag, 00111 Tag &tally_comment_tag, 00112 Tag &tally_particle_tag, 00113 Tag &tally_coord_sys_tag, 00114 Tag &tally_tag, 00115 Tag &error_tag ); 00116 00117 ErrorCode read_file_header( std::fstream &file, 00118 bool debug, 00119 char date_and_time[100], 00120 char title[100], 00121 unsigned long int &nps ); 00122 00123 ErrorCode set_header_tags( EntityHandle output_meshset, 00124 char date_and_time[100], 00125 char title[100], 00126 unsigned long int nps, 00127 Tag data_and_time_tag, 00128 Tag title_tag, 00129 Tag nps_tag ); 00130 00131 ErrorCode read_tally_header( std::fstream &file, 00132 bool debug, 00133 unsigned int &tally_number, 00134 char tally_comment[100], 00135 particle &tally_particle ); 00136 00137 ErrorCode get_tally_particle( std::string a, 00138 bool debug, 00139 particle &tally_particle ); 00140 00141 ErrorCode read_mesh_planes( std::fstream &file, 00142 bool debug, 00143 std::vector<double> planes[3], 00144 coordinate_system &coord_sys); 00145 00146 ErrorCode get_mesh_plane( std::istringstream &ss, 00147 bool debug, 00148 std::vector<double> &plane); 00149 00150 ErrorCode read_element_values_and_errors( std::fstream &file, 00151 bool debug, 00152 std::vector<double> planes[3], 00153 unsigned int n_chopped_x0_planes, 00154 unsigned int n_chopped_x2_planes, 00155 particle tally_particle, 00156 double values[], 00157 double errors[] ); 00158 00159 ErrorCode set_tally_tags( EntityHandle tally_meshset, 00160 unsigned int tally_number, 00161 char tally_comment[100], 00162 particle tally_particle, 00163 coordinate_system tally_coord_sys, 00164 Tag tally_number_tag, 00165 Tag tally_comment_tag, 00166 Tag tally_particle_tag, 00167 Tag tally_coord_sys_tag ); 00168 00169 ErrorCode create_vertices( std::vector<double> planes[3], 00170 bool debug, 00171 EntityHandle &start_vert, 00172 coordinate_system coord_sys, 00173 EntityHandle tally_meshset ); 00174 00175 ErrorCode create_elements( bool debug, 00176 std::vector<double> planes[3], 00177 unsigned int n_chopped_x0_planes, 00178 unsigned int n_chopped_x2_planes, 00179 EntityHandle start_vert, 00180 double values[], 00181 double errors[], 00182 Tag tally_tag, 00183 Tag error_tag, 00184 EntityHandle tally_meshset, 00185 coordinate_system tally_coord_sys ); 00186 00187 ErrorCode average_with_existing_tally( bool debug, 00188 unsigned long int &new_nps, 00189 unsigned long int nps, 00190 unsigned int tally_number, 00191 Tag tally_number_tag, 00192 Tag nps_tag, 00193 Tag tally_tag, 00194 Tag error_tag, 00195 double values[], 00196 double errors[], 00197 unsigned int n_elements ); 00198 00199 ErrorCode transform_point_to_cartesian(double *in, 00200 double *out, 00201 coordinate_system coord_sys); 00202 00203 ErrorCode average_tally_values(const unsigned long int nps0, 00204 const unsigned long int nps1, 00205 double *values0, 00206 const double *values1, 00207 double *errors0, 00208 const double *errors1, 00209 const unsigned long int n_values); 00210 }; 00211 00212 } // namespace moab