81 #include <H5Tpublic.h>
90 #ifdef MOAB_HAVE_TEMPESTREMAP
91 #include "STLStringHelper.h"
103 using namespace moab;
114 #ifdef MOAB_HAVE_TEMPESTREMAP
115 struct TempestMapAppData
118 std::map< std::string, moab::TempestOnlineMap* > weightMaps;
121 int num_src_ghost_layers;
122 int num_tgt_ghost_layers;
160 #ifdef MOAB_HAVE_TEMPESTREMAP
164 TempestMapAppData tempestData;
165 std::map< std::string, std::string > metadataMap;
242 for(
int i = 0; i < 4; i++ )
258 MPI_Initialized( &flagInit );
337 std::string appstr( str );
339 unsigned int h = 2166136261u;
342 for(
char c : appstr )
344 h ^=
static_cast< unsigned char >( c );
351 h ^=
static_cast< unsigned int >( identifier & 0xFFFFFFFF );
354 return static_cast< int >( h & 0x7FFFFFFF );
411 std::string name( app_name );
415 std::cout <<
" application " << name <<
" already registered \n";
416 return moab::MB_FAILURE;
422 *pid =
apphash( app_name, *compid );
427 MPI_Comm_rank( *comm, &rankHere );
430 std::cout <<
" application " << name <<
" with ID = " << *pid <<
" and external id: " << *compid
431 <<
" is registered now \n";
434 std::cout <<
" convention for external application is to have its id positive \n";
435 return moab::MB_FAILURE;
445 app_data.
name = name;
447 #ifdef MOAB_HAVE_TEMPESTREMAP
448 app_data.tempestData.remapper =
nullptr;
449 app_data.tempestData.num_src_ghost_layers = 0;
450 app_data.tempestData.num_tgt_ghost_layers = 0;
457 #ifdef MOAB_HAVE_TEMPESTREMAP
458 app_data.secondary_file_set = app_data.
file_set;
503 assert( app_name !=
nullptr );
504 std::string name( app_name );
512 ccomm = MPI_Comm_f2c( (MPI_Fint)*comm );
568 appData& data = appIterator->second;
574 std::cout <<
" application with ID: " << *pid <<
" global id: " << data.
global_id <<
" name: " << data.
name
575 <<
" is de-registered now \n";
581 "can't get file entities" );
582 fileents.
insert( fileSet );
584 "can't get file entities" );
586 #ifdef MOAB_HAVE_TEMPESTREMAP
587 if( data.tempestData.remapper )
delete data.tempestData.remapper;
588 if( data.tempestData.weightMaps.size() ) data.tempestData.weightMaps.clear();
595 auto& pargs = data.
pgraph;
597 for(
auto mt = pargs.begin(); mt != pargs.end(); ++mt )
610 data.
pcomm =
nullptr;
622 "can't get 1D adjacencies" );
624 "can't get 2D adjacencies" );
626 "can't get 3D adjacencies" );
628 if( !adj_ents_left.
empty() )
632 vertices =
subtract( vertices, conn_verts );
639 if( *pid == mit->second )
645 data.
pcomm =
nullptr;
715 int* num_global_vertices,
716 int* num_global_elements,
721 IMOAB_ASSERT( strlen( filename ),
"Invalid filename length." );
723 #ifdef MOAB_HAVE_HDF5
724 std::string filen( filename );
729 if( num_global_vertices ) *num_global_vertices = 0;
730 if( num_global_elements ) *num_global_elements = 0;
731 if( num_dimension ) *num_dimension = 0;
732 if( num_parts ) *num_parts = 0;
736 unsigned long max_id;
739 file =
mhdf_openFile( filen.c_str(), 0, &max_id, -1, &status );
743 fprintf( stderr,
"%s: %s\n", filename,
mhdf_message( &status ) );
744 return moab::MB_FAILURE;
752 fprintf( stderr,
"%s: %s\n", filename,
mhdf_message( &status ) );
753 return moab::MB_FAILURE;
757 if( num_global_vertices ) *num_global_vertices = (int)data->
nodes.
count;
766 edges += ent_d->
count;
771 faces += ent_d->
count;
776 faces += ent_d->
count;
781 faces += ent_d->
count;
786 regions += ent_d->
count;
791 regions += ent_d->
count;
796 regions += ent_d->
count;
801 regions += ent_d->
count;
806 regions += ent_d->
count;
811 regions += ent_d->
count;
816 regions += ent_d->
count;
820 if( num_parts ) *num_parts = data->
numEntSets[0];
825 if( num_dimension ) *num_dimension = 1;
826 if( num_global_elements ) *num_global_elements = edges;
831 if( num_dimension ) *num_dimension = 2;
832 if( num_global_elements ) *num_global_elements = faces;
837 if( num_dimension ) *num_dimension = 3;
838 if( num_global_elements ) *num_global_elements = regions;
846 std::cout << filename
847 <<
": Please reconfigure with HDF5. Cannot retrieve header information for file "
848 "formats other than a h5m file.\n";
849 if( num_global_vertices ) *num_global_vertices = 0;
850 if( num_global_elements ) *num_global_elements = 0;
851 if( num_dimension ) *num_dimension = 0;
852 if( num_parts ) *num_parts = 0;
898 int* num_ghost_layers )
901 IMOAB_ASSERT( strlen( filename ),
"Invalid filename length." );
905 std::ostringstream newopts;
906 if( read_options ) newopts << read_options;
914 std::string opts( ( read_options ? read_options :
"" ) );
915 std::string pcid(
"PARALLEL_COMM=" );
916 std::size_t found = opts.find( pcid );
918 if( found != std::string::npos )
920 std::cerr <<
" cannot specify PARALLEL_COMM option, it is implicit \n";
921 return moab::MB_FAILURE;
926 std::string filen( filename );
927 std::string::size_type idx = filen.rfind(
'.' );
929 if( idx != std::string::npos )
932 std::string extension = filen.substr( idx + 1 );
933 if( ( extension == std::string(
"h5m" ) ) || ( extension == std::string(
"nc" ) ) )
934 newopts <<
";;PARALLEL_COMM=" << pco->
get_id();
937 if( *num_ghost_layers >= 1 )
941 std::string pcid2(
"PARALLEL_GHOSTS=" );
942 std::size_t found2 = opts.find( pcid2 );
944 if( found2 != std::string::npos )
946 std::cout <<
" PARALLEL_GHOSTS option is already specified, ignore passed "
947 "number of layers \n";
954 newopts <<
";PARALLEL_GHOSTS=3.0." << *num_ghost_layers <<
".3";
960 IMOAB_ASSERT( *num_ghost_layers == 0,
"Cannot provide ghost layers in serial." );
969 std::ostringstream outfile;
972 int rank = pco->
rank();
973 int nprocs = pco->
size();
974 outfile <<
"TaskMesh_n" << nprocs <<
"." << rank <<
".h5m";
976 outfile <<
"TaskMesh_n1.0.h5m";
981 "can't write file" );
994 bool primary_set =
true )
997 IMOAB_ASSERT( strlen( filename ),
"Invalid filename length." );
1002 std::ostringstream newopts;
1003 #ifdef MOAB_HAVE_MPI
1004 std::string write_opts( ( write_options ? write_options :
"" ) );
1005 std::string pcid(
"PARALLEL_COMM=" );
1007 if( write_opts.find( pcid ) != std::string::npos )
1009 std::cerr <<
" cannot specify PARALLEL_COMM option, it is implicit \n";
1010 return moab::MB_FAILURE;
1014 std::string pw(
"PARALLEL=WRITE_PART" );
1015 if( write_opts.find( pw ) != std::string::npos )
1018 newopts <<
"PARALLEL_COMM=" << pco->
get_id() <<
";";
1023 #ifdef MOAB_HAVE_TEMPESTREMAP
1026 if( data.tempestData.remapper !=
nullptr )
1028 else if( data.
file_set != data.secondary_file_set )
1029 fileSet = data.secondary_file_set;
1031 MB_CHK_SET_ERR( moab::MB_FAILURE,
"Invalid secondary file set handle" );
1036 if( write_options ) newopts << write_options;
1038 std::vector< Tag > copyTagList = data.
tagList;
1040 std::string gid_name_tag(
"GLOBAL_ID" );
1043 if( data.
tagMap.find( gid_name_tag ) == data.
tagMap.end() )
1046 copyTagList.push_back( gid );
1049 std::string pp_name_tag(
"PARALLEL_PARTITION" );
1052 if( data.
tagMap.find( pp_name_tag ) == data.
tagMap.end() )
1056 if( ptag ) copyTagList.push_back( ptag );
1063 copyTagList.size() ) );
1134 IMOAB_ASSERT( strlen( prefix ),
"Invalid prefix string length." );
1137 std::ostringstream file_name;
1138 int rank = 0, size = 1;
1139 #ifdef MOAB_HAVE_MPI
1141 rank = pcomm->
rank();
1142 size = pcomm->
size();
1144 file_name << prefix <<
"_" << size <<
"_" << rank <<
".h5m";
1206 "can't get vertices" );
1211 "can't get primary elements" );
1218 "can't get primary elements" );
1225 "can't get primary elements" );
1238 #ifdef MOAB_HAVE_MPI
1246 "can't filter ghost vertices" );
1253 "can't filter ghost elements" );
1260 "can't filter ghost vertices" );
1261 int local[2], global[2];
1264 MPI_Allreduce( local, global, 2, MPI_INT, MPI_SUM, pco->
comm() );
1283 "can't get material sets" );
1287 "can't get neumann sets" );
1291 "can't get dirichlet sets" );
1333 int* num_visible_vertices,
1334 int* num_visible_elements,
1335 int* num_visible_blocks,
1336 int* num_visible_surfaceBC,
1337 int* num_visible_vertexBC )
1344 if( num_visible_elements )
1348 num_visible_elements[0] =
static_cast< int >( data.
owned_elems.
size() );
1349 num_visible_elements[1] =
static_cast< int >( data.
ghost_elems.
size() );
1351 if( num_visible_vertices )
1353 num_visible_vertices[2] =
static_cast< int >( data.
all_verts.
size() );
1356 num_visible_vertices[0] = num_visible_vertices[2] - num_visible_vertices[1];
1359 if( num_visible_blocks )
1363 "can't get material sets" );
1366 num_visible_blocks[0] = num_visible_blocks[2];
1367 num_visible_blocks[1] = 0;
1370 if( num_visible_surfaceBC )
1374 "can't get neumann sets" );
1376 num_visible_surfaceBC[2] = 0;
1381 for(
int i = 0; i < numNeuSets; i++ )
1386 "can't get neumann sets" );
1391 Range adjPrimaryEnts;
1393 "can't get adjacencies" );
1395 num_visible_surfaceBC[2] += (int)adjPrimaryEnts.
size();
1399 num_visible_surfaceBC[0] = num_visible_surfaceBC[2];
1400 num_visible_surfaceBC[1] = 0;
1403 if( num_visible_vertexBC )
1407 "can't get dirichlet sets" );
1409 num_visible_vertexBC[2] = 0;
1412 for(
int i = 0; i < numDiriSets; i++ )
1418 num_visible_vertexBC[2] += (int)verts.
size();
1421 num_visible_vertexBC[0] = num_visible_vertexBC[2];
1422 num_visible_vertexBC[1] = 0;
1460 IMOAB_ASSERT( *vertices_length ==
static_cast< int >( verts.
size() ),
"Invalid vertices length provided" );
1492 assert( vertices_length && *vertices_length );
1493 assert( visible_global_rank_ID );
1497 #ifdef MOAB_HAVE_MPI
1509 if( i != *vertices_length )
1516 if( (
int)verts.
size() != *vertices_length )
1524 visible_global_rank_ID[i] = 0;
1562 if( *coords_length != 3 * (
int)verts.
size() )
1604 if( *block_length != (
int)matSets.
size() )
1611 "can't get material IDs" );
1615 for(
unsigned i = 0; i < matSets.
size(); i++ )
1617 matIdx[global_block_IDs[i]] = i;
1652 int* vertices_per_element,
1653 int* num_elements_in_block )
1655 assert( global_block_ID );
1658 std::map< int, int >::iterator it = matMap.find( *global_block_ID );
1660 if( it == matMap.end() )
1662 return moab::MB_FAILURE;
1665 int blockIndex = matMap[*global_block_ID];
1670 if( blo_elems.
empty() )
return moab::MB_FAILURE;
1674 if( !blo_elems.
all_of_type( type ) )
return moab::MB_FAILURE;
1680 *vertices_per_element = num_verts;
1681 *num_elements_in_block = (int)blo_elems.
size();
1687 int* num_visible_elements,
1693 #ifdef MOAB_HAVE_MPI
1698 "can't get global IDs" );
1704 #ifdef MOAB_HAVE_MPI
1721 "can't get material tag" );
1730 return moab::MB_FAILURE;
1733 if( -1 >= *num_visible_elements )
1735 return moab::MB_FAILURE;
1738 block_IDs[
index] = valMatTag;
1747 int* connectivity_length,
1748 int* element_connectivity )
1750 assert( global_block_ID );
1751 assert( connectivity_length );
1754 std::map< int, int >& matMap = data.
matIndex;
1755 std::map< int, int >::iterator it = matMap.find( *global_block_ID );
1757 if( it == matMap.end() )
1759 return moab::MB_FAILURE;
1762 int blockIndex = matMap[*global_block_ID];
1764 std::vector< EntityHandle > elems;
1768 if( elems.empty() )
return moab::MB_FAILURE;
1770 std::vector< EntityHandle > vconnect;
1773 if( *connectivity_length != (
int)vconnect.size() )
1775 return moab::MB_FAILURE;
1778 for(
int i = 0; i < *connectivity_length; i++ )
1784 return moab::MB_FAILURE;
1787 element_connectivity[i] = inx;
1795 int* connectivity_length,
1796 int* element_connectivity )
1798 assert( elem_index );
1799 assert( connectivity_length );
1802 assert( ( *elem_index >= 0 ) && ( *elem_index < (
int)data.
primary_elems.
size() ) );
1811 if( *connectivity_length < num_nodes )
1813 return moab::MB_FAILURE;
1816 for(
int i = 0; i < num_nodes; i++ )
1822 return moab::MB_FAILURE;
1825 element_connectivity[i] =
index;
1828 *connectivity_length = num_nodes;
1835 int* num_elements_in_block,
1836 int* element_ownership )
1838 assert( global_block_ID );
1839 assert( num_elements_in_block );
1843 std::map< int, int >::iterator it = matMap.find( *global_block_ID );
1845 if( it == matMap.end() )
1847 return moab::MB_FAILURE;
1850 int blockIndex = matMap[*global_block_ID];
1856 if( elems.
empty() )
return moab::MB_FAILURE;
1858 if( *num_elements_in_block != (
int)elems.
size() )
1860 return moab::MB_FAILURE;
1864 #ifdef MOAB_HAVE_MPI
1870 #ifdef MOAB_HAVE_MPI
1873 element_ownership[i] = 0;
1882 int* num_elements_in_block,
1886 assert( global_block_ID );
1887 assert( num_elements_in_block );
1890 std::map< int, int >& matMap = data.
matIndex;
1892 std::map< int, int >::iterator it = matMap.find( *global_block_ID );
1894 if( it == matMap.end() )
1896 return moab::MB_FAILURE;
1899 int blockIndex = matMap[*global_block_ID];
1904 if( elems.
empty() )
return moab::MB_FAILURE;
1906 if( *num_elements_in_block != (
int)elems.
size() )
1908 return moab::MB_FAILURE;
1912 "can't get global IDs" );
1915 for(
int i = 0; i < *num_elements_in_block; i++ )
1919 if( -1 == local_element_ID[i] )
1921 return moab::MB_FAILURE;
1929 int* surface_BC_length,
1931 int* reference_surface_ID,
1932 int* boundary_condition_value )
1942 for(
int i = 0; i < numNeuSets; i++ )
1947 "can't get subentities" );
1955 Range adjPrimaryEnts;
1957 "can't get adjacencies" );
1974 if( -1 == local_element_ID[
index] )
1976 return moab::MB_FAILURE;
1981 "can't get side number" );
1984 boundary_condition_value[
index] = neuVal;
1990 if(
index != *surface_BC_length )
1992 return moab::MB_FAILURE;
1999 int* vertex_BC_length,
2001 int* boundary_condition_value )
2008 for(
int i = 0; i < numDiriSets; i++ )
2016 "can't get dirichlet tag" );
2028 if( -1 == local_vertex_ID[
index] )
2030 return moab::MB_FAILURE;
2033 boundary_condition_value[
index] = diriVal;
2038 if( *vertex_BC_length !=
index )
2040 return moab::MB_FAILURE;
2048 std::string& separator,
2049 std::vector< std::string >& list_tag_names )
2053 while( ( pos = input_names.find( separator ) ) != std::string::npos )
2055 token = input_names.substr( 0, pos );
2056 if( !token.empty() ) list_tag_names.push_back( token );
2058 input_names.erase( 0, pos + separator.length() );
2060 if( !input_names.empty() )
2063 list_tag_names.push_back( input_names );
2071 int* components_per_entity,
2076 if( *tag_type < 0 || *tag_type > 5 )
return moab::MB_FAILURE;
2080 void* defaultVal =
nullptr;
2081 int* defInt =
new int[*components_per_entity];
2082 double* defDouble =
new double[*components_per_entity];
2085 for(
int i = 0; i < *components_per_entity; i++ )
2088 defDouble[i] = -1e+10;
2097 defaultVal = defInt;
2103 defaultVal = defDouble;
2109 defaultVal = defHandle;
2115 defaultVal = defInt;
2121 defaultVal = defDouble;
2127 defaultVal = defHandle;
2134 return moab::MB_FAILURE;
2139 std::string tag_name( tag_storage_name );
2142 std::vector< std::string > tagNames;
2143 std::string separator(
":" );
2148 int already_defined_tags = 0;
2151 for(
size_t i = 0; i < tagNames.size(); i++ )
2158 std::map< std::string, Tag >& mTags = data.
tagMap;
2159 std::map< std::string, Tag >::iterator mit = mTags.find( tagNames[i].c_str() );
2161 if( mit == mTags.end() )
2164 mTags[tagNames[i]] = tagHandle;
2166 *tag_index = (int)data.
tagList.size();
2167 data.
tagList.push_back( tagHandle );
2170 already_defined_tags++;
2174 data.
tagMap[tagNames[i]] = tagHandle;
2175 *tag_index = (int)data.
tagList.size();
2176 data.
tagList.push_back( tagHandle );
2180 rval = moab::MB_FAILURE;
2185 #ifdef MOAB_HAVE_MPI
2187 rankHere = pco->
rank();
2189 if( !rankHere && already_defined_tags )
2190 std::cout <<
" application with ID: " << *pid <<
" global id: " << data.
global_id <<
" name: " << data.
name
2191 <<
" has " << already_defined_tags <<
" already defined tags out of " << tagNames.size()
2201 int* num_tag_storage_length,
2203 int* tag_storage_data )
2205 std::string tag_name( tag_storage_name );
2210 if( data.
tagMap.find( tag_name ) == data.
tagMap.end() )
return moab::MB_FAILURE;
2222 MB_CHK_SET_ERR( moab::MB_FAILURE,
"The tag is not of integer type." );
2228 int nents_to_be_set = *num_tag_storage_length / tagLength;
2230 if( nents_to_be_set > (
int)ents_to_set->
size() )
2232 return moab::MB_FAILURE;
2243 int* num_tag_storage_length,
2245 int* tag_storage_data )
2247 std::string tag_name( tag_storage_name );
2251 if( data.
tagMap.find( tag_name ) == data.
tagMap.end() )
2253 return moab::MB_FAILURE;
2266 MB_CHK_SET_ERR( moab::MB_FAILURE,
"The tag is not of integer type." );
2272 int nents_to_get = *num_tag_storage_length / tagLength;
2274 if( nents_to_get > (
int)ents_to_get->
size() )
2276 return moab::MB_FAILURE;
2287 int* num_tag_storage_length,
2289 double* tag_storage_data )
2291 std::string tag_names( tag_storage_names );
2293 std::vector< std::string > tagNames;
2294 std::vector< Tag > tagHandles;
2295 std::string separator(
":" );
2303 int nents_to_be_set = (int)( *ents_to_set ).
size();
2305 for(
size_t i = 0; i < tagNames.size(); i++ )
2307 if( data.
tagMap.find( tagNames[i] ) == data.
tagMap.end() )
2309 return moab::MB_FAILURE;
2322 return moab::MB_FAILURE;
2326 if( position + tagLength * nents_to_be_set > *num_tag_storage_length )
2327 return moab::MB_FAILURE;
2331 position = position + tagLength * nents_to_be_set;
2338 int* num_tag_storage_length,
2340 double* tag_storage_data,
2343 std::string tag_names( tag_storage_names );
2345 std::vector< std::string > tagNames;
2346 std::vector< Tag > tagHandles;
2347 std::string separator(
":" );
2354 int nents_to_be_set = (int)( *ents_to_set ).
size();
2357 std::vector< int > gids;
2358 gids.resize( nents_to_be_set );
2364 std::map< int, EntityHandle > eh_by_gid;
2368 eh_by_gid[gids[i]] = *it;
2372 size_t nbLocalVals = *num_tag_storage_length / tagNames.size();
2375 std::set< int > globalIdsSet( globalIds, globalIds + nbLocalVals );
2376 if( globalIdsSet.size() < nbLocalVals )
2378 std::cout <<
"iMOAB_SetDoubleTagStorageWithGid: for pid:" << *pid <<
" tags[0]:" << tagNames[0]
2379 <<
" global ids passed are not unique, major error\n";
2380 std::cout <<
" nbLocalVals:" << nbLocalVals <<
" globalIdsSet.size():" << globalIdsSet.size()
2381 <<
" first global id:" << globalIds[0] <<
"\n";
2382 return moab::MB_FAILURE;
2385 std::vector< int > tagLengths( tagNames.size() );
2386 std::vector< Tag > tagList;
2387 #ifdef MOAB_HAVE_MPI
2388 size_t total_tag_len = 0;
2390 for(
size_t i = 0; i < tagNames.size(); i++ )
2392 if( data.
tagMap.find( tagNames[i] ) == data.
tagMap.end() )
2394 MB_SET_ERR( moab::MB_FAILURE,
"tag missing" );
2398 tagList.push_back( tag );
2403 #ifdef MOAB_HAVE_MPI
2404 total_tag_len += tagLength;
2406 tagLengths[i] = tagLength;
2412 MB_SET_ERR( moab::MB_FAILURE,
"tag not double type" );
2416 #ifdef MOAB_HAVE_MPI
2418 unsigned num_procs = pco->
size();
2419 if( num_procs > 1 ) serial =
false;
2428 for(
int i = 0; i < nents_to_be_set; i++ )
2430 int gid = globalIds[i];
2431 std::map< int, EntityHandle >::iterator mapIt = eh_by_gid.find( gid );
2432 if( mapIt == eh_by_gid.end() )
continue;
2435 int indexInTagValues = 0;
2436 for(
size_t j = 0; j < tagList.size(); j++ )
2438 indexInTagValues += i * tagLengths[j];
2441 indexInTagValues += ( nents_to_be_set - i ) * tagLengths[j];
2445 #ifdef MOAB_HAVE_MPI
2454 TLsend.
initialize( 2, 0, 0, total_tag_len, nbLocalVals );
2458 int indexInRealLocal = 0;
2459 for(
size_t i = 0; i < nbLocalVals; i++ )
2462 int marker = globalIds[i];
2463 int to_proc = marker % num_procs;
2464 int n = TLsend.
get_n();
2465 TLsend.
vi_wr[2 * n] = to_proc;
2466 TLsend.
vi_wr[2 * n + 1] = marker;
2467 int indexInTagValues = 0;
2469 for(
size_t j = 0; j < tagList.size(); j++ )
2471 indexInTagValues += i * tagLengths[j];
2472 for(
int k = 0; k < tagLengths[j]; k++ )
2474 TLsend.
vr_wr[indexInRealLocal++] = tag_storage_data[indexInTagValues + k];
2476 indexInTagValues += ( nbLocalVals - i ) * tagLengths[j];
2486 TLreq.
initialize( 2, 0, 0, 0, nents_to_be_set );
2488 for(
int i = 0; i < nents_to_be_set; i++ )
2491 int marker = gids[i];
2492 int to_proc = marker % num_procs;
2493 int n = TLreq.
get_n();
2494 TLreq.
vi_wr[2 * n] = to_proc;
2495 TLreq.
vi_wr[2 * n + 1] = marker;
2508 sort_buffer.buffer_init( TLreq.
get_n() );
2509 TLreq.
sort( 1, &sort_buffer );
2510 sort_buffer.
reset();
2511 sort_buffer.buffer_init( TLsend.
get_n() );
2512 TLsend.
sort( 1, &sort_buffer );
2513 sort_buffer.
reset();
2521 TLBack.
initialize( 3, 0, 0, total_tag_len, 0 );
2524 int n1 = TLreq.
get_n();
2525 int n2 = TLsend.
get_n();
2527 int indexInTLreq = 0;
2528 int indexInTLsend = 0;
2529 if( n1 > 0 && n2 > 0 )
2532 while( indexInTLreq < n1 && indexInTLsend < n2 )
2534 int currentValue1 = TLreq.
vi_rd[2 * indexInTLreq + 1];
2535 int currentValue2 = TLsend.
vi_rd[2 * indexInTLsend + 1];
2536 if( currentValue1 < currentValue2 )
2544 if( currentValue1 > currentValue2 )
2551 while( indexInTLreq + size1 < n1 && currentValue1 == TLreq.
vi_rd[2 * ( indexInTLreq + size1 ) + 1] )
2554 while( indexInTLsend + size2 < n2 && currentValue2 == TLsend.
vi_rd[2 * ( indexInTLsend + size2 ) + 1] )
2558 for(
int i1 = 0; i1 < size1; i1++ )
2560 for(
int i2 = 0; i2 < size2; i2++ )
2563 int n = TLBack.
get_n();
2565 TLBack.
vi_wr[3 * n] = TLreq.
vi_rd[2 * ( indexInTLreq + i1 )];
2567 TLBack.
vi_wr[3 * n + 1] = currentValue1;
2568 TLBack.
vi_wr[3 * n + 2] = TLsend.
vi_rd[2 * ( indexInTLsend + i2 )];
2570 for(
size_t k = 0; k < total_tag_len; k++ )
2572 TLBack.
vr_rd[total_tag_len * n + k] =
2573 TLsend.
vr_rd[total_tag_len * indexInTLsend + k];
2577 indexInTLreq += size1;
2578 indexInTLsend += size2;
2587 n1 = TLBack.
get_n();
2588 double* ptrVal = &TLBack.
vr_rd[0];
2589 for(
int i = 0; i < n1; i++ )
2591 const int gid = TLBack.
vi_rd[3 * i + 1];
2592 const auto mapIt = eh_by_gid.find( gid );
2593 if( mapIt == eh_by_gid.end() )
continue;
2597 for(
size_t j = 0; j < tagList.size(); j++ )
2601 ptrVal += tagLengths[j];
2609 #ifdef MOAB_HAVE_TEMPESTREMAP
2644 ErrCode iMOAB_GetCoverageMeshInfo(
iMOAB_AppID pid,
int* num_cov_elems,
int* gids,
double* centroids )
2647 MB_CHK_ERR( get_coverage_entities( pid, covEnts ) );
2648 *num_cov_elems =
static_cast< int >( covEnts.
size() );
2651 if( gids !=
nullptr )
2653 std::vector< int > tmpGids( covEnts.
size() );
2655 std::copy( tmpGids.begin(), tmpGids.end(), gids );
2658 if( centroids !=
nullptr )
2662 std::vector< double > coords;
2667 coords.resize( 3 * numNodes );
2669 double cx = 0.0, cy = 0.0, cz = 0.0;
2670 for(
int v = 0; v < numNodes; v++ )
2672 cx += coords[3 * v + 0];
2673 cy += coords[3 * v + 1];
2674 cz += coords[3 * v + 2];
2676 centroids[3 * i + 0] = cx / numNodes;
2677 centroids[3 * i + 1] = cy / numNodes;
2678 centroids[3 * i + 2] = cz / numNodes;
2704 int* num_tag_storage_length,
2705 double* tag_storage_data )
2708 MB_CHK_ERR( get_coverage_entities( pid, covEnts ) );
2711 std::string tagName( tag_storage_name );
2721 const int needed = tagLen *
static_cast< int >( covEnts.
size() );
2722 if( *num_tag_storage_length < needed )
return moab::MB_FAILURE;
2731 int* num_tag_storage_length,
2733 double* tag_storage_data )
2736 std::string tag_names( tag_storage_names );
2738 std::vector< std::string > tagNames;
2739 std::vector< Tag > tagHandles;
2740 std::string separator(
":" );
2746 Range* ents_to_get =
nullptr;
2748 if( *ent_type == 0 )
2752 else if( *ent_type == 1 )
2756 int nents_to_get = (int)ents_to_get->
size();
2758 for(
size_t i = 0; i < tagNames.size(); i++ )
2760 if( data.
tagMap.find( tagNames[i] ) == data.
tagMap.end() )
2762 return moab::MB_FAILURE;
2775 return moab::MB_FAILURE;
2778 if( position + nents_to_get * tagLength > *num_tag_storage_length )
2779 return moab::MB_FAILURE;
2782 position = position + nents_to_get * tagLength;
2790 #ifdef MOAB_HAVE_MPI
2793 std::vector< Tag > tags;
2795 for(
int i = 0; i < *num_tag; i++ )
2797 if( tag_indices[i] < 0 || tag_indices[i] >= (
int)data.
tagList.size() )
2799 return moab::MB_FAILURE;
2802 tags.push_back( data.
tagList[tag_indices[i]] );
2805 if( *ent_type == 0 )
2809 else if( *ent_type == 1 )
2815 return moab::MB_FAILURE;
2835 #ifdef MOAB_HAVE_MPI
2839 if( *tag_index < 0 || *tag_index >= (
int)data.
tagList.size() )
2841 return moab::MB_FAILURE;
2846 if( *ent_type == 0 )
2850 else if( *ent_type == 1 )
2856 return moab::MB_FAILURE;
2874 int* num_adjacent_elements,
2877 assert( local_index && *local_index >= 0 );
2885 "Getting bridge adjacencies failed" );
2887 if( *num_adjacent_elements < (
int)adjs.
size() )
2889 return moab::MB_FAILURE;
2892 *num_adjacent_elements = (int)adjs.
size();
2894 for(
int i = 0; i < *num_adjacent_elements; i++ )
2917 return moab::MB_FAILURE;
2920 int nverts = *coords_len / *dim;
2934 int* num_nodes_per_element,
2944 EntityType mbtype = (EntityType)( *type );
2948 read_iface->
get_element_connect( *num_elem, *num_nodes_per_element, mbtype, 1, actual_start_handle, array ) );
2954 for(
int j = 0; j < *num_elem * ( *num_nodes_per_element ); j++ )
2956 array[j] = connectivity[j] + firstVertex - 1;
2959 Range new_elems( actual_start_handle, actual_start_handle + *num_elem - 1 );
2971 int set_no = *block_ID;
2972 const void* setno_ptr = &set_no;
2976 &setno_ptr, 1, sets );
2978 if( MB_FAILURE == rval || sets.
empty() )
2990 block_set = sets[0];
3010 if(
nullptr != num_global_verts )
3014 if(
nullptr != num_global_elems )
3022 #ifdef MOAB_HAVE_MPI
3048 return moab::MB_FAILURE;
3065 std::cout <<
" can't get par part tag.\n";
3066 return moab::MB_FAILURE;
3069 int rank = pco->
rank();
3079 if( num_ghost_layers && *num_ghost_layers <= 0 )
3088 constexpr
int addl_ents = 0;
3090 addl_ents,
true,
true, &data.
file_set ) );
3091 for(
int i = 2; i <= *num_ghost_layers; i++ )
3095 addl_ents,
true,
true, &data.
file_set ) );
3141 MPI_Comm* joint_communicator,
3142 MPI_Group* receivingGroup,
3147 assert( joint_communicator !=
nullptr );
3148 assert( receivingGroup !=
nullptr );
3149 assert( rcompid !=
nullptr );
3158 MPI_Comm global = ( data.
is_fortran ? MPI_Comm_f2c( *
reinterpret_cast< MPI_Fint*
>( joint_communicator ) )
3159 : *joint_communicator );
3160 MPI_Group recvGroup =
3161 ( data.
is_fortran ? MPI_Group_f2c( *
reinterpret_cast< MPI_Fint*
>( receivingGroup ) ) : *receivingGroup );
3165 MPI_Comm sender = pco->
comm();
3167 MPI_Group senderGroup;
3168 ierr = MPI_Comm_group( sender, &senderGroup );
3169 if( ierr != 0 )
return moab::MB_FAILURE;
3181 int sender_rank = -1;
3182 MPI_Comm_rank( sender, &sender_rank );
3185 std::vector< int > number_elems_per_part;
3187 if( owned.
size() == 0 )
3197 int local_owned_elem = (int)owned.
size();
3198 int size = pco->
size();
3199 int rank = pco->
rank();
3202 number_elems_per_part.resize( size );
3203 number_elems_per_part[rank] = local_owned_elem;
3206 #if ( MPI_VERSION >= 2 )
3208 ierr = MPI_Allgather( MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, &number_elems_per_part[0], 1, MPI_INT, sender );
3212 std::vector< int > all_tmp( size );
3213 ierr = MPI_Allgather( &number_elems_per_part[rank], 1, MPI_INT, &all_tmp[0], 1, MPI_INT, sender );
3214 number_elems_per_part = all_tmp;
3220 return moab::MB_FAILURE;
3247 MPI_Group_free( &senderGroup );
3290 assert( joint_communicator !=
nullptr );
3291 assert( sendingGroup !=
nullptr );
3292 assert( scompid !=
nullptr );
3298 MPI_Comm receive = pco->
comm();
3302 MPI_Comm global = ( data.
is_fortran ? MPI_Comm_f2c( *
reinterpret_cast< MPI_Fint*
>( joint_communicator ) )
3303 : *joint_communicator );
3304 MPI_Group sendGroup =
3305 ( data.
is_fortran ? MPI_Group_f2c( *
reinterpret_cast< MPI_Fint*
>( sendingGroup ) ) : *sendingGroup );
3308 MPI_Group receiverGroup;
3309 int ierr = MPI_Comm_group( receive, &receiverGroup );
CHK_MPI_ERR( ierr );
3321 int receiver_rank = -1;
3322 MPI_Comm_rank( receive, &receiver_rank );
3326 std::vector< int > pack_array;
3330 int current_receiver = cgraph->
receiver( receiver_rank );
3333 std::vector< int > senders_local;
3337 while( n < pack_array.size() )
3339 if( current_receiver == pack_array[n] )
3342 for(
int j = 0; j < pack_array[n + 1]; j++ )
3344 senders_local.push_back( pack_array[n + 2 + j] );
3349 n = n + 2 + pack_array[n + 1];
3353 std::cout <<
" receiver " << current_receiver <<
" at rank " << receiver_rank <<
" will receive from "
3354 << senders_local.size() <<
" tasks: ";
3356 for(
int k = 0; k < (int)senders_local.size(); k++ )
3358 std::cout <<
" " << senders_local[k];
3365 if( senders_local.empty() )
3367 std::cout <<
" we do not have any senders for receiver rank " << receiver_rank <<
"\n";
3387 if( (
int)senders_local.size() >= 2 )
3398 std::cout <<
"current_receiver " << current_receiver <<
" local verts: " << local_verts.
size() <<
"\n";
3409 std::cout <<
"after merging: new verts: " << new_verts.
size() <<
"\n";
3429 if(
nullptr != densePartTag &&
MB_SUCCESS == rval )
3433 std::vector< int > vals;
3434 int rank = pco->
rank();
3435 vals.resize( local_verts.
size(), rank );
3447 std::cout <<
" can't get par part tag.\n";
3448 return moab::MB_FAILURE;
3452 int rank = pco->
rank();
3465 MPI_Group_free( &receiverGroup );
3506 MPI_Comm* joint_communicator,
3511 std::map< int, ParCommGraph* >::iterator mt = data.
pgraph.find( *context_id );
3512 if( mt == data.
pgraph.end() )
3515 std::cout <<
" no par com graph for context_id:" << *context_id <<
" available contexts:";
3516 for(
auto mit = data.
pgraph.begin(); mit != data.
pgraph.end(); mit++ )
3517 std::cout <<
" " << mit->first;
3519 return moab::MB_FAILURE;
3527 MPI_Comm global = ( data.
is_fortran ? MPI_Comm_f2c( *
reinterpret_cast< MPI_Fint*
>( joint_communicator ) )
3528 : *joint_communicator );
3533 #ifdef MOAB_HAVE_TEMPESTREMAP
3535 if( data.tempestData.remapper !=
nullptr )
3548 std::string tag_name( tag_storage_name );
3551 std::vector< std::string > tagNames;
3552 std::vector< Tag > tagHandles;
3553 std::string separator(
":" );
3557 for(
size_t i = 0; i < tagNames.size(); i++ )
3561 if(
MB_SUCCESS != rval ||
nullptr == tagHandle )
3564 "can't get tag handle with name: " << tagNames[i].c_str() <<
" at index " << i );
3566 tagHandles.push_back( tagHandle );
3613 MPI_Comm* joint_communicator,
3618 std::map< int, ParCommGraph* >::iterator mt = data.
pgraph.find( *context_id );
3619 if( mt == data.
pgraph.end() )
3622 std::cout <<
" no par com graph for context_id:" << *context_id <<
" available contexts:";
3623 for(
auto mit = data.
pgraph.begin(); mit != data.
pgraph.end(); mit++ )
3624 std::cout <<
" " << mit->first;
3626 return moab::MB_FAILURE;
3634 MPI_Comm global = ( data.
is_fortran ? MPI_Comm_f2c( *
reinterpret_cast< MPI_Fint*
>( joint_communicator ) )
3635 : *joint_communicator );
3645 #ifdef MOAB_HAVE_TEMPESTREMAP
3647 if( data.tempestData.remapper !=
nullptr )
3655 std::string tag_name( tag_storage_name );
3658 std::vector< std::string > tagNames;
3659 std::vector< Tag > tagHandles;
3660 std::string separator(
":" );
3664 for(
size_t i = 0; i < tagNames.size(); i++ )
3668 if(
MB_SUCCESS != rval ||
nullptr == tagHandle )
3671 " can't get tag handle for tag named:" << tagNames[i].c_str() <<
" at index " << i );
3673 tagHandles.push_back( tagHandle );
3677 std::cout << pco->
rank() <<
". Looking to receive data for tags: " << tag_name
3678 <<
" and file set = " << ( data.
file_set ) <<
"\n";
3686 std::cout << pco->
rank() <<
". Looking to receive data for tags: " << tag_name <<
"\n";
3697 std::map< int, ParCommGraph* >::iterator mt = data.
pgraph.find( *context_id );
3698 if( mt == data.
pgraph.end() )
return moab::MB_FAILURE;
3702 mt->second->release_send_buffers();
3755 MPI_Comm* joint_communicator,
3764 assert( joint_communicator );
3767 int localRank = 0, numProcs = 1;
3770 bool isFortran =
false;
3771 if( *pid1 >= 0 ) isFortran = isFortran ||
context.
appDatas[*pid1].is_fortran;
3772 if( *pid2 >= 0 ) isFortran = isFortran ||
context.
appDatas[*pid2].is_fortran;
3776 ( isFortran ? MPI_Comm_f2c( *
reinterpret_cast< MPI_Fint*
>( joint_communicator ) ) : *joint_communicator );
3777 MPI_Group srcGroup = ( isFortran ? MPI_Group_f2c( *
reinterpret_cast< MPI_Fint*
>( group1 ) ) : *group1 );
3778 MPI_Group tgtGroup = ( isFortran ? MPI_Group_f2c( *
reinterpret_cast< MPI_Fint*
>( group2 ) ) : *group2 );
3781 MPI_Comm_rank( global, &localRank );
3782 MPI_Comm_size( global, &numProcs );
3794 auto mt = data.
pgraph.find( *comp2 );
3796 cgraph =
new ParCommGraph( global, srcGroup, tgtGroup, *comp1, *comp2 );
3804 auto mt = data.
pgraph.find( *comp1 );
3806 cgraph_rev =
new ParCommGraph( global, tgtGroup, srcGroup, *comp2, *comp1 );
3824 int lenTagType1 = 1;
3825 if( 1 == *type1 || 1 == *type2 )
3834 std::vector< int > valuesComp1;
3841 #ifdef MOAB_HAVE_TEMPESTREMAP
3842 if( data1.tempestData.remapper !=
nullptr )
3846 Range ents_of_interest;
3851 valuesComp1.resize( ents_of_interest.
size() * lenTagType1 );
3854 else if( *type1 == 2 )
3857 valuesComp1.resize( ents_of_interest.
size() );
3860 else if( *type1 == 3 )
3863 valuesComp1.resize( ents_of_interest.
size() );
3873 std::set< int > uniq( valuesComp1.begin(), valuesComp1.end() );
3874 TLcomp1.
resize( uniq.size() );
3875 for( std::set< int >::iterator sit = uniq.begin(); sit != uniq.end(); sit++ )
3878 int to_proc = marker % numProcs;
3879 int n = TLcomp1.
get_n();
3880 TLcomp1.
vi_wr[2 * n] = to_proc;
3881 TLcomp1.
vi_wr[2 * n + 1] = marker;
3893 std::stringstream ff1;
3894 ff1 <<
"TLcomp1_" << localRank <<
".txt";
3898 sort_buffer.buffer_init( TLcomp1.
get_n() );
3899 TLcomp1.
sort( 1, &sort_buffer );
3900 sort_buffer.
reset();
3908 std::vector< int > valuesComp2;
3915 #ifdef MOAB_HAVE_TEMPESTREMAP
3916 if( data2.tempestData.remapper !=
nullptr )
3920 Range ents_of_interest;
3925 valuesComp2.resize( ents_of_interest.
size() * lenTagType1 );
3928 else if( *type2 == 2 )
3931 valuesComp2.resize( ents_of_interest.
size() );
3934 else if( *type2 == 3 )
3937 valuesComp2.resize( ents_of_interest.
size() );
3946 std::set< int > uniq( valuesComp2.begin(), valuesComp2.end() );
3947 TLcomp2.
resize( uniq.size() );
3948 for( std::set< int >::iterator sit = uniq.begin(); sit != uniq.end(); sit++ )
3951 int to_proc = marker % numProcs;
3952 int n = TLcomp2.
get_n();
3953 TLcomp2.
vi_wr[2 * n] = to_proc;
3954 TLcomp2.
vi_wr[2 * n + 1] = marker;
3964 std::stringstream ff2;
3965 ff2 <<
"TLcomp2_" << localRank <<
".txt";
3968 sort_buffer.buffer_reserve( TLcomp2.
get_n() );
3969 TLcomp2.
sort( 1, &sort_buffer );
3970 sort_buffer.
reset();
3990 int n1 = TLcomp1.
get_n();
3991 int n2 = TLcomp2.
get_n();
3994 int indexInTLComp1 = 0;
3995 int indexInTLComp2 = 0;
3996 if( n1 > 0 && n2 > 0 )
3998 while( indexInTLComp1 < n1 && indexInTLComp2 < n2 )
4001 int currentValue1 = TLcomp1.
vi_rd[2 * indexInTLComp1 + 1];
4002 int currentValue2 = TLcomp2.
vi_rd[2 * indexInTLComp2 + 1];
4004 if( currentValue1 < currentValue2 )
4011 if( currentValue1 > currentValue2 )
4021 while( indexInTLComp1 + size1 < n1 && currentValue1 == TLcomp1.
vi_rd[2 * ( indexInTLComp1 + size1 ) + 1] )
4023 while( indexInTLComp2 + size2 < n2 && currentValue2 == TLcomp2.
vi_rd[2 * ( indexInTLComp2 + size2 ) + 1] )
4027 for(
int i1 = 0; i1 < size1; i1++ )
4029 for(
int i2 = 0; i2 < size2; i2++ )
4032 int n = TLBackToComp1.
get_n();
4034 TLBackToComp1.
vi_wr[3 * n] =
4035 TLcomp1.
vi_rd[2 * ( indexInTLComp1 + i1 )];
4036 TLBackToComp1.
vi_wr[3 * n + 1] = currentValue1;
4037 TLBackToComp1.
vi_wr[3 * n + 2] =
4038 TLcomp2.
vi_rd[2 * ( indexInTLComp2 + i2 )];
4041 n = TLBackToComp2.
get_n();
4043 TLBackToComp2.
vi_wr[3 * n] =
4044 TLcomp2.
vi_rd[2 * ( indexInTLComp2 + i2 )];
4045 TLBackToComp2.
vi_wr[3 * n + 1] = currentValue1;
4046 TLBackToComp2.
vi_wr[3 * n + 2] =
4047 TLcomp1.
vi_rd[2 * ( indexInTLComp1 + i1 )];
4052 indexInTLComp1 += size1;
4053 indexInTLComp2 += size2;
4065 std::stringstream f1;
4066 f1 <<
"TLBack1_" << localRank <<
".txt";
4069 sort_buffer.buffer_reserve( TLBackToComp1.
get_n() );
4070 TLBackToComp1.
sort( 1, &sort_buffer );
4071 sort_buffer.
reset();
4085 std::stringstream f2;
4086 f2 <<
"TLBack2_" << localRank <<
".txt";
4089 sort_buffer.buffer_reserve( TLBackToComp2.
get_n() );
4090 TLBackToComp2.
sort( 2, &sort_buffer );
4091 sort_buffer.
reset();
4179 std::vector< Tag > tagsList;
4189 return moab::MB_FAILURE;
4192 tagsList.push_back( tag );
4200 tagsList.push_back( tag );
4209 tagsList.push_back( tag );
4219 const double tol = 1.0e-9;
4329 std::cout <<
"Failed to create/retrieve PARALLEL_PARTITION tag.\n";
4330 return moab::MB_FAILURE;
4335 int rank = pco->
rank();
4347 #ifdef MOAB_HAVE_TEMPESTREMAP
4396 ErrCode iMOAB_CoverageGraph( MPI_Comm* joint_communicator,
4408 assert( joint_communicator !=
nullptr );
4410 std::vector< int > srcSenders, receivers;
4412 bool is_fortran_context =
false;
4416 MB_CHK_SET_ERR( moab::MB_FAILURE,
"Invalid source application ID specified: " << *pid_src );
4418 MB_CHK_SET_ERR( moab::MB_FAILURE,
"Invalid migration/coverage application ID specified: " << *pid_migr );
4420 MB_CHK_SET_ERR( moab::MB_FAILURE,
"Invalid intersection application ID specified: " << *pid_intx );
4427 int default_context_id = *migration_id;
4428 assert( dataSrc.
global_id == *source_id );
4429 is_fortran_context = dataSrc.
is_fortran || is_fortran_context;
4430 if( dataSrc.
pgraph.find( default_context_id ) != dataSrc.
pgraph.end() )
4431 sendGraph = dataSrc.
pgraph[default_context_id];
4433 MB_CHK_SET_ERR( moab::MB_FAILURE,
"Could not find source ParCommGraph with default migration context" );
4436 srcSenders = sendGraph->
senders();
4439 std::cout <<
"senders: " << srcSenders.size() <<
" first sender: " << srcSenders[0] << std::endl;
4446 if( *pid_migr >= 0 )
4449 is_fortran_context = dataMigr.
is_fortran || is_fortran_context;
4450 int default_context_id = *source_id;
4451 assert( dataMigr.
global_id == *migration_id );
4452 if( dataMigr.
pgraph.find( default_context_id ) != dataMigr.
pgraph.end() )
4453 recvGraph = dataMigr.
pgraph[default_context_id];
4456 "Could not find coverage receiver ParCommGraph with default migration context" );
4458 srcSenders = recvGraph->
senders();
4461 std::cout <<
"receivers: " << receivers.size() <<
" first receiver: " << receivers[0] << std::endl;
4469 if( *pid_intx >= 0 ) is_fortran_context =
context.
appDatas[*pid_intx].is_fortran || is_fortran_context;
4478 MPI_Comm global = ( is_fortran_context ? MPI_Comm_f2c( *
reinterpret_cast< MPI_Fint*
>( joint_communicator ) )
4479 : *joint_communicator );
4480 int currentRankInJointComm = -1;
CHK_MPI_ERR( MPI_Comm_rank( global, ¤tRankInJointComm ) );
4491 if( find( receivers.begin(), receivers.end(), currentRankInJointComm ) != receivers.end() )
4508 std::map< int, std::set< int > > idsFromProcs;
4510 if( intx_cells.
size() )
4517 for(
auto it = intx_cells.
begin(); it != intx_cells.
end(); ++it )
4526 if( origProc < 0 )
continue;
4533 idsFromProcs[origProc].insert( gidCell );
4545 for(
auto it = cover_cells.
begin(); it != cover_cells.
end(); ++it )
4554 if( origProc < 0 )
continue;
4559 assert( gidCell > 0 );
4560 idsFromProcs[origProc].insert( gidCell );
4565 std::ofstream dbfile;
4566 std::stringstream outf;
4567 outf <<
"idsFromProc_0" << currentRankInJointComm <<
".txt";
4568 dbfile.open( outf.str().c_str() );
4569 dbfile <<
"Writing this to a file.\n";
4571 dbfile <<
" map size:" << idsFromProcs.size()
4575 for( std::map<
int, std::set< int > >::iterator mt = idsFromProcs.begin(); mt != idsFromProcs.end(); mt++ )
4577 std::set< int >& setIds = mt->second;
4578 dbfile <<
"from id: " << mt->first <<
" receive " << setIds.size() <<
" cells \n";
4580 for( std::set< int >::iterator st = setIds.begin(); st != setIds.end(); st++ )
4583 dbfile <<
" " << valueID;
4585 if( counter % 10 == 0 ) dbfile <<
"\n";
4593 if(
nullptr != recvGraph )
4602 auto existing = pgraphMap.find( *context_id );
4603 if( existing != pgraphMap.end() )
4605 delete existing->second;
4606 pgraphMap.erase( existing );
4608 pgraphMap[*context_id] = newRecvGraph;
4613 for( std::map<
int, std::set< int > >::iterator mit = idsFromProcs.begin(); mit != idsFromProcs.end(); ++mit )
4615 int procToSendTo = mit->first;
4616 std::set< int >& idSet = mit->second;
4617 for( std::set< int >::iterator sit = idSet.begin(); sit != idSet.end(); ++sit )
4619 int n = TLcovIDs.
get_n();
4621 TLcovIDs.
vi_wr[2 * n] = procToSendTo;
4622 TLcovIDs.
vi_wr[2 * n + 1] = *sit;
4633 pc.crystal_router()->gs_transfer( 1, TLcovIDs, 0 );
4639 if(
nullptr != sendGraph )
4646 dataSrc.
pgraph[*context_id] = newSendGraph;
4657 assert( prefix && strlen( prefix ) );
4660 std::string prefix_str( prefix );
4662 if(
nullptr != cgraph )
4666 std::cout <<
" cannot find ParCommGraph on app with pid " << *pid <<
" name: " <<
context.
appDatas[*pid].name
4667 <<
" context: " << *context_id <<
"\n";
4676 #ifdef MOAB_HAVE_TEMPESTREMAP
4678 #ifdef MOAB_HAVE_NETCDF
4726 static ErrCode set_aream_from_trivial_distribution(
iMOAB_AppID pid,
int N, std::vector< double >& trvArea )
4733 int size = 1, rank = 0;
4734 #ifdef MOAB_HAVE_MPI
4736 size = pcomm->
size();
4737 rank = pcomm->
rank();
4747 size_t nents_to_be_set = ents_to_set.
size();
4750 std::vector< int > globalIds( nents_to_be_set );
4757 const bool serial = ( size == 1 );
4762 for(
size_t i = 0; i < nents_to_be_set; i++ )
4764 int gid = globalIds[i];
4765 int indexInVal = gid - 1;
4766 assert( indexInVal < N );
4772 #ifdef MOAB_HAVE_MPI
4784 TLreq.
initialize( 3, 0, 0, 0, nents_to_be_set );
4788 for(
size_t i = 0; i < nents_to_be_set; i++ )
4790 int marker = globalIds[i];
4791 int to_proc = ( marker - 1 ) / nL;
4794 if( to_proc == size ) to_proc = size - 1;
4797 int n = TLreq.
get_n();
4798 TLreq.
vi_wr[3 * n] = to_proc;
4799 TLreq.
vi_wr[3 * n + 1] = marker;
4800 TLreq.
vi_wr[3 * n + 2] = i;
4811 int sizeBack = TLreq.
get_n();
4819 for(
int i = 0; i < sizeBack; i++ )
4821 int from_proc = TLreq.
vi_wr[3 * i];
4822 int marker = TLreq.
vi_wr[3 * i + 1];
4823 int orig_index = TLreq.
vi_wr[3 * i + 2];
4827 int index = marker - 1 - rank * nL;
4828 double area_val = trvArea[
index];
4831 TLBack.
vi_wr[3 * i] = from_proc;
4832 TLBack.
vi_wr[3 * i + 1] = marker;
4833 TLBack.
vi_wr[3 * i + 2] = orig_index;
4834 TLBack.
vr_wr[i] = area_val;
4848 int n1 = TLBack.
get_n();
4850 for(
int i = 0; i < n1; i++ )
4854 int origIndex = TLBack.
vi_rd[3 * i + 2];
4855 double area_val = TLBack.
vr_rd[i];
4876 assert( srctype && tgttype );
4886 TempestMapAppData& tdata = data_intx.tempestData;
4892 if( tdata.remapper ==
nullptr )
4898 #ifdef MOAB_HAVE_MPI
4904 tdata.remapper->meshValidate =
true;
4905 tdata.remapper->constructEdgeMap =
true;
4908 tdata.remapper->initialize(
false );
4920 tdata.weightMaps[std::string( solution_weights_identifier )] =
new moab::TempestOnlineMap( tdata.remapper );
4924 assert( weightMap !=
nullptr );
4930 int src_elem_dof_length = 1, tgt_elem_dof_length = 1;
4932 Tag gdsTag =
nullptr;
4933 if( *srctype == 1 || *tgttype == 1 )
4950 std::vector< int > tgtDofValues;
4954 Range tgt_ents_of_interest;
4960 tgtDofValues.resize( tgt_ents_of_interest.
size() * tgt_elem_dof_length );
4963 else if( *tgttype == 2 )
4967 tgtDofValues.resize( tgt_ents_of_interest.
size() * tgt_elem_dof_length );
4970 else if( *tgttype == 3 )
4974 tgtDofValues.resize( tgt_ents_of_interest.
size() * tgt_elem_dof_length );
4984 std::vector< int > sortTgtDofs( tgtDofValues.begin(), tgtDofValues.end() );
4985 std::sort( sortTgtDofs.begin(), sortTgtDofs.end() );
4986 sortTgtDofs.erase( std::unique( sortTgtDofs.begin(), sortTgtDofs.end() ), sortTgtDofs.end() );
4994 #ifdef MOAB_HAVE_MPI
4997 std::cout <<
" aream tag already defined \n ";
5000 std::vector< double > trvAreaA, trvAreaB;
5004 "reading map from disk failed" );
5008 tdata.pid_src = pid_source;
5009 tdata.pid_dest = pid_target;
5019 if( 1 == *arearead || 3 == *arearead )
5020 MB_CHK_SET_ERR( set_aream_from_trivial_distribution( pid_source, nA, trvAreaA ),
5021 " fail to set aream on source " );
5022 if( 2 == *arearead || 3 == *arearead )
5023 MB_CHK_SET_ERR( set_aream_from_trivial_distribution( pid_target, nB, trvAreaB ),
5024 " fail to set aream on target " );
5035 std::string metadataStr = std::string( remap_weights_filename ) +
";FV:1:GLOBAL_ID;FV:1:GLOBAL_ID";
5037 data_intx.metadataMap[std::string( solution_weights_identifier )] = metadataStr;
5046 assert( solution_weights_identifier && strlen( solution_weights_identifier ) );
5047 assert( remap_weights_filename && strlen( remap_weights_filename ) );
5051 TempestMapAppData& tdata = data_intx.tempestData;
5054 assert( tdata.remapper !=
nullptr );
5058 assert( weightMap !=
nullptr );
5060 std::string filename = std::string( remap_weights_filename );
5062 std::string metadataStr = data_intx.metadataMap[std::string( solution_weights_identifier )];
5063 std::map< std::string, std::string > attrMap;
5064 attrMap[
"title"] =
"MOAB-TempestRemap Online Regridding Weight Generator";
5065 attrMap[
"normalization"] =
"ovarea";
5066 attrMap[
"map_aPb"] = filename;
5086 attrMap[
"concave_a"] =
"false";
5087 attrMap[
"concave_b"] =
"false";
5088 attrMap[
"bubble"] =
"true";
5097 #ifdef MOAB_HAVE_MPI
5100 MPI_Comm* jointcomm,
5107 assert( jointcomm );
5110 bool is_fortran =
false;
5111 if( *pid1 >= 0 ) is_fortran =
context.
appDatas[*pid1].is_fortran || is_fortran;
5112 if( *pid2 >= 0 ) is_fortran =
context.
appDatas[*pid2].is_fortran || is_fortran;
5114 MPI_Comm joint_communicator =
5115 ( is_fortran ? MPI_Comm_f2c( *
reinterpret_cast< MPI_Fint*
>( jointcomm ) ) : *jointcomm );
5117 int localRank = 0, numProcs = 1;
5120 MPI_Comm_rank( joint_communicator, &localRank );
5121 MPI_Comm_size( joint_communicator, &numProcs );
5137 int lenTagType1 = 1;
5145 std::vector< int > valuesComp1;
5148 Range ents_of_interest;
5159 valuesComp1.resize( ents_of_interest.
size() * lenTagType1 );
5162 else if( *type == 2 )
5165 valuesComp1.resize( ents_of_interest.
size() );
5168 else if( *type == 3 )
5171 valuesComp1.resize( ents_of_interest.
size() );
5180 std::set< int > uniq( valuesComp1.begin(), valuesComp1.end() );
5181 TLcomp1.
resize( uniq.size() );
5182 for( std::set< int >::iterator sit = uniq.begin(); sit != uniq.end(); sit++ )
5186 int to_proc = marker % numProcs;
5187 int n = TLcomp1.
get_n();
5188 TLcomp1.
vi_wr[2 * n] = to_proc;
5189 TLcomp1.
vi_wr[2 * n + 1] = marker;
5195 pc.crystal_router()->gs_transfer( 1, TLcomp1,
5199 std::stringstream ff1;
5200 ff1 <<
"TLcomp1_" << localRank <<
".txt";
5204 sort_buffer.buffer_init( TLcomp1.
get_n() );
5205 TLcomp1.
sort( 1, &sort_buffer );
5206 sort_buffer.
reset();
5218 std::vector< int > valuesComp2;
5222 TempestMapAppData& tdata = data2.tempestData;
5227 for(
auto mapIt = tdata.weightMaps.begin(); mapIt != tdata.weightMaps.end(); ++mapIt )
5230 std::vector< int > valueDofs;
5232 valuesComp2.insert( valuesComp2.end(), valueDofs.begin(), valueDofs.end() );
5240 std::set< int > uniq( valuesComp2.begin(), valuesComp2.end() );
5241 TLcomp2.
resize( uniq.size() );
5242 for( std::set< int >::iterator sit = uniq.begin(); sit != uniq.end(); sit++ )
5246 int to_proc = marker % numProcs;
5247 int n = TLcomp2.
get_n();
5248 TLcomp2.
vi_wr[2 * n] = to_proc;
5249 TLcomp2.
vi_wr[2 * n + 1] = marker;
5253 pc.crystal_router()->gs_transfer( 1, TLcomp2,
5258 std::stringstream ff2;
5259 ff2 <<
"TLcomp2_" << localRank <<
".txt";
5262 sort_buffer.buffer_reserve( TLcomp2.
get_n() );
5263 TLcomp2.
sort( 1, &sort_buffer );
5264 sort_buffer.
reset();
5282 int n1 = TLcomp1.
get_n();
5283 int n2 = TLcomp2.
get_n();
5285 int indexInTLComp1 = 0;
5286 int indexInTLComp2 = 0;
5287 if( n1 > 0 && n2 > 0 )
5290 while( indexInTLComp1 < n1 && indexInTLComp2 < n2 )
5292 int currentValue1 = TLcomp1.
vi_rd[2 * indexInTLComp1 + 1];
5293 int currentValue2 = TLcomp2.
vi_rd[2 * indexInTLComp2 + 1];
5294 if( currentValue1 < currentValue2 )
5302 if( currentValue1 > currentValue2 )
5310 while( indexInTLComp1 + size1 < n1 && currentValue1 == TLcomp1.
vi_rd[2 * ( indexInTLComp1 + size1 ) + 1] )
5312 while( indexInTLComp2 + size2 < n2 && currentValue2 == TLcomp2.
vi_rd[2 * ( indexInTLComp2 + size2 ) + 1] )
5315 for(
int i1 = 0; i1 < size1; i1++ )
5317 for(
int i2 = 0; i2 < size2; i2++ )
5320 int n = TLBackToComp1.
get_n();
5322 TLBackToComp1.
vi_wr[3 * n] =
5323 TLcomp1.
vi_rd[2 * ( indexInTLComp1 + i1 )];
5325 TLBackToComp1.
vi_wr[3 * n + 1] = currentValue1;
5326 TLBackToComp1.
vi_wr[3 * n + 2] = TLcomp2.
vi_rd[2 * ( indexInTLComp2 + i2 )];
5329 indexInTLComp1 += size1;
5330 indexInTLComp2 += size2;
5333 pc.crystal_router()->gs_transfer( 1, TLBackToComp1, 0 );
5345 std::stringstream f1;
5346 f1 <<
"TLBack1_" << localRank <<
".txt";
5350 int n = TLBackToComp1.
get_n();
5351 std::map< int, std::set< int > > uniqueIDs;
5352 for(
int i = 0; i < n; i++ )
5354 int to_proc = TLBackToComp1.
vi_wr[3 * i + 2];
5355 int globalId = TLBackToComp1.
vi_wr[3 * i + 1];
5356 uniqueIDs[to_proc].insert( globalId );
5362 std::map< int, Range > splits;
5363 for(
size_t i = 0; i < ents_of_interest.
size(); i++ )
5366 for(
int j = 0; j < lenTagType1; j++ )
5368 int marker = valuesComp1[i * lenTagType1 + j];
5369 for(
auto mit = uniqueIDs.begin(); mit != uniqueIDs.end(); mit++ )
5371 int proc = mit->first;
5372 std::set< int >& setIds = mit->second;
5373 if( setIds.find( marker ) != setIds.end() )
5375 splits[proc].
insert( ent );
5381 std::map< int, Range > verts_to_proc;
5382 int numv = 0, numc = 0;
5383 for(
auto it = splits.begin(); it != splits.end(); it++ )
5385 int to_proc = it->first;
5390 numc += (int)it->second.size();
5394 verts_to_proc[to_proc] = verts;
5395 numv += (int)verts.
size();
5401 for(
auto it = verts_to_proc.begin(); it != verts_to_proc.end(); it++ )
5403 int to_proc = it->first;
5404 Range& verts = it->second;
5408 int n = TLv.
get_n();
5409 TLv.
vi_wr[2 * n] = to_proc;
5420 2 + ( ( *type != 1 ) ? 0 : lenTagType1 ) + 1 + 10;
5422 std::vector< int > gdvals;
5426 for(
auto it = splits.begin(); it != splits.end(); it++ )
5428 int to_proc = it->first;
5429 Range& cells = it->second;
5433 int n = TLc.
get_n();
5434 TLc.
vi_wr[size_tuple * n] = to_proc;
5435 int current_index = 2;
5440 &( TLc.
vi_wr[size_tuple * n + current_index] ) ) );
5441 current_index += lenTagType1;
5448 TLc.
vi_wr[size_tuple * n + current_index] = nnodes;
5450 &( TLc.
vi_wr[size_tuple * n + current_index + 1] ) ) );
5456 else if( *pid2 >= 0 )
5466 int size_tuple = 2 + ( ( *type != 1 ) ? 0 : lenTagType1 ) + 1 +
5472 pc.crystal_router()->gs_transfer( 1, TLv, 0 );
5473 if( *type != 2 ) pc.crystal_router()->gs_transfer( 1, TLc, 0 );
5478 TempestMapAppData& tdata = dataIntx.tempestData;
5480 std::vector< int > values_entities;
5486 Range intx_cov_cells;
5488 const bool has_intersection_coverage = !intx_cov_cells.
empty();
5490 if( !has_intersection_coverage )
5493 std::map< int, EntityHandle > vertexMap;
5496 int n = TLv.
get_n();
5498 for(
int i = 0; i < n; i++ )
5500 int gid = TLv.
vi_rd[2 * i + 1];
5501 if( vertexMap.find( gid ) == vertexMap.end() )
5513 values_entities.resize( verts.
size() );
5515 primary_ents = verts;
5522 2 + ( ( *type != 1 ) ? 0 : lenTagType1 ) + 1 + 10;
5526 std::map< int, EntityHandle >
5528 for(
int i = 0; i < n; i++ )
5531 int globalIdEl = TLc.
vi_rd[size_tuple * i + 1];
5532 if( cellMap.find( globalIdEl ) == cellMap.end() )
5534 int current_index = 2;
5535 if( 1 == *type ) current_index += lenTagType1;
5536 int nnodes = TLc.
vi_rd[size_tuple * i + current_index];
5537 std::vector< EntityHandle > conn;
5538 conn.resize( nnodes );
5539 for(
int j = 0; j < nnodes; j++ )
5541 conn[j] = vertexMap[TLc.
vi_rd[size_tuple * i + current_index + j + 1]];
5544 EntityType entType =
MBQUAD;
5546 if( nnodes < 4 ) entType =
MBTRI;
5548 "can't create new element " );
5549 primary_ents.
insert( new_element );
5550 cellMap[globalIdEl] = new_element;
5552 "can't set global id tag on cell " );
5557 &( TLc.
vi_rd[size_tuple * i + 2] ) ),
5558 "can't set gds tag on cell " );
5565 values_entities.resize( lenTagType1 * primary_ents.
size() );
5570 values_entities.resize( primary_ents.
size() );
5579 primary_ents = intx_cov_cells;
5582 values_entities.resize( lenTagType1 * primary_ents.
size() );
5587 values_entities.resize( primary_ents.
size() );
5593 if( 1 == *type ) ndofPerEl = (int)( sqrt( lenTagType1 ) );
5599 std::stringstream fcov;
5600 fcov <<
"MapCover_" << numProcs <<
"_" << localRank <<
".h5m";
5603 std::stringstream ftarg;
5604 ftarg <<
"TargMap_" << numProcs <<
"_" << localRank <<
".h5m";
5607 for(
auto mapIt = tdata.weightMaps.begin(); mapIt != tdata.weightMaps.end(); ++mapIt )
5617 if( ierr != 0 )
return moab::MB_FAILURE;
5645 ErrCode iMOAB_SetMapGhostLayers(
iMOAB_AppID pid,
int* n_src_ghost_layers,
int* n_tgt_ghost_layers )
5650 data.tempestData.num_src_ghost_layers = *n_src_ghost_layers;
5651 data.tempestData.num_tgt_ghost_layers = *n_tgt_ghost_layers;
5659 constexpr
bool validate =
true;
5660 constexpr
bool meshCleanup =
true;
5661 bool gnomonic =
true;
5662 constexpr
double defaultradius = 1.0;
5663 constexpr
double boxeps = 1.e-10;
5666 const double epsrel = ReferenceTolerance;
5667 double radius_source = 1.0;
5668 double radius_target = 1.0;
5677 #ifdef MOAB_HAVE_MPI
5682 TempestMapAppData& tdata = data_intx.tempestData;
5686 #ifdef MOAB_HAVE_MPI
5689 rank = pco_intx->
rank();
5695 outputFormatter.set_prefix(
"[iMOAB_ComputeCoverageMesh]: " );
5701 MB_CHK_ERR( ComputeSphereRadius( pid_src, &radius_source ) );
5702 MB_CHK_ERR( ComputeSphereRadius( pid_tgt, &radius_target ) );
5705 outputFormatter.printf( 0,
"Radius of spheres: source = %12.14f, and target = %12.14f\n", radius_source,
5711 if( fabs( radius_source - radius_target ) > 1e-10 )
5718 #ifdef MOAB_HAVE_TEMPESTREMAP
5762 outputFormatter.printf( 0,
"The source set contains %zu vertices and %zu elements\n", rintxverts.
size(),
5763 rintxelems.
size() );
5764 outputFormatter.printf( 0,
"The target set contains %zu vertices and %zu elements\n", bintxverts.
size(),
5765 bintxelems.
size() );
5775 tdata.pid_src = pid_src;
5776 tdata.pid_dest = pid_tgt;
5779 #ifdef MOAB_HAVE_MPI
5784 tdata.remapper->meshValidate = validate;
5785 tdata.remapper->constructEdgeMap =
true;
5788 tdata.remapper->initialize(
false );
5794 if( tdata.num_src_ghost_layers >= 1 ) gnomonic =
false;
5795 MB_CHK_SET_ERR( tdata.remapper->ConstructCoveringSet( epsrel, 1.0, 1.0, boxeps,
false, gnomonic,
5796 tdata.num_src_ghost_layers ),
5797 "failed to compute covering set" );
5799 #ifdef MOAB_HAVE_TEMPESTREMAP
5807 #ifdef MOAB_HAVE_TEMPESTREMAP
5816 if( data.tempestData.remapper !=
nullptr )
5818 else if( data.
file_set != data.secondary_file_set )
5819 fileSet = data.secondary_file_set;
5821 MB_CHK_SET_ERR( moab::MB_FAILURE,
"Invalid secondary file set handle" );
5823 std::ostringstream file_name;
5824 int rank = 0, size = 1;
5826 #ifdef MOAB_HAVE_MPI
5828 rank = pcomm->
rank();
5829 size = pcomm->
size();
5832 file_name << prefix <<
"_" << size <<
"_" << rank <<
".h5m";
5842 constexpr
bool validate =
true;
5843 constexpr
bool use_kdtree_search =
true;
5844 constexpr
double defaultradius = 1.0;
5850 #ifdef MOAB_HAVE_MPI
5855 TempestMapAppData& tdata = data_intx.tempestData;
5857 if( tdata.remapper ==
nullptr )
5862 MB_CHK_ERR( iMOAB_ComputeCoverageMesh( pid_src, pid_tgt, pid_intx ) );
5866 #ifdef MOAB_HAVE_MPI
5867 rank = pco_intx->
rank();
5870 outputFormatter.set_prefix(
"[iMOAB_ComputeMeshIntersectionOnSphere]: " );
5874 MB_CHK_ERR( tdata.remapper->ComputeOverlapMesh( use_kdtree_search,
false ) );
5881 double local_areas[3] = { 0.0, 0.0, 0.0 }, global_areas[3] = { 0.0, 0.0, 0.0 };
5882 local_areas[0] = areaAdaptor.area_on_sphere(
context.
MBI, data_src.
file_set, defaultradius );
5883 local_areas[1] = areaAdaptor.area_on_sphere(
context.
MBI, data_tgt.
file_set, defaultradius );
5884 local_areas[2] = areaAdaptor.area_on_sphere(
context.
MBI, data_intx.
file_set, defaultradius );
5885 #ifdef MOAB_HAVE_MPI
5886 global_areas[0] = global_areas[1] = global_areas[2] = 0.0;
5887 MPI_Reduce( &local_areas[0], &global_areas[0], 3, MPI_DOUBLE, MPI_SUM, 0, pco_intx->
comm() );
5889 global_areas[0] = local_areas[0];
5890 global_areas[1] = local_areas[1];
5891 global_areas[2] = local_areas[2];
5896 outputFormatter.printf( 0,
5897 "initial area: source mesh = %12.14f, target mesh = %12.14f, "
5898 "overlap mesh = %12.14f\n",
5899 global_areas[0], global_areas[1], global_areas[2] );
5900 outputFormatter.printf( 0,
" relative error w.r.t source = %12.14e, and target = %12.14e\n",
5901 fabs( global_areas[0] - global_areas[2] ) / global_areas[0],
5902 fabs( global_areas[1] - global_areas[2] ) / global_areas[1] );
5913 double radius_source = 1.0;
5914 double radius_target = 1.0;
5915 const double epsrel = ReferenceTolerance;
5916 const double boxeps = 1.e-8;
5922 #ifdef MOAB_HAVE_MPI
5927 TempestMapAppData& tdata = data_intx.tempestData;
5930 #ifdef MOAB_HAVE_MPI
5941 ComputeSphereRadius( pid_src, &radius_source );
5942 ComputeSphereRadius( pid_tgt, &radius_target );
5953 std::cout <<
"The red set contains " << rintxverts.
size() <<
" vertices and " << rintxelems.
size()
5963 std::cout <<
"The blue set contains " << bintxverts.
size() <<
" vertices and " << bintxelems.
size()
5971 tdata.pid_src = pid_src;
5972 tdata.pid_dest = pid_tgt;
5977 #ifdef MOAB_HAVE_MPI
5982 tdata.remapper->meshValidate =
true;
5983 tdata.remapper->constructEdgeMap =
true;
5986 tdata.remapper->initialize(
false );
5993 if( fabs( radius_source - radius_target ) > 1e-10 )
6003 MB_CHK_ERR( tdata.remapper->ConstructCoveringSet( epsrel, 1.0, 1.0, boxeps,
false ) );
6005 #ifdef MOAB_HAVE_MPI
6019 ErrCode iMOAB_ComputeScalarProjectionWeights(
6023 int* disc_order_source,
6025 int* disc_order_target,
6028 int* fMonotoneTypeID,
6030 int* fInverseDistanceMap,
6031 int* fNoConservation,
6036 assert( disc_order_source && disc_order_target && *disc_order_source > 0 && *disc_order_target > 0 );
6037 assert( solution_weights_identifier && strlen( solution_weights_identifier ) );
6038 assert( disc_method_source && strlen( disc_method_source ) );
6039 assert( disc_method_target && strlen( disc_method_target ) );
6040 assert( source_solution_tag_dof_name && strlen( source_solution_tag_dof_name ) );
6041 assert( target_solution_tag_dof_name && strlen( target_solution_tag_dof_name ) );
6045 TempestMapAppData& tdata = data_intx.tempestData;
6049 tdata.weightMaps[std::string( solution_weights_identifier )] =
new moab::TempestOnlineMap( tdata.remapper );
6053 assert( weightMap !=
nullptr );
6055 GenerateOfflineMapAlgorithmOptions mapOptions;
6056 mapOptions.nPin = *disc_order_source;
6057 mapOptions.nPout = *disc_order_target;
6058 mapOptions.fSourceConcave =
false;
6059 mapOptions.fTargetConcave =
false;
6061 mapOptions.strMethod =
"";
6062 if( fv_method ) mapOptions.strMethod += std::string( fv_method ) +
";";
6063 if( fMonotoneTypeID )
6065 switch( *fMonotoneTypeID )
6068 mapOptions.fMonotone =
false;
6071 mapOptions.strMethod +=
"mono3;";
6074 mapOptions.strMethod +=
"mono2;";
6077 mapOptions.fMonotone =
true;
6081 mapOptions.fMonotone =
false;
6083 mapOptions.fNoBubble = ( fNoBubble ? *fNoBubble : false );
6084 mapOptions.fNoConservation = ( fNoConservation ? *fNoConservation > 0 : false );
6085 mapOptions.fNoCorrectAreas =
false;
6087 mapOptions.fNoCheck =
true;
6088 if( fVolumetric && *fVolumetric ) mapOptions.strMethod +=
"volumetric;";
6089 if( fInverseDistanceMap && *fInverseDistanceMap ) mapOptions.strMethod +=
"invdist;";
6091 std::string metadataStr = mapOptions.strMethod +
";" + std::string( disc_method_source ) +
":" +
6092 std::to_string( *disc_order_source ) +
":" + std::string( source_solution_tag_dof_name ) +
6093 ";" + std::string( disc_method_target ) +
":" + std::to_string( *disc_order_target ) +
6094 ":" + std::string( target_solution_tag_dof_name );
6096 data_intx.metadataMap[std::string( solution_weights_identifier )] = metadataStr;
6102 std::string( disc_method_source ),
6103 std::string( disc_method_target ),
6105 std::string( source_solution_tag_dof_name ),
6106 std::string( target_solution_tag_dof_name )
6112 if( fValidate && *fValidate )
6114 const double dNormalTolerance = 1.0E-8;
6115 const double dStrictTolerance = 1.0E-12;
6116 weightMap->CheckMap(
true,
true, ( fMonotoneTypeID && *fMonotoneTypeID ), dNormalTolerance, dStrictTolerance );
6129 ErrCode iMOAB_ApplyScalarProjectionWeights(
6136 assert( solution_weights_identifier && strlen( solution_weights_identifier ) );
6137 assert( source_solution_tag_name && strlen( source_solution_tag_name ) );
6138 assert( target_solution_tag_name && strlen( target_solution_tag_name ) );
6144 TempestMapAppData& tdata = data_intx.tempestData;
6146 if( !tdata.weightMaps.count( std::string( solution_weights_identifier ) ) )
6151 std::vector< std::string > srcNames;
6152 std::vector< std::string > tgtNames;
6153 std::vector< Tag > srcTagHandles;
6154 std::vector< Tag > tgtTagHandles;
6155 std::string separator(
":" );
6156 std::string src_name( source_solution_tag_name );
6157 std::string tgt_name( target_solution_tag_name );
6160 if( srcNames.size() != tgtNames.size() )
6162 std::cout <<
" error in parsing source and target tag names. \n";
6163 return moab::MB_FAILURE;
6167 for(
size_t i = 0; i < srcNames.size(); i++ )
6172 if(
MB_SUCCESS != rval ||
nullptr == tagHandle )
6176 srcTagHandles.push_back( tagHandle );
6180 if(
MB_SUCCESS != rval ||
nullptr == tagHandle )
6184 tgtTagHandles.push_back( tagHandle );
6190 std::vector< double > solSTagVals;
6191 std::vector< double > solTTagVals;
6201 solSTagVals.resize( covSrcEnts.
size(), 0. );
6214 solTTagVals.resize( tgtEnts.
size(), 0. );
6244 switch( *filter_type )
6261 std::string lo_weights_identifier =
6262 ( strlen( solution_weights_identifier ) > 3 ? std::string( solution_weights_identifier + 3 ) :
"" );
6264 bool useDualMapBounds =
false;
6265 if( lo_weights_identifier.size() && tdata.weightMaps.count( lo_weights_identifier ) )
6268 loWeightMap = tdata.weightMaps[lo_weights_identifier];
6273 if( useDualMapBounds )
6275 for(
size_t i = 0; i < srcTagHandles.size(); i++ )
6287 for(
size_t i = 0; i < srcNames.size(); i++ )
6289 std::string loBoundName = srcNames[i] +
"_DualMapLoBound";
6290 std::string hiBoundName = srcNames[i] +
"_DualMapHiBound";
6291 MB_CHK_ERR( ComputeRowBounds( pid_intersection, solution_weights_identifier, srcNames[i].c_str(),
6292 loBoundName.c_str(), hiBoundName.c_str() ) );
6297 for(
size_t i = 0; i < srcTagHandles.size(); i++ )
6310 Tag ssolnTag = srcTagHandles[ivar];
6311 std::stringstream sstr;
6312 sstr <<
"covsrcTagData_" << *pid_intersection <<
"_" << ivar <<
"_" << pco_intx->
rank() <<
".txt";
6313 std::ofstream output_file( sstr.str().c_str() );
6314 for(
unsigned i = 0; i < sents.
size(); ++i )
6317 std::vector< double > locsolSTagVals( 16 );
6320 for(
unsigned j = 0; j < 16; ++j )
6321 output_file << locsolSTagVals[j] <<
" ";
6323 output_file.flush();
6324 output_file.close();
6327 std::stringstream sstr;
6328 sstr <<
"outputSrcDest_" << *pid_intersection <<
"_" << ivar <<
"_" << pco_intx->
rank() <<
".h5m";
6334 std::stringstream sstr;
6335 sstr <<
"outputCovSrcDest_" << *pid_intersection <<
"_" << ivar <<
"_" << pco_intx->
rank() <<
".h5m";
6342 std::stringstream sstr;
6343 sstr <<
"covMesh_" << *pid_intersection <<
"_" << pco_intx->
rank() <<
".vtk";
6349 std::stringstream sstr;
6350 sstr <<
"tgtMesh_" << *pid_intersection <<
"_" << pco_intx->
rank() <<
".vtk";
6356 std::stringstream sstr;
6357 sstr <<
"colvector_" << *pid_intersection <<
"_" << ivar <<
"_" << pco_intx->
rank() <<
".txt";
6358 std::ofstream output_file( sstr.str().c_str() );
6359 for(
unsigned i = 0; i < solSTagVals.size(); ++i )
6360 output_file << i <<
" " << weightMap->col_dofmap[i] <<
" " << weightMap->
col_gdofmap[i] <<
" "
6361 << solSTagVals[i] <<
"\n";
6362 output_file.flush();
6363 output_file.close();
6377 assert( solution_weights_identifier && strlen( solution_weights_identifier ) );
6378 assert( source_solution_tag_name && strlen( source_solution_tag_name ) );
6379 assert( lower_bound_tag_name && strlen( lower_bound_tag_name ) );
6380 assert( upper_bound_tag_name && strlen( upper_bound_tag_name ) );
6383 TempestMapAppData& tdata = data_intx.tempestData;
6401 std::vector< double > srcVals( covSrcEnts.
size() * srcNDof * srcNDof, 0.0 );
6405 size_t nTargetDofs = tgtEnts.
size() * tgtNDof * tgtNDof;
6409 "Failed to get or create lower bound tag on target entities" );
6412 "Failed to get or create upper bound tag on target entities" );
6417 auto& W = weightMap->GetWeightMatrix();
6418 const std::vector< int >& col_dtoc = weightMap->
GetColDofMap();
6419 const std::vector< int >& row_dtoc = weightMap->
GetRowDofMap();
6421 for(
size_t k = 0; k < srcVals.size() && k < col_dtoc.size(); k++ )
6422 if( col_dtoc[k] > maxMatCol ) maxMatCol = col_dtoc[k];
6423 std::vector< int > col_inv( maxMatCol + 1, -1 );
6424 for(
size_t k = 0; k < srcVals.size() && k < col_dtoc.size(); k++ )
6425 if( col_dtoc[k] >= 0 ) col_inv[col_dtoc[k]] = (int)k;
6427 std::vector< double > loBound( nTargetDofs, 1e308 );
6428 std::vector< double > hiBound( nTargetDofs, -1e308 );
6430 for(
size_t i = 0; i < nTargetDofs; i++ )
6432 int r = ( i < row_dtoc.size() ) ? row_dtoc[i] : -1;
6433 if( r < 0 || r >= W.outerSize() )
6439 for( moab::TempestOnlineMap::WeightMatrix::InnerIterator it( W, r ); it; ++it )
6441 int mc = (int)it.col();
6442 if( mc < 0 || mc > maxMatCol )
continue;
6443 int srcIdx = col_inv[mc];
6444 if( srcIdx < 0 || srcIdx >= (
int)srcVals.size() )
continue;
6445 double v = srcVals[srcIdx];
6446 if( v < loBound[i] ) loBound[i] = v;
6447 if( v > hiBound[i] ) hiBound[i] = v;
6449 if( loBound[i] > hiBound[i] )
6458 "Failed to set lower bound tag data on target entities" );
6460 "Failed to set upper bound tag data on target entities" );