Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
UniformRefinement.cpp File Reference
#include "moab/Core.hpp"
#include "moab/NestedRefine.hpp"
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <stdexcept>
+ Include dependency graph for UniformRefinement.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{UniformRefinement.cpp}
 

Functions

void anonymous_namespace{UniformRefinement.cpp}::print_usage (const char *program_name)
 
std::vector< int > anonymous_namespace{UniformRefinement.cpp}::parse_refinement_levels (int argc, char *argv[])
 
int main (int argc, char *argv[])
 

Variables

constexpr const char * anonymous_namespace{UniformRefinement.cpp}::DEFAULT_OUTPUT_FILE = "mesh_hierarchy.h5m"
 
constexpr int anonymous_namespace{UniformRefinement.cpp}::DEFAULT_REFINEMENT_LEVELS = 2
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
UniformRefinement.cpp.

Definition at line 80 of file UniformRefinement.cpp.

81 {
82  try
83  {
84  // Parse command line arguments
85  if( argc < 2 || std::string( argv[1] ) == "--help" || std::string( argv[1] ) == "-h" )
86  {
87  print_usage( argv[0] );
88  return argc < 2 ? 1 : 0;
89  }
90 
91  const std::string input_file = argv[1];
92  auto level_degrees = parse_refinement_levels( argc, argv );
93  const int num_levels = static_cast< int >( level_degrees.size() );
94 
95  std::cout << "Input file: " << input_file << "\n"
96  << "Refinement levels: " << num_levels << "\n"
97  << "Level degrees: ";
98 
99  for( const auto& degree : level_degrees )
100  {
101  std::cout << degree << " ";
102  }
103  std::cout << "\n";
104 
105  // Initialize MOAB and load the mesh
106  auto moab = std::make_unique< Core >();
107  if( !moab )
108  {
109  throw std::runtime_error( "Failed to create MOAB instance" );
110  }
111 
112  // Load the input mesh file
113  MB_CHK_SET_ERR_CONT( moab->load_file( input_file.c_str() ), "Failed to load mesh file: " << input_file );
114 
115  // Set up the refinement
116  NestedRefine refiner( moab.get() );
117 
118  std::vector< EntityHandle > mesh_sets;
119  std::cout << "Starting mesh hierarchy generation for " << num_levels << " levels...\n";
120  // Perform the refinement
121  MB_CHK_SET_ERR( refiner.generate_mesh_hierarchy( num_levels, level_degrees.data(), mesh_sets ),
122  "Failed to generate mesh hierarchy" );
123  std::cout << "Successfully generated mesh hierarchy\n";
124 
125  // Write the refined mesh to file
126  MB_CHK_SET_ERR( moab->write_file( DEFAULT_OUTPUT_FILE ),
127  "Failed to write output file: " << DEFAULT_OUTPUT_FILE );
128 
129  std::cout << "Output written to: " << DEFAULT_OUTPUT_FILE << "\n";
130  return 0;
131  }
132  catch( const std::exception& e )
133  {
134  std::cerr << "\nError: " << e.what() << "\n";
135  return 1;
136  }
137  catch( ... )
138  {
139  std::cerr << "\nError: Unknown exception occurred\n";
140  return 1;
141  }
142 }

References anonymous_namespace{UniformRefinement.cpp}::DEFAULT_OUTPUT_FILE, moab::NestedRefine::generate_mesh_hierarchy(), input_file, MB_CHK_SET_ERR, MB_CHK_SET_ERR_CONT, anonymous_namespace{UniformRefinement.cpp}::parse_refinement_levels(), and anonymous_namespace{UniformRefinement.cpp}::print_usage().