[MOAB-dev] commit/MOAB: danwu: Ignore some MPAS variables such as topological information. For all NC helpers, determine the entity location type and number of levels in init_mesh_vals(), with some minor changes.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Nov 13 13:05:51 CST 2013


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/527454d1564f/
Changeset:   527454d1564f
Branch:      master
User:        danwu
Date:        2013-11-13 20:05:40
Summary:     Ignore some MPAS variables such as topological information. For all NC helpers, determine the entity location type and number of levels in init_mesh_vals(), with some minor changes.

Affected #:  5 files

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index be91ef8..db0bfd4 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -10,10 +10,10 @@
 #include "MBTagConventions.hpp"
 
 #define ERRORR(rval, str) \
-    if (MB_SUCCESS != rval) {_readNC->readMeshIface->report_error("%s", str); return rval;}
+  if (MB_SUCCESS != rval) {_readNC->readMeshIface->report_error("%s", str); return rval;}
 
 #define ERRORS(err, str) \
-    if (err) {_readNC->readMeshIface->report_error("%s", str); return MB_FAILURE;}
+  if (err) {_readNC->readMeshIface->report_error("%s", str); return MB_FAILURE;}
 
 namespace moab {
 
@@ -893,7 +893,7 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
   ScdParData& parData = _readNC->parData;
 
   Range tmp_range;
-  ScdBox *scd_box;
+  ScdBox* scd_box;
 
   ErrorCode rval = scdi->construct_box(HomCoord(lDims[0], lDims[1], lDims[2], 1), HomCoord(lDims[3], lDims[4], lDims[5], 1), 
                                        NULL, 0, scd_box, locallyPeriodic, &parData, true);
@@ -1050,8 +1050,6 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset_allocate(std::vector<ReadNC::
 #endif
 
   for (unsigned int i = 0; i < vdatas.size(); i++) {
-    vdatas[i].numLev = nLevels;
-
     for (unsigned int t = 0; t < tstep_nums.size(); t++) {
       dbgOut.tprintf(2, "Reading variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
 
@@ -1074,17 +1072,14 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset_allocate(std::vector<ReadNC::
       vdatas[i].readStarts[t].push_back(tstep_nums[t]);
       vdatas[i].readCounts[t].push_back(1);
 
-      // Next: numLev
-      if (vdatas[i].numLev != 1) {
-        vdatas[i].readStarts[t].push_back(0);
-        vdatas[i].readCounts[t].push_back(vdatas[i].numLev);
-      }
+      // Next: numLev, even if it is 1
+      vdatas[i].readStarts[t].push_back(0);
+      vdatas[i].readCounts[t].push_back(vdatas[i].numLev);
 
       // Finally: y and x
       switch (vdatas[i].entLoc) {
         case ReadNC::ENTLOCVERT:
           // Vertices
-          // Only structured mesh has j parameter that multiplies i to get total # vertices
           vdatas[i].readStarts[t].push_back(lDims[1]);
           vdatas[i].readCounts[t].push_back(lDims[4] - lDims[1] + 1);
           vdatas[i].readStarts[t].push_back(lDims[0]);
@@ -1101,8 +1096,8 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset_allocate(std::vector<ReadNC::
         case ReadNC::ENTLOCFACE:
           // Faces
           vdatas[i].readStarts[t].push_back(lCDims[1]);
-          vdatas[i].readStarts[t].push_back(lCDims[0]);
           vdatas[i].readCounts[t].push_back(lCDims[4] - lCDims[1] + 1);
+          vdatas[i].readStarts[t].push_back(lCDims[0]);
           vdatas[i].readCounts[t].push_back(lCDims[3] - lCDims[0] + 1);
           assert(vdatas[i].readStarts[t].size() == vdatas[i].varDims.size());
 #ifdef USE_MPI
@@ -1245,6 +1240,7 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
         rval = tmp_rval;
     }
   }
+
   // Debug output, if requested
   if (1 == dbgOut.get_verbosity()) {
     dbgOut.printf(1, "Read variables: %s", vdatas.begin()->varName.c_str());

diff --git a/src/io/NCHelperEuler.cpp b/src/io/NCHelperEuler.cpp
index 48056c6..5082c2e 100644
--- a/src/io/NCHelperEuler.cpp
+++ b/src/io/NCHelperEuler.cpp
@@ -6,10 +6,10 @@
 #include <sstream>
 
 #define ERRORR(rval, str) \
-    if (MB_SUCCESS != rval) {_readNC->readMeshIface->report_error("%s", str); return rval;}
+  if (MB_SUCCESS != rval) {_readNC->readMeshIface->report_error("%s", str); return rval;}
 
 #define ERRORS(err, str) \
-    if (err) {_readNC->readMeshIface->report_error("%s", str); return MB_FAILURE;}
+  if (err) {_readNC->readMeshIface->report_error("%s", str); return MB_FAILURE;}
 
 namespace moab {
 
@@ -319,13 +319,21 @@ ErrorCode NCHelperEuler::init_mesh_vals()
   dbgOut.tprintf(1, "%d elements, %d vertices\n", (lDims[3] - lDims[0]) * (lDims[4] - lDims[1]), (lDims[3] - lDims[0] + 1)
       * (lDims[4] - lDims[1] + 1));
 
-  // Determine the entity location type of a variable
+  // For each variable, determine the entity location type and number of levels
   std::map<std::string, ReadNC::VarData>::iterator mit;
   for (mit = varInfo.begin(); mit != varInfo.end(); ++mit) {
     ReadNC::VarData& vd = (*mit).second;
-    if ((std::find(vd.varDims.begin(), vd.varDims.end(), iCDim) != vd.varDims.end()) && (std::find(vd.varDims.begin(),
-        vd.varDims.end(), jCDim) != vd.varDims.end()))
-      vd.entLoc = ReadNC::ENTLOCFACE;
+
+    vd.entLoc = ReadNC::ENTLOCSET;
+    if (std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) {
+      if ((std::find(vd.varDims.begin(), vd.varDims.end(), iCDim) != vd.varDims.end()) &&
+          (std::find(vd.varDims.begin(), vd.varDims.end(), jCDim) != vd.varDims.end()))
+        vd.entLoc = ReadNC::ENTLOCFACE;
+    }
+
+    vd.numLev = 1;
+    if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end())
+      vd.numLev = nLevels;
   }
 
   // For Eul models, slon and slat are "virtual" dimensions (not defined in the file header)

diff --git a/src/io/NCHelperFV.cpp b/src/io/NCHelperFV.cpp
index 253d598..488a511 100644
--- a/src/io/NCHelperFV.cpp
+++ b/src/io/NCHelperFV.cpp
@@ -6,7 +6,7 @@
 #include <sstream>
 
 #define ERRORR(rval, str) \
-    if (MB_SUCCESS != rval) {_readNC->readMeshIface->report_error("%s", str); return rval;}
+ if (MB_SUCCESS != rval) {_readNC->readMeshIface->report_error("%s", str); return rval;}
 
 namespace moab {
 
@@ -315,19 +315,27 @@ ErrorCode NCHelperFV::init_mesh_vals()
   dbgOut.tprintf(1, "%d elements, %d vertices\n", (lDims[3] - lDims[0]) * (lDims[4] - lDims[1]), (lDims[3] - lDims[0] + 1)
       * (lDims[4] - lDims[1] + 1));
 
-  // Determine the entity location type of a variable
+  // For each variable, determine the entity location type and number of levels
   std::map<std::string, ReadNC::VarData>::iterator mit;
   for (mit = varInfo.begin(); mit != varInfo.end(); ++mit) {
     ReadNC::VarData& vd = (*mit).second;
-    if ((std::find(vd.varDims.begin(), vd.varDims.end(), iCDim) != vd.varDims.end()) && (std::find(vd.varDims.begin(),
-        vd.varDims.end(), jCDim) != vd.varDims.end()))
-      vd.entLoc = ReadNC::ENTLOCFACE;
-    else if ((std::find(vd.varDims.begin(), vd.varDims.end(), jDim) != vd.varDims.end()) && (std::find(vd.varDims.begin(),
-        vd.varDims.end(), iCDim) != vd.varDims.end()))
-      vd.entLoc = ReadNC::ENTLOCNSEDGE;
-    else if ((std::find(vd.varDims.begin(), vd.varDims.end(), jCDim) != vd.varDims.end()) && (std::find(vd.varDims.begin(),
-        vd.varDims.end(), iDim) != vd.varDims.end()))
-      vd.entLoc = ReadNC::ENTLOCEWEDGE;
+
+    vd.entLoc = ReadNC::ENTLOCSET;
+    if (std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) {
+      if ((std::find(vd.varDims.begin(), vd.varDims.end(), iCDim) != vd.varDims.end()) &&
+          (std::find(vd.varDims.begin(), vd.varDims.end(), jCDim) != vd.varDims.end()))
+        vd.entLoc = ReadNC::ENTLOCFACE;
+      else if ((std::find(vd.varDims.begin(), vd.varDims.end(), jDim) != vd.varDims.end()) &&
+          (std::find(vd.varDims.begin(), vd.varDims.end(), iCDim) != vd.varDims.end()))
+        vd.entLoc = ReadNC::ENTLOCNSEDGE;
+      else if ((std::find(vd.varDims.begin(), vd.varDims.end(), jCDim) != vd.varDims.end()) &&
+          (std::find(vd.varDims.begin(), vd.varDims.end(), iDim) != vd.varDims.end()))
+        vd.entLoc = ReadNC::ENTLOCEWEDGE;
+    }
+
+    vd.numLev = 1;
+    if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end())
+      vd.numLev = nLevels;
   }
 
   std::vector<std::string> ijdimNames(4);

diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index be4d93f..ba504e6 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -151,13 +151,20 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
       tVals.push_back((double)t);
   }
 
-  // Determine the entity location type of a variable
+  // For each variable, determine the entity location type and number of levels
   std::map<std::string, ReadNC::VarData>::iterator mit;
   for (mit = varInfo.begin(); mit != varInfo.end(); ++mit) {
     ReadNC::VarData& vd = (*mit).second;
-    if ((std::find(vd.varDims.begin(), vd.varDims.end(), vDim) != vd.varDims.end()) && (std::find(vd.varDims.begin(),
-        vd.varDims.end(), levDim) != vd.varDims.end()))
-      vd.entLoc = ReadNC::ENTLOCVERT;
+
+    vd.entLoc = ReadNC::ENTLOCSET;
+    if (std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) {
+      if (std::find(vd.varDims.begin(), vd.varDims.end(), vDim) != vd.varDims.end())
+        vd.entLoc = ReadNC::ENTLOCVERT;
+    }
+
+    vd.numLev = 1;
+    if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end())
+      vd.numLev = nLevels;
   }
 
   // Hack: create dummy tags for dimensions (like ncol) with no corresponding coordinate variables
@@ -540,11 +547,9 @@ ErrorCode NCHelperHOMME::read_ucd_variable_to_nonset_allocate(std::vector<ReadNC
       vdatas[i].readStarts[t].push_back(tstep_nums[t]);
       vdatas[i].readCounts[t].push_back(1);
 
-      // Next: numLev
-      if (vdatas[i].numLev != 1) {
-        vdatas[i].readStarts[t].push_back(0);
-        vdatas[i].readCounts[t].push_back(vdatas[i].numLev);
-      }
+      // Next: numLev, even if it is 1
+      vdatas[i].readStarts[t].push_back(0);
+      vdatas[i].readCounts[t].push_back(vdatas[i].numLev);
 
       // Finally: nVertices
       switch (vdatas[i].entLoc) {

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index a326e52..9d50ffe 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -26,8 +26,22 @@ NCHelperMPAS::NCHelperMPAS(ReadNC* readNC, int fileId, const FileOptions& opts,
 , numCellGroups(0)
 , createGatherSet(false)
 {
-  // Hack: ignore 4D variable tracers(Time, nCells, nVertLevels, nTracers)
-  ignoredVarNames.insert("tracers");
+  // Ignore variables containing topological information
+  ignoredVarNames.insert("nEdgesOnEdge");
+  ignoredVarNames.insert("nEdgesOnCell");
+  ignoredVarNames.insert("edgesOnVertex");
+  ignoredVarNames.insert("cellsOnVertex");
+  ignoredVarNames.insert("verticesOnEdge");
+  ignoredVarNames.insert("edgesOnEdge");
+  ignoredVarNames.insert("cellsOnEdge");
+  ignoredVarNames.insert("verticesOnCell");
+  ignoredVarNames.insert("edgesOnCell");
+  ignoredVarNames.insert("cellsOnCell");
+
+  // Ignore variables for index conversion
+  ignoredVarNames.insert("indexToVertexID");
+  ignoredVarNames.insert("indexToEdgeID");
+  ignoredVarNames.insert("indexToCellID");
 }
 
 bool NCHelperMPAS::can_read_file(ReadNC* readNC)
@@ -144,38 +158,36 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
     }
   }
 
-  // Determine the entity location type of a variable
+  // For each variable, determine the entity location type and number of levels
   for (vmit = varInfo.begin(); vmit != varInfo.end(); ++vmit) {
     ReadNC::VarData& vd = (*vmit).second;
-    vd.entLoc = ReadNC::ENTLOCSET;
 
-    if ((std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) &&
-      (std::find(vd.varDims.begin(), vd.varDims.end(), vDim) != vd.varDims.end()))
-      vd.entLoc = ReadNC::ENTLOCVERT;
-    else if ((std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) &&
-      (std::find(vd.varDims.begin(), vd.varDims.end(), eDim) != vd.varDims.end()))
-      vd.entLoc = ReadNC::ENTLOCEDGE;
-    else 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()))
-      vd.entLoc = ReadNC::ENTLOCFACE;
-  }
+    vd.entLoc = ReadNC::ENTLOCSET;
+    if (std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) {
+      if (std::find(vd.varDims.begin(), vd.varDims.end(), vDim) != vd.varDims.end())
+        vd.entLoc = ReadNC::ENTLOCVERT;
+      else if (std::find(vd.varDims.begin(), vd.varDims.end(), eDim) != vd.varDims.end())
+        vd.entLoc = ReadNC::ENTLOCEDGE;
+      else if (std::find(vd.varDims.begin(), vd.varDims.end(), cDim) != vd.varDims.end())
+        vd.entLoc = ReadNC::ENTLOCFACE;
+    }
 
-  // Determine number of levels of a variable
-  for (vmit = varInfo.begin(); vmit != varInfo.end(); ++vmit) {
-    ReadNC::VarData& vd = (*vmit).second;
     vd.numLev = 1;
-
-    if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end()) {
+    if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end())
       vd.numLev = nLevels;
-      continue;
-    }
-
-    for (unsigned int i = 0; i < opt_lev_dims.size(); i++) {
-      if (std::find(vd.varDims.begin(), vd.varDims.end(), opt_lev_dims[i]) != vd.varDims.end()) {
-        vd.numLev = dimLens[opt_lev_dims[i]];
-        break;
+    else {
+      // If nVertLevels dimension is not found, try other optional levels such as nVertLevelsP1
+      for (unsigned int i = 0; i < opt_lev_dims.size(); i++) {
+        if (std::find(vd.varDims.begin(), vd.varDims.end(), opt_lev_dims[i]) != vd.varDims.end()) {
+          vd.numLev = dimLens[opt_lev_dims[i]];
+          break;
+        }
       }
     }
+
+    // Hack: ignore variables with more than 3 dimensions, e.g. tracers(Time, nCells, nVertLevels, nTracers)
+    if (vd.varDims.size() > 3)
+      ignoredVarNames.insert(vd.varName);
   }
 
   // Hack: create dummy tags for dimensions (like nCells) with no corresponding coordinate variables

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