From b9c22bc392a715a64bed4b69e607e093b35aa87d Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Wed, 20 Feb 2019 23:03:16 +0100 Subject: [PATCH] add type traits to be used internally with FEEValuation --- include/deal.II/matrix_free/fe_evaluation.h | 29 +++++++++++++ .../matrix_free/fe_evaluation_type_traits.cc | 43 +++++++++++++++++++ ...tion_type_traits.with_trilinos=true.output | 5 +++ 3 files changed, 77 insertions(+) create mode 100644 tests/matrix_free/fe_evaluation_type_traits.cc create mode 100644 tests/matrix_free/fe_evaluation_type_traits.with_trilinos=true.output diff --git a/include/deal.II/matrix_free/fe_evaluation.h b/include/deal.II/matrix_free/fe_evaluation.h index e0143f51f7..8c3cc1d3bd 100644 --- a/include/deal.II/matrix_free/fe_evaluation.h +++ b/include/deal.II/matrix_free/fe_evaluation.h @@ -3409,6 +3409,35 @@ FEEvaluationBase::read_cell_data( namespace internal { + // a helper type-trait that leverage SFINAE to figure out if type T has + // ... T::local_element() const + template + struct has_local_element + { + private: + // this will work always. + // we let it be void as we know T::local_element() (if exists) should + // certainly return something + static void + detect(...); + + // this detecter will work only if we have "... T::local_element() const" + // and its return type will be the same as local_element(), + // that we expect to be T::value_type + template + static decltype(std::declval().local_element(0)) + detect(const U &); + + public: + // finally here we check if our detector has return type same as + // T::value_type. This will happen if compiler can use second detector, + // otherwise SFINAE let it work with the more general first one that is void + static constexpr bool value = + std::is_same()))>::value; + }; + + // access to generic vectors that have operator (). template inline typename VectorType::value_type & diff --git a/tests/matrix_free/fe_evaluation_type_traits.cc b/tests/matrix_free/fe_evaluation_type_traits.cc new file mode 100644 index 0000000000..68c837d5e1 --- /dev/null +++ b/tests/matrix_free/fe_evaluation_type_traits.cc @@ -0,0 +1,43 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2014 - 2018 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 internal typetraits used in FEEvaluation + +#include +#include + +#include + +#include "../tests.h" + + +int +main() +{ + initlog(); + + deallog << "has_local_element:" << std::endl + << "LinearAlgebra::distributed::Vector = " + << internal::has_local_element< + LinearAlgebra::distributed::Vector>::value + << std::endl + << "TrilinosWrappers::MPI::Vector = " + << internal::has_local_element::value + << std::endl; + + deallog << "OK" << std::endl; +} diff --git a/tests/matrix_free/fe_evaluation_type_traits.with_trilinos=true.output b/tests/matrix_free/fe_evaluation_type_traits.with_trilinos=true.output new file mode 100644 index 0000000000..b62ca9b86d --- /dev/null +++ b/tests/matrix_free/fe_evaluation_type_traits.with_trilinos=true.output @@ -0,0 +1,5 @@ + +DEAL::has_local_element: +DEAL::LinearAlgebra::distributed::Vector = 1 +DEAL::TrilinosWrappers::MPI::Vector = 0 +DEAL::OK -- 2.39.5