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 : WriteSLAC.hpp 18 // 19 // Purpose : ExodusII writer 20 // 21 // Special Notes : Lots of code taken from verde implementation 22 // 23 // Creator : Corey Ernst 24 // 25 // Date : 8/02 26 // 27 // Owner : Corey Ernst 28 //------------------------------------------------------------------------- 29 30 #ifndef WRITESLAC_HPP 31 #define WRITESLAC_HPP 32 33 #ifndef IS_BUILDING_MB 34 #error "WriteSLAC.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/Range.hpp" 42 #include "moab/ExoIIInterface.hpp" 43 #include "moab/WriterIface.hpp" 44 45 namespace moab { 46 47 class WriteUtilIface; 48 49 class WriteSLAC : public WriterIface 50 { 51 52 public: 53 54 //! Constructor 55 WriteSLAC(Interface *impl); 56 57 //! Destructor 58 virtual ~WriteSLAC(); 59 60 static WriterIface* factory( Interface* ); 61 62 //! writes out a file 63 ErrorCode write_file(const char *file_name, 64 const bool overwrite, 65 const FileOptions& opts, 66 const EntityHandle *output_list, 67 const int num_sets, 68 const std::vector<std::string>& qa_list, 69 const Tag* tag_list = NULL, 70 int num_tags = 0, 71 int export_dimension = 3); 72 73 //! struct used to hold data for each block to be output; used by 74 //! initialize_file to initialize the file header for increased speed 75 struct MaterialSetData 76 { 77 int id; 78 int number_elements; 79 int number_nodes_per_element; 80 int number_attributes; 81 ExoIIElementType element_type; 82 EntityType moab_type; 83 Range *elements; 84 }; 85 86 //! struct used to hold data for each nodeset to be output; used by 87 //! initialize_file to initialize the file header for increased speed 88 struct DirichletSetData 89 { 90 int id; 91 int number_nodes; 92 std::vector< EntityHandle > nodes; 93 std::vector< double > node_dist_factors; 94 95 }; 96 97 //! struct used to hold data for each sideset to be output; used by 98 //! initialize_file to initialize the file header for increased speed 99 struct NeumannSetData 100 { 101 int id; 102 int number_elements; 103 std::vector<EntityHandle> elements; 104 std::vector<int> side_numbers; 105 EntityHandle mesh_set_handle; 106 }; 107 108 109 protected: 110 111 //! number of dimensions in this file 112 //int number_dimensions(); 113 114 //! open a file for writing 115 ErrorCode open_file(const char *filename); 116 117 //! contains the general information about a mesh 118 class MeshInfo 119 { 120 public: 121 unsigned int num_dim; 122 unsigned int num_nodes; 123 unsigned int num_elements; 124 unsigned int num_matsets; 125 unsigned int num_int_hexes; 126 unsigned int num_int_tets; 127 Range bdy_hexes, bdy_tets; 128 Range nodes; 129 MeshInfo()130 MeshInfo() 131 : num_dim(0), num_nodes(0), num_elements(0), num_matsets(0), 132 num_int_hexes(0), num_int_tets(0) 133 {} 134 135 }; 136 137 private: 138 139 //! interface instance 140 Interface *mbImpl; 141 WriteUtilIface* mWriteIface; 142 143 //! file name 144 std::string fileName; 145 int ncFile; 146 147 //! Cached tags for reading. Note that all these tags are defined when the 148 //! core is initialized. 149 Tag mMaterialSetTag; 150 Tag mDirichletSetTag; 151 Tag mNeumannSetTag; 152 Tag mGlobalIdTag; 153 Tag mMatSetIdTag; 154 155 Tag mEntityMark; //used to say whether an entity will be exported 156 157 ErrorCode gather_mesh_information(MeshInfo &mesh_info, 158 std::vector<MaterialSetData> &matset_info, 159 std::vector<NeumannSetData> &neuset_info, 160 std::vector<DirichletSetData> &dirset_info, 161 std::vector<EntityHandle> &matsets, 162 std::vector<EntityHandle> &neusets, 163 std::vector<EntityHandle> &dirsets); 164 165 ErrorCode initialize_file(MeshInfo &mesh_info); 166 167 ErrorCode write_nodes(const int num_nodes, const Range& nodes, 168 const int dimension ); 169 170 ErrorCode write_matsets(MeshInfo &mesh_info, 171 std::vector<MaterialSetData> &matset_data, 172 std::vector<NeumannSetData> &neuset_data); 173 174 ErrorCode get_valid_sides(Range &elems, const int sense, 175 WriteSLAC::NeumannSetData &sideset_data); 176 177 void reset_matset(std::vector<MaterialSetData> &matset_info); 178 179 ErrorCode get_neuset_elems(EntityHandle neuset, int current_sense, 180 Range &forward_elems, Range &reverse_elems); 181 182 ErrorCode gather_interior_exterior(MeshInfo &mesh_info, 183 std::vector<MaterialSetData> &matset_data, 184 std::vector<NeumannSetData> &neuset_data); 185 186 }; 187 188 } // namespace moab 189 190 #endif 191