Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ReadMCNP5.hpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 //----------------------------------------------------------------------
17 // Filename : ReadMCNP5.hpp
18 // Purpose : Read a meshtal file created by MCNP5 into MOAB
19 // Creator : Brandon Smith
20 // Date : 07/2009
21 //----------------------------------------------------------------------
22 
23 /**
24  * Data structure of MCNP5 data created by this reader:
25  *
26  * each file_meshset contains
27  * DATA_AND_TIME_TAG
28  * TITLE_TAG
29  * NPS_TAG
30  * each tally_meshset contains
31  * TALLY_NUMBER_TAG
32  * TALLY_COMMENT_TAG
33  * TALLY_PARTICLE_TAG
34  * TALLY_COORD_SYS_TAG
35  * each mesh element contains
36  * TALLY_TAG
37  * ERROR_TAG
38  */
39 
40 #include "moab/Interface.hpp"
41 #include "moab/ReaderIface.hpp"
42 #include <iostream>
43 #include <fstream>
44 #include <sstream>
45 #include <vector>
46 
47 namespace moab
48 {
49 
50 class ReadUtilIface;
51 
52 class ReadMCNP5 : public ReaderIface
53 {
54 
55  public:
56  // factory method
57  static ReaderIface* factory( Interface* );
58 
59  ErrorCode load_file( const char* file_name,
60  const EntityHandle* file_set,
61  const FileOptions& opts,
62  const SubsetList* subset_list = 0,
63  const Tag* file_id_tag = 0 );
64 
65  ErrorCode read_tag_values( const char* file_name,
66  const char* tag_name,
67  const FileOptions& opts,
68  std::vector< int >& tag_values_out,
69  const SubsetList* subset_list = 0 );
70 
71  // constructor
72  ReadMCNP5( Interface* impl = NULL );
73 
74  // destructor
75  virtual ~ReadMCNP5();
76 
77  protected:
78  private:
79  // constants
80  static const double PI;
81  static const double C2PI;
82  static const double CPI;
83 
85  {
89  SPHERICAL
90  };
91  enum particle
92  {
95  ELECTRON
96  };
97 
98  // read mesh interface
100 
101  // MOAB Interface
103 
104  const Tag* fileIDTag;
106 
107  // reads the meshtal file
108  ErrorCode load_one_file( const char* fname,
109  const EntityHandle* input_meshset,
110  const FileOptions& options,
111  const bool average );
112 
113  ErrorCode create_tags( Tag& date_and_time_tag,
114  Tag& title_tag,
115  Tag& nps_tag,
116  Tag& tally_number_tag,
117  Tag& tally_comment_tag,
118  Tag& tally_particle_tag,
119  Tag& tally_coord_sys_tag,
120  Tag& tally_tag,
121  Tag& error_tag );
122 
123  ErrorCode read_file_header( std::fstream& file,
124  bool debug,
125  char date_and_time[100],
126  char title[100],
127  unsigned long int& nps );
128 
129  ErrorCode set_header_tags( EntityHandle output_meshset,
130  char date_and_time[100],
131  char title[100],
132  unsigned long int nps,
133  Tag data_and_time_tag,
134  Tag title_tag,
135  Tag nps_tag );
136 
137  ErrorCode read_tally_header( std::fstream& file,
138  bool debug,
139  unsigned int& tally_number,
140  char tally_comment[100],
141  particle& tally_particle );
142 
143  ErrorCode get_tally_particle( std::string a, bool debug, particle& tally_particle );
144 
145  ErrorCode read_mesh_planes( std::fstream& file,
146  bool debug,
147  std::vector< double > planes[3],
148  coordinate_system& coord_sys );
149 
150  ErrorCode get_mesh_plane( std::istringstream& ss, bool debug, std::vector< double >& plane );
151 
152  ErrorCode read_element_values_and_errors( std::fstream& file,
153  bool debug,
154  std::vector< double > planes[3],
155  unsigned int n_chopped_x0_planes,
156  unsigned int n_chopped_x2_planes,
157  particle tally_particle,
158  double values[],
159  double errors[] );
160 
161  ErrorCode set_tally_tags( EntityHandle tally_meshset,
162  unsigned int tally_number,
163  char tally_comment[100],
164  particle tally_particle,
165  coordinate_system tally_coord_sys,
166  Tag tally_number_tag,
167  Tag tally_comment_tag,
168  Tag tally_particle_tag,
169  Tag tally_coord_sys_tag );
170 
171  ErrorCode create_vertices( std::vector< double > planes[3],
172  bool debug,
173  EntityHandle& start_vert,
174  coordinate_system coord_sys,
175  EntityHandle tally_meshset );
176 
178  std::vector< double > planes[3],
179  unsigned int n_chopped_x0_planes,
180  unsigned int n_chopped_x2_planes,
181  EntityHandle start_vert,
182  double values[],
183  double errors[],
184  Tag tally_tag,
185  Tag error_tag,
186  EntityHandle tally_meshset,
187  coordinate_system tally_coord_sys );
188 
190  unsigned long int& new_nps,
191  unsigned long int nps,
192  unsigned int tally_number,
193  Tag tally_number_tag,
194  Tag nps_tag,
195  Tag tally_tag,
196  Tag error_tag,
197  double values[],
198  double errors[],
199  unsigned int n_elements );
200 
201  ErrorCode transform_point_to_cartesian( double* in, double* out, coordinate_system coord_sys );
202 
203  ErrorCode average_tally_values( const unsigned long int nps0,
204  const unsigned long int nps1,
205  double* values0,
206  const double* values1,
207  double* errors0,
208  const double* errors1,
209  const unsigned long int n_values );
210 };
211 
212 } // namespace moab