Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
DeformMeshRemap Class Reference
+ Collaboration diagram for DeformMeshRemap:

Public Types

enum  { MASTER = 0 , SLAVE , SOLID , FLUID }
 Enumerator for solid/fluid, master/slave. More...
 

Public Member Functions

 DeformMeshRemap (Interface *impl, ParallelComm *master=NULL, ParallelComm *slave=NULL)
 Constructor If master is NULL, the MOAB part is run in serial; If slave is NULL but the master isn't, the slave is copied from the master Create communicators using moab::ParallelComm::get_pcomm. More...
 
 ~DeformMeshRemap ()
 Destructor. More...
 
ErrorCode execute ()
 Execute the deformed mesh process. More...
 
ErrorCode add_set_no (int m_or_s, int fluid_or_solid, int set_no)
 Add a set number. More...
 
ErrorCode remove_set_no (int m_or_s, int fluid_or_solid, int set_no)
 Remove a set number. More...
 
ErrorCode get_set_nos (int m_or_s, int fluid_or_solid, set< int > &set_nos) const
 Get the set numbers. More...
 
Tag x_new () const
 Get the xNew tag handle. More...
 
string x_new_name () const
 Get the tag name. More...
 
void x_new_name (const string &name)
 Set the tag name. More...
 
string get_file_name (int m_or_s) const
 Get/set the file name. More...
 
void set_file_name (int m_or_s, const string &name)
 Get/set the file name. More...
 
string xdisp_name (int idx=0)
 Get/set the x displacement tag names. More...
 
void xdisp_name (const string &nm, int idx=0)
 

Private Member Functions

ErrorCode deform_master (Range &fluid_elems, Range &solid_elems, const char *tag_name=NULL)
 Apply a known deformation to the solid elements, putting the results in the xNew tag; also write current coordinates to the xNew tag for fluid elements. More...
 
ErrorCode read_file (int m_or_s, string &fname, EntityHandle &seth)
 Read a file and establish proper ranges. More...
 
ErrorCode write_to_coords (Range &elems, Tag tagh, Tag tmp_tag=0)
 Write the input tag to the coordinates for the vertices in the input elems If non-zero tmp_tag is input, save coords to tmp_tag before over-writing with tag value. More...
 
ErrorCode write_and_save (Range &ents, EntityHandle seth, Tag tagh, const char *filename, bool restore_coords=false)
 Write the tag to the vertices, then save to the specified file If restore_coords is true, coords are restored to their initial state after file is written. More...
 
ErrorCode find_other_sets (int m_or_s, EntityHandle file_set)
 Find fluid/solid sets from complement of solid/fluid sets. More...
 

Private Attributes

InterfacembImpl
 moab interface More...
 
set< int > fluidSetNos [2]
 Material set numbers for fluid materials, for master/slave. More...
 
set< int > solidSetNos [2]
 Material set numbers for solid materials, for master/slave. More...
 
EntityHandle masterSet
 Sets defining master/slave meshes. More...
 
EntityHandle slaveSet
 
Range fluidSets [2]
 Sets in master/slave meshes. More...
 
Range solidSets [2]
 
Range fluidElems [2]
 Elements in master/slave meshes. More...
 
Range solidElems [2]
 
string masterFileName
 Filenames for master/slave meshes. More...
 
string slaveFileName
 
Tag xDisp [3]
 Tag from file, might be 3. More...
 
Tag xNew
 Tag used for new positions. More...
 
string xDispNames [3]
 Tag name used to read disps from file. More...
 
string xNewName
 Tag name used for new positions. More...
 

Detailed Description

Examples
DeformMeshRemap.cpp.

Definition at line 56 of file DeformMeshRemap.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Enumerator for solid/fluid, master/slave.

Enumerator
MASTER 
SLAVE 
SOLID 
FLUID 

Definition at line 60 of file DeformMeshRemap.cpp.

61  {
62  MASTER = 0,
63  SLAVE,
64  SOLID,
65  FLUID
66  };

Constructor & Destructor Documentation

◆ DeformMeshRemap()

DeformMeshRemap::DeformMeshRemap ( Interface impl,
ParallelComm master = NULL,
ParallelComm slave = NULL 
)

Constructor If master is NULL, the MOAB part is run in serial; If slave is NULL but the master isn't, the slave is copied from the master Create communicators using moab::ParallelComm::get_pcomm.

Examples
DeformMeshRemap.cpp.

Definition at line 417 of file DeformMeshRemap.cpp.

418  : mbImpl( impl ), pcMaster( master ), pcSlave( slave ), masterSet( 0 ), slaveSet( 0 ), xNew( 0 ), xNewName( "xnew" )
419 {
420  xDisp[0] = xDisp[1] = xDisp[2] = 0;
421 
422  if( !pcSlave && pcMaster ) pcSlave = pcMaster;
423 }

References xDisp.

◆ ~DeformMeshRemap()

DeformMeshRemap::~DeformMeshRemap ( )

Destructor.

Examples
DeformMeshRemap.cpp.

Definition at line 425 of file DeformMeshRemap.cpp.

425 {}

Member Function Documentation

◆ add_set_no()

ErrorCode DeformMeshRemap::add_set_no ( int  m_or_s,
int  fluid_or_solid,
int  set_no 
)
inline

Add a set number.

Examples
DeformMeshRemap.cpp.

Definition at line 180 of file DeformMeshRemap.cpp.

181 {
182  set< int >* this_set;
183  assert( ( m_or_s == MASTER || m_or_s == SLAVE ) && "m_or_s should be MASTER or SLAVE." );
184  if( m_or_s != MASTER && m_or_s != SLAVE ) return MB_INDEX_OUT_OF_RANGE;
185 
186  switch( f_or_s )
187  {
188  case FLUID:
189  this_set = &fluidSetNos[m_or_s];
190  break;
191  case SOLID:
192  this_set = &solidSetNos[m_or_s];
193  break;
194  default:
195  assert( false && "f_or_s should be FLUID or SOLID." );
196  return MB_FAILURE;
197  }
198 
199  this_set->insert( set_no );
200 
201  return MB_SUCCESS;
202 }

References MB_INDEX_OUT_OF_RANGE, MB_SUCCESS, and SOLID.

Referenced by main().

◆ deform_master()

ErrorCode DeformMeshRemap::deform_master ( Range fluid_elems,
Range solid_elems,
const char *  tag_name = NULL 
)
private

Apply a known deformation to the solid elements, putting the results in the xNew tag; also write current coordinates to the xNew tag for fluid elements.

Examples
DeformMeshRemap.cpp.

Definition at line 563 of file DeformMeshRemap.cpp.

564 {
565  // Deform elements with an analytic function
566  ErrorCode rval;
567 
568  // Get all the vertices and coords in the solid
569  Range solid_verts, fluid_verts;
570  rval = mbImpl->get_adjacencies( solid_elems, 0, false, solid_verts, Interface::UNION );MB_CHK_SET_ERR( rval, "Failed to get vertices" );
571  vector< double > coords( 3 * solid_verts.size() ), new_coords( 3 * solid_verts.size() );
572  rval = mbImpl->get_coords( solid_verts, &coords[0] );MB_CHK_SET_ERR( rval, "Failed to get vertex coords" );
573  unsigned int num_verts = solid_verts.size();
574 
575  // Get or create the tag
576  if( !xDispNames[0].empty() && !xDispNames[1].empty() && !xDispNames[2].empty() )
577  {
578  // 3 tags, specifying xyz individual data, integrate into one tag
579  rval = mbImpl->tag_get_handle( ( tag_name ? tag_name : "" ), 3, MB_TYPE_DOUBLE, xNew,
580  MB_TAG_CREAT | MB_TAG_DENSE );MB_CHK_SET_ERR( rval, "Failed to create xnew tag" );
581  vector< double > disps( num_verts );
582  for( int i = 0; i < 3; i++ )
583  {
584  rval = mbImpl->tag_get_handle( xDispNames[0].c_str(), 1, MB_TYPE_DOUBLE, xDisp[i] );MB_CHK_SET_ERR( rval, "Failed to get xDisp tag" );
585  rval = mbImpl->tag_get_data( xDisp[i], solid_verts, &disps[0] );MB_CHK_SET_ERR( rval, "Failed to get xDisp tag values" );
586  for( unsigned int j = 0; j < num_verts; j++ )
587  new_coords[3 * j + i] = coords[3 * j + i] + disps[j];
588  }
589  }
590  else if( !xDispNames[0].empty() )
591  {
592  rval = mbImpl->tag_get_handle( xDispNames[0].c_str(), 3, MB_TYPE_DOUBLE, xDisp[0] );MB_CHK_SET_ERR( rval, "Failed to get first xDisp tag" );
593  xNew = xDisp[0];
594  vector< double > disps( 3 * num_verts );
595  rval = mbImpl->tag_get_data( xDisp[0], solid_verts, &disps[0] );
596  for( unsigned int j = 0; j < 3 * num_verts; j++ )
597  new_coords[j] = coords[j] + disps[j];
598  }
599  else
600  {
601  // Get the bounding box of the solid mesh
602  BoundBox bbox;
603  bbox.update( *mbImpl, solid_elems );
604 
605  for( unsigned int j = 0; j < num_verts; j++ )
606  deform_func( bbox, &coords[3 * j], &new_coords[3 * j] );
607  }
608 
609  if( debug )
610  {
611  double len = 0.0;
612  for( unsigned int i = 0; i < num_verts; i++ )
613  {
614  CartVect dx = CartVect( &new_coords[3 * i] ) - CartVect( &coords[3 * i] );
615  double tmp_len = dx.length_squared();
616  if( tmp_len > len ) len = tmp_len;
617  }
618  Range tmp_elems( fluid_elems );
619  tmp_elems.merge( solid_elems );
620  BoundBox box;
621  box.update( *mbImpl, tmp_elems );
622  double max_len =
623  std::max( box.bMax[2] - box.bMin[2], std::max( box.bMax[1] - box.bMin[1], box.bMax[0] - box.bMin[0] ) );
624 
625  cout << "Max displacement = " << len << " (" << 100.0 * len / max_len << "% of max box length)" << endl;
626  }
627 
628  if( !xNew )
629  {
630  rval = mbImpl->tag_get_handle( ( tag_name ? tag_name : "" ), 3, MB_TYPE_DOUBLE, xDisp[0],
631  MB_TAG_CREAT | MB_TAG_DENSE );MB_CHK_SET_ERR( rval, "Failed to get xNew tag" );
632  xNew = xDisp[0];
633  }
634 
635  // Set the new tag to those coords
636  rval = mbImpl->tag_set_data( xNew, solid_verts, &new_coords[0] );MB_CHK_SET_ERR( rval, "Failed to set tag data" );
637 
638  // Get all the vertices and coords in the fluid, set xnew to them
639  rval = mbImpl->get_adjacencies( fluid_elems, 0, false, fluid_verts, Interface::UNION );MB_CHK_SET_ERR( rval, "Failed to get vertices" );
640  fluid_verts = subtract( fluid_verts, solid_verts );
641 
642  if( coords.size() < 3 * fluid_verts.size() ) coords.resize( 3 * fluid_verts.size() );
643  rval = mbImpl->get_coords( fluid_verts, &coords[0] );MB_CHK_SET_ERR( rval, "Failed to get vertex coords" );
644  rval = mbImpl->tag_set_data( xNew, fluid_verts, &coords[0] );MB_CHK_SET_ERR( rval, "Failed to set xnew tag on fluid verts" );
645 
646  if( debug )
647  {
648  // Save deformed mesh coords to new file for visualizing
649  Range tmp_range( fluidElems[MASTER] );
650  tmp_range.merge( solidElems[MASTER] );
651  rval = write_and_save( tmp_range, masterSet, xNew, "deformed_master.h5m", true );MB_CHK_ERR( rval );
652  }
653 
654  return MB_SUCCESS;
655 }

References moab::BoundBox::bMax, moab::BoundBox::bMin, debug, deform_func(), ErrorCode, fluidElems, moab::Interface::get_adjacencies(), moab::Interface::get_coords(), moab::CartVect::length_squared(), MASTER, masterSet, MB_CHK_ERR, MB_CHK_SET_ERR, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_DOUBLE, mbImpl, moab::Range::merge(), moab::Range::size(), solidElems, moab::subtract(), moab::Interface::tag_get_data(), moab::Interface::tag_get_handle(), moab::Interface::tag_set_data(), moab::BoundBox::update(), write_and_save(), xDisp, xDispNames, and xNew.

◆ execute()

ErrorCode DeformMeshRemap::execute ( )

Execute the deformed mesh process.

Examples
DeformMeshRemap.cpp.

Definition at line 266 of file DeformMeshRemap.cpp.

267 {
268  // Read master/slave files and get fluid/solid material sets
270 
271  if( solidSetNos[MASTER].empty() || fluidSetNos[MASTER].empty() )
272  {
273  rval = find_other_sets( MASTER, masterSet );MB_CHK_SET_ERR( rval, "Failed to find other sets in master mesh" );
274  }
275 
276  bool have_slave = !( slaveFileName == "none" );
277  if( have_slave )
278  {
279  rval = read_file( SLAVE, slaveFileName, slaveSet );MB_CHK_ERR( rval );
280 
281  if( solidSetNos[SLAVE].empty() || fluidSetNos[SLAVE].empty() )
282  {
283  rval = find_other_sets( SLAVE, slaveSet );MB_CHK_SET_ERR( rval, "Failed to find other sets in slave mesh" );
284  }
285  }
286 
287  if( debug ) cout << "Constructing data coupler/search tree on master mesh..." << endl;
288 
289  Range src_elems = solidElems[MASTER];
290  src_elems.merge( fluidElems[MASTER] );
291 
292  // Initialize data coupler on source elements
293  DataCoupler dc_master( mbImpl, src_elems, 0, NULL );
294 
295  Range tgt_verts;
296  if( have_slave )
297  {
298  // Locate slave vertices in master, orig coords; do this with a data coupler, so you can
299  // later interpolate
300  Range tmp_range = solidElems[SLAVE];
301  tmp_range.merge( fluidElems[SLAVE] );
302  rval = mbImpl->get_adjacencies( tmp_range, 0, false, tgt_verts, Interface::UNION );MB_CHK_SET_ERR( rval, "Failed to get target verts" );
303 
304  // Locate slave vertices, caching results in dc
305  if( debug ) cout << "Locating slave vertices in master mesh..." << endl;
306  rval = dc_master.locate_points( tgt_verts );MB_CHK_SET_ERR( rval, "Point location of tgt verts failed" );
307  int num_located = dc_master.spatial_locator()->local_num_located();
308  if( num_located != (int)tgt_verts.size() )
309  {
310  rval = MB_FAILURE;
311  cout << "Only " << num_located << " out of " << tgt_verts.size() << " target points successfully located."
312  << endl;
313  return rval;
314  }
315  }
316 
317  // Deform the master's solid mesh, put results in a new tag
318  if( debug ) cout << "Deforming fluid elements in master mesh..." << endl;
319  rval = deform_master( fluidElems[MASTER], solidElems[MASTER], "xnew" );MB_CHK_ERR( rval );
320 
321  { // To isolate the lloyd smoother & delete when done
322  if( debug )
323  {
324  // Output the skin of smoothed elems, as a check
325  // Get the skin; get facets, because we might need to filter on shared entities
326  Skinner skinner( mbImpl );
327  Range skin;
328  rval = skinner.find_skin( 0, fluidElems[MASTER], false, skin );MB_CHK_SET_ERR( rval, "Unable to find skin" );
329  EntityHandle skin_set;
330  cout << "Writing skin_mesh.g and fluid_mesh.g." << endl;
331  rval = mbImpl->create_meshset( MESHSET_SET, skin_set );MB_CHK_SET_ERR( rval, "Failed to create skin set" );
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" );
338  }
339 
340  // Smooth the master mesh
341  if( debug ) cout << "Smoothing fluid elements in master mesh..." << endl;
342  LloydSmoother ll( mbImpl, NULL, fluidElems[MASTER], xNew );
343  rval = ll.perform_smooth();MB_CHK_SET_ERR( rval, "Failed in lloyd smoothing" );
344  cout << "Lloyd smoothing required " << ll.num_its() << " iterations." << endl;
345  }
346 
347  // Transfer xNew to coords, for master
348  if( debug ) cout << "Transferring coords tag to vertex coordinates in master mesh..." << endl;
349  rval = write_to_coords( solidElems[MASTER], xNew );MB_CHK_SET_ERR( rval, "Failed writing tag to master fluid verts" );
350  rval = write_to_coords( fluidElems[MASTER], xNew );MB_CHK_SET_ERR( rval, "Failed writing tag to master fluid verts" );
351 
352  if( have_slave )
353  {
354  // Map new locations to slave
355  // Interpolate xNew to slave points
356  if( debug ) cout << "Interpolating new coordinates to slave vertices..." << endl;
357  rval = dc_master.interpolate( (int)DataCoupler::VOLUME, "xnew" );MB_CHK_SET_ERR( rval, "Failed to interpolate target solution" );
358  // Transfer xNew to coords, for slave
359  if( debug ) cout << "Transferring coords tag to vertex coordinates in slave mesh..." << endl;
360  rval = write_to_coords( tgt_verts, xNew );MB_CHK_SET_ERR( rval, "Failed writing tag to slave verts" );
361  }
362 
363  if( debug )
364  {
365  string str;
366 #ifdef USE_MPI
367  if( pcMaster && pcMaster->size() > 1 ) str = "PARALLEL=WRITE_PART";
368 #endif
369  if( debug ) cout << "Writing smoothed_master.h5m..." << endl;
370  rval = mbImpl->write_file( "smoothed_master.h5m", NULL, str.c_str(), &masterSet, 1 );
371 
372  if( have_slave )
373  {
374 #ifdef USE_MPI
375  str.clear();
376  if( pcSlave && pcSlave->size() > 1 ) str = "PARALLEL=WRITE_PART";
377 #endif
378  if( debug ) cout << "Writing slave_interp.h5m..." << endl;
379  rval = mbImpl->write_file( "slave_interp.h5m", NULL, str.c_str(), &slaveSet, 1 );
380  } // if have_slave
381  } // if debug
382 
383  if( debug ) dc_master.spatial_locator()->get_tree()->tree_stats().print();
384 
385  return MB_SUCCESS;
386 }

References moab::debug, deform_master(), ErrorCode, moab::Skinner::find_skin(), moab::SpatialLocator::get_tree(), moab::DataCoupler::interpolate(), moab::SpatialLocator::local_num_located(), moab::DataCoupler::locate_points(), MB_CHK_ERR, MB_CHK_SET_ERR, MB_SUCCESS, moab::Range::merge(), MESHSET_SET, moab::LloydSmoother::num_its(), moab::LloydSmoother::perform_smooth(), moab::TreeStats::print(), read_file(), moab::Range::size(), moab::DataCoupler::spatial_locator(), moab::Tree::tree_stats(), moab::Interface::UNION, moab::DataCoupler::VOLUME, and write_to_coords().

Referenced by main().

◆ find_other_sets()

ErrorCode DeformMeshRemap::find_other_sets ( int  m_or_s,
EntityHandle  file_set 
)
private

Find fluid/solid sets from complement of solid/fluid sets.

Examples
DeformMeshRemap.cpp.

Definition at line 743 of file DeformMeshRemap.cpp.

744 {
745  // Solid or fluid sets are missing; find the other
746  Range *filled_sets = NULL, *unfilled_sets = NULL, *unfilled_elems = NULL;
747 
748  if( fluidSets[m_or_s].empty() && !solidSets[m_or_s].empty() )
749  {
750  unfilled_sets = &fluidSets[m_or_s];
751  filled_sets = &solidSets[m_or_s];
752  unfilled_elems = &fluidElems[m_or_s];
753  if( debug )
754  cout << "Finding unspecified fluid elements in " << ( m_or_s == MASTER ? "master" : "slave" ) << " mesh...";
755  }
756  else if( !fluidSets[m_or_s].empty() && solidSets[m_or_s].empty() )
757  {
758  filled_sets = &fluidSets[m_or_s];
759  unfilled_sets = &solidSets[m_or_s];
760  unfilled_elems = &solidElems[m_or_s];
761  if( debug )
762  cout << "Finding unspecified solid elements in " << ( m_or_s == MASTER ? "master" : "slave" ) << " mesh...";
763  }
764 
765  // Ok, we know the filled sets, now fill the unfilled sets, and the elems from those
766  Tag tagh;
767  ErrorCode rval = mbImpl->tag_get_handle( MATERIAL_SET_TAG_NAME, tagh );MB_CHK_SET_ERR( rval, "Couldn't get material set tag name" );
768  Range matsets;
769  rval = mbImpl->get_entities_by_type_and_tag( file_set, MBENTITYSET, &tagh, NULL, 1, matsets );
770  if( MB_SUCCESS != rval || matsets.empty() )
771  {
772  MB_SET_ERR( MB_FAILURE, "Couldn't get any material sets" );
773  }
774  *unfilled_sets = subtract( matsets, *filled_sets );
775  if( unfilled_sets->empty() )
776  {
777  MB_SET_ERR( MB_FAILURE, "Failed to find any unfilled material sets" );
778  }
779  Range tmp_range;
780  for( Range::iterator rit = unfilled_sets->begin(); rit != unfilled_sets->end(); ++rit )
781  {
782  rval = mbImpl->get_entities_by_handle( *rit, tmp_range, true );MB_CHK_SET_ERR( rval, "Failed to get entities in unfilled set" );
783  }
784  int dim = mbImpl->dimension_from_handle( *tmp_range.rbegin() );
785  assert( dim > 0 && dim < 4 );
786  *unfilled_elems = tmp_range.subset_by_dimension( dim );
787  if( unfilled_elems->empty() )
788  {
789  MB_SET_ERR( MB_FAILURE, "Failed to find any unfilled set entities" );
790  }
791 
792  if( debug )
793  cout << "found " << unfilled_sets->size() << " sets and " << unfilled_elems->size() << " elements." << endl;
794 
795  return MB_SUCCESS;
796 }

