Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
moab::WriteGMV Class Reference

Output Exodus File for VERDE. More...

#include <WriteGMV.hpp>

+ Inheritance diagram for moab::WriteGMV:
+ Collaboration diagram for moab::WriteGMV:

Public Member Functions

 WriteGMV (Interface *impl)
 Constructor. More...
 
virtual ~WriteGMV ()
 Destructor. More...
 
ErrorCode write_file (const char *filename, const bool overwite, const FileOptions &opts, const EntityHandle *output_sets, const int num_output_sets, const std::vector< std::string > &qa_list, const Tag *tag_list=NULL, int num_tags=0, int requested_dimension=3)
 Export mesh to a file. More...
 
ErrorCode write_file (const char *file_name, const EntityHandle output_set, const int user_dimension=3, const bool mesh=true, const bool poly_mesh=true)
 writes out a mesh file More...
 
- Public Member Functions inherited from moab::WriterIface
virtual ~WriterIface ()
 

Static Public Member Functions

static WriterIfacefactory (Interface *)
 

Private Member Functions

ErrorCode local_write_mesh (const char *file_name, const EntityHandle output_set, const int user_dimension, const bool mesh, const bool poly_mesh)
 

Private Attributes

InterfacembImpl
 interface instance More...
 
WriteUtilIfacemWriteIface
 
Tag mMaterialSetTag
 Cached tags for reading. Note that all these tags are defined when the core is initialized. More...
 
Tag mDirichletSetTag
 
Tag mNeumannSetTag
 
Tag mHasMidNodesTag
 
Tag mGeomDimensionTag
 
Tag mGlobalIdTag
 

Static Private Attributes

static const char * gmvTypeNames [MBMAXTYPE] = { "", "line", "tri", "quad", "", "tet", "pyramid", "prism", "", "hex", "", "" }
 

Detailed Description

Output Exodus File for VERDE.

Definition at line 41 of file WriteGMV.hpp.

Constructor & Destructor Documentation

◆ WriteGMV()

moab::WriteGMV::WriteGMV ( Interface impl)

Constructor.

get and cache predefined tag handles

get and cache predefined tag handles

Definition at line 45 of file WriteGMV.cpp.

45  : mbImpl( impl )
46 {
47  assert( impl != NULL );
48 
49  impl->query_interface( mWriteIface );
50 
51  // initialize in case tag_get_handle fails below
52  mMaterialSetTag = 0;
53  mDirichletSetTag = 0;
54  mNeumannSetTag = 0;
55  mHasMidNodesTag = 0;
57  mGlobalIdTag = 0;
58 
59  //! get and cache predefined tag handles
60  // initialize in case tag_get_handle fails below
61  //! get and cache predefined tag handles
62  int negone = -1;
64  &negone );
65 
67  &negone );
68 
70  &negone );
71 
72  mGlobalIdTag = impl->globalId_tag();
73 
74  int dum_val_array[] = { -1, -1, -1, -1 };
76  dum_val_array );
77 }

References DIRICHLET_SET_TAG_NAME, moab::Interface::globalId_tag(), HAS_MID_NODES_TAG_NAME, MATERIAL_SET_TAG_NAME, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_INTEGER, mDirichletSetTag, mGeomDimensionTag, mGlobalIdTag, mHasMidNodesTag, mMaterialSetTag, mNeumannSetTag, mWriteIface, NEUMANN_SET_TAG_NAME, moab::Interface::query_interface(), and moab::Interface::tag_get_handle().

Referenced by factory().

◆ ~WriteGMV()

moab::WriteGMV::~WriteGMV ( )
virtual

Destructor.

Definition at line 79 of file WriteGMV.cpp.

80 {
82 }

References mbImpl, mWriteIface, and moab::Interface::release_interface().

Member Function Documentation

◆ factory()

WriterIface * moab::WriteGMV::factory ( Interface iface)
static

Definition at line 40 of file WriteGMV.cpp.

41 {
42  return new WriteGMV( iface );
43 }

References iface, and WriteGMV().

Referenced by moab::ReaderWriterSet::ReaderWriterSet().

◆ local_write_mesh()

ErrorCode moab::WriteGMV::local_write_mesh ( const char *  file_name,
const EntityHandle  output_set,
const int  user_dimension,
const bool  mesh,
const bool  poly_mesh 
)
private

Definition at line 136 of file WriteGMV.cpp.

141 {
142  std::ofstream ofile;
143  ErrorCode result;
144 
145  if( mesh )
146  {
147  // need to insert ".gmv"
148  std::string tmp_name( file_name );
149  tmp_name += ".gmv";
150  ofile.open( tmp_name.c_str() );
151  }
152  else if( poly_mesh )
153  {
154  // need to insert ".poly.gmv"
155  std::string tmp_name( file_name );
156  tmp_name += ".poly.gmv";
157  ofile.open( tmp_name.c_str() );
158  }
159 
160  ofile << "gmvinput ascii" << std::endl;
161 
162  // get elements to be output
163  Range dum_range, elements, all_verts;
164  EntityType otype;
165  if( poly_mesh )
166  {
167  result = mbImpl->get_entities_by_type( output_set, MBPOLYGON, elements, true );
168  if( MB_SUCCESS != result ) return result;
169  }
170  else
171  {
172  for( otype = CN::TypeDimensionMap[user_dimension].first; otype <= CN::TypeDimensionMap[user_dimension].second;
173  otype++ )
174  {
175  if( otype == MBPOLYGON || otype == MBPOLYHEDRON ) continue;
176  dum_range.clear();
177  result = mbImpl->get_entities_by_type( output_set, otype, dum_range, true );
178  if( MB_SUCCESS != result ) return result;
179 
180  std::copy( dum_range.begin(), dum_range.end(), range_inserter( elements ) );
181  }
182  }
183 
184  // gather the vertices in these elements
185  result = mbImpl->get_adjacencies( elements, 0, false, all_verts, Interface::UNION );
186  if( MB_SUCCESS != result ) return result;
187 
188  int num_verts = all_verts.size();
189 
190  // allocate coordinate arrays and put pointers to them in a list
191  double* xcoord = new double[num_verts];
192  double* ycoord = new double[num_verts];
193  double* zcoord = new double[num_verts];
194  std::vector< double* > coord_arrays;
195  coord_arrays.push_back( xcoord );
196  coord_arrays.push_back( ycoord );
197  coord_arrays.push_back( zcoord );
198 
199  // fill them in, writing id tags at the same time
200  result = mWriteIface->get_node_coords( 3, num_verts, all_verts, mGlobalIdTag, 1, coord_arrays );
201  if( MB_SUCCESS != result ) return result;
202 
203  int i, j;
204 
205  //========================================
206  // WRITE COORDINATE DATA TO FILE HERE
207 
208  ofile << "nodev " << num_verts << std::endl;
209  for( i = 0; i < num_verts; i++ )
210  ofile << xcoord[i] << " " << ycoord[i] << " " << zcoord[i] << std::endl;
211 
212  //========================================
213 
214  delete[] xcoord;
215  delete[] ycoord;
216  delete[] zcoord;
217 
218  // iterate over types in selected dimension
219 
220  std::vector< int > connect;
221  std::vector< EntityHandle > connecth;
222 
223  if( mesh )
224  {
225  Range sub_range;
226 
227  ofile << "cells " << elements.size() << std::endl;
228 
229  for( otype = CN::TypeDimensionMap[user_dimension].first; otype <= CN::TypeDimensionMap[user_dimension].second;
230  otype++ )
231  {
232 
233  if( otype == MBPOLYGON || otype == MBPOLYHEDRON ) continue;
234 
235  // get the first element of this type in the range, and one past the last
236  Range::iterator lower =
237  Range::lower_bound( elements.begin(), elements.end(), CREATE_HANDLE( otype, MB_START_ID, i ) );
238  Range::iterator upper =
239  Range::lower_bound( elements.begin(), elements.end(), CREATE_HANDLE( otype + 1, MB_START_ID, i ) );
240 
241  if( lower == upper ) continue;
242 
243  // copy these elements into a subrange
244  sub_range.clear();
245  std::copy( lower, upper, range_inserter( sub_range ) );
246 
247  // make sure the connectivity array is big enough
248  int verts_per = CN::VerticesPerEntity( otype );
249  if( connect.size() < verts_per * sub_range.size() ) connect.resize( verts_per * sub_range.size() );
250 
251  // get the connectivity
252  result = mWriteIface->get_element_connect( sub_range.size(), verts_per, mGlobalIdTag, sub_range,
253  mGlobalIdTag, 1, &connect[0] );
254  if( MB_SUCCESS != result ) return result;
255 
256  //========================================
257  // WRITE CONNECTIVITY DATA TO FILE HERE
258 
259  for( i = 0; i < (int)sub_range.size(); i++ )
260  {
261  ofile << gmvTypeNames[otype] << " " << verts_per << std::endl;
262  for( j = i * verts_per; j < (int)( i + 1 ) * verts_per; j++ )
263  ofile << connect[j] << " ";
264  ofile << std::endl;
265  }
266 
267  //========================================
268  }
269  }
270 
271  else if( poly_mesh )
272  {
273 
274  // write polygons/hedra, if any
275  Range polygons, polyhedra;
276  result = mbImpl->get_entities_by_type( output_set, MBPOLYGON, polygons, true );
277  if( MB_SUCCESS != result ) return result;
278 
279  result = mbImpl->get_entities_by_type( output_set, MBPOLYHEDRON, polyhedra, true );
280  if( MB_SUCCESS != result ) return result;
281 
282  if( polygons.size() == 0 ) return result;
283 
284  // mark polyhedra with global ids
285  result = mWriteIface->assign_ids( polyhedra, mGlobalIdTag, 1 );
286  if( MB_SUCCESS != result ) return result;
287 
288  ofile << "faces " << polygons.size() << " " << polyhedra.size() << std::endl;
289 
290  for( Range::iterator rit = polygons.begin(); rit != polygons.end(); ++rit )
291  {
292  // get the vertices
293  connecth.clear();
294  result = mbImpl->get_connectivity( &( *rit ), 1, connecth, true );
295  if( MB_SUCCESS != result ) return result;
296 
297  if( 0 == connecth.size() ) continue;
298 
299  // get the polyhedra, if any
300  if( user_dimension == 3 )
301  {
302  polyhedra.clear();
303  result = mbImpl->get_adjacencies( Range( *rit, *rit ), 3, false, polyhedra );
304  if( MB_SUCCESS != result ) return result;
305 
306  // put them in the connect array
307  connecth.push_back( ( polyhedra.size() > 0 ? *polyhedra.begin() : 0 ) );
308  connecth.push_back( ( polyhedra.size() > 1 ? *polyhedra.rbegin() : 0 ) );
309  }
310 
311  // replace handles with ids
312  connect.resize( connecth.size() + 2 );
313 
314  // pre-set polyhedra ids in case there aren't any
315  connect[connecth.size()] = 0;
316  connect[connecth.size() + 1] = 0;
317  result =
318  mbImpl->tag_get_data( mGlobalIdTag, &connecth[0], connecth.size() - 2 + polyhedra.size(), &connect[0] );
319  if( MB_SUCCESS != result ) return result;
320 
321  // write the data
322  ofile << connecth.size() - 2;
323 
324  for( i = 0; i < (int)connecth.size(); i++ )
325  ofile << " " << connect[i];
326 
327  ofile << std::endl;
328  }
329  }
330 
331  ofile << std::endl << "endgmv" << std::endl;
332 
333  ofile.close();
334 
335  return MB_SUCCESS;
336 }

