Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ToolContext Struct Reference
+ Collaboration diagram for ToolContext:

Public Member Functions

 ToolContext (moab::Core *icore)
 
 ~ToolContext ()
 
void timer_push (std::string operation)
 
void timer_pop ()
 
void ParseCLOptions (int argc, char *argv[])
 

Public Attributes

moab::Corembcore
 
const int proc_id
 
const int n_procs
 
moab::DebugOutput outputFormatter
 
int blockSize
 
int nlayers
 
std::vector< std::string > inFilenames
 
std::vector< Mesh * > meshes
 
std::vector< moab::EntityHandlemeshsets
 
std::vector< int > disc_orders
 
std::vector< std::string > disc_methods
 
std::vector< std::string > doftag_names
 
std::string fvMethod
 
std::string outFilename
 
std::string intxFilename
 
std::string baselineFile
 
std::string variableToVerify
 
moab::TempestRemapper::TempestMeshType meshType
 
bool skip_io
 
bool computeDual
 
bool computeWeights
 
bool verifyWeights
 
bool enforceConvexity
 
int ensureMonotonicity
 
bool rrmGrids
 
bool kdtreeSearch
 
bool fCheck
 
bool fVolumetric
 
bool useGnomonicProjection
 
moab::TempestOnlineMap::CAASType cassType
 
GenerateOfflineMapAlgorithmOptions mapOptions
 
bool print_diagnostics
 
double boxeps
 
double epsrel
 

Private Attributes

moab::CpuTimertimer
 
double timer_ops
 
std::string opName
 

Detailed Description

Definition at line 44 of file mbtempest.cpp.

Constructor & Destructor Documentation

◆ ToolContext()

ToolContext::ToolContext ( moab::Core icore)
inline

Definition at line 89 of file mbtempest.cpp.

90  : mbcore( icore ), proc_id( 0 ), n_procs( 1 ), outputFormatter( std::cout, 0, 0 ),
91 #endif
92  blockSize( 5 ), nlayers( 0 ), fvMethod( "none" ), outFilename( "outputFile.nc" ), intxFilename( "" ),
94  computeDual( false ), computeWeights( false ), verifyWeights( false ), enforceConvexity( false ),
95  ensureMonotonicity( 0 ), rrmGrids( false ), kdtreeSearch( true ), fCheck( false ), fVolumetric( false ),
97  boxeps( 1e-7 ), // Box error tolerance default value
98  epsrel( ReferenceTolerance ) // ReferenceTolerance is defined in Defines.h in TempestRemap
99  {
100  inFilenames.resize( 2 );
101  doftag_names.resize( 2 );
102  timer = new moab::CpuTimer();
103 
104  outputFormatter.set_prefix( "[MBTempest]: " );
105  }

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

◆ ~ToolContext()

ToolContext::~ToolContext ( )
inline

Definition at line 107 of file mbtempest.cpp.

108  {
109  // for (unsigned i=0; i < meshes.size(); ++i) delete meshes[i];
110  meshes.clear();
111  inFilenames.clear();
112  disc_orders.clear();
113  disc_methods.clear();
114  doftag_names.clear();
115  outFilename.clear();
116  intxFilename.clear();
117  baselineFile.clear();
118  variableToVerify.clear();
119  meshsets.clear();
120  delete timer;
121  }

References baselineFile, disc_methods, disc_orders, doftag_names, inFilenames, intxFilename, meshes, meshsets, outFilename, timer, and variableToVerify.

Member Function Documentation

◆ ParseCLOptions()

void ToolContext::ParseCLOptions ( int  argc,
char *  argv[] 
)
inline

Definition at line 150 of file mbtempest.cpp.

151  {
152  ProgOptions opts;
153  int imeshType = 0;
154  std::string expectedFName = "output.exo";
155  std::string expectedMethod = "fv";
156  std::string expectedFVMethod = "none";
157  std::string expectedDofTagName = "GLOBAL_ID";
158  int expectedOrder = 1;
159  int useCAAS = 0;
160  int nlayer_input = 0;
161 
162  if( !proc_id )
163  {
164  std::cout << "Command line options provided to mbtempest:\n ";
165  for( int iarg = 0; iarg < argc; ++iarg )
166  std::cout << argv[iarg] << " ";
167  std::cout << std::endl << std::endl;
168  }
169 
170  opts.addOpt< int >( "type,t",
171  "Type of mesh (default=CS; Choose from [CS=0, RLL=1, ICO=2, OVERLAP_FILES=3, "
172  "OVERLAP_MEMORY=4, OVERLAP_MOAB=5])",
173  &imeshType );
174 
175  opts.addOpt< int >( "res,r", "Resolution of the mesh (default=5)", &blockSize );
176 
177  opts.addOpt< void >( "dual,d", "Output the dual of the mesh (relevant only for ICO mesh type)", &computeDual );
178 
179  opts.addOpt< std::string >( "file,f", "Output computed mesh or remapping weights to specified filename",
180  &outFilename );
181  opts.addOpt< std::string >(
182  "load,l", "Input mesh filenames for source and target meshes. (relevant only when computing weights)",
183  &expectedFName );
184 
185  opts.addOpt< void >( "advfront,a",
186  "Use the advancing front intersection instead of the Kd-tree based algorithm "
187  "to compute mesh intersections. (relevant only when computing weights)" );
188 
189  opts.addOpt< std::string >( "intx,i", "Output TempestRemap intersection mesh filename", &intxFilename );
190 
191  opts.addOpt< void >( "weights,w",
192  "Compute and output the weights using the overlap mesh (generally "
193  "relevant only for OVERLAP mesh)",
194  &computeWeights );
195 
196  opts.addOpt< void >( "verbose,v",
197  "Print verbose diagnostic messages during intersection and map computation (default=false)",
199 
200  opts.addOpt< std::string >( "method,m", "Discretization method for the source and target solution fields",
201  &expectedMethod );
202 
203  opts.addOpt< int >( "order,o", "Discretization orders for the source and target solution fields",
204  &expectedOrder );
205 
206  opts.addOpt< std::string >( "global_id,g",
207  "Tag name that contains the global DoF IDs for source and target solution fields",
208  &expectedDofTagName );
209 
210  opts.addOpt< std::string >( "fvmethod",
211  "Sub-type method for FV-FV projections (invdist, delaunay, bilin, "
212  "intbilin, intbilingb, none. Default: none)",
213  &expectedFVMethod );
214 
215  opts.addOpt< void >( "noconserve",
216  "Do not apply conservation to the resultant weights (relevant only "
217  "when computing weights)",
218  &mapOptions.fNoConservation );
219 
220  opts.addOpt< void >( "volumetric",
221  "Apply a volumetric projection to compute the weights (relevant only "
222  "when computing weights)",
223  &fVolumetric );
224 
225  opts.addOpt< void >( "skip_output", "For performance studies, skip all I/O operations.", &skip_io );
226 
227  opts.addOpt< void >( "gnomonic", "Use Gnomonic plane projections to compute coverage mesh.",
229 
230  opts.addOpt< void >( "enforce_convexity", "check convexity of input meshes to compute mesh intersections",
231  &enforceConvexity );
232 
233  opts.addOpt< void >( "nobubble", "do not use bubble on interior of spectral element nodes",
234  &mapOptions.fNoBubble );
235 
236  opts.addOpt< void >(
237  "sparseconstraints",
238  "Use sparse solver for constraints when we have high-valence (typical with high-res RLL mesh)",
239  &mapOptions.fSparseConstraints );
240 
241  opts.addOpt< void >( "rrmgrids",
242  "At least one of the meshes is a regionally refined grid (relevant to "
243  "accelerate intersection computation)",
244  &rrmGrids );
245 
246  opts.addOpt< void >( "checkmap", "Check the generated map for conservation and consistency", &fCheck );
247 
248  opts.addOpt< void >( "verify",
249  "Verify the accuracy of the maps by projecting analytical functions "
250  "from source to target "
251  "grid by applying the maps",
252  &verifyWeights );
253 
254  opts.addOpt< std::string >( "var",
255  "Tag name of the variable to use in the verification study "
256  "(error metrics for user defined variables may not be available)",
257  &variableToVerify );
258 
259  opts.addOpt< int >( "monotonicity", "Ensure monotonicity in the weight generation. Options=[0,1,2,3]",
261 
262  opts.addOpt< int >( "ghost", "Number of ghost layers in coverage mesh (default=1)", &nlayer_input );
263 
264  opts.addOpt< double >( "boxeps", "The tolerance for boxes (default=1e-7)", &boxeps );
265 
266  opts.addOpt< int >( "caas", "apply CAAS nonlinear filter after linear map application", &useCAAS );
267 
268  opts.addOpt< std::string >( "baseline", "Output baseline file", &baselineFile );
269 
270  opts.parseCommandLine( argc, argv );
271 
272  // By default - use Kd-tree based search; if user asks for advancing front, disable Kd-tree
273  // algorithm
274  kdtreeSearch = opts.numOptSet( "advfront,a" ) == 0;
275 
276  switch( imeshType )
277  {
278  case 0:
280  break;
281 
282  case 1:
284  break;
285 
286  case 2:
288  break;
289 
290  case 3:
292  break;
293 
294  case 4:
296  break;
297 
298  case 5:
300  break;
301 
302  default:
304  break;
305  }
306 
307  // decipher whether we want to use CAAS filter when applying the projection
308  switch( useCAAS )
309  {
312  break;
315  break;
318  break;
321  break;
322  default:
324  break;
325  }
326 
327  if( meshType > moab::TempestRemapper::ICO ) // compute overlap mesh and maps possibly
328  {
329  opts.getOptAllArgs( "load,l", inFilenames );
330  opts.getOptAllArgs( "order,o", disc_orders );
331  opts.getOptAllArgs( "method,m", disc_methods );
332  opts.getOptAllArgs( "global_id,i", doftag_names );
333 
334  assert( inFilenames.size() == 2 );
335  assert( ensureMonotonicity >= 0 && ensureMonotonicity <= 3 );
336 
337  // get discretization order parameters
338  if( disc_orders.size() == 0 ) disc_orders.resize( 2, 1 );
339  if( disc_orders.size() == 1 ) disc_orders.push_back( disc_orders[0] );
340 
341  // get discretization method parameters
342  if( disc_methods.size() == 0 ) disc_methods.resize( 2, "fv" );
343  if( disc_methods.size() == 1 ) disc_methods.push_back( disc_methods[0] );
344 
345  // get DoF tagname parameters
346  if( doftag_names.size() == 0 ) doftag_names.resize( 2, "GLOBAL_ID" );
347  if( doftag_names.size() == 1 ) doftag_names.push_back( doftag_names[0] );
348 
349  assert( disc_orders.size() == 2 );
350  assert( disc_methods.size() == 2 );
351  assert( doftag_names.size() == 2 );
352 
353  // for computing maps and overlaps, set discretization orders
354  mapOptions.nPin = disc_orders[0];
355  mapOptions.nPout = disc_orders[1];
356  mapOptions.fSourceConcave = false;
357  mapOptions.fTargetConcave = false;
358 
359  mapOptions.strMethod = "";
360 
361  if( expectedFVMethod != "none" )
362  {
363  mapOptions.strMethod += expectedFVMethod + ";";
364  fvMethod = expectedFVMethod;
365 
366  // These FV projection methods are non-conservative; specify it explicitly
367  mapOptions.fNoConservation = true;
368  }
369  switch( ensureMonotonicity )
370  {
371  case 0:
372  mapOptions.fMonotone = false;
373  break;
374  case 3:
375  mapOptions.strMethod += "mono3;";
376  break;
377  case 2:
378  mapOptions.strMethod += "mono2;";
379  break;
380  default:
381  mapOptions.fMonotone = true;
382  }
383  mapOptions.fNoCorrectAreas = false;
384  mapOptions.fNoCheck = !fCheck;
385 
386  //assert( fVolumetric && fInverseDistanceMap == false ); // both options cannot be active
387  if( fVolumetric ) mapOptions.strMethod += "volumetric;";
388 
389  // For global meshes, this default should work out of the box.
390  if( !fvMethod.compare( "bilin" ) ) nlayers = 3;
391  else
392  nlayers = ( mapOptions.nPin > 1 ? mapOptions.nPin + 1 : 0 );
393  if ( nlayer_input )
394  nlayers = std::max( nlayer_input, nlayers );
395  }
396 
397  // clear temporary string name
398  expectedFName.clear();
399 
400  mapOptions.strOutputMapFile = outFilename;
401  mapOptions.strOutputFormat = "Netcdf4";
402  }

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, moab::TempestRemapper::CS, moab::TempestRemapper::DEFAULT, disc_methods, disc_orders, doftag_names, enforceConvexity, ensureMonotonicity, fCheck, fvMethod, fVolumetric, ProgOptions::getOptAllArgs(), moab::TempestRemapper::ICO, inFilenames, intxFilename, kdtreeSearch, mapOptions, meshType, nlayers, ProgOptions::numOptSet(), outFilename, moab::TempestRemapper::OVERLAP_FILES, moab::TempestRemapper::OVERLAP_MEMORY, moab::TempestRemapper::OVERLAP_MOAB, ProgOptions::parseCommandLine(), print_diagnostics, proc_id, moab::TempestRemapper::RLL, rrmGrids, skip_io, useGnomonicProjection, variableToVerify, and verifyWeights.

Referenced by main().

◆ timer_pop()

void ToolContext::timer_pop ( )
inline

Definition at line 129 of file mbtempest.cpp.

130  {
131  double locElapsed = timer->time_since_birth() - timer_ops, avgElapsed = 0, maxElapsed = 0;
132 #ifdef MOAB_HAVE_MPI
133  MPI_Reduce( &locElapsed, &maxElapsed, 1, MPI_DOUBLE, MPI_MAX, 0, pcomm->comm() );
134  MPI_Reduce( &locElapsed, &avgElapsed, 1, MPI_DOUBLE, MPI_SUM, 0, pcomm->comm() );
135 #else
136  maxElapsed = locElapsed;
137  avgElapsed = locElapsed;
138 #endif
139  if( !proc_id )
140  {
141  avgElapsed /= n_procs;
142  std::cout << "[LOG] Time taken to " << opName.c_str() << ": max = " << maxElapsed
143  << ", avg = " << avgElapsed << "\n";
144  }
145  // std::cout << "\n[LOG" << proc_id << "] Time taken to " << opName << " = " <<
146  // timer->time_since_birth() - timer_ops << std::endl;
147  opName.clear();
148  }

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

Referenced by CreateTempestMesh(), and main().

◆ timer_push()

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

Definition at line 123 of file mbtempest.cpp.

124  {
126  opName = operation;
127  }

References opName, moab::CpuTimer::time_since_birth(), timer, and timer_ops.

Referenced by CreateTempestMesh(), and main().

Member Data Documentation

◆ baselineFile

std::string ToolContext::baselineFile

Definition at line 63 of file mbtempest.cpp.

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

◆ blockSize

int ToolContext::blockSize

Definition at line 52 of file mbtempest.cpp.

Referenced by CreateTempestMesh(), and ParseCLOptions().

◆ boxeps

double ToolContext::boxeps

Definition at line 81 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ cassType

moab::TempestOnlineMap::CAASType ToolContext::cassType

Definition at line 78 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ computeDual

bool ToolContext::computeDual

Definition at line 68 of file mbtempest.cpp.

Referenced by CreateTempestMesh(), and ParseCLOptions().

◆ computeWeights

bool ToolContext::computeWeights

Definition at line 69 of file mbtempest.cpp.

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

◆ disc_methods

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

Definition at line 58 of file mbtempest.cpp.

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

◆ disc_orders

std::vector< int > ToolContext::disc_orders

Definition at line 57 of file mbtempest.cpp.

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

◆ doftag_names

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

Definition at line 59 of file mbtempest.cpp.

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

◆ enforceConvexity

bool ToolContext::enforceConvexity

Definition at line 71 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ ensureMonotonicity

int ToolContext::ensureMonotonicity

Definition at line 72 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ epsrel

double ToolContext::epsrel

Definition at line 82 of file mbtempest.cpp.

Referenced by main().

◆ fCheck

bool ToolContext::fCheck

Definition at line 75 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ fvMethod

std::string ToolContext::fvMethod

Definition at line 60 of file mbtempest.cpp.

Referenced by ParseCLOptions().

◆ fVolumetric

bool ToolContext::fVolumetric

Definition at line 76 of file mbtempest.cpp.

Referenced by ParseCLOptions().

◆ inFilenames

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

Definition at line 54 of file mbtempest.cpp.

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

◆ intxFilename

std::string ToolContext::intxFilename

Definition at line 62 of file mbtempest.cpp.

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

◆ kdtreeSearch

bool ToolContext::kdtreeSearch

Definition at line 74 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ mapOptions

GenerateOfflineMapAlgorithmOptions ToolContext::mapOptions

Definition at line 79 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ mbcore

moab::Core* ToolContext::mbcore

Definition at line 46 of file mbtempest.cpp.

Referenced by CreateTempestMesh(), and main().

◆ meshes

std::vector< Mesh* > ToolContext::meshes

Definition at line 55 of file mbtempest.cpp.

Referenced by CreateTempestMesh(), main(), and ~ToolContext().

◆ meshsets

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

Definition at line 56 of file mbtempest.cpp.

Referenced by CreateTempestMesh(), main(), and ~ToolContext().

◆ meshType

Definition at line 66 of file mbtempest.cpp.

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

◆ n_procs

const int ToolContext::n_procs

Definition at line 50 of file mbtempest.cpp.

Referenced by CreateTempestMesh(), get_file_read_options(), and timer_pop().

◆ nlayers

int ToolContext::nlayers

Definition at line 53 of file mbtempest.cpp.

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

◆ opName

std::string ToolContext::opName
private

Definition at line 407 of file mbtempest.cpp.

Referenced by timer_pop(), and timer_push().

◆ outFilename

std::string ToolContext::outFilename

Definition at line 61 of file mbtempest.cpp.

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

◆ outputFormatter

moab::DebugOutput ToolContext::outputFormatter

Definition at line 51 of file mbtempest.cpp.

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

◆ print_diagnostics

bool ToolContext::print_diagnostics

Definition at line 80 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ proc_id

const int ToolContext::proc_id

◆ rrmGrids

bool ToolContext::rrmGrids

Definition at line 73 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ skip_io

bool ToolContext::skip_io

Definition at line 67 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ timer

moab::CpuTimer* ToolContext::timer
private

Definition at line 405 of file mbtempest.cpp.

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

◆ timer_ops

double ToolContext::timer_ops
private

Definition at line 406 of file mbtempest.cpp.

Referenced by timer_pop(), and timer_push().

◆ useGnomonicProjection

bool ToolContext::useGnomonicProjection

Definition at line 77 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().

◆ variableToVerify

std::string ToolContext::variableToVerify

Definition at line 64 of file mbtempest.cpp.

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

◆ verifyWeights

bool ToolContext::verifyWeights

Definition at line 70 of file mbtempest.cpp.

Referenced by main(), and ParseCLOptions().


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