MOAB: Mesh Oriented datABase  (version 5.5.0)
test_remapping.cpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 #ifdef WIN32
17 #ifdef _DEBUG
18 // turn off warnings that say they debugging identifier has been truncated
19 // this warning comes up when using some STL containers
20 #pragma warning( disable : 4786 )
21 #endif
22 #endif
23 
24 #include <iostream>
25 #include "moab/Core.hpp"
27 
28 #ifdef MOAB_HAVE_MPI
29 #include "moab/ParallelComm.hpp"
30 #endif
31 
32 #ifndef IS_BUILDING_MB
33 #define IS_BUILDING_MB
34 #endif
35 
36 #include "Internals.hpp"
37 #include "TestRunner.hpp"
38 
39 using namespace moab;
40 
41 const static double radius = 1.0;
42 const double MOAB_PI = 3.1415926535897932384626433832795028841971693993751058209749445923;
43 const static double surface_area = 4.0 * MOAB_PI * radius * radius;
44 const static std::string outFilenames[5] = { "outTempestCS.g", "outTempestRLL.g", "outTempestICO.g", "outTempestICOD.g",
45  "outTempestOV.g" };
46 
53 
54 int main( int argc, char** argv )
55 {
62 
63 #ifdef MOAB_HAVE_MPI
64  MPI_Init( &argc, &argv );
65 #endif
66  int result = RUN_TESTS( argc, argv );
67 #ifdef MOAB_HAVE_MPI
68  MPI_Finalize();
69 #endif
70  return result;
71 }
72 
74 {
75  NcError error( NcError::verbose_nonfatal );
76  const int blockSize = 30;
77  const std::string outFilename = outFilenames[0];
78 
79  std::cout << "Creating TempestRemap Cubed-Sphere Mesh ...\n";
80  Mesh tempest_mesh;
81  int ierr = GenerateCSMesh( tempest_mesh, blockSize, outFilename, "NetCDF4" );
82  CHECK_EQUAL( ierr, 0 );
83 
84  // Compute the surface area of CS mesh
85  const double sphere_area = tempest_mesh.CalculateFaceAreas( false );
86  CHECK_REAL_EQUAL( sphere_area, surface_area, 1e-10 );
87 }
88 
90 {
91  NcError error( NcError::verbose_nonfatal );
92  const int blockSize = 30;
93  const std::string outFilename = outFilenames[1];
94 
95  std::cout << "Creating TempestRemap Latitude-Longitude Mesh ...\n";
96  Mesh tempest_mesh;
97  int ierr =
98  GenerateRLLMesh( tempest_mesh, blockSize * 2, blockSize, 0.0, 360.0, -90.0, 90.0, false, false, true, "", "",
99  "", // std::string strInputFile, std::string strInputFileLonName, std::string
100  // strInputFileLatName,
101  outFilename, "NetCDF4", // std::string strOutputFile, std::string strOutputFormat
102  false );
103  CHECK_EQUAL( ierr, 0 );
104 
105  // Compute the surface area of RLL mesh
106  const double sphere_area = tempest_mesh.CalculateFaceAreas( false );
107  CHECK_REAL_EQUAL( sphere_area, surface_area, 1e-10 );
108 }
109 
111 {
112  NcError error( NcError::verbose_nonfatal );
113  const int blockSize = 30;
114  const bool computeDual = false;
115  const std::string outFilename = outFilenames[2];
116 
117  std::cout << "Creating TempestRemap Icosahedral Mesh ...\n";
118  Mesh tempest_mesh;
119  int ierr = GenerateICOMesh( tempest_mesh, blockSize, computeDual, outFilename, "NetCDF4" );
120  CHECK_EQUAL( ierr, 0 );
121 
122  // Compute the surface area of ICO mesh
123  const double sphere_area = tempest_mesh.CalculateFaceAreas( false );
124  CHECK_REAL_EQUAL( sphere_area, surface_area, 1e-10 );
125 }
126 
128 {
129  NcError error( NcError::verbose_nonfatal );
130  const int blockSize = 30;
131  const bool computeDual = true;
132  const std::string outFilename = outFilenames[3];
133 
134  std::cout << "Creating TempestRemap MPAS Mesh (dual of the Icosahedral) ...\n";
135  Mesh tempest_mesh;
136  int ierr = GenerateICOMesh( tempest_mesh, blockSize, computeDual, outFilename, "NetCDF4" );
137  CHECK_EQUAL( ierr, 0 );
138 
139  // Compute the surface area of MPAS mesh
140  const double sphere_area = tempest_mesh.CalculateFaceAreas( false );
141  CHECK_REAL_EQUAL( sphere_area, surface_area, 1e-10 );
142 }
143 
145 {
146  NcError error( NcError::verbose_nonfatal );
147  const std::string outFilename = outFilenames[4];
148 
149  Mesh inpMesh( outFilenames[0] );
150  // verify input mesh area first
151  const double inpArea = inpMesh.CalculateFaceAreas( false );
152  CHECK_REAL_EQUAL( inpArea, surface_area, 1e-10 );
153 
154  for( int isrc = 0; isrc < 4; ++isrc )
155  {
156  for( int jsrc = 0; jsrc < 4; ++jsrc )
157  {
158  std::cout << "Computing Overlap between " << outFilenames[isrc] << " and " << outFilenames[jsrc]
159  << " ...\n";
160  Mesh tempest_mesh;
161  int ierr = GenerateOverlapMesh( outFilenames[isrc], outFilenames[jsrc], tempest_mesh, outFilename,
162  "NetCDF4", "exact", false, false, false, false, false );
163  CHECK_EQUAL( ierr, 0 );
164  // verify overlap mesh area
165  const double ovArea = tempest_mesh.CalculateFaceAreas( false );
166  CHECK_REAL_EQUAL( ovArea, surface_area, 1e-10 );
167  }
168  }
169 }
170 
172 {
173  NcError error( NcError::verbose_nonfatal );
174 
175  // Allocate and create MOAB Remapper object
176  moab::ErrorCode rval;
177  moab::Interface* mbCore = new( std::nothrow ) moab::Core;
178  CHECK( NULL != mbCore );
179 
180 #ifdef MOAB_HAVE_MPI
181  moab::ParallelComm* pcomm = new moab::ParallelComm( mbCore, MPI_COMM_WORLD, 0 );
182  moab::TempestRemapper* remapper = new moab::TempestRemapper( mbCore, pcomm );
183 #else
184  moab::TempestRemapper* remapper = new moab::TempestRemapper( mbCore );
185 #endif
186  remapper->meshValidate = true;
187  remapper->constructEdgeMap = true;
188  remapper->initialize();
189 
190 #ifdef MOAB_HAVE_MPI
191  rval = pcomm->check_all_shared_handles();CHECK_ERR( rval );
192 #endif
193 
195 
196  // Load the meshes and validate
197  rval = remapper->ConvertTempestMesh( moab::Remapper::SourceMesh );CHECK_ERR( rval );
198 
199  Mesh* srcTempest = remapper->GetMesh( moab::Remapper::SourceMesh );
200 
202 
204 
205  tgtset = srcset;
206 
207  // Load the meshes and validate
208  rval = remapper->ConvertMeshToTempest( moab::Remapper::TargetMesh );CHECK_ERR( rval );
209 
210  Mesh* tgtTempest = remapper->GetMesh( moab::Remapper::TargetMesh );
211 
212  const size_t tempest_nodes_src = srcTempest->nodes.size(), tempest_elems_src = srcTempest->faces.size();
213  const size_t tempest_nodes_tgt = tgtTempest->nodes.size(), tempest_elems_tgt = tgtTempest->faces.size();
214  CHECK_EQUAL( tempest_nodes_src, tempest_nodes_tgt );
215  CHECK_EQUAL( tempest_elems_src, tempest_elems_tgt );
216 
217  delete remapper;
218 #ifdef MOAB_HAVE_MPI
219  delete pcomm;
220 #endif
221  delete mbCore;
222 }