17 #include "FiniteElementTools.h"
21 #ifdef MOAB_HAVE_NETCDFPAR
24 #include "netcdfcpp.h"
27 #ifdef MOAB_HAVE_PNETCDF
30 #define ERR_PARNC( err ) \
31 if( err != NC_NOERR ) \
33 fprintf( stderr, "Error at line %d: %s\n", __LINE__, ncmpi_strerror( err ) ); \
34 MPI_Abort( MPI_COMM_WORLD, 1 ); \
41 #define MPI_CHK_ERR( err ) \
44 std::cout << "MPI Failure. ErrorCode (" << ( err ) << ") "; \
45 std::cout << "\nMPI Aborting... \n"; \
46 return moab::MB_FAILURE; \
49 int moab::TempestOnlineMap::rearrange_arrays_by_dofs(
const std::vector< unsigned int >& gdofmap,
50 DataArray1D< double >& vecFaceArea,
51 DataArray1D< double >& dCenterLon,
52 DataArray1D< double >& dCenterLat,
53 DataArray2D< double >& dVertexLon,
54 DataArray2D< double >& dVertexLat,
55 std::vector< int >& masks,
61 unsigned int localmax = 0;
62 for(
unsigned i = 0; i < N; i++ )
63 if( gdofmap[i] > localmax ) localmax = gdofmap[i];
66 MPI_Allreduce( &localmax, &maxdof, 1, MPI_INT, MPI_MAX, m_pcomm->comm() );
69 int size_per_task = ( maxdof + 1 ) /
size;
72 unsigned numr = 2 * nv + 3;
76 for(
unsigned i = 0; i < N; i++ )
78 int gdof = gdofmap[i];
79 int to_proc = gdof / size_per_task;
81 if( to_proc >=
size ) to_proc =
size - 1;
83 tl.
vi_wr[3 * n] = to_proc;
84 tl.
vi_wr[3 * n + 1] = gdof;
85 tl.
vi_wr[3 * n + 2] = mask;
86 tl.
vr_wr[n * numr] = vecFaceArea[i];
87 tl.
vr_wr[n * numr + 1] = dCenterLon[i];
88 tl.
vr_wr[n * numr + 2] = dCenterLat[i];
89 for(
int j = 0; j < nv; j++ )
91 tl.
vr_wr[n * numr + 3 + j] = dVertexLon[i][j];
92 tl.
vr_wr[n * numr + 3 + nv + j] = dVertexLat[i][j];
98 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tl, 0 );
103 sort_buffer.buffer_init( tl.
get_n() );
104 tl.
sort( 1, &sort_buffer );
107 for(
unsigned i = 0; i < tl.
get_n() - 1; i++ )
109 if( tl.
vi_wr[3 * i + 1] != tl.
vi_wr[3 * i + 4] ) nb_unique++;
111 vecFaceArea.Allocate( nb_unique );
112 dCenterLon.Allocate( nb_unique );
113 dCenterLat.Allocate( nb_unique );
114 dVertexLon.Allocate( nb_unique, nv );
115 dVertexLat.Allocate( nb_unique, nv );
116 masks.resize( nb_unique );
117 int current_size = 1;
118 vecFaceArea[0] = tl.
vr_wr[0];
119 dCenterLon[0] = tl.
vr_wr[1];
120 dCenterLat[0] = tl.
vr_wr[2];
121 masks[0] = tl.
vi_wr[2];
122 for(
int j = 0; j < nv; j++ )
124 dVertexLon[0][j] = tl.
vr_wr[3 + j];
125 dVertexLat[0][j] = tl.
vr_wr[3 + nv + j];
127 for(
unsigned i = 0; i < tl.
get_n() - 1; i++ )
130 if( tl.
vi_wr[3 * i + 1] != tl.
vi_wr[3 * i + 4] )
132 vecFaceArea[current_size] = tl.
vr_wr[i1 * numr];
133 dCenterLon[current_size] = tl.
vr_wr[i1 * numr + 1];
134 dCenterLat[current_size] = tl.
vr_wr[i1 * numr + 2];
135 for(
int j = 0; j < nv; j++ )
137 dVertexLon[current_size][j] = tl.
vr_wr[i1 * numr + 3 + j];
138 dVertexLat[current_size][j] = tl.
vr_wr[i1 * numr + 3 + nv + j];
140 masks[current_size] = tl.
vi_wr[3 * i1 + 2];
145 vecFaceArea[current_size - 1] += tl.
vr_wr[i1 * numr];
157 const std::map< std::string, std::string >& attrMap )
161 size_t lastindex = strFilename.find_last_of(
"." );
162 std::string extension = strFilename.substr( lastindex + 1, strFilename.size() );
165 if( extension ==
"nc" )
168 rval = this->WriteSCRIPMapFile( strFilename.c_str(), attrMap );
MB_CHK_ERR( rval );
173 rval = this->WriteHDF5MapFile( strFilename.c_str() );
MB_CHK_ERR( rval );
182 const std::map< std::string, std::string >& attrMap )
184 NcError
error( NcError::silent_nonfatal );
186 #ifdef MOAB_HAVE_NETCDFPAR
187 bool is_independent =
true;
188 ParNcFile ncMap( m_pcomm->comm(), MPI_INFO_NULL, strFilename.c_str(), NcFile::Replace, NcFile::Netcdf4 );
191 NcFile ncMap( strFilename.c_str(), NcFile::Replace );
194 if( !ncMap.is_valid() )
196 _EXCEPTION1(
"Unable to open output map file \"%s\"", strFilename.c_str() );
201 auto it = attrMap.begin();
202 while( it != attrMap.end() )
205 ncMap.add_att( it->first.c_str(), it->second.c_str() );
219 DataArray1D< double > vecSourceFaceArea, vecTargetFaceArea;
220 DataArray1D< double > dSourceCenterLon, dSourceCenterLat, dTargetCenterLon, dTargetCenterLat;
221 DataArray2D< double > dSourceVertexLon, dSourceVertexLat, dTargetVertexLon, dTargetVertexLat;
222 if( m_srcDiscType == DiscretizationType_FV || m_srcDiscType == DiscretizationType_PCLOUD )
224 this->InitializeCoordinatesFromMeshFV(
225 *m_meshInput, dSourceCenterLon, dSourceCenterLat, dSourceVertexLon, dSourceVertexLat,
227 m_remapper->max_source_edges );
229 vecSourceFaceArea.Allocate( m_meshInput->vecFaceArea.GetRows() );
230 for(
unsigned i = 0; i < m_meshInput->vecFaceArea.GetRows(); ++i )
231 vecSourceFaceArea[i] = m_meshInput->vecFaceArea[i];
235 DataArray3D< double > dataGLLJacobianSrc;
236 this->InitializeCoordinatesFromMeshFE( *m_meshInput, m_nDofsPEl_Src, dataGLLNodesSrc, dSourceCenterLon,
237 dSourceCenterLat, dSourceVertexLon, dSourceVertexLat );
240 GenerateMetaData( *m_meshInput, m_nDofsPEl_Src,
false , dataGLLNodesSrc, dataGLLJacobianSrc );
242 if( m_srcDiscType == DiscretizationType_CGLL )
244 GenerateUniqueJacobian( dataGLLNodesSrc, dataGLLJacobianSrc, vecSourceFaceArea );
248 GenerateDiscontinuousJacobian( dataGLLJacobianSrc, vecSourceFaceArea );
252 if( m_destDiscType == DiscretizationType_FV || m_destDiscType == DiscretizationType_PCLOUD )
254 this->InitializeCoordinatesFromMeshFV(
255 *m_meshOutput, dTargetCenterLon, dTargetCenterLat, dTargetVertexLon, dTargetVertexLat,
257 m_remapper->max_target_edges );
259 vecTargetFaceArea.Allocate( m_meshOutput->vecFaceArea.GetRows() );
260 for(
unsigned i = 0; i < m_meshOutput->vecFaceArea.GetRows(); ++i )
262 vecTargetFaceArea[i] = m_meshOutput->vecFaceArea[i];
267 DataArray3D< double > dataGLLJacobianDest;
268 this->InitializeCoordinatesFromMeshFE( *m_meshOutput, m_nDofsPEl_Dest, dataGLLNodesDest, dTargetCenterLon,
269 dTargetCenterLat, dTargetVertexLon, dTargetVertexLat );
272 GenerateMetaData( *m_meshOutput, m_nDofsPEl_Dest,
false , dataGLLNodesDest, dataGLLJacobianDest );
274 if( m_destDiscType == DiscretizationType_CGLL )
276 GenerateUniqueJacobian( dataGLLNodesDest, dataGLLJacobianDest, vecTargetFaceArea );
280 GenerateDiscontinuousJacobian( dataGLLJacobianDest, vecTargetFaceArea );
285 unsigned nA = ( vecSourceFaceArea.GetRows() );
286 unsigned nB = ( vecTargetFaceArea.GetRows() );
288 std::vector< int > masksA, masksB;
293 int nSourceNodesPerFace = dSourceVertexLon.GetColumns();
294 int nTargetNodesPerFace = dTargetVertexLon.GetColumns();
300 for(
unsigned i = 0; i < nA; i++ )
302 const Face&
face = m_meshInput->faces[i];
304 int nNodes =
face.edges.size();
305 int indexNodeAtPole = -1;
308 for(
int j = 0; j < nNodes; j++ )
309 if( fabs( fabs( dSourceVertexLat[i][j] ) - 90.0 ) < 1.0e-12 )
315 if( indexNodeAtPole < 0 )
continue;
317 int nodeAtPole =
face[indexNodeAtPole];
318 Node nodePole = m_meshInput->nodes[nodeAtPole];
319 Node newCenter = nodePole * 2;
320 for(
int j = 1; j < nNodes; j++ )
322 int indexi = ( indexNodeAtPole + j ) % nNodes;
323 const Node& node = m_meshInput->nodes[
face[indexi]];
324 newCenter = newCenter + node;
326 newCenter = newCenter * 0.25;
327 newCenter = newCenter.Normalized();
330 double iniLon = dSourceCenterLon[i], iniLat = dSourceCenterLat[i];
333 XYZtoRLL_Deg( newCenter.x, newCenter.y, newCenter.z, dSourceCenterLon[i], dSourceCenterLat[i] );
335 std::cout <<
" modify center of triangle from " << iniLon <<
" " << iniLat <<
" to " << dSourceCenterLon[i]
336 <<
" " << dSourceCenterLat[i] <<
"\n";
341 #if defined( MOAB_HAVE_MPI )
342 int max_row_dof, max_col_dof;
345 int ierr = rearrange_arrays_by_dofs( srccol_gdofmap, vecSourceFaceArea, dSourceCenterLon, dSourceCenterLat,
346 dSourceVertexLon, dSourceVertexLat, masksA, nA, nSourceNodesPerFace,
350 _EXCEPTION1(
"Unable to arrange source data %d ", nA );
354 ierr = rearrange_arrays_by_dofs( row_gdofmap, vecTargetFaceArea, dTargetCenterLon, dTargetCenterLat,
355 dTargetVertexLon, dTargetVertexLat, masksB, nB, nTargetNodesPerFace,
359 _EXCEPTION1(
"Unable to arrange target data %d ", nB );
365 int nS = m_weightMatrix.nonZeros();
367 #if defined( MOAB_HAVE_MPI ) && defined( MOAB_HAVE_NETCDFPAR )
368 int locbuf[5] = { (int)nA, (
int)nB, nS, nSourceNodesPerFace, nTargetNodesPerFace };
369 int offbuf[3] = { 0, 0, 0 };
370 int globuf[5] = { 0, 0, 0, 0, 0 };
371 MPI_Scan( locbuf, offbuf, 3, MPI_INT, MPI_SUM, m_pcomm->comm() );
372 MPI_Allreduce( locbuf, globuf, 3, MPI_INT, MPI_SUM, m_pcomm->comm() );
373 MPI_Allreduce( &locbuf[3], &globuf[3], 2, MPI_INT, MPI_MAX, m_pcomm->comm() );
381 int offbuf[3] = { 0, 0, 0 };
382 int globuf[5] = { (int)nA, (
int)nB, nS, nSourceNodesPerFace, nTargetNodesPerFace };
385 std::vector< std::string > srcdimNames, tgtdimNames;
386 std::vector< int > srcdimSizes, tgtdimSizes;
390 srcdimNames.push_back(
"lat" );
391 srcdimNames.push_back(
"lon" );
392 srcdimSizes.resize( 2, 0 );
393 srcdimSizes[0] = m_remapper->m_source_metadata[0];
394 srcdimSizes[1] = m_remapper->m_source_metadata[1];
398 srcdimNames.push_back(
"num_elem" );
399 srcdimSizes.push_back( globuf[0] );
404 tgtdimNames.push_back(
"lat" );
405 tgtdimNames.push_back(
"lon" );
406 tgtdimSizes.resize( 2, 0 );
407 tgtdimSizes[0] = m_remapper->m_target_metadata[0];
408 tgtdimSizes[1] = m_remapper->m_target_metadata[1];
412 tgtdimNames.push_back(
"num_elem" );
413 tgtdimSizes.push_back( globuf[1] );
418 unsigned nSrcGridDims = ( srcdimSizes.size() );
419 unsigned nDstGridDims = ( tgtdimSizes.size() );
421 NcDim* dimSrcGridRank = ncMap.add_dim(
"src_grid_rank", nSrcGridDims );
422 NcDim* dimDstGridRank = ncMap.add_dim(
"dst_grid_rank", nDstGridDims );
424 NcVar* varSrcGridDims = ncMap.add_var(
"src_grid_dims", ncInt, dimSrcGridRank );
425 NcVar* varDstGridDims = ncMap.add_var(
"dst_grid_dims", ncInt, dimDstGridRank );
427 #ifdef MOAB_HAVE_NETCDFPAR
428 ncMap.enable_var_par_access( varSrcGridDims, is_independent );
429 ncMap.enable_var_par_access( varDstGridDims, is_independent );
435 for(
unsigned i = 0; i < srcdimSizes.size(); i++ )
437 varSrcGridDims->set_cur( nSrcGridDims - i - 1 );
438 varSrcGridDims->put( &( srcdimSizes[nSrcGridDims - i - 1] ), 1 );
441 for(
unsigned i = 0; i < srcdimSizes.size(); i++ )
443 snprintf( szDim, 64,
"name%i", i );
444 varSrcGridDims->add_att( szDim, srcdimNames[nSrcGridDims - i - 1].c_str() );
447 for(
unsigned i = 0; i < tgtdimSizes.size(); i++ )
449 varDstGridDims->set_cur( nDstGridDims - i - 1 );
450 varDstGridDims->put( &( tgtdimSizes[nDstGridDims - i - 1] ), 1 );
453 for(
unsigned i = 0; i < tgtdimSizes.size(); i++ )
455 snprintf( szDim, 64,
"name%i", i );
456 varDstGridDims->add_att( szDim, tgtdimNames[nDstGridDims - i - 1].c_str() );
461 NcDim* dimNA = ncMap.add_dim(
"n_a", globuf[0] );
462 NcDim* dimNB = ncMap.add_dim(
"n_b", globuf[1] );
465 NcDim* dimNVA = ncMap.add_dim(
"nv_a", globuf[3] );
466 NcDim* dimNVB = ncMap.add_dim(
"nv_b", globuf[4] );
469 NcVar* varYCA = ncMap.add_var(
"yc_a", ncDouble, dimNA );
470 NcVar* varYCB = ncMap.add_var(
"yc_b", ncDouble, dimNB );
472 NcVar* varXCA = ncMap.add_var(
"xc_a", ncDouble, dimNA );
473 NcVar* varXCB = ncMap.add_var(
"xc_b", ncDouble, dimNB );
475 NcVar* varYVA = ncMap.add_var(
"yv_a", ncDouble, dimNA, dimNVA );
476 NcVar* varYVB = ncMap.add_var(
"yv_b", ncDouble, dimNB, dimNVB );
478 NcVar* varXVA = ncMap.add_var(
"xv_a", ncDouble, dimNA, dimNVA );
479 NcVar* varXVB = ncMap.add_var(
"xv_b", ncDouble, dimNB, dimNVB );
482 NcVar* varMaskA = ncMap.add_var(
"mask_a", ncInt, dimNA );
483 NcVar* varMaskB = ncMap.add_var(
"mask_b", ncInt, dimNB );
485 #ifdef MOAB_HAVE_NETCDFPAR
486 ncMap.enable_var_par_access( varYCA, is_independent );
487 ncMap.enable_var_par_access( varYCB, is_independent );
488 ncMap.enable_var_par_access( varXCA, is_independent );
489 ncMap.enable_var_par_access( varXCB, is_independent );
490 ncMap.enable_var_par_access( varYVA, is_independent );
491 ncMap.enable_var_par_access( varYVB, is_independent );
492 ncMap.enable_var_par_access( varXVA, is_independent );
493 ncMap.enable_var_par_access( varXVB, is_independent );
494 ncMap.enable_var_par_access( varMaskA, is_independent );
495 ncMap.enable_var_par_access( varMaskB, is_independent );
498 varYCA->add_att(
"units",
"degrees" );
499 varYCB->add_att(
"units",
"degrees" );
501 varXCA->add_att(
"units",
"degrees" );
502 varXCB->add_att(
"units",
"degrees" );
504 varYVA->add_att(
"units",
"degrees" );
505 varYVB->add_att(
"units",
"degrees" );
507 varXVA->add_att(
"units",
"degrees" );
508 varXVB->add_att(
"units",
"degrees" );
511 if( dSourceCenterLon.GetRows() != nA )
513 _EXCEPTIONT(
"Mismatch between dSourceCenterLon and nA" );
515 if( dSourceCenterLat.GetRows() != nA )
517 _EXCEPTIONT(
"Mismatch between dSourceCenterLat and nA" );
519 if( dTargetCenterLon.GetRows() != nB )
521 _EXCEPTIONT(
"Mismatch between dTargetCenterLon and nB" );
523 if( dTargetCenterLat.GetRows() != nB )
525 _EXCEPTIONT(
"Mismatch between dTargetCenterLat and nB" );
527 if( dSourceVertexLon.GetRows() != nA )
529 _EXCEPTIONT(
"Mismatch between dSourceVertexLon and nA" );
531 if( dSourceVertexLat.GetRows() != nA )
533 _EXCEPTIONT(
"Mismatch between dSourceVertexLat and nA" );
535 if( dTargetVertexLon.GetRows() != nB )
537 _EXCEPTIONT(
"Mismatch between dTargetVertexLon and nB" );
539 if( dTargetVertexLat.GetRows() != nB )
541 _EXCEPTIONT(
"Mismatch between dTargetVertexLat and nB" );
544 varYCA->set_cur( (
long)offbuf[0] );
545 varYCA->put( &( dSourceCenterLat[0] ), nA );
546 varYCB->set_cur( (
long)offbuf[1] );
547 varYCB->put( &( dTargetCenterLat[0] ), nB );
549 varXCA->set_cur( (
long)offbuf[0] );
550 varXCA->put( &( dSourceCenterLon[0] ), nA );
551 varXCB->set_cur( (
long)offbuf[1] );
552 varXCB->put( &( dTargetCenterLon[0] ), nB );
554 varYVA->set_cur( (
long)offbuf[0] );
555 varYVA->put( &( dSourceVertexLat[0][0] ), nA, nSourceNodesPerFace );
556 varYVB->set_cur( (
long)offbuf[1] );
557 varYVB->put( &( dTargetVertexLat[0][0] ), nB, nTargetNodesPerFace );
559 varXVA->set_cur( (
long)offbuf[0] );
560 varXVA->put( &( dSourceVertexLon[0][0] ), nA, nSourceNodesPerFace );
561 varXVB->set_cur( (
long)offbuf[1] );
562 varXVB->put( &( dTargetVertexLon[0][0] ), nB, nTargetNodesPerFace );
564 varMaskA->set_cur( (
long)offbuf[0] );
565 varMaskA->put( &( masksA[0] ), nA );
566 varMaskB->set_cur( (
long)offbuf[1] );
567 varMaskB->put( &( masksB[0] ), nB );
570 NcVar* varAreaA = ncMap.add_var(
"area_a", ncDouble, dimNA );
571 #ifdef MOAB_HAVE_NETCDFPAR
572 ncMap.enable_var_par_access( varAreaA, is_independent );
574 varAreaA->set_cur( (
long)offbuf[0] );
575 varAreaA->put( &( vecSourceFaceArea[0] ), nA );
577 NcVar* varAreaB = ncMap.add_var(
"area_b", ncDouble, dimNB );
578 #ifdef MOAB_HAVE_NETCDFPAR
579 ncMap.enable_var_par_access( varAreaB, is_independent );
581 varAreaB->set_cur( (
long)offbuf[1] );
582 varAreaB->put( &( vecTargetFaceArea[0] ), nB );
585 DataArray1D< int > vecRow( nS );
586 DataArray1D< int > vecCol( nS );
587 DataArray1D< double > vecS( nS );
588 DataArray1D< double > dFracA( nA );
589 DataArray1D< double > dFracB( nB );
606 #if defined( MOAB_HAVE_MPI )
607 int nAbase = ( max_col_dof + 1 ) /
size;
608 int nBbase = ( max_row_dof + 1 ) /
size;
610 for(
int i = 0; i < m_weightMatrix.outerSize(); ++i )
612 for( WeightMatrix::InnerIterator it( m_weightMatrix, i ); it; ++it )
614 vecRow[offset] = 1 + this->GetRowGlobalDoF( it.row() );
615 vecCol[offset] = 1 + this->GetColGlobalDoF( it.col() );
616 vecS[offset] = it.value();
618 #if defined( MOAB_HAVE_MPI )
621 int procRow = ( vecRow[offset] - 1 ) / nBbase;
622 if( procRow >=
size ) procRow =
size - 1;
623 int procCol = ( vecCol[offset] - 1 ) / nAbase;
624 if( procCol >=
size ) procCol =
size - 1;
625 int nrInd = tlValRow.
get_n();
626 tlValRow.
vi_wr[2 * nrInd] = procRow;
627 tlValRow.
vi_wr[2 * nrInd + 1] = vecRow[offset] - 1;
628 tlValRow.
vr_wr[nrInd] = vecS[offset];
630 int ncInd = tlValCol.
get_n();
631 tlValCol.
vi_wr[3 * ncInd] = procCol;
632 tlValCol.
vi_wr[3 * ncInd + 1] = vecRow[offset] - 1;
633 tlValCol.
vi_wr[3 * ncInd + 2] = vecCol[offset] - 1;
634 tlValCol.
vr_wr[ncInd] = vecS[offset];
642 #if defined( MOAB_HAVE_MPI )
645 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tlValCol, 0 );
646 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tlValRow, 0 );
652 for(
unsigned i = 0; i < tlValRow.
get_n(); i++ )
655 int gRowInd = tlValRow.
vi_wr[2 * i + 1];
656 int localIndexRow = gRowInd - nBbase * rank;
657 double wgt = tlValRow.
vr_wr[i];
658 assert( localIndexRow >= 0 );
659 assert( nB - localIndexRow > 0 );
660 dFracB[localIndexRow] += wgt;
664 std::set< int > neededRows;
665 for(
unsigned i = 0; i < tlValCol.
get_n(); i++ )
667 int rRowInd = tlValCol.
vi_wr[3 * i + 1];
668 neededRows.insert( rRowInd );
672 tgtAreaReq.
initialize( 2, 0, 0, 0, neededRows.size() );
674 for( std::set< int >::iterator sit = neededRows.begin(); sit != neededRows.end(); sit++ )
676 int neededRow = *sit;
677 int procRow = neededRow / nBbase;
678 if( procRow >=
size ) procRow =
size - 1;
680 tgtAreaReq.
vi_wr[2 *
nr] = procRow;
681 tgtAreaReq.
vi_wr[2 *
nr + 1] = neededRow;
685 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tgtAreaReq, 0 );
690 for(
unsigned i = 0; i < tgtAreaReq.
get_n(); i++ )
692 int from_proc = tgtAreaReq.
vi_wr[2 * i];
693 int row = tgtAreaReq.
vi_wr[2 * i + 1];
694 int locaIndexRow = row - rank * nBbase;
695 double areaToSend = vecTargetFaceArea[locaIndexRow];
698 tgtAreaInfo.
vi_wr[2 * i] = from_proc;
699 tgtAreaInfo.
vi_wr[2 * i + 1] = row;
700 tgtAreaInfo.
vr_wr[i] = areaToSend;
703 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tgtAreaInfo, 0 );
705 std::map< int, double > areaAtRow;
706 for(
unsigned i = 0; i < tgtAreaInfo.
get_n(); i++ )
709 int row = tgtAreaInfo.
vi_wr[2 * i + 1];
710 areaAtRow[row] = tgtAreaInfo.
vr_wr[i];
718 for(
unsigned i = 0; i < tlValCol.
get_n(); i++ )
720 int rRowInd = tlValCol.
vi_wr[3 * i + 1];
721 int colInd = tlValCol.
vi_wr[3 * i + 2];
722 double val = tlValCol.
vr_wr[i];
723 int localColInd = colInd - rank * nAbase;
725 auto itMap = areaAtRow.find( rRowInd );
726 if( itMap != areaAtRow.end() )
728 double areaRow = itMap->second;
729 dFracA[localColInd] += val / vecSourceFaceArea[localColInd] * areaRow;
735 NcDim* dimNS = ncMap.add_dim(
"n_s", globuf[2] );
737 NcVar* varRow = ncMap.add_var(
"row", ncInt, dimNS );
738 NcVar* varCol = ncMap.add_var(
"col", ncInt, dimNS );
739 NcVar* varS = ncMap.add_var(
"S", ncDouble, dimNS );
740 #ifdef MOAB_HAVE_NETCDFPAR
741 ncMap.enable_var_par_access( varRow, is_independent );
742 ncMap.enable_var_par_access( varCol, is_independent );
743 ncMap.enable_var_par_access( varS, is_independent );
746 varRow->set_cur( (
long)offbuf[2] );
747 varRow->put( vecRow, nS );
749 varCol->set_cur( (
long)offbuf[2] );
750 varCol->put( vecCol, nS );
752 varS->set_cur( (
long)offbuf[2] );
753 varS->put( &( vecS[0] ), nS );
756 NcVar* varFracA = ncMap.add_var(
"frac_a", ncDouble, dimNA );
757 #ifdef MOAB_HAVE_NETCDFPAR
758 ncMap.enable_var_par_access( varFracA, is_independent );
760 varFracA->add_att(
"name",
"fraction of target coverage of source dof" );
761 varFracA->add_att(
"units",
"unitless" );
762 varFracA->set_cur( (
long)offbuf[0] );
763 varFracA->put( &( dFracA[0] ), nA );
765 NcVar* varFracB = ncMap.add_var(
"frac_b", ncDouble, dimNB );
766 #ifdef MOAB_HAVE_NETCDFPAR
767 ncMap.enable_var_par_access( varFracB, is_independent );
769 varFracB->add_att(
"name",
"fraction of source coverage of target dof" );
770 varFracB->add_att(
"units",
"unitless" );
771 varFracB->set_cur( (
long)offbuf[1] );
772 varFracB->put( &( dFracB[0] ), nB );
803 DataArray1D< double > vecSourceFaceArea, vecTargetFaceArea;
804 DataArray1D< double > dSourceCenterLon, dSourceCenterLat, dTargetCenterLon, dTargetCenterLat;
805 DataArray2D< double > dSourceVertexLon, dSourceVertexLat, dTargetVertexLon, dTargetVertexLat;
806 if( m_srcDiscType == DiscretizationType_FV || m_srcDiscType == DiscretizationType_PCLOUD )
808 this->InitializeCoordinatesFromMeshFV(
809 *m_meshInput, dSourceCenterLon, dSourceCenterLat, dSourceVertexLon, dSourceVertexLat,
811 m_remapper->max_source_edges );
813 vecSourceFaceArea.Allocate( m_meshInput->vecFaceArea.GetRows() );
814 for(
unsigned i = 0; i < m_meshInput->vecFaceArea.GetRows(); ++i )
815 vecSourceFaceArea[i] = m_meshInput->vecFaceArea[i];
819 DataArray3D< double > dataGLLJacobianSrc;
820 this->InitializeCoordinatesFromMeshFE( *m_meshInput, m_nDofsPEl_Src, dataGLLNodesSrc, dSourceCenterLon,
821 dSourceCenterLat, dSourceVertexLon, dSourceVertexLat );
824 GenerateMetaData( *m_meshInput, m_nDofsPEl_Src,
false , dataGLLNodesSrc, dataGLLJacobianSrc );
826 if( m_srcDiscType == DiscretizationType_CGLL )
828 GenerateUniqueJacobian( dataGLLNodesSrc, dataGLLJacobianSrc, vecSourceFaceArea );
832 GenerateDiscontinuousJacobian( dataGLLJacobianSrc, vecSourceFaceArea );
836 if( m_destDiscType == DiscretizationType_FV || m_destDiscType == DiscretizationType_PCLOUD )
838 this->InitializeCoordinatesFromMeshFV(
839 *m_meshOutput, dTargetCenterLon, dTargetCenterLat, dTargetVertexLon, dTargetVertexLat,
841 m_remapper->max_target_edges );
843 vecTargetFaceArea.Allocate( m_meshOutput->vecFaceArea.GetRows() );
844 for(
unsigned i = 0; i < m_meshOutput->vecFaceArea.GetRows(); ++i )
845 vecTargetFaceArea[i] = m_meshOutput->vecFaceArea[i];
849 DataArray3D< double > dataGLLJacobianDest;
850 this->InitializeCoordinatesFromMeshFE( *m_meshOutput, m_nDofsPEl_Dest, dataGLLNodesDest, dTargetCenterLon,
851 dTargetCenterLat, dTargetVertexLon, dTargetVertexLat );
854 GenerateMetaData( *m_meshOutput, m_nDofsPEl_Dest,
false , dataGLLNodesDest, dataGLLJacobianDest );
856 if( m_destDiscType == DiscretizationType_CGLL )
858 GenerateUniqueJacobian( dataGLLNodesDest, dataGLLJacobianDest, vecTargetFaceArea );
862 GenerateDiscontinuousJacobian( dataGLLJacobianDest, vecTargetFaceArea );
867 int tot_src_ents = m_remapper->m_source_entities.size();
868 int tot_tgt_ents = m_remapper->m_target_entities.size();
869 int tot_src_size = dSourceCenterLon.GetRows();
870 int tot_tgt_size = m_dTargetCenterLon.GetRows();
871 int tot_vsrc_size = dSourceVertexLon.GetRows() * dSourceVertexLon.GetColumns();
872 int tot_vtgt_size = m_dTargetVertexLon.GetRows() * m_dTargetVertexLon.GetColumns();
874 const int weightMatNNZ = m_weightMatrix.nonZeros();
875 moab::Tag tagMapMetaData, tagMapIndexRow, tagMapIndexCol, tagMapValues, srcEleIDs, tgtEleIDs;
878 rval = m_interface->tag_get_handle(
"SMAT_ROWS", weightMatNNZ,
moab::MB_TYPE_INTEGER, tagMapIndexRow,
880 rval = m_interface->tag_get_handle(
"SMAT_COLS", weightMatNNZ,
moab::MB_TYPE_INTEGER, tagMapIndexCol,
882 rval = m_interface->tag_get_handle(
"SMAT_VALS", weightMatNNZ,
moab::MB_TYPE_DOUBLE, tagMapValues,
889 rval = m_interface->tag_get_handle(
"SourceAreas", tot_src_size,
moab::MB_TYPE_DOUBLE, srcAreaValues,
891 rval = m_interface->tag_get_handle(
"TargetAreas", tot_tgt_size,
moab::MB_TYPE_DOUBLE, tgtAreaValues,
893 moab::Tag tagSrcCoordsCLon, tagSrcCoordsCLat, tagTgtCoordsCLon, tagTgtCoordsCLat;
894 rval = m_interface->tag_get_handle(
"SourceCoordCenterLon", tot_src_size,
moab::MB_TYPE_DOUBLE, tagSrcCoordsCLon,
896 rval = m_interface->tag_get_handle(
"SourceCoordCenterLat", tot_src_size,
moab::MB_TYPE_DOUBLE, tagSrcCoordsCLat,
898 rval = m_interface->tag_get_handle(
"TargetCoordCenterLon", tot_tgt_size,
moab::MB_TYPE_DOUBLE, tagTgtCoordsCLon,
900 rval = m_interface->tag_get_handle(
"TargetCoordCenterLat", tot_tgt_size,
moab::MB_TYPE_DOUBLE, tagTgtCoordsCLat,
902 moab::Tag tagSrcCoordsVLon, tagSrcCoordsVLat, tagTgtCoordsVLon, tagTgtCoordsVLat;
903 rval = m_interface->tag_get_handle(
"SourceCoordVertexLon", tot_vsrc_size,
moab::MB_TYPE_DOUBLE, tagSrcCoordsVLon,
905 rval = m_interface->tag_get_handle(
"SourceCoordVertexLat", tot_vsrc_size,
moab::MB_TYPE_DOUBLE, tagSrcCoordsVLat,
907 rval = m_interface->tag_get_handle(
"TargetCoordVertexLon", tot_vtgt_size,
moab::MB_TYPE_DOUBLE, tagTgtCoordsVLon,
909 rval = m_interface->tag_get_handle(
"TargetCoordVertexLat", tot_vtgt_size,
moab::MB_TYPE_DOUBLE, tagTgtCoordsVLat,
912 if( m_iSourceMask.IsAttached() )
914 rval = m_interface->tag_get_handle(
"SourceMask", m_iSourceMask.GetRows(),
moab::MB_TYPE_INTEGER, srcMaskValues,
917 if( m_iTargetMask.IsAttached() )
919 rval = m_interface->tag_get_handle(
"TargetMask", m_iTargetMask.GetRows(),
moab::MB_TYPE_INTEGER, tgtMaskValues,
923 std::vector< int > smatrowvals( weightMatNNZ ), smatcolvals( weightMatNNZ );
924 std::vector< double > smatvals( weightMatNNZ );
927 for(
int k = 0, offset = 0; k < m_weightMatrix.outerSize(); ++k )
929 for( moab::TempestOnlineMap::WeightMatrix::InnerIterator it( m_weightMatrix, k ); it; ++it, ++offset )
931 smatrowvals[offset] = this->GetRowGlobalDoF( it.row() );
932 smatcolvals[offset] = this->GetColGlobalDoF( it.col() );
933 smatvals[offset] = it.value();
942 int maxrow = 0, maxcol = 0;
943 std::vector< int > src_global_dofs( tot_src_size ), tgt_global_dofs( tot_tgt_size );
944 for(
int i = 0; i < tot_src_size; ++i )
946 src_global_dofs[i] = srccol_gdofmap[i];
947 maxcol = ( src_global_dofs[i] > maxcol ) ? src_global_dofs[i] : maxcol;
950 for(
int i = 0; i < tot_tgt_size; ++i )
952 tgt_global_dofs[i] = row_gdofmap[i];
953 maxrow = ( tgt_global_dofs[i] > maxrow ) ? tgt_global_dofs[i] : maxrow;
978 int map_disc_details[6];
979 map_disc_details[0] = m_nDofsPEl_Src;
980 map_disc_details[1] = m_nDofsPEl_Dest;
981 map_disc_details[2] = ( m_srcDiscType == DiscretizationType_FV || m_srcDiscType == DiscretizationType_PCLOUD
983 : ( m_srcDiscType == DiscretizationType_CGLL ? 1 : 2 ) );
984 map_disc_details[3] = ( m_destDiscType == DiscretizationType_FV || m_destDiscType == DiscretizationType_PCLOUD
986 : ( m_destDiscType == DiscretizationType_CGLL ? 1 : 2 ) );
987 map_disc_details[4] = ( m_bConserved ? 1 : 0 );
988 map_disc_details[5] = m_iMonotonicity;
991 int loc_smatmetadata[13] = { tot_src_ents,
993 m_remapper->max_source_edges,
994 m_remapper->max_target_edges,
1000 map_disc_details[2],
1001 map_disc_details[3],
1002 map_disc_details[4],
1003 map_disc_details[5] };
1004 rval = m_interface->tag_set_data( tagMapMetaData, &m_meshOverlapSet, 1, &loc_smatmetadata[0] );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1005 int glb_smatmetadata[13] = { 0,
1012 map_disc_details[0],
1013 map_disc_details[1],
1014 map_disc_details[2],
1015 map_disc_details[3],
1016 map_disc_details[4],
1017 map_disc_details[5] };
1019 tot_src_ents, tot_tgt_ents, weightMatNNZ, m_remapper->max_source_edges, m_remapper->max_target_edges,
1021 int glb_buf[4] = { 0, 0, 0, 0 };
1022 MPI_Reduce( &loc_buf[0], &glb_buf[0], 3, MPI_INT, MPI_SUM, 0, m_pcomm->comm() );
1023 glb_smatmetadata[0] = glb_buf[0];
1024 glb_smatmetadata[1] = glb_buf[1];
1025 glb_smatmetadata[6] = glb_buf[2];
1026 MPI_Reduce( &loc_buf[3], &glb_buf[0], 4, MPI_INT, MPI_MAX, 0, m_pcomm->comm() );
1027 glb_smatmetadata[2] = glb_buf[0];
1028 glb_smatmetadata[3] = glb_buf[1];
1029 glb_smatmetadata[4] = glb_buf[2];
1030 glb_smatmetadata[5] = glb_buf[3];
1032 int glb_smatmetadata[13] = { tot_src_ents,
1034 m_remapper->max_source_edges,
1035 m_remapper->max_target_edges,
1039 map_disc_details[0],
1040 map_disc_details[1],
1041 map_disc_details[2],
1042 map_disc_details[3],
1043 map_disc_details[4],
1044 map_disc_details[5] };
1047 glb_smatmetadata[4]++;
1048 glb_smatmetadata[5]++;
1052 std::cout <<
" " << this->rank <<
" Writing remap weights with size [" << glb_smatmetadata[4] <<
" X "
1053 << glb_smatmetadata[5] <<
"] and NNZ = " << glb_smatmetadata[6] << std::endl;
1055 rval = m_interface->tag_set_data( tagMapMetaData, &root_set, 1, &glb_smatmetadata[0] );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1059 const int numval = weightMatNNZ;
1060 const void* smatrowvals_d = smatrowvals.data();
1061 const void* smatcolvals_d = smatcolvals.data();
1062 const void* smatvals_d = smatvals.data();
1063 rval = m_interface->tag_set_by_ptr( tagMapIndexRow, &m_meshOverlapSet, 1, &smatrowvals_d, &numval );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1064 rval = m_interface->tag_set_by_ptr( tagMapIndexCol, &m_meshOverlapSet, 1, &smatcolvals_d, &numval );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1065 rval = m_interface->tag_set_by_ptr( tagMapValues, &m_meshOverlapSet, 1, &smatvals_d, &numval );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1068 const void* srceleidvals_d = src_global_dofs.data();
1069 const void* tgteleidvals_d = tgt_global_dofs.data();
1070 dsize = src_global_dofs.size();
1071 rval = m_interface->tag_set_by_ptr( srcEleIDs, &m_meshOverlapSet, 1, &srceleidvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1072 dsize = tgt_global_dofs.size();
1073 rval = m_interface->tag_set_by_ptr( tgtEleIDs, &m_meshOverlapSet, 1, &tgteleidvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1076 const void* srcareavals_d = vecSourceFaceArea;
1077 const void* tgtareavals_d = vecTargetFaceArea;
1078 dsize = tot_src_size;
1079 rval = m_interface->tag_set_by_ptr( srcAreaValues, &m_meshOverlapSet, 1, &srcareavals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1080 dsize = tot_tgt_size;
1081 rval = m_interface->tag_set_by_ptr( tgtAreaValues, &m_meshOverlapSet, 1, &tgtareavals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1084 const void* srccoordsclonvals_d = &dSourceCenterLon[0];
1085 const void* srccoordsclatvals_d = &dSourceCenterLat[0];
1086 dsize = dSourceCenterLon.GetRows();
1087 rval = m_interface->tag_set_by_ptr( tagSrcCoordsCLon, &m_meshOverlapSet, 1, &srccoordsclonvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1088 rval = m_interface->tag_set_by_ptr( tagSrcCoordsCLat, &m_meshOverlapSet, 1, &srccoordsclatvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1089 const void* tgtcoordsclonvals_d = &m_dTargetCenterLon[0];
1090 const void* tgtcoordsclatvals_d = &m_dTargetCenterLat[0];
1091 dsize = vecTargetFaceArea.GetRows();
1092 rval = m_interface->tag_set_by_ptr( tagTgtCoordsCLon, &m_meshOverlapSet, 1, &tgtcoordsclonvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1093 rval = m_interface->tag_set_by_ptr( tagTgtCoordsCLat, &m_meshOverlapSet, 1, &tgtcoordsclatvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1096 const void* srccoordsvlonvals_d = &( dSourceVertexLon[0][0] );
1097 const void* srccoordsvlatvals_d = &( dSourceVertexLat[0][0] );
1098 dsize = dSourceVertexLon.GetRows() * dSourceVertexLon.GetColumns();
1099 rval = m_interface->tag_set_by_ptr( tagSrcCoordsVLon, &m_meshOverlapSet, 1, &srccoordsvlonvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1100 rval = m_interface->tag_set_by_ptr( tagSrcCoordsVLat, &m_meshOverlapSet, 1, &srccoordsvlatvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1101 const void* tgtcoordsvlonvals_d = &( m_dTargetVertexLon[0][0] );
1102 const void* tgtcoordsvlatvals_d = &( m_dTargetVertexLat[0][0] );
1103 dsize = m_dTargetVertexLon.GetRows() * m_dTargetVertexLon.GetColumns();
1104 rval = m_interface->tag_set_by_ptr( tagTgtCoordsVLon, &m_meshOverlapSet, 1, &tgtcoordsvlonvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1105 rval = m_interface->tag_set_by_ptr( tagTgtCoordsVLat, &m_meshOverlapSet, 1, &tgtcoordsvlatvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1108 if( m_iSourceMask.IsAttached() )
1110 const void* srcmaskvals_d = m_iSourceMask;
1111 dsize = m_iSourceMask.GetRows();
1112 rval = m_interface->tag_set_by_ptr( srcMaskValues, &m_meshOverlapSet, 1, &srcmaskvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1115 if( m_iTargetMask.IsAttached() )
1117 const void* tgtmaskvals_d = m_iTargetMask;
1118 dsize = m_iTargetMask.GetRows();
1119 rval = m_interface->tag_set_by_ptr( tgtMaskValues, &m_meshOverlapSet, 1, &tgtmaskvals_d, &dsize );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1122 #ifdef MOAB_HAVE_MPI
1123 const char* writeOptions = ( this->
size > 1 ?
"PARALLEL=WRITE_PART" :
"" );
1125 const char* writeOptions =
"";
1130 rval = m_interface->write_file( strOutputFile.c_str(), NULL, writeOptions, sets, 1 );
MB_CHK_ERR( rval );
1132 #ifdef WRITE_SCRIP_FILE
1134 sstr << ctx.outFilename.substr( 0, lastindex ) <<
"_" << proc_id <<
".nc";
1135 std::map< std::string, std::string > mapAttributes;
1136 mapAttributes[
"Creator"] =
"MOAB mbtempest workflow";
1137 if( !ctx.proc_id ) std::cout <<
"Writing offline map to file: " << sstr.str() << std::endl;
1138 this->Write( strOutputFile.c_str(), mapAttributes, NcFile::Netcdf4 );
1149 std::cout << message <<
" [";
1150 int pos = barWidth * progress;
1151 for(
int i = 0; i < barWidth; ++i )
1160 std::cout <<
"] " << int( progress * 100.0 ) <<
" %\r";
1166 const std::vector< int >& owned_dof_ids,
1167 bool row_partition )
1169 NcError
error( NcError::silent_nonfatal );
1171 NcVar *varRow = NULL, *varCol = NULL, *varS = NULL;
1172 int nS = 0, nA = 0, nB = 0;
1173 #ifdef MOAB_HAVE_PNETCDF
1175 int ncfile = -1, ret = 0;
1176 int ndims, nvars, ngatts, unlimited;
1178 #ifdef MOAB_HAVE_NETCDFPAR
1179 bool is_independent =
true;
1180 ParNcFile ncMap( m_pcomm->comm(), MPI_INFO_NULL, strSource, NcFile::ReadOnly, NcFile::Netcdf4 );
1183 NcFile ncMap( strSource, NcFile::ReadOnly );
1186 #define CHECK_EXCEPTION( obj, type, varstr ) \
1190 _EXCEPTION3( "Map file \"%s\" does not contain %s \"%s\"", strSource, type, varstr ); \
1196 if( ncMap.is_valid() )
1198 NcDim* dimNS = ncMap.get_dim(
"n_s" );
1201 NcDim* dimNA = ncMap.get_dim(
"n_a" );
1204 NcDim* dimNB = ncMap.get_dim(
"n_b" );
1212 varRow = ncMap.get_var(
"row" );
1215 varCol = ncMap.get_var(
"col" );
1218 varS = ncMap.get_var(
"S" );
1221 #ifdef MOAB_HAVE_NETCDFPAR
1222 ncMap.enable_var_par_access( varRow, is_independent );
1223 ncMap.enable_var_par_access( varCol, is_independent );
1224 ncMap.enable_var_par_access( varS, is_independent );
1229 #ifdef MOAB_HAVE_PNETCDF
1233 ret = ncmpi_open( m_pcomm->comm(), strSource, NC_NOWRITE, MPI_INFO_NULL, &ncfile );
1235 ret = ncmpi_inq( ncfile, &ndims, &nvars, &ngatts, &unlimited );
1239 ret = ncmpi_inq_dimid( ncfile,
"n_s", &ins );
1242 ret = ncmpi_inq_dimlen( ncfile, ins, &leng );
1245 ret = ncmpi_inq_dimid( ncfile,
"n_b", &ins );
1247 ret = ncmpi_inq_dimlen( ncfile, ins, &leng );
1251 _EXCEPTION1(
"cannot read the file %s", strSource );
1256 SparseMatrix< double >& sparseMatrix = this->GetSparseMatrix();
1258 int localSize = nS /
size;
1259 long offsetRead = rank * localSize;
1261 if( rank ==
size - 1 )
1263 localSize += nS %
size;
1266 std::vector< int > vecRow, vecCol;
1267 std::vector< double > vecS;
1268 vecRow.resize( localSize );
1269 vecCol.resize( localSize );
1270 vecS.resize( localSize );
1272 if( ncMap.is_valid() )
1274 varRow->set_cur( (
long)( offsetRead ) );
1275 varRow->get( &( vecRow[0] ), localSize );
1277 varCol->set_cur( (
long)( offsetRead ) );
1278 varCol->get( &( vecCol[0] ), localSize );
1280 varS->set_cur( (
long)( offsetRead ) );
1281 varS->get( &( vecS[0] ), localSize );
1287 #ifdef MOAB_HAVE_PNETCDF
1289 MPI_Offset start = (MPI_Offset)offsetRead;
1290 MPI_Offset count = (MPI_Offset)localSize;
1292 ret = ncmpi_inq_varid( ncfile,
"S", &varid );
1294 ret = ncmpi_get_vara_double_all( ncfile, varid, &start, &count, &vecS[0] );
1296 ret = ncmpi_inq_varid( ncfile,
"row", &varid );
1298 ret = ncmpi_get_vara_int_all( ncfile, varid, &start, &count, &vecRow[0] );
1300 ret = ncmpi_inq_varid( ncfile,
"col", &varid );
1302 ret = ncmpi_get_vara_int_all( ncfile, varid, &start, &count, &vecCol[0] );
1304 ret = ncmpi_close( ncfile );
1311 row_dtoc_dofmap.clear();
1313 col_dtoc_dofmap.clear();
1320 #ifdef MOAB_HAVE_MPI
1325 std::vector< int > ownership;
1328 if( !row_partition ) nDofs = nA;
1331 ownership.resize(
size );
1332 int nPerPart = nDofs /
size;
1333 int nRemainder = nDofs %
size;
1334 ownership[0] = nPerPart + nRemainder;
1335 for(
int ip = 1, roffset = ownership[0]; ip <
size; ++ip )
1337 roffset += nPerPart;
1338 ownership[ip] = roffset;
1345 for(
int i = 0; i < localSize; i++ )
1347 int rowval = vecRow[i] - 1;
1348 int colval = vecCol[i] - 1;
1350 int dof_val = colval;
1351 if( row_partition ) dof_val = rowval;
1353 if( ownership[0] > dof_val )
1357 for(
int ip = 1; ip <
size; ++ip )
1359 if( ownership[ip - 1] <= dof_val && ownership[ip] > dof_val )
1367 int n = tl->
get_n();
1368 tl->
vi_wr[3 * n] = to_proc;
1369 tl->
vi_wr[3 * n + 1] = rowval;
1370 tl->
vi_wr[3 * n + 2] = colval;
1371 tl->
vr_wr[n] = vecS[i];
1375 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, *tl, 0 );
1377 if( owned_dof_ids.size() > 0 )
1381 tl_re.
initialize( 2, 0, 0, 0, owned_dof_ids.size() );
1385 for(
size_t i = 0; i < owned_dof_ids.size(); i++ )
1388 int dof_val = owned_dof_ids[i] - 1;
1390 if( ownership[0] > dof_val )
1394 for(
int ip = 1; ip <
size; ++ip )
1396 if( ownership[ip - 1] <= dof_val && ownership[ip] > dof_val )
1404 int n = tl_re.
get_n();
1405 tl_re.
vi_wr[2 * n] = to_proc;
1406 tl_re.
vi_wr[2 * n + 1] = dof_val;
1410 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tl_re, 0 );
1413 sort_buffer.buffer_init( tl_re.
get_n() );
1414 tl_re.
sort( 1, &sort_buffer );
1416 sort_buffer.buffer_init( tl->
get_n() );
1418 if( row_partition ) indexOrder = 1;
1421 std::map< int, int > startDofIndex, endDofIndex;
1423 if( tl_re.
get_n() > 0 ) dofVal = tl_re.
vi_rd[1];
1424 startDofIndex[dofVal] = 0;
1425 endDofIndex[dofVal] = 0;
1426 for(
unsigned k = 1; k < tl_re.
get_n(); k++ )
1428 int newDof = tl_re.
vi_rd[2 * k + 1];
1429 if( dofVal == newDof )
1431 endDofIndex[dofVal] = k;
1436 startDofIndex[dofVal] = k;
1437 endDofIndex[dofVal] = k;
1454 for(
unsigned k = 0; k < tl->
get_n(); k++ )
1456 int valDof = tl->
vi_rd[3 * k + indexOrder];
1457 for(
int ire = startDofIndex[valDof]; ire <= endDofIndex[valDof]; ire++ )
1459 int to_proc = tl_re.
vi_rd[2 * ire];
1460 int n = tl_back->
get_n();
1461 tl_back->
vi_wr[3 * n] = to_proc;
1462 tl_back->
vi_wr[3 * n + 1] = tl->
vi_rd[3 * k + 1];
1463 tl_back->
vi_wr[3 * n + 2] = tl->
vi_rd[3 * k + 2];
1470 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, *tl_back, 0 );
1477 int rindexMax = 0, cindexMax = 0;
1479 int n = tl->
get_n();
1480 for(
int i = 0; i < n; i++ )
1483 const int& vecRowValue = tl->
vi_wr[3 * i + 1];
1484 const int& vecColValue = tl->
vi_wr[3 * i + 2];
1486 std::map< int, int >::iterator riter = rowMap.find( vecRowValue );
1487 if( riter == rowMap.end() )
1489 rowMap[vecRowValue] = rindexMax;
1491 row_gdofmap.push_back( vecRowValue );
1496 rindex = riter->second;
1498 std::map< int, int >::iterator citer = colMap.find( vecColValue );
1499 if( citer == colMap.end() )
1501 colMap[vecColValue] = cindexMax;
1503 col_gdofmap.push_back( vecColValue );
1508 cindex = citer->second;
1510 sparseMatrix( rindex, cindex ) = tl->
vr_wr[i];
1517 int rindexMax = 0, cindexMax = 0;
1519 for(
int i = 0; i < nS; i++ )
1522 const int& vecRowValue = vecRow[i] - 1;
1523 const int& vecColValue = vecCol[i] - 1;
1525 std::map< int, int >::iterator riter = rowMap.find( vecRowValue );
1526 if( riter == rowMap.end() )
1528 rowMap[vecRowValue] = rindexMax;
1530 row_gdofmap.push_back( vecRowValue );
1535 rindex = riter->second;
1537 std::map< int, int >::iterator citer = colMap.find( vecColValue );
1538 if( citer == colMap.end() )
1540 colMap[vecColValue] = cindexMax;
1542 col_gdofmap.push_back( vecColValue );
1547 cindex = citer->second;
1549 sparseMatrix( rindex, cindex ) = vecS[i];
1553 m_nTotDofs_SrcCov = sparseMatrix.GetColumns();
1554 m_nTotDofs_Dest = sparseMatrix.GetRows();
1556 #ifdef MOAB_HAVE_EIGEN3
1557 this->copy_tempest_sparsemat_to_eigen3();
1561 m_rowVector.setZero();
1562 m_colVector.setZero();