MOAB: Mesh Oriented datABase  (version 5.4.1)
WriteNCDF.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      : WriteNCDF.hpp
00018 //
00019 // Purpose       : ExodusII writer
00020 //
00021 // Special Notes : Lots of code taken from verde implementation
00022 //
00023 // Creator       : Corey Ernst
00024 //
00025 // Date          : 8/02
00026 //
00027 // Owner         : Corey Ernst
00028 //-------------------------------------------------------------------------
00029 
00030 #ifndef WRITENCDF_HPP
00031 #define WRITENCDF_HPP
00032 
00033 #ifndef IS_BUILDING_MB
00034 #error "WriteNCDF.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/Range.hpp"
00042 #include "moab/ExoIIInterface.hpp"
00043 #include "moab/WriterIface.hpp"
00044 
00045 namespace moab
00046 {
00047 
00048 class WriteUtilIface;
00049 
00050 //! struct used to hold data for each block to be output in Exodus; used by
00051 //! initialize_exodus_file to initialize the file header for increased speed
00052 struct MaterialSetData
00053 {
00054     int id;
00055     int number_elements;
00056     int number_nodes_per_element;
00057     int number_attributes;
00058     ExoIIElementType element_type;
00059     Range elements;
00060 };
00061 
00062 //! struct used to hold data for each nodeset to be output in Exodus; used by
00063 //! initialize_exodus_file to initialize the file header for increased speed
00064 struct DirichletSetData
00065 {
00066     int id;
00067     int number_nodes;
00068     std::vector< EntityHandle > nodes;
00069     std::vector< double > node_dist_factors;
00070 };
00071 
00072 //! struct used to hold data for each sideset to be output in Exodus; used by
00073 //! initialize_exodus_file to initialize the file header for increased speed
00074 struct NeumannSetData
00075 {
00076     int id;
00077     int number_elements;
00078     std::vector< EntityHandle > elements;
00079     std::vector< int > side_numbers;
00080     EntityHandle mesh_set_handle;
00081     std::vector< double > ss_dist_factors;
00082 };
00083 
00084 //! Output Exodus File for VERDE
00085 class WriteNCDF : public WriterIface
00086 {
00087 
00088   public:
00089     static WriterIface* factory( Interface* );
00090 
00091     //! Constructor
00092     WriteNCDF( Interface* impl );
00093 
00094     //! Destructor
00095     virtual ~WriteNCDF();
00096 
00097     //! writes out an ExoII file
00098     ErrorCode write_file( const char* exodus_file_name,
00099                           const bool overwrite,
00100                           const FileOptions& opts,
00101                           const EntityHandle* output_list,
00102                           const int num_sets,
00103                           const std::vector< std::string >& qa_records,
00104                           const Tag*         = NULL,
00105                           int                = 0,
00106                           int user_dimension = 3 );
00107 
00108   protected:
00109     //! number of dimensions in this exo file
00110     // int number_dimensions();
00111 
00112     //! open an ExoII file for writing
00113     ErrorCode open_file( const char* file_name );
00114 
00115     //! contains the general information about a mesh
00116     struct ExodusMeshInfo
00117     {
00118         unsigned int num_dim;
00119         unsigned int num_nodes;
00120         unsigned int num_elements;
00121         unsigned int num_elementblocks;
00122         unsigned int num_polyhedra_blocks;
00123         std::vector< std::string > qaRecords;
00124         Range nodes;
00125         Range polyhedronFaces;  // they will accumulate, like nodes
00126         // they will be written before any other face blocks, and before polyhedra blocks
00127     };
00128 
00129   private:
00130     //! interface instance
00131     Interface* mdbImpl;
00132     WriteUtilIface* mWriteIface;
00133 
00134     //! file name
00135     std::string exodusFile;
00136     int ncFile;
00137 
00138     //! Meshset Handle for the mesh that is currently being read
00139     EntityHandle mCurrentMeshHandle;
00140 
00141     //! Cached tags for reading.  Note that all these tags are defined when the
00142     //! core is initialized.
00143     Tag mMaterialSetTag;
00144     Tag mDirichletSetTag;
00145     Tag mNeumannSetTag;
00146     Tag mHasMidNodesTag;
00147     Tag mGeomDimensionTag;
00148     Tag mDistFactorTag;
00149     Tag mGlobalIdTag;
00150     Tag mQaRecordTag;
00151 
00152     Tag mEntityMark;  // used to say whether an entity will be exported
00153 
00154     int repeat_face_blocks;  // only to make paraview and visit happy
00155 
00156     ErrorCode gather_mesh_information( ExodusMeshInfo& mesh_info,
00157                                        std::vector< MaterialSetData >& block_info,
00158                                        std::vector< NeumannSetData >& sideset_info,
00159                                        std::vector< DirichletSetData >& nodeset_info,
00160                                        std::vector< EntityHandle >& blocks,
00161                                        std::vector< EntityHandle >& sidesets,
00162                                        std::vector< EntityHandle >& nodesets );
00163 
00164     ErrorCode write_header( ExodusMeshInfo& mesh_info,
00165                             std::vector< MaterialSetData >& block_info,
00166                             std::vector< NeumannSetData >& sideset_info,
00167                             std::vector< DirichletSetData >& nodeset_info,
00168                             const char* filename );
00169 
00170     ErrorCode initialize_exodus_file( ExodusMeshInfo& mesh_info,
00171                                       std::vector< MaterialSetData >& block_data,
00172                                       std::vector< NeumannSetData >& sideset_data,
00173                                       std::vector< DirichletSetData >& nodeset_data,
00174                                       const char* title_string,
00175                                       bool write_maps                         = true,
00176                                       bool write_sideset_distribution_factors = true );
00177 
00178     ErrorCode write_qa_string( const char* string, int record_number, int record_position );
00179 
00180     ErrorCode write_qa_records( std::vector< std::string >& qa_record_list );
00181 
00182     ErrorCode write_nodes( int num_nodes, Range& nodes, int dimension );
00183 
00184     ErrorCode write_poly_faces( ExodusMeshInfo& mesh_info );
00185     ErrorCode write_elementblocks( ExodusMeshInfo& mesh_info, std::vector< MaterialSetData >& block_data );
00186 
00187     ErrorCode write_exodus_integer_variable( const char* variable_name,
00188                                              int* variable_array,
00189                                              int start_position,
00190                                              int number_values );
00191 
00192     ErrorCode write_global_node_order_map( int num_nodes, Range& nodes );
00193     ErrorCode write_global_element_order_map( int num_elements );
00194     ErrorCode write_element_order_map( int num_elements );
00195 
00196     ErrorCode write_BCs( std::vector< NeumannSetData >& sidesets, std::vector< DirichletSetData >& nodesets );
00197 
00198     ErrorCode find_side_element_type( const int element_id, ExoIIElementType& type );
00199 
00200     /* ErrorCode assign_block_ids_to_ssets(EntityHandle ss_handle,
00201                                             MB_MeshSet *ss_mesh_set);
00202                                             */
00203     //! free up allocated Ranges
00204     void reset_block( std::vector< MaterialSetData >& block_info );
00205 
00206     //! recursive function; given a meshset handle, get the entities and put them
00207     //! on the right list, then call recursively for any contained meshsets, first
00208     //! checking for sense reversals
00209     ErrorCode get_sideset_elems( EntityHandle sideset, int current_sense, Range& forward_elems, Range& reverse_elems );
00210 
00211     ErrorCode get_valid_sides( Range& elems, ExodusMeshInfo& mesh_info, const int sense, NeumannSetData& sideset_data );
00212 
00213     //! get the time and date in strings
00214     static void time_and_date( char* time_string, char* date_string );
00215 };
00216 
00217 }  // namespace moab
00218 
00219 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines