MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /** @example LoadPartial.cpp \n 00002 * \brief Load a part of a file \n 00003 * <b>To run</b>: LoadPartial <file> <tag_name> <val1> <val2> ...\n 00004 * 00005 * In this example, it is shown how to load only a part of one file; the file must be organized in 00006 * sets. (cherry-picking only the sets we want) The sets to load are identified by a tag name and 00007 * the tag values for the sets of interest. This procedure is used when reading in parallel, as 00008 * each processor will load only its part of the file, identified either by partition or by 00009 * material/block sets by default, this example will load parallel partition sets with values 1, 2, 00010 * and 5 from ../MeshFiles/unittest/64bricks_1khex.h5m The example will always write the output to a 00011 * file name part.h5m 00012 */ 00013 00014 #include <iostream> 00015 #include <vector> 00016 00017 // Include header for MOAB instance and tag conventions for 00018 #include "moab/Core.hpp" 00019 #include "MBTagConventions.hpp" 00020 00021 #define NTAGVALS 3 00022 00023 using namespace moab; 00024 using namespace std; 00025 00026 // Function to parse input parameters 00027 ErrorCode get_file_options( int argc, char** argv, string& filename, string& tagName, vector< int >& tagValues ) 00028 { 00029 // Get mesh filename 00030 if( argc > 1 ) 00031 filename = string( argv[1] ); 00032 else 00033 filename = string( MESH_DIR ) + string( "/64bricks_512hex_256part.h5m" ); 00034 00035 // Get tag selection options 00036 if( argc > 2 ) 00037 tagName = string( argv[2] ); 00038 else 00039 tagName = "USERTAG"; 00040 00041 if( argc > 3 ) 00042 { 00043 tagValues.resize( argc - 3, 0 ); 00044 for( int i = 3; i < argc; ++i ) 00045 tagValues[i - 3] = atoi( argv[i] ); 00046 } 00047 else 00048 { 00049 for( unsigned i = 0; i < tagValues.size(); ++i ) 00050 tagValues[i] = 2 * i + 1; 00051 } 00052 00053 if( argc > 1 && argc < 4 ) // print usage 00054 cout << " usage is " << argv[0] << " <file> <tag_name> <value1> <value2> .. \n"; 00055 return MB_SUCCESS; 00056 } 00057 00058 int main( int argc, char** argv ) 00059 { 00060 // Get MOAB instance 00061 Interface* mb = new( std::nothrow ) Core; 00062 if( NULL == mb ) return 1; 00063 00064 std::string filename, tagname; 00065 vector< int > tagvals( NTAGVALS ); // Allocate for a maximum of 5 tag values 00066 ErrorCode rval = get_file_options( argc, argv, filename, tagname, tagvals );MB_CHK_ERR( rval ); 00067 00068 #ifdef MOAB_HAVE_HDF5 00069 // This file is in the mesh files directory 00070 rval = mb->load_file( filename.c_str(), 0, 0, PARALLEL_PARTITION_TAG_NAME, tagvals.data(), (int)tagvals.size() );MB_CHK_SET_ERR( rval, "Failed to read" ); 00071 00072 // If HANDLEID tag present, convert to long, and see what we read from file 00073 Tag handleid_tag; 00074 rval = mb->tag_get_handle( "HANDLEID", handleid_tag ); 00075 if( MB_SUCCESS == rval ) 00076 { 00077 // Convert a few values for a few vertices 00078 Range verts; 00079 rval = mb->get_entities_by_type( 0, MBVERTEX, verts );MB_CHK_SET_ERR( rval, "Failed to get vertices" ); 00080 vector< long > valsTag( verts.size() ); 00081 rval = mb->tag_get_data( handleid_tag, verts, &valsTag[0] ); 00082 if( MB_SUCCESS == rval ) cout << "First 2 long values recovered: " << valsTag[0] << " " << valsTag[1] << "\n"; 00083 } 00084 00085 rval = mb->write_file( "part.h5m" );MB_CHK_SET_ERR( rval, "Failed to write partial file" ); 00086 cout << "Wrote successfully part.h5m.\n"; 00087 00088 #else 00089 std::cout << "Configure MOAB with HDF5 to build and use this example correctly.\n"; 00090 #endif 00091 delete mb; 00092 return 0; 00093 }