[MOAB-dev] commit/MOAB: 40 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sun Nov 10 11:38:01 CST 2013


40 new commits in MOAB:

https://bitbucket.org/fathomteam/moab/commits/3e77eda03ea6/
Changeset:   3e77eda03ea6
Branch:      None
User:        iulian07
Date:        2013-09-19 02:40:13
Summary:     local changes to resolve skinner issues

Affected #:  7 files

diff --git a/src/MergeMesh.cpp b/src/MergeMesh.cpp
index 4cc8158..7293e17 100644
--- a/src/MergeMesh.cpp
+++ b/src/MergeMesh.cpp
@@ -61,7 +61,7 @@ moab::ErrorCode MergeMesh::merge_entities(moab::Range &elems,
   // get the skin of the entities
   moab::Skinner skinner(mbImpl);
   moab::Range skin_range;
-  moab::ErrorCode result = skinner.find_skin(0, elems, 0, skin_range);
+  moab::ErrorCode result = skinner.find_skin(0, elems, 0, skin_range, false, false);
   if (moab::MB_SUCCESS != result) return result;
 
   // create a tag to mark merged-to entity; reuse tree_root
@@ -232,16 +232,16 @@ moab::ErrorCode MergeMesh::merge_higher_dimensions(moab::Range &elems)
   for(int dim = 1; dim <3; dim++){
     skinEnts.clear();
     moreDeadEnts.clear();
-    result = skinner.find_skin(0, elems, dim, skinEnts);
+    result = skinner.find_skin(0, elems, dim, skinEnts, false, false);
     //Go through each skin entity and see if it shares adjacancies with another entity
     for(moab::Range::iterator skinIt = skinEnts.begin(); skinIt != skinEnts.end(); skinIt++){
       adj.clear();
       //Get the adjacencies 1 dimension lower
-      result = mbImpl->get_adjacencies(&(*skinIt), 1, dim-1, true, adj);
+      result = mbImpl->get_adjacencies(&(*skinIt), 1, dim-1, false, adj);
       if(result != moab::MB_SUCCESS) return result;
       //See what other entities share these adjacencies
       matches.clear();
-      result = mbImpl->get_adjacencies(adj, dim, true, matches, moab::Interface::INTERSECT);
+      result = mbImpl->get_adjacencies(adj, dim, false, matches, moab::Interface::INTERSECT);
       if(result != moab::MB_SUCCESS) return result;
       //If there is more than one entity, then we have some to merge and erase
       if(matches.size() > 1){

diff --git a/src/Skinner.cpp b/src/Skinner.cpp
index b5fd24e..c3c6b1b 100644
--- a/src/Skinner.cpp
+++ b/src/Skinner.cpp
@@ -1015,11 +1015,12 @@ ErrorCode Skinner::find_skin(const EntityHandle this_set,
                              const Range &entities,
                                  int dim,
                                  Range &skin_entities,
-                                 bool create_vert_elem_adjs) 
+                                 bool create_vert_elem_adjs,
+                                 bool create_skin_elements)
 {
   Range tmp_skin;
   ErrorCode result = find_skin(this_set, entities, (dim==0), tmp_skin, 0,
-                                 create_vert_elem_adjs, true);
+                                 create_vert_elem_adjs, create_skin_elements);
   if (MB_SUCCESS != result || tmp_skin.empty()) return result;
   
   if (tmp_skin.all_of_dimension(dim)) {
@@ -1029,7 +1030,7 @@ ErrorCode Skinner::find_skin(const EntityHandle this_set,
       skin_entities.merge(tmp_skin);
   }
   else {
-    result = thisMB->get_adjacencies( tmp_skin, dim, true, skin_entities, 
+    result = thisMB->get_adjacencies( tmp_skin, dim, create_skin_elements, skin_entities,
                                       Interface::UNION );
   }
   

diff --git a/src/moab/Skinner.hpp b/src/moab/Skinner.hpp
index 7ec5450..4eb2f51 100644
--- a/src/moab/Skinner.hpp
+++ b/src/moab/Skinner.hpp
@@ -119,7 +119,8 @@ public:
                       const Range &entities,
                       int dim,
                       Range &skin_entities,
-                      bool create_vert_elem_adjs = false);
+                      bool create_vert_elem_adjs = false,
+                      bool create_skin_elements = true);
 
   ErrorCode classify_2d_boundary( const Range &boundary,
                                      const Range &bar_elements,

diff --git a/test/mergemesh_test.cpp b/test/mergemesh_test.cpp
index 0b382e6..fca5304 100644
--- a/test/mergemesh_test.cpp
+++ b/test/mergemesh_test.cpp
@@ -38,11 +38,11 @@ int main( int argc, char* argv[] )
     }
 
     // Fixed for now
-//    const char *outfile = "mm_out.h5m";
-//    rval = iface->write_mesh( outfile);
-//    if (MB_SUCCESS != rval) {
-//        std::cerr << "Error saving file: " << outfile << std::endl;
-//        exit(2);
-//    }
+    const char *outfile = "mm_out.h5m";
+    rval = iface->write_mesh( outfile);
+    if (MB_SUCCESS != rval) {
+        std::cerr << "Error saving file: " << outfile << std::endl;
+        exit(2);
+    }
     return 0;
 }

diff --git a/tools/mbcslam/CslamUtils.hpp b/tools/mbcslam/CslamUtils.hpp
index 0f9b573..5d51ae2 100644
--- a/tools/mbcslam/CslamUtils.hpp
+++ b/tools/mbcslam/CslamUtils.hpp
@@ -15,6 +15,8 @@
 #define MAXEDGES 10
 #define MAXEDGES2 20 // used for coordinates in plane
 
+//char * CORRTAGNAME = "__correspondent";
+
 namespace moab
 {
 double dist2(double * a, double * b);

diff --git a/tools/mbcslam/Intx2MeshOnSphere.cpp b/tools/mbcslam/Intx2MeshOnSphere.cpp
index 0952ef6..21c612d 100644
--- a/tools/mbcslam/Intx2MeshOnSphere.cpp
+++ b/tools/mbcslam/Intx2MeshOnSphere.cpp
@@ -422,7 +422,11 @@ ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagE
   ErrorCode rval = mb->get_entities_by_dimension(out_set, 2, polys);
   ERRORR(rval, "can't get polygons out");
 
-  // rs2 is the red rage, arrival; rs1 is blue, departure;
+  // rs2 is the red range, arrival; rs1 is blue, departure;
+  // there is a connection between rs1 and rs2, through the corrTag
+  // corrTag is __correlation
+  // basically, mb->tag_get_data(corrTag, &(redPoly), 1, &bluePoly);
+  // also,  mb->tag_get_data(corrTag, &(bluePoly), 1, &redPoly);
   // we start from rs2 existing, then we have to update something
   std::vector<double>  currentVals(rs2.size());
   rval = mb->tag_get_data(tagElem, rs2, &currentVals[0]);

diff --git a/tools/mbcslam/diffusion.cpp b/tools/mbcslam/diffusion.cpp
index 6720c58..5ac588a 100644
--- a/tools/mbcslam/diffusion.cpp
+++ b/tools/mbcslam/diffusion.cpp
@@ -39,6 +39,7 @@ on the sphere; see CSLAM Utils case1
 
 #include "CslamUtils.hpp"
 
+char * corrTagName = "__correspondent";
 
 // non smooth scalar field
 // some input data
@@ -51,6 +52,8 @@ double T = 5;
 
 int case_number = 1; // 1, 2 (non-divergent) 3 divergent
 
+moab::Tag corrTag;
+
 int field_type = 1 ; // 1 quasi smooth, 2 - smooth, 3 non-smooth,
 #ifdef MESHDIR
 std::string TestDir( STRINGIFY(MESHDIR) );
@@ -267,16 +270,17 @@ ErrorCode compute_velocity_case1(Interface * mb, EntityHandle euler_set, Tag & t
 
   return MB_SUCCESS;
 }
-ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
-    EntityHandle lagr_set, EntityHandle out_set,
-    Tag & tagElem, int rank, int tStep)
+ErrorCode  create_lagr_mesh(Interface * mb, EntityHandle euler_set, EntityHandle lagr_set)
 {
-  ErrorCode rval = MB_SUCCESS;
+  // create the handle tag for the corresponding element / vertex
 
-  double t = tStep*T/numSteps; // numSteps is global; so is T
-  double delta_t = T/numSteps; // this is global too, actually
+  EntityHandle dum = 0;
+
+  ErrorCode result = mb->tag_get_handle(corrTagName,
+                                           1, MB_TYPE_HANDLE, corrTag,
+                                           MB_TAG_DENSE|MB_TAG_CREAT, &dum);
   Range polys;
-  rval = mb->get_entities_by_dimension(euler_set, 2, polys);
+  ErrorCode  rval = mb->get_entities_by_dimension(euler_set, 2, polys);
   CHECK_ERR(rval);
 
   Range connecVerts;
@@ -284,21 +288,22 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
   CHECK_ERR(rval);
 
   std::map<EntityHandle, EntityHandle> newNodes;
-  for (Range::iterator vit = connecVerts.begin(); vit != connecVerts.end();
-      vit++)
+  for (Range::iterator vit = connecVerts.begin(); vit != connecVerts.end(); vit++)
   {
     EntityHandle oldV = *vit;
     CartVect posi;
     rval = mb->get_coords(&oldV, 1, &(posi[0]));
     CHECK_ERR(rval);
-    // cslam utils, case 1
-    CartVect newPos;
-    departure_point_case1(posi, t, delta_t, newPos);
-    newPos = radius * newPos;
     EntityHandle new_vert;
-    rval = mb->create_vertex(&(newPos[0]), new_vert);
+    rval = mb->create_vertex(&(posi[0]), new_vert); // duplicate the position
     CHECK_ERR(rval);
     newNodes[oldV] = new_vert;
+    // set also the correspondent tag :)
+    rval = mb->tag_set_data(corrTag, &oldV, 1, &new_vert);
+    CHECK_ERR(rval);
+    // also the other side
+    rval = mb->tag_set_data(corrTag, &new_vert, 1, &oldV);
+    CHECK_ERR(rval);
   }
   for (Range::iterator it = polys.begin(); it != polys.end(); it++)
   {
@@ -317,14 +322,62 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
     EntityHandle newElement;
     rval = mb->create_element(typeElem, &new_conn[0], nnodes, newElement);
     CHECK_ERR(rval);
+    //set the corresponding tag
+    rval = mb->tag_set_data(corrTag, &q, 1, &newElement);
+    CHECK_ERR(rval);
+    rval = mb->tag_set_data(corrTag, &newElement, 1, &q);
+    CHECK_ERR(rval);
+
     rval = mb->add_entities(lagr_set, &newElement, 1);
     CHECK_ERR(rval);
   }
+
+  return MB_SUCCESS;
+}
+ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
+    EntityHandle lagr_set, EntityHandle out_set, Tag & tagElem, int rank,
+    int tStep)
+{
+  ErrorCode rval = MB_SUCCESS;
+
+  if (!corrTag)
+    return MB_FAILURE;
+  double t = tStep * T / numSteps; // numSteps is global; so is T
+  double delta_t = T / numSteps; // this is global too, actually
+  Range polys;
+  rval = mb->get_entities_by_dimension(euler_set, 2, polys);
+  CHECK_ERR(rval);
+
+  Range connecVerts;
+  rval = mb->get_connectivity(polys, connecVerts);
+  CHECK_ERR(rval);
+
+
+  // change coordinates of lagr mesh vertices
+  for (Range::iterator vit = connecVerts.begin(); vit != connecVerts.end();
+      vit++)
+  {
+    EntityHandle oldV = *vit;
+    CartVect posi;
+    rval = mb->get_coords(&oldV, 1, &(posi[0]));
+    CHECK_ERR(rval);
+    // cslam utils, case 1
+    CartVect newPos;
+    departure_point_case1(posi, t, delta_t, newPos);
+    newPos = radius * newPos; // do we need this? the radius should be 1
+    EntityHandle new_vert;
+    rval = mb->tag_get_data(corrTag, &oldV, 1, &new_vert);
+    CHECK_ERR(rval);
+    // set the new position for the new vertex
+    rval = mb->set_coords(&new_vert, 1, &(newPos[0]));
+    CHECK_ERR(rval);
+  }
+
   // so we have now the departure at the previous time
   // intersect the 2 meshes (what about some checking of convexity?) for sufficient
   // small dt, it is not an issue;
   Intx2MeshOnSphere worker(mb);
-  worker.SetRadius(1.);
+  worker.SetRadius(radius);
 
   worker.SetErrorTolerance(gtol);
   // std::cout << "error tolerance epsilon_1=" << gtol << "\n";
@@ -338,12 +391,12 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
   CHECK_ERR(rval);
 
   std::stringstream newTracer;
-  newTracer<<"Tracer" << rank<<"_"<<tStep<<  ".vtk";
+  newTracer << "Tracer" << rank << "_" << tStep << ".vtk";
   rval = mb->write_file(newTracer.str().c_str(), 0, 0, &euler_set, 1);
   CHECK_ERR(rval);
 
   std::stringstream newIntx;
-  newIntx<<"newIntx" << rank<<"_"<<tStep<<  ".vtk";
+  newIntx << "newIntx" << rank << "_" << tStep << ".vtk";
   rval = mb->write_file(newIntx.str().c_str(), 0, 0, &out_set, 1);
   CHECK_ERR(rval);
   // delete now the polygons and the lagr set ents
@@ -478,6 +531,11 @@ int main(int argc, char **argv)
   CHECK_ERR(rval);
   rval = mb.create_meshset(MESHSET_SET, lagr_set);
   CHECK_ERR(rval);
+  // copy the initial mesh in the lagrangian set
+  // initial vertices will be at the same position as euler;
+
+  rval = create_lagr_mesh(&mb, euler_set, lagr_set);
+  CHECK_ERR(rval);
   for (int i=1; i<numSteps+1; i++)
   {
     // time depends on i; t = i*T/numSteps: ( 0, T/numSteps, 2*T/numSteps, ..., T )


https://bitbucket.org/fathomteam/moab/commits/52002602be38/
Changeset:   52002602be38
Branch:      None
User:        iulian07
Date:        2013-09-19 17:43:44
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  2 files

diff --git a/MeshFiles/unittest/Makefile.am b/MeshFiles/unittest/Makefile.am
index 16dc2ed..a1784ee 100644
--- a/MeshFiles/unittest/Makefile.am
+++ b/MeshFiles/unittest/Makefile.am
@@ -1,6 +1,7 @@
 SUBDIRS = io
 
 EXTRA_DIST  = 125hex.g \
+              16_unmerged_hex.h5m \
               1hex.g \
               1khex.g \
               1tet.g \

diff --git a/test/Makefile.am b/test/Makefile.am
index 467b2a2..100285b 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -48,13 +48,13 @@ TESTS = range_test \
 	coords_connect_iterate \
 	elem_eval_test \
 	spatial_locator_test \
-        mergemesh_test \
 	test_boundbox
 
 if HDF5_FILE
   TESTS += mbfacet_test \
         gttool_test \
         cropvol_test \
+        mergemesh_test \
         mbground_test
 endif
 


https://bitbucket.org/fathomteam/moab/commits/6b2e83a6a618/
Changeset:   6b2e83a6a618
Branch:      None
User:        iulian07
Date:        2013-09-19 18:20:09
Summary:     revert skinner to initial logic

so, always create a lot of skin entities as part of merging
it is not working right for the current unmerged file uploaded by Rajeev

Affected #:  4 files

diff --git a/src/MergeMesh.cpp b/src/MergeMesh.cpp
index 7293e17..4cc8158 100644
--- a/src/MergeMesh.cpp
+++ b/src/MergeMesh.cpp
@@ -61,7 +61,7 @@ moab::ErrorCode MergeMesh::merge_entities(moab::Range &elems,
   // get the skin of the entities
   moab::Skinner skinner(mbImpl);
   moab::Range skin_range;
-  moab::ErrorCode result = skinner.find_skin(0, elems, 0, skin_range, false, false);
+  moab::ErrorCode result = skinner.find_skin(0, elems, 0, skin_range);
   if (moab::MB_SUCCESS != result) return result;
 
   // create a tag to mark merged-to entity; reuse tree_root
@@ -232,16 +232,16 @@ moab::ErrorCode MergeMesh::merge_higher_dimensions(moab::Range &elems)
   for(int dim = 1; dim <3; dim++){
     skinEnts.clear();
     moreDeadEnts.clear();
-    result = skinner.find_skin(0, elems, dim, skinEnts, false, false);
+    result = skinner.find_skin(0, elems, dim, skinEnts);
     //Go through each skin entity and see if it shares adjacancies with another entity
     for(moab::Range::iterator skinIt = skinEnts.begin(); skinIt != skinEnts.end(); skinIt++){
       adj.clear();
       //Get the adjacencies 1 dimension lower
-      result = mbImpl->get_adjacencies(&(*skinIt), 1, dim-1, false, adj);
+      result = mbImpl->get_adjacencies(&(*skinIt), 1, dim-1, true, adj);
       if(result != moab::MB_SUCCESS) return result;
       //See what other entities share these adjacencies
       matches.clear();
-      result = mbImpl->get_adjacencies(adj, dim, false, matches, moab::Interface::INTERSECT);
+      result = mbImpl->get_adjacencies(adj, dim, true, matches, moab::Interface::INTERSECT);
       if(result != moab::MB_SUCCESS) return result;
       //If there is more than one entity, then we have some to merge and erase
       if(matches.size() > 1){

diff --git a/src/Skinner.cpp b/src/Skinner.cpp
index c3c6b1b..b5fd24e 100644
--- a/src/Skinner.cpp
+++ b/src/Skinner.cpp
@@ -1015,12 +1015,11 @@ ErrorCode Skinner::find_skin(const EntityHandle this_set,
                              const Range &entities,
                                  int dim,
                                  Range &skin_entities,
-                                 bool create_vert_elem_adjs,
-                                 bool create_skin_elements)
+                                 bool create_vert_elem_adjs) 
 {
   Range tmp_skin;
   ErrorCode result = find_skin(this_set, entities, (dim==0), tmp_skin, 0,
-                                 create_vert_elem_adjs, create_skin_elements);
+                                 create_vert_elem_adjs, true);
   if (MB_SUCCESS != result || tmp_skin.empty()) return result;
   
   if (tmp_skin.all_of_dimension(dim)) {
@@ -1030,7 +1029,7 @@ ErrorCode Skinner::find_skin(const EntityHandle this_set,
       skin_entities.merge(tmp_skin);
   }
   else {
-    result = thisMB->get_adjacencies( tmp_skin, dim, create_skin_elements, skin_entities,
+    result = thisMB->get_adjacencies( tmp_skin, dim, true, skin_entities, 
                                       Interface::UNION );
   }
   

diff --git a/src/moab/Skinner.hpp b/src/moab/Skinner.hpp
index 4eb2f51..7ec5450 100644
--- a/src/moab/Skinner.hpp
+++ b/src/moab/Skinner.hpp
@@ -119,8 +119,7 @@ public:
                       const Range &entities,
                       int dim,
                       Range &skin_entities,
-                      bool create_vert_elem_adjs = false,
-                      bool create_skin_elements = true);
+                      bool create_vert_elem_adjs = false);
 
   ErrorCode classify_2d_boundary( const Range &boundary,
                                      const Range &bar_elements,

diff --git a/test/mergemesh_test.cpp b/test/mergemesh_test.cpp
index fca5304..0b382e6 100644
--- a/test/mergemesh_test.cpp
+++ b/test/mergemesh_test.cpp
@@ -38,11 +38,11 @@ int main( int argc, char* argv[] )
     }
 
     // Fixed for now
-    const char *outfile = "mm_out.h5m";
-    rval = iface->write_mesh( outfile);
-    if (MB_SUCCESS != rval) {
-        std::cerr << "Error saving file: " << outfile << std::endl;
-        exit(2);
-    }
+//    const char *outfile = "mm_out.h5m";
+//    rval = iface->write_mesh( outfile);
+//    if (MB_SUCCESS != rval) {
+//        std::cerr << "Error saving file: " << outfile << std::endl;
+//        exit(2);
+//    }
     return 0;
 }


https://bitbucket.org/fathomteam/moab/commits/01d58c2c955a/
Changeset:   01d58c2c955a
Branch:      None
User:        iulian07
Date:        2013-09-20 05:06:05
Summary:     fix transport to use correspondence between arrival and departure
with this fix, the large model works too
it uses a correspondence tag between red and blue (entity handle tag)

Affected #:  3 files

diff --git a/tools/mbcslam/CslamUtils.hpp b/tools/mbcslam/CslamUtils.hpp
index 5d51ae2..bc1223d 100644
--- a/tools/mbcslam/CslamUtils.hpp
+++ b/tools/mbcslam/CslamUtils.hpp
@@ -15,7 +15,7 @@
 #define MAXEDGES 10
 #define MAXEDGES2 20 // used for coordinates in plane
 
-//char * CORRTAGNAME = "__correspondent";
+#define CORRTAGNAME "__correspondent"
 
 namespace moab
 {

diff --git a/tools/mbcslam/Intx2MeshOnSphere.cpp b/tools/mbcslam/Intx2MeshOnSphere.cpp
index 21c612d..9dacfb9 100644
--- a/tools/mbcslam/Intx2MeshOnSphere.cpp
+++ b/tools/mbcslam/Intx2MeshOnSphere.cpp
@@ -417,9 +417,17 @@ bool Intx2MeshOnSphere::is_inside_element(double xyz[3], EntityHandle eh)
 
 ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagElem)
 {
+  EntityHandle dum = 0;
+
+  Tag corrTag;
+  ErrorCode rval = mb->tag_get_handle(CORRTAGNAME,
+                                           1, MB_TYPE_HANDLE, corrTag,
+                                           MB_TAG_DENSE|MB_TAG_CREAT, &dum);
+  ERRORR(rval, "can't get correlation tag");
+
   // get all polygons out of out_set; then see where are they coming from
   Range polys;
-  ErrorCode rval = mb->get_entities_by_dimension(out_set, 2, polys);
+  rval = mb->get_entities_by_dimension(out_set, 2, polys);
   ERRORR(rval, "can't get polygons out");
 
   // rs2 is the red range, arrival; rs1 is blue, departure;
@@ -443,14 +451,23 @@ ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagE
     int blueIndex, redIndex;
     rval =  mb->tag_get_data(blueParentTag, &poly, 1, &blueIndex);
     ERRORR(rval, "can't get blue tag");
-    //EntityHandle blue = rs1[blueIndex];
+    EntityHandle blue = rs1[blueIndex];
     rval =  mb->tag_get_data(redParentTag, &poly, 1, &redIndex);
     ERRORR(rval, "can't get red tag");
     //EntityHandle red = rs2[redIndex];
     // big assumption here, red and blue are "parallel" ;we should have an index from
     // blue to red (so a deformed blue corresponds to an arrival red)
     double areap = area_spherical_element(mb, poly, R);
-    newValues[blueIndex] += currentVals[redIndex]*areap;
+    // so the departure cell at time t (blueIndex) covers a portion of a redCell
+    // that quantity will be transported to the redCell at time t+dt
+    // the blue corresponds to a red arrival
+    EntityHandle redArr;
+    rval = mb->tag_get_data(corrTag, &blue, 1, &redArr);
+    ERRORR(rval, "can't get arrival red for corresponding ");
+    int arrRedIndex = rs2.index(redArr);
+    if (-1 == arrRedIndex)
+      ERRORR(MB_FAILURE, "can't find the red arrival index");
+    newValues[arrRedIndex] += currentVals[redIndex]*areap;
   }
   // now divide by red area (current)
   int j=0;

diff --git a/tools/mbcslam/diffusion.cpp b/tools/mbcslam/diffusion.cpp
index 5ac588a..11fd1e4 100644
--- a/tools/mbcslam/diffusion.cpp
+++ b/tools/mbcslam/diffusion.cpp
@@ -39,8 +39,6 @@ on the sphere; see CSLAM Utils case1
 
 #include "CslamUtils.hpp"
 
-char * corrTagName = "__correspondent";
-
 // non smooth scalar field
 // some input data
 double gtol = 1.e-9; // this is for geometry tolerance
@@ -276,11 +274,12 @@ ErrorCode  create_lagr_mesh(Interface * mb, EntityHandle euler_set, EntityHandle
 
   EntityHandle dum = 0;
 
-  ErrorCode result = mb->tag_get_handle(corrTagName,
+  ErrorCode rval = mb->tag_get_handle(CORRTAGNAME,
                                            1, MB_TYPE_HANDLE, corrTag,
                                            MB_TAG_DENSE|MB_TAG_CREAT, &dum);
+  CHECK_ERR(rval);
   Range polys;
-  ErrorCode  rval = mb->get_entities_by_dimension(euler_set, 2, polys);
+  rval = mb->get_entities_by_dimension(euler_set, 2, polys);
   CHECK_ERR(rval);
 
   Range connecVerts;
@@ -399,8 +398,8 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
   newIntx << "newIntx" << rank << "_" << tStep << ".vtk";
   rval = mb->write_file(newIntx.str().c_str(), 0, 0, &out_set, 1);
   CHECK_ERR(rval);
-  // delete now the polygons and the lagr set ents
-  // also, all verts that are not in euler set
+  // delete now the polygons and the elements of out_set
+  // also, all verts that are not in euler set or lagr_set
   Range allVerts;
   rval = mb->get_entities_by_dimension(0, 0, allVerts);
   CHECK_ERR(rval);
@@ -408,16 +407,20 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
   Range allElems;
   rval = mb->get_entities_by_dimension(0, 2, allElems);
   CHECK_ERR(rval);
+  // add to polys range the lagr polys
+  rval = mb->get_entities_by_dimension(lagr_set, 2, polys); // do not delete lagr set either, with its vertices
+  CHECK_ERR(rval);
+ // add to the connecVerts range all verts, from all initial polys
+  rval = mb->get_connectivity(polys, connecVerts);
+  CHECK_ERR(rval);
   Range todeleteVerts = subtract(allVerts, connecVerts);
 
   Range todeleteElem = subtract(allElems, polys);
 
+  // empty the out mesh set
   rval = mb->clear_meshset(&out_set, 1);
   CHECK_ERR(rval);
 
-  rval = mb->clear_meshset(&lagr_set, 1);
-  CHECK_ERR(rval);
-
   rval = mb->delete_entities(todeleteElem);
   CHECK_ERR(rval);
   rval = mb->delete_entities(todeleteVerts);


https://bitbucket.org/fathomteam/moab/commits/c02005ad8bb2/
Changeset:   c02005ad8bb2
Branch:      None
User:        iulian07
Date:        2013-09-20 05:33:18
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  1 file

diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index 4f2ac51..f750e78 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -232,7 +232,7 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
       conn_fname = "HommeMapping.nc";
   }
 
-  int success;
+  int success = 0;
 
   int rank = 0;
   int procs = 1;
@@ -265,9 +265,11 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
   ERRORR(rval, "Failed to get dimensions for connectivity.");
 
   // Read connectivity into temporary variable
-  int num_fine_quads, num_coarse_quads, start_idx;
+  int num_fine_quads = 0;
+  int num_coarse_quads = 0;
+  int start_idx = 0;
   std::vector<std::string>::iterator vit;
-  int idx;
+  int idx = 0;
   if ((vit = std::find(conn_names.begin(), conn_names.end(), "ncells")) != conn_names.end())
     idx = vit - conn_names.begin();
   else if ((vit = std::find(conn_names.begin(), conn_names.end(), "ncenters")) != conn_names.end())


https://bitbucket.org/fathomteam/moab/commits/3cfac41c2dee/
Changeset:   3cfac41c2dee
Branch:      None
User:        iulian07
Date:        2013-09-21 05:05:44
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  8 files

diff --git a/examples/HelloMOAB.cpp b/examples/HelloMOAB.cpp
index 6129233..6ca2b23 100644
--- a/examples/HelloMOAB.cpp
+++ b/examples/HelloMOAB.cpp
@@ -57,6 +57,8 @@ int main( int argc, char** argv )
   cout << "Number of edges is " << edges.size() <<  endl;
   cout << "Number of faces is " << faces.size() <<  endl;
   cout << "Number of elements is " << elems.size() <<  endl;
-  
+
+  delete iface;
+
   return 0;
 }

diff --git a/src/MergeMesh.cpp b/src/MergeMesh.cpp
index 4cc8158..7293e17 100644
--- a/src/MergeMesh.cpp
+++ b/src/MergeMesh.cpp
@@ -61,7 +61,7 @@ moab::ErrorCode MergeMesh::merge_entities(moab::Range &elems,
   // get the skin of the entities
   moab::Skinner skinner(mbImpl);
   moab::Range skin_range;
-  moab::ErrorCode result = skinner.find_skin(0, elems, 0, skin_range);
+  moab::ErrorCode result = skinner.find_skin(0, elems, 0, skin_range, false, false);
   if (moab::MB_SUCCESS != result) return result;
 
   // create a tag to mark merged-to entity; reuse tree_root
@@ -232,16 +232,16 @@ moab::ErrorCode MergeMesh::merge_higher_dimensions(moab::Range &elems)
   for(int dim = 1; dim <3; dim++){
     skinEnts.clear();
     moreDeadEnts.clear();
-    result = skinner.find_skin(0, elems, dim, skinEnts);
+    result = skinner.find_skin(0, elems, dim, skinEnts, false, false);
     //Go through each skin entity and see if it shares adjacancies with another entity
     for(moab::Range::iterator skinIt = skinEnts.begin(); skinIt != skinEnts.end(); skinIt++){
       adj.clear();
       //Get the adjacencies 1 dimension lower
-      result = mbImpl->get_adjacencies(&(*skinIt), 1, dim-1, true, adj);
+      result = mbImpl->get_adjacencies(&(*skinIt), 1, dim-1, false, adj);
       if(result != moab::MB_SUCCESS) return result;
       //See what other entities share these adjacencies
       matches.clear();
-      result = mbImpl->get_adjacencies(adj, dim, true, matches, moab::Interface::INTERSECT);
+      result = mbImpl->get_adjacencies(adj, dim, false, matches, moab::Interface::INTERSECT);
       if(result != moab::MB_SUCCESS) return result;
       //If there is more than one entity, then we have some to merge and erase
       if(matches.size() > 1){

diff --git a/src/Skinner.cpp b/src/Skinner.cpp
index b5fd24e..c3c6b1b 100644
--- a/src/Skinner.cpp
+++ b/src/Skinner.cpp
@@ -1015,11 +1015,12 @@ ErrorCode Skinner::find_skin(const EntityHandle this_set,
                              const Range &entities,
                                  int dim,
                                  Range &skin_entities,
-                                 bool create_vert_elem_adjs) 
+                                 bool create_vert_elem_adjs,
+                                 bool create_skin_elements)
 {
   Range tmp_skin;
   ErrorCode result = find_skin(this_set, entities, (dim==0), tmp_skin, 0,
-                                 create_vert_elem_adjs, true);
+                                 create_vert_elem_adjs, create_skin_elements);
   if (MB_SUCCESS != result || tmp_skin.empty()) return result;
   
   if (tmp_skin.all_of_dimension(dim)) {
@@ -1029,7 +1030,7 @@ ErrorCode Skinner::find_skin(const EntityHandle this_set,
       skin_entities.merge(tmp_skin);
   }
   else {
-    result = thisMB->get_adjacencies( tmp_skin, dim, true, skin_entities, 
+    result = thisMB->get_adjacencies( tmp_skin, dim, create_skin_elements, skin_entities,
                                       Interface::UNION );
   }
   

diff --git a/src/moab/Skinner.hpp b/src/moab/Skinner.hpp
index 7ec5450..4eb2f51 100644
--- a/src/moab/Skinner.hpp
+++ b/src/moab/Skinner.hpp
@@ -119,7 +119,8 @@ public:
                       const Range &entities,
                       int dim,
                       Range &skin_entities,
-                      bool create_vert_elem_adjs = false);
+                      bool create_vert_elem_adjs = false,
+                      bool create_skin_elements = true);
 
   ErrorCode classify_2d_boundary( const Range &boundary,
                                      const Range &bar_elements,

diff --git a/test/Makefile.am b/test/Makefile.am
index 100285b..99c5211 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -76,6 +76,7 @@ MOSTLYCLEANFILES = mb_write.g \
                    tri_mid_edge_face_nodes.g \
                    mb_stress_out.g \
                    merge_test.g \
+                   mm_out.h5m \
                    tree.h5m 
 
 # Tests and such

diff --git a/test/mergemesh_test.cpp b/test/mergemesh_test.cpp
index 0b382e6..fca5304 100644
--- a/test/mergemesh_test.cpp
+++ b/test/mergemesh_test.cpp
@@ -38,11 +38,11 @@ int main( int argc, char* argv[] )
     }
 
     // Fixed for now
-//    const char *outfile = "mm_out.h5m";
-//    rval = iface->write_mesh( outfile);
-//    if (MB_SUCCESS != rval) {
-//        std::cerr << "Error saving file: " << outfile << std::endl;
-//        exit(2);
-//    }
+    const char *outfile = "mm_out.h5m";
+    rval = iface->write_mesh( outfile);
+    if (MB_SUCCESS != rval) {
+        std::cerr << "Error saving file: " << outfile << std::endl;
+        exit(2);
+    }
     return 0;
 }

diff --git a/tools/mbcoupler/Coupler.cpp b/tools/mbcoupler/Coupler.cpp
index 71231b8..f7f74b2 100644
--- a/tools/mbcoupler/Coupler.cpp
+++ b/tools/mbcoupler/Coupler.cpp
@@ -6,6 +6,7 @@
 #include "iMesh_extensions.h"
 #include "moab/gs.hpp"
 #include "moab/TupleList.hpp"
+#include "moab/Error.hpp"
 #include "iostream"
 #include <stdio.h>
 #include <algorithm>
@@ -518,6 +519,27 @@ ErrorCode Coupler::test_local_box(double *xyz,
   return MB_SUCCESS;
 }
 
+ErrorCode Coupler::interpolate(Coupler::Method method,
+                                      const std::string &interp_tag,
+                                      double *interp_vals,
+                                      TupleList *tl,
+                                      bool normalize)
+{
+  Tag tag;
+  ErrorCode result ;
+  if (_spectralSource)
+    result = mbImpl->tag_get_handle(interp_tag.c_str(), _ntot, MB_TYPE_DOUBLE, tag);
+  else
+    result = mbImpl->tag_get_handle(interp_tag.c_str(), 1, MB_TYPE_DOUBLE, tag);
+  if (MB_SUCCESS != result) {
+    std::ostringstream str;
+    str << "Failed to get handle for interpolation tag \"" << interp_tag << "\"";
+    mError->set_last_error(str.str());
+    return result;
+  }
+  return interpolate(method, tag, interp_vals, tl, normalize);
+}
+
 ErrorCode Coupler::interpolate(Coupler::Method *methods,
                                Tag *tags,
                                int *points_per_method,

diff --git a/tools/mbcoupler/Coupler.hpp b/tools/mbcoupler/Coupler.hpp
index 74170d5..705e2dc 100644
--- a/tools/mbcoupler/Coupler.hpp
+++ b/tools/mbcoupler/Coupler.hpp
@@ -29,7 +29,6 @@
 #include "moab/Interface.hpp"
 #include "moab/CartVect.hpp"
 #include "moab/TupleList.hpp"
-#include "moab/Error.hpp"
 
 #include <sstream>
 
@@ -41,6 +40,8 @@ class AdaptiveKDTree;
   
 class TupleList;
 
+class Error;
+
 class Coupler
 {
 public:
@@ -530,27 +531,6 @@ private:
     // error object used to set last error on interface
   Error *mError;
 };
-
-inline ErrorCode Coupler::interpolate(Coupler::Method method,
-                                      const std::string &interp_tag,
-                                      double *interp_vals,
-                                      TupleList *tl,
-                                      bool normalize)
-{
-  Tag tag;
-  ErrorCode result ;
-  if (_spectralSource)
-    result = mbImpl->tag_get_handle(interp_tag.c_str(), _ntot, MB_TYPE_DOUBLE, tag);
-  else
-    result = mbImpl->tag_get_handle(interp_tag.c_str(), 1, MB_TYPE_DOUBLE, tag);
-  if (MB_SUCCESS != result) {
-    std::ostringstream str;
-    str << "Failed to get handle for interpolation tag \"" << interp_tag << "\"";
-    mError->set_last_error(str.str());
-    return result;
-  }
-  return interpolate(method, tag, interp_vals, tl, normalize);
-}
   
 inline ErrorCode Coupler::interpolate(Coupler::Method method,
                                       Tag tag,


https://bitbucket.org/fathomteam/moab/commits/b2634574534f/
Changeset:   b2634574534f
Branch:      None
User:        iulian07
Date:        2013-09-21 05:19:52
Summary:     introduce writing option, total mass and 1 norm for the tracer

the big model with 200 time steps took more than 24 h in serial, on my laptop
the culprit is writing the vtk file with intersection polygons at every time step.
need to investigate why it is so slow; one posibility is the fragmented ranges
with polygons; still, very disappointing
writing option reduces that to about 1 minute per time step, for a total of about
200 minutes.

Affected #:  3 files

diff --git a/tools/mbcslam/Intx2MeshOnSphere.cpp b/tools/mbcslam/Intx2MeshOnSphere.cpp
index 9dacfb9..2fe03c3 100644
--- a/tools/mbcslam/Intx2MeshOnSphere.cpp
+++ b/tools/mbcslam/Intx2MeshOnSphere.cpp
@@ -415,7 +415,7 @@ bool Intx2MeshOnSphere::is_inside_element(double xyz[3], EntityHandle eh)
   return false;
 }
 
-ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagElem)
+ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagElem, Tag & tagArea)
 {
   EntityHandle dum = 0;
 
@@ -471,14 +471,24 @@ ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagE
   }
   // now divide by red area (current)
   int j=0;
-  for (Range::iterator it=rs2.begin(); it!=rs2.end(); it++, j++ )
+  Range::iterator iter = rs2.begin();
+  void * data=NULL; //used for stored area
+  int count =0;
+  double total_mass_current=0.;
+  while (iter != rs2.end())
   {
-    EntityHandle red = *it;
-    double areaRed = area_spherical_element(mb, red, R);
-    newValues[j]/=areaRed;
+    rval = mb->tag_iterate(tagArea, iter, rs2.end(), count, data);
+    ERRORR(rval, "can't tag iterate");
+    double * ptrArea=(double*)data;
+    for (int i=0; i<count; i++, iter++, j++, ptrArea++)
+    {
+      total_mass_current+=newValues[j];
+      newValues[j]/= (*ptrArea);
+    }
   }
   rval = mb->tag_set_data(tagElem, rs2, &newValues[0]);
   ERRORR(rval, "can't set new values tag");
+  std::cout <<"total mass now:" << total_mass_current << "\n";
   return MB_SUCCESS;
 }
 } /* namespace moab */

diff --git a/tools/mbcslam/Intx2MeshOnSphere.hpp b/tools/mbcslam/Intx2MeshOnSphere.hpp
index c2a3066..8047840 100644
--- a/tools/mbcslam/Intx2MeshOnSphere.hpp
+++ b/tools/mbcslam/Intx2MeshOnSphere.hpp
@@ -31,7 +31,7 @@ public:
 
   bool is_inside_element(double xyz[3], EntityHandle eh);
 
-  ErrorCode update_tracer_data(EntityHandle out_set, Tag & tagElem);
+  ErrorCode update_tracer_data(EntityHandle out_set, Tag & tagElem, Tag & tagArea);
 
 private:
   int plane; // current gnomonic plane

diff --git a/tools/mbcslam/diffusion.cpp b/tools/mbcslam/diffusion.cpp
index 11fd1e4..a44c3ca 100644
--- a/tools/mbcslam/diffusion.cpp
+++ b/tools/mbcslam/diffusion.cpp
@@ -51,7 +51,7 @@ double T = 5;
 int case_number = 1; // 1, 2 (non-divergent) 3 divergent
 
 moab::Tag corrTag;
-
+bool noWrite = false;
 int field_type = 1 ; // 1 quasi smooth, 2 - smooth, 3 non-smooth,
 #ifdef MESHDIR
 std::string TestDir( STRINGIFY(MESHDIR) );
@@ -334,7 +334,7 @@ ErrorCode  create_lagr_mesh(Interface * mb, EntityHandle euler_set, EntityHandle
   return MB_SUCCESS;
 }
 ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
-    EntityHandle lagr_set, EntityHandle out_set, Tag & tagElem, int rank,
+    EntityHandle lagr_set, EntityHandle out_set, Tag & tagElem, Tag & tagArea, int rank,
     int tStep)
 {
   ErrorCode rval = MB_SUCCESS;
@@ -386,18 +386,21 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
   // serially: lagr is the same order as euler;
   // we need to update now the tracer information on each element, based on
   // initial value and areas of each resulting polygons
-  rval = worker.update_tracer_data(out_set, tagElem);
+  rval = worker.update_tracer_data(out_set, tagElem, tagArea);
   CHECK_ERR(rval);
 
-  std::stringstream newTracer;
-  newTracer << "Tracer" << rank << "_" << tStep << ".vtk";
-  rval = mb->write_file(newTracer.str().c_str(), 0, 0, &euler_set, 1);
-  CHECK_ERR(rval);
+  if (!noWrite) // so if write
+  {
+    std::stringstream newTracer;
+    newTracer << "Tracer" << rank << "_" << tStep << ".vtk";
+    rval = mb->write_file(newTracer.str().c_str(), 0, 0, &euler_set, 1);
+    CHECK_ERR(rval);
 
-  std::stringstream newIntx;
-  newIntx << "newIntx" << rank << "_" << tStep << ".vtk";
-  rval = mb->write_file(newIntx.str().c_str(), 0, 0, &out_set, 1);
-  CHECK_ERR(rval);
+    std::stringstream newIntx;
+    newIntx << "newIntx" << rank << "_" << tStep << ".vtk";
+    rval = mb->write_file(newIntx.str().c_str(), 0, 0, &out_set, 1);
+    CHECK_ERR(rval);
+  }
   // delete now the polygons and the elements of out_set
   // also, all verts that are not in euler set or lagr_set
   Range allVerts;
@@ -425,6 +428,7 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
   CHECK_ERR(rval);
   rval = mb->delete_entities(todeleteVerts);
   CHECK_ERR(rval);
+  std::cout << " step: " << tStep << "\n";
   return rval;
 }
 int main(int argc, char **argv)
@@ -465,11 +469,16 @@ int main(int argc, char **argv)
         numSteps = atoi(argv[++index]);
       }
 
+      if (!strcmp(argv[index], "-nw"))
+      {
+        noWrite = true;
+      }
+
       if (!strcmp(argv[index], "-h"))
       {
         std::cout << "usage: -gtol <tol> -input <file> -O <extra_read_opts> \n   "
         <<    "-f <field_type> -h (this help) -ns <numSteps> \n";
-        std::cout << " filed type: 1: quasi-smooth; 2: smooth; 3: slotted cylinders (non-smooth)\n";
+        std::cout << " field type: 1: quasi-smooth; 2: smooth; 3: slotted cylinders (non-smooth)\n";
         return 0;
       }
       index++;
@@ -519,11 +528,12 @@ int main(int argc, char **argv)
   rval = add_field_value(&mb, euler_set, rank, tagTracer, tagElem, tagArea);
   CHECK_ERR(rval);
 
-
-  // do some velocity fields at some time steps; with animations
-  // first delete the
-
-
+  Range redEls;
+  rval = mb.get_entities_by_dimension(euler_set, 2, redEls);
+  CHECK_ERR(rval);
+  std::vector<double> iniVals(redEls.size());
+  rval = mb.tag_get_data(tagElem, redEls, &iniVals[0]);
+  CHECK_ERR(rval);
 
   Tag tagh = 0;
   std::string tag_name3("Case1");
@@ -548,8 +558,32 @@ int main(int argc, char **argv)
     // this is to actually compute concentrations, using the current concentrations
     //
     rval = compute_tracer_case1(&mb, euler_set, lagr_set, out_set,
-        tagElem, rank, i);
+        tagElem, tagArea, rank, i);
+    CHECK_ERR(rval);
+
+  }
+
+  //final vals and 1-norm
+  Range::iterator iter = redEls.begin();
+  double norm1 = 0.;
+  int count =0;
+  void * data;
+  int j=0;// index in iniVals
+  while (iter != redEls.end())
+  {
+    rval = mb.tag_iterate(tagElem, iter, redEls.end(), count, data);
+    CHECK_ERR(rval);
+    double * ptrTracer=(double*)data;
 
+    rval = mb.tag_iterate(tagArea, iter, redEls.end(), count, data);
+    CHECK_ERR(rval);
+    double * ptrArea=(double*)data;
+    for (int i=0; i<count; i++, iter++, ptrTracer++, ptrArea++, j++)
+    {
+      //double area = *ptrArea;
+      norm1+=fabs(*ptrTracer - iniVals[j])* (*ptrArea);
+    }
   }
+  std::cout << " numSteps:" << numSteps << " 1-norm:" << norm1 << "\n";
   return 0;
 }


https://bitbucket.org/fathomteam/moab/commits/2452b59922a1/
Changeset:   2452b59922a1
Branch:      None
User:        iulian07
Date:        2013-09-24 03:18:42
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  11 files

diff --git a/examples/GetEntities.cpp b/examples/GetEntities.cpp
index 6c6a956..d9dc34e 100644
--- a/examples/GetEntities.cpp
+++ b/examples/GetEntities.cpp
@@ -55,6 +55,8 @@ int main(int argc, char **argv) {
       cout << endl;
     }
   }
-  
+
+  delete mb;
+
   return 0;
 }

diff --git a/examples/HelloParMOAB.cpp b/examples/HelloParMOAB.cpp
index 75daeda..03366f9 100644
--- a/examples/HelloParMOAB.cpp
+++ b/examples/HelloParMOAB.cpp
@@ -97,6 +97,8 @@ int main(int argc, char **argv)
     }
   }
 
+  delete mb;
+
   MPI_Finalize();
 
   return 0;

diff --git a/examples/old/FileRead.cpp b/examples/old/FileRead.cpp
index bff9e28..b1abda0 100644
--- a/examples/old/FileRead.cpp
+++ b/examples/old/FileRead.cpp
@@ -160,5 +160,8 @@ int main(int argc, char **argv) {
      cout << "Writing output file " << outfile << endl;
      mb->write_file(outfile); 
    }
+
+   delete mb;
+
    return 0;
 }  

diff --git a/examples/old/GeomSetHierarchy.cpp b/examples/old/GeomSetHierarchy.cpp
index a49dafe..493baa7 100644
--- a/examples/old/GeomSetHierarchy.cpp
+++ b/examples/old/GeomSetHierarchy.cpp
@@ -79,5 +79,9 @@ int main(int argc, char **argv) {
         }
       }
     }
-  } 
+  }
+
+  delete mb;
+
+  return 0;
 }

diff --git a/examples/old/ObbTree.cpp b/examples/old/ObbTree.cpp
index 220681f..f83b440 100644
--- a/examples/old/ObbTree.cpp
+++ b/examples/old/ObbTree.cpp
@@ -76,5 +76,7 @@ int main(int argc, char **argv) {
   }
   std::cout << " of ray length " << ray_length << std::endl;
 
+  delete mb;
+
   return 0;
 }

diff --git a/examples/old/simple/GetEntities.cpp b/examples/old/simple/GetEntities.cpp
index 1ac5783..8d235fd 100644
--- a/examples/old/simple/GetEntities.cpp
+++ b/examples/old/simple/GetEntities.cpp
@@ -27,5 +27,8 @@ int main(int argc, char **argv) {
                 << mb->id_from_handle(ent) << "." << std::endl;
     }
   }
+
+  delete mb;
+
   return 0;
 }

diff --git a/test/kd_tree_time.cpp b/test/kd_tree_time.cpp
index 7917295..10af975 100644
--- a/test/kd_tree_time.cpp
+++ b/test/kd_tree_time.cpp
@@ -144,6 +144,7 @@ int main( int argc, char* argv[] )
     }
   }
   printf("%0.2f seconds\n", (clock()-t)/(double)CLOCKS_PER_SEC); fflush( stdout );
+  delete[] values;
 
   return 0;
 }

diff --git a/tools/mbcoupler/ElemUtil.hpp b/tools/mbcoupler/ElemUtil.hpp
index 1db4c9e..219323b 100644
--- a/tools/mbcoupler/ElemUtil.hpp
+++ b/tools/mbcoupler/ElemUtil.hpp
@@ -168,7 +168,7 @@ namespace ElemUtil {
     /**\brief Shape function space for a linear tetrahedron, obtained by a pushforward of the canonical affine shape functions. */
     class LinearTet : public Map {
     public:
-      LinearTet(const std::vector<CartVect>& vertices) : Map(vertices){};
+      LinearTet(const std::vector<CartVect>& vertices) : Map(vertices){ LinearTet::set_vertices(vertex);};
       LinearTet();
       virtual ~LinearTet();
       /* Override the evaluation routines to take advantage of the properties of P1. */

diff --git a/tools/mbcslam/Intx2MeshInPlane.cpp b/tools/mbcslam/Intx2MeshInPlane.cpp
index 496903a..9fb2a94 100644
--- a/tools/mbcslam/Intx2MeshInPlane.cpp
+++ b/tools/mbcslam/Intx2MeshInPlane.cpp
@@ -318,6 +318,7 @@ int Intx2MeshInPlane::findNodes(EntityHandle red, int nsRed, EntityHandle blue,
       }
       std::cout << " a point pp is not on a red polygon " << *pp << " " << pp[1]
           << " red polygon " << mb->id_from_handle(red) << " \n";
+      delete[] foundIds;
       return 1;
     }
   }

diff --git a/tools/mbcslam/Intx2MeshOnSphere.cpp b/tools/mbcslam/Intx2MeshOnSphere.cpp
index 2fe03c3..3ab761c 100644
--- a/tools/mbcslam/Intx2MeshOnSphere.cpp
+++ b/tools/mbcslam/Intx2MeshOnSphere.cpp
@@ -320,6 +320,7 @@ int Intx2MeshOnSphere::findNodes(EntityHandle red, int nsRed, EntityHandle blue,
       }
       std::cout << " a point pp is not on a red quad " << *pp << " " << pp[1]
           << " red quad " << mb->id_from_handle(red) << " \n";
+      delete[] foundIds;
       return 1;
     }
   }

diff --git a/tools/mbzoltan/MBZoltan.cpp b/tools/mbzoltan/MBZoltan.cpp
index f1b712c..d07ffcf 100644
--- a/tools/mbzoltan/MBZoltan.cpp
+++ b/tools/mbzoltan/MBZoltan.cpp
@@ -1159,6 +1159,9 @@ ErrorCode MBZoltan::partition_round_robin(const int n_part)
     } // for (j = 0; j < n_child; j++)
   } // for (i = 0; i < n_entity; i++)
 
+  delete[] loads;
+  delete[] ve_loads;
+
   return MB_SUCCESS;
 }
 


https://bitbucket.org/fathomteam/moab/commits/09e08d5291ae/
Changeset:   09e08d5291ae
Branch:      None
User:        iulian07
Date:        2013-09-25 18:01:08
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  14 files

diff --git a/examples/GetEntities.cpp b/examples/GetEntities.cpp
index d9dc34e..5124529 100644
--- a/examples/GetEntities.cpp
+++ b/examples/GetEntities.cpp
@@ -29,19 +29,28 @@ int main(int argc, char **argv) {
     // instantiate & load a mesh from a file
   Core *mb = new Core();
   ErrorCode rval = mb->load_mesh(test_file_name.c_str());
-  if (MB_SUCCESS != rval) return 1;
+  if (MB_SUCCESS != rval) {
+    delete mb;
+    return 1;
+  }
 
   Range ents;
 
     // get all entities in the database
   rval = mb->get_entities_by_handle(0, ents);
-  if (MB_SUCCESS != rval) return 1;
+  if (MB_SUCCESS != rval) {
+    delete mb;
+    return 1;
+  }
 
   for (Range::iterator it = ents.begin(); it != ents.end(); it++) {
     if (MBVERTEX == mb->type_from_handle(*it)) {
       Range adjs;
       rval = mb->get_adjacencies(&(*it), 1, 3, false, adjs);
-      if (MB_SUCCESS != rval) return 1;
+      if (MB_SUCCESS != rval) {
+        delete mb;
+        return 1;
+      }
       cout << "Vertex " << mb->id_from_handle(*it) << " adjacencies:" << endl;
       adjs.print();
     }
@@ -49,9 +58,13 @@ int main(int argc, char **argv) {
       const EntityHandle *connect;
       int num_connect;
       rval = mb->get_connectivity(*it, connect, num_connect);
-      if (MB_SUCCESS != rval) return 1;
+      if (MB_SUCCESS != rval) {
+        delete mb;
+        return 1;
+      }
       cout << CN::EntityTypeName(mb->type_from_handle(*it)) << " " << mb->id_from_handle(*it) << " vertex connectivity is: ";
-      for (int i = 0; i < num_connect; i++) cout << mb->id_from_handle(connect[i]) << " ";
+      for (int i = 0; i < num_connect; i++)
+        cout << mb->id_from_handle(connect[i]) << " ";
       cout << endl;
     }
   }

diff --git a/examples/HelloParMOAB.cpp b/examples/HelloParMOAB.cpp
index 03366f9..5bcc4ab 100644
--- a/examples/HelloParMOAB.cpp
+++ b/examples/HelloParMOAB.cpp
@@ -20,20 +20,23 @@ int main(int argc, char **argv)
 
   string options;
 
-    // need option handling here for input filename
+  // Need option handling here for input filename
   if (argc > 1){
-    //user has input a mesh file
+    // user has input a mesh file
     test_file_name = argv[1];
   }  
 
   options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS";
 
-  // get MOAB instance and read the file with the specified options
-  Interface *mb = new Core;
-  if (NULL == mb) return 1;
-  // get the ParallelComm instance
+  // Get MOAB instance and read the file with the specified options
+  Interface* mb = new Core;
+  if (NULL == mb)
+    return 1;
+
+  // Get the ParallelComm instance
   ParallelComm* pcomm = new ParallelComm(mb, MPI_COMM_WORLD);
-  int nprocs = pcomm->proc_config().proc_size(), rank = pcomm->proc_config().proc_rank();
+  int nprocs = pcomm->proc_config().proc_size();
+  int rank = pcomm->proc_config().proc_rank();
   MPI_Comm comm = pcomm->proc_config().proc_comm();
 
   if (rank == 0)
@@ -41,59 +44,76 @@ int main(int argc, char **argv)
          << " on " << nprocs << " processors\n";
 
   ErrorCode rval = mb->load_file(test_file_name.c_str(), 0, options.c_str());
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
   Range shared_ents;
-    // get entities shared with all other processors
+  // Get entities shared with all other processors
   rval = pcomm->get_shared_entities(-1, shared_ents);
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
-    // filter shared entities with not not_owned, which means owned
+  // Filter shared entities with not not_owned, which means owned
   Range owned_entities;
   rval = pcomm->filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &owned_entities);
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
-  unsigned int nums[4]={0}; // to store the owned entities per dimension
-  for (int i=0; i<4; i++) nums[i]=(int)owned_entities.num_of_dimension(i);
+  unsigned int nums[4] = {0}; // to store the owned entities per dimension
+  for (int i = 0; i < 4; i++)
+    nums[i] = (int)owned_entities.num_of_dimension(i);
   vector<int> rbuf(nprocs*4, 0);
-  MPI_Gather( nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, MPI_COMM_WORLD);
-  // print the stats gathered:
+  MPI_Gather(nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, MPI_COMM_WORLD);
+  // Print the stats gathered:
   if (rank == 0) {
-    for (int i=0; i<nprocs; i++)
+    for (int i = 0; i < nprocs; i++)
       cout << " Shared, owned entities on proc " << i << ": " << rbuf[4*i] << " verts, " <<
-          rbuf[4*i+1] << " edges, " << rbuf[4*i+2] << " faces, " << rbuf[4*i+3] << " elements" << endl;
+          rbuf[4*i + 1] << " edges, " << rbuf[4*i + 2] << " faces, " << rbuf[4*i + 3] << " elements" << endl;
   }
 
-    // Now exchange 1 layer of ghost elements, using vertices as bridge
-    // (we could have done this as part of reading process, using the PARALLEL_GHOSTS read option)
+  // Now exchange 1 layer of ghost elements, using vertices as bridge
+  // (we could have done this as part of reading process, using the PARALLEL_GHOSTS read option)
   rval = pcomm->exchange_ghost_cells(3, // int ghost_dim,
                                      0, // int bridge_dim,
                                      1, //int num_layers,
                                      0, //int addl_ents,
                                      true); // bool store_remote_handles);
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
-  // repeat the reports, after ghost exchange
+  // Repeat the reports, after ghost exchange
   shared_ents.clear();
   owned_entities.clear();
   rval = pcomm->get_shared_entities(-1, shared_ents);
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
   rval = pcomm->filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &owned_entities);
-  if (rval != MB_SUCCESS)  return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
   // find out how many shared entities of each dimension are owned on this processor
-  for (int i=0; i<4; i++)
-    nums[i]=(int)owned_entities.num_of_dimension(i);
+  for (int i = 0; i < 4; i++)
+    nums[i] = (int)owned_entities.num_of_dimension(i);
 
   // gather the statistics on processor 0
-  MPI_Gather( nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, comm);
-  if (rank == 0)
-  {
+  MPI_Gather(nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, comm);
+  if (rank == 0) {
     cout << " \n\n After exchanging one ghost layer: \n";
-    for (int i=0; i<nprocs; i++)
-    {
+    for (int i = 0; i < nprocs; i++) {
       cout << " Shared, owned entities on proc " << i << ": " << rbuf[4*i] << " verts, " <<
-          rbuf[4*i+1] << " edges, " << rbuf[4*i+2] << " faces, " << rbuf[4*i+3] << " elements" << endl;
+          rbuf[4*i + 1] << " edges, " << rbuf[4*i + 2] << " faces, " << rbuf[4*i + 3] << " elements" << endl;
     }
   }
 

diff --git a/examples/old/ObbTree.cpp b/examples/old/ObbTree.cpp
index f83b440..ff4aadf 100644
--- a/examples/old/ObbTree.cpp
+++ b/examples/old/ObbTree.cpp
@@ -22,9 +22,10 @@ int main(int argc, char **argv) {
   moab::Range tris;
   //moab::OrientedBoxTreeTool::Settings settings;
 
-  rval = mb->get_entities_by_type( 0, moab::MBTRI, tris );
+  rval = mb->get_entities_by_type(0, moab::MBTRI, tris);
   if (rval != moab::MB_SUCCESS) {
     std::cerr << "Couldn't get triangles." << std::endl;
+    delete mb;
     return 1;
   }
 
@@ -33,7 +34,8 @@ int main(int argc, char **argv) {
   //rval = tool.build(tris, tree_root, &settings);
   rval = tool.build(tris, tree_root);
   if (rval != moab::MB_SUCCESS) {
-    std::cerr << "Could'nt build tree." << std::endl;    
+    std::cerr << "Could'nt build tree." << std::endl;
+    delete mb;
     return 1;
   }
   
@@ -42,6 +44,7 @@ int main(int argc, char **argv) {
   rval = tool.box(tree_root, box_center, box_axis1, box_axis2, box_axis3);
   if (rval != moab::MB_SUCCESS) {
     std::cerr << "Couldn't get box for tree root set.";
+    delete mb;
     return 1;
   }
 
@@ -52,17 +55,19 @@ int main(int argc, char **argv) {
   std::vector<double> intersections;
   std::vector<moab::EntityHandle> intersection_facets;
 
-  for (int i=0; i<3; i++)
-    pnt_start[i] = box_center[i]-box_axis1[i];
+  for (int i = 0; i < 3; i++)
+    pnt_start[i] = box_center[i] - box_axis1[i];
 
-  if (ray_length>0) // normalize ray direction
-    for (int j=0; j<3; j++)
-      box_axis1[j]=2*box_axis1[j]/ray_length;
+  if (ray_length > 0) { // normalize ray direction
+    for (int j = 0; j < 3; j++)
+      box_axis1[j] = 2 * box_axis1[j] / ray_length;
+  }
   rval = tool.ray_intersect_triangles(intersections, intersection_facets, 
 				      tree_root, 10e-12, pnt_start, box_axis1,
 				      &ray_length);
   if (rval != moab::MB_SUCCESS) {
     std::cerr << "Couldn't ray tracing.";
+    delete mb;
     return 1;
   }
   
@@ -71,9 +76,8 @@ int main(int argc, char **argv) {
   std::cout << " ray direction: " << box_axis1[0] << " " << box_axis1[1] << " " << box_axis1[2] << "\n";
   std::cout << "# of intersections : " << intersections.size() << std::endl;
   std::cout << "intersection distances are on";
-  for (unsigned int i = 0; i < intersections.size(); i++) {
+  for (unsigned int i = 0; i < intersections.size(); i++)
     std::cout << " " << intersections[i];
-  }
   std::cout << " of ray length " << ray_length << std::endl;
 
   delete mb;

diff --git a/examples/old/simple/GetEntities.cpp b/examples/old/simple/GetEntities.cpp
index 8d235fd..31d24d7 100644
--- a/examples/old/simple/GetEntities.cpp
+++ b/examples/old/simple/GetEntities.cpp
@@ -8,18 +8,24 @@ int main(int argc, char **argv) {
     return 0;
   }
 
-    // instantiate & load a mesh from a file
+  // Instantiate & load a mesh from a file
   moab::Core *mb = new moab::Core();
   moab::ErrorCode rval = mb->load_mesh(argv[1]);
-  if (moab::MB_SUCCESS != rval) return 1;
+  if (moab::MB_SUCCESS != rval) {
+    delete mb;
+    return 1;
+  }
 
   moab::Range ents;
 
-    // iterate over dimensions
+  // Iterate over dimensions
   for (int d = 0; d <= 3; d++) {
     ents.clear();
     rval = mb->get_entities_by_dimension(0, d, ents);
-    if (moab::MB_SUCCESS != rval) return 1;
+    if (moab::MB_SUCCESS != rval) {
+      delete mb;
+      return 1;
+    }
     std::cout << "Found " << ents.size() << " " << d << "-dimensional entities:" << std::endl;
     for (moab::Range::iterator it = ents.begin(); it != ents.end(); it++) {
       moab::EntityHandle ent = *it;

diff --git a/src/io/ReadNCDF.cpp b/src/io/ReadNCDF.cpp
index 3ed25d1..c400cd2 100644
--- a/src/io/ReadNCDF.cpp
+++ b/src/io/ReadNCDF.cpp
@@ -171,13 +171,11 @@ void ReadNCDF::reset()
     nodesInLoadedBlocks.clear();
 }
 
-
 ReadNCDF::~ReadNCDF() 
 {
   mdbImpl->release_interface(readMeshIface);
 }
   
-
 ErrorCode ReadNCDF::read_tag_values(const char* file_name,
                                     const char* tag_name,
                                     const FileOptions& ,
@@ -236,8 +234,6 @@ ErrorCode ReadNCDF::read_tag_values(const char* file_name,
   return MB_SUCCESS;
 }
 
-
-
 ErrorCode ReadNCDF::load_file(const char *exodus_file_name,
                               const EntityHandle* file_set,
                               const FileOptions& opts,
@@ -328,8 +324,6 @@ ErrorCode ReadNCDF::load_file(const char *exodus_file_name,
   return MB_SUCCESS;
 }
 
-
-
 ErrorCode ReadNCDF::read_exodus_header()
 {
   CPU_WORD_SIZE = sizeof(double);  // With ExodusII version 2, all floats
@@ -403,17 +397,18 @@ ErrorCode ReadNCDF::read_exodus_header()
     readMeshIface->report_error("ReadNCDF:: Problem getting title attribute.");
     return MB_FAILURE;
   }
-  char *title = new char[att_len+1];
   if (att_type != NC_CHAR) {
     readMeshIface->report_error("ReadNCDF:: title didn't have type char.");
     return MB_FAILURE;
   }
+  char *title = new char[att_len + 1];
   fail = nc_get_att_text(ncFile, NC_GLOBAL, "title", title);
   if (NC_NOERR != fail) {
     readMeshIface->report_error("ReadNCDF:: trouble getting title.");
+    delete[] title;
     return MB_FAILURE;
   }
-  delete [] title;
+  delete[] title;
 
   return MB_SUCCESS;
 }
@@ -683,12 +678,10 @@ ErrorCode ReadNCDF::read_elements(const Tag* file_id_tag)
     const int* reorder = exodus_elem_order_map[mb_type][verts_per_element];
     if (reorder)
       ReadUtilIface::reorder( reorder, conn, this_it->numElements, verts_per_element );
-    
 
-      
     readMeshIface->update_adjacencies((*this_it).startMBId, (*this_it).numElements,
                                       ExoIIUtil::VerticesPerElement[(*this_it).elemType], conn);
-    
+
     if ( result == -1 )
     {
       readMeshIface->report_error("ReadNCDF:: error getting element connectivity for block %i",
@@ -701,8 +694,7 @@ ErrorCode ReadNCDF::read_elements(const Tag* file_id_tag)
       return MB_FAILURE;
     if( mdbImpl->tag_set_data( mGlobalIdTag, &ms_handle, 1, &block_id ) != MB_SUCCESS )
       return MB_FAILURE;
-      
-      
+
     if (file_id_tag) {
       Range range;
       range.insert( this_it->startMBId, this_it->startMBId + this_it->numElements - 1 );
@@ -1199,7 +1191,6 @@ ErrorCode ReadNCDF::create_ss_elements( int *element_ids,
     else if( type == MBQUAD &&
              exoii_type >= EXOII_SHELL && exoii_type <= EXOII_SHELL9 )
     {
-
       //ent_handle = CREATE_HANDLE(MBQUAD, base_id, error );
 
       //just use this quad
@@ -1325,9 +1316,7 @@ ErrorCode ReadNCDF::create_ss_elements( int *element_ids,
             dist_factor_vector.push_back( temp_dist_factor_vector[df_index++] );
         }
       }
-
     }
-
   }
 
   return MB_SUCCESS; 
@@ -1411,11 +1400,9 @@ ErrorCode ReadNCDF::create_sideset_element( const std::vector<EntityHandle>& con
   return error;
 }
 
-
 ErrorCode ReadNCDF::find_side_element_type( const int exodus_id, ExoIIElementType &elem_type, 
                                                 ReadBlockData &block_data, int &df_index, int side_id)
 {
-
   std::vector<ReadBlockData>::iterator iter, end_iter;
   iter = blocksLoading.begin();
   end_iter = blocksLoading.end();
@@ -1450,7 +1437,6 @@ ErrorCode ReadNCDF::find_side_element_type( const int exodus_id, ExoIIElementTyp
           df_index += 3;
 
         return MB_FAILURE;
-
       }
 
       block_data = *iter;

diff --git a/src/io/WriteSmf.cpp b/src/io/WriteSmf.cpp
index 9d7f5f0..d2c4fc9 100644
--- a/src/io/WriteSmf.cpp
+++ b/src/io/WriteSmf.cpp
@@ -13,7 +13,6 @@
  * 
  */
 
-
 #ifdef WIN32
 #ifdef _DEBUG
 // turn off warnings that say they debugging identifier has been truncated
@@ -22,7 +21,6 @@
 #endif
 #endif
 
-
 #include "WriteSmf.hpp"
 
 #include <fstream>
@@ -48,15 +46,16 @@ namespace moab {
 const int DEFAULT_PRECISION = 10;
 //const bool DEFAULT_STRICT = true;
 
-WriterIface *WriteSmf::factory( Interface* iface )
-  { return new WriteSmf( iface ); }
+WriterIface *WriteSmf::factory(Interface* iface)
+{
+  return new WriteSmf(iface);
+}
 
-WriteSmf::WriteSmf(Interface *impl) 
-    : mbImpl(impl), writeTool(0)
+WriteSmf::WriteSmf(Interface *impl)
+  : mbImpl(impl), writeTool(0)
 {
   assert(impl != NULL);
-
-  impl->query_interface( writeTool );
+  impl->query_interface(writeTool);
 }
 
 WriteSmf::~WriteSmf() 
@@ -72,119 +71,124 @@ ErrorCode WriteSmf::write_file(const char *file_name,
                                  const std::vector<std::string>& ,
                                  const Tag* /*tag_list*/,
                                  int /*num_tags*/,
-                                 int )
+                                 int /*export_dimension*/)
 {
   ErrorCode rval;
 
-    // Get precision for node coordinates
+  // Get precision for node coordinates
   int precision;
-  if (MB_SUCCESS != opts.get_int_option( "PRECISION", precision ))
+  if (MB_SUCCESS != opts.get_int_option("PRECISION", precision))
     precision = DEFAULT_PRECISION;
-  
-   // Honor overwrite flag
-  if (!overwrite)
-  {
-    rval = writeTool->check_doesnt_exist( file_name );
+
+  // Honor overwrite flag
+  if (!overwrite) {
+    rval = writeTool->check_doesnt_exist(file_name);
     if (MB_SUCCESS != rval)
       return rval;
   }
-  
-    // Create file
-  std::ofstream file( file_name );
-  if (!file)
-  {
-    writeTool->report_error("Could not open file: %s\n", file_name );
+
+  // Create file
+  std::ofstream file(file_name);
+  if (!file) {
+    writeTool->report_error("Could not open file: %s\n", file_name);
     return MB_FILE_WRITE_ERROR;
   }
-  file.precision( precision );
-    // Get entities to write
-  
+  file.precision(precision);
+
+  // Get entities to write
   Range triangles;
-  if (!output_list || !num_sets)
-  {
-    rval = mbImpl->get_entities_by_type( 0, MBTRI, triangles, false);
-    if (MB_SUCCESS != rval) return rval;
+  if (!output_list || !num_sets) {
+    rval = mbImpl->get_entities_by_type(0, MBTRI, triangles, false);
+    if (MB_SUCCESS != rval)
+      return rval;
 
-    // somehow get all the nodes from this range, order them, uniquify, then use binary search
+  // Somehow get all the nodes from this range, order them, uniquify, then use binary search
   }
-  else
-  {
+  else {
     // get all triangles from output sets
-    for (int i=0; i<num_sets; i++)
-      rval = mbImpl->get_entities_by_type( output_list[i], MBTRI, triangles, false);
+    for (int i = 0; i < num_sets; i++)
+      rval = mbImpl->get_entities_by_type(output_list[i], MBTRI, triangles, false);
   }
-  // use an array with all the connectivities in the triangles; it will be converted later to ints
+  // Use an array with all the connectivities in the triangles; it will be converted later to ints
   int numTriangles = triangles.size();
-  int array_alloc = 3*numTriangles;       // allocated size of 'array'
+  int array_alloc = 3 * numTriangles;       // allocated size of 'array'
   EntityHandle* array = new EntityHandle[array_alloc]; // ptr to working array of result handles
-  // fill up array with node handles; reorder and uniquify 
+  // Fill up array with node handles; reorder and uniquify
   if (!array)
      return MB_MEMORY_ALLOCATION_FAILED;
   int fillA = 0;
-  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e)
-    {
+  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e) {
       const EntityHandle* conn;
       int conn_len;
-      rval = mbImpl->get_connectivity( *e, conn, conn_len );
-      if (MB_SUCCESS != rval  ) 
-	return rval;
-      if ( 3!=conn_len) 
+      rval = mbImpl->get_connectivity(*e, conn, conn_len);
+      if (MB_SUCCESS != rval) {
+        delete[] array;
+        return rval;
+      }
+      if (3 != conn_len) {
+        delete[] array;
         return MB_INVALID_SIZE;
+      }
 
       for (int i = 0; i < conn_len; ++i)
         array[fillA++] = conn[i];
-    }
-  if (fillA != array_alloc)
-	 return MB_INVALID_SIZE;
-    
-  std::sort( array, array + array_alloc);
-  int numNodes = std::unique(array, array + array_alloc ) - array;
-  
+  }
+  if (fillA != array_alloc) {
+    delete[] array;
+    return MB_INVALID_SIZE;
+  }
+
+  std::sort(array, array + array_alloc);
+  int numNodes = std::unique(array, array + array_alloc) - array;
+
   file << "#$SMF 1.0\n";
   file << "#$vertices " << numNodes << std::endl;
   file << "#$faces " << numTriangles << std::endl;
   file << "# \n";
   file << "# output from MOAB \n";
   file << "# \n";
-  
+
   // output first the nodes
   // num nodes??
   // write the nodes 
   double coord[3];
-  for(int i=0; i<numNodes; i++)
-    {
-      EntityHandle node_handle = array[i];
-     
-      rval = mbImpl->get_coords(&node_handle,1, coord);
-      if(rval !=MB_SUCCESS) return rval;
-      
-      file << "v " << coord[0] << " " << coord[1] << " " << coord[2] << std::endl; 
+  for (int i = 0; i < numNodes; i++) {
+    EntityHandle node_handle = array[i];
+
+    rval = mbImpl->get_coords(&node_handle, 1, coord);
+    if (rval != MB_SUCCESS) {
+      delete[] array;
+      return rval;
     }
-  // write faces now
-  // leave a blank line for cosmetics
+
+    file << "v " << coord[0] << " " << coord[1] << " " << coord[2] << std::endl;
+  }
+  // Write faces now
+  // Leave a blank line for cosmetics
   file << " \n";
-  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e)
-    {
-      const EntityHandle* conn;
-      int conn_len;
-      rval = mbImpl->get_connectivity( *e, conn, conn_len );
-      if (MB_SUCCESS != rval  ) 
-	return rval;
-      if ( 3!=conn_len) 
-        return MB_INVALID_SIZE;
-      file << "f ";
-      for (int i = 0; i < conn_len; ++i)
-      {
-	int indexInArray = std::lower_bound( array, array + numNodes, conn[i] ) - array;
-        file << indexInArray + 1 << " " ;
-      }
-      file << std::endl;
+  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e) {
+    const EntityHandle* conn;
+    int conn_len;
+    rval = mbImpl->get_connectivity(*e, conn, conn_len);
+    if (MB_SUCCESS != rval) {
+      delete[] array;
+      return rval;
     }
+    if (3!= conn_len) {
+      delete[] array;
+      return MB_INVALID_SIZE;
+    }
+    file << "f ";
+    for (int i = 0; i < conn_len; ++i) {
+      int indexInArray = std::lower_bound(array, array + numNodes, conn[i]) - array;
+      file << indexInArray + 1 << " ";
+    }
+    file << std::endl;
+  }
 
   file.close();
-  delete [] array;
+  delete[] array;
   return MB_SUCCESS;
 }
 
 } // namespace moab
-

diff --git a/src/parallel/ParallelComm.cpp b/src/parallel/ParallelComm.cpp
index 2d9e61c..d9e06d5 100644
--- a/src/parallel/ParallelComm.cpp
+++ b/src/parallel/ParallelComm.cpp
@@ -614,6 +614,10 @@ namespace moab {
       
         result = pack_buffer(entities[i], adjacencies, tags, 
                              false, -1, &buff); 
+        if (MB_SUCCESS != result) {
+          delete[] sendCounts;
+          delete[] displacements;
+        }
         RRA("Failed to compute buffer size in scatter_entities.");
 
         buff_size = buff.buff_ptr - buff.mem_ptr - prev_size;
@@ -626,6 +630,8 @@ namespace moab {
     success = MPI_Bcast(sendCounts, nProcs, MPI_INT, from_proc, procConfig.proc_comm());
     if (MPI_SUCCESS != success) {
       result = MB_FAILURE;
+      delete[] sendCounts;
+      delete[] displacements;
       RRA("MPI_Bcast of buffer size failed.");
     }
   
@@ -643,6 +649,8 @@ namespace moab {
   
     if (MPI_SUCCESS != success) {
       result = MB_FAILURE;
+      delete[] sendCounts;
+      delete[] displacements;
       RRA("MPI_Scatterv of buffer failed.");
     }
 
@@ -655,10 +663,17 @@ namespace moab {
       rec_buff.reset_ptr(sizeof(int));
       result = unpack_buffer(rec_buff.buff_ptr, false, from_proc, -1, 
                              dum1a, dum1b, dum1p, dum2, dum2, dum3, dum4);
+      if (MB_SUCCESS != result) {
+        delete[] sendCounts;
+        delete[] displacements;
+      }
       RRA("Failed to unpack buffer in scatter_entities.");
       std::copy(dum4.begin(), dum4.end(), range_inserter(entities[my_proc]));
     }
 
+    delete[] sendCounts;
+    delete[] displacements;
+
     return MB_SUCCESS;
 #endif
   }

diff --git a/test/h5file/h5file_test.cpp b/test/h5file/h5file_test.cpp
index 66703a5..94dc218 100644
--- a/test/h5file/h5file_test.cpp
+++ b/test/h5file/h5file_test.cpp
@@ -42,7 +42,6 @@ const int REGION_SET_ID = 1103;
 const int EMPTY_SET_ID  = 1100;
 const int SET_SET_ID    = 1105;
 
-
 Interface* iface;
 
 void create();
@@ -83,7 +82,6 @@ int main(int argc, char* argv[])
     }
   }
   
-  
   iface = new Core();
   
   // create a dodecahedron and inscribed hex
@@ -98,6 +96,7 @@ int main(int argc, char* argv[])
     fprintf( stderr, "Failed to write \"%s\"\n", filename );
     if (MB_SUCCESS == iface->get_last_error( msg ))
       fprintf( stderr, "%s\n", msg.c_str() );
+    delete iface;
     return 1;
   }
   
@@ -109,6 +108,7 @@ int main(int argc, char* argv[])
     fprintf( stderr, "Failed to read \"%s\"\n", filename );
     if (MB_SUCCESS == iface->get_last_error( msg ))
       fprintf( stderr, "%s\n", msg.c_str() );
+    delete iface;
     return 1;
   }
   
@@ -117,6 +117,7 @@ int main(int argc, char* argv[])
   if (!compare())
   {
     fprintf(stderr, "Comparison failed.\n");
+    delete iface;
     return 1;
   }
   fprintf( stderr, "success!\n" );
@@ -129,6 +130,7 @@ int main(int argc, char* argv[])
     fprintf( stderr, "Failed to write \"%s\"\n", filename );
     if (MB_SUCCESS == iface->get_last_error( msg ))
       fprintf( stderr, "%s\n", msg.c_str() );
+    delete iface;
     return 1;
   }
  
@@ -146,6 +148,7 @@ int main(int argc, char* argv[])
     fprintf( stderr, "Failed to read \"%s\"\n", filename );
     if (MB_SUCCESS == iface->get_last_error( msg ))
       fprintf( stderr, "%s\n", msg.c_str() );
+    delete iface;
     return 1;
   }
 
@@ -154,6 +157,7 @@ int main(int argc, char* argv[])
   if (!compare())
   {
     fprintf(stderr, "Comparison failed.\n");
+    delete iface;
     return 1;
   }
   fprintf( stderr, "success!\n" );
@@ -167,6 +171,7 @@ int main(int argc, char* argv[])
   // Clean up the file.
   remove( filename );
   fprintf( stderr, "done.\n" );
+  delete iface;
   return 0;
 }
 
@@ -233,7 +238,6 @@ EntityHandle make_set( unsigned int options,
   return handle;
 }
 
-
 void create()
 {
   // Create dodecahedron
@@ -427,8 +431,7 @@ bool compare_conn( std::vector<EntityHandle>& conn1,
       return false;
     }
   }
- 
-  
+
   std::vector<int> tags[2];
   tags[0].resize( conn1.size() ); tags[1].resize( conn2.size() );
   Tag tag;
@@ -486,9 +489,8 @@ bool compare_sets( int id, const char* tag_name = 0 )
   EntityHandle set1 = *range.begin();
   EntityHandle set2 = *++range.begin();
   
-  
     // Compare set descriptions
-  
+
   unsigned opt1, opt2;
   if (MB_SUCCESS != iface->get_meshset_options( set1, opt1 ) ||
       MB_SUCCESS != iface->get_meshset_options( set2, opt2 ))
@@ -509,7 +511,6 @@ bool compare_sets( int id, const char* tag_name = 0 )
     return false;
   }
 
-
     // Compare set contents
     // First check if same number of entities.
     // Then select from three possible methods to compare set contents
@@ -599,10 +600,9 @@ bool compare_sets( int id, const char* tag_name = 0 )
     if (!ok)
       return false;
   }
-  
-    
+
     // Compare set parent/child links using global id
-  
+
   ok = true;
   const char* words[] = { "children", "parents" };
   std::vector<EntityHandle> adj1, adj2;
@@ -686,7 +686,6 @@ bool compare_tags( EntityHandle dod[] )
     return false;
   }
 
-
     // Get double tag handle and characterstics
   if (MB_SUCCESS != iface->tag_get_handle( dblname, 1, MB_TYPE_DOUBLE, tag, MB_TAG_DENSE|MB_TAG_STORE ))
     moab_error( "tag_get_handle(dblname)" );
@@ -708,7 +707,6 @@ bool compare_tags( EntityHandle dod[] )
     return false;
   }
  
-
     // Get handle tag handle and characterstics
   if (MB_SUCCESS != iface->tag_get_handle( handlename, 3, MB_TYPE_HANDLE, tag, MB_TAG_SPARSE|MB_TAG_STORE ))
     moab_error( "tag_get_handle(handlename)" );
@@ -760,8 +758,6 @@ bool compare_tags( EntityHandle dod[] )
   
   return true;
 }
- 
-  
 
 bool compare()
 {
@@ -861,6 +857,6 @@ void moab_error( const char* str )
   fprintf( stderr, "%s() failed.\n", str );
   if (MB_SUCCESS == iface->get_last_error( msg ))
     fprintf( stderr, "%s\n", msg.c_str() );
+  delete iface;
   exit( 1 );
 }
-  

diff --git a/test/io/VtkTest.cpp b/test/io/VtkTest.cpp
index 100674c..d6208a2 100644
--- a/test/io/VtkTest.cpp
+++ b/test/io/VtkTest.cpp
@@ -108,7 +108,7 @@ DECLARE_TEST(unstructured_field)
 
 int main( int argc, char* argv[] )
 {
-  int *test_indices = (int*)malloc( sizeof(int) * num_tests );
+  int *test_indices = (int*)malloc(sizeof(int) * num_tests);
   int test_count;
     // if no arguments, do all tests
   if (argc == 1) {
@@ -126,8 +126,7 @@ int main( int argc, char* argv[] )
   }
   
   int fail_count = 0;
-  for (int i = 0; i < test_count; ++i)
-  {
+  for (int i = 0; i < test_count; ++i) {
     test_data& test = test_array[test_indices[i]];
     printf("Testing %s...\n", test.name );
     if (!(test.result = test.test()))
@@ -137,23 +136,23 @@ int main( int argc, char* argv[] )
   printf("\n\n");
   if (fail_count) {
     printf("FAILED TESTS:\n");
-    for (int i = 0; i < test_count; ++i)
-    {
+    for (int i = 0; i < test_count; ++i) {
       test_data& test = test_array[test_indices[i]];
       if (!test.result)
         printf("\t%s\n", test.name);
     }
   }
-    
-  
+
   if (test_count == 0)
     printf("0 VTK tests run\n");
   else if (fail_count == 0)
     printf("%d tests passed\n", test_count );
   else
-    printf("%d of %d tests failed\n", fail_count, test_count );
+    printf("%d of %d tests failed\n", fail_count, test_count);
   printf("\n");
-  
+
+  free(test_indices);
+
   return fail_count;
 }
 
@@ -179,7 +178,6 @@ static inline bool is_error( ErrorCode b )
 bool read_file( Interface* iface, const char* file );
 bool write_and_read( Interface* iface1, Interface* iface2 );
 
-
 bool test_read_write_element( const double* coords, unsigned num_coords,
                               const int* vtk_conn, const int* moab_conn,
                               unsigned num_conn,
@@ -203,8 +201,7 @@ bool test_edge2()
       
   return test_read_write_element( coords, 5, conn, conn, 10, 5, 3, MBEDGE );
 }
-  
-  
+
 bool test_edge3()
 {
   const double coords[] =
@@ -243,7 +240,6 @@ bool test_tri3()
   return test_read_write_element( coords, 5, conn, conn, 12, 4, 5, MBTRI );
 }
 
-
 bool test_tri6()
 {
   const double coords[] = 
@@ -429,7 +425,6 @@ bool test_tet10()
   return test_read_write_element( coords, 14, conn, conn, 20, 2, 24, MBTET );
 }
 
-
 const double grid_2x2x2[] =
   { 0, 0, 0,
     1, 0, 0,
@@ -904,7 +899,6 @@ bool test_vector_attrib_double()
   return test_vector_attrib("double", MB_TYPE_DOUBLE);
 }
 
-
 bool test_tensor_attrib_uchar()
 {
   return test_tensor_attrib("unsigned_char", MB_TYPE_INTEGER);
@@ -955,9 +949,6 @@ bool test_tensor_attrib_double()
   return test_tensor_attrib("double", MB_TYPE_DOUBLE);
 }
 
-
-
-
 bool read_file( Interface* iface, const char* file )
 {
   char fname[] = "tmp_file.vtk";
@@ -1086,7 +1077,6 @@ bool match_vertices_and_elements( Interface* iface,
   return true;
 }
 
-
 bool check_elements( Interface* iface,
                      EntityType moab_type, unsigned num_elem, unsigned vert_per_elem,
                      const double* coords, unsigned num_vert, 
@@ -1099,8 +1089,6 @@ bool check_elements( Interface* iface,
   CHECK(rval);
   return true;
 }
-      
-                     
 
 bool test_read_write_element( const double* coords, unsigned num_verts,
                               const int* vtk_conn, const int* moab_conn,
@@ -1295,7 +1283,6 @@ bool check_tag_values( Interface* iface,
   return true;
 }
 
-
 bool check_tag_values( Interface* iface, DataType type, int vals_per_ent )
 {
   EntityHandle vert_handles[6], elem_handles[2];
@@ -1369,7 +1356,7 @@ bool test_tensor_attrib( const char* vtk_type, DataType mb_type )
   return check_tag_data( file, mb_type, 9 );
 } 
 
-bool test_subset( )
+bool test_subset()
 {
   Core moab_inst;
   Interface& moab = moab_inst;

diff --git a/test/kd_tree_time.cpp b/test/kd_tree_time.cpp
index 10af975..af0e33d 100644
--- a/test/kd_tree_time.cpp
+++ b/test/kd_tree_time.cpp
@@ -8,49 +8,49 @@
 
 using namespace moab;
 
-void usage( const char* argv0 )
+void usage(const char* argv0)
 {
   fprintf(stderr, "usage: %s [-t] [-d <result_file>] <tree_file><point_file> [<count>]\n", argv0);
   exit(1);
 }
 
-void print_file_stats( Interface& moab )
+void print_file_stats(Interface& moab)
 {
   ErrorCode rval;
   int num_tri;
   Range sets;
   unsigned long set_mem, set_am, tag_mem, tag_am;
-  
-  rval = moab.get_number_entities_by_type( 0, MBTRI, num_tri );
+
+  rval = moab.get_number_entities_by_type(0, MBTRI, num_tri);
   if (MB_SUCCESS != rval)
     num_tri = -1;
-  rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );
+  rval = moab.get_entities_by_type(0, MBENTITYSET, sets);
   if (MB_SUCCESS != rval)
     sets.clear();
-  
-  moab.estimated_memory_use( sets, 0, 0, &set_mem, &set_am, 0, 0, 0, 0, &tag_mem, &tag_am );
-  printf( "Triangles:   %d\n", num_tri );
-  printf( "Sets:        %lu\n", (unsigned long)sets.size() );
-  printf( "Set storage: %lu (%lu)\n", set_mem, set_am );
-  printf( "Tag storage: %lu (%lu)\n", tag_mem, tag_am );
+
+  moab.estimated_memory_use(sets, 0, 0, &set_mem, &set_am, 0, 0, 0, 0, &tag_mem, &tag_am);
+  printf("Triangles:   %d\n", num_tri);
+  printf("Sets:        %lu\n", (unsigned long)sets.size());
+  printf("Set storage: %lu (%lu)\n", set_mem, set_am);
+  printf("Tag storage: %lu (%lu)\n", tag_mem, tag_am);
 }
 
-int main( int argc, char* argv[] ) 
+int main(int argc, char* argv[])
 {
   double* values;
   unsigned long length;
   FILE *file, *rfile = 0;
   unsigned long count = 0;
   clock_t t;
-  
+
   const char* tree_file = 0;
   const char* point_file = 0;
   const char* result_file = 0;
   bool query_triangles = false;
-  
+
   if (argc < 3 || argc > 7)
     usage(argv[0]);
-  
+
   for (int i = 1; i < argc; ++i) {
     if (!strcmp("-t", argv[i]))
       query_triangles = true;
@@ -66,87 +66,93 @@ int main( int argc, char* argv[] )
       point_file = argv[i];
     else {
       char* endptr;
-      count = strtol( argv[i], &endptr, 0 );
+      count = strtol(argv[i], &endptr, 0);
       if (*endptr || count < 1)
         usage(argv[0]);
     }
   }
-  
-  file = fopen( point_file, "rb" );
+
+  file = fopen(point_file, "rb");
   if (!file) {
     perror(point_file);
     return 2;
   }
-  fseek( file, 0, SEEK_END );
-  length = ftell(file) / (3*sizeof(double));
-  fseek( file, 0, SEEK_SET );
-  values = new double[3*length];
-  if (length != fread( values, 3*sizeof(double), length, file )) {
-    fprintf( stderr, "Error reading %lu points from file \"%s\"\n", length, argv[2] );
+  fseek(file, 0, SEEK_END);
+  length = ftell(file) / (3 * sizeof(double));
+  fseek(file, 0, SEEK_SET);
+  values = new double[3 * length];
+  if (length != fread(values, 3 * sizeof(double), length, file)) {
+    fprintf(stderr, "Error reading %lu points from file \"%s\"\n", length, argv[2]);
+    delete[] values;
     return 2;
   }
-  fclose( file );
-  
+  fclose(file);
+
   if (result_file) {
-    rfile = fopen( result_file, "w" );
+    rfile = fopen(result_file, "w");
     if (!rfile) {
       perror(result_file);
+      delete[] values;
       return 2;
     }
   }
-  
+
   if (!count)
     count = length;
- 
-  printf("Loading tree..."); fflush( stdout );
+
+  printf("Loading tree...");
+  fflush(stdout);
   t = clock();
   Core moab;
-  ErrorCode rval = moab.load_mesh( tree_file, 0, 0 );
+  ErrorCode rval = moab.load_mesh(tree_file, 0, 0);
   if (MB_SUCCESS != rval) {
-    fprintf(stderr,"Failed to read file: %s\n", tree_file );
+    fprintf(stderr,"Failed to read file: %s\n", tree_file);
+    delete[] values;
     return 2;
   }
-  printf("%0.2f seconds\n", (clock()-t)/(double)CLOCKS_PER_SEC); fflush( stdout );
-  
+  printf("%0.2f seconds\n", (clock() - t) / (double)CLOCKS_PER_SEC);
+  fflush(stdout);
+
   Range range;
   AdaptiveKDTree tool(&moab);
   tool.find_all_trees(range);
   if (range.size() != 1) {
-    fprintf(stderr,"%s : found %d kd-trees\n", argv[1], (int)range.size() );
+    fprintf(stderr,"%s : found %d kd-trees\n", argv[1], (int)range.size());
+    delete[] values;
     return 3;
   }
   EntityHandle root = range.front();
 
-  print_file_stats( moab );
-  
-  printf("Running point queries..."); fflush( stdout );
+  print_file_stats(moab);
+
+  printf("Running point queries...");
+  fflush(stdout);
   t = clock();
   EntityHandle leaf;
   double pt[3];
   for (unsigned long i = 0; i < count; ++i) {
     const double* coords = values + 3 * (i % length);
     if (query_triangles)
-      rval = tool.closest_triangle( root, coords, pt, leaf );
+      rval = tool.closest_triangle(root, coords, pt, leaf);
     else
       rval = tool.point_search(coords, leaf, 0.0, NULL, &root);
     if (MB_SUCCESS != rval) {
       fprintf(stderr, "Failure (ErrorCode == %d) for point %d (%f, %f, %f)\n",
-        (int)rval, (int)(count % length), coords[0], coords[1], coords[2] );
+        (int)rval, (int)(count % length), coords[0], coords[1], coords[2]);
     }
     else if (rfile) {
       if (query_triangles)
-        fprintf( rfile, "%f %f %f %f %f %f %lu\n", 
+        fprintf(rfile, "%f %f %f %f %f %f %lu\n",
           coords[0], coords[1], coords[2],
-          pt[0], pt[1], pt[2], (unsigned long)leaf );
+          pt[0], pt[1], pt[2], (unsigned long)leaf);
       else
-        fprintf( rfile, "%f %f %f %lu\n", 
-          coords[0], coords[1], coords[2], (unsigned long)leaf );
+        fprintf(rfile, "%f %f %f %lu\n",
+          coords[0], coords[1], coords[2], (unsigned long)leaf);
     }
   }
-  printf("%0.2f seconds\n", (clock()-t)/(double)CLOCKS_PER_SEC); fflush( stdout );
+  printf("%0.2f seconds\n", (clock() - t) / (double)CLOCKS_PER_SEC);
+  fflush(stdout);
   delete[] values;
 
   return 0;
 }
-
-  

diff --git a/test/parallel/scdtest.cpp b/test/parallel/scdtest.cpp
index 5fe6f36..3202621 100644
--- a/test/parallel/scdtest.cpp
+++ b/test/parallel/scdtest.cpp
@@ -47,37 +47,37 @@ int main(int argc, char *argv[])
   MPI_Init(&argc, &argv);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   MPI_Comm_size(MPI_COMM_WORLD, &size);
-  if(size != 4 && size != 2) {
+  if (size != 4 && size != 2) {
     cerr << "Run this with 2 or 4 processes\n";
     exit(1);
   }
-  
+
   mbint = new Core();
-  mbpc  = new ParallelComm(mbint, MPI_COMM_WORLD);
+  mbpc = new ParallelComm(mbint, MPI_COMM_WORLD);
 
   set_local_domain_bounds();
   create_hexes_and_verts();
   resolve_and_exchange();
 
+  delete mbpc; // ParallelComm instance should be deleted before MOAB instance is deleted
+  delete mbint;
+
   MPI_Finalize();
   return 0;
 }
 
-
 void set_local_domain_bounds() 
 {
   switch (size) {
     case 2:
-        switch(rank) {
+        switch (rank) {
           case 0:
-              is = 0; ie = NI/2;
+              is = 0; ie = NI / 2;
               js = 0; je = NJ;
               ks = 0; ke = NK;
               break;
-
-
           case 1:
-              is = NI/2; ie = NI;
+              is = NI / 2; ie = NI;
               js = 0; je = NJ;
               ks = 0; ke = NK;
               break;
@@ -85,25 +85,25 @@ void set_local_domain_bounds()
         break;
         
     case 4:
-        switch(rank) {
+        switch (rank) {
           case 0:
-              is = 0; ie = NI/2;
-              js = 0; je = NJ/2;
+              is = 0; ie = NI / 2;
+              js = 0; je = NJ / 2;
               ks = 0; ke = NK;
               break;
           case 1:
-              is = NI/2; ie = NI;
-              js = 0; je = NJ/2;
+              is = NI / 2; ie = NI;
+              js = 0; je = NJ / 2;
               ks = 0; ke = NK;
               break;
           case 2:
-              is = 0; ie = NI/2;
-              js = NJ/2; je = NJ;
+              is = 0; ie = NI / 2;
+              js = NJ / 2; je = NJ;
               ks = 0; ke = NK;
               break;
           case 3:
-              is = NI/2; ie = NI;
-              js = NJ/2; je = NJ;
+              is = NI / 2; ie = NI;
+              js = NJ / 2; je = NJ;
               ks = 0; ke = NK;
               break;
         }
@@ -115,12 +115,11 @@ void set_local_domain_bounds()
   }
 }
 
-
 void create_hexes_and_verts()
 {
   Core *mbcore = dynamic_cast<Core*>(mbint);
   HomCoord coord_min(0,0,0);
-  HomCoord coord_max(ie-is, je-js, ke-ks);
+  HomCoord coord_max(ie - is, je - js, ke - ks);
   EntitySequence* vertex_seq = NULL;
   EntitySequence* cell_seq = NULL;
   EntityHandle vs, cs;
@@ -139,32 +138,31 @@ void create_hexes_and_verts()
   Tag global_id_tag;
   error(mbint->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, global_id_tag));
   EntityHandle handle = vs;
-  int i,j,k;
+  int i, j, k;
 
   ErrorCode err;
 
-  for(k = ks; k < ke + 1; k++)
-    for(j = js; j < je + 1; j++)
-      for(i = is; i < ie + 1; i++) {
-        gid = 1 + i + j*(NI+1) + k*(NI+1)*(NJ+1);
+  for (k = ks; k < ke + 1; k++)
+    for (j = js; j < je + 1; j++)
+      for (i = is; i < ie + 1; i++) {
+        gid = 1 + i + j*(NI + 1) + k*(NI + 1)*(NJ + 1);
         err = mbint->tag_set_data(global_id_tag, &handle, 1, &gid);
-        if(err != MB_SUCCESS) {
+        if (err != MB_SUCCESS) {
           exit(1);
         }
         handle++;
       }
 
   handle = cs;
-  for(k = ks; k < ke; k++)
-    for(j = js; j < je; j++)
-      for(i = is; i < ie; i++) {
+  for (k = ks; k < ke; k++)
+    for (j = js; j < je; j++)
+      for (i = is; i < ie; i++) {
         gid = 1 + i + j*NI + k*NI*NJ;
         error(mbint->tag_set_data(global_id_tag, &handle, 1, &gid));
-	handle++;
+        handle++;
       }
 }
 
-
 void resolve_and_exchange()
 {
   EntityHandle entity_set;
@@ -198,7 +196,7 @@ void resolve_and_exchange()
 
 void error(ErrorCode err)
 {
-  if(err != MB_SUCCESS) {
+  if (err != MB_SUCCESS) {
     cerr << "Error: MOAB function failed\n";
     assert(0);
   }

diff --git a/tools/mbcoupler/Coupler.cpp b/tools/mbcoupler/Coupler.cpp
index f7f74b2..28f67ca 100644
--- a/tools/mbcoupler/Coupler.cpp
+++ b/tools/mbcoupler/Coupler.cpp
@@ -299,7 +299,6 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
     // appending results to tuple_list;
     // keep local points separately, in local_pts, which has pairs
     // of <local_index, mapped_index>, where mapped_index is the index
-    // of <local_index, mapped_index>, where mapped_index is the index
     // into the mappedPts tuple list
 
   unsigned int my_rank = (myPc ? myPc->proc_config().proc_rank() : 0);
@@ -333,19 +332,21 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
   int num_to_me = 0;
   for (unsigned int i = 0; i < target_pts.get_n(); i++)
     if (target_pts.vi_rd[2*i] == (int)my_rank) num_to_me++;
-
+#ifndef NDEBUG
   printf("rank: %d local points: %d, nb sent target pts: %d mappedPts: %d num to me: %d \n",
          my_rank, num_points, target_pts.get_n(), mappedPts->get_n(), num_to_me);
-    // perform scatter/gather, to gather points to source mesh procs
+#endif
+  // perform scatter/gather, to gather points to source mesh procs
   if (myPc) {
     (myPc->proc_config().crystal_router())->gs_transfer(1, target_pts, 0);
 
     num_to_me = 0;
     for (unsigned int i = 0; i < target_pts.get_n(); i++)
       if (target_pts.vi_rd[2*i] == (int)my_rank) num_to_me++;
-
+#ifndef NDEBUG
     printf("rank: %d after first gs nb received_pts: %d; num_from_me = %d\n",
            my_rank, target_pts.get_n(), num_to_me);
+#endif
       // after scatter/gather:
       // target_pts.set_n( # points local proc has to map );
       // target_pts.vi_wr[2*i] = proc sending point i
@@ -374,15 +375,19 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
 
       // no longer need target_pts
     target_pts.reset();
-
+#ifndef NDEBUG
     printf("rank: %d nb sent source pts: %d, mappedPts now: %d\n",
            my_rank, source_pts.get_n(),  mappedPts->get_n());
+#endif
       // send target points back to target procs
     (myPc->proc_config().crystal_router())->gs_transfer(1, source_pts, 0);
 
+#ifndef NDEBUG
     printf("rank: %d nb received source pts: %d\n",
            my_rank, source_pts.get_n());
+#endif
   }
+
   
     // store proc/index tuples in targetPts, and/or pass back to application;
     // the tuple this gets stored to looks like:
@@ -411,7 +416,7 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
   unsigned int local_pts = 0;
   for (unsigned int i = 0; i < source_pts.get_n(); i++) {
     if (-1 != source_pts.vi_rd[3*i+2]) { //why bother sending message saying "i don't have the point" if it gets discarded?
-      if (source_pts.vi_rd[3*i] == (int)my_rank) local_pts++;
+      //if (source_pts.vi_rd[3*i] == (int)my_rank) local_pts++;
       int tgt_index = 3*source_pts.vi_rd[3*i+1];
       tl_tmp->vi_wr[tgt_index]   = source_pts.vi_rd[3*i];
       tl_tmp->vi_wr[tgt_index+1] = source_pts.vi_rd[3*i+1];
@@ -422,11 +427,18 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
     // count missing points
   unsigned int missing_pts = 0;
   for (int i = 0; i < num_points; i++) 
-    if (tl_tmp->vi_rd[3*i+1] == -1) missing_pts++;
-  
+  {
+    if (tl_tmp->vi_rd[3*i+1] == -1)
+      missing_pts++;
+    else
+      if (tl_tmp->vi_rd[3*i]==(int)my_rank)
+        local_pts++;
+  }
+#ifndef NDEBUG
   printf("rank: %d point location: wanted %d got %u locally, %d remote, missing %d\n",
          my_rank, num_points, local_pts,  num_points-missing_pts-local_pts, missing_pts);
-  assert(0==missing_pts); //will litely break on curved geometries
+#endif
+  assert(0==missing_pts); //will likely break on curved geometries
   
     // no longer need source_pts
   source_pts.reset();

diff --git a/tools/mbzoltan/MBZoltan.cpp b/tools/mbzoltan/MBZoltan.cpp
index d07ffcf..1ec6757 100644
--- a/tools/mbzoltan/MBZoltan.cpp
+++ b/tools/mbzoltan/MBZoltan.cpp
@@ -65,34 +65,39 @@ static int *Parts=NULL;
 
 const bool debug = false;
 
-MBZoltan::MBZoltan( Interface *impl , 
-
+MBZoltan::MBZoltan( Interface *impl,
                     const bool use_coords,
-                    int argc, 
+                    int argc,
                     char **argv
 #ifdef CGM
                     , GeometryQueryTool *gqt
-#endif                   
-) 
-                   : mbImpl(impl), 
-
-                     myZZ(NULL), 
-                     newMoab(false), 
+#endif
+)
+                   : mbImpl(impl),
+                     myZZ(NULL),
+                     newMoab(false),
+                     newComm(false),
                      useCoords(use_coords),
-                     argcArg(argc), 
+                     argcArg(argc),
                      argvArg(argv)
 #ifdef CGM
                    , gti(gqt)
 #endif
 {
   mbpc = ParallelComm::get_pcomm(mbImpl, 0);
-  if (!mbpc)
-    mbpc = new ParallelComm( impl, MPI_COMM_WORLD, 0 );
+  if (!mbpc) {
+    mbpc = new ParallelComm(impl, MPI_COMM_WORLD, 0);
+    newComm = true;
+  }
 }
 
 MBZoltan::~MBZoltan() 
 {
-  if (NULL == myZZ) delete myZZ;
+  if (NULL != myZZ)
+    delete myZZ;
+
+  if (newComm)
+    delete mbpc;
 }
 
 ErrorCode MBZoltan::balance_mesh(const char *zmethod,
@@ -1068,7 +1073,8 @@ ErrorCode MBZoltan::partition_round_robin(const int n_part)
     DLIList<int> shared_procs;
     shared_procs.append(proc);
     TDParallel *td_par = (TDParallel *) entity->get_TD(&TDParallel::is_parallel);
-    if (td_par == NULL) td_par = new TDParallel(entity, NULL, &shared_procs);
+    if (td_par == NULL)
+      td_par = new TDParallel(entity, NULL, &shared_procs);
     loads[proc] += entity->measure();
 
     // assign to volumes, it should be removed in future
@@ -1079,7 +1085,8 @@ ErrorCode MBZoltan::partition_round_robin(const int n_part)
     for (j = 0; j < n_vol; j++) {
       RefEntity *vol = volumes.get_and_step();
       td_par = (TDParallel *) vol->get_TD(&TDParallel::is_parallel);
-      if (td_par == NULL) td_par = new TDParallel(vol, NULL, &shared_procs);
+      if (td_par == NULL)
+        td_par = new TDParallel(vol, NULL, &shared_procs);
     }
 
     // add local surface load
@@ -1117,6 +1124,8 @@ ErrorCode MBZoltan::partition_round_robin(const int n_part)
 
           if (parent_td == NULL) {
             PRINT_ERROR("parent Volume has to be partitioned.");
+            delete[] loads;
+            delete[] ve_loads;
             return MB_FAILURE;
           }
           child_shared_procs.append_unique(parent_td->get_charge_proc());
@@ -1129,6 +1138,8 @@ ErrorCode MBZoltan::partition_round_robin(const int n_part)
             if (entity->entity_type_info() == typeid(RefFace)) { // face
               if (child_shared_procs.size() != 2) {
                 PRINT_ERROR("Error: # of shared processors of interface surface should be 2.");
+                delete[] loads;
+                delete[] ve_loads;
                 return MB_FAILURE;
               }
 

diff --git a/tools/mbzoltan/MBZoltan.hpp b/tools/mbzoltan/MBZoltan.hpp
index e36ec13..269d9ae 100644
--- a/tools/mbzoltan/MBZoltan.hpp
+++ b/tools/mbzoltan/MBZoltan.hpp
@@ -171,6 +171,8 @@ using namespace moab;
     Range partSets;
   
     bool newMoab;
+
+    bool newComm;
   
     bool useCoords;
 


https://bitbucket.org/fathomteam/moab/commits/8f0620ae268a/
Changeset:   8f0620ae268a
Branch:      None
User:        iulian07
Date:        2013-09-26 02:54:37
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  1 file

diff --git a/itaps/imesh/testc_cbind.cpp b/itaps/imesh/testc_cbind.cpp
index 9520768..fdf49a0 100755
--- a/itaps/imesh/testc_cbind.cpp
+++ b/itaps/imesh/testc_cbind.cpp
@@ -62,7 +62,7 @@
 #include "iMesh_extensions.h"
 #include "moab/Types.hpp"
 using namespace moab;
-extern enum iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE+1];
+extern enum iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE + 1];
 
 
 #define FALSE 0
@@ -78,17 +78,22 @@ extern enum iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE+1];
 #  define DEFAULT_INPUT_FILE STRINGIFY(DEFAULT_TEST_FILE)
 #endif
 
+static bool assert_pass;
+#define ASSERT(COND) \
+  assert_pass = true; \
+  if (!(COND)) { \
+    PRINT_ASSERT_FAILURE(#COND, __FILE__, __LINE__); \
+    assert_pass = false; \
+  }
 
-#define ASSERT(A) if (!(A)) return ASSERT_( #A, __FILE__, __LINE__ )
-int ASSERT_( const char* cond, const char* file, int line ) 
+void PRINT_ASSERT_FAILURE(const char* cond, const char* file, int line)
 {
   printf("Condition: %s\n", cond );
   printf(" failed at %s line %d\n", file, line );
-  return FALSE;
 }
 
-#define CHK(err) if (err != iBase_SUCCESS)                              \
-    do {printf("%s:%d ITAPS error %d\n",__FILE__,__LINE__,err); return 0;} while (0)
+#define CHK(err) if (err != iBase_SUCCESS) \
+  do {printf("%s:%d ITAPS error %d\n", __FILE__, __LINE__, err); return 0;} while (0)
 
 static iBase_EntitySetHandle root_set;
 
@@ -175,17 +180,22 @@ int topology_dimension_test(iMesh_Instance mesh)
                       &dimensions, &dimensions_alloc, &dimensions_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get dimensions of faces in topology_test.\n");
+    free(faces);
     return FALSE;
   }
 
   if (dimensions_size != faces_size) {
     printf("Didn't get the right number of types in topology_test.\n");
+    free(faces);
+    free(dimensions);
     return FALSE;
   }
     
     /* make sure all elements are 2D */
   for (i = 0; i < faces_size; i++) {
     if (dimensions[i] != iBase_FACE) {
+      free(faces);
+      free(dimensions);
       return FALSE;
     }
   }
@@ -253,6 +263,8 @@ int topology_adjacency_test(iMesh_Instance mesh)
       if (topologies_size != entities_size) {
         printf("Didn't get the right number of topologies "
                "in topology_adjacency_test.\n");
+        free(topologies);
+        free(entities);
         return FALSE;
       }
     
@@ -282,11 +294,15 @@ int topology_adjacency_test(iMesh_Instance mesh)
     iMesh_getNumOfTopo(mesh, root_set, top_j, &num_tops, &result);
     if (iBase_SUCCESS != result) {
       printf("Failed to get number of topologies in adjacencies_test.\n");
+      for (i = 0; i < iMesh_ALL_TOPOLOGIES; i++)
+        free(entity_vectors[i]);
       return FALSE;
     }
     
     if (entity_vectors_sizes[top_j] != num_tops) {
       printf("Topology count mismatch.\n");
+      for (i = 0; i < iMesh_ALL_TOPOLOGIES; i++)
+        free(entity_vectors[i]);
       return FALSE;
     }
   }
@@ -313,12 +329,18 @@ int topology_adjacency_test(iMesh_Instance mesh)
                          &face_offsets_size, &result);
       if (iBase_SUCCESS != result) {
         printf("Failed to get adjacent faces of regions in adjacencies_test.\n");
+        for (i = 0; i < iMesh_ALL_TOPOLOGIES; i++)
+          free(entity_vectors[i]);
         return FALSE;
       }
 
-      if (num_region+1 != face_offsets_size) {
+      if (num_region + 1 != face_offsets_size) {
         printf("Number of offsets didn't agree with number of "
                "regions in topology_adjacency_test.\n");
+        free(face_offsets);
+        free(adj_faces);
+        for (i = 0; i < iMesh_ALL_TOPOLOGIES; i++)
+          free(entity_vectors[i]);
         return FALSE;
       }
 
@@ -326,23 +348,23 @@ int topology_adjacency_test(iMesh_Instance mesh)
 
         /* check # of faces really loaded */
       if (region_type == iMesh_TETRAHEDRON) {
-        if (adj_faces_size == 4*num_region)
+        if (adj_faces_size == 4 * num_region)
           face_loaded = TRUE;
       }
       else if (region_type == iMesh_HEXAHEDRON) {
-        if (adj_faces_size == 6*num_region)
+        if (adj_faces_size == 6 * num_region)
           face_loaded = TRUE;
       }
       else if (region_type == iMesh_PRISM) {
-        if (adj_faces_size == 5*num_region)
+        if (adj_faces_size == 5 * num_region)
           face_loaded = TRUE;
       }
       else if (region_type == iMesh_PYRAMID) {
-        if (adj_faces_size == 5*num_region)
+        if (adj_faces_size == 5 * num_region)
           face_loaded = TRUE;
       }
       else if (region_type == iMesh_SEPTAHEDRON) {
-        if (adj_faces_size == 7*num_region)
+        if (adj_faces_size == 7 * num_region)
           face_loaded = TRUE;
       }
       else
@@ -360,23 +382,34 @@ int topology_adjacency_test(iMesh_Instance mesh)
                          &region_offsets_size, &result);
       if (iBase_SUCCESS != result) {
         printf("Failed to get regions from faces in adjacencies_test.\n");
+        free(face_offsets);
+        free(adj_faces);
+        for (i = 0; i < iMesh_ALL_TOPOLOGIES; i++)
+          free(entity_vectors[i]);
         return FALSE;
       }
 
-      if (adj_faces_size+1 != region_offsets_size) {
+      if (adj_faces_size + 1 != region_offsets_size) {
         printf("Number of offsets didn't agree with number of faces in topology_adjacency_test.\n");
+        free(face_offsets);
+        free(region_offsets);
+        free(adj_faces);
+        free(adj_regions);
+        for (i = 0; i < iMesh_ALL_TOPOLOGIES; i++)
+          free(entity_vectors[i]);
         return FALSE;
       }
 
       interior = (iBase_EntityHandle*)malloc(adj_faces_size*sizeof(iBase_EntityHandle)),
       exterior = (iBase_EntityHandle*)malloc(adj_faces_size*sizeof(iBase_EntityHandle));
-      num_int = 0; num_ext = 0;
-      
+      num_int = 0;
+      num_ext = 0;
+
         /* find the interior faces having two adjacent regions */
       for (i = 0; i < adj_faces_size; i++) {
         next_offset = 0;
         if (i == adj_faces_size-1) next_offset = adj_regions_size;
-        else next_offset = region_offsets[i+1];
+        else next_offset = region_offsets[i + 1];
 
         if (next_offset - region_offsets[i] == 2) {
           found = FALSE;
@@ -386,7 +419,8 @@ int topology_adjacency_test(iMesh_Instance mesh)
               break;
             }
           }
-          if (!found) interior[num_int++] = adj_faces[i];
+          if (!found)
+            interior[num_int++] = adj_faces[i];
         }
       }
 
@@ -400,7 +434,8 @@ int topology_adjacency_test(iMesh_Instance mesh)
             break;
           }
         }
-        if (!found) exterior[num_ext++] = adj_faces[i];
+        if (!found)
+          exterior[num_ext++] = adj_faces[i];
       }
 
       num_faces_per_region = face_offsets[1] - face_offsets[0];
@@ -408,13 +443,22 @@ int topology_adjacency_test(iMesh_Instance mesh)
         /* check # of exterior and interior faces */
         /* should be #exterior_faces + 2 * #interior_faces = #faces_per_region */
         /* * #regions */
-      if (face_loaded)
-        if (num_ext+2*num_int !=
+      if (face_loaded) {
+        if (num_ext + 2*num_int !=
             num_faces_per_region*num_region) {
           printf("exterior/interior failure: %d ext, %d int, %d regions, %d faces per\n",
                  num_ext, num_int, num_region, num_faces_per_region);
+          free(face_offsets);
+          free(region_offsets);
+          free(adj_faces);
+          free(adj_regions);
+          free(interior);
+          free(exterior);
+          for (i = 0; i < iMesh_ALL_TOPOLOGIES; i++)
+            free(entity_vectors[i]);
           return FALSE;
-    }
+        }
+      }
 
       free(face_offsets);
       free(region_offsets);
@@ -456,8 +500,8 @@ int entity_connectivity_test(iMesh_Instance mesh)
   for (type = iBase_EDGE; type < iBase_ALL_TYPES; type++) {
     entities = NULL; entities_alloc = 0;
     adj_ents = NULL; adj_ents_alloc = 0;
-    offsets = NULL; offsets_alloc = 0;
     indices = NULL; indices_alloc = 0;
+    offsets = NULL; offsets_alloc = 0;
     iMesh_getAdjEntIndices( mesh, root_set, 
                             type, iMesh_ALL_TOPOLOGIES, iBase_VERTEX,
                             &entities, &entities_alloc, &entities_size,
@@ -472,34 +516,71 @@ int entity_connectivity_test(iMesh_Instance mesh)
 
     if (entities_alloc != entities_size) {
       printf("Number of entities didn't agree with array size in connectivity_test.\n");
+      free(entities);
+      free(adj_ents);
+      free(indices);
+      free(offsets);
       return FALSE;
     }
 
     if (offsets_alloc != offsets_size) {
       printf("Number of offsets didn't agree with array size in connectivity_test.\n");
+      free(entities);
+      free(adj_ents);
+      free(indices);
+      free(offsets);
       return FALSE;
     }
 
     if (indices_alloc != indices_size) {
       printf("Number of indices didn't agree with array size in connectivity_test.\n");
+      free(entities);
+      free(adj_ents);
+      free(indices);
+      free(offsets);
       return FALSE;
     }
 
     if (adj_ents_alloc != adj_ents_size) {
       printf("Number of adjacent entities didn't agree with array size in connectivity_test.\n");
+      free(entities);
+      free(adj_ents);
+      free(indices);
+      free(offsets);
       return FALSE;
     }
     
-    if (offsets_size != entities_size+1) {
+    if (offsets_size != entities_size + 1) {
       printf("Invalid/inconsistent offset size from iMesh_getAdjEntIndices.\n");
+      free(entities);
+      free(adj_ents);
+      free(indices);
+      free(offsets);
       return FALSE;
     }
-    
+
       /* check that results are valid */
-    for (i = 0; i < entities_size; ++i) 
-      ASSERT( offsets[i] < offsets[i+1] && offsets[i] < indices_size );
-    for (i = 0; i < indices_size; ++i)
+    for (i = 0; i < entities_size; ++i) {
+      ASSERT( offsets[i] < offsets[i + 1] && offsets[i] < indices_size );
+      if (!assert_pass) {
+        free(entities);
+        free(adj_ents);
+        free(indices);
+        free(offsets);
+        return FALSE;
+      }
+    }
+
+    for (i = 0; i < indices_size; ++i) {
       ASSERT( indices[i] >= 0 && indices[i] < adj_ents_size );
+      if (!assert_pass) {
+        free(entities);
+        free(adj_ents);
+        free(indices);
+        free(offsets);
+        return FALSE;
+      }
+    }
     
       /* compare initial entity list against result of iMesh_getEntities */
     entities2 = NULL; entities2_alloc = 0;
@@ -508,41 +589,92 @@ int entity_connectivity_test(iMesh_Instance mesh)
                        &entities2, &entities2_alloc, &entities2_size,
                        &result );
     ASSERT( iBase_SUCCESS == result );
+    if (!assert_pass) {
+      free(entities);
+      free(adj_ents);
+      free(indices);
+      free(offsets);
+      return FALSE;
+    }
 
     size = sizeof(iBase_EntityHandle)*entities_size;
     sorted = (iBase_EntityHandle*)malloc(size);
     memcpy( sorted, entities, size );
     qsort( sorted, entities_size, sizeof(iBase_EntityHandle), &qsort_comp_handles );
     qsort( entities2, entities2_size, sizeof(iBase_EntityHandle), &qsort_comp_handles );
-    ASSERT( entities_size == entities2_size && !memcmp(sorted, entities2, size) ); 
+
+    ASSERT( entities_size == entities2_size && !memcmp(sorted, entities2, size) );
+    if (!assert_pass) {
+      free(entities);
+      free(adj_ents);
+      free(indices);
+      free(offsets);
+      free(entities2);
+      free(sorted);
+      return FALSE;
+    }
+
     free(entities2);
     free(sorted);
-    
+
       /* compare results against output of iMesh_getEntAdj */
     for (i = 0; i < entities_size; ++i) {
       iMesh_getEntAdj( mesh, entities[i], iBase_VERTEX,
                        &adj_ents2_ptr, &adj_ents2_alloc, &adj_ents2_size,
                        &result );
       ASSERT( iBase_SUCCESS == result );
+      if (!assert_pass) {
+        free(entities);
+        free(adj_ents);
+        free(indices);
+        free(offsets);
+        return FALSE;
+      }
+
       ASSERT( adj_ents2_ptr == adj_ents2 ); /* shouldn't change */
+      if (!assert_pass) {
+        free(entities);
+        free(adj_ents);
+        free(indices);
+        free(offsets);
+        return FALSE;
+      }
+
       ASSERT( adj_ents2_alloc == 27 ); /* shouldn't change */
-        /* compare results */
-      size = offsets[i+1]-offsets[i];
+      if (!assert_pass) {
+        free(entities);
+        free(adj_ents);
+        free(indices);
+        free(offsets);
+        return FALSE;
+      }
+
+      /* compare results */
+      size = offsets[i + 1] - offsets[i];
       ASSERT( size == adj_ents2_size );
-      while (--size >= 0) 
-        ASSERT( adj_ents2[size] == adj_ents[indices[offsets[i]+size]] );
+      while (--size >= 0) {
+        ASSERT( adj_ents2[size] == adj_ents[indices[offsets[i] + size]] );
+        if (!assert_pass) {
+          free(entities);
+          free(adj_ents);
+          free(indices);
+          free(offsets);
+          return FALSE;
+        }
+      }
     }
-    
+
     free(entities);
     free(adj_ents);
     free(indices);
     free(offsets);
 
+/*
     offsets = NULL;
     offsets_alloc = 0;
     entities = NULL;
     entities_alloc = 0;
-/*
+
     iMesh_getAdjEntities(mesh, root_set, type, 
                          iMesh_ALL_TOPOLOGIES, iBase_VERTEX, 
                          &entities, &entities_alloc, &entities_size,
@@ -611,10 +743,6 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iBase_EntityHandle *hexes = NULL;
   int hexes_alloc = 0, hexes_size;
   iBase_EntitySetHandle hex_set;
-  iBase_EntityHandle *adj_faces1 = NULL;
-  /* int adj_faces1_alloc = 0, adj_faces1_size; */
-  int *face_offsets1 = NULL;
-  /* int face_offsets1_alloc = 0, face_offsets1_size; */
 
     /* get the number of whole mesh */
   int n_whole_mesh = 0;
@@ -647,6 +775,7 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
 
     if (entities_alloc != entities_size) {
       printf("Number of entities didn't agree with array size in entity_sets_subtest.\n");
+      free(entities);
       return FALSE;
     }
 
@@ -655,16 +784,18 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
       iMesh_addEntArrToSet(mesh, entities, entities_size, es_array[ent_type], &result);
       if (iBase_SUCCESS != result) {
         printf("Failed to add entities in entity_sets_test.\n");
+        free(entities);
         return FALSE;
       }
     }
     
       /* Check to make sure entity set really has correct number of entities in it */
     iMesh_getNumOfType(mesh, es_array[ent_type], ent_type,
-                       number_array+ent_type, &result);
+                       number_array + ent_type, &result);
       
     if (iBase_SUCCESS != result) {
       printf("Failed to get number of entities by type in entity_sets_test.\n");
+      free(entities);
       return FALSE;
     }  
 
@@ -672,6 +803,7 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
     if (number_array[ent_type] != entities_size)
     {
       printf("Number of entities by type is not correct\n");
+      free(entities);
       return FALSE;
     }
 
@@ -681,7 +813,8 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
     free(entities);
   }
 
-  if (!check_esets(mesh, n_whole_mesh + num_type)) return FALSE;
+  if (!check_esets(mesh, n_whole_mesh + num_type))
+    return FALSE;
 
     /* make a super set having all entitysets */
   super_set = NULL;
@@ -710,14 +843,15 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
     return FALSE;
   }
   
-  if (!check_esets(mesh, n_whole_mesh + num_type + 2)) return FALSE;
+  if (!check_esets(mesh, n_whole_mesh + num_type + 2)) {
+    return FALSE;
+  }
 
     /* Subtract */
     /* add all EDGEs and FACEs to temp_es1 */
     /* get all EDGE entities */
-  edges = NULL; faces = NULL; temp_entities1 = NULL; temp_entities2 = NULL;
-  edges_alloc = 0; faces_alloc = 0; temp_entities1_alloc = 0; temp_entities2_alloc = 0;
-  
+  edges = NULL;
+  edges_alloc = 0;
   iMesh_getEntities(mesh, es_array[iBase_EDGE], iBase_EDGE, 
                     iMesh_ALL_TOPOLOGIES, 
                     &edges, &edges_alloc, &edges_size, &result);
@@ -731,15 +865,19 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_addEntArrToSet(mesh, edges, edges_size, temp_es1, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to add edge entities in entity_sets_test.\n");
+    free(edges);
     return FALSE;
   }
 
     /* get all FACE entities */
+  faces = NULL;
+  faces_alloc = 0;
   iMesh_getEntities(mesh, es_array[iBase_FACE], iBase_FACE, 
                     iMesh_ALL_TOPOLOGIES, 
                     &faces, &faces_alloc, &faces_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get face entities in entity_sets_test.\n");
+    free(edges);
     return FALSE;
   }
 
@@ -747,6 +885,8 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_addEntArrToSet(mesh, faces, faces_size, temp_es1, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to add face entities in entity_sets_test.\n");
+    free(edges);
+    free(faces);
     return FALSE;
   }
 
@@ -755,35 +895,50 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_subtract(mesh, temp_es1, es_array[iBase_EDGE], &temp_es2, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to subtract entitysets in entity_sets_test.\n");
+    free(edges);
+    free(faces);
     return FALSE;
   }
 
+  temp_entities1 = NULL;
+  temp_entities1_alloc = 0;
   iMesh_getEntities(mesh, temp_es2, iBase_FACE, iMesh_ALL_TOPOLOGIES, 
                     &temp_entities1, &temp_entities1_alloc, &temp_entities1_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get face entities in entity_sets_test.\n");
+    free(edges);
+    free(faces);
     return FALSE;
   }
 
   if (faces_size != temp_entities1_size) {
     printf("not match number of entitysets after subtraction "
            "in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
     return FALSE;
   }
 
     /* check there's nothing but faces in face_es */
   types = NULL;
   types_alloc = 0;
-  
   iMesh_getEntArrType(mesh, temp_entities1, temp_entities1_size,
                       &types, &types_alloc, &types_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get types of entities in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
     return FALSE;
   }
   for (i = 0; i < types_size; i++) {
     if (types[i] != iBase_FACE) {
       printf("wrong entity type for face test in entity_sets_test.\n");
+      free(edges);
+      free(faces);
+      free(temp_entities1);
+      free(types);
       return FALSE;
     }
   }
@@ -791,17 +946,31 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_destroyEntSet(mesh, temp_es2, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to destroy temp es2.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(types);
     return FALSE;
   }
     
-  if (!check_esets(mesh, n_whole_mesh + num_type + 2)) return FALSE;
-  
+  if (!check_esets(mesh, n_whole_mesh + num_type + 2)) {
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(types);
+    return FALSE;
+  }
+
     /*------------Intersect------------ */
 
     /* clean out the temp_ms1 */
   iMesh_rmvEntArrFromSet(mesh, faces, faces_size, temp_es1, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to remove face entities in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(types);
     return FALSE;
   }
 
@@ -809,11 +978,19 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_getNumOfType(mesh, temp_es1, iBase_FACE, &num_rest, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get number of entities by type in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(types);
     return FALSE;
   }
 
   if (num_rest != 0) {
     printf("failed to remove correctly.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(types);
     return FALSE;
   }
   
@@ -821,6 +998,10 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_addEntArrToSet(mesh, edges, edges_size, temp_es1, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to add edge entities in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(types);
     return FALSE;
   }
 
@@ -828,6 +1009,10 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_addEntArrToSet(mesh, faces, faces_size, temp_es1, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to add edge entities in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(types);
     return FALSE;
   }
 
@@ -836,48 +1021,84 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_intersect(mesh, temp_es1, es_array[iBase_EDGE], &temp_es2, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to intersect in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(types);
     return FALSE;
   }
 
+  temp_entities2 = NULL;
+  temp_entities2_alloc = 0;
   iMesh_getEntities(mesh, temp_es2, iBase_FACE, iMesh_ALL_TOPOLOGIES, 
                     &temp_entities2, &temp_entities2_alloc, 
                     &temp_entities2_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get face entities in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(types);
     return FALSE;
   }
 
   if (temp_entities2_size != 0) {
     printf("wrong number of faces.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
     return FALSE;
   }
 
   iMesh_destroyEntSet(mesh, temp_es2, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to destroy temp es2.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
     return FALSE;
   }
     
-  if (!check_esets(mesh, n_whole_mesh + num_type + 2)) return FALSE;
+  if (!check_esets(mesh, n_whole_mesh + num_type + 2)) {
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    return FALSE;
+  }
 
     /*-------------Unite-------------- */
 
-    /* get all regions */
-  regions = NULL;
-  regions_alloc = 0;
-
   iMesh_createEntSet(mesh, is_list, &temp_es2, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to create a temp entityset in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
     return FALSE;
   }
 
+  /* get all regions */
+  regions = NULL;
+  regions_alloc = 0;
   iMesh_getEntities(mesh, es_array[iBase_REGION], 
                     iBase_REGION, 
                     iMesh_ALL_TOPOLOGIES, 
                     &regions, &regions_alloc, &regions_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get region entities in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
     return FALSE;
   }
 
@@ -885,6 +1106,12 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_addEntArrToSet(mesh, regions, regions_size, temp_es2, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to add region entities in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
     return FALSE;
   }
 
@@ -892,6 +1119,12 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_unite(mesh, temp_es1, temp_es2, &temp_es3, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to unite in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
     return FALSE;
   }
 
@@ -899,15 +1132,35 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_getNumOfType(mesh, temp_es3, iBase_REGION, &num_regions, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get number of region entities by type in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
     return FALSE;
   }
   
   if (num_regions != number_array[iBase_REGION]) {
     printf("different number of regions in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
     return FALSE;
   }
 
-  if (!check_esets(mesh, n_whole_mesh + num_type + 4)) return FALSE;
+  if (!check_esets(mesh, n_whole_mesh + num_type + 4)) {
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    return FALSE;
+  }
 
     /*--------Test parent/child stuff in entiysets----------- */
 
@@ -915,12 +1168,24 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_createEntSet(mesh, is_list, &parent_child, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem creating entityset in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
     return FALSE;
   }
 
   iMesh_addPrntChld(mesh, es_array[iBase_VERTEX], parent_child, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem add parent in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
     return FALSE;
   }
 
@@ -931,11 +1196,24 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
                  &parents, &parents_alloc, &parents_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem getting parents in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
     return FALSE;
   }
 
   if (parents_size != 1) {
     printf("number of parents is not correct in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
     return FALSE;
   }
 
@@ -943,11 +1221,25 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_getNumChld(mesh, es_array[iBase_VERTEX], 0, &temp_numb, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem getting number of children in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
     return FALSE;
   }
 
   if (temp_numb != 1) {
     printf("number of children is not correct in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
     return FALSE;
   }
 
@@ -956,10 +1248,24 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_isChildOf(mesh, es_array[iBase_VERTEX], parent_child, &is_child, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem checking relation in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
     return FALSE;
   }
   if (!is_child) {
     printf("parent_child and es_array[iBase_VERTEX] should be related\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
     return FALSE;
   }
     
@@ -968,14 +1274,37 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_isChildOf(mesh, es_array[iBase_FACE], es_array[iBase_REGION], &is_child, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem checking relation in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
     return FALSE;
   }
   if (is_child) {
     printf("es_array[iBase_REGION] and es_array[iBase_FACE] should not be related\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
     return FALSE;
   }
   
-  if (!check_esets(mesh, n_whole_mesh + num_type + 5)) return FALSE;
+  if (!check_esets(mesh, n_whole_mesh + num_type + 5)) {
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
+    return FALSE;
+  }
 
     /*--------test modify and query functions----------------------------- */
   
@@ -986,6 +1315,13 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
                    &es_array1, &es_array1_alloc, &es_array1_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem to get entity sets in super set.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
     return FALSE;
   }
 
@@ -993,6 +1329,14 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
   iMesh_getNumEntSets(mesh, super_set, 0, &num_super, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem to get the number of all entity sets in super set.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
+    free(es_array1);
     return FALSE;
   }
 
@@ -1010,6 +1354,14 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
                     &all_entities, &all_entities_alloc, &all_entities_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem to get all entities in super set.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
+    free(es_array1);
     return FALSE;
   }
   
@@ -1032,6 +1384,15 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
       iMesh_addEntSet(mesh, es_array1[l], es_k, &result);
       if (iBase_SUCCESS != result) {
         printf("Problem to add entity set to entityset.\n");
+        free(edges);
+        free(faces);
+        free(temp_entities1);
+        free(temp_entities2);
+        free(types);
+        free(regions);
+        free(parents);
+        free(es_array1);
+        free(all_entities);
         return FALSE;
       }
     }
@@ -1040,6 +1401,15 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
     iMesh_addEntSet(mesh, super_set, es_k, &result);
     if (iBase_SUCCESS != result) {
       printf("Problem to add super set to entitysets.\n");
+      free(edges);
+      free(faces);
+      free(temp_entities1);
+      free(temp_entities2);
+      free(types);
+      free(regions);
+      free(parents);
+      free(es_array1);
+      free(all_entities);
       return FALSE;
     }
 
@@ -1048,6 +1418,15 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
       iMesh_addEntSet(mesh, temp_es1, es_k, &result);
       if (iBase_SUCCESS != result) {
         printf("Problem to add temp set to entitysets.\n");
+        free(edges);
+        free(faces);
+        free(temp_entities1);
+        free(temp_entities2);
+        free(types);
+        free(regions);
+        free(parents);
+        free(es_array1);
+        free(all_entities);
         return FALSE;
       }
     }
@@ -1061,6 +1440,15 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
                     iMesh_HEXAHEDRON, &hexes, &hexes_alloc, &hexes_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get hexes in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
+    free(es_array1);
+    free(all_entities);
     return FALSE;
   }
 
@@ -1076,62 +1464,68 @@ int entity_sets_subtest(iMesh_Instance mesh, int is_list,
                       &result);
   if (iBase_SUCCESS != result) {
     printf("Problem to get adjacent entities in entitysets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
+    free(es_array1);
+    free(all_entities);
+    free(hexes);
     return FALSE;
   }
-  
 
   iMesh_createEntSet(mesh, FALSE, &hex_set, &result);
   if (iBase_SUCCESS != result) {
     printf("Problem creating entityset in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
+    free(es_array1);
+    free(all_entities);
+    free(hexes);
+    free(adj_faces);
+    free(face_offsets);
     return FALSE;
   }
   
   iMesh_addEntArrToSet(mesh, hexes, hexes_size, hex_set, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to add hexes in entity_sets_test.\n");
+    free(edges);
+    free(faces);
+    free(temp_entities1);
+    free(temp_entities2);
+    free(types);
+    free(regions);
+    free(parents);
+    free(es_array1);
+    free(all_entities);
+    free(hexes);
+    free(adj_faces);
+    free(face_offsets);
     return FALSE;
   }
   
-    /* get adjacent faces of all hexes */
-/*
-  adj_faces1 = NULL;
-  adj_faces1_alloc = 0;
-  face_offsets1 = NULL;
-  face_offsets1_alloc = 0;
-  iMesh_getAdjEntities(mesh, hex_set,
-                       iBase_ALL_TYPES,
-                       iMesh_HEXAHEDRON, iBase_FACE,
-                       &adj_faces1, &adj_faces1_alloc, &adj_faces1_size, 
-                       &face_offsets1, &face_offsets1_alloc, &face_offsets1_size,
-                       &result);
-  if (iBase_SUCCESS != result) {
-    printf("Failed to get faces from hexes in entityset_test.\n");
-    return FALSE;
-  }
-*/
-    /* compare number of faces */
-/*
-  if (adj_faces_size != adj_faces1_size ||
-      face_offsets_size != face_offsets1_size)
-    return FALSE;
-  
-  if (!check_esets(mesh, n_whole_mesh + num_type + 6)) return FALSE;
-*/
-  free(temp_entities1);
-  free(temp_entities2);
   free(edges);
   free(faces);
+  free(temp_entities1);
+  free(temp_entities2);
   free(types);
   free(regions);
   free(parents);
   free(es_array1);
   free(all_entities);
-  free(face_offsets);
-  free(adj_faces);
   free(hexes);
-  free(face_offsets1);
-  free(adj_faces1);
-  
+  free(adj_faces);
+  free(face_offsets);
+
   return TRUE;
 }
 
@@ -1215,6 +1609,7 @@ int vertex_coordinates_test(iMesh_Instance mesh)
                         &vert_coords, &vert_coords_alloc, &vert_coords_size, &result);
   if (iBase_SUCCESS != result) {
     printf("failed to get vertex cooridinate of entities in vertex_coordinates_test.\n");
+    free(verts);
     return FALSE;
   }
 
@@ -1337,7 +1732,7 @@ int vertex_int_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
 
-  if(dum_val2 != 11) {
+  if (dum_val2 != 11) {
     
     printf("Value of vertex tag (val=11) wrong.\n");
     return FALSE;
@@ -1360,7 +1755,7 @@ int vertex_int_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
 
-  if(dum_val2 != 12) {
+  if (dum_val2 != 12) {
     
     printf("Value of vertex tag (val=12) wrong.\n");
     return FALSE;
@@ -1406,8 +1801,7 @@ int vertex_double_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
 
-  if(dum_val2 != 1.0e6) {
-    
+  if (dum_val2 != 1.0e6) {
     printf("Value of vertex tag (val=1.0e6) wrong.\n");
     return FALSE;
   }
@@ -1429,7 +1823,7 @@ int vertex_double_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
 
-  if(dum_val2 != 2.0e9) {
+  if (dum_val2 != 2.0e9) {
     printf("Value of vertex tag (val=2.0e9) wrong.\n");
     return FALSE;
   }
@@ -1481,11 +1875,11 @@ int vertex_struct_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
 
-  if(dum_struct_size != sizeof(struct TagStruct)) {
+  if (dum_struct_size != sizeof(struct TagStruct)) {
     printf("Size of vertex struct tag wrong.\n");
     return FALSE;
   }
-  if(dum_struct2.test_int1 != dum_struct.test_int1 ||
+  if (dum_struct2.test_int1 != dum_struct.test_int1 ||
      dum_struct2.test_int2 != dum_struct.test_int2 ||
      dum_struct2.test_double != dum_struct.test_double) {
     printf("Value of vertex struct tag wrong.\n");
@@ -1518,6 +1912,7 @@ int vertex_tag_delete_test(iMesh_Instance mesh,
   iMesh_rmvArrTag(mesh, &dum_entity, 1, all_tags[0], &result);
   if (iBase_SUCCESS != result) {
     printf("Couldn't remove tag from vertex.\n");
+    free(all_tags);
     return FALSE;
   }
   
@@ -1527,17 +1922,19 @@ int vertex_tag_delete_test(iMesh_Instance mesh,
   }
   if (!delete_err) {
     printf("Error when unforced-deleting tag in use on a vertex.\n");
+    free(all_tags);
     return FALSE;
   }
 
   iMesh_destroyTag(mesh, all_tags[1], TRUE, &result);
   if (iBase_SUCCESS != result) {
     printf("Couldn't force-delete a tag in use on a vertex.\n");
+    free(all_tags);
     return FALSE;
   }
 
   free(all_tags);
-  
+
     /* ok, we're done */
   return TRUE;
 }
@@ -1622,21 +2019,21 @@ int entityset_int_tag_test(iMesh_Instance mesh,
 
     /* put a value in the last faces and retrieve */
   dum_val = 12;
-  iMesh_setEntSetData(mesh, sets[sets_size-1], *int_tag,
+  iMesh_setEntSetData(mesh, sets[sets_size - 1], *int_tag,
                       (char*)(&dum_val), sizeof(int), &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to set int tag (val=12) in entityset_int_tag_test.");
     return FALSE;
   }
 
-  iMesh_getEntSetData(mesh, sets[sets_size-1], *int_tag,
+  iMesh_getEntSetData(mesh, sets[sets_size - 1], *int_tag,
                       &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Failed to get int tag (val=12) in entityset_int_tag_test.");
     return FALSE;
   }
   
-  if(dum_val2 != 12) {
+  if (dum_val2 != 12) {
     printf("Value of entityset tag (val=12) wrong.\n");
     return FALSE;
   }
@@ -1701,7 +2098,7 @@ int entityset_double_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
   
-  if(dum_val2 != 2.0e9) {
+  if (dum_val2 != 2.0e9) {
     printf("Value of entityset tag (val=2.0e9) wrong.\n");
     return FALSE;
   }
@@ -1745,11 +2142,11 @@ int entityset_struct_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
 
-  if(dum_struct_size != sizeof(struct TagStruct)) {
+  if (dum_struct_size != sizeof(struct TagStruct)) {
     printf("Size of entityset struct tag wrong.\n");
     return FALSE;
   }
-  if(dum_struct2.test_int1 != dum_struct.test_int1 ||
+  if (dum_struct2.test_int1 != dum_struct.test_int1 ||
      dum_struct2.test_int2 != dum_struct.test_int2 ||
      dum_struct2.test_double != dum_struct.test_double) {
     printf("Value of entityset struct tag wrong.\n");
@@ -1767,10 +2164,9 @@ int entityset_tag_delete_test(iMesh_Instance mesh,
   int result;
   int delete_err = FALSE;
 
-
     /* test getAlliBase_TagHandles for first entity */
   iBase_TagHandle *all_tags = NULL;
-  if (sets_size<1)
+  if (sets_size < 1)
   {
     printf("no sets.\n");
     return FALSE;
@@ -1781,12 +2177,14 @@ int entityset_tag_delete_test(iMesh_Instance mesh,
              &all_tags_size, &result);
   if (iBase_SUCCESS != result) {
     printf("Couldn't get all tag handles from entityset.\n");
+    free(all_tags);
     return FALSE;
   }
 
   iMesh_rmvEntSetTag(mesh, dum_entity, all_tags[0], &result);
   if (iBase_SUCCESS != result) {
     printf("Couldn't remove tag from entityset.\n");
+    free(all_tags);
     return FALSE;
   }
   
@@ -1796,12 +2194,14 @@ int entityset_tag_delete_test(iMesh_Instance mesh,
   }
   if (!delete_err) {
     printf("Error when unforced-deleting tag in use on a entityset.\n");
+    free(all_tags);
     return FALSE;
   }
 
   iMesh_destroyTag(mesh, all_tags[1], TRUE, &result);
   if (iBase_SUCCESS != result) {
     printf("Couldn't force-delete a tag in use on a entityset.\n");
+    free(all_tags);
     return FALSE;
   }
 
@@ -1828,11 +2228,11 @@ int entityset_tag_test(iMesh_Instance mesh)
   iMesh_getEntSets(mesh, root_set, 1, &esets, &esets_alloc, &esets_size, &result);
   if (iBase_SUCCESS != result) {
     printf("entitysetGetEntities failed in entityset_tag_test.\n");
+    free(esets);
     return FALSE;
   }
 
-  
-    /* entityset int tag */
+     /* entityset int tag */
   int_success = entityset_int_tag_test(mesh, esets, esets_size, 
                                             &int_tag);
 
@@ -1907,7 +2307,7 @@ int mesh_int_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
   
-  if(dum_val2 != 12) {
+  if (dum_val2 != 12) {
     printf("Value of entityset tag (val=12) wrong.\n");
     return FALSE;
   }
@@ -1971,7 +2371,7 @@ int mesh_double_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
   
-  if(dum_val2 != 2.0e9) {
+  if (dum_val2 != 2.0e9) {
     printf("Value of entityset tag (val=2.0e9) wrong.\n");
     return FALSE;
   }
@@ -2014,11 +2414,11 @@ int mesh_struct_tag_test(iMesh_Instance mesh,
     return FALSE;
   }
 
-  if(dum_struct_size != sizeof(struct TagStruct)) {
+  if (dum_struct_size != sizeof(struct TagStruct)) {
     printf("Size of entityset struct tag wrong.\n");
     return FALSE;
   }
-  if(dum_struct2.test_int1 != dum_struct.test_int1 ||
+  if (dum_struct2.test_int1 != dum_struct.test_int1 ||
      dum_struct2.test_int2 != dum_struct.test_int2 ||
      dum_struct2.test_double != dum_struct.test_double) {
     printf("Value of entityset struct tag wrong.\n");
@@ -2035,7 +2435,6 @@ int mesh_tag_delete_test(iMesh_Instance mesh)
   int result;
   int delete_err = FALSE;
 
-
     /* test getAlliBase_TagHandles for first entity */
   iBase_TagHandle *all_tags = NULL;
   int all_tags_alloc = 0, all_tags_size;
@@ -2049,6 +2448,7 @@ int mesh_tag_delete_test(iMesh_Instance mesh)
   iMesh_rmvEntSetTag(mesh, root_set, all_tags[0], &result);
   if (iBase_SUCCESS != result) {
     printf("Couldn't remove tag from entityset.\n");
+    free(all_tags);
     return FALSE;
   }
   
@@ -2058,12 +2458,14 @@ int mesh_tag_delete_test(iMesh_Instance mesh)
   }
   if (!delete_err) {
     printf("Error when unforced-deleting tag in use on a entityset.\n");
+    free(all_tags);
     return FALSE;
   }
 
   iMesh_destroyTag(mesh, all_tags[1], TRUE, &result);
   if (iBase_SUCCESS != result) {
     printf("Couldn't force-delete a tag in use on a entityset.\n");
+    free(all_tags);
     return FALSE;
   }
 
@@ -2099,34 +2501,40 @@ int mesh_tag_test(iMesh_Instance mesh)
 
 int set_remove_contained_regression( iMesh_Instance mesh )
 {
-    int err,contained;
-    iBase_EntitySetHandle set,sub;
+    int err, contained;
+    iBase_EntitySetHandle set, sub;
 
-    iMesh_createEntSet(mesh,0,&set,&err);
-    if (iBase_SUCCESS != err) return 0;
-    iMesh_createEntSet(mesh,1,&sub,&err);
-    if (iBase_SUCCESS != err) return 0;
+    iMesh_createEntSet(mesh, 0, &set, &err);
+    if (iBase_SUCCESS != err)
+      return 0;
+    iMesh_createEntSet(mesh, 1, &sub, &err);
+    if (iBase_SUCCESS != err)
+      return 0;
 
-    iMesh_addEntSet(mesh,sub,set,&err);
-    if (iBase_SUCCESS != err) return 0;
+    iMesh_addEntSet(mesh, sub, set, &err);
+    if (iBase_SUCCESS != err)
+      return 0;
 
-    iMesh_isEntSetContained(mesh,set,sub,&contained,&err);
-    if (iBase_SUCCESS != err) return 0;
+    iMesh_isEntSetContained(mesh, set, sub, &contained, &err);
+    if (iBase_SUCCESS != err)
+      return 0;
     if (!contained) {
-      fprintf(stderr,"isEntSetContained returned false for contained set\n");
+      fprintf(stderr, "isEntSetContained returned false for contained set\n");
       return 0;
     }
 
-    iMesh_rmvEntSet(mesh,sub,set,&err);
-    if (iBase_SUCCESS != err) return 0;
+    iMesh_rmvEntSet(mesh, sub, set, &err);
+    if (iBase_SUCCESS != err)
+      return 0;
 
-    iMesh_isEntSetContained(mesh,set,sub,&contained,&err);
-    if (iBase_SUCCESS != err) return 0;
+    iMesh_isEntSetContained(mesh, set, sub, &contained, &err);
+    if (iBase_SUCCESS != err)
+      return 0;
     if (contained) {
-      fprintf(stderr,"isEntSetContained returned true for removed set\n");
+      fprintf(stderr, "isEntSetContained returned true for removed set\n");
       return 0;
     }
-    
+
     return 1;
 }
 
@@ -2137,75 +2545,91 @@ int all_adjacency_regression( iMesh_Instance mesh )
     double coords[] = { 0,0,0, 1,1,1 };
 
     iBase_EntityHandle *verts = NULL;
-    int verts_alloc = 0,verts_size;
+    int verts_alloc = 0, verts_size;
 
     iBase_EntityHandle line;
     int status;
 
     iBase_EntityHandle *adj = NULL;
-    int adj_alloc = 0,adj_size;
+    int adj_alloc = 0, adj_size;
 
-    iMesh_newMesh("",&mesh,&err,0);
-    if (iBase_SUCCESS != err) return 0;
+    iMesh_newMesh("", &mesh, &err, 0);
+    if (iBase_SUCCESS != err)
+      return 0;
 
-    iMesh_createVtxArr(mesh,2,iBase_INTERLEAVED,coords,6,&verts,&verts_alloc,
-                       &verts_size,&err);
-    if (iBase_SUCCESS != err) return 0;
+    iMesh_createVtxArr(mesh, 2, iBase_INTERLEAVED, coords, 6, &verts, &verts_alloc,
+                       &verts_size, &err);
+    if (iBase_SUCCESS != err)
+      return 0;
 
-    iMesh_createEnt(mesh,iMesh_LINE_SEGMENT,verts,2,&line,&status,&err);
-    if (iBase_SUCCESS != err || status != iBase_NEW) return 0;
+    iMesh_createEnt(mesh, iMesh_LINE_SEGMENT, verts, 2, &line, &status, &err);
+    if (iBase_SUCCESS != err || status != iBase_NEW)
+      return 0;
 
-    iMesh_getEntAdj(mesh,verts[0],iBase_ALL_TYPES,&adj,&adj_alloc,&adj_size,
+    iMesh_getEntAdj(mesh, verts[0], iBase_ALL_TYPES, &adj, &adj_alloc, &adj_size,
                     &err);
-    if (iBase_SUCCESS != err) return 0;
-    if(adj_size != 1 || adj[0] != line) {
+    if (iBase_SUCCESS != err)
+      return 0;
+    if (adj_size != 1 || adj[0] != line) {
         printf("Bad: couldn't find adjacency for vertex\n");
         return 0;
     }
     free(adj);
 
-    adj_alloc = 0; adj = 0;
-    iMesh_getEntAdj(mesh,line,iBase_ALL_TYPES,&adj,&adj_alloc,&adj_size,
+    adj_alloc = 0; adj = NULL;
+    iMesh_getEntAdj(mesh, line, iBase_ALL_TYPES, &adj, &adj_alloc, &adj_size,
                     &err);
-    if (iBase_SUCCESS != err) return 0;
-    if(adj_size != 2 || ((adj[0] != verts[0] || adj[1] != verts[1]) &&
+    if (iBase_SUCCESS != err)
+      return 0;
+    if (adj_size != 2 || ((adj[0] != verts[0] || adj[1] != verts[1]) &&
                          (adj[0] != verts[1] || adj[1] != verts[0])) ) {
         printf("Bad: couldn't find adjacencies for line\n");
+        free(adj);
+        free(verts);
         return 0;
     }
     free(adj);
     free(verts);
     iMesh_dtor(mesh,&err);
-    if (iBase_SUCCESS != err) return 0;
+    if (iBase_SUCCESS != err)
+      return 0;
     return 1;
 }
 
 static int ordered_set_regression( iMesh_Instance mesh )
 {
   double coords[] = { 0,0,0, 1,1,1 };
-  iBase_EntityHandle line,*p,verts[2],ents_in[3],ents_out[3];
+  iBase_EntityHandle line, *p, verts[2], ents_in[3], ents_out[3];
   iBase_EntitySetHandle set;
-  int i,err,status,two=2,three=3;
+  int i, err, status, two = 2, three = 3;
 
-  iMesh_newMesh("",&mesh,&err,0);CHK(err);
+  iMesh_newMesh("", &mesh, &err, 0);
+  CHK(err);
   p = verts;
-  iMesh_createVtxArr(mesh,2,iBase_INTERLEAVED,coords,6,&p,&two,&two,&err);CHK(err);
-  iMesh_createEnt(mesh,iMesh_LINE_SEGMENT,verts,2,&line,&status,&err);CHK(err);
-  if (status != iBase_NEW) return 0;
-  iMesh_createEntSet(mesh,1,&set,&err);CHK(err);
+  iMesh_createVtxArr(mesh, 2, iBase_INTERLEAVED, coords, 6, &p, &two, &two, &err);
+  CHK(err);
+  iMesh_createEnt(mesh, iMesh_LINE_SEGMENT, verts, 2, &line, &status, &err);
+  CHK(err);
+  if (status != iBase_NEW)
+    return 0;
+  iMesh_createEntSet(mesh, 1, &set, &err);
+  CHK(err);
   ents_in[0] = verts[1];
   ents_in[1] = line;
   ents_in[2] = verts[0];
-  iMesh_addEntArrToSet(mesh,ents_in,three,set,&err);CHK(err);
+  iMesh_addEntArrToSet(mesh, ents_in, three, set, &err);
+  CHK(err);
   p = ents_out;
-  iMesh_getEntities(mesh,set,iBase_ALL_TYPES,iMesh_ALL_TOPOLOGIES,&p,&three,&three,&err);CHK(err);
-  for (i=0; i<three; i++) {
+  iMesh_getEntities(mesh, set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &p, &three, &three, &err);
+  CHK(err);
+  for (i = 0; i < three; i++) {
     if (ents_in[i] != ents_out[i]) {
       printf("Ordered set does not preserve order\n");
       return 0;
     }
   }
-  iMesh_dtor(mesh,&err);CHK(err);
+  iMesh_dtor(mesh, &err);
+  CHK(err);
   return 1;
 }
 
@@ -2216,13 +2640,14 @@ int array_allocation( iMesh_Instance mesh )
   double coords[] = { 0,0,0, 1,1,1, 2,2,2, 3,3,3 };
 
   iBase_EntityHandle *verts = NULL;
-  int verts_alloc = 0,verts_size;
+  int verts_alloc = 0, verts_size;
 
   iBase_EntityHandle *ents;
   int ents_alloc, ents_size;
 
-  iMesh_newMesh("",&mesh,&err,0);
-  if (iBase_SUCCESS != err) return 0;
+  iMesh_newMesh("", &mesh, &err, 0);
+  if (iBase_SUCCESS != err)
+    return 0;
 
   iMesh_getRootSet(mesh, &root_set, &err);
   if (iBase_SUCCESS != err) {
@@ -2230,9 +2655,11 @@ int array_allocation( iMesh_Instance mesh )
     return 0;
   }
 
-  iMesh_createVtxArr(mesh,4,iBase_INTERLEAVED,coords,12,&verts,&verts_alloc,
-                     &verts_size,&err);
-  if (iBase_SUCCESS != err) return 0;
+  iMesh_createVtxArr(mesh, 4, iBase_INTERLEAVED, coords, 12, &verts, &verts_alloc,
+                     &verts_size, &err);
+  if (iBase_SUCCESS != err)
+    return 0;
+
   free(verts);
 
     /* test for proper allocation when array pointer passed in null but alloc'd size not */
@@ -2241,15 +2668,15 @@ int array_allocation( iMesh_Instance mesh )
   iMesh_getEntities(mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 
                     &ents, &ents_alloc, &ents_size, &err);
   CHK(err);
-    
+
   free(ents);
-    
+
     /* test for proper allocation when array pointer passed in non-null but alloc'd size 0 */
   ents_alloc = 0;
   iMesh_getEntities(mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 
                     &ents, &ents_alloc, &ents_size, &err);
   CHK(err);
-    
+
   free(ents);
 
     /* test for failure when passed in alloc'd size is smaller than it should be */
@@ -2260,8 +2687,9 @@ int array_allocation( iMesh_Instance mesh )
     err = iBase_FAILURE;
     CHK(err);
   }
-    
-  iMesh_dtor(mesh,&err);CHK(err);
+
+  iMesh_dtor(mesh, &err);
+  CHK(err);
 
   return 1;
 }
@@ -2281,7 +2709,7 @@ int compare_single_iter( const char* info,
   iMesh_initEntIter( mesh, set, type, topo, 0, &iter, &result );
   if (iBase_SUCCESS != result) {
     printf("%s:%d: Error %d initializing %s iterator for type %d/topo %d\n",
-      __FILE__,__LINE__,result,info,(int)type,(int)topo);
+      __FILE__, __LINE__, result, info, (int)type, (int)topo);
     return result;
   }
   
@@ -2291,20 +2719,20 @@ int compare_single_iter( const char* info,
       iMesh_getNextEntIter( mesh, iter, &value, &has_data, &result );
       if (iBase_SUCCESS != result) {
         printf("%s:%d: Error %d stepping %s iterator for type %d/topo %d\n",
-          __FILE__,__LINE__,result,info,(int)type,(int)topo);
+          __FILE__, __LINE__, result, info, (int)type, (int)topo);
         goto end_single_iter;
       }
 
       if (!has_data) {
         printf("%s:%d: %s iterator for type %d/topo %d ended prematurely at %d of %d\n",
-          __FILE__,__LINE__,info,(int)type,(int)topo,i,contents_size);
+          __FILE__, __LINE__, info, (int)type, (int)topo, i, contents_size);
         result = iBase_FAILURE;
         goto end_single_iter;
       }
 
       if (value != contents[i]) {
         printf("%s:%d: %s iterator for type %d/topo %d returned incorrect value at %d of %d\n",
-          __FILE__,__LINE__,info,(int)type,(int)topo,i,contents_size);
+          __FILE__, __LINE__, info, (int)type, (int)topo, i, contents_size);
         result = iBase_FAILURE;
         goto end_single_iter;
       }
@@ -2313,13 +2741,13 @@ int compare_single_iter( const char* info,
     iMesh_getNextEntIter( mesh, iter, &value, &has_data, &result );
     if (iBase_SUCCESS != result) {
       printf("%s:%d: Error %d stepping %s iterator for type %d/topo %d\n",
-        __FILE__,__LINE__,result,info,(int)type,(int)topo);
+        __FILE__, __LINE__, result, info, (int)type, (int)topo);
       goto end_single_iter;
     }
 
     if (has_data) {
       printf("%s:%d: %s iterator for type %d/topo %d did not end after %d values\n",
-        __FILE__,__LINE__,info,(int)type,(int)topo,contents_size);
+        __FILE__, __LINE__, info, (int)type, (int)topo, contents_size);
       result = iBase_FAILURE;
       goto end_single_iter;
     }
@@ -2327,7 +2755,7 @@ int compare_single_iter( const char* info,
     iMesh_resetEntIter( mesh, iter, &result );
     if (iBase_SUCCESS != result) {
       printf("%s:%d: Error %d resetting %s iterator for type %d/topo %d\n",
-        __FILE__,__LINE__,result,info,(int)type,(int)topo);
+        __FILE__, __LINE__, result, info, (int)type, (int)topo);
       result = iBase_FAILURE;
       goto end_single_iter;
     }
@@ -2337,7 +2765,7 @@ end_single_iter:
   iMesh_endEntIter( mesh, iter, &result2 );
   if (iBase_SUCCESS != result2) {
     printf("%s:%d: Error %d releasing %s iterator for type %d/topo %d\n",
-      __FILE__,__LINE__,result,info,(int)type,(int)topo);
+      __FILE__, __LINE__, result, info, (int)type, (int)topo);
     if (iBase_SUCCESS == result)
       result = result2;
   }
@@ -2362,7 +2790,7 @@ int compare_array_iter( const char* info,
   iMesh_initEntArrIter( mesh, set, type, topo, array_size, 0, &iter, &result );
   if (iBase_SUCCESS != result) {
     printf("%s:%d: Error %d initializing %s array iterator for type %d/topo %d\n",
-      __FILE__,__LINE__,result,info,(int)type,(int)topo);
+      __FILE__, __LINE__, result, info, (int)type, (int)topo);
     free(values);
     return result;
   }
@@ -2374,27 +2802,27 @@ int compare_array_iter( const char* info,
       iMesh_getNextEntArrIter( mesh, iter, &values, &values_alloc, &values_size, &has_data, &result );
       if (iBase_SUCCESS != result) {
         printf("%s:%d: Error %d stepping %s array iterator for type %d/topo %d\n",
-          __FILE__,__LINE__,result,info,(int)type,(int)topo);
+          __FILE__, __LINE__, result, info, (int)type, (int)topo);
         goto end_arr_iter;
       }
 
       if (!has_data || !values_size) {
         printf("%s:%d: %s array iterator for type %d/topo %d ended prematurely at %d of %d\n",
-          __FILE__,__LINE__,info,(int)type,(int)topo,i,contents_size);
+          __FILE__, __LINE__,info, (int)type, (int)topo, i, contents_size);
         result = iBase_FAILURE;
         goto end_arr_iter;
       }
       
       if (i + values_size > contents_size) {
         printf("%s:%d: %s array iterator for type %d/topo %d returned more than %d handles\n",
-          __FILE__,__LINE__,info,(int)type,(int)topo,contents_size);
+          __FILE__, __LINE__,info, (int)type, (int)topo, contents_size);
         result = iBase_FAILURE;
         goto end_arr_iter;
       }
       
       if (contents_size - i >= array_size && values_size < array_size) {
         printf("%s:%d: %s array iterator for type %d/topo %d returned fewer than %d handles\n",
-          __FILE__,__LINE__,info,(int)type,(int)topo,array_size);
+          __FILE__, __LINE__, info, (int)type, (int)topo, array_size);
         result = iBase_FAILURE;
         goto end_arr_iter;
       }
@@ -2402,7 +2830,7 @@ int compare_array_iter( const char* info,
       for (j = 0; j < values_size; ++j, ++i) {
         if (values[j] != contents[i]) {
           printf("%s:%d: %s array iterator for type %d/topo %d returned incorrect value at %d of %d\n",
-            __FILE__,__LINE__,info,(int)type,(int)topo,i,contents_size);
+            __FILE__, __LINE__, info, (int)type, (int)topo, i, contents_size);
           result = iBase_FAILURE;
           goto end_arr_iter;
         }
@@ -2412,13 +2840,13 @@ int compare_array_iter( const char* info,
     iMesh_getNextEntArrIter( mesh, iter, &values, &values_alloc, &values_size, &has_data, &result );
     if (iBase_SUCCESS != result) {
       printf("%s:%d: Error %d stepping %s array iterator for type %d/topo %d\n",
-        __FILE__,__LINE__,result,info,(int)type,(int)topo);
+        __FILE__, __LINE__, result, info, (int)type, (int)topo);
       goto end_arr_iter;
     }
 
     if (has_data || values_size) {
       printf("%s:%d: %s array iterator for type %d/topo %d did not end after %d values\n",
-        __FILE__,__LINE__,info,(int)type,(int)topo,contents_size);
+        __FILE__, __LINE__, info, (int)type, (int)topo, contents_size);
       result = iBase_FAILURE;
       goto end_arr_iter;
     }
@@ -2426,7 +2854,7 @@ int compare_array_iter( const char* info,
     iMesh_resetEntArrIter( mesh, iter, &result );
     if (iBase_SUCCESS != result) {
       printf("%s:%d: Error %d resetting %s array iterator for type %d/topo %d\n",
-        __FILE__,__LINE__,result,info,(int)type,(int)topo);
+        __FILE__, __LINE__, result, info, (int)type, (int)topo);
       result = iBase_FAILURE;
       goto end_arr_iter;
     }
@@ -2437,14 +2865,13 @@ end_arr_iter:
   iMesh_endEntArrIter( mesh, iter, &result2 );
   if (iBase_SUCCESS != result2) {
     printf("%s:%d: Error %d releasing %s array iterator for type %d/topo %d\n",
-      __FILE__,__LINE__,result,info,(int)type,(int)topo);
+      __FILE__, __LINE__, result, info, (int)type, (int)topo);
     if (iBase_SUCCESS == result)
       result = result2;
   }
   return result;
 }
 
-
 int test_iterator_common( const char* info,
                           iMesh_Instance mesh,
                           iBase_EntitySetHandle set,
@@ -2452,7 +2879,7 @@ int test_iterator_common( const char* info,
                           enum iBase_EntityType type,
                           enum iMesh_EntityTopology topo )
 {
-  iBase_EntityHandle *contents = 0;
+  iBase_EntityHandle *contents = NULL;
   int content_size = 0, content_alloc = 0;
   int result;
 
@@ -2466,24 +2893,22 @@ int test_iterator_common( const char* info,
   return result;
 }
 
-
 int test_iterator( iMesh_Instance mesh )
 {
   int result, i;
-  iBase_EntitySetHandle root, list, set ,*setptr;
-  iBase_EntityHandle* array = 0;
+  iBase_EntitySetHandle root, list, set, *setptr;
+  iBase_EntityHandle* array = NULL;
   int array_len = 0, array_size = 0;
-  
+
   iMesh_getRootSet( mesh, &root, &result );
   CHK(result);
 
-
   /* create some sets containing every other handle */
   iMesh_getEntities( mesh, root, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 
                      &array, &array_size, &array_len, &result );
   CHK(result);
   for (i = 1; i < array_size; i += 2)
-    array[i] = array[i-1];
+    array[i] = array[i - 1];
   for (i = 0; i < 2; ++i) {
     setptr = i ? &list : &set;
     iMesh_createEntSet( mesh, i, setptr, &result );
@@ -2499,7 +2924,7 @@ int test_iterator( iMesh_Instance mesh )
 
   /* test single iterator and array iterator for all types */
   for (i = 0; i < iBase_ALL_TYPES; ++i) {
-    array_size = 2*i+2;
+    array_size = 2*i + 2;
     result = test_iterator_common( "root", mesh, root, 1, (enum iBase_EntityType)i, iMesh_ALL_TOPOLOGIES );
     CHK(result);
     result = test_iterator_common( "root", mesh, root, array_size, (enum iBase_EntityType)i, iMesh_ALL_TOPOLOGIES );
@@ -2516,7 +2941,7 @@ int test_iterator( iMesh_Instance mesh )
 
   /* test single iterator and array iterator for all types */
   for (i = 0; i < iMesh_ALL_TOPOLOGIES; ++i) {
-    array_size = 2*i+2;
+    array_size = 2*i + 2;
     result = test_iterator_common( "root", mesh, root, 1, iBase_ALL_TYPES, (enum iMesh_EntityTopology)i );
     CHK(result);
     result = test_iterator_common( "root", mesh, root, array_size, iBase_ALL_TYPES, (enum iMesh_EntityTopology)i );
@@ -2534,7 +2959,6 @@ int test_iterator( iMesh_Instance mesh )
   return 1;
 }
 
-
 int main( int argc, char *argv[] )
 {
     /* Check command line arg */
@@ -2557,7 +2981,6 @@ int main( int argc, char *argv[] )
     filename = DEFAULT_INPUT_FILE;
   }
 
-
     /* initialize the Mesh */
   iMesh_newMesh(NULL, &mesh, &result, 0);
   if (iBase_SUCCESS != result) {


https://bitbucket.org/fathomteam/moab/commits/8abb351ecc18/
Changeset:   8abb351ecc18
Branch:      None
User:        iulian07
Date:        2013-09-26 06:54:46
Summary:     the projection utility will delete the parallel partition tag
because the file cannot be repartitioned with mbpart

Affected #:  1 file

diff --git a/tools/mbcslam/proj1.cpp b/tools/mbcslam/proj1.cpp
index e78ef79..b4ef89c 100644
--- a/tools/mbcslam/proj1.cpp
+++ b/tools/mbcslam/proj1.cpp
@@ -73,7 +73,23 @@ int main(int argc, char **argv)
   rval = mb.get_entities_by_dimension(0, 1, edges);
   if (MB_SUCCESS != rval)
     return 1;
-  mb.delete_entities(edges);
+  rval = mb.delete_entities(edges);
+
+  // delete the parallel partition sets, if exisiting
+
+  Tag par_tag;
+  rval = mb.tag_get_handle("PARALLEL_PARTITION", par_tag);
+  if (MB_SUCCESS == rval)
+  {
+    Range par_sets;
+    rval =  mb.get_entities_by_type_and_tag(0, MBENTITYSET, &par_tag, NULL, 1, par_sets,
+       moab::Interface::UNION);
+    if (!par_sets.empty())
+        mb.delete_entities(par_sets);
+    mb.tag_delete(par_tag);
+  }
+
+
   mb.write_file(output);
 
   // remove all edges


https://bitbucket.org/fathomteam/moab/commits/dd34c5e6cdd6/
Changeset:   dd34c5e6cdd6
Branch:      None
User:        iulian07
Date:        2013-09-27 16:18:17
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  1 file

diff --git a/src/MeshTopoUtil.cpp b/src/MeshTopoUtil.cpp
index cef11e3..711cbf5 100644
--- a/src/MeshTopoUtil.cpp
+++ b/src/MeshTopoUtil.cpp
@@ -468,24 +468,40 @@ ErrorCode MeshTopoUtil::get_bridge_adjacencies(const EntityHandle from_entity,
 
   if (bridge_dim < from_dim) {
       // looping over each sub-entity of dimension bridge_dim...
-    EntityHandle bridge_verts[MAX_SUB_ENTITIES];
-    int bridge_indices[MAX_SUB_ENTITIES];
-    for (int i = 0; i < CN::NumSubEntities(from_type, bridge_dim); i++) {
-
-        // get the vertices making up this sub-entity
-      int num_bridge_verts = CN::VerticesPerEntity( CN::SubEntityType( from_type, bridge_dim, i ) );
-      CN::SubEntityVertexIndices( from_type, bridge_dim, i, bridge_indices );
-      for (int j = 0; j < num_bridge_verts; ++j)
-        bridge_verts[j]= connect[bridge_indices[j]];
-      //CN::SubEntityConn(connect, from_type, bridge_dim, i, &bridge_verts[0], num_bridge_verts);
-    
-        // get the to_dim entities adjacent
-      to_ents.clear();
-      ErrorCode tmp_result = mbImpl->get_adjacencies(bridge_verts, num_bridge_verts,
-                                                       to_dim, false, to_ents, Interface::INTERSECT);
-      if (MB_SUCCESS != tmp_result) result = tmp_result;
-    
-      to_adjs.merge(to_ents);
+    if (MBPOLYGON == from_type)
+    {
+      for (int i=0; i<num_connect; i++)
+      {
+        // loop over edges, and get the vertices
+        EntityHandle verts_on_edge[2]={connect[i], connect[(i+1)%num_connect]};
+        to_ents.clear();
+        ErrorCode tmp_result = mbImpl->get_adjacencies(verts_on_edge, 2,
+                        to_dim, false, to_ents, Interface::INTERSECT);
+        if (MB_SUCCESS != tmp_result) result = tmp_result;
+        to_adjs.merge(to_ents);
+      }
+    }
+    else
+    {
+      EntityHandle bridge_verts[MAX_SUB_ENTITIES];
+      int bridge_indices[MAX_SUB_ENTITIES];
+      for (int i = 0; i < CN::NumSubEntities(from_type, bridge_dim); i++) {
+
+          // get the vertices making up this sub-entity
+        int num_bridge_verts = CN::VerticesPerEntity( CN::SubEntityType( from_type, bridge_dim, i ) );
+        CN::SubEntityVertexIndices( from_type, bridge_dim, i, bridge_indices );
+        for (int j = 0; j < num_bridge_verts; ++j)
+          bridge_verts[j]= connect[bridge_indices[j]];
+        //CN::SubEntityConn(connect, from_type, bridge_dim, i, &bridge_verts[0], num_bridge_verts);
+
+          // get the to_dim entities adjacent
+        to_ents.clear();
+        ErrorCode tmp_result = mbImpl->get_adjacencies(bridge_verts, num_bridge_verts,
+                                                         to_dim, false, to_ents, Interface::INTERSECT);
+        if (MB_SUCCESS != tmp_result) result = tmp_result;
+
+        to_adjs.merge(to_ents);
+      }
     }
 
   }


https://bitbucket.org/fathomteam/moab/commits/2782f04fe219/
Changeset:   2782f04fe219
Branch:      None
User:        iulian07
Date:        2013-09-28 00:07:49
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  1 file

diff --git a/src/parallel/ParallelComm.cpp b/src/parallel/ParallelComm.cpp
index d9e06d5..68b2eb6 100644
--- a/src/parallel/ParallelComm.cpp
+++ b/src/parallel/ParallelComm.cpp
@@ -2565,10 +2565,13 @@ ErrorCode ParallelComm::recv_entities(std::set<unsigned int>& recv_procs,
     if ((new_numps > 2 && !(new_pstat&(PSTATUS_INTERFACE|PSTATUS_GHOST|PSTATUS_NOT_OWNED))) ||
         (new_pstat&PSTATUS_INTERFACE && !(new_pstat&PSTATUS_NOT_OWNED))
         ) {
+      idx = std::min_element(&new_ps[0], &new_ps[0] + new_numps) - &new_ps[0];
       std::swap(new_ps[0], new_ps[idx]);
       std::swap(new_hs[0], new_hs[idx]);
+      if (new_ps[0] != (int)rank())
+        new_pstat |= PSTATUS_NOT_OWNED;
     }
-      
+
 /*    
     plist("new_ps", new_ps, new_numps);
     plist("new_hs", new_hs, new_numps);


https://bitbucket.org/fathomteam/moab/commits/c30c84f15610/
Changeset:   c30c84f15610
Branch:      None
User:        iulian07
Date:        2013-10-04 01:41:15
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  1 file

diff --git a/src/parallel/ParallelComm.cpp b/src/parallel/ParallelComm.cpp
index 68b2eb6..e83653b 100644
--- a/src/parallel/ParallelComm.cpp
+++ b/src/parallel/ParallelComm.cpp
@@ -5929,9 +5929,12 @@ ErrorCode ParallelComm::resolve_shared_ents(EntityHandle this_set,
                                            int old_nump, int new_nump,
                                            int *ps, EntityHandle *hs) 
   {
-    // set sharing data to what's passed in; may have to clean up existing sharing tags
-    // if things changed too much
-    
+    // If new nump is less than 3, the entity is no longer mutishared
+     if (old_nump > 2 && (pstatus & PSTATUS_MULTISHARED) && new_nump < 3) {
+       // Unset multishared flag
+       pstatus ^= PSTATUS_MULTISHARED;
+     }
+
     // check for consistency in input data
     assert(new_nump > 1 &&
            ((new_nump == 2 && pstatus&PSTATUS_SHARED && !(pstatus&PSTATUS_MULTISHARED)) || // if <= 2 must not be multishared
@@ -7781,9 +7784,10 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
   Tag ParallelComm::partition_tag()
   {  
     if (!partitionTag) {
+      int dum_id = -1;
       ErrorCode result = mbImpl->tag_get_handle(PARALLEL_PARTITION_TAG_NAME, 
                                                 1, MB_TYPE_INTEGER, partitionTag,
-                                                MB_TAG_SPARSE|MB_TAG_CREAT);
+                                                MB_TAG_SPARSE|MB_TAG_CREAT, &dum_id);
       if (MB_SUCCESS != result)
         return 0;
     }


https://bitbucket.org/fathomteam/moab/commits/7474db614d8b/
Changeset:   7474db614d8b
Branch:      None
User:        iulian07
Date:        2013-10-08 03:02:18
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  12 files

diff --git a/src/Skinner.cpp b/src/Skinner.cpp
index c3c6b1b..02acf2c 100644
--- a/src/Skinner.cpp
+++ b/src/Skinner.cpp
@@ -424,6 +424,7 @@ ErrorCode Skinner::find_skin_noadj(const Range &source_entities,
   for(iter = source_entities.begin(); iter != end_iter; ++iter)
   {
     // get the connectivity of this entity
+    int actual_num_nodes_polygon=0;
     result = thisMB->get_connectivity(*iter, conn, num_nodes, false, &tmp_conn_vec);
     if (MB_SUCCESS != result)
       return result;
@@ -434,7 +435,13 @@ ErrorCode Skinner::find_skin_noadj(const Range &source_entities,
     // treat separately polygons (also, polyhedra will need special handling)
     if (MBPOLYGON == type)
     {
-      num_sides = num_nodes;
+      // treat padded polygons, if existing; count backwards, see how many of the last nodes are repeated
+      // assume connectivity is fine, otherwise we could be in trouble
+      actual_num_nodes_polygon = num_nodes;
+      while (actual_num_nodes_polygon >= 3 &&
+          conn[actual_num_nodes_polygon-1]==conn[actual_num_nodes_polygon-2])
+        actual_num_nodes_polygon--;
+      num_sides = actual_num_nodes_polygon;
       sub_type = MBEDGE;
       num_sub_nodes = 2;
     }
@@ -445,7 +452,9 @@ ErrorCode Skinner::find_skin_noadj(const Range &source_entities,
       if(MBPOLYGON==type)
       {
         sub_conn[0] = conn[i];
-        sub_conn[1] = conn[(i+1)%num_sides];
+        sub_conn[1] = conn[i+1];
+        if (i+1 == actual_num_nodes_polygon)
+          sub_conn[1]=conn[0];
       }
       else
       {
@@ -1431,8 +1440,17 @@ ErrorCode Skinner::create_side( EntityHandle elem,
     }
     if (len == i)
       return MB_FAILURE; // not found, big error
+    // now, what if the polygon is padded?
+    // the previous index is fine always. but the next one could be trouble :(
     int prevIndex = (i+len-1)%len;
     int nextIndex = (i+1)%len;
+    // if the next index actually point to the same node, as current, it means it is padded
+    if (conn[nextIndex]== conn[i])
+    {
+      // it really means we are at the end of proper nodes, the last nodes are repeated, so it should
+      // be the first node
+      nextIndex = 0; // this is the first node!
+    }
     EntityHandle conn2[2] = {side_conn[0], side_conn[1]};
     if (conn[prevIndex]==side_conn[1])
     {
@@ -1617,9 +1635,12 @@ ErrorCode Skinner::find_skin_vertices_2D( Tag tag,
         }
       }
 
-      const int prev_idx = (idx + len - 1)%len;
+      // so it must be a MBPOLYGON
+      const int prev_idx = (idx + len - 1)%len; // this should be fine, always, even for padded case
       prev = conn[prev_idx];
       next = conn[(idx+1)%len];
+      if (next == conn[idx]) // it must be the padded case, so roll to the beginning
+        next = conn[0];
       
         // Insert sides (edges) in our list of candidate skin sides
       adj_edges.insert( &prev, 1, *i, prev_idx );

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index c0605e8..42eeca0 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -18,7 +18,7 @@ const int MAX_EDGES_PER_CELL = 10;
 
 NCHelperMPAS::NCHelperMPAS(ReadNC* readNC, int fileId, const FileOptions& opts, EntityHandle fileSet)
 : UcdNCHelper(readNC, fileId, opts, fileSet)
-, maxCellEdges(MAX_EDGES_PER_CELL)
+, maxEdgesPerCell(MAX_EDGES_PER_CELL)
 , numCellGroups(0)
 {
 }
@@ -47,9 +47,9 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   // Get max edges per cell
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "maxEdges")) != dimNames.end()) {
     idx = vit - dimNames.begin();
-    maxCellEdges = dimLens[idx];
-    if (maxCellEdges > MAX_EDGES_PER_CELL) {
-      ERRORR(MB_FAILURE, "maxEdges read from MPAS file has exceeded the limit");
+    maxEdgesPerCell = dimLens[idx];
+    if (maxEdgesPerCell > MAX_EDGES_PER_CELL) {
+      ERRORR(MB_FAILURE, "maxEdgesPerCell read from MPAS file has exceeded the limit");
     }
   }
 
@@ -182,6 +182,14 @@ ErrorCode NCHelperMPAS::check_existing_mesh()
   if (noMesh) {
     ErrorCode rval;
 
+    // Restore numCellGroups
+    if (0 == numCellGroups) {
+      Tag numCellGroupsTag;
+      rval = mbImpl->tag_get_handle("__NUM_CELL_GROUPS", 1, MB_TYPE_INTEGER, numCellGroupsTag);
+      if (MB_SUCCESS == rval)
+        rval = mbImpl->tag_get_data(numCellGroupsTag, &_fileSet, 1, &numCellGroups);
+    }
+
     if (localGidVerts.empty()) {
       // Get all vertices from tmp_set (it is the input set in no_mesh scenario)
       Range local_verts;
@@ -243,20 +251,15 @@ ErrorCode NCHelperMPAS::check_existing_mesh()
         std::copy(gids.rbegin(), gids.rend(), range_inserter(localGidCells));
         nLocalCells = localGidCells.size();
 
-        // Restore cellHandleToGlobalID
-        Range::const_iterator rit;
-        int i;
-        for (rit = local_cells.begin(), i = 0; rit != local_cells.end(); ++rit, i++)
-          cellHandleToGlobalID[*rit] = gids[i];
+        if (numCellGroups > 1) {
+          // Restore cellHandleToGlobalID
+          Range::const_iterator rit;
+          int i;
+          for (rit = local_cells.begin(), i = 0; rit != local_cells.end(); ++rit, i++)
+            cellHandleToGlobalID[*rit] = gids[i];
+        }
       }
     }
-
-    // Restore numCellGroups
-    if (0 == numCellGroups) {
-      Tag numCellGroupsTag;
-      rval = mbImpl->tag_get_handle("__NUM_CELL_GROUPS", 1, MB_TYPE_INTEGER, numCellGroupsTag);
-      rval = mbImpl->tag_get_data(numCellGroupsTag, &_fileSet, 1, &numCellGroups);
-    }
   }
 
   return MB_SUCCESS;
@@ -268,6 +271,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   Tag& mGlobalIdTag = _readNC->mGlobalIdTag;
   const Tag*& mpFileIdTag = _readNC->mpFileIdTag;
   int& gatherSetRank = _readNC->gatherSetRank;
+  bool& noMixedElements = _readNC->noMixedElements;
 
   int rank = 0;
   int procs = 1;
@@ -312,8 +316,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   success = NCFUNC(inq_varid)(_fileId, "verticesOnCell", &verticesOnCellVarId);
   ERRORS(success, "Failed to get variable id of verticesOnCell.");
   NCDF_SIZE tmp_starts_2[2] = {static_cast<NCDF_SIZE>(start_cell_idx - 1), 0};
-  NCDF_SIZE tmp_counts_2[2] = {static_cast<NCDF_SIZE>(nLocalCells), maxCellEdges};
-  std::vector<int> vertices_on_local_cells(nLocalCells * maxCellEdges);
+  NCDF_SIZE tmp_counts_2[2] = {static_cast<NCDF_SIZE>(nLocalCells), maxEdgesPerCell};
+  std::vector<int> vertices_on_local_cells(nLocalCells * maxEdgesPerCell);
   success = NCFUNCAG(_vara_int)(_fileId, verticesOnCellVarId, tmp_starts_2, tmp_counts_2, &vertices_on_local_cells[0]);
   ERRORS(success, "Failed to read variable values of verticesOnCell.");
 
@@ -322,78 +326,33 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   success = NCFUNC(inq_varid)(_fileId, "edgesOnCell", &edgesOnCellVarId);
   ERRORS(success, "Failed to get variable id of edgesOnCell.");
   NCDF_SIZE tmp_starts_3[2] = {static_cast<NCDF_SIZE>(start_cell_idx - 1), 0};
-  NCDF_SIZE tmp_counts_3[2] = {static_cast<NCDF_SIZE>(nLocalCells), maxCellEdges};
-  std::vector<int> edges_on_local_cells(nLocalCells * maxCellEdges);
+  NCDF_SIZE tmp_counts_3[2] = {static_cast<NCDF_SIZE>(nLocalCells), maxEdgesPerCell};
+  std::vector<int> edges_on_local_cells(nLocalCells * maxEdgesPerCell);
   success = NCFUNCAG(_vara_int)(_fileId, edgesOnCellVarId, tmp_starts_3, tmp_counts_3, &edges_on_local_cells[0]);
   ERRORS(success, "Failed to read variable values of edgesOnCell.");
 
-  // Divide local cells into groups based on the number of edges
-  std::vector<int> local_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
-  for (int i = 0; i < nLocalCells; i++) {
-    int cell_index = start_cell_idx + i; // Global cell index
-    int num_edges = num_edges_on_local_cells[i];
-    local_cells_with_n_edges[num_edges].push_back(cell_index);
-  }
-
-  // For each non-empty cell group, create cells and set connectivity array initially based on file ids
-  ErrorCode rval;
-  EntityHandle start_element;
-  EntityHandle* conn_arr_local_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
-  Range tmp_range;
-  void* data;
-  int count;
-  int* gid_data;
+  // Collect localGid for vertices and edges
   std::set<int> local_verts_set;
   std::set<int> local_edges_set;
-  numCellGroups = 0;
-  for (int i = 3; i <= maxCellEdges; i++) {
-    int num_cells = local_cells_with_n_edges[i].size();
-    if (num_cells > 0) {
-      numCellGroups++;
-
-      rval = _readNC->readMeshIface->get_element_connect(num_cells, i, MBPOLYGON, 0, start_element, conn_arr_local_cells_with_n_edges[i], num_cells);
-      ERRORR(rval, "Couldn't create local cells in MPAS mesh.");
-      Range local_cell_range(start_element, start_element + num_cells - 1);
-      tmp_range.insert(start_element, start_element + num_cells - 1);
-      faces.insert(start_element, start_element + num_cells - 1);
-
-      // Get ptr to gid memory for local cells
-      rval = mbImpl->tag_iterate(mGlobalIdTag, local_cell_range.begin(), local_cell_range.end(), count, data);
-      ERRORR(rval, "Failed to get tag iterator on global id tag.");
-      assert(count == (int) num_cells);
-      gid_data = (int*) data;
-      std::copy(local_cells_with_n_edges[i].begin(), local_cells_with_n_edges[i].end(), gid_data);
-
-      for (int j = 0; j < num_cells; j++) {
-        int cell_idx = local_cells_with_n_edges[i][j]; // Global cell index
-        cellHandleToGlobalID[start_element + j] = cell_idx;
-        cell_idx -= start_cell_idx; // Local cell index
-        for (int k = 0; k < i; k++) {
-          conn_arr_local_cells_with_n_edges[i][i * j + k] = vertices_on_local_cells[cell_idx * maxCellEdges + k];
-          local_verts_set.insert(vertices_on_local_cells[cell_idx * maxCellEdges + k]);
-          local_edges_set.insert(edges_on_local_cells[cell_idx * maxCellEdges + k]);
-        }
-      }
+  for (int i = 0; i < nLocalCells; i++) {
+    int num_edges = num_edges_on_local_cells[i];
+    for (int j = 0; j < num_edges; j++) {
+      local_verts_set.insert(vertices_on_local_cells[i * maxEdgesPerCell + j]);
+      local_edges_set.insert(edges_on_local_cells[i * maxEdgesPerCell + j]);
     }
   }
-
-  // Set tag for numCellGroups
-  Tag numCellGroupsTag = 0;
-  rval = mbImpl->tag_get_handle("__NUM_CELL_GROUPS", 1, MB_TYPE_INTEGER, numCellGroupsTag, MB_TAG_SPARSE | MB_TAG_CREAT);
-  ERRORR(rval, "Trouble creating __NUM_CELL_GROUPS tag.");
-  rval = mbImpl->tag_set_data(numCellGroupsTag, &_fileSet, 1, &numCellGroups);
-  ERRORR(rval, "Trouble setting data for __NUM_CELL_GROUPS tag.");
-
-  // Collect localGid for vertices
   std::copy(local_verts_set.rbegin(), local_verts_set.rend(), range_inserter(localGidVerts));
   nLocalVertices = localGidVerts.size();
+  std::copy(local_edges_set.rbegin(), local_edges_set.rend(), range_inserter(localGidEdges));
+  nLocalEdges = localGidEdges.size();
 
   // Create local vertices
   EntityHandle start_vertex;
   std::vector<double*> arrays;
-  rval = _readNC->readMeshIface->get_node_coords(3, nLocalVertices, 0, start_vertex, arrays,
-                                        // Might have to create gather mesh later
-                                        (create_gathers ? nLocalVertices + nVertices : nLocalVertices));
+  Range tmp_range;
+  ErrorCode rval = _readNC->readMeshIface->get_node_coords(3, nLocalVertices, 0, start_vertex, arrays,
+                                                          // Might have to create gather mesh later
+                                                          (create_gathers ? nLocalVertices + nVertices : nLocalVertices));
   ERRORR(rval, "Couldn't create local vertices in MPAS mesh.");
   tmp_range.insert(start_vertex, start_vertex + nLocalVertices - 1);
 
@@ -412,17 +371,19 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
   // Get ptr to gid memory for local vertices
   Range local_verts_range(start_vertex, start_vertex + nLocalVertices - 1);
+  int count = 0;
+  void* data = NULL;
   rval = mbImpl->tag_iterate(mGlobalIdTag, local_verts_range.begin(), local_verts_range.end(), count, data);
-  ERRORR(rval, "Failed to get tag iterator on global id tag.");
-  assert(count == (int) nLocalVertices);
-  gid_data = (int*) data;
+  ERRORR(rval, "Failed to get global id tag iterator on local vertices.");
+  assert(count == nLocalVertices);
+  int* gid_data = (int*) data;
   std::copy(localGidVerts.begin(), localGidVerts.end(), gid_data);
 
   // Duplicate global id data, which will be used to resolve sharing
   if (mpFileIdTag) {
     rval = mbImpl->tag_iterate(*mpFileIdTag, local_verts_range.begin(), local_verts_range.end(), count, data);
-    ERRORR(rval, "Failed to get tag iterator on file id tag.");
-    assert(count == (int) nLocalVertices);
+    ERRORR(rval, "Failed to get file id tag iterator on local vertices.");
+    assert(count == nLocalVertices);
     gid_data = (int*) data;
     std::copy(localGidVerts.begin(), localGidVerts.end(), gid_data);
   }
@@ -432,29 +393,12 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   for (rit = localGidVerts.begin(), vert_idx = 0; rit != localGidVerts.end(); ++rit, vert_idx++)
     vert_handles[*rit] = start_vertex + vert_idx;
 
-  // For each non-empty cell group, set connectivity array with proper local vertices handles
-  for (int i = 3; i <= maxCellEdges; i++) {
-    int num_cells = local_cells_with_n_edges[i].size();
-    if (num_cells > 0) {
-      for (int j = 0; j < num_cells; j++) {
-        for (int k = 0; k < i; k++) {
-          EntityHandle global_vert_id = conn_arr_local_cells_with_n_edges[i][i * j + k];
-          conn_arr_local_cells_with_n_edges[i][i * j + k] = vert_handles[global_vert_id];
-        }
-      }
-    }
-  }
-
-  // Collect localGid for edges
-  std::copy(local_edges_set.rbegin(), local_edges_set.rend(), range_inserter(localGidEdges));
-  nLocalEdges = localGidEdges.size();
-
   // Create local edges
   EntityHandle start_edge;
   EntityHandle* conn_arr_edges;
   rval = _readNC->readMeshIface->get_element_connect(nLocalEdges, 2, MBEDGE, 0, start_edge, conn_arr_edges,
-                                            // Might have to create gather mesh later
-                                            (create_gathers ? nLocalEdges + nEdges : nLocalEdges));
+                                                    // Might have to create gather mesh later
+                                                    (create_gathers ? nLocalEdges + nEdges : nLocalEdges));
   ERRORR(rval, "Couldn't create local edges in MPAS mesh.");
   Range local_edges_range(start_edge, start_edge + nLocalEdges - 1);
   tmp_range.insert(start_edge, start_edge + nLocalEdges - 1);
@@ -471,11 +415,102 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
   // Get ptr to gid memory for edges
   rval = mbImpl->tag_iterate(mGlobalIdTag, local_edges_range.begin(), local_edges_range.end(), count, data);
-  ERRORR(rval, "Failed to get tag iterator on global id tag.");
+  ERRORR(rval, "Failed to get global id tag iterator on local edges.");
   assert(count == (int) nLocalEdges);
   gid_data = (int*) data;
   std::copy(localGidEdges.begin(), localGidEdges.end(), gid_data);
 
+  EntityHandle start_element = 0;
+  if (noMixedElements) {
+    // Only one group of cells (each cell is represented by a polygon with maxEdgesPerCell edges)
+    numCellGroups = 1;
+
+    // Create cells and set connectivity array with proper local vertices handles
+    EntityHandle* conn_arr_local_cells = NULL;
+    rval = _readNC->readMeshIface->get_element_connect(nLocalCells, maxEdgesPerCell, MBPOLYGON, 0, start_element, conn_arr_local_cells,
+                                                      // Might have to create gather mesh later
+                                                      (create_gathers ? nLocalCells + nCells : nLocalCells));
+    ERRORR(rval, "Couldn't create local cells in MPAS mesh.");
+    Range local_cell_range(start_element, start_element + nLocalCells - 1);
+    tmp_range.insert(start_element, start_element + nLocalCells - 1);
+    faces.insert(start_element, start_element + nLocalCells - 1);
+
+    // Get ptr to gid memory for local cells
+    rval = mbImpl->tag_iterate(mGlobalIdTag, local_cell_range.begin(), local_cell_range.end(), count, data);
+    ERRORR(rval, "Failed to get global id tag iterator on local cells.");
+    assert(count == nLocalCells);
+    gid_data = (int*) data;
+    std::copy(localGidCells.begin(), localGidCells.end(), gid_data);
+
+    // Set connectivity array with proper local vertices handles
+    for (int cell_idx = 0; cell_idx < nLocalCells; cell_idx++) {
+      int num_edges = num_edges_on_local_cells[cell_idx];
+      for (int i = 0; i < num_edges; i++) {
+        EntityHandle global_vert_id = vertices_on_local_cells[cell_idx * maxEdgesPerCell + i];
+        conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] = vert_handles[global_vert_id];
+      }
+
+      // Padding: fill connectivity array with last vertex handle
+      EntityHandle last_vert_id = conn_arr_local_cells[cell_idx * maxEdgesPerCell + num_edges - 1];
+      for (int i = num_edges; i < maxEdgesPerCell; i++)
+        conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] = last_vert_id;
+    }
+  } // if (noMixedElements)
+  else {
+    // Divide local cells into groups based on the number of edges
+    std::vector<int> local_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
+    for (int i = 0; i < nLocalCells; i++) {
+      int num_edges = num_edges_on_local_cells[i];
+      local_cells_with_n_edges[num_edges].push_back(start_cell_idx + i); // Global cell index
+    }
+
+    std::vector<int> num_edges_on_cell_groups;
+    for (int i = 3; i <= maxEdgesPerCell; i++) {
+      if (local_cells_with_n_edges[i].size() > 0)
+        num_edges_on_cell_groups.push_back(i);
+    }
+    numCellGroups = num_edges_on_cell_groups.size();
+
+    // For each non-empty cell group, create cells and set connectivity array with proper local vertices handles
+    EntityHandle* conn_arr_local_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
+    for (int i = 0; i < numCellGroups; i++) {
+      int num_edges_per_cell = num_edges_on_cell_groups[i];
+      int num_cells = local_cells_with_n_edges[num_edges_per_cell].size();
+
+      rval = _readNC->readMeshIface->get_element_connect(num_cells, num_edges_per_cell, MBPOLYGON, 0, start_element,
+                                                         conn_arr_local_cells_with_n_edges[num_edges_per_cell], num_cells);
+      ERRORR(rval, "Couldn't create local cells in MPAS mesh.");
+      Range local_cell_range(start_element, start_element + num_cells - 1);
+      tmp_range.insert(start_element, start_element + num_cells - 1);
+      faces.insert(start_element, start_element + num_cells - 1);
+
+      // Get ptr to gid memory for local cells
+      rval = mbImpl->tag_iterate(mGlobalIdTag, local_cell_range.begin(), local_cell_range.end(), count, data);
+      ERRORR(rval, "Failed to get global id tag iterator on local cells.");
+      assert(count == num_cells);
+      gid_data = (int*) data;
+      std::copy(local_cells_with_n_edges[num_edges_per_cell].begin(), local_cells_with_n_edges[num_edges_per_cell].end(), gid_data);
+
+      for (int j = 0; j < num_cells; j++) {
+        int cell_idx = local_cells_with_n_edges[num_edges_per_cell][j]; // Global cell index
+        if (numCellGroups > 1)
+          cellHandleToGlobalID[start_element + j] = cell_idx;
+        cell_idx -= start_cell_idx; // Local cell index
+        for (int k = 0; k < num_edges_per_cell; k++) {
+          EntityHandle global_vert_id = vertices_on_local_cells[cell_idx * maxEdgesPerCell + k];
+          conn_arr_local_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] = vert_handles[global_vert_id];
+        }
+      }
+    } // for (int i = 0; i < numCellGroups; i++)
+  }
+
+  // Set tag for numCellGroups
+  Tag numCellGroupsTag = 0;
+  rval = mbImpl->tag_get_handle("__NUM_CELL_GROUPS", 1, MB_TYPE_INTEGER, numCellGroupsTag, MB_TAG_SPARSE | MB_TAG_CREAT);
+  ERRORR(rval, "Trouble creating __NUM_CELL_GROUPS tag.");
+  rval = mbImpl->tag_set_data(numCellGroupsTag, &_fileSet, 1, &numCellGroups);
+  ERRORR(rval, "Trouble setting data for __NUM_CELL_GROUPS tag.");
+
   // Add new vertices, elements and edges to the file set
   rval = _readNC->mbImpl->add_entities(_fileSet, tmp_range);
   ERRORR(rval, "Couldn't add new vertices/faces/edges to file set.");
@@ -487,7 +522,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
     // Create gather vertices
     arrays.clear();
-    // Don't need to specify allocation number here, because we know enough verts were created before
+    // Don't need to specify allocation number here, because we know enough vertices were created before
     rval = _readNC->readMeshIface->get_node_coords(3, nVertices, 0, start_vertex, arrays);
     ERRORR(rval, "Couldn't create vertices in MPAS mesh for gather set.");
     Range gather_verts_range(start_vertex, start_vertex + nVertices - 1);
@@ -503,7 +538,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
     // Get ptr to gid memory for gather vertices
     rval = mbImpl->tag_iterate(mGlobalIdTag, gather_verts_range.begin(), gather_verts_range.end(), count, data);
-    ERRORR(rval, "Failed to get tag iterator on global id tag..");
+    ERRORR(rval, "Failed to get global id tag iterator on gather vertices.");
     assert(count == nVertices);
     gid_data = (int*) data;
     for (int j = 1; j <= nVertices; j++)
@@ -511,7 +546,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     // Set the file id tag too, it should be bigger something not interfering with global id
     if (mpFileIdTag) {
       rval = mbImpl->tag_iterate(*mpFileIdTag, gather_verts_range.begin(), gather_verts_range.end(), count, data);
-      ERRORR(rval, "Failed to get tag iterator on file id tag.");
+      ERRORR(rval, "Failed to get file id tag iterator on gather vertices.");
       assert(count == nVertices);
       gid_data = (int*) data;
       for (int j = 1; j <= nVertices; j++)
@@ -537,12 +572,28 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     success = NCFUNCG(_vara_int)(_fileId, nEdgesOnCellVarId, tmp_starts_1, tmp_counts_1, &num_edges_on_gather_cells[0]);
     ERRORS(success, "Failed to read variable values of nEdgesOnCell.");
 #endif
+
+    // Create gather edges
+    EntityHandle* conn_arr_gather_edges;
+    // Don't need to specify allocation number here, because we know enough edges were created before
+    rval = _readNC->readMeshIface->get_element_connect(nEdges, 2, MBEDGE, 0, start_edge, conn_arr_gather_edges);
+    ERRORR(rval, "Couldn't create edges in MPAS mesh for gather set.");
+    Range gather_edges_range(start_edge, start_edge + nEdges - 1);
+
+    std::copy(verticesOnEdge.begin(), verticesOnEdge.end(), conn_arr_gather_edges);
+    for (int i = 0; i < 2 * nEdges; i++)
+      // Connectivity array is shifted by where the gather verts start
+      conn_arr_gather_edges[i] += start_vertex - 1;
+
+    rval = mbImpl->add_entities(gather_set, gather_edges_range);
+    ERRORR(rval, "Couldn't add edges to gather set.");
+
     // Read vertices on each gather cell (connectivity)
-    std::vector<int> vertices_on_gather_cells(nCells * maxCellEdges);
+    std::vector<int> vertices_on_gather_cells(nCells * maxEdgesPerCell);
     tmp_starts_2[0] = 0;
     tmp_starts_2[1] = 0;
     tmp_counts_2[0] = nCells;
-    tmp_counts_2[1] = maxCellEdges;
+    tmp_counts_2[1] = maxEdgesPerCell;
 #ifdef PNETCDF_FILE
     // Enter independent I/O mode, since this read is only for the gather processor
     success = NCFUNC(begin_indep_data)(_fileId);
@@ -556,50 +607,58 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     ERRORS(success, "Failed to read variable values of verticesOnCell.");
 #endif
 
-    // Divide gather cells into groups based on the number of edges
-    std::vector<int> gather_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
-    for (int i = 0; i < nCells; i++) {
-      int num_edges = num_edges_on_gather_cells[i];
-      gather_cells_with_n_edges[num_edges].push_back(i + 1); // 0 based -> 1 based
+    Range gather_cells_range;
+    if (noMixedElements) {
+      // Create gather cells
+      EntityHandle* conn_arr_gather_cells;
+      // Don't need to specify allocation number here, because we know enough cells were created before
+      rval = _readNC->readMeshIface->get_element_connect(nCells, maxEdgesPerCell, MBPOLYGON, 0, start_element, conn_arr_gather_cells);
+      ERRORR(rval, "Couldn't create cells in MPAS mesh for gather set.");
+      gather_cells_range.insert(start_element, start_element + nCells - 1);
+
+      for (int cell_idx = 0; cell_idx < nCells; cell_idx++) {
+        int num_edges = num_edges_on_gather_cells[cell_idx];
+        for (int i = 0; i < num_edges; i++)
+          // Connectivity array is shifted by where the gather verts start
+          conn_arr_gather_cells[cell_idx * maxEdgesPerCell + i] = (start_vertex - 1) + vertices_on_gather_cells[cell_idx * maxEdgesPerCell + i];
+
+        // Padding: fill connectivity array with last vertex handle
+        EntityHandle last_vert_id = conn_arr_gather_cells[cell_idx * maxEdgesPerCell + num_edges - 1];
+        for (int i = num_edges; i < maxEdgesPerCell; i++)
+          conn_arr_gather_cells[cell_idx * maxEdgesPerCell + i] = last_vert_id;
+      }
     }
+    else {
+      // Divide gather cells into groups based on the number of edges
+      std::vector<int> gather_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
+      for (int i = 0; i < nCells; i++) {
+        int num_edges = num_edges_on_gather_cells[i];
+        gather_cells_with_n_edges[num_edges].push_back(i + 1); // 0 based -> 1 based
+      }
 
-    // For each non-empty cell group, create cells and set connectivity array
-    EntityHandle* conn_arr_gather_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
-    Range gather_cells_range;
-    for (int i = 3; i <= maxCellEdges; i++) {
-      int num_cells = gather_cells_with_n_edges[i].size();
-      if (num_cells > 0) {
-        rval = _readNC->readMeshIface->get_element_connect(num_cells, i, MBPOLYGON, 0, start_element, conn_arr_gather_cells_with_n_edges[i], num_cells);
-        ERRORR(rval, "Couldn't create cells in MPAS mesh for gather set.");
-        gather_cells_range.insert(start_element, start_element + num_cells - 1);
-        for (int j = 0; j < num_cells; j++) {
-          int cell_idx = gather_cells_with_n_edges[i][j]; // Global cell index
-          cell_idx--; // 1 based -> 0 based
-          for (int k = 0; k < i; k++)
-            // Connectivity array is shifted by where the gather verts start
-            conn_arr_gather_cells_with_n_edges[i][i * j + k] = (start_vertex - 1) + vertices_on_gather_cells[cell_idx * maxCellEdges + k];
+      // Create gather cells
+      EntityHandle* conn_arr_gather_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
+      for (int num_edges_per_cell = 3; num_edges_per_cell <= maxEdgesPerCell; num_edges_per_cell++) {
+        int num_cells = gather_cells_with_n_edges[num_edges_per_cell].size();
+        if (num_cells > 0) {
+          rval = _readNC->readMeshIface->get_element_connect(num_cells, num_edges_per_cell, MBPOLYGON, 0, start_element,
+                                                             conn_arr_gather_cells_with_n_edges[num_edges_per_cell], num_cells);
+          ERRORR(rval, "Couldn't create cells in MPAS mesh for gather set.");
+          gather_cells_range.insert(start_element, start_element + num_cells - 1);
+          for (int j = 0; j < num_cells; j++) {
+            int cell_idx = gather_cells_with_n_edges[num_edges_per_cell][j];
+            cell_idx--; // 1 based -> 0 based
+            for (int k = 0; k < num_edges_per_cell; k++)
+              // Connectivity array is shifted by where the gather verts start
+              conn_arr_gather_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] =
+                (start_vertex - 1) + vertices_on_gather_cells[cell_idx * maxEdgesPerCell + k];
+          }
         }
       }
     }
 
     rval = mbImpl->add_entities(gather_set, gather_cells_range);
     ERRORR(rval, "Couldn't add cells to gather set.");
-
-    // Create gather edges
-    EntityHandle* conn_arr_gather_edges;
-
-    // Don't need to specify allocation number here, because we know enough edges were created before
-    rval = _readNC->readMeshIface->get_element_connect(nEdges, 2, MBEDGE, 0, start_edge, conn_arr_gather_edges);
-    ERRORR(rval, "Couldn't create edges in MPAS mesh for gather set.");
-    Range gather_edges_range(start_edge, start_edge + nEdges - 1);
-
-    std::copy(verticesOnEdge.begin(), verticesOnEdge.end(), conn_arr_gather_edges);
-    for (int i = 0; i < 2 * nEdges; i++)
-      // Connectivity array is shifted by where the gather verts start
-      conn_arr_gather_edges[i] += start_vertex - 1;
-
-    rval = mbImpl->add_entities(gather_set, gather_edges_range);
-    ERRORR(rval, "Couldn't add edges to gather set.");
   }
 
   return MB_SUCCESS;
@@ -615,8 +674,7 @@ ErrorCode NCHelperMPAS::read_ucd_variable_setup(std::vector<std::string>& var_na
   if (var_names.empty()) {
     for (mit = varInfo.begin(); mit != varInfo.end(); ++mit) {
       ReadNC::VarData vd = (*mit).second;
-      if (3 == vd.varDims.size())
-      {
+      if (3 == vd.varDims.size()) {
         if ((std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) && (std::find(vd.varDims.begin(),
             vd.varDims.end(), cDim) != vd.varDims.end()) && (std::find(vd.varDims.begin(), vd.varDims.end(), levDim)
             != vd.varDims.end()))
@@ -667,6 +725,7 @@ ErrorCode NCHelperMPAS::read_ucd_variable_setup(std::vector<std::string>& var_na
     for (int i = 0; i < nTimeSteps; i++)
       tstep_nums.push_back(i);
   }
+
   if (!tstep_nums.empty()) {
     for (unsigned int i = 0; i < vdatas.size(); i++) {
       vdatas[i].varTags.resize(tstep_nums.size(), 0);
@@ -790,8 +849,10 @@ ErrorCode NCHelperMPAS::read_ucd_variable_to_nonset_allocate(std::vector<ReadNC:
       assert(vdatas[i].readStarts[t].size() == vdatas[i].varDims.size());
 
       // Get ptr to tag space
-      if (vdatas[i].entLoc == ReadNC::ENTLOCFACE && numCellGroups > 1)
+      if (vdatas[i].entLoc == ReadNC::ENTLOCFACE && numCellGroups > 1) {
+        // For a cell variable that is NOT on one contiguous chunk of faces, defer its tag space allocation
         vdatas[i].varDatas[t] = NULL;
+      }
       else {
         assert(1 == range->psize());
         void* data;
@@ -893,9 +954,9 @@ ErrorCode NCHelperMPAS::read_ucd_variable_to_nonset_async(std::vector<ReadNC::Va
           success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
           ERRORS(success, "Failed on wait_all.");
 
-          // Local cells are grouped by the number of edges on each cell, e.g. 5, 6 or 7
-          // Tags created for cell variables may have to read data from different groups
           if (vdatas[i].entLoc == ReadNC::ENTLOCFACE && numCellGroups > 1) {
+            // For a cell variable that is NOT on one contiguous chunk of faces, allocate tag space for
+            // each cell group, and utilize cellHandleToGlobalID map to read tag data
             Range::iterator iter = facesOwned.begin();
             while (iter != facesOwned.end()) {
               int count;
@@ -1030,9 +1091,9 @@ ErrorCode NCHelperMPAS::read_ucd_variable_to_nonset(std::vector<ReadNC::VarData>
           }
           assert(ic == pLocalGid->psize());
 
-          // Local cells are grouped by the number of edges on each cell, e.g. 5, 6 or 7
-          // Tags created for cell variables may have to read data from different groups
           if (vdatas[i].entLoc == ReadNC::ENTLOCFACE && numCellGroups > 1) {
+            // For a cell variable that is NOT on one contiguous chunk of faces, allocate tag space for
+            // each cell group, and utilize cellHandleToGlobalID map to read tag data
             Range::iterator iter = facesOwned.begin();
             while (iter != facesOwned.end()) {
               int count;

diff --git a/src/io/NCHelperMPAS.hpp b/src/io/NCHelperMPAS.hpp
index 789a0fb..2c97566 100644
--- a/src/io/NCHelperMPAS.hpp
+++ b/src/io/NCHelperMPAS.hpp
@@ -49,7 +49,7 @@ private:
 #endif
 
 private:
-  int maxCellEdges;
+  int maxEdgesPerCell;
   int numCellGroups;
   std::vector<int> verticesOnEdge;
   std::map<EntityHandle, int> cellHandleToGlobalID;

diff --git a/src/io/ReadNC.cpp b/src/io/ReadNC.cpp
index a27a89d..80ad2f1 100644
--- a/src/io/ReadNC.cpp
+++ b/src/io/ReadNC.cpp
@@ -24,7 +24,7 @@ ReadNC::ReadNC(Interface* impl) :
 #ifdef USE_MPI
   myPcomm(NULL),
 #endif
-  noMesh(false), noVars(false), spectralMesh(false), gatherSetRank(-1), myHelper(NULL)
+  noMesh(false), noVars(false), spectralMesh(false), noMixedElements(false), gatherSetRank(-1), myHelper(NULL)
 {
   assert(impl != NULL);
   impl->query_interface(readMeshIface);
@@ -214,6 +214,10 @@ ErrorCode ReadNC::parse_options(const FileOptions& opts, std::vector<std::string
   if (MB_SUCCESS == rval)
     spectralMesh = true;
 
+  rval = opts.get_null_option("NO_MIXED_ELEMENTS");
+  if (MB_SUCCESS == rval)
+    noMixedElements = true;
+
   if (2 <= dbgOut.get_verbosity()) {
     if (!var_names.empty()) {
       std::cerr << "Variables requested: ";

diff --git a/src/io/ReadNC.hpp b/src/io/ReadNC.hpp
index e8b1845..eb470cd 100644
--- a/src/io/ReadNC.hpp
+++ b/src/io/ReadNC.hpp
@@ -207,6 +207,7 @@ private:
   bool noMesh;
   bool noVars;
   bool spectralMesh;
+  bool noMixedElements;
   int gatherSetRank;
 
   //! Helper class instance

diff --git a/test/io/read_mpas_nc.cpp b/test/io/read_mpas_nc.cpp
index d442577..597c752 100644
--- a/test/io/read_mpas_nc.cpp
+++ b/test/io/read_mpas_nc.cpp
@@ -1,5 +1,6 @@
 #include "TestUtil.hpp"
 #include "moab/Core.hpp"
+#include "moab/ReadUtilIface.hpp"
 
 using namespace moab;
 
@@ -11,6 +12,7 @@ static const char example[] = "/io/mpasx1.642.t.2.nc";
 
 #ifdef USE_MPI
 #include "moab_mpi.h"
+#include "moab/ParallelComm.hpp"
 #endif
 
 void test_read_all();
@@ -18,6 +20,7 @@ void test_read_onevar();
 void test_read_onetimestep();
 void test_read_nomesh();
 void test_read_novars();
+void test_read_no_mixed_elements();
 
 ErrorCode get_options(std::string& opts);
 
@@ -30,7 +33,7 @@ int main(int argc, char* argv[])
   if (fail)
     return 1;
 #else
-  argv[0] = argv[argc-argc]; // To remove the warnings in serial mode about unused variables
+  argv[0] = argv[argc - argc]; // To remove the warnings in serial mode about unused variables
 #endif
 
   result += RUN_TEST(test_read_all);
@@ -38,6 +41,8 @@ int main(int argc, char* argv[])
   result += RUN_TEST(test_read_onetimestep);
   result += RUN_TEST(test_read_nomesh);
   result += RUN_TEST(test_read_novars);
+  // Test read option NO_MIXED_ELEMENTS
+  result += RUN_TEST(test_read_no_mixed_elements);
 
 #ifdef USE_MPI
   fail = MPI_Finalize();
@@ -50,8 +55,6 @@ int main(int argc, char* argv[])
 
 void test_read_all()
 {
-  const double eps = 1e-20;
-  double val[2];
   Core moab;
   Interface& mb = moab;
 
@@ -62,81 +65,93 @@ void test_read_all()
   rval = mb.load_file(example, NULL, opts.c_str());
   CHECK_ERR(rval);
 
-  // Check tags for vertex variable vorticity
-  Tag vorticity_tag0, vorticity_tag1;
-  rval = mb.tag_get_handle("vorticity0", 1, MB_TYPE_DOUBLE, vorticity_tag0);
-  CHECK_ERR(rval);
-  rval = mb.tag_get_handle("vorticity1", 1, MB_TYPE_DOUBLE, vorticity_tag1);
-  CHECK_ERR(rval);
-
-  // Get vertices (1280 edges)
-  Range verts;
-  rval = mb.get_entities_by_type(0, MBVERTEX, verts);
-  assert(rval == MB_SUCCESS);
-  CHECK_EQUAL((size_t)1280, verts.size());
-  CHECK_EQUAL((size_t)1, verts.psize());
-
-  // Check vorticity tag values on first two vertices
-  EntityHandle vert_ents[] = {verts[0], verts[1]};
-  rval = mb.tag_get_data(vorticity_tag0, &vert_ents[0], 2, val);
-  CHECK_REAL_EQUAL(1.1, val[0], eps);
-  CHECK_REAL_EQUAL(1.2, val[1], eps);
-  rval = mb.tag_get_data(vorticity_tag1, &vert_ents[0], 2, val);
-  CHECK_REAL_EQUAL(2.1, val[0], eps);
-  CHECK_REAL_EQUAL(2.2, val[1], eps);
-
-  // Check tags for edge variable u
-  Tag u_tag0, u_tag1;
-  rval = mb.tag_get_handle("u0", 1, MB_TYPE_DOUBLE, u_tag0);
-  CHECK_ERR(rval);
-  rval = mb.tag_get_handle("u1", 1, MB_TYPE_DOUBLE, u_tag1);
-  CHECK_ERR(rval);
-
-  // Get edges (1920 edges)
-  Range edges;
-  rval = mb.get_entities_by_type(0, MBEDGE, edges);
-  assert(rval == MB_SUCCESS);
-  CHECK_EQUAL((size_t)1920, edges.size());
-  CHECK_EQUAL((size_t)1, edges.psize());
-
-  // Check u tag values on two specified edges
-  EntityHandle edge_ents[] = {edges[5], edges[6]};
-  rval = mb.tag_get_data(u_tag0, &edge_ents[0], 2, val);
-  CHECK_REAL_EQUAL(1.113138721544778, val[0], eps);
-  CHECK_REAL_EQUAL(-1.113138721930009, val[1], eps);
-  rval = mb.tag_get_data(u_tag1, &edge_ents[0], 2, val);
-  CHECK_REAL_EQUAL(2.113138721544778, val[0], eps);
-  CHECK_REAL_EQUAL(-2.113138721930009, val[1], eps);
-
-  // Check tags for cell variable ke
-  Tag ke_tag0, ke_tag1;
-  rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
-  CHECK_ERR(rval);
-  rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
-  CHECK_ERR(rval);
+  int procs = 1;
+#ifdef USE_MPI
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
+  procs = pcomm->proc_config().proc_size();
+#endif
 
-  // Get cells (12 pentagons and 630 hexagons)
-  Range cells;
-  rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
-  assert(rval == MB_SUCCESS);
-  CHECK_EQUAL((size_t)642, cells.size());
+  // Make check runs this test in one processor
+  if (1 == procs) {
+    // Check tags for vertex variable vorticity
+    Tag vorticity_tag0, vorticity_tag1;
+    rval = mb.tag_get_handle("vorticity0", 1, MB_TYPE_DOUBLE, vorticity_tag0);
+    CHECK_ERR(rval);
+    rval = mb.tag_get_handle("vorticity1", 1, MB_TYPE_DOUBLE, vorticity_tag1);
+    CHECK_ERR(rval);
+
+    // Get vertices (1280 edges)
+    Range verts;
+    rval = mb.get_entities_by_type(0, MBVERTEX, verts);
+    assert(rval == MB_SUCCESS);
+    CHECK_EQUAL((size_t)1280, verts.size());
+    CHECK_EQUAL((size_t)1, verts.psize());
+
+    const double eps = 1e-20;
+    double val[2];
+
+    // Check vorticity tag values on first two vertices
+    EntityHandle vert_ents[] = {verts[0], verts[1]};
+    rval = mb.tag_get_data(vorticity_tag0, &vert_ents[0], 2, val);
+    CHECK_REAL_EQUAL(1.1, val[0], eps);
+    CHECK_REAL_EQUAL(1.2, val[1], eps);
+    rval = mb.tag_get_data(vorticity_tag1, &vert_ents[0], 2, val);
+    CHECK_REAL_EQUAL(2.1, val[0], eps);
+    CHECK_REAL_EQUAL(2.2, val[1], eps);
+
+    // Check tags for edge variable u
+    Tag u_tag0, u_tag1;
+    rval = mb.tag_get_handle("u0", 1, MB_TYPE_DOUBLE, u_tag0);
+    CHECK_ERR(rval);
+    rval = mb.tag_get_handle("u1", 1, MB_TYPE_DOUBLE, u_tag1);
+    CHECK_ERR(rval);
+
+    // Get edges (1920 edges)
+    Range edges;
+    rval = mb.get_entities_by_type(0, MBEDGE, edges);
+    assert(rval == MB_SUCCESS);
+    CHECK_EQUAL((size_t)1920, edges.size());
+    CHECK_EQUAL((size_t)1, edges.psize());
+
+    // Check u tag values on two specified edges
+    EntityHandle edge_ents[] = {edges[5], edges[6]};
+    rval = mb.tag_get_data(u_tag0, &edge_ents[0], 2, val);
+    CHECK_REAL_EQUAL(1.113138721544778, val[0], eps);
+    CHECK_REAL_EQUAL(-1.113138721930009, val[1], eps);
+    rval = mb.tag_get_data(u_tag1, &edge_ents[0], 2, val);
+    CHECK_REAL_EQUAL(2.113138721544778, val[0], eps);
+    CHECK_REAL_EQUAL(-2.113138721930009, val[1], eps);
+
+    // Check tags for cell variable ke
+    Tag ke_tag0, ke_tag1;
+    rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+    CHECK_ERR(rval);
+    rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+    CHECK_ERR(rval);
+
+    // Get cells (12 pentagons and 630 hexagons)
+    Range cells;
+    rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+    assert(rval == MB_SUCCESS);
+    CHECK_EQUAL((size_t)642, cells.size());
 #ifdef USE_MPI
-  // If MOAB is compiled parallel, sequence size requested are increased
-  // by a factor of 1.5, to allow for ghosts. This will introduce a gap
-  // between the two face sequences.
-  CHECK_EQUAL((size_t)2, cells.psize());
+    // If MOAB is compiled parallel, sequence size requested are increased
+    // by a factor of 1.5, to allow for ghosts. This will introduce a gap
+    // between the two face sequences.
+    CHECK_EQUAL((size_t)2, cells.psize());
 #else
-  CHECK_EQUAL((size_t)1, cells.psize());
+    CHECK_EQUAL((size_t)1, cells.psize());
 #endif
 
-  // Check ke tag values on first pentagon and first hexagon
-  EntityHandle cell_ents[] = {cells[0], cells[12]};
-  rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
-  CHECK_REAL_EQUAL(1.5, val[0], eps);
-  CHECK_REAL_EQUAL(1.6, val[1], eps);
-  rval = mb.tag_get_data(ke_tag1, &cell_ents[0], 2, val);
-  CHECK_REAL_EQUAL(2.5, val[0], eps);
-  CHECK_REAL_EQUAL(2.6, val[1], eps);
+    // Check ke tag values on first pentagon and first hexagon
+    EntityHandle cell_ents[] = {cells[0], cells[12]};
+    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
+    CHECK_REAL_EQUAL(1.5, val[0], eps);
+    CHECK_REAL_EQUAL(1.6, val[1], eps);
+    rval = mb.tag_get_data(ke_tag1, &cell_ents[0], 2, val);
+    CHECK_REAL_EQUAL(2.5, val[0], eps);
+    CHECK_REAL_EQUAL(2.6, val[1], eps);
+  }
 }
 
 void test_read_onevar() 
@@ -148,15 +163,75 @@ void test_read_onevar()
   CHECK_ERR(rval);
 
   opts += std::string(";VARIABLE=ke");
+  // Create gather set
+  opts += std::string(";GATHER_SET=");
   rval = mb.load_file(example, NULL, opts.c_str());
   CHECK_ERR(rval);
 
-  // Check for proper tags
-  Tag ke_tag0, ke_tag1;
-  rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
-  CHECK_ERR(rval);
-  rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
-  CHECK_ERR(rval);
+  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
+  if (1 == procs) {
+    // Check for proper tags
+    Tag ke_tag0, ke_tag1;
+    rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+    CHECK_ERR(rval);
+    rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+    CHECK_ERR(rval);
+
+    // Get cells (12 pentagons and 630 hexagons)
+    Range cells;
+    rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+    assert(rval == MB_SUCCESS);
+    CHECK_EQUAL((size_t)1284, cells.size()); // Gather set cells included
+#ifdef USE_MPI
+    // If MOAB is compiled parallel, sequence size requested are increased
+    // by a factor of 1.5, to allow for ghosts. This will introduce a gap
+    // between the two face sequences.
+    CHECK_EQUAL((size_t)4, cells.psize()); // Gather set cells included
+#else
+    CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included
+#endif
+
+    // 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 cells
+    cells = subtract(cells, gather_ents);
+    CHECK_EQUAL((size_t)642, cells.size()); // Gather set cells excluded
+#ifdef USE_MPI
+    // If MOAB is compiled parallel, sequence size requested are increased
+    // by a factor of 1.5, to allow for ghosts. This will introduce a gap
+    // between the two face sequences.
+    CHECK_EQUAL((size_t)2, cells.psize()); // Gather set cells excluded
+#else
+    CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded
+#endif
+
+    // Check ke tag values on first pentagon and first hexagon
+    const double eps = 1e-20;
+    double val[2];
+    EntityHandle cell_ents[] = {cells[0], cells[12]};
+    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
+    CHECK_REAL_EQUAL(1.5, val[0], eps);
+    CHECK_REAL_EQUAL(1.6, val[1], eps);
+    rval = mb.tag_get_data(ke_tag1, &cell_ents[0], 2, val);
+    CHECK_REAL_EQUAL(2.5, val[0], eps);
+    CHECK_REAL_EQUAL(2.6, val[1], eps);
+  }
 }
 
 void test_read_onetimestep()
@@ -196,7 +271,7 @@ void test_read_nomesh()
   opts = orig + std::string(";TIMESTEP=0");
   rval = mb.load_file(example, &set, opts.c_str());
   CHECK_ERR(rval);
-  
+
   // Check for proper tags
   Tag ke_tag0, ke_tag1;
   rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
@@ -261,6 +336,55 @@ void test_read_novars()
   CHECK_ERR(rval);
 }
 
+void test_read_no_mixed_elements()
+{
+  Core moab;
+  Interface& mb = moab;
+  std::string opts;
+  ErrorCode rval = get_options(opts);
+  CHECK_ERR(rval);
+
+  opts += std::string(";NO_MIXED_ELEMENTS;VARIABLE=ke");
+  rval = mb.load_file(example, NULL, 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
+
+  // Make check runs this test in one processor
+  if (1 == procs) {
+    // Check for proper tags
+    Tag ke_tag0, ke_tag1;
+    rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+    CHECK_ERR(rval);
+    rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+    CHECK_ERR(rval);
+
+    // Get cells (12 pentagons and 630 hexagons)
+    Range cells;
+    rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+    assert(rval == MB_SUCCESS);
+    CHECK_EQUAL((size_t)642, cells.size());
+    // Only one group of cells (each cell is actually represented by a 10-vertex polygon)
+    CHECK_EQUAL((size_t)1, cells.psize());
+
+    const double eps = 1e-20;
+    double val[2];
+
+    // Check ke tag values on first pentagon and first hexagon
+    EntityHandle cell_ents[] = {cells[0], cells[12]};
+    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
+    CHECK_REAL_EQUAL(1.5, val[0], eps);
+    CHECK_REAL_EQUAL(1.6, val[1], eps);
+    rval = mb.tag_get_data(ke_tag1, &cell_ents[0], 2, val);
+    CHECK_REAL_EQUAL(2.5, val[0], eps);
+    CHECK_REAL_EQUAL(2.6, val[1], eps);
+  }
+}
+
 ErrorCode get_options(std::string &opts) 
 {
 #ifdef USE_MPI

diff --git a/test/io/read_ucd_nc.cpp b/test/io/read_ucd_nc.cpp
index bd16ec4..12ca977 100644
--- a/test/io/read_ucd_nc.cpp
+++ b/test/io/read_ucd_nc.cpp
@@ -85,14 +85,6 @@ void test_read_onevar()
   rval = mb.load_file(example, NULL, opts.c_str());
   CHECK_ERR(rval);
 
-  // Check for proper tags
-  Tag Ttag0, Ttag1;
-  rval = mb.tag_get_handle("T0", 26, MB_TYPE_DOUBLE, Ttag0);
-  CHECK_ERR(rval);
-
-  rval = mb.tag_get_handle("T1", 26, MB_TYPE_DOUBLE, Ttag1);
-  CHECK_ERR(rval);
-
   // Check values of tag T0 at some strategically chosen places below
   int procs = 1;
 #ifdef USE_MPI
@@ -102,6 +94,13 @@ void test_read_onevar()
 
   // Make check runs this test in one processor
   if (1 == procs) {
+    // Check for proper tags
+    Tag Ttag0, Ttag1;
+    rval = mb.tag_get_handle("T0", 26, MB_TYPE_DOUBLE, Ttag0);
+    CHECK_ERR(rval);
+    rval = mb.tag_get_handle("T1", 26, MB_TYPE_DOUBLE, Ttag1);
+    CHECK_ERR(rval);
+
     // Get vertices
     Range verts;
     rval = mb.get_entities_by_type(0, MBVERTEX, verts);
@@ -131,9 +130,10 @@ void test_read_onevar()
     CHECK_ERR(rval);
     CHECK_EQUAL((size_t)count, verts.size());
 
-    // Check first level values at some vertices
     const double eps = 0.0001;
     double* data = (double*) Tbuf;
+
+    // Check first level values at some 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

diff --git a/test/parallel/mpastrvpart.cpp b/test/parallel/mpastrvpart.cpp
index 5cacd2c..2b86f61 100644
--- a/test/parallel/mpastrvpart.cpp
+++ b/test/parallel/mpastrvpart.cpp
@@ -12,9 +12,11 @@ static const char example[] = STRINGIFY(MESHDIR) "/io/mpasx1.642.t.2.nc";
 #endif
 
 void test_read_parallel_mpas_trivial();
-void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges);
-
+void test_read_parallel_mpas_trivial_no_mixed_elements();
+void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges,
+                        int num_cells, bool test_nb_cells, bool mixed_elements);
 void test_multiple_loads_of_same_file();
+void test_multiple_loads_of_same_file_no_mixed_elements();
 
 std::string partition_method;
 
@@ -24,7 +26,9 @@ int main(int argc, char* argv[])
   int result = 0;
 
   result += RUN_TEST(test_read_parallel_mpas_trivial);
+  result += RUN_TEST(test_read_parallel_mpas_trivial_no_mixed_elements);
   result += RUN_TEST(test_multiple_loads_of_same_file);
+  result += RUN_TEST(test_multiple_loads_of_same_file_no_mixed_elements);
 
   MPI_Finalize();
   return result;
@@ -33,10 +37,17 @@ int main(int argc, char* argv[])
 void test_read_parallel_mpas_trivial()
 {
   partition_method = std::string(";PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS");
-  test_read_parallel(1280, true, 1920, true);
+  test_read_parallel(1280, true, 1920, true, 642, true, true);
 }
-  
-void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges)
+
+void test_read_parallel_mpas_trivial_no_mixed_elements()
+{
+  partition_method = std::string(";PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS;NO_MIXED_ELEMENTS");
+  test_read_parallel(1280, true, 1920, true, 642, true, false);
+}
+
+void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges,
+                        int num_cells, bool test_nb_cells, bool mixed_elements)
 {
   Core moab;
   Interface& mb = moab;
@@ -82,43 +93,6 @@ void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool t
       CHECK_EQUAL(160, my_verts_num); // Not owned vertices excluded
   }
 
-  if (0 == rank) {
-    // Get gather set
-    EntityHandle gather_set;
-    ReadUtilIface* readUtilIface;
-    rval = mb.query_interface(readUtilIface);
-    CHECK_ERR(rval);
-    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 in processor 0
-    verts = subtract(verts, gather_ents);
-  }
-
-  my_verts_num = verts.size();
-  if (test_nb_nodes && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(1120, my_verts_num); // Gather set vertices excluded
-    else if (1 == rank)
-      CHECK_EQUAL(160, my_verts_num); // Not owned vertices excluded
-  }
-
-  std::cout << "proc: " << rank << " verts:" << my_verts_num << "\n";
-
-  int total_verts;
-  MPI_Reduce(&my_verts_num, &total_verts, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
-  if (0 == rank)
-  {
-    std::cout << "total vertices: " << total_verts << "\n";
-    if (test_nb_nodes)
-      CHECK_EQUAL(total_verts, num_verts);
-  }
-
   // Get the total # owned edges
   Range edges;
   rval = mb.get_entities_by_type(0, MBEDGE, edges);
@@ -143,6 +117,44 @@ void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool t
       CHECK_EQUAL(482, my_edges_num); // Not owned edges excluded
   }
 
+  // Get the total # owned cells
+  Range cells;
+  rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+  CHECK_ERR(rval);
+
+  int my_cells_num = cells.size();
+  if (test_nb_cells && 2 == procs) {
+    if (0 == rank) {
+      CHECK_EQUAL(963, my_cells_num); // Gather set cells included
+      if (mixed_elements)
+        CHECK_EQUAL((size_t)4, cells.psize()); // Gather set cells included
+      else
+        CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included
+    }
+    else if (1 == rank) {
+      CHECK_EQUAL(321, my_cells_num); // Not owned cells included
+      CHECK_EQUAL((size_t)1, cells.psize()); // Not owned cells included
+    }
+  }
+
+   rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+   CHECK_ERR(rval);
+
+   my_cells_num = cells.size();
+   if (test_nb_cells && 2 == procs) {
+     if (0 == rank) {
+       CHECK_EQUAL(963, my_cells_num); // Gather set cells included
+       if (mixed_elements)
+         CHECK_EQUAL((size_t)4, cells.psize()); // Gather set cells included
+       else
+         CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included
+     }
+     else if (1 == rank) {
+       CHECK_EQUAL(321, my_cells_num); // Not owned cells excluded
+       CHECK_EQUAL((size_t)1, cells.psize()); // Not owned cells excluded
+     }
+   }
+
   if (0 == rank) {
     // Get gather set
     EntityHandle gather_set;
@@ -157,8 +169,32 @@ void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool t
     rval = mb.get_entities_by_handle(gather_set, gather_ents);
     CHECK_ERR(rval);
 
+    // Remove gather set vertices in processor 0
+    verts = subtract(verts, gather_ents);
+
     // Remove gather set edges in processor 0
     edges = subtract(edges, gather_ents);
+
+    // Remove gather set cells in processor 0
+    cells = subtract(cells, gather_ents);
+  }
+
+  my_verts_num = verts.size();
+  if (test_nb_nodes && 2 == procs) {
+    if (0 == rank)
+      CHECK_EQUAL(1120, my_verts_num); // Gather set vertices excluded
+    else if (1 == rank)
+      CHECK_EQUAL(160, my_verts_num); // Not owned vertices excluded
+  }
+
+  std::cout << "proc: " << rank << " verts:" << my_verts_num << "\n";
+
+  int total_verts;
+  MPI_Reduce(&my_verts_num, &total_verts, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
+  if (0 == rank) {
+    std::cout << "total vertices: " << total_verts << "\n";
+    if (test_nb_nodes)
+      CHECK_EQUAL(total_verts, num_verts);
   }
 
   my_edges_num = edges.size();
@@ -173,13 +209,37 @@ void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool t
 
   int total_edges;
   MPI_Reduce(&my_edges_num, &total_edges, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
-  if (0 == rank)
-  {
+  if (0 == rank) {
     std::cout << "total edges: " << total_edges << "\n";
     if (test_nb_edges)
       CHECK_EQUAL(total_edges, num_edges);
   }
 
+  my_cells_num = cells.size();
+  if (test_nb_cells && 2 == procs) {
+    if (0 == rank) {
+      CHECK_EQUAL(321, my_cells_num); // Gather set cells excluded
+      if (mixed_elements)
+        CHECK_EQUAL((size_t)2, cells.psize()); // Gather set cells excluded
+      else
+        CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded
+    }
+    else if (1 == rank) {
+      CHECK_EQUAL(321, my_cells_num); // Not owned cells excluded
+      CHECK_EQUAL((size_t)1, cells.psize()); // Not owned cells excluded
+    }
+  }
+
+   std::cout << "proc: " << rank << " cells:" << my_cells_num << "\n";
+
+   int total_cells;
+   MPI_Reduce(&my_cells_num, &total_cells, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
+   if (0 == rank) {
+     std::cout << "total cells: " << total_cells << "\n";
+     if (test_nb_cells)
+       CHECK_EQUAL(total_cells, num_cells);
+   }
+
   std::string write_options("PARALLEL=WRITE_PART;");
   mb.write_file("test_mpas.h5m", NULL, write_options.c_str());
 }
@@ -220,13 +280,44 @@ void test_multiple_loads_of_same_file()
     rval = mb.get_entities_by_type(0, MBVERTEX, verts);
     CHECK_ERR(rval);
 
+    Range edges;
+    rval = mb.get_entities_by_type(0, MBEDGE, edges);
+    CHECK_ERR(rval);
+
+    Range cells;
+    rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+    CHECK_ERR(rval);
+
     int my_verts_num = verts.size();
-    if (0 == rank)
+    int my_edges_num = edges.size();
+    int my_cells_num = cells.size();
+
+    if (0 == rank) {
       CHECK_EQUAL(1120, my_verts_num);
-    else if (1 == rank)
+      CHECK_EQUAL(1438, my_edges_num);
+      CHECK_EQUAL(321, my_cells_num);
+      CHECK_EQUAL((size_t)2, cells.psize());
+
+      const double eps = 1e-20;
+      double val[2];
+
+      // Check tag for cell variable ke at timestep 0
+      Tag ke_tag0;
+      rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+      CHECK_ERR(rval);
+
+      // Check ke0 tag values on first pentagon and first hexagon
+      EntityHandle cell_ents[] = {cells[0], cells[12]};
+      rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
+      CHECK_REAL_EQUAL(1.5, val[0], eps);
+      CHECK_REAL_EQUAL(1.6, val[1], eps);
+    }
+    else if (1 == rank) {
       CHECK_EQUAL(2402, my_verts_num); // Gather set vertices included; Not owned vertices included
+      CHECK_EQUAL(3364, my_edges_num); // Gather set edges included; Not owned edges included
+      CHECK_EQUAL(963, my_cells_num); // Gather set cells included; Not owned cells included
+      CHECK_EQUAL((size_t)3, cells.psize()); // Gather set cells included; Not owned cells included
 
-    if (1 == rank) {
       // Get gather set
       EntityHandle gather_set;
       ReadUtilIface* readUtilIface;
@@ -242,12 +333,125 @@ void test_multiple_loads_of_same_file()
 
       // Remove gather set vertices in processor 1
       verts = subtract(verts, gather_ents);
+      my_verts_num = verts.size();
+      CHECK_EQUAL(1122, my_verts_num); // Gather set vertices excluded; Not owned vertices included
+
+      // Remove gather set edges in processor 1
+      edges = subtract(edges, gather_ents);
+      my_edges_num = edges.size();
+      CHECK_EQUAL(1444, my_edges_num); // Gather set edges excluded; Not owned edges included
+
+      // Remove gather set cells in processor 1
+      cells = subtract(cells, gather_ents);
+      my_cells_num = cells.size();
+      CHECK_EQUAL(321, my_cells_num); // Gather set cells excluded; Not owned cells included
+      CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded; Not owned cells included
     }
+  }
+}
 
-    my_verts_num = verts.size();
-    if (0 == rank)
+void test_multiple_loads_of_same_file_no_mixed_elements()
+{
+  Core moab;
+  Interface& mb = moab;
+  EntityHandle file_set;
+  ErrorCode rval;
+  rval = mb.create_meshset(MESHSET_SET, file_set);
+  CHECK_ERR(rval);
+
+  // Read first only header information, no mesh, no variable
+  std::string opts("PARALLEL=READ_PART;PARTITION;NOMESH;VARIABLE=;PARTITION_METHOD=TRIVIAL;NO_MIXED_ELEMENTS");
+  rval = mb.load_file(example, &file_set, opts.c_str());
+  CHECK_ERR(rval);
+
+  // Create mesh, no variable
+  opts="PARALLEL=READ_PART;PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION_METHOD=TRIVIAL;NO_MIXED_ELEMENTS;VARIABLE=";
+  // Create gather set in processor 1
+  opts += std::string(";GATHER_SET=1");
+  rval = mb.load_file(example, &file_set, opts.c_str());
+  CHECK_ERR(rval);
+
+  // Read variable ke at timestep 0, no mesh
+  opts = "PARALLEL=READ_PART;PARTITION;PARTITION_METHOD=TRIVIAL;NO_MIXED_ELEMENTS;NOMESH;VARIABLE=ke;TIMESTEP=0";
+  rval = mb.load_file(example, &file_set, opts.c_str());
+  CHECK_ERR(rval);
+
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
+  int procs = pcomm->proc_config().proc_size();
+  int rank = pcomm->proc_config().proc_rank();
+
+  // Make check runs this test in two processors
+  if (2 == procs) {
+    Range verts;
+    rval = mb.get_entities_by_type(0, MBVERTEX, verts);
+    CHECK_ERR(rval);
+
+    Range edges;
+    rval = mb.get_entities_by_type(0, MBEDGE, edges);
+    CHECK_ERR(rval);
+
+    Range cells;
+    rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+    CHECK_ERR(rval);
+
+    int my_verts_num = verts.size();
+    int my_edges_num = edges.size();
+    int my_cells_num = cells.size();
+
+    if (0 == rank) {
       CHECK_EQUAL(1120, my_verts_num);
-    else if (1 == rank)
+      CHECK_EQUAL(1438, my_edges_num);
+      CHECK_EQUAL(321, my_cells_num);
+      CHECK_EQUAL((size_t)1, cells.psize());
+
+      const double eps = 1e-20;
+      double val[2];
+
+      // Check tag for cell variable ke at timestep 0
+      Tag ke_tag0;
+      rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+      CHECK_ERR(rval);
+
+      // Check ke0 tag values on first pentagon and first hexagon
+      EntityHandle cell_ents[] = {cells[0], cells[12]};
+      rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
+      CHECK_REAL_EQUAL(1.5, val[0], eps);
+      CHECK_REAL_EQUAL(1.6, val[1], eps);
+    }
+    else if (1 == rank) {
+      CHECK_EQUAL(2402, my_verts_num); // Gather set vertices included; Not owned vertices included
+      CHECK_EQUAL(3364, my_edges_num); // Gather set edges included; Not owned edges included
+      CHECK_EQUAL(963, my_cells_num); // Gather set cells included; Not owned cells included
+      CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included; Not owned cells included
+
+      // Get gather set
+      EntityHandle gather_set;
+      ReadUtilIface* readUtilIface;
+      rval = mb.query_interface(readUtilIface);
+      CHECK_ERR(rval);
+      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 in processor 1
+      verts = subtract(verts, gather_ents);
+      my_verts_num = verts.size();
       CHECK_EQUAL(1122, my_verts_num); // Gather set vertices excluded; Not owned vertices included
+
+      // Remove gather set edges in processor 1
+      edges = subtract(edges, gather_ents);
+      my_edges_num = edges.size();
+      CHECK_EQUAL(1444, my_edges_num); // Gather set edges excluded; Not owned edges included
+
+      // Remove gather set cells in processor 1
+      cells = subtract(cells, gather_ents);
+      my_cells_num = cells.size();
+      CHECK_EQUAL(321, my_cells_num); // Gather set cells excluded; Not owned cells included
+      CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded; Not owned cells included
+    }
   }
 }

diff --git a/test/parallel/ucdtrvpart.cpp b/test/parallel/ucdtrvpart.cpp
index 720df36..0800b4c 100644
--- a/test/parallel/ucdtrvpart.cpp
+++ b/test/parallel/ucdtrvpart.cpp
@@ -169,10 +169,9 @@ void test_multiple_loads_of_same_file()
     int my_num = verts.size();
     if (0 == rank)
       CHECK_EQUAL(1825, my_num);
-    else if (1 == rank)
+    else if (1 == rank) {
       CHECK_EQUAL(5283, my_num); // Gather set vertices included; Not owned vertices included
 
-    if (1 == rank) {
       // Get gather set
       EntityHandle gather_set;
       ReadUtilIface* readUtilIface;
@@ -188,13 +187,9 @@ void test_multiple_loads_of_same_file()
 
       // Remove gather set vertices in processor 1
       verts = subtract(verts, gather_ents);
-    }
-
-    my_num = verts.size();
-    if (0 == rank)
-      CHECK_EQUAL(1825, my_num);
-    else if (1 == rank)
+      my_num = verts.size();
       CHECK_EQUAL(1825, my_num); // Gather set vertices excluded; Not owned vertices included
+    }
 
     Tag Ttag0;
     rval = mb.tag_get_handle("T0", 26, MB_TYPE_DOUBLE, Ttag0, MB_TAG_DENSE);

diff --git a/tools/mbzoltan/MBZoltan.cpp b/tools/mbzoltan/MBZoltan.cpp
index 1ec6757..45b8a35 100644
--- a/tools/mbzoltan/MBZoltan.cpp
+++ b/tools/mbzoltan/MBZoltan.cpp
@@ -254,7 +254,8 @@ ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
                                         const int obj_weight,
                                         const int edge_weight,
                                         const bool part_surf,
-                                        const bool ghost) 
+                                        const bool ghost,
+                                        const bool print_time)
 {
     // should only be called in serial
   if (mbpc->proc_config().proc_size() != 1) {
@@ -262,7 +263,7 @@ ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
               << std::endl;
     return MB_FAILURE;
   }
-  
+  clock_t t = clock();
   if (NULL != zmethod && strcmp(zmethod, "RR") && strcmp(zmethod, "RCB") && strcmp(zmethod, "RIB") &&
       strcmp(zmethod, "HSFC") && strcmp(zmethod, "Hypergraph") &&
       strcmp(zmethod, "PHG") && strcmp(zmethod, "PARMETIS") &&
@@ -274,6 +275,10 @@ ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
     return MB_FAILURE;
   }
 
+  bool part_geom = false;
+  if ( 0==  strcmp(zmethod, "RR") || 0== strcmp(zmethod, "RCB") || 0== strcmp(zmethod, "RIB")
+      || 0==strcmp(zmethod, "HSFC") )
+    part_geom=true; // so no adjacency / edges needed
   std::vector<double> pts; // x[0], y[0], z[0], ... from MOAB
   std::vector<int> ids; // point ids from MOAB
   std::vector<int> adjs, length, parts;
@@ -321,7 +326,7 @@ ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
   
   if (part_geom_mesh_size < 0.) {
     //if (!part_geom) {
-    result = assemble_graph(part_dim, pts, ids, adjs, length, elems); RR;
+       result = assemble_graph(part_dim, pts, ids, adjs, length, elems, part_geom); RR;
   }
   else {
 #ifdef CGM
@@ -347,20 +352,29 @@ ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
     }
 #endif
   }
-  
+  if (print_time)
+  {
+    std::cout << " time to assemble graph: " << (clock() - t) / (double) CLOCKS_PER_SEC  << "s. \n";
+    t = clock();
+  }
   double* o_wgt = NULL;
   double* e_wgt = NULL;
   if (obj_weights.size() > 0) o_wgt = &obj_weights[0];
   if (edge_weights.size() > 0) e_wgt = &edge_weights[0];
     
   myNumPts = mbInitializePoints((int)ids.size(), &pts[0], &ids[0], &adjs[0],
-                                &length[0], o_wgt, e_wgt, &parts[0]);
+                                &length[0], o_wgt, e_wgt, &parts[0], part_geom);
   
 
   // Initialize Zoltan.  This is a C call.  The simple C++ code 
   // that creates Zoltan objects does not keep track of whether 
   // Zoltan_Initialize has been called.
 
+  if (print_time)
+  {
+    std::cout << " time to initialize points: " << (clock() - t) / (double) CLOCKS_PER_SEC  << "s. \n";
+    t = clock();
+  }
   float version;
 
   std::cout << "Initializing zoltan..." << std::endl;
@@ -458,6 +472,11 @@ ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
                               assign_procs, assign_parts);
   if (ZOLTAN_OK != retval) return MB_FAILURE;
   
+  if (print_time)
+  {
+    std::cout << " time to LB_partition " << (clock() - t) / (double) CLOCKS_PER_SEC  << "s. \n";
+    t = clock();
+  }
   // take results & write onto MOAB partition sets
   std::cout << "Saving partition information to MOAB..." << std::endl;
   
@@ -473,6 +492,12 @@ ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
 #endif
   }
 
+  if (print_time)
+  {
+    std::cout << " time to write partition in memory " <<(clock() - t) / (double) CLOCKS_PER_SEC  << "s. \n";
+    t = clock();
+  }
+
   if (MB_SUCCESS != result) return result;
 
 
@@ -550,7 +575,7 @@ ErrorCode MBZoltan::assemble_graph(const int dimension,
                                    std::vector<int> &moab_ids,
                                    std::vector<int> &adjacencies, 
                                    std::vector<int> &length,
-                                   Range &elems) 
+                                   Range &elems, bool  part_geom)
 {
     // assemble a graph with vertices equal to elements of specified dimension, edges
     // signified by list of other elements to which an element is connected
@@ -580,21 +605,24 @@ ErrorCode MBZoltan::assemble_graph(const int dimension,
   
   for (Range::iterator rit = elems.begin(); rit != elems.end(); rit++) {
 
-      // get bridge adjacencies
-    adjs.clear();
-    result = mtu.get_bridge_adjacencies(*rit, (dimension > 0 ? dimension-1 : 3), 
-                                        dimension, adjs); RR;
 
-      // get the graph vertex ids of those
-    if (!adjs.empty()) {
-      assert(adjs.size() < 5*MAX_SUB_ENTITIES);
-      result = mbImpl->tag_get_data(gid, adjs, neighbors); RR;
-    }
+    if (!part_geom)
+    {
+      // get bridge adjacencies
+      adjs.clear();
+      result = mtu.get_bridge_adjacencies(*rit, (dimension > 0 ? dimension-1 : 3),
+                                          dimension, adjs); RR;
 
-      // copy those into adjacencies vector
-    length.push_back((int)adjs.size());
-    std::copy(neighbors, neighbors+adjs.size(), std::back_inserter(adjacencies));
+        // get the graph vertex ids of those
+      if (!adjs.empty()) {
+        assert(adjs.size() < 5*MAX_SUB_ENTITIES);
+        result = mbImpl->tag_get_data(gid, adjs, neighbors); RR;
+      }
 
+        // copy those into adjacencies vector
+      length.push_back((int)adjs.size());
+      std::copy(neighbors, neighbors+adjs.size(), std::back_inserter(adjacencies));
+    }
 
       // get average position of vertices
     result = mtu.get_average_position(*rit, avg_position); RR;
@@ -1305,7 +1333,7 @@ ErrorCode MBZoltan::write_partition(const int nparts,
                                     Range &elems, 
                                     const int *assignment,
                                     const bool write_as_sets,
-                                    const bool write_as_tags) 
+                                    const bool write_as_tags)
 {
   ErrorCode result;
 
@@ -1347,10 +1375,9 @@ ErrorCode MBZoltan::write_partition(const int nparts,
         result = mbImpl->delete_entities(&old_set, 1); RR;
       }
     }
-  
-      // assign partition sets to vector
+    // assign partition sets to vector
     partSets.swap(tagged_sets);
-  
+
       // write a tag to those sets denoting they're partition sets, with a value of the
       // proc number
     int *dum_ids = new int[nparts];
@@ -1358,14 +1385,26 @@ ErrorCode MBZoltan::write_partition(const int nparts,
   
     result = mbImpl->tag_set_data(part_set_tag, partSets, dum_ids); RR;
 
-      // assign entities to the relevant sets
+    // assign entities to the relevant sets
     std::vector<EntityHandle> tmp_part_sets;
+    //int N = (int)elems.size();
     std::copy(partSets.begin(), partSets.end(), std::back_inserter(tmp_part_sets));
+    /*Range::reverse_iterator riter;
+    for (i = N-1, riter = elems.rbegin(); riter != elems.rend(); riter++, i--) {
+      int assigned_part = assignment[i];
+      part_ranges[assigned_part].insert(*riter);
+      //result = mbImpl->add_entities(tmp_part_sets[assignment[i]], &(*rit), 1); RR;
+    }*/
+
     Range::iterator rit;
     for (i = 0, rit = elems.begin(); rit != elems.end(); rit++, i++) {
       result = mbImpl->add_entities(tmp_part_sets[assignment[i]], &(*rit), 1); RR;
     }
-
+    /*for (i=0; i<nparts; i++)
+    {
+      result = mbImpl->add_entities(tmp_part_sets[i], part_ranges[i]); RR;
+    }
+    delete [] part_ranges;*/
       // check for empty sets, warn if there are any
     Range empty_sets;
     for (rit = partSets.begin(); rit != partSets.end(); rit++) {
@@ -1474,17 +1513,17 @@ void MBZoltan::SetOCTPART_Parameters(const char *oct_method)
 int MBZoltan::mbInitializePoints(int npts, double *pts, int *ids, 
                                  int *adjs, int *length,
                                  double *obj_weights, double *edge_weights,
-                                 int *parts)
+                                 int *parts, bool part_geom)
 {
   unsigned int i;
   int j;
-  int *numPts, *nborProcs;
+  int *numPts, *nborProcs = NULL;
   int sum, ptsPerProc, ptsAssigned, mySize;
   MPI_Status stat;
   double *sendPts;
   int *sendIds;
-  int *sendEdges;
-  int *sendNborId;
+  int *sendEdges = NULL;
+  int *sendNborId = NULL;
   int *sendProcs;
 
   if (mbpc->proc_config().proc_rank() == 0) {
@@ -1504,19 +1543,22 @@ int MBZoltan::mbInitializePoints(int npts, double *pts, int *ids,
     mySize = numPts[mbpc->proc_config().proc_rank()];
     sendPts = pts + (3 * numPts[0]);
     sendIds = ids + numPts[0];
-    sendEdges = length + numPts[0];
-    sum = 0;
+    sum = 0; // possible no adjacency sent
+    if (!part_geom)
+    {
+      sendEdges = length + numPts[0];
 
-    for (j = 0; j < numPts[0]; j++)
-      sum += length[j];
 
-    sendNborId = adjs + sum;
+      for (j = 0; j < numPts[0]; j++)
+        sum += length[j];
 
-    for (j = numPts[0]; j < npts; j++)
-      sum += length[j];
+      sendNborId = adjs + sum;
 
-    nborProcs = (int *)malloc(sizeof(int) * sum);
+      for (j = numPts[0]; j < npts; j++)
+        sum += length[j];
 
+      nborProcs = (int *)malloc(sizeof(int) * sum);
+    }
     for (j = 0; j < sum; j++)
       if ((i = adjs[j] / ptsPerProc) < mbpc->proc_config().proc_size())
         nborProcs[j] = i;

diff --git a/tools/mbzoltan/MBZoltan.hpp b/tools/mbzoltan/MBZoltan.hpp
index 269d9ae..4a0e999 100644
--- a/tools/mbzoltan/MBZoltan.hpp
+++ b/tools/mbzoltan/MBZoltan.hpp
@@ -112,7 +112,8 @@ using namespace moab;
                                   const int obj_weight = 0,
                                   const int edge_weight = 0,
                                   const bool part_surf = false,
-                                  const bool ghost = false);
+                                  const bool ghost = false,
+                                  const bool print_time = false);
     
     int get_mesh(std::vector<double> &pts, std::vector<int> &ids,
                  std::vector<int> &adjs, std::vector<int> &length,
@@ -198,7 +199,7 @@ using namespace moab;
                              std::vector<int> &moab_ids,
                              std::vector<int> &adjacencies, 
                              std::vector<int> &length,
-                             Range &elems);
+                             Range &elems, bool part_geom = false);
     
 #ifdef CGM
     std::map<int, int> body_vertex_map, surf_vertex_map;
@@ -234,7 +235,7 @@ using namespace moab;
                            int *adjs, int *length,
                            double *obj_weights = NULL,
                            double *edge_weights = NULL,
-                           int *parts = NULL);
+                           int *parts = NULL, bool part_geom = false);
 
 #ifdef CGM
     GeometryQueryTool *gti;

This diff is so big that we needed to truncate the remainder.

https://bitbucket.org/fathomteam/moab/commits/55759362996c/
Changeset:   55759362996c
Branch:      None
User:        iulian07
Date:        2013-10-08 05:21:29
Summary:     add sperical coordinates conversion
-s will be a new option to project everything in a spherical coords
system;
important for trying a different partition on a sphere, as the problem becomes
2d

Affected #:  3 files

diff --git a/tools/mbzoltan/MBZoltan.cpp b/tools/mbzoltan/MBZoltan.cpp
index 45b8a35..e51d9d3 100644
--- a/tools/mbzoltan/MBZoltan.cpp
+++ b/tools/mbzoltan/MBZoltan.cpp
@@ -255,7 +255,8 @@ ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
                                         const int edge_weight,
                                         const bool part_surf,
                                         const bool ghost,
-                                        const bool print_time)
+                                        const bool print_time,
+                                        const bool spherical_coords)
 {
     // should only be called in serial
   if (mbpc->proc_config().proc_size() != 1) {
@@ -326,7 +327,8 @@ ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
   
   if (part_geom_mesh_size < 0.) {
     //if (!part_geom) {
-       result = assemble_graph(part_dim, pts, ids, adjs, length, elems, part_geom); RR;
+       result = assemble_graph(part_dim, pts, ids, adjs, length, elems, part_geom,
+           spherical_coords); RR;
   }
   else {
 #ifdef CGM
@@ -575,7 +577,7 @@ ErrorCode MBZoltan::assemble_graph(const int dimension,
                                    std::vector<int> &moab_ids,
                                    std::vector<int> &adjacencies, 
                                    std::vector<int> &length,
-                                   Range &elems, bool  part_geom)
+                                   Range &elems, bool  part_geom, bool spherical_coords)
 {
     // assemble a graph with vertices equal to elements of specified dimension, edges
     // signified by list of other elements to which an element is connected
@@ -632,6 +634,18 @@ ErrorCode MBZoltan::assemble_graph(const int dimension,
 
       // copy those into coords vector
     moab_ids.push_back(moab_id);
+    // transform coordinates to spherical coordinates, if requested
+    if (spherical_coords)
+    {
+      double R = avg_position[0]*avg_position[0]+avg_position[1]*avg_position[1]+avg_position[2]*avg_position[2];
+      R = sqrt(R);
+      double lat = asin(avg_position[2]/R);
+      double lon=atan2(avg_position[1], avg_position[0]);
+      avg_position[0]=lon;
+      avg_position[1]=lat;
+      avg_position[2]=R;
+    }
+
     std::copy(avg_position, avg_position+3, std::back_inserter(coords));
   }
 

diff --git a/tools/mbzoltan/MBZoltan.hpp b/tools/mbzoltan/MBZoltan.hpp
index 4a0e999..5a7bbf1 100644
--- a/tools/mbzoltan/MBZoltan.hpp
+++ b/tools/mbzoltan/MBZoltan.hpp
@@ -113,7 +113,8 @@ using namespace moab;
                                   const int edge_weight = 0,
                                   const bool part_surf = false,
                                   const bool ghost = false,
-                                  const bool print_time = false);
+                                  const bool print_time = false,
+                                  const bool spherical_coords  = false);
     
     int get_mesh(std::vector<double> &pts, std::vector<int> &ids,
                  std::vector<int> &adjs, std::vector<int> &length,
@@ -199,7 +200,7 @@ using namespace moab;
                              std::vector<int> &moab_ids,
                              std::vector<int> &adjacencies, 
                              std::vector<int> &length,
-                             Range &elems, bool part_geom = false);
+                             Range &elems, bool part_geom = false, const bool spherical_coords=false);
     
 #ifdef CGM
     std::map<int, int> body_vertex_map, surf_vertex_map;

diff --git a/tools/mbzoltan/mbpart.cpp b/tools/mbzoltan/mbpart.cpp
index 7ad6dd2..c7a6c50 100644
--- a/tools/mbzoltan/mbpart.cpp
+++ b/tools/mbzoltan/mbpart.cpp
@@ -112,6 +112,10 @@ int main(int argc, char* argv[])
   bool print_time = false;
   opts.addOpt<void>(",T", "Print CPU time for each phase.", &print_time);
 
+  bool spherical_coords = false;
+  opts.addOpt<void>("project_on_sphere,s",
+      "use spherical coordinates for partitioning ", &spherical_coords);
+
   opts.parseCommandLine(argc, argv);
 
   MBZoltan *tool = NULL;
@@ -263,7 +267,7 @@ int main(int argc, char* argv[])
         zoltan_method.c_str(),
         (!parm_method.empty() ? parm_method.c_str() : oct_method.c_str()),
         imbal_tol, !no_write_sets, write_tags, part_dim, obj_weight,
-        edge_weight, part_surf, ghost, print_time);
+        edge_weight, part_surf, ghost, print_time, spherical_coords);
     if (MB_SUCCESS != rval)
     {
       std::cerr << "Partitioner failed!" << std::endl;


https://bitbucket.org/fathomteam/moab/commits/ee72201cabf9/
Changeset:   ee72201cabf9
Branch:      None
User:        iulian07
Date:        2013-10-08 05:44:45
Summary:     small utils in mbcslam
one to test loading a partition
test loading an MPAS file without edges
collect a few polygons from a file
modify proj1 to extract and delete edges from a partitioned file

Affected #:  5 files

diff --git a/tools/mbcslam/Makefile.am b/tools/mbcslam/Makefile.am
index 440384c..4f09b1f 100644
--- a/tools/mbcslam/Makefile.am
+++ b/tools/mbcslam/Makefile.am
@@ -40,7 +40,7 @@ cfgdir = $(libdir)
 
 TESTS = intx_on_sphere_test  intx_in_plane_test  spec_visu_test spherical_area_test \
          case1_test  intx_mpas
-noinst_PROGRAMS =  cslam_par_test diffusion proj1
+noinst_PROGRAMS =  cslam_par_test diffusion proj1 smallPoly mpas_mesh load_partial
 
 check_PROGRAMS = $(TESTS) 
 intx_on_sphere_test_SOURCES = intx_on_sphere_test.cpp
@@ -52,6 +52,9 @@ case1_test_SOURCES = case1_test.cpp
 intx_mpas_SOURCES = intx_mpas.cpp
 cslam_par_test_SOURCES = cslam_par_test.cpp
 proj1_SOURCES = proj1.cpp
+smallPoly_SOURCES = smallPoly.cpp
+mpas_mesh_SOURCES = mpas_mesh.cpp
+load_partial_SOURCES = load_partial.cpp
 
 EXTRA_DIST  = lagrangeHomme.vtk  \
               eulerHomme.vtk \

diff --git a/tools/mbcslam/load_partial.cpp b/tools/mbcslam/load_partial.cpp
new file mode 100644
index 0000000..cf65a0a
--- /dev/null
+++ b/tools/mbcslam/load_partial.cpp
@@ -0,0 +1,50 @@
+/** @example LoadPartial.cpp
+ * This example demonstrates how to load partially an h5m file
+ * Sets in MOAB contain entities and have a tag on them to give meaning to the entities.
+ * Tag name: PARALLEL_PARTITION_TAG_NAME "PARALLEL_PARTITION" is used for
+ *   parallel partitions
+ *
+ * <b>Steps in this example </b>:
+ *    -# Instantiate MOAB
+ *    -# Get input mesh file name, already partitioned in 16 parts
+ *    -# Load some parts; save
+ *    -# Destroy the MOAB instance
+ *
+ *
+ * <b> To compile: </b>
+ *    make LoadPartial MOAB_DIR=<installdir> \n
+ *
+ * <b> To run: </b>
+ *    -# LoadPartial <mesh-file><int> \n
+ *    -# LoadPartial (This uses the default <mesh-file>: <MOAB_SRC_DIR>/MeshFiles/unittest/mbtest2.g)
+ */
+#include <iostream>
+#include <string>
+
+// Include header for MOAB instance and range
+#include "moab/Core.hpp"
+#include "MBTagConventions.hpp"
+
+int main(int argc, char **argv) {
+
+  // instantiate & load a file
+  moab::Interface *mb = new moab::Core();
+
+  moab::ErrorCode rval;
+
+  std::string file_name = "mpas_p16.h5m";
+  int one = 1;
+
+  if (argc>1)
+    one = atoi(argv[1]);
+  if (argc>2)
+    file_name = argv[2];
+  rval = mb->load_file(file_name.c_str(),
+                       0, "DEBUG_IO=9;", PARALLEL_PARTITION_TAG_NAME, &one, 1);
+
+  if (moab::MB_SUCCESS!=rval)
+    std::cout << " failed to read\n";
+
+  rval = mb->write_file("part.h5m");
+  delete mb;
+}

diff --git a/tools/mbcslam/mpas_mesh.cpp b/tools/mbcslam/mpas_mesh.cpp
new file mode 100644
index 0000000..2e4026a
--- /dev/null
+++ b/tools/mbcslam/mpas_mesh.cpp
@@ -0,0 +1,500 @@
+/*
+ * mpas_mesh.cpp
+ *
+ *  Created on: Sep 29
+ */
+
+// simple mpas reader that should work in serial; read only the nodes and polygons
+//
+//
+#include <iostream>
+#include <sstream>
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "moab/Core.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "MBTagConventions.hpp"
+#include "CslamUtils.hpp"
+
+#include "mpi.h"
+#include "pnetcdf.h"
+
+#define NCFUNC(func) ncmpi_ ## func
+
+//! Collective I/O mode get
+#define NCFUNCAG(func) ncmpi_get ## func ## _all
+
+//! Independent I/O mode get
+#define NCFUNCG(func) ncmpi_get ## func
+
+//! Nonblocking get (request aggregation), used so far only for ucd mesh
+#define NCFUNCREQG(func) ncmpi_iget ## func
+
+#define NCDF_SIZE MPI_Offset
+#define NCDF_DIFF MPI_Offset
+
+
+#include <algorithm>
+#include <string>
+#include <assert.h>
+
+#include <cmath>
+
+
+using namespace moab;
+
+#define INS_ID(stringvar, prefix, id) \
+          sprintf(stringvar, prefix, id)
+
+#define GET_DIM(ncdim, name, val)\
+    {                            \
+    int gdfail = NCFUNC(inq_dimid)(ncFile, name, &ncdim);          \
+    if (NC_NOERR == gdfail) {                                             \
+      MPI_Offset tmp_val;                                                   \
+      gdfail = NCFUNC(inq_dimlen)(ncFile, ncdim, &tmp_val);                        \
+      if (NC_NOERR != gdfail) {                                           \
+        std::cout<<"couldn't get dimension length for" << name<< " \n"; \
+        return 1;                                              \
+      }                                                                 \
+      else val = tmp_val;                                               \
+    } else val = 0;}
+
+#define GET_DIMB(ncdim, name, varname, id, val) \
+          INS_ID(name, varname, id); \
+          GET_DIM(ncdim, name, val);
+
+#define GET_VAR(name, id, dims) \
+    {                           \
+    id = -1;\
+    int gvfail = NCFUNC(inq_varid)( ncFile, name, &id);   \
+    if (NC_NOERR == gvfail) {       \
+    int ndims;\
+    gvfail = NCFUNC(inq_varndims)( ncFile, id, &ndims);\
+    if (NC_NOERR == gvfail) {\
+    dims.resize(ndims);    \
+    gvfail = NCFUNC(inq_vardimid)( ncFile, id, &dims[0]);}}}
+
+#define GET_1D_INT_VAR(name, id, vals) \
+    {GET_VAR(name, id, vals);  \
+  if (-1 != id) {\
+    NCDF_SIZE ntmp;\
+    int ivfail = NCFUNC(inq_dimlen)(ncFile, vals[0], &ntmp);\
+    vals.resize(ntmp);\
+    NCDF_SIZE ntmp1 = 0;                                                           \
+    ivfail = NCFUNC(get_vara_int_all)(ncFile, id, &ntmp1, &ntmp, &vals[0]);\
+    if (NC_NOERR != ivfail) {\
+      std::cout<<"ReadNCDF:: Problem getting variable " <<name <<"\n";\
+      return 1;}}}
+
+#define GET_1D_DBL_VAR(name, id, vals) \
+    {std::vector<int> dum_dims;        \
+  GET_VAR(name, id, dum_dims);\
+  if (-1 != id) {\
+    std::cout << " var:" << name << " id: " << id << "\n"; \
+    NCDF_SIZE ntmp;\
+    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
+    vals.resize(ntmp);\
+    NCDF_SIZE ntmp1 = 0;               \
+    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &ntmp, &vals[0]);\
+    if (NC_NOERR != dvfail) {\
+      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
+      return 1;}}}
+
+#define FILL_1D_DBL_VAR(name, id, vals) \
+    {std::vector<int> dum_dims;        \
+  GET_VAR(name, id, dum_dims);\
+  if (-1 != id) {\
+    MPI_Offset ntmp;\
+    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
+    std::cout <<" var:" << name << " ntmp:" << ntmp << "\n"; \
+    MPI_Offset ntmp1 = 0;                                                           \
+    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &ntmp, vals);\
+    if (NC_NOERR != dvfail) {\
+      std::cout<<"FILL_1D_DBL_VAR:: Problem getting variable "<< name<<"\n";\
+      return 1;}}}
+
+/*
+int get_2d_flt_var(int ncFile, const char * name, int index, std::vector<float> & vals)
+{
+  int id;
+  std::vector<int> dum_dims;
+  GET_VAR(name, id, dum_dims);
+  if (-1 != id) {
+    size_t ntmp;
+  int dvfail = nc_inq_dimlen(ncFile, dum_dims[1], &ntmp);
+  vals.resize(ntmp);
+  size_t ntmp1[2] = {index, 0};
+
+  int ntimes;
+  dvfail = nc_inq_dimlen(ncFile, dum_dims[0], &ntimes);
+  if (index>=ntimes) {
+    std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";
+    return 1;
+  }
+  size_t count[2] ={1, ntmp};
+  dvfail = nc_get_vara_float(ncFile, id, ntmp1, count, &vals[0]);
+  if (NC_NOERR != dvfail) {
+    std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";
+    return 1;
+  }
+  return 0;
+}
+*/
+/* get the variable along an index */
+#define GET_2D_FLT_VAR(name, id, index, vals) \
+    {std::vector<int> dum_dims;        \
+  GET_VAR(name, id, dum_dims);\
+  if (-1 != id) {\
+    MPI_Offset ntmp, ntmp2;\
+    int dvfail = NCFUNC(inq_dimlen)( ncFile, dum_dims[1], &ntmp);\
+    dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp2);\
+    vals.resize(ntmp);\
+    MPI_Offset ntmp1[2] = {index, 0}; \
+    if (index>=ntmp2) { \
+      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n"; \
+      return 1; \
+    } \
+    MPI_Offset count[2] ={1, ntmp}; \
+    dvfail = NCFUNC(get_vara_float)( ncFile, id, ntmp1, count, &vals[0]);\
+    if (NC_NOERR != dvfail) {\
+      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
+      return 1;}}}
+
+int main(int argc, char ** argv)
+{
+
+  MPI_Init(&argc, &argv);
+  int num_el = 50000;
+  const char *data_file = "/home/iulian/source/myMoabRepo/MeshFiles/unittest/io/mpasx1.642.t.2.nc";
+  if (argc>1)
+  {
+    data_file = argv[1];
+  }
+  std::cout << "num_el=" << num_el << "\n";
+
+  Core moab;
+  Interface & mb = moab;
+  ErrorCode rval;
+
+  int ncFile, temp_dim;        // netcdf/exodus file
+
+  int fail = NCFUNC(open)(MPI_COMM_WORLD, data_file, 0, MPI_INFO_NULL, &ncFile);
+  if (NC_NOWRITE != fail) {
+    std::cout<<"ReadNCDF:: problem opening Netcdf/Exodus II "<<data_file <<"\n";
+    return 1;
+  }
+  int maxEdges;
+  GET_DIM(temp_dim, "maxEdges", maxEdges);
+  std::cout << "maxEdges:" << maxEdges << "\n";
+
+  int nVertices;
+  GET_DIM(temp_dim, "nVertices", nVertices);
+    std::cout << "nVertices:" << nVertices << "\n";
+
+  int nCells;
+  GET_DIM(temp_dim, "nCells", nCells);
+  std::cout << "nCells:" << nCells << "\n";
+
+  // see if the mesh from metadata makes sense
+  // create polygons with the connectivity from conn array
+
+  ReadUtilIface* readMeshIface;
+  mb.query_interface( readMeshIface );
+  if (NULL==readMeshIface)
+    return 1;
+  EntityHandle node_handle = 0;
+  std::vector<double*> arrays;
+  rval = readMeshIface->get_node_coords(3, nVertices,
+      1, node_handle, arrays);
+  if (MB_SUCCESS!= rval)
+    return 1;
+
+  std::vector<double> cor;
+
+  FILL_1D_DBL_VAR("xVertex", temp_dim, &(arrays[0][0]));
+  FILL_1D_DBL_VAR("yVertex", temp_dim, &(arrays[1][0]));
+  FILL_1D_DBL_VAR("zVertex", temp_dim, &(arrays[2][0]));
+
+  Range nodes(node_handle, node_handle+nVertices-1);
+  std::vector<int> gids(nVertices);
+  for (int j=0; j<nVertices; j++)
+    gids[j]=j+1;
+  Tag gid;
+  int dum_val = 0;
+  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid, MB_TAG_DENSE | MB_TAG_CREAT, &dum_val);
+  if (MB_SUCCESS != rval)
+    return 1;
+
+  rval = mb.tag_set_data(gid, nodes, &gids[0]);
+  if (MB_SUCCESS!= rval)
+       return 1;
+
+  EntityHandle newSet;
+  rval = mb.create_meshset(MESHSET_SET, newSet);
+  if (MB_SUCCESS != rval)
+    return 1;
+
+  // so the nodes will be part
+  mb.add_entities(newSet, nodes);
+
+
+  std::vector<int>  nEdgesOnCell;
+  GET_1D_INT_VAR("nEdgesOnCell", temp_dim, nEdgesOnCell);
+
+  std::cout << " size of : nEdgesOnCell: " << nEdgesOnCell.size() << "\n";
+  std::vector<int> numCellsWithNEdges(maxEdges, 0);
+  int actualMaxEdges = 0;
+  for (int j=0; j<nCells; j++)
+  {
+    int nEdgesThisCell = nEdgesOnCell[j];
+    numCellsWithNEdges[nEdgesThisCell-1]++;
+    if (actualMaxEdges<nEdgesThisCell)
+      actualMaxEdges = nEdgesThisCell;
+  }
+  std::vector<EntityHandle> starthp(maxEdges, 0);
+  std::vector<int> indexCellsWithNEdges(actualMaxEdges, 0);
+  std::vector<EntityHandle*> conn_arr_local_cells_with_n_edges(actualMaxEdges);
+
+  for (int j=2; j<maxEdges; j++)
+  {
+    std::cout << "cells with " << j+1 << " edges:" << numCellsWithNEdges[j] << "\n";
+    if (numCellsWithNEdges[j]>0)
+    {
+      readMeshIface->get_element_connect(numCellsWithNEdges[j], j+1, MBPOLYGON, 0,
+          starthp[j], conn_arr_local_cells_with_n_edges[j]);
+    }
+  }
+
+  std::cout << " actualMaxEdges: " << actualMaxEdges << "\n";
+
+
+  std::vector<int> vertices_on_cells(nCells * actualMaxEdges);
+  NCDF_SIZE starts[2]={0, 0};
+  NCDF_SIZE counts[2]={nCells, actualMaxEdges};
+  std::vector<int> dum_dims;
+  int verticesOnCellVarId;
+  GET_VAR("verticesOnCell", verticesOnCellVarId, dum_dims);
+
+  int nf = NCFUNCAG(_vara_int)(ncFile, verticesOnCellVarId, starts, counts, &vertices_on_cells[0]);
+  if (nf!=0)
+    return 1;
+
+  for (int j = 1; j <= nCells; j++) {
+    int nEdgesThisCell = nEdgesOnCell[j-1]; //
+    int indxFill=indexCellsWithNEdges[nEdgesThisCell-1]*nEdgesThisCell;
+    for (int k =0; k<nEdgesThisCell; k++)
+    {
+      conn_arr_local_cells_with_n_edges[nEdgesThisCell-1][indxFill+k]=
+          (EntityHandle)vertices_on_cells[(j-1)*actualMaxEdges+k];
+    }
+
+    indexCellsWithNEdges[nEdgesThisCell-1]++;
+    EntityHandle polygon=starthp[nEdgesThisCell-1]+indexCellsWithNEdges[nEdgesThisCell-1];
+    mb.tag_set_data(gid, &polygon, 1, &j);
+  }
+
+  /*// create element tags with lat and lon, for centers
+  Tag latTag=0;
+  rval = mb.tag_get_handle("latCell", 1, MB_TYPE_DOUBLE, latTag, MB_TAG_DENSE | MB_TAG_CREAT);
+  if (MB_SUCCESS != rval)
+    return 1;
+  Tag lonTag=0;
+  rval = mb.tag_get_handle("lonCell", 1, MB_TYPE_DOUBLE, lonTag, MB_TAG_DENSE | MB_TAG_CREAT);
+  if (MB_SUCCESS != rval)
+    return 1;
+  // do a deep copy or not?? for now it is OK :(
+  std::vector<double> lonc;
+  GET_1D_DBL_VAR("latCell", temp_dim, lonc);
+  std::vector<double> latc;
+  GET_1D_DBL_VAR("lonCell", temp_dim, latc);*/
+
+  // now, we know that vertices are the same as handles, just set them dry :)
+
+
+/*  // build a kd tree with the vertices
+  EntityHandle tree_root;
+  AdaptiveKDTree kd(&mb, true);
+  rval = kd.build_tree(nodes, tree_root);
+  if (MB_SUCCESS != rval)
+    return 1;
+
+  unsigned int  min_depth, max_depth;
+  rval = kd.depth(tree_root, min_depth, max_depth);
+  if (MB_SUCCESS != rval)
+     return 1;
+  std::cout << "min_depth, max_depth " << min_depth << " " << max_depth << "\n";
+  // now, read the conn file created using spectral visu, and see how they fit
+  // this can be directly imported to moab
+  const char *myconn_file = "spec.R2.vtk";
+  EntityHandle euler_set;
+  rval = mb.create_meshset(MESHSET_SET, euler_set);
+  if (MB_SUCCESS != rval)
+    return 1;
+
+  rval = mb.load_file(myconn_file, &euler_set);
+
+  if (MB_SUCCESS != rval)
+    return 1;
+
+  mb.list_entities(&euler_set, 1);
+
+  Range specQuads;
+  rval = mb.get_entities_by_dimension(euler_set, 2, specQuads );
+  if (MB_SUCCESS != rval)
+     return 1;
+
+  Range vertices;
+  rval = mb.get_connectivity(specQuads, vertices);
+  if (MB_SUCCESS != rval)
+     return 1;
+
+  // do a mapping, from position of vertices to the vertices in the kd tree.
+  // find the closest vertex to each of this
+  std::vector<EntityHandle> mappedTo(vertices.size());
+  std::vector<double> mycoords(vertices.size()*3);
+  rval = mb.get_coords(vertices, &mycoords[0]);
+  double * ptr = &mycoords[0];
+  size_t num_verts=vertices.size();
+  for (size_t i=0; i<num_verts; i++, ptr+=3)
+  {
+    CartVect pos(ptr); // take 3 coordinates
+    std::vector<EntityHandle> leaves;
+    rval = kd.leaves_within_distance( tree_root,
+                                          ptr,
+                                          0.001,
+                                        leaves);
+    if (MB_SUCCESS != rval)
+      return 1;
+    Range closeVerts;
+    for (std::vector<EntityHandle>::iterator vit = leaves.begin(); vit != leaves.end(); vit++)
+    {
+      rval= mb.get_entities_by_handle(*vit, closeVerts, Interface::UNION);
+      if (moab::MB_SUCCESS != rval)
+        return 1;
+    }
+    if (closeVerts.size()<1)
+    {
+      std::cout << "increase tolerance, no points close to " << pos << "\n";
+      return 1;
+    }
+    std::vector<CartVect> coordsTarget(closeVerts.size());
+    rval = mb.get_coords(closeVerts, &(coordsTarget[0][0]));
+    if (MB_SUCCESS != rval)
+      return 1;
+    double minDist2=(pos-coordsTarget[0]).length_squared();
+    EntityHandle closestVertex=closeVerts[0];
+    for (unsigned int j=1; j<closeVerts.size(); j++)
+    {
+      double dist2=(pos-coordsTarget[j]).length_squared();
+      if (minDist2>dist2)
+      {
+        closestVertex = closeVerts[j];
+        minDist2=dist2;
+      }
+    }
+    if (minDist2 > 0.00001)
+    {
+      std::cout << " problem with node " << vertices[i] << "  min dist2:" << minDist2 << "\n";
+      return 1;
+    }
+    mappedTo [i] = closestVertex;
+  }
+
+  num_el = (int)specQuads.size();
+  // tmp_ptr is of type int* and points at the same place as conn
+  EntityHandle * conn = 0;
+
+  EntityHandle elh;
+
+  readMeshIface->get_element_connect(
+          num_el,
+          4,
+          MBQUAD,
+          1,
+          elh,
+          conn);
+
+  EntityHandle firstVertMyMesh=vertices[0];
+  for (int k=0; k<num_el; k++)
+  {
+    const EntityHandle * myconn=0;
+    EntityHandle specElem = specQuads[k];
+    int num_nodes=0;
+    rval = mb.get_connectivity(specElem, myconn, num_nodes);
+    if (MB_SUCCESS != rval || num_nodes !=4)
+      return 1;
+
+    int start_el = k*4;
+    for (int j=0; j<4; j++)
+       conn[start_el+j] = mappedTo[myconn[j]-firstVertMyMesh];
+  }
+  std::cout << " conn:" << conn[0] << " " << conn[1] << " " << conn[3]<< "\n";
+  Range erange(elh, elh+num_el-1);
+
+  mb.add_entities(newSet, erange);
+  std::vector<int> gidels(num_el);
+  Tag gid2;
+  rval = mb.tag_get_handle("GLOBAL_ID_EL", 1, MB_TYPE_INTEGER,
+        gid2, MB_TAG_SPARSE|MB_TAG_CREAT);
+
+  if (MB_SUCCESS != rval)
+      return 1;
+  for (int k=0; k<num_el; k++)
+    gidels[k]=k+1;
+  mb.tag_set_data(gid2, erange, &gidels[0]);
+
+  int times;
+  GET_DIM(temp_dim, "time", times);
+  Tag velotag;
+  rval = mb.tag_get_handle("VELO", 3, MB_TYPE_DOUBLE,
+            velotag, MB_TAG_DENSE|MB_TAG_CREAT);
+  if (MB_SUCCESS!= rval)
+    return 1;*/
+
+ /* for (size_t tt=0; tt<56 (size_t)times; tt++)
+  {
+    // now, read velocities from file:
+    // read the U850 and V850 variables
+    std::vector<float> u850;
+    GET_2D_FLT_VAR("U850", temp_dim, tt, u850);
+    std::vector<float> v850;
+    GET_2D_FLT_VAR("V850", temp_dim, tt, v850);
+
+    std::cout << " U850:" << u850[0] << " " << u850[1] << " " << u850[5] << " "<< u850.size()<<"\n";
+    std::cout << " V850:" << v850[0] << " " << v850[1] << " " << v850[5] << " "<< u850.size()<<"\n";
+    // ok, use radius as 6371km; not needed
+
+    std::vector<CartVect> velo850(ncol);
+
+    std::stringstream fileName;
+    fileName << "VELO0" <<  tt << ".h5m";
+    std::cout << " read velocities at 850 for time:" << tt << "\n";
+
+
+    for (int k=0; k<ncol; k++)
+    {
+      double latRad=lat[k]*conversion_factor;
+      double lonRad=lon[k]*conversion_factor;
+      CartVect U(-sin(lonRad), cos(lonRad), 0.);
+      CartVect V(-sin(latRad)*cos(lonRad), -sin(latRad)*cos(lonRad), cos(latRad));
+      velo850[k]=U*u850[k] +V*v850[k];
+    }
+    rval = mb.tag_set_data(velotag, nodes, &(velo850[0][0]));
+    if (MB_SUCCESS!= rval)
+      return 1;
+    rval = mb.write_mesh(fileName.str().c_str(), &newSet, 1);
+    if (MB_SUCCESS!= rval)
+      return 1;
+  }*/
+
+  rval = mb.write_mesh("out.h5m");
+  if (rval!=MB_SUCCESS)
+    std::cout << " can't write file\n";
+  std::cout << " wrote out.h5m\n";
+  MPI_Finalize();
+
+  return 0;
+}

diff --git a/tools/mbcslam/proj1.cpp b/tools/mbcslam/proj1.cpp
index b4ef89c..7326b68 100644
--- a/tools/mbcslam/proj1.cpp
+++ b/tools/mbcslam/proj1.cpp
@@ -1,7 +1,8 @@
 /*
  * proj1.cpp
  *
- *  project on a sphere of radius R
+ *  project on a sphere of radius R, delete sets if needed, and delete edges between parts
+ *  (created by resolve shared ents)
  */
 
 #include "moab/Core.hpp"
@@ -18,8 +19,7 @@ double radius = 1.;// in m:  6371220.
 int main(int argc, char **argv)
 {
 
-  std::string extra_read_opts;
-  // read a file and project on a sphere
+  bool delete_partition_sets = false;
 
   if (argc < 3)
     return 1;
@@ -29,11 +29,20 @@ int main(int argc, char **argv)
   char * output = argv[2];
   while (index < argc)
   {
-    if (!strcmp(argv[index], "-R")) // this is for geometry tolerance
+    if (!strcmp(argv[index], "-R")) // this is for radius to project
     {
       radius = atof(argv[++index]);
     }
+    if (!strcmp(argv[index], "-DS")) // delete partition sets
+    {
+      delete_partition_sets = true;
+    }
 
+    if (!strcmp(argv[index], "-h"))
+    {
+      std::cout << " usage: proj1 <input><output> -R <value>  -DS (delete partition sets)\n";
+      return 1;
+    }
     index++;
   }
 
@@ -73,27 +82,39 @@ int main(int argc, char **argv)
   rval = mb.get_entities_by_dimension(0, 1, edges);
   if (MB_SUCCESS != rval)
     return 1;
-  rval = mb.delete_entities(edges);
-
-  // delete the parallel partition sets, if exisiting
+  // write edges to a new set, and after that, write the set, delete the edges and the set
+  EntityHandle sf1;
+  rval = mb.create_meshset(MESHSET_SET, sf1);
+  if (MB_SUCCESS != rval)
+    return 1;
+  rval = mb.add_entities(sf1, edges);
+  if (MB_SUCCESS != rval)
+    return 1;
+  rval = mb.write_mesh("edgesOnly.h5m", &sf1, 1);
+  if (MB_SUCCESS != rval)
+    return 1;
+  rval = mb.delete_entities(&sf1, 1);
+  if (MB_SUCCESS != rval)
+    return 1;
+  mb.delete_entities(edges);
+  mb.write_file(output);
 
-  Tag par_tag;
-  rval = mb.tag_get_handle("PARALLEL_PARTITION", par_tag);
-  if (MB_SUCCESS == rval)
+  if (delete_partition_sets)
   {
-    Range par_sets;
-    rval =  mb.get_entities_by_type_and_tag(0, MBENTITYSET, &par_tag, NULL, 1, par_sets,
-       moab::Interface::UNION);
-    if (!par_sets.empty())
+    Tag par_tag;
+    rval = mb.tag_get_handle("PARALLEL_PARTITION", par_tag);
+    if (MB_SUCCESS == rval)
+
+    {
+      Range par_sets;
+      rval =  mb.get_entities_by_type_and_tag(0, MBENTITYSET, &par_tag, NULL, 1, par_sets,
+         moab::Interface::UNION);
+      if (!par_sets.empty())
         mb.delete_entities(par_sets);
-    mb.tag_delete(par_tag);
+      mb.tag_delete(par_tag);
+    }
   }
 
 
-  mb.write_file(output);
-
-  // remove all edges
-
-
   return 0;
 }

diff --git a/tools/mbcslam/smallPoly.cpp b/tools/mbcslam/smallPoly.cpp
new file mode 100644
index 0000000..b5b2c5a
--- /dev/null
+++ b/tools/mbcslam/smallPoly.cpp
@@ -0,0 +1,53 @@
+/*
+ * smallPoly.cpp
+ *
+ */
+
+#include <iostream>
+#include <sstream>
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "moab/Core.hpp"
+#include "moab/Interface.hpp"
+#include "TestUtil.hpp"
+
+using namespace moab;
+
+int main(int argc, char **argv)
+{
+
+  // read an MPAS file, extract few polys and write them out
+  std::string fileN="mpas_p8.h5m";
+  const char *filename_mesh1 = fileN.c_str();
+  Core moab;
+  Interface & mb = moab;
+  EntityHandle euler_set;
+  ErrorCode rval;
+  rval = mb.create_meshset(MESHSET_SET, euler_set);
+  CHECK_ERR(rval);
+
+  rval = mb.load_file(filename_mesh1);
+  CHECK_ERR(rval);
+
+  // get one / two vertices , and polys adjacent to them;
+  Range verts;
+  rval = mb.get_entities_by_type(0, MBVERTEX, verts);
+  CHECK_ERR(rval);
+
+  EntityHandle v[3]={verts[0], verts[1], verts[2]};
+  Range  elems;
+  rval= mb.get_adjacencies(v, 3, 2, false, elems, Interface::UNION);
+  CHECK_ERR(rval);
+
+  rval = mb.add_entities(euler_set, elems);
+  CHECK_ERR(rval);
+
+  rval = mb.write_mesh("fewPolys.h5m", &euler_set, 1);
+  CHECK_ERR(rval);
+    return 0;
+
+}
+
+


https://bitbucket.org/fathomteam/moab/commits/d34ac070c607/
Changeset:   d34ac070c607
Branch:      None
User:        iulian07
Date:        2013-10-08 05:47:10
Summary:     prefer local entities in coupler
if some target vertices are located in multiple elements, prefer those that are
local on the processor, to avoid communication

Affected #:  1 file

diff --git a/tools/mbcoupler/Coupler.cpp b/tools/mbcoupler/Coupler.cpp
index 28f67ca..8d968c5 100644
--- a/tools/mbcoupler/Coupler.cpp
+++ b/tools/mbcoupler/Coupler.cpp
@@ -416,11 +416,17 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
   unsigned int local_pts = 0;
   for (unsigned int i = 0; i < source_pts.get_n(); i++) {
     if (-1 != source_pts.vi_rd[3*i+2]) { //why bother sending message saying "i don't have the point" if it gets discarded?
-      //if (source_pts.vi_rd[3*i] == (int)my_rank) local_pts++;
       int tgt_index = 3*source_pts.vi_rd[3*i+1];
-      tl_tmp->vi_wr[tgt_index]   = source_pts.vi_rd[3*i];
-      tl_tmp->vi_wr[tgt_index+1] = source_pts.vi_rd[3*i+1];
-      tl_tmp->vi_wr[tgt_index+2] = source_pts.vi_rd[3*i+2];
+      // prefer always entities that are local, from the source_pts
+      // if a local entity was already found to contain the target point, skip
+      // tl_tmp->vi_wr[tgt_index] is -1 initially, but it could already be set with
+      // a remote processor
+      if (tl_tmp->vi_wr[tgt_index] != (int)my_rank)
+      {
+        tl_tmp->vi_wr[tgt_index]   = source_pts.vi_rd[3*i];
+        tl_tmp->vi_wr[tgt_index+1] = source_pts.vi_rd[3*i+1];
+        tl_tmp->vi_wr[tgt_index+2] = source_pts.vi_rd[3*i+2];
+      }
     }
   }
 


https://bitbucket.org/fathomteam/moab/commits/82a23230eb22/
Changeset:   82a23230eb22
Branch:      None
User:        iulian07
Date:        2013-10-08 16:58:04
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  2 files

diff --git a/tools/mbcslam/Intx2Mesh.cpp b/tools/mbcslam/Intx2Mesh.cpp
index 6faa94a..d9db131 100644
--- a/tools/mbcslam/Intx2Mesh.cpp
+++ b/tools/mbcslam/Intx2Mesh.cpp
@@ -381,8 +381,12 @@ ErrorCode Intx2Mesh::intersect_meshes(EntityHandle mbset1, EntityHandle mbset2,
   }
   // before cleaning up , we need to settle the position of the intersection points
   // on the boundary edges
+  // this needs to be collective, so we should maybe wait something
   rval = correct_intersection_points_positions();
-  ERRORR(rval, "can't correct position");
+  if (rval!=MB_SUCCESS)
+  {
+    std::cout << "can't correct position, Intx2Mesh.cpp \n";
+  }
   clean();
   return MB_SUCCESS;
 }
@@ -480,7 +484,6 @@ ErrorCode Intx2Mesh::initialize_local_kdtree(EntityHandle euler_set)
               << dep << std::endl;
   #endif
 
-    return result;
   return MB_SUCCESS;
 }
 // this will work in parallel only
@@ -1365,11 +1368,14 @@ void Intx2Mesh::correct_polygon(EntityHandle * nodes, int & nP)
     if (nodes[i]==nodes[nextIndex])
     {
       // we need to reduce nP, and collapse nodes
-      std::cout<<" nodes duplicated in list: " ;
-      for (int j=0; j<nP; j++)
-        std::cout<<nodes[j] << " " ;
-      std::cout<<"\n";
-      std::cout<<" node " << nodes[i] << " at index " << i << " is duplicated" << "\n";
+      if (dbg_1)
+      {
+        std::cout<<" nodes duplicated in list: " ;
+        for (int j=0; j<nP; j++)
+          std::cout<<nodes[j] << " " ;
+        std::cout<<"\n";
+        std::cout<<" node " << nodes[i] << " at index " << i << " is duplicated" << "\n";
+      }
       // this will work even if we start from 1 2 3 1; when i is 3, we find nextIndex is 0, then next thing does nothing
       //  (nP-1 is 3, so k is already >= nP-1); it will result in nodes -> 1, 2, 3
       for (int k=i; k<nP-1; k++)

diff --git a/tools/mbcslam/intx_mpas.cpp b/tools/mbcslam/intx_mpas.cpp
index ab50ce9..6888cb3 100644
--- a/tools/mbcslam/intx_mpas.cpp
+++ b/tools/mbcslam/intx_mpas.cpp
@@ -42,6 +42,7 @@ double gtol = 1.e-9; // this is for geometry tolerance
 double radius = 1.;// in m:  6371220.
 
 double t = 0.1, delta_t = 0.05; // check the script
+bool Verbose = false;
 
 ErrorCode manufacture_lagrange_mesh_on_sphere(Interface * mb,
     EntityHandle euler_set)
@@ -153,6 +154,11 @@ int main(int argc, char **argv)
         flux_form= true;
         index++;
       }
+      if (!strcmp(argv[index], "-v"))
+      {
+        Verbose = true;
+        index++;
+      }
 
       index++;
     }
@@ -207,17 +213,22 @@ int main(int argc, char **argv)
   rval = worker.create_departure_mesh_2nd_alg(euler_set, covering_lagr_set);
   CHECK_ERR(rval);
 
-  std::stringstream lagrIni;
-  lagrIni<<"def0" << rank<<".h5m";
-  rval = mb.write_file(lagrIni.str().c_str(), 0, 0, &covering_lagr_set, 1);
+  if (Verbose)
+  {
+    std::stringstream lagrIni;
+    lagrIni<<"def0" << rank<<".h5m";
+    rval = mb.write_file(lagrIni.str().c_str(), 0, 0, &covering_lagr_set, 1);
+  }
 
   rval = enforce_convexity(&mb, covering_lagr_set, rank);
   if (MB_SUCCESS != rval)
     return 1;
-
-  std::stringstream ste;
-  ste<<"lagr0" << rank<<".h5m";
-  rval = mb.write_file(ste.str().c_str(), 0, 0, &euler_set, 1);
+  if (Verbose)
+  {
+    std::stringstream ste;
+    ste<<"lagr0" << rank<<".h5m";
+    rval = mb.write_file(ste.str().c_str(), 0, 0, &euler_set, 1);
+  }
 
   if (MB_SUCCESS != rval)
     std::cout << "can't write lagr set\n";
@@ -230,12 +241,15 @@ int main(int argc, char **argv)
   if (MB_SUCCESS != rval)
     return 1;
 
-  std::string opts_write("");
-  std::stringstream outf;
-  outf << "intersect0" << rank << ".h5m";
-  rval = mb.write_file(outf.str().c_str(), 0, 0, &outputSet, 1);
-  if (MB_SUCCESS != rval)
-    std::cout << "can't write output\n";
+  if (rank<=4)
+  {
+    std::string opts_write("");
+    std::stringstream outf;
+    outf << "intersect0" << rank << ".h5m";
+    rval = mb.write_file(outf.str().c_str(), 0, 0, &outputSet, 1);
+    if (MB_SUCCESS != rval)
+      std::cout << "can't write output\n";
+  }
   double intx_area = area_on_sphere_lHuiller(&mb, outputSet, radius);
   double arrival_area = area_on_sphere_lHuiller(&mb, euler_set, radius);
   std::cout << " Arrival area: " << arrival_area


https://bitbucket.org/fathomteam/moab/commits/23e9e9237bcd/
Changeset:   23e9e9237bcd
Branch:      None
User:        iulian07
Date:        2013-10-12 04:47:20
Summary:     add the mpas partitioner in mbcslam
prototype for partitioning the huge mpas file
it is depending on mbzoltan and using also tuple transfer to
inform each processor what are the Global ids of elements in partition

Affected #:  5 files

diff --git a/tools/Makefile.am b/tools/Makefile.am
index e8ad0db..a7131ac 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -133,8 +133,8 @@ noinst_PROGRAMS = $(parread)
 SUBDIRS = . \
           $(refiner_DIR) \
           $(mbcoupler_DIR) \
-          $(mbcslam_DIR) \
           $(mbzoltan_DIR) \
+          $(mbcslam_DIR) \
 	  $(mcnpmit_DIR) \
           $(qvdual_DIR) \
 	  $(vtkMOABReader_DIR) \

diff --git a/tools/mbcslam/MPASpartitioner.cpp b/tools/mbcslam/MPASpartitioner.cpp
new file mode 100644
index 0000000..ccf80a5
--- /dev/null
+++ b/tools/mbcslam/MPASpartitioner.cpp
@@ -0,0 +1,326 @@
+/*
+ * MPASpartitioner.cpp
+ *  simple mpas reader that should work in parallel to partition the element space
+ *  will link against zoltan
+ *  Created on: Oct 8
+ */
+
+
+//
+//
+#include <iostream>
+#include <sstream>
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "MBZoltan.hpp"
+#include "moab/Core.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "MBTagConventions.hpp"
+#include "CslamUtils.hpp"
+#include "moab/ParallelComm.hpp"
+
+#include "mpi.h"
+#include "pnetcdf.h"
+
+#define NCFUNC(func) ncmpi_ ## func
+
+//! Collective I/O mode get
+#define NCFUNCAG(func) ncmpi_get ## func ## _all
+
+//! Independent I/O mode get
+#define NCFUNCG(func) ncmpi_get ## func
+
+//! Nonblocking get (request aggregation), used so far only for ucd mesh
+#define NCFUNCREQG(func) ncmpi_iget ## func
+
+#define NCDF_SIZE MPI_Offset
+#define NCDF_DIFF MPI_Offset
+
+
+#include <algorithm>
+#include <string>
+#include <assert.h>
+
+#include <cmath>
+
+
+using namespace moab;
+
+int ierr, rank=0;
+
+// Error routines for use with MOAB API
+#define CHKERR(CODE, MSG)                                 \
+  do {                                                    \
+    if (MB_SUCCESS != (CODE)) {                           \
+      std::string errstr;  mbi->get_last_error(errstr);   \
+      std::cerr << errstr << std::endl;                   \
+      std::cerr << MSG << std::endl;                      \
+      MPI_Finalize();                                     \
+    }                                                     \
+  } while(false)
+
+// Error routines for use with MPI API
+#define MPICHKERR(CODE, MSG)                              \
+  do {                                                    \
+    if (0 != CODE) {                                      \
+      std::cerr << MSG << std::endl;                      \
+      MPI_Finalize();                                     \
+    }                                                     \
+  } while(false)
+
+#define dbgprint(MSG)                                \
+  do {                                              \
+      if (!rank) std::cerr << MSG << std::endl;     \
+  } while(false)
+
+#define dbgprintall(MSG)                                      \
+  do {                                                        \
+      std::cerr << "[" << rank << "]: " << MSG << std::endl;  \
+  } while(false)
+
+
+#define INS_ID(stringvar, prefix, id) \
+          sprintf(stringvar, prefix, id)
+
+#define GET_DIM(ncdim, name, val)\
+    {                            \
+    int gdfail = NCFUNC(inq_dimid)(ncFile, name, &ncdim);          \
+    if (NC_NOERR == gdfail) {                                             \
+      MPI_Offset tmp_val;                                                   \
+      gdfail = NCFUNC(inq_dimlen)(ncFile, ncdim, &tmp_val);                        \
+      if (NC_NOERR != gdfail) {                                           \
+        std::cout<<"couldn't get dimension length for" << name<< " \n"; \
+        return 1;                                              \
+      }                                                                 \
+      else val = tmp_val;                                               \
+    } else val = 0;}
+
+#define GET_DIMB(ncdim, name, varname, id, val) \
+          INS_ID(name, varname, id); \
+          GET_DIM(ncdim, name, val);
+
+#define GET_VAR(name, id, dims) \
+    {                           \
+    id = -1;\
+    int gvfail = NCFUNC(inq_varid)( ncFile, name, &id);   \
+    if (NC_NOERR == gvfail) {       \
+    int ndims;\
+    gvfail = NCFUNC(inq_varndims)( ncFile, id, &ndims);\
+    if (NC_NOERR == gvfail) {\
+    dims.resize(ndims);    \
+    gvfail = NCFUNC(inq_vardimid)( ncFile, id, &dims[0]);}}}
+
+#define GET_1D_INT_VAR(name, id, vals) \
+    {GET_VAR(name, id, vals);  \
+  if (-1 != id) {\
+    NCDF_SIZE ntmp;\
+    int ivfail = NCFUNC(inq_dimlen)(ncFile, vals[0], &ntmp);\
+    vals.resize(ntmp);\
+    NCDF_SIZE ntmp1 = 0;                                                           \
+    ivfail = NCFUNC(get_vara_int_all)(ncFile, id, &ntmp1, &ntmp, &vals[0]);\
+    if (NC_NOERR != ivfail) {\
+      std::cout<<"ReadNCDF:: Problem getting variable " <<name <<"\n";\
+      return 1;}}}
+
+#define GET_1D_DBL_VAR(name, id, vals) \
+    {std::vector<int> dum_dims;        \
+  GET_VAR(name, id, dum_dims);\
+  if (-1 != id) {\
+    std::cout << " var:" << name << " id: " << id << "\n"; \
+    NCDF_SIZE ntmp;\
+    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
+    vals.resize(ntmp);\
+    NCDF_SIZE ntmp1 = 0;               \
+    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &ntmp, &vals[0]);\
+    if (NC_NOERR != dvfail) {\
+      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
+      return 1;}}}
+
+#define GET_1D_DBL_VAR_RANGE(name, id, startIndex, endIndex, vals) \
+    {std::vector<int> dum_dims;        \
+  GET_VAR(name, id, dum_dims);\
+  if (-1 != id) {\
+    if (rank==0) std::cout << " var:" << name << " id: " << id << "\n"; \
+    NCDF_SIZE ntmp;\
+    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
+    if (rank==0) std::cout << " prepare read var " << name << " start:" << startIndex << " end:"<< endIndex <<" Actual size:" << \
+       ntmp << "\n" ; \
+    if (startIndex > (int)ntmp || endIndex > (int) ntmp || startIndex>=endIndex) \
+      { std::cout << "bad input \n"; return 1;} \
+    vals.resize(endIndex-startIndex);\
+    NCDF_SIZE ntmp1 = startIndex;    NCDF_SIZE count = endIndex-startIndex;           \
+    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &count, &vals[0]);\
+    if (NC_NOERR != dvfail) {\
+      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
+      return 1;}}}
+
+#define FILL_1D_DBL_VAR(name, id, vals) \
+    {std::vector<int> dum_dims;        \
+  GET_VAR(name, id, dum_dims);\
+  if (-1 != id) {\
+    MPI_Offset ntmp;\
+    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
+    std::cout <<" var:" << name << " ntmp:" << ntmp << "\n"; \
+    MPI_Offset ntmp1 = 0;                                                           \
+    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &ntmp, vals);\
+    if (NC_NOERR != dvfail) {\
+      std::cout<<"FILL_1D_DBL_VAR:: Problem getting variable "<< name<<"\n";\
+      return 1;}}}
+
+/*
+int get_2d_flt_var(int ncFile, const char * name, int index, std::vector<float> & vals)
+{
+  int id;
+  std::vector<int> dum_dims;
+  GET_VAR(name, id, dum_dims);
+  if (-1 != id) {
+    size_t ntmp;
+  int dvfail = nc_inq_dimlen(ncFile, dum_dims[1], &ntmp);
+  vals.resize(ntmp);
+  size_t ntmp1[2] = {index, 0};
+
+  int ntimes;
+  dvfail = nc_inq_dimlen(ncFile, dum_dims[0], &ntimes);
+  if (index>=ntimes) {
+    std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";
+    return 1;
+  }
+  size_t count[2] ={1, ntmp};
+  dvfail = nc_get_vara_float(ncFile, id, ntmp1, count, &vals[0]);
+  if (NC_NOERR != dvfail) {
+    std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";
+    return 1;
+  }
+  return 0;
+}
+*/
+/* get the variable along an index */
+#define GET_2D_FLT_VAR(name, id, index, vals) \
+    {std::vector<int> dum_dims;        \
+  GET_VAR(name, id, dum_dims);\
+  if (-1 != id) {\
+    MPI_Offset ntmp, ntmp2;\
+    int dvfail = NCFUNC(inq_dimlen)( ncFile, dum_dims[1], &ntmp);\
+    dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp2);\
+    vals.resize(ntmp);\
+    MPI_Offset ntmp1[2] = {index, 0}; \
+    if (index>=ntmp2) { \
+      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n"; \
+      return 1; \
+    } \
+    MPI_Offset count[2] ={1, ntmp}; \
+    dvfail = NCFUNC(get_vara_float)( ncFile, id, ntmp1, count, &vals[0]);\
+    if (NC_NOERR != dvfail) {\
+      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
+      return 1;}}}
+
+int main(int argc, char ** argv)
+{
+
+  MPI_Comm comm = MPI_COMM_WORLD;
+  ierr = MPI_Init(&argc, &argv);
+  MPICHKERR(ierr, "MPI Init  failed");
+  ierr = MPI_Comm_rank(comm, &rank);
+  MPICHKERR(ierr, "rank failed");
+
+
+  const char *data_file = "/home/iulian/source/myMoabRepo/MeshFiles/unittest/io/mpasx1.642.t.2.nc";
+  if (argc>1)
+  {
+    data_file = argv[1];
+  }
+
+  if (0==rank)
+    std::cout<<" processing file: " << data_file << "\n";
+  Interface * mb = new Core;
+  ErrorCode rval;
+
+  ParallelComm* pcomm = new ParallelComm(mb, MPI_COMM_WORLD);
+  int nprocs = pcomm->proc_config().proc_size();
+
+  MBZoltan * mbZTool = new MBZoltan(mb, false, argc, argv);
+
+  int ncFile, temp_dim;        // netcdf/exodus file
+
+  int fail = NCFUNC(open)(comm, data_file, 0, MPI_INFO_NULL, &ncFile);
+  if (NC_NOWRITE != fail) {
+    std::cout<<"ReadNCDF:: problem opening Netcdf/Exodus II "<<data_file <<"\n";
+    return 1;
+  }
+  int maxEdges;
+  GET_DIM(temp_dim, "maxEdges", maxEdges);
+
+  int nVertices;
+  GET_DIM(temp_dim, "nVertices", nVertices);
+
+  int nCells;
+  GET_DIM(temp_dim, "nCells", nCells);
+
+  if (rank==0)
+  {
+    std::cout << "maxEdges:" << maxEdges << "\n";
+    std::cout << "nVertices:" << nVertices << "\n";
+    std::cout << "nCells:" << nCells << "\n";
+  }
+  // see if the mesh from metadata makes sense
+  // create polygons with the connectivity from conn array
+
+  // find out how many element centers do we have to read per processor
+  int numLocalCells = nCells/nprocs;
+
+  int leftOver= nCells%nprocs;
+  if (rank<leftOver)
+    numLocalCells++;
+  // start index
+  int startCellIndex = rank*numLocalCells;
+  if (rank>=leftOver)
+    startCellIndex+=leftOver;
+  int endCellIndex = startCellIndex + numLocalCells; // exclusive
+  // so now, every processor will read xCell, yCell, zCell for cells with indices:
+  // [startCellIndex, endCellIndex)
+  // their global ids will be [startCellIndex+1, endCellIndex+1) // global id starts at 1 :)
+  // read 3 coordinates for x, y, z, separately
+
+  std::vector<double> x, y, z;
+  GET_1D_DBL_VAR_RANGE("xCell", temp_dim, startCellIndex, endCellIndex, x) ;
+  GET_1D_DBL_VAR_RANGE("yCell", temp_dim, startCellIndex, endCellIndex, y) ;
+  GET_1D_DBL_VAR_RANGE("zCell", temp_dim, startCellIndex, endCellIndex, z) ;
+
+  Range localGIDs;
+  rval = mbZTool->repartition(x, y, z, startCellIndex+1, "RCB", localGIDs );
+  if (rval !=MB_SUCCESS)
+    std::cout <<" error in partitioning\n";
+
+  // gather all psizes on root for printing
+  int lsize[2]={ (int)localGIDs.psize(), (int)localGIDs.size()};
+  /*ierr = MPI_Gather(
+    void *sendbuf,
+    int sendcnt,
+    MPI_Datatype sendtype,
+    void *recvbuf,
+    int recvcnt,
+    MPI_Datatype recvtype,
+    int root,
+    MPI_Comm comm
+  );*/
+  int * sizes=0;
+  if (rank==0)
+    sizes = new int [2* nprocs];
+  ierr = MPI_Gather( lsize, 2, MPI_INT, sizes, 2, MPI_INT, 0, comm);
+
+  if (rank==0)
+  {
+    for (int i=0; i<nprocs; i++)
+      std::cout << " on rank:" << i <<"  psize:" << sizes[2*i] << " size: " << sizes[2*i+1] << "\n";
+    delete [] sizes;
+    std::cout<<" localGIDs on rank 0\n";
+    localGIDs.print(0);
+  }
+  // form tuples (toProc, GlobalId)
+  MPI_Finalize();
+
+  return 0;
+}

diff --git a/tools/mbcslam/Makefile.am b/tools/mbcslam/Makefile.am
index 4f09b1f..5309a83 100644
--- a/tools/mbcslam/Makefile.am
+++ b/tools/mbcslam/Makefile.am
@@ -15,7 +15,9 @@ AM_CPPFLAGS += -DSRCDIR=$(srcdir) \
                -I$(top_srcdir)/itaps/imesh \
                -I$(top_builddir)/itaps \
                -I$(top_builddir)/itaps/imesh \
-               -I$(top_srcdir)/test
+               -I$(top_srcdir)/test \
+               -I$(top_srcdir)/tools/mbzoltan \
+               -I$(top_builddir)/tools/mbzoltan
 
 lib_LTLIBRARIES = libmbcslam.la
 libmbcslam_la_LIBADD = $(top_builddir)/src/libMOAB.la $(top_builddir)/itaps/imesh/libiMesh.la \
@@ -23,6 +25,16 @@ libmbcslam_la_LIBADD = $(top_builddir)/src/libMOAB.la $(top_builddir)/itaps/imes
          
 LDADD = $(top_builddir)/src/libMOAB.la libmbcslam.la $(top_builddir)/tools/mbcoupler/libmbcoupler.la
 
+if ENABLE_mbzoltan
+  libmbcslam_la_LIBADD+=$(top_builddir)/tools/mbzoltan/libmbzoltan.la
+  LDADD+=$(top_builddir)/tools/mbzoltan/libmbzoltan.la
+  AM_CPPFLAGS += $(ZOLTAN_INC_FLAGS) 
+endif
+
+if HAVE_CGM
+  AM_CPPFLAGS += @CGM_CPPFLAGS@ -DCGM @MOAB_CGM_DEFINES@
+endif
+  
 libmbcslam_la_SOURCES = \
    Intx2Mesh.cpp Intx2Mesh.hpp Intx2MeshOnSphere.cpp Intx2MeshOnSphere.hpp \
      CslamUtils.cpp CslamUtils.hpp Intx2MeshInPlane.cpp Intx2MeshInPlane.hpp 
@@ -42,6 +54,11 @@ TESTS = intx_on_sphere_test  intx_in_plane_test  spec_visu_test spherical_area_t
          case1_test  intx_mpas
 noinst_PROGRAMS =  cslam_par_test diffusion proj1 smallPoly mpas_mesh load_partial
 
+if ENABLE_mbzoltan
+noinst_PROGRAMS+=MPASpartitioner
+MPASpartitioner_SOURCES = MPASpartitioner.cpp
+endif 
+
 check_PROGRAMS = $(TESTS) 
 intx_on_sphere_test_SOURCES = intx_on_sphere_test.cpp
 diffusion_SOURCES = diffusion.cpp

diff --git a/tools/mbzoltan/MBZoltan.cpp b/tools/mbzoltan/MBZoltan.cpp
index e51d9d3..fc1e387 100644
--- a/tools/mbzoltan/MBZoltan.cpp
+++ b/tools/mbzoltan/MBZoltan.cpp
@@ -243,6 +243,130 @@ ErrorCode MBZoltan::balance_mesh(const char *zmethod,
   return MB_SUCCESS;
 }
 
+ErrorCode  MBZoltan::repartition(std::vector<double> & x,std::vector<double>&y, std::vector<double> &z, int StartID,
+    const char * zmethod, Range & localGIDs)
+{
+  //
+  std::vector<int> sendToProcs;
+  int nprocs=mbpc->proc_config().proc_size();
+  int rank = mbpc->proc_config().proc_rank();
+  clock_t t = clock();
+  // form pts and ids, as in assemble_graph
+  std::vector<double> pts; // x[0], y[0], z[0], ... from MOAB
+  pts.resize(x.size()*3);
+  std::vector<int> ids; // point ids from MOAB
+  ids.resize(x.size());
+  for (size_t i=0; i<x.size(); i++)
+  {
+    pts[3*i]=  x[i];
+    pts[3*i+1]=y[i];
+    pts[3*i+2]=z[i];
+    ids[i]=StartID+(int)i;
+  }
+  // do not get out until done!
+
+  Points= &pts[0];
+  GlobalIds=&ids[0];
+  NumPoints=(int)x.size();
+  NumEdges=NULL;
+  NborGlobalId=NULL;
+  NborProcs=NULL;
+  ObjWeights=NULL;
+  EdgeWeights=NULL;
+  Parts=NULL;
+
+  float version;
+  if (rank==0)
+    std::cout << "Initializing zoltan..." << std::endl;
+
+  Zoltan_Initialize(argcArg, argvArg, &version);
+
+  // Create Zoltan object.  This calls Zoltan_Create.
+  if (NULL == myZZ) myZZ = new Zoltan(MPI_COMM_WORLD);
+
+  if (NULL == zmethod || !strcmp(zmethod, "RCB"))
+    SetRCB_Parameters();
+  else if (!strcmp(zmethod, "RIB"))
+    SetRIB_Parameters();
+  else if (!strcmp(zmethod, "HSFC"))
+    SetHSFC_Parameters();
+
+  // set # requested partitions
+  char buff[10];
+  sprintf(buff, "%d", nprocs);
+  int retval = myZZ->Set_Param("NUM_GLOBAL_PARTITIONS", buff);
+  if (ZOLTAN_OK != retval) return MB_FAILURE;
+
+    // request only partition assignments
+  retval = myZZ->Set_Param("RETURN_LISTS", "PARTITION ASSIGNMENTS");
+  if (ZOLTAN_OK != retval) return MB_FAILURE;
+
+
+  myZZ->Set_Num_Obj_Fn(mbGetNumberOfAssignedObjects, NULL);
+  myZZ->Set_Obj_List_Fn(mbGetObjectList, NULL);
+  myZZ->Set_Num_Geom_Fn(mbGetObjectSize, NULL);
+  myZZ->Set_Geom_Multi_Fn(mbGetObject, NULL);
+  myZZ->Set_Num_Edges_Multi_Fn(mbGetNumberOfEdges, NULL);
+  myZZ->Set_Edge_List_Multi_Fn(mbGetEdgeList, NULL);
+
+  // Perform the load balancing partitioning
+
+  int changes;
+  int numGidEntries;
+  int numLidEntries;
+  int dumnum1;
+  ZOLTAN_ID_PTR dum_local, dum_global;
+  int *dum1, *dum2;
+  int num_assign;
+  ZOLTAN_ID_PTR assign_gid, assign_lid;
+  int *assign_procs, *assign_parts;
+
+  if (rank ==0)
+    std::cout << "Computing partition using " << (zmethod ? zmethod : "RCB") <<
+      " method for " << nprocs << " processors..." << std::endl;
+
+  retval = myZZ->LB_Partition(changes, numGidEntries, numLidEntries,
+                              dumnum1, dum_global, dum_local, dum1, dum2,
+                              num_assign, assign_gid, assign_lid,
+                              assign_procs, assign_parts);
+  if (ZOLTAN_OK != retval) return MB_FAILURE;
+
+  if (rank==0)
+  {
+    std::cout << " time to LB_partition " << (clock() - t) / (double) CLOCKS_PER_SEC  << "s. \n";
+    t = clock();
+  }
+
+  // free some memory?
+  delete myZZ;
+  for (size_t i=0; i<x.size(); i++)
+    sendToProcs.push_back(assign_procs[i]);
+  // free memory used by Zoltan
+  // form tuples for Gids!
+  TupleList gidProcs;
+
+    // allocate a TupleList of that size
+  gidProcs.initialize(1, 1, 0, 0, x.size()*2);// to account for some imbalances
+  gidProcs.enableWriteAccess();
+  for (size_t i = 0;i <sendToProcs.size(); i++)
+  {
+    gidProcs.vi_wr[i]=sendToProcs[i];
+    gidProcs.vl_wr[i]=StartID+i;
+    gidProcs.inc_n();
+  }
+
+  // now do a transfer
+  (mbpc->proc_config().crystal_router())->gs_transfer(1, gidProcs, 0);
+
+  // after this, every gidProc should contain the gids sent from other processes
+
+  int receivedGIDs=gidProcs.get_n();
+  for (int j=0;j<receivedGIDs; j++)
+    localGIDs.insert(gidProcs.vl_wr[j]);
+
+  return MB_SUCCESS;
+}
+
 ErrorCode MBZoltan::partition_mesh_geom(const double part_geom_mesh_size,
                                         const int nparts,
                                         const char *zmethod,

diff --git a/tools/mbzoltan/MBZoltan.hpp b/tools/mbzoltan/MBZoltan.hpp
index 5a7bbf1..2acce87 100644
--- a/tools/mbzoltan/MBZoltan.hpp
+++ b/tools/mbzoltan/MBZoltan.hpp
@@ -127,6 +127,10 @@ using namespace moab;
                               const bool write_as_sets,
                               const bool write_as_tags);
 
+    // given x, y, z and a starting id, return where to send to each (x[i],y[i],z[i]) point
+    ErrorCode repartition(std::vector<double> & x,std::vector<double>&y, std::vector<double> &z, int StartID,
+        const char * zmethod, Range & localGIDs);
+
 #ifdef CGM
     ErrorCode write_partition(const int nparts,
                               DLIList<RefEntity*> entities,


https://bitbucket.org/fathomteam/moab/commits/966bc87677be/
Changeset:   966bc87677be
Branch:      None
User:        iulian07
Date:        2013-10-12 04:53:28
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  6 files

diff --git a/doc/MetaData/metadata.h b/doc/MetaData/metadata.h
index d67ca27..9bca8a6 100644
--- a/doc/MetaData/metadata.h
+++ b/doc/MetaData/metadata.h
@@ -208,6 +208,12 @@ to the variable name. Multiple time step values can be specified, separated from
 
 Create a gather set (associated with tag GATHER_SET) on one processor with the specified rank, to duplicate entities on other processors. If the rank is not specified, it will be rank 0 by default. If an invalid rank is passed, no gather set will be created. Gather set is specially used by HOMME, MPAS, and any other unstructured grid.
 
+<H3>no_mixed_elements </H3>
+
+Indicates that no mixed elements (e.g. pentagons and hexagons) should be created by the MPAS reader. If this option is used, a common parameter maxEdgesPerCell will be computed to be used across all
+processors (instead of the one reported in the MPAS file header, which is usually 10), and each cell is created with maxEdgesPerCell edges. Any cell that has less actual edges will be padded by duplicating
+the last vertex in the connectivity array. As a result, all created cells will be in one contiguous chunk.
+
 \ref md-contents "Top"
 
   \section meta-references References

diff --git a/doc/metadata_info.doc b/doc/metadata_info.doc
index 6e3eb34..a143f91 100644
Binary files a/doc/metadata_info.doc and b/doc/metadata_info.doc differ

diff --git a/doc/metadata_info.pdf b/doc/metadata_info.pdf
index 376aa51..d86a470 100644
Binary files a/doc/metadata_info.pdf and b/doc/metadata_info.pdf differ

diff --git a/src/AEntityFactory.cpp b/src/AEntityFactory.cpp
index 577162e..08ddb00 100644
--- a/src/AEntityFactory.cpp
+++ b/src/AEntityFactory.cpp
@@ -820,6 +820,9 @@ ErrorCode AEntityFactory::get_down_adjacency_elements_poly(EntityHandle source_e
       Range vrange, adj_edges;
       vrange.insert(vertex_array[i]);
       vrange.insert(vertex_array[i+1]);
+      // account for padded polygons; if the vertices are the same, skip
+      if (vrange.size() == 1)
+        continue;
       tmp_result = thisMB->get_adjacencies(vrange, 1, false, adj_edges);
       if (MB_SUCCESS != tmp_result) result = tmp_result;
       if (adj_edges.size() == 1) {

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index 42eeca0..45ce16e 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -14,11 +14,11 @@
 
 namespace moab {
 
-const int MAX_EDGES_PER_CELL = 10;
+const int DEFAULT_MAX_EDGES_PER_CELL = 10;
 
 NCHelperMPAS::NCHelperMPAS(ReadNC* readNC, int fileId, const FileOptions& opts, EntityHandle fileSet)
 : UcdNCHelper(readNC, fileId, opts, fileSet)
-, maxEdgesPerCell(MAX_EDGES_PER_CELL)
+, maxEdgesPerCell(DEFAULT_MAX_EDGES_PER_CELL)
 , numCellGroups(0)
 {
 }
@@ -44,12 +44,12 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   unsigned int idx;
   std::vector<std::string>::iterator vit;
 
-  // Get max edges per cell
+  // Get max edges per cell reported in the MPAS file header
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "maxEdges")) != dimNames.end()) {
     idx = vit - dimNames.begin();
     maxEdgesPerCell = dimLens[idx];
-    if (maxEdgesPerCell > MAX_EDGES_PER_CELL) {
-      ERRORR(MB_FAILURE, "maxEdgesPerCell read from MPAS file has exceeded the limit");
+    if (maxEdgesPerCell > DEFAULT_MAX_EDGES_PER_CELL) {
+      ERRORR(MB_FAILURE, "maxEdgesPerCell read from the MPAS file header has exceeded DEFAULT_MAX_EDGES_PER_CELL.");
     }
   }
 
@@ -311,6 +311,20 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   success = NCFUNCAG(_vara_int)(_fileId, nEdgesOnCellVarId, tmp_starts_1, tmp_counts_1, &num_edges_on_local_cells[0]);
   ERRORS(success, "Failed to read variable values of nEdgesOnCell.");
 
+  // Get local maxEdgesPerCell on this proc
+  maxEdgesPerCell = *(std::max_element(num_edges_on_local_cells.begin(), num_edges_on_local_cells.end()));
+
+  // In parallel, do a MPI_Allreduce to get a common global maxEdgesPerCell used across all procs
+#ifdef USE_MPI
+  if (procs > 1) {
+    int global_max_edges_per_cell;
+    ParallelComm*& myPcomm = _readNC->myPcomm;
+    MPI_Allreduce(&maxEdgesPerCell, &global_max_edges_per_cell, 1, MPI_INTEGER, MPI_MAX, myPcomm->proc_config().proc_comm());
+    assert(maxEdgesPerCell <= global_max_edges_per_cell);
+    maxEdgesPerCell = global_max_edges_per_cell;
+  }
+#endif
+
   // Read vertices on each local cell (connectivity)
   int verticesOnCellVarId;
   success = NCFUNC(inq_varid)(_fileId, "verticesOnCell", &verticesOnCellVarId);
@@ -451,14 +465,16 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
       }
 
       // Padding: fill connectivity array with last vertex handle
-      EntityHandle last_vert_id = conn_arr_local_cells[cell_idx * maxEdgesPerCell + num_edges - 1];
-      for (int i = num_edges; i < maxEdgesPerCell; i++)
-        conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] = last_vert_id;
+      if (num_edges < maxEdgesPerCell) {
+        EntityHandle last_vert_id = conn_arr_local_cells[cell_idx * maxEdgesPerCell + num_edges - 1];
+        for (int i = num_edges; i < maxEdgesPerCell; i++)
+          conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] = last_vert_id;
+      }
     }
   } // if (noMixedElements)
   else {
     // Divide local cells into groups based on the number of edges
-    std::vector<int> local_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
+    std::vector<int> local_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
     for (int i = 0; i < nLocalCells; i++) {
       int num_edges = num_edges_on_local_cells[i];
       local_cells_with_n_edges[num_edges].push_back(start_cell_idx + i); // Global cell index
@@ -472,7 +488,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     numCellGroups = num_edges_on_cell_groups.size();
 
     // For each non-empty cell group, create cells and set connectivity array with proper local vertices handles
-    EntityHandle* conn_arr_local_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
+    EntityHandle* conn_arr_local_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
     for (int i = 0; i < numCellGroups; i++) {
       int num_edges_per_cell = num_edges_on_cell_groups[i];
       int num_cells = local_cells_with_n_edges[num_edges_per_cell].size();
@@ -630,14 +646,14 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     }
     else {
       // Divide gather cells into groups based on the number of edges
-      std::vector<int> gather_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
+      std::vector<int> gather_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
       for (int i = 0; i < nCells; i++) {
         int num_edges = num_edges_on_gather_cells[i];
         gather_cells_with_n_edges[num_edges].push_back(i + 1); // 0 based -> 1 based
       }
 
       // Create gather cells
-      EntityHandle* conn_arr_gather_cells_with_n_edges[MAX_EDGES_PER_CELL + 1];
+      EntityHandle* conn_arr_gather_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
       for (int num_edges_per_cell = 3; num_edges_per_cell <= maxEdgesPerCell; num_edges_per_cell++) {
         int num_cells = gather_cells_with_n_edges[num_edges_per_cell].size();
         if (num_cells > 0) {

diff --git a/src/io/mhdf/example/validate.c b/src/io/mhdf/example/validate.c
index 3ed7e78..4bd3ad8 100644
--- a/src/io/mhdf/example/validate.c
+++ b/src/io/mhdf/example/validate.c
@@ -816,12 +816,13 @@ static int merge_ranges( long* ranges, int nranges )
   qsort( ranges, nranges, 2*sizeof(long), &lcomp );
   n = 1;
   for (i = 1; i < nranges; ++i) {
-    if (ranges[2*n-2] + ranges[2*n-1+1] == ranges[2*i]) {
-      ranges[2*n-1] += ranges[2*i+1];
+    if (ranges[2*n-2] + ranges[2*n-1] == ranges[2*i]) {
+      ranges[2*n-1] += ranges[2*i+1]; /*compact the range*/
     }
     else {
-      ranges[2*n  ] = ranges[i];
-      ranges[2*n+1] = ranges[i+1];
+      /* do not compact, just copy, and increase number of ranges*/
+      ranges[2*n  ] = ranges[2*i];
+      ranges[2*n+1] = ranges[2*i+1];
       ++n;
     }
   }


https://bitbucket.org/fathomteam/moab/commits/34b0d2b4dc68/
Changeset:   34b0d2b4dc68
Branch:      None
User:        iulian07
Date:        2013-10-17 19:17:33
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  2 files

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index 45ce16e..09fe541 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -101,33 +101,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   levDim = idx;
   nLevels = dimLens[idx];
 
-  // Store xVertex values in xVertVals
   std::map<std::string, ReadNC::VarData>::iterator vmit;
-  if ((vmit = varInfo.find("xVertex")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
-    rval = read_coordinate("xVertex", 0, nVertices - 1, xVertVals);
-    ERRORR(rval, "Trouble reading 'xVertex' variable.");
-  }
-  else {
-    ERRORR(MB_FAILURE, "Couldn't find 'xVertex' variable.");
-  }
-
-  // Store yVertex values in yVertVals
-  if ((vmit = varInfo.find("yVertex")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
-    rval = read_coordinate("yVertex", 0, nVertices - 1, yVertVals);
-    ERRORR(rval, "Trouble reading 'yVertex' variable.");
-  }
-  else {
-    ERRORR(MB_FAILURE, "Couldn't find 'yVertex' variable.");
-  }
-
-  // Store zVertex values in zVertVals
-  if ((vmit = varInfo.find("zVertex")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
-    rval = read_coordinate("zVertex", 0, nVertices - 1, zVertVals);
-    ERRORR(rval, "Trouble reading 'zVertex' variable.");
-  }
-  else {
-    ERRORR(MB_FAILURE, "Couldn't find 'zVertex' variable.");
-  }
 
   // Store time coordinate values in tVals
   if (nTimeSteps > 0) {
@@ -142,16 +116,6 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
     }
   }
 
-  // Read vertices on each edge
-  int verticesOnEdgeVarId;
-  int success = NCFUNC(inq_varid)(_fileId, "verticesOnEdge", &verticesOnEdgeVarId);
-  ERRORS(success, "Failed to get variable id of verticesOnEdge.");
-  NCDF_SIZE tmp_starts[2] = {0, 0};
-  NCDF_SIZE tmp_counts[2] = {static_cast<NCDF_SIZE>(nEdges), 2};
-  verticesOnEdge.resize(nEdges * 2);
-  success = NCFUNCAG(_vara_int)(_fileId, verticesOnEdgeVarId, tmp_starts, tmp_counts, &verticesOnEdge[0]);
-  ERRORS(success, "Failed to read variable values of verticesOnEdge.");
-
   // Determine the entity location type of a variable
   for (vmit = varInfo.begin(); vmit != varInfo.end(); ++vmit) {
     ReadNC::VarData& vd = (*vmit).second;
@@ -289,78 +253,170 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   if (rank == gatherSetRank)
     create_gathers = true;
 
-  // Compute the number of local cells on this proc
-  nLocalCells = int(std::floor(1.0 * nCells / procs));
-  // start_cell_idx is the starting global cell index in the MPAS file for this proc
-  int start_cell_idx = rank * nLocalCells;
-  // iextra = # cells extra after equal split over procs
-  int iextra = nCells % procs;
-  if (rank < iextra)
-    nLocalCells++;
-  start_cell_idx += std::min(rank, iextra);
-  start_cell_idx++; // 0 based -> 1 based
-  localGidCells.insert(start_cell_idx, start_cell_idx + nLocalCells - 1);
-
-  // Read number of edges on each local cell
+  bool apply_zoltan = false;
+  if (apply_zoltan) {
+    // Zoltan partition, TBD
+  }
+  else {
+    // Trivial partition
+    // Compute the number of local cells on this proc
+    nLocalCells = int(std::floor(1.0 * nCells / procs));
+    // start_cell_idx is the starting global cell index in the MPAS file for this proc
+    int start_cell_idx = rank * nLocalCells;
+    // iextra = # cells extra after equal split over procs
+    int iextra = nCells % procs;
+    if (rank < iextra)
+      nLocalCells++;
+    start_cell_idx += std::min(rank, iextra);
+    start_cell_idx++; // 0 based -> 1 based
+    localGidCells.insert(start_cell_idx, start_cell_idx + nLocalCells - 1);
+  }
+
+  // Read number of edges on each local cell, to calculate actual maxEdgesPerCell
   int nEdgesOnCellVarId;
   int success = NCFUNC(inq_varid)(_fileId, "nEdgesOnCell", &nEdgesOnCellVarId);
   ERRORS(success, "Failed to get variable id of nEdgesOnCell.");
-  NCDF_SIZE tmp_starts_1[1] = {static_cast<NCDF_SIZE>(start_cell_idx - 1)};
-  NCDF_SIZE tmp_counts_1[1] = {static_cast<NCDF_SIZE>(nLocalCells)};
   std::vector<int> num_edges_on_local_cells(nLocalCells);
-  success = NCFUNCAG(_vara_int)(_fileId, nEdgesOnCellVarId, tmp_starts_1, tmp_counts_1, &num_edges_on_local_cells[0]);
-  ERRORS(success, "Failed to read variable values of nEdgesOnCell.");
+#ifdef PNETCDF_FILE
+  size_t nb_reads = localGidCells.psize();
+  std::vector<int> requests(nb_reads);
+  std::vector<int> statuss(nb_reads);
+  size_t idxReq = 0;
+#endif
+  size_t indexInArray = 0;
+  for (Range::pair_iterator pair_iter = localGidCells.pair_begin();
+       pair_iter != localGidCells.pair_end();
+       pair_iter++) {
+    EntityHandle starth = pair_iter->first;
+    EntityHandle endh = pair_iter->second;
+    NCDF_SIZE tmp_start = (NCDF_SIZE) (starth - 1);
+    NCDF_SIZE tmp_count = (NCDF_SIZE) (endh - starth + 1);
+
+    // Do a partial read in each subrange
+#ifdef PNETCDF_FILE
+    success = NCFUNCREQG(_vara_int)(_fileId, nEdgesOnCellVarId, &tmp_start, &tmp_count,
+                                      &(num_edges_on_local_cells[indexInArray]), &requests[idxReq++]);
+#else
+    success = NCFUNCAG(_vara_int)(_fileId, nEdgesOnCellVarId, &tmp_start, &tmp_count,
+                                      &(num_edges_on_local_cells[indexInArray]));
+#endif
+    ERRORS(success, "Failed to read nEdgesOnCell data in a loop");
+
+    // Increment the index for next subrange
+    indexInArray += (endh - starth + 1);
+  }
+
+#ifdef PNETCDF_FILE
+  // Wait outside the loop
+  success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
+  ERRORS(success, "Failed on wait_all.");
+#endif
 
   // Get local maxEdgesPerCell on this proc
-  maxEdgesPerCell = *(std::max_element(num_edges_on_local_cells.begin(), num_edges_on_local_cells.end()));
+  int local_max_edges_per_cell = *(std::max_element(num_edges_on_local_cells.begin(), num_edges_on_local_cells.end()));
+  maxEdgesPerCell = local_max_edges_per_cell;
 
-  // In parallel, do a MPI_Allreduce to get a common global maxEdgesPerCell used across all procs
+  // If parallel, do a MPI_Allreduce to get a common global maxEdgesPerCell used across all procs
 #ifdef USE_MPI
   if (procs > 1) {
     int global_max_edges_per_cell;
     ParallelComm*& myPcomm = _readNC->myPcomm;
-    MPI_Allreduce(&maxEdgesPerCell, &global_max_edges_per_cell, 1, MPI_INTEGER, MPI_MAX, myPcomm->proc_config().proc_comm());
-    assert(maxEdgesPerCell <= global_max_edges_per_cell);
+    MPI_Allreduce(&local_max_edges_per_cell, &global_max_edges_per_cell, 1, MPI_INTEGER, MPI_MAX, myPcomm->proc_config().proc_comm());
+    assert(local_max_edges_per_cell <= global_max_edges_per_cell);
     maxEdgesPerCell = global_max_edges_per_cell;
   }
 #endif
 
-  // Read vertices on each local cell (connectivity)
+  // Read edges on each local cell, to get localGidEdges later
+  int edgesOnCellVarId;
+  success = NCFUNC(inq_varid)(_fileId, "edgesOnCell", &edgesOnCellVarId);
+  ERRORS(success, "Failed to get variable id of edgesOnCell.");
+  std::vector<int> edges_on_local_cells(nLocalCells * maxEdgesPerCell);
+#ifdef PNETCDF_FILE
+  idxReq = 0;
+#endif
+  indexInArray = 0;
+  for (Range::pair_iterator pair_iter = localGidCells.pair_begin();
+       pair_iter != localGidCells.pair_end();
+       pair_iter++) {
+    EntityHandle starth = pair_iter->first;
+    EntityHandle endh = pair_iter->second;
+    NCDF_SIZE tmp_starts[2] = {static_cast<NCDF_SIZE>(starth - 1), 0};
+    NCDF_SIZE tmp_counts[2] = {static_cast<NCDF_SIZE>(endh - starth + 1), maxEdgesPerCell};
+
+    // Do a partial read in each subrange
+#ifdef PNETCDF_FILE
+    success = NCFUNCREQG(_vara_int)(_fileId, edgesOnCellVarId, tmp_starts, tmp_counts,
+                                      &(edges_on_local_cells[indexInArray]), &requests[idxReq++]);
+#else
+    success = NCFUNCAG(_vara_int)(_fileId, edgesOnCellVarId, tmp_starts, tmp_counts,
+                                      &(edges_on_local_cells[indexInArray]));
+#endif
+    ERRORS(success, "Failed to read edgesOnCell data in a loop");
+
+    // Increment the index for next subrange
+    indexInArray += (endh - starth + 1) * maxEdgesPerCell;
+  }
+
+#ifdef PNETCDF_FILE
+  // Wait outside the loop
+  success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
+  ERRORS(success, "Failed on wait_all.");
+#endif
+
+  // Collect local edges
+  std::sort(edges_on_local_cells.begin(), edges_on_local_cells.end());
+  std::copy(edges_on_local_cells.rbegin(), edges_on_local_cells.rend(), range_inserter(localGidEdges));
+  nLocalEdges = localGidEdges.size();
+
+  // Read vertices on each local cell, to get localGidVerts and cell connectivity later
   int verticesOnCellVarId;
   success = NCFUNC(inq_varid)(_fileId, "verticesOnCell", &verticesOnCellVarId);
   ERRORS(success, "Failed to get variable id of verticesOnCell.");
-  NCDF_SIZE tmp_starts_2[2] = {static_cast<NCDF_SIZE>(start_cell_idx - 1), 0};
-  NCDF_SIZE tmp_counts_2[2] = {static_cast<NCDF_SIZE>(nLocalCells), maxEdgesPerCell};
   std::vector<int> vertices_on_local_cells(nLocalCells * maxEdgesPerCell);
-  success = NCFUNCAG(_vara_int)(_fileId, verticesOnCellVarId, tmp_starts_2, tmp_counts_2, &vertices_on_local_cells[0]);
-  ERRORS(success, "Failed to read variable values of verticesOnCell.");
+#ifdef PNETCDF_FILE
+  idxReq = 0;
+#endif
+  indexInArray = 0;
+  for (Range::pair_iterator pair_iter = localGidCells.pair_begin();
+       pair_iter != localGidCells.pair_end();
+       pair_iter++) {
+    EntityHandle starth = pair_iter->first;
+    EntityHandle endh = pair_iter->second;
+    NCDF_SIZE tmp_starts[2] = {static_cast<NCDF_SIZE>(starth - 1), 0};
+    NCDF_SIZE tmp_counts[2] = {static_cast<NCDF_SIZE>(endh - starth + 1), maxEdgesPerCell};
+
+    // Do a partial read in each subrange
+#ifdef PNETCDF_FILE
+    success = NCFUNCREQG(_vara_int)(_fileId, verticesOnCellVarId, tmp_starts, tmp_counts,
+                                      &(vertices_on_local_cells[indexInArray]), &requests[idxReq++]);
+#else
+    success = NCFUNCAG(_vara_int)(_fileId, verticesOnCellVarId, tmp_starts, tmp_counts,
+                                      &(vertices_on_local_cells[indexInArray]));
+#endif
+    ERRORS(success, "Failed to read verticesOnCell data in a loop");
 
-  // Read edges on each local cell
-  int edgesOnCellVarId;
-  success = NCFUNC(inq_varid)(_fileId, "edgesOnCell", &edgesOnCellVarId);
-  ERRORS(success, "Failed to get variable id of edgesOnCell.");
-  NCDF_SIZE tmp_starts_3[2] = {static_cast<NCDF_SIZE>(start_cell_idx - 1), 0};
-  NCDF_SIZE tmp_counts_3[2] = {static_cast<NCDF_SIZE>(nLocalCells), maxEdgesPerCell};
-  std::vector<int> edges_on_local_cells(nLocalCells * maxEdgesPerCell);
-  success = NCFUNCAG(_vara_int)(_fileId, edgesOnCellVarId, tmp_starts_3, tmp_counts_3, &edges_on_local_cells[0]);
-  ERRORS(success, "Failed to read variable values of edgesOnCell.");
-
-  // Collect localGid for vertices and edges
-  std::set<int> local_verts_set;
-  std::set<int> local_edges_set;
-  for (int i = 0; i < nLocalCells; i++) {
-    int num_edges = num_edges_on_local_cells[i];
-    for (int j = 0; j < num_edges; j++) {
-      local_verts_set.insert(vertices_on_local_cells[i * maxEdgesPerCell + j]);
-      local_edges_set.insert(edges_on_local_cells[i * maxEdgesPerCell + j]);
-    }
+    // Increment the index for next subrange
+    indexInArray += (endh - starth + 1) * maxEdgesPerCell;
   }
-  std::copy(local_verts_set.rbegin(), local_verts_set.rend(), range_inserter(localGidVerts));
+
+#ifdef PNETCDF_FILE
+  // Wait outside the loop
+  success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
+  ERRORS(success, "Failed on wait_all.");
+#endif
+
+  // To keep unsorted vertices_on_local_cells for cell connectivity, we reuse edges_on_local_cells for sorting
+  std::vector<int>& vertices_on_local_cells_sorted = edges_on_local_cells;
+  std::copy(vertices_on_local_cells.begin(), vertices_on_local_cells.end(), vertices_on_local_cells_sorted.begin());
+
+  // Collect local vertices
+  std::sort(vertices_on_local_cells_sorted.begin(), vertices_on_local_cells_sorted.end());
+  std::copy(vertices_on_local_cells_sorted.rbegin(), vertices_on_local_cells_sorted.rend(), range_inserter(localGidVerts));
   nLocalVertices = localGidVerts.size();
-  std::copy(local_edges_set.rbegin(), local_edges_set.rend(), range_inserter(localGidEdges));
-  nLocalEdges = localGidEdges.size();
 
   // Create local vertices
+  // We can temporarily use the memory storage allocated before it will be populated
   EntityHandle start_vertex;
   std::vector<double*> arrays;
   Range tmp_range;
@@ -370,20 +426,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   ERRORR(rval, "Couldn't create local vertices in MPAS mesh.");
   tmp_range.insert(start_vertex, start_vertex + nLocalVertices - 1);
 
-  // Set coordinates for local vertices
-  double* xptr = arrays[0];
-  double* yptr = arrays[1];
-  double* zptr = arrays[2];
-  Range::const_iterator rit;
-  int vert_idx;
-  for (vert_idx = 0, rit = localGidVerts.begin(); vert_idx < nLocalVertices; vert_idx++, ++rit) {
-    assert(*rit < xVertVals.size() + 1);
-    xptr[vert_idx] = xVertVals[(*rit) - 1];
-    yptr[vert_idx] = yVertVals[(*rit) - 1];
-    zptr[vert_idx] = zVertVals[(*rit) - 1];
-  }
-
-  // Get ptr to gid memory for local vertices
+  // Get ptr to GID memory for local vertices
   Range local_verts_range(start_vertex, start_vertex + nLocalVertices - 1);
   int count = 0;
   void* data = NULL;
@@ -393,7 +436,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   int* gid_data = (int*) data;
   std::copy(localGidVerts.begin(), localGidVerts.end(), gid_data);
 
-  // Duplicate global id data, which will be used to resolve sharing
+  // Duplicate GID data, which will be used to resolve sharing
   if (mpFileIdTag) {
     rval = mbImpl->tag_iterate(*mpFileIdTag, local_verts_range.begin(), local_verts_range.end(), count, data);
     ERRORR(rval, "Failed to get file id tag iterator on local vertices.");
@@ -402,14 +445,10 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     std::copy(localGidVerts.begin(), localGidVerts.end(), gid_data);
   }
 
-  // Create map from file ids to vertex handles
-  std::map<EntityHandle, EntityHandle> vert_handles;
-  for (rit = localGidVerts.begin(), vert_idx = 0; rit != localGidVerts.end(); ++rit, vert_idx++)
-    vert_handles[*rit] = start_vertex + vert_idx;
-
   // Create local edges
+  // We can temporarily use the memory storage allocated before it will be populated
   EntityHandle start_edge;
-  EntityHandle* conn_arr_edges;
+  EntityHandle* conn_arr_edges = NULL;
   rval = _readNC->readMeshIface->get_element_connect(nLocalEdges, 2, MBEDGE, 0, start_edge, conn_arr_edges,
                                                     // Might have to create gather mesh later
                                                     (create_gathers ? nLocalEdges + nEdges : nLocalEdges));
@@ -417,17 +456,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   Range local_edges_range(start_edge, start_edge + nLocalEdges - 1);
   tmp_range.insert(start_edge, start_edge + nLocalEdges - 1);
 
-  // Set vertices for local edges
-  int edge_idx;
-  for (rit = localGidEdges.begin(), edge_idx = 0; rit != localGidEdges.end(); ++rit, edge_idx++) {
-    EntityHandle gloabl_edge_id = *rit;
-    EntityHandle gloabl_vert_id_1 = verticesOnEdge[(gloabl_edge_id - 1) * 2 + 0];
-    EntityHandle gloabl_vert_id_2 = verticesOnEdge[(gloabl_edge_id - 1) * 2 + 1];
-    conn_arr_edges[edge_idx * 2 + 0] = vert_handles[gloabl_vert_id_1];
-    conn_arr_edges[edge_idx * 2 + 1] = vert_handles[gloabl_vert_id_2];
-  }
-
-  // Get ptr to gid memory for edges
+  // Get ptr to GID memory for edges
   rval = mbImpl->tag_iterate(mGlobalIdTag, local_edges_range.begin(), local_edges_range.end(), count, data);
   ERRORR(rval, "Failed to get global id tag iterator on local edges.");
   assert(count == (int) nLocalEdges);
@@ -435,12 +464,23 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   std::copy(localGidEdges.begin(), localGidEdges.end(), gid_data);
 
   EntityHandle start_element = 0;
+
+  // Used when NO_MIXED_ELEMENTS option is NOT set
+  EntityHandle* conn_arr_local_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
+  std::vector<int> local_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
+  std::vector<int> num_edges_on_cell_groups;
+  std::vector<EntityHandle> start_element_on_cell_groups;
+
+  // Used when NO_MIXED_ELEMENTS option is set
+  EntityHandle* conn_arr_local_cells = NULL;
+
+  // Create local cells
+  // We can temporarily use the memory storage allocated before it will be populated
   if (noMixedElements) {
     // Only one group of cells (each cell is represented by a polygon with maxEdgesPerCell edges)
     numCellGroups = 1;
 
-    // Create cells and set connectivity array with proper local vertices handles
-    EntityHandle* conn_arr_local_cells = NULL;
+    // Create cells for this cell group
     rval = _readNC->readMeshIface->get_element_connect(nLocalCells, maxEdgesPerCell, MBPOLYGON, 0, start_element, conn_arr_local_cells,
                                                       // Might have to create gather mesh later
                                                       (create_gathers ? nLocalCells + nCells : nLocalCells));
@@ -449,77 +489,271 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     tmp_range.insert(start_element, start_element + nLocalCells - 1);
     faces.insert(start_element, start_element + nLocalCells - 1);
 
-    // Get ptr to gid memory for local cells
+    // Get ptr to GID memory for local cells
     rval = mbImpl->tag_iterate(mGlobalIdTag, local_cell_range.begin(), local_cell_range.end(), count, data);
     ERRORR(rval, "Failed to get global id tag iterator on local cells.");
     assert(count == nLocalCells);
     gid_data = (int*) data;
     std::copy(localGidCells.begin(), localGidCells.end(), gid_data);
-
-    // Set connectivity array with proper local vertices handles
-    for (int cell_idx = 0; cell_idx < nLocalCells; cell_idx++) {
-      int num_edges = num_edges_on_local_cells[cell_idx];
-      for (int i = 0; i < num_edges; i++) {
-        EntityHandle global_vert_id = vertices_on_local_cells[cell_idx * maxEdgesPerCell + i];
-        conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] = vert_handles[global_vert_id];
-      }
-
-      // Padding: fill connectivity array with last vertex handle
-      if (num_edges < maxEdgesPerCell) {
-        EntityHandle last_vert_id = conn_arr_local_cells[cell_idx * maxEdgesPerCell + num_edges - 1];
-        for (int i = num_edges; i < maxEdgesPerCell; i++)
-          conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] = last_vert_id;
-      }
-    }
-  } // if (noMixedElements)
+  }
   else {
     // Divide local cells into groups based on the number of edges
-    std::vector<int> local_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
     for (int i = 0; i < nLocalCells; i++) {
       int num_edges = num_edges_on_local_cells[i];
-      local_cells_with_n_edges[num_edges].push_back(start_cell_idx + i); // Global cell index
+      local_cells_with_n_edges[num_edges].push_back(localGidCells[i]); // Global cell index
     }
 
-    std::vector<int> num_edges_on_cell_groups;
     for (int i = 3; i <= maxEdgesPerCell; i++) {
       if (local_cells_with_n_edges[i].size() > 0)
         num_edges_on_cell_groups.push_back(i);
     }
     numCellGroups = num_edges_on_cell_groups.size();
 
-    // For each non-empty cell group, create cells and set connectivity array with proper local vertices handles
-    EntityHandle* conn_arr_local_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
+    // Create cells for each non-empty cell group
     for (int i = 0; i < numCellGroups; i++) {
       int num_edges_per_cell = num_edges_on_cell_groups[i];
-      int num_cells = local_cells_with_n_edges[num_edges_per_cell].size();
+      int num_group_cells = local_cells_with_n_edges[num_edges_per_cell].size();
 
-      rval = _readNC->readMeshIface->get_element_connect(num_cells, num_edges_per_cell, MBPOLYGON, 0, start_element,
-                                                         conn_arr_local_cells_with_n_edges[num_edges_per_cell], num_cells);
+      rval = _readNC->readMeshIface->get_element_connect(num_group_cells, num_edges_per_cell, MBPOLYGON, 0, start_element,
+                                                         conn_arr_local_cells_with_n_edges[num_edges_per_cell], num_group_cells);
       ERRORR(rval, "Couldn't create local cells in MPAS mesh.");
-      Range local_cell_range(start_element, start_element + num_cells - 1);
-      tmp_range.insert(start_element, start_element + num_cells - 1);
-      faces.insert(start_element, start_element + num_cells - 1);
+      start_element_on_cell_groups.push_back(start_element);
+      Range local_cell_range(start_element, start_element + num_group_cells - 1);
+      tmp_range.insert(start_element, start_element + num_group_cells - 1);
+      faces.insert(start_element, start_element + num_group_cells - 1);
 
       // Get ptr to gid memory for local cells
       rval = mbImpl->tag_iterate(mGlobalIdTag, local_cell_range.begin(), local_cell_range.end(), count, data);
       ERRORR(rval, "Failed to get global id tag iterator on local cells.");
-      assert(count == num_cells);
+      assert(count == num_group_cells);
       gid_data = (int*) data;
       std::copy(local_cells_with_n_edges[num_edges_per_cell].begin(), local_cells_with_n_edges[num_edges_per_cell].end(), gid_data);
+    }
+  }
+
+  // Create a temporary map from vertex GIDs to local handles
+  // Utilize the memory storage pointed by arrays[0]
+  EntityHandle* vert_gid_to_local_handle_tmp_map = (EntityHandle*) arrays[0];
+  Range::const_iterator rit;
+  int vert_idx;
+  for (rit = localGidVerts.begin(), vert_idx = 0; rit != localGidVerts.end(); ++rit, vert_idx++)
+    vert_gid_to_local_handle_tmp_map[*rit - 1] = start_vertex + vert_idx;
+
+  // Read vertices on each local edge, to get edge connectivity
+  // Utilize the memory storage pointed by conn_arr_edges
+  int verticesOnEdgeVarId;
+  success = NCFUNC(inq_varid)(_fileId, "verticesOnEdge", &verticesOnEdgeVarId);
+  ERRORS(success, "Failed to get variable id of verticesOnEdge.");
+  int* vertices_on_local_edges = (int*) conn_arr_edges;
+#ifdef PNETCDF_FILE
+  nb_reads = localGidEdges.psize();
+  requests.resize(nb_reads);
+  statuss.resize(nb_reads);
+  idxReq = 0;
+#endif
+  indexInArray = 0;
+  for (Range::pair_iterator pair_iter = localGidEdges.pair_begin();
+       pair_iter != localGidEdges.pair_end();
+       pair_iter++) {
+    EntityHandle starth = pair_iter->first;
+    EntityHandle endh = pair_iter->second;
+    NCDF_SIZE tmp_starts[2] = {static_cast<NCDF_SIZE>(starth - 1), 0};
+    NCDF_SIZE tmp_counts[2] = {static_cast<NCDF_SIZE>(endh - starth + 1), 2};
+
+    // Do a partial read in each subrange
+#ifdef PNETCDF_FILE
+    success = NCFUNCREQG(_vara_int)(_fileId, verticesOnEdgeVarId, tmp_starts, tmp_counts,
+                                      &(vertices_on_local_edges[indexInArray]), &requests[idxReq++]);
+#else
+    success = NCFUNCAG(_vara_int)(_fileId, verticesOnEdgeVarId, tmp_starts, tmp_counts,
+                                      &(vertices_on_local_edges[indexInArray]));
+#endif
+    ERRORS(success, "Failed to read verticesOnEdge data in a loop");
+
+    // Increment the index for next subrange
+    indexInArray += (endh - starth + 1) * 2;
+  }
+
+#ifdef PNETCDF_FILE
+  // Wait outside the loop
+  success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
+  ERRORS(success, "Failed on wait_all.");
+#endif
+
+  // Populate connectivity for local edges
+  // Convert in-place from int to EntityHandle type (backward)
+  for (int edge_vert = nLocalEdges * 2 - 1; edge_vert >= 0; edge_vert--) {
+    EntityHandle global_vert_id = vertices_on_local_edges[edge_vert];
+    conn_arr_edges[edge_vert] = vert_gid_to_local_handle_tmp_map[global_vert_id - 1];
+  }
+
+  // Populate connectivity for local cells
+  int cell_idx;
+  if (noMixedElements) {
+    // Set connectivity array with proper local vertices handles
+    for (cell_idx = 0; cell_idx < nLocalCells; cell_idx++) {
+      int num_edges = num_edges_on_local_cells[cell_idx];
+      for (int i = 0; i < num_edges; i++) {
+        EntityHandle global_vert_id = vertices_on_local_cells[cell_idx * maxEdgesPerCell + i];
+        conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] = vert_gid_to_local_handle_tmp_map[global_vert_id - 1];
+      }
+
+      // Padding: fill connectivity array with last vertex handle
+      if (num_edges < maxEdgesPerCell) {
+        EntityHandle last_vert_id = conn_arr_local_cells[cell_idx * maxEdgesPerCell + num_edges - 1];
+        for (int i = num_edges; i < maxEdgesPerCell; i++)
+          conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] = last_vert_id;
+      }
+    }
+  } // if (noMixedElements)
+  else {
+    // Create a temporary map from cell GID to local index
+    // Utilize the memory storage pointed by arrays[1]
+    EntityHandle* cell_gid_to_local_index_tmp_map = (EntityHandle*) arrays[1];
+    for (rit = localGidCells.begin(), cell_idx = 0; rit != localGidCells.end(); ++rit, cell_idx++)
+      cell_gid_to_local_index_tmp_map[*rit - 1] = cell_idx;
+
+    // For each non-empty cell group, set connectivity array with proper local vertices handles
+    for (int i = 0; i < numCellGroups; i++) {
+      int num_edges_per_cell = num_edges_on_cell_groups[i];
+      int num_cells = local_cells_with_n_edges[num_edges_per_cell].size();
+      start_element = start_element_on_cell_groups[i];
 
       for (int j = 0; j < num_cells; j++) {
-        int cell_idx = local_cells_with_n_edges[num_edges_per_cell][j]; // Global cell index
+        cell_idx = local_cells_with_n_edges[num_edges_per_cell][j]; // Global cell index
+
         if (numCellGroups > 1)
           cellHandleToGlobalID[start_element + j] = cell_idx;
-        cell_idx -= start_cell_idx; // Local cell index
+
+        cell_idx = cell_gid_to_local_index_tmp_map[cell_idx - 1]; // Local cell index
         for (int k = 0; k < num_edges_per_cell; k++) {
           EntityHandle global_vert_id = vertices_on_local_cells[cell_idx * maxEdgesPerCell + k];
-          conn_arr_local_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] = vert_handles[global_vert_id];
+          conn_arr_local_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] =
+              vert_gid_to_local_handle_tmp_map[global_vert_id - 1];
         }
       }
-    } // for (int i = 0; i < numCellGroups; i++)
+    }
+  }
+
+#ifdef PNETCDF_FILE
+  nb_reads = localGidVerts.psize();
+  requests.resize(nb_reads);
+  statuss.resize(nb_reads);
+#endif
+
+  // Read x coordinates for local vertices
+  // Note: vert_gid_to_local_handle_tmp_map is no longer used
+  double* xptr = arrays[0];
+  int xVertexVarId;
+  success = NCFUNC(inq_varid)(_fileId, "xVertex", &xVertexVarId);
+  ERRORS(success, "Failed to get variable id of xVertex.");
+#ifdef PNETCDF_FILE
+  idxReq = 0;
+#endif
+  indexInArray = 0;
+  for (Range::pair_iterator pair_iter = localGidVerts.pair_begin();
+       pair_iter != localGidVerts.pair_end();
+       pair_iter++) {
+    EntityHandle starth = pair_iter->first;
+    EntityHandle endh = pair_iter->second;
+    NCDF_SIZE tmp_start = (NCDF_SIZE) (starth - 1);
+    NCDF_SIZE tmp_count = (NCDF_SIZE) (endh - starth + 1);
+
+    // Do a partial read in each subrange
+#ifdef PNETCDF_FILE
+    success = NCFUNCREQG(_vara_double)(_fileId, xVertexVarId, &tmp_start, &tmp_count,
+                                      &(xptr[indexInArray]), &requests[idxReq++]);
+#else
+    success = NCFUNCAG(_vara_double)(_fileId, xVertexVarId, &tmp_start, &tmp_count,
+                                      &(xptr[indexInArray]));
+#endif
+    ERRORS(success, "Failed to read xVertex data in a loop");
+
+    // Increment the index for next subrange
+    indexInArray += (endh - starth + 1);
+  }
+
+#ifdef PNETCDF_FILE
+  // Wait outside the loop
+  success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
+  ERRORS(success, "Failed on wait_all.");
+#endif
+
+  // Read y coordinates for local vertices
+  // Note: cell_gid_to_local_index_tmp_ma is no longer used
+  double* yptr = arrays[1];
+  int yVertexVarId;
+  success = NCFUNC(inq_varid)(_fileId, "yVertex", &yVertexVarId);
+  ERRORS(success, "Failed to get variable id of yVertex.");
+#ifdef PNETCDF_FILE
+  idxReq = 0;
+#endif
+  indexInArray = 0;
+  for (Range::pair_iterator pair_iter = localGidVerts.pair_begin();
+       pair_iter != localGidVerts.pair_end();
+       pair_iter++) {
+    EntityHandle starth = pair_iter->first;
+    EntityHandle endh = pair_iter->second;
+    NCDF_SIZE tmp_start = (NCDF_SIZE) (starth - 1);
+    NCDF_SIZE tmp_count = (NCDF_SIZE) (endh - starth + 1);
+
+    // Do a partial read in each subrange
+#ifdef PNETCDF_FILE
+    success = NCFUNCREQG(_vara_double)(_fileId, yVertexVarId, &tmp_start, &tmp_count,
+                                      &(yptr[indexInArray]), &requests[idxReq++]);
+#else
+    success = NCFUNCAG(_vara_double)(_fileId, yVertexVarId, &tmp_start, &tmp_count,
+                                      &(yptr[indexInArray]));
+#endif
+    ERRORS(success, "Failed to read yVertex data in a loop");
+
+    // Increment the index for next subrange
+    indexInArray += (endh - starth + 1);
+  }
+
+#ifdef PNETCDF_FILE
+  // Wait outside the loop
+  success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
+  ERRORS(success, "Failed on wait_all.");
+#endif
+
+  // Read z coordinates for local vertices
+  double* zptr = arrays[2];
+  int zVertexVarId;
+  success = NCFUNC(inq_varid)(_fileId, "zVertex", &zVertexVarId);
+  ERRORS(success, "Failed to get variable id of zVertex.");
+#ifdef PNETCDF_FILE
+  idxReq = 0;
+#endif
+  indexInArray = 0;
+  for (Range::pair_iterator pair_iter = localGidVerts.pair_begin();
+       pair_iter != localGidVerts.pair_end();
+       pair_iter++) {
+    EntityHandle starth = pair_iter->first;
+    EntityHandle endh = pair_iter->second;
+    NCDF_SIZE tmp_start = (NCDF_SIZE) (starth - 1);
+    NCDF_SIZE tmp_count = (NCDF_SIZE) (endh - starth + 1);
+
+    // Do a partial read in each subrange
+#ifdef PNETCDF_FILE
+    success = NCFUNCREQG(_vara_double)(_fileId, zVertexVarId, &tmp_start, &tmp_count,
+                                      &(zptr[indexInArray]), &requests[idxReq++]);
+#else
+    success = NCFUNCAG(_vara_double)(_fileId, zVertexVarId, &tmp_start, &tmp_count,
+                                      &(zptr[indexInArray]));
+#endif
+    ERRORS(success, "Failed to read zVertex data in a loop");
+
+    // Increment the index for next subrange
+    indexInArray += (endh - starth + 1);
   }
 
+#ifdef PNETCDF_FILE
+  // Wait outside the loop
+  success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
+  ERRORS(success, "Failed on wait_all.");
+#endif
+
   // Set tag for numCellGroups
   Tag numCellGroupsTag = 0;
   rval = mbImpl->tag_get_handle("__NUM_CELL_GROUPS", 1, MB_TYPE_INTEGER, numCellGroupsTag, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -546,19 +780,59 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     xptr = arrays[0];
     yptr = arrays[1];
     zptr = arrays[2];
-    for (vert_idx = 0; vert_idx < nVertices; vert_idx++) {
-      xptr[vert_idx] = xVertVals[vert_idx];
-      yptr[vert_idx] = yVertVals[vert_idx];
-      zptr[vert_idx] = zVertVals[vert_idx];
-    }
+    NCDF_SIZE tmp_start = 0;
+    NCDF_SIZE tmp_count = static_cast<NCDF_SIZE>(nVertices);
 
-    // Get ptr to gid memory for gather vertices
+    // Read x coordinates for gather vertices
+#ifdef PNETCDF_FILE
+    // Enter independent I/O mode, since this read is only for the gather processor
+    success = NCFUNC(begin_indep_data)(_fileId);
+    ERRORS(success, "Failed to begin independent I/O mode.");
+    success = NCFUNCG(_vara_double)(_fileId, xVertexVarId, &tmp_start, &tmp_count, xptr);
+    ERRORS(success, "Failed to read xVertex data.");
+    success = NCFUNC(end_indep_data)(_fileId);
+    ERRORS(success, "Failed to end independent I/O mode.");
+#else
+    success = NCFUNCG(_vara_double)(_fileId, xVertexVarId, &tmp_start, &tmp_count, xptr);
+    ERRORS(success, "Failed to read xVertex data.");
+#endif
+
+    // Read y coordinates for gather vertices
+#ifdef PNETCDF_FILE
+    // Enter independent I/O mode, since this read is only for the gather processor
+    success = NCFUNC(begin_indep_data)(_fileId);
+    ERRORS(success, "Failed to begin independent I/O mode.");
+    success = NCFUNCG(_vara_double)(_fileId, yVertexVarId, &tmp_start, &tmp_count, yptr);
+    ERRORS(success, "Failed to read yVertex data.");
+    success = NCFUNC(end_indep_data)(_fileId);
+    ERRORS(success, "Failed to end independent I/O mode.");
+#else
+    success = NCFUNCG(_vara_double)(_fileId, yVertexVarId, &tmp_start, &tmp_count, yptr);
+    ERRORS(success, "Failed to read yVertex data.");
+#endif
+
+    // Read z coordinates for gather vertices
+#ifdef PNETCDF_FILE
+    // Enter independent I/O mode, since this read is only for the gather processor
+    success = NCFUNC(begin_indep_data)(_fileId);
+    ERRORS(success, "Failed to begin independent I/O mode.");
+    success = NCFUNCG(_vara_double)(_fileId, zVertexVarId, &tmp_start, &tmp_count, zptr);
+    ERRORS(success, "Failed to read zVertex data.");
+    success = NCFUNC(end_indep_data)(_fileId);
+    ERRORS(success, "Failed to end independent I/O mode.");
+#else
+    success = NCFUNCG(_vara_double)(_fileId, zVertexVarId, &tmp_start, &tmp_count, zptr);
+    ERRORS(success, "Failed to read zVertex data.");
+#endif
+
+    // Get ptr to GID memory for gather vertices
     rval = mbImpl->tag_iterate(mGlobalIdTag, gather_verts_range.begin(), gather_verts_range.end(), count, data);
     ERRORR(rval, "Failed to get global id tag iterator on gather vertices.");
     assert(count == nVertices);
     gid_data = (int*) data;
     for (int j = 1; j <= nVertices; j++)
       gid_data[j - 1] = j;
+
     // Set the file id tag too, it should be bigger something not interfering with global id
     if (mpFileIdTag) {
       rval = mbImpl->tag_iterate(*mpFileIdTag, gather_verts_range.begin(), gather_verts_range.end(), count, data);
@@ -574,19 +848,19 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
     // Read number of edges on each gather cell
     std::vector<int> num_edges_on_gather_cells(nCells);
-    tmp_starts_1[0] = 0;
-    tmp_counts_1[0] = static_cast<NCDF_SIZE>(nCells);
+    tmp_start = 0;
+    tmp_count = static_cast<NCDF_SIZE>(nCells);
 #ifdef PNETCDF_FILE
     // Enter independent I/O mode, since this read is only for the gather processor
     success = NCFUNC(begin_indep_data)(_fileId);
     ERRORS(success, "Failed to begin independent I/O mode.");
-    success = NCFUNCG(_vara_int)(_fileId, nEdgesOnCellVarId, tmp_starts_1, tmp_counts_1, &num_edges_on_gather_cells[0]);
-    ERRORS(success, "Failed to read variable values of nEdgesOnCell.");
+    success = NCFUNCG(_vara_int)(_fileId, nEdgesOnCellVarId, &tmp_start, &tmp_count, &num_edges_on_gather_cells[0]);
+    ERRORS(success, "Failed to read nEdgesOnCell data.");
     success = NCFUNC(end_indep_data)(_fileId);
     ERRORS(success, "Failed to end independent I/O mode.");
 #else
-    success = NCFUNCG(_vara_int)(_fileId, nEdgesOnCellVarId, tmp_starts_1, tmp_counts_1, &num_edges_on_gather_cells[0]);
-    ERRORS(success, "Failed to read variable values of nEdgesOnCell.");
+    success = NCFUNCG(_vara_int)(_fileId, nEdgesOnCellVarId, &tmp_start, &tmp_count, &num_edges_on_gather_cells[0]);
+    ERRORS(success, "Failed to read nEdgesOnCell data.");
 #endif
 
     // Create gather edges
@@ -596,7 +870,23 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     ERRORR(rval, "Couldn't create edges in MPAS mesh for gather set.");
     Range gather_edges_range(start_edge, start_edge + nEdges - 1);
 
-    std::copy(verticesOnEdge.begin(), verticesOnEdge.end(), conn_arr_gather_edges);
+    // Read vertices on each edge
+    std::vector<int> vertices_on_gather_edges(nEdges * 2);
+    NCDF_SIZE tmp_starts[2] = {0, 0};
+    NCDF_SIZE tmp_counts[2] = {static_cast<NCDF_SIZE>(nEdges), 2};
+#ifdef PNETCDF_FILE
+    // Enter independent I/O mode, since this read is only for the gather processor
+    success = NCFUNC(begin_indep_data)(_fileId);
+    success = NCFUNCG(_vara_int)(_fileId, verticesOnEdgeVarId, tmp_starts, tmp_counts, &vertices_on_gather_edges[0]);
+    ERRORS(success, "Failed to read verticesOnEdge data.");
+    success = NCFUNC(end_indep_data)(_fileId);
+    ERRORS(success, "Failed to end independent I/O mode.");
+#else
+    success = NCFUNCG(_vara_int)(_fileId, verticesOnEdgeVarId, tmp_starts, tmp_counts, &vertices_on_gather_edges[0]);
+    ERRORS(success, "Failed to read verticesOnEdge data.");
+#endif
+
+    std::copy(vertices_on_gather_edges.begin(), vertices_on_gather_edges.end(), conn_arr_gather_edges);
     for (int i = 0; i < 2 * nEdges; i++)
       // Connectivity array is shifted by where the gather verts start
       conn_arr_gather_edges[i] += start_vertex - 1;
@@ -606,21 +896,21 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
     // Read vertices on each gather cell (connectivity)
     std::vector<int> vertices_on_gather_cells(nCells * maxEdgesPerCell);
-    tmp_starts_2[0] = 0;
-    tmp_starts_2[1] = 0;
-    tmp_counts_2[0] = nCells;
-    tmp_counts_2[1] = maxEdgesPerCell;
+    tmp_starts[0] = 0;
+    tmp_starts[1] = 0;
+    tmp_counts[0] = nCells;
+    tmp_counts[1] = maxEdgesPerCell;
 #ifdef PNETCDF_FILE
     // Enter independent I/O mode, since this read is only for the gather processor
     success = NCFUNC(begin_indep_data)(_fileId);
     ERRORS(success, "Failed to begin independent I/O mode.");
-    success = NCFUNCG(_vara_int)(_fileId, verticesOnCellVarId, tmp_starts_2, tmp_counts_2, &vertices_on_gather_cells[0]);
-    ERRORS(success, "Failed to read variable values of verticesOnCell.");
+    success = NCFUNCG(_vara_int)(_fileId, verticesOnCellVarId, tmp_starts, tmp_counts, &vertices_on_gather_cells[0]);
+    ERRORS(success, "Failed to read verticesOnCell data.");
     success = NCFUNC(end_indep_data)(_fileId);
     ERRORS(success, "Failed to end independent I/O mode.");
 #else
-    success = NCFUNCG(_vara_int)(_fileId, verticesOnCellVarId, tmp_starts_2, tmp_counts_2, &vertices_on_gather_cells[0]);
-    ERRORS(success, "Failed to read variable values of verticesOnCell.");
+    success = NCFUNCG(_vara_int)(_fileId, verticesOnCellVarId, tmp_starts, tmp_counts, &vertices_on_gather_cells[0]);
+    ERRORS(success, "Failed to read verticesOnCell data.");
 #endif
 
     Range gather_cells_range;
@@ -632,7 +922,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
       ERRORR(rval, "Couldn't create cells in MPAS mesh for gather set.");
       gather_cells_range.insert(start_element, start_element + nCells - 1);
 
-      for (int cell_idx = 0; cell_idx < nCells; cell_idx++) {
+      for (cell_idx = 0; cell_idx < nCells; cell_idx++) {
         int num_edges = num_edges_on_gather_cells[cell_idx];
         for (int i = 0; i < num_edges; i++)
           // Connectivity array is shifted by where the gather verts start
@@ -662,7 +952,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
           ERRORR(rval, "Couldn't create cells in MPAS mesh for gather set.");
           gather_cells_range.insert(start_element, start_element + num_cells - 1);
           for (int j = 0; j < num_cells; j++) {
-            int cell_idx = gather_cells_with_n_edges[num_edges_per_cell][j];
+            cell_idx = gather_cells_with_n_edges[num_edges_per_cell][j];
             cell_idx--; // 1 based -> 0 based
             for (int k = 0; k < num_edges_per_cell; k++)
               // Connectivity array is shifted by where the gather verts start

diff --git a/src/io/NCHelperMPAS.hpp b/src/io/NCHelperMPAS.hpp
index 2c97566..ba440b8 100644
--- a/src/io/NCHelperMPAS.hpp
+++ b/src/io/NCHelperMPAS.hpp
@@ -51,7 +51,6 @@ private:
 private:
   int maxEdgesPerCell;
   int numCellGroups;
-  std::vector<int> verticesOnEdge;
   std::map<EntityHandle, int> cellHandleToGlobalID;
   Range facesOwned;
 };


https://bitbucket.org/fathomteam/moab/commits/358a6ad9de6c/
Changeset:   358a6ad9de6c
Branch:      None
User:        iulian07
Date:        2013-10-19 21:33:43
Summary:     clear memory in MBZoltan after we are done

Affected #:  1 file

diff --git a/tools/mbzoltan/MBZoltan.cpp b/tools/mbzoltan/MBZoltan.cpp
index fc1e387..e598f0e 100644
--- a/tools/mbzoltan/MBZoltan.cpp
+++ b/tools/mbzoltan/MBZoltan.cpp
@@ -337,10 +337,11 @@ ErrorCode  MBZoltan::repartition(std::vector<double> & x,std::vector<double>&y,
     t = clock();
   }
 
-  // free some memory?
-  delete myZZ;
+
   for (size_t i=0; i<x.size(); i++)
     sendToProcs.push_back(assign_procs[i]);
+  // free some memory after we are done
+  delete myZZ;
   // free memory used by Zoltan
   // form tuples for Gids!
   TupleList gidProcs;


https://bitbucket.org/fathomteam/moab/commits/cc82ce81b041/
Changeset:   cc82ce81b041
Branch:      None
User:        iulian07
Date:        2013-10-19 21:39:35
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  8 files

diff --git a/itaps/iBase.h b/itaps/iBase.h
index e61f92d..4af4f7b 100644
--- a/itaps/iBase.h
+++ b/itaps/iBase.h
@@ -18,7 +18,7 @@
  ******************************************************************************/
 #define IBASE_VERSION_MAJOR 1
 #define IBASE_VERSION_MINOR 4
-#define IBASE_VERSION_PATCH 0
+#define IBASE_VERSION_PATCH 1
 
 /***************************************************************************//**
  * \ingroup VersionNumbers

diff --git a/src/Makefile.am b/src/Makefile.am
index dc0c3f2..3a86984 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -205,6 +205,18 @@ nobase_libMOAB_la_include_HEADERS = \
   MOAB_FCDefs.h \
   MBCN_protos.h \
   MBTagConventions.hpp
+if ENABLE_mbzoltan
+  libMOAB_la_SOURCES += $(srcdir)/../tools/mbzoltan/MBZoltan.cpp
+  nobase_libMOAB_la_include_HEADERS += $(srcdir)/../tools/mbzoltan/MBZoltan.hpp
+  AM_CPPFLAGS +=  $(ZOLTAN_INC_FLAGS) -DHAVE_ZOLTAN
+  # not sure yet if this is needed; will see when linking io reader (MPAS so far)
+  # the tool mbpart needed it, and it just includes MBZoltan.hpp; so it needs ways to find 
+  # the libraries zoltan depends on
+  libMOAB_la_LIBADD += $(ZOLTAN_LIBS) $(ZOLTAN_LIB_FLAGS)
+endif
+if HAVE_CGM
+  AM_CPPFLAGS += @CGM_CPPFLAGS@ -DCGM @MOAB_CGM_DEFINES@
+endif
   
 MBCN_protos.h: MBCN.h $(top_srcdir)/itaps/mkprotos.sh
 	$(AM_V_GEN)$(top_srcdir)/itaps/mkprotos.sh MBCN MOAB $< $@ MOAB_FCDefs.h

diff --git a/src/ScdInterface.cpp b/src/ScdInterface.cpp
index 1d42dde..12f5b89 100644
--- a/src/ScdInterface.cpp
+++ b/src/ScdInterface.cpp
@@ -22,7 +22,7 @@
 namespace moab 
 {
 
-const char *ScdParData::PartitionMethodNames[] = {"alljorkori", "alljkbal", "sqij", "sqjk", "sqijk", "trivial", "nopart"};
+const char *ScdParData::PartitionMethodNames[] = {"alljorkori", "alljkbal", "sqij", "sqjk", "sqijk", "trivial","rcbzoltan", "nopart"};
 
 ScdInterface::ScdInterface(Interface *imp, bool boxes) 
         : mbImpl(imp), 

diff --git a/src/io/Makefile.am b/src/io/Makefile.am
index bb5b7cb..968f47f 100644
--- a/src/io/Makefile.am
+++ b/src/io/Makefile.am
@@ -39,6 +39,9 @@ if !NETCDF_FILE
 endif
 endif
 
+if ENABLE_mbzoltan
+  AM_CPPFLAGS += -DHAVE_ZOLTAN -I$(srcdir)/../../tools/mbzoltan $(ZOLTAN_INC_FLAGS) 
+endif
 if HDF5_FILE
   libmoabio_la_LIBADD += mhdf/libmhdf.la
   MOAB_HDF5_SRCS = HDF5Common.cpp \

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index 09fe541..35fdb2b 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -4,6 +4,10 @@
 #include "moab/SpectralMeshTool.hpp"
 #include "MBTagConventions.hpp"
 
+#if HAVE_ZOLTAN
+#include "MBZoltan.hpp"
+#endif
+
 #include <cmath>
 
 #define ERRORR(rval, str) \
@@ -16,6 +20,36 @@ namespace moab {
 
 const int DEFAULT_MAX_EDGES_PER_CELL = 10;
 
+// this is used for zoltan only related stuff
+#define GET_VAR(name, id, dims) \
+    {                           \
+    id = -1;\
+    int gvfail = NCFUNC(inq_varid)( _fileId, name, &id);   \
+    if (NC_NOERR == gvfail) {       \
+    int ndims;\
+    gvfail = NCFUNC(inq_varndims)( _fileId, id, &ndims);\
+    if (NC_NOERR == gvfail) {\
+    dims.resize(ndims);    \
+    gvfail = NCFUNC(inq_vardimid)( _fileId, id, &dims[0]);}}}
+
+#define GET_1D_DBL_VAR_RANGE(name, id, startIndex, endIndex, vals) \
+    {std::vector<int> dum_dims;        \
+  GET_VAR(name, id, dum_dims);\
+  if (-1 != id) {\
+    if (rank==0) std::cout << " var:" << name << " id: " << id << "\n"; \
+    NCDF_SIZE ntmp;\
+    int dvfail = NCFUNC(inq_dimlen)(_fileId, dum_dims[0], &ntmp);\
+    if (rank==0) std::cout << " prepare read var " << name << " start:" << startIndex << " end:"<< endIndex <<" Actual size:" << \
+       ntmp << "\n" ; \
+    if (startIndex > (int)ntmp || endIndex > (int) ntmp || startIndex>=endIndex) \
+      { std::cout << "bad input \n"; return MB_FAILURE;} \
+    vals.resize(endIndex-startIndex);\
+    NCDF_SIZE ntmp1 = startIndex;    NCDF_SIZE count = endIndex-startIndex;           \
+    dvfail = NCFUNC(get_vara_double_all)( _fileId, id, &ntmp1, &count, &vals[0]);\
+    if (NC_NOERR != dvfail) {\
+      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
+      return MB_FAILURE;}}}
+
 NCHelperMPAS::NCHelperMPAS(ReadNC* readNC, int fileId, const FileOptions& opts, EntityHandle fileSet)
 : UcdNCHelper(readNC, fileId, opts, fileSet)
 , maxEdgesPerCell(DEFAULT_MAX_EDGES_PER_CELL)
@@ -237,6 +271,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   int& gatherSetRank = _readNC->gatherSetRank;
   bool& noMixedElements = _readNC->noMixedElements;
 
+  DebugOutput& dbgOut = _readNC->dbgOut;
+
   int rank = 0;
   int procs = 1;
 #ifdef USE_MPI
@@ -253,25 +289,54 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   if (rank == gatherSetRank)
     create_gathers = true;
 
-  bool apply_zoltan = false;
-  if (apply_zoltan) {
-    // Zoltan partition, TBD
+  // Trivial partition
+  // Compute the number of local cells on this proc
+  nLocalCells = int(std::floor(1.0 * nCells / procs));
+  // start_cell_idx is the starting global cell index in the MPAS file for this proc
+  int start_cell_idx = rank * nLocalCells;
+  // iextra = # cells extra after equal split over procs
+  int iextra = nCells % procs;
+  if (rank < iextra)
+    nLocalCells++;
+  start_cell_idx += std::min(rank, iextra);
+
+
+#ifdef USE_MPI
+  int& partMethod = _readNC->partMethod;
+  if (partMethod==ScdParData::RCBZOLTAN && procs >=2) // it does not make sense to partition
+    // if the number of processors is less than 2; trivial partition is good enough
+  {
+    // Zoltan partition using RCB; maybe more studies would be good, as to which partition
+    // is better
+    int temp_dim;
+    MBZoltan * mbZTool = new MBZoltan(mbImpl, false, 0, NULL);
+
+    std::vector<double> x, y, z;
+    int end_cell_index=start_cell_idx+nLocalCells;
+    GET_1D_DBL_VAR_RANGE("xCell", temp_dim, start_cell_idx, end_cell_index, x) ;
+    GET_1D_DBL_VAR_RANGE("yCell", temp_dim, start_cell_idx, end_cell_index, y) ;
+    GET_1D_DBL_VAR_RANGE("zCell", temp_dim, start_cell_idx, end_cell_index, z) ;
+
+    ErrorCode rval = mbZTool->repartition(x, y, z, start_cell_idx+1, "RCB", localGidCells );
+    //delete mbZTool;
+    if (rval !=MB_SUCCESS)
+    {
+      std::cout <<" error in partitioning\n";
+      return MB_FAILURE;
+    }
+
+    dbgOut.tprintf(1, "After partitioning, localGidCells.psize()=%d\n", (int)localGidCells.psize());
+    dbgOut.tprintf(1, "                    localGidCells.size()=%d\n",  (int)localGidCells.size());
+    // this is important: local cells are now redistributed, so nLocalCells is different!
+    nLocalCells = localGidCells.size();
   }
   else {
-    // Trivial partition
-    // Compute the number of local cells on this proc
-    nLocalCells = int(std::floor(1.0 * nCells / procs));
-    // start_cell_idx is the starting global cell index in the MPAS file for this proc
-    int start_cell_idx = rank * nLocalCells;
-    // iextra = # cells extra after equal split over procs
-    int iextra = nCells % procs;
-    if (rank < iextra)
-      nLocalCells++;
-    start_cell_idx += std::min(rank, iextra);
+#endif  /* use mpi */
     start_cell_idx++; // 0 based -> 1 based
     localGidCells.insert(start_cell_idx, start_cell_idx + nLocalCells - 1);
+#ifdef USE_MPI
   }
-
+#endif
   // Read number of edges on each local cell, to calculate actual maxEdgesPerCell
   int nEdgesOnCellVarId;
   int success = NCFUNC(inq_varid)(_fileId, "nEdgesOnCell", &nEdgesOnCellVarId);
@@ -324,14 +389,18 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     MPI_Allreduce(&local_max_edges_per_cell, &global_max_edges_per_cell, 1, MPI_INTEGER, MPI_MAX, myPcomm->proc_config().proc_comm());
     assert(local_max_edges_per_cell <= global_max_edges_per_cell);
     maxEdgesPerCell = global_max_edges_per_cell;
+    if (0==rank)
+      dbgOut.tprintf(1, "  global_max_edges_per_cell=%d\n", global_max_edges_per_cell);
   }
 #endif
 
+
   // Read edges on each local cell, to get localGidEdges later
   int edgesOnCellVarId;
   success = NCFUNC(inq_varid)(_fileId, "edgesOnCell", &edgesOnCellVarId);
   ERRORS(success, "Failed to get variable id of edgesOnCell.");
   std::vector<int> edges_on_local_cells(nLocalCells * maxEdgesPerCell);
+  dbgOut.tprintf(1, "   edges_on_local_cells.size()=%d\n", (int)edges_on_local_cells.size());
 #ifdef PNETCDF_FILE
   idxReq = 0;
 #endif
@@ -342,7 +411,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     EntityHandle starth = pair_iter->first;
     EntityHandle endh = pair_iter->second;
     NCDF_SIZE tmp_starts[2] = {static_cast<NCDF_SIZE>(starth - 1), 0};
-    NCDF_SIZE tmp_counts[2] = {static_cast<NCDF_SIZE>(endh - starth + 1), maxEdgesPerCell};
+    NCDF_SIZE tmp_counts[2] = {static_cast<NCDF_SIZE>(endh - starth + 1), static_cast<NCDF_SIZE>(maxEdgesPerCell)};
 
     // Do a partial read in each subrange
 #ifdef PNETCDF_FILE
@@ -357,7 +426,6 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     // Increment the index for next subrange
     indexInArray += (endh - starth + 1) * maxEdgesPerCell;
   }
-
 #ifdef PNETCDF_FILE
   // Wait outside the loop
   success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
@@ -369,6 +437,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   std::copy(edges_on_local_cells.rbegin(), edges_on_local_cells.rend(), range_inserter(localGidEdges));
   nLocalEdges = localGidEdges.size();
 
+  dbgOut.tprintf(1, "   localGidEdges.psize()=%d\n", (int)localGidEdges.psize());
+  dbgOut.tprintf(1, "   localGidEdges.size()=%d\n",  (int)localGidEdges.size());
   // Read vertices on each local cell, to get localGidVerts and cell connectivity later
   int verticesOnCellVarId;
   success = NCFUNC(inq_varid)(_fileId, "verticesOnCell", &verticesOnCellVarId);
@@ -415,6 +485,9 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   std::copy(vertices_on_local_cells_sorted.rbegin(), vertices_on_local_cells_sorted.rend(), range_inserter(localGidVerts));
   nLocalVertices = localGidVerts.size();
 
+  dbgOut.tprintf(1, "   localGidVerts.psize()=%d\n", (int)localGidVerts.psize());
+  dbgOut.tprintf(1, "   localGidVerts.size()=%d\n",  (int)localGidVerts.size());
+
   // Create local vertices
   // We can temporarily use the memory storage allocated before it will be populated
   EntityHandle start_vertex;
@@ -467,7 +540,9 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
   // Used when NO_MIXED_ELEMENTS option is NOT set
   EntityHandle* conn_arr_local_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
-  std::vector<int> local_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
+  // put in subranges; each subrange (for numEdges) will contain, in order, the
+  // gids for cells with that many edges (numEdges)
+  Range local_cells_with_n_edges[DEFAULT_MAX_EDGES_PER_CELL + 1];
   std::vector<int> num_edges_on_cell_groups;
   std::vector<EntityHandle> start_element_on_cell_groups;
 
@@ -500,7 +575,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     // Divide local cells into groups based on the number of edges
     for (int i = 0; i < nLocalCells; i++) {
       int num_edges = num_edges_on_local_cells[i];
-      local_cells_with_n_edges[num_edges].push_back(localGidCells[i]); // Global cell index
+      local_cells_with_n_edges[num_edges].insert(localGidCells[i]); // Global cell index
+      // by construction, this subrange will contain cells in order
     }
 
     for (int i = 3; i <= maxEdgesPerCell; i++) {
@@ -533,11 +609,16 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
   // Create a temporary map from vertex GIDs to local handles
   // Utilize the memory storage pointed by arrays[0]
-  EntityHandle* vert_gid_to_local_handle_tmp_map = (EntityHandle*) arrays[0];
-  Range::const_iterator rit;
+  // EntityHandle* vert_gid_to_local_handle_tmp_map = (EntityHandle*) arrays[0];
+  // you don't need it:
+  // so vertex handle start_vertex+idx has the global ID localGidVerts[idx]
+  //  if I need the vertex handle for gid, use Range::index();
+  // so, from gid to eh: int index = localGidVerts.index(gid)
+  // eh = start_vertex+idx;
+  /*Range::const_iterator rit;
   int vert_idx;
   for (rit = localGidVerts.begin(), vert_idx = 0; rit != localGidVerts.end(); ++rit, vert_idx++)
-    vert_gid_to_local_handle_tmp_map[*rit - 1] = start_vertex + vert_idx;
+    vert_gid_to_local_handle_tmp_map[*rit - 1] = start_vertex + vert_idx;*/
 
   // Read vertices on each local edge, to get edge connectivity
   // Utilize the memory storage pointed by conn_arr_edges
@@ -584,7 +665,9 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   // Convert in-place from int to EntityHandle type (backward)
   for (int edge_vert = nLocalEdges * 2 - 1; edge_vert >= 0; edge_vert--) {
     EntityHandle global_vert_id = vertices_on_local_edges[edge_vert];
-    conn_arr_edges[edge_vert] = vert_gid_to_local_handle_tmp_map[global_vert_id - 1];
+    int idx_vertex=localGidVerts.index(global_vert_id);
+    assert(idx_vertex!=-1);
+    conn_arr_edges[edge_vert] = start_vertex+idx_vertex;
   }
 
   // Populate connectivity for local cells
@@ -595,7 +678,9 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
       int num_edges = num_edges_on_local_cells[cell_idx];
       for (int i = 0; i < num_edges; i++) {
         EntityHandle global_vert_id = vertices_on_local_cells[cell_idx * maxEdgesPerCell + i];
-        conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] = vert_gid_to_local_handle_tmp_map[global_vert_id - 1];
+        int idx_vertex=localGidVerts.index(global_vert_id);
+        assert(idx_vertex!=-1);
+        conn_arr_local_cells[cell_idx * maxEdgesPerCell + i] =  start_vertex+idx_vertex;
       }
 
       // Padding: fill connectivity array with last vertex handle
@@ -609,14 +694,16 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   else {
     // Create a temporary map from cell GID to local index
     // Utilize the memory storage pointed by arrays[1]
-    EntityHandle* cell_gid_to_local_index_tmp_map = (EntityHandle*) arrays[1];
+    // again, not correct because of overflow
+    // here we have to use a different map, maybe RangeMap
+    /*EntityHandle* cell_gid_to_local_index_tmp_map = (EntityHandle*) arrays[1];
     for (rit = localGidCells.begin(), cell_idx = 0; rit != localGidCells.end(); ++rit, cell_idx++)
-      cell_gid_to_local_index_tmp_map[*rit - 1] = cell_idx;
+      cell_gid_to_local_index_tmp_map[*rit - 1] = cell_idx;*/
 
     // For each non-empty cell group, set connectivity array with proper local vertices handles
     for (int i = 0; i < numCellGroups; i++) {
       int num_edges_per_cell = num_edges_on_cell_groups[i];
-      int num_cells = local_cells_with_n_edges[num_edges_per_cell].size();
+      int num_cells = (int)local_cells_with_n_edges[num_edges_per_cell].size();
       start_element = start_element_on_cell_groups[i];
 
       for (int j = 0; j < num_cells; j++) {
@@ -624,12 +711,18 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
         if (numCellGroups > 1)
           cellHandleToGlobalID[start_element + j] = cell_idx;
+        // find the index in the range: local_cells_with_n_edges[num_edges_per_cell];
 
-        cell_idx = cell_gid_to_local_index_tmp_map[cell_idx - 1]; // Local cell index
+        // overflow averted :(
+        // cell_idx = cell_gid_to_local_index_tmp_map[cell_idx - 1]; // Local cell index
+        cell_idx = localGidCells.index(cell_idx);
+        assert(cell_idx!=-1);
         for (int k = 0; k < num_edges_per_cell; k++) {
           EntityHandle global_vert_id = vertices_on_local_cells[cell_idx * maxEdgesPerCell + k];
+          int idx_vertex=localGidVerts.index(global_vert_id);
+          assert(idx_vertex!=-1);
           conn_arr_local_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] =
-              vert_gid_to_local_handle_tmp_map[global_vert_id - 1];
+              start_vertex+idx_vertex;
         }
       }
     }
@@ -765,6 +858,7 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   rval = _readNC->mbImpl->add_entities(_fileSet, tmp_range);
   ERRORR(rval, "Couldn't add new vertices/faces/edges to file set.");
 
+  dbgOut.tprintf(1, "   local entities in set: tmp_range.size()=%d\n",  (int)tmp_range.size());
   if (create_gathers) {
     EntityHandle gather_set;
     rval = _readNC->readMeshIface->create_gather_set(gather_set);

diff --git a/src/moab/ScdInterface.hpp b/src/moab/ScdInterface.hpp
index 0726b13..1f2a482 100644
--- a/src/moab/ScdInterface.hpp
+++ b/src/moab/ScdInterface.hpp
@@ -112,7 +112,7 @@ public:
     //! Partition method enumeration; these strategies are described in comments for
     //! compute_partition_alljorkori, compute_partition_alljkbal, compute_partition_sqij,
     //! compute_partition_sqjk, and compute_partition_sqijk
-  enum PartitionMethod {ALLJORKORI = 0, ALLJKBAL, SQIJ, SQJK, SQIJK, TRIVIAL, NOPART};
+  enum PartitionMethod {ALLJORKORI = 0, ALLJKBAL, SQIJ, SQJK, SQIJK, TRIVIAL, RCBZOLTAN, NOPART};
 
     //! Partition method names
   static const char *PartitionMethodNames[NOPART + 1];

diff --git a/test/parallel/mpastrvpart.cpp b/test/parallel/mpastrvpart.cpp
index 2b86f61..f9bfa36 100644
--- a/test/parallel/mpastrvpart.cpp
+++ b/test/parallel/mpastrvpart.cpp
@@ -13,6 +13,8 @@ static const char example[] = STRINGIFY(MESHDIR) "/io/mpasx1.642.t.2.nc";
 
 void test_read_parallel_mpas_trivial();
 void test_read_parallel_mpas_trivial_no_mixed_elements();
+void test_read_parallel_mpas_rcbzoltan();
+void test_read_parallel_mpas_rcbzoltan_no_mixed_elements();
 void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges,
                         int num_cells, bool test_nb_cells, bool mixed_elements);
 void test_multiple_loads_of_same_file();
@@ -27,6 +29,8 @@ int main(int argc, char* argv[])
 
   result += RUN_TEST(test_read_parallel_mpas_trivial);
   result += RUN_TEST(test_read_parallel_mpas_trivial_no_mixed_elements);
+  result += RUN_TEST(test_read_parallel_mpas_rcbzoltan);
+  result += RUN_TEST(test_read_parallel_mpas_rcbzoltan_no_mixed_elements);
   result += RUN_TEST(test_multiple_loads_of_same_file);
   result += RUN_TEST(test_multiple_loads_of_same_file_no_mixed_elements);
 
@@ -46,6 +50,18 @@ void test_read_parallel_mpas_trivial_no_mixed_elements()
   test_read_parallel(1280, true, 1920, true, 642, true, false);
 }
 
+void test_read_parallel_mpas_rcbzoltan()
+{
+  partition_method = std::string(";PARTITION_METHOD=RCBZOLTAN;PARALLEL_RESOLVE_SHARED_ENTS");
+  test_read_parallel(1280, false, 1920, false, 642, false, true);
+}
+
+void test_read_parallel_mpas_rcbzoltan_no_mixed_elements()
+{
+  partition_method = std::string(";PARTITION_METHOD=RCBZOLTAN;PARALLEL_RESOLVE_SHARED_ENTS;NO_MIXED_ELEMENTS");
+  test_read_parallel(1280, false, 1920, false, 642, false, true);
+}
+
 void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges,
                         int num_cells, bool test_nb_cells, bool mixed_elements)
 {

diff --git a/tools/mbzoltan/Makefile.am b/tools/mbzoltan/Makefile.am
index 3b68941..355ead8 100644
--- a/tools/mbzoltan/Makefile.am
+++ b/tools/mbzoltan/Makefile.am
@@ -11,14 +11,15 @@ AM_CPPFLAGS += $(CGM_CPPFLAGS)
 endif
 
 AM_LDFLAGS += $(ZOLTAN_LIB_FLAGS)
-lib_LTLIBRARIES = libmbzoltan.la
-libmbzoltan_la_LIBADD = $(top_builddir)/src/libMOAB.la $(ZOLTAN_LIBS)
-libmbzoltan_la_includedir = $(includedir)
-libmbzoltan_la_SOURCES = MBZoltan.cpp
-libmbzoltan_la_include_HEADERS = MBZoltan.hpp
+# lib_LTLIBRARIES = libmbzoltan.la
+# libmbzoltan_la_LIBADD = $(top_builddir)/src/libMOAB.la $(ZOLTAN_LIBS)
+# libmbzoltan_la_includedir = $(includedir)
+# libmbzoltan_la_SOURCES = MBZoltan.cpp
+# libmbzoltan_la_include_HEADERS = MBZoltan.hpp
 
 bin_PROGRAMS = mbpart
-LDADD = libmbzoltan.la
+# LDADD = libmbzoltan.la
 mbpart_SOURCES = mbpart.cpp
-mbpart_LDADD = libmbzoltan.la 
+# mbpart_LDADD = libmbzoltan.la 
+mbpart_LDADD = $(top_builddir)/src/libMOAB.la $(ZOLTAN_LIBS)
 


https://bitbucket.org/fathomteam/moab/commits/d67187b8f0a8/
Changeset:   d67187b8f0a8
Branch:      None
User:        iulian07
Date:        2013-10-19 21:45:10
Summary:     zoltan is now part of libMOAB
no need to specify it separately in Makefile.am for mbcslam

Affected #:  1 file

diff --git a/tools/mbcslam/Makefile.am b/tools/mbcslam/Makefile.am
index 5309a83..f5a475d 100644
--- a/tools/mbcslam/Makefile.am
+++ b/tools/mbcslam/Makefile.am
@@ -25,16 +25,6 @@ libmbcslam_la_LIBADD = $(top_builddir)/src/libMOAB.la $(top_builddir)/itaps/imes
          
 LDADD = $(top_builddir)/src/libMOAB.la libmbcslam.la $(top_builddir)/tools/mbcoupler/libmbcoupler.la
 
-if ENABLE_mbzoltan
-  libmbcslam_la_LIBADD+=$(top_builddir)/tools/mbzoltan/libmbzoltan.la
-  LDADD+=$(top_builddir)/tools/mbzoltan/libmbzoltan.la
-  AM_CPPFLAGS += $(ZOLTAN_INC_FLAGS) 
-endif
-
-if HAVE_CGM
-  AM_CPPFLAGS += @CGM_CPPFLAGS@ -DCGM @MOAB_CGM_DEFINES@
-endif
-  
 libmbcslam_la_SOURCES = \
    Intx2Mesh.cpp Intx2Mesh.hpp Intx2MeshOnSphere.cpp Intx2MeshOnSphere.hpp \
      CslamUtils.cpp CslamUtils.hpp Intx2MeshInPlane.cpp Intx2MeshInPlane.hpp 


https://bitbucket.org/fathomteam/moab/commits/255c4f745a0f/
Changeset:   255c4f745a0f
Branch:      None
User:        iulian07
Date:        2013-10-20 02:06:48
Summary:     makefile change because of zoltan
cgm needs to be included too

Affected #:  1 file

diff --git a/tools/mbcslam/Makefile.am b/tools/mbcslam/Makefile.am
index f5a475d..6db90f2 100644
--- a/tools/mbcslam/Makefile.am
+++ b/tools/mbcslam/Makefile.am
@@ -15,9 +15,15 @@ AM_CPPFLAGS += -DSRCDIR=$(srcdir) \
                -I$(top_srcdir)/itaps/imesh \
                -I$(top_builddir)/itaps \
                -I$(top_builddir)/itaps/imesh \
-               -I$(top_srcdir)/test \
+               -I$(top_srcdir)/test 
+if ENABLE_mbzoltan
+  AM_CPPFLAGS +=  $(ZOLTAN_INC_FLAGS) -DHAVE_ZOLTAN \
                -I$(top_srcdir)/tools/mbzoltan \
                -I$(top_builddir)/tools/mbzoltan
+if HAVE_CGM
+  AM_CPPFLAGS += @CGM_CPPFLAGS@ -DCGM @MOAB_CGM_DEFINES@
+endif
+endif
 
 lib_LTLIBRARIES = libmbcslam.la
 libmbcslam_la_LIBADD = $(top_builddir)/src/libMOAB.la $(top_builddir)/itaps/imesh/libiMesh.la \


https://bitbucket.org/fathomteam/moab/commits/3affd3572a1c/
Changeset:   3affd3572a1c
Branch:      None
User:        iulian07
Date:        2013-11-01 17:07:37
Summary:     Merged fathomteam/moab into master
Affected #:  19 files

diff --git a/MeshFiles/unittest/io/mpasx1.642.t.2.nc b/MeshFiles/unittest/io/mpasx1.642.t.2.nc
index f1e8c94..f055c49 100644
Binary files a/MeshFiles/unittest/io/mpasx1.642.t.2.nc and b/MeshFiles/unittest/io/mpasx1.642.t.2.nc differ

diff --git a/configure.ac b/configure.ac
index cc1d3e0..937385d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -557,8 +557,6 @@ AC_ARG_WITH([parmetis],
 		 ;;
                esac] )
 
-
-
 ################################################################################
 #                            Optional Libraries
 ################################################################################
@@ -740,6 +738,8 @@ AC_SUBST(ZOLTAN_LIBS)
 AC_SUBST(ZOLTAN_LIB_FLAGS)
 AC_SUBST(ZOLTAN_INC_FLAGS)
 
+EXPORT_LDFLAGS="$ZOLTAN_LIB_FLAGS $EXPORT_LDFLAGS"
+
 ################################################################################
 #                    VTK for qvdual and/or vtkMOABReader
 ################################################################################

diff --git a/itaps/igeom/FBiGeom-Defs.inc.in b/itaps/igeom/FBiGeom-Defs.inc.in
index 54217e4..0ed147a 100644
--- a/itaps/igeom/FBiGeom-Defs.inc.in
+++ b/itaps/igeom/FBiGeom-Defs.inc.in
@@ -15,7 +15,7 @@ FBIGEOM_INCLUDES = $(FBIGEOM_CPPFLAGS)
 FBIGEOM_LIBS = $(FBIGEOM_LDFLAGS) -L$(MOAB_LIBDIR) \
                -L$(FBIGEOM_LIBDIR) -liMesh -lFBiGeomMOAB -lMOAB \
                @NETCDF_LIBS@ @HDF5_LIBS@ @LIBS@ \
-               @CGM_LDFLAGS@ @CGM_LIBS@
+               @CGM_LDFLAGS@ @CGM_LIBS@ @ZOLTAN_LIBS@ 
 
 FBIGEOM_INCLUDEDIR1 = @abs_srcdir@
 FBIGEOM_INCLUDEDIR2 = -I at abs_top_builddir@

diff --git a/itaps/imesh/iMesh-Defs.inc.in b/itaps/imesh/iMesh-Defs.inc.in
index 44418e6..b0b7f70 100644
--- a/itaps/imesh/iMesh-Defs.inc.in
+++ b/itaps/imesh/iMesh-Defs.inc.in
@@ -15,7 +15,7 @@ IMESH_INCLUDES = $(IMESH_CPPFLAGS)
 IMESH_LIBS = $(IMESH_LDFLAGS) -L$(MOAB_LIBDIR) \
              -L$(IMESH_LIBDIR) -liMesh -lMOAB \
              @NETCDF_LIBS@ @PNETCDF_LIBS@ @HDF5_LIBS@ @DAMSEL_LIBS@ @LIBS@ \
-             @CGM_LDFLAGS@ @CGM_LIBS@ @CCMIO_LIBS@
+             @CGM_LDFLAGS@ @CGM_LIBS@ @CCMIO_LIBS@ @ZOLTAN_LIBS@ 
 
 IMESH_INCLUDEDIR = @abs_srcdir@
 IMESH_INCLUDEDIR2 = -I at abs_builddir@ -I at abs_srcdir@/.. -I at abs_builddir@/.. -I at abs_top_builddir@/src

diff --git a/moab.make.in b/moab.make.in
index e6dc42d..45f80de 100644
--- a/moab.make.in
+++ b/moab.make.in
@@ -8,13 +8,15 @@ MOAB_INCLUDES = -I at abs_srcdir@/src \
                 -I at abs_srcdir@/src/parallel \
                 -I at abs_builddir@/src/parallel
 
+MOAB_INCLUDES += @ZOLTAN_INC_FLAGS@
+
 MOAB_CXXFLAGS = @CXXFLAGS@ @AM_CXXFLAGS@
 MOAB_CFLAGS = @CFLAGS@ @AM_CFLAGS@
 MOAB_FFLAGS = @FFLAGS@
 MOAB_FCFLAGS = @FCFLAGS@
 MOAB_LDFLAGS = @EXPORT_LDFLAGS@
 
-MOAB_LIBS_LINK = ${MOAB_LDFLAGS} -L${MOAB_LIBDIR} -lMOAB @LIBS@ @PNETCDF_LIBS@ @NETCDF_LIBS@ @HDF5_LIBS@ @CCMIO_LIBS@ @CGM_LIBS@
+MOAB_LIBS_LINK = ${MOAB_LDFLAGS} -L${MOAB_LIBDIR} -lMOAB @LIBS@ @PNETCDF_LIBS@ @NETCDF_LIBS@ @HDF5_LIBS@ @CCMIO_LIBS@ @CGM_LIBS@ @ZOLTAN_LIBS@ 
 
 MOAB_CXX = @CXX@
 MOAB_CC  = @CC@

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index 5f621d7..bc8da0f 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -306,7 +306,7 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
 
 ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
-  std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;;
+  std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;
   Interface*& mbImpl = _readNC->mbImpl;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
@@ -316,8 +316,11 @@ ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, s
   // Finally, read into that space
   int success;
   for (unsigned int i = 0; i < vdatas.size(); i++) {
-    if (dummyVarNames.find(vdatas[i].varName) != dummyVarNames.end() )
-       continue; // This is a dummy one, we don't have it; we created it for the dummy tag
+    // This is a dummy variable for a dimension with no corresponding coordinate variable
+    // No need to set its tag data
+    if (dummyVarNames.find(vdatas[i].varName) != dummyVarNames.end())
+       continue;
+
     for (unsigned int t = 0; t < tstep_nums.size(); t++) {
       void* data = vdatas[i].varDatas[t];
 
@@ -355,21 +358,20 @@ ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, s
 
       if (success)
         ERRORR(MB_FAILURE, "Trouble reading variable.");
-      if (vdatas[i].varDims.size() <= 1)
-        break;
-    }
-  }
 
-  for (unsigned int i = 0; i < vdatas.size(); i++) {
-    for (unsigned int t = 0; t < tstep_nums.size(); t++) {
       dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
-      ErrorCode tmp_rval = convert_variable(vdatas[i], t);
-      if (MB_SUCCESS != tmp_rval)
-        rval = tmp_rval;
+      rval = convert_variable(vdatas[i], t);
+      ERRORR(rval, "Failed to convert variable.");
+
+      dbgOut.tprintf(2, "Setting data for variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
+      rval = mbImpl->tag_set_by_ptr(vdatas[i].varTags[t], &_fileSet, 1, &(vdatas[i].varDatas[t]), &vdatas[i].sz);
+      ERRORR(rval, "Failed to set data for variable.");
+
       if (vdatas[i].varDims.size() <= 1)
         break;
     }
   }
+
   // Debug output, if requested
   if (1 == dbgOut.get_verbosity()) {
     dbgOut.printf(1, "Read variables: %s", vdatas.begin()->varName.c_str());
@@ -378,17 +380,6 @@ ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, s
     dbgOut.tprintf(1, "\n");
   }
 
-  for (unsigned int i = 0; i < vdatas.size(); i++) {
-    for (unsigned int t = 0; t < tstep_nums.size(); t++) {
-      dbgOut.tprintf(2, "Setting data for variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
-      ErrorCode tmp_rval = mbImpl->tag_set_by_ptr(vdatas[i].varTags[t], &_fileSet, 1, &(vdatas[i].varDatas[t]), &vdatas[i].sz);
-      if (MB_SUCCESS != tmp_rval)
-        rval = tmp_rval;
-      if (vdatas[i].varDims.size() <= 1)
-        break;
-    }
-  }
-
   return rval;
 }
 
@@ -652,7 +643,7 @@ ErrorCode NCHelper::create_attrib_string(const std::map<std::string, ReadNC::Att
   return MB_SUCCESS;
 }
 
-void NCHelper::init_dims_with_no_cvars_info()
+void NCHelper::init_dims_with_no_coord_vars_info()
 {
   std::vector<std::string>& dimNames = _readNC->dimNames;
   std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;
@@ -660,24 +651,23 @@ void NCHelper::init_dims_with_no_cvars_info()
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   // Hack: look at all dimensions, and see if we have one that does not appear in the list of varInfo names
-  // right now, candidates are ncol and nbnd
-  // for them, create dummy tags
-  for (unsigned int i = 0; i < dimNames.size(); i++)
-  {
-    // If there is a var with this name, skip, we are fine; if not, create a varInfo...
+  // Right now, candidates are from unstructured meshes, such as ncol(HOMME) and nCells(MPAS)
+  // For them, create dummy tags
+  for (unsigned int i = 0; i < dimNames.size(); i++) {
+    // If there is a variable with this dimension name, skip, we are fine; if not, create a dummy varInfo
     if (varInfo.find(dimNames[i]) != varInfo.end())
-      continue; // We already have a variable with this dimension name
+      continue;
 
     int sizeTotalVar = varInfo.size();
     std::string var_name(dimNames[i]);
-    ReadNC::VarData &data = varInfo[var_name];
+    ReadNC::VarData& data = varInfo[var_name];
     data.varName = std::string(var_name);
-    data.varId =sizeTotalVar;
+    data.varId = sizeTotalVar;
     data.varTags.resize(1, 0);
     data.varDataType = NC_DOUBLE; // Could be int, actually, but we do not really need the type
     data.varDims.resize(1);
-    data.varDims[0]= (int)i;
-    data.numAtts=0;
+    data.varDims[0] = (int)i;
+    data.numAtts = 0;
     data.entLoc = ReadNC::ENTLOCSET;
     dbgOut.tprintf(2, "Dummy varInfo created for dimension %s\n", dimNames[i].c_str());
     dummyVarNames.insert(dimNames[i]);
@@ -686,12 +676,23 @@ void NCHelper::init_dims_with_no_cvars_info()
 
 ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
+  std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;
   std::vector<int>& dimLens = _readNC->dimLens;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   ErrorCode rval = MB_SUCCESS;
 
   for (unsigned int i = 0; i < vdatas.size(); i++) {
+    // This is a dummy variable for a dimension with no corresponding coordinate variable
+    // No need to allocate memory to read it
+    if (dummyVarNames.find(vdatas[i].varName) != dummyVarNames.end()) {
+      if (!vdatas[i].varTags[0]) {
+        rval = get_tag_to_set(vdatas[i], 0, vdatas[i].varTags[0]);
+        ERRORR(rval, "Trouble getting dummy tag.");
+      }
+      continue;
+    }
+
     if ((std::find(vdatas[i].varDims.begin(), vdatas[i].varDims.end(), tDim) != vdatas[i].varDims.end()))
       vdatas[i].has_t = true;
 
@@ -710,15 +711,12 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
 
       // Set up the dimensions and counts
       // First variable dimension is time, if it exists
-      if (vdatas[i].has_t)
-      {
-        if (vdatas[i].varDims.size() != 1)
-        {
+      if (vdatas[i].has_t) {
+        if (vdatas[i].varDims.size() != 1) {
           vdatas[i].readStarts[t].push_back(tstep_nums[t]);
           vdatas[i].readCounts[t].push_back(1);
         }
-        else
-        {
+        else {
           vdatas[i].readStarts[t].push_back(0);
           vdatas[i].readCounts[t].push_back(tstep_nums.size());
         }
@@ -739,10 +737,12 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
           }
         }
       }
+
       std::size_t sz = 1;
       for (std::size_t idx = 0; idx != vdatas[i].readCounts[t].size(); idx++)
         sz *= vdatas[i].readCounts[t][idx];
       vdatas[i].sz = sz;
+
       switch (vdatas[i].varDataType) {
         case NC_BYTE:
         case NC_CHAR:
@@ -760,6 +760,7 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
           std::cerr << "Unrecognized data type for tag " << std::endl;
           rval = MB_FAILURE;
       }
+
       if (vdatas[i].varDims.size() <= 1)
         break;
     }
@@ -779,8 +780,7 @@ ErrorCode ScdNCHelper::check_existing_mesh() {
   /*
   // Check against parameters
   // When ghosting is used, this check might fail (to be updated later)
-  if (num_verts > 0)
-  {
+  if (num_verts > 0) {
     int expected_verts = (lDims[3] - lDims[0] + 1) * (lDims[4] - lDims[1] + 1) * (-1 == lDims[2] ? 1 : lDims[5] - lDims[2] + 1);
     if (num_verts != expected_verts) {
       ERRORR(MB_FAILURE, "Number of vertices doesn't match.");
@@ -796,8 +796,7 @@ ErrorCode ScdNCHelper::check_existing_mesh() {
   /*
   // Check against parameters
   // The expected number of elements calculated below is incorrect (to be updated later)
-  if (num_elems > 0)
-  {
+  if (num_elems > 0) {
     int expected_elems = (lDims[3] - lDims[0]) * (lDims[4] - lDims[1]) * (-1 == lDims[2] ? 1 : lDims[5] - lDims[2]);
     if (num_elems != expected_elems) {
       ERRORR(MB_FAILURE, "Number of elements doesn't match.");
@@ -990,6 +989,7 @@ ErrorCode ScdNCHelper::read_scd_variable_setup(std::vector<std::string>& var_nam
       vdatas[i].readStarts.resize(tstep_nums.size());
       vdatas[i].readCounts.resize(tstep_nums.size());
     }
+
     for (unsigned int i = 0; i < vsetdatas.size(); i++) {
       if ((std::find(vsetdatas[i].varDims.begin(), vsetdatas[i].varDims.end(), tDim) != vsetdatas[i].varDims.end())
           && (vsetdatas[i].varDims.size() != 1)) {

diff --git a/src/io/NCHelper.hpp b/src/io/NCHelper.hpp
index 4982b4c..f3d1875 100644
--- a/src/io/NCHelper.hpp
+++ b/src/io/NCHelper.hpp
@@ -58,9 +58,9 @@ protected:
                                  std::string& attString,
                                  std::vector<int>& attLen);
 
-  //! Init info for dimensions that don't have corresponding
-  //! coordinate variables - this info is used for creating tags
-  void init_dims_with_no_cvars_info();
+  //! Initialize information for dimensions that don't have corresponding
+  //! coordinate variables - this information is used for creating dummy tags
+  void init_dims_with_no_coord_vars_info();
 
 private:
   //! Used by read_variable_to_set()

diff --git a/src/io/NCHelperEuler.cpp b/src/io/NCHelperEuler.cpp
index ca86127..48056c6 100644
--- a/src/io/NCHelperEuler.cpp
+++ b/src/io/NCHelperEuler.cpp
@@ -328,18 +328,28 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       vd.entLoc = ReadNC::ENTLOCFACE;
   }
 
-  std::vector<std::string> ijdimNames(2);
-  ijdimNames[0] = "__lon";
-  ijdimNames[1] = "__lat";
+  // For Eul models, slon and slat are "virtual" dimensions (not defined in the file header)
+  std::vector<std::string> ijdimNames(4);
+  ijdimNames[0] = "__slon";
+  ijdimNames[1] = "__slat";
+  ijdimNames[2] = "__lon";
+  ijdimNames[3] = "__lat";
 
-  std::stringstream ss_tag_name;
   std::string tag_name;
   Tag tagh;
 
-  // __<dim_name>_LOC_MINMAX (for lon and lat)
+  // __<dim_name>_LOC_MINMAX (for virtual slon, virtual slat, lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
     std::vector<int> val(2, 0);
-    if (ijdimNames[i] == "__lon") {
+    if (ijdimNames[i] == "__slon") {
+      val[0] = lDims[0];
+      val[1] = lDims[3];
+    }
+    else if (ijdimNames[i] == "__slat") {
+      val[0] = lDims[1];
+      val[1] = lDims[4];
+    }
+    else if (ijdimNames[i] == "__lon") {
       val[0] = lCDims[0];
       val[1] = lCDims[3];
     }
@@ -347,7 +357,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       val[0] = lCDims[1];
       val[1] = lCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -358,11 +368,19 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // __<dim_name>_LOC_VALS (for lon and lat)
+  // __<dim_name>_LOC_VALS (for virtual slon, virtual slat, lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
     void* val = NULL;
     int val_len = 0;
-    if (ijdimNames[i] == "__lon") {
+    if (ijdimNames[i] == "__slon") {
+      val = &ilVals[0];
+      val_len = ilVals.size();
+    }
+    else if (ijdimNames[i] == "__slat") {
+      val = &jlVals[0];
+      val_len = jlVals.size();
+    }
+    else if (ijdimNames[i] == "__lon") {
       val = &ilCVals[0];
       val_len = ilCVals.size();
     }
@@ -392,7 +410,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
         ERRORR(MB_FAILURE, "Unrecognized data type");
         break;
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_VALS";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
@@ -403,10 +421,18 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // __<dim_name>_GLOBAL_MINMAX (for lon and lat)
+  // __<dim_name>_GLOBAL_MINMAX (for virtual slon, virtual slat, lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
     std::vector<int> val(2, 0);
-    if (ijdimNames[i] == "__lon") {
+    if (ijdimNames[i] == "__slon") {
+      val[0] = gDims[0];
+      val[1] = gDims[3];
+    }
+    else if (ijdimNames[i] == "__slat") {
+      val[0] = gDims[1];
+      val[1] = gDims[4];
+    }
+    else if (ijdimNames[i] == "__lon") {
       val[0] = gCDims[0];
       val[1] = gCDims[3];
     }
@@ -414,7 +440,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       val[0] = gCDims[1];
       val[1] = gCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -425,8 +451,8 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // Hack: create dummy tags, if needed, for variables with no corresponding variables
-  init_dims_with_no_cvars_info();
+  // Hack: create dummy tags, if needed, for dimensions with no corresponding coordinate variables
+  init_dims_with_no_coord_vars_info();
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperFV.cpp b/src/io/NCHelperFV.cpp
index a234450..253d598 100644
--- a/src/io/NCHelperFV.cpp
+++ b/src/io/NCHelperFV.cpp
@@ -336,7 +336,6 @@ ErrorCode NCHelperFV::init_mesh_vals()
   ijdimNames[2] = "__lon";
   ijdimNames[3] = "__lat";
 
-  std::stringstream ss_tag_name;
   std::string tag_name;
   Tag tagh;
 
@@ -359,7 +358,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
       val[0] = lCDims[1];
       val[1] = lCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -412,7 +411,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
         ERRORR(MB_FAILURE, "Unrecognized data type");
         break;
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_VALS";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
@@ -442,7 +441,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
       val[0] = gCDims[1];
       val[1] = gCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -453,8 +452,8 @@ ErrorCode NCHelperFV::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // Hack: create dummy tags, if needed, for dimensions with no corresponding variables
-  init_dims_with_no_cvars_info();
+  // Hack: create dummy tags, if needed, for dimensions with no corresponding coordinate variables
+  init_dims_with_no_coord_vars_info();
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index f750e78..154d61d 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -160,8 +160,8 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
       vd.entLoc = ReadNC::ENTLOCVERT;
   }
 
-  // Hack: create dummy tags, if needed, for variables with no corresponding variables
-  init_dims_with_no_cvars_info();
+  // Hack: create dummy tags for dimensions (like ncol) with no corresponding coordinate variables
+  init_dims_with_no_coord_vars_info();
 
   return MB_SUCCESS;
 }
@@ -548,6 +548,7 @@ ErrorCode NCHelperHOMME::read_ucd_variable_setup(std::vector<std::string>& var_n
       vdatas[i].readStarts.resize(tstep_nums.size());
       vdatas[i].readCounts.resize(tstep_nums.size());
     }
+
     for (unsigned int i = 0; i < vsetdatas.size(); i++) {
       if ((std::find(vsetdatas[i].varDims.begin(), vsetdatas[i].varDims.end(), tDim) != vsetdatas[i].varDims.end())
           && (vsetdatas[i].varDims.size() != 1)) {

This diff is so big that we needed to truncate the remainder.

https://bitbucket.org/fathomteam/moab/commits/5e239ec49957/
Changeset:   5e239ec49957
Branch:      None
User:        iulian07
Date:        2013-11-05 16:38:15
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  20 files

diff --git a/MeshFiles/unittest/io/mpasx1.642.t.2.nc b/MeshFiles/unittest/io/mpasx1.642.t.2.nc
index f1e8c94..f055c49 100644
Binary files a/MeshFiles/unittest/io/mpasx1.642.t.2.nc and b/MeshFiles/unittest/io/mpasx1.642.t.2.nc differ

diff --git a/configure.ac b/configure.ac
index cc1d3e0..937385d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -557,8 +557,6 @@ AC_ARG_WITH([parmetis],
 		 ;;
                esac] )
 
-
-
 ################################################################################
 #                            Optional Libraries
 ################################################################################
@@ -740,6 +738,8 @@ AC_SUBST(ZOLTAN_LIBS)
 AC_SUBST(ZOLTAN_LIB_FLAGS)
 AC_SUBST(ZOLTAN_INC_FLAGS)
 
+EXPORT_LDFLAGS="$ZOLTAN_LIB_FLAGS $EXPORT_LDFLAGS"
+
 ################################################################################
 #                    VTK for qvdual and/or vtkMOABReader
 ################################################################################

diff --git a/itaps/igeom/FBiGeom-Defs.inc.in b/itaps/igeom/FBiGeom-Defs.inc.in
index 54217e4..0ed147a 100644
--- a/itaps/igeom/FBiGeom-Defs.inc.in
+++ b/itaps/igeom/FBiGeom-Defs.inc.in
@@ -15,7 +15,7 @@ FBIGEOM_INCLUDES = $(FBIGEOM_CPPFLAGS)
 FBIGEOM_LIBS = $(FBIGEOM_LDFLAGS) -L$(MOAB_LIBDIR) \
                -L$(FBIGEOM_LIBDIR) -liMesh -lFBiGeomMOAB -lMOAB \
                @NETCDF_LIBS@ @HDF5_LIBS@ @LIBS@ \
-               @CGM_LDFLAGS@ @CGM_LIBS@
+               @CGM_LDFLAGS@ @CGM_LIBS@ @ZOLTAN_LIBS@ 
 
 FBIGEOM_INCLUDEDIR1 = @abs_srcdir@
 FBIGEOM_INCLUDEDIR2 = -I at abs_top_builddir@

diff --git a/itaps/imesh/iMesh-Defs.inc.in b/itaps/imesh/iMesh-Defs.inc.in
index 44418e6..b0b7f70 100644
--- a/itaps/imesh/iMesh-Defs.inc.in
+++ b/itaps/imesh/iMesh-Defs.inc.in
@@ -15,7 +15,7 @@ IMESH_INCLUDES = $(IMESH_CPPFLAGS)
 IMESH_LIBS = $(IMESH_LDFLAGS) -L$(MOAB_LIBDIR) \
              -L$(IMESH_LIBDIR) -liMesh -lMOAB \
              @NETCDF_LIBS@ @PNETCDF_LIBS@ @HDF5_LIBS@ @DAMSEL_LIBS@ @LIBS@ \
-             @CGM_LDFLAGS@ @CGM_LIBS@ @CCMIO_LIBS@
+             @CGM_LDFLAGS@ @CGM_LIBS@ @CCMIO_LIBS@ @ZOLTAN_LIBS@ 
 
 IMESH_INCLUDEDIR = @abs_srcdir@
 IMESH_INCLUDEDIR2 = -I at abs_builddir@ -I at abs_srcdir@/.. -I at abs_builddir@/.. -I at abs_top_builddir@/src

diff --git a/moab.make.in b/moab.make.in
index e6dc42d..45f80de 100644
--- a/moab.make.in
+++ b/moab.make.in
@@ -8,13 +8,15 @@ MOAB_INCLUDES = -I at abs_srcdir@/src \
                 -I at abs_srcdir@/src/parallel \
                 -I at abs_builddir@/src/parallel
 
+MOAB_INCLUDES += @ZOLTAN_INC_FLAGS@
+
 MOAB_CXXFLAGS = @CXXFLAGS@ @AM_CXXFLAGS@
 MOAB_CFLAGS = @CFLAGS@ @AM_CFLAGS@
 MOAB_FFLAGS = @FFLAGS@
 MOAB_FCFLAGS = @FCFLAGS@
 MOAB_LDFLAGS = @EXPORT_LDFLAGS@
 
-MOAB_LIBS_LINK = ${MOAB_LDFLAGS} -L${MOAB_LIBDIR} -lMOAB @LIBS@ @PNETCDF_LIBS@ @NETCDF_LIBS@ @HDF5_LIBS@ @CCMIO_LIBS@ @CGM_LIBS@
+MOAB_LIBS_LINK = ${MOAB_LDFLAGS} -L${MOAB_LIBDIR} -lMOAB @LIBS@ @PNETCDF_LIBS@ @NETCDF_LIBS@ @HDF5_LIBS@ @CCMIO_LIBS@ @CGM_LIBS@ @ZOLTAN_LIBS@ 
 
 MOAB_CXX = @CXX@
 MOAB_CC  = @CC@

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index 5f621d7..bc8da0f 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -306,7 +306,7 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
 
 ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
-  std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;;
+  std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;
   Interface*& mbImpl = _readNC->mbImpl;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
@@ -316,8 +316,11 @@ ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, s
   // Finally, read into that space
   int success;
   for (unsigned int i = 0; i < vdatas.size(); i++) {
-    if (dummyVarNames.find(vdatas[i].varName) != dummyVarNames.end() )
-       continue; // This is a dummy one, we don't have it; we created it for the dummy tag
+    // This is a dummy variable for a dimension with no corresponding coordinate variable
+    // No need to set its tag data
+    if (dummyVarNames.find(vdatas[i].varName) != dummyVarNames.end())
+       continue;
+
     for (unsigned int t = 0; t < tstep_nums.size(); t++) {
       void* data = vdatas[i].varDatas[t];
 
@@ -355,21 +358,20 @@ ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, s
 
       if (success)
         ERRORR(MB_FAILURE, "Trouble reading variable.");
-      if (vdatas[i].varDims.size() <= 1)
-        break;
-    }
-  }
 
-  for (unsigned int i = 0; i < vdatas.size(); i++) {
-    for (unsigned int t = 0; t < tstep_nums.size(); t++) {
       dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
-      ErrorCode tmp_rval = convert_variable(vdatas[i], t);
-      if (MB_SUCCESS != tmp_rval)
-        rval = tmp_rval;
+      rval = convert_variable(vdatas[i], t);
+      ERRORR(rval, "Failed to convert variable.");
+
+      dbgOut.tprintf(2, "Setting data for variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
+      rval = mbImpl->tag_set_by_ptr(vdatas[i].varTags[t], &_fileSet, 1, &(vdatas[i].varDatas[t]), &vdatas[i].sz);
+      ERRORR(rval, "Failed to set data for variable.");
+
       if (vdatas[i].varDims.size() <= 1)
         break;
     }
   }
+
   // Debug output, if requested
   if (1 == dbgOut.get_verbosity()) {
     dbgOut.printf(1, "Read variables: %s", vdatas.begin()->varName.c_str());
@@ -378,17 +380,6 @@ ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, s
     dbgOut.tprintf(1, "\n");
   }
 
-  for (unsigned int i = 0; i < vdatas.size(); i++) {
-    for (unsigned int t = 0; t < tstep_nums.size(); t++) {
-      dbgOut.tprintf(2, "Setting data for variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
-      ErrorCode tmp_rval = mbImpl->tag_set_by_ptr(vdatas[i].varTags[t], &_fileSet, 1, &(vdatas[i].varDatas[t]), &vdatas[i].sz);
-      if (MB_SUCCESS != tmp_rval)
-        rval = tmp_rval;
-      if (vdatas[i].varDims.size() <= 1)
-        break;
-    }
-  }
-
   return rval;
 }
 
@@ -652,7 +643,7 @@ ErrorCode NCHelper::create_attrib_string(const std::map<std::string, ReadNC::Att
   return MB_SUCCESS;
 }
 
-void NCHelper::init_dims_with_no_cvars_info()
+void NCHelper::init_dims_with_no_coord_vars_info()
 {
   std::vector<std::string>& dimNames = _readNC->dimNames;
   std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;
@@ -660,24 +651,23 @@ void NCHelper::init_dims_with_no_cvars_info()
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   // Hack: look at all dimensions, and see if we have one that does not appear in the list of varInfo names
-  // right now, candidates are ncol and nbnd
-  // for them, create dummy tags
-  for (unsigned int i = 0; i < dimNames.size(); i++)
-  {
-    // If there is a var with this name, skip, we are fine; if not, create a varInfo...
+  // Right now, candidates are from unstructured meshes, such as ncol(HOMME) and nCells(MPAS)
+  // For them, create dummy tags
+  for (unsigned int i = 0; i < dimNames.size(); i++) {
+    // If there is a variable with this dimension name, skip, we are fine; if not, create a dummy varInfo
     if (varInfo.find(dimNames[i]) != varInfo.end())
-      continue; // We already have a variable with this dimension name
+      continue;
 
     int sizeTotalVar = varInfo.size();
     std::string var_name(dimNames[i]);
-    ReadNC::VarData &data = varInfo[var_name];
+    ReadNC::VarData& data = varInfo[var_name];
     data.varName = std::string(var_name);
-    data.varId =sizeTotalVar;
+    data.varId = sizeTotalVar;
     data.varTags.resize(1, 0);
     data.varDataType = NC_DOUBLE; // Could be int, actually, but we do not really need the type
     data.varDims.resize(1);
-    data.varDims[0]= (int)i;
-    data.numAtts=0;
+    data.varDims[0] = (int)i;
+    data.numAtts = 0;
     data.entLoc = ReadNC::ENTLOCSET;
     dbgOut.tprintf(2, "Dummy varInfo created for dimension %s\n", dimNames[i].c_str());
     dummyVarNames.insert(dimNames[i]);
@@ -686,12 +676,23 @@ void NCHelper::init_dims_with_no_cvars_info()
 
 ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
+  std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;
   std::vector<int>& dimLens = _readNC->dimLens;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   ErrorCode rval = MB_SUCCESS;
 
   for (unsigned int i = 0; i < vdatas.size(); i++) {
+    // This is a dummy variable for a dimension with no corresponding coordinate variable
+    // No need to allocate memory to read it
+    if (dummyVarNames.find(vdatas[i].varName) != dummyVarNames.end()) {
+      if (!vdatas[i].varTags[0]) {
+        rval = get_tag_to_set(vdatas[i], 0, vdatas[i].varTags[0]);
+        ERRORR(rval, "Trouble getting dummy tag.");
+      }
+      continue;
+    }
+
     if ((std::find(vdatas[i].varDims.begin(), vdatas[i].varDims.end(), tDim) != vdatas[i].varDims.end()))
       vdatas[i].has_t = true;
 
@@ -710,15 +711,12 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
 
       // Set up the dimensions and counts
       // First variable dimension is time, if it exists
-      if (vdatas[i].has_t)
-      {
-        if (vdatas[i].varDims.size() != 1)
-        {
+      if (vdatas[i].has_t) {
+        if (vdatas[i].varDims.size() != 1) {
           vdatas[i].readStarts[t].push_back(tstep_nums[t]);
           vdatas[i].readCounts[t].push_back(1);
         }
-        else
-        {
+        else {
           vdatas[i].readStarts[t].push_back(0);
           vdatas[i].readCounts[t].push_back(tstep_nums.size());
         }
@@ -739,10 +737,12 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
           }
         }
       }
+
       std::size_t sz = 1;
       for (std::size_t idx = 0; idx != vdatas[i].readCounts[t].size(); idx++)
         sz *= vdatas[i].readCounts[t][idx];
       vdatas[i].sz = sz;
+
       switch (vdatas[i].varDataType) {
         case NC_BYTE:
         case NC_CHAR:
@@ -760,6 +760,7 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
           std::cerr << "Unrecognized data type for tag " << std::endl;
           rval = MB_FAILURE;
       }
+
       if (vdatas[i].varDims.size() <= 1)
         break;
     }
@@ -779,8 +780,7 @@ ErrorCode ScdNCHelper::check_existing_mesh() {
   /*
   // Check against parameters
   // When ghosting is used, this check might fail (to be updated later)
-  if (num_verts > 0)
-  {
+  if (num_verts > 0) {
     int expected_verts = (lDims[3] - lDims[0] + 1) * (lDims[4] - lDims[1] + 1) * (-1 == lDims[2] ? 1 : lDims[5] - lDims[2] + 1);
     if (num_verts != expected_verts) {
       ERRORR(MB_FAILURE, "Number of vertices doesn't match.");
@@ -796,8 +796,7 @@ ErrorCode ScdNCHelper::check_existing_mesh() {
   /*
   // Check against parameters
   // The expected number of elements calculated below is incorrect (to be updated later)
-  if (num_elems > 0)
-  {
+  if (num_elems > 0) {
     int expected_elems = (lDims[3] - lDims[0]) * (lDims[4] - lDims[1]) * (-1 == lDims[2] ? 1 : lDims[5] - lDims[2]);
     if (num_elems != expected_elems) {
       ERRORR(MB_FAILURE, "Number of elements doesn't match.");
@@ -990,6 +989,7 @@ ErrorCode ScdNCHelper::read_scd_variable_setup(std::vector<std::string>& var_nam
       vdatas[i].readStarts.resize(tstep_nums.size());
       vdatas[i].readCounts.resize(tstep_nums.size());
     }
+
     for (unsigned int i = 0; i < vsetdatas.size(); i++) {
       if ((std::find(vsetdatas[i].varDims.begin(), vsetdatas[i].varDims.end(), tDim) != vsetdatas[i].varDims.end())
           && (vsetdatas[i].varDims.size() != 1)) {

diff --git a/src/io/NCHelper.hpp b/src/io/NCHelper.hpp
index 4982b4c..f3d1875 100644
--- a/src/io/NCHelper.hpp
+++ b/src/io/NCHelper.hpp
@@ -58,9 +58,9 @@ protected:
                                  std::string& attString,
                                  std::vector<int>& attLen);
 
-  //! Init info for dimensions that don't have corresponding
-  //! coordinate variables - this info is used for creating tags
-  void init_dims_with_no_cvars_info();
+  //! Initialize information for dimensions that don't have corresponding
+  //! coordinate variables - this information is used for creating dummy tags
+  void init_dims_with_no_coord_vars_info();
 
 private:
   //! Used by read_variable_to_set()

diff --git a/src/io/NCHelperEuler.cpp b/src/io/NCHelperEuler.cpp
index ca86127..48056c6 100644
--- a/src/io/NCHelperEuler.cpp
+++ b/src/io/NCHelperEuler.cpp
@@ -328,18 +328,28 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       vd.entLoc = ReadNC::ENTLOCFACE;
   }
 
-  std::vector<std::string> ijdimNames(2);
-  ijdimNames[0] = "__lon";
-  ijdimNames[1] = "__lat";
+  // For Eul models, slon and slat are "virtual" dimensions (not defined in the file header)
+  std::vector<std::string> ijdimNames(4);
+  ijdimNames[0] = "__slon";
+  ijdimNames[1] = "__slat";
+  ijdimNames[2] = "__lon";
+  ijdimNames[3] = "__lat";
 
-  std::stringstream ss_tag_name;
   std::string tag_name;
   Tag tagh;
 
-  // __<dim_name>_LOC_MINMAX (for lon and lat)
+  // __<dim_name>_LOC_MINMAX (for virtual slon, virtual slat, lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
     std::vector<int> val(2, 0);
-    if (ijdimNames[i] == "__lon") {
+    if (ijdimNames[i] == "__slon") {
+      val[0] = lDims[0];
+      val[1] = lDims[3];
+    }
+    else if (ijdimNames[i] == "__slat") {
+      val[0] = lDims[1];
+      val[1] = lDims[4];
+    }
+    else if (ijdimNames[i] == "__lon") {
       val[0] = lCDims[0];
       val[1] = lCDims[3];
     }
@@ -347,7 +357,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       val[0] = lCDims[1];
       val[1] = lCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -358,11 +368,19 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // __<dim_name>_LOC_VALS (for lon and lat)
+  // __<dim_name>_LOC_VALS (for virtual slon, virtual slat, lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
     void* val = NULL;
     int val_len = 0;
-    if (ijdimNames[i] == "__lon") {
+    if (ijdimNames[i] == "__slon") {
+      val = &ilVals[0];
+      val_len = ilVals.size();
+    }
+    else if (ijdimNames[i] == "__slat") {
+      val = &jlVals[0];
+      val_len = jlVals.size();
+    }
+    else if (ijdimNames[i] == "__lon") {
       val = &ilCVals[0];
       val_len = ilCVals.size();
     }
@@ -392,7 +410,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
         ERRORR(MB_FAILURE, "Unrecognized data type");
         break;
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_VALS";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
@@ -403,10 +421,18 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // __<dim_name>_GLOBAL_MINMAX (for lon and lat)
+  // __<dim_name>_GLOBAL_MINMAX (for virtual slon, virtual slat, lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
     std::vector<int> val(2, 0);
-    if (ijdimNames[i] == "__lon") {
+    if (ijdimNames[i] == "__slon") {
+      val[0] = gDims[0];
+      val[1] = gDims[3];
+    }
+    else if (ijdimNames[i] == "__slat") {
+      val[0] = gDims[1];
+      val[1] = gDims[4];
+    }
+    else if (ijdimNames[i] == "__lon") {
       val[0] = gCDims[0];
       val[1] = gCDims[3];
     }
@@ -414,7 +440,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       val[0] = gCDims[1];
       val[1] = gCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -425,8 +451,8 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // Hack: create dummy tags, if needed, for variables with no corresponding variables
-  init_dims_with_no_cvars_info();
+  // Hack: create dummy tags, if needed, for dimensions with no corresponding coordinate variables
+  init_dims_with_no_coord_vars_info();
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperFV.cpp b/src/io/NCHelperFV.cpp
index a234450..253d598 100644
--- a/src/io/NCHelperFV.cpp
+++ b/src/io/NCHelperFV.cpp
@@ -336,7 +336,6 @@ ErrorCode NCHelperFV::init_mesh_vals()
   ijdimNames[2] = "__lon";
   ijdimNames[3] = "__lat";
 
-  std::stringstream ss_tag_name;
   std::string tag_name;
   Tag tagh;
 
@@ -359,7 +358,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
       val[0] = lCDims[1];
       val[1] = lCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -412,7 +411,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
         ERRORR(MB_FAILURE, "Unrecognized data type");
         break;
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_VALS";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
@@ -442,7 +441,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
       val[0] = gCDims[1];
       val[1] = gCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -453,8 +452,8 @@ ErrorCode NCHelperFV::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // Hack: create dummy tags, if needed, for dimensions with no corresponding variables
-  init_dims_with_no_cvars_info();
+  // Hack: create dummy tags, if needed, for dimensions with no corresponding coordinate variables
+  init_dims_with_no_coord_vars_info();
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index f750e78..154d61d 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -160,8 +160,8 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
       vd.entLoc = ReadNC::ENTLOCVERT;
   }
 
-  // Hack: create dummy tags, if needed, for variables with no corresponding variables
-  init_dims_with_no_cvars_info();
+  // Hack: create dummy tags for dimensions (like ncol) with no corresponding coordinate variables
+  init_dims_with_no_coord_vars_info();
 
   return MB_SUCCESS;
 }
@@ -548,6 +548,7 @@ ErrorCode NCHelperHOMME::read_ucd_variable_setup(std::vector<std::string>& var_n
       vdatas[i].readStarts.resize(tstep_nums.size());
       vdatas[i].readCounts.resize(tstep_nums.size());
     }
+
     for (unsigned int i = 0; i < vsetdatas.size(); i++) {
       if ((std::find(vsetdatas[i].varDims.begin(), vsetdatas[i].varDims.end(), tDim) != vsetdatas[i].varDims.end())
           && (vsetdatas[i].varDims.size() != 1)) {

This diff is so big that we needed to truncate the remainder.

https://bitbucket.org/fathomteam/moab/commits/867f67519d8d/
Changeset:   867f67519d8d
Branch:      None
User:        iulian07
Date:        2013-11-05 16:39:05
Summary:     Merge branch 'master' of bitbucket.org:iulian07/moab

Affected #:  0 files



https://bitbucket.org/fathomteam/moab/commits/179eecc7de20/
Changeset:   179eecc7de20
Branch:      None
User:        iulian07
Date:        2013-11-05 18:27:41
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  1 file

diff --git a/src/parallel/ParallelComm.cpp b/src/parallel/ParallelComm.cpp
index efc4fa1..7c3f5c7 100644
--- a/src/parallel/ParallelComm.cpp
+++ b/src/parallel/ParallelComm.cpp
@@ -8738,7 +8738,7 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
     int sz_buffer = sizeof(int) + gather_ents.size()*(sizeof(int) + bytes_per_tag);
     void* senddata = malloc(sz_buffer);
     ((int*)senddata)[0] = (int) gather_ents.size();    
-    int * ptr_int = (int*)senddata + 1;
+    int* ptr_int = (int*)senddata + 1;
     rval = mbImpl->tag_get_data(id_tag, gather_ents, (void*)ptr_int);
     ptr_int = (int*)(senddata) + 1 + gather_ents.size();
     rval = mbImpl->tag_get_data(tag_handle, gather_ents, (void*)ptr_int);
@@ -8762,15 +8762,22 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
       MPI_Gatherv(senddata, sz_buffer, MPI_BYTE, recvbuf, &recvcnts[0], &displs[0], MPI_BYTE, 0, comm());
 
       void* gvals = NULL;
-      // If gents is contiguous, gathered values will be directly copied to its tag space
-      if (gents.psize() == 1) {
+
+      // Test whether gents has multiple sequences
+      bool multiple_sequences = false;
+      if (gents.psize() > 1)
+        multiple_sequences = true;
+      else {
         int count;
         rval = mbImpl->tag_iterate(tag_handle, gents.begin(), gents.end(), count, gvals);
         assert(NULL != gvals);
-        assert(count == (int)gents.size());
+        assert(count > 0);
+        if ((size_t)count != gents.size())
+          multiple_sequences = true;
       }
-      // If gents is not contiguous, gathered values will be copied to a temp buffer first
-      else if (gents.psize() > 1) {
+
+      // If gents has multiple sequences, create a temp buffer for gathered values
+      if (multiple_sequences) {
         gvals = new (std::nothrow) char[gents.size() * bytes_per_tag];
         assert(NULL != gvals);
       }
@@ -8785,16 +8792,17 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
         }
       }
 
-      // If gents is not contiguous, set tag data (stored in the temp buffer) on each sequence separately
-      if (gents.psize() > 1) {
+      // If gents has multiple sequences, copy tag data (stored in the temp buffer) to each sequence separately
+      if (multiple_sequences) {
         Range::iterator iter = gents.begin();
         size_t start_idx = 0;
         while (iter != gents.end()) {
           int count;
           void* ptr;
           rval = mbImpl->tag_iterate(tag_handle, iter, gents.end(), count, ptr);
-          for (int i = 0; i < count; i++)
-            ((char*)ptr)[i] = ((char*)gvals)[start_idx + i];
+          assert(NULL != ptr);
+          assert(count > 0);
+          memcpy((char*)ptr, (char*)gvals + start_idx * bytes_per_tag, bytes_per_tag * count);
 
           iter += count;
           start_idx += count;
@@ -8802,7 +8810,7 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
         assert(start_idx == gents.size());
 
         // Delete the temp buffer
-        delete (char*)gvals;
+        delete[] (char*)gvals;
       }
     }
 


https://bitbucket.org/fathomteam/moab/commits/191f4aee35fa/
Changeset:   191f4aee35fa
Branch:      None
User:        iulian07
Date:        2013-11-05 19:17:03
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  1 file

diff --git a/test/io/read_mpas_nc.cpp b/test/io/read_mpas_nc.cpp
index 5ceb994..d6e886f 100644
--- a/test/io/read_mpas_nc.cpp
+++ b/test/io/read_mpas_nc.cpp
@@ -1,6 +1,7 @@
 #include "TestUtil.hpp"
 #include "moab/Core.hpp"
 #include "moab/ReadUtilIface.hpp"
+#include "MBTagConventions.hpp"
 
 using namespace moab;
 
@@ -20,7 +21,9 @@ void test_read_onevar();
 void test_read_onetimestep();
 void test_read_nomesh();
 void test_read_novars();
-void test_read_no_mixed_elements();
+void test_read_no_mixed_elements(); // Test read option NO_MIXED_ELEMENTS
+void test_read_no_edges(); // Test read option NO_EDGES
+void test_gather_onevar(); // Test gather set with one variable
 
 ErrorCode get_options(std::string& opts);
 
@@ -41,8 +44,9 @@ int main(int argc, char* argv[])
   result += RUN_TEST(test_read_onetimestep);
   result += RUN_TEST(test_read_nomesh);
   result += RUN_TEST(test_read_novars);
-  // Test read option NO_MIXED_ELEMENTS
   result += RUN_TEST(test_read_no_mixed_elements);
+  result += RUN_TEST(test_read_no_edges);
+  result += RUN_TEST(test_gather_onevar);
 
 #ifdef USE_MPI
   fail = MPI_Finalize();
@@ -163,8 +167,6 @@ void test_read_onevar()
   CHECK_ERR(rval);
 
   opts += std::string(";VARIABLE=ke");
-  // Create gather set
-  opts += std::string(";GATHER_SET=");
   rval = mb.load_file(example, NULL, opts.c_str());
   CHECK_ERR(rval);
 
@@ -187,38 +189,15 @@ void test_read_onevar()
     Range cells;
     rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
     assert(rval == MB_SUCCESS);
-    CHECK_EQUAL((size_t)1284, cells.size()); // Gather set cells included
-#ifdef USE_MPI
-    // If MOAB is compiled parallel, sequence size requested are increased
-    // by a factor of 1.5, to allow for ghosts. This will introduce a gap
-    // between the two face sequences.
-    CHECK_EQUAL((size_t)4, cells.psize()); // Gather set cells included
-#else
-    CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included
-#endif
-
-    // 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);
+    CHECK_EQUAL((size_t)642, cells.size());
 
-    // Remove gather set cells
-    cells = subtract(cells, gather_ents);
-    CHECK_EQUAL((size_t)642, cells.size()); // Gather set cells excluded
 #ifdef USE_MPI
     // If MOAB is compiled parallel, sequence size requested are increased
     // by a factor of 1.5, to allow for ghosts. This will introduce a gap
     // between the two face sequences.
-    CHECK_EQUAL((size_t)2, cells.psize()); // Gather set cells excluded
+    CHECK_EQUAL((size_t)2, cells.psize());
 #else
-    CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded
+    CHECK_EQUAL((size_t)1, cells.psize());
 #endif
 
     // Check ke tag values on first pentagon and first hexagon
@@ -368,7 +347,8 @@ void test_read_no_mixed_elements()
     rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
     assert(rval == MB_SUCCESS);
     CHECK_EQUAL((size_t)642, cells.size());
-    // Only one group of cells (each cell is actually represented by a 10-vertex polygon)
+    // Only one group of cells (pentagons are padded to hexagons,
+    // e.g. connectivity [1 2 3 4 5] => [1 2 3 4 5 5])
     CHECK_EQUAL((size_t)1, cells.psize());
 
     const double eps = 1e-20;
@@ -385,7 +365,104 @@ void test_read_no_mixed_elements()
   }
 }
 
-ErrorCode get_options(std::string &opts) 
+void test_read_no_edges()
+{
+  Core moab;
+  Interface& mb = moab;
+  std::string opts;
+  ErrorCode rval = get_options(opts);
+  CHECK_ERR(rval);
+
+  opts += std::string(";NO_EDGES;VARIABLE=");
+  rval = mb.load_file(example, NULL, 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
+
+  // Make check runs this test in one processor
+  if (1 == procs) {
+    // Get edges
+    Range edges;
+    rval = mb.get_entities_by_type(0, MBEDGE, edges);
+    assert(rval == MB_SUCCESS);
+    CHECK_EQUAL((size_t)0, edges.size());
+  }
+}
+
+void test_gather_onevar()
+{
+  Core moab;
+  Interface& mb = moab;
+  std::string opts;
+  ErrorCode rval = get_options(opts);
+  CHECK_ERR(rval);
+
+  EntityHandle file_set;
+  rval = mb.create_meshset(MESHSET_SET, file_set);
+  CHECK_ERR(rval);
+
+  // Get cell variable ke
+  opts += std::string(";VARIABLE=ke;");
+  // Create gather set
+  opts += std::string(";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 procs = pcomm->proc_config().proc_size();
+
+  // Make check runs this test in one processor
+  if (1 == procs) {
+    Range cells, cells_owned;
+    rval = mb.get_entities_by_type(file_set, MBPOLYGON, cells);
+    CHECK_ERR(rval);
+
+    // Get locally owned cells
+    rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &cells_owned);
+    CHECK_ERR(rval);
+    CHECK_EQUAL((size_t)642, cells_owned.size());
+    CHECK_EQUAL((size_t)2, cells_owned.psize());
+
+    // Get gather set
+    EntityHandle gather_set;
+    ReadUtilIface* readUtilIface;
+    mb.query_interface(readUtilIface);
+    rval = readUtilIface->get_gather_set(gather_set);
+    CHECK_ERR(rval);
+
+    Tag ke_tag0, gid_tag;
+    rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0, 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(cells_owned, ke_tag0, gid_tag, gather_set);
+
+    // Get gather set cells
+    Range gather_set_cells;
+    rval = mb.get_entities_by_type(gather_set, MBPOLYGON, gather_set_cells);
+    CHECK_EQUAL((size_t)642, gather_set_cells.size());
+    CHECK_EQUAL((size_t)2, gather_set_cells.psize());
+
+    const double eps = 1e-20;
+    double val[2];
+
+    // Check ke0 tag values on first pentagon and first hexagon of the gather set cells
+    EntityHandle cell_ents[] = {gather_set_cells[0], gather_set_cells[12]};
+    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
+    CHECK_REAL_EQUAL(15.001, val[0], eps);
+    CHECK_REAL_EQUAL(16.013, val[1], eps);
+  }
+#endif
+}
+
+ErrorCode get_options(std::string& opts)
 {
 #ifdef USE_MPI
   // Use parallel options


https://bitbucket.org/fathomteam/moab/commits/6eee55f31a88/
Changeset:   6eee55f31a88
Branch:      None
User:        iulian07
Date:        2013-11-06 18:22:36
Summary:     build processor boxes in a separate method

it will be used for transport problem before starting communicating the
departure mesh to other procs

Affected #:  2 files

diff --git a/tools/mbcslam/Intx2Mesh.cpp b/tools/mbcslam/Intx2Mesh.cpp
index d9db131..3e62b72 100644
--- a/tools/mbcslam/Intx2Mesh.cpp
+++ b/tools/mbcslam/Intx2Mesh.cpp
@@ -1051,41 +1051,20 @@ ErrorCode Intx2Mesh::create_departure_mesh(EntityHandle & covering_lagr_set)
 
   return MB_SUCCESS;
 }
-
-ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, EntityHandle & covering_lagr_set)
+ErrorCode Intx2Mesh::build_processor_euler_boxes(Range & local_verts)
 {
-  // compute the bounding box on each proc
   parcomm = ParallelComm::get_pcomm(mb, 0);
   if (NULL==parcomm)
     return MB_FAILURE;
-
-  localEnts.clear();
-  ErrorCode rval = mb->get_entities_by_dimension(euler_set, 2, localEnts);
-  ERRORR(rval, "can't get ents by dimension");
-
-  Tag dpTag = 0;
-  std::string tag_name("DP");
-  rval = mb->tag_get_handle(tag_name.c_str(), 3, MB_TYPE_DOUBLE, dpTag, MB_TAG_DENSE);
-  ERRORR(rval, "can't get DP tag");
-  // get all local verts
-  Range local_verts;
-  rval = mb->get_connectivity(localEnts, local_verts);
   int num_local_verts = (int) local_verts.size();
-  ERRORR(rval, "can't get local vertices");
-
-  Tag gid;
-  rval = mb->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid, MB_TAG_DENSE);
-  ERRORR(rval,"can't get global ID tag" );
-  std::vector<int> gids(num_local_verts);
-  rval = mb->tag_get_data(gid, local_verts, &gids[0]);
-  ERRORR(rval, "can't get local vertices gids");
 
   // get the position of local vertices, and decide local boxes (allBoxes...)
   double bmin[3]={DBL_MAX, DBL_MAX, DBL_MAX};
   double bmax[3] ={-DBL_MAX, -DBL_MAX, -DBL_MAX};
 
   std::vector<double> coords(3*num_local_verts);
-  rval = mb->get_coords(local_verts, &coords[0]);
+  ErrorCode rval = mb->get_coords(local_verts, &coords[0]);
+  ERRORR(rval, "can't get coords of vertices ");
 
   for (int i=0; i< num_local_verts; i++)
   {
@@ -1124,14 +1103,46 @@ ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, Ent
     }
   }
 
+  return MB_SUCCESS;
+}
+ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, EntityHandle & covering_lagr_set)
+{
+  // compute the bounding box on each proc
+  parcomm = ParallelComm::get_pcomm(mb, 0);
+  if (NULL==parcomm)
+    return MB_FAILURE;
+
+  localEnts.clear();
+  ErrorCode rval = mb->get_entities_by_dimension(euler_set, 2, localEnts);
+  ERRORR(rval, "can't get ents by dimension");
+
+  Tag dpTag = 0;
+  std::string tag_name("DP");
+  rval = mb->tag_get_handle(tag_name.c_str(), 3, MB_TYPE_DOUBLE, dpTag, MB_TAG_DENSE);
+  ERRORR(rval, "can't get DP tag");
+  // get all local verts
+  Range local_verts;
+  rval = mb->get_connectivity(localEnts, local_verts);
+  int num_local_verts = (int) local_verts.size();
+  ERRORR(rval, "can't get local vertices");
+
+  rval = build_processor_euler_boxes(local_verts);
+  ERRORR(rval, "can't build processor boxes");
+  Tag gid;
+  rval = mb->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid, MB_TAG_DENSE);
+  ERRORR(rval,"can't get global ID tag" );
+  std::vector<int> gids(num_local_verts);
+  rval = mb->tag_get_data(gid, local_verts, &gids[0]);
+  ERRORR(rval, "can't get local vertices gids");
 
   // now see the departure points; to what boxes should we send them?
   std::vector<double> dep_points(3*num_local_verts);
   rval = mb->tag_get_data(dpTag, local_verts, (void*)&dep_points[0]);
   ERRORR(rval, "can't get DP tag values");
   // ranges to send to each processor; will hold vertices and elements (quads?)
-  // will look if the box of the dep quad covers box of of euler mesh on proc (with tolerances)
+  // will look if the box of the dep quad covers box of euler mesh on proc (with tolerances)
   std::map<int, Range> Rto;
+  int numprocs=parcomm->proc_config().proc_size();
 
   for (Range::iterator eit = localEnts.begin(); eit!=localEnts.end(); eit++)
   {

diff --git a/tools/mbcslam/Intx2Mesh.hpp b/tools/mbcslam/Intx2Mesh.hpp
index 21e56e4..8c8ad6e 100644
--- a/tools/mbcslam/Intx2Mesh.hpp
+++ b/tools/mbcslam/Intx2Mesh.hpp
@@ -91,6 +91,8 @@ public:
 
   ErrorCode create_departure_mesh_2nd_alg(EntityHandle & euler_set, EntityHandle & covering_lagr_set);
 
+  ErrorCode build_processor_euler_boxes(Range & local_verts);
+
   void correct_polygon(EntityHandle * foundIds, int & nP);
 
   ErrorCode correct_intersection_points_positions();


https://bitbucket.org/fathomteam/moab/commits/8777019f9b73/
Changeset:   8777019f9b73
Branch:      None
User:        iulian07
Date:        2013-11-06 23:07:32
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  1 file

diff --git a/src/AEntityFactory.cpp b/src/AEntityFactory.cpp
index 08ddb00..e29df97 100644
--- a/src/AEntityFactory.cpp
+++ b/src/AEntityFactory.cpp
@@ -65,7 +65,7 @@ AEntityFactory::~AEntityFactory()
   EntityType ent_type;
 
   // iterate through each element type
-  for (ent_type = MBVERTEX; ent_type != MBENTITYSET; ent_type++) {
+  for (ent_type = MBVERTEX; ent_type <= MBENTITYSET; ent_type++) {
     TypeSequenceManager::iterator i;
     TypeSequenceManager& seqman = thisMB->sequence_manager()->entity_map( ent_type );
     for (i = seqman.begin(); i != seqman.end(); ++i) {


https://bitbucket.org/fathomteam/moab/commits/7521bf054d37/
Changeset:   7521bf054d37
Branch:      None
User:        iulian07
Date:        2013-11-08 17:58:50
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  7 files

diff --git a/configure.ac b/configure.ac
index 937385d..bdc225b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -698,7 +698,7 @@ if test "xyes" = "x$WITH_ZOLTAN"; then
                   [#include <stdlib.h>])
   CPPFLAGS="$old_CPPFLAGS"
   AC_LANG_POP([C++])
-  
+
     # Build LDFLAGS for Zoltan
   found=no
   if test "x" != "x$ZOLTAN_DIR"; then
@@ -720,7 +720,7 @@ if test "xyes" = "x$WITH_ZOLTAN"; then
       ZOLTAN_LIB_FLAGS="$ZOLTAN_LIB_FLAGS -L$ZOLTAN_DIR"
     fi
   fi
-  
+
     # Test for Zoltan library, possibly requiring parmetis
   old_LDFLAGS="$LDFLAGS"
   LDFLAGS="$LDFLAGS $ZOLTAN_LIB_FLAGS"
@@ -731,7 +731,9 @@ if test "xyes" = "x$WITH_ZOLTAN"; then
                   [AC_MSG_ERROR([zoltan library not found or not usable.  Perhaps you need to specify --with-parmetis=@<:@DIR@:>@?])],
                   [-lparmetis -lmetis])])
   LDFLAGS="$old_LDFLAGS"
-  
+
+    # Define macro HAVE_ZOLTAN
+  AM_CPPFLAGS="$AM_CPPFLAGS -DHAVE_ZOLTAN"  
 fi
 
 AC_SUBST(ZOLTAN_LIBS)

diff --git a/src/Makefile.am b/src/Makefile.am
index 3a86984..64b8a0f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,7 +28,6 @@ AM_CPPFLAGS += -DIS_BUILDING_MB \
 # The directory in which to install headers
 libMOAB_la_includedir = $(includedir)
 
-
 # The list of source files, and any header files that do not need to be installed
 libMOAB_la_SOURCES = \
   AdaptiveKDTree.cpp \
@@ -205,23 +204,24 @@ nobase_libMOAB_la_include_HEADERS = \
   MOAB_FCDefs.h \
   MBCN_protos.h \
   MBTagConventions.hpp
+
 if ENABLE_mbzoltan
   libMOAB_la_SOURCES += $(srcdir)/../tools/mbzoltan/MBZoltan.cpp
   nobase_libMOAB_la_include_HEADERS += $(srcdir)/../tools/mbzoltan/MBZoltan.hpp
-  AM_CPPFLAGS +=  $(ZOLTAN_INC_FLAGS) -DHAVE_ZOLTAN
+  AM_CPPFLAGS += $(ZOLTAN_INC_FLAGS)
   # not sure yet if this is needed; will see when linking io reader (MPAS so far)
   # the tool mbpart needed it, and it just includes MBZoltan.hpp; so it needs ways to find 
   # the libraries zoltan depends on
   libMOAB_la_LIBADD += $(ZOLTAN_LIBS) $(ZOLTAN_LIB_FLAGS)
 endif
+
 if HAVE_CGM
   AM_CPPFLAGS += @CGM_CPPFLAGS@ -DCGM @MOAB_CGM_DEFINES@
 endif
-  
+
 MBCN_protos.h: MBCN.h $(top_srcdir)/itaps/mkprotos.sh
 	$(AM_V_GEN)$(top_srcdir)/itaps/mkprotos.sh MBCN MOAB $< $@ MOAB_FCDefs.h
 
-
 MOAB_FCDefs.h: FCDefs.h
 	$(AM_V_GEN)cd .. && ./config.status src/MOAB_FCDefs.h
 

diff --git a/src/io/Makefile.am b/src/io/Makefile.am
index 968f47f..60caa48 100644
--- a/src/io/Makefile.am
+++ b/src/io/Makefile.am
@@ -40,8 +40,9 @@ endif
 endif
 
 if ENABLE_mbzoltan
-  AM_CPPFLAGS += -DHAVE_ZOLTAN -I$(srcdir)/../../tools/mbzoltan $(ZOLTAN_INC_FLAGS) 
+  AM_CPPFLAGS += -I$(srcdir)/../../tools/mbzoltan $(ZOLTAN_INC_FLAGS) 
 endif
+
 if HDF5_FILE
   libmoabio_la_LIBADD += mhdf/libmhdf.la
   MOAB_HDF5_SRCS = HDF5Common.cpp \
@@ -58,6 +59,7 @@ if HDF5_FILE
 else
   MOAB_HDF5_SRCS = 
 endif
+
 if CCMIO_FILE
   MOAB_CCMIO_SRCS = WriteCCMIO.cpp WriteCCMIO.hpp ReadCCMIO.cpp ReadCCMIO.hpp
   libmoabio_la_LIBADD += $(CCMIO_LIBS)
@@ -142,7 +144,5 @@ libmoabio_la_SOURCES = \
   $(MOAB_DAMSEL_SRCS) \
   $(MOAB_CGM_SRCS)
 
-
 libmoabio_la_includedir = $(includedir)
 nobase_libmoabio_la_include_HEADERS = moab/ExoIIInterface.hpp
-

diff --git a/src/parallel/ParallelComm.cpp b/src/parallel/ParallelComm.cpp
index 7c3f5c7..8efc777 100644
--- a/src/parallel/ParallelComm.cpp
+++ b/src/parallel/ParallelComm.cpp
@@ -8728,7 +8728,7 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
   }
 
   ErrorCode ParallelComm::gather_data(Range &gather_ents, Tag &tag_handle, 
-				      Tag id_tag, EntityHandle gather_set) 
+				      Tag id_tag, EntityHandle gather_set, int root_proc_rank)
   {
     int dim = mbImpl->dimension_from_handle(*gather_ents.begin());
     int bytes_per_tag = 0;
@@ -8743,7 +8743,7 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
     ptr_int = (int*)(senddata) + 1 + gather_ents.size();
     rval = mbImpl->tag_get_data(tag_handle, gather_ents, (void*)ptr_int);
     std::vector<int> displs(proc_config().proc_size(), 0);
-    MPI_Gather(&sz_buffer, 1, MPI_INT, &displs[0], 1, MPI_INT, 0, comm());
+    MPI_Gather(&sz_buffer, 1, MPI_INT, &displs[0], 1, MPI_INT, root_proc_rank, comm());
     std::vector<int> recvcnts(proc_config().proc_size(), 0);
     std::copy(displs.begin(), displs.end(), recvcnts.begin());
     std::partial_sum(displs.begin(), displs.end(), displs.begin());
@@ -8752,14 +8752,14 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
     //std::copy_backward(displs.begin(), --displs.end(), displs.end());
     displs[0] = 0;
 
-    if (rank() != 0)
-      MPI_Gatherv(senddata, sz_buffer, MPI_BYTE, NULL, NULL, NULL, MPI_BYTE, 0, comm());
+    if ((int)rank() != root_proc_rank)
+      MPI_Gatherv(senddata, sz_buffer, MPI_BYTE, NULL, NULL, NULL, MPI_BYTE, root_proc_rank, comm());
     else {
       Range gents;
       mbImpl->get_entities_by_dimension(gather_set, dim, gents);
       int recvbuffsz = gents.size() * (bytes_per_tag + sizeof(int)) + proc_config().proc_size() * sizeof(int);
       void* recvbuf = malloc(recvbuffsz);
-      MPI_Gatherv(senddata, sz_buffer, MPI_BYTE, recvbuf, &recvcnts[0], &displs[0], MPI_BYTE, 0, comm());
+      MPI_Gatherv(senddata, sz_buffer, MPI_BYTE, recvbuf, &recvcnts[0], &displs[0], MPI_BYTE, root_proc_rank, comm());
 
       void* gvals = NULL;
 
@@ -8772,13 +8772,15 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
         rval = mbImpl->tag_iterate(tag_handle, gents.begin(), gents.end(), count, gvals);
         assert(NULL != gvals);
         assert(count > 0);
-        if ((size_t)count != gents.size())
+        if ((size_t)count != gents.size()) {
           multiple_sequences = true;
+          gvals = NULL;
+        }
       }
 
       // If gents has multiple sequences, create a temp buffer for gathered values
       if (multiple_sequences) {
-        gvals = new (std::nothrow) char[gents.size() * bytes_per_tag];
+        gvals = malloc(gents.size() * bytes_per_tag);
         assert(NULL != gvals);
       }
 
@@ -8809,8 +8811,8 @@ ErrorCode ParallelComm::post_irecv(std::vector<unsigned int>& shared_procs,
         }
         assert(start_idx == gents.size());
 
-        // Delete the temp buffer
-        delete[] (char*)gvals;
+        // Free the temp buffer
+        free(gvals);
       }
     }
 

diff --git a/src/parallel/moab/ParallelComm.hpp b/src/parallel/moab/ParallelComm.hpp
index e02d4b3..e4217ce 100644
--- a/src/parallel/moab/ParallelComm.hpp
+++ b/src/parallel/moab/ParallelComm.hpp
@@ -899,7 +899,7 @@ namespace moab {
     //! get the verbosity level of output from this pcomm
     int get_debug_verbosity();
 
-    /* \brief Gather tag value from entities down to root proc
+    /* \brief Gather tag value from entities down to a specified root proc
      * This function gathers data from a domain-decomposed mesh onto a global mesh
      * represented on the root processor.  On the root, this gather mesh is distinct from
      * the root's domain-decomposed subdomain.  Entities are matched by global id, or by
@@ -910,9 +910,10 @@ namespace moab {
      * \param tag_handle Tag whose values are being gathered
      * \param id_tag Tag to use for matching entities (global id used by default)
      * \param gather_set On root, set containing global mesh onto which to put data
+     * \param root_proc_rank Rank of the specified root processor (default rank is 0)
      */
     ErrorCode gather_data(Range &gather_ents, Tag &tag_handle, 
-			  Tag id_tag = 0, EntityHandle gather_set = 0);
+			  Tag id_tag = 0, EntityHandle gather_set = 0, int root_proc_rank = 0);
 
     /* \brief communicate extra points positions on boundary
      * This function is called after intersection of 2 meshes, to settle the

diff --git a/test/parallel/Makefile.am b/test/parallel/Makefile.am
index d611c7b..6dd3207 100644
--- a/test/parallel/Makefile.am
+++ b/test/parallel/Makefile.am
@@ -11,14 +11,13 @@ AM_CPPFLAGS += -DIS_BUILDING_MB \
                -I$(top_srcdir)/src \
                -I$(top_srcdir)/src/parallel \
                -I$(top_srcdir)/src/io/mhdf/include
-               
+
 if ENABLE_mbcoupler
   AM_CPPFLAGS += -I$(top_srcdir)/tools/mbcoupler \
                  -I$(top_srcdir)/itaps \
                  -I$(top_srcdir)/itaps/imesh \
                  -I$(top_builddir)/itaps/imesh \
-                 -I$(top_srcdir)/src/moab/point_locater/lotte 
-  
+                 -I$(top_srcdir)/src/moab/point_locater/lotte
 endif
 
 if ENABLE_mbcslam

diff --git a/test/parallel/mpastrvpart.cpp b/test/parallel/mpastrvpart.cpp
index 24f0b9b..7ff375a 100644
--- a/test/parallel/mpastrvpart.cpp
+++ b/test/parallel/mpastrvpart.cpp
@@ -4,6 +4,9 @@
 #include "moab/ProgOptions.hpp"
 #include "MBParallelConventions.h"
 #include "moab/ReadUtilIface.hpp"
+#include "MBTagConventions.hpp"
+
+#include <sstream>
 
 using namespace moab;
 
@@ -11,26 +14,57 @@ using namespace moab;
 static const char example[] = STRINGIFY(MESHDIR) "/io/mpasx1.642.t.2.nc";
 #endif
 
-void test_read_parallel_mpas_trivial();
-void test_read_parallel_mpas_trivial_no_mixed_elements();
-void test_read_parallel_mpas_rcbzoltan();
-void test_read_parallel_mpas_rcbzoltan_no_mixed_elements();
-void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges,
-                        int num_cells, bool test_nb_cells, bool mixed_elements);
+void test_read_onevar_trivial();
+void test_read_onevar_trivial_no_mixed_elements();
+#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+void test_read_onevar_rcbzoltan();
+void test_read_onevar_rcbzoltan_no_mixed_elements();
+#endif
+
+void test_read_mesh_parallel_trivial();
+void test_read_mesh_parallel_trivial_no_mixed_elements();
+#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+void test_read_mesh_parallel_rcbzoltan();
+void test_read_mesh_parallel_rcbzoltan_no_mixed_elements();
+#endif
+
+void test_gather_onevar_on_rank0();
+void test_gather_onevar_on_rank1();
+
 void test_multiple_loads_of_same_file();
 void test_multiple_loads_of_same_file_no_mixed_elements();
 
-std::string partition_method;
+// Helper functions
+void read_one_cell_var(bool rcbzoltan, bool no_mixed_elements);
+void read_mesh_parallel(bool rcbzoltan, bool no_mixed_elements);
+void gather_one_cell_var(int gather_set_rank);
+void multiple_loads_of_same_file(bool no_mixed_elements);
+
+std::string read_options;
+const double eps = 1e-20;
 
 int main(int argc, char* argv[])
 {
   MPI_Init(&argc, &argv);
   int result = 0;
 
-  result += RUN_TEST(test_read_parallel_mpas_trivial);
-  result += RUN_TEST(test_read_parallel_mpas_trivial_no_mixed_elements);
-  result += RUN_TEST(test_read_parallel_mpas_rcbzoltan);
-  result += RUN_TEST(test_read_parallel_mpas_rcbzoltan_no_mixed_elements);
+  result += RUN_TEST(test_read_onevar_trivial);
+  result += RUN_TEST(test_read_onevar_trivial_no_mixed_elements);
+#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+  result += RUN_TEST(test_read_onevar_rcbzoltan);
+  result += RUN_TEST(test_read_onevar_rcbzoltan_no_mixed_elements);
+#endif
+
+  result += RUN_TEST(test_read_mesh_parallel_trivial);
+  result += RUN_TEST(test_read_mesh_parallel_trivial_no_mixed_elements);
+#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+  result += RUN_TEST(test_read_mesh_parallel_rcbzoltan);
+  result += RUN_TEST(test_read_mesh_parallel_rcbzoltan_no_mixed_elements);
+#endif
+
+  result += RUN_TEST(test_gather_onevar_on_rank0);
+  result += RUN_TEST(test_gather_onevar_on_rank1);
+
   result += RUN_TEST(test_multiple_loads_of_same_file);
   result += RUN_TEST(test_multiple_loads_of_same_file_no_mixed_elements);
 
@@ -38,436 +72,553 @@ int main(int argc, char* argv[])
   return result;
 }
 
-void test_read_parallel_mpas_trivial()
+void test_read_onevar_trivial()
+{
+  read_one_cell_var(false, false);
+}
+
+void test_read_onevar_trivial_no_mixed_elements()
+{
+  read_one_cell_var(false, true);
+}
+
+void test_read_onevar_rcbzoltan()
+{
+  read_one_cell_var(true, false);
+}
+
+void test_read_onevar_rcbzoltan_no_mixed_elements()
 {
-  partition_method = std::string(";PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS");
-  test_read_parallel(1280, true, 1920, true, 642, true, true);
+  read_one_cell_var(true, true);
 }
 
-void test_read_parallel_mpas_trivial_no_mixed_elements()
+void test_read_mesh_parallel_trivial()
 {
-  partition_method = std::string(";PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS;NO_MIXED_ELEMENTS");
-  test_read_parallel(1280, true, 1920, true, 642, true, false);
+  read_mesh_parallel(false, false);
 }
 
-void test_read_parallel_mpas_rcbzoltan()
+void test_read_mesh_parallel_trivial_no_mixed_elements()
 {
-  partition_method = std::string(";PARTITION_METHOD=RCBZOLTAN;PARALLEL_RESOLVE_SHARED_ENTS");
-  test_read_parallel(1280, false, 1920, false, 642, false, true);
+  read_mesh_parallel(false, true);
 }
 
-void test_read_parallel_mpas_rcbzoltan_no_mixed_elements()
+void test_read_mesh_parallel_rcbzoltan()
 {
-  partition_method = std::string(";PARTITION_METHOD=RCBZOLTAN;PARALLEL_RESOLVE_SHARED_ENTS;NO_MIXED_ELEMENTS");
-  test_read_parallel(1280, false, 1920, false, 642, false, true);
+  read_mesh_parallel(true, false);
 }
 
-void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges,
-                        int num_cells, bool test_nb_cells, bool mixed_elements)
+void test_read_mesh_parallel_rcbzoltan_no_mixed_elements()
+{
+  read_mesh_parallel(true, true);
+}
+
+void test_gather_onevar_on_rank0()
+{
+  gather_one_cell_var(0);
+}
+
+void test_gather_onevar_on_rank1()
+{
+  gather_one_cell_var(1);
+}
+
+void test_multiple_loads_of_same_file()
+{
+  multiple_loads_of_same_file(false);
+}
+
+void test_multiple_loads_of_same_file_no_mixed_elements()
+{
+  multiple_loads_of_same_file(true);
+}
+
+// Helper functions
+void read_one_cell_var(bool rcbzoltan, bool no_mixed_elements)
 {
   Core moab;
   Interface& mb = moab;
-  EntityHandle file_set;
-  ErrorCode rval;
-  rval = mb.create_meshset(MESHSET_SET, file_set);
+
+  read_options = "PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL;NO_EDGES;VARIABLE=ke";
+  if (rcbzoltan)
+    read_options = "PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN;NO_EDGES;VARIABLE=ke";
+
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  ErrorCode rval = mb.load_file(example, NULL, read_options.c_str());
+  CHECK_ERR(rval);
+
+  // Get local edges
+  Range local_edges;
+  rval = mb.get_entities_by_type(0, MBEDGE, local_edges);
+  CHECK_ERR(rval);
+  CHECK_EQUAL((size_t)0, local_edges.size());
+
+  // Get local cells
+  Range local_cells;
+  rval = mb.get_entities_by_type(0, MBPOLYGON, local_cells);
   CHECK_ERR(rval);
 
-  std::string opt = std::string("PARALLEL=READ_PART") + partition_method;
-  // Create gather set in processor 0
-  opt += std::string(";GATHER_SET=0");
-  rval = mb.load_file(example, &file_set, opt.c_str());
+  Tag gid_tag;
+  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag, MB_TAG_DENSE);
   CHECK_ERR(rval);
 
+  std::vector<int> gids(local_cells.size());
+  rval = mb.tag_get_data(gid_tag, local_cells, &gids[0]);
+  Range local_cell_gids;
+  std::copy(gids.rbegin(), gids.rend(), range_inserter(local_cell_gids));
+
   ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
   int procs = pcomm->proc_config().proc_size();
   int rank = pcomm->proc_config().proc_rank();
 
-  rval = pcomm->check_all_shared_handles();
-  CHECK_ERR(rval);
+  // Make check runs this test on two processors
+  if (2 == procs) {
+    CHECK_EQUAL((size_t)321, local_cells.size());
+    CHECK_EQUAL((size_t)321, local_cell_gids.size());
 
-  // Get the total # owned verts
-  Range verts;
-  rval = mb.get_entities_by_type(0, MBVERTEX, verts);
-  CHECK_ERR(rval);
+    // Check tag for cell variable ke at timestep 0
+    Tag ke_tag0;
+    rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+    CHECK_ERR(rval);
+
+    // Check tag for cell variable ke at timestep 1
+    Tag ke_tag1;
+    rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+    CHECK_ERR(rval);
+
+    // Get ke0 and ke1 tag values on 3 local cells
+    EntityHandle cell_ents[] = {local_cells[0], local_cells[160], local_cells[320]};
+    double ke0_val[3];
+    rval = mb.tag_get_data(ke_tag0, cell_ents, 3, ke0_val);
+    CHECK_ERR(rval);
+    double ke1_val[3];
+    rval = mb.tag_get_data(ke_tag1, cell_ents, 3, ke1_val);
+    CHECK_ERR(rval);
 
-  int my_verts_num = verts.size();
-  if (test_nb_nodes && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(2400, my_verts_num); // Gather set vertices included
-    else if (1 == rank)
-      CHECK_EQUAL(1122, my_verts_num); // Not owned vertices included
+    if (rcbzoltan) {
+      if (no_mixed_elements)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+      else
+        CHECK_EQUAL((size_t)2, local_cells.psize());
+
+      CHECK_EQUAL((size_t)37, local_cell_gids.psize());
+
+      if (0 == rank) {
+        CHECK_EQUAL(1, (int)local_cell_gids[0]);
+        CHECK_EQUAL(284, (int)local_cell_gids[160]);
+        CHECK_EQUAL(630, (int)local_cell_gids[320]);
+
+        CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+        CHECK_REAL_EQUAL(16.284, ke0_val[1], eps);
+        CHECK_REAL_EQUAL(16.630, ke0_val[2], eps);
+        CHECK_REAL_EQUAL(25.001, ke1_val[0], eps);
+        CHECK_REAL_EQUAL(26.284, ke1_val[1], eps);
+        CHECK_REAL_EQUAL(26.630, ke1_val[2], eps);
+      }
+      else if (1 == rank) {
+        CHECK_EQUAL(4, (int)local_cell_gids[0]);
+        CHECK_EQUAL(341, (int)local_cell_gids[160]);
+        CHECK_EQUAL(642, (int)local_cell_gids[320]);
+
+        CHECK_REAL_EQUAL(15.004, ke0_val[0], eps);
+        CHECK_REAL_EQUAL(16.341, ke0_val[1], eps);
+        CHECK_REAL_EQUAL(16.642, ke0_val[2], eps);
+        CHECK_REAL_EQUAL(25.004, ke1_val[0], eps);
+        CHECK_REAL_EQUAL(26.341, ke1_val[1], eps);
+        CHECK_REAL_EQUAL(26.642, ke1_val[2], eps);
+      }
+    }
+    else {
+      CHECK_EQUAL((size_t)1, local_cell_gids.psize());
+
+      if (0 == rank) {
+        if (no_mixed_elements)
+          CHECK_EQUAL((size_t)1, local_cells.psize());
+        else
+          CHECK_EQUAL((size_t)2, local_cells.psize());
+        CHECK_EQUAL(1, (int)local_cell_gids[0]);
+        CHECK_EQUAL(161, (int)local_cell_gids[160]);
+        CHECK_EQUAL(321, (int)local_cell_gids[320]);
+
+        CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+        CHECK_REAL_EQUAL(16.161, ke0_val[1], eps);
+        CHECK_REAL_EQUAL(16.321, ke0_val[2], eps);
+        CHECK_REAL_EQUAL(25.001, ke1_val[0], eps);
+        CHECK_REAL_EQUAL(26.161, ke1_val[1], eps);
+        CHECK_REAL_EQUAL(26.321, ke1_val[2], eps);
+      }
+      else if (1 == rank) {
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+        CHECK_EQUAL(322, (int)local_cell_gids[0]);
+        CHECK_EQUAL(482, (int)local_cell_gids[160]);
+        CHECK_EQUAL(642, (int)local_cell_gids[320]);
+
+        CHECK_REAL_EQUAL(16.322, ke0_val[0], eps);
+        CHECK_REAL_EQUAL(16.482, ke0_val[1], eps);
+        CHECK_REAL_EQUAL(16.642, ke0_val[2], eps);
+        CHECK_REAL_EQUAL(26.322, ke1_val[0], eps);
+        CHECK_REAL_EQUAL(26.482, ke1_val[1], eps);
+        CHECK_REAL_EQUAL(26.642, ke1_val[2], eps);
+      }
+    }
   }
+}
 
-  rval = pcomm->filter_pstatus(verts, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+void read_mesh_parallel(bool rcbzoltan, bool no_mixed_elements)
+{
+  Core moab;
+  Interface& mb = moab;
+
+  read_options = "PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=";
+  if (rcbzoltan)
+    read_options = "PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=";
+
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  ErrorCode rval = mb.load_file(example, NULL, read_options.c_str());
   CHECK_ERR(rval);
 
-  my_verts_num = verts.size();
-  if (test_nb_nodes && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(2400, my_verts_num); // Gather set vertices included
-    else if (1 == rank)
-      CHECK_EQUAL(160, my_verts_num); // Not owned vertices excluded
-  }
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
+  int procs = pcomm->proc_config().proc_size();
+  int rank = pcomm->proc_config().proc_rank();
 
-  // Get the total # owned edges
-  Range edges;
-  rval = mb.get_entities_by_type(0, MBEDGE, edges);
+  rval = pcomm->check_all_shared_handles();
   CHECK_ERR(rval);
 
-  int my_edges_num = edges.size();
-  if (test_nb_edges && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(3358, my_edges_num); // Gather set edges included
-    else if (1 == rank)
-      CHECK_EQUAL(1444, my_edges_num); // Not owned edges included
+  // Get local vertices
+  Range local_verts;
+  rval = mb.get_entities_by_type(0, MBVERTEX, local_verts);
+  CHECK_ERR(rval);
+
+  int verts_num = local_verts.size();
+  if (2 == procs) {
+    if (rcbzoltan) {
+      if (0 == rank)
+        CHECK_EQUAL(685, verts_num);
+      else if (1 == rank)
+        CHECK_EQUAL(685, verts_num); // Not owned vertices included
+    }
+    else {
+      if (0 == rank)
+        CHECK_EQUAL(1120, verts_num);
+      else if (1 == rank)
+        CHECK_EQUAL(1122, verts_num); // Not owned vertices included
+    }
   }
 
-  rval = pcomm->filter_pstatus(edges, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+  rval = pcomm->filter_pstatus(local_verts, PSTATUS_NOT_OWNED, PSTATUS_NOT);
   CHECK_ERR(rval);
 
-  my_edges_num = edges.size();
-  if (test_nb_edges && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(3358, my_edges_num); // Gather set edges included
-    else if (1 == rank)
-      CHECK_EQUAL(482, my_edges_num); // Not owned edges excluded
+  verts_num = local_verts.size();
+  if (2 == procs) {
+    if (rcbzoltan) {
+      if (0 == rank)
+        CHECK_EQUAL(685, verts_num);
+      else if (1 == rank)
+        CHECK_EQUAL(595, verts_num); // Not owned vertices excluded
+    }
+    else {
+      if (0 == rank)
+        CHECK_EQUAL(1120, verts_num);
+      else if (1 == rank)
+        CHECK_EQUAL(160, verts_num); // Not owned vertices excluded
+    }
   }
 
-  // Get the total # owned cells
-  Range cells;
-  rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+  // Get local edges
+  Range local_edges;
+  rval = mb.get_entities_by_type(0, MBEDGE, local_edges);
   CHECK_ERR(rval);
 
-  int my_cells_num = cells.size();
-  if (test_nb_cells && 2 == procs) {
-    if (0 == rank) {
-      CHECK_EQUAL(963, my_cells_num); // Gather set cells included
-      if (mixed_elements)
-        CHECK_EQUAL((size_t)4, cells.psize()); // Gather set cells included
-      else
-        CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included
+  int edges_num = local_edges.size();
+  if (2 == procs) {
+    if (rcbzoltan) {
+      if (0 == rank)
+        CHECK_EQUAL(1005, edges_num);
+      else if (1 == rank)
+        CHECK_EQUAL(1005, edges_num); // Not owned edges included
     }
-    else if (1 == rank) {
-      CHECK_EQUAL(321, my_cells_num); // Not owned cells included
-      CHECK_EQUAL((size_t)1, cells.psize()); // Not owned cells included
+    else {
+      if (0 == rank)
+        CHECK_EQUAL(1438, edges_num);
+      else if (1 == rank)
+        CHECK_EQUAL(1444, edges_num); // Not owned edges included
     }
   }
 
-   rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT);
-   CHECK_ERR(rval);
-
-   my_cells_num = cells.size();
-   if (test_nb_cells && 2 == procs) {
-     if (0 == rank) {
-       CHECK_EQUAL(963, my_cells_num); // Gather set cells included
-       if (mixed_elements)
-         CHECK_EQUAL((size_t)4, cells.psize()); // Gather set cells included
-       else
-         CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included
-     }
-     else if (1 == rank) {
-       CHECK_EQUAL(321, my_cells_num); // Not owned cells excluded
-       CHECK_EQUAL((size_t)1, cells.psize()); // Not owned cells excluded
-     }
-   }
-
-  if (0 == rank) {
-    // Get gather set
-    EntityHandle gather_set;
-    ReadUtilIface* readUtilIface;
-    rval = mb.query_interface(readUtilIface);
-    CHECK_ERR(rval);
-    rval = readUtilIface->get_gather_set(gather_set);
-    CHECK_ERR(rval);
+  rval = pcomm->filter_pstatus(local_edges, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+  CHECK_ERR(rval);
 
-    // Get gather set entities
-    Range gather_ents;
-    rval = mb.get_entities_by_handle(gather_set, gather_ents);
-    CHECK_ERR(rval);
+  edges_num = local_edges.size();
+  if (2 == procs) {
+    if (rcbzoltan) {
+      if (0 == rank)
+        CHECK_EQUAL(1005, edges_num);
+      else if (1 == rank)
+        CHECK_EQUAL(915, edges_num); // Not owned edges excluded
+    }
+    else {
+      if (0 == rank)
+        CHECK_EQUAL(1438, edges_num);
+      else if (1 == rank)
+        CHECK_EQUAL(482, edges_num); // Not owned edges excluded
+    }
+  }
 
-    // Remove gather set vertices in processor 0
-    verts = subtract(verts, gather_ents);
+  // Get local cells
+  Range local_cells;
+  rval = mb.get_entities_by_type(0, MBPOLYGON, local_cells);
+  CHECK_ERR(rval);
 
-    // Remove gather set edges in processor 0
-    edges = subtract(edges, gather_ents);
+  int cells_num = local_cells.size();
+  if (2 == procs) {
+    CHECK_EQUAL(321, cells_num);
 
-    // Remove gather set cells in processor 0
-    cells = subtract(cells, gather_ents);
+    if (rcbzoltan) {
+      if (no_mixed_elements)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+      else
+        CHECK_EQUAL((size_t)2, local_cells.psize());
+     }
+    else {
+      if (0 == rank) {
+        if (no_mixed_elements)
+          CHECK_EQUAL((size_t)1, local_cells.psize());
+        else
+          CHECK_EQUAL((size_t)2, local_cells.psize());
+      }
+      else if (1 == rank)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+    }
   }
 
-  my_verts_num = verts.size();
-  if (test_nb_nodes && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(1120, my_verts_num); // Gather set vertices excluded
-    else if (1 == rank)
-      CHECK_EQUAL(160, my_verts_num); // Not owned vertices excluded
-  }
+  rval = pcomm->filter_pstatus(local_cells, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+  CHECK_ERR(rval);
 
-  std::cout << "proc: " << rank << " verts:" << my_verts_num << "\n";
+  cells_num = local_cells.size();
+  if (2 == procs) {
+    CHECK_EQUAL(321, cells_num);
 
-  int total_verts;
-  MPI_Reduce(&my_verts_num, &total_verts, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
-  if (0 == rank) {
-    std::cout << "total vertices: " << total_verts << "\n";
-    if (test_nb_nodes)
-      CHECK_EQUAL(total_verts, num_verts);
+    if (rcbzoltan) {
+      if (no_mixed_elements)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+      else
+        CHECK_EQUAL((size_t)2, local_cells.psize());
+    }
+    else {
+      if (0 == rank) {
+        if (no_mixed_elements)
+          CHECK_EQUAL((size_t)1, local_cells.psize());
+        else
+          CHECK_EQUAL((size_t)2, local_cells.psize());
+      }
+      else if (1 == rank)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+    }
   }
 
-  my_edges_num = edges.size();
-  if (test_nb_edges && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(1438, my_edges_num); // Gather set edges excluded
-    else if (1 == rank)
-      CHECK_EQUAL(482, my_edges_num); // Not owned edges excluded
+  std::cout << "proc: " << rank << " verts:" << verts_num << "\n";
+
+  int total_verts_num;
+  MPI_Reduce(&verts_num, &total_verts_num, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
+  if (0 == rank) {
+    std::cout << "total vertices: " << total_verts_num << "\n";
+    CHECK_EQUAL(1280, total_verts_num);
   }
 
-  std::cout << "proc: " << rank << " edges:" << my_edges_num << "\n";
+  std::cout << "proc: " << rank << " edges:" << edges_num << "\n";
 
-  int total_edges;
-  MPI_Reduce(&my_edges_num, &total_edges, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
+  int total_edges_num;
+  MPI_Reduce(&edges_num, &total_edges_num, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
   if (0 == rank) {
-    std::cout << "total edges: " << total_edges << "\n";
-    if (test_nb_edges)
-      CHECK_EQUAL(total_edges, num_edges);
+    std::cout << "total edges: " << total_edges_num << "\n";
+    CHECK_EQUAL(1920, total_edges_num);
   }
 
-  my_cells_num = cells.size();
-  if (test_nb_cells && 2 == procs) {
-    if (0 == rank) {
-      CHECK_EQUAL(321, my_cells_num); // Gather set cells excluded
-      if (mixed_elements)
-        CHECK_EQUAL((size_t)2, cells.psize()); // Gather set cells excluded
-      else
-        CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded
-    }
-    else if (1 == rank) {
-      CHECK_EQUAL(321, my_cells_num); // Not owned cells excluded
-      CHECK_EQUAL((size_t)1, cells.psize()); // Not owned cells excluded
-    }
+  std::cout << "proc: " << rank << " cells:" << cells_num << "\n";
+
+  int total_cells_num;
+  MPI_Reduce(&cells_num, &total_cells_num, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
+  if (0 == rank) {
+    std::cout << "total cells: " << total_cells_num << "\n";
+    CHECK_EQUAL(642, total_cells_num);
   }
 
-   std::cout << "proc: " << rank << " cells:" << my_cells_num << "\n";
+#ifdef HDF5_PARALLEL
+  std::string write_options("PARALLEL=WRITE_PART;");
 
-   int total_cells;
-   MPI_Reduce(&my_cells_num, &total_cells, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
-   if (0 == rank) {
-     std::cout << "total cells: " << total_cells << "\n";
-     if (test_nb_cells)
-       CHECK_EQUAL(total_cells, num_cells);
-   }
+  std::string output_file = "test_mpas";
+  if (rcbzoltan)
+    output_file += "_rcbzoltan";
+  if (no_mixed_elements)
+    output_file += "_no_mixed_elements";
+  output_file += ".h5m";
 
-  std::string write_options("PARALLEL=WRITE_PART;");
-  mb.write_file("test_mpas.h5m", NULL, write_options.c_str());
+  mb.write_file(output_file.c_str(), NULL, write_options.c_str());
+#endif
 }
 
-void test_multiple_loads_of_same_file()
+void gather_one_cell_var(int gather_set_rank)
 {
   Core moab;
   Interface& mb = moab;
+
   EntityHandle file_set;
-  ErrorCode rval;
-  rval = mb.create_meshset(MESHSET_SET, file_set);
+  ErrorCode rval = mb.create_meshset(MESHSET_SET, file_set);
   CHECK_ERR(rval);
 
-  // Read first only header information, no mesh, no variable
-  std::string opts("PARALLEL=READ_PART;PARTITION;NOMESH;VARIABLE=;PARTITION_METHOD=TRIVIAL");
-  rval = mb.load_file(example, &file_set, opts.c_str());
-  CHECK_ERR(rval);
+  read_options = "PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS";
+  std::ostringstream gather_set_option;
+  gather_set_option << ";GATHER_SET=" << gather_set_rank;
+  read_options += gather_set_option.str();
 
-  // Create mesh, no variable
-  opts="PARALLEL=READ_PART;PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION_METHOD=TRIVIAL;VARIABLE=";
-  // Create gather set in processor 1
-  opts += std::string(";GATHER_SET=1");
-  rval = mb.load_file(example, &file_set, opts.c_str());
-  CHECK_ERR(rval);
-
-  // Read variable ke at timestep 0, no mesh
-  opts = "PARALLEL=READ_PART;PARTITION;PARTITION_METHOD=TRIVIAL;NOMESH;VARIABLE=ke;TIMESTEP=0";
-  rval = mb.load_file(example, &file_set, opts.c_str());
+  rval = mb.load_file(example, &file_set, read_options.c_str());
   CHECK_ERR(rval);
 
   ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
   int procs = pcomm->proc_config().proc_size();
   int rank = pcomm->proc_config().proc_rank();
 
-  // Make check runs this test in two processors
-  if (2 == procs) {
-    Range verts;
-    rval = mb.get_entities_by_type(0, MBVERTEX, verts);
-    CHECK_ERR(rval);
+  // Make sure gather_set_rank is valid
+  if (gather_set_rank < 0 || gather_set_rank >= procs)
+    return;
 
-    Range edges;
-    rval = mb.get_entities_by_type(0, MBEDGE, edges);
-    CHECK_ERR(rval);
+  Range cells, cells_owned;
+  rval = mb.get_entities_by_type(file_set, MBPOLYGON, cells);
+  CHECK_ERR(rval);
 
-    Range cells;
-    rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+  // Get local owned cells
+  rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &cells_owned);
+  CHECK_ERR(rval);
+
+  EntityHandle gather_set = 0;
+  if (gather_set_rank == rank) {
+    // Get gather set
+    ReadUtilIface* readUtilIface;
+    mb.query_interface(readUtilIface);
+    rval = readUtilIface->get_gather_set(gather_set);
     CHECK_ERR(rval);
+    assert(gather_set != 0);
+  }
 
-    int my_verts_num = verts.size();
-    int my_edges_num = edges.size();
-    int my_cells_num = cells.size();
+  Tag ke_tag0, gid_tag;
+  rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0, MB_TAG_DENSE);
+  CHECK_ERR(rval);
 
-    if (0 == rank) {
-      CHECK_EQUAL(1120, my_verts_num);
-      CHECK_EQUAL(1438, my_edges_num);
-      CHECK_EQUAL(321, my_cells_num);
-      CHECK_EQUAL((size_t)2, cells.psize());
-
-      const double eps = 1e-20;
-      double val[2];
-
-      // Check tag for cell variable ke at timestep 0
-      Tag ke_tag0;
-      rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
-      CHECK_ERR(rval);
-
-      // Check ke0 tag values on first pentagon and first hexagon
-      EntityHandle cell_ents[] = {cells[0], cells[12]};
-      rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
-      CHECK_REAL_EQUAL(15.001, val[0], eps);
-      CHECK_REAL_EQUAL(16.013, val[1], eps);
-    }
-    else if (1 == rank) {
-      CHECK_EQUAL(2402, my_verts_num); // Gather set vertices included; Not owned vertices included
-      CHECK_EQUAL(3364, my_edges_num); // Gather set edges included; Not owned edges included
-      CHECK_EQUAL(963, my_cells_num); // Gather set cells included; Not owned cells included
-      CHECK_EQUAL((size_t)3, cells.psize()); // Gather set cells included; Not owned cells included
-
-      // Get gather set
-      EntityHandle gather_set;
-      ReadUtilIface* readUtilIface;
-      rval = mb.query_interface(readUtilIface);
-      CHECK_ERR(rval);
-      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 in processor 1
-      verts = subtract(verts, gather_ents);
-      my_verts_num = verts.size();
-      CHECK_EQUAL(1122, my_verts_num); // Gather set vertices excluded; Not owned vertices included
-
-      // Remove gather set edges in processor 1
-      edges = subtract(edges, gather_ents);
-      my_edges_num = edges.size();
-      CHECK_EQUAL(1444, my_edges_num); // Gather set edges excluded; Not owned edges included
-
-      // Remove gather set cells in processor 1
-      cells = subtract(cells, gather_ents);
-      my_cells_num = cells.size();
-      CHECK_EQUAL(321, my_cells_num); // Gather set cells excluded; Not owned cells included
-      CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded; Not owned cells included
-    }
+  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag, MB_TAG_DENSE);
+  CHECK_ERR(rval);
+
+  pcomm->gather_data(cells_owned, ke_tag0, gid_tag, gather_set, gather_set_rank);
+
+  if (gather_set_rank == rank) {
+    // Get gather set cells
+    Range gather_set_cells;
+    rval = mb.get_entities_by_type(gather_set, MBPOLYGON, gather_set_cells);
+    CHECK_EQUAL((size_t)642, gather_set_cells.size());
+    CHECK_EQUAL((size_t)2, gather_set_cells.psize());
+
+    // Check ke0 tag values on 4 gather set cells: first pentagon, last pentagon,
+    // first hexagon and last hexagon
+    EntityHandle cell_ents[] = {gather_set_cells[0], gather_set_cells[11],
+                                gather_set_cells[12], gather_set_cells[641]};
+    double ke0_val[4];
+    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 4, ke0_val);
+
+    CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+    CHECK_REAL_EQUAL(15.012, ke0_val[1], eps);
+    CHECK_REAL_EQUAL(16.013, ke0_val[2], eps);
+    CHECK_REAL_EQUAL(16.642, ke0_val[3], eps);
   }
 }
 
-void test_multiple_loads_of_same_file_no_mixed_elements()
+void multiple_loads_of_same_file(bool no_mixed_elements)
 {
   Core moab;
   Interface& mb = moab;
+
+  // Need a file set for nomesh to work right
   EntityHandle file_set;
   ErrorCode rval;
   rval = mb.create_meshset(MESHSET_SET, file_set);
   CHECK_ERR(rval);
 
   // Read first only header information, no mesh, no variable
-  std::string opts("PARALLEL=READ_PART;PARTITION;NOMESH;VARIABLE=;PARTITION_METHOD=TRIVIAL;NO_MIXED_ELEMENTS");
-  rval = mb.load_file(example, &file_set, opts.c_str());
+  read_options = "PARALLEL=READ_PART;PARTITION;NOMESH;VARIABLE=;PARTITION_METHOD=TRIVIAL";
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  rval = mb.load_file(example, &file_set, read_options.c_str());
   CHECK_ERR(rval);
 
   // Create mesh, no variable
-  opts="PARALLEL=READ_PART;PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION_METHOD=TRIVIAL;NO_MIXED_ELEMENTS;VARIABLE=";
-  // Create gather set in processor 1
-  opts += std::string(";GATHER_SET=1");
-  rval = mb.load_file(example, &file_set, opts.c_str());
+  read_options = "PARALLEL=READ_PART;PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION_METHOD=TRIVIAL;VARIABLE=";
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  rval = mb.load_file(example, &file_set, read_options.c_str());
   CHECK_ERR(rval);
 
   // Read variable ke at timestep 0, no mesh
-  opts = "PARALLEL=READ_PART;PARTITION;PARTITION_METHOD=TRIVIAL;NO_MIXED_ELEMENTS;NOMESH;VARIABLE=ke;TIMESTEP=0";
-  rval = mb.load_file(example, &file_set, opts.c_str());
+  read_options = "PARALLEL=READ_PART;PARTITION;PARTITION_METHOD=TRIVIAL;NOMESH;VARIABLE=ke;TIMESTEP=0";
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  rval = mb.load_file(example, &file_set, read_options.c_str());
+  CHECK_ERR(rval);
+
+  Range local_verts;
+  rval = mb.get_entities_by_type(file_set, MBVERTEX, local_verts);
+  CHECK_ERR(rval);
+
+  Range local_edges;
+  rval = mb.get_entities_by_type(file_set, MBEDGE, local_edges);
+  CHECK_ERR(rval);
+
+  Range local_cells;
+  rval = mb.get_entities_by_type(file_set, MBPOLYGON, local_cells);
   CHECK_ERR(rval);
 
   ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
   int procs = pcomm->proc_config().proc_size();
   int rank = pcomm->proc_config().proc_rank();
 
-  // Make check runs this test in two processors
+  // Make check runs this test on two processors
   if (2 == procs) {
-    Range verts;
-    rval = mb.get_entities_by_type(0, MBVERTEX, verts);
-    CHECK_ERR(rval);
+    CHECK_EQUAL((size_t)321, local_cells.size());
 
-    Range edges;
-    rval = mb.get_entities_by_type(0, MBEDGE, edges);
+    // Check tag for cell variable ke at timestep 0
+    Tag ke_tag0;
+    rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
     CHECK_ERR(rval);
 
-    Range cells;
-    rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+    // Get ke0 tag values on 3 local cells
+    EntityHandle cell_ents[] = {local_cells[0], local_cells[160], local_cells[320]};
+    double ke0_val[3];
+    rval = mb.tag_get_data(ke_tag0, cell_ents, 3, ke0_val);
     CHECK_ERR(rval);
 
-    int my_verts_num = verts.size();
-    int my_edges_num = edges.size();
-    int my_cells_num = cells.size();
-
     if (0 == rank) {
-      CHECK_EQUAL(1120, my_verts_num);
-      CHECK_EQUAL(1438, my_edges_num);
-      CHECK_EQUAL(321, my_cells_num);
-      CHECK_EQUAL((size_t)1, cells.psize());
-
-      const double eps = 1e-20;
-      double val[2];
-
-      // Check tag for cell variable ke at timestep 0
-      Tag ke_tag0;
-      rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
-      CHECK_ERR(rval);
-
-      // Check ke0 tag values on first pentagon and first hexagon
-      EntityHandle cell_ents[] = {cells[0], cells[12]};
-      rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
-      CHECK_REAL_EQUAL(15.001, val[0], eps);
-      CHECK_REAL_EQUAL(16.013, val[1], eps);
+      CHECK_EQUAL((size_t)1120, local_verts.size());
+      CHECK_EQUAL((size_t)1438, local_edges.size());
+      if (no_mixed_elements)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+      else
+        CHECK_EQUAL((size_t)2, local_cells.psize());
+
+      CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+      CHECK_REAL_EQUAL(16.161, ke0_val[1], eps);
+      CHECK_REAL_EQUAL(16.321, ke0_val[2], eps);
     }
     else if (1 == rank) {
-      CHECK_EQUAL(2402, my_verts_num); // Gather set vertices included; Not owned vertices included
-      CHECK_EQUAL(3364, my_edges_num); // Gather set edges included; Not owned edges included
-      CHECK_EQUAL(963, my_cells_num); // Gather set cells included; Not owned cells included
-      CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included; Not owned cells included
-
-      // Get gather set
-      EntityHandle gather_set;
-      ReadUtilIface* readUtilIface;
-      rval = mb.query_interface(readUtilIface);
-      CHECK_ERR(rval);
-      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 in processor 1
-      verts = subtract(verts, gather_ents);
-      my_verts_num = verts.size();
-      CHECK_EQUAL(1122, my_verts_num); // Gather set vertices excluded; Not owned vertices included
-
-      // Remove gather set edges in processor 1
-      edges = subtract(edges, gather_ents);
-      my_edges_num = edges.size();
-      CHECK_EQUAL(1444, my_edges_num); // Gather set edges excluded; Not owned edges included
-
-      // Remove gather set cells in processor 1
-      cells = subtract(cells, gather_ents);
-      my_cells_num = cells.size();
-      CHECK_EQUAL(321, my_cells_num); // Gather set cells excluded; Not owned cells included
-      CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded; Not owned cells included
+      CHECK_EQUAL((size_t)1122, local_verts.size());
+      CHECK_EQUAL((size_t)1444, local_edges.size());
+      CHECK_EQUAL((size_t)1, local_cells.psize());
+
+      CHECK_REAL_EQUAL(16.322, ke0_val[0], eps);
+      CHECK_REAL_EQUAL(16.482, ke0_val[1], eps);
+      CHECK_REAL_EQUAL(16.642, ke0_val[2], eps);
     }
   }
 }


https://bitbucket.org/fathomteam/moab/commits/cecd02115bea/
Changeset:   cecd02115bea
Branch:      None
User:        iulian07
Date:        2013-11-08 18:03:31
Summary:     make diffusion run in parallel
still some clean up needed
TO DO:
write in parallel the result tracer file
remove some redundant tags

Affected #:  4 files

diff --git a/tools/mbcslam/Intx2Mesh.cpp b/tools/mbcslam/Intx2Mesh.cpp
index 3e62b72..74f65ff 100644
--- a/tools/mbcslam/Intx2Mesh.cpp
+++ b/tools/mbcslam/Intx2Mesh.cpp
@@ -18,11 +18,16 @@
 
 namespace moab {
 
-Intx2Mesh::Intx2Mesh(Interface * mbimpl):mb(mbimpl), parcomm(NULL), myTree(NULL)
+Intx2Mesh::Intx2Mesh(Interface * mbimpl):mb(mbimpl), parcomm(NULL), myTree(NULL), remote_cells(NULL)
 {
   dbg_1=0;
   box_error=0;
   my_rank=0;
+  BlueFlagTag=0;
+  RedFlagTag=0;
+  redParentTag =0;
+  blueParentTag = 0;
+  countTag = 0;
 }
 
 Intx2Mesh::~Intx2Mesh()
@@ -31,6 +36,15 @@ Intx2Mesh::~Intx2Mesh()
 }
 void Intx2Mesh::createTags()
 {
+  if (redParentTag)
+    mb->tag_delete(redParentTag);
+  if(blueParentTag)
+    mb->tag_delete(blueParentTag);
+  if (countTag)
+    mb->tag_delete(countTag);
+    /*RedEdges.clear();
+    localEnts.clear()*/
+
   unsigned char def_data_bit = 0; // unused by default
   ErrorCode rval = mb->tag_get_handle("blueFlag", 1, MB_TYPE_BIT, BlueFlagTag,
       MB_TAG_CREAT, &def_data_bit);
@@ -409,6 +423,12 @@ void Intx2Mesh::clean()
   mb->tag_delete(RedFlagTag);// to mark blue quads already considered
   mb->tag_delete(BlueFlagTag);
 
+  /*mb->tag_delete(redParentTag);
+  mb->tag_delete(blueParentTag);
+  mb->tag_delete(countTag);
+  RedEdges.clear();
+  localEnts.clear();*/
+
 }
 ErrorCode Intx2Mesh::initialize_local_kdtree(EntityHandle euler_set)
 {
@@ -817,7 +837,7 @@ ErrorCode Intx2Mesh::create_departure_mesh(EntityHandle & covering_lagr_set)
   // the elements are already in localEnts; get all vertices, and DP and LOC tag
   // get the DP tag , and get the departure points
   std::map<int, EntityHandle> globalID_to_handle;
-  std::map<int, EntityHandle> globalID_to_eh;
+/*  std::map<int, EntityHandle> globalID_to_eh;*/
   std::map<int, Range> rs;
   std::set<int> ps; // processors working with my_rank
   Tag dpTag = 0;
@@ -1051,19 +1071,26 @@ ErrorCode Intx2Mesh::create_departure_mesh(EntityHandle & covering_lagr_set)
 
   return MB_SUCCESS;
 }
-ErrorCode Intx2Mesh::build_processor_euler_boxes(Range & local_verts)
+ErrorCode Intx2Mesh::build_processor_euler_boxes(EntityHandle euler_set, Range & local_verts)
 {
+  localEnts.clear();
+  ErrorCode rval = mb->get_entities_by_dimension(euler_set, 2, localEnts);
+  ERRORR(rval, "can't get ents by dimension");
+
+  rval = mb->get_connectivity(localEnts, local_verts);
+  int num_local_verts = (int) local_verts.size();
+  ERRORR(rval, "can't get local vertices");
+
   parcomm = ParallelComm::get_pcomm(mb, 0);
   if (NULL==parcomm)
     return MB_FAILURE;
-  int num_local_verts = (int) local_verts.size();
 
   // get the position of local vertices, and decide local boxes (allBoxes...)
   double bmin[3]={DBL_MAX, DBL_MAX, DBL_MAX};
   double bmax[3] ={-DBL_MAX, -DBL_MAX, -DBL_MAX};
 
   std::vector<double> coords(3*num_local_verts);
-  ErrorCode rval = mb->get_coords(local_verts, &coords[0]);
+  rval = mb->get_coords(local_verts, &coords[0]);
   ERRORR(rval, "can't get coords of vertices ");
 
   for (int i=0; i< num_local_verts; i++)
@@ -1094,8 +1121,25 @@ ErrorCode Intx2Mesh::build_processor_euler_boxes(Range & local_verts)
                                parcomm->proc_config().proc_comm());
   if (MPI_SUCCESS != mpi_err) return MB_FAILURE;
 
+  // also process the max number of vertices per cell (4 for quads, but could be more for polygons)
+  int local_max_edges = 3;
+  for (Range::iterator it = localEnts.begin(); it!=localEnts.end(); it++)
+  {
+    const EntityHandle * conn;
+    int num_nodes;
+    rval = mb->get_connectivity(*it, conn, num_nodes);
+    ERRORR(rval, "can't get connectivity");
+    if (num_nodes>local_max_edges)
+      local_max_edges = num_nodes;
+  }
+
+  // now reduce max_edges over all processors
+  mpi_err = MPI_Allreduce(&local_max_edges, &max_edges, 1, MPI_INTEGER, MPI_MAX, parcomm->proc_config().proc_comm());
+  if (MPI_SUCCESS != mpi_err) return MB_FAILURE;
+
   if (my_rank==0)
   {
+    std::cout << " maximum number of vertices per cell is " << max_edges << "\n";
     for (int i=0; i<numprocs; i++)
     {
       std::cout<<"proc: " << i << " box min: " << allBoxes[6*i  ] << " " <<allBoxes[6*i+1] << " " << allBoxes[6*i+2]  << " \n";
@@ -1126,7 +1170,7 @@ ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, Ent
   int num_local_verts = (int) local_verts.size();
   ERRORR(rval, "can't get local vertices");
 
-  rval = build_processor_euler_boxes(local_verts);
+  rval = build_processor_euler_boxes(euler_set, local_verts);
   ERRORR(rval, "can't build processor boxes");
   Tag gid;
   rval = mb->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid, MB_TAG_DENSE);
@@ -1200,8 +1244,8 @@ ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, Ent
   TLv.initialize(2, 0, 0, 3, numv); // to proc, GLOBAL ID, DP points
   TLv.enableWriteAccess();
 
-  int sizeTuple = 2+MAXEDGES; // max edges is now 10 :) for polygons
-  TLq.initialize(12, 0, 0, 0, numq); // to proc, elem GLOBAL ID, connectivity[10] (global ID v)
+  int sizeTuple = 2+max_edges; // determined earlier
+  TLq.initialize(2+max_edges, 0, 0, 0, numq); // to proc, elem GLOBAL ID, connectivity[10] (global ID v)
   TLq.enableWriteAccess();
   std::cout << "from proc " << my_rank << " send " << numv << " vertices and " << numq << " elements\n";
 
@@ -1237,8 +1281,8 @@ ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, Ent
       TLq.vi_wr[sizeTuple*n+1] = global_id; // global id of element, used to identify it ...
       const EntityHandle * conn4;
       int num_nodes;
-      rval = mb->get_connectivity(q, conn4, num_nodes);// could be up to 10;
-      ERRORR(rval, "can't get connectivity for quad");
+      rval = mb->get_connectivity(q, conn4, num_nodes);// could be up to MAXEDGES, but it is limited by max_edges
+      ERRORR(rval, "can't get connectivity for cell");
       if (num_nodes > MAXEDGES)
         ERRORR(MB_FAILURE, "too many nodes in a polygon");
       for (int i=0; i<num_nodes; i++)
@@ -1247,7 +1291,7 @@ ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, Ent
         unsigned int index = local_verts.find(v)-local_verts.begin();
         TLq.vi_wr[sizeTuple*n+2+i] = gids[index];
       }
-      for (int k=num_nodes; k<MAXEDGES; k++)
+      for (int k=num_nodes; k<max_edges; k++)
       {
         TLq.vi_wr[sizeTuple*n+2+k] = 0; // fill the rest of node ids with 0; we know that the node ids start from 1!
       }
@@ -1256,7 +1300,7 @@ ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, Ent
     }
 
   }
-  // now we can route them to each processor
+
   // now we are done populating the tuples; route them to the appropriate processors
   (parcomm->proc_config().crystal_router())->gs_transfer(1, TLv, 0);
   (parcomm->proc_config().crystal_router())->gs_transfer(1, TLq, 0);
@@ -1264,7 +1308,8 @@ ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, Ent
 
   // maps from global ids to new vertex and quad handles, that are added
   std::map<int, EntityHandle> globalID_to_handle;
-  std::map<int, EntityHandle> globalID_to_eh;
+  /*std::map<int, EntityHandle> globalID_to_eh;*/
+  globalID_to_eh.clear();// need for next iteration
   // now, look at every TLv, and see if we have to create a vertex there or not
   int n=TLv.get_n();// the size of the points received
   for (int i=0; i<n; i++)
@@ -1339,7 +1384,7 @@ ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, Ent
       // construct the conn quad
       EntityHandle new_conn[MAXEDGES];
       int nnodes;
-      for (int j=0; j<MAXEDGES; j++)
+      for (int j=0; j<max_edges; j++)
       {
         int vgid = TLq.vi_rd[sizeTuple*i+2+j];// vertex global ID
         if (vgid==0)
@@ -1367,6 +1412,298 @@ ErrorCode Intx2Mesh::create_departure_mesh_2nd_alg(EntityHandle & euler_set, Ent
   }
   return MB_SUCCESS;
 }
+
+// this algorithm assumes lagr set is already created, and some elements will be coming from
+// other procs, and populate the covering_set
+// we need to keep in a tuple list the remote cells from other procs, because we need to send back
+// the intersection info (like area of the intx polygon, and the current concentration) maybe total
+// mass in that intx
+ErrorCode Intx2Mesh::create_departure_mesh_3rd_alg(EntityHandle & lagr_set,
+    EntityHandle & covering_set)
+{
+  EntityHandle dum = 0;
+
+  Tag corrTag;
+  ErrorCode rval = mb->tag_get_handle(CORRTAGNAME,
+                                           1, MB_TYPE_HANDLE, corrTag,
+                                           MB_TAG_DENSE, &dum);
+  //start copy from 2nd alg
+  // compute the bounding box on each proc
+  parcomm = ParallelComm::get_pcomm(mb, 0);
+  if (NULL == parcomm || ( 1==parcomm->proc_config().proc_size()))
+  {
+    covering_set = lagr_set; // nothing to communicate, it must be serial
+    return MB_SUCCESS;
+  }
+
+  // get all local verts
+  Range local_verts;
+  rval = mb->get_connectivity(localEnts, local_verts);
+  int num_local_verts = (int) local_verts.size();
+  ERRORR(rval, "can't get local vertices");
+
+  Tag gid;
+  rval = mb->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid,
+      MB_TAG_DENSE);
+  ERRORR(rval, "can't get global ID tag");
+  std::vector<int> gids(num_local_verts);
+  rval = mb->tag_get_data(gid, local_verts, &gids[0]);
+  ERRORR(rval, "can't get local vertices gids");
+
+  Range localDepCells;
+  rval = mb->get_entities_by_dimension(lagr_set, 2, localDepCells);
+  ERRORR(rval, "can't get ents by dimension from lagr set");
+
+  // get all lagr verts (departure vertices)
+  Range lagr_verts;
+  rval = mb->get_connectivity(localDepCells, lagr_verts);// they should be created in
+  // the same order as the euler vertices
+  int num_lagr_verts = (int) lagr_verts.size();
+  ERRORR(rval, "can't get local lagr vertices");
+
+  // now see the departure points position; to what boxes should we send them?
+  std::vector<double> dep_points(3 * num_lagr_verts);
+  rval = mb->get_coords(lagr_verts, &dep_points[0]);
+  ERRORR(rval, "can't get departure points position");
+  // ranges to send to each processor; will hold vertices and elements (quads?)
+  // will look if the box of the dep quad covers box of euler mesh on proc (with tolerances)
+  std::map<int, Range> Rto;
+  int numprocs = parcomm->proc_config().proc_size();
+
+  for (Range::iterator eit = localDepCells.begin(); eit != localDepCells.end(); eit++)
+  {
+    EntityHandle q = *eit;
+    const EntityHandle * conn4;
+    int num_nodes;
+    rval = mb->get_connectivity(q, conn4, num_nodes);
+    ERRORR(rval, "can't get DP tag values");
+    CartVect qbmin(DBL_MAX);
+    CartVect qbmax(-DBL_MAX);
+    for (int i = 0; i < num_nodes; i++)
+    {
+      EntityHandle v = conn4[i];
+      int index = lagr_verts.index(v);
+      assert(-1!=index);
+      CartVect dp(&dep_points[3 * index]); // will use constructor
+      for (int j = 0; j < 3; j++)
+      {
+        if (qbmin[j] > dp[j])
+          qbmin[j] = dp[j];
+        if (qbmax[j] < dp[j])
+          qbmax[j] = dp[j];
+      }
+    }
+    for (int p = 0; p < numprocs; p++)
+    {
+      CartVect bbmin(&allBoxes[6 * p]);
+      CartVect bbmax(&allBoxes[6 * p + 3]);
+      if (GeomUtil::boxes_overlap(bbmin, bbmax, qbmin, qbmax, box_error))
+      {
+        Rto[p].insert(q);
+      }
+    }
+  }
+
+  // now, build TLv and TLq, for each p
+  size_t numq = 0;
+  size_t numv = 0;
+  for (int p = 0; p < numprocs; p++)
+  {
+    if (p == (int) my_rank)
+      continue; // do not "send" it, because it is already here
+    Range & range_to_P = Rto[p];
+    // add the vertices to it
+    if (range_to_P.empty())
+      continue; // nothing to send to proc p
+    Range vertsToP;
+    rval = mb->get_connectivity(range_to_P, vertsToP);
+    ERRORR(rval, "can't get connectivity");
+    numq = numq + range_to_P.size();
+    numv = numv + vertsToP.size();
+    range_to_P.merge(vertsToP);
+  }
+  TupleList TLv;
+  TupleList TLq;
+  TLv.initialize(2, 0, 0, 3, numv); // to proc, GLOBAL ID, DP points
+  TLv.enableWriteAccess();
+
+  int sizeTuple = 2 + max_edges; // max edges could be up to MAXEDGES :) for polygons
+  TLq.initialize(2+max_edges, 0, 1, 0, numq); // to proc, elem GLOBAL ID, connectivity[max_edges] (global ID v)
+  // send also the corresponding red cell it will come to
+  TLq.enableWriteAccess();
+  std::cout << "from proc " << my_rank << " send " << numv << " vertices and "
+      << numq << " elements\n";
+
+  for (int to_proc = 0; to_proc < numprocs; to_proc++)
+  {
+    if (to_proc == (int) my_rank)
+      continue;
+    Range & range_to_P = Rto[to_proc];
+    Range V = range_to_P.subset_by_type(MBVERTEX);
+
+    for (Range::iterator it = V.begin(); it != V.end(); it++)
+    {
+      EntityHandle v = *it;
+      int index = lagr_verts.index(v);// will be the same index as the corresponding vertex in euler verts
+      assert(-1!=index);
+      int n = TLv.get_n();
+      TLv.vi_wr[2 * n] = to_proc; // send to processor
+      TLv.vi_wr[2 * n + 1] = gids[index]; // global id needs index in the local_verts range
+      TLv.vr_wr[3 * n] = dep_points[3 * index]; // departure position, of the node local_verts[i]
+      TLv.vr_wr[3 * n + 1] = dep_points[3 * index + 1];
+      TLv.vr_wr[3 * n + 2] = dep_points[3 * index + 2];
+      TLv.inc_n();
+    }
+    // also, prep the 2d cells for sending ...
+    Range Q = range_to_P.subset_by_dimension(2);
+    for (Range::iterator it = Q.begin(); it != Q.end(); it++)
+    {
+      EntityHandle q = *it; // this is a blue cell
+      int global_id;
+      rval = mb->tag_get_data(gid, &q, 1, &global_id);
+      ERRORR(rval, "can't get gid for polygon");
+      int n = TLq.get_n();
+      TLq.vi_wr[sizeTuple * n] = to_proc; //
+      TLq.vi_wr[sizeTuple * n + 1] = global_id; // global id of element, used to identify it ...
+      const EntityHandle * conn4;
+      int num_nodes;
+      rval = mb->get_connectivity(q, conn4, num_nodes); // could be up to 10;
+      ERRORR(rval, "can't get connectivity for quad");
+      if (num_nodes > MAXEDGES)
+        ERRORR(MB_FAILURE, "too many nodes in a polygon");
+      for (int i = 0; i < num_nodes; i++)
+      {
+        EntityHandle v = conn4[i];
+        int index = lagr_verts.index(v);
+        assert(-1!=index);
+        TLq.vi_wr[sizeTuple * n + 2 + i] = gids[index];
+      }
+      for (int k = num_nodes; k < max_edges; k++)
+      {
+        TLq.vi_wr[sizeTuple * n + 2 + k] = 0; // fill the rest of node ids with 0; we know that the node ids start from 1!
+      }
+      EntityHandle redCell;
+      rval = mb->tag_get_data(corrTag, &q, 1, &redCell);
+      ERRORR(rval, "can't get corresponding red cell for dep cell");
+      TLq.vul_wr[n]=redCell; // this will be sent to remote_cells, to be able to come back
+      TLq.inc_n();
+
+    }
+
+  }
+  // now we can route them to each processor
+  // now we are done populating the tuples; route them to the appropriate processors
+  (parcomm->proc_config().crystal_router())->gs_transfer(1, TLv, 0);
+  (parcomm->proc_config().crystal_router())->gs_transfer(1, TLq, 0);
+  // the elements are already in localEnts;
+
+  // maps from global ids to new vertex and quad handles, that are added
+  std::map<int, EntityHandle> globalID_to_handle;
+  // we already have vertices from lagr set; they are already in the processor, even before receiving other
+  // verts from neighbors
+  int k=0;
+  for (Range::iterator vit=lagr_verts.begin(); vit!=lagr_verts.end(); vit++, k++)
+  {
+    globalID_to_handle[gids[k]] = *vit; // a little bit of overkill
+    // we do know that the global ids between euler and lagr verts are parallel
+  }
+  /*std::map<int, EntityHandle> globalID_to_eh;*/ // do we need this one?
+  globalID_to_eh.clear();
+  // now, look at every TLv, and see if we have to create a vertex there or not
+  int n = TLv.get_n(); // the size of the points received
+  for (int i = 0; i < n; i++)
+  {
+    int globalId = TLv.vi_rd[2 * i + 1];
+    if (globalID_to_handle.find(globalId) == globalID_to_handle.end())
+    {
+      EntityHandle new_vert;
+      double dp_pos[3] = { TLv.vr_wr[3 * i], TLv.vr_wr[3 * i + 1], TLv.vr_wr[3
+          * i + 2] };
+      rval = mb->create_vertex(dp_pos, new_vert);
+      ERRORR(rval, "can't create new vertex ");
+      globalID_to_handle[globalId] = new_vert;
+    }
+  }
+
+  // now, all dep points should be at their place
+  // look in the local list of 2d cells for this proc, and create all those cells if needed
+  // it may be an overkill, but because it does not involve communication, we do it anyway
+  Range & local = Rto[my_rank];
+  Range local_q = local.subset_by_dimension(2);
+  // the local should have all the vertices in lagr_verts
+  for (Range::iterator it = local_q.begin(); it != local_q.end(); it++)
+  {
+    EntityHandle q = *it;// these are from lagr cells, local
+    int gid_el;
+    rval = mb->tag_get_data(gid, &q, 1, &gid_el);
+    ERRORR(rval, "can't get element global ID ");
+    globalID_to_eh[gid_el] = q; // do we need this? maybe to just mark the ones on this processor
+    // maybe a range of global cell ids is fine?
+  }
+  // now look at all elements received through; we do not want to duplicate them
+  n = TLq.get_n(); // number of elements received by this processor
+  // a cell should be received from one proc only; so why are we so worried about duplicated elements?
+  // a vertex can be received from multiple sources, that is fine
+
+  remote_cells = new TupleList();
+  remote_cells->initialize(2, 0, 1, 1, n);
+  remote_cells->enableWriteAccess();
+  for (int i = 0; i < n; i++)
+  {
+    int globalIdEl = TLq.vi_rd[sizeTuple * i + 1];
+    int from_proc=TLq.vi_rd[sizeTuple * i ];
+    // do we already have a quad with this global ID, represented?
+    if (globalID_to_eh.find(globalIdEl) == globalID_to_eh.end())
+    {
+      // construct the conn quad
+      EntityHandle new_conn[MAXEDGES];
+      int nnodes;
+      for (int j = 0; j < max_edges; j++)
+      {
+        int vgid = TLq.vi_rd[sizeTuple * i + 2 + j]; // vertex global ID
+        if (vgid == 0)
+          new_conn[j] = 0;
+        else
+        {
+          assert(globalID_to_handle.find(vgid)!=globalID_to_handle.end());
+          new_conn[j] = globalID_to_handle[vgid];
+          nnodes = j + 1; // nodes are at the beginning, and are variable number
+        }
+      }
+      EntityHandle new_element;
+      //
+      EntityType entType = MBQUAD;
+      if (nnodes > 4)
+        entType = MBPOLYGON;
+      if (nnodes < 4)
+        entType = MBTRI;
+      rval = mb->create_element(entType, new_conn, nnodes, new_element);
+      ERRORR(rval, "can't create new element ");
+      globalID_to_eh[globalIdEl] = new_element;
+      local_q.insert(new_element);
+      rval = mb->tag_set_data(gid, &new_element, 1, &globalIdEl);
+      ERRORR(rval, "can't set gid on new element ");
+    }
+    remote_cells->vi_wr[2*i]=from_proc;
+    remote_cells->vi_wr[2*i+1]=globalIdEl;
+    remote_cells->vr_wr[i] = 0.; // no contribution yet sent back
+    remote_cells->vul_wr[i]= TLq.vul_rd[i];// this is the corresponding red cell (arrival)
+    remote_cells->inc_n();
+  }
+  // now, create a new set, covering_set
+  rval = mb->create_meshset(MESHSET_SET, covering_set);
+  ERRORR(rval, "can't create new mesh set ");
+  rval = mb->add_entities(covering_set, local_q);
+  ERRORR(rval, "can't add entities to new mesh set ");
+  // order the remote cells tuple list, with the global id, because we will search in it
+  //remote_cells->print("remote_cells before sorting");
+  moab::TupleList::buffer sort_buffer;
+  sort_buffer.buffer_init(n);
+  remote_cells->sort(1, &sort_buffer);
+  sort_buffer.reset();
+  return MB_SUCCESS;
+  //end copy
+}
 // this method will reduce number of nodes, collapse edges that are of length 0
   // so a polygon like 428 431 431 will become a line 428 431
   // or something like 428 431 431 531 -> 428 431 531

diff --git a/tools/mbcslam/Intx2Mesh.hpp b/tools/mbcslam/Intx2Mesh.hpp
index 8c8ad6e..6dcdc13 100644
--- a/tools/mbcslam/Intx2Mesh.hpp
+++ b/tools/mbcslam/Intx2Mesh.hpp
@@ -11,6 +11,7 @@
 #include <iostream>
 #include <sstream>
 #include <fstream>
+#include <map>
 #include <time.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -91,7 +92,16 @@ public:
 
   ErrorCode create_departure_mesh_2nd_alg(EntityHandle & euler_set, EntityHandle & covering_lagr_set);
 
-  ErrorCode build_processor_euler_boxes(Range & local_verts);
+  // in this method, used in parallel, each departure elements are already created, and at their positions
+  // the covering_set is output, will contain the departure cells that cover the euler set; some of these
+  // departure cells might come from different processors
+  // so the covering_set contains some elements from lagr_set and some elements that come from other procs
+  // we need to keep track of what processors "sent" the elements so we know were to
+  // send back the info about the tracers masses
+
+  ErrorCode create_departure_mesh_3rd_alg(EntityHandle & lagr_set, EntityHandle & covering_set);
+
+  ErrorCode build_processor_euler_boxes(EntityHandle euler_set, Range & local_verts);
 
   void correct_polygon(EntityHandle * foundIds, int & nP);
 
@@ -147,10 +157,15 @@ protected: // so it can be accessed in derived classes, InPlane and OnSphere
   double box_error;
   /* \brief Local root of the kdtree */
   EntityHandle localRoot;
-  Range localEnts;// this range is for local elements of interest
+  Range localEnts;// this range is for local elements of interest, euler cells
 
   unsigned int my_rank;
 
+  int max_edges; // maximum number of edges in the euler set
+
+  TupleList * remote_cells;
+  std::map<int, EntityHandle> globalID_to_eh;// needed for parallel, mostly
+
 };
 
 } /* namespace moab */

diff --git a/tools/mbcslam/Intx2MeshOnSphere.cpp b/tools/mbcslam/Intx2MeshOnSphere.cpp
index 3ab761c..f1c38d0 100644
--- a/tools/mbcslam/Intx2MeshOnSphere.cpp
+++ b/tools/mbcslam/Intx2MeshOnSphere.cpp
@@ -6,6 +6,8 @@
 
 #include "Intx2MeshOnSphere.hpp"
 #include "moab/GeomUtil.hpp"
+#include "MBTagConventions.hpp"
+#include "moab/ParallelComm.hpp"
 #include <queue>
 
 namespace moab {
@@ -423,9 +425,13 @@ ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagE
   Tag corrTag;
   ErrorCode rval = mb->tag_get_handle(CORRTAGNAME,
                                            1, MB_TYPE_HANDLE, corrTag,
-                                           MB_TAG_DENSE|MB_TAG_CREAT, &dum);
+                                           MB_TAG_DENSE, &dum); // it should have been created
   ERRORR(rval, "can't get correlation tag");
 
+  Tag gid;
+  rval = mb->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid, MB_TAG_DENSE);
+  ERRORR(rval,"can't get global ID tag" );
+
   // get all polygons out of out_set; then see where are they coming from
   Range polys;
   rval = mb->get_entities_by_dimension(out_set, 2, polys);
@@ -464,12 +470,50 @@ ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagE
     // the blue corresponds to a red arrival
     EntityHandle redArr;
     rval = mb->tag_get_data(corrTag, &blue, 1, &redArr);
-    ERRORR(rval, "can't get arrival red for corresponding ");
-    int arrRedIndex = rs2.index(redArr);
-    if (-1 == arrRedIndex)
-      ERRORR(MB_FAILURE, "can't find the red arrival index");
-    newValues[arrRedIndex] += currentVals[redIndex]*areap;
+    if (0==redArr || MB_TAG_NOT_FOUND==rval)
+    {
+      if (!remote_cells)
+        ERRORR( MB_FAILURE, "no remote cells, failure\n");
+      // maybe the element is remote, from another processor
+      int global_id_blue;
+      rval = mb->tag_get_data(gid, &blue, 1, &global_id_blue);
+      ERRORR(rval, "can't get arrival red for corresponding blue gid");
+      // find the
+      int index_in_remote = remote_cells->find(1, global_id_blue);
+      if (index_in_remote==-1)
+        ERRORR( MB_FAILURE, "can't find the global id element in remote cells\n");
+      remote_cells->vr_wr[index_in_remote] += currentVals[redIndex]*areap;
+    }
+    else if (MB_SUCCESS==rval)
+    {
+      int arrRedIndex = rs2.index(redArr);
+      if (-1 == arrRedIndex)
+        ERRORR(MB_FAILURE, "can't find the red arrival index");
+      newValues[arrRedIndex] += currentVals[redIndex]*areap;
+    }
+
+    else
+      ERRORR(rval, "can't get arrival red for corresponding ");
+  }
+  // now, send back the remote_cells to the processors they came from, with the updated values for
+  // the tracer mass in a cell
+  if (remote_cells)
+  {
+    // so this means that some cells will be sent back with tracer info to the procs they were sent from
+    (parcomm->proc_config().crystal_router())->gs_transfer(1, *remote_cells, 0);
+    // now, look at the global id, find the proper "red" cell with that index and update its mass
+    //remote_cells->print("remote cells after routing");
+    int n = remote_cells->get_n();
+    for (int j=0; j<n; j++)
+    {
+      EntityHandle redCell = remote_cells->vul_rd[j];// entity handle sent back
+      int arrRedIndex = rs2.index(redCell);
+      if (-1 == arrRedIndex)
+        ERRORR(MB_FAILURE, "can't find the red arrival index");
+      newValues[arrRedIndex] += remote_cells->vr_rd[j];
+    }
   }
+
   // now divide by red area (current)
   int j=0;
   Range::iterator iter = rs2.begin();
@@ -490,6 +534,12 @@ ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagE
   rval = mb->tag_set_data(tagElem, rs2, &newValues[0]);
   ERRORR(rval, "can't set new values tag");
   std::cout <<"total mass now:" << total_mass_current << "\n";
+
+  if (remote_cells)
+  {
+    delete remote_cells;
+    remote_cells=NULL;
+  }
   return MB_SUCCESS;
 }
 } /* namespace moab */

diff --git a/tools/mbcslam/diffusion.cpp b/tools/mbcslam/diffusion.cpp
index a44c3ca..9144eab 100644
--- a/tools/mbcslam/diffusion.cpp
+++ b/tools/mbcslam/diffusion.cpp
@@ -278,6 +278,12 @@ ErrorCode  create_lagr_mesh(Interface * mb, EntityHandle euler_set, EntityHandle
                                            1, MB_TYPE_HANDLE, corrTag,
                                            MB_TAG_DENSE|MB_TAG_CREAT, &dum);
   CHECK_ERR(rval);
+
+  // give the same global id to new verts and cells created in the lagr(departure) mesh
+  Tag gid;
+  rval = mb->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid, MB_TAG_DENSE);
+  CHECK_ERR(rval);
+
   Range polys;
   rval = mb->get_entities_by_dimension(euler_set, 2, polys);
   CHECK_ERR(rval);
@@ -293,6 +299,9 @@ ErrorCode  create_lagr_mesh(Interface * mb, EntityHandle euler_set, EntityHandle
     CartVect posi;
     rval = mb->get_coords(&oldV, 1, &(posi[0]));
     CHECK_ERR(rval);
+    int global_id;
+    rval = mb->tag_get_data(gid, &oldV, 1, &global_id);
+    CHECK_ERR(rval);
     EntityHandle new_vert;
     rval = mb->create_vertex(&(posi[0]), new_vert); // duplicate the position
     CHECK_ERR(rval);
@@ -303,6 +312,10 @@ ErrorCode  create_lagr_mesh(Interface * mb, EntityHandle euler_set, EntityHandle
     // also the other side
     rval = mb->tag_set_data(corrTag, &new_vert, 1, &oldV);
     CHECK_ERR(rval);
+    // set the global id
+    rval = mb->tag_set_data(gid, &new_vert, 1, &global_id);
+    CHECK_ERR(rval);
+
   }
   for (Range::iterator it = polys.begin(); it != polys.end(); it++)
   {
@@ -311,6 +324,9 @@ ErrorCode  create_lagr_mesh(Interface * mb, EntityHandle euler_set, EntityHandle
     const EntityHandle * conn;
     rval = mb->get_connectivity(q, conn, nnodes);
     CHECK_ERR(rval);
+    int global_id;
+    rval = mb->tag_get_data(gid, &q, 1, &global_id);
+    CHECK_ERR(rval);
     EntityType typeElem = mb->type_from_handle(q);
     std::vector<EntityHandle> new_conn(nnodes);
     for (int i = 0; i < nnodes; i++)
@@ -326,6 +342,9 @@ ErrorCode  create_lagr_mesh(Interface * mb, EntityHandle euler_set, EntityHandle
     CHECK_ERR(rval);
     rval = mb->tag_set_data(corrTag, &newElement, 1, &q);
     CHECK_ERR(rval);
+    // set the global id
+    rval = mb->tag_set_data(gid, &newElement, 1, &global_id);
+    CHECK_ERR(rval);
 
     rval = mb->add_entities(lagr_set, &newElement, 1);
     CHECK_ERR(rval);
@@ -333,9 +352,9 @@ ErrorCode  create_lagr_mesh(Interface * mb, EntityHandle euler_set, EntityHandle
 
   return MB_SUCCESS;
 }
-ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
+ErrorCode compute_tracer_case1(Interface * mb, Intx2MeshOnSphere & worker, EntityHandle euler_set,
     EntityHandle lagr_set, EntityHandle out_set, Tag & tagElem, Tag & tagArea, int rank,
-    int tStep)
+    int tStep, Range & connecVerts)
 {
   ErrorCode rval = MB_SUCCESS;
 
@@ -347,11 +366,6 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
   rval = mb->get_entities_by_dimension(euler_set, 2, polys);
   CHECK_ERR(rval);
 
-  Range connecVerts;
-  rval = mb->get_connectivity(polys, connecVerts);
-  CHECK_ERR(rval);
-
-
   // change coordinates of lagr mesh vertices
   for (Range::iterator vit = connecVerts.begin(); vit != connecVerts.end();
       vit++)
@@ -372,17 +386,37 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
     CHECK_ERR(rval);
   }
 
+  // if in parallel, we have to move some elements to another proc, and receive other cells
+  // from other procs
+  // lagr and euler are preserved
+  EntityHandle covering_set;
+  rval = worker.create_departure_mesh_3rd_alg(lagr_set, covering_set);
+  if (!noWrite) // so if write
+  {
+    std::stringstream newTracer;
+    newTracer << "Tracer" << rank << "_" << tStep << ".vtk";
+    rval = mb->write_file(newTracer.str().c_str(), 0, 0, &euler_set, 1);
+
+    std::stringstream lagr_cover;
+    lagr_cover << "Cover" << rank << "_" << tStep << ".vtk";
+    rval = mb->write_file(lagr_cover.str().c_str(), 0, 0, &covering_set, 1);
+
+  }
   // so we have now the departure at the previous time
   // intersect the 2 meshes (what about some checking of convexity?) for sufficient
   // small dt, it is not an issue;
-  Intx2MeshOnSphere worker(mb);
-  worker.SetRadius(radius);
 
-  worker.SetErrorTolerance(gtol);
   // std::cout << "error tolerance epsilon_1=" << gtol << "\n";
 
-  rval = worker.intersect_meshes(lagr_set, euler_set, out_set);
+  rval = worker.intersect_meshes(covering_set, euler_set, out_set);
   CHECK_ERR(rval);
+  if (!noWrite) // so if write
+  {
+    std::stringstream intx_mesh;
+    intx_mesh << "Intx" << rank << "_" << tStep << ".vtk";
+    rval = mb->write_file(intx_mesh.str().c_str(), 0, 0, &out_set, 1);
+  }
+
   // serially: lagr is the same order as euler;
   // we need to update now the tracer information on each element, based on
   // initial value and areas of each resulting polygons
@@ -391,11 +425,6 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
 
   if (!noWrite) // so if write
   {
-    std::stringstream newTracer;
-    newTracer << "Tracer" << rank << "_" << tStep << ".vtk";
-    rval = mb->write_file(newTracer.str().c_str(), 0, 0, &euler_set, 1);
-    CHECK_ERR(rval);
-
     std::stringstream newIntx;
     newIntx << "newIntx" << rank << "_" << tStep << ".vtk";
     rval = mb->write_file(newIntx.str().c_str(), 0, 0, &out_set, 1);
@@ -414,9 +443,11 @@ ErrorCode compute_tracer_case1(Interface * mb, EntityHandle euler_set,
   rval = mb->get_entities_by_dimension(lagr_set, 2, polys); // do not delete lagr set either, with its vertices
   CHECK_ERR(rval);
  // add to the connecVerts range all verts, from all initial polys
-  rval = mb->get_connectivity(polys, connecVerts);
+  Range vertsToStay;
+  rval = mb->get_connectivity(polys, vertsToStay);
   CHECK_ERR(rval);
-  Range todeleteVerts = subtract(allVerts, connecVerts);
+
+  Range todeleteVerts = subtract(allVerts, vertsToStay);
 
   Range todeleteElem = subtract(allElems, polys);
 
@@ -549,16 +580,31 @@ int main(int argc, char **argv)
 
   rval = create_lagr_mesh(&mb, euler_set, lagr_set);
   CHECK_ERR(rval);
+
+  Intx2MeshOnSphere worker(&mb);
+  worker.SetRadius(radius);
+
+  worker.SetErrorTolerance(gtol);
+
+  Range local_verts;
+  rval = worker.build_processor_euler_boxes(euler_set, local_verts);// output also the local_verts
+  // these stay fixed for one run
+  // other things from intersection might need to change, like input blue set (departure set)
+  // so we need also a method to clean memory
+  CHECK_ERR(rval);
+
   for (int i=1; i<numSteps+1; i++)
   {
     // time depends on i; t = i*T/numSteps: ( 0, T/numSteps, 2*T/numSteps, ..., T )
+    // this is really just to create some plots; it is not really needed to proceed
+    // the compute_tracer_case1 method actually computes the departure point position
     rval = compute_velocity_case1(&mb, euler_set, tagh, rank, i);
     CHECK_ERR(rval);
 
     // this is to actually compute concentrations, using the current concentrations
     //
-    rval = compute_tracer_case1(&mb, euler_set, lagr_set, out_set,
-        tagElem, tagArea, rank, i);
+    rval = compute_tracer_case1(&mb, worker, euler_set, lagr_set, out_set,
+        tagElem, tagArea, rank, i, local_verts);
     CHECK_ERR(rval);
 
   }
@@ -585,5 +631,6 @@ int main(int argc, char **argv)
     }
   }
   std::cout << " numSteps:" << numSteps << " 1-norm:" << norm1 << "\n";
+  MPI_Finalize();
   return 0;
 }


https://bitbucket.org/fathomteam/moab/commits/dec845aee4ec/
Changeset:   dec845aee4ec
Branch:      None
User:        iulian07
Date:        2013-11-08 18:55:44
Summary:     zoltan related changes

Affected #:  2 files

diff --git a/tools/Makefile.am b/tools/Makefile.am
index a7131ac..e8ad0db 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -133,8 +133,8 @@ noinst_PROGRAMS = $(parread)
 SUBDIRS = . \
           $(refiner_DIR) \
           $(mbcoupler_DIR) \
-          $(mbzoltan_DIR) \
           $(mbcslam_DIR) \
+          $(mbzoltan_DIR) \
 	  $(mcnpmit_DIR) \
           $(qvdual_DIR) \
 	  $(vtkMOABReader_DIR) \

diff --git a/tools/mbcslam/Makefile.am b/tools/mbcslam/Makefile.am
index 6db90f2..61776bf 100644
--- a/tools/mbcslam/Makefile.am
+++ b/tools/mbcslam/Makefile.am
@@ -17,7 +17,7 @@ AM_CPPFLAGS += -DSRCDIR=$(srcdir) \
                -I$(top_builddir)/itaps/imesh \
                -I$(top_srcdir)/test 
 if ENABLE_mbzoltan
-  AM_CPPFLAGS +=  $(ZOLTAN_INC_FLAGS) -DHAVE_ZOLTAN \
+  AM_CPPFLAGS +=  $(ZOLTAN_INC_FLAGS) \
                -I$(top_srcdir)/tools/mbzoltan \
                -I$(top_builddir)/tools/mbzoltan
 if HAVE_CGM


https://bitbucket.org/fathomteam/moab/commits/46789ce126b3/
Changeset:   46789ce126b3
Branch:      None
User:        iulian07
Date:        2013-11-08 22:31:36
Summary:     use MPI_reduce to compute the total mass, 1-norm

Affected #:  2 files

diff --git a/tools/mbcslam/Intx2MeshOnSphere.cpp b/tools/mbcslam/Intx2MeshOnSphere.cpp
index f1c38d0..7ea5854 100644
--- a/tools/mbcslam/Intx2MeshOnSphere.cpp
+++ b/tools/mbcslam/Intx2MeshOnSphere.cpp
@@ -519,7 +519,7 @@ ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagE
   Range::iterator iter = rs2.begin();
   void * data=NULL; //used for stored area
   int count =0;
-  double total_mass_current=0.;
+  double total_mass_local=0.;
   while (iter != rs2.end())
   {
     rval = mb->tag_iterate(tagArea, iter, rs2.end(), count, data);
@@ -527,13 +527,18 @@ ErrorCode Intx2MeshOnSphere::update_tracer_data(EntityHandle out_set, Tag & tagE
     double * ptrArea=(double*)data;
     for (int i=0; i<count; i++, iter++, j++, ptrArea++)
     {
-      total_mass_current+=newValues[j];
+      total_mass_local+=newValues[j];
       newValues[j]/= (*ptrArea);
     }
   }
   rval = mb->tag_set_data(tagElem, rs2, &newValues[0]);
   ERRORR(rval, "can't set new values tag");
-  std::cout <<"total mass now:" << total_mass_current << "\n";
+
+  double total_mass=0.;
+  int mpi_err = MPI_Reduce(&total_mass_local, &total_mass, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
+  if (MPI_SUCCESS != mpi_err) return MB_FAILURE;
+  if (my_rank==0)
+    std::cout <<"total mass now:" << total_mass << "\n";
 
   if (remote_cells)
   {

diff --git a/tools/mbcslam/diffusion.cpp b/tools/mbcslam/diffusion.cpp
index 9144eab..e6b3ad7 100644
--- a/tools/mbcslam/diffusion.cpp
+++ b/tools/mbcslam/diffusion.cpp
@@ -52,6 +52,7 @@ int case_number = 1; // 1, 2 (non-divergent) 3 divergent
 
 moab::Tag corrTag;
 bool noWrite = false;
+bool parallelWrite = false;
 int field_type = 1 ; // 1 quasi smooth, 2 - smooth, 3 non-smooth,
 #ifdef MESHDIR
 std::string TestDir( STRINGIFY(MESHDIR) );
@@ -167,7 +168,7 @@ ErrorCode add_field_value(Interface * mb, EntityHandle euler_set, int rank, Tag
 
 
   Range::iterator iter = polygons.begin();
-  double total_mass = 0.;
+  double local_mass = 0.; // this is total mass on one proc
   while (iter != polygons.end())
   {
     rval = mb->tag_iterate(tagElem, iter, polygons.end(), count, data);
@@ -203,18 +204,16 @@ ErrorCode add_field_value(Interface * mb, EntityHandle euler_set, int rank, Tag
 
       // we should have used some
       // total mass:
-      total_mass += *ptrArea * average;
+      local_mass += *ptrArea * average;
     }
 
   }
+  double total_mass=0.;
+  int mpi_err = MPI_Reduce(&local_mass, &total_mass, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
+  if (MPI_SUCCESS != mpi_err) return MB_FAILURE;
 
-  std::stringstream iniPos;
-  iniPos<< "Tracer" << rank<<"_"<<0<<  ".vtk";// first time step
-
-  rval = mb->write_file(iniPos.str().c_str(), 0, 0, &euler_set, 1);
-  CHECK_ERR(rval);
-
-  std::cout << "initial total mass:" << total_mass << "\n";
+  if (rank==0)
+    std::cout << "initial total mass:" << total_mass << "\n";
 
   // now we can delete the tags? not yet
   return MB_SUCCESS;
@@ -261,10 +260,13 @@ ErrorCode compute_velocity_case1(Interface * mb, EntityHandle euler_set, Tag & t
     // increment to the next node
     ptr_velo+=3;// to next velocity
   }
-  std::stringstream velos;
-  velos<<"Tracer" << rank<<"_"<<tStep<<  ".vtk";
-  rval = mb->write_file(velos.str().c_str(), 0, 0, &euler_set, 1);
-  CHECK_ERR(rval);
+  if (!noWrite)
+  {
+    std::stringstream velos;
+    velos<<"Tracer" << rank<<"_"<<tStep<<  ".vtk";
+    rval = mb->write_file(velos.str().c_str(), 0, 0, &euler_set, 1, &tagh, 1);
+    CHECK_ERR(rval);
+  }
 
   return MB_SUCCESS;
 }
@@ -420,9 +422,22 @@ ErrorCode compute_tracer_case1(Interface * mb, Intx2MeshOnSphere & worker, Entit
   // serially: lagr is the same order as euler;
   // we need to update now the tracer information on each element, based on
   // initial value and areas of each resulting polygons
+  if (parallelWrite && tStep==1)
+  {
+    std::stringstream resTrace;
+    resTrace << "Tracer" << "_" << tStep-1 << ".h5m";
+    rval = mb->write_file(resTrace.str().c_str(), 0, "PARALLEL=WRITE_PART", &euler_set, 1, &tagElem, 1);
+  }
   rval = worker.update_tracer_data(out_set, tagElem, tagArea);
   CHECK_ERR(rval);
 
+  if (parallelWrite)
+  {
+    std::stringstream resTrace;
+    resTrace << "Tracer" << "_" << tStep << ".h5m";
+    rval = mb->write_file(resTrace.str().c_str(), 0, "PARALLEL=WRITE_PART", &euler_set, 1, &tagElem, 1);
+  }
+
   if (!noWrite) // so if write
   {
     std::stringstream newIntx;
@@ -459,7 +474,8 @@ ErrorCode compute_tracer_case1(Interface * mb, Intx2MeshOnSphere & worker, Entit
   CHECK_ERR(rval);
   rval = mb->delete_entities(todeleteVerts);
   CHECK_ERR(rval);
-  std::cout << " step: " << tStep << "\n";
+  if (rank==0)
+    std::cout << " step: " << tStep << "\n";
   return rval;
 }
 int main(int argc, char **argv)
@@ -505,6 +521,11 @@ int main(int argc, char **argv)
         noWrite = true;
       }
 
+      if (!strcmp(argv[index], "-pw"))
+      {
+        parallelWrite = true;
+      }
+
       if (!strcmp(argv[index], "-h"))
       {
         std::cout << "usage: -gtol <tol> -input <file> -O <extra_read_opts> \n   "
@@ -630,7 +651,12 @@ int main(int argc, char **argv)
       norm1+=fabs(*ptrTracer - iniVals[j])* (*ptrArea);
     }
   }
-  std::cout << " numSteps:" << numSteps << " 1-norm:" << norm1 << "\n";
+
+  double total_norm1=0;
+  int mpi_err = MPI_Reduce(&norm1, &total_norm1, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
+  if (MPI_SUCCESS != mpi_err) return 1;
+  if (0==rank)
+    std::cout << " numSteps:" << numSteps << " 1-norm:" << norm1 << "\n";
   MPI_Finalize();
   return 0;
 }


https://bitbucket.org/fathomteam/moab/commits/2122fc2c4e29/
Changeset:   2122fc2c4e29
Branch:      None
User:        iulian07
Date:        2013-11-09 05:48:57
Summary:     remove some test files from master branch

Affected #:  4 files

diff --git a/tools/mbcslam/Makefile.am b/tools/mbcslam/Makefile.am
index 61776bf..9f2087b 100644
--- a/tools/mbcslam/Makefile.am
+++ b/tools/mbcslam/Makefile.am
@@ -48,7 +48,7 @@ cfgdir = $(libdir)
 
 TESTS = intx_on_sphere_test  intx_in_plane_test  spec_visu_test spherical_area_test \
          case1_test  intx_mpas
-noinst_PROGRAMS =  cslam_par_test diffusion proj1 smallPoly mpas_mesh load_partial
+noinst_PROGRAMS =  cslam_par_test diffusion proj1 
 
 if ENABLE_mbzoltan
 noinst_PROGRAMS+=MPASpartitioner
@@ -65,9 +65,6 @@ case1_test_SOURCES = case1_test.cpp
 intx_mpas_SOURCES = intx_mpas.cpp
 cslam_par_test_SOURCES = cslam_par_test.cpp
 proj1_SOURCES = proj1.cpp
-smallPoly_SOURCES = smallPoly.cpp
-mpas_mesh_SOURCES = mpas_mesh.cpp
-load_partial_SOURCES = load_partial.cpp
 
 EXTRA_DIST  = lagrangeHomme.vtk  \
               eulerHomme.vtk \

diff --git a/tools/mbcslam/load_partial.cpp b/tools/mbcslam/load_partial.cpp
deleted file mode 100644
index cf65a0a..0000000
--- a/tools/mbcslam/load_partial.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/** @example LoadPartial.cpp
- * This example demonstrates how to load partially an h5m file
- * Sets in MOAB contain entities and have a tag on them to give meaning to the entities.
- * Tag name: PARALLEL_PARTITION_TAG_NAME "PARALLEL_PARTITION" is used for
- *   parallel partitions
- *
- * <b>Steps in this example </b>:
- *    -# Instantiate MOAB
- *    -# Get input mesh file name, already partitioned in 16 parts
- *    -# Load some parts; save
- *    -# Destroy the MOAB instance
- *
- *
- * <b> To compile: </b>
- *    make LoadPartial MOAB_DIR=<installdir> \n
- *
- * <b> To run: </b>
- *    -# LoadPartial <mesh-file><int> \n
- *    -# LoadPartial (This uses the default <mesh-file>: <MOAB_SRC_DIR>/MeshFiles/unittest/mbtest2.g)
- */
-#include <iostream>
-#include <string>
-
-// Include header for MOAB instance and range
-#include "moab/Core.hpp"
-#include "MBTagConventions.hpp"
-
-int main(int argc, char **argv) {
-
-  // instantiate & load a file
-  moab::Interface *mb = new moab::Core();
-
-  moab::ErrorCode rval;
-
-  std::string file_name = "mpas_p16.h5m";
-  int one = 1;
-
-  if (argc>1)
-    one = atoi(argv[1]);
-  if (argc>2)
-    file_name = argv[2];
-  rval = mb->load_file(file_name.c_str(),
-                       0, "DEBUG_IO=9;", PARALLEL_PARTITION_TAG_NAME, &one, 1);
-
-  if (moab::MB_SUCCESS!=rval)
-    std::cout << " failed to read\n";
-
-  rval = mb->write_file("part.h5m");
-  delete mb;
-}

diff --git a/tools/mbcslam/mpas_mesh.cpp b/tools/mbcslam/mpas_mesh.cpp
deleted file mode 100644
index 2e4026a..0000000
--- a/tools/mbcslam/mpas_mesh.cpp
+++ /dev/null
@@ -1,500 +0,0 @@
-/*
- * mpas_mesh.cpp
- *
- *  Created on: Sep 29
- */
-
-// simple mpas reader that should work in serial; read only the nodes and polygons
-//
-//
-#include <iostream>
-#include <sstream>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "moab/Core.hpp"
-#include "moab/Interface.hpp"
-#include "moab/ReadUtilIface.hpp"
-#include "MBTagConventions.hpp"
-#include "CslamUtils.hpp"
-
-#include "mpi.h"
-#include "pnetcdf.h"
-
-#define NCFUNC(func) ncmpi_ ## func
-
-//! Collective I/O mode get
-#define NCFUNCAG(func) ncmpi_get ## func ## _all
-
-//! Independent I/O mode get
-#define NCFUNCG(func) ncmpi_get ## func
-
-//! Nonblocking get (request aggregation), used so far only for ucd mesh
-#define NCFUNCREQG(func) ncmpi_iget ## func
-
-#define NCDF_SIZE MPI_Offset
-#define NCDF_DIFF MPI_Offset
-
-
-#include <algorithm>
-#include <string>
-#include <assert.h>
-
-#include <cmath>
-
-
-using namespace moab;
-
-#define INS_ID(stringvar, prefix, id) \
-          sprintf(stringvar, prefix, id)
-
-#define GET_DIM(ncdim, name, val)\
-    {                            \
-    int gdfail = NCFUNC(inq_dimid)(ncFile, name, &ncdim);          \
-    if (NC_NOERR == gdfail) {                                             \
-      MPI_Offset tmp_val;                                                   \
-      gdfail = NCFUNC(inq_dimlen)(ncFile, ncdim, &tmp_val);                        \
-      if (NC_NOERR != gdfail) {                                           \
-        std::cout<<"couldn't get dimension length for" << name<< " \n"; \
-        return 1;                                              \
-      }                                                                 \
-      else val = tmp_val;                                               \
-    } else val = 0;}
-
-#define GET_DIMB(ncdim, name, varname, id, val) \
-          INS_ID(name, varname, id); \
-          GET_DIM(ncdim, name, val);
-
-#define GET_VAR(name, id, dims) \
-    {                           \
-    id = -1;\
-    int gvfail = NCFUNC(inq_varid)( ncFile, name, &id);   \
-    if (NC_NOERR == gvfail) {       \
-    int ndims;\
-    gvfail = NCFUNC(inq_varndims)( ncFile, id, &ndims);\
-    if (NC_NOERR == gvfail) {\
-    dims.resize(ndims);    \
-    gvfail = NCFUNC(inq_vardimid)( ncFile, id, &dims[0]);}}}
-
-#define GET_1D_INT_VAR(name, id, vals) \
-    {GET_VAR(name, id, vals);  \
-  if (-1 != id) {\
-    NCDF_SIZE ntmp;\
-    int ivfail = NCFUNC(inq_dimlen)(ncFile, vals[0], &ntmp);\
-    vals.resize(ntmp);\
-    NCDF_SIZE ntmp1 = 0;                                                           \
-    ivfail = NCFUNC(get_vara_int_all)(ncFile, id, &ntmp1, &ntmp, &vals[0]);\
-    if (NC_NOERR != ivfail) {\
-      std::cout<<"ReadNCDF:: Problem getting variable " <<name <<"\n";\
-      return 1;}}}
-
-#define GET_1D_DBL_VAR(name, id, vals) \
-    {std::vector<int> dum_dims;        \
-  GET_VAR(name, id, dum_dims);\
-  if (-1 != id) {\
-    std::cout << " var:" << name << " id: " << id << "\n"; \
-    NCDF_SIZE ntmp;\
-    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
-    vals.resize(ntmp);\
-    NCDF_SIZE ntmp1 = 0;               \
-    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &ntmp, &vals[0]);\
-    if (NC_NOERR != dvfail) {\
-      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
-      return 1;}}}
-
-#define FILL_1D_DBL_VAR(name, id, vals) \
-    {std::vector<int> dum_dims;        \
-  GET_VAR(name, id, dum_dims);\
-  if (-1 != id) {\
-    MPI_Offset ntmp;\
-    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
-    std::cout <<" var:" << name << " ntmp:" << ntmp << "\n"; \
-    MPI_Offset ntmp1 = 0;                                                           \
-    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &ntmp, vals);\
-    if (NC_NOERR != dvfail) {\
-      std::cout<<"FILL_1D_DBL_VAR:: Problem getting variable "<< name<<"\n";\
-      return 1;}}}
-
-/*
-int get_2d_flt_var(int ncFile, const char * name, int index, std::vector<float> & vals)
-{
-  int id;
-  std::vector<int> dum_dims;
-  GET_VAR(name, id, dum_dims);
-  if (-1 != id) {
-    size_t ntmp;
-  int dvfail = nc_inq_dimlen(ncFile, dum_dims[1], &ntmp);
-  vals.resize(ntmp);
-  size_t ntmp1[2] = {index, 0};
-
-  int ntimes;
-  dvfail = nc_inq_dimlen(ncFile, dum_dims[0], &ntimes);
-  if (index>=ntimes) {
-    std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";
-    return 1;
-  }
-  size_t count[2] ={1, ntmp};
-  dvfail = nc_get_vara_float(ncFile, id, ntmp1, count, &vals[0]);
-  if (NC_NOERR != dvfail) {
-    std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";
-    return 1;
-  }
-  return 0;
-}
-*/
-/* get the variable along an index */
-#define GET_2D_FLT_VAR(name, id, index, vals) \
-    {std::vector<int> dum_dims;        \
-  GET_VAR(name, id, dum_dims);\
-  if (-1 != id) {\
-    MPI_Offset ntmp, ntmp2;\
-    int dvfail = NCFUNC(inq_dimlen)( ncFile, dum_dims[1], &ntmp);\
-    dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp2);\
-    vals.resize(ntmp);\
-    MPI_Offset ntmp1[2] = {index, 0}; \
-    if (index>=ntmp2) { \
-      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n"; \
-      return 1; \
-    } \
-    MPI_Offset count[2] ={1, ntmp}; \
-    dvfail = NCFUNC(get_vara_float)( ncFile, id, ntmp1, count, &vals[0]);\
-    if (NC_NOERR != dvfail) {\
-      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
-      return 1;}}}
-
-int main(int argc, char ** argv)
-{
-
-  MPI_Init(&argc, &argv);
-  int num_el = 50000;
-  const char *data_file = "/home/iulian/source/myMoabRepo/MeshFiles/unittest/io/mpasx1.642.t.2.nc";
-  if (argc>1)
-  {
-    data_file = argv[1];
-  }
-  std::cout << "num_el=" << num_el << "\n";
-
-  Core moab;
-  Interface & mb = moab;
-  ErrorCode rval;
-
-  int ncFile, temp_dim;        // netcdf/exodus file
-
-  int fail = NCFUNC(open)(MPI_COMM_WORLD, data_file, 0, MPI_INFO_NULL, &ncFile);
-  if (NC_NOWRITE != fail) {
-    std::cout<<"ReadNCDF:: problem opening Netcdf/Exodus II "<<data_file <<"\n";
-    return 1;
-  }
-  int maxEdges;
-  GET_DIM(temp_dim, "maxEdges", maxEdges);
-  std::cout << "maxEdges:" << maxEdges << "\n";
-
-  int nVertices;
-  GET_DIM(temp_dim, "nVertices", nVertices);
-    std::cout << "nVertices:" << nVertices << "\n";
-
-  int nCells;
-  GET_DIM(temp_dim, "nCells", nCells);
-  std::cout << "nCells:" << nCells << "\n";
-
-  // see if the mesh from metadata makes sense
-  // create polygons with the connectivity from conn array
-
-  ReadUtilIface* readMeshIface;
-  mb.query_interface( readMeshIface );
-  if (NULL==readMeshIface)
-    return 1;
-  EntityHandle node_handle = 0;
-  std::vector<double*> arrays;
-  rval = readMeshIface->get_node_coords(3, nVertices,
-      1, node_handle, arrays);
-  if (MB_SUCCESS!= rval)
-    return 1;
-
-  std::vector<double> cor;
-
-  FILL_1D_DBL_VAR("xVertex", temp_dim, &(arrays[0][0]));
-  FILL_1D_DBL_VAR("yVertex", temp_dim, &(arrays[1][0]));
-  FILL_1D_DBL_VAR("zVertex", temp_dim, &(arrays[2][0]));
-
-  Range nodes(node_handle, node_handle+nVertices-1);
-  std::vector<int> gids(nVertices);
-  for (int j=0; j<nVertices; j++)
-    gids[j]=j+1;
-  Tag gid;
-  int dum_val = 0;
-  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid, MB_TAG_DENSE | MB_TAG_CREAT, &dum_val);
-  if (MB_SUCCESS != rval)
-    return 1;
-
-  rval = mb.tag_set_data(gid, nodes, &gids[0]);
-  if (MB_SUCCESS!= rval)
-       return 1;
-
-  EntityHandle newSet;
-  rval = mb.create_meshset(MESHSET_SET, newSet);
-  if (MB_SUCCESS != rval)
-    return 1;
-
-  // so the nodes will be part
-  mb.add_entities(newSet, nodes);
-
-
-  std::vector<int>  nEdgesOnCell;
-  GET_1D_INT_VAR("nEdgesOnCell", temp_dim, nEdgesOnCell);
-
-  std::cout << " size of : nEdgesOnCell: " << nEdgesOnCell.size() << "\n";
-  std::vector<int> numCellsWithNEdges(maxEdges, 0);
-  int actualMaxEdges = 0;
-  for (int j=0; j<nCells; j++)
-  {
-    int nEdgesThisCell = nEdgesOnCell[j];
-    numCellsWithNEdges[nEdgesThisCell-1]++;
-    if (actualMaxEdges<nEdgesThisCell)
-      actualMaxEdges = nEdgesThisCell;
-  }
-  std::vector<EntityHandle> starthp(maxEdges, 0);
-  std::vector<int> indexCellsWithNEdges(actualMaxEdges, 0);
-  std::vector<EntityHandle*> conn_arr_local_cells_with_n_edges(actualMaxEdges);
-
-  for (int j=2; j<maxEdges; j++)
-  {
-    std::cout << "cells with " << j+1 << " edges:" << numCellsWithNEdges[j] << "\n";
-    if (numCellsWithNEdges[j]>0)
-    {
-      readMeshIface->get_element_connect(numCellsWithNEdges[j], j+1, MBPOLYGON, 0,
-          starthp[j], conn_arr_local_cells_with_n_edges[j]);
-    }
-  }
-
-  std::cout << " actualMaxEdges: " << actualMaxEdges << "\n";
-
-
-  std::vector<int> vertices_on_cells(nCells * actualMaxEdges);
-  NCDF_SIZE starts[2]={0, 0};
-  NCDF_SIZE counts[2]={nCells, actualMaxEdges};
-  std::vector<int> dum_dims;
-  int verticesOnCellVarId;
-  GET_VAR("verticesOnCell", verticesOnCellVarId, dum_dims);
-
-  int nf = NCFUNCAG(_vara_int)(ncFile, verticesOnCellVarId, starts, counts, &vertices_on_cells[0]);
-  if (nf!=0)
-    return 1;
-
-  for (int j = 1; j <= nCells; j++) {
-    int nEdgesThisCell = nEdgesOnCell[j-1]; //
-    int indxFill=indexCellsWithNEdges[nEdgesThisCell-1]*nEdgesThisCell;
-    for (int k =0; k<nEdgesThisCell; k++)
-    {
-      conn_arr_local_cells_with_n_edges[nEdgesThisCell-1][indxFill+k]=
-          (EntityHandle)vertices_on_cells[(j-1)*actualMaxEdges+k];
-    }
-
-    indexCellsWithNEdges[nEdgesThisCell-1]++;
-    EntityHandle polygon=starthp[nEdgesThisCell-1]+indexCellsWithNEdges[nEdgesThisCell-1];
-    mb.tag_set_data(gid, &polygon, 1, &j);
-  }
-
-  /*// create element tags with lat and lon, for centers
-  Tag latTag=0;
-  rval = mb.tag_get_handle("latCell", 1, MB_TYPE_DOUBLE, latTag, MB_TAG_DENSE | MB_TAG_CREAT);
-  if (MB_SUCCESS != rval)
-    return 1;
-  Tag lonTag=0;
-  rval = mb.tag_get_handle("lonCell", 1, MB_TYPE_DOUBLE, lonTag, MB_TAG_DENSE | MB_TAG_CREAT);
-  if (MB_SUCCESS != rval)
-    return 1;
-  // do a deep copy or not?? for now it is OK :(
-  std::vector<double> lonc;
-  GET_1D_DBL_VAR("latCell", temp_dim, lonc);
-  std::vector<double> latc;
-  GET_1D_DBL_VAR("lonCell", temp_dim, latc);*/
-
-  // now, we know that vertices are the same as handles, just set them dry :)
-
-
-/*  // build a kd tree with the vertices
-  EntityHandle tree_root;
-  AdaptiveKDTree kd(&mb, true);
-  rval = kd.build_tree(nodes, tree_root);
-  if (MB_SUCCESS != rval)
-    return 1;
-
-  unsigned int  min_depth, max_depth;
-  rval = kd.depth(tree_root, min_depth, max_depth);
-  if (MB_SUCCESS != rval)
-     return 1;
-  std::cout << "min_depth, max_depth " << min_depth << " " << max_depth << "\n";
-  // now, read the conn file created using spectral visu, and see how they fit
-  // this can be directly imported to moab
-  const char *myconn_file = "spec.R2.vtk";
-  EntityHandle euler_set;
-  rval = mb.create_meshset(MESHSET_SET, euler_set);
-  if (MB_SUCCESS != rval)
-    return 1;
-
-  rval = mb.load_file(myconn_file, &euler_set);
-
-  if (MB_SUCCESS != rval)
-    return 1;
-
-  mb.list_entities(&euler_set, 1);
-
-  Range specQuads;
-  rval = mb.get_entities_by_dimension(euler_set, 2, specQuads );
-  if (MB_SUCCESS != rval)
-     return 1;
-
-  Range vertices;
-  rval = mb.get_connectivity(specQuads, vertices);
-  if (MB_SUCCESS != rval)
-     return 1;
-
-  // do a mapping, from position of vertices to the vertices in the kd tree.
-  // find the closest vertex to each of this
-  std::vector<EntityHandle> mappedTo(vertices.size());
-  std::vector<double> mycoords(vertices.size()*3);
-  rval = mb.get_coords(vertices, &mycoords[0]);
-  double * ptr = &mycoords[0];
-  size_t num_verts=vertices.size();
-  for (size_t i=0; i<num_verts; i++, ptr+=3)
-  {
-    CartVect pos(ptr); // take 3 coordinates
-    std::vector<EntityHandle> leaves;
-    rval = kd.leaves_within_distance( tree_root,
-                                          ptr,
-                                          0.001,
-                                        leaves);
-    if (MB_SUCCESS != rval)
-      return 1;
-    Range closeVerts;
-    for (std::vector<EntityHandle>::iterator vit = leaves.begin(); vit != leaves.end(); vit++)
-    {
-      rval= mb.get_entities_by_handle(*vit, closeVerts, Interface::UNION);
-      if (moab::MB_SUCCESS != rval)
-        return 1;
-    }
-    if (closeVerts.size()<1)
-    {
-      std::cout << "increase tolerance, no points close to " << pos << "\n";
-      return 1;
-    }
-    std::vector<CartVect> coordsTarget(closeVerts.size());
-    rval = mb.get_coords(closeVerts, &(coordsTarget[0][0]));
-    if (MB_SUCCESS != rval)
-      return 1;
-    double minDist2=(pos-coordsTarget[0]).length_squared();
-    EntityHandle closestVertex=closeVerts[0];
-    for (unsigned int j=1; j<closeVerts.size(); j++)
-    {
-      double dist2=(pos-coordsTarget[j]).length_squared();
-      if (minDist2>dist2)
-      {
-        closestVertex = closeVerts[j];
-        minDist2=dist2;
-      }
-    }
-    if (minDist2 > 0.00001)
-    {
-      std::cout << " problem with node " << vertices[i] << "  min dist2:" << minDist2 << "\n";
-      return 1;
-    }
-    mappedTo [i] = closestVertex;
-  }
-
-  num_el = (int)specQuads.size();
-  // tmp_ptr is of type int* and points at the same place as conn
-  EntityHandle * conn = 0;
-
-  EntityHandle elh;
-
-  readMeshIface->get_element_connect(
-          num_el,
-          4,
-          MBQUAD,
-          1,
-          elh,
-          conn);
-
-  EntityHandle firstVertMyMesh=vertices[0];
-  for (int k=0; k<num_el; k++)
-  {
-    const EntityHandle * myconn=0;
-    EntityHandle specElem = specQuads[k];
-    int num_nodes=0;
-    rval = mb.get_connectivity(specElem, myconn, num_nodes);
-    if (MB_SUCCESS != rval || num_nodes !=4)
-      return 1;
-
-    int start_el = k*4;
-    for (int j=0; j<4; j++)
-       conn[start_el+j] = mappedTo[myconn[j]-firstVertMyMesh];
-  }
-  std::cout << " conn:" << conn[0] << " " << conn[1] << " " << conn[3]<< "\n";
-  Range erange(elh, elh+num_el-1);
-
-  mb.add_entities(newSet, erange);
-  std::vector<int> gidels(num_el);
-  Tag gid2;
-  rval = mb.tag_get_handle("GLOBAL_ID_EL", 1, MB_TYPE_INTEGER,
-        gid2, MB_TAG_SPARSE|MB_TAG_CREAT);
-
-  if (MB_SUCCESS != rval)
-      return 1;
-  for (int k=0; k<num_el; k++)
-    gidels[k]=k+1;
-  mb.tag_set_data(gid2, erange, &gidels[0]);
-
-  int times;
-  GET_DIM(temp_dim, "time", times);
-  Tag velotag;
-  rval = mb.tag_get_handle("VELO", 3, MB_TYPE_DOUBLE,
-            velotag, MB_TAG_DENSE|MB_TAG_CREAT);
-  if (MB_SUCCESS!= rval)
-    return 1;*/
-
- /* for (size_t tt=0; tt<56 (size_t)times; tt++)
-  {
-    // now, read velocities from file:
-    // read the U850 and V850 variables
-    std::vector<float> u850;
-    GET_2D_FLT_VAR("U850", temp_dim, tt, u850);
-    std::vector<float> v850;
-    GET_2D_FLT_VAR("V850", temp_dim, tt, v850);
-
-    std::cout << " U850:" << u850[0] << " " << u850[1] << " " << u850[5] << " "<< u850.size()<<"\n";
-    std::cout << " V850:" << v850[0] << " " << v850[1] << " " << v850[5] << " "<< u850.size()<<"\n";
-    // ok, use radius as 6371km; not needed
-
-    std::vector<CartVect> velo850(ncol);
-
-    std::stringstream fileName;
-    fileName << "VELO0" <<  tt << ".h5m";
-    std::cout << " read velocities at 850 for time:" << tt << "\n";
-
-
-    for (int k=0; k<ncol; k++)
-    {
-      double latRad=lat[k]*conversion_factor;
-      double lonRad=lon[k]*conversion_factor;
-      CartVect U(-sin(lonRad), cos(lonRad), 0.);
-      CartVect V(-sin(latRad)*cos(lonRad), -sin(latRad)*cos(lonRad), cos(latRad));
-      velo850[k]=U*u850[k] +V*v850[k];
-    }
-    rval = mb.tag_set_data(velotag, nodes, &(velo850[0][0]));
-    if (MB_SUCCESS!= rval)
-      return 1;
-    rval = mb.write_mesh(fileName.str().c_str(), &newSet, 1);
-    if (MB_SUCCESS!= rval)
-      return 1;
-  }*/
-
-  rval = mb.write_mesh("out.h5m");
-  if (rval!=MB_SUCCESS)
-    std::cout << " can't write file\n";
-  std::cout << " wrote out.h5m\n";
-  MPI_Finalize();
-
-  return 0;
-}

diff --git a/tools/mbcslam/smallPoly.cpp b/tools/mbcslam/smallPoly.cpp
deleted file mode 100644
index b5b2c5a..0000000
--- a/tools/mbcslam/smallPoly.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * smallPoly.cpp
- *
- */
-
-#include <iostream>
-#include <sstream>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include "moab/Core.hpp"
-#include "moab/Interface.hpp"
-#include "TestUtil.hpp"
-
-using namespace moab;
-
-int main(int argc, char **argv)
-{
-
-  // read an MPAS file, extract few polys and write them out
-  std::string fileN="mpas_p8.h5m";
-  const char *filename_mesh1 = fileN.c_str();
-  Core moab;
-  Interface & mb = moab;
-  EntityHandle euler_set;
-  ErrorCode rval;
-  rval = mb.create_meshset(MESHSET_SET, euler_set);
-  CHECK_ERR(rval);
-
-  rval = mb.load_file(filename_mesh1);
-  CHECK_ERR(rval);
-
-  // get one / two vertices , and polys adjacent to them;
-  Range verts;
-  rval = mb.get_entities_by_type(0, MBVERTEX, verts);
-  CHECK_ERR(rval);
-
-  EntityHandle v[3]={verts[0], verts[1], verts[2]};
-  Range  elems;
-  rval= mb.get_adjacencies(v, 3, 2, false, elems, Interface::UNION);
-  CHECK_ERR(rval);
-
-  rval = mb.add_entities(euler_set, elems);
-  CHECK_ERR(rval);
-
-  rval = mb.write_mesh("fewPolys.h5m", &euler_set, 1);
-  CHECK_ERR(rval);
-    return 0;
-
-}
-
-


https://bitbucket.org/fathomteam/moab/commits/1b0b232c3263/
Changeset:   1b0b232c3263
Branch:      None
User:        iulian07
Date:        2013-11-09 05:51:57
Summary:     remove zoltan example and dependency

Affected #:  2 files

diff --git a/tools/mbcslam/MPASpartitioner.cpp b/tools/mbcslam/MPASpartitioner.cpp
deleted file mode 100644
index ccf80a5..0000000
--- a/tools/mbcslam/MPASpartitioner.cpp
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * MPASpartitioner.cpp
- *  simple mpas reader that should work in parallel to partition the element space
- *  will link against zoltan
- *  Created on: Oct 8
- */
-
-
-//
-//
-#include <iostream>
-#include <sstream>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "MBZoltan.hpp"
-#include "moab/Core.hpp"
-#include "moab/Interface.hpp"
-#include "moab/ReadUtilIface.hpp"
-#include "MBTagConventions.hpp"
-#include "CslamUtils.hpp"
-#include "moab/ParallelComm.hpp"
-
-#include "mpi.h"
-#include "pnetcdf.h"
-
-#define NCFUNC(func) ncmpi_ ## func
-
-//! Collective I/O mode get
-#define NCFUNCAG(func) ncmpi_get ## func ## _all
-
-//! Independent I/O mode get
-#define NCFUNCG(func) ncmpi_get ## func
-
-//! Nonblocking get (request aggregation), used so far only for ucd mesh
-#define NCFUNCREQG(func) ncmpi_iget ## func
-
-#define NCDF_SIZE MPI_Offset
-#define NCDF_DIFF MPI_Offset
-
-
-#include <algorithm>
-#include <string>
-#include <assert.h>
-
-#include <cmath>
-
-
-using namespace moab;
-
-int ierr, rank=0;
-
-// Error routines for use with MOAB API
-#define CHKERR(CODE, MSG)                                 \
-  do {                                                    \
-    if (MB_SUCCESS != (CODE)) {                           \
-      std::string errstr;  mbi->get_last_error(errstr);   \
-      std::cerr << errstr << std::endl;                   \
-      std::cerr << MSG << std::endl;                      \
-      MPI_Finalize();                                     \
-    }                                                     \
-  } while(false)
-
-// Error routines for use with MPI API
-#define MPICHKERR(CODE, MSG)                              \
-  do {                                                    \
-    if (0 != CODE) {                                      \
-      std::cerr << MSG << std::endl;                      \
-      MPI_Finalize();                                     \
-    }                                                     \
-  } while(false)
-
-#define dbgprint(MSG)                                \
-  do {                                              \
-      if (!rank) std::cerr << MSG << std::endl;     \
-  } while(false)
-
-#define dbgprintall(MSG)                                      \
-  do {                                                        \
-      std::cerr << "[" << rank << "]: " << MSG << std::endl;  \
-  } while(false)
-
-
-#define INS_ID(stringvar, prefix, id) \
-          sprintf(stringvar, prefix, id)
-
-#define GET_DIM(ncdim, name, val)\
-    {                            \
-    int gdfail = NCFUNC(inq_dimid)(ncFile, name, &ncdim);          \
-    if (NC_NOERR == gdfail) {                                             \
-      MPI_Offset tmp_val;                                                   \
-      gdfail = NCFUNC(inq_dimlen)(ncFile, ncdim, &tmp_val);                        \
-      if (NC_NOERR != gdfail) {                                           \
-        std::cout<<"couldn't get dimension length for" << name<< " \n"; \
-        return 1;                                              \
-      }                                                                 \
-      else val = tmp_val;                                               \
-    } else val = 0;}
-
-#define GET_DIMB(ncdim, name, varname, id, val) \
-          INS_ID(name, varname, id); \
-          GET_DIM(ncdim, name, val);
-
-#define GET_VAR(name, id, dims) \
-    {                           \
-    id = -1;\
-    int gvfail = NCFUNC(inq_varid)( ncFile, name, &id);   \
-    if (NC_NOERR == gvfail) {       \
-    int ndims;\
-    gvfail = NCFUNC(inq_varndims)( ncFile, id, &ndims);\
-    if (NC_NOERR == gvfail) {\
-    dims.resize(ndims);    \
-    gvfail = NCFUNC(inq_vardimid)( ncFile, id, &dims[0]);}}}
-
-#define GET_1D_INT_VAR(name, id, vals) \
-    {GET_VAR(name, id, vals);  \
-  if (-1 != id) {\
-    NCDF_SIZE ntmp;\
-    int ivfail = NCFUNC(inq_dimlen)(ncFile, vals[0], &ntmp);\
-    vals.resize(ntmp);\
-    NCDF_SIZE ntmp1 = 0;                                                           \
-    ivfail = NCFUNC(get_vara_int_all)(ncFile, id, &ntmp1, &ntmp, &vals[0]);\
-    if (NC_NOERR != ivfail) {\
-      std::cout<<"ReadNCDF:: Problem getting variable " <<name <<"\n";\
-      return 1;}}}
-
-#define GET_1D_DBL_VAR(name, id, vals) \
-    {std::vector<int> dum_dims;        \
-  GET_VAR(name, id, dum_dims);\
-  if (-1 != id) {\
-    std::cout << " var:" << name << " id: " << id << "\n"; \
-    NCDF_SIZE ntmp;\
-    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
-    vals.resize(ntmp);\
-    NCDF_SIZE ntmp1 = 0;               \
-    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &ntmp, &vals[0]);\
-    if (NC_NOERR != dvfail) {\
-      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
-      return 1;}}}
-
-#define GET_1D_DBL_VAR_RANGE(name, id, startIndex, endIndex, vals) \
-    {std::vector<int> dum_dims;        \
-  GET_VAR(name, id, dum_dims);\
-  if (-1 != id) {\
-    if (rank==0) std::cout << " var:" << name << " id: " << id << "\n"; \
-    NCDF_SIZE ntmp;\
-    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
-    if (rank==0) std::cout << " prepare read var " << name << " start:" << startIndex << " end:"<< endIndex <<" Actual size:" << \
-       ntmp << "\n" ; \
-    if (startIndex > (int)ntmp || endIndex > (int) ntmp || startIndex>=endIndex) \
-      { std::cout << "bad input \n"; return 1;} \
-    vals.resize(endIndex-startIndex);\
-    NCDF_SIZE ntmp1 = startIndex;    NCDF_SIZE count = endIndex-startIndex;           \
-    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &count, &vals[0]);\
-    if (NC_NOERR != dvfail) {\
-      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
-      return 1;}}}
-
-#define FILL_1D_DBL_VAR(name, id, vals) \
-    {std::vector<int> dum_dims;        \
-  GET_VAR(name, id, dum_dims);\
-  if (-1 != id) {\
-    MPI_Offset ntmp;\
-    int dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp);\
-    std::cout <<" var:" << name << " ntmp:" << ntmp << "\n"; \
-    MPI_Offset ntmp1 = 0;                                                           \
-    dvfail = NCFUNC(get_vara_double_all)( ncFile, id, &ntmp1, &ntmp, vals);\
-    if (NC_NOERR != dvfail) {\
-      std::cout<<"FILL_1D_DBL_VAR:: Problem getting variable "<< name<<"\n";\
-      return 1;}}}
-
-/*
-int get_2d_flt_var(int ncFile, const char * name, int index, std::vector<float> & vals)
-{
-  int id;
-  std::vector<int> dum_dims;
-  GET_VAR(name, id, dum_dims);
-  if (-1 != id) {
-    size_t ntmp;
-  int dvfail = nc_inq_dimlen(ncFile, dum_dims[1], &ntmp);
-  vals.resize(ntmp);
-  size_t ntmp1[2] = {index, 0};
-
-  int ntimes;
-  dvfail = nc_inq_dimlen(ncFile, dum_dims[0], &ntimes);
-  if (index>=ntimes) {
-    std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";
-    return 1;
-  }
-  size_t count[2] ={1, ntmp};
-  dvfail = nc_get_vara_float(ncFile, id, ntmp1, count, &vals[0]);
-  if (NC_NOERR != dvfail) {
-    std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";
-    return 1;
-  }
-  return 0;
-}
-*/
-/* get the variable along an index */
-#define GET_2D_FLT_VAR(name, id, index, vals) \
-    {std::vector<int> dum_dims;        \
-  GET_VAR(name, id, dum_dims);\
-  if (-1 != id) {\
-    MPI_Offset ntmp, ntmp2;\
-    int dvfail = NCFUNC(inq_dimlen)( ncFile, dum_dims[1], &ntmp);\
-    dvfail = NCFUNC(inq_dimlen)(ncFile, dum_dims[0], &ntmp2);\
-    vals.resize(ntmp);\
-    MPI_Offset ntmp1[2] = {index, 0}; \
-    if (index>=ntmp2) { \
-      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n"; \
-      return 1; \
-    } \
-    MPI_Offset count[2] ={1, ntmp}; \
-    dvfail = NCFUNC(get_vara_float)( ncFile, id, ntmp1, count, &vals[0]);\
-    if (NC_NOERR != dvfail) {\
-      std::cout<<"ReadNCDF:: Problem getting variable "<< name<<"\n";\
-      return 1;}}}
-
-int main(int argc, char ** argv)
-{
-
-  MPI_Comm comm = MPI_COMM_WORLD;
-  ierr = MPI_Init(&argc, &argv);
-  MPICHKERR(ierr, "MPI Init  failed");
-  ierr = MPI_Comm_rank(comm, &rank);
-  MPICHKERR(ierr, "rank failed");
-
-
-  const char *data_file = "/home/iulian/source/myMoabRepo/MeshFiles/unittest/io/mpasx1.642.t.2.nc";
-  if (argc>1)
-  {
-    data_file = argv[1];
-  }
-
-  if (0==rank)
-    std::cout<<" processing file: " << data_file << "\n";
-  Interface * mb = new Core;
-  ErrorCode rval;
-
-  ParallelComm* pcomm = new ParallelComm(mb, MPI_COMM_WORLD);
-  int nprocs = pcomm->proc_config().proc_size();
-
-  MBZoltan * mbZTool = new MBZoltan(mb, false, argc, argv);
-
-  int ncFile, temp_dim;        // netcdf/exodus file
-
-  int fail = NCFUNC(open)(comm, data_file, 0, MPI_INFO_NULL, &ncFile);
-  if (NC_NOWRITE != fail) {
-    std::cout<<"ReadNCDF:: problem opening Netcdf/Exodus II "<<data_file <<"\n";
-    return 1;
-  }
-  int maxEdges;
-  GET_DIM(temp_dim, "maxEdges", maxEdges);
-
-  int nVertices;
-  GET_DIM(temp_dim, "nVertices", nVertices);
-
-  int nCells;
-  GET_DIM(temp_dim, "nCells", nCells);
-
-  if (rank==0)
-  {
-    std::cout << "maxEdges:" << maxEdges << "\n";
-    std::cout << "nVertices:" << nVertices << "\n";
-    std::cout << "nCells:" << nCells << "\n";
-  }
-  // see if the mesh from metadata makes sense
-  // create polygons with the connectivity from conn array
-
-  // find out how many element centers do we have to read per processor
-  int numLocalCells = nCells/nprocs;
-
-  int leftOver= nCells%nprocs;
-  if (rank<leftOver)
-    numLocalCells++;
-  // start index
-  int startCellIndex = rank*numLocalCells;
-  if (rank>=leftOver)
-    startCellIndex+=leftOver;
-  int endCellIndex = startCellIndex + numLocalCells; // exclusive
-  // so now, every processor will read xCell, yCell, zCell for cells with indices:
-  // [startCellIndex, endCellIndex)
-  // their global ids will be [startCellIndex+1, endCellIndex+1) // global id starts at 1 :)
-  // read 3 coordinates for x, y, z, separately
-
-  std::vector<double> x, y, z;
-  GET_1D_DBL_VAR_RANGE("xCell", temp_dim, startCellIndex, endCellIndex, x) ;
-  GET_1D_DBL_VAR_RANGE("yCell", temp_dim, startCellIndex, endCellIndex, y) ;
-  GET_1D_DBL_VAR_RANGE("zCell", temp_dim, startCellIndex, endCellIndex, z) ;
-
-  Range localGIDs;
-  rval = mbZTool->repartition(x, y, z, startCellIndex+1, "RCB", localGIDs );
-  if (rval !=MB_SUCCESS)
-    std::cout <<" error in partitioning\n";
-
-  // gather all psizes on root for printing
-  int lsize[2]={ (int)localGIDs.psize(), (int)localGIDs.size()};
-  /*ierr = MPI_Gather(
-    void *sendbuf,
-    int sendcnt,
-    MPI_Datatype sendtype,
-    void *recvbuf,
-    int recvcnt,
-    MPI_Datatype recvtype,
-    int root,
-    MPI_Comm comm
-  );*/
-  int * sizes=0;
-  if (rank==0)
-    sizes = new int [2* nprocs];
-  ierr = MPI_Gather( lsize, 2, MPI_INT, sizes, 2, MPI_INT, 0, comm);
-
-  if (rank==0)
-  {
-    for (int i=0; i<nprocs; i++)
-      std::cout << " on rank:" << i <<"  psize:" << sizes[2*i] << " size: " << sizes[2*i+1] << "\n";
-    delete [] sizes;
-    std::cout<<" localGIDs on rank 0\n";
-    localGIDs.print(0);
-  }
-  // form tuples (toProc, GlobalId)
-  MPI_Finalize();
-
-  return 0;
-}

diff --git a/tools/mbcslam/Makefile.am b/tools/mbcslam/Makefile.am
index 9f2087b..b6b7b9d 100644
--- a/tools/mbcslam/Makefile.am
+++ b/tools/mbcslam/Makefile.am
@@ -16,14 +16,6 @@ AM_CPPFLAGS += -DSRCDIR=$(srcdir) \
                -I$(top_builddir)/itaps \
                -I$(top_builddir)/itaps/imesh \
                -I$(top_srcdir)/test 
-if ENABLE_mbzoltan
-  AM_CPPFLAGS +=  $(ZOLTAN_INC_FLAGS) \
-               -I$(top_srcdir)/tools/mbzoltan \
-               -I$(top_builddir)/tools/mbzoltan
-if HAVE_CGM
-  AM_CPPFLAGS += @CGM_CPPFLAGS@ -DCGM @MOAB_CGM_DEFINES@
-endif
-endif
 
 lib_LTLIBRARIES = libmbcslam.la
 libmbcslam_la_LIBADD = $(top_builddir)/src/libMOAB.la $(top_builddir)/itaps/imesh/libiMesh.la \
@@ -50,11 +42,6 @@ TESTS = intx_on_sphere_test  intx_in_plane_test  spec_visu_test spherical_area_t
          case1_test  intx_mpas
 noinst_PROGRAMS =  cslam_par_test diffusion proj1 
 
-if ENABLE_mbzoltan
-noinst_PROGRAMS+=MPASpartitioner
-MPASpartitioner_SOURCES = MPASpartitioner.cpp
-endif 
-
 check_PROGRAMS = $(TESTS) 
 intx_on_sphere_test_SOURCES = intx_on_sphere_test.cpp
 diffusion_SOURCES = diffusion.cpp


https://bitbucket.org/fathomteam/moab/commits/ab70281068f3/
Changeset:   ab70281068f3
Branch:      master
User:        iulian07
Date:        2013-11-10 18:17:02
Summary:     Merge branch 'master' of bitbucket.org:fathomteam/moab

Affected #:  3 files

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index 6a73e31..54ba598 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -4,7 +4,7 @@
 #include "moab/SpectralMeshTool.hpp"
 #include "MBTagConventions.hpp"
 
-#if HAVE_ZOLTAN
+#ifdef HAVE_ZOLTAN
 #include "MBZoltan.hpp"
 #endif
 
@@ -971,7 +971,7 @@ ErrorCode NCHelperMPAS::redistribute_local_cells(int start_cell_idx)
 {
   // If possible, apply Zoltan partition
   if (_readNC->partMethod == ScdParData::RCBZOLTAN) {
-#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+#if defined(USE_MPI) && defined(HAVE_ZOLTAN)
     // Read x coordinates of cell centers
     int xCellVarId;
     int success = NCFUNC(inq_varid)(_fileId, "xCell", &xCellVarId);

diff --git a/test/io/read_mpas_nc.cpp b/test/io/read_mpas_nc.cpp
index d6e886f..75923fd 100644
--- a/test/io/read_mpas_nc.cpp
+++ b/test/io/read_mpas_nc.cpp
@@ -25,7 +25,9 @@ void test_read_no_mixed_elements(); // Test read option NO_MIXED_ELEMENTS
 void test_read_no_edges(); // Test read option NO_EDGES
 void test_gather_onevar(); // Test gather set with one variable
 
-ErrorCode get_options(std::string& opts);
+void get_options(std::string& opts);
+
+const double eps = 1e-20;
 
 int main(int argc, char* argv[])
 {
@@ -63,10 +65,10 @@ 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());
+  // Read mesh and read all variables at all timesteps
+  ErrorCode rval = mb.load_file(example, NULL, opts.c_str());
   CHECK_ERR(rval);
 
   int procs = 1;
@@ -75,8 +77,11 @@ void test_read_all()
   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) {
+    // For each tag, check two values
+    double val[2];
+
     // Check tags for vertex variable vorticity
     Tag vorticity_tag0, vorticity_tag1;
     rval = mb.tag_get_handle("vorticity0", 1, MB_TYPE_DOUBLE, vorticity_tag0);
@@ -87,19 +92,18 @@ void test_read_all()
     // Get vertices (1280 edges)
     Range verts;
     rval = mb.get_entities_by_type(0, MBVERTEX, verts);
-    assert(rval == MB_SUCCESS);
+    CHECK_ERR(rval);
     CHECK_EQUAL((size_t)1280, verts.size());
     CHECK_EQUAL((size_t)1, verts.psize());
 
-    const double eps = 1e-20;
-    double val[2];
-
     // Check vorticity tag values on first two vertices
     EntityHandle vert_ents[] = {verts[0], verts[1]};
-    rval = mb.tag_get_data(vorticity_tag0, &vert_ents[0], 2, val);
+    rval = mb.tag_get_data(vorticity_tag0, vert_ents, 2, val);
+    CHECK_ERR(rval);
     CHECK_REAL_EQUAL(1.1, val[0], eps);
     CHECK_REAL_EQUAL(1.2, val[1], eps);
-    rval = mb.tag_get_data(vorticity_tag1, &vert_ents[0], 2, val);
+    rval = mb.tag_get_data(vorticity_tag1, vert_ents, 2, val);
+    CHECK_ERR(rval);
     CHECK_REAL_EQUAL(2.1, val[0], eps);
     CHECK_REAL_EQUAL(2.2, val[1], eps);
 
@@ -113,16 +117,18 @@ void test_read_all()
     // Get edges (1920 edges)
     Range edges;
     rval = mb.get_entities_by_type(0, MBEDGE, edges);
-    assert(rval == MB_SUCCESS);
+    CHECK_ERR(rval);
     CHECK_EQUAL((size_t)1920, edges.size());
     CHECK_EQUAL((size_t)1, edges.psize());
 
     // Check u tag values on two specified edges
     EntityHandle edge_ents[] = {edges[5], edges[6]};
-    rval = mb.tag_get_data(u_tag0, &edge_ents[0], 2, val);
+    rval = mb.tag_get_data(u_tag0, edge_ents, 2, val);
+    CHECK_ERR(rval);
     CHECK_REAL_EQUAL(1.113138721544778, val[0], eps);
     CHECK_REAL_EQUAL(-1.113138721930009, val[1], eps);
-    rval = mb.tag_get_data(u_tag1, &edge_ents[0], 2, val);
+    rval = mb.tag_get_data(u_tag1, edge_ents, 2, val);
+    CHECK_ERR(rval);
     CHECK_REAL_EQUAL(2.113138721544778, val[0], eps);
     CHECK_REAL_EQUAL(-2.113138721930009, val[1], eps);
 
@@ -136,7 +142,7 @@ void test_read_all()
     // Get cells (12 pentagons and 630 hexagons)
     Range cells;
     rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
-    assert(rval == MB_SUCCESS);
+    CHECK_ERR(rval);
     CHECK_EQUAL((size_t)642, cells.size());
 #ifdef USE_MPI
     // If MOAB is compiled parallel, sequence size requested are increased
@@ -149,10 +155,12 @@ void test_read_all()
 
     // Check ke tag values on first pentagon and first hexagon
     EntityHandle cell_ents[] = {cells[0], cells[12]};
-    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
+    rval = mb.tag_get_data(ke_tag0, cell_ents, 2, val);
+    CHECK_ERR(rval);
     CHECK_REAL_EQUAL(15.001, val[0], eps);
     CHECK_REAL_EQUAL(16.013, val[1], eps);
-    rval = mb.tag_get_data(ke_tag1, &cell_ents[0], 2, val);
+    rval = mb.tag_get_data(ke_tag1, cell_ents, 2, val);
+    CHECK_ERR(rval);
     CHECK_REAL_EQUAL(25.001, val[0], eps);
     CHECK_REAL_EQUAL(26.013, val[1], eps);
   }
@@ -162,12 +170,13 @@ void test_read_onevar()
 {
   Core moab;
   Interface& mb = moab;
+
   std::string opts;
-  ErrorCode rval = get_options(opts);
-  CHECK_ERR(rval);
+  get_options(opts);
 
-  opts += std::string(";VARIABLE=ke");
-  rval = mb.load_file(example, NULL, opts.c_str());
+  // Read mesh and read cell variable ke at all timesteps
+  opts += ";VARIABLE=ke";
+  ErrorCode rval = mb.load_file(example, NULL, opts.c_str());
   CHECK_ERR(rval);
 
   int procs = 1;
@@ -176,9 +185,9 @@ void test_read_onevar()
   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
+    // Check ke tags
     Tag ke_tag0, ke_tag1;
     rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
     CHECK_ERR(rval);
@@ -188,7 +197,7 @@ void test_read_onevar()
     // Get cells (12 pentagons and 630 hexagons)
     Range cells;
     rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
-    assert(rval == MB_SUCCESS);
+    CHECK_ERR(rval);
     CHECK_EQUAL((size_t)642, cells.size());
 
 #ifdef USE_MPI
@@ -200,16 +209,23 @@ void test_read_onevar()
     CHECK_EQUAL((size_t)1, cells.psize());
 #endif
 
-    // Check ke tag values on first pentagon and first hexagon
-    const double eps = 1e-20;
-    double val[2];
-    EntityHandle cell_ents[] = {cells[0], cells[12]};
-    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
-    CHECK_REAL_EQUAL(15.001, val[0], eps);
-    CHECK_REAL_EQUAL(16.013, val[1], eps);
-    rval = mb.tag_get_data(ke_tag1, &cell_ents[0], 2, val);
-    CHECK_REAL_EQUAL(25.001, val[0], eps);
-    CHECK_REAL_EQUAL(26.013, val[1], eps);
+    // Check ke tag values on 4 cells: first pentagon, last pentagon,
+    // first hexagon, and last hexagon
+    EntityHandle cell_ents[] = {cells[0], cells[11], cells[12], cells[641]};
+    double ke0_val[4];
+    rval = mb.tag_get_data(ke_tag0, cell_ents, 4, ke0_val);
+    CHECK_ERR(rval);
+    CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+    CHECK_REAL_EQUAL(15.012, ke0_val[1], eps);
+    CHECK_REAL_EQUAL(16.013, ke0_val[2], eps);
+    CHECK_REAL_EQUAL(16.642, ke0_val[3], eps);
+    double ke1_val[4];
+    rval = mb.tag_get_data(ke_tag1, cell_ents, 4, ke1_val);
+    CHECK_ERR(rval);
+    CHECK_REAL_EQUAL(25.001, ke1_val[0], eps);
+    CHECK_REAL_EQUAL(25.012, ke1_val[1], eps);
+    CHECK_REAL_EQUAL(26.013, ke1_val[2], eps);
+    CHECK_REAL_EQUAL(26.642, ke1_val[3], eps);
   }
 }
 
@@ -217,19 +233,21 @@ void test_read_onetimestep()
 {
   Core moab;
   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());
+  // Read mesh and read all variables at 2nd timestep
+  opts += ";TIMESTEP=1";
+  ErrorCode rval = mb.load_file(example, NULL, opts.c_str());
   CHECK_ERR(rval);
 
-  // Check for proper tags
-  Tag ke_tag0, ke_tag1;
-  rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+  // Check vorticity tags
+  Tag vorticity_tag0, vorticity_tag1;
+  rval = mb.tag_get_handle("vorticity0", 1, MB_TYPE_DOUBLE, vorticity_tag0);
+  // Tag vorticity0 should not exist
   CHECK_EQUAL(rval, MB_TAG_NOT_FOUND);
-  rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+  rval = mb.tag_get_handle("vorticity1", 1, MB_TYPE_DOUBLE, vorticity_tag1);
   CHECK_ERR(rval);
 }
 
@@ -238,33 +256,35 @@ void test_read_nomesh()
   Core moab;
   Interface& mb = moab;
 
-  // Need a set for nomesh to work right
-  EntityHandle set;
-  ErrorCode rval = mb.create_meshset(MESHSET_SET, set);
+  // Need a file set for nomesh to work right
+  EntityHandle file_set;
+  ErrorCode rval = mb.create_meshset(MESHSET_SET, file_set);
   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, &set, opts.c_str());
+  // Read mesh and read all variables at 1st timestep
+  opts = orig + ";TIMESTEP=0";
+  rval = mb.load_file(example, &file_set, opts.c_str());
   CHECK_ERR(rval);
 
-  // Check for proper tags
-  Tag ke_tag0, ke_tag1;
-  rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+  // Check u tags
+  Tag u_tag0, u_tag1;
+  rval = mb.tag_get_handle("u0", 1, MB_TYPE_DOUBLE, u_tag0);
   CHECK_ERR(rval);
-  rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+  // Tag u1 should not exist
+  rval = mb.tag_get_handle("u1", 1, MB_TYPE_DOUBLE, u_tag1);
   CHECK_EQUAL(rval, MB_TAG_NOT_FOUND);
 
-  // Now read 2nd timestep with nomesh option
-  opts = orig + std::string(";TIMESTEP=1;NOMESH");
-  rval = mb.load_file(example, &set, opts.c_str());
+  // Read all variables at 2nd timestep 0, no need to read mesh
+  opts = orig + ";TIMESTEP=1;NOMESH";
+  rval = mb.load_file(example, &file_set, opts.c_str());
   CHECK_ERR(rval);
 
-  // Check for proper tag
-  rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+  // Check tag u1 again
+  rval = mb.tag_get_handle("u1", 1, MB_TYPE_DOUBLE, u_tag1);
+  // Tag u1 should exist at this time
   CHECK_ERR(rval);
 }
 
@@ -273,58 +293,111 @@ void test_read_novars()
   Core moab;
   Interface& mb = moab;
 
-  // Need a set for nomesh to work right
-  EntityHandle set;
-  ErrorCode rval = mb.create_meshset(MESHSET_SET, set);
+  // Need a file set for nomesh to work right
+  EntityHandle file_set;
+  ErrorCode rval = mb.create_meshset(MESHSET_SET, file_set);
   CHECK_ERR(rval);
 
   std::string orig, opts;
-  rval = get_options(orig);
+  get_options(orig);
   CHECK_ERR(rval);
 
-  opts = orig + std::string(";NOMESH;VARIABLE=");
-  rval = mb.load_file(example, &set, opts.c_str());
+  // Read header info only, no mesh, no variables
+  opts = orig + ";NOMESH;VARIABLE=";
+  rval = mb.load_file(example, &file_set, opts.c_str());
   CHECK_ERR(rval);
 
-  opts = orig + std::string(";VARIABLE=;TIMESTEP=0");
-  rval = mb.load_file(example, &set, opts.c_str());
+  // Read mesh, but still no variables
+  opts = orig + ";VARIABLE=;TIMESTEP=0";
+  rval = mb.load_file(example, &file_set, opts.c_str());
   CHECK_ERR(rval);
 
-  // Check for proper tag
+  // Check ke tags
   Tag ke_tag0, ke_tag1;
   rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+  // Tag ke0 should not exist
+  CHECK_EQUAL(rval, MB_TAG_NOT_FOUND);
+  rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+  // Tag ke1 should not exist
   CHECK_EQUAL(rval, MB_TAG_NOT_FOUND);
 
-  opts = orig + std::string(";VARIABLE=ke;TIMESTEP=0;NOMESH");
-  rval = mb.load_file(example, &set, opts.c_str());
+  // Read ke at 1st timestep, no need to read mesh
+  opts = orig + ";VARIABLE=ke;TIMESTEP=0;NOMESH";
+  rval = mb.load_file(example, &file_set, opts.c_str());
   CHECK_ERR(rval);
 
-  // Check for proper tags
+  // Check ke tags again
   rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+  // Tag ke0 should exist at this time
   CHECK_ERR(rval);
+  // Tag ke1 should still not exist
   rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
   CHECK_EQUAL(rval, MB_TAG_NOT_FOUND);
 
-  // Now read 2nd timestep with nomesh option
-  opts = orig + std::string(";VARIABLE=ke;TIMESTEP=1;NOMESH");
-  rval = mb.load_file(example, &set, opts.c_str());
+  // Read ke at 2nd timestep, no need to read mesh
+  opts = orig + ";VARIABLE=ke;TIMESTEP=1;NOMESH";
+  rval = mb.load_file(example, &file_set, opts.c_str());
   CHECK_ERR(rval);
 
-  // Check for proper tag
+  // Check tag ke1 again
   rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+  // Tag ke1 should exist at this time
   CHECK_ERR(rval);
+
+  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 on one processor
+  if (1 == procs) {
+    // Get cells (12 pentagons and 630 hexagons)
+    Range cells;
+    rval = mb.get_entities_by_type(file_set, MBPOLYGON, cells);
+    CHECK_ERR(rval);
+    CHECK_EQUAL((size_t)642, cells.size());
+
+#ifdef USE_MPI
+    // If MOAB is compiled parallel, sequence size requested are increased
+    // by a factor of 1.5, to allow for ghosts. This will introduce a gap
+    // between the two face sequences.
+    CHECK_EQUAL((size_t)2, cells.psize());
+#else
+    CHECK_EQUAL((size_t)1, cells.psize());
+#endif
+
+    // Check ke tag values on 4 cells: first pentagon, last pentagon,
+    // first hexagon, and last hexagon
+    EntityHandle cell_ents[] = {cells[0], cells[11], cells[12], cells[641]};
+    double ke0_val[4];
+    rval = mb.tag_get_data(ke_tag0, cell_ents, 4, ke0_val);
+    CHECK_ERR(rval);
+    CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+    CHECK_REAL_EQUAL(15.012, ke0_val[1], eps);
+    CHECK_REAL_EQUAL(16.013, ke0_val[2], eps);
+    CHECK_REAL_EQUAL(16.642, ke0_val[3], eps);
+    double ke1_val[4];
+    rval = mb.tag_get_data(ke_tag1, cell_ents, 4, ke1_val);
+    CHECK_ERR(rval);
+    CHECK_REAL_EQUAL(25.001, ke1_val[0], eps);
+    CHECK_REAL_EQUAL(25.012, ke1_val[1], eps);
+    CHECK_REAL_EQUAL(26.013, ke1_val[2], eps);
+    CHECK_REAL_EQUAL(26.642, ke1_val[3], eps);
+  }
 }
 
 void test_read_no_mixed_elements()
 {
   Core moab;
   Interface& mb = moab;
+
   std::string opts;
-  ErrorCode rval = get_options(opts);
-  CHECK_ERR(rval);
+  get_options(opts);
 
-  opts += std::string(";NO_MIXED_ELEMENTS;VARIABLE=ke");
-  rval = mb.load_file(example, NULL, opts.c_str());
+  // Read mesh with no mixed elements and read all variables at all timesteps
+  opts += ";NO_MIXED_ELEMENTS";
+  ErrorCode rval = mb.load_file(example, NULL, opts.c_str());
   CHECK_ERR(rval);
 
   int procs = 1;
@@ -333,9 +406,9 @@ void test_read_no_mixed_elements()
   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
+    // Check ke tags
     Tag ke_tag0, ke_tag1;
     rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
     CHECK_ERR(rval);
@@ -345,23 +418,29 @@ void test_read_no_mixed_elements()
     // Get cells (12 pentagons and 630 hexagons)
     Range cells;
     rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
-    assert(rval == MB_SUCCESS);
+    CHECK_ERR(rval);
     CHECK_EQUAL((size_t)642, cells.size());
     // Only one group of cells (pentagons are padded to hexagons,
     // e.g. connectivity [1 2 3 4 5] => [1 2 3 4 5 5])
     CHECK_EQUAL((size_t)1, cells.psize());
 
-    const double eps = 1e-20;
-    double val[2];
-
-    // Check ke tag values on first pentagon and first hexagon
-    EntityHandle cell_ents[] = {cells[0], cells[12]};
-    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
-    CHECK_REAL_EQUAL(15.001, val[0], eps);
-    CHECK_REAL_EQUAL(16.013, val[1], eps);
-    rval = mb.tag_get_data(ke_tag1, &cell_ents[0], 2, val);
-    CHECK_REAL_EQUAL(25.001, val[0], eps);
-    CHECK_REAL_EQUAL(26.013, val[1], eps);
+    // Check ke tag values on 4 cells: first pentagon, last pentagon,
+    // first hexagon, and last hexagon
+    EntityHandle cell_ents[] = {cells[0], cells[11], cells[12], cells[641]};
+    double ke0_val[4];
+    rval = mb.tag_get_data(ke_tag0, cell_ents, 4, ke0_val);
+    CHECK_ERR(rval);
+    CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+    CHECK_REAL_EQUAL(15.012, ke0_val[1], eps);
+    CHECK_REAL_EQUAL(16.013, ke0_val[2], eps);
+    CHECK_REAL_EQUAL(16.642, ke0_val[3], eps);
+    double ke1_val[4];
+    rval = mb.tag_get_data(ke_tag1, cell_ents, 4, ke1_val);
+    CHECK_ERR(rval);
+    CHECK_REAL_EQUAL(25.001, ke1_val[0], eps);
+    CHECK_REAL_EQUAL(25.012, ke1_val[1], eps);
+    CHECK_REAL_EQUAL(26.013, ke1_val[2], eps);
+    CHECK_REAL_EQUAL(26.642, ke1_val[3], eps);
   }
 }
 
@@ -369,107 +448,98 @@ void test_read_no_edges()
 {
   Core moab;
   Interface& mb = moab;
+
   std::string opts;
-  ErrorCode rval = get_options(opts);
-  CHECK_ERR(rval);
+  get_options(opts);
 
-  opts += std::string(";NO_EDGES;VARIABLE=");
-  rval = mb.load_file(example, NULL, opts.c_str());
+  opts += ";NO_EDGES;VARIABLE=";
+  ErrorCode rval = mb.load_file(example, NULL, 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
-
-  // Make check runs this test in one processor
-  if (1 == procs) {
-    // Get edges
-    Range edges;
-    rval = mb.get_entities_by_type(0, MBEDGE, edges);
-    assert(rval == MB_SUCCESS);
-    CHECK_EQUAL((size_t)0, edges.size());
-  }
+  // Get edges
+  Range edges;
+  rval = mb.get_entities_by_type(0, MBEDGE, edges);
+  CHECK_ERR(rval);
+  CHECK_EQUAL((size_t)0, edges.size());
 }
 
 void test_gather_onevar()
 {
   Core moab;
   Interface& mb = moab;
-  std::string opts;
-  ErrorCode rval = get_options(opts);
-  CHECK_ERR(rval);
 
   EntityHandle file_set;
-  rval = mb.create_meshset(MESHSET_SET, file_set);
+  ErrorCode rval = mb.create_meshset(MESHSET_SET, file_set);
   CHECK_ERR(rval);
 
-  // Get cell variable ke
-  opts += std::string(";VARIABLE=ke;");
-  // Create gather set
-  opts += std::string(";GATHER_SET=0;");
+  std::string opts;
+  get_options(opts);
+
+  // Read cell variable ke and create gather set on processor 0
+  opts += ";VARIABLE=ke;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 procs = pcomm->proc_config().proc_size();
+  int rank = pcomm->proc_config().proc_rank();
 
-  // Make check runs this test in one processor
-  if (1 == procs) {
-    Range cells, cells_owned;
-    rval = mb.get_entities_by_type(file_set, MBPOLYGON, cells);
-    CHECK_ERR(rval);
+  Range cells, cells_owned;
+  rval = mb.get_entities_by_type(file_set, MBPOLYGON, cells);
+  CHECK_ERR(rval);
 
-    // Get locally owned cells
-    rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &cells_owned);
-    CHECK_ERR(rval);
-    CHECK_EQUAL((size_t)642, cells_owned.size());
-    CHECK_EQUAL((size_t)2, cells_owned.psize());
+  // Get local owned cells
+  rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &cells_owned);
+  CHECK_ERR(rval);
 
+  EntityHandle gather_set = 0;
+  if (0 == rank) {
     // Get gather set
-    EntityHandle gather_set;
     ReadUtilIface* readUtilIface;
     mb.query_interface(readUtilIface);
     rval = readUtilIface->get_gather_set(gather_set);
     CHECK_ERR(rval);
+    assert(gather_set != 0);
+  }
 
-    Tag ke_tag0, gid_tag;
-    rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0, MB_TAG_DENSE);
-    CHECK_ERR(rval);
+  Tag ke_tag0, gid_tag;
+  rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0, 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);
+  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag, MB_TAG_DENSE);
+  CHECK_ERR(rval);
 
-    pcomm->gather_data(cells_owned, ke_tag0, gid_tag, gather_set);
+  pcomm->gather_data(cells_owned, ke_tag0, gid_tag, gather_set, 0);
 
+  if (0 == rank) {
     // Get gather set cells
     Range gather_set_cells;
     rval = mb.get_entities_by_type(gather_set, MBPOLYGON, gather_set_cells);
+    CHECK_ERR(rval);
     CHECK_EQUAL((size_t)642, gather_set_cells.size());
     CHECK_EQUAL((size_t)2, gather_set_cells.psize());
 
-    const double eps = 1e-20;
-    double val[2];
-
-    // Check ke0 tag values on first pentagon and first hexagon of the gather set cells
-    EntityHandle cell_ents[] = {gather_set_cells[0], gather_set_cells[12]};
-    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
-    CHECK_REAL_EQUAL(15.001, val[0], eps);
-    CHECK_REAL_EQUAL(16.013, val[1], eps);
+    // Check ke0 tag values on 4 gather set cells: first pentagon, last pentagon,
+    // first hexagon, and last hexagon
+    double ke0_val[4];
+    EntityHandle cell_ents[] = {gather_set_cells[0], gather_set_cells[11],
+                                gather_set_cells[12], gather_set_cells[641]};
+    rval = mb.tag_get_data(ke_tag0, cell_ents, 4, ke0_val);
+    CHECK_ERR(rval);
+    CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+    CHECK_REAL_EQUAL(15.012, ke0_val[1], eps);
+    CHECK_REAL_EQUAL(16.013, ke0_val[2], eps);
+    CHECK_REAL_EQUAL(16.642, ke0_val[3], eps);
   }
 #endif
 }
 
-ErrorCode get_options(std::string& opts)
+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
 }

diff --git a/test/parallel/mpastrvpart.cpp b/test/parallel/mpastrvpart.cpp
index 7ff375a..b42f11e 100644
--- a/test/parallel/mpastrvpart.cpp
+++ b/test/parallel/mpastrvpart.cpp
@@ -16,14 +16,14 @@ static const char example[] = STRINGIFY(MESHDIR) "/io/mpasx1.642.t.2.nc";
 
 void test_read_onevar_trivial();
 void test_read_onevar_trivial_no_mixed_elements();
-#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+#if defined(USE_MPI) && defined(HAVE_ZOLTAN)
 void test_read_onevar_rcbzoltan();
 void test_read_onevar_rcbzoltan_no_mixed_elements();
 #endif
 
 void test_read_mesh_parallel_trivial();
 void test_read_mesh_parallel_trivial_no_mixed_elements();
-#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+#if defined(USE_MPI) && defined(HAVE_ZOLTAN)
 void test_read_mesh_parallel_rcbzoltan();
 void test_read_mesh_parallel_rcbzoltan_no_mixed_elements();
 #endif
@@ -50,14 +50,14 @@ int main(int argc, char* argv[])
 
   result += RUN_TEST(test_read_onevar_trivial);
   result += RUN_TEST(test_read_onevar_trivial_no_mixed_elements);
-#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+#if defined(USE_MPI) && defined(HAVE_ZOLTAN)
   result += RUN_TEST(test_read_onevar_rcbzoltan);
   result += RUN_TEST(test_read_onevar_rcbzoltan_no_mixed_elements);
 #endif
 
   result += RUN_TEST(test_read_mesh_parallel_trivial);
   result += RUN_TEST(test_read_mesh_parallel_trivial_no_mixed_elements);
-#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+#if defined(USE_MPI) && defined(HAVE_ZOLTAN)
   result += RUN_TEST(test_read_mesh_parallel_rcbzoltan);
   result += RUN_TEST(test_read_mesh_parallel_rcbzoltan_no_mixed_elements);
 #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