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

#include <NCHelperScrip.hpp>

+ Inheritance diagram for moab::NCHelperScrip:
+ Collaboration diagram for moab::NCHelperScrip:

Public Member Functions

 NCHelperScrip (ReadNC *readNC, int fileId, const FileOptions &opts, EntityHandle fileSet)
 
ErrorCode create_mesh (Range &faces)
 Implementation of NCHelper::create_mesh() More...
 
- Public Member Functions inherited from moab::ScdNCHelper
 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 ()
 
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...
 

Static Public Member Functions

static bool can_read_file (ReadNC *readNC, int fileId)
 
- 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 NCHelper * get_nc_helper (ReadNC *readNC, int fileId, const FileOptions &opts, EntityHandle fileSet)
 Get appropriate helper instance for ReadNC class. More...
 

Private Member Functions

ErrorCode assign_local_vertex_global_ids (Range &verts)
 Number the given vertices 1..n in GLOBAL_ID, for the serial read path where ParallelComm::assign_global_ids() is not available. Downstream consumers (notably the coverage-mesh migration in Intx2MeshOnSphere) key vertices by GLOBAL_ID. More...
 
virtual ErrorCode init_mesh_vals ()
 Interfaces to be implemented in child classes. More...
 
virtual std::string get_mesh_type_name ()
 

Private Attributes

int grid_corners
 
int grid_size
 
int grid_rank
 
int nLocalCells
 
Range localGidCells
 
bool degrees
 

Additional Inherited Members

- 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...
 
- Protected Attributes inherited from moab::ScdNCHelper
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...
 

Detailed Description

Definition at line 16 of file NCHelperScrip.hpp.

Constructor & Destructor Documentation

◆ NCHelperScrip()

moab::NCHelperScrip::NCHelperScrip ( ReadNC *  readNC,
int  fileId,
const FileOptions &  opts,
EntityHandle  fileSet 
)
inline

Definition at line 19 of file NCHelperScrip.hpp.

20  : ScdNCHelper( readNC, fileId, opts, fileSet ), grid_corners( 0 ), grid_size( 0 ), grid_rank( 1 ),
21  nLocalCells( 0 ), degrees( true )
22  {
23  }

Member Function Documentation

◆ assign_local_vertex_global_ids()

ErrorCode moab::NCHelperScrip::assign_local_vertex_global_ids ( Range &  verts)
private

Number the given vertices 1..n in GLOBAL_ID, for the serial read path where ParallelComm::assign_global_ids() is not available. Downstream consumers (notably the coverage-mesh migration in Intx2MeshOnSphere) key vertices by GLOBAL_ID.

Definition at line 95 of file NCHelperScrip.cpp.

96 {
97  Interface*& mbImpl = _readNC->mbImpl;
98  if( verts.empty() ) return MB_SUCCESS;
99 
100  Tag gidTag = mbImpl->globalId_tag();
101  std::vector< int > gids( verts.size() );
102  int id = 1;
103  for( size_t i = 0; i < gids.size(); i++ )
104  gids[i] = id++;
105  MB_CHK_SET_ERR( mbImpl->tag_set_data( gidTag, verts, &gids[0] ),
106  "Failed to assign GLOBAL_ID to SCRIP vertices" );
107  return MB_SUCCESS;
108 }

References moab::NCHelper::_readNC, moab::Range::empty(), moab::Interface::globalId_tag(), MB_CHK_SET_ERR, MB_SUCCESS, moab::ReadNC::mbImpl, moab::Range::size(), and moab::Interface::tag_set_data().

Referenced by create_mesh().

◆ can_read_file()

bool moab::NCHelperScrip::can_read_file ( ReadNC *  readNC,
int  fileId 
)
static

Definition at line 19 of file NCHelperScrip.cpp.

20 {
21  std::vector< std::string >& dimNames = readNC->dimNames;
22 
23  // If dimension names "grid_size" AND "grid_corners" AND "grid_rank" exist then it should be the Scrip grid
24  if( ( std::find( dimNames.begin(), dimNames.end(), std::string( "grid_size" ) ) != dimNames.end() ) &&
25  ( std::find( dimNames.begin(), dimNames.end(), std::string( "grid_corners" ) ) != dimNames.end() ) &&
26  ( std::find( dimNames.begin(), dimNames.end(), std::string( "grid_rank" ) ) != dimNames.end() ) )
27  {
28  return true;
29  }
30 
31  return false;
32 }

References moab::ReadNC::dimNames.

Referenced by moab::NCHelper::get_nc_format().

◆ create_mesh()

ErrorCode moab::NCHelperScrip::create_mesh ( Range &  faces)
virtual

Implementation of NCHelper::create_mesh()

Reimplemented from moab::ScdNCHelper.

Definition at line 110 of file NCHelperScrip.cpp.

111 {
112  Interface*& mbImpl = _readNC->mbImpl;
113  DebugOutput& dbgOut = _readNC->dbgOut;
114  Tag& mGlobalIdTag = _readNC->mGlobalIdTag;
115  ErrorCode rval;
116 
117 #ifdef MOAB_HAVE_MPI
118  int rank = 0;
119  int procs = 1;
120  bool& isParallel = _readNC->isParallel;
121  ParallelComm* myPcomm = NULL;
122  if( isParallel )
123  {
124  myPcomm = _readNC->myPcomm;
125  rank = myPcomm->proc_config().proc_rank();
126  procs = myPcomm->proc_config().proc_size();
127  }
128 
129  if( procs >= 2 )
130  {
131  // Shift rank to obtain a rotated trivial partition
132  int shifted_rank = rank;
133  int& trivialPartitionShift = _readNC->trivialPartitionShift;
134  if( trivialPartitionShift > 0 ) shifted_rank = ( rank + trivialPartitionShift ) % procs;
135 
136  // Compute the number of local cells on this proc
137  nLocalCells = int( std::floor( 1.0 * grid_size / procs ) );
138 
139  // The starting global cell index in the MPAS file for this proc
140  int start_cell_idx = shifted_rank * nLocalCells;
141 
142  // Number of extra cells after equal split over procs
143  int iextra = grid_size % procs;
144 
145  // Allocate extra cells over procs
146  if( shifted_rank < iextra ) nLocalCells++;
147  start_cell_idx += std::min( shifted_rank, iextra );
148 
149  start_cell_idx++; // 0 based -> 1 based
150 
151  // Redistribute local cells after trivial partition (e.g. apply Zoltan partition)
152  MB_CHK_SET_ERR( redistribute_local_cells( start_cell_idx, myPcomm ),
153  "Failed to redistribute local cells after trivial partition" );
154  }
155  else
156  {
159  }
160 #else
163 #endif
164  dbgOut.tprintf( 1, " localGidCells.psize() = %d\n", (int)localGidCells.psize() );
165  dbgOut.tprintf( 1, " localGidCells.size() = %d\n", (int)localGidCells.size() );
166 
167  // double grid_corner_lat(grid_size, grid_corners) ;
168  // double grid_corner_lon(grid_size, grid_corners) ;
169  int xvId, yvId;
170  int success = NCFUNC( inq_varid )( _fileId, "grid_corner_lon", &xvId );
171  if( success ) MB_SET_ERR( MB_FAILURE, "Failed to get variable id of grid_corner_lon" );
172  success = NCFUNC( inq_varid )( _fileId, "grid_corner_lat", &yvId );
173  if( success ) MB_SET_ERR( MB_FAILURE, "Failed to get variable id of grid_corner_lat" );
174 
175  // important upgrade: read masks if they exist, and save them as tags
176  int gmId = -1;
177  int sizeMasks = 0;
178 #ifdef MOAB_HAVE_PNETCDF
179  int factorRequests = 2; // we would read in general only 2 variables, xv and yv
180 #endif
181  success = NCFUNC( inq_varid )( _fileId, "grid_imask", &gmId );
182  Tag maskTag = 0; // not sure yet if we have the masks or not
183  if( success )
184  {
185  gmId = -1; // we do not have masks
186  }
187  else
188  {
189  sizeMasks = nLocalCells;
190 #ifdef MOAB_HAVE_PNETCDF
191  factorRequests = 3; // we also need to read masks distributed
192 #endif
193  // create the maskTag GRID_IMASK, with default value of 1
194  int def_val = 1;
195  MB_CHK_SET_ERR( mbImpl->tag_get_handle( "GRID_IMASK", 1, MB_TYPE_INTEGER, maskTag, MB_TAG_DENSE | MB_TAG_CREAT,
196  &def_val ),
197  "Trouble creating GRID_IMASK tag" );
198  }
199 
200  std::vector< double > xv( nLocalCells * grid_corners );
201  std::vector< double > yv( nLocalCells * grid_corners );
202  std::vector< int > masks( sizeMasks );
203 #ifdef MOAB_HAVE_PNETCDF
204  size_t nb_reads = localGidCells.psize();
205  std::vector< int > requests( nb_reads * factorRequests );
206  std::vector< int > statuss( nb_reads * factorRequests );
207  size_t idxReq = 0;
208 #endif
209  size_t indexInArray = 0;
210  size_t indexInMaskArray = 0;
211  for( Range::pair_iterator pair_iter = localGidCells.pair_begin(); pair_iter != localGidCells.pair_end();
212  ++pair_iter )
213  {
214  EntityHandle starth = pair_iter->first;
215  EntityHandle endh = pair_iter->second;
216  NCDF_SIZE read_starts[2] = { static_cast< NCDF_SIZE >( starth - 1 ), 0 };
217  NCDF_SIZE read_counts[2] = { static_cast< NCDF_SIZE >( endh - starth + 1 ),
218  static_cast< NCDF_SIZE >( grid_corners ) };
219 
220  // Do a partial read in each subrange
221 #ifdef MOAB_HAVE_PNETCDF
222  success = NCFUNCREQG( _vara_double )( _fileId, xvId, read_starts, read_counts, &( xv[indexInArray] ),
223  &requests[idxReq++] );
224 #else
225  success = NCFUNCAG( _vara_double )( _fileId, xvId, read_starts, read_counts, &( xv[indexInArray] ) );
226 #endif
227  if( success ) MB_SET_ERR( MB_FAILURE, "Failed to read grid_corner_lon data in a loop" );
228 
229  // Do a partial read in each subrange
230 #ifdef MOAB_HAVE_PNETCDF
231  success = NCFUNCREQG( _vara_double )( _fileId, yvId, read_starts, read_counts, &( yv[indexInArray] ),
232  &requests[idxReq++] );
233 #else
234  success = NCFUNCAG( _vara_double )( _fileId, yvId, read_starts, read_counts, &( yv[indexInArray] ) );
235 #endif
236  if( success ) MB_SET_ERR( MB_FAILURE, "Failed to read grid_corner_lat data in a loop" );
237  // Increment the index for next subrange
238  indexInArray += ( endh - starth + 1 ) * grid_corners;
239 
240  if( gmId >= 0 ) // it means we need to read masks too, distributed:
241  {
242  NCDF_SIZE read_st = static_cast< NCDF_SIZE >( starth - 1 );
243  NCDF_SIZE read_ct = static_cast< NCDF_SIZE >( endh - starth + 1 );
244  // Do a partial read in each subrange, for mask variable:
245 #ifdef MOAB_HAVE_PNETCDF
246  success = NCFUNCREQG( _vara_int )( _fileId, gmId, &read_st, &read_ct, &( masks[indexInMaskArray] ),
247  &requests[idxReq++] );
248 #else
249  success = NCFUNCAG( _vara_int )( _fileId, gmId, &read_st, &read_ct, &( masks[indexInMaskArray] ) );
250 #endif
251  if( success ) MB_SET_ERR( MB_FAILURE, "Failed on mask read " );
252  indexInMaskArray += endh - starth + 1;
253  }
254  }
255 
256 #ifdef MOAB_HAVE_PNETCDF
257  // Wait outside the loop
258  success = NCFUNC( wait_all )( _fileId, requests.size(), &requests[0], &statuss[0] );
259  if( success ) MB_SET_ERR( MB_FAILURE, "Failed on wait_all" );
260 #endif
261 
262  // int grid_dims(grid_rank)
263  {
264  int gdId;
265  int success = NCFUNC( inq_varid )( _fileId, "grid_dims", &gdId );
266  if( success ) MB_SET_ERR( MB_FAILURE, "Failed to get variable id of grid_dims" );
267 
268  // If rectilinear attribute present, mark it
269  std::vector< int > vecDimSizes( 3, 0 );
270  Tag rectilinearTag;
271  // Tag data contains: guessed mesh type, mesh size1, mesh size 2
272  // Example: CS(0)/ICO(1)/ICOD(2), num_elements, num_nodes
273  // : RLL(3), num_lat, num_lon
274 
275  // create the maskTag GRID_IMASK, with default value of 1
276 
277  vecDimSizes[0] = ( grid_rank == 2 ? 1 /* moab::TempestRemapper::RLL */ : 0 /* moab::TempestRemapper::CS */ );
278  vecDimSizes[1] = grid_size; // number of elements
279  vecDimSizes[2] = grid_size; // number of elements
280  rval = mbImpl->tag_get_handle( "ClimateMetadata", 3, MB_TYPE_INTEGER, rectilinearTag,
281  MB_TAG_SPARSE | MB_TAG_CREAT, vecDimSizes.data() );
282  if( MB_ALREADY_ALLOCATED != rval && MB_SUCCESS != rval )
283  MB_CHK_SET_ERR( rval, "can't create rectilinear sizes tag" );
284 
285  if( grid_rank == 2 )
286  {
287  NCDF_SIZE read_starts[1] = { static_cast< NCDF_SIZE >( 0 ) };
288  NCDF_SIZE read_counts[1] = { static_cast< NCDF_SIZE >( grid_rank ) };
289 
290  // Do a partial read in each subrange
291 #ifdef MOAB_HAVE_PNETCDF
292  std::vector< int > requeststatus( 2 );
293  success = NCFUNCREQG( _vara_int )( _fileId, gdId, read_starts, read_counts, vecDimSizes.data() + 1,
294  &requeststatus[0] );
295  if( success ) MB_SET_ERR( MB_FAILURE, "Failed to read grid_dims data" );
296 
297  // Wait outside the loop
298  success = NCFUNC( wait_all )( _fileId, 1, &requeststatus[0], &requeststatus[1] );
299  if( success ) MB_SET_ERR( MB_FAILURE, "Failed on wait_all" );
300 #else
301  success = NCFUNCAG( _vara_int )( _fileId, gdId, read_starts, read_counts, vecDimSizes.data() + 1 );
302  if( success ) MB_SET_ERR( MB_FAILURE, "Failed to read grid_dims data" );
303 #endif
304  }
305 
306  rval = mbImpl->tag_set_data( rectilinearTag, &_fileSet, 1, vecDimSizes.data() );
307  }
308 
309  // so we read xv, yv for all corners in the local mesh, and masks if they exist
310 
311  // Create vertices; first identify different ones, with a tolerance
312  std::map< Node3D, EntityHandle > vertex_map;
313 
314  // Set vertex coordinates
315  // will read all xv, yv, but use only those with correct mask on
316 
317  int elem_index = 0; // local index in netcdf arrays
318  double pideg = 1.; // radians
319  if( degrees ) pideg = acos( -1.0 ) / 180.0;
320 
321  for( ; elem_index < nLocalCells; elem_index++ )
322  {
323  // set area and fraction on those elements too
324  for( int k = 0; k < grid_corners; k++ )
325  {
326  int index_v_arr = grid_corners * elem_index + k;
327  double x, y;
328  x = xv[index_v_arr];
329  y = yv[index_v_arr];
330  double cosphi = cos( pideg * y );
331  double zmult = sin( pideg * y );
332  double xmult = cosphi * cos( x * pideg );
333  double ymult = cosphi * sin( x * pideg );
334  Node3D pt( xmult, ymult, zmult );
335  vertex_map[pt] = 0;
336  }
337  }
338  int nLocalVertices = (int)vertex_map.size();
339  std::vector< double* > arrays;
340  EntityHandle start_vertex, vtx_handle;
341  MB_CHK_SET_ERR( _readNC->readMeshIface->get_node_coords( 3, nLocalVertices, 0, start_vertex, arrays ),
342  "Failed to create local vertices" );
343 
344  vtx_handle = start_vertex;
345  // Copy vertex coordinates into entity sequence coordinate arrays
346  // and copy handle into vertex_map.
347  double *x = arrays[0], *y = arrays[1], *z = arrays[2];
348  for( auto i = vertex_map.begin(); i != vertex_map.end(); ++i )
349  {
350  i->second = vtx_handle;
351  ++vtx_handle;
352  *x = i->first.coords[0];
353  ++x;
354  *y = i->first.coords[1];
355  ++y;
356  *z = i->first.coords[2];
357  ++z;
358  }
359 
360  EntityHandle start_cell;
361  int nv = grid_corners;
362  EntityType mdb_type = MBVERTEX;
363  if( nv == 3 )
364  mdb_type = MBTRI;
365  else if( nv == 4 )
366  mdb_type = MBQUAD;
367  else if( nv > 4 ) // (nv > 4)
368  mdb_type = MBPOLYGON;
369 
370  Range tmp_range;
371  EntityHandle* conn_arr;
372 
373  MB_CHK_SET_ERR( _readNC->readMeshIface->get_element_connect( nLocalCells, nv, mdb_type, 0, start_cell, conn_arr ),
374  "Failed to create local cells" );
375  tmp_range.insert( start_cell, start_cell + nLocalCells - 1 );
376 
377  elem_index = 0;
378 
379  for( ; elem_index < nLocalCells; elem_index++ )
380  {
381  for( int k = 0; k < nv; k++ )
382  {
383  int index_v_arr = nv * elem_index + k;
384  if( nv > 1 )
385  {
386  double x = xv[index_v_arr];
387  double y = yv[index_v_arr];
388  double cosphi = cos( pideg * y );
389  double zmult = sin( pideg * y );
390  double xmult = cosphi * cos( x * pideg );
391  double ymult = cosphi * sin( x * pideg );
392  Node3D pt( xmult, ymult, zmult );
393  conn_arr[elem_index * nv + k] = vertex_map[pt];
394  }
395  }
396  EntityHandle cell = start_cell + elem_index;
397  // set other tags, like xc, yc, frac, area
398  /*MB_CHK_SET_ERR( mbImpl->tag_set_data( xcTag, &cell, 1, &xc[elem_index] ), "Failed to set xc tag" );
399  MB_CHK_SET_ERR( mbImpl->tag_set_data( ycTag, &cell, 1, &yc[elem_index] ), "Failed to set yc tag" );
400  MB_CHK_SET_ERR( mbImpl->tag_set_data( areaTag, &cell, 1, &area[elem_index] ), "Failed to set area tag" );
401  MB_CHK_SET_ERR( mbImpl->tag_set_data( fracTag, &cell, 1, &frac[elem_index] ), "Failed to set frac tag" );
402 */
403  // set the global id too:
404  int globalId = localGidCells[elem_index];
405 
406  MB_CHK_SET_ERR( mbImpl->tag_set_data( mGlobalIdTag, &cell, 1, &globalId ), "Failed to set global id tag" );
407  if( gmId >= 0 )
408  {
409  int localMask = masks[elem_index];
410  MB_CHK_SET_ERR( mbImpl->tag_set_data( maskTag, &cell, 1, &localMask ), "Failed to set mask tag" );
411  }
412  }
413 
414  MB_CHK_SET_ERR( mbImpl->add_entities( _fileSet, tmp_range ), "Failed to add new cells to current file set" );
415 
416  // modify local file set, to merge coincident vertices, and to correct repeated vertices in elements
417  std::vector< Tag > tagList;
418  tagList.push_back( mGlobalIdTag );
419  if( gmId >= 0 ) tagList.push_back( maskTag );
421  "Failed to remove duplicate vertices" );
422 
423  MB_CHK_ERR( mbImpl->get_entities_by_dimension( _fileSet, 2, faces ) );
424  Range all_verts;
425  MB_CHK_ERR( mbImpl->get_connectivity( faces, all_verts ) );
426  MB_CHK_ERR( mbImpl->add_entities( _fileSet, all_verts ) );
427  // need to add adjacencies; TODO: fix this for all nc readers
428  // copy this logic from migrate mesh in par comm graph
429  Core* mb = (Core*)mbImpl;
430  AEntityFactory* adj_fact = mb->a_entity_factory();
431  if( !adj_fact->vert_elem_adjacencies() )
432  adj_fact->create_vert_elem_adjacencies();
433  else
434  {
435  for( Range::iterator it = faces.begin(); it != faces.end(); ++it )
436  {
437  EntityHandle eh = *it;
438  const EntityHandle* conn = NULL;
439  int num_nodes = 0;
440  MB_CHK_ERR( mb->get_connectivity( eh, conn, num_nodes ) );
441  adj_fact->notify_create_entity( eh, conn, num_nodes );
442  }
443  }
444 
445 #ifdef MOAB_HAVE_MPI
446  if( myPcomm )
447  {
448  double tol = 1.e-12; // this is the same as static tolerance in NCHelper
449  ParallelMergeMesh pmm( myPcomm, tol );
450  MB_CHK_SET_ERR( pmm.merge( _fileSet,
451  /* do not do local merge*/ false,
452  /* 2d cells*/ 2 ),
453  "Failed to merge vertices in parallel" );
454 
455  // assign global ids only for vertices, cells have them fine
456  MB_CHK_ERR( myPcomm->assign_global_ids( _fileSet, /*dim*/ 0 ) );
457  // remove all sets, edges and vertices from the file set
458  Range edges, vertices;
459  MB_CHK_ERR( mbImpl->get_entities_by_dimension( _fileSet, 1, edges, /*recursive*/ true ) );
460  MB_CHK_ERR( mbImpl->get_entities_by_dimension( _fileSet, 0, vertices, /*recursive*/ true ) );
461  MB_CHK_ERR( mbImpl->remove_entities( _fileSet, edges ) );
462  MB_CHK_ERR( mbImpl->remove_entities( _fileSet, vertices ) );
463 
464  Range intfSets = myPcomm->interface_sets();
465  // empty intf sets
466  MB_CHK_ERR( mbImpl->clear_meshset( intfSets ) );
467  // delete the sets without shame :)
468  //sets.merge(intfSets);
469  //MB_CHK_ERR( myPcomm->delete_entities(sets) ); // will also clean shared ents !
470  MB_CHK_ERR( myPcomm->delete_entities( edges ) ); // will also clean shared ents !
471  }
472  else
473  {
474  // Serial read (no ParallelComm): still number the vertices. Consumers such as
475  // Intx2MeshOnSphere::construct_covering_set() identify vertices across ranks purely
476  // by GLOBAL_ID, so a mesh written out here and re-read in parallel later must carry
477  // one; otherwise every vertex reads back as the tag default (-1) and migrated cells
478  // collapse to a single repeated corner.
480  MB_CHK_ERR( mbImpl->remove_entities( _fileSet, all_verts ) );
481  }
482 #else
484  MB_CHK_ERR( mbImpl->remove_entities( _fileSet, all_verts ) );
485 #endif
486 
487  return MB_SUCCESS;
488 }

