Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
ReadMCNP5.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
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 
00023 /**
00024  * Data structure of MCNP5 data created by this reader:
00025  *
00026  * each file_meshset contains
00027  *   DATA_AND_TIME_TAG
00028  *   TITLE_TAG
00029  *   NPS_TAG
00030  *   each tally_meshset contains
00031  *     TALLY_NUMBER_TAG
00032  *     TALLY_COMMENT_TAG
00033  *     TALLY_PARTICLE_TAG
00034  *     TALLY_COORD_SYS_TAG
00035  *     each mesh element contains
00036  *       TALLY_TAG
00037  *       ERROR_TAG
00038  */
00039 
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 
00050 class ReadUtilIface;
00051 
00052 class ReadMCNP5 : public ReaderIface
00053 {
00054 
00055   public:
00056     // factory method
00057     static ReaderIface* factory( Interface* );
00058 
00059     ErrorCode load_file( const char* file_name,
00060                          const EntityHandle* file_set,
00061                          const FileOptions& opts,
00062                          const SubsetList* subset_list = 0,
00063                          const Tag* file_id_tag        = 0 );
00064 
00065     ErrorCode read_tag_values( const char* file_name,
00066                                const char* tag_name,
00067                                const FileOptions& opts,
00068                                std::vector< int >& tag_values_out,
00069                                const SubsetList* subset_list = 0 );
00070 
00071     // constructor
00072     ReadMCNP5( Interface* impl = NULL );
00073 
00074     // destructor
00075     virtual ~ReadMCNP5();
00076 
00077   protected:
00078   private:
00079     // constants
00080     static const double PI;
00081     static const double C2PI;
00082     static const double CPI;
00083 
00084     enum coordinate_system
00085     {
00086         NO_SYSTEM,
00087         CARTESIAN,
00088         CYLINDRICAL,
00089         SPHERICAL
00090     };
00091     enum particle
00092     {
00093         NEUTRON,
00094         PHOTON,
00095         ELECTRON
00096     };
00097 
00098     // read mesh interface
00099     ReadUtilIface* readMeshIface;
00100 
00101     // MOAB Interface
00102     Interface* MBI;
00103 
00104     const Tag* fileIDTag;
00105     int nodeId, elemId;
00106 
00107     // reads the meshtal file
00108     ErrorCode load_one_file( const char* fname,
00109                              const EntityHandle* input_meshset,
00110                              const FileOptions& options,
00111                              const bool average );
00112 
00113     ErrorCode create_tags( Tag& date_and_time_tag,
00114                            Tag& title_tag,
00115                            Tag& nps_tag,
00116                            Tag& tally_number_tag,
00117                            Tag& tally_comment_tag,
00118                            Tag& tally_particle_tag,
00119                            Tag& tally_coord_sys_tag,
00120                            Tag& tally_tag,
00121                            Tag& error_tag );
00122 
00123     ErrorCode read_file_header( std::fstream& file,
00124                                 bool debug,
00125                                 char date_and_time[100],
00126                                 char title[100],
00127                                 unsigned long int& nps );
00128 
00129     ErrorCode set_header_tags( EntityHandle output_meshset,
00130                                char date_and_time[100],
00131                                char title[100],
00132                                unsigned long int nps,
00133                                Tag data_and_time_tag,
00134                                Tag title_tag,
00135                                Tag nps_tag );
00136 
00137     ErrorCode read_tally_header( std::fstream& file,
00138                                  bool debug,
00139                                  unsigned int& tally_number,
00140                                  char tally_comment[100],
00141                                  particle& tally_particle );
00142 
00143     ErrorCode get_tally_particle( std::string a, bool debug, particle& tally_particle );
00144 
00145     ErrorCode read_mesh_planes( std::fstream& file,
00146                                 bool debug,
00147                                 std::vector< double > planes[3],
00148                                 coordinate_system& coord_sys );
00149 
00150     ErrorCode get_mesh_plane( std::istringstream& ss, bool debug, std::vector< double >& plane );
00151 
00152     ErrorCode read_element_values_and_errors( std::fstream& file,
00153                                               bool debug,
00154                                               std::vector< double > planes[3],
00155                                               unsigned int n_chopped_x0_planes,
00156                                               unsigned int n_chopped_x2_planes,
00157                                               particle tally_particle,
00158                                               double values[],
00159                                               double errors[] );
00160 
00161     ErrorCode set_tally_tags( EntityHandle tally_meshset,
00162                               unsigned int tally_number,
00163                               char tally_comment[100],
00164                               particle tally_particle,
00165                               coordinate_system tally_coord_sys,
00166                               Tag tally_number_tag,
00167                               Tag tally_comment_tag,
00168                               Tag tally_particle_tag,
00169                               Tag tally_coord_sys_tag );
00170 
00171     ErrorCode create_vertices( std::vector< double > planes[3],
00172                                bool debug,
00173                                EntityHandle& start_vert,
00174                                coordinate_system coord_sys,
00175                                EntityHandle tally_meshset );
00176 
00177     ErrorCode create_elements( bool debug,
00178                                std::vector< double > planes[3],
00179                                unsigned int n_chopped_x0_planes,
00180                                unsigned int n_chopped_x2_planes,
00181                                EntityHandle start_vert,
00182                                double values[],
00183                                double errors[],
00184                                Tag tally_tag,
00185                                Tag error_tag,
00186                                EntityHandle tally_meshset,
00187                                coordinate_system tally_coord_sys );
00188 
00189     ErrorCode average_with_existing_tally( bool debug,
00190                                            unsigned long int& new_nps,
00191                                            unsigned long int nps,
00192                                            unsigned int tally_number,
00193                                            Tag tally_number_tag,
00194                                            Tag nps_tag,
00195                                            Tag tally_tag,
00196                                            Tag error_tag,
00197                                            double values[],
00198                                            double errors[],
00199                                            unsigned int n_elements );
00200 
00201     ErrorCode transform_point_to_cartesian( double* in, double* out, 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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines