Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
anonymous_namespace{mbtempest.cpp} Namespace Reference

Sample functions for testing remapping operations. More...

Functions

moab::ErrorCode handleOverlapMemory (ToolContext &ctx, moab::TempestRemapper &remapper, Mesh *tempest_mesh)
 
moab::ErrorCode handleOverlapMOAB (ToolContext &ctx, moab::TempestRemapper &remapper)
 
moab::ErrorCode handleOverlapFiles (ToolContext &ctx, Mesh *tempest_mesh)
 
moab::ErrorCode convertAndWriteMOABMesh (ToolContext &ctx, moab::TempestRemapper &remapper, Mesh *tempest_mesh)
 Convert a generated TempestRemap mesh to MOAB format and write as h5m file. More...
 
moab::ErrorCode handleICOMesh (ToolContext &ctx, moab::TempestRemapper &remapper, Mesh *tempest_mesh)
 
moab::ErrorCode handleRLLMesh (ToolContext &ctx, moab::TempestRemapper &remapper, Mesh *tempest_mesh)
 
moab::ErrorCode handleCSMesh (ToolContext &ctx, moab::TempestRemapper &remapper, Mesh *tempest_mesh)
 

Variables

constexpr double VORTEX_LON0 = 0.0
 
constexpr double VORTEX_LAT0 = 0.6
 
constexpr double VORTEX_R0 = 3.0
 
constexpr double VORTEX_D = 5.0
 
constexpr double VORTEX_T = 6.0
 

Detailed Description

Sample functions for testing remapping operations.

These functions provide analytical test cases with different spatial patterns for verifying remapping accuracy and performance.

Function Documentation

◆ convertAndWriteMOABMesh()

moab::ErrorCode anonymous_namespace{mbtempest.cpp}::convertAndWriteMOABMesh ( ToolContext ctx,
moab::TempestRemapper remapper,
Mesh *  tempest_mesh 
)

Convert a generated TempestRemap mesh to MOAB format and write as h5m file.

When the output filename has a .h5m extension, the mesh is converted from TempestRemap format to MOAB format in memory and written as a native MOAB HDF5 file. This allows the generated meshes to be loaded by mbtempest type 5 (OVERLAP_MOAB) workflows. The TempestRemap format file is still written (with .g extension) for compatibility.

Definition at line 1775 of file mbtempest.cpp.

1776 {
1777  // Check if output filename has .h5m extension
1778  const std::string& outFile = ctx.outFilename;
1779  const size_t dot = outFile.find_last_of( "." );
1780  if( dot == std::string::npos ) return moab::MB_SUCCESS;
1781 
1782  const std::string ext = outFile.substr( dot + 1 );
1783  if( ext != "h5m" ) return moab::MB_SUCCESS;
1784 
1785  // Register the TempestRemap mesh with the remapper as SourceMesh
1786  remapper.SetMesh( moab::Remapper::SourceMesh, tempest_mesh, false );
1787 
1788  // Convert TempestRemap mesh to MOAB format
1789  ctx.timer_push( "convert TempestRemap mesh to MOAB format" );
1791  "Failed to convert TempestRemap mesh to MOAB format" );
1792  ctx.timer_pop();
1793 
1794  // Fix degenerate quads: RLL meshes from TempestRemap have polar cells stored as
1795  // 4-node quads with duplicate vertices. Convert these to proper triangles so the
1796  // intersection algorithm can handle them correctly.
1799  "Failed to fix degenerate quads in converted mesh" );
1800  ctx.timer_push( "write MOAB mesh to h5m file" );
1801  MB_CHK_SET_ERR( ctx.mbcore->write_file( outFile.c_str(), nullptr, nullptr, &meshSet, 1 ),
1802  "Failed to write MOAB mesh to h5m file" );
1803  ctx.timer_pop();
1804 
1805  if( !ctx.proc_id )
1806  ctx.outputFormatter.printf( 0, "Wrote MOAB mesh to %s\n", outFile.c_str() );
1807 
1808  return moab::MB_SUCCESS;
1809 }

References moab::TempestRemapper::ConvertTempestMesh(), moab::dot(), moab::IntxUtils::fix_degenerate_quads(), moab::TempestRemapper::GetMeshSet(), MB_CHK_SET_ERR, MB_SUCCESS, ToolContext::mbcore, ToolContext::outFilename, ToolContext::outputFormatter, moab::DebugOutput::printf(), ToolContext::proc_id, moab::TempestRemapper::SetMesh(), moab::Remapper::SourceMesh, ToolContext::timer_pop(), ToolContext::timer_push(), and moab::Core::write_file().

