Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
Initialization and Finalization

Functions for initializing and finalizing the iMOAB library. More...

+ Collaboration diagram for Initialization and Finalization:

Functions

ErrCode iMOAB_Initialize (int argc, iMOAB_String *argv)
 Initialize iMOAB library and create MOAB instance. More...
 
ErrCode iMOAB_InitializeFortran ()
 Fortran-compatible wrapper for iMOAB_Initialize. More...
 
ErrCode iMOAB_Finalize ()
 Finalize iMOAB library and cleanup MOAB instance. More...
 

Detailed Description

Functions for initializing and finalizing the iMOAB library.

Function Documentation

◆ iMOAB_Finalize()

ErrCode iMOAB_Finalize ( void  )

Finalize iMOAB library and cleanup MOAB instance.

Finalize the iMOAB interface implementation.

Decrements reference count and deletes MOAB Core instance when count reaches zero. Safe to call multiple times - must be called once for each Initialize call.

Postcondition
Reference count decremented
MOAB instance deleted when refCountMB reaches 0
All application data should be cleaned up before final Finalize
Warning
Must call iMOAB_DeregisterApplication for all applications before final Finalize
Note
Uses reference counting to support nested Initialize/Finalize pairs
Returns
moab::MB_SUCCESS on success
See also
iMOAB_Initialize()

Definition at line 308 of file iMOAB.cpp.

309 {
310  // Decrement reference count
312 
313  // Delete MOAB instance only when last user finalizes
314  if( 0 == context.refCountMB )
315  {
316  delete context.MBI;
317  }
318 
319  return MB_SUCCESS;
320 }

References context, MB_SUCCESS, GlobalContext::MBI, and GlobalContext::refCountMB.

◆ iMOAB_Initialize()

ErrCode iMOAB_Initialize ( int  argc,
iMOAB_String argv 
)

Initialize iMOAB library and create MOAB instance.

Initialize the iMOAB interface implementation.

Initializes the iMOAB interface by creating a MOAB Core instance and setting up standard tags for material sets, boundary conditions, and global IDs. Uses reference counting to support multiple initialization calls. Detects MPI initialization status if built with MPI support.

Initialization Steps:
  1. Store command-line arguments (argc/argv) for later use
  2. Create MOAB Core instance on first initialization (refCountMB == 0)
  3. Retrieve standard tag handles: MATERIAL_SET, NEUMANN_SET, DIRICHLET_SET, GLOBAL_ID
  4. Store tag handles in global context for efficient access
  5. Detect MPI initialization and store world size/rank if MPI is active
  6. Increment reference count to support nested initialization
Parameters
[in]argcNumber of command-line arguments (can be 0)
[in]argvArray of command-line argument strings (can be NULL if argc is 0)
Precondition
MPI must be initialized before calling if using parallel features
Postcondition
MOAB Core instance created and ready for use
Standard tags available via context.material_tag, context.neumann_tag, etc.
Note
Uses reference counting - safe to call multiple times
Fortran interface should use iMOAB_InitializeFortran() instead
Returns
moab::MB_SUCCESS on success, error code otherwise
See also
iMOAB_Finalize()

Definition at line 224 of file iMOAB.cpp.

225 {
226  if( argc ) IMOAB_CHECKPOINTER( argv, 1 );
227 
228  // Store command-line arguments for potential later use
229  context.iArgc = argc;
230  context.iArgv = argv; // Shallow copy - caller must maintain argv lifetime
231 
232  // Create MOAB instance only on first initialization
233  if( 0 == context.refCountMB )
234  {
235  context.MBI = new( std::nothrow ) moab::Core;
236 
237  // Retrieve standard MOAB tags that are commonly used across applications
238  const char* const shared_set_tag_names[] = { MATERIAL_SET_TAG_NAME, NEUMANN_SET_TAG_NAME,
240  // Tag purposes: materials (blocks), surface-BC (Neumann), vertex-BC (Dirichlet), global-id
241  Tag gtags[4];
242  for( int i = 0; i < 4; i++ )
243  {
244  MB_CHK_ERR(
245  context.MBI->tag_get_handle( shared_set_tag_names[i], 1, MB_TYPE_INTEGER, gtags[i], MB_TAG_ANY ) );
246  }
247 
248  // Cache standard tag handles in global context for efficient repeated access
249  context.material_tag = gtags[0]; // Material/block identification
250  context.neumann_tag = gtags[1]; // Surface boundary conditions
251  context.dirichlet_tag = gtags[2]; // Vertex boundary conditions
252  context.globalID_tag = gtags[3]; // Global entity identification
253 
254  // Check if MPI is initialized and cache world communicator info
255  context.MPI_initialized = false;
256 #ifdef MOAB_HAVE_MPI
257  int flagInit;
258  MPI_Initialized( &flagInit );
259 
260  if( flagInit && !context.MPI_initialized )
261  {
262  MPI_Comm_size( MPI_COMM_WORLD, &context.worldprocs );
263  MPI_Comm_rank( MPI_COMM_WORLD, &context.globalrank );
264  context.MPI_initialized = true;
265  }
266 #endif
267  }
268 
269  // Increment reference count to track active users
271  return moab::MB_SUCCESS;
272 }

References context, DIRICHLET_SET_TAG_NAME, GlobalContext::dirichlet_tag, GLOBAL_ID_TAG_NAME, GlobalContext::globalID_tag, GlobalContext::globalrank, GlobalContext::iArgc, GlobalContext::iArgv, IMOAB_CHECKPOINTER, MATERIAL_SET_TAG_NAME, GlobalContext::material_tag, MB_CHK_ERR, MB_SUCCESS, MB_TAG_ANY, MB_TYPE_INTEGER, GlobalContext::MBI, GlobalContext::MPI_initialized, NEUMANN_SET_TAG_NAME, GlobalContext::neumann_tag, GlobalContext::refCountMB, moab::Interface::tag_get_handle(), and GlobalContext::worldprocs.

Referenced by iMOAB_InitializeFortran().

◆ iMOAB_InitializeFortran()

ErrCode iMOAB_InitializeFortran ( void  )

Fortran-compatible wrapper for iMOAB_Initialize.

Initialize the iMOAB interface implementation from Fortran driver.

Calls iMOAB_Initialize with zero arguments, suitable for Fortran applications that don't pass command-line arguments through the interface.

Returns
moab::MB_SUCCESS on success, error code otherwise
See also
iMOAB_Initialize()

Definition at line 285 of file iMOAB.cpp.

286 {
287  return iMOAB_Initialize( 0, 0 );
288 }

References iMOAB_Initialize().