MOAB: Mesh Oriented datABase
(version 5.2.1)
|
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, const bool overwrite, const FileOptions& opts, 00099 const EntityHandle* output_list, const int num_sets, 00100 const std::vector< std::string >& qa_records, const Tag* = NULL, int = 0, 00101 int user_dimension = 3 ); 00102 00103 protected: 00104 //! number of dimensions in this exo file 00105 // int number_dimensions(); 00106 00107 //! open an ExoII file for writing 00108 ErrorCode open_file( const char* file_name ); 00109 00110 //! contains the general information about a mesh 00111 struct ExodusMeshInfo 00112 { 00113 unsigned int num_dim; 00114 unsigned int num_nodes; 00115 unsigned int num_elements; 00116 unsigned int num_elementblocks; 00117 unsigned int num_polyhedra_blocks; 00118 std::vector< std::string > qaRecords; 00119 Range nodes; 00120 Range polyhedronFaces; // they will accumulate, like nodes 00121 // they will be written before any other face blocks, and before polyhedra blocks 00122 }; 00123 00124 private: 00125 //! interface instance 00126 Interface* mdbImpl; 00127 WriteUtilIface* mWriteIface; 00128 00129 //! file name 00130 std::string exodusFile; 00131 int ncFile; 00132 00133 //! Meshset Handle for the mesh that is currently being read 00134 EntityHandle mCurrentMeshHandle; 00135 00136 //! Cached tags for reading. Note that all these tags are defined when the 00137 //! core is initialized. 00138 Tag mMaterialSetTag; 00139 Tag mDirichletSetTag; 00140 Tag mNeumannSetTag; 00141 Tag mHasMidNodesTag; 00142 Tag mGeomDimensionTag; 00143 Tag mDistFactorTag; 00144 Tag mGlobalIdTag; 00145 Tag mQaRecordTag; 00146 00147 Tag mEntityMark; // used to say whether an entity will be exported 00148 00149 int repeat_face_blocks; // only to make paraview and visit happy 00150 00151 ErrorCode gather_mesh_information( ExodusMeshInfo& mesh_info, std::vector< MaterialSetData >& block_info, 00152 std::vector< NeumannSetData >& sideset_info, 00153 std::vector< DirichletSetData >& nodeset_info, 00154 std::vector< EntityHandle >& blocks, std::vector< EntityHandle >& sidesets, 00155 std::vector< EntityHandle >& nodesets ); 00156 00157 ErrorCode write_header( ExodusMeshInfo& mesh_info, std::vector< MaterialSetData >& block_info, 00158 std::vector< NeumannSetData >& sideset_info, std::vector< DirichletSetData >& nodeset_info, 00159 const char* filename ); 00160 00161 ErrorCode initialize_exodus_file( ExodusMeshInfo& mesh_info, std::vector< MaterialSetData >& block_data, 00162 std::vector< NeumannSetData >& sideset_data, 00163 std::vector< DirichletSetData >& nodeset_data, const char* title_string, 00164 bool write_maps = true, bool write_sideset_distribution_factors = true ); 00165 00166 ErrorCode write_qa_string( const char* string, int record_number, int record_position ); 00167 00168 ErrorCode write_qa_records( std::vector< std::string >& qa_record_list ); 00169 00170 ErrorCode write_nodes( int num_nodes, Range& nodes, int dimension ); 00171 00172 ErrorCode write_poly_faces( ExodusMeshInfo& mesh_info ); 00173 ErrorCode write_elementblocks( ExodusMeshInfo& mesh_info, std::vector< MaterialSetData >& block_data ); 00174 00175 ErrorCode write_exodus_integer_variable( const char* variable_name, int* variable_array, int start_position, 00176 int number_values ); 00177 00178 ErrorCode write_global_node_order_map( int num_nodes, Range& nodes ); 00179 ErrorCode write_global_element_order_map( int num_elements ); 00180 ErrorCode write_element_order_map( int num_elements ); 00181 00182 ErrorCode write_BCs( std::vector< NeumannSetData >& sidesets, std::vector< DirichletSetData >& nodesets ); 00183 00184 ErrorCode find_side_element_type( const int element_id, ExoIIElementType& type ); 00185 00186 /* ErrorCode assign_block_ids_to_ssets(EntityHandle ss_handle, 00187 MB_MeshSet *ss_mesh_set); 00188 */ 00189 //! free up allocated Ranges 00190 void reset_block( std::vector< MaterialSetData >& block_info ); 00191 00192 //! recursive function; given a meshset handle, get the entities and put them 00193 //! on the right list, then call recursively for any contained meshsets, first 00194 //! checking for sense reversals 00195 ErrorCode get_sideset_elems( EntityHandle sideset, int current_sense, Range& forward_elems, Range& reverse_elems ); 00196 00197 ErrorCode get_valid_sides( Range& elems, ExodusMeshInfo& mesh_info, const int sense, NeumannSetData& sideset_data ); 00198 00199 //! get the time and date in strings 00200 static void time_and_date( char* time_string, char* date_string ); 00201 }; 00202 00203 } // namespace moab 00204 00205 #endif