A simple example demonstrating basic MOAB functionality.This example demonstrates the fundamental operations in MOAB:
- Creating a MOAB instance
- Loading a mesh from a file
- Querying entities by type and dimension
- Basic error handling with MB_CHK_ERR
The program reads a mesh file (default: 3k-tri-sphere.vtk) and reports the number of vertices, edges, faces, and elements in the mesh.
To run: ./HelloMOAB [meshfile] (default values can run if users don't specify a mesh file)
#include <iostream>
#include <memory>
#include <string>
namespace
{
}
int main(
int argc,
char** argv )
{
try
{
auto moab = std::make_unique< Core >();
{
std::cerr << "Error: Failed to create MOAB instance\n";
return 1;
}
const std::string mesh_file =
MB_CHK_SET_ERR(
moab->load_mesh( mesh_file.c_str() ),
"Error: Could not load mesh file: " << mesh_file );
Range vertices, edges, faces, elements;
const auto print_entity_count = []( const std::string& name, const auto& range ) {
std::cout << "Number of " << name << ": " << range.size() << "\n";
};
print_entity_count( "vertices", vertices );
print_entity_count( "edges ", edges );
print_entity_count( "faces ", faces );
print_entity_count( "elements", elements );
return 0;
}
catch( const std::exception& e )
{
std::cerr << "Error: " << e.what() << "\n";
return 1;
}
catch( ... )
{
std::cerr << "Error: Unknown exception occurred\n";
return 1;
}
}