Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ReadNCDF.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 : ReadNCDF.hpp
18 //
19 // Purpose : ExodusII reader
20 //
21 // Special Notes : Lots of code taken from verde implementation
22 //
23 // Creator : Tim Tautges & Corey Ernst
24 //
25 // Date : 3/02
26 //
27 // Owner : Tim Tautges & Corey Ernst
28 //-------------------------------------------------------------------------
29 
30 #ifndef READNCDF_HPP
31 #define READNCDF_HPP
32 
33 #ifndef IS_BUILDING_MB
34 //#error "ReadNCDF.hpp isn't supposed to be included into an application"
35 #endif
36 
37 #include <vector>
38 #include <string>
39 
40 #include "moab/Forward.hpp"
41 #include "moab/ReaderIface.hpp"
42 #include "moab/ExoIIInterface.hpp"
43 #include "moab/Range.hpp"
44 
45 namespace moab
46 {
47 
48 class ReadUtilIface;
49 
51 {
52  int blockId;
56  bool reading_in;
58  std::vector< EntityHandle > polys; // used only if elem type is polyhedra or polygons
59  // because the order has to be maintained
60 };
61 
62 // these are for polyhedra only
64 {
68  bool reading_in;
69  // ExoIIElementType elemType; should be polygons
70 };
71 
72 //! Output Exodus File for VERDE
73 class ReadNCDF : public ReaderIface
74 {
75 
76  public:
77  static ReaderIface* factory( Interface* );
78 
79  void tokenize( const std::string& str, std::vector< std::string >& tokens, const char* delimiters );
80 
81  //! load an ExoII file
82  ErrorCode load_file( const char* file_name,
83  const EntityHandle* file_set,
84  const FileOptions& opts,
85  const SubsetList* subset_list = 0,
86  const Tag* file_id_tag = 0 );
87 
88  ErrorCode read_tag_values( const char* file_name,
89  const char* tag_name,
90  const FileOptions& opts,
91  std::vector< int >& tag_values_out,
92  const SubsetList* subset_list = 0 );
93 
94  //! Constructor
95  ReadNCDF( Interface* impl = NULL );
96 
97  //! Destructor
98  virtual ~ReadNCDF();
99 
100  // update the coords for deformed mesh according to FileOptions
101  ErrorCode update( const char* exodus_file_name,
102  const FileOptions& opts,
103  const int num_blocks,
104  const int* blocks_to_load,
105  const EntityHandle file_set );
106 
107  private:
109 
110  bool dimension_exists( const char* attrib_name );
111 
112  void reset();
113 
114  //! read the header from the ExoII file
116 
117  //! read the nodes
118  ErrorCode read_nodes( const Tag* file_id_tag );
119 
120  // face blocks for polyhedra
121  ErrorCode read_face_blocks_headers(); // all of them?
122 
123  //! read block headers, containing info about element type, number, etc.
124  ErrorCode read_block_headers( const int* blocks_to_load, const int num_blocks );
125 
126  // these are needed only when polyhedra are present
128 
129  //! read the element blocks
130  ErrorCode read_elements( const Tag* file_id_tag );
131 
132  //! read in the global element ids
134 
135  //! read the nodesets into meshsets
137 
138  //! read the sidesets (does nothing for now)
140 
141  //! exodus file bound to this object
142  int exodus_file();
143 
144  //! number of dimensions in this exo file
145  int number_dimensions();
146 
147  //! map a character exodusII element type to a TSTT type & topology
148  ErrorCode get_type( char* exo_element_type, EntityType& elem_type );
149 
150  ErrorCode get_type( EntityType& elem_type, std::string& exo_element_type );
151 
152  /*
153  int get_int_tag(const MB_MeshSet *this_ms,
154  const TagHandle tag_id);
155  */
156 
157  // qa record stuff
159  ErrorCode read_qa_information( std::vector< std::string >& qa_record_list );
160 
161  ErrorCode read_qa_string( char* string, int record_number, int record_position );
162 
163  ErrorCode create_ss_elements( int* element_ids,
164  int* side_list,
165  int num_sides,
166  int num_dist_factors,
167  std::vector< EntityHandle >& entities_to_add,
168  std::vector< EntityHandle >& reverse_entities,
169  std::vector< double >& dist_factor_vector,
170  int ss_seq_id );
171 
172  ErrorCode find_side_element_type( const int element_id,
173  ExoIIElementType& type,
174  ReadBlockData& block_data,
175  int& df_index,
176  int side_id );
177 
178  /* ErrorCode assign_block_ids_to_ssets(EntityHandle ss_handle,
179  MB_MeshSet *ss_mesh_set);
180  */
181 
182  //! creates an element with the given connectivity
183  ErrorCode create_sideset_element( const std::vector< EntityHandle >&, EntityType, EntityHandle&, int& );
184 
186 
187  //------------member variables ------------//
188 
189  //! interface instance
191 
192  int ncFile; // netcdf/exodus file
193 
196 
197  //! int to offset vertex ids with
199 
200  //! file name
201  std::string exodusFile;
202 
203  //! number of nodes in the current exoII file
205 
206  //! number of elements in the current exoII file
208 
209  //! number of blocks in the current exoII file
211 
212  //! number of face blocks in the current exoII file (used for polyhedra)
214 
215  //! number of nodesets in the current exoII file
217 
218  //! number of sidesets in the current exoII file
220 
222 
223  //! Meshset Handle for the mesh that is currently being read
225 
226  // keeps track of the exodus ids of the elements and nodes just loaded
227  std::vector< char > nodesInLoadedBlocks;
228  // note- vector<bool> has limited capabilities
229 
230  // vector of blocks that are loading
231  std::vector< ReadBlockData > blocksLoading;
232 
233  std::vector< EntityHandle > polyfaces; // the order is maintained with this for polyhedra
234 
235  // vector of face blocks that are loading : these are for polyhedra blocks
236  std::vector< ReadFaceBlockData > faceBlocksLoading;
237 
238  //! Cached tags for reading. Note that all these tags are defined when the
239  //! core is initialized.
247 
249 
250  //! range of entities in initial mesh, before this read
252 };
253 
254 // inline functions
256 {
258 }
259 
260 } // namespace moab
261 
262 #endif