9 #ifdef MOAB_HAVE_ZOLTAN
22 std::vector< std::string >& dimNames = readNC->
dimNames;
26 if( ( std::find( dimNames.begin(), dimNames.end(), std::string(
"ni" ) ) != dimNames.end() ) &&
27 ( std::find( dimNames.begin(), dimNames.end(), std::string(
"nj" ) ) != dimNames.end() ) &&
28 ( std::find( dimNames.begin(), dimNames.end(), std::string(
"nv" ) ) != dimNames.end() ) )
42 std::map< std::string, ReadNC::VarData >& varInfo =
_readNC->
varInfo;
54 std::vector< std::string >::iterator vit;
56 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"ni" ) ) != dimNames.end() )
57 idx = vit - dimNames.begin();
60 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'ni' variable" );
64 gDims[3] = dimLens[idx];
67 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nj" ) ) != dimNames.end() )
68 idx = vit - dimNames.begin();
71 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nj' variable" );
75 gDims[4] = dimLens[idx];
84 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nv" ) ) != dimNames.end() )
85 idx = vit - dimNames.begin();
88 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nv' dimension" );
94 int rank = 0, procs = 1;
105 for(
int i = 0; i < 6; i++ )
112 for(
int i = 0; i < 3; i++ )
113 parData.
pDims[i] = pdims[i];
118 dbgOut.
tprintf( 1,
"Contiguous chunks of size %d bytes.\n",
123 for(
int i = 0; i < 6; i++ )
156 std::map< std::string, ReadNC::VarData >::iterator mit;
157 for( mit = varInfo.begin(); mit != varInfo.end(); ++mit )
179 std::vector< std::string > ijdimNames( 2 );
180 ijdimNames[0] =
"__ni";
181 ijdimNames[1] =
"__nj";
182 std::string tag_name;
186 for(
unsigned int i = 0; i != ijdimNames.size(); i++ )
188 std::vector< int > val( 2, 0 );
189 if( ijdimNames[i] ==
"__ni" )
194 else if( ijdimNames[i] ==
"__nj" )
200 std::stringstream ss_tag_name;
201 ss_tag_name << ijdimNames[i] <<
"_LOC_MINMAX";
202 tag_name = ss_tag_name.str();
205 if(
MB_SUCCESS == rval ) dbgOut.
tprintf( 2,
"Conventional tag %s is created.\n", tag_name.c_str() );
210 switch( varInfo[
"xc"].varDataType )
216 MB_SET_ERR( MB_FAILURE,
"Unexpected variable data type for 'lon'" );
220 Tag convTagsCreated = 0;
224 int create_conv_tags_flag = 1;
245 dbgOut.
tprintf( 1,
"local cells: %d \n", local_elems );
249 std::string maskstr(
"mask" );
257 std::vector< int > mask( local_elems );
259 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read int data for mask variable " );
261 std::vector< int > gids( local_elems );
268 gids[elem_index] = j * global_row_size + i + 1;
271 std::vector< NCDF_SIZE > startsv( 3 );
275 std::vector< NCDF_SIZE > countsv( 3 );
281 std::string xvstr(
"xv" );
283 std::vector< double > xv( local_elems *
nv );
285 std::vector< NCDF_SIZE > starts_vv, counts_vv;
286 starts_vv.resize( 3 );
287 counts_vv.resize( 3 );
292 starts_vv[1] = startsv[0];
293 starts_vv[2] = startsv[1];
295 counts_vv[1] = countsv[0];
296 counts_vv[2] = countsv[1];
304 dbgOut.
tprintf( 1,
" nv is the last dimension in xv array (0 or 1) %d \n", (
int)nv_last );
305 success =
NCFUNCAG( _vara_double )(
_fileId, var_xv.
varId, &starts_vv[0], &counts_vv[0], &xv[0] );
306 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read double data for xv variable " );
308 std::string yvstr(
"yv" );
310 std::vector< double > yv( local_elems *
nv );
311 success =
NCFUNCAG( _vara_double )(
_fileId, var_yv.
varId, &starts_vv[0], &counts_vv[0], &yv[0] );
312 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read double data for yv variable " );
315 std::string xcstr(
"xc" );
317 std::vector< double > xc( local_elems );
319 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read double data for xc variable " );
321 std::string ycstr(
"yc" );
323 std::vector< double > yc( local_elems );
325 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read double data for yc variable " );
327 std::string fracstr(
"frac" );
329 std::vector< double > frac( local_elems );
330 if( var_frac.
varId >= 0 )
334 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read double data for frac variable " );
336 std::string areastr(
"area" );
337 std::vector< double > area( local_elems );
340 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read double data for area variable " );
342 Tag areaTag, fracTag, xcTag, ycTag;
366 if( procs >= 2 && repartition )
369 rval = redistribute_cells( myPcomm, xc, yc, xv, yv, frac, mask, area, gids,
nv, nv_last );
MB_CHK_SET_ERR( rval,
"Failed to redistribute local cells" );
370 local_elems = (int)xc.size();
371 dbgOut.
tprintf( 1,
"local cells after repartition: %d \n", local_elems );
376 int nb_with_mask1 = 0;
377 for(
int i = 0; i < local_elems; i++ )
378 if( 1 == mask[i] ) nb_with_mask1++;
379 dbgOut.
tprintf( 1,
"local cells with mask 1: %d \n", nb_with_mask1 );
397 int num_actual_cells = local_elems;
398 if( culling ) num_actual_cells = nb_with_mask1;
400 if(
nv > 1 && num_actual_cells > 0 )
403 tmp_range.
insert( start_cell, start_cell + num_actual_cells - 1 );
407 std::map< Node3D, EntityHandle > vertex_map;
409 if( num_actual_cells > 0 )
415 const double pideg = acos( -1.0 ) / 180.0;
417 for( elem_index = 0; elem_index < local_elems; elem_index++ )
419 if( culling && 0 == mask[elem_index] )
422 dbgOut.
tprintf( 3,
"elem index %d \n", elem_index );
423 for(
int k = 0; k <
nv; k++ )
425 int index_v_arr =
nv * elem_index + k;
426 if( !nv_last ) index_v_arr = k * local_elems + elem_index;
432 double cosphi = cos(
pideg * y );
433 double zmult = sin(
pideg * y );
434 double xmult = cosphi * cos( x *
pideg );
435 double ymult = cosphi * sin( x *
pideg );
436 Node3D pt( xmult, ymult, zmult );
438 dbgOut.
tprintf( 3,
" %d x=%5.1f y=%5.1f pt: %f %f %f \n", k, x, y, pt.
coords[0], pt.
coords[1],
450 int nLocalVertices = (int)vertex_map.size();
451 std::vector< double* > arrays;
455 vtx_handle = start_vertex;
458 double *x = arrays[0], *y = arrays[1], *z = arrays[2];
459 for(
auto i = vertex_map.begin(); i != vertex_map.end(); ++i )
461 i->second = vtx_handle;
463 *x = i->first.coords[0];
465 *y = i->first.coords[1];
467 *z = i->first.coords[2];
477 for( elem_index = 0; elem_index < local_elems; elem_index++ )
479 if( culling && 0 == mask[elem_index] )
482 for(
int k = 0; k <
nv; k++ )
484 int index_v_arr =
nv * elem_index + k;
485 if( !nv_last ) index_v_arr = k * local_elems + elem_index;
488 double x = xv[index_v_arr];
489 double y = yv[index_v_arr];
490 double cosphi = cos(
pideg * y );
491 double zmult = sin(
pideg * y );
492 double xmult = cosphi * cos( x *
pideg );
493 double ymult = cosphi * sin( x *
pideg );
494 Node3D pt( xmult, ymult, zmult );
495 conn_arr[index *
nv + k] = vertex_map[pt];
499 if(
nv > 1 ) cell = start_cell + index;
508 int globalId = gids[elem_index];
516 std::vector< Tag > tagList;
517 tagList.push_back( mGlobalIdTag );
518 tagList.push_back( xcTag );
519 tagList.push_back( ycTag );
520 tagList.push_back( areaTag );
521 tagList.push_back( fracTag );
522 tagList.push_back( maskTag );
544 rval =
mb->get_connectivity( eh, conn, num_nodes );
MB_CHK_ERR( rval );
552 if( myPcomm && procs >= 2 )
558 2 );
MB_CHK_SET_ERR( rval,
"Failed to merge vertices in parallel" );
569 std::vector< double >& xc,
570 std::vector< double >& yc,
571 std::vector< double >& xv,
572 std::vector< double >& yv,
573 std::vector< double >& frac,
574 std::vector< int >& masks,
575 std::vector< double >& area,
576 std::vector< int >& gids,
581 #ifdef MOAB_HAVE_ZOLTAN
583 size_t num_local_cells = gids.size();
590 for (
size_t i = 0; i< masks.size(); i++)
591 if (1 == masks[i]) ++num_local_cells;
594 std::vector< double > xi( num_local_cells ), yi( num_local_cells ), zi( num_local_cells );
595 std::vector< int > gids2( num_local_cells );
596 const double pideg = acos( -1.0 ) / 180.0;
597 size_t actual_index = 0;
598 for(
size_t i = 0; i < xc.size(); i++ )
600 if (culling && 0 == masks[i])
604 double cosphi = cos(
pideg * y );
605 double zmult = sin(
pideg * y );
606 double xmult = cosphi * cos( x *
pideg );
607 double ymult = cosphi * sin( x *
pideg );
608 xi[actual_index] = xmult;
609 yi[actual_index] = ymult;
610 zi[actual_index] = zmult;
611 gids2[actual_index] = gids[i];
616 std::vector< int > dest( num_local_cells );
621 unsigned numr = 2 *
nv + 4;
622 tl.
initialize( 3, 0, 0, numr, num_local_cells );
625 int index_in_dest = 0;
626 for(
size_t i = 0; i < xc.size(); i++ )
628 if (culling && 0 == masks[i])
630 int gdof = gids2[index_in_dest];
631 int to_proc = dest[index_in_dest];
634 tl.
vi_wr[3 * n] = to_proc;
635 tl.
vi_wr[3 * n + 1] = gdof;
636 tl.
vi_wr[3 * n + 2] = mask;
637 tl.
vr_wr[n * numr] = area[i];
638 tl.
vr_wr[n * numr + 1] = xc[i];
639 tl.
vr_wr[n * numr + 2] = yc[i];
640 tl.
vr_wr[n * numr + 3] = frac[i];
641 for(
int k = 0; k <
nv; k++ )
643 int index_v_arr =
nv * i + k;
644 if( !nv_last ) index_v_arr = k * xc.size() + n;
645 tl.
vr_wr[n * numr + 4 + k] = xv[index_v_arr];
646 tl.
vr_wr[n * numr + 4 +
nv + k] = yv[index_v_arr];
659 sort_buffer.buffer_init( N );
660 tl.
sort( 1, &sort_buffer );
669 for(
int n = 0; n < N; n++ )
672 gids[n] = tl.
vi_wr[3 * n + 1];
673 masks[n] = tl.
vi_wr[3 * n + 2];
674 area[n] = tl.
vr_wr[n * numr];
675 xc[n] = tl.
vr_wr[n * numr + 1];
676 yc[n] = tl.
vr_wr[n * numr + 2];
677 frac[n] = tl.
vr_wr[n * numr + 3];
678 for(
int k = 0; k <
nv; k++ )
680 int index_v_arr =
nv * n + k;
681 if( !nv_last ) index_v_arr = k * N + n;
682 xv[index_v_arr] = tl.
vr_wr[n * numr + 4 + k];
683 yv[index_v_arr] = tl.
vr_wr[n * numr + 4 +
nv + k];