Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
WriteTemplate.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 : WriteTemplate.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 WRITETemplate_HPP
31 #define WRITETemplate_HPP
32 
33 #ifndef IS_BUILDING_MB
34 #error "WriteTemplate.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 class WriteTemplate : public WriterIface
51 {
52 
53  public:
54  //! Constructor
55  WriteTemplate( Interface* impl );
56 
57  //! Destructor
58  virtual ~WriteTemplate();
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
76  {
77  int id;
82  EntityType moab_type;
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
89  {
90  int id;
92  std::vector< EntityHandle > nodes;
93  std::vector< double > node_dist_factors;
94  };
95 
96  //! struct used to hold data for each sideset to be output; used by
97  //! initialize_file to initialize the file header for increased speed
99  {
100  int id;
102  std::vector< EntityHandle > elements;
103  std::vector< int > side_numbers;
105  };
106 
107  protected:
108  //! number of dimensions in this file
109  // int number_dimensions();
110 
111  //! open a file for writing
112  ErrorCode open_file( const char* filename );
113 
114  //! contains the general information about a mesh
115  class MeshInfo
116  {
117  public:
118  unsigned int num_dim;
119  unsigned int num_nodes;
120  unsigned int num_elements;
121  unsigned int num_matsets;
122  unsigned int num_dirsets;
123  unsigned int num_neusets;
125 
127  : num_dim( 0 ), num_nodes( 0 ), num_elements( 0 ), num_matsets( 0 ), num_dirsets( 0 ), num_neusets( 0 )
128  {
129  }
130  };
131 
132  private:
133  //! interface instance
136 
137  //! file name
138  std::string fileName;
139 
140  //! Cached tags for reading. Note that all these tags are defined when the
141  //! core is initialized.
146 
147  Tag mEntityMark; // used to say whether an entity will be exported
148 
150  std::vector< MaterialSetData >& matset_info,
151  std::vector< NeumannSetData >& neuset_info,
152  std::vector< DirichletSetData >& dirset_info,
153  std::vector< EntityHandle >& matsets,
154  std::vector< EntityHandle >& neusets,
155  std::vector< EntityHandle >& dirsets );
156 
157  ErrorCode initialize_file( MeshInfo& mesh_info );
158 
159  ErrorCode write_nodes( const int num_nodes, const Range& nodes, const int dimension );
160 
161  ErrorCode write_matsets( MeshInfo& mesh_info,
162  std::vector< MaterialSetData >& matset_data,
163  std::vector< NeumannSetData >& neuset_data );
164 
165  ErrorCode get_valid_sides( Range& elems, const int sense, WriteTemplate::NeumannSetData& neuset_data );
166 
167  void reset_matset( std::vector< MaterialSetData >& matset_info );
168 
169  ErrorCode get_neuset_elems( EntityHandle neuset, int current_sense, Range& forward_elems, Range& reverse_elems );
170 };
171 
172 } // namespace moab
173 
174 #endif