Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
moab::ScdNCHelper Class Reference

Child helper class for scd mesh, e.g. CAM_EL or CAM_FV. More...

#include <NCHelper.hpp>

+ Inheritance diagram for moab::ScdNCHelper:
+ Collaboration diagram for moab::ScdNCHelper:

Public Member Functions

 ScdNCHelper (ReadNC *readNC, int fileId, const FileOptions &opts, EntityHandle fileSet)
 
virtual ~ScdNCHelper ()
 
- Public Member Functions inherited from moab::NCHelper
 NCHelper (ReadNC *readNC, int fileId, const FileOptions &opts, EntityHandle fileSet)
 
virtual ~NCHelper ()
 
virtual ErrorCode init_mesh_vals ()=0
 Interfaces to be implemented in child classes. More...
 
virtual std::string get_mesh_type_name ()=0
 
ErrorCode create_conventional_tags (const std::vector< int > &tstep_nums)
 Create NC conventional tags. More...
 
ErrorCode update_time_tag_vals ()
 Update time tag values if timesteps spread across files. More...
 

Protected Attributes

int gDims [6]
 Dimensions of global grid in file. More...
 
int lDims [6]
 Dimensions of my local part of grid. More...
 
int gCDims [6]
 Center dimensions of global grid in file. More...
 
int lCDims [6]
 Center dimensions of my local part of grid. More...
 
std::vector< double > ilVals
 Values for i/j. More...
 
std::vector< double > jlVals
 
std::vector< double > ilCVals
 Center values for i/j. More...
 
std::vector< double > jlCVals
 
int iDim
 Dimension numbers for i/j. More...
 
int jDim
 
int iCDim
 Center dimension numbers for i/j. More...
 
int jCDim
 
int locallyPeriodic [3]
 Whether mesh is locally periodic in i or j or k. More...
 
int globallyPeriodic [3]
 Whether mesh is globally periodic in i or j or k. More...
 
- Protected Attributes inherited from moab::NCHelper
ReadNC_readNC
 Allow NCHelper to directly access members of ReadNC. More...
 
int _fileId
 Cache some information from ReadNC. More...
 
const FileOptions_opts
 
EntityHandle _fileSet
 
int nTimeSteps
 Dimensions of time and level. More...
 
int nLevels
 
std::vector< double > tVals
 Values for time and level. More...
 
std::vector< double > levVals
 
int tDim
 Dimension numbers for time and level. More...
 
int levDim
 
std::set< std::string > ignoredVarNames
 Ignored variables. More...
 
std::set< std::string > dummyVarNames
 Dummy variables. More...
 

Private Member Functions

virtual ErrorCode check_existing_mesh ()
 Implementation of NCHelper::check_existing_mesh() More...
 
virtual ErrorCode create_mesh (Range &faces)
 Implementation of NCHelper::create_mesh() More...
 
virtual ErrorCode read_variables (std::vector< std::string > &var_names, std::vector< int > &tstep_nums)
 Implementation of NCHelper::read_variables() More...
 
ErrorCode read_scd_variables_to_nonset_allocate (std::vector< ReadNC::VarData > &vdatas, std::vector< int > &tstep_nums)
 Read non-set variables for scd mesh. More...
 
ErrorCode read_scd_variables_to_nonset (std::vector< ReadNC::VarData > &vdatas, std::vector< int > &tstep_nums)
 
ErrorCode create_quad_coordinate_tag ()
 Create COORDS tag for quads coordinate. More...
 
template<typename T >
void kji_to_jik (size_t ni, size_t nj, size_t nk, void *dest, T *source)
 

Additional Inherited Members

- Static Public Member Functions inherited from moab::NCHelper
static ReadNC::NCFormatType get_nc_format (ReadNC *readNC, int fileId)
 Get appropriate format to read the file. More...
 
static std::string get_default_ncformat_options (ReadNC::NCFormatType format)
 Get appropriate format to read the file. More...
 
static NCHelperget_nc_helper (ReadNC *readNC, int fileId, const FileOptions &opts, EntityHandle fileSet)
 Get appropriate helper instance for ReadNC class. More...
 
- Protected Member Functions inherited from moab::NCHelper
ErrorCode read_variables_setup (std::vector< std::string > &var_names, std::vector< int > &tstep_nums, std::vector< ReadNC::VarData > &vdatas, std::vector< ReadNC::VarData > &vsetdatas)
 Separate set and non-set variables (common to scd mesh and ucd mesh) More...
 
ErrorCode read_variables_to_set (std::vector< ReadNC::VarData > &vdatas, std::vector< int > &tstep_nums)
 Read set variables (common to scd mesh and ucd mesh) More...
 
ErrorCode read_coordinate (const char *var_name, int lmin, int lmax, std::vector< double > &cvals)
 
ErrorCode get_tag_to_set (ReadNC::VarData &var_data, int tstep_num, Tag &tagh)
 
ErrorCode get_tag_to_nonset (ReadNC::VarData &var_data, int tstep_num, Tag &tagh, int num_lev)
 
ErrorCode create_attrib_string (const std::map< std::string, ReadNC::AttData > &attMap, std::string &attString, std::vector< int > &attLen)
 Create a character string attString of attMap. with '\0' terminating each attribute name, ';' separating the data type and value, and ';' separating one name/data type/value from the next'. attLen stores the end position for each name/data type/ value. More...
 
ErrorCode create_dummy_variables ()
 For a dimension that does not have a corresponding coordinate variable (e.g. ncol for HOMME), create a dummy variable with a sparse tag to store the dimension length. More...
 

Detailed Description

Child helper class for scd mesh, e.g. CAM_EL or CAM_FV.

Definition at line 130 of file NCHelper.hpp.

Constructor & Destructor Documentation

◆ ScdNCHelper()

moab::ScdNCHelper::ScdNCHelper ( ReadNC readNC,
int  fileId,
const FileOptions opts,
EntityHandle  fileSet 
)
inline

Definition at line 133 of file NCHelper.hpp.

134  : NCHelper( readNC, fileId, opts, fileSet ), iDim( -1 ), jDim( -1 ), iCDim( -1 ), jCDim( -1 )
135  {
136  for( unsigned int i = 0; i < 6; i++ )
137  {
138  gDims[i] = -1;
139  lDims[i] = -1;
140  gCDims[i] = -1;
141  lCDims[i] = -1;
142  }
143 
146  }

References gCDims, gDims, globallyPeriodic, lCDims, lDims, and locallyPeriodic.

◆ ~ScdNCHelper()

virtual moab::ScdNCHelper::~ScdNCHelper ( )
inlinevirtual

Definition at line 147 of file NCHelper.hpp.

147 {}

Member Function Documentation

◆ check_existing_mesh()

ErrorCode moab::ScdNCHelper::check_existing_mesh ( )
privatevirtual

Implementation of NCHelper::check_existing_mesh()

Implements moab::NCHelper.

Definition at line 1002 of file NCHelper.cpp.

1003 {
1004  Interface*& mbImpl = _readNC->mbImpl;
1005 
1006  // Get the number of vertices
1007  int num_verts;
1008  MB_CHK_SET_ERR( mbImpl->get_number_entities_by_dimension( _fileSet, 0, num_verts ),
1009  "Trouble getting number of vertices" );
1010 
1011  /*
1012  // Check against parameters
1013  // When ghosting is used, this check might fail (to be updated later)
1014  if (num_verts > 0) {
1015  int expected_verts = (lDims[3] - lDims[0] + 1) * (lDims[4] - lDims[1] + 1) * (-1 == lDims[2] ?
1016  1 : lDims[5] - lDims[2] + 1); if (num_verts != expected_verts) { MB_SET_ERR(MB_FAILURE, "Number
1017  of vertices doesn't match");
1018  }
1019  }
1020  */
1021 
1022  // Check the number of elements too
1023  int num_elems;
1024  MB_CHK_SET_ERR( mbImpl->get_number_entities_by_dimension( _fileSet, ( -1 == lCDims[2] ? 2 : 3 ), num_elems ),
1025  "Trouble getting number of elements" );
1026 
1027  /*
1028  // Check against parameters
1029  // When ghosting is used, this check might fail (to be updated later)
1030  if (num_elems > 0) {
1031  int expected_elems = (lCDims[3] - lCDims[0] + 1) * (lCDims[4] - lCDims[1] + 1) * (-1 ==
1032  lCDims[2] ? 1 : (lCDims[5] - lCDims[2] + 1)); if (num_elems != expected_elems) {
1033  MB_SET_ERR(MB_FAILURE, "Number of elements doesn't match");
1034  }
1035  }
1036  */
1037 
1038  return MB_SUCCESS;
1039 }

References moab::NCHelper::_fileSet, moab::NCHelper::_readNC, moab::Interface::get_number_entities_by_dimension(), lCDims, MB_CHK_SET_ERR, MB_SUCCESS, and moab::ReadNC::mbImpl.

◆ create_mesh()

ErrorCode moab::ScdNCHelper::create_mesh ( Range faces)
privatevirtual

Implementation of NCHelper::create_mesh()

Implements moab::NCHelper.

Reimplemented in moab::NCHelperScrip, and moab::NCHelperDomain.

Definition at line 1041 of file NCHelper.cpp.

1042 {
1043  Interface*& mbImpl = _readNC->mbImpl;
1044  Tag& mGlobalIdTag = _readNC->mGlobalIdTag;
1045  const Tag*& mpFileIdTag = _readNC->mpFileIdTag;
1046  DebugOutput& dbgOut = _readNC->dbgOut;
1047  ScdInterface* scdi = _readNC->scdi;
1048  ScdParData& parData = _readNC->parData;
1049 
1050  Range tmp_range;
1051  ScdBox* scd_box;
1052 
1053  MB_CHK_SET_ERR( scdi->construct_box( HomCoord( lDims[0], lDims[1], lDims[2], 1 ),
1054  HomCoord( lDims[3], lDims[4], lDims[5], 1 ), NULL, 0, scd_box, locallyPeriodic,
1055  &parData, true ),
1056  "Trouble creating scd vertex sequence" );
1057 
1058  // Add verts to tmp_range first, so we can duplicate global ids in vertex ids
1059  tmp_range.insert( scd_box->start_vertex(), scd_box->start_vertex() + scd_box->num_vertices() - 1 );
1060 
1061  if( mpFileIdTag )
1062  {
1063  int count;
1064  void* data;
1065  MB_CHK_SET_ERR( mbImpl->tag_iterate( *mpFileIdTag, tmp_range.begin(), tmp_range.end(), count, data ),
1066  "Failed to iterate file ID tag on local vertices" );
1067  assert( count == scd_box->num_vertices() );
1068  int* fid_data = (int*)data;
1069  MB_CHK_SET_ERR( mbImpl->tag_iterate( mGlobalIdTag, tmp_range.begin(), tmp_range.end(), count, data ),
1070  "Failed to iterate global ID tag on local vertices" );
1071  assert( count == scd_box->num_vertices() );
1072  int* gid_data = (int*)data;
1073  for( int i = 0; i < count; i++ )
1074  fid_data[i] = gid_data[i];
1075  }
1076 
1077  // Then add box set and elements to the range, then to the file set
1078  tmp_range.insert( scd_box->start_element(), scd_box->start_element() + scd_box->num_elements() - 1 );
1079  tmp_range.insert( scd_box->box_set() );
1080  MB_CHK_SET_ERR( mbImpl->add_entities( _fileSet, tmp_range ), "Couldn't add new vertices to current file set" );
1081 
1082  dbgOut.tprintf( 1, "scdbox %d quads, %d vertices\n", scd_box->num_elements(), scd_box->num_vertices() );
1083 
1084  // Set the vertex coordinates
1085  double *xc, *yc, *zc;
1086  MB_CHK_SET_ERR( scd_box->get_coordinate_arrays( xc, yc, zc ), "Couldn't get vertex coordinate arrays" );
1087 
1088  int i, j, k, il, jl, kl;
1089  int dil = lDims[3] - lDims[0] + 1;
1090  int djl = lDims[4] - lDims[1] + 1;
1091  assert( dil == (int)ilVals.size() && djl == (int)jlVals.size() &&
1092  ( -1 == lDims[2] || lDims[5] - lDims[2] + 1 == (int)levVals.size() ) );
1093 
1094  for( kl = lDims[2]; kl <= lDims[5]; kl++ )
1095  {
1096  k = kl - lDims[2];
1097  for( jl = lDims[1]; jl <= lDims[4]; jl++ )
1098  {
1099  j = jl - lDims[1];
1100  for( il = lDims[0]; il <= lDims[3]; il++ )
1101  {
1102  i = il - lDims[0];
1103  unsigned int pos = i + j * dil + k * dil * djl;
1104  xc[pos] = ilVals[i];
1105  yc[pos] = jlVals[j];
1106  zc[pos] = ( -1 == lDims[2] ? 0.0 : levVals[k] );
1107  }
1108  }
1109  }
1110 
1111 #ifndef NDEBUG
1112  int num_verts =
1113  ( lDims[3] - lDims[0] + 1 ) * ( lDims[4] - lDims[1] + 1 ) * ( -1 == lDims[2] ? 1 : lDims[5] - lDims[2] + 1 );
1114  std::vector< int > gids( num_verts );
1115  Range verts( scd_box->start_vertex(), scd_box->start_vertex() + scd_box->num_vertices() - 1 );
1116  MB_CHK_SET_ERR( mbImpl->tag_get_data( mGlobalIdTag, verts, &gids[0] ),
1117  "Trouble getting local gid values of vertices" );
1118  int vmin = *( std::min_element( gids.begin(), gids.end() ) ),
1119  vmax = *( std::max_element( gids.begin(), gids.end() ) );
1120  dbgOut.tprintf( 1, "Vertex gids %d-%d\n", vmin, vmax );
1121 #endif
1122 
1123  // Add elements to the range passed in
1124  faces.insert( scd_box->start_element(), scd_box->start_element() + scd_box->num_elements() - 1 );
1125 
1126  if( 2 <= dbgOut.get_verbosity() )
1127  {
1128  assert( scd_box->boundary_complete() );
1129  EntityHandle dum_ent = scd_box->start_element();
1130  MB_CHK_SET_ERR( mbImpl->list_entities( &dum_ent, 1 ), "Trouble listing first hex" );
1131 
1132  std::vector< EntityHandle > connect;
1133  MB_CHK_SET_ERR( mbImpl->get_connectivity( &dum_ent, 1, connect ), "Trouble getting connectivity" );
1134 
1135  MB_CHK_SET_ERR( mbImpl->list_entities( &connect[0], connect.size() ), "Trouble listing element connectivity" );
1136  }
1137 
1138  Range edges;
1139  mbImpl->get_adjacencies( faces, 1, true, edges, Interface::UNION );
1140 
1141  // Create COORDS tag for quads
1142  MB_CHK_SET_ERR( create_quad_coordinate_tag(), "Trouble creating COORDS tag for quads" );
1143 
1144  return MB_SUCCESS;
1145 }

References moab::NCHelper::_fileSet, moab::NCHelper::_readNC, moab::Interface::add_entities(), moab::Range::begin(), moab::ScdBox::boundary_complete(), moab::ScdBox::box_set(), moab::ScdInterface::construct_box(), create_quad_coordinate_tag(), moab::ReadNC::dbgOut, moab::Range::end(), moab::Interface::get_adjacencies(), moab::Interface::get_connectivity(), moab::ScdBox::get_coordinate_arrays(), moab::DebugOutput::get_verbosity(), ilVals, moab::Range::insert(), jlVals, lDims, moab::NCHelper::levVals, moab::Interface::list_entities(), locallyPeriodic, MB_CHK_SET_ERR, MB_SUCCESS, moab::ReadNC::mbImpl, moab::ReadNC::mGlobalIdTag, moab::ReadNC::mpFileIdTag, moab::ScdBox::num_elements(), moab::ScdBox::num_vertices(), moab::ReadNC::parData, moab::ReadNC::scdi, moab::ScdBox::start_element(), moab::ScdBox::start_vertex(), moab::Interface::tag_get_data(), moab::Interface::tag_iterate(), moab::DebugOutput::tprintf(), and moab::Interface::UNION.

◆ create_quad_coordinate_tag()

ErrorCode moab::ScdNCHelper::create_quad_coordinate_tag ( )
private

Create COORDS tag for quads coordinate.

Definition at line 1408 of file NCHelper.cpp.

1409 {
1410  Interface*& mbImpl = _readNC->mbImpl;
1411 
1412  Range ents;
1413  MB_CHK_SET_ERR( mbImpl->get_entities_by_type( _fileSet, moab::MBQUAD, ents ), "Trouble getting quads" );
1414 
1415  std::size_t numOwnedEnts = 0;
1416 #ifdef MOAB_HAVE_MPI
1417  Range ents_owned;
1418  bool& isParallel = _readNC->isParallel;
1419  if( isParallel )
1420  {
1421  ParallelComm*& myPcomm = _readNC->myPcomm;
1422  MB_CHK_SET_ERR( myPcomm->filter_pstatus( ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &ents_owned ),
1423  "Trouble getting owned quads" );
1424  numOwnedEnts = ents_owned.size();
1425  }
1426  else
1427  {
1428  numOwnedEnts = ents.size();
1429  ents_owned = ents;
1430  }
1431 #else
1432  numOwnedEnts = ents.size();
1433 #endif
1434 
1435  if( numOwnedEnts == 0 ) return MB_SUCCESS;
1436 
1437  assert( numOwnedEnts == ilCVals.size() * jlCVals.size() );
1438  std::vector< double > coords( numOwnedEnts * 3 );
1439  std::size_t pos = 0;
1440  for( std::size_t j = 0; j != jlCVals.size(); ++j )
1441  {
1442  for( std::size_t i = 0; i != ilCVals.size(); ++i )
1443  {
1444  pos = j * ilCVals.size() * 3 + i * 3;
1445  coords[pos] = ilCVals[i];
1446  coords[pos + 1] = jlCVals[j];
1447  coords[pos + 2] = 0.0;
1448  }
1449  }
1450  std::string tag_name = "COORDS";
1451  Tag tagh = 0;
1452  MB_CHK_SET_ERR( mbImpl->tag_get_handle( tag_name.c_str(), 3, MB_TYPE_DOUBLE, tagh, MB_TAG_DENSE | MB_TAG_CREAT ),
1453  "Trouble creating COORDS tag" );
1454 
1455  void* data;
1456  int count;
1457 #ifdef MOAB_HAVE_MPI
1458  MB_CHK_SET_ERR( mbImpl->tag_iterate( tagh, ents_owned.begin(), ents_owned.end(), count, data ),
1459  "Failed to iterate COORDS tag on quads" );
1460 #else
1461  MB_CHK_SET_ERR( mbImpl->tag_iterate( tagh, ents.begin(), ents.end(), count, data ),
1462  "Failed to iterate COORDS tag on quads" );
1463 #endif
1464  assert( count == (int)numOwnedEnts );
1465  double* quad_data = (double*)data;
1466  std::copy( coords.begin(), coords.end(), quad_data );
1467 
1468  return MB_SUCCESS;
1469 }

References moab::NCHelper::_fileSet, moab::NCHelper::_readNC, moab::Range::begin(), moab::Range::end(), moab::ParallelComm::filter_pstatus(), moab::Interface::get_entities_by_type(), ilCVals, moab::ReadNC::isParallel, jlCVals, MB_CHK_SET_ERR, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_DOUBLE, moab::ReadNC::mbImpl, MBQUAD, PSTATUS_NOT, PSTATUS_NOT_OWNED, moab::Range::size(), moab::Interface::tag_get_handle(), and moab::Interface::tag_iterate().

Referenced by create_mesh().

◆ kji_to_jik()

template<typename T >
void moab::ScdNCHelper::kji_to_jik ( size_t  ni,
size_t  nj,
size_t  nk,
void *  dest,
T *  source 
)
inlineprivate

Definition at line 166 of file NCHelper.hpp.

167  {
168  size_t nik = ni * nk, nij = ni * nj;
169  T* tmp_data = reinterpret_cast< T* >( dest );
170  for( std::size_t j = 0; j != nj; j++ )
171  for( std::size_t i = 0; i != ni; i++ )
172  for( std::size_t k = 0; k != nk; k++ )
173  tmp_data[j * nik + i * nk + k] = source[k * nij + j * ni + i];
174  }

Referenced by read_scd_variables_to_nonset().

◆ read_scd_variables_to_nonset()

ErrorCode moab::ScdNCHelper::read_scd_variables_to_nonset ( std::vector< ReadNC::VarData > &  vdatas,
std::vector< int > &  tstep_nums 
)
private

Definition at line 1293 of file NCHelper.cpp.

1295 {
1296  DebugOutput& dbgOut = _readNC->dbgOut;
1297 
1299  "Trouble allocating space to read non-set variables" );
1300 
1301  // Finally, read into that space
1302  int success;
1303  for( unsigned int i = 0; i < vdatas.size(); i++ )
1304  {
1305  std::size_t sz = vdatas[i].sz;
1306 
1307  // A typical supported variable: float T(time, lev, lat, lon)
1308  // For tag values, need transpose (lev, lat, lon) to (lat, lon, lev)
1309  size_t ni = vdatas[i].readCounts[3]; // lon or slon
1310  size_t nj = vdatas[i].readCounts[2]; // lat or slat
1311  size_t nk = vdatas[i].readCounts[1]; // lev
1312 
1313  for( unsigned int t = 0; t < tstep_nums.size(); t++ )
1314  {
1315  // Tag data for this timestep
1316  void* data = vdatas[i].varDatas[t];
1317 
1318  // Set readStart for each timestep along time dimension
1319  vdatas[i].readStarts[0] = tstep_nums[t];
1320 
1321  switch( vdatas[i].varDataType )
1322  {
1323  case NC_BYTE:
1324  case NC_CHAR: {
1325  std::vector< char > tmpchardata( sz );
1326  success = NCFUNCAG( _vara_text )( _fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
1327  &vdatas[i].readCounts[0], &tmpchardata[0] );
1328  if( success )
1329  MB_SET_ERR( MB_FAILURE, "Failed to read byte/char data for variable " << vdatas[i].varName );
1330  if( vdatas[i].numLev > 1 )
1331  // Transpose (lev, lat, lon) to (lat, lon, lev)
1332  kji_to_jik( ni, nj, nk, data, &tmpchardata[0] );
1333  else
1334  {
1335  for( std::size_t idx = 0; idx != tmpchardata.size(); idx++ )
1336  ( (char*)data )[idx] = tmpchardata[idx];
1337  }
1338  break;
1339  }
1340  case NC_SHORT:
1341  case NC_INT: {
1342  std::vector< int > tmpintdata( sz );
1343  success = NCFUNCAG( _vara_int )( _fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
1344  &vdatas[i].readCounts[0], &tmpintdata[0] );
1345  if( success )
1346  MB_SET_ERR( MB_FAILURE, "Failed to read short/int data for variable " << vdatas[i].varName );
1347  if( vdatas[i].numLev > 1 )
1348  // Transpose (lev, lat, lon) to (lat, lon, lev)
1349  kji_to_jik( ni, nj, nk, data, &tmpintdata[0] );
1350  else
1351  {
1352  for( std::size_t idx = 0; idx != tmpintdata.size(); idx++ )
1353  ( (int*)data )[idx] = tmpintdata[idx];
1354  }
1355  break;
1356  }
1357  case NC_INT64: {
1358  std::vector< long > tmpintdata( sz );
1359  success = NCFUNCAG( _vara_long )( _fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
1360  &vdatas[i].readCounts[0], &tmpintdata[0] );
1361  if( success )
1362  MB_SET_ERR( MB_FAILURE, "Failed to read long data for variable " << vdatas[i].varName );
1363  if( vdatas[i].numLev > 1 )
1364  // Transpose (lev, lat, lon) to (lat, lon, lev)
1365  kji_to_jik( ni, nj, nk, data, &tmpintdata[0] );
1366  else
1367  {
1368  for( std::size_t idx = 0; idx != tmpintdata.size(); idx++ )
1369  ( (long*)data )[idx] = tmpintdata[idx];
1370  }
1371  break;
1372  }
1373  case NC_FLOAT:
1374  case NC_DOUBLE: {
1375  std::vector< double > tmpdoubledata( sz );
1376  success = NCFUNCAG( _vara_double )( _fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
1377  &vdatas[i].readCounts[0], &tmpdoubledata[0] );
1378  if( success )
1379  MB_SET_ERR( MB_FAILURE, "Failed to read float/double data for variable " << vdatas[i].varName );
1380  if( vdatas[i].numLev > 1 )
1381  // Transpose (lev, lat, lon) to (lat, lon, lev)
1382  kji_to_jik( ni, nj, nk, data, &tmpdoubledata[0] );
1383  else
1384  {
1385  for( std::size_t idx = 0; idx != tmpdoubledata.size(); idx++ )
1386  ( (double*)data )[idx] = tmpdoubledata[idx];
1387  }
1388  break;
1389  }
1390  default:
1391  MB_SET_ERR( MB_FAILURE, "Unexpected data type for variable " << vdatas[i].varName );
1392  }
1393  }
1394  }
1395 
1396  // Debug output, if requested
1397  if( 1 == dbgOut.get_verbosity() )
1398  {
1399  dbgOut.printf( 1, "Read variables: %s", vdatas.begin()->varName.c_str() );
1400  for( unsigned int i = 1; i < vdatas.size(); i++ )
1401  dbgOut.printf( 1, ", %s ", vdatas[i].varName.c_str() );
1402  dbgOut.tprintf( 1, "\n" );
1403  }
1404 
1405  return MB_SUCCESS;
1406 }

References moab::NCHelper::_fileId, moab::NCHelper::_readNC, moab::ReadNC::dbgOut, moab::DebugOutput::get_verbosity(), kji_to_jik(), MB_CHK_SET_ERR, MB_SET_ERR, MB_SUCCESS, NCFUNCAG, moab::DebugOutput::printf(), read_scd_variables_to_nonset_allocate(), and moab::DebugOutput::tprintf().

Referenced by read_variables().

◆ read_scd_variables_to_nonset_allocate()

ErrorCode moab::ScdNCHelper::read_scd_variables_to_nonset_allocate ( std::vector< ReadNC::VarData > &  vdatas,
std::vector< int > &  tstep_nums 
)
private

Read non-set variables for scd mesh.

Definition at line 1169 of file NCHelper.cpp.

1171 {
1172  Interface*& mbImpl = _readNC->mbImpl;
1173  std::vector< int >& dimLens = _readNC->dimLens;
1174  DebugOutput& dbgOut = _readNC->dbgOut;
1175 
1176  Range* range = NULL;
1177 
1178  // Get vertices
1179  Range verts;
1180  MB_CHK_SET_ERR( mbImpl->get_entities_by_dimension( _fileSet, 0, verts ),
1181  "Trouble getting vertices in current file set" );
1182  assert( "Should only have a single vertex subrange, since they were read in one shot" && verts.psize() == 1 );
1183 
1184  Range edges;
1185  MB_CHK_SET_ERR( mbImpl->get_entities_by_dimension( _fileSet, 1, edges ),
1186  "Trouble getting edges in current file set" );
1187 
1188  // Get faces
1189  Range faces;
1190  MB_CHK_SET_ERR( mbImpl->get_entities_by_dimension( _fileSet, 2, faces ),
1191  "Trouble getting faces in current file set" );
1192  assert( "Should only have a single face subrange, since they were read in one shot" && faces.psize() == 1 );
1193 
1194 #ifdef MOAB_HAVE_MPI
1195  moab::Range faces_owned;
1196  bool& isParallel = _readNC->isParallel;
1197  if( isParallel )
1198  {
1199  ParallelComm*& myPcomm = _readNC->myPcomm;
1200  MB_CHK_SET_ERR( myPcomm->filter_pstatus( faces, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &faces_owned ),
1201  "Trouble getting owned faces in current file set" );
1202  }
1203  else
1204  faces_owned = faces; // Not running in parallel, but still with MPI
1205 #endif
1206 
1207  for( unsigned int i = 0; i < vdatas.size(); i++ )
1208  {
1209  // Support non-set variables with 4 dimensions like (time, lev, lat, lon)
1210  assert( 4 == vdatas[i].varDims.size() );
1211 
1212  // For a non-set variable, time should be the first dimension
1213  assert( tDim == vdatas[i].varDims[0] );
1214 
1215  // Set up readStarts and readCounts
1216  vdatas[i].readStarts.resize( 4 );
1217  vdatas[i].readCounts.resize( 4 );
1218 
1219  // First: time
1220  vdatas[i].readStarts[0] = 0; // This value is timestep dependent, will be set later
1221  vdatas[i].readCounts[0] = 1;
1222 
1223  // Next: lev
1224  vdatas[i].readStarts[1] = 0;
1225  vdatas[i].readCounts[1] = vdatas[i].numLev;
1226 
1227  // Finally: lat (or slat) and lon (or slon)
1228  switch( vdatas[i].entLoc )
1229  {
1230  case ReadNC::ENTLOCVERT:
1231  // Vertices
1232  vdatas[i].readStarts[2] = lDims[1];
1233  vdatas[i].readCounts[2] = lDims[4] - lDims[1] + 1;
1234  vdatas[i].readStarts[3] = lDims[0];
1235  vdatas[i].readCounts[3] = lDims[3] - lDims[0] + 1;
1236  range = &verts;
1237  break;
1238  case ReadNC::ENTLOCNSEDGE:
1239  case ReadNC::ENTLOCEWEDGE:
1240  case ReadNC::ENTLOCEDGE:
1241  // Not implemented yet, set a global error
1242  MB_SET_GLB_ERR( MB_NOT_IMPLEMENTED, "Reading edge data is not implemented yet" );
1243  case ReadNC::ENTLOCFACE:
1244  // Faces
1245  vdatas[i].readStarts[2] = lCDims[1];
1246  vdatas[i].readCounts[2] = lCDims[4] - lCDims[1] + 1;
1247  vdatas[i].readStarts[3] = lCDims[0];
1248  vdatas[i].readCounts[3] = lCDims[3] - lCDims[0] + 1;
1249 #ifdef MOAB_HAVE_MPI
1250  range = &faces_owned;
1251 #else
1252  range = &faces;
1253 #endif
1254  break;
1255  default:
1256  MB_SET_ERR( MB_FAILURE, "Unexpected entity location type for variable " << vdatas[i].varName );
1257  }
1258 
1259  for( unsigned int t = 0; t < tstep_nums.size(); t++ )
1260  {
1261  dbgOut.tprintf( 2, "Reading variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t] );
1262 
1263  if( tstep_nums[t] >= dimLens[tDim] )
1264  {
1265  MB_SET_ERR( MB_INDEX_OUT_OF_RANGE, "Wrong value for timestep number " << tstep_nums[t] );
1266  }
1267 
1268  // Get the tag to read into
1269  if( !vdatas[i].varTags[t] )
1270  {
1271  MB_CHK_SET_ERR( get_tag_to_nonset( vdatas[i], tstep_nums[t], vdatas[i].varTags[t], vdatas[i].numLev ),
1272  "Trouble getting tag to non-set variable " << vdatas[i].varName );
1273  }
1274 
1275  // Get ptr to tag space
1276  void* data;
1277  int count;
1278  MB_CHK_SET_ERR( mbImpl->tag_iterate( vdatas[i].varTags[t], range->begin(), range->end(), count, data ),
1279  "Failed to iterate tag for non-set variable " << vdatas[i].varName );
1280  assert( (unsigned)count == range->size() );
1281  vdatas[i].varDatas[t] = data;
1282  }
1283 
1284  // Get variable size
1285  vdatas[i].sz = 1;
1286  for( std::size_t idx = 0; idx != vdatas[i].readCounts.size(); idx++ )
1287  vdatas[i].sz *= vdatas[i].readCounts[idx];
1288  }
1289 
1290  return MB_SUCCESS;
1291 }

References moab::NCHelper::_fileSet, moab::NCHelper::_readNC, moab::Range::begin(), moab::ReadNC::dbgOut, moab::ReadNC::dimLens, moab::Range::end(), moab::ReadNC::ENTLOCEDGE, moab::ReadNC::ENTLOCEWEDGE, moab::ReadNC::ENTLOCFACE, moab::ReadNC::ENTLOCNSEDGE, moab::ReadNC::ENTLOCVERT, moab::ParallelComm::filter_pstatus(), moab::Interface::get_entities_by_dimension(), moab::NCHelper::get_tag_to_nonset(), moab::ReadNC::isParallel, lCDims, lDims, MB_CHK_SET_ERR, MB_INDEX_OUT_OF_RANGE, MB_NOT_IMPLEMENTED, MB_SET_ERR, MB_SET_GLB_ERR, MB_SUCCESS, moab::ReadNC::mbImpl, moab::Range::psize(), PSTATUS_NOT, PSTATUS_NOT_OWNED, moab::Range::size(), moab::Interface::tag_iterate(), moab::NCHelper::tDim, and moab::DebugOutput::tprintf().

Referenced by read_scd_variables_to_nonset().

◆ read_variables()

ErrorCode moab::ScdNCHelper::read_variables ( std::vector< std::string > &  var_names,
std::vector< int > &  tstep_nums 
)
privatevirtual

Implementation of NCHelper::read_variables()

Implements moab::NCHelper.

Definition at line 1147 of file NCHelper.cpp.

1148 {
1149  std::vector< ReadNC::VarData > vdatas;
1150  std::vector< ReadNC::VarData > vsetdatas;
1151 
1152  MB_CHK_SET_ERR( read_variables_setup( var_names, tstep_nums, vdatas, vsetdatas ),
1153  "Trouble setting up to read variables" );
1154 
1155  if( !vsetdatas.empty() )
1156  {
1157  MB_CHK_SET_ERR( read_variables_to_set( vsetdatas, tstep_nums ), "Trouble reading variables to set" );
1158  }
1159 
1160  if( !vdatas.empty() )
1161  {
1162  MB_CHK_SET_ERR( read_scd_variables_to_nonset( vdatas, tstep_nums ),
1163  "Trouble reading variables to verts/edges/faces" );
1164  }
1165 
1166  return MB_SUCCESS;
1167 }

References MB_CHK_SET_ERR, MB_SUCCESS, read_scd_variables_to_nonset(), moab::NCHelper::read_variables_setup(), and moab::NCHelper::read_variables_to_set().

Member Data Documentation

◆ gCDims

int moab::ScdNCHelper::gCDims[6]
protected

Center dimensions of global grid in file.

Definition at line 184 of file NCHelper.hpp.

Referenced by moab::NCHelperEuler::init_mesh_vals(), moab::NCHelperFV::init_mesh_vals(), and ScdNCHelper().

◆ gDims

int moab::ScdNCHelper::gDims[6]
protected

◆ globallyPeriodic

int moab::ScdNCHelper::globallyPeriodic[3]
protected

Whether mesh is globally periodic in i or j or k.

Definition at line 205 of file NCHelper.hpp.

Referenced by moab::NCHelperDomain::init_mesh_vals(), moab::NCHelperEuler::init_mesh_vals(), moab::NCHelperFV::init_mesh_vals(), and ScdNCHelper().

◆ iCDim

int moab::ScdNCHelper::iCDim
protected

Center dimension numbers for i/j.

Definition at line 199 of file NCHelper.hpp.

Referenced by moab::NCHelperDomain::init_mesh_vals(), moab::NCHelperEuler::init_mesh_vals(), and moab::NCHelperFV::init_mesh_vals().

◆ iDim

int moab::ScdNCHelper::iDim
protected

Dimension numbers for i/j.

Definition at line 196 of file NCHelper.hpp.

Referenced by moab::NCHelperDomain::init_mesh_vals(), and moab::NCHelperFV::init_mesh_vals().

◆ ilCVals

std::vector< double > moab::ScdNCHelper::ilCVals
protected

◆ ilVals

std::vector< double > moab::ScdNCHelper::ilVals
protected

◆ jCDim

int moab::ScdNCHelper::jCDim
protected

◆ jDim

int moab::ScdNCHelper::jDim
protected

◆ jlCVals

std::vector< double > moab::ScdNCHelper::jlCVals
protected

◆ jlVals

std::vector< double > moab::ScdNCHelper::jlVals
protected

◆ lCDims

◆ lDims

◆ locallyPeriodic

int moab::ScdNCHelper::locallyPeriodic[3]
protected

Whether mesh is locally periodic in i or j or k.

Definition at line 202 of file NCHelper.hpp.

Referenced by create_mesh(), moab::NCHelperDomain::init_mesh_vals(), moab::NCHelperEuler::init_mesh_vals(), moab::NCHelperFV::init_mesh_vals(), and ScdNCHelper().


The documentation for this class was generated from the following files: