[MOAB-dev] commit/MOAB: danwu: In unit test read_ucd_nc, added test_gather_onevar(). Also removed gather set testing code from test_read_onevar().
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Nov 22 16:36:31 CST 2013
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/83c399ef0096/
Changeset: 83c399ef0096
Branch: master
User: danwu
Date: 2013-11-22 23:36:16
Summary: In unit test read_ucd_nc, added test_gather_onevar(). Also removed gather set testing code from test_read_onevar().
Affected #: 1 file
diff --git a/test/io/read_ucd_nc.cpp b/test/io/read_ucd_nc.cpp
index b28eb2d..b6bec41 100644
--- a/test/io/read_ucd_nc.cpp
+++ b/test/io/read_ucd_nc.cpp
@@ -2,6 +2,7 @@
#include "moab/Core.hpp"
#include "moab/ReadUtilIface.hpp"
#include "TagInfo.hpp"
+#include "MBTagConventions.hpp"
using namespace moab;
@@ -21,9 +22,10 @@ void test_read_onevar();
void test_read_onetimestep();
void test_read_nomesh();
void test_read_novars();
-void test_read_dim_vars();
+void test_read_dim_vars(); // Test reading dimension variables
+void test_gather_onevar(); // Test gather set with one variable
-ErrorCode get_options(std::string& opts);
+void get_options(std::string& opts);
int main(int argc, char* argv[])
{
@@ -43,6 +45,7 @@ int main(int argc, char* argv[])
result += RUN_TEST(test_read_nomesh);
result += RUN_TEST(test_read_novars);
result += RUN_TEST(test_read_dim_vars);
+ result += RUN_TEST(test_gather_onevar);
#ifdef USE_MPI
fail = MPI_Finalize();
@@ -59,10 +62,9 @@ void test_read_all()
Interface& mb = moab;
std::string opts;
- ErrorCode rval = get_options(opts);
- CHECK_ERR(rval);
+ get_options(opts);
- rval = mb.load_file(example, NULL, opts.c_str());
+ ErrorCode rval = mb.load_file(example, NULL, opts.c_str());
CHECK_ERR(rval);
// Check for proper tags
@@ -80,23 +82,20 @@ void test_read_onevar()
Interface& mb = moab;
std::string opts;
- ErrorCode rval = get_options(opts);
- CHECK_ERR(rval);
+ get_options(opts);
+ // Read mesh and read vertex variable T at all timesteps
opts += std::string(";VARIABLE=T");
- // Create gather set
- opts += std::string(";GATHER_SET=");
- rval = mb.load_file(example, NULL, opts.c_str());
+ ErrorCode rval = mb.load_file(example, NULL, opts.c_str());
CHECK_ERR(rval);
- // Check values of tag T0 at some strategically chosen places below
int procs = 1;
#ifdef USE_MPI
ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
procs = pcomm->proc_config().proc_size();
#endif
- // Make check runs this test in one processor
+ // Make check runs this test on one processor
if (1 == procs) {
// Check for proper tags
Tag Ttag0, Ttag1;
@@ -109,23 +108,7 @@ void test_read_onevar()
Range verts;
rval = mb.get_entities_by_type(0, MBVERTEX, verts);
CHECK_ERR(rval);
- CHECK_EQUAL((size_t)6916, verts.size()); // Gather set vertices included
-
- // Get gather set
- EntityHandle gather_set;
- ReadUtilIface* readUtilIface;
- mb.query_interface(readUtilIface);
- rval = readUtilIface->get_gather_set(gather_set);
- CHECK_ERR(rval);
-
- // Get gather set entities
- Range gather_ents;
- rval = mb.get_entities_by_handle(gather_set, gather_ents);
- CHECK_ERR(rval);
-
- // Remove gather set vertices
- verts = subtract(verts, gather_ents);
- CHECK_EQUAL((size_t)3458, verts.size()); // Gather set vertices excluded
+ CHECK_EQUAL((size_t)3458, verts.size());
// Get all values of tag T0
int count;
@@ -137,7 +120,7 @@ void test_read_onevar()
const double eps = 0.0001;
double* data = (double*) Tbuf;
- // Check first level values at some vertices
+ // Check first level values on 4 strategically selected vertices
CHECK_REAL_EQUAL(233.1136, data[0 * 26], eps); // First vert
CHECK_REAL_EQUAL(236.1505, data[1728 * 26], eps); // Median vert
CHECK_REAL_EQUAL(235.7722, data[1729 * 26], eps); // Median vert
@@ -151,11 +134,10 @@ void test_read_onetimestep()
Interface& mb = moab;
std::string opts;
- ErrorCode rval = get_options(opts);
- CHECK_ERR(rval);
+ get_options(opts);
opts += std::string(";TIMESTEP=1");
- rval = mb.load_file(example, NULL, opts.c_str());
+ ErrorCode rval = mb.load_file(example, NULL, opts.c_str());
CHECK_ERR(rval);
// Check for proper tags
@@ -178,8 +160,7 @@ void test_read_nomesh()
CHECK_ERR(rval);
std::string orig, opts;
- rval = get_options(orig);
- CHECK_ERR(rval);
+ get_options(orig);
opts = orig + std::string(";TIMESTEP=0");
rval = mb.load_file(example, &file_set, opts.c_str());
@@ -214,8 +195,7 @@ void test_read_novars()
CHECK_ERR(rval);
std::string orig, opts;
- rval = get_options(orig);
- CHECK_ERR(rval);
+ get_options(orig);
opts = orig + std::string(";NOMESH;VARIABLE=");
rval = mb.load_file(example, &set, opts.c_str());
@@ -260,8 +240,7 @@ void test_read_dim_vars()
CHECK_ERR(rval);
std::string orig, opts;
- rval = get_options(orig);
- CHECK_ERR(rval);
+ get_options(orig);
opts = orig + std::string(";NOMESH;VARIABLE=");
rval = mb.load_file(example, &file_set, opts.c_str());
@@ -345,14 +324,85 @@ void test_read_dim_vars()
CHECK_EQUAL(3458, ncol_val[0]);
}
-ErrorCode get_options(std::string& opts)
+void test_gather_onevar()
+{
+ Core moab;
+ Interface& mb = moab;
+
+ EntityHandle file_set;
+ ErrorCode rval = mb.create_meshset(MESHSET_SET, file_set);
+ CHECK_ERR(rval);
+
+ std::string opts;
+ get_options(opts);
+
+ // Read vertex variable T and create gather set on processor 0
+ opts += ";VARIABLE=T;GATHER_SET=0";
+ rval = mb.load_file(example, &file_set, opts.c_str());
+ CHECK_ERR(rval);
+
+#ifdef USE_MPI
+ ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
+ int rank = pcomm->proc_config().proc_rank();
+
+ Range verts, verts_owned;
+ rval = mb.get_entities_by_type(file_set, MBVERTEX, verts);
+ CHECK_ERR(rval);
+
+ // Get local owned vertices
+ rval = pcomm->filter_pstatus(verts, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &verts_owned);
+ CHECK_ERR(rval);
+
+ EntityHandle gather_set = 0;
+ if (0 == rank) {
+ // Get gather set
+ ReadUtilIface* readUtilIface;
+ mb.query_interface(readUtilIface);
+ rval = readUtilIface->get_gather_set(gather_set);
+ CHECK_ERR(rval);
+ assert(gather_set != 0);
+ }
+
+ Tag Ttag0, gid_tag;
+ rval = mb.tag_get_handle("T0", 26, MB_TYPE_DOUBLE, Ttag0, MB_TAG_DENSE);
+ CHECK_ERR(rval);
+
+ rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag, MB_TAG_DENSE);
+ CHECK_ERR(rval);
+
+ pcomm->gather_data(verts_owned, Ttag0, gid_tag, gather_set, 0);
+
+ if (0 == rank) {
+ // Get gather set vertices
+ Range gather_set_verts;
+ rval = mb.get_entities_by_type(gather_set, MBVERTEX, gather_set_verts);
+ CHECK_ERR(rval);
+ CHECK_EQUAL((size_t)3458, gather_set_verts.size());
+
+ // Get T0 tag values on 4 strategically selected gather set vertices
+ double T0_val[4 * 26];
+ EntityHandle vert_ents[] = {gather_set_verts[0], gather_set_verts[1728],
+ gather_set_verts[1729], gather_set_verts[3457]};
+ rval = mb.tag_get_data(Ttag0, vert_ents, 4, T0_val);
+ CHECK_ERR(rval);
+
+ const double eps = 0.001;
+
+ // Check first level values
+ CHECK_REAL_EQUAL(233.1136, T0_val[0 * 26], eps); // First vert
+ CHECK_REAL_EQUAL(236.1505, T0_val[1 * 26], eps); // Median vert
+ CHECK_REAL_EQUAL(235.7722, T0_val[2 * 26], eps); // Median vert
+ CHECK_REAL_EQUAL(234.0416, T0_val[3 * 26], eps); // Last vert
+ }
+#endif
+}
+
+void get_options(std::string& opts)
{
#ifdef USE_MPI
// Use parallel options
opts = std::string(";;PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL");
- return MB_SUCCESS;
#else
opts = std::string(";;");
- return MB_SUCCESS;
#endif
}
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