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 #ifdef MOAB_HAVE_EIGEN3
52 template <
typename SparseMatrixType >
55 std::ofstream ofs( filename );
58 std::cerr <<
"Failed to open file for writing: " << filename << std::endl;
63 int rows = mat.rows();
64 int cols = mat.cols();
65 typename SparseMatrixType::Index nnz = mat.nonZeros();
66 ofs << rows <<
" " << cols <<
" " << nnz <<
"\n";
69 for(
int k = 0; k < mat.outerSize(); ++k )
71 for(
typename SparseMatrixType::InnerIterator it( mat, k ); it; ++it )
77 auto value = it.value();
78 ofs << row <<
" " << col <<
" " << value <<
"\n";
86 int moab::TempestOnlineMap::rearrange_arrays_by_dofs(
const std::vector< unsigned int >& gdofmap,
87 DataArray1D< double >& vecFaceArea,
88 DataArray1D< double >& dCenterLon,
89 DataArray1D< double >& dCenterLat,
90 DataArray2D< double >& dVertexLon,
91 DataArray2D< double >& dVertexLat,
92 std::vector< int >& masks,
98 unsigned int localmax = 0;
99 for(
unsigned i = 0; i < N; i++ )
100 if( gdofmap[i] > localmax ) localmax = gdofmap[i];
103 MPI_Allreduce( &localmax, &maxdof, 1, MPI_INT, MPI_MAX, m_pcomm->comm() );
106 int size_per_task = ( maxdof + 1 ) / size;
109 unsigned numr = 2 * nv + 3;
113 for(
unsigned i = 0; i < N; i++ )
115 int gdof = gdofmap[i];
116 int to_proc = gdof / size_per_task;
118 if( to_proc >= size ) to_proc = size - 1;
120 tl.
vi_wr[3 * n] = to_proc;
121 tl.
vi_wr[3 * n + 1] = gdof;
122 tl.
vi_wr[3 * n + 2] = mask;
123 tl.
vr_wr[n * numr] = vecFaceArea[i];
124 tl.
vr_wr[n * numr + 1] = dCenterLon[i];
125 tl.
vr_wr[n * numr + 2] = dCenterLat[i];
126 for(
int j = 0; j < nv; j++ )
128 tl.
vr_wr[n * numr + 3 + j] = dVertexLon[i][j];
129 tl.
vr_wr[n * numr + 3 + nv + j] = dVertexLat[i][j];
135 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tl, 0 );
140 sort_buffer.buffer_init( tl.
get_n() );
141 tl.
sort( 1, &sort_buffer );
144 for(
unsigned i = 0; i < tl.
get_n() - 1; i++ )
146 if( tl.
vi_wr[3 * i + 1] != tl.
vi_wr[3 * i + 4] ) nb_unique++;
148 vecFaceArea.Allocate( nb_unique );
149 dCenterLon.Allocate( nb_unique );
150 dCenterLat.Allocate( nb_unique );
151 dVertexLon.Allocate( nb_unique, nv );
152 dVertexLat.Allocate( nb_unique, nv );
153 masks.resize( nb_unique );
154 int current_size = 1;
155 vecFaceArea[0] = tl.
vr_wr[0];
156 dCenterLon[0] = tl.
vr_wr[1];
157 dCenterLat[0] = tl.
vr_wr[2];
158 masks[0] = tl.
vi_wr[2];
159 for(
int j = 0; j < nv; j++ )
161 dVertexLon[0][j] = tl.
vr_wr[3 + j];
162 dVertexLat[0][j] = tl.
vr_wr[3 + nv + j];
164 for(
unsigned i = 0; i < tl.
get_n() - 1; i++ )
167 if( tl.
vi_wr[3 * i + 1] != tl.
vi_wr[3 * i + 4] )
169 vecFaceArea[current_size] = tl.
vr_wr[i1 * numr];
170 dCenterLon[current_size] = tl.
vr_wr[i1 * numr + 1];
171 dCenterLat[current_size] = tl.
vr_wr[i1 * numr + 2];
172 for(
int j = 0; j < nv; j++ )
174 dVertexLon[current_size][j] = tl.
vr_wr[i1 * numr + 3 + j];
175 dVertexLat[current_size][j] = tl.
vr_wr[i1 * numr + 3 + nv + j];
177 masks[current_size] = tl.
vi_wr[3 * i1 + 2];
182 vecFaceArea[current_size - 1] += tl.
vr_wr[i1 * numr];
194 const std::map< std::string, std::string >& attrMap )
196 size_t lastindex = strFilename.find_last_of(
"." );
197 std::string extension = strFilename.substr( lastindex + 1, strFilename.size() );
200 if( extension ==
"nc" )
203 MB_CHK_ERR( this->WriteSCRIPMapFile( strFilename.c_str(), attrMap ) );
208 MB_CHK_ERR( this->WriteHDF5MapFile( strFilename.c_str() ) );
217 const std::map< std::string, std::string >& attrMap )
219 NcError
error( NcError::silent_nonfatal );
221 #ifdef MOAB_HAVE_NETCDFPAR
222 bool is_independent =
true;
223 ParNcFile ncMap( m_pcomm->comm(), MPI_INFO_NULL, strFilename.c_str(), NcFile::Replace, NcFile::Netcdf4 );
226 NcFile ncMap( strFilename.c_str(), NcFile::Replace );
229 if( !ncMap.is_valid() )
231 _EXCEPTION1(
"Unable to open output map file \"%s\"", strFilename.c_str() );
236 auto it = attrMap.begin();
237 while( it != attrMap.end() )
240 ncMap.add_att( it->first.c_str(), it->second.c_str() );
254 DataArray1D< double > vecSourceFaceArea, vecTargetFaceArea;
255 DataArray1D< double > dSourceCenterLon, dSourceCenterLat, dTargetCenterLon, dTargetCenterLat;
256 DataArray2D< double > dSourceVertexLon, dSourceVertexLat, dTargetVertexLon, dTargetVertexLat;
257 if( m_srcDiscType == DiscretizationType_FV || m_srcDiscType == DiscretizationType_PCLOUD )
259 this->InitializeCoordinatesFromMeshFV(
260 *m_meshInput, dSourceCenterLon, dSourceCenterLat, dSourceVertexLon, dSourceVertexLat,
262 m_remapper->max_source_edges );
264 vecSourceFaceArea.Allocate( m_meshInput->vecFaceArea.GetRows() );
265 for(
unsigned i = 0; i < m_meshInput->vecFaceArea.GetRows(); ++i )
266 vecSourceFaceArea[i] = m_meshInput->vecFaceArea[i];
270 DataArray3D< double > dataGLLJacobianSrc;
271 this->InitializeCoordinatesFromMeshFE( *m_meshInput, m_nDofsPEl_Src, dataGLLNodesSrc, dSourceCenterLon,
272 dSourceCenterLat, dSourceVertexLon, dSourceVertexLat );
275 GenerateMetaData( *m_meshInput, m_nDofsPEl_Src,
false , dataGLLNodesSrc, dataGLLJacobianSrc );
277 if( m_srcDiscType == DiscretizationType_CGLL )
279 GenerateUniqueJacobian( dataGLLNodesSrc, dataGLLJacobianSrc, vecSourceFaceArea );
283 GenerateDiscontinuousJacobian( dataGLLJacobianSrc, vecSourceFaceArea );
287 if( m_destDiscType == DiscretizationType_FV || m_destDiscType == DiscretizationType_PCLOUD )
289 this->InitializeCoordinatesFromMeshFV(
290 *m_meshOutput, dTargetCenterLon, dTargetCenterLat, dTargetVertexLon, dTargetVertexLat,
292 m_remapper->max_target_edges );
294 vecTargetFaceArea.Allocate( m_meshOutput->vecFaceArea.GetRows() );
295 for(
unsigned i = 0; i < m_meshOutput->vecFaceArea.GetRows(); ++i )
297 vecTargetFaceArea[i] = m_meshOutput->vecFaceArea[i];
302 DataArray3D< double > dataGLLJacobianDest;
303 this->InitializeCoordinatesFromMeshFE( *m_meshOutput, m_nDofsPEl_Dest, dataGLLNodesDest, dTargetCenterLon,
304 dTargetCenterLat, dTargetVertexLon, dTargetVertexLat );
307 GenerateMetaData( *m_meshOutput, m_nDofsPEl_Dest,
false , dataGLLNodesDest, dataGLLJacobianDest );
309 if( m_destDiscType == DiscretizationType_CGLL )
311 GenerateUniqueJacobian( dataGLLNodesDest, dataGLLJacobianDest, vecTargetFaceArea );
315 GenerateDiscontinuousJacobian( dataGLLJacobianDest, vecTargetFaceArea );
320 unsigned nA = ( vecSourceFaceArea.GetRows() );
321 unsigned nB = ( vecTargetFaceArea.GetRows() );
323 std::vector< int > masksA, masksB;
328 int nSourceNodesPerFace = dSourceVertexLon.GetColumns();
329 int nTargetNodesPerFace = dTargetVertexLon.GetColumns();
335 for(
unsigned i = 0; i < nA; i++ )
337 const Face&
face = m_meshInput->faces[i];
339 int nNodes =
face.edges.size();
340 int indexNodeAtPole = -1;
343 for(
int j = 0; j < nNodes; j++ )
344 if( fabs( fabs( dSourceVertexLat[i][j] ) - 90.0 ) < 1.0e-12 )
350 if( indexNodeAtPole < 0 )
continue;
352 int nodeAtPole =
face[indexNodeAtPole];
353 Node nodePole = m_meshInput->nodes[nodeAtPole];
354 Node newCenter = nodePole * 2;
355 for(
int j = 1; j < nNodes; j++ )
357 int indexi = ( indexNodeAtPole + j ) % nNodes;
358 const Node& node = m_meshInput->nodes[
face[indexi]];
359 newCenter = newCenter + node;
361 newCenter = newCenter * 0.25;
362 newCenter = newCenter.Normalized();
365 double iniLon = dSourceCenterLon[i], iniLat = dSourceCenterLat[i];
368 XYZtoRLL_Deg( newCenter.x, newCenter.y, newCenter.z, dSourceCenterLon[i], dSourceCenterLat[i] );
370 std::cout <<
" modify center of triangle from " << iniLon <<
" " << iniLat <<
" to " << dSourceCenterLon[i]
371 <<
" " << dSourceCenterLat[i] <<
"\n";
376 #if defined( MOAB_HAVE_MPI )
377 int max_row_dof, max_col_dof;
380 int ierr = rearrange_arrays_by_dofs( srccol_gdofmap, vecSourceFaceArea, dSourceCenterLon, dSourceCenterLat,
381 dSourceVertexLon, dSourceVertexLat, masksA, nA, nSourceNodesPerFace,
385 _EXCEPTION1(
"Unable to arrange source data %d ", nA );
389 ierr = rearrange_arrays_by_dofs( row_gdofmap, vecTargetFaceArea, dTargetCenterLon, dTargetCenterLat,
390 dTargetVertexLon, dTargetVertexLat, masksB, nB, nTargetNodesPerFace,
394 _EXCEPTION1(
"Unable to arrange target data %d ", nB );
400 int nS = m_weightMatrix.nonZeros();
402 #if defined( MOAB_HAVE_MPI ) && defined( MOAB_HAVE_NETCDFPAR )
403 int locbuf[5] = { (int)nA, (
int)nB, nS, nSourceNodesPerFace, nTargetNodesPerFace };
404 int offbuf[3] = { 0, 0, 0 };
405 int globuf[5] = { 0, 0, 0, 0, 0 };
406 MPI_Scan( locbuf, offbuf, 3, MPI_INT, MPI_SUM, m_pcomm->comm() );
407 MPI_Allreduce( locbuf, globuf, 3, MPI_INT, MPI_SUM, m_pcomm->comm() );
408 MPI_Allreduce( &locbuf[3], &globuf[3], 2, MPI_INT, MPI_MAX, m_pcomm->comm() );
416 int offbuf[3] = { 0, 0, 0 };
417 int globuf[5] = { (int)nA, (
int)nB, nS, nSourceNodesPerFace, nTargetNodesPerFace };
420 std::vector< std::string > srcdimNames, tgtdimNames;
421 std::vector< int > srcdimSizes, tgtdimSizes;
425 srcdimNames.push_back(
"lat" );
426 srcdimNames.push_back(
"lon" );
427 srcdimSizes.resize( 2, 0 );
428 srcdimSizes[0] = m_remapper->m_source_metadata[0];
429 srcdimSizes[1] = m_remapper->m_source_metadata[1];
433 srcdimNames.push_back(
"num_elem" );
434 srcdimSizes.push_back( globuf[0] );
439 tgtdimNames.push_back(
"lat" );
440 tgtdimNames.push_back(
"lon" );
441 tgtdimSizes.resize( 2, 0 );
442 tgtdimSizes[0] = m_remapper->m_target_metadata[0];
443 tgtdimSizes[1] = m_remapper->m_target_metadata[1];
447 tgtdimNames.push_back(
"num_elem" );
448 tgtdimSizes.push_back( globuf[1] );
453 unsigned nSrcGridDims = ( srcdimSizes.size() );
454 unsigned nDstGridDims = ( tgtdimSizes.size() );
456 NcDim* dimSrcGridRank = ncMap.add_dim(
"src_grid_rank", nSrcGridDims );
457 NcDim* dimDstGridRank = ncMap.add_dim(
"dst_grid_rank", nDstGridDims );
459 NcVar* varSrcGridDims = ncMap.add_var(
"src_grid_dims", ncInt, dimSrcGridRank );
460 NcVar* varDstGridDims = ncMap.add_var(
"dst_grid_dims", ncInt, dimDstGridRank );
462 #ifdef MOAB_HAVE_NETCDFPAR
463 ncMap.enable_var_par_access( varSrcGridDims, is_independent );
464 ncMap.enable_var_par_access( varDstGridDims, is_independent );
470 for(
unsigned i = 0; i < srcdimSizes.size(); i++ )
472 varSrcGridDims->set_cur( nSrcGridDims - i - 1 );
473 varSrcGridDims->put( &( srcdimSizes[nSrcGridDims - i - 1] ), 1 );
476 for(
unsigned i = 0; i < srcdimSizes.size(); i++ )
478 snprintf( szDim, 64,
"name%i", i );
479 varSrcGridDims->add_att( szDim, srcdimNames[nSrcGridDims - i - 1].c_str() );
482 for(
unsigned i = 0; i < tgtdimSizes.size(); i++ )
484 varDstGridDims->set_cur( nDstGridDims - i - 1 );
485 varDstGridDims->put( &( tgtdimSizes[nDstGridDims - i - 1] ), 1 );
488 for(
unsigned i = 0; i < tgtdimSizes.size(); i++ )
490 snprintf( szDim, 64,
"name%i", i );
491 varDstGridDims->add_att( szDim, tgtdimNames[nDstGridDims - i - 1].c_str() );
496 NcDim* dimNA = ncMap.add_dim(
"n_a", globuf[0] );
497 NcDim* dimNB = ncMap.add_dim(
"n_b", globuf[1] );
500 NcDim* dimNVA = ncMap.add_dim(
"nv_a", globuf[3] );
501 NcDim* dimNVB = ncMap.add_dim(
"nv_b", globuf[4] );
504 NcVar* varYCA = ncMap.add_var(
"yc_a", ncDouble, dimNA );
505 NcVar* varYCB = ncMap.add_var(
"yc_b", ncDouble, dimNB );
507 NcVar* varXCA = ncMap.add_var(
"xc_a", ncDouble, dimNA );
508 NcVar* varXCB = ncMap.add_var(
"xc_b", ncDouble, dimNB );
510 NcVar* varYVA = ncMap.add_var(
"yv_a", ncDouble, dimNA, dimNVA );
511 NcVar* varYVB = ncMap.add_var(
"yv_b", ncDouble, dimNB, dimNVB );
513 NcVar* varXVA = ncMap.add_var(
"xv_a", ncDouble, dimNA, dimNVA );
514 NcVar* varXVB = ncMap.add_var(
"xv_b", ncDouble, dimNB, dimNVB );
517 NcVar* varMaskA = ncMap.add_var(
"mask_a", ncInt, dimNA );
518 NcVar* varMaskB = ncMap.add_var(
"mask_b", ncInt, dimNB );
520 #ifdef MOAB_HAVE_NETCDFPAR
521 ncMap.enable_var_par_access( varYCA, is_independent );
522 ncMap.enable_var_par_access( varYCB, is_independent );
523 ncMap.enable_var_par_access( varXCA, is_independent );
524 ncMap.enable_var_par_access( varXCB, is_independent );
525 ncMap.enable_var_par_access( varYVA, is_independent );
526 ncMap.enable_var_par_access( varYVB, is_independent );
527 ncMap.enable_var_par_access( varXVA, is_independent );
528 ncMap.enable_var_par_access( varXVB, is_independent );
529 ncMap.enable_var_par_access( varMaskA, is_independent );
530 ncMap.enable_var_par_access( varMaskB, is_independent );
533 varYCA->add_att(
"units",
"degrees" );
534 varYCB->add_att(
"units",
"degrees" );
536 varXCA->add_att(
"units",
"degrees" );
537 varXCB->add_att(
"units",
"degrees" );
539 varYVA->add_att(
"units",
"degrees" );
540 varYVB->add_att(
"units",
"degrees" );
542 varXVA->add_att(
"units",
"degrees" );
543 varXVB->add_att(
"units",
"degrees" );
546 if( dSourceCenterLon.GetRows() != nA )
548 _EXCEPTIONT(
"Mismatch between dSourceCenterLon and nA" );
550 if( dSourceCenterLat.GetRows() != nA )
552 _EXCEPTIONT(
"Mismatch between dSourceCenterLat and nA" );
554 if( dTargetCenterLon.GetRows() != nB )
556 _EXCEPTIONT(
"Mismatch between dTargetCenterLon and nB" );
558 if( dTargetCenterLat.GetRows() != nB )
560 _EXCEPTIONT(
"Mismatch between dTargetCenterLat and nB" );
562 if( dSourceVertexLon.GetRows() != nA )
564 _EXCEPTIONT(
"Mismatch between dSourceVertexLon and nA" );
566 if( dSourceVertexLat.GetRows() != nA )
568 _EXCEPTIONT(
"Mismatch between dSourceVertexLat and nA" );
570 if( dTargetVertexLon.GetRows() != nB )
572 _EXCEPTIONT(
"Mismatch between dTargetVertexLon and nB" );
574 if( dTargetVertexLat.GetRows() != nB )
576 _EXCEPTIONT(
"Mismatch between dTargetVertexLat and nB" );
579 varYCA->set_cur( (
long)offbuf[0] );
580 varYCA->put( &( dSourceCenterLat[0] ), nA );
581 varYCB->set_cur( (
long)offbuf[1] );
582 varYCB->put( &( dTargetCenterLat[0] ), nB );
584 varXCA->set_cur( (
long)offbuf[0] );
585 varXCA->put( &( dSourceCenterLon[0] ), nA );
586 varXCB->set_cur( (
long)offbuf[1] );
587 varXCB->put( &( dTargetCenterLon[0] ), nB );
589 varYVA->set_cur( (
long)offbuf[0] );
590 varYVA->put( &( dSourceVertexLat[0][0] ), nA, nSourceNodesPerFace );
591 varYVB->set_cur( (
long)offbuf[1] );
592 varYVB->put( &( dTargetVertexLat[0][0] ), nB, nTargetNodesPerFace );
594 varXVA->set_cur( (
long)offbuf[0] );
595 varXVA->put( &( dSourceVertexLon[0][0] ), nA, nSourceNodesPerFace );
596 varXVB->set_cur( (
long)offbuf[1] );
597 varXVB->put( &( dTargetVertexLon[0][0] ), nB, nTargetNodesPerFace );
599 varMaskA->set_cur( (
long)offbuf[0] );
600 varMaskA->put( &( masksA[0] ), nA );
601 varMaskB->set_cur( (
long)offbuf[1] );
602 varMaskB->put( &( masksB[0] ), nB );
605 NcVar* varAreaA = ncMap.add_var(
"area_a", ncDouble, dimNA );
606 #ifdef MOAB_HAVE_NETCDFPAR
607 ncMap.enable_var_par_access( varAreaA, is_independent );
609 varAreaA->set_cur( (
long)offbuf[0] );
610 varAreaA->put( &( vecSourceFaceArea[0] ), nA );
612 NcVar* varAreaB = ncMap.add_var(
"area_b", ncDouble, dimNB );
613 #ifdef MOAB_HAVE_NETCDFPAR
614 ncMap.enable_var_par_access( varAreaB, is_independent );
616 varAreaB->set_cur( (
long)offbuf[1] );
617 varAreaB->put( &( vecTargetFaceArea[0] ), nB );
620 DataArray1D< int > vecRow( nS );
621 DataArray1D< int > vecCol( nS );
622 DataArray1D< double > vecS( nS );
623 DataArray1D< double > dFracA( nA );
624 DataArray1D< double > dFracB( nB );
640 #if defined( MOAB_HAVE_MPI )
641 int nAbase = ( max_col_dof + 1 ) / size;
642 int nBbase = ( max_row_dof + 1 ) / size;
644 for(
int i = 0; i < m_weightMatrix.outerSize(); ++i )
646 for( WeightMatrix::InnerIterator it( m_weightMatrix, i ); it; ++it )
648 vecRow[offset] = 1 + this->GetRowGlobalDoF( it.row() );
649 vecCol[offset] = 1 + this->GetColGlobalDoF( it.col() );
650 vecS[offset] = it.value();
652 #if defined( MOAB_HAVE_MPI )
655 int procRow = ( vecRow[offset] - 1 ) / nBbase;
656 if( procRow >= size ) procRow = size - 1;
657 int procCol = ( vecCol[offset] - 1 ) / nAbase;
658 if( procCol >= size ) procCol = size - 1;
659 int nrInd = tlValRow.
get_n();
660 tlValRow.
vi_wr[2 * nrInd] = procRow;
661 tlValRow.
vi_wr[2 * nrInd + 1] = vecRow[offset] - 1;
662 tlValRow.
vr_wr[nrInd] = vecS[offset];
664 int ncInd = tlValCol.
get_n();
665 tlValCol.
vi_wr[3 * ncInd] = procCol;
666 tlValCol.
vi_wr[3 * ncInd + 1] = vecRow[offset] - 1;
667 tlValCol.
vi_wr[3 * ncInd + 2] = vecCol[offset] - 1;
668 tlValCol.
vr_wr[ncInd] = vecS[offset];
676 #if defined( MOAB_HAVE_MPI )
679 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tlValCol, 0 );
680 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tlValRow, 0 );
686 for(
unsigned i = 0; i < tlValRow.
get_n(); i++ )
689 int gRowInd = tlValRow.
vi_wr[2 * i + 1];
690 int localIndexRow = gRowInd - nBbase * rank;
691 double wgt = tlValRow.
vr_wr[i];
692 assert( localIndexRow >= 0 );
693 assert( nB - localIndexRow > 0 );
694 dFracB[localIndexRow] += wgt;
698 std::set< int > neededRows;
699 for(
unsigned i = 0; i < tlValCol.
get_n(); i++ )
701 int rRowInd = tlValCol.
vi_wr[3 * i + 1];
702 neededRows.insert( rRowInd );
706 tgtAreaReq.
initialize( 2, 0, 0, 0, neededRows.size() );
708 for( std::set< int >::iterator sit = neededRows.begin(); sit != neededRows.end(); sit++ )
710 int neededRow = *sit;
711 int procRow = neededRow / nBbase;
712 if( procRow >= size ) procRow = size - 1;
713 int nr = tgtAreaReq.
get_n();
714 tgtAreaReq.
vi_wr[2 * nr] = procRow;
715 tgtAreaReq.
vi_wr[2 * nr + 1] = neededRow;
719 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tgtAreaReq, 0 );
724 for(
unsigned i = 0; i < tgtAreaReq.
get_n(); i++ )
726 int from_proc = tgtAreaReq.
vi_wr[2 * i];
727 int row = tgtAreaReq.
vi_wr[2 * i + 1];
728 int locaIndexRow = row - rank * nBbase;
729 double areaToSend = vecTargetFaceArea[locaIndexRow];
732 tgtAreaInfo.
vi_wr[2 * i] = from_proc;
733 tgtAreaInfo.
vi_wr[2 * i + 1] = row;
734 tgtAreaInfo.
vr_wr[i] = areaToSend;
737 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tgtAreaInfo, 0 );
739 std::map< int, double > areaAtRow;
740 for(
unsigned i = 0; i < tgtAreaInfo.
get_n(); i++ )
743 int row = tgtAreaInfo.
vi_wr[2 * i + 1];
744 areaAtRow[row] = tgtAreaInfo.
vr_wr[i];
752 for(
unsigned i = 0; i < tlValCol.
get_n(); i++ )
754 int rRowInd = tlValCol.
vi_wr[3 * i + 1];
755 int colInd = tlValCol.
vi_wr[3 * i + 2];
756 double val = tlValCol.
vr_wr[i];
757 int localColInd = colInd - rank * nAbase;
759 auto itMap = areaAtRow.find( rRowInd );
760 if( itMap != areaAtRow.end() )
762 double areaRow = itMap->second;
763 dFracA[localColInd] += val / vecSourceFaceArea[localColInd] * areaRow;
769 NcDim* dimNS = ncMap.add_dim(
"n_s", globuf[2] );
771 NcVar* varRow = ncMap.add_var(
"row", ncInt, dimNS );
772 NcVar* varCol = ncMap.add_var(
"col", ncInt, dimNS );
773 NcVar* varS = ncMap.add_var(
"S", ncDouble, dimNS );
774 #ifdef MOAB_HAVE_NETCDFPAR
775 ncMap.enable_var_par_access( varRow, is_independent );
776 ncMap.enable_var_par_access( varCol, is_independent );
777 ncMap.enable_var_par_access( varS, is_independent );
780 varRow->set_cur( (
long)offbuf[2] );
781 varRow->put( vecRow, nS );
783 varCol->set_cur( (
long)offbuf[2] );
784 varCol->put( vecCol, nS );
786 varS->set_cur( (
long)offbuf[2] );
787 varS->put( &( vecS[0] ), nS );
790 NcVar* varFracA = ncMap.add_var(
"frac_a", ncDouble, dimNA );
791 #ifdef MOAB_HAVE_NETCDFPAR
792 ncMap.enable_var_par_access( varFracA, is_independent );
794 varFracA->add_att(
"name",
"fraction of target coverage of source dof" );
795 varFracA->add_att(
"units",
"unitless" );
796 varFracA->set_cur( (
long)offbuf[0] );
797 varFracA->put( &( dFracA[0] ), nA );
799 NcVar* varFracB = ncMap.add_var(
"frac_b", ncDouble, dimNB );
800 #ifdef MOAB_HAVE_NETCDFPAR
801 ncMap.enable_var_par_access( varFracB, is_independent );
803 varFracB->add_att(
"name",
"fraction of source coverage of target dof" );
804 varFracB->add_att(
"units",
"unitless" );
805 varFracB->set_cur( (
long)offbuf[1] );
806 varFracB->put( &( dFracB[0] ), nB );
820 serializeSparseMatrix( m_weightMatrix,
"map_operator_" + std::to_string( rank ) +
".txt" );
838 DataArray1D< double > vecSourceFaceArea, vecTargetFaceArea;
839 DataArray1D< double > dSourceCenterLon, dSourceCenterLat, dTargetCenterLon, dTargetCenterLat;
840 DataArray2D< double > dSourceVertexLon, dSourceVertexLat, dTargetVertexLon, dTargetVertexLat;
841 if( m_srcDiscType == DiscretizationType_FV || m_srcDiscType == DiscretizationType_PCLOUD )
843 this->InitializeCoordinatesFromMeshFV(
844 *m_meshInput, dSourceCenterLon, dSourceCenterLat, dSourceVertexLon, dSourceVertexLat,
846 m_remapper->max_source_edges );
848 vecSourceFaceArea.Allocate( m_meshInput->vecFaceArea.GetRows() );
849 for(
unsigned i = 0; i < m_meshInput->vecFaceArea.GetRows(); ++i )
850 vecSourceFaceArea[i] = m_meshInput->vecFaceArea[i];
854 DataArray3D< double > dataGLLJacobianSrc;
855 this->InitializeCoordinatesFromMeshFE( *m_meshInput, m_nDofsPEl_Src, dataGLLNodesSrc, dSourceCenterLon,
856 dSourceCenterLat, dSourceVertexLon, dSourceVertexLat );
859 GenerateMetaData( *m_meshInput, m_nDofsPEl_Src,
false , dataGLLNodesSrc, dataGLLJacobianSrc );
861 if( m_srcDiscType == DiscretizationType_CGLL )
863 GenerateUniqueJacobian( dataGLLNodesSrc, dataGLLJacobianSrc, vecSourceFaceArea );
867 GenerateDiscontinuousJacobian( dataGLLJacobianSrc, vecSourceFaceArea );
871 if( m_destDiscType == DiscretizationType_FV || m_destDiscType == DiscretizationType_PCLOUD )
873 this->InitializeCoordinatesFromMeshFV(
874 *m_meshOutput, dTargetCenterLon, dTargetCenterLat, dTargetVertexLon, dTargetVertexLat,
876 m_remapper->max_target_edges );
878 vecTargetFaceArea.Allocate( m_meshOutput->vecFaceArea.GetRows() );
879 for(
unsigned i = 0; i < m_meshOutput->vecFaceArea.GetRows(); ++i )
880 vecTargetFaceArea[i] = m_meshOutput->vecFaceArea[i];
884 DataArray3D< double > dataGLLJacobianDest;
885 this->InitializeCoordinatesFromMeshFE( *m_meshOutput, m_nDofsPEl_Dest, dataGLLNodesDest, dTargetCenterLon,
886 dTargetCenterLat, dTargetVertexLon, dTargetVertexLat );
889 GenerateMetaData( *m_meshOutput, m_nDofsPEl_Dest,
false , dataGLLNodesDest, dataGLLJacobianDest );
891 if( m_destDiscType == DiscretizationType_CGLL )
893 GenerateUniqueJacobian( dataGLLNodesDest, dataGLLJacobianDest, vecTargetFaceArea );
897 GenerateDiscontinuousJacobian( dataGLLJacobianDest, vecTargetFaceArea );
902 int tot_src_ents = m_remapper->m_source_entities.size();
903 int tot_tgt_ents = m_remapper->m_target_entities.size();
904 int tot_src_size = dSourceCenterLon.GetRows();
905 int tot_tgt_size = m_dTargetCenterLon.GetRows();
906 int tot_vsrc_size = dSourceVertexLon.GetRows() * dSourceVertexLon.GetColumns();
907 int tot_vtgt_size = m_dTargetVertexLon.GetRows() * m_dTargetVertexLon.GetColumns();
909 const int weightMatNNZ = m_weightMatrix.nonZeros();
910 moab::Tag tagMapMetaData, tagMapIndexRow, tagMapIndexCol, tagMapValues, srcEleIDs, tgtEleIDs;
913 "Retrieving tag handles failed" );
916 "Retrieving tag handles failed" );
919 "Retrieving tag handles failed" );
922 "Retrieving tag handles failed" );
925 "Retrieving tag handles failed" );
928 "Retrieving tag handles failed" );
932 "Retrieving tag handles failed" );
935 "Retrieving tag handles failed" );
936 moab::Tag tagSrcCoordsCLon, tagSrcCoordsCLat, tagTgtCoordsCLon, tagTgtCoordsCLat;
940 "Retrieving tag handles failed" );
944 "Retrieving tag handles failed" );
948 "Retrieving tag handles failed" );
952 "Retrieving tag handles failed" );
953 moab::Tag tagSrcCoordsVLon, tagSrcCoordsVLat, tagTgtCoordsVLon, tagTgtCoordsVLat;
957 "Retrieving tag handles failed" );
961 "Retrieving tag handles failed" );
965 "Retrieving tag handles failed" );
969 "Retrieving tag handles failed" );
971 if( m_iSourceMask.IsAttached() )
976 "Retrieving tag handles failed" );
978 if( m_iTargetMask.IsAttached() )
983 "Retrieving tag handles failed" );
986 std::vector< int > smatrowvals( weightMatNNZ ), smatcolvals( weightMatNNZ );
987 std::vector< double > smatvals( weightMatNNZ );
990 for(
int k = 0, offset = 0; k < m_weightMatrix.outerSize(); ++k )
992 for( moab::TempestOnlineMap::WeightMatrix::InnerIterator it( m_weightMatrix, k ); it; ++it, ++offset )
994 smatrowvals[offset] = this->GetRowGlobalDoF( it.row() );
995 smatcolvals[offset] = this->GetColGlobalDoF( it.col() );
996 smatvals[offset] = it.value();
1005 int maxrow = 0, maxcol = 0;
1006 std::vector< int > src_global_dofs( tot_src_size ), tgt_global_dofs( tot_tgt_size );
1007 for(
int i = 0; i < tot_src_size; ++i )
1009 src_global_dofs[i] = srccol_gdofmap[i];
1010 maxcol = ( src_global_dofs[i] > maxcol ) ? src_global_dofs[i] : maxcol;
1013 for(
int i = 0; i < tot_tgt_size; ++i )
1015 tgt_global_dofs[i] = row_gdofmap[i];
1016 maxrow = ( tgt_global_dofs[i] > maxrow ) ? tgt_global_dofs[i] : maxrow;
1041 int map_disc_details[6];
1042 map_disc_details[0] = m_nDofsPEl_Src;
1043 map_disc_details[1] = m_nDofsPEl_Dest;
1044 map_disc_details[2] = ( m_srcDiscType == DiscretizationType_FV || m_srcDiscType == DiscretizationType_PCLOUD
1046 : ( m_srcDiscType == DiscretizationType_CGLL ? 1 : 2 ) );
1047 map_disc_details[3] = ( m_destDiscType == DiscretizationType_FV || m_destDiscType == DiscretizationType_PCLOUD
1049 : ( m_destDiscType == DiscretizationType_CGLL ? 1 : 2 ) );
1050 map_disc_details[4] = ( m_bConserved ? 1 : 0 );
1051 map_disc_details[5] = m_iMonotonicity;
1053 #ifdef MOAB_HAVE_MPI
1054 int loc_smatmetadata[13] = { tot_src_ents,
1056 m_remapper->max_source_edges,
1057 m_remapper->max_target_edges,
1061 map_disc_details[0],
1062 map_disc_details[1],
1063 map_disc_details[2],
1064 map_disc_details[3],
1065 map_disc_details[4],
1066 map_disc_details[5] };
1067 MB_CHK_SET_ERR( m_interface->tag_set_data( tagMapMetaData, &m_meshOverlapSet, 1, &loc_smatmetadata[0] ),
1068 "Setting local tag data failed" );
1069 int glb_smatmetadata[13] = { 0,
1076 map_disc_details[0],
1077 map_disc_details[1],
1078 map_disc_details[2],
1079 map_disc_details[3],
1080 map_disc_details[4],
1081 map_disc_details[5] };
1083 tot_src_ents, tot_tgt_ents, weightMatNNZ, m_remapper->max_source_edges, m_remapper->max_target_edges,
1085 int glb_buf[4] = { 0, 0, 0, 0 };
1086 MPI_Reduce( &loc_buf[0], &glb_buf[0], 3, MPI_INT, MPI_SUM, 0, m_pcomm->comm() );
1087 glb_smatmetadata[0] = glb_buf[0];
1088 glb_smatmetadata[1] = glb_buf[1];
1089 glb_smatmetadata[6] = glb_buf[2];
1090 MPI_Reduce( &loc_buf[3], &glb_buf[0], 4, MPI_INT, MPI_MAX, 0, m_pcomm->comm() );
1091 glb_smatmetadata[2] = glb_buf[0];
1092 glb_smatmetadata[3] = glb_buf[1];
1093 glb_smatmetadata[4] = glb_buf[2];
1094 glb_smatmetadata[5] = glb_buf[3];
1096 int glb_smatmetadata[13] = { tot_src_ents,
1098 m_remapper->max_source_edges,
1099 m_remapper->max_target_edges,
1103 map_disc_details[0],
1104 map_disc_details[1],
1105 map_disc_details[2],
1106 map_disc_details[3],
1107 map_disc_details[4],
1108 map_disc_details[5] };
1111 glb_smatmetadata[4]++;
1112 glb_smatmetadata[5]++;
1116 std::cout <<
" " << this->rank <<
" Writing remap weights with size [" << glb_smatmetadata[4] <<
" X "
1117 << glb_smatmetadata[5] <<
"] and NNZ = " << glb_smatmetadata[6] << std::endl;
1119 MB_CHK_SET_ERR( m_interface->tag_set_data( tagMapMetaData, &root_set, 1, &glb_smatmetadata[0] ),
1120 "Setting local tag data failed" );
1124 const int numval = weightMatNNZ;
1125 const void* smatrowvals_d = smatrowvals.data();
1126 const void* smatcolvals_d = smatcolvals.data();
1127 const void* smatvals_d = smatvals.data();
1128 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagMapIndexRow, &m_meshOverlapSet, 1, &smatrowvals_d, &numval ),
1129 "Setting local tag data failed" );
1130 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagMapIndexCol, &m_meshOverlapSet, 1, &smatcolvals_d, &numval ),
1131 "Setting local tag data failed" );
1132 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagMapValues, &m_meshOverlapSet, 1, &smatvals_d, &numval ),
1133 "Setting local tag data failed" );
1136 const void* srceleidvals_d = src_global_dofs.data();
1137 const void* tgteleidvals_d = tgt_global_dofs.data();
1138 dsize = src_global_dofs.size();
1139 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( srcEleIDs, &m_meshOverlapSet, 1, &srceleidvals_d, &dsize ),
1140 "Setting local tag data failed" );
1141 dsize = tgt_global_dofs.size();
1142 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tgtEleIDs, &m_meshOverlapSet, 1, &tgteleidvals_d, &dsize ),
1143 "Setting local tag data failed" );
1146 const void* srcareavals_d = vecSourceFaceArea;
1147 const void* tgtareavals_d = vecTargetFaceArea;
1148 dsize = tot_src_size;
1149 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( srcAreaValues, &m_meshOverlapSet, 1, &srcareavals_d, &dsize ),
1150 "Setting local tag data failed" );
1151 dsize = tot_tgt_size;
1152 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tgtAreaValues, &m_meshOverlapSet, 1, &tgtareavals_d, &dsize ),
1153 "Setting local tag data failed" );
1156 const void* srccoordsclonvals_d = &dSourceCenterLon[0];
1157 const void* srccoordsclatvals_d = &dSourceCenterLat[0];
1158 dsize = dSourceCenterLon.GetRows();
1159 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagSrcCoordsCLon, &m_meshOverlapSet, 1, &srccoordsclonvals_d, &dsize ),
1160 "Setting local tag data failed" );
1161 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagSrcCoordsCLat, &m_meshOverlapSet, 1, &srccoordsclatvals_d, &dsize ),
1162 "Setting local tag data failed" );
1163 const void* tgtcoordsclonvals_d = &m_dTargetCenterLon[0];
1164 const void* tgtcoordsclatvals_d = &m_dTargetCenterLat[0];
1165 dsize = vecTargetFaceArea.GetRows();
1166 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagTgtCoordsCLon, &m_meshOverlapSet, 1, &tgtcoordsclonvals_d, &dsize ),
1167 "Setting local tag data failed" );
1168 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagTgtCoordsCLat, &m_meshOverlapSet, 1, &tgtcoordsclatvals_d, &dsize ),
1169 "Setting local tag data failed" );
1172 const void* srccoordsvlonvals_d = &( dSourceVertexLon[0][0] );
1173 const void* srccoordsvlatvals_d = &( dSourceVertexLat[0][0] );
1174 dsize = dSourceVertexLon.GetRows() * dSourceVertexLon.GetColumns();
1175 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagSrcCoordsVLon, &m_meshOverlapSet, 1, &srccoordsvlonvals_d, &dsize ),
1176 "Setting local tag data failed" );
1177 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagSrcCoordsVLat, &m_meshOverlapSet, 1, &srccoordsvlatvals_d, &dsize ),
1178 "Setting local tag data failed" );
1179 const void* tgtcoordsvlonvals_d = &( m_dTargetVertexLon[0][0] );
1180 const void* tgtcoordsvlatvals_d = &( m_dTargetVertexLat[0][0] );
1181 dsize = m_dTargetVertexLon.GetRows() * m_dTargetVertexLon.GetColumns();
1182 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagTgtCoordsVLon, &m_meshOverlapSet, 1, &tgtcoordsvlonvals_d, &dsize ),
1183 "Setting local tag data failed" );
1184 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tagTgtCoordsVLat, &m_meshOverlapSet, 1, &tgtcoordsvlatvals_d, &dsize ),
1185 "Setting local tag data failed" );
1188 if( m_iSourceMask.IsAttached() )
1190 const void* srcmaskvals_d = m_iSourceMask;
1191 dsize = m_iSourceMask.GetRows();
1192 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( srcMaskValues, &m_meshOverlapSet, 1, &srcmaskvals_d, &dsize ),
1193 "Setting local tag data failed" );
1196 if( m_iTargetMask.IsAttached() )
1198 const void* tgtmaskvals_d = m_iTargetMask;
1199 dsize = m_iTargetMask.GetRows();
1200 MB_CHK_SET_ERR( m_interface->tag_set_by_ptr( tgtMaskValues, &m_meshOverlapSet, 1, &tgtmaskvals_d, &dsize ),
1201 "Setting local tag data failed" );
1204 #ifdef MOAB_HAVE_MPI
1205 const char* writeOptions = ( this->size > 1 ?
"PARALLEL=WRITE_PART" :
"" );
1207 const char* writeOptions =
"";
1212 MB_CHK_ERR( m_interface->write_file( strOutputFile.c_str(), NULL, writeOptions, sets, 1 ) );
1214 #ifdef WRITE_SCRIP_FILE
1216 sstr << ctx.outFilename.substr( 0, lastindex ) <<
"_" << proc_id <<
".nc";
1217 std::map< std::string, std::string > mapAttributes;
1218 mapAttributes[
"Creator"] =
"MOAB mbtempest workflow";
1219 if( !ctx.proc_id ) std::cout <<
"Writing offline map to file: " << sstr.str() << std::endl;
1220 this->Write( strOutputFile.c_str(), mapAttributes, NcFile::Netcdf4 );
1231 std::cout << message <<
" [";
1232 int pos = barWidth * progress;
1233 for(
int i = 0; i < barWidth; ++i )
1242 std::cout <<
"] " << int( progress * 100.0 ) <<
" %\r";
1249 const std::vector< int >& owned_dof_ids,
1251 std::vector< double >& vecAreaA,
1253 std::vector< double >& vecAreaB,
1256 NcError
error( NcError::silent_nonfatal );
1258 NcVar *varRow = NULL, *varCol = NULL, *varS = NULL;
1259 NcVar *varAreaA = NULL, *varAreaB = NULL;
1260 bool readAreaA =
false;
1261 bool readAreaB =
false;
1262 if( 1 == arearead || 3 == arearead ) readAreaA =
true;
1263 if( 2 == arearead || 3 == arearead ) readAreaB =
true;
1265 #ifdef MOAB_HAVE_PNETCDF
1268 int ndims, nvars, ngatts, unlimited;
1270 #ifdef MOAB_HAVE_NETCDFPAR
1271 bool is_independent =
true;
1272 ParNcFile ncMap( m_pcomm->comm(), MPI_INFO_NULL, strSource, NcFile::ReadOnly, NcFile::Netcdf4 );
1275 NcFile ncMap( strSource, NcFile::ReadOnly );
1278 #define CHECK_EXCEPTION( obj, type, varstr ) \
1280 if( obj == nullptr ) \
1282 _EXCEPTION3( "Map file \"%s\" does not contain %s \"%s\"", strSource, type, varstr ); \
1288 if( ncMap.is_valid() )
1290 NcDim* dimNS = ncMap.get_dim(
"n_s" );
1293 NcDim* dimNA = ncMap.get_dim(
"n_a" );
1296 NcDim* dimNB = ncMap.get_dim(
"n_b" );
1304 varRow = ncMap.get_var(
"row" );
1307 varCol = ncMap.get_var(
"col" );
1310 varS = ncMap.get_var(
"S" );
1315 varAreaA = ncMap.get_var(
"area_a" );
1320 varAreaB = ncMap.get_var(
"area_b" );
1324 #ifdef MOAB_HAVE_NETCDFPAR
1325 ncMap.enable_var_par_access( varRow, is_independent );
1326 ncMap.enable_var_par_access( varCol, is_independent );
1327 ncMap.enable_var_par_access( varS, is_independent );
1328 if( readAreaA ) ncMap.enable_var_par_access( varAreaA, is_independent );
1329 if( readAreaB ) ncMap.enable_var_par_access( varAreaB, is_independent );
1334 #ifdef MOAB_HAVE_PNETCDF
1339 ncmpi_open( m_pcomm->comm(), strSource, NC_NOWRITE, MPI_INFO_NULL, &ncfile ) );
1340 ERR_PARNC( ncmpi_inq( ncfile, &ndims, &nvars, &ngatts, &unlimited ) );
1343 ERR_PARNC( ncmpi_inq_dimid( ncfile,
"n_s", &ins ) );
1345 ERR_PARNC( ncmpi_inq_dimlen( ncfile, ins, &leng ) );
1347 ERR_PARNC( ncmpi_inq_dimid( ncfile,
"n_a", &ins ) );
1348 ERR_PARNC( ncmpi_inq_dimlen( ncfile, ins, &leng ) );
1350 ERR_PARNC( ncmpi_inq_dimid( ncfile,
"n_b", &ins ) );
1351 ERR_PARNC( ncmpi_inq_dimlen( ncfile, ins, &leng ) );
1354 _EXCEPTION1(
"cannot read the file %s", strSource );
1361 int localSize = nS / size;
1362 long offsetRead = rank * localSize;
1364 if( rank == size - 1 )
1366 localSize += nS % size;
1369 int localSizeA = nA / size;
1370 long offsetReadA = rank * localSizeA;
1372 if( rank == size - 1 )
1374 localSizeA += nA % size;
1377 int localSizeB = nB / size;
1378 long offsetReadB = rank * localSizeB;
1380 if( rank == size - 1 )
1382 localSizeB += nB % size;
1385 std::vector< int > vecRow, vecCol;
1386 std::vector< double > vecS;
1387 vecRow.resize( localSize );
1388 vecCol.resize( localSize );
1389 vecS.resize( localSize );
1390 if( readAreaA ) vecAreaA.resize( localSizeA );
1391 if( readAreaB ) vecAreaB.resize( localSizeB );
1393 if( ncMap.is_valid() )
1395 varRow->set_cur( (
long)( offsetRead ) );
1396 varRow->get( &( vecRow[0] ), localSize );
1398 varCol->set_cur( (
long)( offsetRead ) );
1399 varCol->get( &( vecCol[0] ), localSize );
1401 varS->set_cur( (
long)( offsetRead ) );
1402 varS->get( &( vecS[0] ), localSize );
1406 varAreaA->set_cur( (
long)( offsetReadA ) );
1407 varAreaA->get( &( vecAreaA[0] ), localSizeA );
1412 varAreaB->set_cur( (
long)( offsetReadB ) );
1413 varAreaB->get( &( vecAreaB[0] ), localSizeB );
1420 #ifdef MOAB_HAVE_PNETCDF
1422 MPI_Offset start = (MPI_Offset)offsetRead;
1423 MPI_Offset count = (MPI_Offset)localSize;
1426 ERR_PARNC( ncmpi_inq_varid( ncfile,
"S", &varid ) );
1427 ERR_PARNC( ncmpi_get_vara_double_all( ncfile, varid, &start, &count, &vecS[0] ) );
1428 ERR_PARNC( ncmpi_inq_varid( ncfile,
"row", &varid ) );
1429 ERR_PARNC( ncmpi_get_vara_int_all( ncfile, varid, &start, &count, &vecRow[0] ) );
1430 ERR_PARNC( ncmpi_inq_varid( ncfile,
"col", &varid ) );
1431 ERR_PARNC( ncmpi_get_vara_int_all( ncfile, varid, &start, &count, &vecCol[0] ) );
1435 ERR_PARNC( ncmpi_inq_varid( ncfile,
"area_a", &varid ) );
1436 MPI_Offset startA = (MPI_Offset)offsetReadA;
1437 MPI_Offset countA = (MPI_Offset)localSizeA;
1438 ERR_PARNC( ncmpi_get_vara_double_all( ncfile, varid, &startA, &countA, &vecAreaA[0] ) );
1442 ERR_PARNC( ncmpi_inq_varid( ncfile,
"area_b", &varid ) );
1443 MPI_Offset startB = (MPI_Offset)offsetReadB;
1444 MPI_Offset countB = (MPI_Offset)localSizeB;
1445 ERR_PARNC( ncmpi_get_vara_double_all( ncfile, varid, &startB, &countB, &vecAreaB[0] ) );
1447 ERR_PARNC( ncmpi_close( ncfile ) );
1459 #ifdef MOAB_HAVE_EIGEN3
1461 typedef Eigen::Triplet< double >
Triplet;
1462 std::vector< Triplet > tripletList;
1464 #ifdef MOAB_HAVE_MPI
1469 std::vector< int > ownership;
1473 int nPerPart = nDofs / size;
1479 for(
int i = 0; i < localSize; i++ )
1481 int rowval = vecRow[i] - 1;
1482 int colval = vecCol[i] - 1;
1485 to_proc = rowval / nPerPart;
1486 if( to_proc == size ) to_proc = size - 1;
1488 int n = tl->
get_n();
1489 tl->
vi_wr[3 * n] = to_proc;
1490 tl->
vi_wr[3 * n + 1] = rowval;
1491 tl->
vi_wr[3 * n + 2] = colval;
1492 tl->
vr_wr[n] = vecS[i];
1496 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, *tl, 0 );
1498 if( owned_dof_ids.size() > 0 )
1502 tl_re.
initialize( 2, 0, 0, 0, owned_dof_ids.size() );
1506 for(
size_t i = 0; i < owned_dof_ids.size(); i++ )
1509 int dof_val = owned_dof_ids[i] - 1;
1510 to_proc = dof_val / nPerPart;
1511 if( to_proc == size ) to_proc = size - 1;
1513 int n = tl_re.
get_n();
1514 tl_re.
vi_wr[2 * n] = to_proc;
1515 tl_re.
vi_wr[2 * n + 1] = dof_val;
1519 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, tl_re, 0 );
1522 sort_buffer.buffer_init( tl_re.
get_n() );
1523 tl_re.
sort( 1, &sort_buffer );
1527 std::map< int, int > startDofIndex, endDofIndex;
1529 if( tl_re.
get_n() > 0 )
1531 dofVal = tl_re.
vi_rd[1];
1533 startDofIndex[dofVal] = 0;
1534 endDofIndex[dofVal] = 0;
1535 for(
unsigned k = 1; k < tl_re.
get_n(); k++ )
1537 int newDof = tl_re.
vi_rd[2 * k + 1];
1538 if( dofVal == newDof )
1540 endDofIndex[dofVal] = k;
1545 startDofIndex[dofVal] = k;
1546 endDofIndex[dofVal] = k;
1563 for(
unsigned k = 0; k < tl->
get_n(); k++ )
1565 int valDof = tl->
vi_rd[3 * k + 1];
1566 if( startDofIndex.find( valDof ) == startDofIndex.end() )
continue;
1567 for(
int ire = startDofIndex[valDof]; ire <= endDofIndex[valDof]; ire++ )
1569 int to_proc = tl_re.
vi_rd[2 * ire];
1570 int n = tl_back->
get_n();
1571 tl_back->
vi_wr[3 * n] = to_proc;
1572 tl_back->
vi_wr[3 * n + 1] = tl->
vi_rd[3 * k + 1];
1573 tl_back->
vi_wr[3 * n + 2] = tl->
vi_rd[3 * k + 2];
1580 ( m_pcomm->proc_config().crystal_router() )->gs_transfer( 1, *tl_back, 0 );
1588 std::set< int > rowSet;
1589 std::set< int > colSet;
1591 int n = tl->
get_n();
1592 for(
int i = 0; i < n; i++ )
1594 const int vecRowValue = tl->
vi_wr[3 * i + 1];
1595 const int vecColValue = tl->
vi_wr[3 * i + 2];
1596 rowSet.insert( vecRowValue );
1597 colSet.insert( vecColValue );
1600 row_gdofmap.resize( rowSet.size() );
1601 for(
auto setIt : rowSet )
1603 row_gdofmap[
index] = setIt;
1604 rowMap[setIt] =
index++;
1606 m_nTotDofs_Dest =
index;
1608 col_gdofmap.resize( colSet.size() );
1609 for(
auto setIt : colSet )
1611 col_gdofmap[
index] = setIt;
1612 colMap[setIt] =
index++;
1614 m_nTotDofs_SrcCov =
index;
1616 tripletList.reserve( n );
1617 for(
int i = 0; i < n; i++ )
1619 const int vecRowValue = tl->
vi_wr[3 * i + 1];
1620 const int vecColValue = tl->
vi_wr[3 * i + 2];
1621 double value = tl->
vr_wr[i];
1622 tripletList.emplace_back( rowMap[vecRowValue], colMap[vecColValue], value );
1630 std::set< int > rowSet;
1631 std::set< int > colSet;
1633 for(
int i = 0; i < nS; i++ )
1635 const int vecRowValue = vecRow[i] - 1;
1636 const int vecColValue = vecCol[i] - 1;
1637 rowSet.insert( vecRowValue );
1638 colSet.insert( vecColValue );
1642 row_gdofmap.resize( rowSet.size() );
1643 for(
auto setIt : rowSet )
1645 row_gdofmap[
index] = setIt;
1646 rowMap[setIt] =
index++;
1648 m_nTotDofs_Dest =
index;
1650 col_gdofmap.resize( colSet.size() );
1651 for(
auto setIt : colSet )
1653 col_gdofmap[
index] = setIt;
1654 colMap[setIt] =
index++;
1656 m_nTotDofs_SrcCov =
index;
1658 tripletList.reserve( nS );
1659 for(
int i = 0; i < nS; i++ )
1661 const int vecRowValue = vecRow[i] - 1;
1662 const int vecColValue = vecCol[i] - 1;
1663 double value = vecS[i];
1664 tripletList.emplace_back( rowMap[vecRowValue], colMap[vecColValue], value );
1668 m_weightMatrix.resize( m_nTotDofs_Dest, m_nTotDofs_SrcCov );
1669 m_rowVector.resize( m_nTotDofs_Dest );
1670 m_colVector.resize( m_nTotDofs_SrcCov );
1671 m_nTotDofs_Src = m_nTotDofs_SrcCov;
1672 m_weightMatrix.setFromTriplets( tripletList.begin(), tripletList.end() );
1674 m_rowVector.setZero();
1675 m_colVector.setZero();
1677 serializeSparseMatrix( m_weightMatrix,
"map_operator_" + std::to_string( rank ) +
".txt" );
1683 m_nDofsPEl_Dest = 1;