Mesh Oriented datABase  (version 5.5.1)
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, // default context
60  SourceMesh = 0, // source mesh
61  TargetMesh = 1, // target mesh
62  OverlapMesh = 2, // overlap/intersection mesh
63  CoveringMesh = 3, // source mesh covering target mesh
64  };
65 
67  {
68  return m_interface;
69  }
70 //#define MOAB_DBG
71 #ifdef MOAB_HAVE_MPI
72  moab::ParallelComm* get_parallel_communicator()
73  {
74  return m_pcomm;
75  }
76 
77 #endif
78 
79 #undef MOAB_DBG
80 
81  ErrorCode LoadNativeMesh( std::string filename,
82  moab::EntityHandle& meshset,
83  std::vector< int >& metadata,
84  const char* readopts = 0 )
85  {
86 #ifdef MOAB_HAVE_MPI
87  std::string opts = "";
88  if( readopts )
89  {
90  if( opts.size() )
91  opts = opts + ";" + std::string( readopts );
92  else
93  opts = std::string( readopts );
94  }
95 
96  if( !m_pcomm->rank() ) std::cout << "Reading file (" << filename << ") with options = [" << opts << "]\n";
97 #else
98  const std::string opts = std::string( ( readopts ? readopts : "" ) );
99  std::cout << "Reading file (" << filename << ") with options = [" << opts << "]\n";
100 #endif
101  MB_CHK_ERR( m_interface->load_file( filename.c_str(), &meshset, opts.c_str() ) );
102 
103  Tag rectilinearTag;
104  ErrorCode rval = m_interface->tag_get_handle( "ClimateMetadata", rectilinearTag );
105 
106  if( rval != MB_FAILURE && rval != MB_TAG_NOT_FOUND && rval != MB_ALREADY_ALLOCATED &&
107  rectilinearTag != nullptr )
108  {
109  int dimSizes[3];
110  EntityHandle rootset = 0;
111  rval = m_interface->tag_get_data( rectilinearTag, &rootset, 1,
112  dimSizes ); // MB_CHK_SET_ERR( rval, "Error geting tag data" );
113  metadata.clear();
114  metadata.push_back( dimSizes[0] );
115  metadata.push_back( dimSizes[1] );
116  metadata.push_back( dimSizes[2] );
117  }
118 
119  return MB_SUCCESS;
120  }
121 
122  protected:
123  // member data
125 
126 #ifdef MOAB_HAVE_MPI
127  ParallelComm* m_pcomm;
128 #endif
129 };
130 
131 } // namespace moab
132 
133 #endif /* MB_REMAPPER_HPP */