]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make FEEval more consistent with FEValues 13341/head
authorPeter Munch <peterrmuench@gmail.com>
Sun, 6 Feb 2022 06:52:04 +0000 (07:52 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 21 Apr 2022 09:07:17 +0000 (11:07 +0200)
doc/news/changes/minor/20220206Munch [new file with mode: 0644]
include/deal.II/matrix_free/fe_evaluation.h
include/deal.II/matrix_free/fe_evaluation_data.h
tests/matrix_free/ecl_02.cc

diff --git a/doc/news/changes/minor/20220206Munch b/doc/news/changes/minor/20220206Munch
new file mode 100644 (file)
index 0000000..e788376
--- /dev/null
@@ -0,0 +1,6 @@
+Improved: To be consistent with the FEValues classes, one can now 
+loop over all DoF and quadrature-point indices in a 
+range-based loop with the help of the new functions dof_indices() and
+quadrature_point_indices().
+<br>
+(Peter Munch, 2022/02/06)
index b4c4ab72ff3c74602060c8a8b11287c428b5e9c3..16e236948b9149a976d60d90bd80c6849105e736 100644 (file)
@@ -2302,6 +2302,14 @@ public:
                     const bool  integrate_gradients,
                     VectorType &output_vector);
 
+  /**
+   * Return an object that can be thought of as an array containing all indices
+   * from zero to @p dofs_per_cell. This allows to write code using
+   * range-based for loops.
+   */
+  std_cxx20::ranges::iota_view<unsigned int, unsigned int>
+  dof_indices() const;
+
   /**
    * The number of degrees of freedom of a single component on the cell for
    * the underlying evaluation object. Usually close to
@@ -2700,6 +2708,14 @@ public:
                     const bool  integrate_gradients,
                     VectorType &output_vector);
 
+  /**
+   * Return an object that can be thought of as an array containing all indices
+   * from zero to @p dofs_per_cell. This allows to write code using
+   * range-based for loops.
+   */
+  std_cxx20::ranges::iota_view<unsigned int, unsigned int>
+  dof_indices() const;
+
   /**
    * The number of degrees of freedom of a single component on the cell for
    * the underlying evaluation object. Usually close to
@@ -7552,6 +7568,25 @@ FEEvaluation<dim,
 
 
 
+template <int dim,
+          int fe_degree,
+          int n_q_points_1d,
+          int n_components_,
+          typename Number,
+          typename VectorizedArrayType>
+inline std_cxx20::ranges::iota_view<unsigned int, unsigned int>
+FEEvaluation<dim,
+             fe_degree,
+             n_q_points_1d,
+             n_components_,
+             Number,
+             VectorizedArrayType>::dof_indices() const
+{
+  return {0U, dofs_per_cell};
+}
+
+
+
 /*-------------------------- FEFaceEvaluation ---------------------------*/
 
 
@@ -8351,6 +8386,25 @@ FEFaceEvaluation<dim,
 
 
 
+template <int dim,
+          int fe_degree,
+          int n_q_points_1d,
+          int n_components_,
+          typename Number,
+          typename VectorizedArrayType>
+inline std_cxx20::ranges::iota_view<unsigned int, unsigned int>
+FEFaceEvaluation<dim,
+                 fe_degree,
+                 n_q_points_1d,
+                 n_components_,
+                 Number,
+                 VectorizedArrayType>::dof_indices() const
+{
+  return {0U, dofs_per_cell};
+}
+
+
+
 template <int dim,
           int fe_degree,
           int n_q_points_1d,
index 57ff0ac6021ae4f77125d43a75459ec6b811175e..26df97bf9e99fa37ab3df89eb8891ef3a48d9e81 100644 (file)
@@ -533,6 +533,14 @@ public:
       return face_ids;
   }
 
+  /**
+   * Return an object that can be thought of as an array containing all indices
+   * from zero to @p n_quadrature_points. This allows to write code using
+   * range-based for loops.
+   */
+  std_cxx20::ranges::iota_view<unsigned int, unsigned int>
+  quadrature_point_indices() const;
+
   //@}
 
   /**
@@ -1582,6 +1590,15 @@ FEEvaluationData<dim, Number, is_face>::is_interior_face() const
 
 
 
+template <int dim, typename Number, bool is_face>
+inline std_cxx20::ranges::iota_view<unsigned int, unsigned int>
+FEEvaluationData<dim, Number, is_face>::quadrature_point_indices() const
+{
+  return {0U, n_quadrature_points};
+}
+
+
+
 namespace internal
 {
   template <std::size_t N,
index 04a699695dcb2c353e9dde7c49582005ba622432..27856995376765e253dec99bf8ff72a630d99156 100644 (file)
@@ -125,24 +125,24 @@ test(const unsigned int n_refinements = 1)
 
               phi_m.read_dof_values(src);
 
-              for (unsigned int i = 0; i < phi_m.static_dofs_per_component; ++i)
+              for (const auto i : phi_m.dof_indices())
                 deallog << static_cast<int>(phi_m.begin_dof_values()[i][0])
                         << ' ';
               deallog << std::endl;
               phi_m.gather_evaluate(src, EvaluationFlags::values);
-              for (unsigned int i = 0; i < phi_m.static_n_q_points; ++i)
-                deallog << static_cast<int>(phi_m.begin_values()[i][0]) << ' ';
+              for (const auto q : phi_p.quadrature_point_indices())
+                deallog << static_cast<int>(phi_m.begin_values()[q][0]) << " ";
               deallog << std::endl;
 
               phi_p.read_dof_values(src);
-              for (unsigned int i = 0; i < phi_p.static_dofs_per_component; ++i)
+              for (const auto i : phi_p.dof_indices())
                 deallog << static_cast<int>(phi_p.begin_dof_values()[i][0])
                         << ' ';
               deallog << std::endl;
 
               phi_p.gather_evaluate(src, EvaluationFlags::values);
-              for (unsigned int i = 0; i < phi_p.static_n_q_points; ++i)
-                deallog << static_cast<int>(phi_p.begin_values()[i][0]) << ' ';
+              for (const auto q : phi_p.quadrature_point_indices())
+                deallog << static_cast<int>(phi_p.begin_values()[q][0]) << " ";
               deallog << std::endl << std::endl;
             }
         }

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.