Mesh Oriented datABase  (version 5.6.0)
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 422 of file DeformMeshRemap.cpp.

423  : mbImpl( impl ), pcMaster( master ), pcSlave( slave ), masterSet( 0 ), slaveSet( 0 ), xNew( 0 ), xNewName( "xnew" )
424 {
425  xDisp[0] = xDisp[1] = xDisp[2] = 0;
426 
427  if( !pcSlave && pcMaster ) pcSlave = pcMaster;
428 }

References xDisp.

◆ ~DeformMeshRemap()

DeformMeshRemap::~DeformMeshRemap ( )

Destructor.

Examples
DeformMeshRemap.cpp.

Definition at line 430 of file DeformMeshRemap.cpp.

430 {}

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 567 of file DeformMeshRemap.cpp.

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

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  MB_CHK_SET_ERR( find_other_sets( MASTER, masterSet ), "Failed to find other sets in master mesh" );
274  }
275 
276  bool have_slave = !( slaveFileName == "none" );
277  if( have_slave )
278  {
280 
281  if( solidSetNos[SLAVE].empty() || fluidSetNos[SLAVE].empty() )
282  {
283  MB_CHK_SET_ERR( find_other_sets( SLAVE, slaveSet ), "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  MB_CHK_SET_ERR( mbImpl->get_adjacencies( tmp_range, 0, false, tgt_verts, Interface::UNION ),
303  "Failed to get target verts" );
304 
305  // Locate slave vertices, caching results in dc
306  if( debug ) cout << "Locating slave vertices in master mesh..." << endl;
307  MB_CHK_SET_ERR( dc_master.locate_points( tgt_verts ), "Point location of tgt verts failed" );
308  int num_located = dc_master.spatial_locator()->local_num_located();
309  if( num_located != (int)tgt_verts.size() )
310  {
311  MB_CHK_ERR( MB_FAILURE );
312  cout << "Only " << num_located << " out of " << tgt_verts.size() << " target points successfully located."
313  << endl;
314  return MB_FAILURE;
315  }
316  }
317 
318  // Deform the master's solid mesh, put results in a new tag
319  if( debug ) cout << "Deforming fluid elements in master mesh..." << endl;
321 
322  { // To isolate the lloyd smoother & delete when done
323  if( debug )
324  {
325  // Output the skin of smoothed elems, as a check
326  // Get the skin; get facets, because we might need to filter on shared entities
327  Skinner skinner( mbImpl );
328  Range skin;
329  MB_CHK_SET_ERR( skinner.find_skin( 0, fluidElems[MASTER], false, skin ), "Unable to find skin" );
330  EntityHandle skin_set;
331  cout << "Writing skin_mesh.g and fluid_mesh.g." << endl;
332  MB_CHK_SET_ERR( mbImpl->create_meshset( MESHSET_SET, skin_set ), "Failed to create skin set" );
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" );
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" );
342  }
343 
344  // Smooth the master mesh
345  if( debug ) cout << "Smoothing fluid elements in master mesh..." << endl;
346  LloydSmoother ll( mbImpl, NULL, fluidElems[MASTER], xNew );
347  MB_CHK_SET_ERR( ll.perform_smooth(), "Failed in lloyd smoothing" );
348  cout << "Lloyd smoothing required " << ll.num_its() << " iterations." << endl;
349  }
350 
351  // Transfer xNew to coords, for master
352  if( debug ) cout << "Transferring coords tag to vertex coordinates in master mesh..." << endl;
353  MB_CHK_SET_ERR( write_to_coords( solidElems[MASTER], xNew ), "Failed writing tag to master fluid verts" );
354  MB_CHK_SET_ERR( write_to_coords( fluidElems[MASTER], xNew ), "Failed writing tag to master fluid verts" );
355 
356  if( have_slave )
357  {
358  // Map new locations to slave
359  // Interpolate xNew to slave points
360  if( debug ) cout << "Interpolating new coordinates to slave vertices..." << endl;
361  MB_CHK_SET_ERR( dc_master.interpolate( (int)DataCoupler::VOLUME, "xnew" ),
362  "Failed to interpolate target solution" );
363  // Transfer xNew to coords, for slave
364  if( debug ) cout << "Transferring coords tag to vertex coordinates in slave mesh..." << endl;
365  MB_CHK_SET_ERR( write_to_coords( tgt_verts, xNew ), "Failed writing tag to slave verts" );
366  }
367 
368  if( debug )
369  {
370  string str;
371 #ifdef USE_MPI
372  if( pcMaster && pcMaster->size() > 1 ) str = "PARALLEL=WRITE_PART";
373 #endif
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 ) );
376 
377  if( have_slave )
378  {
379 #ifdef USE_MPI
380  str.clear();
381  if( pcSlave && pcSlave->size() > 1 ) str = "PARALLEL=WRITE_PART";
382 #endif
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 ) );
385  } // if have_slave
386  } // if debug
387 
388  if( debug ) dc_master.spatial_locator()->get_tree()->tree_stats().print();
389 
390  return MB_SUCCESS;
391 }

References moab::debug, deform_master(), 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 757 of file DeformMeshRemap.cpp.

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

References debug, moab::Interface::dimension_from_handle(), moab::Range::empty(), 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 393 of file DeformMeshRemap.cpp.

394 {
395  switch( m_or_s )
396  {
397  case MASTER:
398  return masterFileName;
399  case SLAVE:
400  return slaveFileName;
401  default:
402  assert( false && "m_or_s should be MASTER or SLAVE." );
403  return string();
404  }
405 }

◆ 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 670 of file DeformMeshRemap.cpp.

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

References moab::Range::clear(), moab::Interface::create_meshset(), debug, moab::Interface::dimension_from_handle(), moab::Range::empty(), moab::Range::end(), 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 407 of file DeformMeshRemap.cpp.

408 {
409  switch( m_or_s )
410  {
411  case MASTER:
412  masterFileName = name;
413  break;
414  case SLAVE:
415  slaveFileName = name;
416  break;
417  default:
418  assert( false && "m_or_s should be MASTER or SLAVE." );
419  }
420 }

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 509 of file DeformMeshRemap.cpp.

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

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 531 of file DeformMeshRemap.cpp.

532 {
533  // Write the tag to coordinates
534  Range verts;
535  MB_CHK_SET_ERR( mbImpl->get_adjacencies( elems, 0, false, verts, Interface::UNION ), "Failed to get adj vertices" );
536 
537  // Save current coordinates
538  vector< double > coords( 3 * verts.size() );
539  MB_CHK_SET_ERR( mbImpl->get_coords( verts, &coords[0] ), "Failed to get tmp copy of coords" );
540  MB_CHK_SET_ERR( mbImpl->tag_set_data( tmp_tag, verts, &coords[0] ), "Failed to save tmp copy of coords" );
541 
542  // Get tag data and set as coordinates
543  MB_CHK_SET_ERR( mbImpl->tag_get_data( tagh, verts, &coords[0] ), "Failed to get tag data" );
544  MB_CHK_SET_ERR( mbImpl->set_coords( verts, &coords[0] ), "Failed to set coordinates" );
545  return MB_SUCCESS;
546 }

References 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: