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() ) )
40 std::vector< std::string >::iterator vit;
43 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"grid_size" ) ) != dimNames.end() )
45 idx = vit - dimNames.begin();
50 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"grid_corners" ) ) != dimNames.end() )
52 idx = vit - dimNames.begin();
57 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"grid_rank" ) ) != dimNames.end() )
59 idx = vit - dimNames.begin();
64 Tag convTagsCreated = 0;
68 int create_conv_tags_flag = 1;
73 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_center_lon", &xCellVarId );
74 if( success )
MB_CHK_SET_ERR( MB_FAILURE,
"Trouble getting grid_center_lon" );
75 std::map< std::string, ReadNC::VarData >& varInfo =
_readNC->
varInfo;
76 auto vmit = varInfo.find(
"grid_center_lon" );
77 if( varInfo.end() == vmit )
78 MB_SET_ERR( MB_FAILURE,
"Couldn't find variable "
79 <<
"grid_center_lon" );
81 auto attIt = glData.
varAtts.find(
"units" );
82 if( attIt != glData.
varAtts.end() )
84 unsigned int sz = attIt->second.attLen;
86 att_data.resize( sz + 1 );
87 att_data[sz] =
'\000';
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;
117 int shifted_rank = rank;
119 if( trivialPartitionShift > 0 ) shifted_rank = ( rank + trivialPartitionShift ) % procs;
132 start_cell_idx += std::min( shifted_rank, iextra );
137 ErrorCode rval = redistribute_local_cells( start_cell_idx, myPcomm );
MB_CHK_SET_ERR( rval,
"Failed to redistribute local cells after trivial partition" );
154 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_corner_lon", &xvId );
155 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_corner_lon" );
156 success =
NCFUNC( inq_varid )(
_fileId,
"grid_corner_lat", &yvId );
157 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_corner_lat" );
162 #ifdef MOAB_HAVE_PNETCDF
163 int factorRequests = 2;
165 success =
NCFUNC( inq_varid )(
_fileId,
"grid_imask", &gmId );
174 #ifdef MOAB_HAVE_PNETCDF
185 std::vector< int > masks( sizeMasks );
186 #ifdef MOAB_HAVE_PNETCDF
188 std::vector< int > requests( nb_reads * factorRequests );
189 std::vector< int > statuss( nb_reads * factorRequests );
192 size_t indexInArray = 0;
193 size_t indexInMaskArray = 0;
204 #ifdef MOAB_HAVE_PNETCDF
205 success = NCFUNCREQG( _vara_double )(
_fileId, xvId, read_starts, read_counts, &( xv[indexInArray] ),
206 &requests[idxReq++] );
208 success =
NCFUNCAG( _vara_double )(
_fileId, xvId, read_starts, read_counts, &( xv[indexInArray] ) );
210 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_corner_lon data in a loop" );
213 #ifdef MOAB_HAVE_PNETCDF
214 success = NCFUNCREQG( _vara_double )(
_fileId, yvId, read_starts, read_counts, &( yv[indexInArray] ),
215 &requests[idxReq++] );
217 success =
NCFUNCAG( _vara_double )(
_fileId, yvId, read_starts, read_counts, &( yv[indexInArray] ) );
219 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_corner_lat data in a loop" );
228 #ifdef MOAB_HAVE_PNETCDF
229 success = NCFUNCREQG( _vara_int )(
_fileId, gmId, &read_st, &read_ct, &( masks[indexInMaskArray] ),
230 &requests[idxReq++] );
232 success =
NCFUNCAG( _vara_int )(
_fileId, gmId, &read_st, &read_ct, &( masks[indexInMaskArray] ) );
234 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on mask read " );
235 indexInMaskArray += endh - starth + 1;
239 #ifdef MOAB_HAVE_PNETCDF
241 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
242 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
248 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_dims", &gdId );
249 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_dims" );
252 std::vector< int > vecDimSizes( 3, 0 );
260 vecDimSizes[0] = (
grid_rank == 2 ? 1 : 0 );
274 #ifdef MOAB_HAVE_PNETCDF
275 std::vector< int > requeststatus( 2 );
276 success = NCFUNCREQG( _vara_int )(
_fileId, gdId, read_starts, read_counts, vecDimSizes.data() + 1,
278 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_dims data" );
281 success =
NCFUNC( wait_all )(
_fileId, 1, &requeststatus[0], &requeststatus[1] );
282 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
284 success =
NCFUNCAG( _vara_int )(
_fileId, gdId, read_starts, read_counts, vecDimSizes.data() + 1 );
285 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_dims data" );
295 std::map< Node3D, EntityHandle > vertex_map;
313 double cosphi = cos(
pideg * y );
314 double zmult = sin(
pideg * y );
315 double xmult = cosphi * cos( x *
pideg );
316 double ymult = cosphi * sin( x *
pideg );
317 Node3D pt( xmult, ymult, zmult );
321 int nLocalVertices = (int)vertex_map.size();
322 std::vector< double* > arrays;
326 vtx_handle = start_vertex;
329 double *x = arrays[0], *y = arrays[1], *z = arrays[2];
330 for(
auto i = vertex_map.begin(); i != vertex_map.end(); ++i )
332 i->second = vtx_handle;
334 *x = i->first.coords[0];
336 *y = i->first.coords[1];
338 *z = i->first.coords[2];
362 for(
int k = 0; k < nv; k++ )
364 int index_v_arr = nv * elem_index + k;
367 double x = xv[index_v_arr];
368 double y = yv[index_v_arr];
369 double cosphi = cos(
pideg * y );
370 double zmult = sin(
pideg * y );
371 double xmult = cosphi * cos( x *
pideg );
372 double ymult = cosphi * sin( x *
pideg );
373 Node3D pt( xmult, ymult, zmult );
374 conn_arr[elem_index * nv + k] = vertex_map[pt];
390 int localMask = masks[elem_index];
398 std::vector< Tag > tagList;
399 tagList.push_back( mGlobalIdTag );
400 if( gmId >= 0 ) tagList.push_back( maskTag );
420 rval =
mb->get_connectivity( eh, conn, num_nodes );
MB_CHK_ERR( rval );
432 2 );
MB_CHK_SET_ERR( rval,
"Failed to merge vertices in parallel" );
437 Range edges, vertices;
462 #ifdef MOAB_HAVE_ZOLTAN
467 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_center_lon", &xCellVarId );
468 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_center_lon" );
472 success =
NCFUNCAG( _vara_double )(
_fileId, xCellVarId, &read_start, &read_count, &xc[0] );
473 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_center_lat data" );
477 success =
NCFUNC( inq_varid )(
_fileId,
"grid_center_lat", &yCellVarId );
478 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_center_lat" );
480 success =
NCFUNCAG( _vara_double )(
_fileId, yCellVarId, &read_start, &read_count, &yc[0] );
481 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_center_lon data" );
498 cosphi = cos(
pideg * y );
499 zCell[i] = sin(
pideg * y );
500 xCell[i] = cosphi * cos( x *
pideg );
501 yCell[i] = cosphi * sin( x *
pideg );