Example #1
0
void integrate_function (const MeshBase & mesh)
{
#if defined(LIBMESH_HAVE_TRIANGLE) && defined(LIBMESH_HAVE_TETGEN)

  std::vector<Real> vertex_distance;

  QComposite<QGauss> qrule (mesh.mesh_dimension(), FIRST);
  //QGauss qrule (mesh.mesh_dimension(), FIRST);

  std::unique_ptr<FEBase> fe (FEBase::build (mesh.mesh_dimension(), FEType (FIRST, LAGRANGE)));

  Real int_val=0.;

  const std::vector<Point> & q_points = fe->get_xyz();
  const std::vector<Real>  & JxW      = fe->get_JxW();

  for (const auto & elem : mesh.active_local_element_ptr_range())
    {
      vertex_distance.clear();

      for (unsigned int v=0; v<elem->n_vertices(); v++)
        vertex_distance.push_back (distance(elem->point(v)));

      qrule.init (*elem, vertex_distance);

      fe->reinit (elem,
                  &(qrule.get_points()),
                  &(qrule.get_weights()));


      // TODO:  would it be valuable to have the composite quadrature rule sort
      // from smallest to largest JxW value to help prevent
      // ... large + small + large + large + small ...
      // type truncation errors?
      for (std::size_t qp=0; qp<q_points.size(); qp++)
        int_val += JxW[qp] * integrand(q_points[qp]);
    }

  mesh.comm().sum (int_val);

  libMesh::out << "\n***********************************\n"
               << " int_val   = " << int_val << std::endl
               << " exact_val = " <<  1*(2*2 - radius*radius*pi) + 10.*(radius*radius*pi)
               << "\n***********************************\n"
               << std::endl;
#else
  libmesh_ignore(mesh);
#endif
}