12 #ifdef MOAB_HAVE_ZOLTAN
22 const double pideg = acos( -1.0 ) / 180.0;
26 centerCoordsId( -1 ), degrees( true )
32 std::vector< std::string >& dimNames = readNC->
dimNames;
33 if( ( std::find( dimNames.begin(), dimNames.end(), std::string(
"nodeCount" ) ) != dimNames.end() ) &&
34 ( std::find( dimNames.begin(), dimNames.end(), std::string(
"elementCount" ) ) != dimNames.end() ) &&
35 ( std::find( dimNames.begin(), dimNames.end(), std::string(
"maxNodePElement" ) ) != dimNames.end() ) &&
36 ( std::find( dimNames.begin(), dimNames.end(), std::string(
"coordDim" ) ) != dimNames.end() ) )
48 std::map< std::string, ReadNC::VarData >& varInfo =
_readNC->
varInfo;
51 std::vector< std::string >::iterator vit;
54 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"maxNodePElement" ) ) != dimNames.end() )
56 idx = vit - dimNames.begin();
66 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"elementCount" ) ) != dimNames.end() )
67 idx = vit - dimNames.begin();
70 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'elementCount' dimension" );
76 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"maxNodePElement" ) ) != dimNames.end() )
77 idx = vit - dimNames.begin();
80 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'maxNodePElement' dimension" );
87 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nodeCount" ) ) != dimNames.end() )
88 idx = vit - dimNames.begin();
91 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nodeCount' dimension" );
97 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"coordDim" ) ) != dimNames.end() )
98 idx = vit - dimNames.begin();
101 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'coordDim' dimension" );
111 success =
NCFUNC( inq_varid )(
_fileId,
"nodeCoords", &nodeCoordsId );
112 if( success )
MB_CHK_SET_ERR( MB_FAILURE,
"Trouble getting nodeCoords" );
114 auto vmit = varInfo.find(
"nodeCoords" );
115 if( varInfo.end() == vmit )
MB_SET_ERR( MB_FAILURE,
"Couldn't find variable " <<
"nodeCoords" );
117 auto attIt = glData.
varAtts.find(
"units" );
118 if( attIt != glData.
varAtts.end() )
120 unsigned int sz = attIt->second.attLen;
121 std::string att_data;
122 att_data.resize( sz + 1 );
123 att_data[sz] =
'\000';
125 NCFUNC( get_att_text )(
_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), &att_data[0] );
126 if( 0 == success && att_data.find(
"radians" ) != std::string::npos )
degrees =
false;
156 int shifted_rank = rank;
158 if( trivialPartitionShift > 0 ) shifted_rank = ( rank + trivialPartitionShift ) % procs;
167 int iextra =
nCells % procs;
171 start_cell_idx += std::min( shifted_rank, iextra );
176 MB_CHK_SET_ERR( redistribute_local_cells( start_cell_idx, myPcomm ),
177 "Failed to redistribute local cells after trivial partition" );
192 int nEdgesOnCellVarId;
193 int success =
NCFUNC( inq_varid )(
_fileId,
"numElementConn", &nEdgesOnCellVarId );
194 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of numElementConn" );
195 std::vector< int > num_edges_on_local_cells(
nLocalCells );
197 #ifdef MOAB_HAVE_PNETCDF
199 std::vector< int > requests( nb_reads );
200 std::vector< int > statuss( nb_reads );
203 size_t indexInArray = 0;
213 #ifdef MOAB_HAVE_PNETCDF
214 success = NCFUNCREQG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count,
215 &( num_edges_on_local_cells[indexInArray] ), &requests[idxReq++] );
217 success =
NCFUNCAG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count,
218 &( num_edges_on_local_cells[indexInArray] ) );
220 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data in a loop" );
223 indexInArray += ( endh - starth + 1 );
226 #ifdef MOAB_HAVE_PNETCDF
228 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
229 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
233 int verticesOnCellVarId;
234 success =
NCFUNC( inq_varid )(
_fileId,
"elementConn", &verticesOnCellVarId );
235 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of elementConn" );
237 #ifdef MOAB_HAVE_PNETCDF
251 #ifdef MOAB_HAVE_PNETCDF
252 success = NCFUNCREQG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
253 &( vertices_on_local_cells[indexInArray] ), &requests[idxReq++] );
255 success =
NCFUNCAG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
256 &( vertices_on_local_cells[indexInArray] ) );
258 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data in a loop" );
264 #ifdef MOAB_HAVE_PNETCDF
266 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
267 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
273 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
275 int num_edges = num_edges_on_local_cells[local_cell_idx];
277 int last_vert_idx = vertices_on_local_cells[idx_in_local_vert_arr + num_edges - 1];
279 vertices_on_local_cells[idx_in_local_vert_arr + i] = last_vert_idx;
285 "Failed to create local vertices for MPAS mesh" );
288 if( noMixedElements )
291 "Failed to create padded local cells for MPAS mesh" );
296 "Failed to create local cells for MPAS mesh" );
309 #ifdef MOAB_HAVE_ZOLTAN
313 std::vector< double > xverts, yverts, zverts;
327 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on reading center coordinates" );
334 double lon = coords[i * 2] * factor;
335 double lat = coords[i * 2 + 1] * factor;
336 double cosphi = cos( lat );
337 zverts[i] = sin( lat );
338 xverts[i] = cosphi * cos( lon );
339 yverts[i] = cosphi * sin( lon );
347 int verticesOnCellVarId;
348 int success =
NCFUNC( inq_varid )(
_fileId,
"elementConn", &verticesOnCellVarId );
349 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of elementConn" );
356 success =
NCFUNCAG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
357 &( vertices_on_local_cells[0] ) );
358 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on reading elementConn variable" );
359 std::vector< int > num_edges_on_local_cells(
nLocalCells );
361 NCDF_SIZE read_start = start_cell_idx - 1;
364 int nEdgesOnCellVarId;
365 success =
NCFUNC( inq_varid )(
_fileId,
"numElementConn", &nEdgesOnCellVarId );
366 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of numElementConn" );
367 success =
NCFUNCAG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count,
368 &( num_edges_on_local_cells[0] ) );
369 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get numElementConn" );
376 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
378 int num_edges = num_edges_on_local_cells[local_cell_idx];
380 int last_vert_idx = vertices_on_local_cells[idx_in_local_vert_arr + num_edges - 1];
382 vertices_on_local_cells[idx_in_local_vert_arr + i] = last_vert_idx;
385 std::vector< int > vertices_on_local_cells_sorted( vertices_on_local_cells );
386 std::sort( vertices_on_local_cells_sorted.begin(), vertices_on_local_cells_sorted.end() );
387 std::copy( vertices_on_local_cells_sorted.rbegin(), vertices_on_local_cells_sorted.rend(),
394 success =
NCFUNC( inq_varid )(
_fileId,
"nodeCoords", &nodeCoordVarId );
395 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of nodeCoords" );
396 #ifdef MOAB_HAVE_PNETCDF
398 std::vector< int > requests( nb_reads );
399 std::vector< int > statuss( nb_reads );
402 size_t indexInArray = 0;
413 #ifdef MOAB_HAVE_PNETCDF
414 success = NCFUNCREQG( _vara_double )(
_fileId, nodeCoordVarId, read_starts, read_counts,
415 &coords[indexInArray], &requests[idxReq++] );
417 success =
NCFUNCAG( _vara_double )(
_fileId, nodeCoordVarId, read_starts, read_counts,
418 &coords[indexInArray] );
420 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nodeCoords data in a loop" );
423 indexInArray += ( endh - starth + 1 ) *
coordDim;
426 #ifdef MOAB_HAVE_PNETCDF
428 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
429 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
441 double lon = coords[i * 2] * factor;
442 double lat = coords[i * 2 + 1] * factor;
443 double cosphi = cos( lat );
444 coords3d[3 * i + 2] = sin( lat );
445 coords3d[3 * i] = cosphi * cos( lon );
446 coords3d[3 * i + 1] = cosphi * sin( lon );
453 int nv = num_edges_on_local_cells[i];
454 double x = 0., y = 0., z = 0.;
455 for(
int j = 0; j < nv; j++ )
460 x += coords3d[3 *
index];
461 y += coords3d[3 *
index + 1];
462 z += coords3d[3 *
index + 2];
482 "Error in Zoltan partitioning" );
485 dbgOut.tprintf( 1,
"After Zoltan partitioning, localGidCells.psize() = %d\n", (
int)
localGidCells.
psize() );
514 std::vector< int > vertices_on_local_cells_sorted( vertices_on_local_cells );
515 std::sort( vertices_on_local_cells_sorted.begin(), vertices_on_local_cells_sorted.end() );
516 std::copy( vertices_on_local_cells_sorted.rbegin(), vertices_on_local_cells_sorted.rend(),
524 std::vector< double* > arrays;
527 "Failed to create local vertices" );
532 "Failed to add local vertices to current file set" );
539 "Failed to iterate global id tag on local vertices" );
541 int* gid_data = (
int*)data;
549 "Failed to iterate file id tag on local vertices" );
551 int bytes_per_tag = 4;
553 "Can't get number of bytes for file id tag" );
554 if( 4 == bytes_per_tag )
556 gid_data = (
int*)data;
559 else if( 8 == bytes_per_tag )
561 long* handle_tag_data = (
long*)data;
566 #ifdef MOAB_HAVE_PNETCDF
568 std::vector< int > requests( nb_reads );
569 std::vector< int > statuss( nb_reads );
576 int success =
NCFUNC( inq_varid )(
_fileId,
"nodeCoords", &nodeCoordVarId );
577 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of nodeCoords" );
578 size_t indexInArray = 0;
589 #ifdef MOAB_HAVE_PNETCDF
590 success = NCFUNCREQG( _vara_double )(
_fileId, nodeCoordVarId, read_starts, read_counts, &coords[indexInArray],
591 &requests[idxReq++] );
593 success =
NCFUNCAG( _vara_double )(
_fileId, nodeCoordVarId, read_starts, read_counts, &coords[indexInArray] );
595 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nodeCoords data in a loop" );
598 indexInArray += ( endh - starth + 1 ) *
coordDim;
601 #ifdef MOAB_HAVE_PNETCDF
603 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
604 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
615 double lon = coords[i * 2] * factor;
616 double lat = coords[i * 2 + 1] * factor;
617 double cosphi = cos( lat );
618 arrays[2][i] = sin( lat );
619 arrays[0][i] = cosphi * cos( lon );
620 arrays[1][i] = cosphi * sin( lon );
628 const std::vector< int >& num_edges_on_local_cells,
640 int num_edges = num_edges_on_local_cells[i];
644 std::vector< int > num_edges_on_cell_groups;
647 if( local_cells_with_n_edges[i].size() > 0 ) num_edges_on_cell_groups.push_back( i );
649 int numCellGroups = (int)num_edges_on_cell_groups.size();
651 for(
int i = 0; i < numCellGroups; i++ )
653 int num_edges_per_cell = num_edges_on_cell_groups[i];
654 int num_group_cells = (int)local_cells_with_n_edges[num_edges_per_cell].size();
656 EntityType typeEl =
MBTRI;
657 if( num_edges_per_cell == 4 ) typeEl =
MBQUAD;
658 if( num_edges_per_cell > 4 ) typeEl =
MBPOLYGON;
662 num_group_cells, num_edges_per_cell, typeEl, 0, start_element,
663 conn_arr_local_cells_with_n_edges[num_edges_per_cell], num_group_cells ),
664 "Failed to create local cells" );
665 faces.
insert( start_element, start_element + num_group_cells - 1 );
668 Range local_cells_range( start_element, start_element + num_group_cells - 1 );
670 "Failed to add local cells to current file set" );
677 "Failed to iterate global id tag on local cells" );
678 assert( count == num_group_cells );
679 int* gid_data = (
int*)data;
680 std::copy( local_cells_with_n_edges[num_edges_per_cell].begin(),
681 local_cells_with_n_edges[num_edges_per_cell].end(), gid_data );
684 for(
int j = 0; j < num_group_cells; j++ )
687 local_cells_with_n_edges[num_edges_per_cell][j];
689 assert( local_cell_idx != -1 );
691 for(
int k = 0; k < num_edges_per_cell; k++ )
696 assert( local_vert_idx != -1 );
697 conn_arr_local_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] =
698 start_vertex + local_vert_idx;
717 start_element, conn_arr_local_cells,
nLocalCells ),
718 "Failed to create local cells" );
724 "Failed to add local cells to current file set" );
731 "Failed to iterate global id tag on local cells" );
733 int* gid_data = (
int*)data;
739 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
746 assert( local_vert_idx != -1 );
747 conn_arr_local_cells[local_cell_idx *
maxEdgesPerCell + i] = start_vertex + local_vert_idx;