References moab::NCHelper::_fileId, moab::NCHelper::_fileSet, moab::NCHelper::_readNC, moab::Interface::add_entities(), moab::ParallelComm::assign_global_ids(), assign_local_vertex_global_ids(), moab::Range::begin(), moab::Interface::clear_meshset(), moab::AEntityFactory::create_vert_elem_adjacencies(), moab::ReadNC::dbgOut, degrees, moab::ParallelComm::delete_entities(), moab::Range::end(), ErrorCode, moab::Interface::get_connectivity(), moab::ReadUtilIface::get_element_connect(), moab::Interface::get_entities_by_dimension(), moab::ReadUtilIface::get_node_coords(), grid_corners, grid_rank, grid_size, moab::Range::insert(), moab::ParallelComm::interface_sets(), moab::ReadNC::isParallel, localGidCells, mb, MB_ALREADY_ALLOCATED, MB_CHK_ERR, MB_CHK_SET_ERR, MB_SET_ERR, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TAG_SPARSE, MB_TYPE_INTEGER, moab::ReadNC::mbImpl, MBPOLYGON, MBQUAD, MBTRI, MBVERTEX, moab::ParallelMergeMesh::merge(), moab::ReadNC::mGlobalIdTag, NCDF_SIZE, NCFUNC, NCFUNCAG, NCFUNCREQG, nLocalCells, moab::AEntityFactory::notify_create_entity(), moab::Range::pair_begin(), moab::Range::pair_end(), moab::pideg, moab::ParallelComm::proc_config(), moab::ProcConfig::proc_rank(), moab::ProcConfig::proc_size(), moab::Range::psize(), moab::ReadNC::readMeshIface, moab::Interface::remove_entities(), moab::IntxUtils::remove_padded_vertices(), moab::Range::size(), moab::Interface::tag_get_handle(), moab::Interface::tag_set_data(), moab::DebugOutput::tprintf(), moab::ReadNC::trivialPartitionShift, and moab::AEntityFactory::vert_elem_adjacencies().