Referenced by handleCSMesh(), handleICOMesh(), and handleRLLMesh().

◆ handleCSMesh()

moab::ErrorCode anonymous_namespace{mbtempest.cpp}::handleCSMesh ( ToolContext ctx,
moab::TempestRemapper remapper,
Mesh *  tempest_mesh 
)

Definition at line 1864 of file mbtempest.cpp.

1865 {
1866  // Generate the TempestRemap Exodus mesh (always written as .g for TempestRemap compatibility)
1867  std::string trFilename = ctx.outFilename;
1868  const size_t dot = trFilename.find_last_of( "." );
1869  if( dot != std::string::npos && trFilename.substr( dot + 1 ) == "h5m" )
1870  trFilename = trFilename.substr( 0, dot ) + ".g";
1871 
1872  ctx.timer_push( "generate CS mesh with TempestRemap" );
1873  TR_CHK_SET_ERR( GenerateCSMesh( *tempest_mesh, ctx.blockSize, trFilename, "NetCDF4" ),
1874  "Failed to generate CS mesh with TempestRemap" );
1875  ctx.timer_pop();
1876 
1877  // Add the CS mesh to the list of meshes
1878  ctx.meshes.push_back( tempest_mesh );
1879 
1880  // Convert and write as MOAB h5m if requested
1881  MB_CHK_SET_ERR( convertAndWriteMOABMesh( ctx, remapper, tempest_mesh ),
1882  "Failed to convert and write MOAB mesh" );
1883 
1884  return moab::MB_SUCCESS;
1885 }

References ToolContext::blockSize, convertAndWriteMOABMesh(), moab::dot(), MB_CHK_SET_ERR, MB_SUCCESS, ToolContext::meshes, ToolContext::outFilename, ToolContext::timer_pop(), ToolContext::timer_push(), and TR_CHK_SET_ERR.

Referenced by CreateTempestMesh().

◆ handleICOMesh()

moab::ErrorCode anonymous_namespace{mbtempest.cpp}::handleICOMesh ( ToolContext ctx,
moab::TempestRemapper remapper,
Mesh *  tempest_mesh 
)

Definition at line 1811 of file mbtempest.cpp.

1812 {
1813  std::string trFilename = ctx.outFilename;
1814  const size_t dot = trFilename.find_last_of( "." );
1815  if( dot != std::string::npos && trFilename.substr( dot + 1 ) == "h5m" )
1816  trFilename = trFilename.substr( 0, dot ) + ".g";
1817 
1818  ctx.timer_push( "generate ICO mesh with TempestRemap" );
1819  TR_CHK_SET_ERR( GenerateICOMesh( *tempest_mesh, ctx.blockSize, ctx.computeDual, trFilename, "NetCDF4" ),
1820  "Failed to generate ICO mesh with TempestRemap" );
1821  ctx.timer_pop();
1822 
1823  // Add the ICO mesh to the list of meshes
1824  ctx.meshes.push_back( tempest_mesh );
1825 
1826  MB_CHK_SET_ERR( convertAndWriteMOABMesh( ctx, remapper, tempest_mesh ),
1827  "Failed to convert and write MOAB mesh" );
1828 
1829  return moab::MB_SUCCESS;
1830 }

References ToolContext::blockSize, ToolContext::computeDual, convertAndWriteMOABMesh(), moab::dot(), MB_CHK_SET_ERR, MB_SUCCESS, ToolContext::meshes, ToolContext::outFilename, ToolContext::timer_pop(), ToolContext::timer_push(), and TR_CHK_SET_ERR.

Referenced by CreateTempestMesh().

◆ handleOverlapFiles()

moab::ErrorCode anonymous_namespace{mbtempest.cpp}::handleOverlapFiles ( ToolContext ctx,
Mesh *  tempest_mesh 
)

Definition at line 1754 of file mbtempest.cpp.

1755 {
1756  ctx.timer_push( "create Tempest OverlapMesh" );
1757  TR_CHK_SET_ERR( GenerateOverlapMesh( ctx.inFilenames[0], ctx.inFilenames[1], *tempest_mesh, ctx.outFilename,
1758  "NetCDF4", "exact", true ),
1759  "Failed to create Tempest OverlapMesh" );
1760  ctx.timer_pop();
1761 
1762  // Add the overlap mesh to the list of meshes
1763  ctx.meshes.push_back( tempest_mesh );
1764  return moab::MB_SUCCESS;
1765 }

