Discontinuous Galerkin Library
#include "dg/algorithm.h"
Loading...
Searching...
No Matches
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
11// Q: Make inclusion of tensor_traits easier if all you want is to use the full traits system in feltor?
12// A: Some subtle issues:
13// - Do you want the thrust header? (And thus depend on thrust library?)
14// - Do you want all matrix traits as well?
15// - If so, do you want the sparsematrix.h which incurs -lcusparse dependency
16// In fact, it is possible to include tensor_traits.h as is and include the specialisation later when it is needed
17
18namespace dg{
21
22
36template< class Vector, class Enable=void>
43
44template<class Vector>
46template<class Vector>
48template<class Vector>
49using get_execution_policy = typename TensorTraits<std::decay_t<Vector>>::execution_policy;
50
52
55template<class T> //T = SharedVector
56using get_pointer_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
58
59template<class T> //T = RecursiveVector
60using get_element_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
61 const typename std::decay_t<T>::value_type&, typename std::decay_t<T>::value_type& >;
62template<class T> //T = std::map
63using get_mapped_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
64 const typename std::decay_t<T>::mapped_type&, typename std::decay_t<T>::mapped_type& >;
65
66template<class T>//T = MPIVector
67using get_data_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
68 const typename std::decay_t<T>::container_type&, typename std::decay_t<T>::container_type& >;
69
70template<class T>
71inline get_element_type<T> do_get_vector_element( T&& v, unsigned i, RecursiveVectorTag)//-> decltype(v[i]){
72{
73 return v[i];
74}
75template<class T, class Key>
76inline get_mapped_type<T> do_get_vector_element( T&& v, const Key& key, StdMapTag)//-> decltype(v[i]){
77{
78 return v.at(key);
79}
80template<class T, class Key>
81inline T&& do_get_vector_element( T&& v, const Key& i, AnyScalarTag){
82 return std::forward<T>(v);
83}
84
85template<class T>
86inline get_data_type<T> do_get_data( T&& v, MPIVectorTag)//-> decltype(v.data())
87{
88 return v.data();
89}
90template<class T>
91inline T&& do_get_data( T&& v, AnyScalarTag){
92 return std::forward<T>(v);
93}
94
95template<class T>
96inline 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
97{
98 return thrust::raw_pointer_cast(v.data());
99}
100template<class T>
101inline T&& do_get_pointer_or_reference( T&& v, AnyScalarTag){
102 return std::forward<T>(v);
103}
104
106
107//template<class T>
108//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>()) )
109//{
110// return do_get_vector_element( std::forward<T>(v), i, get_tensor_category<T>());
111//}
112//
113//template<class T>
114//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>() ))
115//{
116// return do_get_data( std::forward<T>(v), get_tensor_category<T>());
117//}
118//
119//template<class T>
120//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>()))
121//{
122// return do_get_pointer_or_reference( std::forward<T>(v), get_tensor_category<T>());
123//}
124
125}//namespace dg
126
127#endif //_DG_VECTOR_TRAITS_
typename TensorTraits< std::decay_t< Vector > >::tensor_category get_tensor_category
Definition tensor_traits.h:47
typename TensorTraits< std::decay_t< Vector > >::execution_policy get_execution_policy
Definition tensor_traits.h:49
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition tensor_traits.h:45
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:38
void value_type
Definition tensor_traits.h:39