◆ get_mesh_type_name()

virtual std::string moab::NCHelperScrip::get_mesh_type_name ( )
inlineprivatevirtual

Implements moab::NCHelper.

Definition at line 40 of file NCHelperScrip.hpp.

41  {
42  return "SCRIP";
43  }

◆ init_mesh_vals()

ErrorCode moab::NCHelperScrip::init_mesh_vals ( )
privatevirtual

Interfaces to be implemented in child classes.

Implements moab::NCHelper.

Definition at line 33 of file NCHelperScrip.cpp.

34 {
35  Interface*& mbImpl = _readNC->mbImpl;
36  std::vector< std::string >& dimNames = _readNC->dimNames;
37  std::vector< int >& dimLens = _readNC->dimLens;
38 
39  unsigned int idx;
40  std::vector< std::string >::iterator vit;
41 
42  // get grid_size
43  if( ( vit = std::find( dimNames.begin(), dimNames.end(), "grid_size" ) ) != dimNames.end() )
44  {
45  idx = vit - dimNames.begin();
46  grid_size = dimLens[idx];
47  }
48 
49  // get grid_corners
50  if( ( vit = std::find( dimNames.begin(), dimNames.end(), "grid_corners" ) ) != dimNames.end() )
51  {
52  idx = vit - dimNames.begin();
53  grid_corners = dimLens[idx];
54  }
55 
56  // get grid_rank
57  if( ( vit = std::find( dimNames.begin(), dimNames.end(), "grid_rank" ) ) != dimNames.end() )
58  {
59  idx = vit - dimNames.begin();
60  grid_rank = dimLens[idx];
61  }
62 
63  // do not need conventional tags
64  Tag convTagsCreated = 0;
65  int def_val = 0;
66  MB_CHK_SET_ERR( mbImpl->tag_get_handle( "__CONV_TAGS_CREATED", 1, MB_TYPE_INTEGER, convTagsCreated,
67  MB_TAG_SPARSE | MB_TAG_CREAT, &def_val ),
68  "Trouble getting _CONV_TAGS_CREATED tag" );
69  int create_conv_tags_flag = 1;
70  MB_CHK_SET_ERR( mbImpl->tag_set_data( convTagsCreated, &_fileSet, 1, &create_conv_tags_flag ),
71  "Trouble setting _CONV_TAGS_CREATED tag" );
72 
73  // decide now the units, by looking at grid_center_lon
74  int xCellVarId;
75  int success = NCFUNC( inq_varid )( _fileId, "grid_center_lon", &xCellVarId );
76  if( success ) MB_CHK_SET_ERR( MB_FAILURE, "Trouble getting grid_center_lon" );
77  std::map< std::string, ReadNC::VarData >& varInfo = _readNC->varInfo;
78  auto vmit = varInfo.find( "grid_center_lon" );
79  if( varInfo.end() == vmit ) MB_SET_ERR( MB_FAILURE, "Couldn't find variable " << "grid_center_lon" );
80  ReadNC::VarData& glData = vmit->second;
81  auto attIt = glData.varAtts.find( "units" );
82  if( attIt != glData.varAtts.end() )
83  {
84  unsigned int sz = attIt->second.attLen;
85  std::string att_data;
86  att_data.resize( sz + 1 );
87  att_data[sz] = '\000';
88  success =
89  NCFUNC( get_att_text )( _fileId, attIt->second.attVarId, attIt->second.attName.c_str(), &att_data[0] );
90  if( 0 == success && att_data.find( "radians" ) != std::string::npos ) degrees = false;
91  }
92 
93  return MB_SUCCESS;
94 }

References moab::NCHelper::_fileId, moab::NCHelper::_fileSet, moab::NCHelper::_readNC, degrees, moab::ReadNC::dimLens, moab::ReadNC::dimNames, grid_corners, grid_rank, grid_size, MB_CHK_SET_ERR, MB_SET_ERR, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_INTEGER, moab::ReadNC::mbImpl, NCFUNC, moab::Interface::tag_get_handle(), moab::Interface::tag_set_data(), moab::ReadNC::VarData::varAtts, and moab::ReadNC::varInfo.

Member Data Documentation

◆ degrees

bool moab::NCHelperScrip::degrees
private

Definition at line 50 of file NCHelperScrip.hpp.

Referenced by create_mesh(), and init_mesh_vals().

◆ grid_corners

int moab::NCHelperScrip::grid_corners
private

Definition at line 45 of file NCHelperScrip.hpp.

Referenced by create_mesh(), and init_mesh_vals().

◆ grid_rank

int moab::NCHelperScrip::grid_rank
private

Definition at line 47 of file NCHelperScrip.hpp.

Referenced by create_mesh(), and init_mesh_vals().

◆ grid_size

int moab::NCHelperScrip::grid_size
private

Definition at line 46 of file NCHelperScrip.hpp.

Referenced by create_mesh(), and init_mesh_vals().

◆ localGidCells

Range moab::NCHelperScrip::localGidCells
private

Definition at line 49 of file NCHelperScrip.hpp.

Referenced by create_mesh().

◆ nLocalCells

int moab::NCHelperScrip::nLocalCells
private

Definition at line 48 of file NCHelperScrip.hpp.

Referenced by create_mesh().


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