Пример #1
0
  //Determine the global assembly box
  ErrorCode ParallelMergeMesh::GetGlobalBox(double *gbox)
  {
    ErrorCode rval;

    /*Get Bounding Box*/
    BoundBox box;
    if(mySkinEnts[0].size() != 0){
      rval = box.update(*myMB, mySkinEnts[0]);MB_CHK_ERR(rval);
    }

    //Invert the max
    box.bMax *= -1;

    /*Communicate to all processors*/
    MPI_Allreduce(&box, gbox, 6, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD);

    /*Assemble Global Bounding Box*/
    //Flip the max back
    for(int i=3; i<6; i++){
      gbox[i] *= -1;
    }
    return MB_SUCCESS;
  }
Пример #2
0
    ErrorCode BoundBox::update(Interface &iface, const Range& elems)
    {
      ErrorCode rval;
      bMin = CartVect(HUGE_VAL);
      bMax = CartVect(-HUGE_VAL);
      
      CartVect coords;
      EntityHandle const *conn, *conn2;
      int len, len2;
      Range::const_iterator i;
  
        // vertices
      const Range::const_iterator elem_begin = elems.lower_bound( MBEDGE );
      for (i = elems.begin(); i != elem_begin; ++i) {
        rval = iface.get_coords( &*i, 1, coords.array() );
        if (MB_SUCCESS != rval)
          return rval;
        update_min(coords.array());
        update_max(coords.array());
      }

        // elements with vertex-handle connectivity list
      const Range::const_iterator poly_begin = elems.lower_bound( MBPOLYHEDRON, elem_begin );
      std::vector<EntityHandle> dum_vector;
      for (i = elem_begin; i != poly_begin; ++i) {
        rval = iface.get_connectivity( *i, conn, len, true, &dum_vector);
        if (MB_SUCCESS != rval)
          return rval;

        for (int j = 0; j < len; ++j) {
          rval = iface.get_coords( conn+j, 1, coords.array() );
          if (MB_SUCCESS != rval)
            return rval;
          update_min(coords.array());
          update_max(coords.array());
        }
      }
  
        // polyhedra
      const Range::const_iterator set_begin  = elems.lower_bound( MBENTITYSET, poly_begin );
      for (i = poly_begin; i != set_begin; ++i) {
        rval = iface.get_connectivity( *i, conn, len, true );
        if (MB_SUCCESS != rval)
          return rval;

        for (int j = 0; j < len; ++j) {
          rval = iface.get_connectivity( conn[j], conn2, len2 );
          for (int k = 0; k < len2; ++k) {
            rval = iface.get_coords( conn2+k, 1, coords.array() );
            if (MB_SUCCESS != rval)
              return rval;
            update_min(coords.array());
            update_max(coords.array());
          }
        }
      }
  
        // sets
      BoundBox box;
      for (i = set_begin; i != elems.end(); ++i) {
        Range tmp_elems;
        rval = iface.get_entities_by_handle(*i, tmp_elems);
        if (MB_SUCCESS != rval) return rval;
        rval = box.update(iface, tmp_elems);
        if (MB_SUCCESS != rval) return rval;

        update(box);
      }
  
      return MB_SUCCESS;
    }
Пример #3
0
ErrorCode DeformMeshRemap::deform_master(Range &fluid_elems, Range &solid_elems, const char *tag_name) 
{
  // Deform elements with an analytic function
  ErrorCode rval;

  // Get all the vertices and coords in the solid
  Range solid_verts, fluid_verts;
  rval = mbImpl->get_adjacencies(solid_elems, 0, false, solid_verts, Interface::UNION);MB_CHK_SET_ERR(rval, "Failed to get vertices");
  vector<double> coords(3*solid_verts.size()), new_coords(3*solid_verts.size());
  rval = mbImpl->get_coords(solid_verts, &coords[0]);MB_CHK_SET_ERR(rval, "Failed to get vertex coords");
  unsigned int num_verts = solid_verts.size();

  // Get or create the tag
  if (!xDispNames[0].empty() && !xDispNames[1].empty() && !xDispNames[2].empty()) {
    // 3 tags, specifying xyz individual data, integrate into one tag
    rval = mbImpl->tag_get_handle((tag_name ? tag_name : ""), 3, MB_TYPE_DOUBLE,
        xNew, MB_TAG_CREAT | MB_TAG_DENSE);MB_CHK_SET_ERR(rval, "Failed to create xnew tag");
    vector<double> disps(num_verts);
    for (int i = 0; i < 3; i++) {
      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");
      rval = mbImpl->tag_get_data(xDisp[i], solid_verts, &disps[0]);MB_CHK_SET_ERR(rval, "Failed to get xDisp tag values");
      for (unsigned int j = 0; j < num_verts; j++)
        new_coords[3*j+i] = coords[3*j+i] + disps[j];
    }
  }
  else if (!xDispNames[0].empty()) {
    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");
    xNew = xDisp[0];
    vector<double> disps(3*num_verts);
    rval = mbImpl->tag_get_data(xDisp[0], solid_verts, &disps[0]);
    for (unsigned int j = 0; j < 3*num_verts; j++)
      new_coords[j] = coords[j] + disps[j];
  }
  else {
    // Get the bounding box of the solid mesh
    BoundBox bbox;
    bbox.update(*mbImpl, solid_elems);
  
    for (unsigned int j = 0; j < num_verts; j++)
      deform_func(bbox, &coords[3*j], &new_coords[3*j]);
  }

  if (debug) {
    double len = 0.0;
    for (unsigned int i = 0; i < num_verts; i++) {
      CartVect dx = CartVect(&new_coords[3*i]) - CartVect(&coords[3*i]);
      double tmp_len = dx.length_squared();
      if (tmp_len > len) len = tmp_len;
    }
    Range tmp_elems(fluid_elems);
    tmp_elems.merge(solid_elems);
    BoundBox box;
    box.update(*mbImpl, tmp_elems);
    double max_len = std::max(box.bMax[2] - box.bMin[2], std::max(box.bMax[1] - box.bMin[1], box.bMax[0] - box.bMin[0]));

    cout << "Max displacement = " << len << " (" << 100.0 * len / max_len << "% of max box length)" << endl;
  }

  if (!xNew) {
    rval = mbImpl->tag_get_handle((tag_name ? tag_name : ""), 3, MB_TYPE_DOUBLE, 
                                  xDisp[0], MB_TAG_CREAT|MB_TAG_DENSE);MB_CHK_SET_ERR(rval, "Failed to get xNew tag");
    xNew = xDisp[0];
  }

  // Set the new tag to those coords
  rval = mbImpl->tag_set_data(xNew, solid_verts, &new_coords[0]);MB_CHK_SET_ERR(rval, "Failed to set tag data");

  // Get all the vertices and coords in the fluid, set xnew to them
  rval = mbImpl->get_adjacencies(fluid_elems, 0, false, fluid_verts, Interface::UNION);MB_CHK_SET_ERR(rval, "Failed to get vertices");
  fluid_verts = subtract(fluid_verts, solid_verts);

  if (coords.size() < 3*fluid_verts.size()) coords.resize(3*fluid_verts.size());
  rval = mbImpl->get_coords(fluid_verts, &coords[0]);MB_CHK_SET_ERR(rval, "Failed to get vertex coords");
  rval = mbImpl->tag_set_data(xNew, fluid_verts, &coords[0]);MB_CHK_SET_ERR(rval, "Failed to set xnew tag on fluid verts");

  if (debug) {
    // Save deformed mesh coords to new file for visualizing
    Range tmp_range(fluidElems[MASTER]);
    tmp_range.merge(solidElems[MASTER]);
    rval = write_and_save(tmp_range, masterSet, xNew, "deformed_master.h5m", true);MB_CHK_ERR(rval);
  }

  return MB_SUCCESS;
}