MOAB: Mesh Oriented datABase  (version 5.2.1)
ReadNCDF.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      : ReadNCDF.hpp
00018 //
00019 // Purpose       : ExodusII reader
00020 //
00021 // Special Notes : Lots of code taken from verde implementation
00022 //
00023 // Creator       : Tim Tautges & Corey Ernst
00024 //
00025 // Date          : 3/02
00026 //
00027 // Owner         : Tim Tautges & Corey Ernst
00028 //-------------------------------------------------------------------------
00029 
00030 #ifndef READNCDF_HPP
00031 #define READNCDF_HPP
00032 
00033 #ifndef IS_BUILDING_MB
00034 //#error "ReadNCDF.hpp isn't supposed to be included into an application"
00035 #endif
00036 
00037 #include <vector>
00038 #include <string>
00039 
00040 #include "moab/Forward.hpp"
00041 #include "moab/ReaderIface.hpp"
00042 #include "moab/ExoIIInterface.hpp"
00043 #include "moab/Range.hpp"
00044 
00045 namespace moab
00046 {
00047 
00048 class ReadUtilIface;
00049 
00050 struct ReadBlockData
00051 {
00052     int blockId;
00053     int startExoId;
00054     EntityHandle startMBId;
00055     int numElements;
00056     bool reading_in;
00057     ExoIIElementType elemType;
00058     std::vector< EntityHandle > polys;  // used only if elem type is polyhedra or polygons
00059                                         // because the order has to be maintained
00060 };
00061 
00062 // these are for polyhedra only
00063 struct ReadFaceBlockData
00064 {
00065     int faceBlockId;
00066     int startExoId;
00067     int numElements;
00068     bool reading_in;
00069     // ExoIIElementType elemType; should be polygons
00070 };
00071 
00072 //! Output Exodus File for VERDE
00073 class ReadNCDF : public ReaderIface
00074 {
00075 
00076   public:
00077     static ReaderIface* factory( Interface* );
00078 
00079     void tokenize( const std::string& str, std::vector< std::string >& tokens, const char* delimiters );
00080 
00081     //! load an ExoII file
00082     ErrorCode load_file( const char* file_name, const EntityHandle* file_set, const FileOptions& opts,
00083                          const SubsetList* subset_list = 0, const Tag* file_id_tag = 0 );
00084 
00085     ErrorCode read_tag_values( const char* file_name, const char* tag_name, const FileOptions& opts,
00086                                std::vector< int >& tag_values_out, const SubsetList* subset_list = 0 );
00087 
00088     //! Constructor
00089     ReadNCDF( Interface* impl = NULL );
00090 
00091     //! Destructor
00092     virtual ~ReadNCDF();
00093 
00094     // update the coords for deformed mesh according to FileOptions
00095     ErrorCode update( const char* exodus_file_name, const FileOptions& opts, const int num_blocks,
00096                       const int* blocks_to_load, const EntityHandle file_set );
00097 
00098   private:
00099     ReadUtilIface* readMeshIface;
00100 
00101     bool dimension_exists( const char* attrib_name );
00102 
00103     void reset();
00104 
00105     //! read the header from the ExoII file
00106     ErrorCode read_exodus_header();
00107 
00108     //! read the nodes
00109     ErrorCode read_nodes( const Tag* file_id_tag );
00110 
00111     // face blocks for polyhedra
00112     ErrorCode read_face_blocks_headers();  // all of them?
00113 
00114     //! read block headers, containing info about element type, number, etc.
00115     ErrorCode read_block_headers( const int* blocks_to_load, const int num_blocks );
00116 
00117     // these are needed only when polyhedra are present
00118     ErrorCode read_polyhedra_faces();
00119 
00120     //! read the element blocks
00121     ErrorCode read_elements( const Tag* file_id_tag );
00122 
00123     //! read in the global element ids
00124     ErrorCode read_global_ids();
00125 
00126     //! read the nodesets into meshsets
00127     ErrorCode read_nodesets();
00128 
00129     //! read the sidesets (does nothing for now)
00130     ErrorCode read_sidesets();
00131 
00132     //! exodus file bound to this object
00133     int exodus_file();
00134 
00135     //! number of dimensions in this exo file
00136     int number_dimensions();
00137 
00138     //! map a character exodusII element type to a TSTT type & topology
00139     ErrorCode get_type( char* exo_element_type, EntityType& elem_type );
00140 
00141     ErrorCode get_type( EntityType& elem_type, std::string& exo_element_type );
00142 
00143     /*
00144     int get_int_tag(const MB_MeshSet *this_ms,
00145                     const TagHandle tag_id);
00146    */
00147 
00148     // qa record stuff
00149     ErrorCode read_qa_records( EntityHandle file_set );
00150     ErrorCode read_qa_information( std::vector< std::string >& qa_record_list );
00151 
00152     ErrorCode read_qa_string( char* string, int record_number, int record_position );
00153 
00154     ErrorCode create_ss_elements( int* element_ids, int* side_list, int num_sides, int num_dist_factors,
00155                                   std::vector< EntityHandle >& entities_to_add,
00156                                   std::vector< EntityHandle >& reverse_entities,
00157                                   std::vector< double >& dist_factor_vector, int ss_seq_id );
00158 
00159     ErrorCode find_side_element_type( const int element_id, ExoIIElementType& type, ReadBlockData& block_data,
00160                                       int& df_index, int side_id );
00161 
00162     /* ErrorCode assign_block_ids_to_ssets(EntityHandle ss_handle,
00163                                             MB_MeshSet *ss_mesh_set);
00164                                             */
00165 
00166     //! creates an element with the given connectivity
00167     ErrorCode create_sideset_element( const std::vector< EntityHandle >&, EntityType, EntityHandle&, int& );
00168 
00169     int get_number_nodes( EntityHandle handle );
00170 
00171     //------------member variables ------------//
00172 
00173     //! interface instance
00174     Interface* mdbImpl;
00175 
00176     int ncFile;  // netcdf/exodus file
00177 
00178     int CPU_WORD_SIZE;
00179     int IO_WORD_SIZE;
00180 
00181     //! int to offset vertex ids with
00182     int vertexOffset;
00183 
00184     //! file name
00185     std::string exodusFile;
00186 
00187     //! number of nodes in the current exoII file
00188     int numberNodes_loading;
00189 
00190     //! number of elements in the current exoII file
00191     int numberElements_loading;
00192 
00193     //! number of blocks in the current exoII file
00194     int numberElementBlocks_loading;
00195 
00196     //! number of face blocks in the current exoII file (used for polyhedra)
00197     int numberFaceBlocks_loading;
00198 
00199     //! number of nodesets in the current exoII file
00200     int numberNodeSets_loading;
00201 
00202     //! number of sidesets in the current exoII file
00203     int numberSideSets_loading;
00204 
00205     int numberDimensions_loading;
00206 
00207     //! Meshset Handle for the mesh that is currently being read
00208     EntityHandle mCurrentMeshHandle;
00209 
00210     // keeps track of the exodus ids of the elements and nodes just loaded
00211     std::vector< char > nodesInLoadedBlocks;
00212     // note- vector<bool> has limited capabilities
00213 
00214     // vector of blocks that are loading
00215     std::vector< ReadBlockData > blocksLoading;
00216 
00217     std::vector< EntityHandle > polyfaces;  // the order is maintained with this for polyhedra
00218 
00219     // vector of face blocks that are loading : these are for polyhedra blocks
00220     std::vector< ReadFaceBlockData > faceBlocksLoading;
00221 
00222     //! Cached tags for reading.  Note that all these tags are defined when the
00223     //! core is initialized.
00224     Tag mMaterialSetTag;
00225     Tag mDirichletSetTag;
00226     Tag mNeumannSetTag;
00227     Tag mHasMidNodesTag;
00228     Tag mDistFactorTag;
00229     Tag mGlobalIdTag;
00230     Tag mQaRecordTag;
00231 
00232     int max_line_length, max_str_length;
00233 
00234     //! range of entities in initial mesh, before this read
00235     Range initRange;
00236 };
00237 
00238 // inline functions
00239 inline int ReadNCDF::number_dimensions()
00240 {
00241     return numberDimensions_loading;
00242 }
00243 
00244 }  // namespace moab
00245 
00246 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines