21 #ifndef IS_BUILDING_MB
22 #define IS_BUILDING_MB
36 std::vector< const char* >& filenames,
37 std::string& norm_tag,
38 std::vector< const char* >& tag_names,
39 std::vector< const char* >& tag_values,
40 std::string& file_opts,
46 std::vector< std::vector< EntityHandle > >& groups,
51 double field_1(
double x,
double y,
double z );
52 double field_2(
double x,
double y,
double z );
53 double field_3(
double x,
double y,
double z );
54 double physField(
double x,
double y,
double z );
63 int main(
int argc,
char** argv )
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" );
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,
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;
225 std::cout <<
" create_tuples returned" << std::endl;
229 (
const void*
const*)&tagValues[0], tagHandles.size(), entsets2,
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;
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;
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() );
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() );
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;
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;
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;
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;
569 std::cout <<
"********** Test moab::Element::Map::integrate_scalar_field **********" << std::endl;
571 std::vector< CartVect > biunit_cube( 8 );
572 biunit_cube[0] =
CartVect( -1, -1, -1 );
573 biunit_cube[1] =
CartVect( 1, -1, -1 );
574 biunit_cube[2] =
CartVect( 1, 1, -1 );
575 biunit_cube[3] =
CartVect( -1, 1, -1 );
576 biunit_cube[4] =
CartVect( -1, -1, 1 );
577 biunit_cube[5] =
CartVect( 1, -1, 1 );
578 biunit_cube[6] =
CartVect( 1, 1, 1 );
579 biunit_cube[7] =
CartVect( -1, 1, 1 );
581 std::vector< CartVect > zerobase_cube( 8 );
582 zerobase_cube[0] =
CartVect( 0, 0, 0 );
583 zerobase_cube[1] =
CartVect( 2, 0, 0 );
584 zerobase_cube[2] =
CartVect( 2, 2, 0 );
585 zerobase_cube[3] =
CartVect( 0, 2, 0 );
586 zerobase_cube[4] =
CartVect( 0, 0, 2 );
587 zerobase_cube[5] =
CartVect( 2, 0, 2 );
588 zerobase_cube[6] =
CartVect( 2, 2, 2 );
589 zerobase_cube[7] =
CartVect( 0, 2, 2 );
592 double bcf[8], bf1[8], bf2[8], bf3[8], zcf[8], zf1[8], zf2[8], zf3[8];
593 for(
int i = 0; i < 8; i++ )
595 bcf[i] =
const_field( biunit_cube[i][0], biunit_cube[i][1], biunit_cube[i][2] );
596 bf1[i] =
field_1( biunit_cube[i][0], biunit_cube[i][1], biunit_cube[i][2] );
597 bf2[i] =
field_2( biunit_cube[i][0], biunit_cube[i][1], biunit_cube[i][2] );
598 bf3[i] =
field_3( biunit_cube[i][0], biunit_cube[i][1], biunit_cube[i][2] );
600 zcf[i] =
const_field( zerobase_cube[i][0], zerobase_cube[i][1], zerobase_cube[i][2] );
601 zf1[i] =
field_1( zerobase_cube[i][0], zerobase_cube[i][1], zerobase_cube[i][2] );
602 zf2[i] =
field_2( zerobase_cube[i][0], zerobase_cube[i][1], zerobase_cube[i][2] );
603 zf3[i] =
field_3( zerobase_cube[i][0], zerobase_cube[i][1], zerobase_cube[i][2] );
606 std::cout <<
"Integrated values:" << std::endl;
610 double field_const1, field_const2;
611 double field_linear1, field_linear2;
612 double field_quad1, field_quad2;
613 double field_cubic1, field_cubic2;
621 std::cout <<
" binunit_cube, const_field(num_pts=" << ipoints <<
"): field_val=" << field_const1
623 std::cout <<
" zerobase_cube, const_field(num_pts=" << ipoints <<
"): field_val=" << field_const2
628 std::cout <<
" binunit_cube, field_1(num_pts=" << ipoints <<
"): field_val=" << field_linear1 << std::endl;
629 std::cout <<
" zerobase_cube, field_1(num_pts=" << ipoints <<
"): field_val=" << field_linear2 << std::endl;
633 std::cout <<
" binunit_cube, field_2(num_pts=" << ipoints <<
"): field_val=" << field_quad1 << std::endl;
634 std::cout <<
" zerobase_cube, field_2(num_pts=" << ipoints <<
"): field_val=" << field_quad2 << std::endl;
638 std::cout <<
" binunit_cube, field_3(num_pts=" << ipoints <<
"): field_val=" << field_cubic1 << std::endl;
639 std::cout <<
" zerobase_cube, field_3(num_pts=" << ipoints <<
"): field_val=" << field_cubic2 << std::endl;
643 MB_CHK_SET_ERR( MB_FAILURE,
"Failed to set vertices on Element::Map." );
647 MB_CHK_SET_ERR( MB_FAILURE,
"Failed to get inverse evaluation of coordinate on Element::Map." );
655 std::vector< const char* >& filenames,
656 std::string& normTag,
657 std::vector< const char* >& tagNames,
658 std::vector< const char* >& tagValues,
659 std::string& fileOpts,
665 int nfiles = atoi( argv[npos++] );
668 filenames.resize( nfiles );
669 for(
int i = 0; i < nfiles; i++ )
670 filenames[i] = argv[npos++];
674 normTag = argv[npos++];
677 std::cerr <<
"Insufficient parameters: norm_tag missing" << std::endl;
685 char* opts = argv[npos++];
688 bool end_vals_seen =
false;
689 std::vector< char* > tmpTagOpts;
692 for(
char* i = strtok( opts,
";" ); i; i = strtok( 0,
";" ) )
694 if(
debug ) std::cout <<
"get_file_options: i=" << i << std::endl;
695 tmpTagOpts.push_back( i );
699 for(
unsigned int j = 0; j < tmpTagOpts.size(); j++ )
701 char* e = strtok( tmpTagOpts[j],
"=" );
702 if(
debug ) std::cout <<
"get_file_options: name=" << e << std::endl;
703 tagNames.push_back( e );
704 e = strtok( 0,
"=" );
707 if(
debug ) std::cout <<
"get_file_options: val=" << e << std::endl;
712 std::cerr <<
"Incorrect parameters: new value seen after end of values" << std::endl;
719 tagValues.push_back( (
const char*)valp );
724 end_vals_seen =
true;
725 tagValues.push_back( (
const char*)0 );
731 std::cerr <<
"Insufficient parameters: tag_select_opts missing" << std::endl;
738 fileOpts = argv[npos++];
741 std::cerr <<
"Insufficient parameters: file_opts missing" << std::endl;
750 uint mi, ml, mul, mr;
752 std::cout <<
" tuple data: (n=" << tlp->
get_n() <<
")" << std::endl;
753 std::cout <<
" mi:" << mi <<
" ml:" << ml <<
" mul:" << mul <<
" mr:" << mr << std::endl;
754 std::cout <<
" [" << std::setw( 11 * mi ) <<
" int data"
755 <<
" |" << std::setw( 11 * ml ) <<
" long data"
756 <<
" |" << std::setw( 11 * mul ) <<
" Ulong data"
757 <<
" |" << std::setw( 11 * mr ) <<
" real data"
760 for(
unsigned int i = 0; i < tlp->
get_n(); i++ )
764 for(
unsigned int j = 0; j < mi; j++ )
766 std::cout << std::setw( 10 ) << tlp->
vi_rd[i * mi + j] <<
" ";
777 for(
unsigned int j = 0; j < ml; j++ )
779 std::cout << std::setw( 10 ) << tlp->
vl_rd[i * ml + j] <<
" ";
790 for(
unsigned int j = 0; j < mul; j++ )
792 std::cout << std::setw( 10 ) << tlp->
vul_rd[i * mul + j] <<
" ";
803 for(
unsigned int j = 0; j < mr; j++ )
805 std::cout << std::setw( 10 ) << tlp->
vr_rd[i * mr + j] <<
" ";
813 if( i + 1 < tlp->
get_n() ) std::cout << std::endl <<
" ";
815 std::cout <<
"]" << std::endl;
820 std::vector< std::vector< EntityHandle > >& groups,
826 std::vector< EntityHandle >::iterator iter_j;
828 for(
unsigned int i = 0; i < groups.size(); i++ )
830 std::cout <<
" Group - " << std::endl <<
" ";
831 for( iter_j = groups[i].begin(); iter_j != groups[i].end(); ++iter_j )
845 std::cout << std::fixed;
846 for(
int iv = 0; iv < num_verts; iv++ )
849 result = mbi->
tag_get_data( norm_hdl, &conn[iv], 1, &data );
851 std::cout << std::setprecision( 8 ) << data <<
", ";
853 std::cout << std::endl <<
" ";
855 std::cout << std::endl;
856 std::cout.unsetf( std::ios_base::floatfield );
870 double field_1(
double x,
double y,
double z )
872 double f = fabs( x ) + fabs( y ) + fabs( z );
877 double field_2(
double x,
double y,
double z )
879 double f = x * x + y * y + z * z;
884 double field_3(
double x,
double y,
double z )
886 double f = 2 * x + 2 * y + 2 * z;
898 out = x * x + y * y + z * z;
905 #define UINT_PER_X( X ) ( ( sizeof( X ) + sizeof( uint ) - 1 ) / sizeof( uint ) )
906 #define UINT_PER_REAL UINT_PER_X( realType )
907 #define UINT_PER_LONG UINT_PER_X( slong )
908 #define UINT_PER_ULONG UINT_PER_X( Ulong )
909 #define UINT_PER_UNSIGNED UINT_PER_X( unsigned )
914 uint mi, ml, mul, mr;
926 memcpy( buf, &n,
sizeof(
uint ) ), buf += 1;
954 unsigned mit, mlt, mult, mrt;
958 memcpy( &nt, buf,
sizeof(
uint ) ), buf += 1;
973 uint mi, ml, mul, mr;