Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 /* 00002 * ===================================================================================== 00003 * 00004 * Filename: Remapper.hpp 00005 * 00006 * Description: Interface to the a general remapping capability on arbitrary topology 00007 * that performs both mesh intersection between a source and target grid, 00008 * with arbitrary decompositions. The intersections can then be used to 00009 * either evaluate interpolation weights or to perform high-order 00010 * conservative remapping of solutions defined on the source grid. 00011 * 00012 * Author: Vijay S. Mahadevan (vijaysm), [email protected] 00013 * 00014 * ===================================================================================== 00015 */ 00016 00017 #ifndef MB_REMAPPER_HPP 00018 #define MB_REMAPPER_HPP 00019 00020 #include <string> 00021 00022 #include "moab/Interface.hpp" 00023 #ifdef MOAB_HAVE_MPI 00024 #include "moab/ParallelComm.hpp" 00025 #endif 00026 00027 // Tempest includes 00028 #ifdef MOAB_HAVE_TEMPESTREMAP 00029 #include "netcdfcpp.h" 00030 #include "TempestRemapAPI.h" 00031 #else 00032 #error "This tool depends on TempestRemap library. Reconfigure using --with-tempestremap" 00033 #endif 00034 00035 namespace moab 00036 { 00037 00038 class Remapper 00039 { 00040 public: 00041 #ifdef MOAB_HAVE_MPI 00042 Remapper( moab::Interface* mbInt, moab::ParallelComm* pcomm = NULL ) : m_interface( mbInt ), m_pcomm( pcomm ) 00043 #else 00044 Remapper( moab::Interface* mbInt ) : m_interface( mbInt ) 00045 #endif 00046 { 00047 } 00048 00049 virtual ~Remapper() 00050 { 00051 #ifdef MOAB_HAVE_MPI 00052 m_pcomm = NULL; 00053 #endif 00054 m_interface = NULL; 00055 } 00056 00057 enum IntersectionContext 00058 { 00059 DEFAULT = -1, 00060 SourceMesh = 0, 00061 TargetMesh = 1, 00062 OverlapMesh = 2, 00063 CoveringMesh = 3 00064 }; 00065 00066 moab::Interface* get_interface() 00067 { 00068 return m_interface; 00069 } 00070 00071 #ifdef MOAB_HAVE_MPI 00072 moab::ParallelComm* get_parallel_communicator() 00073 { 00074 return m_pcomm; 00075 } 00076 #endif 00077 00078 ErrorCode LoadNativeMesh( std::string filename, 00079 moab::EntityHandle& meshset, 00080 std::vector< int >& metadata, 00081 const char* readopts = 0 ) 00082 { 00083 #ifdef MOAB_HAVE_MPI 00084 size_t lastindex = filename.find_last_of( "." ); 00085 std::string extension = filename.substr( lastindex + 1, filename.size() ); 00086 std::string opts = ""; 00087 if( m_pcomm->size() > 1 ) 00088 { 00089 if( extension != "h5m" ) 00090 opts = std::string( "PARALLEL=BCAST_DELETE;PARTITION=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS" ); 00091 else 00092 opts = std::string( "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_" 00093 "RESOLVE_SHARED_ENTS" ); 00094 } 00095 00096 if( readopts ) 00097 { 00098 if( opts.size() ) 00099 opts = opts + ";" + std::string( readopts ); 00100 else 00101 opts = std::string( readopts ); 00102 } 00103 00104 if( !m_pcomm->rank() ) std::cout << "Reading file (" << filename << ") with options = [" << opts << "]\n"; 00105 #else 00106 const std::string opts = std::string( ( readopts ? readopts : "" ) ); 00107 std::cout << "Reading file (" << filename << ") with options = [" << opts << "]\n"; 00108 #endif 00109 moab::ErrorCode rval = m_interface->load_file( filename.c_str(), &meshset, opts.c_str() );MB_CHK_ERR( rval ); 00110 00111 Tag rectilinearTag; 00112 rval = m_interface->tag_get_handle( "ClimateMetadata", rectilinearTag ); 00113 00114 if( rval != MB_FAILURE && rval != MB_TAG_NOT_FOUND && rval != MB_ALREADY_ALLOCATED && 00115 rectilinearTag != nullptr ) 00116 { 00117 int dimSizes[3]; 00118 moab::EntityHandle rootset = 0; 00119 rval = m_interface->tag_get_data( rectilinearTag, &rootset, 1, 00120 dimSizes ); // MB_CHK_SET_ERR( rval, "Error geting tag data" ); 00121 metadata.clear(); 00122 metadata.push_back( dimSizes[0] ); 00123 metadata.push_back( dimSizes[1] ); 00124 metadata.push_back( dimSizes[2] ); 00125 // printf( "Mesh metadata: %d, %d, %d\n", metadata[0], metadata[1], metadata[2] ); 00126 } 00127 00128 return MB_SUCCESS; 00129 } 00130 00131 protected: 00132 // member data 00133 Interface* m_interface; 00134 00135 #ifdef MOAB_HAVE_MPI 00136 ParallelComm* m_pcomm; 00137 #endif 00138 }; 00139 00140 } // namespace moab 00141 00142 #endif /* MB_REMAPPER_HPP */