Example #1
0
void generate_random_points( Interface& mb, size_t num_points,
                             std::vector<CartVect>& points,
                             std::vector<EntityHandle>& point_elems )
{
  Range elems;
  ErrorCode rval;
  rval = mb.get_entities_by_dimension( 0, 3, elems );
  CHK(rval);
  if (!elems.all_of_type(MBHEX)) {
    std::cerr << "Warning: ignoring non-hexahedral elements." << std::endl;
    std::pair< Range::iterator, Range::iterator > p = elems.equal_range(MBHEX);
    elems.erase( p.second, elems.end() );
    elems.erase( elems.begin(), p.first );
  }
  if (elems.empty()) {
    std::cerr << "Input file contains no hexahedral elements." << std::endl;
    exit(1);
  }
  
  points.resize( num_points );
  point_elems.resize( num_points );
  const size_t num_elem = elems.size();
  for (size_t i = 0; i < num_points; ++i) {
    size_t offset = 0;
    for (size_t x = num_elem; x > 0; x /= RAND_MAX)
      offset += rand();
    offset %= num_elem;
    point_elems[i] = elems[offset];
    points[i] = random_point_in_hex( mb, point_elems[i] );
  }
}
Example #2
0
void recursive_check_tree( int max_depth,
                           Interface& mb,
                           Tag tag,
                           EntityHandle p,
                           int depth,
                           int& idx )
{
  int id;
  ErrorCode rval = mb.tag_get_data( tag, &p, 1, &id); CHECK_ERR(rval);
  CHECK_EQUAL( idx, id );
  
  Range verts;
  double coords[6][3];
  int num_vtx = coords_by_idx( idx, coords );
  rval = mb.get_entities_by_handle( p, verts );
  CHECK( verts.all_of_type( MBVERTEX ) );
  CHECK_EQUAL( num_vtx, (int)verts.size() );
  double coords2[6][3];
  rval = mb.get_coords( verts, &coords2[0][0] );
  std::vector<bool> match(6,true);
  for (int i = 0; i < num_vtx; ++i) {
    match[i] = false;
    for (int j = 0; j < num_vtx; ++j) {
      if (!match[j]) {
        double d[3] = { coords[i][0] - coords2[j][0],
                        coords[i][1] - coords2[j][1],
                        coords[i][2] - coords2[j][2] };
        double ds = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
        if (ds < 1e-12) {
          match[j] = true;
          break;
        }
      }
    }
  }
  CHECK( match[0] );
  CHECK( match[1] );
  CHECK( match[2] );
  CHECK( match[3] );
  CHECK( match[4] );
  CHECK( match[5] );
 
  ++idx;
  
  std::vector<EntityHandle> children, parents;

  rval = mb.get_child_meshsets( p, children ); CHECK_ERR(rval);
  if (depth == max_depth) {
    CHECK_EQUAL( (size_t)0, children.size() );
    return;
  }
  
  CHECK_EQUAL( (size_t)2, children.size() );
  EntityHandle l = children.front();
  EntityHandle r = children.back();
  
  parents.clear();
  rval = mb.get_parent_meshsets( l, parents ); CHECK_ERR(rval);
  CHECK_EQUAL( (size_t)1, parents.size() );
  CHECK_EQUAL( p, parents.front() );
  parents.clear();
  rval = mb.get_parent_meshsets( r, parents ); CHECK_ERR(rval);
  CHECK_EQUAL( (size_t)1, parents.size() );
  CHECK_EQUAL( p, parents.front() );
  
  recursive_check_tree( max_depth, mb, tag, l, depth+1, idx );
  recursive_check_tree( max_depth, mb, tag, r, depth+1, idx );
}