dune-pdelab  2.0.0
backend/istl/utility.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_PDELAB_BACKEND_ISTL_UTILITY_HH
4 #define DUNE_PDELAB_BACKEND_ISTL_UTILITY_HH
5 
6 #include <dune/common/typetraits.hh>
7 
9 
10 namespace Dune {
11 
12  namespace PDELab {
13 
14  namespace istl {
15 
16  // ********************************************************************************
17  // Helper functions for uniform access to ISTL containers
18  //
19  // The following suite of raw() functions should be used in places where an
20  // algorithm might work on either the bare ISTL container or the PDELab
21  // wrapper and has to access the bare container.
22  // ********************************************************************************
23 
25  template<typename V>
26  V& raw(V& v)
27  {
28  return v;
29  }
30 
32  template<typename V>
33  const V& raw(const V& v)
34  {
35  return v;
36  }
37 
39  template<typename C>
40  struct raw_type
41  {
42  typedef C type;
43  };
44 
45 #ifndef DOXYGEN
46 
47  template<typename GFS, typename C>
50  {
51  return v.base();
52  }
53 
54  template<typename GFS, typename C>
57  {
58  return v.base();
59  }
60 
61  template<typename GFSU, typename GFSV, typename C, typename Stats>
62  typename ISTLMatrixContainer<GFSU,GFSV,C,Stats>::Container&
63  raw(ISTLMatrixContainer<GFSU,GFSV,C,Stats>& m)
64  {
65  return m.base();
66  }
67 
68  template<typename GFSU, typename GFSV, typename C, typename Stats>
69  const typename ISTLMatrixContainer<GFSU,GFSV,C,Stats>::Container&
70  raw(const ISTLMatrixContainer<GFSU,GFSV,C,Stats>& m)
71  {
72  return m.base();
73  }
74 
75  template<typename GFS, typename C>
76  struct raw_type<ISTLBlockVectorContainer<GFS,C> >
77  {
78  typedef C type;
79  };
80 
81  template<typename GFSU, typename GFSV, typename C, typename Stats>
82  struct raw_type<ISTLMatrixContainer<GFSU,GFSV,C,Stats> >
83  {
84  typedef C type;
85  };
86 
87 
88  // ********************************************************************************
89  // Helpers for the nesting_depth TMP
90  // ********************************************************************************
91 
92  namespace impl {
93 
94  template<typename T, std::size_t depth, typename Tag>
95  struct nesting_depth;
96 
97  template<typename T, std::size_t depth>
98  struct nesting_depth<T,depth,tags::block_vector>
99  : public nesting_depth<typename T::block_type,depth+1,typename tags::container<typename T::block_type>::type::base_tag>
100  {};
101 
102  template<typename T, std::size_t depth>
103  struct nesting_depth<T,depth,tags::dynamic_vector>
104  : public integral_constant<std::size_t,depth+1>
105  {};
106 
107  template<typename T, std::size_t depth>
108  struct nesting_depth<T,depth,tags::field_vector>
109  : public integral_constant<std::size_t,depth+1>
110  {};
111 
112  template<typename T, std::size_t depth>
113  struct nesting_depth<T,depth,tags::bcrs_matrix>
114  : public nesting_depth<typename T::block_type,depth+1,typename tags::container<typename T::block_type>::type::base_tag>
115  {};
116 
117  template<typename T, std::size_t depth>
118  struct nesting_depth<T,depth,tags::dynamic_matrix>
119  : public integral_constant<std::size_t,depth+1>
120  {};
121 
122  template<typename T, std::size_t depth>
123  struct nesting_depth<T,depth,tags::field_matrix>
124  : public integral_constant<std::size_t,depth+1>
125  {};
126 
127  }
128 
129 #endif // DOXYGEN
130 
132 
136  template<typename T>
138  : public impl::nesting_depth<T,0,typename tags::container<T>::type::base_tag>
139  {};
140 
141  } // namespace istl
142  } // namespace PDELab
143 } // namespace Dune
144 
145 #endif // DUNE_PDELAB_BACKEND_ISTL_UTILITY_HH
TMP for figuring out the depth up to which ISTL containers are nested.
Definition: backend/istl/utility.hh:137
Returns the raw ISTL type associated with C, or C itself it is already an ISTL type.
Definition: backend/istl/utility.hh:40
C Container
Definition: istlvectorbackend.hh:30
Container & base()
Definition: istlvectorbackend.hh:248
C type
Definition: backend/istl/utility.hh:42
V & raw(V &v)
Returns the raw ISTL object associated with v, or v itself it is already an ISTL object.
Definition: backend/istl/utility.hh:26
Definition: istlvectorbackend.hh:24