From: Denis Davydov Date: Tue, 5 Mar 2019 14:13:53 +0000 (+0100) Subject: add two more type traits to FEEvaluation X-Git-Tag: v9.1.0-rc1~302^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41e0507737bebcaae9d8a6859cef9c2d1c6ef189;p=dealii.git add two more type traits to FEEvaluation --- diff --git a/include/deal.II/matrix_free/fe_evaluation.h b/include/deal.II/matrix_free/fe_evaluation.h index 337846d4bd..5d3b0f4128 100644 --- a/include/deal.II/matrix_free/fe_evaluation.h +++ b/include/deal.II/matrix_free/fe_evaluation.h @@ -3431,6 +3431,58 @@ namespace internal template const bool has_local_element::value; + + + // a helper type-trait that leverage SFINAE to figure out if type T has + // void T::add_local_element(const uint, const typename T::value_type) + template + struct has_add_local_element + { + private: + static int + detect(...); + + template + static decltype( + std::declval().add_local_element(0, typename T::value_type())) + detect(const U &); + + public: + static const bool value = + !std::is_same()))>::value; + }; + + // We need to have a separate declaration for static const members + template + const bool has_add_local_element::value; + + + + // a helper type-trait that leverage SFINAE to figure out if type T has + // void T::set_local_element(const uint, const typename T::value_type) + template + struct has_set_local_element + { + private: + static int + detect(...); + + template + static decltype( + std::declval().set_local_element(0, typename T::value_type())) + detect(const U &); + + public: + static const bool value = + !std::is_same()))>::value; + }; + + // We need to have a separate declaration for static const members + template + const bool has_set_local_element::value; + + + // same as above to check // bool T::partitioners_are_compatible(const Utilities::MPI::Partitioner &) // const diff --git a/tests/matrix_free/fe_evaluation_type_traits_02.cc b/tests/matrix_free/fe_evaluation_type_traits_02.cc new file mode 100644 index 0000000000..f87bf95c1b --- /dev/null +++ b/tests/matrix_free/fe_evaluation_type_traits_02.cc @@ -0,0 +1,120 @@ +// --------------------------------------------------------------------- +// +// 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 internal typetraits used in FEEvaluation + +#include + +#include "../tests.h" + +// dummy class we use to check typetraits and internal function. +// this one mimics LA::d::Vec +template +class Dummy +{ +public: + using value_type = Number; + + Number + local_element(const unsigned int) const + { + deallog << "Dummy::local_element() const" << std::endl; + return Number(); + } + + void + set_local_element(const unsigned int, const Number) + { + deallog << "Dummy::set_local_element()" << std::endl; + } + + void + add_local_element(const unsigned int, const Number) + { + deallog << "Dummy::add_local_element()" << std::endl; + } + + Number + operator()(const unsigned int) const + { + deallog << "Dummy::operator() const" << std::endl; + return Number(); + } +}; + + +template +class Dummy2 +{ +public: + using value_type = Number; + + Number + local_element(const unsigned int) const + { + deallog << "Dummy2::local_element() const" << std::endl; + return Number(); + } + + Number & + local_element(const unsigned int) + { + deallog << "Dummy2::local_element()" << std::endl; + return dummy; + } + + Number + operator()(const unsigned int) const + { + deallog << "Dummy2::operator() const" << std::endl; + return Number(); + } + + Number & + operator()(const unsigned int) + { + deallog << "Dummy2::operator()" << std::endl; + return dummy; + } + +private: + Number dummy; +}; + + +int +main() +{ + initlog(); + + Dummy dummy; + Dummy2 dummy2; + + deallog << "has_add_local_element:" << std::endl + << "Dummy = " << internal::has_add_local_element>::value + << std::endl + << "Dummy2 = " + << internal::has_add_local_element>::value << std::endl + << "has_set_local_element:" << std::endl + << "Dummy = " << internal::has_set_local_element>::value + << std::endl + << "Dummy2 = " + << internal::has_set_local_element>::value + << std::endl; + + deallog << "OK" << std::endl; +} diff --git a/tests/matrix_free/fe_evaluation_type_traits_02.output b/tests/matrix_free/fe_evaluation_type_traits_02.output new file mode 100644 index 0000000000..d6fcec8248 --- /dev/null +++ b/tests/matrix_free/fe_evaluation_type_traits_02.output @@ -0,0 +1,8 @@ + +DEAL::has_add_local_element: +DEAL::Dummy = 1 +DEAL::Dummy2 = 0 +DEAL::has_set_local_element: +DEAL::Dummy = 1 +DEAL::Dummy2 = 0 +DEAL::OK