5#ifndef DUNE_FUNCTIONS_BACKENDS_ISTL_VECTORFACTORY_HH
6#define DUNE_FUNCTIONS_BACKENDS_ISTL_VECTORFACTORY_HH
10#include <dune/common/exceptions.hh>
11#include <dune/common/fvector.hh>
12#include <dune/common/indices.hh>
14#include <dune/functions/functionspacebases/containerdescriptors.hh>
16#include <dune/istl/bvector.hh>
17#include <dune/istl/multitypeblockvector.hh>
19namespace Dune::Functions {
20namespace ContainerDescriptors {
24struct ISTLVectorFactory
26 void operator() (
const Unknown& tree)
const
28 DUNE_THROW(Dune::NotImplemented,
"Cannot create a vector. The container descriptor is unknown.");
32 auto operator() (
const Tuple<V...>& tree)
const
34 return unpackIntegerSequence([&](
auto... ii) {
35 return Dune::MultiTypeBlockVector<
decltype((*this)(tree[ii]))...>{(*this)(tree[ii])...};
36 }, std::make_index_sequence<
sizeof...(V)>());
39 template<
class V, std::
size_t n>
40 auto operator() (
const Array<V,n>& tree)
const
42 return unpackIntegerSequence([&](
auto... ii) {
43 return Dune::BlockVector{(*this)(tree[ii])...};
44 }, std::make_index_sequence<n>());
48 auto operator() (
const Vector<V>& tree)
const
50 using W =
decltype((*this)(tree[0]));
51 Dune::BlockVector<W> result(tree.size());
52 for (std::size_t i = 0; i < tree.size(); ++i)
53 result[i] = (*
this)(tree[i]);
57 template<
class V, std::
size_t n>
58 auto operator() (
const UniformArray<V,n>& tree)
const
60 auto node = (*this)(tree[0]);
61 return unpackIntegerSequence([&](
auto... ii) {
62 return Dune::BlockVector{((void)(ii),node)...};
63 }, std::make_index_sequence<n>());
67 auto operator() (
const UniformVector<V>& tree)
const
69 auto node = (*this)(tree[0]);
70 using W =
decltype(node);
71 Dune::BlockVector<W> result(tree.size());
72 for (std::size_t i = 0; i < tree.size(); ++i)
79 auto operator() (
const Value& tree)
const
86 template<std::
size_t n>
87 auto operator() (
const UniformArray<Value,n>& tree)
const
89 return Dune::FieldVector<T,n>(0);
92 auto operator() (
const UniformVector<Value>& tree)
const
94 return Dune::BlockVector<T>(tree.size());
99 template<std::
size_t n>
100 auto operator() (
const UniformVector<UniformArray<Value,n>>& tree)
const
102 return Dune::BlockVector<Dune::FieldVector<T,n>>(tree.size());
105 template<std::
size_t n>
106 auto operator() (
const Vector<UniformArray<Value,n>>& tree)
const
108 return Dune::BlockVector<Dune::FieldVector<T,n>>(tree.size());
111 template<std::
size_t n, std::
size_t m>
112 auto operator() (
const Array<UniformArray<Value,n>,m>& tree)
const
114 return Dune::BlockVector<Dune::FieldVector<T,n>>(m);
130template<
class T =
double,
class ContainerDescriptor>
131auto makeISTLVector (
const ContainerDescriptor& tree)
133 auto factory = ContainerDescriptors::Impl::ISTLVectorFactory<T>{};
134 return factory(tree);