6 #if defined( __MINGW32__ )
31 #define NOT_IMPLEMENTED 2
35 static void print_usage(
const char* name, std::ostream& stream )
37 stream <<
"Usage: " << name <<
" <options> <input_file> [<input_file2> ...]" << std::endl
38 <<
"Options: " << std::endl
39 <<
"\t-h - Print this help text and exit." << std::endl
40 <<
"\t-d - Dimension of the mesh." << std::endl
41 <<
"\t-n - Exact or a maximum number of levels for the hierarchy. Default 1." << std::endl
42 <<
"\t-L - Degree of refinement for each level. Pass an array or a number. It "
43 "is mandatory to pass dimension and num_levels before to use this option. If this flag "
44 "is not used, a default of deg 2 refinement is used. "
46 <<
"\t-V - Pass a desired volume (absolute) . This will generate a hierarchy "
47 "such that the maximum volume is reduced to the given amount approximately. The length "
48 "of the hierarchy can be constrained further if a maximum number of levels is passed. "
49 "It is mandatory to pass the dimension for this option. "
51 <<
"\t-q - Prints out the maximum volume of the mesh and exits the program. "
52 "This option can be used as a guide to volume constrainted mesh hierarchy later. "
54 <<
"\t-t - Print out the time taken to generate hierarchy." << std::endl
55 <<
"\t-s - Print out the mesh sizes of each level of the generated hierarchy." << std::endl
56 <<
"\t-o - Specify true for output files for the mesh levels of the hierarchy." << std::endl
59 <<
"\t-p[0|1|2] - Read in parallel[0], optionally also doing resolve_shared_ents (1) "
60 "and exchange_ghosts (2)"
76 bool parse_id_list(
const char*
string,
int dim,
int nval, std::vector< int >& results );
78 bool make_opts_string( std::vector< std::string > options, std::string& opts );
85 std::vector< int >& level_degs );
89 int main(
int argc,
char* argv[] )
91 int proc_id = 0,
size = 1;
93 MPI_Init( &argc, &argv );
94 MPI_Comm_rank( MPI_COMM_WORLD, &proc_id );
95 MPI_Comm_size( MPI_COMM_WORLD, &
size );
98 int num_levels = 0,
dim = 0;
99 std::vector< int > level_degrees;
100 bool optimize =
false;
102 bool print_times =
false, print_size =
false,
output =
false;
103 bool parallel =
false, resolve_shared =
false, exchange_ghosts =
false;
104 bool printusage =
false, parselevels =
true;
105 bool qc_vol =
false, only_quality =
false;
112 if( !argv[i][0] && 0 == proc_id )
120 if( do_flag && argv[i][0] ==
'-' )
140 dim = atol( argv[i + 1] );
144 num_levels = atol( argv[i + 1] );
148 if(
dim != 0 && num_levels != 0 )
161 cvol = strtod( argv[i + 1], NULL );
176 resolve_shared =
true;
177 if( argv[i][1] ==
'1' ) exchange_ghosts =
true;
182 switch( argv[i - 1][1] )
186 std::cerr <<
"Invalid option: " << argv[i] << std::endl;
199 if( infile.empty() && !printusage )
print_usage( argv[0], std::cerr );
205 resolve_shared =
true;
218 std::vector< std::string > read_opts, write_opts;
219 std::string read_options, write_options;
221 if( parallel &&
size > 1 )
223 read_opts.push_back(
"PARALLEL=READ_PART" );
224 read_opts.push_back(
"PARTITION=PARALLEL_PARTITION" );
225 if( resolve_shared ) read_opts.push_back(
"PARALLEL_RESOLVE_SHARED_ENTS" );
226 if( exchange_ghosts ) read_opts.push_back(
"PARALLEL_GHOSTS=3.0.1" );
244 std::cout <<
"READ OPTS=" << (
char*)read_options.c_str() << std::endl;
256 std::vector< EntityHandle > lsets;
266 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
267 if( rank == 0 ) std::cout <<
"Maximum global volume = " << vmax << std::endl;
269 std::cout <<
"Maximum volume = " << vmax << std::endl;
283 if( num_levels == 0 ) num_levels = 1;
285 int* ldeg =
new int[num_levels];
287 if( level_degrees.empty() )
289 for(
int l = 0; l < num_levels; l++ )
294 for(
int l = 0; l < num_levels; l++ )
295 ldeg[l] = level_degrees[l];
298 std::cout <<
"Starting hierarchy generation" << std::endl;
300 std::cout <<
"opt = " << optimize << std::endl;
306 std::cout <<
"Finished hierarchy generation in " << uref->
timeall.
tm_total <<
" secs" << std::endl;
309 std::cout <<
"Time taken for refinement " << uref->
timeall.
tm_refine <<
" secs" << std::endl;
310 std::cout <<
"Time taken for resolving shared interface " << uref->
timeall.
tm_resolve <<
" secs"
315 std::cout <<
"Finished hierarchy generation " << std::endl;
319 Range all_ents, ents[4];
322 for(
int k = 0; k < 4; k++ )
325 std::cout << std::endl;
330 std::cout <<
"Mesh size for level 0"
331 <<
" :: nverts = " << ents[0].
size() <<
", nedges = " << ents[1].
size()
332 <<
", nfaces = " << ents[2].
size() <<
", ncells = " << ents[3].
size() <<
" :: Vmax = " << volume
336 std::cout <<
"Mesh size for level 0"
337 <<
" :: nverts = " << ents[0].
size() <<
", nedges = " << ents[1].
size()
338 <<
", nfaces = " << ents[2].
size() <<
", ncells = " << ents[3].
size() << std::endl;
340 for(
int l = 0; l < num_levels; l++ )
349 for(
int k = 0; k < 4; k++ )
358 std::cout <<
"Mesh size for level " << l + 1 <<
" :: nverts = " << ents[0].
size()
359 <<
", nedges = " << ents[1].
size() <<
", nfaces = " << ents[2].
size()
360 <<
", ncells = " << ents[3].
size() <<
" :: Vmax = " << volume << std::endl;
363 std::cout <<
"Mesh size for level " << l + 1 <<
" :: nverts = " << ents[0].
size()
364 <<
", nedges = " << ents[1].
size() <<
", nfaces = " << ents[2].
size()
365 <<
", ncells = " << ents[3].
size() << std::endl;
371 for(
int l = 0; l < num_levels; l++ )
373 std::string::size_type idx1 = infile.find_last_of(
"\\/" );
374 std::string::size_type idx2 = infile.find_last_of(
"." );
375 std::string file = infile.substr( idx1 + 1, idx2 - idx1 - 1 );
376 std::stringstream out;
378 out <<
"_ML_" << l + 1 <<
".h5m";
380 out <<
"_ML_" << l + 1 <<
".vtk";
381 file = file + out.str();
382 const char* output_file = file.c_str();
416 std::vector< int >& level_degs )
422 int init_nl = num_levels;
430 double Vdesired = desired_vol;
432 double remV = vmax_global;
433 int degs[3][3] = { { 5, 3, 2 }, { 25, 9, 4 }, { 0, 27, 8 } };
435 if(
dim == 1 ||
dim == 2 )
437 while( remV - Vdesired >= 0 )
439 try_x = degs[
dim - 1][0];
440 if( ( remV / try_x - Vdesired ) >= 0 )
442 level_degs.push_back( 5 );
448 try_x = degs[
dim - 1][1];
449 if( ( remV / try_x - Vdesired ) >= 0 )
451 level_degs.push_back( 3 );
457 try_x = degs[
dim - 1][2];
458 if( ( remV / try_x - Vdesired ) >= 0 )
460 level_degs.push_back( 2 );
472 while( remV - Vdesired >= 0 )
474 try_x = degs[
dim - 1][1];
475 if( ( remV / try_x - Vdesired ) >= 0 )
477 level_degs.push_back( 3 );
483 try_x = degs[
dim - 1][2];
484 if( ( remV / try_x - Vdesired ) >= 0 )
486 level_degs.push_back( 2 );
496 if( init_nl != 0 && init_nl < num_levels )
498 for(
int i = level_degs.size(); i >= init_nl; i-- )
499 level_degs.pop_back();
500 num_levels = init_nl;
529 Range allents, owned;
536 MPI_Comm_size( MPI_COMM_WORLD, &
size );
542 Range current = owned;
553 double vmax_local = 0;
559 if( volume > vmax_local ) vmax_local = volume;
563 double vmax_global = vmax_local;
565 mpi_err = MPI_Reduce( &vmax_local, &vmax_global, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
581 char* mystr = strdup(
string );
582 for(
const char* ptr = strtok( mystr,
"," ); ptr; ptr = strtok( 0,
"," ) )
585 int val = strtol( ptr, &endptr, 0 );
587 if(
dim == 1 ||
dim == 2 )
589 if( val != 2 && val != 3 && val != 5 )
591 std::cerr <<
"Not a valid degree for the passed dimension" << std::endl;
598 if( val != 2 && val != 3 )
600 std::cerr <<
"Not a valid degree for the passed dimension" << std::endl;
606 if( endptr == ptr || val <= 0 )
608 std::cerr <<
"Not a valid id: " << ptr << std::endl;
613 results.push_back( val );
616 if( (
int)results.size() < nval )
618 for(
int i = results.size(); i <= nval - 1; i++ )
619 results.push_back( results[0] );
621 else if( (
int)results.size() > nval )
623 for(
int i = results.size(); i > nval; i-- )
634 if( options.empty() )
return true;
637 std::vector< std::string >::const_iterator i;
638 char separator =
'\0';
639 const char* alt_separators =
";+,:\t\n";
640 for(
const char* sep_ptr = alt_separators; *sep_ptr; ++sep_ptr )
643 for( i = options.begin(); i != options.end(); ++i )
644 if( i->find( *sep_ptr, 0 ) != std::string::npos )
651 separator = *sep_ptr;
657 std::cerr <<
"Error: cannot find separator character for options string" << std::endl;
660 if( separator !=
';' )
669 for( ++i; i != options.end(); ++i )