MOAB: Mesh Oriented datABase  (version 5.4.1)
test_exo.cpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #include "moab/Defines.h"
00017 #include "moab/Core.hpp"
00018 #include "ReadWriteExoII.hpp"
00019 #include "moab/_MBSet.hpp"
00020 
00021 #include <iostream>
00022 
00023 using namespace moab;
00024 
00025 std::ostream& operator<<( std::ostream& out, const std::vector< int >& v )
00026 {
00027     std::copy( v.begin(), v.end(), std::ostream_iterator< int >( std::cout, " " ) );
00028     return out;
00029 }
00030 
00031 int main( int argc, char* argv[] )
00032 {
00033     // check for file name on command line
00034     if( 2 != argc )
00035     {
00036         std::cout << "Usage: " << argv[0] << " <exoII_file_name>" << std::endl;
00037         return 1;
00038     }
00039 
00040     Core mdb;
00041     ReadWriteExoII reader( &mdb );
00042     ErrorCode result = reader.load_file( argv[1], NULL );
00043 
00044     std::cout << "Result of reading file = " << ( MB_FAILURE == result ? "FAILURE." : "SUCCESS." ) << std::endl;
00045 
00046     // print some data about the mesh
00047     int num_nodes    = mdb.total_num_nodes();
00048     int num_elements = mdb.total_num_elements();
00049     std::cout << "Total number of nodes, elements read = " << num_nodes << ", " << num_elements << std::endl;
00050 
00051     // get the nodeset meshsets and blocks
00052     std::vector< MB_MBSet* > blocks, nodesets, sidesets;
00053     std::vector< int > block_ids, nodeset_ids, sideset_ids;
00054     const std::set< MB_MBSet* >& gms = MB_MBSet::GlobalMBSets();
00055 
00056     std::set< MB_MBSet* >::const_iterator this_it = gms.begin(), end_it = MB_MBSet::GlobalMBSets().end();
00057     MB_MBSet* this_meshset;
00058     int bc_tag;
00059     for( ; this_it != end_it; ++this_it )
00060     {
00061         // get the next set
00062         this_meshset = *this_it;
00063 
00064         bc_tag = reader.get_block_id( this_meshset );
00065         if( -1 != bc_tag )
00066         {
00067             blocks.push_back( this_meshset );
00068             block_ids.push_back( bc_tag );
00069         }
00070 
00071         // same for nodeset tag
00072         bc_tag = reader.get_nodeset_id( this_meshset );
00073         if( -1 != bc_tag )
00074         {
00075             nodesets.push_back( this_meshset );
00076             nodeset_ids.push_back( bc_tag );
00077         }
00078 
00079         // same for sideset tag
00080         bc_tag = reader.get_sideset_id( this_meshset );
00081         if( -1 != bc_tag )
00082         {
00083             sidesets.push_back( this_meshset );
00084             sideset_ids.push_back( bc_tag );
00085         }
00086     }
00087 
00088     // std::vector<int>::iterator set_it;
00089     std::cout << "Block numbers read: " << std::endl;
00090     if( !blocks.empty() )
00091         std::cout << block_ids << std::endl;
00092     else
00093         std::cout << "(no blocks)" << std::endl;
00094 
00095     std::cout << "Nodeset numbers read: " << std::endl;
00096     if( !nodesets.empty() )
00097         std::cout << nodeset_ids << std::endl;
00098     else
00099         std::cout << "(no nodesets)" << std::endl;
00100 
00101     std::cout << "Sideset numbers read: " << std::endl;
00102     if( !sidesets.empty() )
00103         std::cout << sideset_ids << std::endl;
00104     else
00105         std::cout << "(no sidesets)" << std::endl;
00106 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines