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 rval = find_other_sets( MASTER, masterSet );
MB_CHK_SET_ERR( rval,
"Failed to find other sets in master mesh" );
276 bool have_slave = !( slaveFileName ==
"none" );
281 if( solidSetNos[SLAVE].empty() || fluidSetNos[SLAVE].empty() )
283 rval = find_other_sets( SLAVE, slaveSet );
MB_CHK_SET_ERR( rval,
"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] );
305 if(
debug ) cout <<
"Locating slave vertices in master mesh..." << endl;
308 if( num_located != (
int)tgt_verts.
size() )
311 cout <<
"Only " << num_located <<
" out of " << tgt_verts.
size() <<
" target points successfully located."
318 if(
debug ) cout <<
"Deforming fluid elements in master mesh..." << endl;
330 cout <<
"Writing skin_mesh.g and fluid_mesh.g." << endl;
332 rval = mbImpl->add_entities( skin_set, skin );
MB_CHK_SET_ERR( rval,
"Failed to add skin entities to set" );
333 rval = mbImpl->write_file(
"skin_mesh.vtk", NULL, NULL, &skin_set, 1 );
MB_CHK_SET_ERR( rval,
"Failure to write skin set" );
334 rval = mbImpl->remove_entities( skin_set, skin );
MB_CHK_SET_ERR( rval,
"Failed to remove skin entities from set" );
335 rval = mbImpl->add_entities( skin_set, fluidElems[MASTER] );
MB_CHK_SET_ERR( rval,
"Failed to add fluid entities to set" );
336 rval = mbImpl->write_file(
"fluid_mesh.vtk", NULL, NULL, &skin_set, 1 );
MB_CHK_SET_ERR( rval,
"Failure to write fluid set" );
337 rval = mbImpl->delete_entities( &skin_set, 1 );
MB_CHK_SET_ERR( rval,
"Failed to delete skin set" );
341 if(
debug ) cout <<
"Smoothing fluid elements in master mesh..." << endl;
344 cout <<
"Lloyd smoothing required " << ll.
num_its() <<
" iterations." << endl;
348 if(
debug ) cout <<
"Transferring coords tag to vertex coordinates in master mesh..." << endl;
356 if(
debug ) cout <<
"Interpolating new coordinates to slave vertices..." << endl;
359 if(
debug ) cout <<
"Transferring coords tag to vertex coordinates in slave mesh..." << endl;
367 if( pcMaster && pcMaster->size() > 1 ) str =
"PARALLEL=WRITE_PART";
369 if(
debug ) cout <<
"Writing smoothed_master.h5m..." << endl;
370 rval = mbImpl->write_file(
"smoothed_master.h5m", NULL, str.c_str(), &masterSet, 1 );
376 if( pcSlave && pcSlave->size() > 1 ) str =
"PARALLEL=WRITE_PART";
378 if(
debug ) cout <<
"Writing slave_interp.h5m..." << endl;
379 rval = mbImpl->write_file(
"slave_interp.h5m", NULL, str.c_str(), &slaveSet, 1 );
393 return masterFileName;
395 return slaveFileName;
397 assert(
false &&
"m_or_s should be MASTER or SLAVE." );
407 masterFileName = name;
410 slaveFileName = name;
413 assert(
false &&
"m_or_s should be MASTER or SLAVE." );
418 : mbImpl( impl ), pcMaster( master ), pcSlave( slave ), masterSet( 0 ), slaveSet( 0 ), xNew( 0 ), xNewName(
"xnew" )
422 if( !pcSlave && pcMaster ) pcSlave = pcMaster;
427 int main(
int argc,
char** argv )
432 po.
addOpt<
string >(
"master,m",
"Specify the master meshfile name" );
433 po.
addOpt<
string >(
"worker,w",
"Specify the slave/worker meshfile name, or 'none' (no quotes) if master only" );
434 po.
addOpt<
string >(
"d1,",
"Tag name for displacement x or xyz" );
435 po.
addOpt<
string >(
"d2,",
"Tag name for displacement y" );
436 po.
addOpt<
string >(
"d3,",
"Tag name for displacement z" );
437 po.
addOpt<
int >(
"fm,",
"Specify master fluid material set number(s). If none specified, "
438 "fluid sets derived from complement of solid sets." );
439 po.
addOpt<
int >(
"fs,",
"Specify master solid material set number(s). If none specified, "
440 "solid sets derived from complement of fluid sets." );
441 po.
addOpt<
int >(
"sm,",
"Specify slave fluid material set number(s). If none specified, fluid "
442 "sets derived from complement of solid sets." );
443 po.
addOpt<
int >(
"ss,",
"Specify slave solid material set number(s). If none specified, solid "
444 "sets derived from complement of fluid sets." );
458 string masterf, slavef;
459 if( !po.
getOpt(
"master", &masterf ) ) masterf = string(
MESH_DIR ) + string(
"/rodquad.g" );
462 if( !po.
getOpt(
"worker", &slavef ) ) slavef = string(
MESH_DIR ) + string(
"/rodtri.g" );
466 cerr <<
"Empty slave file name; if no slave, use filename 'none' (no quotes)." << endl;
470 vector< int > set_nos;
472 for( vector< int >::iterator vit = set_nos.begin(); vit != set_nos.end(); ++vit )
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 )
486 for( vector< int >::iterator vit = set_nos.begin(); vit != set_nos.end(); ++vit )
490 po.
getOpt(
"d1", &tnames[0] );
491 po.
getOpt(
"d2", &tnames[1] );
492 po.
getOpt(
"d3", &tnames[2] );
493 for(
int i = 0; i < 3; i++ )
494 if( !tnames[i].empty() ) dfr->
xdisp_name( tnames[i], i );
507 const char* filename,
508 bool restore_coords )
530 vector< double > coords( 3 * verts.
size() );
569 Range solid_verts, fluid_verts;
571 vector< double > coords( 3 * solid_verts.
size() ), new_coords( 3 * solid_verts.
size() );
573 unsigned int num_verts = solid_verts.
size();
581 vector< double > disps( num_verts );
582 for(
int i = 0; i < 3; i++ )
586 for(
unsigned int j = 0; j < num_verts; j++ )
587 new_coords[3 * j + i] = coords[3 * j + i] + disps[j];
594 vector< double > disps( 3 * num_verts );
596 for(
unsigned int j = 0; j < 3 * num_verts; j++ )
597 new_coords[j] = coords[j] + disps[j];
605 for(
unsigned int j = 0; j < num_verts; j++ )
606 deform_func( bbox, &coords[3 * j], &new_coords[3 * j] );
612 for(
unsigned int i = 0; i < num_verts; i++ )
616 if( tmp_len > len ) len = tmp_len;
618 Range tmp_elems( fluid_elems );
619 tmp_elems.
merge( solid_elems );
625 cout <<
"Max displacement = " << len <<
" (" << 100.0 * len / max_len <<
"% of max box length)" << endl;
640 fluid_verts =
subtract( fluid_verts, solid_verts );
642 if( coords.size() < 3 * fluid_verts.
size() ) coords.resize( 3 * fluid_verts.
size() );
661 ostringstream options;
664 if( pc && pc->
size() > 1 )
666 if(
debug ) options <<
"DEBUG_IO=1;CPUTIME;";
667 options <<
"PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;"
668 <<
"PARALLEL_GHOSTS=2.0.1;PARALLEL_COMM=" << pc->
get_id();
682 const void* setno_ptr = &set_no;
686 MB_SET_ERR( MB_FAILURE,
"Couldn't find solid set #" << *sit );
698 if( !tmp_range.
empty() )
701 assert(
dim > 0 &&
dim < 4 );
707 <<
" sets in " << ( m_or_s ==
MASTER ?
"master" :
"slave" ) <<
" mesh." << endl;
713 const void* setno_ptr = &set_no;
717 MB_SET_ERR( MB_FAILURE,
"Couldn't find fluid set #" << *sit );
729 if( !tmp_range.
empty() )
732 assert(
dim > 0 &&
dim < 4 );
738 <<
" sets in " << ( m_or_s ==
MASTER ?
"master" :
"slave" ) <<
" mesh." << endl;
746 Range *filled_sets = NULL, *unfilled_sets = NULL, *unfilled_elems = NULL;
754 cout <<
"Finding unspecified fluid elements in " << ( m_or_s ==
MASTER ?
"master" :
"slave" ) <<
" mesh...";
762 cout <<
"Finding unspecified solid elements in " << ( m_or_s ==
MASTER ?
"master" :
"slave" ) <<
" mesh...";
772 MB_SET_ERR( MB_FAILURE,
"Couldn't get any material sets" );
774 *unfilled_sets =
subtract( matsets, *filled_sets );
775 if( unfilled_sets->empty() )
777 MB_SET_ERR( MB_FAILURE,
"Failed to find any unfilled material sets" );
780 for(
Range::iterator rit = unfilled_sets->begin(); rit != unfilled_sets->end(); ++rit )
785 assert(
dim > 0 &&
dim < 4 );
787 if( unfilled_elems->empty() )
789 MB_SET_ERR( MB_FAILURE,
"Failed to find any unfilled set entities" );
793 cout <<
"found " << unfilled_sets->size() <<
" sets and " << unfilled_elems->size() <<
" elements." << endl;