7 #ifdef MOAB_HAVE_ZOLTAN
20 createGatherSet( false )
70 std::vector< std::string >& dimNames = readNC->
dimNames;
73 if( std::find( dimNames.begin(), dimNames.end(), std::string(
"vertexDegree" ) ) != dimNames.end() )
return true;
82 std::map< std::string, ReadNC::VarData >& varInfo =
_readNC->
varInfo;
86 std::vector< std::string >::iterator vit;
89 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"maxEdges" ) ) != dimNames.end() )
91 idx = vit - dimNames.begin();
102 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"Time" ) ) != dimNames.end() )
103 idx = vit - dimNames.begin();
104 else if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"time" ) ) != dimNames.end() )
105 idx = vit - dimNames.begin();
119 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nCells" ) ) != dimNames.end() )
120 idx = vit - dimNames.begin();
123 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nCells' dimension" );
129 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nEdges" ) ) != dimNames.end() )
130 idx = vit - dimNames.begin();
133 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nEdges' dimension" );
140 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nVertices" ) ) != dimNames.end() )
141 idx = vit - dimNames.begin();
144 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nVertices' dimension" );
150 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nVertLevels" ) ) != dimNames.end() )
151 idx = vit - dimNames.begin();
154 std::cerr <<
"Warning: dimension nVertLevels not found in header.\nThe file may contain "
162 std::vector< unsigned int > opt_lev_dims;
165 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nVertLevelsP1" ) ) != dimNames.end() )
167 idx = vit - dimNames.begin();
168 opt_lev_dims.push_back( idx );
172 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nVertLevelsP2" ) ) != dimNames.end() )
174 idx = vit - dimNames.begin();
175 opt_lev_dims.push_back( idx );
179 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nSoilLevels" ) ) != dimNames.end() )
181 idx = vit - dimNames.begin();
182 opt_lev_dims.push_back( idx );
185 std::map< std::string, ReadNC::VarData >::iterator vmit;
191 if( ( vmit = varInfo.find(
"xtime" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
200 tVals.push_back( (
double)t );
205 for( vmit = varInfo.begin(); vmit != varInfo.end(); ++vmit )
227 for(
unsigned int i = 0; i < opt_lev_dims.size(); i++ )
231 vd.
numLev = dimLens[opt_lev_dims[i]];
266 Tag numCellGroupsTag;
277 if( !local_verts.
empty() )
279 std::vector< int > gids( local_verts.
size() );
282 rval = mbImpl->
tag_get_data( mGlobalIdTag, local_verts, &gids[0] );
MB_CHK_SET_ERR( rval,
"Trouble getting local gid values of vertices" );
296 if( !local_edges.
empty() )
298 std::vector< int > gids( local_edges.
size() );
301 rval = mbImpl->
tag_get_data( mGlobalIdTag, local_edges, &gids[0] );
MB_CHK_SET_ERR( rval,
"Trouble getting local gid values of edges" );
315 if( !local_cells.
empty() )
317 std::vector< int > gids( local_cells.
size() );
320 rval = mbImpl->
tag_get_data( mGlobalIdTag, local_cells, &gids[0] );
MB_CHK_SET_ERR( rval,
"Trouble getting local gid values of cells" );
331 for( rit = local_cells.
begin(), i = 0; rit != local_cells.
end(); ++rit, i++ )
366 int shifted_rank = rank;
368 if( trivialPartitionShift > 0 ) shifted_rank = ( rank + trivialPartitionShift ) % procs;
377 int iextra =
nCells % procs;
381 start_cell_idx += std::min( shifted_rank, iextra );
386 ErrorCode rval = redistribute_local_cells( start_cell_idx, myPcomm );
MB_CHK_SET_ERR( rval,
"Failed to redistribute local cells after trivial partition" );
401 int nEdgesOnCellVarId;
402 int success =
NCFUNC( inq_varid )(
_fileId,
"nEdgesOnCell", &nEdgesOnCellVarId );
403 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of nEdgesOnCell" );
404 std::vector< int > num_edges_on_local_cells(
nLocalCells );
405 #ifdef MOAB_HAVE_PNETCDF
407 std::vector< int > requests( nb_reads );
408 std::vector< int > statuss( nb_reads );
411 size_t indexInArray = 0;
421 #ifdef MOAB_HAVE_PNETCDF
422 success = NCFUNCREQG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count,
423 &( num_edges_on_local_cells[indexInArray] ), &requests[idxReq++] );
425 success =
NCFUNCAG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count,
426 &( num_edges_on_local_cells[indexInArray] ) );
428 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data in a loop" );
431 indexInArray += ( endh - starth + 1 );
434 #ifdef MOAB_HAVE_PNETCDF
436 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
437 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
441 int local_max_edges_per_cell =
442 *( std::max_element( num_edges_on_local_cells.begin(), num_edges_on_local_cells.end() ) );
449 int global_max_edges_per_cell;
451 MPI_Allreduce( &local_max_edges_per_cell, &global_max_edges_per_cell, 1, MPI_INT, MPI_MAX,
453 assert( local_max_edges_per_cell <= global_max_edges_per_cell );
455 if( 0 == rank ) dbgOut.
tprintf( 1,
" global_max_edges_per_cell = %d\n", global_max_edges_per_cell );
460 int verticesOnCellVarId;
461 success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnCell", &verticesOnCellVarId );
462 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnCell" );
464 #ifdef MOAB_HAVE_PNETCDF
478 #ifdef MOAB_HAVE_PNETCDF
479 success = NCFUNCREQG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
480 &( vertices_on_local_cells[indexInArray] ), &requests[idxReq++] );
482 success =
NCFUNCAG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
483 &( vertices_on_local_cells[indexInArray] ) );
485 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data in a loop" );
491 #ifdef MOAB_HAVE_PNETCDF
493 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
494 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
500 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
502 int num_edges = num_edges_on_local_cells[local_cell_idx];
504 int last_vert_idx = vertices_on_local_cells[idx_in_local_vert_arr + num_edges - 1];
506 vertices_on_local_cells[idx_in_local_vert_arr + i] = last_vert_idx;
520 if( noMixedElements )
526 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" );
530 Tag numCellGroupsTag = 0;
551 if( noMixedElements )
565 std::vector< int >& tstep_nums )
577 assert(
"Should only have a single vertex subrange, since they were read in one shot" && verts.
psize() == 1 );
601 for(
unsigned int i = 0; i < vdatas.size(); i++ )
608 assert( 3 == vdatas[i].varDims.size() || 2 == vdatas[i].varDims.size() );
611 assert(
tDim == vdatas[i].varDims[0] );
614 vdatas[i].readStarts.resize( 3 );
615 vdatas[i].readCounts.resize( 3 );
618 vdatas[i].readStarts[0] = 0;
619 vdatas[i].readCounts[0] = 1;
622 switch( vdatas[i].entLoc )
649 MB_SET_ERR( MB_FAILURE,
"Unexpected entity location type for variable " << vdatas[i].varName );
654 if( vdatas[i].numLev < 1 ) vdatas[i].numLev = 1;
655 vdatas[i].readStarts[2] = 0;
656 vdatas[i].readCounts[2] = vdatas[i].numLev;
660 for( std::size_t idx = 0; idx != 3; idx++ )
661 vdatas[i].sz *= vdatas[i].readCounts[idx];
663 for(
unsigned int t = 0; t < tstep_nums.size(); t++ )
665 dbgOut.
tprintf( 2,
"Reading variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t] );
667 if( tstep_nums[t] >= dimLens[
tDim] )
673 if( !vdatas[i].varTags[t] )
675 rval =
get_tag_to_nonset( vdatas[i], tstep_nums[t], vdatas[i].varTags[t], vdatas[i].numLev );
MB_CHK_SET_ERR( rval,
"Trouble getting tag for variable " << vdatas[i].varName );
683 vdatas[i].varDatas[t] = NULL;
687 assert( 1 == range->
psize() );
690 rval = mbImpl->
tag_iterate( vdatas[i].varTags[t], range->
begin(), range->
end(), count, data );
MB_CHK_SET_ERR( rval,
"Failed to iterate tag for variable " << vdatas[i].varName );
691 assert( (
unsigned)count == range->
size() );
692 vdatas[i].varDatas[t] = data;
700 #ifdef MOAB_HAVE_PNETCDF
701 ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async( std::vector< ReadNC::VarData >& vdatas,
702 std::vector< int >& tstep_nums )
712 Range* pLocalGid = NULL;
714 for(
unsigned int i = 0; i < vdatas.size(); i++ )
719 switch( vdatas[i].entLoc )
731 MB_SET_ERR( MB_FAILURE,
"Unexpected entity location type for variable " << vdatas[i].varName );
734 std::size_t sz = vdatas[i].sz;
736 for(
unsigned int t = 0; t < tstep_nums.size(); t++ )
740 size_t nb_reads = pLocalGid->
psize();
741 std::vector< int > requests( nb_reads ), statuss( nb_reads );
745 vdatas[i].readStarts[0] = tstep_nums[t];
747 switch( vdatas[i].varDataType )
752 std::vector< double > tmpdoubledata( sz );
759 size_t indexInDoubleArray = 0;
761 for( Range::pair_iterator pair_iter = pLocalGid->
pair_begin(); pair_iter != pLocalGid->
pair_end();
766 vdatas[i].readStarts[1] = (
NCDF_SIZE)( starth - 1 );
767 vdatas[i].readCounts[1] = (
NCDF_SIZE)( endh - starth + 1 );
772 NCFUNCREQG( _vara_double )(
_fileId, vdatas[i].varId, &( vdatas[i].readStarts[0] ),
773 &( vdatas[i].readCounts[0] ),
774 &( tmpdoubledata[indexInDoubleArray] ), &requests[idxReq++] );
777 "Failed to read double data in a loop for variable " << vdatas[i].varName );
780 indexInDoubleArray += ( endh - starth + 1 ) * 1 * vdatas[i].numLev;
782 assert( ic == pLocalGid->
psize() );
784 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
785 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
799 for(
int j = 0; j < count; j++ )
801 int global_cell_idx =
805 assert( local_cell_idx != -1 );
806 for(
int level = 0; level < vdatas[i].numLev; level++ )
807 ( (
double*)ptr )[j * vdatas[i].numLev + level] =
808 tmpdoubledata[local_cell_idx * vdatas[i].numLev + level];
816 void* data = vdatas[i].varDatas[t];
817 for( std::size_t idx = 0; idx != tmpdoubledata.size(); idx++ )
818 ( (
double*)data )[idx] = tmpdoubledata[idx];
824 MB_SET_ERR( MB_FAILURE,
"Unexpected data type for variable " << vdatas[i].varName );
832 dbgOut.
printf( 1,
"Read variables: %s", vdatas.begin()->varName.c_str() );
833 for(
unsigned int i = 1; i < vdatas.size(); i++ )
834 dbgOut.
printf( 1,
", %s ", vdatas[i].varName.c_str() );
842 std::vector< int >& tstep_nums )
852 Range* pLocalGid = NULL;
854 for(
unsigned int i = 0; i < vdatas.size(); i++ )
859 switch( vdatas[i].entLoc )
871 MB_SET_ERR( MB_FAILURE,
"Unexpected entity location type for variable " << vdatas[i].varName );
874 std::size_t sz = vdatas[i].sz;
876 for(
unsigned int t = 0; t < tstep_nums.size(); t++ )
879 vdatas[i].readStarts[0] = tstep_nums[t];
881 switch( vdatas[i].varDataType )
886 std::vector< double > tmpdoubledata( sz );
893 size_t indexInDoubleArray = 0;
900 vdatas[i].readStarts[1] = (
NCDF_SIZE)( starth - 1 );
901 vdatas[i].readCounts[1] = (
NCDF_SIZE)( endh - starth + 1 );
903 success =
NCFUNCAG( _vara_double )(
_fileId, vdatas[i].varId, &( vdatas[i].readStarts[0] ),
904 &( vdatas[i].readCounts[0] ),
905 &( tmpdoubledata[indexInDoubleArray] ) );
908 "Failed to read double data in a loop for variable " << vdatas[i].varName );
911 indexInDoubleArray += ( endh - starth + 1 ) * 1 * vdatas[i].numLev;
913 assert( ic == pLocalGid->
psize() );
927 for(
int j = 0; j < count; j++ )
929 int global_cell_idx =
933 assert( local_cell_idx != -1 );
934 for(
int level = 0; level < vdatas[i].numLev; level++ )
935 ( (
double*)ptr )[j * vdatas[i].numLev + level] =
936 tmpdoubledata[local_cell_idx * vdatas[i].numLev + level];
944 void* data = vdatas[i].varDatas[t];
945 for( std::size_t idx = 0; idx != tmpdoubledata.size(); idx++ )
946 ( (
double*)data )[idx] = tmpdoubledata[idx];
952 MB_SET_ERR( MB_FAILURE,
"Unexpected data type for variable " << vdatas[i].varName );
960 dbgOut.
printf( 1,
"Read variables: %s", vdatas.begin()->varName.c_str() );
961 for(
unsigned int i = 1; i < vdatas.size(); i++ )
962 dbgOut.
printf( 1,
", %s ", vdatas[i].varName.c_str() );
974 #ifdef MOAB_HAVE_ZOLTAN
979 int success =
NCFUNC( inq_varid )(
_fileId,
"xCell", &xCellVarId );
980 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of xCell" );
984 success =
NCFUNCAG( _vara_double )(
_fileId, xCellVarId, &read_start, &read_count, &xCell[0] );
985 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read xCell data" );
989 success =
NCFUNC( inq_varid )(
_fileId,
"yCell", &yCellVarId );
990 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of yCell" );
992 success =
NCFUNCAG( _vara_double )(
_fileId, yCellVarId, &read_start, &read_count, &yCell[0] );
993 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read yCell data" );
997 success =
NCFUNC( inq_varid )(
_fileId,
"zCell", &zCellVarId );
998 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of zCell" );
1000 success =
NCFUNCAG( _vara_double )(
_fileId, zCellVarId, &read_start, &read_count, &zCell[0] );
1001 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read zCell data" );
1038 std::vector< int > vertices_on_local_cells_sorted( vertices_on_local_cells );
1039 std::sort( vertices_on_local_cells_sorted.begin(), vertices_on_local_cells_sorted.end() );
1040 std::copy( vertices_on_local_cells_sorted.rbegin(), vertices_on_local_cells_sorted.rend(),
1048 std::vector< double* > arrays;
1061 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" );
1063 int* gid_data = (
int*)data;
1069 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" );
1071 int bytes_per_tag = 4;
1073 if( 4 == bytes_per_tag )
1075 gid_data = (
int*)data;
1078 else if( 8 == bytes_per_tag )
1080 long* handle_tag_data = (
long*)data;
1085 #ifdef MOAB_HAVE_PNETCDF
1087 std::vector< int > requests( nb_reads );
1088 std::vector< int > statuss( nb_reads );
1093 double* xptr = arrays[0];
1095 int success =
NCFUNC( inq_varid )(
_fileId,
"xVertex", &xVertexVarId );
1096 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of xVertex" );
1097 size_t indexInArray = 0;
1107 #ifdef MOAB_HAVE_PNETCDF
1108 success = NCFUNCREQG( _vara_double )(
_fileId, xVertexVarId, &read_start, &read_count, &( xptr[indexInArray] ),
1109 &requests[idxReq++] );
1111 success =
NCFUNCAG( _vara_double )(
_fileId, xVertexVarId, &read_start, &read_count, &( xptr[indexInArray] ) );
1113 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read xVertex data in a loop" );
1116 indexInArray += ( endh - starth + 1 );
1119 #ifdef MOAB_HAVE_PNETCDF
1121 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1122 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1126 double* yptr = arrays[1];
1128 success =
NCFUNC( inq_varid )(
_fileId,
"yVertex", &yVertexVarId );
1129 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of yVertex" );
1130 #ifdef MOAB_HAVE_PNETCDF
1143 #ifdef MOAB_HAVE_PNETCDF
1144 success = NCFUNCREQG( _vara_double )(
_fileId, yVertexVarId, &read_start, &read_count, &( yptr[indexInArray] ),
1145 &requests[idxReq++] );
1147 success =
NCFUNCAG( _vara_double )(
_fileId, yVertexVarId, &read_start, &read_count, &( yptr[indexInArray] ) );
1149 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read yVertex data in a loop" );
1152 indexInArray += ( endh - starth + 1 );
1155 #ifdef MOAB_HAVE_PNETCDF
1157 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1158 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1162 double* zptr = arrays[2];
1164 success =
NCFUNC( inq_varid )(
_fileId,
"zVertex", &zVertexVarId );
1165 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of zVertex" );
1166 #ifdef MOAB_HAVE_PNETCDF
1179 #ifdef MOAB_HAVE_PNETCDF
1180 success = NCFUNCREQG( _vara_double )(
_fileId, zVertexVarId, &read_start, &read_count, &( zptr[indexInArray] ),
1181 &requests[idxReq++] );
1183 success =
NCFUNCAG( _vara_double )(
_fileId, zVertexVarId, &read_start, &read_count, &( zptr[indexInArray] ) );
1185 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read zVertex data in a loop" );
1188 indexInArray += ( endh - starth + 1 );
1191 #ifdef MOAB_HAVE_PNETCDF
1193 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1194 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1201 const std::vector< int >& num_edges_on_local_cells )
1208 int edgesOnCellVarId;
1209 int success =
NCFUNC( inq_varid )(
_fileId,
"edgesOnCell", &edgesOnCellVarId );
1210 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of edgesOnCell" );
1213 dbgOut.
tprintf( 1,
" edges_on_local_cells.size() = %d\n", (
int)edges_on_local_cells.size() );
1215 #ifdef MOAB_HAVE_PNETCDF
1217 std::vector< int > requests( nb_reads );
1218 std::vector< int > statuss( nb_reads );
1221 size_t indexInArray = 0;
1232 #ifdef MOAB_HAVE_PNETCDF
1233 success = NCFUNCREQG( _vara_int )(
_fileId, edgesOnCellVarId, read_starts, read_counts,
1234 &( edges_on_local_cells[indexInArray] ), &requests[idxReq++] );
1236 success =
NCFUNCAG( _vara_int )(
_fileId, edgesOnCellVarId, read_starts, read_counts,
1237 &( edges_on_local_cells[indexInArray] ) );
1239 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read edgesOnCell data in a loop" );
1245 #ifdef MOAB_HAVE_PNETCDF
1247 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1248 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1253 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
1255 int num_edges = num_edges_on_local_cells[local_cell_idx];
1257 int last_edge_idx = edges_on_local_cells[idx_in_local_edge_arr + num_edges - 1];
1259 edges_on_local_cells[idx_in_local_edge_arr + i] = last_edge_idx;
1263 std::sort( edges_on_local_cells.begin(), edges_on_local_cells.end() );
1285 rval = mbImpl->
tag_iterate( mGlobalIdTag, local_edges_range.
begin(), local_edges_range.
end(), count, data );
MB_CHK_SET_ERR( rval,
"Failed to iterate global id tag on local edges" );
1287 int* gid_data = (
int*)data;
1290 int verticesOnEdgeVarId;
1293 success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnEdge", &verticesOnEdgeVarId );
1294 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnEdge" );
1296 int* vertices_on_local_edges = (
int*)conn_arr_edges;
1297 #ifdef MOAB_HAVE_PNETCDF
1299 requests.resize( nb_reads );
1300 statuss.resize( nb_reads );
1313 #ifdef MOAB_HAVE_PNETCDF
1314 success = NCFUNCREQG( _vara_int )(
_fileId, verticesOnEdgeVarId, read_starts, read_counts,
1315 &( vertices_on_local_edges[indexInArray] ), &requests[idxReq++] );
1317 success =
NCFUNCAG( _vara_int )(
_fileId, verticesOnEdgeVarId, read_starts, read_counts,
1318 &( vertices_on_local_edges[indexInArray] ) );
1320 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnEdge data in a loop" );
1323 indexInArray += ( endh - starth + 1 ) * 2;
1326 #ifdef MOAB_HAVE_PNETCDF
1328 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1329 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1335 for(
int edge_vert =
nLocalEdges * 2 - 1; edge_vert >= 0; edge_vert-- )
1337 int global_vert_idx = vertices_on_local_edges[edge_vert];
1339 assert( local_vert_idx != -1 );
1340 conn_arr_edges[edge_vert] = start_vertex + local_vert_idx;
1347 const std::vector< int >& num_edges_on_local_cells,
1359 int num_edges = num_edges_on_local_cells[i];
1363 std::vector< int > num_edges_on_cell_groups;
1366 if( local_cells_with_n_edges[i].
size() > 0 ) num_edges_on_cell_groups.push_back( i );
1373 int num_edges_per_cell = num_edges_on_cell_groups[i];
1374 int num_group_cells = (int)local_cells_with_n_edges[num_edges_per_cell].
size();
1379 num_group_cells, num_edges_per_cell,
MBPOLYGON, 0, start_element,
1380 conn_arr_local_cells_with_n_edges[num_edges_per_cell], num_group_cells );
MB_CHK_SET_ERR( rval,
"Failed to create local cells" );
1381 faces.
insert( start_element, start_element + num_group_cells - 1 );
1384 Range local_cells_range( start_element, start_element + num_group_cells - 1 );
1390 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" );
1391 assert( count == num_group_cells );
1392 int* gid_data = (
int*)data;
1393 std::copy( local_cells_with_n_edges[num_edges_per_cell].begin(),
1394 local_cells_with_n_edges[num_edges_per_cell].end(), gid_data );
1397 for(
int j = 0; j < num_group_cells; j++ )
1400 local_cells_with_n_edges[num_edges_per_cell][j];
1402 assert( local_cell_idx != -1 );
1410 for(
int k = 0; k < num_edges_per_cell; k++ )
1415 assert( local_vert_idx != -1 );
1416 conn_arr_local_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] =
1417 start_vertex + local_vert_idx;
1440 conn_arr_local_cells,
1452 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" );
1454 int* gid_data = (
int*)data;
1460 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
1467 assert( local_vert_idx != -1 );
1468 conn_arr_local_cells[local_cell_idx *
maxEdgesPerCell + i] = start_vertex + local_vert_idx;
1482 std::vector< double* > arrays;
1488 Range gather_set_verts_range( gather_set_start_vertex, gather_set_start_vertex +
nVertices - 1 );
1489 rval = mbImpl->
add_entities( gather_set, gather_set_verts_range );
MB_CHK_SET_ERR( rval,
"Failed to add vertices to the gather set" );
1492 double* xptr = arrays[0];
1494 int success =
NCFUNC( inq_varid )(
_fileId,
"xVertex", &xVertexVarId );
1495 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of xVertex" );
1498 #ifdef MOAB_HAVE_PNETCDF
1501 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1502 success =
NCFUNCG( _vara_double )(
_fileId, xVertexVarId, &read_start, &read_count, xptr );
1503 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read xVertex data" );
1505 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1507 success =
NCFUNCG( _vara_double )(
_fileId, xVertexVarId, &read_start, &read_count, xptr );
1508 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read xVertex data" );
1512 double* yptr = arrays[1];
1514 success =
NCFUNC( inq_varid )(
_fileId,
"yVertex", &yVertexVarId );
1515 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of yVertex" );
1516 #ifdef MOAB_HAVE_PNETCDF
1519 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1520 success =
NCFUNCG( _vara_double )(
_fileId, yVertexVarId, &read_start, &read_count, yptr );
1521 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read yVertex data" );
1523 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1525 success =
NCFUNCG( _vara_double )(
_fileId, yVertexVarId, &read_start, &read_count, yptr );
1526 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read yVertex data" );
1530 double* zptr = arrays[2];
1532 success =
NCFUNC( inq_varid )(
_fileId,
"zVertex", &zVertexVarId );
1533 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of zVertex" );
1534 #ifdef MOAB_HAVE_PNETCDF
1537 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1538 success =
NCFUNCG( _vara_double )(
_fileId, zVertexVarId, &read_start, &read_count, zptr );
1539 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read zVertex data" );
1541 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1543 success =
NCFUNCG( _vara_double )(
_fileId, zVertexVarId, &read_start, &read_count, zptr );
1544 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read zVertex data" );
1551 mbImpl->
tag_iterate( mGlobalIdTag, gather_set_verts_range.
begin(), gather_set_verts_range.
end(), count, data );
MB_CHK_SET_ERR( rval,
"Failed to iterate global id tag on gather set vertices" );
1553 int* gid_data = (
int*)data;
1555 gid_data[j - 1] = j;
1560 rval = mbImpl->
tag_iterate( *mpFileIdTag, gather_set_verts_range.
begin(), gather_set_verts_range.
end(), count,
1561 data );
MB_CHK_SET_ERR( rval,
"Failed to iterate file id tag on gather set vertices" );
1563 int bytes_per_tag = 4;
1565 if( 4 == bytes_per_tag )
1567 gid_data = (
int*)data;
1571 else if( 8 == bytes_per_tag )
1573 long* handle_tag_data = (
long*)data;
1595 Range gather_set_edges_range( start_edge, start_edge +
nEdges - 1 );
1596 rval = mbImpl->
add_entities( gather_set, gather_set_edges_range );
MB_CHK_SET_ERR( rval,
"Failed to add edges to the gather set" );
1599 int verticesOnEdgeVarId;
1600 int success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnEdge", &verticesOnEdgeVarId );
1601 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnEdge" );
1603 int* vertices_on_gather_set_edges = (
int*)conn_arr_gather_set_edges;
1606 #ifdef MOAB_HAVE_PNETCDF
1609 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1611 NCFUNCG( _vara_int )(
_fileId, verticesOnEdgeVarId, read_starts, read_counts, vertices_on_gather_set_edges );
1612 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnEdge data" );
1614 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1617 NCFUNCG( _vara_int )(
_fileId, verticesOnEdgeVarId, read_starts, read_counts, vertices_on_gather_set_edges );
1618 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnEdge data" );
1624 for(
int edge_vert =
nEdges * 2 - 1; edge_vert >= 0; edge_vert-- )
1626 int gather_set_vert_idx = vertices_on_gather_set_edges[edge_vert];
1627 gather_set_vert_idx--;
1629 conn_arr_gather_set_edges[edge_vert] = gather_set_start_vertex + gather_set_vert_idx;
1640 int nEdgesOnCellVarId;
1641 int success =
NCFUNC( inq_varid )(
_fileId,
"nEdgesOnCell", &nEdgesOnCellVarId );
1642 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of nEdgesOnCell" );
1643 std::vector< int > num_edges_on_gather_set_cells(
nCells );
1646 #ifdef MOAB_HAVE_PNETCDF
1649 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1651 NCFUNCG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0] );
1652 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data" );
1654 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1657 NCFUNCG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0] );
1658 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data" );
1662 int verticesOnCellVarId;
1663 success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnCell", &verticesOnCellVarId );
1664 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnCell" );
1668 #ifdef MOAB_HAVE_PNETCDF
1671 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1672 success =
NCFUNCG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
1673 &vertices_on_gather_set_cells[0] );
1674 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data" );
1676 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1678 success =
NCFUNCG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
1679 &vertices_on_gather_set_cells[0] );
1680 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data" );
1686 for(
int i =
nCells - 1; i >= 0; i-- )
1688 int num_edges = num_edges_on_gather_set_cells[i];
1689 gather_set_cells_with_n_edges[num_edges].
insert( i + 1 );
1694 for(
int num_edges_per_cell = 3; num_edges_per_cell <=
maxEdgesPerCell; num_edges_per_cell++ )
1696 int num_group_cells = gather_set_cells_with_n_edges[num_edges_per_cell].
size();
1697 if( num_group_cells > 0 )
1701 num_group_cells, num_edges_per_cell,
MBPOLYGON, 0, start_element,
1702 conn_arr_gather_set_cells_with_n_edges[num_edges_per_cell], num_group_cells );
MB_CHK_SET_ERR( rval,
"Failed to create gather set cells" );
1705 Range gather_set_cells_range( start_element, start_element + num_group_cells - 1 );
1706 rval = mbImpl->
add_entities( gather_set, gather_set_cells_range );
MB_CHK_SET_ERR( rval,
"Failed to add cells to the gather set" );
1708 for(
int j = 0; j < num_group_cells; j++ )
1710 int gather_set_cell_idx =
1711 gather_set_cells_with_n_edges[num_edges_per_cell][j];
1712 gather_set_cell_idx--;
1714 for(
int k = 0; k < num_edges_per_cell; k++ )
1719 gather_set_vert_idx--;
1722 conn_arr_gather_set_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] =
1723 gather_set_start_vertex + gather_set_vert_idx;
1737 int nEdgesOnCellVarId;
1738 int success =
NCFUNC( inq_varid )(
_fileId,
"nEdgesOnCell", &nEdgesOnCellVarId );
1739 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of nEdgesOnCell" );
1740 std::vector< int > num_edges_on_gather_set_cells(
nCells );
1743 #ifdef MOAB_HAVE_PNETCDF
1746 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1748 NCFUNCG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0] );
1749 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data" );
1751 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1754 NCFUNCG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0] );
1755 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data" );
1764 conn_arr_gather_set_cells );
MB_CHK_SET_ERR( rval,
"Failed to create gather set cells" );
1767 Range gather_set_cells_range( start_element, start_element +
nCells - 1 );
1768 rval = mbImpl->
add_entities( gather_set, gather_set_cells_range );
MB_CHK_SET_ERR( rval,
"Failed to add cells to the gather set" );
1771 int verticesOnCellVarId;
1772 success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnCell", &verticesOnCellVarId );
1773 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnCell" );
1775 int* vertices_on_gather_set_cells = (
int*)conn_arr_gather_set_cells;
1778 #ifdef MOAB_HAVE_PNETCDF
1781 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1783 NCFUNCG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts, vertices_on_gather_set_cells );
1784 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data" );
1786 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1789 NCFUNCG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts, vertices_on_gather_set_cells );
1790 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data" );
1795 for(
int gather_set_cell_idx = 0; gather_set_cell_idx <
nCells; gather_set_cell_idx++ )
1797 int num_edges = num_edges_on_gather_set_cells[gather_set_cell_idx];
1798 int idx_in_gather_set_vert_arr = gather_set_cell_idx *
maxEdgesPerCell;
1799 int last_vert_idx = vertices_on_gather_set_cells[idx_in_gather_set_vert_arr + num_edges - 1];
1801 vertices_on_gather_set_cells[idx_in_gather_set_vert_arr + i] = last_vert_idx;
1809 int gather_set_vert_idx = vertices_on_gather_set_cells[cell_vert];
1810 gather_set_vert_idx--;
1812 conn_arr_gather_set_cells[cell_vert] = gather_set_start_vertex + gather_set_vert_idx;