12 #ifdef MOAB_HAVE_ZOLTAN
21 std::vector< std::string >& dimNames = readNC->
dimNames;
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() ) )
41 std::vector< std::string >::iterator vit;
44 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"grid_size" ) ) != dimNames.end() )
46 idx = vit - dimNames.begin();
51 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"grid_corners" ) ) != dimNames.end() )
53 idx = vit - dimNames.begin();
58 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"grid_rank" ) ) != dimNames.end() )
60 idx = vit - dimNames.begin();
65 Tag convTagsCreated = 0;
69 int create_conv_tags_flag = 1;
74 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_center_lon", &xCellVarId );
75 if( success )
MB_CHK_SET_ERR( MB_FAILURE,
"Trouble getting grid_center_lon" );
76 std::map< std::string, ReadNC::VarData >& varInfo =
_readNC->
varInfo;
77 auto vmit = varInfo.find(
"grid_center_lon" );
78 if( varInfo.end() == vmit )
79 MB_SET_ERR( MB_FAILURE,
"Couldn't find variable "
80 <<
"grid_center_lon" );
82 auto attIt = glData.
varAtts.find(
"units" );
83 if( attIt != glData.
varAtts.end() )
85 unsigned int sz = attIt->second.attLen;
87 att_data.resize( sz + 1 );
88 att_data[sz] =
'\000';
90 NCFUNC( get_att_text )(
_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), &att_data[0] );
91 if( 0 == success && att_data.find(
"radians" ) != std::string::npos )
degrees =
false;
118 int shifted_rank = rank;
120 if( trivialPartitionShift > 0 ) shifted_rank = ( rank + trivialPartitionShift ) % procs;
133 start_cell_idx += std::min( shifted_rank, iextra );
138 ErrorCode rval = redistribute_local_cells( start_cell_idx, myPcomm );
MB_CHK_SET_ERR( rval,
"Failed to redistribute local cells after trivial partition" );
155 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_corner_lon", &xvId );
156 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_corner_lon" );
157 success =
NCFUNC( inq_varid )(
_fileId,
"grid_corner_lat", &yvId );
158 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_corner_lat" );
163 #ifdef MOAB_HAVE_PNETCDF
164 int factorRequests = 2;
166 success =
NCFUNC( inq_varid )(
_fileId,
"grid_imask", &gmId );
175 #ifdef MOAB_HAVE_PNETCDF
186 std::vector< int > masks( sizeMasks );
187 #ifdef MOAB_HAVE_PNETCDF
189 std::vector< int > requests( nb_reads * factorRequests );
190 std::vector< int > statuss( nb_reads * factorRequests );
193 size_t indexInArray = 0;
194 size_t indexInMaskArray = 0;
205 #ifdef MOAB_HAVE_PNETCDF
206 success = NCFUNCREQG( _vara_double )(
_fileId, xvId, read_starts, read_counts, &( xv[indexInArray] ),
207 &requests[idxReq++] );
209 success =
NCFUNCAG( _vara_double )(
_fileId, xvId, read_starts, read_counts, &( xv[indexInArray] ) );
211 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_corner_lon data in a loop" );
214 #ifdef MOAB_HAVE_PNETCDF
215 success = NCFUNCREQG( _vara_double )(
_fileId, yvId, read_starts, read_counts, &( yv[indexInArray] ),
216 &requests[idxReq++] );
218 success =
NCFUNCAG( _vara_double )(
_fileId, yvId, read_starts, read_counts, &( yv[indexInArray] ) );
220 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_corner_lat data in a loop" );
229 #ifdef MOAB_HAVE_PNETCDF
230 success = NCFUNCREQG( _vara_int )(
_fileId, gmId, &read_st, &read_ct, &( masks[indexInMaskArray] ),
231 &requests[idxReq++] );
233 success =
NCFUNCAG( _vara_int )(
_fileId, gmId, &read_st, &read_ct, &( masks[indexInMaskArray] ) );
235 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on mask read " );
236 indexInMaskArray += endh - starth + 1;
240 #ifdef MOAB_HAVE_PNETCDF
242 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
243 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
249 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_dims", &gdId );
250 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_dims" );
253 std::vector< int > vecDimSizes( 3, 0 );
261 vecDimSizes[0] = (
grid_rank == 2 ? 1 : 0 );
275 #ifdef MOAB_HAVE_PNETCDF
276 std::vector< int > requeststatus( 2 );
277 success = NCFUNCREQG( _vara_int )(
_fileId, gdId, read_starts, read_counts, vecDimSizes.data() + 1,
279 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_dims data" );
282 success =
NCFUNC( wait_all )(
_fileId, 1, &requeststatus[0], &requeststatus[1] );
283 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
285 success =
NCFUNCAG( _vara_int )(
_fileId, gdId, read_starts, read_counts, vecDimSizes.data() + 1 );
286 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_dims data" );
296 std::map< Node3D, EntityHandle > vertex_map;
314 double cosphi = cos(
pideg * y );
315 double zmult = sin(
pideg * y );
316 double xmult = cosphi * cos( x *
pideg );
317 double ymult = cosphi * sin( x *
pideg );
318 Node3D pt( xmult, ymult, zmult );
322 int nLocalVertices = (int)vertex_map.size();
323 std::vector< double* > arrays;
327 vtx_handle = start_vertex;
330 double *x = arrays[0], *y = arrays[1], *z = arrays[2];
331 for(
auto i = vertex_map.begin(); i != vertex_map.end(); ++i )
333 i->second = vtx_handle;
335 *x = i->first.coords[0];
337 *y = i->first.coords[1];
339 *z = i->first.coords[2];
363 for(
int k = 0; k < nv; k++ )
365 int index_v_arr = nv * elem_index + k;
368 double x = xv[index_v_arr];
369 double y = yv[index_v_arr];
370 double cosphi = cos(
pideg * y );
371 double zmult = sin(
pideg * y );
372 double xmult = cosphi * cos( x *
pideg );
373 double ymult = cosphi * sin( x *
pideg );
374 Node3D pt( xmult, ymult, zmult );
375 conn_arr[elem_index * nv + k] = vertex_map[pt];
391 int localMask = masks[elem_index];
399 std::vector< Tag > tagList;
400 tagList.push_back( mGlobalIdTag );
401 if( gmId >= 0 ) tagList.push_back( maskTag );
421 rval =
mb->get_connectivity( eh, conn, num_nodes );
MB_CHK_ERR( rval );
433 2 );
MB_CHK_SET_ERR( rval,
"Failed to merge vertices in parallel" );
438 Range edges, vertices;
463 #ifdef MOAB_HAVE_ZOLTAN
468 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_center_lon", &xCellVarId );
469 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_center_lon" );
473 success =
NCFUNCAG( _vara_double )(
_fileId, xCellVarId, &read_start, &read_count, &xc[0] );
474 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_center_lat data" );
478 success =
NCFUNC( inq_varid )(
_fileId,
"grid_center_lat", &yCellVarId );
479 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_center_lat" );
481 success =
NCFUNCAG( _vara_double )(
_fileId, yCellVarId, &read_start, &read_count, &yc[0] );
482 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_center_lon data" );
499 cosphi = cos(
pideg * y );
500 zCell[i] = sin(
pideg * y );
501 xCell[i] = cosphi * cos( x *
pideg );
502 yCell[i] = cosphi * sin( x *
pideg );