MOAB: Mesh Oriented datABase  (version 5.2.1)
Remapper.hpp
Go to the documentation of this file.
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), mahadevan@anl.gov
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, moab::EntityHandle& meshset, const char* readopts = 0 )
00079     {
00080 #ifdef MOAB_HAVE_MPI
00081         size_t lastindex      = filename.find_last_of( "." );
00082         std::string extension = filename.substr( lastindex + 1, filename.size() );
00083         std::string opts      = "";
00084         if( m_pcomm->size() > 1 )
00085         {
00086             if( extension != "h5m" )
00087                 opts = std::string( "PARALLEL=BCAST_DELETE;PARTITION=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS" );
00088             else
00089                 opts = std::string( "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_"
00090                                     "RESOLVE_SHARED_ENTS" );
00091         }
00092 
00093         if( readopts )
00094         {
00095             if( opts.size() )
00096                 opts = opts + ";" + std::string( readopts );
00097             else
00098                 opts = std::string( readopts );
00099         }
00100 
00101         if( !m_pcomm->rank() ) std::cout << "Reading file (" << filename << ") with options = [" << opts << "]\n";
00102 #else
00103         const std::string opts = std::string( ( readopts ? readopts : "" ) );
00104         std::cout << "Reading file (" << filename << ") with options = [" << opts << "]\n";
00105 #endif
00106         return m_interface->load_file( filename.c_str(), &meshset, opts.c_str() );
00107     }
00108 
00109   protected:
00110     // member data
00111     Interface* m_interface;
00112 
00113 #ifdef MOAB_HAVE_MPI
00114     ParallelComm* m_pcomm;
00115 #endif
00116 };
00117 
00118 }  // namespace moab
00119 
00120 #endif /* MB_REMAPPER_HPP */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines