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;
52 std::vector< std::string >::iterator vit;
55 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"maxNodePElement" ) ) != dimNames.end() )
57 idx = vit - dimNames.begin();
67 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"elementCount" ) ) != dimNames.end() )
68 idx = vit - dimNames.begin();
71 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'elementCount' dimension" );
77 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"maxNodePElement" ) ) != dimNames.end() )
78 idx = vit - dimNames.begin();
81 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'maxNodePElement' dimension" );
88 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nodeCount" ) ) != dimNames.end() )
89 idx = vit - dimNames.begin();
92 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nodeCount' dimension" );
98 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"coordDim" ) ) != dimNames.end() )
99 idx = vit - dimNames.begin();
102 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'coordDim' dimension" );
112 success =
NCFUNC( inq_varid )(
_fileId,
"nodeCoords", &nodeCoordsId );
113 if( success )
MB_CHK_SET_ERR( MB_FAILURE,
"Trouble getting nodeCoords" );
115 auto vmit = varInfo.find(
"nodeCoords" );
116 if( varInfo.end() == vmit )
117 MB_SET_ERR( MB_FAILURE,
"Couldn't find variable "
120 auto attIt = glData.
varAtts.find(
"units" );
121 if( attIt != glData.
varAtts.end() )
123 unsigned int sz = attIt->second.attLen;
124 std::string att_data;
125 att_data.resize( sz + 1 );
126 att_data[sz] =
'\000';
128 NCFUNC( get_att_text )(
_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), &att_data[0] );
129 if( 0 == success && att_data.find(
"radians" ) != std::string::npos )
degrees =
false;
159 int shifted_rank = rank;
161 if( trivialPartitionShift > 0 ) shifted_rank = ( rank + trivialPartitionShift ) % procs;
170 int iextra =
nCells % procs;
174 start_cell_idx += std::min( shifted_rank, iextra );
179 ErrorCode rval = redistribute_local_cells( start_cell_idx, myPcomm );
MB_CHK_SET_ERR( rval,
"Failed to redistribute local cells after trivial partition" );
194 int nEdgesOnCellVarId;
195 int success =
NCFUNC( inq_varid )(
_fileId,
"numElementConn", &nEdgesOnCellVarId );
196 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of numElementConn" );
197 std::vector< int > num_edges_on_local_cells(
nLocalCells );
199 #ifdef MOAB_HAVE_PNETCDF
201 std::vector< int > requests( nb_reads );
202 std::vector< int > statuss( nb_reads );
205 size_t indexInArray = 0;
215 #ifdef MOAB_HAVE_PNETCDF
216 success = NCFUNCREQG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count,
217 &( num_edges_on_local_cells[indexInArray] ), &requests[idxReq++] );
219 success =
NCFUNCAG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count,
220 &( num_edges_on_local_cells[indexInArray] ) );
222 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data in a loop" );
225 indexInArray += ( endh - starth + 1 );
228 #ifdef MOAB_HAVE_PNETCDF
230 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
231 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
235 int verticesOnCellVarId;
236 success =
NCFUNC( inq_varid )(
_fileId,
"elementConn", &verticesOnCellVarId );
237 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of elementConn" );
239 #ifdef MOAB_HAVE_PNETCDF
253 #ifdef MOAB_HAVE_PNETCDF
254 success = NCFUNCREQG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
255 &( vertices_on_local_cells[indexInArray] ), &requests[idxReq++] );
257 success =
NCFUNCAG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
258 &( vertices_on_local_cells[indexInArray] ) );
260 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data in a loop" );
266 #ifdef MOAB_HAVE_PNETCDF
268 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
269 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
275 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
277 int num_edges = num_edges_on_local_cells[local_cell_idx];
279 int last_vert_idx = vertices_on_local_cells[idx_in_local_vert_arr + num_edges - 1];
281 vertices_on_local_cells[idx_in_local_vert_arr + i] = last_vert_idx;
289 if( noMixedElements )
295 rval =
create_local_cells( vertices_on_local_cells, num_edges_on_local_cells, start_vertex, faces );
MB_CHK_SET_ERR( rval,
"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];
484 dbgOut.tprintf( 1,
"After Zoltan partitioning, localGidCells.psize() = %d\n", (
int)
localGidCells.
psize() );
511 std::vector< int > vertices_on_local_cells_sorted( vertices_on_local_cells );
512 std::sort( vertices_on_local_cells_sorted.begin(), vertices_on_local_cells_sorted.end() );
513 std::copy( vertices_on_local_cells_sorted.rbegin(), vertices_on_local_cells_sorted.rend(),
521 std::vector< double* > arrays;
532 rval = mbImpl->
tag_iterate( mGlobalIdTag, local_verts_range.
begin(), local_verts_range.
end(), count, data );
MB_CHK_SET_ERR( rval,
"Failed to iterate global id tag on local vertices" );
534 int* gid_data = (
int*)data;
540 rval = mbImpl->
tag_iterate( *mpFileIdTag, local_verts_range.
begin(), local_verts_range.
end(), count, data );
MB_CHK_SET_ERR( rval,
"Failed to iterate file id tag on local vertices" );
542 int bytes_per_tag = 4;
544 if( 4 == bytes_per_tag )
546 gid_data = (
int*)data;
549 else if( 8 == bytes_per_tag )
551 long* handle_tag_data = (
long*)data;
556 #ifdef MOAB_HAVE_PNETCDF
558 std::vector< int > requests( nb_reads );
559 std::vector< int > statuss( nb_reads );
566 int success =
NCFUNC( inq_varid )(
_fileId,
"nodeCoords", &nodeCoordVarId );
567 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of nodeCoords" );
568 size_t indexInArray = 0;
579 #ifdef MOAB_HAVE_PNETCDF
580 success = NCFUNCREQG( _vara_double )(
_fileId, nodeCoordVarId, read_starts, read_counts, &coords[indexInArray],
581 &requests[idxReq++] );
583 success =
NCFUNCAG( _vara_double )(
_fileId, nodeCoordVarId, read_starts, read_counts, &coords[indexInArray] );
585 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nodeCoords data in a loop" );
588 indexInArray += ( endh - starth + 1 ) *
coordDim;
591 #ifdef MOAB_HAVE_PNETCDF
593 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
594 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
605 double lon = coords[i * 2] * factor;
606 double lat = coords[i * 2 + 1] * factor;
607 double cosphi = cos( lat );
608 arrays[2][i] = sin( lat );
609 arrays[0][i] = cosphi * cos( lon );
610 arrays[1][i] = cosphi * sin( lon );
618 const std::vector< int >& num_edges_on_local_cells,
630 int num_edges = num_edges_on_local_cells[i];
634 std::vector< int > num_edges_on_cell_groups;
637 if( local_cells_with_n_edges[i].
size() > 0 ) num_edges_on_cell_groups.push_back( i );
639 int numCellGroups = (int)num_edges_on_cell_groups.size();
641 for(
int i = 0; i < numCellGroups; i++ )
643 int num_edges_per_cell = num_edges_on_cell_groups[i];
644 int num_group_cells = (int)local_cells_with_n_edges[num_edges_per_cell].
size();
646 EntityType typeEl =
MBTRI;
647 if( num_edges_per_cell == 4 ) typeEl =
MBQUAD;
648 if( num_edges_per_cell > 4 ) typeEl =
MBPOLYGON;
653 conn_arr_local_cells_with_n_edges[num_edges_per_cell],
654 num_group_cells );
MB_CHK_SET_ERR( rval,
"Failed to create local cells" );
655 faces.
insert( start_element, start_element + num_group_cells - 1 );
658 Range local_cells_range( start_element, start_element + num_group_cells - 1 );
664 rval = mbImpl->
tag_iterate( mGlobalIdTag, local_cells_range.
begin(), local_cells_range.
end(), count, data );
MB_CHK_SET_ERR( rval,
"Failed to iterate global id tag on local cells" );
665 assert( count == num_group_cells );
666 int* gid_data = (
int*)data;
667 std::copy( local_cells_with_n_edges[num_edges_per_cell].begin(),
668 local_cells_with_n_edges[num_edges_per_cell].end(), gid_data );
671 for(
int j = 0; j < num_group_cells; j++ )
674 local_cells_with_n_edges[num_edges_per_cell][j];
676 assert( local_cell_idx != -1 );
678 for(
int k = 0; k < num_edges_per_cell; k++ )
683 assert( local_vert_idx != -1 );
684 conn_arr_local_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] =
685 start_vertex + local_vert_idx;
714 rval = mbImpl->
tag_iterate( mGlobalIdTag, local_cells_range.
begin(), local_cells_range.
end(), count, data );
MB_CHK_SET_ERR( rval,
"Failed to iterate global id tag on local cells" );
716 int* gid_data = (
int*)data;
722 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
729 assert( local_vert_idx != -1 );
730 conn_arr_local_cells[local_cell_idx *
maxEdgesPerCell + i] = start_vertex + local_vert_idx;