]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add type traits to be used internally with FEEValuation
authorDenis Davydov <davydden@gmail.com>
Wed, 20 Feb 2019 22:03:16 +0000 (23:03 +0100)
committerDenis Davydov <davydden@gmail.com>
Wed, 20 Feb 2019 22:19:25 +0000 (23:19 +0100)
include/deal.II/matrix_free/fe_evaluation.h
tests/matrix_free/fe_evaluation_type_traits.cc [new file with mode: 0644]
tests/matrix_free/fe_evaluation_type_traits.with_trilinos=true.output [new file with mode: 0644]

index e0143f51f754a6ec69605edaf4873bca51f1ff46..8c3cc1d3bd76b156c2b819a51b54c54fa6b9e736 100644 (file)
@@ -3409,6 +3409,35 @@ FEEvaluationBase<dim, n_components_, Number, is_face>::read_cell_data(
 
 namespace internal
 {
+  // a helper type-trait that leverage SFINAE to figure out if type T has
+  // ... T::local_element() const
+  template <typename T>
+  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 <typename U>
+    static decltype(std::declval<U const>().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<typename T::value_type,
+                   decltype(detect(std::declval<T>()))>::value;
+  };
+
+
   // access to generic vectors that have operator ().
   template <typename VectorType>
   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 (file)
index 0000000..68c837d
--- /dev/null
@@ -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 <deal.II/lac/la_parallel_vector.h>
+#include <deal.II/lac/trilinos_vector.h>
+
+#include <deal.II/matrix_free/fe_evaluation.h>
+
+#include "../tests.h"
+
+
+int
+main()
+{
+  initlog();
+
+  deallog << "has_local_element:" << std::endl
+          << "LinearAlgebra::distributed::Vector = "
+          << internal::has_local_element<
+               LinearAlgebra::distributed::Vector<double>>::value
+          << std::endl
+          << "TrilinosWrappers::MPI::Vector = "
+          << internal::has_local_element<TrilinosWrappers::MPI::Vector>::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 (file)
index 0000000..b62ca9b
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL::has_local_element:
+DEAL::LinearAlgebra::distributed::Vector = 1
+DEAL::TrilinosWrappers::MPI::Vector = 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.