deal.II version 9.8.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
type_traits.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2019 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#ifndef dealii_matrix_free_type_traits_h
15#define dealii_matrix_free_type_traits_h
16
17// various type-traits used exclusively within the matrix-free framework
18
19#include <deal.II/base/config.h>
20
22
24
25
27
28#ifndef DOXYGEN
29
30namespace internal
31{
32 //
33 // type traits for FEEvaluation
34 //
35
36 // a helper type-trait leveraging SFINAE to figure out if type T has
37 // ... T::local_element() const
38 template <typename T>
39 using local_element_t = decltype(std::declval<const T>().local_element(0));
40
41 template <typename T>
42 constexpr bool has_local_element = is_supported_operation<local_element_t, T>;
43
44
45
46 // a helper type-trait leveraging SFINAE to figure out if type T has
47 // void T::add_local_element(const uint, const typename T::value_type)
48 template <typename T>
49 using add_local_element_t =
50 decltype(std::declval<T>().add_local_element(0, typename T::value_type()));
51
52 template <typename T>
53 constexpr bool has_add_local_element =
55
56
57
58 // a helper type-trait leveraging SFINAE to figure out if type T has
59 // void T::set_local_element(const uint, const typename T::value_type)
60 template <typename T>
61 using set_local_element_t =
62 decltype(std::declval<T>().set_local_element(0, typename T::value_type()));
63
64 template <typename T>
65 constexpr bool has_set_local_element =
67
68
69 // same as above to check
70 // bool T::partitioners_are_compatible(const Utilities::MPI::Partitioner &)
71 // const
72 template <typename T>
73 using partitioners_are_compatible_t =
74 decltype(std::declval<const T>().partitioners_are_compatible(
75 std::declval<Utilities::MPI::Partitioner>()));
76
77 template <typename T>
78 constexpr bool has_partitioners_are_compatible =
80
81
82
83 // same as above to check
84 // ... T::begin() const
85 template <typename T>
86 using begin_t = decltype(std::declval<const T>().begin());
87
88 template <typename T>
89 constexpr bool has_begin = is_supported_operation<begin_t, T>;
90
91
92
93 // same as above to check
94 // ... T::shared_vector_data() const
95 template <typename T>
96 using shared_vector_data_t =
97 decltype(std::declval<const T>().shared_vector_data());
98
99 template <typename T>
100 constexpr bool has_shared_vector_data =
102
103
104 //
105 // type-traits for Matrix-Free
106 //
107 // similar to type traits in FEEvaluation, below we add type-traits
108 // to distinguish between vectors that provide different interface for
109 // operations like update_ghost_values(), compress(), etc.
110 // see internal::has_local_element in fe_evaluation.h that documents
111 // how those type traits work.
112
113 // a helper type-trait that leverage SFINAE to figure out if type T has
114 // void T::update_ghost_values_start(const uint) const
115 template <typename T>
116 using update_ghost_values_start_t =
117 decltype(std::declval<const T>().update_ghost_values_start(0));
118
119 template <typename T>
120 constexpr bool has_update_ghost_values_start =
122
123
124
125 // a helper type-trait that leverage SFINAE to figure out if type T has
126 // void T:: compress_start(const uint, VectorOperation::values)
127 template <typename T>
128 using compress_start_t =
129 decltype(std::declval<T>().compress_start(0, VectorOperation::add));
130
131 template <typename T>
132 constexpr bool has_compress_start =
134
135
136
137 // type trait for vector T to see if
138 // we do a custom data exchange route.
139 // We assume that if both begin() and local_element()
140 // exist, then begin() + offset == local_element(offset)
141 template <typename T>
142 constexpr bool has_exchange_on_subset =
143 has_begin<T> && has_local_element<T> && has_partitioners_are_compatible<T>;
144
145
146
147 // a helper type-trait that leverage SFINAE to figure out if type T has
148 // T & T::operator=(const T::value_type) const
149 template <typename T>
150 using assignment_operator_t =
151 decltype(std::declval<T>().operator=(typename T::value_type()));
152
153 template <typename T>
154 constexpr bool has_assignment_operator =
156
157
158
159 // a helper type-trait that leverage SFINAE to figure out if type T has
160 // T::communication_block_size
161 template <typename T>
162 using communication_block_size_t = decltype(T::communication_block_size);
163
164 template <typename T>
165 constexpr bool has_communication_block_size =
167
173 template <typename VectorType>
174 using is_vector_type = decltype(is_serial_vector<VectorType>::value);
175
180 template <typename VectorType>
181 using is_serial_vector_type =
182 decltype(std::enable_if_t<is_serial_vector<VectorType>::value, int>());
183
189 template <typename VectorType>
190 constexpr bool is_not_parallel_vector =
193
194
195
200 template <typename VectorType>
201 struct is_serial_vector_or_array
202 {
203 static const bool value =
204 is_supported_operation<is_serial_vector_type, VectorType>;
205 };
206
211 template <typename Number>
212 struct is_serial_vector_or_array<::ArrayView<Number>>
213 {
214 static const bool value = true;
215 };
216
217 // We need to have a separate declaration for static const members
218 template <typename VectorType>
219 const bool is_serial_vector_or_array<VectorType>::value;
220
221
222
223 // type trait for vector T and Number to see if
224 // we can do vectorized load/save.
225 // for VectorReader and VectorDistributorLocalToGlobal we assume that
226 // if both begin() and local_element()
227 // exist, then begin() + offset == local_element(offset)
228 template <typename T, typename Number>
229 struct is_vectorizable
230 {
231 static const bool value =
232 has_begin<T> &&
233 (has_local_element<T> || is_serial_vector_or_array<T>::value) &&
234 std::is_same_v<typename T::value_type, Number>;
235 };
236
237 // We need to have a separate declaration for static const members
238 template <typename T, typename Number>
239 const bool is_vectorizable<T, Number>::value;
240
241} // namespace internal
242#endif
243
245
246#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
const bool IsBlockVector< VectorType >::value
constexpr bool is_supported_operation