3 #ifndef DUNE_ISTL_MULTITYPEBLOCKVECTOR_HH
4 #define DUNE_ISTL_MULTITYPEBLOCKVECTOR_HH
10 #include <dune/common/dotproduct.hh>
11 #include <dune/common/ftraits.hh>
12 #include <dune/common/hybridutilities.hh>
13 #include <dune/common/typetraits.hh>
19 template <
typename... Args >
20 class MultiTypeBlockVector;
38 template <
typename Arg0,
typename... Args>
41 typedef typename FieldTraits<Arg0>::field_type
field_type;
42 typedef typename FieldTraits<Arg0>::real_type
real_type;
53 template <
typename... Args >
55 :
public std::tuple<Args...>
58 typedef std::tuple<Args...> TupleType;
67 using TupleType::TupleType;
90 return sizeof...(Args);
97 return sizeof...(Args);
103 int count() const DUNE_DEPRECATED_MSG("Use method '
N' instead")
105 return sizeof...(Args);
112 Hybrid::forEach(std::make_index_sequence<
N()>{},
113 [&](
auto i){result += std::get<i>(*this).dim();});
136 template<
size_type index >
137 typename std::tuple_element<index,TupleType>::type&
138 operator[] (
const std::integral_constant< size_type, index > indexVariable )
140 DUNE_UNUSED_PARAMETER(indexVariable);
141 return std::get<index>(*
this);
149 template<
size_type index >
150 const typename std::tuple_element<index,TupleType>::type&
151 operator[] (
const std::integral_constant< size_type, index > indexVariable )
const
153 DUNE_UNUSED_PARAMETER(indexVariable);
154 return std::get<index>(*
this);
161 Dune::Hybrid::forEach(*
this, [&](
auto&& entry) {
170 using namespace Dune::Hybrid;
171 forEach(integralRange(Hybrid::size(*
this)), [&](
auto&& i) {
172 (*this)[i] += newv[i];
180 using namespace Dune::Hybrid;
181 forEach(integralRange(Hybrid::size(*
this)), [&](
auto&& i) {
182 (*this)[i] -= newv[i];
188 std::enable_if_t< IsNumber<T>::value,
int> = 0>
190 Hybrid::forEach(*
this, [&](
auto&& entry) {
197 std::enable_if_t< IsNumber<T>::value,
int> = 0>
199 Hybrid::forEach(*
this, [&](
auto&& entry) {
205 using namespace Dune::Hybrid;
206 return accumulate(integralRange(Hybrid::size(*
this)),
field_type(0), [&](
auto&& a,
auto&& i) {
207 return a + (*this)[i]*newv[i];
212 using namespace Dune::Hybrid;
213 return accumulate(integralRange(Hybrid::size(*
this)),
field_type(0), [&](
auto&& a,
auto&& i) {
214 return a + (*this)[i].dot(newv[i]);
221 using namespace Dune::Hybrid;
222 return accumulate(*
this,
typename FieldTraits<field_type>::real_type(0), [&](
auto&& a,
auto&& entry) {
223 return a + entry.one_norm();
230 using namespace Dune::Hybrid;
231 return accumulate(*
this,
typename FieldTraits<field_type>::real_type(0), [&](
auto&& a,
auto&& entry) {
232 return a + entry.one_norm_real();
238 typename FieldTraits<field_type>::real_type
two_norm2()
const {
239 using namespace Dune::Hybrid;
240 return accumulate(*
this,
typename FieldTraits<field_type>::real_type(0), [&](
auto&& a,
auto&& entry) {
241 return a + entry.two_norm2();
253 using namespace Dune::Hybrid;
255 using real_type =
typename FieldTraits<field_type>::real_type;
257 real_type result = 0.0;
260 ifElse(HasNaN<field_type>(), [&](
auto&&
id) {
262 real_type nanTracker = 1.0;
263 using namespace Dune::Hybrid;
264 forEach(*
this, [&](
auto&& entry) {
265 real_type entryNorm = entry.infinity_norm();
266 result = max(entryNorm, result);
267 nanTracker += entryNorm;
270 result *= (nanTracker / nanTracker);
272 using namespace Dune::Hybrid;
273 forEach(*
this, [&](
auto&& entry) {
274 result = max(entry.infinity_norm(), result);
284 using namespace Dune::Hybrid;
286 using real_type =
typename FieldTraits<field_type>::real_type;
288 real_type result = 0.0;
291 ifElse(HasNaN<field_type>(), [&](
auto&&
id) {
293 real_type nanTracker = 1.0;
294 using namespace Dune::Hybrid;
295 forEach(*
this, [&](
auto&& entry) {
296 real_type entryNorm = entry.infinity_norm_real();
297 result = max(entryNorm, result);
298 nanTracker += entryNorm;
301 result *= (nanTracker / nanTracker);
303 using namespace Dune::Hybrid;
304 forEach(*
this, [&](
auto&& entry) {
305 result = max(entry.infinity_norm_real(), result);
315 template<
typename Ta>
317 using namespace Dune::Hybrid;
318 forEach(integralRange(Hybrid::size(*
this)), [&](
auto&& i) {
319 (*this)[i].axpy(a, y[i]);
329 template <
typename... Args>
331 using namespace Dune::Hybrid;
332 forEach(integralRange(Dune::Hybrid::size(v)), [&](
auto&& i) {
333 s <<
"\t(" << i <<
"):\n" << v[i] <<
"\n";
Simple iterative methods like Jacobi, Gauss-Seidel, SOR, SSOR, etc. in a generic way.
FieldTraits< Arg0 >::field_type field_type
Definition: multitypeblockvector.hh:41
FieldTraits< Arg0 >::real_type real_type
Definition: multitypeblockvector.hh:42
void operator=(const T &newval)
Assignment operator.
Definition: multitypeblockvector.hh:160
std::size_t size_type
Type used for vector sizes.
Definition: multitypeblockvector.hh:62
int count() const
Definition: multitypeblockvector.hh:103
std::tuple_element< index, TupleType >::type & operator[](const std::integral_constant< size_type, index > indexVariable)
Random-access operator.
Definition: multitypeblockvector.hh:138
static constexpr size_type N()
Number of elements.
Definition: multitypeblockvector.hh:95
static constexpr size_type size()
Return the number of non-zero vector entries.
Definition: multitypeblockvector.hh:88
size_type dim() const
Number of scalar elements.
Definition: multitypeblockvector.hh:109
field_type dot(const type &newv) const
Definition: multitypeblockvector.hh:211
void operator*=(const T &w)
Multiplication with a scalar.
Definition: multitypeblockvector.hh:189
void axpy(const Ta &a, const type &y)
Axpy operation on this vector (*this += a * y)
Definition: multitypeblockvector.hh:316
void operator/=(const T &w)
Division by a scalar.
Definition: multitypeblockvector.hh:198
MultiTypeBlockVector< Args... > type
Definition: multitypeblockvector.hh:72
auto one_norm() const
Compute the 1-norm.
Definition: multitypeblockvector.hh:220
void operator-=(const type &newv)
Definition: multitypeblockvector.hh:179
FieldTraits< field_type >::real_type infinity_norm_real() const
Compute the simplified maximum norm (uses 1-norm for complex values)
Definition: multitypeblockvector.hh:282
field_type operator*(const type &newv) const
Definition: multitypeblockvector.hh:204
FieldTraits< field_type >::real_type infinity_norm() const
Compute the maximum norm.
Definition: multitypeblockvector.hh:251
void operator+=(const type &newv)
Definition: multitypeblockvector.hh:169
FieldTraits< field_type >::real_type two_norm2() const
Compute the squared Euclidean norm.
Definition: multitypeblockvector.hh:238
FieldTraits< field_type >::real_type two_norm() const
Compute the Euclidean norm.
Definition: multitypeblockvector.hh:247
auto one_norm_real() const
Compute the simplified 1-norm (uses 1-norm also for complex values)
Definition: multitypeblockvector.hh:229
double field_type
The type used for scalars.
Definition: multitypeblockvector.hh:81
Definition: allocator.hh:7
std::ostream & operator<<(std::ostream &s, const BlockVector< K, A > &v)
Send BlockVector to an output stream.
Definition: bvector.hh:650
A Vector class to support different block types.
Definition: multitypeblockvector.hh:56