From 7c24470709fdc98a4763f20380ef8298c9c61a65 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Mon, 3 May 2021 21:17:24 +0200 Subject: [PATCH] Add FEEvaluation::fast_evaluation_supported() --- .../matrix_free/evaluation_template_factory.h | 8 +++ .../evaluation_template_factory.templates.h | 34 ++++++++++ include/deal.II/matrix_free/fe_evaluation.h | 67 ++++++++++++++++++- tests/matrix_free/fe_evaluation_print_01.cc | 66 ++++++++++++++++++ .../matrix_free/fe_evaluation_print_01.output | 49 ++++++++++++++ 5 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 tests/matrix_free/fe_evaluation_print_01.cc create mode 100644 tests/matrix_free/fe_evaluation_print_01.output diff --git a/include/deal.II/matrix_free/evaluation_template_factory.h b/include/deal.II/matrix_free/evaluation_template_factory.h index 3052af2dff..35dc8ccb1d 100644 --- a/include/deal.II/matrix_free/evaluation_template_factory.h +++ b/include/deal.II/matrix_free/evaluation_template_factory.h @@ -60,6 +60,10 @@ namespace internal VectorizedArrayType *gradients_quad, VectorizedArrayType *scratch_data, const bool sum_into_values_array); + + static bool + fast_evaluation_supported(const unsigned int given_degree, + const unsigned int n_q_points_1d); }; @@ -143,6 +147,10 @@ namespace internal const std::array face_orientations, const Table<2, unsigned int> &orientation_map); + + static bool + fast_evaluation_supported(const unsigned int given_degree, + const unsigned int n_q_points_1d); }; diff --git a/include/deal.II/matrix_free/evaluation_template_factory.templates.h b/include/deal.II/matrix_free/evaluation_template_factory.templates.h index 1a5c254899..67a3deac9b 100644 --- a/include/deal.II/matrix_free/evaluation_template_factory.templates.h +++ b/include/deal.II/matrix_free/evaluation_template_factory.templates.h @@ -63,6 +63,16 @@ namespace internal return EvaluatorType::template run<-1, 0>(args...); } + struct FastEvaluationSupported + { + template + static bool + run() + { + return fe_degree != -1; + } + }; + template @@ -123,6 +133,18 @@ namespace internal + template + bool + FEEvaluationFactory:: + fast_evaluation_supported(const unsigned int given_degree, + const unsigned int n_q_points_1d) + { + return instantiation_helper_run<1, FastEvaluationSupported>(given_degree, + n_q_points_1d); + } + + + template void FEFaceEvaluationFactory::evaluate( @@ -307,6 +329,18 @@ namespace internal + template + bool + FEFaceEvaluationFactory:: + fast_evaluation_supported(const unsigned int given_degree, + const unsigned int n_q_points_1d) + { + return instantiation_helper_run<1, FastEvaluationSupported>(given_degree, + n_q_points_1d); + } + + + template void CellwiseInverseMassFactory::apply( diff --git a/include/deal.II/matrix_free/fe_evaluation.h b/include/deal.II/matrix_free/fe_evaluation.h index 5f4be8d93b..024ae5734a 100644 --- a/include/deal.II/matrix_free/fe_evaluation.h +++ b/include/deal.II/matrix_free/fe_evaluation.h @@ -2320,7 +2320,10 @@ protected: * setting the macro `FE_EVAL_FACTORY_DEGREE_MAX` to the desired integer and * instantiating the classes FEEvaluationFactory and FEFaceEvaluationFactory * (the latter for FEFaceEvaluation) creates paths to templated functions for - * a possibly larger set of degrees. + * a possibly larger set of degrees. You can check if fast + * evaluation/integration for a given degree/n_quadrature_points pair by calling + * FEEvaluation::fast_evaluation_supported() or + * FEFaceEvaluation::fast_evaluation_supported(). * *

Handling multi-component systems

* @@ -2763,6 +2766,13 @@ public: void reinit(const typename Triangulation::cell_iterator &cell); + /** + * Check if face evaluation/integration is supported. + */ + static bool + fast_evaluation_supported(const unsigned int given_degree, + const unsigned int give_n_q_points_1d); + /** * Evaluate the function values, the gradients, and the Hessians of the * polynomial interpolation from the DoF values in the input vector to the @@ -3175,6 +3185,13 @@ public: void reinit(const unsigned int cell_batch_number, const unsigned int face_number); + /** + * Check if face evaluation/integration is supported. + */ + static bool + fast_evaluation_supported(const unsigned int given_degree, + const unsigned int give_n_q_points_1d); + /** * Evaluates the function values, the gradients, and the Laplacians of the * FE function given at the DoF values stored in the internal data field @@ -9538,6 +9555,54 @@ FEFaceEvaluation +bool +FEEvaluation:: + fast_evaluation_supported(const unsigned int given_degree, + const unsigned int give_n_q_points_1d) +{ + return fe_degree == -1 ? + internal::FEEvaluationFactory:: + fast_evaluation_supported(given_degree, give_n_q_points_1d) : + true; +} + + + +template +bool +FEFaceEvaluation:: + fast_evaluation_supported(const unsigned int given_degree, + const unsigned int give_n_q_points_1d) +{ + return fe_degree == -1 ? + internal::FEFaceEvaluationFactory:: + fast_evaluation_supported(given_degree, give_n_q_points_1d) : + true; +} + + + /*------------------------- end FEFaceEvaluation ------------------------- */ diff --git a/tests/matrix_free/fe_evaluation_print_01.cc b/tests/matrix_free/fe_evaluation_print_01.cc new file mode 100644 index 0000000000..e6f1239cde --- /dev/null +++ b/tests/matrix_free/fe_evaluation_print_01.cc @@ -0,0 +1,66 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2021 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// Test FEEvaluation::fast_evaluation_supported() + +#include + +#include + +#include + +#include + +#include +#include + +#include "../tests.h" + + + +template +void +test() +{ + for (unsigned int i = 1; i < 25; i++) + { + for (unsigned int j = 1; j < 25; j++) + if (FEEvaluation::fast_evaluation_supported(i, j)) + deallog << 1 << " "; + else + deallog << " "; + deallog << std::endl; + } + for (unsigned int i = 1; i < 25; i++) + { + for (unsigned int j = 1; j < 25; j++) + if (FEFaceEvaluation::fast_evaluation_supported(i, j)) + deallog << 1 << " "; + else + deallog << " "; + deallog << std::endl; + } +} + + + +int +main() +{ + initlog(); + test<1>(); +} diff --git a/tests/matrix_free/fe_evaluation_print_01.output b/tests/matrix_free/fe_evaluation_print_01.output new file mode 100644 index 0000000000..742ac8d833 --- /dev/null +++ b/tests/matrix_free/fe_evaluation_print_01.output @@ -0,0 +1,49 @@ + +DEAL::1 1 1 +DEAL:: 1 1 1 +DEAL:: 1 1 1 +DEAL:: 1 1 1 1 +DEAL:: 1 1 1 1 +DEAL:: 1 1 1 1 +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL::1 1 1 +DEAL:: 1 1 1 +DEAL:: 1 1 1 +DEAL:: 1 1 1 1 +DEAL:: 1 1 1 1 +DEAL:: 1 1 1 1 +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: +DEAL:: -- 2.39.5