Esempio n. 1
0
// =============================================================================
std::vector<mesh::edge_data>
mesh_tri::
compute_edge_data_() const
{
#ifdef NOSH_TEUCHOS_TIME_MONITOR
  // timer for this routine
  Teuchos::TimeMonitor tm(*compute_edge_data_time_);
#endif

  moab::Range cells = this->mbw_->get_entities_by_dimension(0, 2);

  size_t num_cells = cells.size();

  size_t num_edges = relations_.edge_vertices.size();

  std::vector<edge_data> _edge_data(num_edges);

  // compute all coordinates
  std::vector<Eigen::Vector3d> edge_coords(num_edges);
  for (size_t k = 0; k < num_edges; k++) {
    auto tmp1 = std::get<0>(relations_.edge_vertices[k]);
    std::vector<double> coords0 = this->mbw_->get_coords({tmp1});

    tmp1 = std::get<1>(relations_.edge_vertices[k]);
    std::vector<double> coords1 = this->mbw_->get_coords({tmp1});

    edge_coords[k][0] = coords0[0] - coords1[0];
    edge_coords[k][1] = coords0[1] - coords1[1];
    edge_coords[k][2] = coords0[2] - coords1[2];

    _edge_data[k].length = edge_coords[k].norm();
  }

  // Compute the contributions cell by cell.
  for (size_t k = 0; k < num_cells; k++) {
    const std::vector<size_t> edge_idxs = {
      this->local_index(relations_.cell_edges[k][0]),
      this->local_index(relations_.cell_edges[k][1]),
      this->local_index(relations_.cell_edges[k][2])
    };
    const std::vector<Eigen::Vector3d> local_edge_coords = {
      edge_coords[edge_idxs[0]],
      edge_coords[edge_idxs[1]],
      edge_coords[edge_idxs[2]]
    };

    Eigen::VectorXd edge_coeffs =
      edge_coefficients_numerically_(local_edge_coords);

    // Fill the edge coefficients into the vector.
    for (int i = 0; i < edge_coeffs.size(); i++) {
      const size_t edge_idx = this->local_index(relations_.cell_edges[k][i]);
      // const int edge_id = this->liddd
      _edge_data[edge_idx].covolume +=
        edge_coeffs[i] * _edge_data[edge_idx].length;
    }
  }

  return _edge_data;
}
Esempio n. 2
0
// find the intersection with the sphere
static vec sphere_coords(GLdouble mx, GLdouble my)
{
  GLdouble ax,ay,az;

  gluUnProject(mx,my,0,ab_glm,ab_glp,ab_glv,&ax,&ay,&az);
  vec m = vec((float)ax,(float)ay,(float)az) - ab_eye;
  
  // mouse position represents ray: eye + t*m
  // intersecting with a sphere centered at the origin
  GLfloat a = m*m;
  GLfloat b = (ab_eye*m);
  GLfloat root = (b*b) - a*(ab_zoom2 - ab_sphere2);
  if(root <= 0) return edge_coords(m);
  GLfloat t = (0.0 - b - sqrt(root)) / a;
  return (ab_eye+(m*t)).unit();
}