Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
Output Exodus File for VERDE. More...
#include <WriteGMV.hpp>
Public Member Functions | |
WriteGMV (Interface *impl) | |
Constructor. | |
virtual | ~WriteGMV () |
Destructor. | |
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. | |
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 | |
Static Public Member Functions | |
static WriterIface * | factory (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 | |
Interface * | mbImpl |
interface instance | |
WriteUtilIface * | mWriteIface |
Tag | mMaterialSetTag |
Cached tags for reading. Note that all these tags are defined when the core is initialized. | |
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", "", "" } |
Output Exodus File for VERDE.
Definition at line 41 of file WriteGMV.hpp.
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.
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().
: mbImpl( impl ) { assert( impl != NULL ); impl->query_interface( mWriteIface ); // initialize in case tag_get_handle fails below mMaterialSetTag = 0; mDirichletSetTag = 0; mNeumannSetTag = 0; mHasMidNodesTag = 0; mGeomDimensionTag = 0; mGlobalIdTag = 0; //! get and cache predefined tag handles // initialize in case tag_get_handle fails below //! get and cache predefined tag handles int negone = -1; impl->tag_get_handle( MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mMaterialSetTag, MB_TAG_SPARSE | MB_TAG_CREAT, &negone ); impl->tag_get_handle( DIRICHLET_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mDirichletSetTag, MB_TAG_SPARSE | MB_TAG_CREAT, &negone ); impl->tag_get_handle( NEUMANN_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mNeumannSetTag, MB_TAG_SPARSE | MB_TAG_CREAT, &negone ); mGlobalIdTag = impl->globalId_tag(); int dum_val_array[] = { -1, -1, -1, -1 }; impl->tag_get_handle( HAS_MID_NODES_TAG_NAME, 4, MB_TYPE_INTEGER, mHasMidNodesTag, MB_TAG_SPARSE | MB_TAG_CREAT, dum_val_array ); }
moab::WriteGMV::~WriteGMV | ( | ) | [virtual] |
Destructor.
Definition at line 79 of file WriteGMV.cpp.
References mbImpl, mWriteIface, and moab::Interface::release_interface().
{ mbImpl->release_interface( mWriteIface ); }
WriterIface * moab::WriteGMV::factory | ( | Interface * | iface | ) | [static] |
Definition at line 40 of file WriteGMV.cpp.
References WriteGMV().
Referenced by moab::ReaderWriterSet::ReaderWriterSet().
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.
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().
{ std::ofstream ofile; ErrorCode result; if( mesh ) { // need to insert ".gmv" std::string tmp_name( file_name ); tmp_name += ".gmv"; ofile.open( tmp_name.c_str() ); } else if( poly_mesh ) { // need to insert ".poly.gmv" std::string tmp_name( file_name ); tmp_name += ".poly.gmv"; ofile.open( tmp_name.c_str() ); } ofile << "gmvinput ascii" << std::endl; // get elements to be output Range dum_range, elements, all_verts; EntityType otype; if( poly_mesh ) { result = mbImpl->get_entities_by_type( output_set, MBPOLYGON, elements, true ); if( MB_SUCCESS != result ) return result; } else { for( otype = CN::TypeDimensionMap[user_dimension].first; otype <= CN::TypeDimensionMap[user_dimension].second; otype++ ) { if( otype == MBPOLYGON || otype == MBPOLYHEDRON ) continue; dum_range.clear(); result = mbImpl->get_entities_by_type( output_set, otype, dum_range, true ); if( MB_SUCCESS != result ) return result; std::copy( dum_range.begin(), dum_range.end(), range_inserter( elements ) ); } } // gather the vertices in these elements result = mbImpl->get_adjacencies( elements, 0, false, all_verts, Interface::UNION ); if( MB_SUCCESS != result ) return result; int num_verts = all_verts.size(); // allocate coordinate arrays and put pointers to them in a list double* xcoord = new double[num_verts]; double* ycoord = new double[num_verts]; double* zcoord = new double[num_verts]; std::vector< double* > coord_arrays; coord_arrays.push_back( xcoord ); coord_arrays.push_back( ycoord ); coord_arrays.push_back( zcoord ); // fill them in, writing id tags at the same time result = mWriteIface->get_node_coords( 3, num_verts, all_verts, mGlobalIdTag, 1, coord_arrays ); if( MB_SUCCESS != result ) return result; int i, j; //======================================== // WRITE COORDINATE DATA TO FILE HERE ofile << "nodev " << num_verts << std::endl; for( i = 0; i < num_verts; i++ ) ofile << xcoord[i] << " " << ycoord[i] << " " << zcoord[i] << std::endl; //======================================== delete[] xcoord; delete[] ycoord; delete[] zcoord; // iterate over types in selected dimension std::vector< int > connect; std::vector< EntityHandle > connecth; if( mesh ) { Range sub_range; ofile << "cells " << elements.size() << std::endl; for( otype = CN::TypeDimensionMap[user_dimension].first; otype <= CN::TypeDimensionMap[user_dimension].second; otype++ ) { if( otype == MBPOLYGON || otype == MBPOLYHEDRON ) continue; // get the first element of this type in the range, and one past the last Range::iterator lower = Range::lower_bound( elements.begin(), elements.end(), CREATE_HANDLE( otype, MB_START_ID, i ) ); Range::iterator upper = Range::lower_bound( elements.begin(), elements.end(), CREATE_HANDLE( otype + 1, MB_START_ID, i ) ); if( lower == upper ) continue; // copy these elements into a subrange sub_range.clear(); std::copy( lower, upper, range_inserter( sub_range ) ); // make sure the connectivity array is big enough int verts_per = CN::VerticesPerEntity( otype ); if( connect.size() < verts_per * sub_range.size() ) connect.resize( verts_per * sub_range.size() ); // get the connectivity result = mWriteIface->get_element_connect( sub_range.size(), verts_per, mGlobalIdTag, sub_range, mGlobalIdTag, 1, &connect[0] ); if( MB_SUCCESS != result ) return result; //======================================== // WRITE CONNECTIVITY DATA TO FILE HERE for( i = 0; i < (int)sub_range.size(); i++ ) { ofile << gmvTypeNames[otype] << " " << verts_per << std::endl; for( j = i * verts_per; j < (int)( i + 1 ) * verts_per; j++ ) ofile << connect[j] << " "; ofile << std::endl; } //======================================== } } else if( poly_mesh ) { // write polygons/hedra, if any Range polygons, polyhedra; result = mbImpl->get_entities_by_type( output_set, MBPOLYGON, polygons, true ); if( MB_SUCCESS != result ) return result; result = mbImpl->get_entities_by_type( output_set, MBPOLYHEDRON, polyhedra, true ); if( MB_SUCCESS != result ) return result; if( polygons.size() == 0 ) return result; // mark polyhedra with global ids result = mWriteIface->assign_ids( polyhedra, mGlobalIdTag, 1 ); if( MB_SUCCESS != result ) return result; ofile << "faces " << polygons.size() << " " << polyhedra.size() << std::endl; for( Range::iterator rit = polygons.begin(); rit != polygons.end(); ++rit ) { // get the vertices connecth.clear(); result = mbImpl->get_connectivity( &( *rit ), 1, connecth, true ); if( MB_SUCCESS != result ) return result; if( 0 == connecth.size() ) continue; // get the polyhedra, if any if( user_dimension == 3 ) { polyhedra.clear(); result = mbImpl->get_adjacencies( Range( *rit, *rit ), 3, false, polyhedra ); if( MB_SUCCESS != result ) return result; // put them in the connect array connecth.push_back( ( polyhedra.size() > 0 ? *polyhedra.begin() : 0 ) ); connecth.push_back( ( polyhedra.size() > 1 ? *polyhedra.rbegin() : 0 ) ); } // replace handles with ids connect.resize( connecth.size() + 2 ); // pre-set polyhedra ids in case there aren't any connect[connecth.size()] = 0; connect[connecth.size() + 1] = 0; result = mbImpl->tag_get_data( mGlobalIdTag, &connecth[0], connecth.size() - 2 + polyhedra.size(), &connect[0] ); if( MB_SUCCESS != result ) return result; // write the data ofile << connecth.size() - 2; for( i = 0; i < (int)connecth.size(); i++ ) ofile << " " << connect[i]; ofile << std::endl; } } ofile << std::endl << "endgmv" << std::endl; ofile.close(); return MB_SUCCESS; }
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.
file_name | The name of the file to create. |
overwrite | If false, reader should fail if the file already exists. |
meshset_list | A list of meshsets to export, or NULL if the whole mesh is to be exported. |
num_sets | The length of meshset_list or zero if the whole mesh is to be exported. |
qa_records | File history metadata |
tag_list | Array of handles for tags to write. If null, write all tags. If non-NULL but num_tags is zero, write no tags. |
requseted_output_dimension | The geometric dimension of the output mesh (coord values per vertex.) If zero, the dimension of the mesh as returned from Interface should be used. |
Implements moab::WriterIface.
Definition at line 111 of file WriteGMV.cpp.
References moab::Interface::get_dimension(), and mbImpl.
{ EntityHandle output_set = 0; if( output_sets && num_output_sets > 0 ) { if( num_output_sets > 1 ) return MB_FAILURE; output_set = output_sets[0]; } if( dimension == 0 ) { mbImpl->get_dimension( dimension ); } return write_file( filename, output_set, dimension, true, true ); }
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.
References ErrorCode, local_write_mesh(), and MB_SUCCESS.
{ // general function for writing a mesh ErrorCode result = MB_SUCCESS; // initialize file if( mesh ) { result = local_write_mesh( file_name, output_set, user_dimension, true, false ); if( MB_SUCCESS != result ) return result; } if( poly_mesh ) { result = local_write_mesh( file_name, output_set, user_dimension, false, true ); if( MB_SUCCESS != result ) return result; } return result; }
const char * moab::WriteGMV::gmvTypeNames = { "", "line", "tri", "quad", "", "tet", "pyramid", "prism", "", "hex", "", "" } [static, private] |
Definition at line 85 of file WriteGMV.hpp.
Referenced by local_write_mesh().
Interface* moab::WriteGMV::mbImpl [private] |
interface instance
Definition at line 73 of file WriteGMV.hpp.
Referenced by local_write_mesh(), write_file(), and ~WriteGMV().
Tag moab::WriteGMV::mDirichletSetTag [private] |
Definition at line 79 of file WriteGMV.hpp.
Referenced by WriteGMV().
Tag moab::WriteGMV::mGeomDimensionTag [private] |
Definition at line 82 of file WriteGMV.hpp.
Referenced by WriteGMV().
Tag moab::WriteGMV::mGlobalIdTag [private] |
Definition at line 83 of file WriteGMV.hpp.
Referenced by local_write_mesh(), and WriteGMV().
Tag moab::WriteGMV::mHasMidNodesTag [private] |
Definition at line 81 of file WriteGMV.hpp.
Referenced by WriteGMV().
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().
Tag moab::WriteGMV::mNeumannSetTag [private] |
Definition at line 80 of file WriteGMV.hpp.
Referenced by WriteGMV().
WriteUtilIface* moab::WriteGMV::mWriteIface [private] |
Definition at line 74 of file WriteGMV.hpp.
Referenced by local_write_mesh(), WriteGMV(), and ~WriteGMV().