[MOAB-dev] commit/MOAB: danwu: Added two test cases to write_nc for CAM_EUL, to test writing variable T which is read from three files (each file contains a single timestep).

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri May 16 13:56:53 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/cf2ba4e531d5/
Changeset:   cf2ba4e531d5
Branch:      master
User:        danwu
Date:        2014-05-16 20:56:36
Summary:     Added two test cases to write_nc for CAM_EUL, to test writing variable T which is read from three files (each file contains a single timestep).

Affected #:  3 files

diff --git a/test/io/Makefile.am b/test/io/Makefile.am
index 13b7046..6d01313 100644
--- a/test/io/Makefile.am
+++ b/test/io/Makefile.am
@@ -91,11 +91,12 @@ MOSTLYCLEANFILES = dumped_acis.sat \
                    mb_write.g \
                    mb_write2.g \
                    singlecyl_tmp.ccmg \
+                   test_eul_across_files.nc \
+                   test_eul_append.nc \
+                   test_eul_ghosting.nc \
+                   test_eul_T2.nc \
                    test_eul_T.nc \
                    test_fv_T.nc \
                    test_gcrm_vars.nc \
                    test_homme_T.nc \
-                   test_mpas_vars.nc \
-                   test_eul_T2.nc \
-                   test_eul_append.nc \
-                   test_eul_ghosting.nc
+                   test_mpas_vars.nc

diff --git a/test/io/write_nc.cpp b/test/io/write_nc.cpp
index b0dc3db..d59829d 100644
--- a/test/io/write_nc.cpp
+++ b/test/io/write_nc.cpp
@@ -5,12 +5,18 @@ using namespace moab;
 
 #ifdef MESHDIR
 static const char example_eul[] = STRINGIFY(MESHDIR) "/io/eul26x48x96.t.3.nc";
+static const char example_eul_t0[] = STRINGIFY(MESHDIR) "/io/eul26x48x96.t0.nc";
+static const char example_eul_t1[] = STRINGIFY(MESHDIR) "/io/eul26x48x96.t1.nc";
+static const char example_eul_t2[] = STRINGIFY(MESHDIR) "/io/eul26x48x96.t2.nc";
 static const char example_fv[] = STRINGIFY(MESHDIR) "/io/fv26x46x72.t.3.nc";
 static const char example_homme[] = STRINGIFY(MESHDIR) "/io/homme26x3458.t.3.nc";
 static const char example_mpas[] = STRINGIFY(MESHDIR) "/io/mpasx1.642.t.2.nc";
 static const char example_gcrm[] = STRINGIFY(MESHDIR) "/io/gcrm_r3.nc";
 #else
 static const char example_eul[] = "/io/eul26x48x96.t.3.nc";
+static const char example_eul_t0[] = "/io/eul26x48x96.t0.nc";
+static const char example_eul_t1[] = "/io/eul26x48x96.t1.nc";
+static const char example_eul_t2[] = "/io/eul26x48x96.t2.nc";
 static const char example_fv[] = "/io/fv26x46x72.t.3.nc";
 static const char example_homme[] = "/io/homme26x3458.t.3.nc";
 static const char example_mpas[] = "/io/mpasx1.642.t.2.nc";
@@ -48,7 +54,6 @@ void test_homme_check_T();
 void test_mpas_read_write_vars();
 void test_mpas_check_vars();
 
-
 // GCRM
 void test_gcrm_read_write_vars();
 //void test_gcrm_check_vars();
@@ -61,6 +66,10 @@ void test_eul_check_timestep();
 void test_eul_read_write_append();
 void test_eul_check_append();
 
+// Test writing variables with timesteps spread across files
+void test_eul_read_write_across_files();
+void test_eul_check_across_files();
+
 #ifdef USE_MPI
 // Test mesh with ghosted entities
 void test_eul_read_write_ghosting();
@@ -105,6 +114,9 @@ int main(int argc, char* argv[])
   result += RUN_TEST(test_eul_read_write_append);
   result += RUN_TEST(test_eul_check_append);
 
+  result += RUN_TEST(test_eul_read_write_across_files);
+  result += RUN_TEST(test_eul_check_across_files);
+
 #ifdef USE_MPI
   result += RUN_TEST(test_eul_read_write_ghosting);
   result += RUN_TEST(test_eul_check_ghosting);
@@ -210,15 +222,15 @@ void test_eul_check_T()
 #endif
 
     NCDF_SIZE start[] = {0, 0, 0, 0};
-    NCDF_SIZE count[] = {2, 1, 48, 96}; // Read two timesteps and one level
+    NCDF_SIZE count[] = {3, 1, 48, 96}; // Read three timesteps and one level
 
     // Read variable T on 48 * 96 quads (first level)
-    double T_vals_lev1[2 * 48 * 96];
+    double T_vals_lev1[3 * 48 * 96];
     success = NCFUNC(get_vara_double)(ncid, T_id, start, count, T_vals_lev1);
     CHECK_EQUAL(0, success);
 
     // Read variable T on 48 * 96 quads (last level)
-    double T_vals_lev26[2 * 48 * 96];
+    double T_vals_lev26[3 * 48 * 96];
     start[1] = 25;
     success = NCFUNC(get_vara_double)(ncid, T_id, start, count, T_vals_lev26);
     CHECK_EQUAL(0, success);
@@ -244,10 +256,15 @@ void test_eul_check_T()
     CHECK_REAL_EQUAL(232.6458, T_vals_lev1[2304], eps); // Median quad
     CHECK_REAL_EQUAL(200.6828, T_vals_lev1[4607], eps); // Last quad
     // Timestep 1
-    CHECK_REAL_EQUAL(241.7352, T_vals_lev1[0 + 4608], eps); // First quad
+    CHECK_REAL_EQUAL(241.7353, T_vals_lev1[0 + 4608], eps); // First quad
     CHECK_REAL_EQUAL(234.7536, T_vals_lev1[2303 + 4608], eps); // Median quad
     CHECK_REAL_EQUAL(234.4739, T_vals_lev1[2304 + 4608], eps); // Median quad
     CHECK_REAL_EQUAL(198.2482, T_vals_lev1[4607 + 4608], eps); // Last quad
+    // Timestep 2
+    CHECK_REAL_EQUAL(224.1966, T_vals_lev1[0 + 4608*2], eps); // First quad
+    CHECK_REAL_EQUAL(236.1358, T_vals_lev1[2303 + 4608*2], eps); // Median quad
+    CHECK_REAL_EQUAL(235.9430, T_vals_lev1[2304 + 4608*2], eps); // Median quad
+    CHECK_REAL_EQUAL(218.7719, T_vals_lev1[4607 + 4608*2], eps); // Last quad
 
     // Check T values at some strategically chosen places (last level)
     // Timestep 0
@@ -260,6 +277,11 @@ void test_eul_check_T()
     CHECK_REAL_EQUAL(299.9290, T_vals_lev26[2303 + 4608], eps); // Median quad
     CHECK_REAL_EQUAL(299.7614, T_vals_lev26[2304 + 4608], eps); // Median quad
     CHECK_REAL_EQUAL(241.1057, T_vals_lev26[4607 + 4608], eps); // Last quad
+    // Timestep 2
+    CHECK_REAL_EQUAL(232.7547, T_vals_lev26[0 + 4608*2], eps); // First quad
+    CHECK_REAL_EQUAL(300.2307, T_vals_lev26[2303 + 4608*2], eps); // Median quad
+    CHECK_REAL_EQUAL(299.2372, T_vals_lev26[2304 + 4608*2], eps); // Median quad
+    CHECK_REAL_EQUAL(242.8274, T_vals_lev26[4607 + 4608*2], eps); // Last quad
 
     eps = 1e-10;
 
@@ -1055,6 +1077,165 @@ void test_eul_check_append()
   }
 }
 
+void test_eul_read_write_across_files()
+{
+  int procs = 1;
+#ifdef USE_MPI
+  MPI_Comm_size(MPI_COMM_WORLD, &procs);
+#endif
+
+// We will not test NC writer in parallel without pnetcdf support
+#ifndef PNETCDF_FILE
+  if (procs > 1)
+    return;
+#endif
+
+  Core moab;
+  Interface& mb = moab;
+
+  std::string read_opts;
+
+  EntityHandle set;
+  ErrorCode rval = mb.create_meshset(MESHSET_SET, set);
+  CHECK_ERR(rval);
+
+  // This file contains single timestep 2 (option TIMESTEP=0 will be implicitly used)
+  // Read T as tag T2 with option TIMESTEPBASE=2
+  get_eul_read_options(read_opts);
+  read_opts += ";VARIABLE=T;TIMESTEPBASE=2;DEBUG_IO=0";
+  rval = mb.load_file(example_eul_t2, &set, read_opts.c_str());
+  CHECK_ERR(rval);
+
+  // This file contains single timestep 0 (option TIMESTEP=0 will be implicitly used)
+  // Read T as tag T0 with option TIMESTEPBASE=0
+  get_eul_read_options(read_opts);
+  read_opts += ";VARIABLE=T;TIMESTEPBASE=0;NOMESH;DEBUG_IO=0";
+  rval = mb.load_file(example_eul_t0, &set, read_opts.c_str());
+  CHECK_ERR(rval);
+
+  // This file contains single timestep 1 (option TIMESTEP=0 will be implicitly used)
+  // Read T as tag T1 with option TIMESTEPBASE=1
+  get_eul_read_options(read_opts);
+  read_opts += ";VARIABLE=T;TIMESTEPBASE=1;NOMESH;DEBUG_IO=0";
+  rval = mb.load_file(example_eul_t1, &set, read_opts.c_str());
+  CHECK_ERR(rval);
+
+  // Write variable T with 3 timesteps
+  std::string write_opts = ";;VARIABLE=T;TIMESTEP=0,1,2;DEBUG_IO=0";
+#ifdef USE_MPI
+  // Use parallel options
+  write_opts += ";PARALLEL=WRITE_PART";
+#endif
+  if (procs > 1)
+    rval = mb.write_file("test_par_eul_across_files.nc", 0, write_opts.c_str(), &set, 1);
+  else
+    rval = mb.write_file("test_eul_across_files.nc", 0, write_opts.c_str(), &set, 1);
+  CHECK_ERR(rval);
+}
+
+void test_eul_check_across_files()
+{
+  int rank = 0;
+  int procs = 1;
+#ifdef USE_MPI
+  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+  MPI_Comm_size(MPI_COMM_WORLD, &procs);
+#endif
+
+// We will not test NC writer in parallel without pnetcdf support
+#ifndef PNETCDF_FILE
+  if (procs > 1)
+    return;
+#endif
+
+  if (0 == rank) {
+    int ncid;
+    int success;
+
+    std::string filename;
+    if (procs > 1)
+      filename = "test_par_eul_across_files.nc";
+    else
+      filename = "test_eul_across_files.nc";
+
+#ifdef PNETCDF_FILE
+    success = NCFUNC(open)(MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid);
+#else
+    success = NCFUNC(open)(filename.c_str(), NC_NOWRITE, &ncid);
+#endif
+    CHECK_EQUAL(0, success);
+
+    int T_id;
+    success = NCFUNC(inq_varid)(ncid, "T", &T_id);
+    CHECK_EQUAL(0, success);
+
+#ifdef PNETCDF_FILE
+    // Enter independent I/O mode
+    success = NCFUNC(begin_indep_data)(ncid);
+    CHECK_EQUAL(0, success);
+#endif
+
+    NCDF_SIZE start[] = {0, 0, 0, 0};
+    NCDF_SIZE count[] = {3, 1, 48, 96}; // Read three timesteps and one level
+
+    // Read variable T on 48 * 96 quads (first level)
+    double T_vals_lev1[3 * 48 * 96];
+    success = NCFUNC(get_vara_double)(ncid, T_id, start, count, T_vals_lev1);
+    CHECK_EQUAL(0, success);
+
+    // Read variable T on 48 * 96 quads (last level)
+    double T_vals_lev26[3 * 48 * 96];
+    start[1] = 25;
+    success = NCFUNC(get_vara_double)(ncid, T_id, start, count, T_vals_lev26);
+    CHECK_EQUAL(0, success);
+
+#ifdef PNETCDF_FILE
+    // End independent I/O mode
+    success = NCFUNC(end_indep_data)(ncid);
+    CHECK_EQUAL(0, success);
+#endif
+
+    double eps = 0.0001;
+
+    // Check T values at some strategically chosen places (first level)
+    // Timestep 0
+    CHECK_REAL_EQUAL(252.8529, T_vals_lev1[0], eps); // First quad
+    CHECK_REAL_EQUAL(232.6670, T_vals_lev1[2303], eps); // Median quad
+    CHECK_REAL_EQUAL(232.6458, T_vals_lev1[2304], eps); // Median quad
+    CHECK_REAL_EQUAL(200.6828, T_vals_lev1[4607], eps); // Last quad
+    // Timestep 1
+    CHECK_REAL_EQUAL(241.7353, T_vals_lev1[0 + 4608], eps); // First quad
+    CHECK_REAL_EQUAL(234.7536, T_vals_lev1[2303 + 4608], eps); // Median quad
+    CHECK_REAL_EQUAL(234.4739, T_vals_lev1[2304 + 4608], eps); // Median quad
+    CHECK_REAL_EQUAL(198.2482, T_vals_lev1[4607 + 4608], eps); // Last quad
+    // Timestep 2
+    CHECK_REAL_EQUAL(224.1966, T_vals_lev1[0 + 4608*2], eps); // First quad
+    CHECK_REAL_EQUAL(236.1358, T_vals_lev1[2303 + 4608*2], eps); // Median quad
+    CHECK_REAL_EQUAL(235.9430, T_vals_lev1[2304 + 4608*2], eps); // Median quad
+    CHECK_REAL_EQUAL(218.7719, T_vals_lev1[4607 + 4608*2], eps); // Last quad
+
+    // Check T values at some strategically chosen places (last level)
+    // Timestep 0
+    CHECK_REAL_EQUAL(253.1395, T_vals_lev26[0], eps); // First quad
+    CHECK_REAL_EQUAL(299.0477, T_vals_lev26[2303], eps); // Median quad
+    CHECK_REAL_EQUAL(300.0627, T_vals_lev26[2304], eps); // Median quad
+    CHECK_REAL_EQUAL(241.1817, T_vals_lev26[4607], eps); // Last quad
+    // Timestep 1
+    CHECK_REAL_EQUAL(242.9252, T_vals_lev26[0 + 4608], eps); // First quad
+    CHECK_REAL_EQUAL(299.9290, T_vals_lev26[2303 + 4608], eps); // Median quad
+    CHECK_REAL_EQUAL(299.7614, T_vals_lev26[2304 + 4608], eps); // Median quad
+    CHECK_REAL_EQUAL(241.1057, T_vals_lev26[4607 + 4608], eps); // Last quad
+    // Timestep 2
+    CHECK_REAL_EQUAL(232.7547, T_vals_lev26[0 + 4608*2], eps); // First quad
+    CHECK_REAL_EQUAL(300.2307, T_vals_lev26[2303 + 4608*2], eps); // Median quad
+    CHECK_REAL_EQUAL(299.2372, T_vals_lev26[2304 + 4608*2], eps); // Median quad
+    CHECK_REAL_EQUAL(242.8274, T_vals_lev26[4607 + 4608*2], eps); // Last quad
+
+    success = NCFUNC(close)(ncid);
+    CHECK_EQUAL(0, success);
+  }
+}
+
 #ifdef USE_MPI
 // NC writer should filter entities that are not owned, e.g. ghosted elements
 void test_eul_read_write_ghosting()

diff --git a/test/parallel/Makefile.am b/test/parallel/Makefile.am
index 2736605..b42ba0b 100644
--- a/test/parallel/Makefile.am
+++ b/test/parallel/Makefile.am
@@ -124,11 +124,12 @@ MOSTLYCLEANFILES = mhdf_ll.h5m tmp0.h5m tmp1.h5m tmp2.h5m tmp3.h5m \
                    test_mpas_no_mixed_elements.h5m \
                    test_mpas_rcbzoltan.h5m \
                    test_mpas_rcbzoltan_no_mixed_elements.h5m \
+                   test_par_eul_across_files.nc \
+                   test_par_eul_append.nc \
+                   test_par_eul_ghosting.nc \
+                   test_par_eul_T2.nc \
                    test_par_eul_T.nc \
                    test_par_fv_T.nc \
                    test_par_gcrm_vars.nc \
                    test_par_homme_T.nc \
-                   test_par_mpas_vars.nc \
-                   test_par_eul_T2.nc \
-                   test_par_eul_append.nc \
-                   test_par_eul_ghosting.nc
+                   test_par_mpas_vars.nc

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