Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
WriteCCMIO.hpp
Go to the documentation of this file.
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 : WriteCCMIO.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 WRITECCMIO_HPP
31 #define WRITECCMIO_HPP
32 
33 #ifndef IS_BUILDING_MB
34 #error "WriteCCMIO.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 #include "ccmio.h"
45 
46 namespace moab
47 {
48 
49 class WriteUtilIface;
50 
51 class WriteCCMIO : public WriterIface
52 {
53 
54  public:
55  //! Constructor
56  WriteCCMIO( Interface* impl );
57 
58  //! Destructor
59  virtual ~WriteCCMIO();
60 
61  static WriterIface* factory( Interface* );
62 
63  //! writes out a file
64  ErrorCode write_file( const char* file_name,
65  const bool overwrite,
66  const FileOptions& opts,
67  const EntityHandle* output_list,
68  const int num_sets,
69  const std::vector< std::string >& qa_list,
70  const Tag* tag_list = NULL,
71  int num_tags = 0,
72  int export_dimension = 3 );
73 
74  protected:
75  //! number of dimensions in this file
76  // int number_dimensions();
77 
78  //! open a file for writing
79  ErrorCode open_file( const char* filename, bool overwrite, CCMIOID& rootID );
80 
81  //! contains the general information about a mesh
82  class MeshInfo
83  {
84  public:
85  unsigned int num_dim;
86  unsigned int num_nodes;
87  unsigned int num_elements;
88  unsigned int num_matsets;
89  unsigned int num_dirsets;
90  unsigned int num_neusets;
92 
94  : num_dim( 0 ), num_nodes( 0 ), num_elements( 0 ), num_matsets( 0 ), num_dirsets( 0 ), num_neusets( 0 )
95  {
96  }
97  };
98 
99  // material set information
101  {
102  public:
103  Range elems; // elements in material set
104  EntityHandle setHandle; // handle of the material set
105  EntityType entityType; // entity type of these elements
106  int verts_per_element; // number of vertices in each element
107  int matsetId; // id of this matset, from MATERIAL_SET tag
108  int materialId; // materialid, if any (from CCMIO)
109  std::string setName; // name for this matset, if any
110  std::string materialType; // material type for this matset, if any
111 
113  : setHandle( 0 ), entityType( MBMAXTYPE ), verts_per_element( 0 ), matsetId( -1 ), materialId( -1 )
114 
115  {
116  }
117  };
118 
119  // neumann set information
121  {
122  public:
123  Range elems; // elements in neumann set
124  EntityHandle setHandle; // handle of the neumann set
125  EntityType entityType; // entity type of these elements
126  int verts_per_element; // number of vertices in each element
127  int neusetId; // id of this matset, from NEUMANN_SET tag
128  std::string setName; // name for this neuset, if any
129 
131  };
132 
133  private:
134  //! interface instance
137 
138  //! file name
139  std::string fileName;
140 
141  //! Meshset Handle for the mesh that is currently being read
143 
144  //! Cached tags for reading. Note that all these tags are defined when the
145  //! core is initialized.
156 
157  Tag mEntityMark; // used to say whether an entity will be exported
158 
159  int mDimension; // dimension of entities being exported
160 
161  bool mWholeMesh; // if true, whole mesh is being output
162 
163  //! gathers elements in each matset, and all the vertices used by them;
164  //! marks the vertices with the mEntityMark bit flag
165  ErrorCode gather_matset_info( std::vector< EntityHandle >& matsets,
166  std::vector< MaterialSetData >& matset_data,
167  Range& all_verts );
168 
169  //! gathers elements in each neuset
170  ErrorCode gather_neuset_info( std::vector< EntityHandle >& neusets, std::vector< NeumannSetData >& neuset_data );
171 
172  ErrorCode close_and_compress( const char* filename, CCMIOID rootID );
173 
175 
176  //! write vertices to file
177  ErrorCode write_nodes( CCMIOID rootID, const Range& nodes, const int dimension, CCMIOID& verticesID );
178 
179  //! write cells and internal/boundary faces, using vgids and verts input
180  ErrorCode write_cells_and_faces( CCMIOID rootID,
181  std::vector< WriteCCMIO::MaterialSetData >& matset_data,
182  std::vector< WriteCCMIO::NeumannSetData >& neuset_data,
183  Range& verts,
184  CCMIOID& topologyID );
185 
186  //! write external faces, including connectivity and connected cells
187  ErrorCode write_external_faces( CCMIOID rootID, CCMIOID topologyID, int set_num, Range& facets );
188 
189  // get global ids for these entities; allocates gids and passes back,
190  // caller is responsible for deleting
191  ErrorCode get_gids( const Range& ents, int*& gids, int& minid, int& maxid );
192 
194  std::vector< MaterialSetData >& matset_data,
195  std::vector< NeumannSetData >& neuset_data,
196  Range& verts,
197  const int* vgids );
198 
199  ErrorCode get_valid_sides( Range& elems, const int sense, WriteCCMIO::NeumannSetData& neuset_data );
200 
201  void reset_matset( std::vector< MaterialSetData >& matset_info );
202 
203  ErrorCode get_neuset_elems( EntityHandle neuset, int current_sense, Range& forward_elems, Range& reverse_elems );
204 
205  ErrorCode transform_coords( const int dimension, const int num_nodes, double* coords );
206 
207  ErrorCode write_problem_description( CCMIOID rootID,
208  CCMIOID stateID,
209  CCMIOID& problemID,
210  CCMIOID processorID,
211  std::vector< MaterialSetData >& matset_data,
212  std::vector< NeumannSetData >& neuset_data );
213 
214  // get the material, dirichlet, neumann, and partition sets to be written,
215  // either from input sets or in the whole mesh
216  ErrorCode get_sets( const EntityHandle* ent_handles,
217  int num_sets,
218  std::vector< EntityHandle >& matsets,
219  std::vector< EntityHandle >& dirsets,
220  std::vector< EntityHandle >& neusets,
221  std::vector< EntityHandle >& partsets );
222 
223  //! create state and processor nodes
224  ErrorCode create_ccmio_structure( CCMIOID rootID, CCMIOID& stateID, CCMIOID& processorID );
225 
226  //! write solution (tag) data
228 
229  //! finalize processor
230  ErrorCode write_processor( CCMIOID processorID, CCMIOID verticesID, CCMIOID topologyID );
231 
232  //! convert MOAB to CCMIO type
233  int moab_to_ccmio_type( EntityType etype, int has_mid_nodes[] );
234 
235  ErrorCode write_int_option( const char* opt_name, EntityHandle seth, Tag& tag, CCMIOID& node );
236 
237  ErrorCode write_dbl_option( const char* opt_name, EntityHandle seth, Tag& tag, CCMIOID& node );
238 
239  ErrorCode write_str_option( const char* opt_name,
240  EntityHandle seth,
241  Tag& tag,
242  CCMIOID& node,
243  const char* other_name = NULL );
244 };
245 
246 } // namespace moab
247 
248 #endif