Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
WriteNCDF.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 : WriteNCDF.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 WRITENCDF_HPP
31 #define WRITENCDF_HPP
32 
33 #ifndef IS_BUILDING_MB
34 #error "WriteNCDF.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 
48 class WriteUtilIface;
49 
50 //! struct used to hold data for each block to be output in Exodus; used by
51 //! initialize_exodus_file to initialize the file header for increased speed
53 {
54  int id;
60 };
61 
62 //! struct used to hold data for each nodeset to be output in Exodus; used by
63 //! initialize_exodus_file to initialize the file header for increased speed
65 {
66  int id;
68  std::vector< EntityHandle > nodes;
69  std::vector< double > node_dist_factors;
70 };
71 
72 //! struct used to hold data for each sideset to be output in Exodus; used by
73 //! initialize_exodus_file to initialize the file header for increased speed
75 {
76  int id;
78  std::vector< EntityHandle > elements;
79  std::vector< int > side_numbers;
81  std::vector< double > ss_dist_factors;
82 };
83 
84 //! Output Exodus File for VERDE
85 class WriteNCDF : public WriterIface
86 {
87 
88  public:
89  static WriterIface* factory( Interface* );
90 
91  //! Constructor
92  WriteNCDF( Interface* impl );
93 
94  //! Destructor
95  virtual ~WriteNCDF();
96 
97  //! writes out an ExoII file
98  ErrorCode write_file( const char* exodus_file_name,
99  const bool overwrite,
100  const FileOptions& opts,
101  const EntityHandle* output_list,
102  const int num_sets,
103  const std::vector< std::string >& qa_records,
104  const Tag* = NULL,
105  int = 0,
106  int user_dimension = 3 );
107 
108  protected:
109  //! number of dimensions in this exo file
110  // int number_dimensions();
111 
112  //! open an ExoII file for writing
113  ErrorCode open_file( const char* file_name );
114 
115  //! contains the general information about a mesh
117  {
118  unsigned int num_dim;
119  unsigned int num_nodes;
120  unsigned int num_elements;
121  unsigned int num_elementblocks;
122  unsigned int num_polyhedra_blocks;
123  std::vector< std::string > qaRecords;
125  Range polyhedronFaces; // they will accumulate, like nodes
126  // they will be written before any other face blocks, and before polyhedra blocks
127  };
128 
129  private:
130  //! interface instance
133 
134  //! file name
135  std::string exodusFile;
136  int ncFile;
137 
138  //! Meshset Handle for the mesh that is currently being read
140 
141  //! Cached tags for reading. Note that all these tags are defined when the
142  //! core is initialized.
151 
152  Tag mEntityMark; // used to say whether an entity will be exported
153 
154  int repeat_face_blocks; // only to make paraview and visit happy
155 
157  std::vector< MaterialSetData >& block_info,
158  std::vector< NeumannSetData >& sideset_info,
159  std::vector< DirichletSetData >& nodeset_info,
160  std::vector< EntityHandle >& blocks,
161  std::vector< EntityHandle >& sidesets,
162  std::vector< EntityHandle >& nodesets );
163 
165  std::vector< MaterialSetData >& block_info,
166  std::vector< NeumannSetData >& sideset_info,
167  std::vector< DirichletSetData >& nodeset_info,
168  const char* filename );
169 
171  std::vector< MaterialSetData >& block_data,
172  std::vector< NeumannSetData >& sideset_data,
173  std::vector< DirichletSetData >& nodeset_data,
174  const char* title_string,
175  bool write_maps = true,
176  bool write_sideset_distribution_factors = true );
177 
178  ErrorCode write_qa_string( const char* string, int record_number, int record_position );
179 
180  ErrorCode write_qa_records( std::vector< std::string >& qa_record_list );
181 
182  ErrorCode write_nodes( int num_nodes, Range& nodes, int dimension );
183 
185  ErrorCode write_elementblocks( ExodusMeshInfo& mesh_info, std::vector< MaterialSetData >& block_data );
186 
187  ErrorCode write_exodus_integer_variable( const char* variable_name,
188  int* variable_array,
189  int start_position,
190  int number_values );
191 
192  ErrorCode write_global_node_order_map( int num_nodes, Range& nodes );
193  ErrorCode write_global_element_order_map( int num_elements );
194  ErrorCode write_element_order_map( int num_elements );
195 
196  ErrorCode write_BCs( std::vector< NeumannSetData >& sidesets, std::vector< DirichletSetData >& nodesets );
197 
198  ErrorCode find_side_element_type( const int element_id, ExoIIElementType& type );
199 
200  /* ErrorCode assign_block_ids_to_ssets(EntityHandle ss_handle,
201  MB_MeshSet *ss_mesh_set);
202  */
203  //! free up allocated Ranges
204  void reset_block( std::vector< MaterialSetData >& block_info );
205 
206  //! recursive function; given a meshset handle, get the entities and put them
207  //! on the right list, then call recursively for any contained meshsets, first
208  //! checking for sense reversals
209  ErrorCode get_sideset_elems( EntityHandle sideset, int current_sense, Range& forward_elems, Range& reverse_elems );
210 
211  ErrorCode get_valid_sides( Range& elems, ExodusMeshInfo& mesh_info, const int sense, NeumannSetData& sideset_data );
212 
213  //! get the time and date in strings
214  static void time_and_date( char* time_string, char* date_string );
215 };
216 
217 } // namespace moab
218 
219 #endif