Discontinuous Galerkin Library
#include "dg/algorithm.h"
tensor_traits.h
Go to the documentation of this file.
1#ifndef _DG_VECTOR_TRAITS_
2#define _DG_VECTOR_TRAITS_
3
4#include <type_traits>
5#include <thrust/memory.h>
6#include "scalar_categories.h"
7#include "vector_categories.h"
8#include "matrix_categories.h"
9#include "execution_policy.h"
10
11namespace dg{
14
15
29template< class Vector, class Enable=void>
31{
32 using value_type = void;
35};
36
37template<class Vector>
39template<class Vector>
41template<class Vector>
42using get_execution_policy = typename TensorTraits<std::decay_t<Vector>>::execution_policy;
43
45
48template<class T> //T = SharedVector
49using get_pointer_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
51
52template<class T> //T = RecursiveVector
53using get_element_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
54 const typename std::decay_t<T>::value_type&, typename std::decay_t<T>::value_type& >;
55template<class T> //T = std::map
56using get_mapped_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
57 const typename std::decay_t<T>::mapped_type&, typename std::decay_t<T>::mapped_type& >;
58
59template<class T>//T = MPIVector
60using get_data_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
61 const typename std::decay_t<T>::container_type&, typename std::decay_t<T>::container_type& >;
62
63template<class T>
64inline get_element_type<T> do_get_vector_element( T&& v, unsigned i, RecursiveVectorTag)//-> decltype(v[i]){
65{
66 return v[i];
67}
68template<class T, class Key>
69inline get_mapped_type<T> do_get_vector_element( T&& v, const Key& key, StdMapTag)//-> decltype(v[i]){
70{
71 return v.at(key);
72}
73template<class T, class Key>
74inline T&& do_get_vector_element( T&& v, const Key& i, AnyScalarTag){
75 return std::forward<T>(v);
76}
77
78template<class T>
79inline get_data_type<T> do_get_data( T&& v, MPIVectorTag)//-> decltype(v.data())
80{
81 return v.data();
82}
83template<class T>
84inline T&& do_get_data( T&& v, AnyScalarTag){
85 return std::forward<T>(v);
86}
87
88template<class T>
89inline get_pointer_type<T> do_get_pointer_or_reference( T&& v, AnyVectorTag)// -> decltype(thrust::raw_pointer_cast(v.data())) //nvcc-7.5 does not like decltype in this connection
90{
91 return thrust::raw_pointer_cast(v.data());
92}
93template<class T>
94inline T&& do_get_pointer_or_reference( T&& v, AnyScalarTag){
95 return std::forward<T>(v);
96}
97
99
100//template<class T>
101//inline std::conditional_t<std::is_base_of<AnyScalarTag, get_tensor_category<T>>::value, T&&, get_element_type<T> > get_vector_element( T&& v, unsigned i )// -> decltype( do_get_vector_element( std::forward<T>(v), i, get_tensor_category<T>()) )
102//{
103// return do_get_vector_element( std::forward<T>(v), i, get_tensor_category<T>());
104//}
105//
106//template<class T>
107//inline std::conditional_t<std::is_base_of<AnyScalarTag, get_tensor_category<T>>::value, T, get_data_type<T> > get_data( T&& v)//-> decltype(do_get_data( std::forward<T>(v), get_tensor_category<T>() ))
108//{
109// return do_get_data( std::forward<T>(v), get_tensor_category<T>());
110//}
111//
112//template<class T>
113//std::conditional<std::is_base_of<AnyScalarTag, get_tensor_category<T>>::value, T, get_pointer_type<T> > get_pointer_or_reference( T&& v )// -> decltype( do_get_pointer_or_reference( std::forward<T>(v), get_tensor_category<T>()))
114//{
115// return do_get_pointer_or_reference( std::forward<T>(v), get_tensor_category<T>());
116//}
117
118}//namespace dg
119
120#endif //_DG_VECTOR_TRAITS_
typename TensorTraits< std::decay_t< Vector > >::tensor_category get_tensor_category
Definition: tensor_traits.h:40
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
typename TensorTraits< std::decay_t< Vector > >::execution_policy get_execution_policy
Definition: tensor_traits.h:42
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Indicate that a type does not have an execution policy.
Definition: execution_policy.h:20
Indicate that a type is not a tensor.
Definition: matrix_categories.h:13
This tag indicates composition/recursion.
Definition: vector_categories.h:62
The vector traits.
Definition: tensor_traits.h:31
void value_type
Definition: tensor_traits.h:32