]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add two more type traits to FEEvaluation
authorDenis Davydov <davydden@gmail.com>
Tue, 5 Mar 2019 14:13:53 +0000 (15:13 +0100)
committerDenis Davydov <davydden@gmail.com>
Tue, 5 Mar 2019 18:06:15 +0000 (19:06 +0100)
include/deal.II/matrix_free/fe_evaluation.h
tests/matrix_free/fe_evaluation_type_traits_02.cc [new file with mode: 0644]
tests/matrix_free/fe_evaluation_type_traits_02.output [new file with mode: 0644]

index 337846d4bd28e1d6491d9b71b3d33985ea00d5b6..5d3b0f41288e1006f68a560e15851689e468f053 100644 (file)
@@ -3431,6 +3431,58 @@ namespace internal
   template <typename T>
   const bool has_local_element<T>::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 <typename T>
+  struct has_add_local_element
+  {
+  private:
+    static int
+    detect(...);
+
+    template <typename U>
+    static decltype(
+      std::declval<U>().add_local_element(0, typename T::value_type()))
+    detect(const U &);
+
+  public:
+    static const bool value =
+      !std::is_same<int, decltype(detect(std::declval<T>()))>::value;
+  };
+
+  // We need to have a separate declaration for static const members
+  template <typename T>
+  const bool has_add_local_element<T>::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 <typename T>
+  struct has_set_local_element
+  {
+  private:
+    static int
+    detect(...);
+
+    template <typename U>
+    static decltype(
+      std::declval<U>().set_local_element(0, typename T::value_type()))
+    detect(const U &);
+
+  public:
+    static const bool value =
+      !std::is_same<int, decltype(detect(std::declval<T>()))>::value;
+  };
+
+  // We need to have a separate declaration for static const members
+  template <typename T>
+  const bool has_set_local_element<T>::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 (file)
index 0000000..f87bf95
--- /dev/null
@@ -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 <deal.II/matrix_free/fe_evaluation.h>
+
+#include "../tests.h"
+
+// dummy class we use to check typetraits and internal function.
+// this one mimics LA::d::Vec
+template <typename Number>
+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 <typename Number>
+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<double>  dummy;
+  Dummy2<double> dummy2;
+
+  deallog << "has_add_local_element:" << std::endl
+          << "Dummy = " << internal::has_add_local_element<Dummy<double>>::value
+          << std::endl
+          << "Dummy2 = "
+          << internal::has_add_local_element<Dummy2<double>>::value << std::endl
+          << "has_set_local_element:" << std::endl
+          << "Dummy = " << internal::has_set_local_element<Dummy<double>>::value
+          << std::endl
+          << "Dummy2 = "
+          << internal::has_set_local_element<Dummy2<double>>::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 (file)
index 0000000..d6fcec8
--- /dev/null
@@ -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

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.