Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
ToolContext Class Reference

Context class for MOAB-TempestRemap tool configuration and state management. More...

+ Collaboration diagram for ToolContext:

Public Member Functions

 ToolContext (moab::Core *icore)
 Construct a new ToolContext object with MPI support. More...
 
 ~ToolContext ()=default
 
 ToolContext (const ToolContext &)=delete
 
ToolContextoperator= (const ToolContext &)=delete
 
 ToolContext (ToolContext &&)=delete
 
ToolContextoperator= (ToolContext &&)=delete
 
void timer_push (const std::string &operation)
 Start timing an operation. More...
 
void timer_pop ()
 Stop timing and log the operation duration. More...
 
moab::ErrorCode ParseCLOptions (int argc, char **argv)
 Parse command line arguments. More...
 
std::string get_file_read_options (const std::string &filename)
 Get the appropriate MOAB read options based on file extension and parallel configuration. More...
 

Public Attributes

moab::Core *const mbcore
 MOAB Core instance for mesh operations. More...
 
const int proc_id
 MPI process rank (0 for serial) More...
 
const int n_procs
 Total number of MPI processes (1 for serial) More...
 
moab::DebugOutput outputFormatter
 Formatter for debug output. More...
 
moab::TempestRemapper::TempestMeshType meshType { moab::TempestRemapper::DEFAULT }
 Type of mesh to generate. More...
 
std::vector< std::string > inFilenames
 Input filenames for source and target meshes. More...
 
std::vector< int > disc_orders
 Discretization orders for source and target. More...
 
std::vector< std::string > disc_methods
 Discretization methods (fv, cgll, dgll) for source and target. More...
 
std::vector< std::string > doftag_names
 Degree of freedom tag names for source and target. More...
 
std::string outFilename { "outputFile.nc" }
 Output filename for remapping results. More...
 
std::string intxFilename
 Intersection mesh filename (optional) More...
 
std::string baselineFile
 Baseline file for verification (optional) More...
 
std::string variableToVerify
 Variable name for verification (optional) More...
 
std::string fvMethod { "none" }
 Finite volume method specification. More...
 
GenerateOfflineMapAlgorithmOptions mapOptions
 Configuration for offline map generation. More...
 
moab::TempestOnlineMap::CAASType cassType
 Conservative and accurate advection scheme type. More...
 
int ensureMonotonicity { 0 }
 Monotonicity enforcement level (0=none, 1=basic, 2=full, 3=strict) More...
 
bool rrmGrids { false }
 Flag to use RRM (Regional Refinement Meshes) More...
 
bool kdtreeSearch { true }
 Enable KD-tree for spatial searches. More...
 
bool fCheck { false }
 Enable additional checking during remapping. More...
 
bool fVolumetric { false }
 Enable volumetric (3D) remapping. More...
 
bool useGnomonicProjection { false }
 Use gnomonic projection for certain operations. More...
 
bool print_diagnostics { false }
 Print detailed diagnostic information. More...
 
bool skip_intersection { false }
 Skip intersection computation (for debugging) More...
 
double boxeps { 1e-7 }
 Epsilon for bounding box checks. More...
 
double epsrel { ReferenceTolerance }
 Relative tolerance for convergence. More...
 
bool skip_io { false }
 Skip file I/O operations (for testing) More...
 
bool computeDual { false }
 Compute dual mesh. More...
 
bool computeWeights { false }
 Compute interpolation weights. More...
 
bool verifyConservation { false }
 Verify conservation properties. More...
 
bool verifyWeights { false }
 Verify interpolation weights. More...
 
bool enforceConvexity { false }
 Enforce convexity in mesh elements. More...
 
std::unique_ptr< moab::CpuTimertimer
 Timer for performance measurement. More...
 
double timer_ops { 0.0 }
 Operation timer value. More...
 
std::string opName
 Name of current operation being timed. More...
 
int nlayers { 0 }
 Number of ghost layers for parallel operations. More...
 
int blockSize { 5 }
 Block size for vectorized operations. More...
 
std::vector< Mesh * > meshes
 Collection of TempestRemap meshes. More...
 
std::vector< moab::EntityHandlemeshsets
 MOAB entity sets for meshes. More...
 

Private Member Functions

void printHelp (const char *progName) const
 Print detailed help message with usage examples. More...
 
std::string getMeshTypeName () const
 Get mesh type as string. More...
 
void processMeshOptions (ProgOptions &opts)
 Process mesh options from command line. More...
 
void printRuntimeParameters () const
 Print all runtime parameters in a formatted way. More...
 
void configureMapOptions (int nlayer_input)
 Configure map options based on command line parameters. More...
 

Detailed Description

Context class for MOAB-TempestRemap tool configuration and state management.

Definition at line 95 of file mbtempest.cpp.

Constructor & Destructor Documentation

◆ ToolContext() [1/3]

ToolContext::ToolContext ( moab::Core icore)
inlineexplicit

Construct a new ToolContext object with MPI support.

Parameters
icoreMOAB Core instance (must not be null)
p_pcommParallel communicator (must not be null in MPI mode)
Exceptions
std::invalid_argumentif icore is null or p_pcomm is null in MPI mode

Construct a new ToolContext object (serial version)

Parameters
icoreMOAB Core instance (must not be null)
Exceptions
std::invalid_argumentif icore is null

Definition at line 172 of file mbtempest.cpp.

173  : mbcore( icore ), proc_id( 0 ), n_procs( 1 ), outputFormatter( std::cout, 0, 0 )
174  {
175 #endif
176  // Initialize default values
177  inFilenames.reserve( 2 );
178  doftag_names = { "GLOBAL_ID", "GLOBAL_ID" };
179  disc_orders = { 1, 1 };
180  disc_methods = { "fv", "fv" };
181 
182  // Initialize timer and output formatter
183  timer = std::make_unique< moab::CpuTimer >();
184  outputFormatter.set_prefix( "[MBTempest]: " );
185 
186  // Set default map options
187  mapOptions.fNoConservation = false;
188  mapOptions.fMonotone = false;
189  mapOptions.fNoCorrectAreas = false;
190  mapOptions.fNoCheck = false;
191  mapOptions.nPin = 1;
192  mapOptions.nPout = 1;
193  }

References disc_methods, disc_orders, doftag_names, inFilenames, mapOptions, outputFormatter, moab::DebugOutput::set_prefix(), and timer.

Referenced by main().

◆ ~ToolContext()

ToolContext::~ToolContext ( )
default

◆ ToolContext() [2/3]

ToolContext::ToolContext ( const ToolContext )
delete

◆ ToolContext() [3/3]

ToolContext::ToolContext ( ToolContext &&  )
delete

Member Function Documentation

◆ configureMapOptions()

void ToolContext::configureMapOptions ( int  nlayer_input)
inlineprivate

Configure map options based on command line parameters.

Parameters
nlayer_inputNumber of ghost layers

Definition at line 837 of file mbtempest.cpp.

838  {
839  // Set polynomial orders with bounds checking
840  this->mapOptions.nPin = ( this->disc_orders.empty() ) ? 1 : this->disc_orders[0];
841  this->mapOptions.nPout = ( this->disc_orders.size() > 1 ) ? this->disc_orders[1] : this->mapOptions.nPin;
842 
843  // Initialize flags
844  this->mapOptions.fSourceConcave = false;
845  this->mapOptions.fTargetConcave = false;
846  this->mapOptions.strMethod.clear();
847 
848  // Configure finite volume method if specified
849  if( this->fvMethod != "none" )
850  {
851  this->mapOptions.strMethod = this->fvMethod + ";";
852  this->mapOptions.fNoConservation = true;
853  }
854 
855  // Configure monotonicity with validation
856  this->ensureMonotonicity = std::max( 0, std::min( 3, this->ensureMonotonicity ) ); // Clamp to 0-3
857  switch( this->ensureMonotonicity )
858  {
859  case 0:
860  this->mapOptions.fMonotone = false;
861  break;
862  case 3:
863  this->mapOptions.strMethod += "mono3;";
864  this->mapOptions.fMonotone = true;
865  break;
866  case 2:
867  this->mapOptions.strMethod += "mono2;";
868  this->mapOptions.fMonotone = true;
869  break;
870  case 1:
871  default:
872  this->mapOptions.fMonotone = true;
873  break;
874  }
875 
876  // Set other options
877  this->mapOptions.fNoCorrectAreas = false;
878  this->mapOptions.fNoCheck = !this->fCheck;
879 
880  // Add volumetric flag if needed
881  if( this->fVolumetric )
882  {
883  this->mapOptions.strMethod += "volumetric;";
884  }
885 
886  // Set number of ghost layers based on method and order.
887  // FV order 1 needs 0 ghost layers; FV order p > 1 needs p+1 ghost layers.
888  if( this->fvMethod == "delaunay" || this->fvMethod == "bilin" )
889  {
890  this->skip_intersection = true;
891  this->nlayers = 3; // conservative
892  }
893  else
894  {
895  // order 1: no ghost layers
896  // order p: p+1 layers (again, being conservative)
897  this->nlayers = ( this->mapOptions.nPin > 1 ) ? this->mapOptions.nPin + 1 : 0;
898  }
899 
900  // User-supplied value always overrides the internal default (even 0 is valid).
901  if( nlayer_input >= 0 )
902  {
903  this->nlayers = nlayer_input;
904  }
905 
906  // Configure output
907  this->mapOptions.strOutputMapFile = this->outFilename;
908  this->mapOptions.strOutputFormat = "Netcdf4";
909  }

References ensureMonotonicity, fCheck, fvMethod, fVolumetric, nlayers, outFilename, and skip_intersection.

Referenced by ParseCLOptions().

◆ get_file_read_options()

std::string ToolContext::get_file_read_options ( const std::string &  filename)
inline

Get the appropriate MOAB read options based on file extension and parallel configuration.

Parameters
ctxTool context containing parallel information
filenameInput filename to determine read options
Returns
std::string MOAB read options string

Definition at line 489 of file mbtempest.cpp.

490  {
491  // For serial execution, return default options
492  if( n_procs <= 1 )
493  {
494  return "";
495  }
496 
497  // Extract file extension
498  const size_t last_dot = filename.find_last_of( "." );
499  if( last_dot == std::string::npos )
500  {
501  return ""; // No extension found
502  }
503 
504  const std::string extension = filename.substr( last_dot + 1 );
505 
506  // Handle H5M files
507  if( extension == "h5m" )
508  {
509  return "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;";
510  }
511 
512  // Handle NetCDF files
513  if( extension == "nc" )
514  {
515  // Default NetCDF options
516 #ifdef MOAB_HAVE_ZOLTAN
517  std::string netcdf_options = "PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN;";
518 #else
519  std::string netcdf_options = "PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL;";
520 #endif
521  // Only rank 0 needs to determine the NetCDF file type
522  if( proc_id == 0 )
523  {
524  NcFile ncFile( filename.c_str(), NcFile::ReadOnly );
525  if( !ncFile.is_valid() )
526  {
527  // Handle invalid file
528  return netcdf_options;
529  }
530 
531  // Check for different NetCDF formats
532  int format_flags = 0;
533  for( int i = 0; i < ncFile.num_dims(); i++ )
534  {
535  const std::string dim_name = ncFile.get_dim( i )->name();
536 
537  if( dim_name == "grid_size" || dim_name == "grid_corners" || dim_name == "grid_rank" )
538  {
539  format_flags |= 1; // SCRIP format
540  }
541  else if( dim_name == "nodeCount" || dim_name == "elementCount" || dim_name == "maxNodePElement" )
542  {
543  format_flags |= 2; // ESMF format
544  }
545  else if( dim_name == "nCells" || dim_name == "nEdges" || dim_name == "nVertices" ||
546  dim_name == "vertexDegree" )
547  {
548  format_flags |= 4; // MPAS format
549  }
550  }
551 
552  // Apply format-specific options
553  if( format_flags & 2 )
554  { // ESMF format
555  netcdf_options += "PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=;";
556  }
557  else if( format_flags & 1 )
558  { // SCRIP format
559  netcdf_options += ""; // no extra options necessary for now
560  }
561  else if( format_flags & 4 )
562  { // MPAS format
563  netcdf_options += "PARALLEL_RESOLVE_SHARED_ENTS;NO_EDGES;NO_MIXED_ELEMENTS;VARIABLE=;";
564  }
565  }
566 
567  // Broadcast the options to all processes
568 #ifdef MOAB_HAVE_MPI
569  int line_size = netcdf_options.size();
570  MPI_Bcast( &line_size, 1, MPI_INT, 0, MPI_COMM_WORLD );
571  if( proc_id != 0 )
572  {
573  netcdf_options.resize( line_size );
574  }
575  MPI_Bcast( const_cast< char* >( netcdf_options.data() ), line_size, MPI_CHAR, 0, MPI_COMM_WORLD );
576 #endif
577 
578  return netcdf_options;
579  }
580 
581  // Default options for other file types
582  return "PARALLEL=BCAST_DELETE;PARTITION=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS;";
583  }

References n_procs, ncFile, and proc_id.

Referenced by anonymous_namespace{mbtempest.cpp}::handleOverlapMOAB().

◆ getMeshTypeName()

std::string ToolContext::getMeshTypeName ( ) const
inlineprivate

Get mesh type as string.

Returns
String representation of mesh type

Definition at line 646 of file mbtempest.cpp.

647  {
648  switch( this->meshType )
649  {
651  return "Cubed-Sphere";
653  return "Latitude-Longitude";
655  return "Icosahedral";
657  return "Overlap (files)";
659  return "Overlap (memory)";
661  return "Overlap (MOAB)";
662  default:
663  return "Unknown";
664  }
665  }

References moab::TempestRemapper::CS, moab::TempestRemapper::ICO, meshType, moab::TempestRemapper::OVERLAP_FILES, moab::TempestRemapper::OVERLAP_MEMORY, moab::TempestRemapper::OVERLAP_MOAB, and moab::TempestRemapper::RLL.

Referenced by printRuntimeParameters().

◆ operator=() [1/2]

ToolContext& ToolContext::operator= ( const ToolContext )
delete

◆ operator=() [2/2]

ToolContext& ToolContext::operator= ( ToolContext &&  )
delete

◆ ParseCLOptions()

moab::ErrorCode ToolContext::ParseCLOptions ( int  argc,
char **  argv 
)
inline

Parse command line arguments.

Parameters
argcArgument count
argvArgument values
Returns
moab::ErrorCode indicating success or failure
Exceptions
std::invalid_argumentfor invalid command line arguments

Definition at line 242 of file mbtempest.cpp.

243  {
244  // Initialize variables for command line options
245  int imeshType = 0;
246  std::string expectedFName = "output.exo";
247  std::string expectedMethod = "fv";
248  std::string expectedFVMethod = "none";
249  std::string expectedDofTagName = "GLOBAL_ID";
250  int expectedOrder = 1;
251  int useCAAS = 0;
252  int nlayer_input = -1; // -1 means not set by user
253  bool version_info = false;
254 
255  // Print command line for debugging
256  if( proc_id == 0 )
257  {
258  std::cout << "Command line options provided to mbtempest:\n ";
259  for( int i = 0; i < argc; ++i )
260  {
261  std::cout << argv[i] << " ";
262  }
263  std::cout << "\n" << std::endl;
264  }
265 
266  // Create options object with description
267  ProgOptions opts( "mbtempest - A mesh generation and remapping tool" );
268 
269  // Mesh generation options
270  opts.addOpt< int >( "type,t",
271  "Type of mesh (default=CS; Choose from [CS=0, RLL=1, ICO=2, OVERLAP_FILES=3, "
272  "OVERLAP_MEMORY=4, OVERLAP_MOAB=5])",
273  &imeshType );
274 
275  opts.addOpt< int >( "res,r", "Resolution of the mesh (default=5)", &blockSize );
276 
277  opts.addOpt< void >( "dual,d", "Output the dual of the mesh (relevant only for ICO mesh type)", &computeDual );
278 
279  opts.addOpt< std::string >( "file,f", "Output computed mesh or remapping weights to specified filename",
280  &outFilename );
281 
282  // Input/Output options
283  opts.addOpt< std::string >(
284  "load,l", "Input mesh filenames for source and target meshes. (relevant only when computing weights)",
285  &expectedFName );
286 
287  opts.addOpt< void >( "advfront,a",
288  "Use the advancing front intersection instead of the Kd-tree based algorithm to compute "
289  "mesh intersections.",
290  &kdtreeSearch );
291 
292  opts.addOpt< std::string >( "intx,i", "Output TempestRemap intersection mesh filename", &intxFilename );
293 
294  opts.addOpt< void >(
295  "weights,w",
296  "Compute and output the weights using the overlap mesh (generally relevant only for OVERLAP mesh)",
297  &computeWeights );
298 
299  // Discretization options
300  opts.addOpt< void >(
301  "verbose,v", "Print verbose diagnostic messages during intersection and map computation (default=false)",
303 
304  opts.addOpt< std::string >( "method,m", "Discretization method for the source and target solution fields",
305  &expectedMethod );
306 
307  opts.addOpt< int >( "order,o", "Discretization orders for the source and target solution fields",
308  &expectedOrder );
309 
310  opts.addOpt< std::string >( "global_id,g",
311  "Tag name that contains the global DoF IDs for source and target solution fields",
312  &expectedDofTagName );
313 
314  // Advanced options
315  opts.addOpt< std::string >( "fvmethod",
316  "Sub-type method for FV-FV projections (invdist, delaunay, bilin, intbilin, "
317  "intbilingb, none. Default: none)",
318  &expectedFVMethod );
319 
320  opts.addOpt< void >(
321  "noconserve", "Do not apply conservation to the resultant weights (relevant only when computing weights)",
322  &mapOptions.fNoConservation );
323 
324  opts.addOpt< void >(
325  "volumetric", "Apply a volumetric projection to compute the weights (relevant only when computing weights)",
326  &fVolumetric );
327 
328  opts.addOpt< void >( "skip_intersection", "Skip mesh intersection computation.", &skip_intersection );
329 
330  opts.addOpt< void >( "skip_output", "For performance studies, skip all I/O operations.", &skip_io );
331 
332  opts.addOpt< void >( "gnomonic", "Use Gnomonic plane projections to compute coverage mesh.",
334 
335  opts.addOpt< void >( "enforce_convexity", "Check convexity of input meshes to compute mesh intersections",
336  &enforceConvexity );
337 
338  opts.addOpt< void >( "nobubble", "Do not use bubble on interior of spectral element nodes",
339  &mapOptions.fNoBubble );
340 
341  opts.addOpt< void >(
342  "sparseconstraints",
343  "Use sparse solver for constraints when we have high-valence (typical with high-res RLL mesh)",
344  &mapOptions.fSparseConstraints );
345 
346  opts.addOpt< void >(
347  "rrmgrids",
348  "At least one of the meshes is a regionally refined grid (relevant to accelerate intersection computation)",
349  &rrmGrids );
350 
351  opts.addOpt< void >( "checkmap", "Check the generated map for conservation and consistency", &fCheck );
352 
353  opts.addOpt< void >( "verify",
354  "Verify the accuracy of the maps by projecting analytical functions from source to target "
355  "grid by applying the maps",
356  &verifyWeights );
357 
358  opts.addOpt< std::string >( "var",
359  "Tag name of the variable to use in the verification study (error metrics for user "
360  "defined variables may not be available)",
361  &variableToVerify );
362 
363  opts.addOpt< int >( "monotonicity", "Ensure monotonicity in the weight generation. Options=[0,1,2,3]",
365 
366  opts.addOpt< int >( "ghost",
367  "Number of ghost layers in coverage mesh (overrides automatic selection: 0 for FV order 1, "
368  "p+1 for FV order p>1)",
369  &nlayer_input );
370 
371  opts.addOpt< double >( "boxeps", "The tolerance for boxes (default=1e-7)", &boxeps );
372 
373  opts.addOpt< int >( "limiter", "Apply nonlinear filter after linear map application", &useCAAS );
374 
375  opts.addOpt< std::string >( "baseline", "Output baseline file", &baselineFile );
376 
377  opts.addOpt< void >( "manual", "Show documentation about usage with examples" );
378 
379  opts.addOpt< void >( "version", "Show version information", &version_info );
380 
381  // Parse command line
382  opts.parseCommandLine( argc, argv );
383 
384  // Handle call for detailed information
385  if( opts.numOptSet( "manual" ) > 0 )
386  {
387  if( this->proc_id == 0 )
388  {
389  this->printHelp( argv[0] );
390  }
391  exit( 0 );
392  }
393 
394  if( version_info )
395  {
396  if( this->proc_id == 0 )
397  {
398  std::cout << "mbtempest is part of the MOAB library version " << std::string( MOAB_PACKAGE_VERSION )
399  << "\n";
400  }
401  exit( 0 );
402  }
403 
404  // Process mesh type
405  switch( imeshType )
406  {
407  case 0:
409  break;
410  case 1:
412  break;
413  case 2:
415  break;
416  case 3:
418  break;
419  case 4:
421  break;
422  case 5:
424  break;
425  default:
427  break;
428  }
429 
430  // Process CAAS type
431  switch( useCAAS )
432  {
433  case 1:
435  break;
436  case 2:
438  break;
439  case 3:
441  break;
442  case 4:
444  break;
445  default:
447  break;
448  }
449 
450  // Process input files if provided
451  if( !expectedFName.empty() )
452  {
453  this->inFilenames = { expectedFName };
454  }
455 
456  // Process discretization options through processMeshOptions to handle both single and multiple values
457  // Set initial defaults that can be overridden by processMeshOptions
458  this->fvMethod = expectedFVMethod;
459  this->disc_orders = { expectedOrder, expectedOrder };
460  this->disc_methods = { expectedMethod, expectedMethod };
461  this->doftag_names = { expectedDofTagName, expectedDofTagName };
462 
463  // Let processMeshOptions handle all the discretization option processing
464  this->processMeshOptions( opts );
465 
466  // Now use the processed values for map configuration
467  this->mapOptions.nPin = this->disc_orders[0];
468  this->mapOptions.nPout = this->disc_orders[1];
469  this->mapOptions.fSourceConcave = false;
470  this->mapOptions.fTargetConcave = false;
471  this->mapOptions.strMethod = "";
472 
473  // Configure map options with the processed values - this handles all remaining setup
474  this->configureMapOptions( nlayer_input );
475 
476  // Print runtime parameters
477  this->printRuntimeParameters();
478 
479  return moab::MB_SUCCESS;
480  }

References ProgOptions::addOpt(), baselineFile, blockSize, boxeps, moab::TempestOnlineMap::CAAS_GLOBAL, moab::TempestOnlineMap::CAAS_LOCAL, moab::TempestOnlineMap::CAAS_LOCAL_ADJACENT, moab::TempestOnlineMap::CAAS_NONE, moab::TempestOnlineMap::CAAS_QLT, cassType, computeDual, computeWeights, configureMapOptions(), moab::TempestRemapper::CS, moab::TempestRemapper::DEFAULT, enforceConvexity, ensureMonotonicity, fCheck, fvMethod, fVolumetric, moab::TempestRemapper::ICO, intxFilename, kdtreeSearch, mapOptions, MB_SUCCESS, meshType, MOAB_PACKAGE_VERSION, ProgOptions::numOptSet(), outFilename, moab::TempestRemapper::OVERLAP_FILES, moab::TempestRemapper::OVERLAP_MEMORY, moab::TempestRemapper::OVERLAP_MOAB, ProgOptions::parseCommandLine(), print_diagnostics, printHelp(), printRuntimeParameters(), proc_id, processMeshOptions(), moab::TempestRemapper::RLL, rrmGrids, skip_intersection, skip_io, useGnomonicProjection, variableToVerify, and verifyWeights.

Referenced by main().

◆ printHelp()

void ToolContext::printHelp ( const char *  progName) const
inlineprivate

Print detailed help message with usage examples.

Parameters
progNameProgram name

Definition at line 590 of file mbtempest.cpp.

591  {
592  if( this->proc_id != 0 ) return;
593 
594  std::cout << "MOAB-Tempest: A mesh generation and remapping tool\n"
595  << "==================================================\n\n"
596  << "Usage: " << progName << " [OPTIONS]\n\n"
597  << "Mesh Generation Options:\n"
598  << " -t, --type TYPE Type of mesh to generate (required for mesh generation):\n"
599  << " 0 = Cubed-Sphere (CS)\n"
600  << " 1 = Regular Latitude-Longitude (RLL)\n"
601  << " 2 = Icosahedral (ICO)\n"
602  << " 3 = TempestRemap overlap (thin interface))\n"
603  << " 4 = MOAB with TempestRemap overlap in memory\n"
604  << " 5 = Parallel handling of Overlap meshes with MOAB (recommended)\n\n"
605  << " -r, --res N Resolution (number of elements on edge, default: 10)\n"
606  << " -f, --file FILE Output filename (default: output.h5m)\n\n"
607  << "Discretization Options:\n"
608  << " -m, --method METHOD Discretization method (default: fv):\n"
609  << " fv = Finite Volume\n"
610  << " cgll = Continuous Galerkin with Legendre-Gauss-Lobatto\n"
611  << " dgll = Discontinuous Galerkin with Legendre-Gauss-Lobatto\n\n"
612  << " -o, --order N Discretization order (default: 1, range: 1-4)\n\n"
613  << "Remapping Options:\n"
614  << " --mono N Monotonicity constraints (default: 0):\n"
615  << " 0 = No monotonicity\n"
616  << " 1 = Basic monotonicity\n"
617  << " 2 = Full monotonicity with bounds\n"
618  << " 3 = Strict monotonicity\n\n"
619  << " --limiter TYPE Nonlinear limiting (optional):\n"
620  << " none = No limiting (default)\n"
621  << " global = Global CAAS limiting\n"
622  << " local = Localized CAAS limiting\n"
623  << " qlt = Quasi-Local Tree-based limiting\n\n"
624  << "Input/Output Options:\n"
625  << " -l, --load FILE Load input mesh file (use twice for source and target)\n"
626  << " -i, --global_id TAG Global ID tag name (default: GLOBAL_ID)\n"
627  << " --diagnostics Print diagnostic information\n\n"
628  << "Miscellaneous Options:\n"
629  << " --manual Show this help message and exit\n"
630  << " --version Show version information\n\n"
631  << "Examples:\n"
632  << " # Generate a cubed-sphere mesh with resolution 25\n"
633  << " " << progName << " --type 0 --res 25 -f cs_mesh.h5m\n\n"
634  << " # Generate a latitude-longitude mesh with resolution 180\n"
635  << " " << progName << " --type 1 --res 180 -f rll_mesh.h5m\n\n"
636  << " # Create a map between two meshes with order 4\n"
637  << " " << progName << " --type 5 --load source_mesh.h5m --load target_mesh.h5m \\\n"
638  << " --method cgll --order 4 --global_id GLOBAL_DOFS \\\n"
639  << " --method fv --order 1 --limiter 1 --file map.nc\n";
640  }

Referenced by ParseCLOptions().

◆ printRuntimeParameters()

void ToolContext::printRuntimeParameters ( ) const
inlineprivate

Print all runtime parameters in a formatted way.

Definition at line 768 of file mbtempest.cpp.

769  {
770  if( this->proc_id != 0 ) return;
771 
772  constexpr int width = 60;
773 
774  std::cout << std::string( width, '=' ) << "\n";
775  std::cout << " MOAB-TempestRemap Runtime Configuration " << "\n";
776  std::cout << std::string( width, '=' );
777 
778  // Input files
780  {
781  if( !this->inFilenames.empty() )
782  {
783  std::cout << "\n\nInput Files:";
784  std::cout << "\n Source mesh: " << this->inFilenames[0];
785  std::cout << "\n Target mesh: " << this->inFilenames[1];
786  }
787 
788  std::cout << "\n\nOutput Files:";
789  if( !skip_intersection )
790  std::cout << "\n Intersection mesh: "
791  << ( this->computeWeights ? this->intxFilename : this->outFilename );
792  if( computeWeights ) std::cout << "\n Remap weights: " << this->outFilename;
793  }
794 
795  // Mesh configuration
796  std::cout << "\n\nMesh Configuration:";
797  std::cout << "\n Mesh type: " << this->getMeshTypeName();
798  if( this->meshType <= moab::TempestRemapper::ICO )
799  std::cout << "\n Resolution: " << this->blockSize;
801  std::cout << "\n Compute dual: " << ( this->computeDual ? "Yes" : "No" );
802 
803  if( computeWeights )
804  {
805  std::cout << "\n Gnomonic projection: " << ( this->useGnomonicProjection ? "Yes" : "No" );
806  std::cout << "\n Intersection algorithm: " << ( this->kdtreeSearch ? "KdTree search" : "Advancing front" );
807 
808  // Discretization settings
809  std::cout << "\n\nDiscretization:";
810  std::cout << "\n Source: " << this->disc_methods[0] << " (order " << this->disc_orders[0]
811  << ")";
812  std::cout << "\n Target: " << this->disc_methods[1] << " (order " << this->disc_orders[1]
813  << ")";
814 
815  // Remapping options
816  std::cout << "\n\nRemapping Options:";
817  std::cout << "\n Method: "
818  << ( this->mapOptions.strMethod.empty() ? "Default" : this->mapOptions.strMethod );
819  std::cout << "\n Monotonicity: " << ( this->ensureMonotonicity ? "Yes" : "No" );
820  std::cout << "\n Volumetric: " << ( this->fVolumetric ? "Yes" : "No" );
821  std::cout << "\n Check consistency: " << ( this->fCheck ? "Yes" : "No" );
822  std::cout << "\n Skip intersection: " << ( this->skip_intersection ? "Yes" : "No" );
823  }
824 
825  // Parallel configuration
826  std::cout << "\n\nParallel Configuration:";
827  std::cout << "\n MPI Processes: " << this->n_procs;
828  if( this->meshType > moab::TempestRemapper::ICO ) std::cout << "\n Number of Ghost Layers: " << this->nlayers;
829 
830  std::cout << "\n\n" << std::string( width, '=' ) << "\n\n";
831  }

References blockSize, computeDual, computeWeights, ensureMonotonicity, fCheck, fVolumetric, getMeshTypeName(), moab::TempestRemapper::ICO, intxFilename, kdtreeSearch, meshType, n_procs, nlayers, outFilename, moab::TempestRemapper::OVERLAP_MOAB, skip_intersection, and useGnomonicProjection.

Referenced by ParseCLOptions().

◆ processMeshOptions()

void ToolContext::processMeshOptions ( ProgOptions opts)
inlineprivate

Process mesh options from command line.

Parameters
optsProgram options
expectedFVMethodExpected finite volume method
nlayer_inputNumber of ghost layers

Definition at line 673 of file mbtempest.cpp.

674  {
675  if( this->meshType <= moab::TempestRemapper::ICO ) return;
676 
677  // Process input files
678  std::vector< std::string > inputFiles;
679  opts.getOptAllArgs( "load,l", inputFiles );
680  if( !inputFiles.empty() )
681  {
682  this->inFilenames = inputFiles;
683  if( this->inFilenames.size() != 2 )
684  {
685  throw std::runtime_error( "Exactly two input filenames must be provided with -l/--load" );
686  }
687  }
688 
689  // Process discretization orders
690  std::vector< int > orders;
691  opts.getOptAllArgs( "order,o", orders );
692  if( !orders.empty() )
693  {
694  this->disc_orders = orders;
695  if( this->disc_orders.size() == 1 )
696  {
697  this->disc_orders.push_back( this->disc_orders[0] );
698  }
699  else if( this->disc_orders.size() != 2 )
700  {
701  throw std::runtime_error( "Must specify 1 or 2 values for order (source [target])" );
702  }
703 
704  for( const auto& order : this->disc_orders )
705  {
706  if( order < 1 || order > 4 )
707  {
708  throw std::runtime_error( "Discretization order must be between 1 and 4" );
709  }
710  }
711  }
712 
713  // Process discretization methods
714  std::vector< std::string > methods;
715  opts.getOptAllArgs( "method,m", methods );
716  if( !methods.empty() )
717  {
718  this->disc_methods = methods;
719  if( this->disc_methods.size() == 1 )
720  {
721  // Use same method for both source and target
722  this->disc_methods.push_back( this->disc_methods[0] );
723  }
724  else if( this->disc_methods.size() != 2 )
725  {
726  throw std::runtime_error( "Must specify 1 or 2 values for method (source [target])" );
727  }
728 
729  // Validate method values
730  for( const auto& method : this->disc_methods )
731  {
732  if( method != "fv" && method != "cgll" && method != "dgll" && method != "pcloud" )
733  {
734  throw std::runtime_error( "Invalid method '" + method + "'. Must be one of: fv, cgll, dgll" );
735  }
736  }
737  }
738 
739  // Process DOF tag names
740  std::vector< std::string > tags;
741  opts.getOptAllArgs( "global_id,i", tags );
742  if( !tags.empty() )
743  {
744  this->doftag_names = tags;
745  if( this->doftag_names.size() == 1 )
746  {
747  // Use same tag name for both source and target
748  this->doftag_names.push_back( this->doftag_names[0] );
749  }
750  else if( this->doftag_names.size() != 2 )
751  {
752  throw std::runtime_error( "Must specify 1 or 2 values for DOF tag names (source [target])" );
753  }
754  }
755 
756  // Process output filename if specified
757  std::string outFile;
758  if( opts.getOpt( "file,f", &outFile ) )
759  {
760  this->outFilename = outFile;
761  }
762  // Note: configureMapOptions is now called from ParseCLOptions after processMeshOptions completes
763  }

References ProgOptions::getOpt(), ProgOptions::getOptAllArgs(), moab::TempestRemapper::ICO, meshType, and outFilename.

Referenced by ParseCLOptions().

◆ timer_pop()

void ToolContext::timer_pop ( )
inline

Stop timing and log the operation duration.

Definition at line 215 of file mbtempest.cpp.

216  {
217  double locElapsed = timer->time_since_birth() - timer_ops;
218  double avgElapsed = locElapsed;
219  double maxElapsed = locElapsed;
220 
221 #ifdef MOAB_HAVE_MPI
222  MPI_Reduce( &locElapsed, &maxElapsed, 1, MPI_DOUBLE, MPI_MAX, 0, pcomm->comm() );
223  MPI_Reduce( &locElapsed, &avgElapsed, 1, MPI_DOUBLE, MPI_SUM, 0, pcomm->comm() );
224  avgElapsed /= n_procs;
225 #endif
226 
227  if( proc_id == 0 )
228  {
229  std::cout << "[LOG] Time taken to " << opName << ": max = " << maxElapsed << ", avg = " << avgElapsed
230  << "\n";
231  }
232  opName.clear();
233  }

References moab::ParallelComm::comm(), n_procs, opName, proc_id, timer, and timer_ops.

Referenced by anonymous_namespace{mbtempest.cpp}::convertAndWriteMOABMesh(), anonymous_namespace{mbtempest.cpp}::handleCSMesh(), anonymous_namespace{mbtempest.cpp}::handleICOMesh(), anonymous_namespace{mbtempest.cpp}::handleOverlapFiles(), anonymous_namespace{mbtempest.cpp}::handleRLLMesh(), and main().

◆ timer_push()

void ToolContext::timer_push ( const std::string &  operation)
inline

Start timing an operation.

Parameters
operationName of the operation being timed

Definition at line 206 of file mbtempest.cpp.

207  {
208  timer_ops = timer->time_since_birth();
209  opName = operation;
210  }

References opName, timer, and timer_ops.

Referenced by anonymous_namespace{mbtempest.cpp}::convertAndWriteMOABMesh(), anonymous_namespace{mbtempest.cpp}::handleCSMesh(), anonymous_namespace{mbtempest.cpp}::handleICOMesh(), anonymous_namespace{mbtempest.cpp}::handleOverlapFiles(), anonymous_namespace{mbtempest.cpp}::handleRLLMesh(), and main().

Member Data Documentation

◆ baselineFile

std::string ToolContext::baselineFile

Baseline file for verification (optional)

Definition at line 115 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ blockSize

◆ boxeps

double ToolContext::boxeps { 1e-7 }

Epsilon for bounding box checks.

Definition at line 131 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ cassType

moab::TempestOnlineMap::CAASType ToolContext::cassType
Initial value:

Conservative and accurate advection scheme type.

Definition at line 121 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ computeDual

bool ToolContext::computeDual { false }

Compute dual mesh.

Definition at line 136 of file mbtempest.cpp.

Referenced by anonymous_namespace{mbtempest.cpp}::handleICOMesh(), ParseCLOptions(), and printRuntimeParameters().

◆ computeWeights

bool ToolContext::computeWeights { false }

Compute interpolation weights.

Definition at line 137 of file mbtempest.cpp.

Referenced by anonymous_namespace{mbtempest.cpp}::handleOverlapMOAB(), main(), ParseCLOptions(), and printRuntimeParameters().

◆ disc_methods

std::vector< std::string > ToolContext::disc_methods

Discretization methods (fv, cgll, dgll) for source and target.

Definition at line 111 of file mbtempest.cpp.

Referenced by anonymous_namespace{mbtempest.cpp}::handleOverlapMOAB(), main(), and ToolContext().

◆ disc_orders

std::vector< int > ToolContext::disc_orders

Discretization orders for source and target.

Definition at line 110 of file mbtempest.cpp.

Referenced by main(), and ToolContext().

◆ doftag_names

std::vector< std::string > ToolContext::doftag_names

Degree of freedom tag names for source and target.

Definition at line 112 of file mbtempest.cpp.

Referenced by main(), and ToolContext().

◆ enforceConvexity

bool ToolContext::enforceConvexity { false }

Enforce convexity in mesh elements.

Definition at line 140 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ ensureMonotonicity

int ToolContext::ensureMonotonicity { 0 }

Monotonicity enforcement level (0=none, 1=basic, 2=full, 3=strict)

Definition at line 123 of file mbtempest.cpp.

Referenced by configureMapOptions(), main(), ParseCLOptions(), and printRuntimeParameters().

◆ epsrel

double ToolContext::epsrel { ReferenceTolerance }

Relative tolerance for convergence.

Definition at line 132 of file mbtempest.cpp.

Referenced by main().

◆ fCheck

bool ToolContext::fCheck { false }

Enable additional checking during remapping.

Definition at line 126 of file mbtempest.cpp.

Referenced by configureMapOptions(), main(), ParseCLOptions(), and printRuntimeParameters().

◆ fvMethod

std::string ToolContext::fvMethod { "none" }

Finite volume method specification.

Definition at line 117 of file mbtempest.cpp.

Referenced by configureMapOptions(), and ParseCLOptions().

◆ fVolumetric

bool ToolContext::fVolumetric { false }

Enable volumetric (3D) remapping.

Definition at line 127 of file mbtempest.cpp.

Referenced by configureMapOptions(), ParseCLOptions(), and printRuntimeParameters().

◆ inFilenames

std::vector< std::string > ToolContext::inFilenames

◆ intxFilename

std::string ToolContext::intxFilename

Intersection mesh filename (optional)

Definition at line 114 of file mbtempest.cpp.

Referenced by main(), ParseCLOptions(), and printRuntimeParameters().

◆ kdtreeSearch

bool ToolContext::kdtreeSearch { true }

Enable KD-tree for spatial searches.

Definition at line 125 of file mbtempest.cpp.

Referenced by main(), ParseCLOptions(), and printRuntimeParameters().

◆ mapOptions

GenerateOfflineMapAlgorithmOptions ToolContext::mapOptions

Configuration for offline map generation.

Definition at line 120 of file mbtempest.cpp.

Referenced by main(), ParseCLOptions(), and ToolContext().

◆ mbcore

moab::Core* const ToolContext::mbcore

MOAB Core instance for mesh operations.

Definition at line 99 of file mbtempest.cpp.

Referenced by anonymous_namespace{mbtempest.cpp}::convertAndWriteMOABMesh(), and anonymous_namespace{mbtempest.cpp}::handleOverlapMOAB().

◆ meshes

◆ meshsets

std::vector< moab::EntityHandle > ToolContext::meshsets

◆ meshType

◆ n_procs

const int ToolContext::n_procs

Total number of MPI processes (1 for serial)

Definition at line 104 of file mbtempest.cpp.

Referenced by get_file_read_options(), anonymous_namespace{mbtempest.cpp}::handleOverlapMOAB(), printRuntimeParameters(), and timer_pop().

◆ nlayers

int ToolContext::nlayers { 0 }

Number of ghost layers for parallel operations.

Definition at line 146 of file mbtempest.cpp.

Referenced by configureMapOptions(), main(), and printRuntimeParameters().

◆ opName

std::string ToolContext::opName

Name of current operation being timed.

Definition at line 145 of file mbtempest.cpp.

Referenced by timer_pop(), and timer_push().

◆ outFilename

◆ outputFormatter

moab::DebugOutput ToolContext::outputFormatter

Formatter for debug output.

Definition at line 105 of file mbtempest.cpp.

Referenced by anonymous_namespace{mbtempest.cpp}::convertAndWriteMOABMesh(), CreateTempestMesh(), main(), and ToolContext().

◆ print_diagnostics

bool ToolContext::print_diagnostics { false }

Print detailed diagnostic information.

Definition at line 129 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ proc_id

◆ rrmGrids

bool ToolContext::rrmGrids { false }

Flag to use RRM (Regional Refinement Meshes)

Definition at line 124 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ skip_intersection

bool ToolContext::skip_intersection { false }

Skip intersection computation (for debugging)

Definition at line 130 of file mbtempest.cpp.

Referenced by configureMapOptions(), main(), ParseCLOptions(), and printRuntimeParameters().

◆ skip_io

bool ToolContext::skip_io { false }

Skip file I/O operations (for testing)

Definition at line 135 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ timer

std::unique_ptr< moab::CpuTimer > ToolContext::timer

Timer for performance measurement.

Definition at line 143 of file mbtempest.cpp.

Referenced by timer_pop(), timer_push(), and ToolContext().

◆ timer_ops

double ToolContext::timer_ops { 0.0 }

Operation timer value.

Definition at line 144 of file mbtempest.cpp.

Referenced by timer_pop(), and timer_push().

◆ useGnomonicProjection

bool ToolContext::useGnomonicProjection { false }

Use gnomonic projection for certain operations.

Definition at line 128 of file mbtempest.cpp.

Referenced by main(), ParseCLOptions(), and printRuntimeParameters().

◆ variableToVerify

std::string ToolContext::variableToVerify

Variable name for verification (optional)

Definition at line 116 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ verifyConservation

bool ToolContext::verifyConservation { false }

Verify conservation properties.

Definition at line 138 of file mbtempest.cpp.

◆ verifyWeights

bool ToolContext::verifyWeights { false }

Verify interpolation weights.

Definition at line 139 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().


The documentation for this class was generated from the following file: