68 int err = MPI_Init( &argc, &argv );
73 std::cerr <<
"Usage: ";
74 std::cerr << argv[0] <<
" <nfiles> <fname1> ... <fnamen> <norm_tag> <tag_select_opts> <file_opts>" << std::endl;
75 std::cerr <<
"nfiles : number of mesh files" << std::endl;
76 std::cerr <<
"fname1...fnamen : mesh files" << std::endl;
77 std::cerr <<
"norm_tag : name of tag to normalize across meshes" << std::endl;
78 std::cerr <<
"tag_select_opts : quoted string of tags and values for subset selection, "
79 "e.g. \"TAG1=VAL1;TAG2=VAL2;TAG3;TAG4\""
81 std::cerr <<
"file_opts : quoted string of parallel file read options, e.g. "
82 "\"OPTION1=VALUE1;OPTION2;OPTION3=VALUE3\""
93 err = MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
94 assert( MPI_SUCCESS == err );
95 err = MPI_Comm_rank( MPI_COMM_WORLD, &rank );
96 assert( MPI_SUCCESS == err );
99 std::stringstream fname;
100 fname << argv[0] << rank <<
".out";
101 if( !std::freopen( fname.str().c_str(),
"a", stdout ) )
return -1;
102 if( !std::freopen( fname.str().c_str(),
"a", stderr ) )
return -1;
108 std::cerr <<
"MOAB constructor failed" << std::endl;
113 std::cout <<
"Getting options..." << std::endl;
114 std::vector< const char* > filenames;
115 std::vector< const char* > tagNames;
116 std::vector< const char* > tagValues;
117 std::string normTag, fileOpts;
121 std::cout <<
" Input Parameters - " << std::endl;
122 std::cout <<
" Filenames: ";
123 for( std::vector< const char* >::iterator it = filenames.begin(); it != filenames.end(); ++it )
124 std::cout << *it <<
" ";
125 std::cout << std::endl;
126 std::cout <<
" Norm Tag: " << normTag << std::endl;
127 std::cout <<
" Selection Data: NumNames=" << tagNames.size() <<
" NumValues=" << tagValues.size() << std::endl;
128 std::cout <<
" TagNames TagValues " << std::endl;
129 std::cout <<
" -------------------- --------------------" << std::endl;
130 std::vector< const char* >::iterator nameIt = tagNames.begin();
131 std::vector< const char* >::iterator valIt = tagValues.begin();
132 std::cout << std::setiosflags( std::ios::left );
133 for( ; nameIt != tagNames.end(); ++nameIt )
135 std::cout <<
" " << std::setw( 20 ) << *nameIt;
138 std::cout <<
" " << std::setw( 20 ) << *( (
int*)( *valIt ) ) << std::endl;
142 std::cout <<
" NULL " << std::endl;
144 std::cout << std::resetiosflags( std::ios::left );
145 std::cout <<
" File Options: " << fileOpts << std::endl;
148 std::cout <<
"Reading mesh file(s)..." << std::endl;
149 std::vector< ParallelComm* > pcs( filenames.size() );
150 std::vector< ReadParallel* > rps( filenames.size() );
153 std::vector< EntityHandle > roots( filenames.size() );
156 for(
unsigned int i = 0; i < filenames.size(); i++ )
164 result = rps[i]->load_file( filenames[i], &roots[i],
FileOptions( fileOpts.c_str() ) );
MB_CHK_SET_ERR( result,
"load_file failed" );
169 debugOut.set_rank( rank );
170 debugOut.set_verbosity( 10 );
173 for(
unsigned int k = 0; k < filenames.size(); k++ )
178 debugOut.print( 2,
"Root set entities: ", rootRg );
182 pcs[k]->get_part_entities( partRg );
183 debugOut.
print( 2,
"Partition entities: ", partRg );
188 Range src_elems, targ_elems;
191 std::cout <<
"********** Create Coupler **********" << std::endl;
193 std::cout <<
"Creating Coupler..." << std::endl;
194 Coupler mbc( mbi, pcs[0], src_elems, 0 );
197 std::cout <<
"Getting tag handles..." << std::endl;
198 int numTagNames = tagNames.size();
200 std::vector< Tag > tagHandles( numTagNames );
202 while( iTags < numTagNames )
204 std::cout <<
"Getting handle for " << tagNames[iTags] << std::endl;
210 std::cout <<
"********** Test create_tuples **********" << std::endl;
214 Range entsets1, entsets2;
216 (
const void*
const*)&tagValues[0], tagHandles.size(), entsets1,
217 Interface::INTERSECT );
218 MB_CHK_SET_ERR( result,
"sets: get_entities_by_type_and_tag failed on Mesh 1." );
221 std::cout <<
"Creating tuples for mesh 1..." << std::endl;
223 err = mbc.create_tuples( entsets1, &tagHandles[0], tagHandles.size(), &m1TagTuples );
MB_CHK_SET_ERR( (
ErrorCode)err,
"create_tuples failed" );
225 std::cout <<
" create_tuples returned" << std::endl;
229 (
const void*
const*)&tagValues[0], tagHandles.size(), entsets2,
230 Interface::INTERSECT );
231 MB_CHK_SET_ERR( result,
"sets: get_entities_by_type_and_tag failed on Mesh 2." );
233 std::cout <<
"Creating tuples for mesh 2..." << std::endl;
235 err = mbc.create_tuples( entsets2, (
Tag*)( &tagHandles[0] ), tagHandles.size(), &m2TagTuples );
MB_CHK_SET_ERR( (
ErrorCode)err,
"create_tuples failed" );
237 std::cout <<
" create_tuples returned" << std::endl;
241 std::cout <<
"********** Test consolidate_tuples **********" << std::endl;
244 std::cout <<
"Consolidating tuple_lists for Mesh 1 and Mesh 2..." << std::endl;
247 tplp_arr[0] = m1TagTuples;
248 tplp_arr[1] = m2TagTuples;
250 err = mbc.consolidate_tuples( tplp_arr, 2, &unique_tpl );
MB_CHK_SET_ERR( (
ErrorCode)err,
"consolidate_tuples failed" );
251 std::cout <<
" consolidate_tuples returned" << std::endl;
256 std::cout <<
"********** Test get_matching_entities **********" << std::endl;
257 std::vector< std::vector< EntityHandle > > m1EntitySets;
258 std::vector< std::vector< EntityHandle > > m1EntityGroups;
259 std::vector< std::vector< EntityHandle > > m2EntitySets;
260 std::vector< std::vector< EntityHandle > > m2EntityGroups;
263 std::cout <<
"Get matching entities for mesh 1..." << std::endl;
264 err = mbc.get_matching_entities( roots[0], &tagHandles[0], &tagValues[0], tagHandles.size(), &m1EntitySets,
267 std::cout <<
" get_matching_entities returned " << m1EntityGroups.size() <<
" entity groups" << std::endl;
270 std::vector< std::vector< EntityHandle > >::iterator iter_esi;
271 std::vector< std::vector< EntityHandle > >::iterator iter_egi;
272 std::vector< EntityHandle >::iterator iter_esj;
273 std::vector< EntityHandle >::iterator iter_egj;
276 for( iter_egi = m1EntityGroups.begin(), iter_esi = m1EntitySets.begin(), icnt = 1;
277 ( iter_egi != m1EntityGroups.end() ) && ( iter_esi != m1EntitySets.end() ); ++iter_egi, ++iter_esi, icnt++ )
279 std::cout <<
" EntityGroup(" << icnt <<
") = ";
282 for( iter_egj = ( *iter_egi ).begin(); iter_egj != ( *iter_egi ).end(); ++iter_egj )
284 debugOut.print( 2,
"Mesh1 matching Entities: ", entSetRg );
287 std::cout <<
" EntitySet(" << icnt <<
") = ";
290 for( iter_esj = ( *iter_esi ).begin(); iter_esj != ( *iter_esi ).end(); ++iter_esj )
292 debugOut.print( 2,
"Mesh1 matching EntitySets: ", entSetRg );
297 std::cout <<
"Get matching entities for mesh 2..." << std::endl;
298 err = mbc.get_matching_entities( roots[1], &tagHandles[0], &tagValues[0], tagHandles.size(), &m2EntitySets,
301 std::cout <<
" get_matching_entities returned " << m2EntityGroups.size() <<
" entity groups" << std::endl;
302 for( iter_egi = m2EntityGroups.begin(), iter_esi = m2EntitySets.begin(), icnt = 1;
303 ( iter_egi != m2EntityGroups.end() ) && ( iter_esi != m2EntitySets.end() ); ++iter_egi, ++iter_esi, icnt++ )
305 std::cout <<
" EntityGroup(" << icnt <<
") = ";
308 for( iter_egj = ( *iter_egi ).begin(); iter_egj != ( *iter_egi ).end(); ++iter_egj )
310 debugOut.print( 2,
"Mesh2 matching Entities: ", entSetRg );
313 std::cout <<
" EntitySet(" << icnt <<
") = ";
316 for( iter_esj = ( *iter_esi ).begin(); iter_esj != ( *iter_esi ).end(); ++iter_esj )
318 debugOut.print( 2,
"Mesh2 matching EntitySets: ", entSetRg );
325 std::cout <<
"********** Test print_tuples **********" << std::endl;
327 std::cout <<
"Testing print_tuples..." << std::endl;
330 int num_ints = 3, num_longs = 2, num_ulongs = 4, num_reals = 6, num_rows = 10;
332 std::cout <<
" print of test_tuples zero init..." << std::endl;
339 std::cout <<
" print of test_tuples after setting n to 10..." << std::endl;
340 test_tuple.
set_n( 10 );
343 test_tuple.
initialize( num_ints, num_longs, num_ulongs, num_reals, num_rows );
344 std::cout <<
" print of test_tuples after init..." << std::endl;
347 std::cout <<
" print of test_tuples after setting n to 10..." << std::endl;
348 test_tuple.
set_n( 10 );
351 for(
int i = 0; i < num_rows; i++ )
354 for( j = 0; j < num_ints; j++ )
355 test_tuple.
vi_wr[i * num_ints + j] = (
int)( ( j + 1 ) * ( i + 1 ) );
357 for( j = 0; j < num_longs; j++ )
358 test_tuple.
vl_wr[i * num_longs + j] = (
int)( ( j + 1 ) * ( i + 1 ) );
360 for( j = 0; j < num_ulongs; j++ )
361 test_tuple.
vul_wr[i * num_ulongs + j] = (
int)( ( j + 1 ) * ( i + 1 ) );
363 for( j = 0; j < num_reals; j++ )
364 test_tuple.
vr_wr[i * num_reals + j] = (
int)( ( j + 1 ) * ( i + 1 ) + ( j * 0.01 ) );
366 std::cout <<
" print of test_tuples after filling with data..." << std::endl;
370 std::cout <<
"********** Test pack_tuples and unpack_tuples **********" << std::endl;
379 err = MPI_Bcast( &buf_sz, 1, MPI_INT, 0, MPI_COMM_WORLD );
381 if( err != MPI_SUCCESS )
383 std::cerr <<
"MPI_Bcast of buffer size failed" << std::endl;
390 mp_buf = malloc( buf_sz *
sizeof(
uint ) );
393 err = MPI_Bcast( mp_buf, buf_sz *
sizeof(
uint ), MPI_UNSIGNED_CHAR, 0, MPI_COMM_WORLD );
394 if( err != MPI_SUCCESS )
396 std::cerr <<
"MPI_Bcast of buffer failed" << std::endl;
403 std::cout <<
" print of rcv_tuples after unpacking from MPI_Bcast..." << std::endl;
410 std::cout <<
"********** Test get_group_integ_vals **********" << std::endl;
411 std::cout <<
"Get group integrated field values..." << std::endl;
414 std::cout <<
" print vertex field values first:" << std::endl;
420 std::cout <<
" Original entity vertex field values (mesh 1): " << std::endl;
424 std::cout <<
" Original entity vertex field values (mesh 2): " << std::endl;
428 std::vector< double >::iterator iter_ivals;
430 std::cout <<
"Get group integrated field values for mesh 1..." << std::endl;
431 std::vector< double > m1IntegVals( m1EntityGroups.size() );
432 err = mbc.get_group_integ_vals( m1EntityGroups, m1IntegVals, normTag.c_str(), 4, integ_type );
MB_CHK_SET_ERR( (
ErrorCode)err,
"Failed to get the Mesh 1 group integration values." );
433 std::cout <<
"Mesh 1 integrated field values(" << m1IntegVals.size() <<
"): ";
434 for( iter_ivals = m1IntegVals.begin(); iter_ivals != m1IntegVals.end(); ++iter_ivals )
436 std::cout << ( *iter_ivals ) <<
" ";
438 std::cout << std::endl;
440 std::cout <<
"Get group integrated field values for mesh 2..." << std::endl;
441 std::vector< double > m2IntegVals( m2EntityGroups.size() );
442 err = mbc.get_group_integ_vals( m2EntityGroups, m2IntegVals, normTag.c_str(), 4, integ_type );
MB_CHK_SET_ERR( (
ErrorCode)err,
"Failed to get the Mesh 2 group integration values." );
443 std::cout <<
"Mesh 2 integrated field values(" << m2IntegVals.size() <<
"): ";
444 for( iter_ivals = m2IntegVals.begin(); iter_ivals != m2IntegVals.end(); ++iter_ivals )
446 std::cout << ( *iter_ivals ) <<
" ";
448 std::cout << std::endl;
451 std::cout <<
"********** Test apply_group_norm_factors **********" << std::endl;
454 for(
unsigned int i = 0; i < m1IntegVals.size(); i++ )
456 val = m1IntegVals[i];
457 m1IntegVals[i] = 1 / val;
460 for(
unsigned int i = 0; i < m2IntegVals.size(); i++ )
462 val = m2IntegVals[i];
463 m2IntegVals[i] = 1 / val;
466 std::cout <<
"Mesh 1 norm factors(" << m1IntegVals.size() <<
"): ";
467 for( iter_ivals = m1IntegVals.begin(); iter_ivals != m1IntegVals.end(); ++iter_ivals )
469 std::cout << ( *iter_ivals ) <<
" ";
471 std::cout << std::endl;
473 std::cout <<
"Mesh 2 norm factors(" << m2IntegVals.size() <<
"): ";
474 for( iter_ivals = m2IntegVals.begin(); iter_ivals != m2IntegVals.end(); ++iter_ivals )
476 std::cout << ( *iter_ivals ) <<
" ";
478 std::cout << std::endl;
481 err = mbc.apply_group_norm_factor( m1EntitySets, m1IntegVals, normTag.c_str(), integ_type );
MB_CHK_SET_ERR( (
ErrorCode)err,
"Failed to apply norm factors to Mesh 1." );
483 err = mbc.apply_group_norm_factor( m2EntitySets, m2IntegVals, normTag.c_str(), integ_type );
MB_CHK_SET_ERR( (
ErrorCode)err,
"Failed to apply norm factors to Mesh 2." );
488 std::string normFactor = normTag +
"_normf";
492 std::cout <<
"Mesh 1 norm factors per EntitySet...";
493 for( iter_esi = m1EntitySets.begin(); iter_esi != m1EntitySets.end(); ++iter_esi )
495 for( iter_esj = ( *iter_esi ).begin(); iter_esj != ( *iter_esi ).end(); ++iter_esj )
500 std::cout << data <<
", ";
503 std::cout << std::endl;
506 std::cout <<
"Mesh 2 norm factors per EntitySet...";
507 for( iter_esi = m2EntitySets.begin(); iter_esi != m2EntitySets.end(); ++iter_esi )
509 for( iter_esj = ( *iter_esi ).begin(); iter_esj != ( *iter_esi ).end(); ++iter_esj )
514 std::cout << data <<
", ";
517 std::cout << std::endl;
520 std::cout <<
"********** Test normalize_subset **********" << std::endl;
522 std::cout <<
"Running Coupler::normalize_subset() on mesh 1" << std::endl;
523 err = mbc.normalize_subset( (
EntityHandle)roots[0], normTag.c_str(), &tagNames[0], numTagNames, &tagValues[0],
528 std::cout <<
"Mesh 1 norm factors per EntitySet...";
529 for( iter_esi = m1EntitySets.begin(); iter_esi != m1EntitySets.end(); ++iter_esi )
531 for( iter_esj = ( *iter_esi ).begin(); iter_esj != ( *iter_esi ).end(); ++iter_esj )
536 std::cout << data <<
", ";
539 std::cout << std::endl;
541 std::cout <<
"Running Coupler::normalize_subset() on mesh 2" << std::endl;
542 err = mbc.normalize_subset( (
EntityHandle)roots[1], normTag.c_str(), &tagNames[0], numTagNames, &tagValues[0],
546 std::cout <<
"Mesh 2 norm factors per EntitySet...";
547 for( iter_esi = m2EntitySets.begin(); iter_esi != m2EntitySets.end(); ++iter_esi )
549 for( iter_esj = ( *iter_esi ).begin(); iter_esj != ( *iter_esi ).end(); ++iter_esj )
555 std::cout << data <<
", ";
558 std::cout << std::endl;
561 std::cout <<
"********** ssn_test DONE! **********" << std::endl;