References debug, dim, moab::Interface::dimension_from_handle(), moab::Range::empty(), ErrorCode, fluidElems, fluidSets, moab::Interface::get_entities_by_handle(), moab::Interface::get_entities_by_type_and_tag(), MASTER, MATERIAL_SET_TAG_NAME, MB_CHK_SET_ERR, MB_SET_ERR, MB_SUCCESS, MBENTITYSET, mbImpl, moab::Range::rbegin(), solidElems, solidSets, moab::Range::subset_by_dimension(), moab::subtract(), and moab::Interface::tag_get_handle().

◆ get_file_name()

string DeformMeshRemap::get_file_name ( int  m_or_s) const

Get/set the file name.

Examples
DeformMeshRemap.cpp.

Definition at line 388 of file DeformMeshRemap.cpp.

389 {
390  switch( m_or_s )
391  {
392  case MASTER:
393  return masterFileName;
394  case SLAVE:
395  return slaveFileName;
396  default:
397  assert( false && "m_or_s should be MASTER or SLAVE." );
398  return string();
399  }
400 }

◆ get_set_nos()

ErrorCode DeformMeshRemap::get_set_nos ( int  m_or_s,
int  fluid_or_solid,
set< int > &  set_nos 
) const
inline

Get the set numbers.

Examples
DeformMeshRemap.cpp.

Definition at line 233 of file DeformMeshRemap.cpp.

234 {
235  const set< int >* this_set;
236  assert( ( m_or_s == MASTER || m_or_s == SLAVE ) && "m_or_s should be MASTER or SLAVE." );
237  if( m_or_s != MASTER && m_or_s != SLAVE ) return MB_INDEX_OUT_OF_RANGE;
238  switch( f_or_s )
239  {
240  case FLUID:
241  this_set = &fluidSetNos[m_or_s];
242  break;
243  case SOLID:
244  this_set = &solidSetNos[m_or_s];
245  break;
246  default:
247  assert( false && "f_or_s should be FLUID or SOLID." );
248  return MB_FAILURE;
249  }
250 
251  set_nos = *this_set;
252 
253  return MB_SUCCESS;
254 }

References MB_INDEX_OUT_OF_RANGE, MB_SUCCESS, and SOLID.

◆ read_file()

ErrorCode DeformMeshRemap::read_file ( int  m_or_s,
string &  fname,
EntityHandle seth 
)
private

Read a file and establish proper ranges.

Examples
DeformMeshRemap.cpp.

Definition at line 657 of file DeformMeshRemap.cpp.

658 {
659  // Create meshset
660  ErrorCode rval = mbImpl->create_meshset( 0, seth );MB_CHK_SET_ERR( rval, "Couldn't create master/slave set" );
661  ostringstream options;
662 #ifdef USE_MPI
663  ParallelComm* pc = ( m_or_s == MASTER ? pcMaster : pcSlave );
664  if( pc && pc->size() > 1 )
665  {
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();
669  }
670 #endif
671  rval = mbImpl->load_file( fname.c_str(), &seth, options.str().c_str() );MB_CHK_SET_ERR( rval, "Couldn't load master/slave mesh" );
672 
673  if( *solidSetNos[m_or_s].begin() == -1 || *fluidSetNos[m_or_s].begin() == -1 ) return MB_SUCCESS;
674 
675  // Get material sets for solid/fluid
676  Tag tagh;
677  rval = mbImpl->tag_get_handle( MATERIAL_SET_TAG_NAME, tagh );MB_CHK_SET_ERR( rval, "Couldn't get material set tag name" );
678  for( set< int >::iterator sit = solidSetNos[m_or_s].begin(); sit != solidSetNos[m_or_s].end(); ++sit )
679  {
680  Range sets;
681  int set_no = *sit;
682  const void* setno_ptr = &set_no;
683  rval = mbImpl->get_entities_by_type_and_tag( seth, MBENTITYSET, &tagh, &setno_ptr, 1, sets );
684  if( MB_SUCCESS != rval || sets.empty() )
685  {
686  MB_SET_ERR( MB_FAILURE, "Couldn't find solid set #" << *sit );
687  }
688  else
689  solidSets[m_or_s].merge( sets );
690  }
691 
692  // Get solid entities, and dimension
693  Range tmp_range;
694  for( Range::iterator rit = solidSets[m_or_s].begin(); rit != solidSets[m_or_s].end(); ++rit )
695  {
696  rval = mbImpl->get_entities_by_handle( *rit, tmp_range, true );MB_CHK_SET_ERR( rval, "Failed to get entities in solid" );
697  }
698  if( !tmp_range.empty() )
699  {
700  int dim = mbImpl->dimension_from_handle( *tmp_range.rbegin() );
701  assert( dim > 0 && dim < 4 );
702  solidElems[m_or_s] = tmp_range.subset_by_dimension( dim );
703  }
704 
705  if( debug )
706  cout << "Read " << solidElems[m_or_s].size() << " solid elements from " << solidSets[m_or_s].size()
707  << " sets in " << ( m_or_s == MASTER ? "master" : "slave" ) << " mesh." << endl;
708 
709  for( set< int >::iterator sit = fluidSetNos[m_or_s].begin(); sit != fluidSetNos[m_or_s].end(); ++sit )
710  {
711  Range sets;
712  int set_no = *sit;
713  const void* setno_ptr = &set_no;
714  rval = mbImpl->get_entities_by_type_and_tag( seth, MBENTITYSET, &tagh, &setno_ptr, 1, sets );
715  if( MB_SUCCESS != rval || sets.empty() )
716  {
717  MB_SET_ERR( MB_FAILURE, "Couldn't find fluid set #" << *sit );
718  }
719  else
720  fluidSets[m_or_s].merge( sets );
721  }
722 
723  // Get fluid entities, and dimension
724  tmp_range.clear();
725  for( Range::iterator rit = fluidSets[m_or_s].begin(); rit != fluidSets[m_or_s].end(); ++rit )
726  {
727  rval = mbImpl->get_entities_by_handle( *rit, tmp_range, true );MB_CHK_SET_ERR( rval, "Failed to get entities in fluid" );
728  }
729  if( !tmp_range.empty() )
730  {
731  int dim = mbImpl->dimension_from_handle( *tmp_range.rbegin() );
732  assert( dim > 0 && dim < 4 );
733  fluidElems[m_or_s] = tmp_range.subset_by_dimension( dim );
734  }
735 
736  if( debug )
737  cout << "Read " << fluidElems[m_or_s].size() << " fluid elements from " << fluidSets[m_or_s].size()
738  << " sets in " << ( m_or_s == MASTER ? "master" : "slave" ) << " mesh." << endl;
739 
740  return rval;
741 }

References moab::Range::clear(), moab::Interface::create_meshset(), debug, dim, moab::Interface::dimension_from_handle(), moab::Range::empty(), moab::Range::end(), ErrorCode, fluidElems, fluidSetNos, fluidSets, moab::Interface::get_entities_by_handle(), moab::Interface::get_entities_by_type_and_tag(), moab::ParallelComm::get_id(), moab::Interface::load_file(), MASTER, MATERIAL_SET_TAG_NAME, MB_CHK_SET_ERR, MB_SET_ERR, MB_SUCCESS, MBENTITYSET, mbImpl, moab::Range::merge(), moab::Range::rbegin(), moab::Range::size(), moab::ParallelComm::size(), solidElems, solidSetNos, solidSets, moab::Range::subset_by_dimension(), and moab::Interface::tag_get_handle().

◆ remove_set_no()

ErrorCode DeformMeshRemap::remove_set_no ( int  m_or_s,
int  fluid_or_solid,
int  set_no 
)
inline

Remove a set number.

Examples
DeformMeshRemap.cpp.

Definition at line 205 of file DeformMeshRemap.cpp.

206 {
207  set< int >* this_set;
208  assert( ( m_or_s == MASTER || m_or_s == SLAVE ) && "m_or_s should be MASTER or SLAVE." );
209  if( m_or_s != MASTER && m_or_s != SLAVE ) return MB_INDEX_OUT_OF_RANGE;
210  switch( f_or_s )
211  {
212  case FLUID:
213  this_set = &fluidSetNos[m_or_s];
214  break;
215  case SOLID:
216  this_set = &solidSetNos[m_or_s];
217  break;
218  default:
219  assert( false && "f_or_s should be FLUID or SOLID." );
220  return MB_FAILURE;
221  }
222  set< int >::iterator sit = this_set->find( set_no );
223  if( sit != this_set->end() )
224  {
225  this_set->erase( *sit );
226  return MB_SUCCESS;
227  }
228 
229  return MB_FAILURE;
230 }

References MB_INDEX_OUT_OF_RANGE, MB_SUCCESS, and SOLID.

◆ set_file_name()

void DeformMeshRemap::set_file_name ( int  m_or_s,
const string &  name 
)

Get/set the file name.

Examples
DeformMeshRemap.cpp.

Definition at line 402 of file DeformMeshRemap.cpp.

403 {
404  switch( m_or_s )
405  {
406  case MASTER:
407  masterFileName = name;
408  break;
409  case SLAVE:
410  slaveFileName = name;
411  break;
412  default:
413  assert( false && "m_or_s should be MASTER or SLAVE." );
414  }
415 }

Referenced by main().

◆ write_and_save()

ErrorCode DeformMeshRemap::write_and_save ( Range ents,
EntityHandle  seth,
Tag  tagh,
const char *  filename,
bool  restore_coords = false 
)
private

Write the tag to the vertices, then save to the specified file If restore_coords is true, coords are restored to their initial state after file is written.

Examples
DeformMeshRemap.cpp.

Definition at line 504 of file DeformMeshRemap.cpp.

509 {
510  Tag tmp_tag = 0;
511  ErrorCode rval;
512  if( restore_coords ) rval = mbImpl->tag_get_handle( "", 3, MB_TYPE_DOUBLE, tmp_tag, MB_TAG_CREAT | MB_TAG_DENSE );
513 
514  rval = write_to_coords( ents, tagh, tmp_tag );MB_CHK_ERR( rval );
515  rval = mbImpl->write_file( filename, NULL, NULL, &seth, 1 );MB_CHK_ERR( rval );
516  if( restore_coords )
517  {
518  rval = write_to_coords( ents, tmp_tag );MB_CHK_ERR( rval );
519  rval = mbImpl->tag_delete( tmp_tag );MB_CHK_ERR( rval );
520  }
521 
522  return rval;
523 }

References ErrorCode, MB_CHK_ERR, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_DOUBLE, mbImpl, moab::Interface::tag_delete(), moab::Interface::tag_get_handle(), moab::Interface::write_file(), and write_to_coords().

Referenced by deform_master().

◆ write_to_coords()

ErrorCode DeformMeshRemap::write_to_coords ( Range elems,
Tag  tagh,
Tag  tmp_tag = 0 
)
private

Write the input tag to the coordinates for the vertices in the input elems If non-zero tmp_tag is input, save coords to tmp_tag before over-writing with tag value.

Examples
DeformMeshRemap.cpp.

Definition at line 525 of file DeformMeshRemap.cpp.

526 {
527  // Write the tag to coordinates
528  Range verts;
529  ErrorCode rval = mbImpl->get_adjacencies( elems, 0, false, verts, Interface::UNION );MB_CHK_SET_ERR( rval, "Failed to get adj vertices" );
530  vector< double > coords( 3 * verts.size() );
531 
532  if( tmp_tag )
533  {
534  // Save the coords to tmp_tag first
535  rval = mbImpl->get_coords( verts, &coords[0] );MB_CHK_SET_ERR( rval, "Failed to get tmp copy of coords" );
536  rval = mbImpl->tag_set_data( tmp_tag, verts, &coords[0] );MB_CHK_SET_ERR( rval, "Failed to save tmp copy of coords" );
537  }
538 
539  rval = mbImpl->tag_get_data( tagh, verts, &coords[0] );MB_CHK_SET_ERR( rval, "Failed to get tag data" );
540  rval = mbImpl->set_coords( verts, &coords[0] );MB_CHK_SET_ERR( rval, "Failed to set coordinates" );
541  return MB_SUCCESS;
542 }

References ErrorCode, moab::Interface::get_adjacencies(), moab::Interface::get_coords(), MB_CHK_SET_ERR, MB_SUCCESS, mbImpl, moab::Interface::set_coords(), moab::Range::size(), moab::Interface::tag_get_data(), and moab::Interface::tag_set_data().

Referenced by write_and_save().

◆ x_new()

Tag DeformMeshRemap::x_new ( ) const
inline

Get the xNew tag handle.

Definition at line 90 of file DeformMeshRemap.cpp.

91  {
92  return xNew;
93  }

◆ x_new_name() [1/2]

string DeformMeshRemap::x_new_name ( ) const
inline

Get the tag name.

Definition at line 96 of file DeformMeshRemap.cpp.

97  {
98  return xNewName;
99  }

◆ x_new_name() [2/2]

void DeformMeshRemap::x_new_name ( const string &  name)
inline

Set the tag name.

Definition at line 102 of file DeformMeshRemap.cpp.

103  {
104  xNewName = name;
105  }

◆ xdisp_name() [1/2]

void DeformMeshRemap::xdisp_name ( const string &  nm,
int  idx = 0 
)

Definition at line 261 of file DeformMeshRemap.cpp.

262 {
263  xDispNames[idx] = nm;
264 }

◆ xdisp_name() [2/2]

string DeformMeshRemap::xdisp_name ( int  idx = 0)
inline

Get/set the x displacement tag names.

Examples
DeformMeshRemap.cpp.

Definition at line 256 of file DeformMeshRemap.cpp.

257 {
258  return xDispNames[idx];
259 }

Referenced by main().

Member Data Documentation

◆ fluidElems

Range DeformMeshRemap::fluidElems[2]
private

Elements in master/slave meshes.

Examples
DeformMeshRemap.cpp.

Definition at line 161 of file DeformMeshRemap.cpp.

Referenced by deform_master(), find_other_sets(), and read_file().

◆ fluidSetNos

set< int > DeformMeshRemap::fluidSetNos[2]
private

Material set numbers for fluid materials, for master/slave.

Examples
DeformMeshRemap.cpp.

Definition at line 149 of file DeformMeshRemap.cpp.

Referenced by read_file().

◆ fluidSets

Range DeformMeshRemap::fluidSets[2]
private

Sets in master/slave meshes.

Examples
DeformMeshRemap.cpp.

Definition at line 158 of file DeformMeshRemap.cpp.

Referenced by find_other_sets(), and read_file().

◆ masterFileName

string DeformMeshRemap::masterFileName
private

Filenames for master/slave meshes.

Definition at line 164 of file DeformMeshRemap.cpp.

◆ masterSet

EntityHandle DeformMeshRemap::masterSet
private

Sets defining master/slave meshes.

Examples
DeformMeshRemap.cpp.

Definition at line 155 of file DeformMeshRemap.cpp.

Referenced by deform_master().

◆ mbImpl

Interface* DeformMeshRemap::mbImpl
private

moab interface

Examples
DeformMeshRemap.cpp.

Definition at line 141 of file DeformMeshRemap.cpp.

Referenced by deform_master(), find_other_sets(), read_file(), write_and_save(), and write_to_coords().

◆ slaveFileName

string DeformMeshRemap::slaveFileName
private

Definition at line 164 of file DeformMeshRemap.cpp.

◆ slaveSet

EntityHandle DeformMeshRemap::slaveSet
private

Definition at line 155 of file DeformMeshRemap.cpp.

◆ solidElems

Range DeformMeshRemap::solidElems[2]
private
Examples
DeformMeshRemap.cpp.

Definition at line 161 of file DeformMeshRemap.cpp.

Referenced by deform_master(), find_other_sets(), and read_file().

◆ solidSetNos

set< int > DeformMeshRemap::solidSetNos[2]
private

Material set numbers for solid materials, for master/slave.

Examples
DeformMeshRemap.cpp.

Definition at line 152 of file DeformMeshRemap.cpp.

Referenced by read_file().

◆ solidSets

Range DeformMeshRemap::solidSets[2]
private
Examples
DeformMeshRemap.cpp.

Definition at line 158 of file DeformMeshRemap.cpp.

Referenced by find_other_sets(), and read_file().

◆ xDisp

Tag DeformMeshRemap::xDisp[3]
private

Tag from file, might be 3.

Examples
DeformMeshRemap.cpp.

Definition at line 167 of file DeformMeshRemap.cpp.

Referenced by deform_master(), and DeformMeshRemap().

◆ xDispNames

string DeformMeshRemap::xDispNames[3]
private

Tag name used to read disps from file.

Examples
DeformMeshRemap.cpp.

Definition at line 173 of file DeformMeshRemap.cpp.

Referenced by deform_master().

◆ xNew

Tag DeformMeshRemap::xNew
private

Tag used for new positions.

Examples
DeformMeshRemap.cpp.

Definition at line 170 of file DeformMeshRemap.cpp.

Referenced by deform_master().

◆ xNewName

string DeformMeshRemap::xNewName
private

Tag name used for new positions.

Definition at line 176 of file DeformMeshRemap.cpp.


The documentation for this class was generated from the following file: