81 ErrorCode add_set_no(
int m_or_s,
int fluid_or_solid,
int set_no );
84 ErrorCode remove_set_no(
int m_or_s,
int fluid_or_solid,
int set_no );
87 ErrorCode get_set_nos(
int m_or_s,
int fluid_or_solid, set< int >& set_nos )
const;
108 string get_file_name(
int m_or_s )
const;
111 void set_file_name(
int m_or_s,
const string& name );
114 string xdisp_name(
int idx = 0 );
115 void xdisp_name(
const string& nm,
int idx = 0 );
134 const char* filename,
135 bool restore_coords =
false );
149 set< int > fluidSetNos[2];
152 set< int > solidSetNos[2];
173 string xDispNames[3];
182 set< int >* this_set;
183 assert( ( m_or_s == MASTER || m_or_s == SLAVE ) &&
"m_or_s should be MASTER or SLAVE." );
189 this_set = &fluidSetNos[m_or_s];
192 this_set = &solidSetNos[m_or_s];
195 assert(
false &&
"f_or_s should be FLUID or SOLID." );
199 this_set->insert( set_no );
207 set< int >* this_set;
208 assert( ( m_or_s == MASTER || m_or_s == SLAVE ) &&
"m_or_s should be MASTER or SLAVE." );
213 this_set = &fluidSetNos[m_or_s];
216 this_set = &solidSetNos[m_or_s];
219 assert(
false &&
"f_or_s should be FLUID or SOLID." );
222 set< int >::iterator sit = this_set->find( set_no );
223 if( sit != this_set->end() )
225 this_set->erase( *sit );
235 const set< int >* this_set;
236 assert( ( m_or_s == MASTER || m_or_s == SLAVE ) &&
"m_or_s should be MASTER or SLAVE." );
241 this_set = &fluidSetNos[m_or_s];
244 this_set = &solidSetNos[m_or_s];
247 assert(
false &&
"f_or_s should be FLUID or SOLID." );
258 return xDispNames[idx];
263 xDispNames[idx] = nm;
271 if( solidSetNos[MASTER].empty() || fluidSetNos[MASTER].empty() )
273 MB_CHK_SET_ERR( find_other_sets( MASTER, masterSet ),
"Failed to find other sets in master mesh" );
276 bool have_slave = !( slaveFileName ==
"none" );
281 if( solidSetNos[SLAVE].empty() || fluidSetNos[SLAVE].empty() )
283 MB_CHK_SET_ERR( find_other_sets( SLAVE, slaveSet ),
"Failed to find other sets in slave mesh" );
287 if(
debug ) cout <<
"Constructing data coupler/search tree on master mesh..." << endl;
289 Range src_elems = solidElems[MASTER];
290 src_elems.
merge( fluidElems[MASTER] );
293 DataCoupler dc_master( mbImpl, src_elems, 0, NULL );
300 Range tmp_range = solidElems[SLAVE];
301 tmp_range.
merge( fluidElems[SLAVE] );
303 "Failed to get target verts" );
306 if(
debug ) cout <<
"Locating slave vertices in master mesh..." << endl;
309 if( num_located != (
int)tgt_verts.
size() )
312 cout <<
"Only " << num_located <<
" out of " << tgt_verts.
size() <<
" target points successfully located."
319 if(
debug ) cout <<
"Deforming fluid elements in master mesh..." << endl;
331 cout <<
"Writing skin_mesh.g and fluid_mesh.g." << endl;
333 MB_CHK_SET_ERR( mbImpl->add_entities( skin_set, skin ),
"Failed to add skin entities to set" );
334 MB_CHK_SET_ERR( mbImpl->write_file(
"skin_mesh.vtk", NULL, NULL, &skin_set, 1 ),
335 "Failure to write skin set" );
336 MB_CHK_SET_ERR( mbImpl->remove_entities( skin_set, skin ),
"Failed to remove skin entities from set" );
337 MB_CHK_SET_ERR( mbImpl->add_entities( skin_set, fluidElems[MASTER] ),
338 "Failed to add fluid entities to set" );
339 MB_CHK_SET_ERR( mbImpl->write_file(
"fluid_mesh.vtk", NULL, NULL, &skin_set, 1 ),
340 "Failure to write fluid set" );
341 MB_CHK_SET_ERR( mbImpl->delete_entities( &skin_set, 1 ),
"Failed to delete skin set" );
345 if(
debug ) cout <<
"Smoothing fluid elements in master mesh..." << endl;
348 cout <<
"Lloyd smoothing required " << ll.
num_its() <<
" iterations." << endl;
352 if(
debug ) cout <<
"Transferring coords tag to vertex coordinates in master mesh..." << endl;
360 if(
debug ) cout <<
"Interpolating new coordinates to slave vertices..." << endl;
362 "Failed to interpolate target solution" );
364 if(
debug ) cout <<
"Transferring coords tag to vertex coordinates in slave mesh..." << endl;
372 if( pcMaster && pcMaster->size() > 1 ) str =
"PARALLEL=WRITE_PART";
374 if(
debug ) cout <<
"Writing smoothed_master.h5m..." << endl;
375 MB_CHK_ERR( mbImpl->write_file(
"smoothed_master.h5m", NULL, str.c_str(), &masterSet, 1 ) );
381 if( pcSlave && pcSlave->size() > 1 ) str =
"PARALLEL=WRITE_PART";
383 if(
debug ) cout <<
"Writing slave_interp.h5m..." << endl;
384 MB_CHK_ERR( mbImpl->write_file(
"slave_interp.h5m", NULL, str.c_str(), &slaveSet, 1 ) );
398 return masterFileName;
400 return slaveFileName;
402 assert(
false &&
"m_or_s should be MASTER or SLAVE." );
412 masterFileName = name;
415 slaveFileName = name;
418 assert(
false &&
"m_or_s should be MASTER or SLAVE." );
423 : mbImpl( impl ), pcMaster( master ), pcSlave( slave ), masterSet( 0 ), slaveSet( 0 ), xNew( 0 ), xNewName(
"xnew" )
427 if( !pcSlave && pcMaster ) pcSlave = pcMaster;
432 int main(
int argc,
char** argv )
437 po.
addOpt<
string >(
"master,m",
"Specify the master meshfile name" );
438 po.
addOpt<
string >(
"worker,w",
"Specify the slave/worker meshfile name, or 'none' (no quotes) if master only" );
439 po.
addOpt<
string >(
"d1,",
"Tag name for displacement x or xyz" );
440 po.
addOpt<
string >(
"d2,",
"Tag name for displacement y" );
441 po.
addOpt<
string >(
"d3,",
"Tag name for displacement z" );
442 po.
addOpt<
int >(
"fm,",
"Specify master fluid material set number(s). If none specified, "
443 "fluid sets derived from complement of solid sets." );
444 po.
addOpt<
int >(
"fs,",
"Specify master solid material set number(s). If none specified, "
445 "solid sets derived from complement of fluid sets." );
446 po.
addOpt<
int >(
"sm,",
"Specify slave fluid material set number(s). If none specified, fluid "
447 "sets derived from complement of solid sets." );
448 po.
addOpt<
int >(
"ss,",
"Specify slave solid material set number(s). If none specified, solid "
449 "sets derived from complement of fluid sets." );
463 string masterf, slavef;
464 if( !po.
getOpt(
"master", &masterf ) ) masterf = string(
MESH_DIR ) + string(
"/rodquad.g" );
467 if( !po.
getOpt(
"worker", &slavef ) ) slavef = string(
MESH_DIR ) + string(
"/rodtri.g" );
471 cerr <<
"Empty slave file name; if no slave, use filename 'none' (no quotes)." << endl;
475 vector< int > set_nos;
477 for( vector< int >::iterator vit = set_nos.begin(); vit != set_nos.end(); ++vit )
482 for( vector< int >::iterator vit = set_nos.begin(); vit != set_nos.end(); ++vit )
487 for( vector< int >::iterator vit = set_nos.begin(); vit != set_nos.end(); ++vit )
491 for( vector< int >::iterator vit = set_nos.begin(); vit != set_nos.end(); ++vit )
495 po.
getOpt(
"d1", &tnames[0] );
496 po.
getOpt(
"d2", &tnames[1] );
497 po.
getOpt(
"d3", &tnames[2] );
498 for(
int i = 0; i < 3; i++ )
499 if( !tnames[i].empty() ) dfr->
xdisp_name( tnames[i], i );
512 const char* filename,
513 bool restore_coords )
538 vector< double > coords( 3 * verts.
size() );
575 "Failed to get vertices" );
578 vector< double > coords( 3 * solid_verts.
size() );
580 unsigned int num_verts = solid_verts.
size();
588 "Failed to create xnew tag" );
589 vector< double > disps( num_verts );
590 for(
int i = 0; i < 3; i++ )
593 "Failed to get xDisp tag" );
595 "Failed to get xDisp tag values" );
596 for(
unsigned int j = 0; j < num_verts; j++ )
597 new_coords[3 * j + i] = coords[3 * j + i] + disps[j];
603 "Failed to get first xDisp tag" );
605 vector< double > disps( 3 * num_verts );
607 for(
unsigned int j = 0; j < 3 * num_verts; j++ )
608 new_coords[j] = coords[j] + disps[j];
616 for(
unsigned int j = 0; j < num_verts; j++ )
617 deform_func( bbox, &coords[3 * j], &new_coords[3 * j] );
623 for(
unsigned int i = 0; i < num_verts; i++ )
627 if( tmp_len > len ) len = tmp_len;
629 Range tmp_elems( fluid_elems );
630 tmp_elems.
merge( solid_elems );
636 cout <<
"Max displacement = " << len <<
" (" << 100.0 * len / max_len <<
"% of max box length)" << endl;
643 "Failed to get xNew tag" );
652 "Failed to get vertices" );
653 fluid_verts =
subtract( fluid_verts, solid_verts );
655 if( coords.size() < 3 * fluid_verts.size() ) coords.resize( 3 * fluid_verts.size() );
674 ostringstream options;
677 if( pc && pc->
size() > 1 )
679 if(
debug ) options <<
"DEBUG_IO=1;CPUTIME;";
680 options <<
"PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;"
681 <<
"PARALLEL_GHOSTS=2.0.1;PARALLEL_COMM=" << pc->
get_id();
685 "Couldn't load master/slave mesh" );
696 const void* setno_ptr = &set_no;
700 MB_SET_ERR( MB_FAILURE,
"Couldn't find solid set #" << *sit );
712 if( !tmp_range.
empty() )
715 assert( dim > 0 && dim < 4 );
721 <<
" sets in " << ( m_or_s ==
MASTER ?
"master" :
"slave" ) <<
" mesh." << endl;
727 const void* setno_ptr = &set_no;
731 MB_SET_ERR( MB_FAILURE,
"Couldn't find fluid set #" << *sit );
743 if( !tmp_range.
empty() )
746 assert( dim > 0 && dim < 4 );
752 <<
" sets in " << ( m_or_s ==
MASTER ?
"master" :
"slave" ) <<
" mesh." << endl;
760 Range *filled_sets = NULL, *unfilled_sets = NULL, *unfilled_elems = NULL;
768 cout <<
"Finding unspecified fluid elements in " << ( m_or_s ==
MASTER ?
"master" :
"slave" ) <<
" mesh...";
776 cout <<
"Finding unspecified solid elements in " << ( m_or_s ==
MASTER ?
"master" :
"slave" ) <<
" mesh...";
786 MB_SET_ERR( MB_FAILURE,
"Couldn't get any material sets" );
788 *unfilled_sets =
subtract( matsets, *filled_sets );
789 if( unfilled_sets->empty() )
791 MB_SET_ERR( MB_FAILURE,
"Failed to find any unfilled material sets" );
794 for(
Range::iterator rit = unfilled_sets->begin(); rit != unfilled_sets->end(); ++rit )
797 "Failed to get entities in unfilled set" );
800 assert( dim > 0 && dim < 4 );
802 if( unfilled_elems->empty() )
804 MB_SET_ERR( MB_FAILURE,
"Failed to find any unfilled set entities" );
808 cout <<
"found " << unfilled_sets->size() <<
" sets and " << unfilled_elems->size() <<
" elements." << endl;