5 #include "TestUtil.hpp"
19 #define PRINT_LAST_ERROR \
20 if( MB_SUCCESS != result ) \
22 std::string tmp_str; \
23 std::cout << "Failure; message:" << std::endl; \
24 mbImpl->get_last_error( tmp_str ); \
25 std::cout << tmp_str << std::endl; \
26 MPI_Abort( MPI_COMM_WORLD, result ); \
33 std::cerr <<
"Usage: ";
35 <<
" -meshes <source_mesh> <target_mesh> -itag <interp_tag> [-gnorm <gnorm_tag>] "
36 "[-ssnorm <ssnorm_tag> <ssnorm_selection>] [-ropts <roptions>] [-outfile "
37 "<out_file> [-wopts <woptions>]] [-dbgout [<dbg_file>]]"
39 std::cerr <<
" -meshes" << std::endl;
40 std::cerr <<
" Read in mesh files <source_mesh> and <target_mesh>." << std::endl;
41 std::cerr <<
" -itag" << std::endl;
42 std::cerr <<
" Interpolate tag <interp_tag> from source mesh to target mesh." << std::endl;
43 std::cerr <<
" -gnorm" << std::endl;
44 std::cerr <<
" Normalize the value of tag <gnorm_tag> over then entire mesh and save to" << std::endl;
45 std::cerr <<
" tag \"<gnorm_tag>_normf\" on the mesh set. Do this for all meshes." << std::endl;
46 std::cerr <<
" -ssnorm" << std::endl;
47 std::cerr <<
" Normalize the value of tag <ssnorm_tag> over subsets of a mesh and save to" << std::endl;
48 std::cerr <<
" tag \"<ssnorm_tag>_normf\" on the Entity Set for each subset. Subsets "
51 std::cerr <<
" using criteria in <ssnorm_selection>. Do this for all meshes." << std::endl;
52 std::cerr <<
" -ropts" << std::endl;
53 std::cerr <<
" Read in the mesh files using options in <roptions>." << std::endl;
54 std::cerr <<
" -outfile" << std::endl;
55 std::cerr <<
" Write out target mesh to <out_file>." << std::endl;
56 std::cerr <<
" -wopts" << std::endl;
57 std::cerr <<
" Write out mesh files using options in <woptions>." << std::endl;
58 std::cerr <<
" -dbgout" << std::endl;
59 std::cerr <<
" Write stdout and stderr streams to the file \'<dbg_file>.txt\'." << std::endl;
60 std::cerr <<
" -eps" << std::endl;
61 std::cerr <<
" epsilon" << std::endl;
62 std::cerr <<
" -meth <method> (0=CONSTANT, 1=LINEAR_FE, 2=QUADRATIC_FE, 3=SPECTRAL)" << std::endl;
69 std::vector< std::string >& meshFiles,
71 std::string& interpTag,
72 std::string& gNormTag,
73 std::string& ssNormTag,
74 std::vector< const char* >& ssTagNames,
75 std::vector< const char* >& ssTagValues,
76 std::string& readOpts,
78 std::string& writeOpts,
90 ErrorCode report_iface_ents(
Interface* mbImpl, std::vector< ParallelComm* >& pcs,
bool print_results );
95 std::string& interpTag,
96 std::string& gNormTag,
97 std::string& ssNormTag,
98 std::vector< const char* >& ssTagNames,
99 std::vector< const char* >& ssTagValues,
100 std::vector< ParallelComm* >& pcs,
101 double& instant_time,
102 double& pointloc_time,
108 void reduceMax(
double& v )
112 MPI_Barrier( MPI_COMM_WORLD );
113 MPI_Allreduce( &v, &buf, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
118 int main(
int argc,
char** argv )
122 int err = MPI_Init( &argc, &argv );
125 std::cout <<
"MPI Initialization did not succeed.\n";
130 std::vector< const char* > ssTagNames, ssTagValues;
131 std::vector< std::string > meshFiles;
132 std::string interpTag, gNormTag, ssNormTag, readOpts, outFile, writeOpts, dbgFile;
137 double toler = 5.e-10;
138 result =
get_file_options( argc, argv, meshFiles, method, interpTag, gNormTag, ssNormTag, ssTagNames, ssTagValues,
139 readOpts, outFile, writeOpts, dbgFile,
help, toler );
145 err = MPI_Finalize();
148 std::cout <<
"MPI Initialization did not succeed.\n";
155 int nprocs = 1, rank = 0;
158 err = MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
159 err = MPI_Comm_rank( MPI_COMM_WORLD, &rank );
160 std::vector< ParallelComm* > pcs( meshFiles.size() );
164 if( !dbgFile.empty() )
166 std::stringstream dfname;
167 dfname << dbgFile << rank <<
".txt";
168 if( !std::freopen( dfname.str().c_str(),
"a", stdout ) )
return 2;
169 if( !std::freopen( dfname.str().c_str(),
"a", stderr ) )
return 2;
174 if( NULL == mbImpl )
return 1;
179 std::vector< EntityHandle > roots( meshFiles.size() );
181 for(
unsigned int i = 0; i < meshFiles.size(); i++ )
183 std::string newReadopts;
184 std::ostringstream extraOpt;
187 int index = pcs[i]->get_id();
188 extraOpt <<
";PARALLEL_COMM=" << index;
189 newReadopts = readOpts + extraOpt.str();
194 result = mbImpl->
load_file( meshFiles[i].c_str(), &roots[i], newReadopts.c_str() );
199 result = report_iface_ents( mbImpl, pcs,
true );
203 double instant_time = 0.0, pointloc_time = 0.0,
interp_time = 0.0, gnorm_time = 0.0, ssnorm_time = 0.0;
206 result = test_interpolation( mbImpl, method, interpTag, gNormTag, ssNormTag, ssTagNames, ssTagValues, pcs,
207 instant_time, pointloc_time,
interp_time, gnorm_time, ssnorm_time, toler );
210 reduceMax( instant_time );
211 reduceMax( pointloc_time );
215 printf(
"\nMax time : %g %g %g (inst loc interp -- %d procs)\n", instant_time, pointloc_time,
interp_time,
219 if( !outFile.empty() )
224 std::string newwriteOpts = writeOpts;
225 std::ostringstream extraOpt;
227 extraOpt <<
";PARALLEL_COMM=" << 1;
228 newwriteOpts += extraOpt.str();
230 result = mbImpl->
write_file( outFile.c_str(), NULL, newwriteOpts.c_str(), partSets );
232 std::cout <<
"Wrote " << outFile << std::endl;
233 std::cout <<
"mbcoupler_test complete." << std::endl;
237 for(
unsigned int i = 0; i < meshFiles.size(); i++ )
245 err = MPI_Finalize();
252 ErrorCode report_iface_ents(
Interface* mbImpl, std::vector< ParallelComm* >& pcs,
const bool print_results )
258 for(
unsigned int p = 0; p < pcs.size(); p++ )
260 for(
int i = 0; i < 4; i++ )
262 tmp_result = pcs[p]->get_iface_entities( -1, i, iface_ents[i] );
266 std::cerr <<
"get_iface_entities returned error on proc " << pcs[p]->proc_config().proc_rank()
267 <<
"; message: " << std::endl;
268 std::string last_error;
270 if( last_error.empty() )
271 std::cerr <<
"(none)" << std::endl;
273 std::cerr << last_error << std::endl;
276 if( 0 != i ) iface_ents[4].
merge( iface_ents[i] );
284 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
286 if( print_results || iface_ents[0].
size() != iface_ents[5].
size() )
288 std::cerr <<
"Proc " << rank <<
" iface entities: " << std::endl;
289 for(
int i = 0; i < 4; i++ )
290 std::cerr <<
" " << iface_ents[i].
size() <<
" " << i <<
"d iface entities." << std::endl;
291 std::cerr <<
" (" << iface_ents[5].
size() <<
" verts adj to other iface ents)" << std::endl;
311 std::vector< std::string >& meshFiles,
313 std::string& interpTag,
314 std::string& gNormTag,
315 std::string& ssNormTag,
316 std::vector< const char* >& ssTagNames,
317 std::vector< const char* >& ssTagValues,
318 std::string& readOpts,
319 std::string& outFile,
320 std::string& writeOpts,
321 std::string& dbgFile,
329 readOpts =
"PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARTITION_DISTRIBUTE;PARALLEL_"
330 "RESOLVE_SHARED_ENTS;PARALLEL_GHOSTS=3.0.1;CPUTIME";
332 writeOpts =
"PARALLEL=WRITE_PART;CPUTIME";
334 std::string defaultDbgFile = argv[0];
337 bool haveMeshes =
false;
338 bool haveInterpTag =
false;
343 if( argc > 1 && argv[1] == std::string(
"-h" ) )
351 if( argv[npos] == std::string(
"-meshes" ) )
356 meshFiles.resize( numFiles );
357 for(
int i = 0; i < numFiles; i++ )
360 meshFiles[i] = argv[npos++];
363 std::cerr <<
" ERROR - missing correct number of mesh filenames" << std::endl;
370 else if( argv[npos] == std::string(
"-itag" ) )
375 interpTag = argv[npos++];
378 std::cerr <<
" ERROR - missing <interp_tag>" << std::endl;
382 haveInterpTag =
true;
384 else if( argv[npos] == std::string(
"-meth" ) )
388 if( argv[npos][0] ==
'0' )
390 else if( argv[npos][0] ==
'1' )
392 else if( argv[npos][0] ==
'2' )
394 else if( argv[npos][0] ==
'3' )
398 std::cerr <<
" ERROR - unrecognized method number " << method << std::endl;
403 else if( argv[npos] == std::string(
"-eps" ) )
408 epsilon = atof( argv[npos++] );
411 std::cerr <<
" ERROR - missing <epsilon>" << std::endl;
415 else if( argv[npos] == std::string(
"-gnorm" ) )
420 gNormTag = argv[npos++];
423 std::cerr <<
" ERROR - missing <gnorm_tag>" << std::endl;
427 else if( argv[npos] == std::string(
"-ssnorm" ) )
432 ssNormTag = argv[npos++];
435 std::cerr <<
" ERROR - missing <ssnorm_tag>" << std::endl;
441 char* opts = argv[npos++];
442 char sep1[1] = {
';' };
443 char sep2[1] = {
'=' };
444 bool end_vals_seen =
false;
445 std::vector< char* > tmpTagOpts;
448 for(
char* i = strtok( opts, sep1 ); i; i = strtok( 0, sep1 ) )
449 tmpTagOpts.push_back( i );
452 for(
unsigned int j = 0; j < tmpTagOpts.size(); j++ )
454 char* e = strtok( tmpTagOpts[j], sep2 );
455 ssTagNames.push_back( e );
456 e = strtok( 0, sep2 );
463 std::cerr <<
" ERROR - new value seen after end of values in "
471 ssTagValues.push_back( (
const char*)valp );
476 end_vals_seen =
true;
477 ssTagValues.push_back( (
const char*)0 );
483 std::cerr <<
" ERROR - missing <ssnorm_selection>" << std::endl;
487 else if( argv[npos] == std::string(
"-ropts" ) )
492 readOpts = argv[npos++];
495 std::cerr <<
" ERROR - missing <roptions>" << std::endl;
499 else if( argv[npos] == std::string(
"-outfile" ) )
504 outFile = argv[npos++];
507 std::cerr <<
" ERROR - missing <out_file>" << std::endl;
511 else if( argv[npos] == std::string(
"-wopts" ) )
516 writeOpts = argv[npos++];
519 std::cerr <<
" ERROR - missing <woptions>" << std::endl;
523 else if( argv[npos] == std::string(
"-dbgout" ) )
529 dbgFile = argv[npos++];
531 dbgFile = defaultDbgFile;
536 std::cerr <<
" ERROR - Unrecognized parameter:" << argv[npos] << std::endl;
537 std::cerr <<
" Skipping..." << std::endl;
544 meshFiles.resize( 2 );
545 meshFiles[0] = std::string( TestDir +
"unittest/64bricks_1khex.h5m" );
546 meshFiles[1] = std::string( TestDir +
"unittest/64bricks_12ktet.h5m" );
547 std::cout <<
"Mesh files not entered; using default files " << meshFiles[0] <<
" and " << meshFiles[1]
553 interpTag =
"vertex_field";
554 std::cout <<
"Interpolation field name not given, using default of " << interpTag << std::endl;
557 #ifdef MOAB_HAVE_HDF5
560 std::cout <<
"No arguments given; using output file dum.h5m." << std::endl;
572 std::string& interpTag,
575 std::vector< const char* >& ,
576 std::vector< const char* >& ,
577 std::vector< ParallelComm* >& pcs,
578 double& instant_time,
579 double& pointloc_time,
588 Range src_elems, targ_elems, targ_verts;
589 ErrorCode result = pcs[0]->get_part_entities( src_elems, 3 );
607 std::vector< double > vpos;
608 int numPointsOfInterest = 0;
610 result = pcs[1]->get_part_entities( targ_elems, 3 );
616 targ_verts = targ_elems;
626 targ_verts =
subtract( targ_verts, tmp_verts );
629 numPointsOfInterest = (int)targ_verts.
size();
630 vpos.resize( 3 * targ_verts.
size() );
631 result = mbImpl->
get_coords( targ_verts, &vpos[0] );
636 std::cout <<
"rank " << pcs[0]->proc_config().proc_rank();
638 std::cout <<
" points of interest: " << numPointsOfInterest <<
"\n";
639 result = dc.locate_points( &vpos[0], numPointsOfInterest, toler );
645 std::vector< double > field( numPointsOfInterest );
647 result = dc.interpolate( method, interpTag, &field[0] );
657 result = mbImpl->
tag_set_data( tag, targ_verts, &field[0] );