[MOAB-dev] commit/MOAB: danwu: Updated the unit test for NC writer. As the set variable gw is required for CAM-EUL to create the mesh, we write it to the output file in addition to variable T. A new test case is added to read the output file and verify that the variables were correctly saved. This test fails on checking the values of variable T, which is expected result as current NC writer does not transpose the tag values of T. We need to update NC writer later to make this test pass.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Apr 3 15:06:22 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/1bf6d215fad2/
Changeset:   1bf6d215fad2
Branch:      ncwriter
User:        danwu
Date:        2014-04-03 22:06:07
Summary:     Updated the unit test for NC writer. As the set variable gw is required for CAM-EUL to create the mesh, we write it to the output file in addition to variable T. A new test case is added to read the output file and verify that the variables were correctly saved. This test fails on checking the values of variable T, which is expected result as current NC writer does not transpose the tag values of T. We need to update NC writer later to make this test pass.

Affected #:  1 file

diff --git a/test/io/write_nc.cpp b/test/io/write_nc.cpp
index 1a17ee9..58c1095 100644
--- a/test/io/write_nc.cpp
+++ b/test/io/write_nc.cpp
@@ -1,5 +1,6 @@
 #include "TestUtil.hpp"
 #include "moab/Core.hpp"
+#include "TagInfo.hpp"
 
 using namespace moab;
 
@@ -15,8 +16,8 @@ static const char example_eul[] = "/io/camEul26x48x96.t3.nc";
 #endif
 
 // CAM-EUL
-void test_read_write_T();
-void test_read_write_gw();
+void test_read_write_T_gw();
+void test_check_T_gw_values();
 
 ErrorCode get_options(std::string& opts);
 
@@ -32,8 +33,8 @@ int main(int argc, char* argv[])
   argv[0] = argv[argc - argc]; // To remove the warnings in serial mode about unused variables
 #endif
 
-  result += RUN_TEST(test_read_write_T);
-  result += RUN_TEST(test_read_write_gw);
+  result += RUN_TEST(test_read_write_T_gw);
+  result += RUN_TEST(test_check_T_gw_values);
 
 #ifdef USE_MPI
   fail = MPI_Finalize();
@@ -44,7 +45,7 @@ int main(int argc, char* argv[])
   return result;
 }
 
-void test_read_write_T()
+void test_read_write_T_gw()
 {
   Core moab;
   Interface& mb = moab;
@@ -53,7 +54,7 @@ void test_read_write_T()
   ErrorCode rval = get_options(orig);
   CHECK_ERR(rval);
 
-  // We will have to read without mesh and without var first, to create some tags that we need
+  // We will have to read without mesh and without var first, to create some conventional tags that we need
   // later when we write
   std::string opts;
   opts = orig + std::string(";DEBUG_IO=3;NOMESH;VARIABLE=");
@@ -64,54 +65,88 @@ void test_read_write_T()
   rval = mb.create_meshset(MESHSET_SET, set);
   CHECK_ERR(rval);
 
+  // Load header info only (no mesh, no variables)
+  // This will create some conventional tags
   rval = mb.load_file(example_eul, &set, opts.c_str());
   CHECK_ERR(rval);
 
-  // Load variable T, and the mesh
-  opts= orig + std::string(";DEBUG_IO=3;VARIABLE=T");
+  // Load non-set variable T, set variable gw, and the mesh
+  opts= orig + std::string(";DEBUG_IO=3;VARIABLE=T,gw");
   rval = mb.load_file(example_eul, &set, opts.c_str());
   CHECK_ERR(rval);
 
-  // This test will write information about variable T
+  // This test will write information about variable T and gw
+  // To load the output file with mesh, variable gw is required
   std::string writeopts;
-  writeopts = std::string(";;VARIABLE=T;DEBUG_IO=2;");
-  rval = mb.write_file( "testT.nc", 0, writeopts.c_str(), &set, 1);
+  writeopts = std::string(";;VARIABLE=T,gw;DEBUG_IO=2;");
+  rval = mb.write_file("testTgw.nc", 0, writeopts.c_str(), &set, 1);
   CHECK_ERR(rval);
 }
 
-void test_read_write_gw()
+void test_check_T_gw_values()
 {
   Core moab;
   Interface& mb = moab;
 
-  std::string orig;
-  ErrorCode rval = get_options(orig);
-  CHECK_ERR(rval);
-
-  // We will have to read without mesh and without var first, to create some tags that we need
-  // later when we write
   std::string opts;
-  opts = orig + std::string(";DEBUG_IO=3;NOMESH;VARIABLE=");
+  ErrorCode rval = get_options(opts);
+  CHECK_ERR(rval);
 
-  // Need a set for nomesh to work right
-  // This set will have as tags a lot of header information, that will be used for writing back the file
   EntityHandle set;
   rval = mb.create_meshset(MESHSET_SET, set);
   CHECK_ERR(rval);
 
-  rval = mb.load_file(example_eul, &set, opts.c_str());
+  // Load non-set variable T, set variable gw, and the mesh
+  opts += std::string(";VARIABLE=T,gw");
+  rval = mb.load_file("testTgw.nc", &set, opts.c_str());
   CHECK_ERR(rval);
 
-  // Load variable gw (gauss weights), and the mesh
-  opts= orig + std::string(";DEBUG_IO=3;VARIABLE=gw");
-  rval = mb.load_file(example_eul, &set, opts.c_str());
-  CHECK_ERR(rval);
+  int procs = 1;
+#ifdef USE_MPI
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
+  procs = pcomm->proc_config().proc_size();
+#endif
 
-  // First test will write information about variable gw
-  std::string writeopts;
-  writeopts = std::string(";;VARIABLE=gw;DEBUG_IO=2;");
-  rval = mb.write_file( "testgw.nc", 0, writeopts.c_str(), &set, 1);
-  CHECK_ERR(rval);
+  // Only test serial case for the time being
+  if (1 == procs) {
+    // Get tag gw
+    Tag gw_tag;
+    rval = mb.tag_get_handle("gw", 0, MB_TYPE_OPAQUE, gw_tag, MB_TAG_SPARSE | MB_TAG_VARLEN);
+    CHECK_ERR(rval);
+
+    // Check some values of tag gw
+    const void* var_data;
+    int var_len = 0;
+    rval = mb.tag_get_by_ptr(gw_tag, &set, 1, &var_data, &var_len);
+    CHECK_ERR(rval);
+    CHECK_EQUAL(48, var_len);
+    double* gw_val = (double*)var_data;
+    double eps = 1e-10;
+    CHECK_REAL_EQUAL(0.00315334605230584, gw_val[0], eps);
+    CHECK_REAL_EQUAL(0.0647376968126839, gw_val[23], eps);
+    CHECK_REAL_EQUAL(0.0647376968126839, gw_val[24], eps);
+    CHECK_REAL_EQUAL(0.00315334605230584, gw_val[47], eps);
+
+    // Get tag T0
+    Tag Ttag0;
+    rval = mb.tag_get_handle("T0", 26, MB_TYPE_DOUBLE, Ttag0);
+    CHECK_ERR(rval);
+
+    // Check some values of tag T0
+    double val[4 * 26];
+    Range global_quads;
+    rval = mb.get_entities_by_type(set, MBQUAD, global_quads);
+    CHECK_ERR(rval);
+    CHECK_EQUAL((size_t)4608, global_quads.size());
+    EntityHandle gloabl_quad_ents[] = {global_quads[0], global_quads[2303], global_quads[2304], global_quads[4607]};
+    rval = mb.tag_get_data(Ttag0, &gloabl_quad_ents[0], 4, val);
+    CHECK_ERR(rval);
+    eps = 0.0001;
+    CHECK_REAL_EQUAL(252.8529, val[0 * 26], eps); // First global quad
+    CHECK_REAL_EQUAL(232.6670, val[1 * 26], eps); // 2304th global quad
+    CHECK_REAL_EQUAL(232.6458, val[2 * 26], eps); // 2305th global quad
+    CHECK_REAL_EQUAL(200.6828, val[3 * 26], eps); // Last global quad
+  }
 }
 
 ErrorCode get_options(std::string& opts)

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list