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 : WriteCCMIO.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 WRITECCMIO_HPP 00031 #define WRITECCMIO_HPP 00032 00033 #ifndef IS_BUILDING_MB 00034 #error "WriteCCMIO.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 #include "ccmio.h" 00045 00046 namespace moab 00047 { 00048 00049 class WriteUtilIface; 00050 00051 class WriteCCMIO : public WriterIface 00052 { 00053 00054 public: 00055 //! Constructor 00056 WriteCCMIO( Interface* impl ); 00057 00058 //! Destructor 00059 virtual ~WriteCCMIO(); 00060 00061 static WriterIface* factory( Interface* ); 00062 00063 //! writes out a file 00064 ErrorCode write_file( const char* file_name, const bool overwrite, const FileOptions& opts, 00065 const EntityHandle* output_list, const int num_sets, 00066 const std::vector< std::string >& qa_list, const Tag* tag_list = NULL, int num_tags = 0, 00067 int export_dimension = 3 ); 00068 00069 protected: 00070 //! number of dimensions in this file 00071 // int number_dimensions(); 00072 00073 //! open a file for writing 00074 ErrorCode open_file( const char* filename, bool overwrite, CCMIOID& rootID ); 00075 00076 //! contains the general information about a mesh 00077 class MeshInfo 00078 { 00079 public: 00080 unsigned int num_dim; 00081 unsigned int num_nodes; 00082 unsigned int num_elements; 00083 unsigned int num_matsets; 00084 unsigned int num_dirsets; 00085 unsigned int num_neusets; 00086 Range nodes; 00087 00088 MeshInfo() 00089 : num_dim( 0 ), num_nodes( 0 ), num_elements( 0 ), num_matsets( 0 ), num_dirsets( 0 ), num_neusets( 0 ) 00090 { 00091 } 00092 }; 00093 00094 // material set information 00095 class MaterialSetData 00096 { 00097 public: 00098 Range elems; // elements in material set 00099 EntityHandle setHandle; // handle of the material set 00100 EntityType entityType; // entity type of these elements 00101 int verts_per_element; // number of vertices in each element 00102 int matsetId; // id of this matset, from MATERIAL_SET tag 00103 int materialId; // materialid, if any (from CCMIO) 00104 std::string setName; // name for this matset, if any 00105 std::string materialType; // material type for this matset, if any 00106 00107 MaterialSetData() 00108 : setHandle( 0 ), entityType( MBMAXTYPE ), verts_per_element( 0 ), matsetId( -1 ), materialId( -1 ) 00109 00110 { 00111 } 00112 }; 00113 00114 // neumann set information 00115 class NeumannSetData 00116 { 00117 public: 00118 Range elems; // elements in neumann set 00119 EntityHandle setHandle; // handle of the neumann set 00120 EntityType entityType; // entity type of these elements 00121 int verts_per_element; // number of vertices in each element 00122 int neusetId; // id of this matset, from NEUMANN_SET tag 00123 std::string setName; // name for this neuset, if any 00124 00125 NeumannSetData() : setHandle( 0 ), entityType( MBMAXTYPE ), verts_per_element( 0 ), neusetId( -1 ) {} 00126 }; 00127 00128 private: 00129 //! interface instance 00130 Interface* mbImpl; 00131 WriteUtilIface* mWriteIface; 00132 00133 //! file name 00134 std::string fileName; 00135 00136 //! Meshset Handle for the mesh that is currently being read 00137 EntityHandle mCurrentMeshHandle; 00138 00139 //! Cached tags for reading. Note that all these tags are defined when the 00140 //! core is initialized. 00141 Tag mMaterialSetTag; 00142 Tag mDirichletSetTag; 00143 Tag mNeumannSetTag; 00144 Tag mPartitionSetTag; 00145 Tag mHasMidNodesTag; 00146 Tag mGlobalIdTag; 00147 Tag mNameTag, mMaterialIdTag, mMaterialTypeTag; 00148 Tag mRadiationTag, mPorosityIdTag, mSpinIdTag, mGroupIdTag, mColorIdxTag, mProcessorIdTag, mLightMaterialTag, 00149 mFreeSurfaceMaterialTag; 00150 Tag mThicknessTag, mProstarRegionNumberTag, mBoundaryTypeTag, mCreatingProgramTag; 00151 00152 Tag mEntityMark; // used to say whether an entity will be exported 00153 00154 int mDimension; // dimension of entities being exported 00155 00156 bool mWholeMesh; // if true, whole mesh is being output 00157 00158 //! gathers elements in each matset, and all the vertices used by them; 00159 //! marks the vertices with the mEntityMark bit flag 00160 ErrorCode gather_matset_info( std::vector< EntityHandle >& matsets, std::vector< MaterialSetData >& matset_data, 00161 Range& all_verts ); 00162 00163 //! gathers elements in each neuset 00164 ErrorCode gather_neuset_info( std::vector< EntityHandle >& neusets, std::vector< NeumannSetData >& neuset_data ); 00165 00166 ErrorCode close_and_compress( const char* filename, CCMIOID rootID ); 00167 00168 ErrorCode initialize_file( MeshInfo& mesh_info ); 00169 00170 //! write vertices to file 00171 ErrorCode write_nodes( CCMIOID rootID, const Range& nodes, const int dimension, CCMIOID& verticesID ); 00172 00173 //! write cells and internal/boundary faces, using vgids and verts input 00174 ErrorCode write_cells_and_faces( CCMIOID rootID, std::vector< WriteCCMIO::MaterialSetData >& matset_data, 00175 std::vector< WriteCCMIO::NeumannSetData >& neuset_data, Range& verts, 00176 CCMIOID& topologyID ); 00177 00178 //! write external faces, including connectivity and connected cells 00179 ErrorCode write_external_faces( CCMIOID rootID, CCMIOID topologyID, int set_num, Range& facets ); 00180 00181 // get global ids for these entities; allocates gids and passes back, 00182 // caller is responsible for deleting 00183 ErrorCode get_gids( const Range& ents, int*& gids, int& minid, int& maxid ); 00184 00185 ErrorCode write_meshes( MeshInfo& mesh_info, std::vector< MaterialSetData >& matset_data, 00186 std::vector< NeumannSetData >& neuset_data, Range& verts, const int* vgids ); 00187 00188 ErrorCode get_valid_sides( Range& elems, const int sense, WriteCCMIO::NeumannSetData& neuset_data ); 00189 00190 void reset_matset( std::vector< MaterialSetData >& matset_info ); 00191 00192 ErrorCode get_neuset_elems( EntityHandle neuset, int current_sense, Range& forward_elems, Range& reverse_elems ); 00193 00194 ErrorCode transform_coords( const int dimension, const int num_nodes, double* coords ); 00195 00196 ErrorCode write_problem_description( CCMIOID rootID, CCMIOID stateID, CCMIOID& problemID, CCMIOID processorID, 00197 std::vector< MaterialSetData >& matset_data, 00198 std::vector< NeumannSetData >& neuset_data ); 00199 00200 // get the material, dirichlet, neumann, and partition sets to be written, 00201 // either from input sets or in the whole mesh 00202 ErrorCode get_sets( const EntityHandle* ent_handles, int num_sets, std::vector< EntityHandle >& matsets, 00203 std::vector< EntityHandle >& dirsets, std::vector< EntityHandle >& neusets, 00204 std::vector< EntityHandle >& partsets ); 00205 00206 //! create state and processor nodes 00207 ErrorCode create_ccmio_structure( CCMIOID rootID, CCMIOID& stateID, CCMIOID& processorID ); 00208 00209 //! write solution (tag) data 00210 ErrorCode write_solution_data(); 00211 00212 //! finalize processor 00213 ErrorCode write_processor( CCMIOID processorID, CCMIOID verticesID, CCMIOID topologyID ); 00214 00215 //! convert MOAB to CCMIO type 00216 int moab_to_ccmio_type( EntityType etype, int has_mid_nodes[] ); 00217 00218 ErrorCode write_int_option( const char* opt_name, EntityHandle seth, Tag& tag, CCMIOID& node ); 00219 00220 ErrorCode write_dbl_option( const char* opt_name, EntityHandle seth, Tag& tag, CCMIOID& node ); 00221 00222 ErrorCode write_str_option( const char* opt_name, EntityHandle seth, Tag& tag, CCMIOID& node, 00223 const char* other_name = NULL ); 00224 }; 00225 00226 } // namespace moab 00227 00228 #endif