KASKADE 7 development version
duneInterface.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* see http://www.zib.de/Numerik/numsoft/kaskade7/ */
5/* */
6/* Copyright (C) 2002-2016 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef KASKADE_DUNE_INTERFACE_HH_
14#define KASKADE_DUNE_INTERFACE_HH_
15
16#include <type_traits>
17
18#include <boost/mpl/plus.hpp>
19
20#include "is_function.hh"
22
23namespace Kaskade
24{
26 template <class Type>
27 struct Dim
28 {
29 struct Dummy
30 {
31 static constexpr int dim = 0;
32 static constexpr int dimension = 0;
33 };
34
35 template <class T, bool enable>
36 struct EvaluateDim{ static constexpr int value = 0; };
37
38 template <class T>
39 struct EvaluateDim<T,true>{ static constexpr int value = std::conditional<!IsFunction<decltype(&(T::dim))>::value,T,Dummy>::type::dim; };
40
41 template <class T, bool enable>
42 struct EvaluateDimension{ static constexpr int value = 0; };
43
44 template <class T>
45 struct EvaluateDimension<T,true>{ static constexpr int value = std::conditional<!IsFunction<decltype(&T::dimension)>::value,T,Dummy>::type::dimension; };
46
47
48 KASKADE_CREATE_MEMBER_NAME_CHECK(dimension, HasDimension)
50
51 static_assert(!HasDimension<Type>::value && !HasDim<Type>::value, "Type must provide one of the integral static constexpr members \'dimension\' (DUNE) or \'dim\' (Kaskade7)!");
52
53 static constexpr int value = std::conditional<
54 HasDimension<Type>::value && HasDim<Type>::value,
56 boost::mpl::plus<
59 >
60 >::type::value;
61 };
62
64 template <class Type>
65 struct GetScalar
66 {
67 struct TypeNotFound{};
68
69 template <class LocalType>
70 static typename LocalType::field_type hasFieldType(typename LocalType::field_type);
71
72 template <class LocalType>
74
75 template <class LocalType>
76 static typename LocalType::Scalar hasScalar(typename LocalType::Scalar);
77
78 template <class LocalType>
80
81 template <class LocalType, bool hasScalar_, bool hasFieldType_> struct ExtractScalar;
82
83 template <class LocalType, bool hasFieldType_>
84 struct ExtractScalar<LocalType,true,hasFieldType_>
85 {
86 typedef typename LocalType::Scalar type;
87 };
88
89 template <class LocalType>
90 struct ExtractScalar<LocalType,false,true>
91 {
92 typedef typename LocalType::field_type type;
93 };
94
95 typedef typename ExtractScalar<Type,
96 !std::is_same<decltype(hasScalar<Type>(0)),TypeNotFound>::value,
97 !std::is_same<decltype(hasFieldType<Type>(0)),TypeNotFound>::value
99
100 static_assert(!std::is_same<type,TypeNotFound>::value, "No scalar type found. Type must provide one of the nested types \'field_type\' (DUNE) or \'Scalar\' (Kaskade7)!");
101 };
102
109 template <class Type>
111
112
113}
114
115#endif // KASKADE_DUNE_INTERFACE_HH_
#define KASKADE_CREATE_MEMBER_NAME_CHECK(VARIABLE_NAME, NAME)
typename GetScalar< Type >::type ScalarType
Extracts the scalar field type from linear algebra data types.
static constexpr int dim
static constexpr int dimension
static constexpr int value
static constexpr int value
Get dimension as nested integral static constexpr.
static constexpr int value
Get scalar type from Dune (-> field_type) or Kaskade (-> Scalar) member.
!std ::is_same< decltype(hasFieldType< Type >(0)), TypeNotFound >::value ::type type
static TypeNotFound hasScalar(...)
static LocalType::field_type hasFieldType(typename LocalType::field_type)
static LocalType::Scalar hasScalar(typename LocalType::Scalar)
static TypeNotFound hasFieldType(...)
Checks if type is a function or member function.
Definition: is_function.hh:33