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 "Trouble getting _CONV_TAGS_CREATED tag" );
69 int create_conv_tags_flag = 1;
71 "Trouble setting _CONV_TAGS_CREATED tag" );
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" );
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 MB_CHK_SET_ERR( redistribute_local_cells( start_cell_idx, myPcomm ),
138 "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
182 "Trouble creating GRID_IMASK tag" );
187 std::vector< int > masks( sizeMasks );
188 #ifdef MOAB_HAVE_PNETCDF
190 std::vector< int > requests( nb_reads * factorRequests );
191 std::vector< int > statuss( nb_reads * factorRequests );
194 size_t indexInArray = 0;
195 size_t indexInMaskArray = 0;
206 #ifdef MOAB_HAVE_PNETCDF
207 success = NCFUNCREQG( _vara_double )(
_fileId, xvId, read_starts, read_counts, &( xv[indexInArray] ),
208 &requests[idxReq++] );
210 success =
NCFUNCAG( _vara_double )(
_fileId, xvId, read_starts, read_counts, &( xv[indexInArray] ) );
212 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_corner_lon data in a loop" );
215 #ifdef MOAB_HAVE_PNETCDF
216 success = NCFUNCREQG( _vara_double )(
_fileId, yvId, read_starts, read_counts, &( yv[indexInArray] ),
217 &requests[idxReq++] );
219 success =
NCFUNCAG( _vara_double )(
_fileId, yvId, read_starts, read_counts, &( yv[indexInArray] ) );
221 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_corner_lat data in a loop" );
230 #ifdef MOAB_HAVE_PNETCDF
231 success = NCFUNCREQG( _vara_int )(
_fileId, gmId, &read_st, &read_ct, &( masks[indexInMaskArray] ),
232 &requests[idxReq++] );
234 success =
NCFUNCAG( _vara_int )(
_fileId, gmId, &read_st, &read_ct, &( masks[indexInMaskArray] ) );
236 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on mask read " );
237 indexInMaskArray += endh - starth + 1;
241 #ifdef MOAB_HAVE_PNETCDF
243 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
244 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
250 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_dims", &gdId );
251 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_dims" );
254 std::vector< int > vecDimSizes( 3, 0 );
262 vecDimSizes[0] = (
grid_rank == 2 ? 1 : 0 );
276 #ifdef MOAB_HAVE_PNETCDF
277 std::vector< int > requeststatus( 2 );
278 success = NCFUNCREQG( _vara_int )(
_fileId, gdId, read_starts, read_counts, vecDimSizes.data() + 1,
280 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_dims data" );
283 success =
NCFUNC( wait_all )(
_fileId, 1, &requeststatus[0], &requeststatus[1] );
284 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
286 success =
NCFUNCAG( _vara_int )(
_fileId, gdId, read_starts, read_counts, vecDimSizes.data() + 1 );
287 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_dims data" );
297 std::map< Node3D, EntityHandle > vertex_map;
315 double cosphi = cos(
pideg * y );
316 double zmult = sin(
pideg * y );
317 double xmult = cosphi * cos( x *
pideg );
318 double ymult = cosphi * sin( x *
pideg );
319 Node3D pt( xmult, ymult, zmult );
323 int nLocalVertices = (int)vertex_map.size();
324 std::vector< double* > arrays;
327 "Failed to create local vertices" );
329 vtx_handle = start_vertex;
332 double *x = arrays[0], *y = arrays[1], *z = arrays[2];
333 for(
auto i = vertex_map.begin(); i != vertex_map.end(); ++i )
335 i->second = vtx_handle;
337 *x = i->first.coords[0];
339 *y = i->first.coords[1];
341 *z = i->first.coords[2];
359 "Failed to create local cells" );
366 for(
int k = 0; k < nv; k++ )
368 int index_v_arr = nv * elem_index + k;
371 double x = xv[index_v_arr];
372 double y = yv[index_v_arr];
373 double cosphi = cos(
pideg * y );
374 double zmult = sin(
pideg * y );
375 double xmult = cosphi * cos( x *
pideg );
376 double ymult = cosphi * sin( x *
pideg );
377 Node3D pt( xmult, ymult, zmult );
378 conn_arr[elem_index * nv + k] = vertex_map[pt];
394 int localMask = masks[elem_index];
402 std::vector< Tag > tagList;
403 tagList.push_back( mGlobalIdTag );
404 if( gmId >= 0 ) tagList.push_back( maskTag );
406 "Failed to remove duplicate vertices" );
425 MB_CHK_ERR(
mb->get_connectivity( eh, conn, num_nodes ) );
438 "Failed to merge vertices in parallel" );
443 Range edges, vertices;
468 #ifdef MOAB_HAVE_ZOLTAN
473 int success =
NCFUNC( inq_varid )(
_fileId,
"grid_center_lon", &xCellVarId );
474 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_center_lon" );
478 success =
NCFUNCAG( _vara_double )(
_fileId, xCellVarId, &read_start, &read_count, &xc[0] );
479 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_center_lat data" );
483 success =
NCFUNC( inq_varid )(
_fileId,
"grid_center_lat", &yCellVarId );
484 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of grid_center_lat" );
486 success =
NCFUNCAG( _vara_double )(
_fileId, yCellVarId, &read_start, &read_count, &yc[0] );
487 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read grid_center_lon data" );
504 cosphi = cos(
pideg * y );
505 zCell[i] = sin(
pideg * y );
506 xCell[i] = cosphi * cos( x *
pideg );
507 yCell[i] = cosphi * sin( x *
pideg );
510 "Error in Zoltan partitioning" );