]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add range based loop for QPoints to FEValuesBase
authorJean-Paul Pelteret <jppelteret@gmail.com>
Tue, 28 Apr 2020 18:16:19 +0000 (20:16 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 30 Apr 2020 18:47:46 +0000 (20:47 +0200)
doc/news/changes/minor/20200429Jean-PaulPelteret [new file with mode: 0644]
include/deal.II/fe/fe_values.h

diff --git a/doc/news/changes/minor/20200429Jean-PaulPelteret b/doc/news/changes/minor/20200429Jean-PaulPelteret
new file mode 100644 (file)
index 0000000..c1fe3ef
--- /dev/null
@@ -0,0 +1,5 @@
+New: There is a new function FEValuesBase::quadrature_point_indices()
+that makes writing range-based for loops over all quadrature points of a 
+cell or face much simpler.
+<br>
+(Jean-Paul Pelteret, 2020/04/29)
index 9488af2116f499f534ce2136737fc7c7ec1b5cdb..5ddb4ca9147babcb36763d1d1cb034595818787a 100644 (file)
@@ -39,6 +39,8 @@
 
 #include <deal.II/hp/dof_handler.h>
 
+#include <boost/range/irange.hpp>
+
 #include <algorithm>
 #include <memory>
 #include <type_traits>
@@ -2912,6 +2914,27 @@ public:
   /// @name Geometry of the cell
   //@{
 
+  /**
+   * Return an object that can be thought of as an array containing all
+   * indices from zero to `n_quadrature_points`. This allows to write code
+   * using range-based for loops of the following kind:
+   * @code
+   *   FEValues<dim> fe_values (...);
+   *
+   *   for (auto &cell : dof_handler.active_cell_iterators())
+   *     {
+   *       fe_values.reinit(cell);
+   *       for (const auto q_point : fe_values.quadrature_point_indices())
+   *         ... do something at the quadrature point ...
+   *     }
+   * @endcode
+   * Here, we are looping over all quadrature points on all cells, with
+   * `q_point` taking on all valid indices for quadrature points, as defined
+   * by the quadrature rule passed to `fe_values`.
+   */
+  boost::integer_range<unsigned int>
+  quadrature_point_indices() const;
+
   /**
    * Position of the <tt>q</tt>th quadrature point in real space.
    *
@@ -5406,6 +5429,15 @@ FEValuesBase<dim, spacedim>::get_inverse_jacobians() const
 
 
 
+template <int dim, int spacedim>
+inline boost::integer_range<unsigned int>
+FEValuesBase<dim, spacedim>::quadrature_point_indices() const
+{
+  return boost::irange(0U, n_quadrature_points);
+}
+
+
+
 template <int dim, int spacedim>
 inline const Point<spacedim> &
 FEValuesBase<dim, spacedim>::quadrature_point(const unsigned int i) const

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.