MOAB: Mesh Oriented datABase  (version 5.4.1)
test_remapping.cpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #ifdef WIN32
00017 #ifdef _DEBUG
00018 // turn off warnings that say they debugging identifier has been truncated
00019 // this warning comes up when using some STL containers
00020 #pragma warning( disable : 4786 )
00021 #endif
00022 #endif
00023 
00024 #include <iostream>
00025 #include "moab/Core.hpp"
00026 #include "moab/Remapping/TempestRemapper.hpp"
00027 
00028 #ifdef MOAB_HAVE_MPI
00029 #include "moab/ParallelComm.hpp"
00030 #endif
00031 
00032 #ifndef IS_BUILDING_MB
00033 #define IS_BUILDING_MB
00034 #endif
00035 
00036 #include "Internals.hpp"
00037 #include "TestRunner.hpp"
00038 
00039 using namespace moab;
00040 
00041 const static double radius               = 1.0;
00042 const double MOAB_PI                     = 3.1415926535897932384626433832795028841971693993751058209749445923;
00043 const static double surface_area         = 4.0 * MOAB_PI * radius * radius;
00044 const static std::string outFilenames[5] = { "outTempestCS.g", "outTempestRLL.g", "outTempestICO.g", "outTempestICOD.g",
00045                                              "outTempestOV.g" };
00046 
00047 void test_tempest_cs_create();
00048 void test_tempest_rll_create();
00049 void test_tempest_ico_create();
00050 void test_tempest_mpas_create();
00051 void test_tempest_overlap_combinations();
00052 void test_tempest_to_moab_convert();
00053 
00054 int main( int argc, char** argv )
00055 {
00056     REGISTER_TEST( test_tempest_cs_create );
00057     REGISTER_TEST( test_tempest_rll_create );
00058     REGISTER_TEST( test_tempest_ico_create );
00059     REGISTER_TEST( test_tempest_mpas_create );
00060     REGISTER_TEST( test_tempest_overlap_combinations );
00061     REGISTER_TEST( test_tempest_to_moab_convert );
00062 
00063 #ifdef MOAB_HAVE_MPI
00064     MPI_Init( &argc, &argv );
00065 #endif
00066     int result = RUN_TESTS( argc, argv );
00067 #ifdef MOAB_HAVE_MPI
00068     MPI_Finalize();
00069 #endif
00070     return result;
00071 }
00072 
00073 void test_tempest_cs_create()
00074 {
00075     NcError error( NcError::verbose_nonfatal );
00076     const int blockSize           = 30;
00077     const std::string outFilename = outFilenames[0];
00078 
00079     std::cout << "Creating TempestRemap Cubed-Sphere Mesh ...\n";
00080     Mesh tempest_mesh;
00081     int ierr = GenerateCSMesh( tempest_mesh, blockSize, outFilename, "NetCDF4" );
00082     CHECK_EQUAL( ierr, 0 );
00083 
00084     // Compute the surface area of CS mesh
00085     const double sphere_area = tempest_mesh.CalculateFaceAreas( false );
00086     CHECK_REAL_EQUAL( sphere_area, surface_area, 1e-10 );
00087 }
00088 
00089 void test_tempest_rll_create()
00090 {
00091     NcError error( NcError::verbose_nonfatal );
00092     const int blockSize           = 30;
00093     const std::string outFilename = outFilenames[1];
00094 
00095     std::cout << "Creating TempestRemap Latitude-Longitude Mesh ...\n";
00096     Mesh tempest_mesh;
00097     int ierr =
00098         GenerateRLLMesh( tempest_mesh, blockSize * 2, blockSize, 0.0, 360.0, -90.0, 90.0, false, false, true, "", "",
00099                          "",  // std::string strInputFile, std::string strInputFileLonName, std::string
00100                               // strInputFileLatName,
00101                          outFilename, "NetCDF4",  // std::string strOutputFile, std::string strOutputFormat
00102                          false );
00103     CHECK_EQUAL( ierr, 0 );
00104 
00105     // Compute the surface area of RLL mesh
00106     const double sphere_area = tempest_mesh.CalculateFaceAreas( false );
00107     CHECK_REAL_EQUAL( sphere_area, surface_area, 1e-10 );
00108 }
00109 
00110 void test_tempest_ico_create()
00111 {
00112     NcError error( NcError::verbose_nonfatal );
00113     const int blockSize           = 30;
00114     const bool computeDual        = false;
00115     const std::string outFilename = outFilenames[2];
00116 
00117     std::cout << "Creating TempestRemap Icosahedral Mesh ...\n";
00118     Mesh tempest_mesh;
00119     int ierr = GenerateICOMesh( tempest_mesh, blockSize, computeDual, outFilename, "NetCDF4" );
00120     CHECK_EQUAL( ierr, 0 );
00121 
00122     // Compute the surface area of ICO mesh
00123     const double sphere_area = tempest_mesh.CalculateFaceAreas( false );
00124     CHECK_REAL_EQUAL( sphere_area, surface_area, 1e-10 );
00125 }
00126 
00127 void test_tempest_mpas_create()
00128 {
00129     NcError error( NcError::verbose_nonfatal );
00130     const int blockSize           = 30;
00131     const bool computeDual        = true;
00132     const std::string outFilename = outFilenames[3];
00133 
00134     std::cout << "Creating TempestRemap MPAS Mesh (dual of the Icosahedral) ...\n";
00135     Mesh tempest_mesh;
00136     int ierr = GenerateICOMesh( tempest_mesh, blockSize, computeDual, outFilename, "NetCDF4" );
00137     CHECK_EQUAL( ierr, 0 );
00138 
00139     // Compute the surface area of MPAS mesh
00140     const double sphere_area = tempest_mesh.CalculateFaceAreas( false );
00141     CHECK_REAL_EQUAL( sphere_area, surface_area, 1e-10 );
00142 }
00143 
00144 void test_tempest_overlap_combinations()
00145 {
00146     NcError error( NcError::verbose_nonfatal );
00147     const std::string outFilename = outFilenames[4];
00148 
00149     Mesh inpMesh( outFilenames[0] );
00150     // verify input mesh area first
00151     const double inpArea = inpMesh.CalculateFaceAreas( false );
00152     CHECK_REAL_EQUAL( inpArea, surface_area, 1e-10 );
00153 
00154     for( int isrc = 0; isrc < 4; ++isrc )
00155     {
00156         for( int jsrc = 0; jsrc < 4; ++jsrc )
00157         {
00158             std::cout << "Computing Overlap between " << outFilenames[isrc] << " and " << outFilenames[jsrc]
00159                       << " ...\n";
00160             Mesh tempest_mesh;
00161             int ierr = GenerateOverlapMesh( outFilenames[isrc], outFilenames[jsrc], tempest_mesh, outFilename,
00162                                             "NetCDF4", "exact", false, false, false, false, false );
00163             CHECK_EQUAL( ierr, 0 );
00164             // verify overlap mesh area
00165             const double ovArea = tempest_mesh.CalculateFaceAreas( false );
00166             CHECK_REAL_EQUAL( ovArea, surface_area, 1e-10 );
00167         }
00168     }
00169 }
00170 
00171 void test_tempest_to_moab_convert()
00172 {
00173     NcError error( NcError::verbose_nonfatal );
00174 
00175     // Allocate and create MOAB Remapper object
00176     moab::ErrorCode rval;
00177     moab::Interface* mbCore = new( std::nothrow ) moab::Core;
00178     CHECK( NULL != mbCore );
00179 
00180 #ifdef MOAB_HAVE_MPI
00181     moab::ParallelComm* pcomm       = new moab::ParallelComm( mbCore, MPI_COMM_WORLD, 0 );
00182     moab::TempestRemapper* remapper = new moab::TempestRemapper( mbCore, pcomm );
00183 #else
00184     moab::TempestRemapper* remapper = new moab::TempestRemapper( mbCore );
00185 #endif
00186     remapper->meshValidate     = true;
00187     remapper->constructEdgeMap = true;
00188     remapper->initialize();
00189 
00190 #ifdef MOAB_HAVE_MPI
00191     rval = pcomm->check_all_shared_handles();CHECK_ERR( rval );
00192 #endif
00193 
00194     rval = remapper->LoadMesh( moab::Remapper::SourceMesh, outFilenames[0], moab::TempestRemapper::CS );CHECK_ERR( rval );
00195 
00196     // Load the meshes and validate
00197     rval = remapper->ConvertTempestMesh( moab::Remapper::SourceMesh );CHECK_ERR( rval );
00198 
00199     Mesh* srcTempest = remapper->GetMesh( moab::Remapper::SourceMesh );
00200 
00201     moab::EntityHandle srcset = remapper->GetMeshSet( moab::Remapper::SourceMesh );
00202 
00203     moab::EntityHandle& tgtset = remapper->GetMeshSet( moab::Remapper::TargetMesh );
00204 
00205     tgtset = srcset;
00206 
00207     // Load the meshes and validate
00208     rval = remapper->ConvertMeshToTempest( moab::Remapper::TargetMesh );CHECK_ERR( rval );
00209 
00210     Mesh* tgtTempest = remapper->GetMesh( moab::Remapper::TargetMesh );
00211 
00212     const size_t tempest_nodes_src = srcTempest->nodes.size(), tempest_elems_src = srcTempest->faces.size();
00213     const size_t tempest_nodes_tgt = tgtTempest->nodes.size(), tempest_elems_tgt = tgtTempest->faces.size();
00214     CHECK_EQUAL( tempest_nodes_src, tempest_nodes_tgt );
00215     CHECK_EQUAL( tempest_elems_src, tempest_elems_tgt );
00216 
00217     delete remapper;
00218 #ifdef MOAB_HAVE_MPI
00219     delete pcomm;
00220 #endif
00221     delete mbCore;
00222 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines