16 #include "DataArray3D.h"
17 #include "FiniteVolumeTools.h"
18 #include "FiniteElementTools.h"
19 #include "TriangularQuadrature.h"
20 #include "GaussQuadrature.h"
21 #include "GaussLobattoQuadrature.h"
22 #include "SparseMatrix.h"
23 #include "STLStringHelper.h"
24 #include "LinearRemapFV.h"
26 #include "LinearRemapSE0.h"
27 #include "LinearRemapFV.h"
40 #ifdef MOAB_HAVE_NETCDFPAR
43 #include "netcdfcpp.h"
56 #define MPI_CHK_ERR( err ) \
59 std::cout << "MPI Failure. ErrorCode (" << ( err ) << ") "; \
60 std::cout << "\nMPI Aborting... \n"; \
61 return moab::MB_FAILURE; \
69 m_pcomm =
m_remapper->get_parallel_communicator();
94 std::vector< std::string > dimNames;
95 std::vector< int > dimSizes;
96 dimNames.push_back(
"num_elem" );
97 dimSizes.push_back( m_meshInputCov->faces.size() );
99 this->InitializeSourceDimensions( dimNames, dimSizes );
104 std::vector< std::string > dimNames;
105 std::vector< int > dimSizes;
106 dimNames.push_back(
"num_elem" );
107 dimSizes.push_back( m_meshOutput->faces.size() );
109 this->InitializeTargetDimensions( dimNames, dimSizes );
117 m_interface =
nullptr;
121 m_meshInput =
nullptr;
122 m_meshOutput =
nullptr;
123 m_meshOverlap =
nullptr;
129 const std::string tgtDofTagName )
134 tagSize = ( m_eInputType == DiscretizationType_FV ? 1 : m_nDofsPEl_Src * m_nDofsPEl_Src );
140 MB_CHK_SET_ERR( MB_FAILURE,
"DoF tag is not set correctly for source mesh." );
145 tagSize = ( m_eOutputType == DiscretizationType_FV ? 1 : m_nDofsPEl_Dest * m_nDofsPEl_Dest );
150 MB_CHK_SET_ERR( MB_FAILURE,
"DoF tag is not set correctly for target mesh." );
162 bool isSrcContinuous,
163 DataArray3D< int >* srcdataGLLNodes,
164 DataArray3D< int >* srcdataGLLNodesSrc,
167 bool isTgtContinuous,
168 DataArray3D< int >* tgtdataGLLNodes )
171 std::vector< bool > dgll_cgll_row_ldofmap, dgll_cgll_col_ldofmap, dgll_cgll_covcol_ldofmap;
172 std::vector< int > src_soln_gdofs, locsrc_soln_gdofs, tgt_soln_gdofs;
175 m_srcDiscType = srcType;
176 m_destDiscType = destType;
177 m_input_order = srcOrder;
178 m_output_order = destOrder;
180 bool vprint = is_root &&
false;
186 src_soln_gdofs.resize( m_remapper->m_covering_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src, -1 );
187 rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_covering_source_entities, &src_soln_gdofs[0] );
MB_CHK_ERR( rval );
188 locsrc_soln_gdofs.resize( m_remapper->m_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src );
189 rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_source_entities, &locsrc_soln_gdofs[0] );
MB_CHK_ERR( rval );
190 tgt_soln_gdofs.resize( m_remapper->m_target_entities.size() * m_nDofsPEl_Dest * m_nDofsPEl_Dest );
191 rval = m_interface->tag_get_data( m_dofTagDest, m_remapper->m_target_entities, &tgt_soln_gdofs[0] );
MB_CHK_ERR( rval );
196 std::ofstream output_file(
"sourcecov-gids-0.txt" );
197 output_file <<
"I, GDOF\n";
198 for(
unsigned i = 0; i < src_soln_gdofs.size(); ++i )
199 output_file << i <<
", " << src_soln_gdofs[i] <<
"\n";
201 output_file <<
"ELEMID, IDOF, LDOF, GDOF, NDOF\n";
202 m_nTotDofs_SrcCov = 0;
203 if( isSrcContinuous )
204 dgll_cgll_covcol_ldofmap.resize(
205 m_remapper->m_covering_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src,
false );
206 for(
unsigned j = 0; j < m_remapper->m_covering_source_entities.size(); j++ )
208 for(
int p = 0; p < m_nDofsPEl_Src; p++ )
210 for(
int q = 0; q < m_nDofsPEl_Src; q++ )
212 const int localDOF = ( *srcdataGLLNodes )[p][q][j] - 1;
213 const int offsetDOF = j * m_nDofsPEl_Src * m_nDofsPEl_Src + p * m_nDofsPEl_Src + q;
214 if( isSrcContinuous && !dgll_cgll_covcol_ldofmap[localDOF] )
217 dgll_cgll_covcol_ldofmap[localDOF] =
true;
219 output_file << m_remapper->lid_to_gid_covsrc[j] <<
", " << offsetDOF <<
", " << localDOF
220 <<
", " << src_soln_gdofs[offsetDOF] <<
", " << m_nTotDofs_SrcCov <<
"\n";
226 dgll_cgll_covcol_ldofmap.clear();
230 std::ofstream output_file(
"source-gids-0.txt" );
231 output_file <<
"I, GDOF\n";
232 for(
unsigned i = 0; i < locsrc_soln_gdofs.size(); ++i )
233 output_file << i <<
", " << locsrc_soln_gdofs[i] <<
"\n";
235 output_file <<
"ELEMID, IDOF, LDOF, GDOF, NDOF\n";
237 if( isSrcContinuous )
238 dgll_cgll_col_ldofmap.resize(
239 m_remapper->m_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src,
false );
240 for(
unsigned j = 0; j < m_remapper->m_source_entities.size(); j++ )
242 for(
int p = 0; p < m_nDofsPEl_Src; p++ )
244 for(
int q = 0; q < m_nDofsPEl_Src; q++ )
246 const int localDOF = ( *srcdataGLLNodesSrc )[p][q][j] - 1;
247 const int offsetDOF = j * m_nDofsPEl_Src * m_nDofsPEl_Src + p * m_nDofsPEl_Src + q;
248 if( isSrcContinuous && !dgll_cgll_col_ldofmap[localDOF] )
251 dgll_cgll_col_ldofmap[localDOF] =
true;
253 output_file << m_remapper->lid_to_gid_src[j] <<
", " << offsetDOF <<
", " << localDOF
254 <<
", " << locsrc_soln_gdofs[offsetDOF] <<
", " << m_nTotDofs_Src <<
"\n";
260 dgll_cgll_col_ldofmap.clear();
264 std::ofstream output_file(
"target-gids-0.txt" );
265 output_file <<
"I, GDOF\n";
266 for(
unsigned i = 0; i < tgt_soln_gdofs.size(); ++i )
267 output_file << i <<
", " << tgt_soln_gdofs[i] <<
"\n";
269 output_file <<
"ELEMID, IDOF, GDOF, NDOF\n";
272 for(
unsigned i = 0; i < tgt_soln_gdofs.size(); ++i )
274 output_file << m_remapper->lid_to_gid_tgt[i] <<
", " << i <<
", " << tgt_soln_gdofs[i] <<
", "
275 << m_nTotDofs_Dest <<
"\n";
286 std::ofstream output_file(
"sourcecov-gids-1.txt" );
287 output_file <<
"I, GDOF\n";
288 for(
unsigned i = 0; i < src_soln_gdofs.size(); ++i )
289 output_file << i <<
", " << src_soln_gdofs[i] <<
"\n";
291 output_file <<
"ELEMID, IDOF, LDOF, GDOF, NDOF\n";
292 m_nTotDofs_SrcCov = 0;
293 if( isSrcContinuous )
294 dgll_cgll_covcol_ldofmap.resize(
295 m_remapper->m_covering_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src,
false );
296 for(
unsigned j = 0; j < m_remapper->m_covering_source_entities.size(); j++ )
298 for(
int p = 0; p < m_nDofsPEl_Src; p++ )
300 for(
int q = 0; q < m_nDofsPEl_Src; q++ )
302 const int localDOF = ( *srcdataGLLNodes )[p][q][j] - 1;
303 const int offsetDOF = j * m_nDofsPEl_Src * m_nDofsPEl_Src + p * m_nDofsPEl_Src + q;
304 if( isSrcContinuous && !dgll_cgll_covcol_ldofmap[localDOF] )
307 dgll_cgll_covcol_ldofmap[localDOF] =
true;
309 output_file << m_remapper->lid_to_gid_covsrc[j] <<
", " << offsetDOF <<
", " << localDOF
310 <<
", " << src_soln_gdofs[offsetDOF] <<
", " << m_nTotDofs_SrcCov <<
"\n";
316 dgll_cgll_covcol_ldofmap.clear();
320 std::ofstream output_file(
"source-gids-1.txt" );
321 output_file <<
"I, GDOF\n";
322 for(
unsigned i = 0; i < locsrc_soln_gdofs.size(); ++i )
323 output_file << i <<
", " << locsrc_soln_gdofs[i] <<
"\n";
325 output_file <<
"ELEMID, IDOF, LDOF, GDOF, NDOF\n";
327 if( isSrcContinuous )
328 dgll_cgll_col_ldofmap.resize(
329 m_remapper->m_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src,
false );
330 for(
unsigned j = 0; j < m_remapper->m_source_entities.size(); j++ )
332 for(
int p = 0; p < m_nDofsPEl_Src; p++ )
334 for(
int q = 0; q < m_nDofsPEl_Src; q++ )
336 const int localDOF = ( *srcdataGLLNodesSrc )[p][q][j] - 1;
337 const int offsetDOF = j * m_nDofsPEl_Src * m_nDofsPEl_Src + p * m_nDofsPEl_Src + q;
338 if( isSrcContinuous && !dgll_cgll_col_ldofmap[localDOF] )
341 dgll_cgll_col_ldofmap[localDOF] =
true;
343 output_file << m_remapper->lid_to_gid_src[j] <<
", " << offsetDOF <<
", " << localDOF
344 <<
", " << locsrc_soln_gdofs[offsetDOF] <<
", " << m_nTotDofs_Src <<
"\n";
350 dgll_cgll_col_ldofmap.clear();
354 std::ofstream output_file(
"target-gids-1.txt" );
355 output_file <<
"I, GDOF\n";
356 for(
unsigned i = 0; i < tgt_soln_gdofs.size(); ++i )
357 output_file << i <<
", " << tgt_soln_gdofs[i] <<
"\n";
359 output_file <<
"ELEMID, IDOF, GDOF, NDOF\n";
362 for(
unsigned i = 0; i < tgt_soln_gdofs.size(); ++i )
364 output_file << m_remapper->lid_to_gid_tgt[i] <<
", " << i <<
", " << tgt_soln_gdofs[i] <<
", "
365 << m_nTotDofs_Dest <<
"\n";
377 int srcTagSize = ( m_eInputType == DiscretizationType_FV ? 1 : m_nDofsPEl_Src * m_nDofsPEl_Src );
378 if( m_remapper->point_cloud_source )
380 assert( m_nDofsPEl_Src == 1 );
381 col_gdofmap.resize( m_remapper->m_covering_source_vertices.size(), UINT_MAX );
382 col_dtoc_dofmap.resize( m_remapper->m_covering_source_vertices.size(), UINT_MAX );
383 src_soln_gdofs.resize( m_remapper->m_covering_source_vertices.size(), UINT_MAX );
384 rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_covering_source_vertices, &src_soln_gdofs[0] );
MB_CHK_ERR( rval );
389 col_gdofmap.resize( m_remapper->m_covering_source_entities.size() * srcTagSize, UINT_MAX );
390 col_dtoc_dofmap.resize( m_remapper->m_covering_source_entities.size() * srcTagSize, UINT_MAX );
391 src_soln_gdofs.resize( m_remapper->m_covering_source_entities.size() * srcTagSize, UINT_MAX );
392 rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_covering_source_entities, &src_soln_gdofs[0] );
MB_CHK_ERR( rval );
398 #ifdef ALTERNATE_NUMBERING_IMPLEMENTATION
399 unsigned maxSrcIndx = 0;
402 std::vector< int > locdofs( srcTagSize );
403 std::map< Node, moab::EntityHandle > mapLocalMBNodes;
405 for(
unsigned iel = 0; iel < m_remapper->m_covering_source_entities.size(); ++iel )
407 EntityHandle eh = m_remapper->m_covering_source_entities[iel];
408 rval = m_interface->get_coords( &eh, 1, elcoords );
MB_CHK_ERR( rval );
409 Node elCentroid( elcoords[0], elcoords[1], elcoords[2] );
410 mapLocalMBNodes.insert( std::pair< Node, moab::EntityHandle >( elCentroid, eh ) );
413 const NodeVector& nodes = m_remapper->m_covering_source->nodes;
414 for(
unsigned j = 0; j < m_remapper->m_covering_source->faces.size(); j++ )
416 const Face&
face = m_remapper->m_covering_source->faces[j];
419 centroid.x = centroid.y = centroid.z = 0.0;
420 for(
unsigned l = 0; l <
face.edges.size(); ++l )
422 centroid.x += nodes[
face[l]].x;
423 centroid.y += nodes[
face[l]].y;
424 centroid.z += nodes[
face[l]].z;
426 const double factor = 1.0 /
face.edges.size();
427 centroid.x *= factor;
428 centroid.y *= factor;
429 centroid.z *= factor;
432 if( mapLocalMBNodes.find( centroid ) != mapLocalMBNodes.end() )
434 current_eh = mapLocalMBNodes[centroid];
437 rval = m_interface->tag_get_data( m_dofTagSrc, ¤t_eh, 1, &locdofs[0] );
MB_CHK_ERR( rval );
438 for(
int p = 0; p < m_nDofsPEl_Src; p++ )
440 for(
int q = 0; q < m_nDofsPEl_Src; q++ )
442 const int localDOF = ( *srcdataGLLNodes )[p][q][j] - 1;
443 const int offsetDOF = p * m_nDofsPEl_Src + q;
444 maxSrcIndx = ( localDOF > maxSrcIndx ? localDOF : maxSrcIndx );
445 std::cout <<
"Col: " << current_eh <<
", " << m_remapper->lid_to_gid_covsrc[j] <<
", " << offsetDOF
446 <<
", " << localDOF <<
", " << locdofs[offsetDOF] - 1 <<
", " << maxSrcIndx <<
"\n";
452 m_nTotDofs_SrcCov = 0;
453 if( srcdataGLLNodes ==
nullptr )
455 for(
unsigned i = 0; i < col_gdofmap.size(); ++i )
457 assert( src_soln_gdofs[i] > 0 );
458 col_gdofmap[i] = src_soln_gdofs[i] - 1;
459 col_dtoc_dofmap[i] = i;
460 if( vprint ) std::cout <<
"Col: " << i <<
", " << col_gdofmap[i] <<
"\n";
466 if( isSrcContinuous )
467 dgll_cgll_covcol_ldofmap.resize( m_remapper->m_covering_source_entities.size() * srcTagSize,
false );
469 for(
unsigned j = 0; j < m_remapper->m_covering_source_entities.size(); j++ )
471 for(
int p = 0; p < m_nDofsPEl_Src; p++ )
473 for(
int q = 0; q < m_nDofsPEl_Src; q++ )
475 const int localDOF = ( *srcdataGLLNodes )[p][q][j] - 1;
476 const int offsetDOF = j * srcTagSize + p * m_nDofsPEl_Src + q;
477 if( isSrcContinuous && !dgll_cgll_covcol_ldofmap[localDOF] )
480 dgll_cgll_covcol_ldofmap[localDOF] =
true;
482 if( !isSrcContinuous ) m_nTotDofs_SrcCov++;
483 assert( src_soln_gdofs[offsetDOF] > 0 );
484 col_gdofmap[localDOF] = src_soln_gdofs[offsetDOF] - 1;
485 col_dtoc_dofmap[offsetDOF] = localDOF;
487 std::cout <<
"Col: " << m_remapper->lid_to_gid_covsrc[j] <<
", " << offsetDOF <<
", "
488 << localDOF <<
", " << col_gdofmap[offsetDOF] <<
", " << m_nTotDofs_SrcCov <<
"\n";
494 if( m_remapper->point_cloud_source )
496 assert( m_nDofsPEl_Src == 1 );
497 srccol_gdofmap.resize( m_remapper->m_source_vertices.size(), UINT_MAX );
498 srccol_dtoc_dofmap.resize( m_remapper->m_covering_source_vertices.size(), UINT_MAX );
499 locsrc_soln_gdofs.resize( m_remapper->m_source_vertices.size(), UINT_MAX );
500 rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_source_vertices, &locsrc_soln_gdofs[0] );
MB_CHK_ERR( rval );
504 srccol_gdofmap.resize( m_remapper->m_source_entities.size() * srcTagSize, UINT_MAX );
505 srccol_dtoc_dofmap.resize( m_remapper->m_source_entities.size() * srcTagSize, UINT_MAX );
506 locsrc_soln_gdofs.resize( m_remapper->m_source_entities.size() * srcTagSize, UINT_MAX );
507 rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_source_entities, &locsrc_soln_gdofs[0] );
MB_CHK_ERR( rval );
512 if( srcdataGLLNodesSrc ==
nullptr )
514 for(
unsigned i = 0; i < srccol_gdofmap.size(); ++i )
516 assert( locsrc_soln_gdofs[i] > 0 );
517 srccol_gdofmap[i] = locsrc_soln_gdofs[i] - 1;
518 srccol_dtoc_dofmap[i] = i;
524 if( isSrcContinuous ) dgll_cgll_col_ldofmap.resize( m_remapper->m_source_entities.size() * srcTagSize,
false );
526 for(
unsigned j = 0; j < m_remapper->m_source_entities.size(); j++ )
528 for(
int p = 0; p < m_nDofsPEl_Src; p++ )
530 for(
int q = 0; q < m_nDofsPEl_Src; q++ )
532 const int localDOF = ( *srcdataGLLNodesSrc )[p][q][j] - 1;
533 const int offsetDOF = j * srcTagSize + p * m_nDofsPEl_Src + q;
534 if( isSrcContinuous && !dgll_cgll_col_ldofmap[localDOF] )
537 dgll_cgll_col_ldofmap[localDOF] =
true;
539 if( !isSrcContinuous ) m_nTotDofs_Src++;
540 assert( locsrc_soln_gdofs[offsetDOF] > 0 );
541 srccol_gdofmap[localDOF] = locsrc_soln_gdofs[offsetDOF] - 1;
542 srccol_dtoc_dofmap[offsetDOF] = localDOF;
548 int tgtTagSize = ( m_eOutputType == DiscretizationType_FV ? 1 : m_nDofsPEl_Dest * m_nDofsPEl_Dest );
549 if( m_remapper->point_cloud_target )
551 assert( m_nDofsPEl_Dest == 1 );
552 row_gdofmap.resize( m_remapper->m_target_vertices.size(), UINT_MAX );
553 row_dtoc_dofmap.resize( m_remapper->m_target_vertices.size(), UINT_MAX );
554 tgt_soln_gdofs.resize( m_remapper->m_target_vertices.size(), UINT_MAX );
555 rval = m_interface->tag_get_data( m_dofTagDest, m_remapper->m_target_vertices, &tgt_soln_gdofs[0] );
MB_CHK_ERR( rval );
560 row_gdofmap.resize( m_remapper->m_target_entities.size() * tgtTagSize, UINT_MAX );
561 row_dtoc_dofmap.resize( m_remapper->m_target_entities.size() * tgtTagSize, UINT_MAX );
562 tgt_soln_gdofs.resize( m_remapper->m_target_entities.size() * tgtTagSize, UINT_MAX );
563 rval = m_interface->tag_get_data( m_dofTagDest, m_remapper->m_target_entities, &tgt_soln_gdofs[0] );
MB_CHK_ERR( rval );
569 if( tgtdataGLLNodes ==
nullptr )
571 for(
unsigned i = 0; i < row_gdofmap.size(); ++i )
573 assert( tgt_soln_gdofs[i] > 0 );
574 row_gdofmap[i] = tgt_soln_gdofs[i] - 1;
575 row_dtoc_dofmap[i] = i;
576 if( vprint ) std::cout <<
"Row: " << i <<
", " << row_gdofmap[i] <<
"\n";
582 if( isTgtContinuous ) dgll_cgll_row_ldofmap.resize( m_remapper->m_target_entities.size() * tgtTagSize,
false );
584 for(
unsigned j = 0; j < m_remapper->m_target_entities.size(); j++ )
586 for(
int p = 0; p < m_nDofsPEl_Dest; p++ )
588 for(
int q = 0; q < m_nDofsPEl_Dest; q++ )
590 const int localDOF = ( *tgtdataGLLNodes )[p][q][j] - 1;
591 const int offsetDOF = j * tgtTagSize + p * m_nDofsPEl_Dest + q;
592 if( isTgtContinuous && !dgll_cgll_row_ldofmap[localDOF] )
595 dgll_cgll_row_ldofmap[localDOF] =
true;
597 if( !isTgtContinuous ) m_nTotDofs_Dest++;
598 assert( tgt_soln_gdofs[offsetDOF] > 0 );
599 row_gdofmap[localDOF] = tgt_soln_gdofs[offsetDOF] - 1;
600 row_dtoc_dofmap[offsetDOF] = localDOF;
602 std::cout <<
"Row: " << m_remapper->lid_to_gid_tgt[j] <<
", " << offsetDOF <<
", " << localDOF
603 <<
", " << row_gdofmap[offsetDOF] <<
", " << m_nTotDofs_Dest <<
"\n";
610 #if defined( MOAB_HAVE_EIGEN3 ) && defined( VERBOSE )
613 std::cout <<
"[" << rank <<
"]"
614 <<
"DoFs: row = " << m_nTotDofs_Dest <<
", " << row_gdofmap.size() <<
", col = " << m_nTotDofs_Src
615 <<
", " << m_nTotDofs_SrcCov <<
", " << col_gdofmap.size() <<
"\n";
621 #ifdef CHECK_INCREASING_DOF
622 for(
size_t i = 0; i < row_gdofmap.size() - 1; i++ )
624 if( row_gdofmap[i] > row_gdofmap[i + 1] )
625 std::cout <<
" on rank " << rank <<
" in row_gdofmap[" << i <<
"]=" << row_gdofmap[i] <<
" > row_gdofmap["
626 << i + 1 <<
"]=" << row_gdofmap[i + 1] <<
" \n";
628 for(
size_t i = 0; i < col_gdofmap.size() - 1; i++ )
630 if( col_gdofmap[i] > col_gdofmap[i + 1] )
631 std::cout <<
" on rank " << rank <<
" in col_gdofmap[" << i <<
"]=" << col_gdofmap[i] <<
" > col_gdofmap["
632 << i + 1 <<
"]=" << col_gdofmap[i + 1] <<
" \n";
647 col_dtoc_dofmap.resize( values_entities.size() );
648 for(
int j = 0; j < (int)values_entities.size(); j++ )
650 if( colMap.find( values_entities[j] - 1 ) != colMap.end() )
651 col_dtoc_dofmap[j] = colMap[values_entities[j] - 1];
654 col_dtoc_dofmap[j] = -1;
667 row_dtoc_dofmap.resize( values_entities.size() );
668 for(
int j = 0; j < (int)values_entities.size(); j++ )
670 if( rowMap.find( values_entities[j] - 1 ) != rowMap.end() )
671 row_dtoc_dofmap[j] = rowMap[values_entities[j] - 1];
674 row_dtoc_dofmap[j] = -1;
684 std::string strOutputType,
685 const GenerateOfflineMapAlgorithmOptions& mapOptions,
686 const std::string& srcDofTagName,
687 const std::string& tgtDofTagName )
689 NcError
error( NcError::silent_nonfatal );
692 dbgprint.set_prefix(
"[TempestOnlineMap]: " );
695 const bool m_bPointCloudSource = ( m_remapper->point_cloud_source );
696 const bool m_bPointCloudTarget = ( m_remapper->point_cloud_target );
697 const bool m_bPointCloud = m_bPointCloudSource || m_bPointCloudTarget;
706 STLStringHelper::ToLower( strInputType );
707 STLStringHelper::ToLower( strOutputType );
712 if( strInputType ==
"fv" )
714 eInputType = DiscretizationType_FV;
716 else if( strInputType ==
"cgll" )
718 eInputType = DiscretizationType_CGLL;
720 else if( strInputType ==
"dgll" )
722 eInputType = DiscretizationType_DGLL;
724 else if( strInputType ==
"pcloud" )
726 eInputType = DiscretizationType_PCLOUD;
730 _EXCEPTION1(
"Invalid \"in_type\" value (%s), expected [fv|cgll|dgll]", strInputType.c_str() );
733 if( strOutputType ==
"fv" )
735 eOutputType = DiscretizationType_FV;
737 else if( strOutputType ==
"cgll" )
739 eOutputType = DiscretizationType_CGLL;
741 else if( strOutputType ==
"dgll" )
743 eOutputType = DiscretizationType_DGLL;
745 else if( strOutputType ==
"pcloud" )
747 eOutputType = DiscretizationType_PCLOUD;
751 _EXCEPTION1(
"Invalid \"out_type\" value (%s), expected [fv|cgll|dgll]", strOutputType.c_str() );
755 m_bConserved = !mapOptions.fNoConservation;
756 m_eInputType = eInputType;
757 m_eOutputType = eOutputType;
760 std::string strMapAlgorithm(
"" );
761 int nMonotoneType = ( mapOptions.fMonotone ) ? ( 1 ) : ( 0 );
764 std::set< std::string > setMethodStrings;
767 for(
size_t i = 0; i <= mapOptions.strMethod.length(); i++ )
769 if( ( i == mapOptions.strMethod.length() ) || ( mapOptions.strMethod[i] ==
';' ) )
771 std::string strMethodString = mapOptions.strMethod.substr( iLast, i - iLast );
772 STLStringHelper::RemoveWhitespaceInPlace( strMethodString );
773 if( strMethodString.length() > 0 )
775 setMethodStrings.insert( strMethodString );
782 for(
auto it : setMethodStrings )
787 if( nMonotoneType != 0 )
789 _EXCEPTIONT(
"Multiple monotonicity specifications found (--mono) or (--method \"mono#\")" );
791 if( ( m_eInputType == DiscretizationType_FV ) && ( m_eOutputType == DiscretizationType_FV ) )
793 _EXCEPTIONT(
"--method \"mono2\" is only used when remapping to/from CGLL or DGLL grids" );
799 else if( it ==
"mono3" )
801 if( nMonotoneType != 0 )
803 _EXCEPTIONT(
"Multiple monotonicity specifications found (--mono) or (--method \"mono#\")" );
805 if( ( m_eInputType == DiscretizationType_FV ) && ( m_eOutputType == DiscretizationType_FV ) )
807 _EXCEPTIONT(
"--method \"mono3\" is only used when remapping to/from CGLL or DGLL grids" );
813 else if( it ==
"volumetric" )
815 if( ( m_eInputType != DiscretizationType_FV ) || ( m_eOutputType == DiscretizationType_FV ) )
817 _EXCEPTIONT(
"--method \"volumetric\" may only be used for FV->CGLL or FV->DGLL remapping" );
819 strMapAlgorithm =
"volumetric";
823 else if( it ==
"invdist" )
825 if( ( m_eInputType != DiscretizationType_FV ) || ( m_eOutputType != DiscretizationType_FV ) )
827 _EXCEPTIONT(
"--method \"invdist\" may only be used for FV->FV remapping" );
829 strMapAlgorithm =
"invdist";
833 else if( it ==
"delaunay" )
835 if( ( m_eInputType != DiscretizationType_FV ) || ( m_eOutputType != DiscretizationType_FV ) )
837 _EXCEPTIONT(
"--method \"delaunay\" may only be used for FV->FV remapping" );
839 strMapAlgorithm =
"delaunay";
843 else if( it ==
"bilin" )
845 if( ( m_eInputType != DiscretizationType_FV ) || ( m_eOutputType != DiscretizationType_FV ) )
847 _EXCEPTIONT(
"--method \"bilin\" may only be used for FV->FV remapping" );
849 strMapAlgorithm =
"fvbilin";
853 else if( it ==
"intbilin" )
855 if( m_eOutputType != DiscretizationType_FV )
857 _EXCEPTIONT(
"--method \"intbilin\" may only be used when mapping to FV." );
859 if( m_eInputType == DiscretizationType_FV )
861 strMapAlgorithm =
"fvintbilin";
865 strMapAlgorithm =
"mono3";
870 else if( it ==
"intbilingb" )
872 if( ( m_eInputType != DiscretizationType_FV ) || ( m_eOutputType != DiscretizationType_FV ) )
874 _EXCEPTIONT(
"--method \"intbilingb\" may only be used for FV->FV remapping" );
876 strMapAlgorithm =
"fvintbilingb";
880 _EXCEPTION1(
"Invalid --method argument \"%s\"", it.c_str() );
885 ( m_eInputType == DiscretizationType_FV || m_eInputType == DiscretizationType_PCLOUD ? 1
888 ( m_eOutputType == DiscretizationType_FV || m_eOutputType == DiscretizationType_PCLOUD ? 1
889 : mapOptions.nPout );
891 rval = SetDOFmapTags( srcDofTagName, tgtDofTagName );
MB_CHK_ERR( rval );
895 rval = m_interface->tag_get_handle(
"aream", 1,
MB_TYPE_DOUBLE, areaTag,
899 if( is_root )
dbgprint.printf( 0,
"aream tag already defined \n" );
902 double dTotalAreaInput = 0.0, dTotalAreaOutput = 0.0;
903 if( !m_bPointCloudSource )
906 if( is_root )
dbgprint.printf( 0,
"Calculating input mesh Face areas\n" );
907 double dTotalAreaInput_loc = m_meshInput->CalculateFaceAreas( mapOptions.fSourceConcave );
908 rval = m_interface->tag_set_data( areaTag, m_remapper->m_source_entities, m_meshInput->vecFaceArea );
MB_CHK_ERR( rval );
909 dTotalAreaInput = dTotalAreaInput_loc;
912 MPI_Reduce( &dTotalAreaInput_loc, &dTotalAreaInput, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
914 if( is_root )
dbgprint.printf( 0,
"Input Mesh Geometric Area: %1.15e\n", dTotalAreaInput );
917 m_meshInputCov->CalculateFaceAreas( mapOptions.fSourceConcave );
922 if( !m_bPointCloudTarget )
925 if( is_root )
dbgprint.printf( 0,
"Calculating output mesh Face areas\n" );
926 double dTotalAreaOutput_loc = m_meshOutput->CalculateFaceAreas( mapOptions.fTargetConcave );
927 dTotalAreaOutput = dTotalAreaOutput_loc;
930 MPI_Reduce( &dTotalAreaOutput_loc, &dTotalAreaOutput, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
932 if( is_root )
dbgprint.printf( 0,
"Output Mesh Geometric Area: %1.15e\n", dTotalAreaOutput );
933 rval = m_interface->tag_set_data( areaTag, m_remapper->m_target_entities, m_meshOutput->vecFaceArea );
MB_CHK_ERR( rval );
939 assert( m_meshOverlap->vecSourceFaceIx.size() == m_meshOverlap->vecTargetFaceIx.size() );
942 if( is_root )
dbgprint.printf( 0,
"Calculating overlap mesh Face areas\n" );
943 double dTotalAreaOverlap_loc = m_meshOverlap->CalculateFaceAreas(
false );
944 double dTotalAreaOverlap = dTotalAreaOverlap_loc;
947 MPI_Reduce( &dTotalAreaOverlap_loc, &dTotalAreaOverlap, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
949 if( is_root )
dbgprint.printf( 0,
"Overlap Mesh Area: %1.15e\n", dTotalAreaOverlap );
954 if( is_root )
dbgprint.printf( 0,
"Correcting source/target areas to overlap mesh areas\n" );
955 DataArray1D< double > dSourceArea( m_meshInputCov->faces.size() );
956 DataArray1D< double > dTargetArea( m_meshOutput->faces.size() );
958 assert( m_meshOverlap->vecSourceFaceIx.size() == m_meshOverlap->faces.size() );
959 assert( m_meshOverlap->vecTargetFaceIx.size() == m_meshOverlap->faces.size() );
960 assert( m_meshOverlap->vecFaceArea.GetRows() == m_meshOverlap->faces.size() );
962 assert( m_meshInputCov->vecFaceArea.GetRows() == m_meshInputCov->faces.size() );
963 assert( m_meshOutput->vecFaceArea.GetRows() == m_meshOutput->faces.size() );
965 for(
size_t i = 0; i < m_meshOverlap->faces.size(); i++ )
967 if( m_meshOverlap->vecSourceFaceIx[i] < 0 || m_meshOverlap->vecTargetFaceIx[i] < 0 )
971 assert(
static_cast< size_t >( m_meshOverlap->vecSourceFaceIx[i] ) < m_meshInputCov->faces.size() );
972 dSourceArea[m_meshOverlap->vecSourceFaceIx[i]] += m_meshOverlap->vecFaceArea[i];
973 assert(
static_cast< size_t >( m_meshOverlap->vecTargetFaceIx[i] ) < m_meshOutput->faces.size() );
974 dTargetArea[m_meshOverlap->vecTargetFaceIx[i]] += m_meshOverlap->vecFaceArea[i];
977 for(
size_t i = 0; i < m_meshInputCov->faces.size(); i++ )
979 if( fabs( dSourceArea[i] - m_meshInputCov->vecFaceArea[i] ) < 1.0e-10 )
981 m_meshInputCov->vecFaceArea[i] = dSourceArea[i];
984 for(
size_t i = 0; i < m_meshOutput->faces.size(); i++ )
986 if( fabs( dTargetArea[i] - m_meshOutput->vecFaceArea[i] ) < 1.0e-10 )
988 m_meshOutput->vecFaceArea[i] = dTargetArea[i];
994 if( !m_bPointCloudSource && eInputType == DiscretizationType_FV )
996 this->SetSourceAreas( m_meshInputCov->vecFaceArea );
997 if( m_meshInputCov->vecMask.size() )
999 this->SetSourceMask( m_meshInputCov->vecMask );
1004 if( !m_bPointCloudTarget && eOutputType == DiscretizationType_FV )
1006 this->SetTargetAreas( m_meshOutput->vecFaceArea );
1007 if( m_meshOutput->vecMask.size() )
1009 this->SetTargetMask( m_meshOutput->vecMask );
1024 this->m_pmeshSource = m_meshInputCov;
1025 this->m_pmeshOverlap = m_meshOverlap;
1028 if( ( eInputType == DiscretizationType_FV ) && ( eOutputType == DiscretizationType_FV ) )
1031 if( m_meshInputCov->revnodearray.size() == 0 ) m_meshInputCov->ConstructReverseNodeArray();
1032 if( m_meshInputCov->edgemap.size() == 0 ) m_meshInputCov->ConstructEdgeMap(
false );
1035 this->InitializeSourceCoordinatesFromMeshFV( *m_meshInputCov );
1036 this->InitializeTargetCoordinatesFromMeshFV( *m_meshOutput );
1038 this->m_pdataGLLNodesIn =
nullptr;
1039 this->m_pdataGLLNodesOut =
nullptr;
1042 rval = this->SetDOFmapAssociation( eInputType, mapOptions.nPin,
false,
nullptr,
nullptr, eOutputType,
1043 mapOptions.nPout,
false,
nullptr );
MB_CHK_ERR( rval );
1046 if( is_root )
dbgprint.printf( 0,
"Calculating remap weights\n" );
1049 if( strMapAlgorithm ==
"invdist" )
1051 if( is_root )
dbgprint.printf( 0,
"Calculating map (invdist)\n" );
1052 if( m_meshInputCov->faces.size() )
1053 LinearRemapFVtoFVInvDist( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, *
this );
1055 else if( strMapAlgorithm ==
"delaunay" )
1057 if( is_root )
dbgprint.printf( 0,
"Calculating map (delaunay)\n" );
1058 if( m_meshInputCov->faces.size() )
1059 LinearRemapTriangulation( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, *
this );
1061 else if( strMapAlgorithm ==
"fvintbilin" )
1063 if( is_root )
dbgprint.printf( 0,
"Calculating map (intbilin)\n" );
1064 if( m_meshInputCov->faces.size() )
1065 LinearRemapIntegratedBilinear( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, *
this );
1067 else if( strMapAlgorithm ==
"fvintbilingb" )
1069 if( is_root )
dbgprint.printf( 0,
"Calculating map (intbilingb)\n" );
1070 if( m_meshInputCov->faces.size() )
1071 LinearRemapIntegratedGeneralizedBarycentric( *m_meshInputCov, *m_meshOutput, *m_meshOverlap,
1074 else if( strMapAlgorithm ==
"fvbilin" )
1079 m_meshInputCov->Write(
"SourceMeshMBTR.g" );
1080 m_meshOutput->Write(
"TargetMeshMBTR.g" );
1084 m_meshInputCov->Write(
"SourceMeshMBTR" + std::to_string( rank ) +
".g" );
1085 m_meshOutput->Write(
"TargetMeshMBTR" + std::to_string( rank ) +
".g" );
1088 if( is_root )
dbgprint.printf( 0,
"Calculating map (bilin)\n" );
1089 if( m_meshInputCov->faces.size() )
1090 LinearRemapBilinear( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, *
this );
1094 if( is_root )
dbgprint.printf( 0,
"Calculating conservative FV-FV map\n" );
1095 if( m_meshInputCov->faces.size() )
1097 #ifdef USE_NATIVE_TEMPESTREMAP_ROUTINES
1098 LinearRemapFVtoFV( *m_meshInputCov, *m_meshOutput, *m_meshOverlap,
1099 ( mapOptions.fMonotone ) ? ( 1 ) : ( mapOptions.nPin ), *
this );
1101 LinearRemapFVtoFV_Tempest_MOAB( ( mapOptions.fMonotone ? 1 : mapOptions.nPin ) );
1106 else if( eInputType == DiscretizationType_FV )
1108 DataArray3D< double > dataGLLJacobian;
1110 if( is_root )
dbgprint.printf( 0,
"Generating output mesh meta data\n" );
1111 double dNumericalArea_loc = GenerateMetaData( *m_meshOutput, mapOptions.nPout, mapOptions.fNoBubble,
1112 dataGLLNodesDest, dataGLLJacobian );
1114 double dNumericalArea = dNumericalArea_loc;
1115 #ifdef MOAB_HAVE_MPI
1117 MPI_Reduce( &dNumericalArea_loc, &dNumericalArea, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
1119 if( is_root )
dbgprint.printf( 0,
"Output Mesh Numerical Area: %1.15e\n", dNumericalArea );
1122 this->InitializeSourceCoordinatesFromMeshFV( *m_meshInputCov );
1123 this->InitializeTargetCoordinatesFromMeshFE( *m_meshOutput, mapOptions.nPout, dataGLLNodesDest );
1125 this->m_pdataGLLNodesIn =
nullptr;
1126 this->m_pdataGLLNodesOut = &dataGLLNodesDest;
1129 bool fContinuous = ( eOutputType == DiscretizationType_CGLL );
1131 if( eOutputType == DiscretizationType_CGLL )
1133 GenerateUniqueJacobian( dataGLLNodesDest, dataGLLJacobian, this->GetTargetAreas() );
1137 GenerateDiscontinuousJacobian( dataGLLJacobian, this->GetTargetAreas() );
1141 if( m_meshInputCov->revnodearray.size() == 0 ) m_meshInputCov->ConstructReverseNodeArray();
1142 if( m_meshInputCov->edgemap.size() == 0 ) m_meshInputCov->ConstructEdgeMap(
false );
1145 rval = this->SetDOFmapAssociation( eInputType, mapOptions.nPin,
false,
nullptr,
nullptr, eOutputType,
1146 mapOptions.nPout, ( eOutputType == DiscretizationType_CGLL ),
1150 if( strMapAlgorithm ==
"volumetric" )
1152 if( is_root )
dbgprint.printf( 0,
"Calculating remapping weights for FV->GLL (volumetric)\n" );
1153 LinearRemapFVtoGLL_Volumetric( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, dataGLLNodesDest,
1154 dataGLLJacobian, this->GetTargetAreas(), mapOptions.nPin, *
this,
1155 nMonotoneType, fContinuous, mapOptions.fNoConservation );
1159 if( is_root )
dbgprint.printf( 0,
"Calculating remapping weights for FV->GLL\n" );
1160 LinearRemapFVtoGLL( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, dataGLLNodesDest, dataGLLJacobian,
1161 this->GetTargetAreas(), mapOptions.nPin, *
this, nMonotoneType, fContinuous,
1162 mapOptions.fNoConservation );
1165 else if( ( eInputType == DiscretizationType_PCLOUD ) || ( eOutputType == DiscretizationType_PCLOUD ) )
1167 DataArray3D< double > dataGLLJacobian;
1168 if( !m_bPointCloudSource )
1171 if( m_meshInputCov->revnodearray.size() == 0 ) m_meshInputCov->ConstructReverseNodeArray();
1172 if( m_meshInputCov->edgemap.size() == 0 ) m_meshInputCov->ConstructEdgeMap(
false );
1175 if( eInputType == DiscretizationType_FV )
1177 this->InitializeSourceCoordinatesFromMeshFV( *m_meshInputCov );
1181 if( is_root )
dbgprint.printf( 0,
"Generating input mesh meta data\n" );
1182 DataArray3D< double > dataGLLJacobianSrc;
1183 GenerateMetaData( *m_meshInputCov, mapOptions.nPin, mapOptions.fNoBubble, dataGLLNodesSrcCov,
1185 GenerateMetaData( *m_meshInput, mapOptions.nPin, mapOptions.fNoBubble, dataGLLNodesSrc,
1186 dataGLLJacobianSrc );
1191 if( !m_bPointCloudTarget )
1194 if( m_meshOutput->revnodearray.size() == 0 ) m_meshOutput->ConstructReverseNodeArray();
1195 if( m_meshOutput->edgemap.size() == 0 ) m_meshOutput->ConstructEdgeMap(
false );
1198 if( eOutputType == DiscretizationType_FV )
1200 this->InitializeSourceCoordinatesFromMeshFV( *m_meshOutput );
1204 if( is_root )
dbgprint.printf( 0,
"Generating output mesh meta data\n" );
1205 GenerateMetaData( *m_meshOutput, mapOptions.nPout, mapOptions.fNoBubble, dataGLLNodesDest,
1212 rval = this->SetDOFmapAssociation(
1213 eInputType, mapOptions.nPin, ( eInputType == DiscretizationType_CGLL ),
1214 ( m_bPointCloudSource || eInputType == DiscretizationType_FV ?
nullptr : &dataGLLNodesSrcCov ),
1215 ( m_bPointCloudSource || eInputType == DiscretizationType_FV ?
nullptr : &dataGLLNodesSrc ),
1216 eOutputType, mapOptions.nPout, ( eOutputType == DiscretizationType_CGLL ),
1217 ( m_bPointCloudTarget ?
nullptr : &dataGLLNodesDest ) );
MB_CHK_ERR( rval );
1220 if( is_root )
dbgprint.printf( 0,
"Calculating remap weights with Nearest-Neighbor method\n" );
1221 rval = LinearRemapNN_MOAB(
true ,
false );
MB_CHK_ERR( rval );
1223 else if( ( eInputType != DiscretizationType_FV ) && ( eOutputType == DiscretizationType_FV ) )
1225 DataArray3D< double > dataGLLJacobianSrc, dataGLLJacobian;
1227 if( is_root )
dbgprint.printf( 0,
"Generating input mesh meta data\n" );
1229 GenerateMetaData( *m_meshInputCov, mapOptions.nPin, mapOptions.fNoBubble, dataGLLNodesSrcCov,
1232 double dNumericalArea_loc = GenerateMetaData( *m_meshInput, mapOptions.nPin, mapOptions.fNoBubble,
1233 dataGLLNodesSrc, dataGLLJacobianSrc );
1239 double dNumericalArea = dNumericalArea_loc;
1240 #ifdef MOAB_HAVE_MPI
1242 MPI_Reduce( &dNumericalArea_loc, &dNumericalArea, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
1246 dbgprint.printf( 0,
"Input Mesh Numerical Area: %1.15e\n", dNumericalArea );
1248 if( fabs( dNumericalArea - dTotalAreaInput ) > 1.0e-12 )
1250 dbgprint.printf( 0,
"WARNING: Significant mismatch between input mesh "
1251 "numerical area and geometric area\n" );
1255 if( dataGLLNodesSrcCov.GetSubColumns() != m_meshInputCov->faces.size() )
1257 _EXCEPTIONT(
"Number of element does not match between metadata and "
1262 this->InitializeSourceCoordinatesFromMeshFE( *m_meshInputCov, mapOptions.nPin, dataGLLNodesSrcCov );
1263 this->InitializeTargetCoordinatesFromMeshFV( *m_meshOutput );
1266 bool fContinuousIn = ( eInputType == DiscretizationType_CGLL );
1268 if( eInputType == DiscretizationType_CGLL )
1270 GenerateUniqueJacobian( dataGLLNodesSrcCov, dataGLLJacobian, this->GetSourceAreas() );
1274 GenerateDiscontinuousJacobian( dataGLLJacobian, this->GetSourceAreas() );
1278 rval = this->SetDOFmapAssociation( eInputType, mapOptions.nPin, ( eInputType == DiscretizationType_CGLL ),
1279 &dataGLLNodesSrcCov, &dataGLLNodesSrc, eOutputType, mapOptions.nPout,
1283 if( is_root )
dbgprint.printf( 0,
"Calculating remap weights\n" );
1285 if( strMapAlgorithm ==
"volumetric" )
1287 _EXCEPTIONT(
"Unimplemented: Volumetric currently unavailable for"
1291 this->m_pdataGLLNodesIn = &dataGLLNodesSrcCov;
1292 this->m_pdataGLLNodesOut =
nullptr;
1294 #ifdef USE_NATIVE_TEMPESTREMAP_ROUTINES
1295 LinearRemapSE4( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, dataGLLNodesSrcCov, dataGLLJacobian,
1296 nMonotoneType, fContinuousIn, mapOptions.fNoConservation, mapOptions.fSparseConstraints,
1299 LinearRemapSE4_Tempest_MOAB( dataGLLNodesSrcCov, dataGLLJacobian, nMonotoneType, fContinuousIn,
1300 mapOptions.fNoConservation );
1303 else if( ( eInputType != DiscretizationType_FV ) && ( eOutputType != DiscretizationType_FV ) )
1305 DataArray3D< double > dataGLLJacobianIn, dataGLLJacobianSrc;
1306 DataArray3D< double > dataGLLJacobianOut;
1309 if( is_root )
dbgprint.printf( 0,
"Generating input mesh meta data\n" );
1310 GenerateMetaData( *m_meshInputCov, mapOptions.nPin, mapOptions.fNoBubble, dataGLLNodesSrcCov,
1311 dataGLLJacobianIn );
1313 double dNumericalAreaSrc_loc = GenerateMetaData( *m_meshInput, mapOptions.nPin, mapOptions.fNoBubble,
1314 dataGLLNodesSrc, dataGLLJacobianSrc );
1315 double dNumericalAreaIn = dNumericalAreaSrc_loc;
1316 #ifdef MOAB_HAVE_MPI
1318 MPI_Reduce( &dNumericalAreaSrc_loc, &dNumericalAreaIn, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
1322 dbgprint.printf( 0,
"Input Mesh Numerical Area: %1.15e\n", dNumericalAreaIn );
1324 if( fabs( dNumericalAreaIn - dTotalAreaInput ) > 1.0e-12 )
1326 dbgprint.printf( 0,
"WARNING: Significant mismatch between input mesh "
1327 "numerical area and geometric area\n" );
1332 if( is_root )
dbgprint.printf( 0,
"Generating output mesh meta data\n" );
1333 double dNumericalAreaOut_loc = GenerateMetaData( *m_meshOutput, mapOptions.nPout, mapOptions.fNoBubble,
1334 dataGLLNodesDest, dataGLLJacobianOut );
1335 double dNumericalAreaOut = dNumericalAreaOut_loc;
1336 #ifdef MOAB_HAVE_MPI
1338 MPI_Reduce( &dNumericalAreaOut_loc, &dNumericalAreaOut, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
1342 dbgprint.printf( 0,
"Output Mesh Numerical Area: %1.15e\n", dNumericalAreaOut );
1344 if( fabs( dNumericalAreaOut - dTotalAreaOutput ) > 1.0e-12 )
1347 dbgprint.printf( 0,
"WARNING: Significant mismatch between output mesh "
1348 "numerical area and geometric area\n" );
1353 this->InitializeSourceCoordinatesFromMeshFE( *m_meshInputCov, mapOptions.nPin, dataGLLNodesSrcCov );
1354 this->InitializeTargetCoordinatesFromMeshFE( *m_meshOutput, mapOptions.nPout, dataGLLNodesDest );
1357 bool fContinuousIn = ( eInputType == DiscretizationType_CGLL );
1359 if( eInputType == DiscretizationType_CGLL )
1361 GenerateUniqueJacobian( dataGLLNodesSrcCov, dataGLLJacobianIn, this->GetSourceAreas() );
1365 GenerateDiscontinuousJacobian( dataGLLJacobianIn, this->GetSourceAreas() );
1369 bool fContinuousOut = ( eOutputType == DiscretizationType_CGLL );
1371 if( eOutputType == DiscretizationType_CGLL )
1373 GenerateUniqueJacobian( dataGLLNodesDest, dataGLLJacobianOut, this->GetTargetAreas() );
1377 GenerateDiscontinuousJacobian( dataGLLJacobianOut, this->GetTargetAreas() );
1381 rval = this->SetDOFmapAssociation( eInputType, mapOptions.nPin, ( eInputType == DiscretizationType_CGLL ),
1382 &dataGLLNodesSrcCov, &dataGLLNodesSrc, eOutputType, mapOptions.nPout,
1383 ( eOutputType == DiscretizationType_CGLL ), &dataGLLNodesDest );
MB_CHK_ERR( rval );
1385 this->m_pdataGLLNodesIn = &dataGLLNodesSrcCov;
1386 this->m_pdataGLLNodesOut = &dataGLLNodesDest;
1389 if( is_root )
dbgprint.printf( 0,
"Calculating remap weights\n" );
1391 #ifdef USE_NATIVE_TEMPESTREMAP_ROUTINES
1392 LinearRemapGLLtoGLL_Integrated( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, dataGLLNodesSrcCov,
1393 dataGLLJacobianIn, dataGLLNodesDest, dataGLLJacobianOut,
1394 this->GetTargetAreas(), mapOptions.nPin, mapOptions.nPout, nMonotoneType,
1395 fContinuousIn, fContinuousOut, mapOptions.fSparseConstraints, *
this );
1397 LinearRemapGLLtoGLL2_MOAB( dataGLLNodesSrcCov, dataGLLJacobianIn, dataGLLNodesDest, dataGLLJacobianOut,
1398 this->GetTargetAreas(), mapOptions.nPin, mapOptions.nPout, nMonotoneType,
1399 fContinuousIn, fContinuousOut, mapOptions.fNoConservation );
1404 _EXCEPTIONT(
"Not implemented" );
1407 #ifdef MOAB_HAVE_EIGEN3
1408 copy_tempest_sparsemat_to_eigen3();
1411 #ifdef MOAB_HAVE_MPI
1415 rval = m_remapper->GetOverlapAugmentedEntities( ghostedEnts );
MB_CHK_ERR( rval );
1417 rval = m_interface->remove_entities( m_meshOverlapSet, ghostedEnts );
MB_CHK_SET_ERR( rval,
"Deleting ghosted entities failed" );
1421 if( !mapOptions.fNoCheck )
1423 if( is_root )
dbgprint.printf( 0,
"Verifying map" );
1424 this->IsConsistent( 1.0e-8 );
1425 if( !mapOptions.fNoConservation ) this->IsConservative( 1.0e-8 );
1427 if( nMonotoneType != 0 )
1429 this->IsMonotone( 1.0e-12 );
1433 catch( Exception& e )
1435 dbgprint.printf( 0,
"%s", e.ToString().c_str() );
1436 return ( moab::MB_FAILURE );
1440 return ( moab::MB_FAILURE );
1449 #ifndef MOAB_HAVE_MPI
1451 return OfflineMap::IsConsistent( dTolerance );
1456 DataArray1D< int > dataRows;
1457 DataArray1D< int > dataCols;
1458 DataArray1D< double > dataEntries;
1461 DataArray1D< double > dRowSums;
1462 m_mapRemap.GetEntries( dataRows, dataCols, dataEntries );
1463 dRowSums.Allocate( m_mapRemap.GetRows() );
1465 for(
unsigned i = 0; i < dataRows.GetRows(); i++ )
1467 dRowSums[dataRows[i]] += dataEntries[i];
1471 int fConsistent = 0;
1472 for(
unsigned i = 0; i < dRowSums.GetRows(); i++ )
1474 if( fabs( dRowSums[i] - 1.0 ) > dTolerance )
1477 int rowGID = row_gdofmap[i];
1478 Announce(
"TempestOnlineMap is not consistent in row %i (%1.15e)", rowGID, dRowSums[i] );
1483 int fConsistentGlobal = 0;
1484 ierr = MPI_Allreduce( &fConsistent, &fConsistentGlobal, 1, MPI_INT, MPI_SUM, m_pcomm->comm() );
1485 if( ierr != MPI_SUCCESS )
return -1;
1487 return fConsistentGlobal;
1495 #ifndef MOAB_HAVE_MPI
1497 return OfflineMap::IsConservative( dTolerance );
1504 DataArray1D< int > dataRows;
1505 DataArray1D< int > dataCols;
1506 DataArray1D< double > dataEntries;
1507 const DataArray1D< double >& dTargetAreas = this->GetTargetAreas();
1508 const DataArray1D< double >& dSourceAreas = this->GetSourceAreas();
1511 std::vector< int > dColumnsUnique;
1512 std::vector< double > dColumnSums;
1514 int nColumns = m_mapRemap.GetColumns();
1515 m_mapRemap.GetEntries( dataRows, dataCols, dataEntries );
1516 dColumnSums.resize( m_nTotDofs_SrcCov, 0.0 );
1517 dColumnsUnique.resize( m_nTotDofs_SrcCov, -1 );
1519 for(
unsigned i = 0; i < dataEntries.GetRows(); i++ )
1521 dColumnSums[dataCols[i]] += dataEntries[i] * dTargetAreas[dataRows[i]] / dSourceAreas[dataCols[i]];
1523 assert( dataCols[i] < m_nTotDofs_SrcCov );
1526 int colGID = this->GetColGlobalDoF( dataCols[i] );
1528 dColumnsUnique[dataCols[i]] = colGID;
1535 std::vector< int > nElementsInProc;
1536 const int nDATA = 3;
1537 nElementsInProc.resize(
size * nDATA );
1538 int senddata[nDATA] = { nColumns, m_nTotDofs_SrcCov, m_nTotDofs_Src };
1539 ierr = MPI_Gather( senddata, nDATA, MPI_INT, nElementsInProc.data(), nDATA, MPI_INT, rootProc, m_pcomm->comm() );
1540 if( ierr != MPI_SUCCESS )
return -1;
1542 int nTotVals = 0, nTotColumns = 0, nTotColumnsUnq = 0;
1543 std::vector< int > dColumnIndices;
1544 std::vector< double > dColumnSourceAreas;
1545 std::vector< double > dColumnSumsTotal;
1546 std::vector< int > displs, rcount;
1547 if( rank == rootProc )
1549 displs.resize(
size + 1, 0 );
1550 rcount.resize(
size, 0 );
1552 for(
int ir = 0; ir <
size; ++ir )
1554 nTotVals += nElementsInProc[ir * nDATA];
1555 nTotColumns += nElementsInProc[ir * nDATA + 1];
1556 nTotColumnsUnq += nElementsInProc[ir * nDATA + 2];
1559 rcount[ir] = nElementsInProc[ir * nDATA + 1];
1565 printf(
"Total nnz: %d, global source elements = %d\n", nTotVals, gsum );
1567 dColumnIndices.resize( nTotColumns, -1 );
1568 dColumnSumsTotal.resize( nTotColumns, 0.0 );
1577 ierr = MPI_Gatherv( &dColumnsUnique[0], m_nTotDofs_SrcCov, MPI_INT, &dColumnIndices[0], rcount.data(),
1578 displs.data(), MPI_INT, rootProc, m_pcomm->comm() );
1579 if( ierr != MPI_SUCCESS )
return -1;
1580 ierr = MPI_Gatherv( &dColumnSums[0], m_nTotDofs_SrcCov, MPI_DOUBLE, &dColumnSumsTotal[0], rcount.data(),
1581 displs.data(), MPI_DOUBLE, rootProc, m_pcomm->comm() );
1582 if( ierr != MPI_SUCCESS )
return -1;
1588 dColumnSums.clear();
1589 dColumnsUnique.clear();
1592 int fConservative = 0;
1593 if( rank == rootProc )
1595 displs[
size] = ( nTotColumns );
1597 std::map< int, double > dColumnSumsOnRoot;
1599 for(
int ir = 0; ir <
size; ir++ )
1601 for(
int ips = displs[ir]; ips < displs[ir + 1]; ips++ )
1603 if( dColumnIndices[ips] < 0 )
continue;
1605 assert( dColumnIndices[ips] < nTotColumnsUnq );
1606 dColumnSumsOnRoot[dColumnIndices[ips]] += dColumnSumsTotal[ips];
1612 for( std::map< int, double >::iterator it = dColumnSumsOnRoot.begin(); it != dColumnSumsOnRoot.end(); ++it )
1615 if( fabs( it->second - 1.0 ) > dTolerance )
1618 Announce(
"TempestOnlineMap is not conservative in column "
1621 it->first, it->second );
1627 ierr = MPI_Bcast( &fConservative, 1, MPI_INT, rootProc, m_pcomm->comm() );
1628 if( ierr != MPI_SUCCESS )
return -1;
1630 return fConservative;
1638 #ifndef MOAB_HAVE_MPI
1640 return OfflineMap::IsMonotone( dTolerance );
1645 DataArray1D< int > dataRows;
1646 DataArray1D< int > dataCols;
1647 DataArray1D< double > dataEntries;
1649 m_mapRemap.GetEntries( dataRows, dataCols, dataEntries );
1653 for(
unsigned i = 0; i < dataRows.GetRows(); i++ )
1655 if( ( dataEntries[i] < -dTolerance ) || ( dataEntries[i] > 1.0 + dTolerance ) )
1659 Announce(
"TempestOnlineMap is not monotone in entry (%i): %1.15e", i, dataEntries[i] );
1664 int fMonotoneGlobal = 0;
1665 ierr = MPI_Allreduce( &fMonotone, &fMonotoneGlobal, 1, MPI_INT, MPI_SUM, m_pcomm->comm() );
1666 if( ierr != MPI_SUCCESS )
return -1;
1668 return fMonotoneGlobal;
1677 bool useMOABAdjacencies,
1680 assert( nrings > 0 );
1681 assert( useMOABAdjacencies || trMesh !=
nullptr );
1683 const size_t nrows = vecAdjFaces.size();
1685 for(
size_t index = 0; index < nrows; index++ )
1687 vecAdjFaces[index].insert( index );
1690 if( useMOABAdjacencies )
1700 int adjIndex =
entities.index( *it );
1702 if( adjIndex >= 0 ) vecAdjFaces[index].insert( adjIndex );
1711 Face&
face = trMesh->faces[index];
1712 GetAdjacentFaceVectorByEdge( *trMesh, index, nrings *
face.edges.size(), adjFaces );
1715 for(
auto adjFace : adjFaces )
1716 if( adjFace.first >= 0 )
1717 vecAdjFaces[index].insert( adjFace.first );
1727 double default_projection )
1731 std::vector< double > solSTagVals;
1732 std::vector< double > solTTagVals;
1735 if( m_remapper->point_cloud_source || m_remapper->point_cloud_target )
1737 if( m_remapper->point_cloud_source )
1740 solSTagVals.resize( covSrcEnts.
size(), default_projection );
1746 solSTagVals.resize( covSrcEnts.
size() * this->GetSourceNDofsPerElement() * this->GetSourceNDofsPerElement(),
1747 default_projection );
1750 if( m_remapper->point_cloud_target )
1753 solTTagVals.resize( tgtEnts.
size(), default_projection );
1759 solTTagVals.resize( tgtEnts.
size() * this->GetDestinationNDofsPerElement() *
1760 this->GetDestinationNDofsPerElement(),
1761 default_projection );
1769 solSTagVals.resize( covSrcEnts.
size() * this->GetSourceNDofsPerElement() * this->GetSourceNDofsPerElement(),
1770 default_projection );
1771 solTTagVals.resize( tgtEnts.
size() * this->GetDestinationNDofsPerElement() *
1772 this->GetDestinationNDofsPerElement(),
1773 default_projection );
1780 rval = m_interface->tag_get_data( srcSolutionTag, sents, &solSTagVals[0] );
MB_CHK_SET_ERR( rval,
"Getting local tag data failed" );
1785 rval = this->ApplyWeights( solSTagVals, solTTagVals, transpose );
MB_CHK_SET_ERR( rval,
"Applying remap operator onto source vector data failed" );
1787 if( caasType != CAAS_NONE )
1789 std::string tgtSolutionTagName;
1790 rval = m_interface->tag_get_name( tgtSolutionTag, tgtSolutionTagName );
MB_CHK_SET_ERR( rval,
"Getting tag name failed" );
1793 constexpr
int nmax_caas_iterations = 10;
1794 double mismatch = 1.0;
1795 int caasIteration = 0;
1796 double initialMismatch = 0.0;
1797 while( ( fabs( mismatch / initialMismatch ) > 1e-15 && fabs( mismatch ) > 1e-15 ) &&
1798 caasIteration++ < nmax_caas_iterations )
1801 rval = m_interface->tag_set_data( tgtSolutionTag, tents, &solTTagVals[0] );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1803 double dMassDiffPostGlobal;
1804 std::pair< double, double > mDefect =
1805 this->ApplyBoundsLimiting( solSTagVals, solTTagVals, caasType, caasIteration, mismatch );
1806 #ifdef MOAB_HAVE_MPI
1807 double dMassDiffPost = mDefect.second;
1808 MPI_Allreduce( &dMassDiffPost, &dMassDiffPostGlobal, 1, MPI_DOUBLE, MPI_SUM, m_pcomm->comm() );
1810 dMassDiffPostGlobal = mDefect.second;
1812 if( caasIteration == 1 ) initialMismatch = mDefect.first;
1813 if( m_remapper->verbose && is_root )
1815 printf(
"Field {%s} -> CAAS iteration: %d, mass defect: %3.4e, post-CAAS: %3.4e\n",
1816 tgtSolutionTagName.c_str(), caasIteration, mDefect.first, dMassDiffPostGlobal );
1818 mismatch = dMassDiffPostGlobal;
1823 rval = m_interface->tag_set_data( tgtSolutionTag, tents, &solTTagVals[0] );
MB_CHK_SET_ERR( rval,
"Setting local tag data failed" );
1829 const std::string& solnName,
1831 sample_function testFunction,
1833 std::string cloneSolnName )
1836 const bool outputEnabled = ( is_root );
1846 trmesh = m_remapper->m_covering_source;
1847 entities = ( m_remapper->point_cloud_source ? m_remapper->m_covering_source_vertices
1848 : m_remapper->m_covering_source_entities );
1849 discOrder = m_nDofsPEl_Src;
1850 discMethod = m_eInputType;
1855 trmesh = m_remapper->m_target;
1857 ( m_remapper->point_cloud_target ? m_remapper->m_target_vertices : m_remapper->m_target_entities );
1858 discOrder = m_nDofsPEl_Dest;
1859 discMethod = m_eOutputType;
1864 std::cout <<
"Invalid context specified for defining an analytical solution tag" << std::endl;
1865 return moab::MB_FAILURE;
1870 rval = m_interface->tag_get_handle( solnName.c_str(), discOrder * discOrder,
MB_TYPE_DOUBLE, solnTag,
1872 if( clonedSolnTag !=
nullptr )
1874 if( cloneSolnName.size() == 0 )
1876 cloneSolnName = solnName + std::string(
"Cloned" );
1878 rval = m_interface->tag_get_handle( cloneSolnName.c_str(), discOrder * discOrder,
MB_TYPE_DOUBLE,
1883 const int TriQuadratureOrder = 10;
1885 if( outputEnabled ) std::cout <<
"Using triangular quadrature of order " << TriQuadratureOrder << std::endl;
1887 TriangularQuadratureRule triquadrule( TriQuadratureOrder );
1889 const int TriQuadraturePoints = triquadrule.GetPoints();
1891 const DataArray2D< double >& TriQuadratureG = triquadrule.GetG();
1892 const DataArray1D< double >& TriQuadratureW = triquadrule.GetW();
1895 DataArray1D< double > dVar;
1896 DataArray1D< double > dVarMB;
1899 DataArray1D< double > dNodeArea;
1904 if( discMethod == DiscretizationType_CGLL || discMethod == DiscretizationType_DGLL )
1907 const bool fGLL =
true;
1908 const bool fGLLIntegrate =
false;
1911 DataArray3D< int > dataGLLNodes;
1912 DataArray3D< double > dataGLLJacobian;
1914 GenerateMetaData( *trmesh, discOrder,
false, dataGLLNodes, dataGLLJacobian );
1917 int nElements = trmesh->faces.size();
1920 for(
int k = 0; k < nElements; k++ )
1922 const Face&
face = trmesh->faces[k];
1924 if(
face.edges.size() != 4 )
1926 _EXCEPTIONT(
"Non-quadrilateral face detected; "
1927 "incompatible with --gll" );
1933 for(
int i = 0; i < discOrder; i++ )
1935 for(
int j = 0; j < discOrder; j++ )
1937 for(
int k = 0; k < nElements; k++ )
1939 if( dataGLLNodes[i][j][k] > iMaxNode )
1941 iMaxNode = dataGLLNodes[i][j][k];
1948 DataArray1D< double > dG;
1949 DataArray1D< double > dW;
1951 GaussLobattoQuadrature::GetPoints( discOrder, 0.0, 1.0, dG, dW );
1954 const int nGaussP = 10;
1956 DataArray1D< double > dGaussG;
1957 DataArray1D< double > dGaussW;
1959 GaussQuadrature::GetPoints( nGaussP, 0.0, 1.0, dGaussG, dGaussW );
1962 dVar.Allocate( iMaxNode );
1963 dVarMB.Allocate( discOrder * discOrder * nElements );
1964 dNodeArea.Allocate( iMaxNode );
1967 for(
int k = 0; k < nElements; k++ )
1969 const Face&
face = trmesh->faces[k];
1974 for(
int i = 0; i < discOrder; i++ )
1976 for(
int j = 0; j < discOrder; j++ )
1984 ApplyLocalMap(
face, trmesh->nodes, dG[i], dG[j], node, dDx1G, dDx2G );
1987 double dNodeLon = atan2( node.y, node.x );
1988 if( dNodeLon < 0.0 )
1990 dNodeLon += 2.0 * M_PI;
1992 double dNodeLat = asin( node.z );
1994 double dSample = ( *testFunction )( dNodeLon, dNodeLat );
1996 dVar[dataGLLNodes[j][i][k] - 1] = dSample;
2003 DataArray2D< double > dCoeff( discOrder, discOrder );
2005 for(
int p = 0; p < nGaussP; p++ )
2007 for(
int q = 0; q < nGaussP; q++ )
2015 ApplyLocalMap(
face, trmesh->nodes, dGaussG[p], dGaussG[q], node, dDx1G, dDx2G );
2018 Node nodeCross = CrossProduct( dDx1G, dDx2G );
2021 sqrt( nodeCross.x * nodeCross.x + nodeCross.y * nodeCross.y + nodeCross.z * nodeCross.z );
2025 SampleGLLFiniteElement( 0, discOrder, dGaussG[p], dGaussG[q], dCoeff );
2028 double dNodeLon = atan2( node.y, node.x );
2029 if( dNodeLon < 0.0 )
2031 dNodeLon += 2.0 * M_PI;
2033 double dNodeLat = asin( node.z );
2035 double dSample = ( *testFunction )( dNodeLon, dNodeLat );
2038 for(
int i = 0; i < discOrder; i++ )
2040 for(
int j = 0; j < discOrder; j++ )
2043 double dNodalArea = dCoeff[i][j] * dGaussW[p] * dGaussW[q] * dJacobian;
2045 dVar[dataGLLNodes[i][j][k] - 1] += dSample * dNodalArea;
2047 dNodeArea[dataGLLNodes[i][j][k] - 1] += dNodalArea;
2058 for(
size_t i = 0; i < dVar.GetRows(); i++ )
2060 dVar[i] /= dNodeArea[i];
2067 for(
unsigned j = 0; j <
entities.size(); j++ )
2068 for(
int p = 0; p < discOrder; p++ )
2069 for(
int q = 0; q < discOrder; q++ )
2071 const int offsetDOF = j * discOrder * discOrder + p * discOrder + q;
2072 dVarMB[offsetDOF] = dVar[col_dtoc_dofmap[offsetDOF]];
2077 for(
unsigned j = 0; j <
entities.size(); j++ )
2078 for(
int p = 0; p < discOrder; p++ )
2079 for(
int q = 0; q < discOrder; q++ )
2081 const int offsetDOF = j * discOrder * discOrder + p * discOrder + q;
2082 dVarMB[offsetDOF] = dVar[row_dtoc_dofmap[offsetDOF]];
2087 rval = m_interface->tag_set_data( solnTag,
entities, &dVarMB[0] );
MB_CHK_ERR( rval );
2092 if( discMethod == DiscretizationType_FV )
2097 dVar.Allocate( trmesh->faces.size() );
2099 std::vector< Node >& nodes = trmesh->nodes;
2102 for(
size_t i = 0; i < trmesh->faces.size(); i++ )
2104 const Face&
face = trmesh->faces[i];
2107 for(
size_t j = 0; j <
face.edges.size() - 2; j++ )
2110 const Node& node0 = nodes[
face[0]];
2111 const Node& node1 = nodes[
face[j + 1]];
2112 const Node& node2 = nodes[
face[j + 2]];
2116 faceTri.SetNode( 0,
face[0] );
2117 faceTri.SetNode( 1,
face[j + 1] );
2118 faceTri.SetNode( 2,
face[j + 2] );
2120 double dTriangleArea = CalculateFaceArea( faceTri, nodes );
2123 double dTotalSample = 0.0;
2126 for(
int k = 0; k < TriQuadraturePoints; k++ )
2128 Node node( TriQuadratureG[k][0] * node0.x + TriQuadratureG[k][1] * node1.x +
2129 TriQuadratureG[k][2] * node2.x,
2130 TriQuadratureG[k][0] * node0.y + TriQuadratureG[k][1] * node1.y +
2131 TriQuadratureG[k][2] * node2.y,
2132 TriQuadratureG[k][0] * node0.z + TriQuadratureG[k][1] * node1.z +
2133 TriQuadratureG[k][2] * node2.z );
2135 double dMagnitude = node.Magnitude();
2136 node.x /= dMagnitude;
2137 node.y /= dMagnitude;
2138 node.z /= dMagnitude;
2140 double dLon = atan2( node.y, node.x );
2145 double dLat = asin( node.z );
2147 double dSample = ( *testFunction )( dLon, dLat );
2149 dTotalSample += dSample * TriQuadratureW[k] * dTriangleArea;
2152 dVar[i] += dTotalSample / trmesh->vecFaceArea[i];
2160 std::vector< Node >& nodes = trmesh->nodes;
2163 dVar.Allocate( nodes.size() );
2165 for(
size_t j = 0; j < nodes.size(); j++ )
2167 Node& node = nodes[j];
2168 double dMagnitude = node.Magnitude();
2169 node.x /= dMagnitude;
2170 node.y /= dMagnitude;
2171 node.z /= dMagnitude;
2172 double dLon = atan2( node.y, node.x );
2177 double dLat = asin( node.z );
2179 double dSample = ( *testFunction )( dLon, dLat );
2193 std::map< std::string, double >& metrics,
2197 const bool outputEnabled = ( is_root );
2208 entities = ( m_remapper->point_cloud_source ? m_remapper->m_covering_source_vertices
2209 : m_remapper->m_covering_source_entities );
2210 discOrder = m_nDofsPEl_Src;
2218 ( m_remapper->point_cloud_target ? m_remapper->m_target_vertices : m_remapper->m_target_entities );
2219 discOrder = m_nDofsPEl_Dest;
2225 std::cout <<
"Invalid context specified for defining an analytical solution tag" << std::endl;
2226 return moab::MB_FAILURE;
2231 std::string exactTagName, projTagName;
2232 const int ntotsize =
entities.size() * discOrder * discOrder;
2233 std::vector< double > exactSolution( ntotsize, 0.0 ), projSolution( ntotsize, 0.0 );
2234 rval = m_interface->tag_get_name( exactTag, exactTagName );
MB_CHK_ERR( rval );
2235 rval = m_interface->tag_get_data( exactTag,
entities, &exactSolution[0] );
MB_CHK_ERR( rval );
2236 rval = m_interface->tag_get_name( approxTag, projTagName );
MB_CHK_ERR( rval );
2237 rval = m_interface->tag_get_data( approxTag,
entities, &projSolution[0] );
MB_CHK_ERR( rval );
2239 const auto& ovents = m_remapper->m_overlap_entities;
2241 std::vector< double > errnorms( 4, 0.0 ), globerrnorms( 4, 0.0 );
2242 double sumarea = 0.0;
2243 for(
size_t i = 0; i < ovents.size(); ++i )
2245 const int srcidx = m_remapper->m_overlap->vecSourceFaceIx[i];
2246 if( srcidx < 0 )
continue;
2247 const int tgtidx = m_remapper->m_overlap->vecTargetFaceIx[i];
2248 if( tgtidx < 0 )
continue;
2249 const double ovarea = m_remapper->m_overlap->vecFaceArea[i];
2250 const double error = fabs( exactSolution[tgtidx] - projSolution[tgtidx] );
2251 errnorms[0] += ovarea *
error;
2253 errnorms[3] = (
error > errnorms[3] ?
error : errnorms[3] );
2256 errnorms[2] = sumarea;
2257 #ifdef MOAB_HAVE_MPI
2260 MPI_Reduce( &errnorms[0], &globerrnorms[0], 3, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
2261 MPI_Reduce( &errnorms[3], &globerrnorms[3], 1, MPI_DOUBLE, MPI_MAX, 0, m_pcomm->comm() );
2264 for(
int i = 0; i < 4; ++i )
2265 globerrnorms[i] = errnorms[i];
2268 globerrnorms[0] = ( globerrnorms[0] / globerrnorms[2] );
2269 globerrnorms[1] = std::sqrt( globerrnorms[1] / globerrnorms[2] );
2272 metrics[
"L1Error"] = globerrnorms[0];
2273 metrics[
"L2Error"] = globerrnorms[1];
2274 metrics[
"LinfError"] = globerrnorms[3];
2278 std::cout <<
"Error metrics when comparing " << projTagName <<
" against " << exactTagName << std::endl;
2279 std::cout <<
"\t Total Intersection area = " << globerrnorms[2] << std::endl;
2280 std::cout <<
"\t L_1 error = " << globerrnorms[0] << std::endl;
2281 std::cout <<
"\t L_2 error = " << globerrnorms[1] << std::endl;
2282 std::cout <<
"\t L_inf error = " << globerrnorms[3] << std::endl;