References ToolContext::inFilenames, MB_SUCCESS, ToolContext::meshes, ToolContext::outFilename, ToolContext::timer_pop(), ToolContext::timer_push(), and TR_CHK_SET_ERR.

Referenced by CreateTempestMesh().

◆ handleOverlapMemory()

moab::ErrorCode anonymous_namespace{mbtempest.cpp}::handleOverlapMemory ( ToolContext ctx,
moab::TempestRemapper remapper,
Mesh *  tempest_mesh 
)

Definition at line 1599 of file mbtempest.cpp.

1600 {
1601  using namespace moab;
1602 
1603  // resize the meshsets and meshes vectors
1604  ctx.meshsets.resize( 3 );
1605  ctx.meshes.resize( 3 );
1606 
1607  ctx.meshsets[0] = remapper.GetMeshSet( Remapper::SourceMesh );
1608  ctx.meshsets[1] = remapper.GetMeshSet( Remapper::TargetMesh );
1609  ctx.meshsets[2] = remapper.GetMeshSet( Remapper::OverlapMesh );
1610 
1611  // Load and process source mesh
1613  "Failed to load MOAB Source mesh" );
1614 
1615  // Load and process target mesh
1617  "Failed to load MOAB Target mesh" );
1618 
1619  // Generate overlap mesh
1620  TR_CHK_SET_ERR( GenerateOverlapWithMeshes( *ctx.meshes[0], *ctx.meshes[1], *tempest_mesh, "", "NetCDF4", "exact",
1621  false ),
1622  "Failed to generate TempestRemap OverlapMesh" );
1623 
1624  remapper.SetMesh( Remapper::OverlapMesh, tempest_mesh );
1625  ctx.meshes[2] = remapper.GetMesh( Remapper::OverlapMesh );
1626 
1627  return moab::MB_SUCCESS;
1628 }

References moab::TempestRemapper::GetMesh(), moab::TempestRemapper::GetMeshSet(), ToolContext::inFilenames, moab::TempestRemapper::LoadMesh(), MB_CHK_SET_ERR, MB_SUCCESS, ToolContext::meshes, ToolContext::meshsets, moab::TempestRemapper::SetMesh(), and TR_CHK_SET_ERR.

Referenced by CreateTempestMesh().

◆ handleOverlapMOAB()

moab::ErrorCode anonymous_namespace{mbtempest.cpp}::handleOverlapMOAB ( ToolContext ctx,
moab::TempestRemapper remapper 
)

Definition at line 1630 of file mbtempest.cpp.

1631 {
1632  using namespace moab;
1633 
1634  // resize the meshsets and meshes vectors
1635  ctx.meshsets.resize( 3 );
1636  ctx.meshes.resize( 3 );
1637 
1638  ctx.meshsets[0] = remapper.GetMeshSet( Remapper::SourceMesh );
1639  ctx.meshsets[1] = remapper.GetMeshSet( Remapper::TargetMesh );
1640  ctx.meshsets[2] = remapper.GetMeshSet( Remapper::OverlapMesh );
1641 
1642  constexpr double radius_src = 1.0;
1643  constexpr double radius_dest = 1.0;
1644 
1645  // Load and process target mesh
1646  {
1647  std::vector< int > metadata;
1648  std::string additional_read_opts_tgt = ctx.get_file_read_options( ctx.inFilenames[1] );
1649  if( ctx.n_procs > 1 && ctx.disc_methods[1].compare( "fv" ) != 0 ) // target discretization is cgll or dgll
1650  {
1651  // auto pcomm = new ParallelComm( ctx.mbcore, MPI_COMM_WORLD );
1652  // add one ghost layer to the target mesh
1653  // additional_read_opts_tgt = additional_read_opts_tgt + "PARALLEL_GHOSTS=3.0.2;PARALLEL_THIN_GHOST_LAYER;SKIP_AUGMENT_WITH_GHOSTS;PRINT_PARALLEL;";
1654  // additional_read_opts_tgt = additional_read_opts_tgt + "PARALLEL_COMM=1;";
1655  // additional_read_opts_tgt = additional_read_opts_tgt + "PARALLEL_GHOSTS=3.0.1;";
1656  // additional_read_opts_tgt = additional_read_opts_tgt + "PARALLEL_COMM=" + std::to_string(ctx.pcomm->get_id()) + ";";
1657  }
1658 
1659  MB_CHK_SET_ERR( remapper.LoadNativeMesh( ctx.inFilenames[1], ctx.meshsets[1], metadata,
1660  additional_read_opts_tgt.c_str() ),
1661  "Failed to load MOAB Target mesh" );
1662 
1663 #ifdef MOAB_HAVE_MPI
1664  if( ctx.n_procs > 1 && ctx.disc_methods[1].compare( "fv" ) != 0 &&
1665  false ) // target discretization is cgll or dgll
1666  {
1667  Range beforeGhost, afterGhost;
1668  ctx.mbcore->get_entities_by_dimension( ctx.meshsets[1], 2, beforeGhost );
1669 
1670  ctx.pcomm->set_debug_verbosity( 5 );
1671  MB_CHK_SET_ERR( ctx.pcomm->exchange_ghost_cells( 2, 0, 1, 0, true, true, &ctx.meshsets[1] ),
1672  "Failed to exchange ghost cells for MOAB Target mesh" );
1673  ctx.pcomm->set_debug_verbosity( 0 );
1674 
1675  ctx.mbcore->get_entities_by_dimension( ctx.meshsets[1], 2, afterGhost );
1676  std::cout << ctx.proc_id << ": N(before) = " << beforeGhost.size() << ", N(after) = " << afterGhost.size()
1677  << std::endl;
1678 
1679  std::vector< Tag > taglist;
1680  taglist.push_back( ctx.mbcore->globalId_tag() );
1681  Tag gdofTag;
1682  MB_CHK_SET_ERR( ctx.mbcore->tag_get_handle( "GLOBAL_DOFS", gdofTag ),
1683  "Failed to get global dofs tag for MOAB Target mesh" );
1684  taglist.push_back( gdofTag );
1685  MB_CHK_SET_ERR( ctx.pcomm->exchange_tags( taglist, taglist, afterGhost ),
1686  "Failed to exchange global dofs for MOAB Target mesh" );
1687  // std::set< unsigned int > commprocs;
1688  // MB_CHK_SET_ERR( ctx.pcomm->get_comm_procs( commprocs ),
1689  // "Failed to get commprocs for MOAB Target mesh" );
1690  // if (ctx.proc_id == 0)
1691  // {
1692  // std::cout << ctx.proc_id << ": commprocs = [";
1693  // for( auto p : commprocs ) std::cout << p << ", ";
1694  // std::cout << "]\n";
1695 
1696  // std::cout << ctx.proc_id << ": N(after) = " << afterGhost.size() << std::endl;
1697  // for (auto eh: afterGhost)
1698  // {
1699  // std::cout << ctx.mbcore->type_from_handle(eh) << ": " << eh << std::endl;
1700  // }
1701  // }
1702  }
1703 #endif
1704 
1705  if( !metadata.empty() )
1706  {
1707  remapper.SetMeshType( Remapper::TargetMesh, metadata );
1708  }
1709 
1710  MB_CHK_SET_ERR( IntxUtils::ScaleToRadius( ctx.mbcore, ctx.meshsets[1], radius_dest ),
1711  "Failed to preprocess MOAB Target mesh" );
1712  }
1713 
1714  // Load and process source mesh
1715  {
1716  std::vector< int > metadata;
1717  auto additional_read_opts_src = ctx.get_file_read_options( ctx.inFilenames[0] );
1718 #ifdef MOAB_HAVE_MPI
1719  if( ctx.n_procs > 1 )
1720  {
1721  // auto pcomm = new ParallelComm( ctx.mbcore, MPI_COMM_WORLD );
1722  additional_read_opts_src =
1723  additional_read_opts_src + "PARALLEL_COMM=" + std::to_string( ctx.pcomm->get_id() ) + ";";
1724  }
1725 #endif
1726  MB_CHK_SET_ERR( remapper.LoadNativeMesh( ctx.inFilenames[0], ctx.meshsets[0], metadata,
1727  additional_read_opts_src.c_str() ),
1728  "Failed to load MOAB Source mesh" );
1729 
1730  if( !metadata.empty() )
1731  {
1732  remapper.SetMeshType( Remapper::SourceMesh, metadata );
1733  }
1734 
1735  MB_CHK_SET_ERR( IntxUtils::ScaleToRadius( ctx.mbcore, ctx.meshsets[0], radius_src ),
1736  "Failed to preprocess MOAB Source mesh" );
1737  }
1738 
1739  if( ctx.computeWeights )
1740  {
1741  // Convert MOAB to TempestRemap meshes
1743  "Failed to convert MOAB Source mesh to TempestRemap mesh" );
1744  ctx.meshes[0] = remapper.GetMesh( Remapper::SourceMesh );
1745 
1747  "Failed to convert MOAB Target mesh to TempestRemap mesh" );
1748  ctx.meshes[1] = remapper.GetMesh( Remapper::TargetMesh );
1749  }
1750 
1751  return moab::MB_SUCCESS;
1752 }

References ToolContext::computeWeights, moab::TempestRemapper::ConvertMeshToTempest(), ToolContext::disc_methods, moab::Core::get_entities_by_dimension(), ToolContext::get_file_read_options(), moab::TempestRemapper::GetMesh(), moab::TempestRemapper::GetMeshSet(), moab::Core::globalId_tag(), ToolContext::inFilenames, moab::Remapper::LoadNativeMesh(), MB_CHK_SET_ERR, MB_SUCCESS, ToolContext::mbcore, ToolContext::meshes, ToolContext::meshsets, ToolContext::n_procs, ToolContext::proc_id, moab::TempestRemapper::SetMeshType(), moab::Range::size(), and moab::Core::tag_get_handle().

Referenced by CreateTempestMesh().

◆ handleRLLMesh()

moab::ErrorCode anonymous_namespace{mbtempest.cpp}::handleRLLMesh ( ToolContext ctx,
moab::TempestRemapper remapper,
Mesh *  tempest_mesh 
)

Definition at line 1832 of file mbtempest.cpp.

1833 {
1834  std::string trFilename = ctx.outFilename;
1835  const size_t dot = trFilename.find_last_of( "." );
1836  if( dot != std::string::npos && trFilename.substr( dot + 1 ) == "h5m" )
1837  trFilename = trFilename.substr( 0, dot ) + ".g";
1838 
1839  ctx.timer_push( "generate RLL mesh with TempestRemap" );
1840  TR_CHK_SET_ERR( GenerateRLLMesh( *tempest_mesh, // Mesh& meshOut,
1841  ctx.blockSize * 2, ctx.blockSize, // int nLongitudes, int nLatitudes,
1842  0.0, 360.0, // double dLonBegin, double dLonEnd,
1843  -90.0, 90.0, // double dLatBegin, double dLatEnd,
1844  false, false, false, // bool fGlobalCap, bool fFlipLatLon, bool fForceGlobal,
1845  "" /*ctx.inFilename*/,
1846  "", // std::string strInputFile, std::string strInputFileLonName
1847  "", // std::string strInputFileLatName
1848  trFilename, // std::string strOutputFile
1849  "NetCDF4", // std::string strOutputFormat
1850  true // bool fVerbose
1851  ),
1852  "Failed to generate RLL mesh with TempestRemap" );
1853  ctx.timer_pop();
1854 
1855  // Add the RLL mesh to the list of meshes
1856  ctx.meshes.push_back( tempest_mesh );
1857 
1858  MB_CHK_SET_ERR( convertAndWriteMOABMesh( ctx, remapper, tempest_mesh ),
1859  "Failed to convert and write MOAB mesh" );
1860 
1861  return moab::MB_SUCCESS;
1862 }

References ToolContext::blockSize, convertAndWriteMOABMesh(), moab::dot(), MB_CHK_SET_ERR, MB_SUCCESS, ToolContext::meshes, ToolContext::outFilename, ToolContext::timer_pop(), ToolContext::timer_push(), and TR_CHK_SET_ERR.

Referenced by CreateTempestMesh().

Variable Documentation

◆ VORTEX_D

constexpr double anonymous_namespace{mbtempest.cpp}::VORTEX_D = 5.0
constexpr

Definition at line 1959 of file mbtempest.cpp.

Referenced by sample_stationary_vortex().

◆ VORTEX_LAT0

constexpr double anonymous_namespace{mbtempest.cpp}::VORTEX_LAT0 = 0.6
constexpr

Definition at line 1957 of file mbtempest.cpp.

Referenced by sample_stationary_vortex().

◆ VORTEX_LON0

constexpr double anonymous_namespace{mbtempest.cpp}::VORTEX_LON0 = 0.0
constexpr

Definition at line 1956 of file mbtempest.cpp.

Referenced by sample_stationary_vortex().

◆ VORTEX_R0

constexpr double anonymous_namespace{mbtempest.cpp}::VORTEX_R0 = 3.0
constexpr

Definition at line 1958 of file mbtempest.cpp.

Referenced by sample_stationary_vortex().

◆ VORTEX_T

constexpr double anonymous_namespace{mbtempest.cpp}::VORTEX_T = 6.0
constexpr

Definition at line 1960 of file mbtempest.cpp.

Referenced by sample_stationary_vortex().