From 2325e6aa4c666d06ebf54575fe28dcf303be8df8 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Wed, 20 Mar 2019 00:24:12 +0100 Subject: [PATCH] FEValuesViews::View --- doc/news/changes/minor/20190320LucaHeltai | 5 ++ include/deal.II/fe/fe_values.h | 75 +++++++++++++++++++++++ tests/fe/fe_values_views_types.cc | 67 ++++++++++++++++++++ tests/fe/fe_values_views_types.output | 46 ++++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 doc/news/changes/minor/20190320LucaHeltai create mode 100644 tests/fe/fe_values_views_types.cc create mode 100644 tests/fe/fe_values_views_types.output diff --git a/doc/news/changes/minor/20190320LucaHeltai b/doc/news/changes/minor/20190320LucaHeltai new file mode 100644 index 0000000000..5d1cbf85cf --- /dev/null +++ b/doc/news/changes/minor/20190320LucaHeltai @@ -0,0 +1,5 @@ +New: The type alias FEValuesViews::View now allows one to infer the correct FEValuesViews type +that would be returned by FEValuesBase::operator[]() when called with a specified extractor type from the +FEValuesExtractors namespace. +
+(Luca Heltai, 2019/03/20) diff --git a/include/deal.II/fe/fe_values.h b/include/deal.II/fe/fe_values.h index 713f1c64ad..71b50d9664 100644 --- a/include/deal.II/fe/fe_values.h +++ b/include/deal.II/fe/fe_values.h @@ -1871,6 +1871,69 @@ namespace internal { namespace FEValuesViews { + /** + * A class whose specialization is used to define what FEValuesViews + * object corresponds to the given FEValuesExtractors object. + * + * @author Luca Heltai, 2019. + */ + template + struct ViewType + {}; + + /** + * A class whose specialization is used to define what FEValuesViews + * object corresponds to the given FEValuesExtractors object. + * + * When using FEValuesExtractors::Scalar, the corresponding view is an + * FEValuesViews::Scalar. + */ + template + struct ViewType + { + using type = typename dealii::FEValuesViews::Scalar; + }; + + /** + * A class whose specialization is used to define what FEValuesViews + * object corresponds to the given FEValuesExtractors object. + * + * When using FEValuesExtractors::Vector, the corresponding view is an + * FEValuesViews::Vector. + */ + template + struct ViewType + { + using type = typename dealii::FEValuesViews::Vector; + }; + + /** + * A class whose specialization is used to define what FEValuesViews + * object corresponds to the given FEValuesExtractors object. + * + * When using FEValuesExtractors::Tensor, the corresponding view is an + * FEValuesViews::Tensor. + */ + template + struct ViewType> + { + using type = typename dealii::FEValuesViews::Tensor; + }; + + /** + * A class whose specialization is used to define what FEValuesViews + * object corresponds to the given FEValuesExtractors object. + * + * When using FEValuesExtractors::SymmetricTensor, the corresponding + * view is an FEValuesViews::SymmetricTensor. + */ + template + struct ViewType> + { + using type = + typename dealii::FEValuesViews::SymmetricTensor; + }; + /** * A class objects of which store a collection of FEValuesViews::Scalar, * FEValuesViews::Vector, etc object. The FEValuesBase class uses it to @@ -1900,6 +1963,18 @@ namespace internal } // namespace FEValuesViews } // namespace internal +namespace FEValuesViews +{ + /** + * A templated alias that associates to a given Extractor class + * the corresponding view in FEValuesViews. + * + * @author Luca Heltai, 2019. + */ + template + using View = + typename internal::FEValuesViews::ViewType::type; +} // namespace FEValuesViews /** diff --git a/tests/fe/fe_values_views_types.cc b/tests/fe/fe_values_views_types.cc new file mode 100644 index 0000000000..e6f573900a --- /dev/null +++ b/tests/fe/fe_values_views_types.cc @@ -0,0 +1,67 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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 FEValuesViews::View + +#include + +#include + +#include "../tests.h" + +template +void +test(const Extractor &) +{ + typename FEValuesViews::View::template OutputType< + double>::value_type t1; + + typename FEValuesViews::View::template OutputType< + double>::gradient_type t2; + + deallog << "Test<" << Utilities::dim_string(dim, spacedim) << ">" << std::endl + << Utilities::type_to_string(t1) << std::endl + << Utilities::type_to_string(t2) << std::endl; +} + +int +main() +{ + initlog(); + + FEValuesExtractors::Scalar scalar(0); + FEValuesExtractors::Vector vector(1); + FEValuesExtractors::Tensor<2> tensor(2); + + test<1, 1>(scalar); + test<1, 1>(vector); + test<1, 1>(tensor); + + test<1, 2>(scalar); + test<1, 2>(vector); + test<1, 2>(tensor); + + test<2, 2>(scalar); + test<2, 2>(vector); + test<2, 2>(tensor); + + test<2, 3>(scalar); + test<2, 3>(vector); + test<2, 3>(tensor); + + test<3, 3>(scalar); + test<3, 3>(vector); + test<3, 3>(tensor); +} diff --git a/tests/fe/fe_values_views_types.output b/tests/fe/fe_values_views_types.output new file mode 100644 index 0000000000..5eacce960a --- /dev/null +++ b/tests/fe/fe_values_views_types.output @@ -0,0 +1,46 @@ + +DEAL::Test<1> +DEAL::double +DEAL::dealii::Tensor<1, 1, double> +DEAL::Test<1> +DEAL::dealii::Tensor<1, 1, double> +DEAL::dealii::Tensor<2, 1, double> +DEAL::Test<1> +DEAL::dealii::Tensor<2, 1, double> +DEAL::dealii::Tensor<3, 1, double> +DEAL::Test<1,2> +DEAL::double +DEAL::dealii::Tensor<1, 2, double> +DEAL::Test<1,2> +DEAL::dealii::Tensor<1, 2, double> +DEAL::dealii::Tensor<2, 2, double> +DEAL::Test<1,2> +DEAL::dealii::Tensor<2, 2, double> +DEAL::dealii::Tensor<3, 2, double> +DEAL::Test<2> +DEAL::double +DEAL::dealii::Tensor<1, 2, double> +DEAL::Test<2> +DEAL::dealii::Tensor<1, 2, double> +DEAL::dealii::Tensor<2, 2, double> +DEAL::Test<2> +DEAL::dealii::Tensor<2, 2, double> +DEAL::dealii::Tensor<3, 2, double> +DEAL::Test<2,3> +DEAL::double +DEAL::dealii::Tensor<1, 3, double> +DEAL::Test<2,3> +DEAL::dealii::Tensor<1, 3, double> +DEAL::dealii::Tensor<2, 3, double> +DEAL::Test<2,3> +DEAL::dealii::Tensor<2, 3, double> +DEAL::dealii::Tensor<3, 3, double> +DEAL::Test<3> +DEAL::double +DEAL::dealii::Tensor<1, 3, double> +DEAL::Test<3> +DEAL::dealii::Tensor<1, 3, double> +DEAL::dealii::Tensor<2, 3, double> +DEAL::Test<3> +DEAL::dealii::Tensor<2, 3, double> +DEAL::dealii::Tensor<3, 3, double> -- 2.39.5