Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
Remapper.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Remapper.hpp
5  *
6  * Description: Interface to the a general remapping capability on arbitrary topology
7  * that performs both mesh intersection between a source and target grid,
8  * with arbitrary decompositions. The intersections can then be used to
9  * either evaluate interpolation weights or to perform high-order
10  * conservative remapping of solutions defined on the source grid.
11  *
12  * Author: Vijay S. Mahadevan (vijaysm), [email protected]
13  *
14  * =====================================================================================
15  */
16 
17 #ifndef MB_REMAPPER_HPP
18 #define MB_REMAPPER_HPP
19 
20 #include <string>
21 
22 #include "moab/Interface.hpp"
23 #ifdef MOAB_HAVE_MPI
24 #include "moab/ParallelComm.hpp"
25 #endif
26 
27 // Tempest includes
28 #ifdef MOAB_HAVE_TEMPESTREMAP
29 #include "netcdfcpp.h"
30 #include "TempestRemapAPI.h"
31 #else
32 #error "This tool depends on TempestRemap library. Reconfigure using --with-tempestremap"
33 #endif
34 
35 namespace moab
36 {
37 
38 class Remapper
39 {
40  public:
41 #ifdef MOAB_HAVE_MPI
42  Remapper( moab::Interface* mbInt, moab::ParallelComm* pcomm = NULL ) : m_interface( mbInt ), m_pcomm( pcomm )
43 #else
44  Remapper( moab::Interface* mbInt ) : m_interface( mbInt )
45 #endif
46  {
47  }
48 
49  virtual ~Remapper()
50  {
51 #ifdef MOAB_HAVE_MPI
52  m_pcomm = NULL;
53 #endif
54  m_interface = NULL;
55  }
56 
58  {
59  DEFAULT = -1,
63  CoveringMesh = 3
64  };
65 
67  {
68  return m_interface;
69  }
70 
71 #ifdef MOAB_HAVE_MPI
72  moab::ParallelComm* get_parallel_communicator()
73  {
74  return m_pcomm;
75  }
76 #endif
77 
78  ErrorCode LoadNativeMesh( std::string filename,
79  moab::EntityHandle& meshset,
80  std::vector< int >& metadata,
81  const char* readopts = 0 )
82  {
83 #ifdef MOAB_HAVE_MPI
84  std::string opts = "";
85  if( readopts )
86  {
87  if( opts.size() )
88  opts = opts + ";" + std::string( readopts );
89  else
90  opts = std::string( readopts );
91  }
92 
93  if( !m_pcomm->rank() ) std::cout << "Reading file (" << filename << ") with options = [" << opts << "]\n";
94 #else
95  const std::string opts = std::string( ( readopts ? readopts : "" ) );
96  std::cout << "Reading file (" << filename << ") with options = [" << opts << "]\n";
97 #endif
98  moab::ErrorCode rval = m_interface->load_file( filename.c_str(), &meshset, opts.c_str() );MB_CHK_ERR( rval );
99 
100  Tag rectilinearTag;
101  rval = m_interface->tag_get_handle( "ClimateMetadata", rectilinearTag );
102 
103  if( rval != MB_FAILURE && rval != MB_TAG_NOT_FOUND && rval != MB_ALREADY_ALLOCATED &&
104  rectilinearTag != nullptr )
105  {
106  int dimSizes[3];
107  rval = m_interface->tag_get_data( rectilinearTag, &meshset, 1,
108  dimSizes ); // MB_CHK_SET_ERR( rval, "Error geting tag data" );
109  metadata.clear();
110  metadata.push_back( dimSizes[0] );
111  metadata.push_back( dimSizes[1] );
112  metadata.push_back( dimSizes[2] );
113  }
114 
115  return MB_SUCCESS;
116  }
117 
118  protected:
119  // member data
121 
122 #ifdef MOAB_HAVE_MPI
123  ParallelComm* m_pcomm;
124 #endif
125 };
126 
127 } // namespace moab
128 
129 #endif /* MB_REMAPPER_HPP */