References moab::WriteUtilIface::assign_ids(), moab::Range::begin(), moab::Range::clear(), moab::CREATE_HANDLE(), moab::Range::end(), ErrorCode, moab::GeomUtil::first(), moab::Interface::get_adjacencies(), moab::Interface::get_connectivity(), moab::WriteUtilIface::get_element_connect(), moab::Interface::get_entities_by_type(), moab::WriteUtilIface::get_node_coords(), gmvTypeNames, moab::Range::lower_bound(), MB_START_ID, MB_SUCCESS, mbImpl, MBPOLYGON, MBPOLYHEDRON, mGlobalIdTag, mWriteIface, moab::Range::rbegin(), moab::Range::size(), moab::Interface::tag_get_data(), moab::CN::TypeDimensionMap, moab::Interface::UNION, and moab::CN::VerticesPerEntity().

Referenced by write_file().

◆ write_file() [1/2]

ErrorCode moab::WriteGMV::write_file ( const char *  file_name,
const EntityHandle  output_set,
const int  user_dimension = 3,
const bool  mesh = true,
const bool  poly_mesh = true 
)

writes out a mesh file

Definition at line 84 of file WriteGMV.cpp.

89 {
90  // general function for writing a mesh
91 
92  ErrorCode result = MB_SUCCESS;
93 
94  // initialize file
95 
96  if( mesh )
97  {
98  result = local_write_mesh( file_name, output_set, user_dimension, true, false );
99  if( MB_SUCCESS != result ) return result;
100  }
101 
102  if( poly_mesh )
103  {
104  result = local_write_mesh( file_name, output_set, user_dimension, false, true );
105  if( MB_SUCCESS != result ) return result;
106  }
107 
108  return result;
109 }

References ErrorCode, local_write_mesh(), and MB_SUCCESS.

◆ write_file() [2/2]

ErrorCode moab::WriteGMV::write_file ( const char *  file_name,
const bool  overwrite,
const FileOptions opts,
const EntityHandle meshset_list,
const int  num_sets,
const std::vector< std::string > &  qa_records,
const Tag tag_list = NULL,
int  num_tags = 0,
int  requested_output_dimension = 3 
)
virtual

Export mesh to a file.

Method all writers must provide to export a mesh.

Parameters
file_nameThe name of the file to create.
overwriteIf false, reader should fail if the file already exists.
meshset_listA list of meshsets to export, or NULL if the whole mesh is to be exported.
num_setsThe length of meshset_list or zero if the whole mesh is to be exported.
qa_recordsFile history metadata
tag_listArray of handles for tags to write. If null, write all tags. If non-NULL but num_tags is zero, write no tags.
requseted_output_dimensionThe geometric dimension of the output mesh (coord values per vertex.) If zero, the dimension of the mesh as returned from Interface should be used.
Author
Jason Kraftcheck

Implements moab::WriterIface.

Definition at line 111 of file WriteGMV.cpp.

120 {
121  EntityHandle output_set = 0;
122  if( output_sets && num_output_sets > 0 )
123  {
124  if( num_output_sets > 1 ) return MB_FAILURE;
125  output_set = output_sets[0];
126  }
127 
128  if( dimension == 0 )
129  {
130  mbImpl->get_dimension( dimension );
131  }
132 
133  return write_file( filename, output_set, dimension, true, true );
134 }

References moab::Interface::get_dimension(), and mbImpl.

Member Data Documentation

◆ gmvTypeNames

const char * moab::WriteGMV::gmvTypeNames = { "", "line", "tri", "quad", "", "tet", "pyramid", "prism", "", "hex", "", "" }
staticprivate

Definition at line 85 of file WriteGMV.hpp.

Referenced by local_write_mesh().

◆ mbImpl

Interface* moab::WriteGMV::mbImpl
private

interface instance

Definition at line 73 of file WriteGMV.hpp.

Referenced by local_write_mesh(), write_file(), and ~WriteGMV().

◆ mDirichletSetTag

Tag moab::WriteGMV::mDirichletSetTag
private

Definition at line 79 of file WriteGMV.hpp.

Referenced by WriteGMV().

◆ mGeomDimensionTag

Tag moab::WriteGMV::mGeomDimensionTag
private

Definition at line 82 of file WriteGMV.hpp.

Referenced by WriteGMV().

◆ mGlobalIdTag

Tag moab::WriteGMV::mGlobalIdTag
private

Definition at line 83 of file WriteGMV.hpp.

Referenced by local_write_mesh(), and WriteGMV().

◆ mHasMidNodesTag

Tag moab::WriteGMV::mHasMidNodesTag
private

Definition at line 81 of file WriteGMV.hpp.

Referenced by WriteGMV().

◆ mMaterialSetTag

Tag moab::WriteGMV::mMaterialSetTag
private

Cached tags for reading. Note that all these tags are defined when the core is initialized.

Definition at line 78 of file WriteGMV.hpp.

Referenced by WriteGMV().

◆ mNeumannSetTag

Tag moab::WriteGMV::mNeumannSetTag
private

Definition at line 80 of file WriteGMV.hpp.

Referenced by WriteGMV().

◆ mWriteIface

WriteUtilIface* moab::WriteGMV::mWriteIface
private

Definition at line 74 of file WriteGMV.hpp.

Referenced by local_write_mesh(), WriteGMV(), and ~WriteGMV().


The documentation for this class was generated from the following files: