Mesh Oriented datABase  (version 5.5.1)
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 961 of file NCHelper.cpp.

962 {
963  Interface*& mbImpl = _readNC->mbImpl;
964 
965  // Get the number of vertices
966  int num_verts;
967  ErrorCode rval = mbImpl->get_number_entities_by_dimension( _fileSet, 0, num_verts );MB_CHK_SET_ERR( rval, "Trouble getting number of vertices" );
968 
969  /*
970  // Check against parameters
971  // When ghosting is used, this check might fail (to be updated later)
972  if (num_verts > 0) {
973  int expected_verts = (lDims[3] - lDims[0] + 1) * (lDims[4] - lDims[1] + 1) * (-1 == lDims[2] ?
974  1 : lDims[5] - lDims[2] + 1); if (num_verts != expected_verts) { MB_SET_ERR(MB_FAILURE, "Number
975  of vertices doesn't match");
976  }
977  }
978  */
979 
980  // Check the number of elements too
981  int num_elems;
982  rval = mbImpl->get_number_entities_by_dimension( _fileSet, ( -1 == lCDims[2] ? 2 : 3 ), num_elems );MB_CHK_SET_ERR( rval, "Trouble getting number of elements" );
983 
984  /*
985  // Check against parameters
986  // When ghosting is used, this check might fail (to be updated later)
987  if (num_elems > 0) {
988  int expected_elems = (lCDims[3] - lCDims[0] + 1) * (lCDims[4] - lCDims[1] + 1) * (-1 ==
989  lCDims[2] ? 1 : (lCDims[5] - lCDims[2] + 1)); if (num_elems != expected_elems) {
990  MB_SET_ERR(MB_FAILURE, "Number of elements doesn't match");
991  }
992  }
993  */
994 
995  return MB_SUCCESS;
996 }

References moab::NCHelper::_fileSet, moab::NCHelper::_readNC, ErrorCode, 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 998 of file NCHelper.cpp.

999 {
1000  Interface*& mbImpl = _readNC->mbImpl;
1001  Tag& mGlobalIdTag = _readNC->mGlobalIdTag;
1002  const Tag*& mpFileIdTag = _readNC->mpFileIdTag;
1003  DebugOutput& dbgOut = _readNC->dbgOut;
1004  ScdInterface* scdi = _readNC->scdi;
1005  ScdParData& parData = _readNC->parData;
1006 
1007  Range tmp_range;
1008  ScdBox* scd_box;
1009 
1010  ErrorCode rval =
1011  scdi->construct_box( HomCoord( lDims[0], lDims[1], lDims[2], 1 ), HomCoord( lDims[3], lDims[4], lDims[5], 1 ),
1012  NULL, 0, scd_box, locallyPeriodic, &parData, true );MB_CHK_SET_ERR( rval, "Trouble creating scd vertex sequence" );
1013 
1014  // Add verts to tmp_range first, so we can duplicate global ids in vertex ids
1015  tmp_range.insert( scd_box->start_vertex(), scd_box->start_vertex() + scd_box->num_vertices() - 1 );
1016 
1017  if( mpFileIdTag )
1018  {
1019  int count;
1020  void* data;
1021  rval = mbImpl->tag_iterate( *mpFileIdTag, tmp_range.begin(), tmp_range.end(), count, data );MB_CHK_SET_ERR( rval, "Failed to iterate file ID tag on local vertices" );
1022  assert( count == scd_box->num_vertices() );
1023  int* fid_data = (int*)data;
1024  rval = mbImpl->tag_iterate( mGlobalIdTag, tmp_range.begin(), tmp_range.end(), count, data );MB_CHK_SET_ERR( rval, "Failed to iterate global ID tag on local vertices" );
1025  assert( count == scd_box->num_vertices() );
1026  int* gid_data = (int*)data;
1027  for( int i = 0; i < count; i++ )
1028  fid_data[i] = gid_data[i];
1029  }
1030 
1031  // Then add box set and elements to the range, then to the file set
1032  tmp_range.insert( scd_box->start_element(), scd_box->start_element() + scd_box->num_elements() - 1 );
1033  tmp_range.insert( scd_box->box_set() );
1034  rval = mbImpl->add_entities( _fileSet, tmp_range );MB_CHK_SET_ERR( rval, "Couldn't add new vertices to current file set" );
1035 
1036  dbgOut.tprintf( 1, "scdbox %d quads, %d vertices\n", scd_box->num_elements(), scd_box->num_vertices() );
1037 
1038  // Set the vertex coordinates
1039  double *xc, *yc, *zc;
1040  rval = scd_box->get_coordinate_arrays( xc, yc, zc );MB_CHK_SET_ERR( rval, "Couldn't get vertex coordinate arrays" );
1041 
1042  int i, j, k, il, jl, kl;
1043  int dil = lDims[3] - lDims[0] + 1;
1044  int djl = lDims[4] - lDims[1] + 1;
1045  assert( dil == (int)ilVals.size() && djl == (int)jlVals.size() &&
1046  ( -1 == lDims[2] || lDims[5] - lDims[2] + 1 == (int)levVals.size() ) );
1047 
1048  for( kl = lDims[2]; kl <= lDims[5]; kl++ )
1049  {
1050  k = kl - lDims[2];
1051  for( jl = lDims[1]; jl <= lDims[4]; jl++ )
1052  {
1053  j = jl - lDims[1];
1054  for( il = lDims[0]; il <= lDims[3]; il++ )
1055  {
1056  i = il - lDims[0];
1057  unsigned int pos = i + j * dil + k * dil * djl;
1058  xc[pos] = ilVals[i];
1059  yc[pos] = jlVals[j];
1060  zc[pos] = ( -1 == lDims[2] ? 0.0 : levVals[k] );
1061  }
1062  }
1063  }
1064 
1065 #ifndef NDEBUG
1066  int num_verts =
1067  ( lDims[3] - lDims[0] + 1 ) * ( lDims[4] - lDims[1] + 1 ) * ( -1 == lDims[2] ? 1 : lDims[5] - lDims[2] + 1 );
1068  std::vector< int > gids( num_verts );
1069  Range verts( scd_box->start_vertex(), scd_box->start_vertex() + scd_box->num_vertices() - 1 );
1070  rval = mbImpl->tag_get_data( mGlobalIdTag, verts, &gids[0] );MB_CHK_SET_ERR( rval, "Trouble getting local gid values of vertices" );
1071  int vmin = *( std::min_element( gids.begin(), gids.end() ) ),
1072  vmax = *( std::max_element( gids.begin(), gids.end() ) );
1073  dbgOut.tprintf( 1, "Vertex gids %d-%d\n", vmin, vmax );
1074 #endif
1075 
1076  // Add elements to the range passed in
1077  faces.insert( scd_box->start_element(), scd_box->start_element() + scd_box->num_elements() - 1 );
1078 
1079  if( 2 <= dbgOut.get_verbosity() )
1080  {
1081  assert( scd_box->boundary_complete() );
1082  EntityHandle dum_ent = scd_box->start_element();
1083  rval = mbImpl->list_entities( &dum_ent, 1 );MB_CHK_SET_ERR( rval, "Trouble listing first hex" );
1084 
1085  std::vector< EntityHandle > connect;
1086  rval = mbImpl->get_connectivity( &dum_ent, 1, connect );MB_CHK_SET_ERR( rval, "Trouble getting connectivity" );
1087 
1088  rval = mbImpl->list_entities( &connect[0], connect.size() );MB_CHK_SET_ERR( rval, "Trouble listing element connectivity" );
1089  }
1090 
1091  Range edges;
1092  mbImpl->get_adjacencies( faces, 1, true, edges, Interface::UNION );
1093 
1094  // Create COORDS tag for quads
1095  rval = create_quad_coordinate_tag();MB_CHK_SET_ERR( rval, "Trouble creating COORDS tag for quads" );
1096 
1097  return MB_SUCCESS;
1098 }

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(), ErrorCode, 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 1352 of file NCHelper.cpp.

1353 {
1354  Interface*& mbImpl = _readNC->mbImpl;
1355 
1356  Range ents;
1357  ErrorCode rval = mbImpl->get_entities_by_type( _fileSet, moab::MBQUAD, ents );MB_CHK_SET_ERR( rval, "Trouble getting quads" );
1358 
1359  std::size_t numOwnedEnts = 0;
1360 #ifdef MOAB_HAVE_MPI
1361  Range ents_owned;
1362  bool& isParallel = _readNC->isParallel;
1363  if( isParallel )
1364  {
1365  ParallelComm*& myPcomm = _readNC->myPcomm;
1366  rval = myPcomm->filter_pstatus( ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &ents_owned );MB_CHK_SET_ERR( rval, "Trouble getting owned quads" );
1367  numOwnedEnts = ents_owned.size();
1368  }
1369  else
1370  {
1371  numOwnedEnts = ents.size();
1372  ents_owned = ents;
1373  }
1374 #else
1375  numOwnedEnts = ents.size();
1376 #endif
1377 
1378  if( numOwnedEnts == 0 ) return MB_SUCCESS;
1379 
1380  assert( numOwnedEnts == ilCVals.size() * jlCVals.size() );
1381  std::vector< double > coords( numOwnedEnts * 3 );
1382  std::size_t pos = 0;
1383  for( std::size_t j = 0; j != jlCVals.size(); ++j )
1384  {
1385  for( std::size_t i = 0; i != ilCVals.size(); ++i )
1386  {
1387  pos = j * ilCVals.size() * 3 + i * 3;
1388  coords[pos] = ilCVals[i];
1389  coords[pos + 1] = jlCVals[j];
1390  coords[pos + 2] = 0.0;
1391  }
1392  }
1393  std::string tag_name = "COORDS";
1394  Tag tagh = 0;
1395  rval = mbImpl->tag_get_handle( tag_name.c_str(), 3, MB_TYPE_DOUBLE, tagh, MB_TAG_DENSE | MB_TAG_CREAT );MB_CHK_SET_ERR( rval, "Trouble creating COORDS tag" );
1396 
1397  void* data;
1398  int count;
1399 #ifdef MOAB_HAVE_MPI
1400  rval = mbImpl->tag_iterate( tagh, ents_owned.begin(), ents_owned.end(), count, data );MB_CHK_SET_ERR( rval, "Failed to iterate COORDS tag on quads" );
1401 #else
1402  rval = mbImpl->tag_iterate( tagh, ents.begin(), ents.end(), count, data );MB_CHK_SET_ERR( rval, "Failed to iterate COORDS tag on quads" );
1403 #endif
1404  assert( count == (int)numOwnedEnts );
1405  double* quad_data = (double*)data;
1406  std::copy( coords.begin(), coords.end(), quad_data );
1407 
1408  return MB_SUCCESS;
1409 }

References moab::NCHelper::_fileSet, moab::NCHelper::_readNC, moab::Range::begin(), moab::Range::end(), ErrorCode, 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 1238 of file NCHelper.cpp.

1240 {
1241  DebugOutput& dbgOut = _readNC->dbgOut;
1242 
1243  ErrorCode rval = read_scd_variables_to_nonset_allocate( vdatas, tstep_nums );MB_CHK_SET_ERR( rval, "Trouble allocating space to read non-set variables" );
1244 
1245  // Finally, read into that space
1246  int success;
1247  for( unsigned int i = 0; i < vdatas.size(); i++ )
1248  {
1249  std::size_t sz = vdatas[i].sz;
1250 
1251  // A typical supported variable: float T(time, lev, lat, lon)
1252  // For tag values, need transpose (lev, lat, lon) to (lat, lon, lev)
1253  size_t ni = vdatas[i].readCounts[3]; // lon or slon
1254  size_t nj = vdatas[i].readCounts[2]; // lat or slat
1255  size_t nk = vdatas[i].readCounts[1]; // lev
1256 
1257  for( unsigned int t = 0; t < tstep_nums.size(); t++ )
1258  {
1259  // Tag data for this timestep
1260  void* data = vdatas[i].varDatas[t];
1261 
1262  // Set readStart for each timestep along time dimension
1263  vdatas[i].readStarts[0] = tstep_nums[t];
1264 
1265  switch( vdatas[i].varDataType )
1266  {
1267  case NC_BYTE:
1268  case NC_CHAR: {
1269  std::vector< char > tmpchardata( sz );
1270  success = NCFUNCAG( _vara_text )( _fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
1271  &vdatas[i].readCounts[0], &tmpchardata[0] );
1272  if( success )
1273  MB_SET_ERR( MB_FAILURE, "Failed to read byte/char data for variable " << vdatas[i].varName );
1274  if( vdatas[i].numLev > 1 )
1275  // Transpose (lev, lat, lon) to (lat, lon, lev)
1276  kji_to_jik( ni, nj, nk, data, &tmpchardata[0] );
1277  else
1278  {
1279  for( std::size_t idx = 0; idx != tmpchardata.size(); idx++ )
1280  ( (char*)data )[idx] = tmpchardata[idx];
1281  }
1282  break;
1283  }
1284  case NC_SHORT:
1285  case NC_INT: {
1286  std::vector< int > tmpintdata( sz );
1287  success = NCFUNCAG( _vara_int )( _fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
1288  &vdatas[i].readCounts[0], &tmpintdata[0] );
1289  if( success )
1290  MB_SET_ERR( MB_FAILURE, "Failed to read short/int data for variable " << vdatas[i].varName );
1291  if( vdatas[i].numLev > 1 )
1292  // Transpose (lev, lat, lon) to (lat, lon, lev)
1293  kji_to_jik( ni, nj, nk, data, &tmpintdata[0] );
1294  else
1295  {
1296  for( std::size_t idx = 0; idx != tmpintdata.size(); idx++ )
1297  ( (int*)data )[idx] = tmpintdata[idx];
1298  }
1299  break;
1300  }
1301  case NC_INT64: {
1302  std::vector< long > tmpintdata( sz );
1303  success = NCFUNCAG( _vara_long )( _fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
1304  &vdatas[i].readCounts[0], &tmpintdata[0] );
1305  if( success )
1306  MB_SET_ERR( MB_FAILURE, "Failed to read long data for variable " << vdatas[i].varName );
1307  if( vdatas[i].numLev > 1 )
1308  // Transpose (lev, lat, lon) to (lat, lon, lev)
1309  kji_to_jik( ni, nj, nk, data, &tmpintdata[0] );
1310  else
1311  {
1312  for( std::size_t idx = 0; idx != tmpintdata.size(); idx++ )
1313  ( (long*)data )[idx] = tmpintdata[idx];
1314  }
1315  break;
1316  }
1317  case NC_FLOAT:
1318  case NC_DOUBLE: {
1319  std::vector< double > tmpdoubledata( sz );
1320  success = NCFUNCAG( _vara_double )( _fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
1321  &vdatas[i].readCounts[0], &tmpdoubledata[0] );
1322  if( success )
1323  MB_SET_ERR( MB_FAILURE, "Failed to read float/double data for variable " << vdatas[i].varName );
1324  if( vdatas[i].numLev > 1 )
1325  // Transpose (lev, lat, lon) to (lat, lon, lev)
1326  kji_to_jik( ni, nj, nk, data, &tmpdoubledata[0] );
1327  else
1328  {
1329  for( std::size_t idx = 0; idx != tmpdoubledata.size(); idx++ )
1330  ( (double*)data )[idx] = tmpdoubledata[idx];
1331  }
1332  break;
1333  }
1334  default:
1335  MB_SET_ERR( MB_FAILURE, "Unexpected data type for variable " << vdatas[i].varName );
1336  }
1337  }
1338  }
1339 
1340  // Debug output, if requested
1341  if( 1 == dbgOut.get_verbosity() )
1342  {
1343  dbgOut.printf( 1, "Read variables: %s", vdatas.begin()->varName.c_str() );
1344  for( unsigned int i = 1; i < vdatas.size(); i++ )
1345  dbgOut.printf( 1, ", %s ", vdatas[i].varName.c_str() );
1346  dbgOut.tprintf( 1, "\n" );
1347  }
1348 
1349  return rval;
1350 }

References moab::NCHelper::_fileId, moab::NCHelper::_readNC, moab::ReadNC::dbgOut, ErrorCode, moab::DebugOutput::get_verbosity(), kji_to_jik(), MB_CHK_SET_ERR, MB_SET_ERR, 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 1120 of file NCHelper.cpp.

1122 {
1123  Interface*& mbImpl = _readNC->mbImpl;
1124  std::vector< int >& dimLens = _readNC->dimLens;
1125  DebugOutput& dbgOut = _readNC->dbgOut;
1126 
1127  Range* range = NULL;
1128 
1129  // Get vertices
1130  Range verts;
1131  ErrorCode rval = mbImpl->get_entities_by_dimension( _fileSet, 0, verts );MB_CHK_SET_ERR( rval, "Trouble getting vertices in current file set" );
1132  assert( "Should only have a single vertex subrange, since they were read in one shot" && verts.psize() == 1 );
1133 
1134  Range edges;
1135  rval = mbImpl->get_entities_by_dimension( _fileSet, 1, edges );MB_CHK_SET_ERR( rval, "Trouble getting edges in current file set" );
1136 
1137  // Get faces
1138  Range faces;
1139  rval = mbImpl->get_entities_by_dimension( _fileSet, 2, faces );MB_CHK_SET_ERR( rval, "Trouble getting faces in current file set" );
1140  assert( "Should only have a single face subrange, since they were read in one shot" && faces.psize() == 1 );
1141 
1142 #ifdef MOAB_HAVE_MPI
1143  moab::Range faces_owned;
1144  bool& isParallel = _readNC->isParallel;
1145  if( isParallel )
1146  {
1147  ParallelComm*& myPcomm = _readNC->myPcomm;
1148  rval = myPcomm->filter_pstatus( faces, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &faces_owned );MB_CHK_SET_ERR( rval, "Trouble getting owned faces in current file set" );
1149  }
1150  else
1151  faces_owned = faces; // Not running in parallel, but still with MPI
1152 #endif
1153 
1154  for( unsigned int i = 0; i < vdatas.size(); i++ )
1155  {
1156  // Support non-set variables with 4 dimensions like (time, lev, lat, lon)
1157  assert( 4 == vdatas[i].varDims.size() );
1158 
1159  // For a non-set variable, time should be the first dimension
1160  assert( tDim == vdatas[i].varDims[0] );
1161 
1162  // Set up readStarts and readCounts
1163  vdatas[i].readStarts.resize( 4 );
1164  vdatas[i].readCounts.resize( 4 );
1165 
1166  // First: time
1167  vdatas[i].readStarts[0] = 0; // This value is timestep dependent, will be set later
1168  vdatas[i].readCounts[0] = 1;
1169 
1170  // Next: lev
1171  vdatas[i].readStarts[1] = 0;
1172  vdatas[i].readCounts[1] = vdatas[i].numLev;
1173 
1174  // Finally: lat (or slat) and lon (or slon)
1175  switch( vdatas[i].entLoc )
1176  {
1177  case ReadNC::ENTLOCVERT:
1178  // Vertices
1179  vdatas[i].readStarts[2] = lDims[1];
1180  vdatas[i].readCounts[2] = lDims[4] - lDims[1] + 1;
1181  vdatas[i].readStarts[3] = lDims[0];
1182  vdatas[i].readCounts[3] = lDims[3] - lDims[0] + 1;
1183  range = &verts;
1184  break;
1185  case ReadNC::ENTLOCNSEDGE:
1186  case ReadNC::ENTLOCEWEDGE:
1187  case ReadNC::ENTLOCEDGE:
1188  // Not implemented yet, set a global error
1189  MB_SET_GLB_ERR( MB_NOT_IMPLEMENTED, "Reading edge data is not implemented yet" );
1190  case ReadNC::ENTLOCFACE:
1191  // Faces
1192  vdatas[i].readStarts[2] = lCDims[1];
1193  vdatas[i].readCounts[2] = lCDims[4] - lCDims[1] + 1;
1194  vdatas[i].readStarts[3] = lCDims[0];
1195  vdatas[i].readCounts[3] = lCDims[3] - lCDims[0] + 1;
1196 #ifdef MOAB_HAVE_MPI
1197  range = &faces_owned;
1198 #else
1199  range = &faces;
1200 #endif
1201  break;
1202  default:
1203  MB_SET_ERR( MB_FAILURE, "Unexpected entity location type for variable " << vdatas[i].varName );
1204  }
1205 
1206  for( unsigned int t = 0; t < tstep_nums.size(); t++ )
1207  {
1208  dbgOut.tprintf( 2, "Reading variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t] );
1209 
1210  if( tstep_nums[t] >= dimLens[tDim] )
1211  {
1212  MB_SET_ERR( MB_INDEX_OUT_OF_RANGE, "Wrong value for timestep number " << tstep_nums[t] );
1213  }
1214 
1215  // Get the tag to read into
1216  if( !vdatas[i].varTags[t] )
1217  {
1218  rval = get_tag_to_nonset( vdatas[i], tstep_nums[t], vdatas[i].varTags[t], vdatas[i].numLev );MB_CHK_SET_ERR( rval, "Trouble getting tag to non-set variable " << vdatas[i].varName );
1219  }
1220 
1221  // Get ptr to tag space
1222  void* data;
1223  int count;
1224  rval = mbImpl->tag_iterate( vdatas[i].varTags[t], range->begin(), range->end(), count, data );MB_CHK_SET_ERR( rval, "Failed to iterate tag for non-set variable " << vdatas[i].varName );
1225  assert( (unsigned)count == range->size() );
1226  vdatas[i].varDatas[t] = data;
1227  }
1228 
1229  // Get variable size
1230  vdatas[i].sz = 1;
1231  for( std::size_t idx = 0; idx != vdatas[i].readCounts.size(); idx++ )
1232  vdatas[i].sz *= vdatas[i].readCounts[idx];
1233  }
1234 
1235  return rval;
1236 }

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, ErrorCode, 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, 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 1100 of file NCHelper.cpp.

1101 {
1102  std::vector< ReadNC::VarData > vdatas;
1103  std::vector< ReadNC::VarData > vsetdatas;
1104 
1105  ErrorCode rval = read_variables_setup( var_names, tstep_nums, vdatas, vsetdatas );MB_CHK_SET_ERR( rval, "Trouble setting up to read variables" );
1106 
1107  if( !vsetdatas.empty() )
1108  {
1109  rval = read_variables_to_set( vsetdatas, tstep_nums );MB_CHK_SET_ERR( rval, "Trouble reading variables to set" );
1110  }
1111 
1112  if( !vdatas.empty() )
1113  {
1114  rval = read_scd_variables_to_nonset( vdatas, tstep_nums );MB_CHK_SET_ERR( rval, "Trouble reading variables to verts/edges/faces" );
1115  }
1116 
1117  return MB_SUCCESS;
1118 }

References ErrorCode, 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: