dune-pdelab 2.7-git
Loading...
Searching...
No Matches
istl/vector.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_VECTOR_HH
4#define DUNE_PDELAB_BACKEND_ISTL_VECTOR_HH
5
6#include <dune/common/fvector.hh>
7#include <dune/common/shared_ptr.hh>
8#include <dune/istl/bvector.hh>
9#include <dune/typetree/typetree.hh>
10#include <dune/functions/backends/istlvectorbackend.hh>
11
22
23namespace Dune {
24 namespace PDELab {
25 namespace ISTL {
26
27 template<typename GFS, typename C>
29 : public Backend::impl::Wrapper<C>
30 {
31
32 friend Backend::impl::Wrapper<C>;
33
34 public:
35 typedef typename C::field_type ElementType;
36 typedef ElementType E;
37 typedef C Container;
38 typedef GFS GridFunctionSpace;
39 typedef typename Container::field_type field_type;
40 typedef typename Container::block_type block_type;
41 typedef typename Container::size_type size_type;
42
43 using value_type = E;
44
45 typedef typename GFS::Ordering::Traits::ContainerIndex ContainerIndex;
46
49
50
51 template<typename LFSCache>
53
54 template<typename LFSCache>
56
57 template<typename LFSCache>
59
60 template<typename LFSCache>
62
64 : _gfs(rhs._gfs)
65 , _container(std::make_shared<Container>(_gfs->ordering().blockCount()))
66 {
67 resize();
68 (*_container) = rhs.native();
69 }
70
72 : _gfs(rhs._gfs)
73 , _container(std::move(rhs._container))
74 {}
75
77 : _gfs(gfs)
78 , _container(std::make_shared<Container>())
79 {
80 resize();
81 }
82
84 BlockVector(std::shared_ptr<const GFS> gfs, Backend::unattached_container)
85 : _gfs(gfs)
86 {}
87
93 BlockVector (std::shared_ptr<const GFS> gfs, Container& container)
94 : _gfs(gfs)
95 , _container(stackobject_to_shared_ptr(container))
96 {
97 resize();
98 }
99
100 BlockVector (std::shared_ptr<const GFS> gfs, const E& e)
101 : _gfs(gfs)
102 , _container(std::make_shared<Container>())
103 {
104 resize();
105 (*_container)=e;
106 }
107
109 : BlockVector(Dune::stackobject_to_shared_ptr(gfs), tag)
110 {}
111
114 : BlockVector(Dune::stackobject_to_shared_ptr(gfs), tag)
115 {}
116
122 BlockVector (const GFS& gfs, Container& container)
123 : BlockVector(Dune::stackobject_to_shared_ptr(gfs), container)
124 {}
125
126 BlockVector (const GFS& gfs, const E& e)
127 : BlockVector(Dune::stackobject_to_shared_ptr(gfs), e)
128 {}
129
137 void resize()
138 {
139 assert(_gfs);
140 auto b = Functions::istlVectorBackend(*_container);
141 SizeProviderAdapter size_provider{_gfs->orderingStorage()};
142 static_assert(decltype(size_provider)::ContainerIndexOrder == MultiIndexOrder::Outer2Inner);
143 b.resize(size_provider);
144 }
145
146 void detach()
147 {
148 _container.reset();
149 }
150
151 template<typename LFSCache>
152 value_type* data(const LFSCache& lfs_cache)
153 {
154 return &((*this)[lfs_cache.containerIndex(0)]);
155 }
156
157 template<typename LFSCache>
158 const value_type* data(const LFSCache& lfs_cache) const
159 {
160 return &((*this)[lfs_cache.containerIndex(0)]);
161 }
162
163 void attach(std::shared_ptr<Container> container)
164 {
165 _container = container;
166 }
167
168 bool attached() const
169 {
170 return bool(_container);
171 }
172
173 const std::shared_ptr<Container>& storage() const
174 {
175 return _container;
176 }
177
178 size_type N() const
179 {
180 return _container->N();
181 }
182
184 {
185 if (this == &r)
186 return *this;
187 if (attached())
188 {
189 (*_container) = r.native();
190 }
191 else
192 {
193 _container = std::make_shared<Container>(r.native());
194 }
195 return *this;
196 }
197
199 {
200 (*_container)=e;
201 return *this;
202 }
203
205 {
206 (*_container)*=e;
207 return *this;
208 }
209
210
212 {
213 (*_container)+=e;
214 return *this;
215 }
216
218 {
219 (*_container)+= e.native();
220 return *this;
221 }
222
224 {
225 (*_container)-= e.native();
226 return *this;
227 }
228
229 block_type& block(std::size_t i)
230 {
231 return (*_container)[i];
232 }
233
234 const block_type& block(std::size_t i) const
235 {
236 return (*_container)[i];
237 }
238
240 {
241 return ISTL::access_vector_element(ISTL::container_tag(*_container),*_container,ci,ci.size()-1);
242 }
243
244 const E& operator[](const ContainerIndex& ci) const
245 {
246 return ISTL::access_vector_element(ISTL::container_tag(*_container),*_container,ci,ci.size()-1);
247 }
248
249 typename Dune::template FieldTraits<E>::real_type two_norm2() const
250 {
251 return _container->two_norm2();
252 }
253
254 typename Dune::template FieldTraits<E>::real_type two_norm() const
255 {
256 return _container->two_norm();
257 }
258
259 typename Dune::template FieldTraits<E>::real_type one_norm() const
260 {
261 return _container->one_norm();
262 }
263
264 typename Dune::template FieldTraits<E>::real_type infinity_norm() const
265 {
266 return _container->infinity_norm();
267 }
268
269 E operator*(const BlockVector& y) const
270 {
271 return (*_container)*y.native();
272 }
273
274 E dot(const BlockVector& y) const
275 {
276 return _container->dot(y.native());
277 }
278
279 BlockVector& axpy(const E& a, const BlockVector& y)
280 {
281 _container->axpy(a, y.native());
282 return *this;
283 }
284
285 private:
286
287 // for debugging and AMG access
288 Container& native ()
289 {
290 return *_container;
291 }
292
293 const Container& native () const
294 {
295 return *_container;
296 }
297
298 public:
299
300 operator Container&()
301 {
302 return *_container;
303 }
304
305 operator const Container&() const
306 {
307 return *_container;
308 }
309
311 {
312 return iterator(*_container,false);
313 }
314
315
317 {
318 return const_iterator(*_container,false);
319 }
320
322 {
323 return iterator(*_container,true);
324 }
325
326
328 {
329 return const_iterator(*_container,true);
330 }
331
332 size_t flatsize() const
333 {
334 return _container->dim();
335 }
336
337 const GFS& gridFunctionSpace() const
338 {
339 return *_gfs;
340 }
341
342 std::shared_ptr<const GFS> gridFunctionSpaceStorage() const
343 {
344 return _gfs;
345 }
346
347 private:
348 std::shared_ptr<const GFS> _gfs;
349 std::shared_ptr<Container> _container;
350 };
351
352#ifndef DOXYGEN
353
354 // helper struct invoking the GFS tree -> ISTL vector reduction
355 template<typename GFS, typename E>
356 struct BlockVectorSelectorHelper
357 {
358
359 typedef typename TypeTree::AccumulateType<
360 GFS,
361 ISTL::vector_creation_policy<E>
362 >::type vector_descriptor;
363
364 typedef BlockVector<GFS,typename vector_descriptor::vector_type> Type;
365
366 };
367
368#endif // DOXYGEN
369
370 // can't have the closing of the namespace inside the #ifndef DOXYGEN block
371 } // namespace ISTL
372
373#ifndef DOXYGEN
374
375 namespace Backend {
376 namespace impl {
377
378 template<Dune::PDELab::ISTL::Blocking blocking, std::size_t block_size, typename GFS, typename E>
379 struct BackendVectorSelectorHelper<ISTL::VectorBackend<blocking,block_size>, GFS, E>
380 : public ISTL::BlockVectorSelectorHelper<GFS,E>
381 {};
382
383 } // namespace impl
384 } // namespace Backend
385
386#endif // DOXYGEN
387
388 } // namespace PDELab
389} // namespace Dune
390
391#endif // DUNE_PDELAB_BACKEND_ISTL_VECTOR_HH
@ Outer2Inner
indices are ordered from outer to inner container: {outer,...,inner}
STL namespace.
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
tags::container< T >::type container_tag(const T &)
Gets instance of container tag associated with T.
Definition: backend/istl/tags.hh:234
Definition: aliasedvectorview.hh:18
Definition: aliasedvectorview.hh:128
Tag for requesting a vector or matrix container without a pre-attached underlying object.
Definition: backend/common/tags.hh:24
Tag for requesting a vector or matrix container with a pre-attached underlying object.
Definition: backend/common/tags.hh:28
Definition: uncachedvectorview.hh:18
Definition: uncachedvectorview.hh:149
Definition: istl/vector.hh:30
const value_type * data(const LFSCache &lfs_cache) const
Definition: istl/vector.hh:158
C::field_type ElementType
Definition: istl/vector.hh:35
const std::shared_ptr< Container > & storage() const
Definition: istl/vector.hh:173
block_type & block(std::size_t i)
Definition: istl/vector.hh:229
BlockVector(std::shared_ptr< const GFS > gfs, Container &container)
Constructs an BlockVector for an explicitly given vector object.
Definition: istl/vector.hh:93
BlockVector(const BlockVector &rhs)
Definition: istl/vector.hh:63
Dune::template FieldTraits< E >::real_type one_norm() const
Definition: istl/vector.hh:259
void detach()
Definition: istl/vector.hh:146
size_t flatsize() const
Definition: istl/vector.hh:332
const block_type & block(std::size_t i) const
Definition: istl/vector.hh:234
BlockVector(const GFS &gfs, Container &container)
Constructs an BlockVector for an explicitly given vector object.
Definition: istl/vector.hh:122
BlockVector & operator-=(const BlockVector &e)
Definition: istl/vector.hh:223
GFS::Ordering::Traits::ContainerIndex ContainerIndex
Definition: istl/vector.hh:45
ElementType E
Definition: istl/vector.hh:36
std::shared_ptr< const GFS > gridFunctionSpaceStorage() const
Definition: istl/vector.hh:342
BlockVector(const GFS &gfs, Backend::attached_container tag=Backend::attached_container())
Definition: istl/vector.hh:108
const_iterator begin() const
Definition: istl/vector.hh:316
BlockVector(std::shared_ptr< const GFS > gfs, Backend::unattached_container)
Creates an BlockVector without allocating an underlying ISTL vector.
Definition: istl/vector.hh:84
iterator end()
Definition: istl/vector.hh:321
size_type N() const
Definition: istl/vector.hh:178
C Container
Definition: istl/vector.hh:37
bool attached() const
Definition: istl/vector.hh:168
Dune::template FieldTraits< E >::real_type two_norm() const
Definition: istl/vector.hh:254
E dot(const BlockVector &y) const
Definition: istl/vector.hh:274
ISTL::vector_iterator< C > iterator
Definition: istl/vector.hh:47
BlockVector(std::shared_ptr< const GFS > gfs, Backend::attached_container=Backend::attached_container())
Definition: istl/vector.hh:76
void resize()
Resize container for a given function space ordering.
Definition: istl/vector.hh:137
value_type * data(const LFSCache &lfs_cache)
Definition: istl/vector.hh:152
BlockVector(std::shared_ptr< const GFS > gfs, const E &e)
Definition: istl/vector.hh:100
const E & operator[](const ContainerIndex &ci) const
Definition: istl/vector.hh:244
Dune::template FieldTraits< E >::real_type two_norm2() const
Definition: istl/vector.hh:249
BlockVector & operator+=(const E &e)
Definition: istl/vector.hh:211
ISTL::vector_iterator< const C > const_iterator
Definition: istl/vector.hh:48
const GFS & gridFunctionSpace() const
Definition: istl/vector.hh:337
GFS GridFunctionSpace
Definition: istl/vector.hh:38
iterator begin()
Definition: istl/vector.hh:310
Container::field_type field_type
Definition: istl/vector.hh:39
BlockVector & operator=(const BlockVector &r)
Definition: istl/vector.hh:183
Container::block_type block_type
Definition: istl/vector.hh:40
E operator*(const BlockVector &y) const
Definition: istl/vector.hh:269
BlockVector & axpy(const E &a, const BlockVector &y)
Definition: istl/vector.hh:279
BlockVector(BlockVector &&rhs)
Definition: istl/vector.hh:71
BlockVector(const GFS &gfs, const E &e)
Definition: istl/vector.hh:126
E value_type
Definition: istl/vector.hh:43
BlockVector(const GFS &gfs, Backend::unattached_container tag)
Creates an BlockVector without allocating an underlying ISTL vector.
Definition: istl/vector.hh:113
BlockVector & operator*=(const E &e)
Definition: istl/vector.hh:204
void attach(std::shared_ptr< Container > container)
Definition: istl/vector.hh:163
Dune::template FieldTraits< E >::real_type infinity_norm() const
Definition: istl/vector.hh:264
E & operator[](const ContainerIndex &ci)
Definition: istl/vector.hh:239
Container::size_type size_type
Definition: istl/vector.hh:41
const_iterator end() const
Definition: istl/vector.hh:327
Definition: vectoriterator.hh:113
Adapter to create a size provider from an ordering.
Definition: ordering/utility.hh:363
Various tags for influencing backend behavior.