Dune Core Modules (2.8.0)

bvector.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
4#ifndef DUNE_ISTL_BVECTOR_HH
5#define DUNE_ISTL_BVECTOR_HH
6
7#include <algorithm>
8#include <cmath>
9#include <complex>
10#include <initializer_list>
11#include <limits>
12#include <memory>
13#include <utility>
14#include <vector>
15
23
25
26#include "basearray.hh"
27#include "istlexception.hh"
28
36namespace Dune {
37
39namespace Imp {
40
46 template <class B, bool isNumber>
47 class BlockTraitsImp;
48
49 template <class B>
50 class BlockTraitsImp<B,true>
51 {
52 public:
53 using field_type = B;
54 };
55
56 template <class B>
57 class BlockTraitsImp<B,false>
58 {
59 public:
60 using field_type = typename B::field_type;
61 };
62
65 template <class B>
66 using BlockTraits = BlockTraitsImp<B,IsNumber<B>::value>;
67
81 template<class B, class A=std::allocator<B> >
82 class block_vector_unmanaged : public base_array_unmanaged<B,A>
83 {
84 public:
85
86 //===== type definitions and constants
87 using field_type = typename Imp::BlockTraits<B>::field_type;
88
90 typedef B block_type;
91
93 typedef A allocator_type;
94
96 typedef typename A::size_type size_type;
97
99 typedef typename base_array_unmanaged<B,A>::iterator Iterator;
100
102 typedef typename base_array_unmanaged<B,A>::const_iterator ConstIterator;
103
105 typedef B value_type;
106
108 typedef B& reference;
109
111 typedef const B& const_reference;
112
113 //===== assignment from scalar
115
116 block_vector_unmanaged& operator= (const field_type& k)
117 {
118 for (size_type i=0; i<this->n; i++)
119 (*this)[i] = k;
120 return *this;
121 }
122
123 //===== vector space arithmetic
125 block_vector_unmanaged& operator+= (const block_vector_unmanaged& y)
126 {
127#ifdef DUNE_ISTL_WITH_CHECKING
128 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
129#endif
130 for (size_type i=0; i<this->n; ++i) (*this)[i] += y[i];
131 return *this;
132 }
133
135 block_vector_unmanaged& operator-= (const block_vector_unmanaged& y)
136 {
137#ifdef DUNE_ISTL_WITH_CHECKING
138 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
139#endif
140 for (size_type i=0; i<this->n; ++i) (*this)[i] -= y[i];
141 return *this;
142 }
143
145 block_vector_unmanaged& operator*= (const field_type& k)
146 {
147 for (size_type i=0; i<this->n; ++i) (*this)[i] *= k;
148 return *this;
149 }
150
152 block_vector_unmanaged& operator/= (const field_type& k)
153 {
154 for (size_type i=0; i<this->n; ++i) (*this)[i] /= k;
155 return *this;
156 }
157
159 block_vector_unmanaged& axpy (const field_type& a, const block_vector_unmanaged& y)
160 {
161#ifdef DUNE_ISTL_WITH_CHECKING
162 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
163#endif
164 for (size_type i=0; i<this->n; ++i)
165 Impl::asVector((*this)[i]).axpy(a,Impl::asVector(y[i]));
166
167 return *this;
168 }
169
170
178 template<class OtherB, class OtherA>
179 auto operator* (const block_vector_unmanaged<OtherB,OtherA>& y) const
180 {
181 typedef typename PromotionTraits<field_type,typename BlockTraits<OtherB>::field_type>::PromotedType PromotedType;
182 PromotedType sum(0);
183#ifdef DUNE_ISTL_WITH_CHECKING
184 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
185#endif
186 for (size_type i=0; i<this->n; ++i) {
187 sum += PromotedType(((*this)[i])*y[i]);
188 }
189 return sum;
190 }
191
199 template<class OtherB, class OtherA>
200 auto dot(const block_vector_unmanaged<OtherB,OtherA>& y) const
201 {
202 typedef typename PromotionTraits<field_type,typename BlockTraits<OtherB>::field_type>::PromotedType PromotedType;
203 PromotedType sum(0);
204#ifdef DUNE_ISTL_WITH_CHECKING
205 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
206#endif
207
208 for (size_type i=0; i<this->n; ++i)
209 sum += Impl::asVector((*this)[i]).dot(Impl::asVector(y[i]));
210
211 return sum;
212 }
213
214 //===== norms
215
217 typename FieldTraits<field_type>::real_type one_norm () const
218 {
219 typename FieldTraits<field_type>::real_type sum=0;
220 for (size_type i=0; i<this->n; ++i)
221 sum += Impl::asVector((*this)[i]).one_norm();
222 return sum;
223 }
224
226 typename FieldTraits<field_type>::real_type one_norm_real () const
227 {
228 typename FieldTraits<field_type>::real_type sum=0;
229 for (size_type i=0; i<this->n; ++i)
230 sum += Impl::asVector((*this)[i]).one_norm_real();
231 return sum;
232 }
233
235 typename FieldTraits<field_type>::real_type two_norm () const
236 {
237 using std::sqrt;
238 return sqrt(two_norm2());
239 }
240
242 typename FieldTraits<field_type>::real_type two_norm2 () const
243 {
244 typename FieldTraits<field_type>::real_type sum=0;
245 for (size_type i=0; i<this->n; ++i)
246 sum += Impl::asVector((*this)[i]).two_norm2();
247 return sum;
248 }
249
251 template <typename ft = field_type,
252 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
253 typename FieldTraits<ft>::real_type infinity_norm() const {
254 using real_type = typename FieldTraits<ft>::real_type;
255 using std::max;
256
257 real_type norm = 0;
258 for (auto const &xi : *this) {
259 real_type const a = Impl::asVector(xi).infinity_norm();
260 norm = max(a, norm);
261 }
262 return norm;
263 }
264
266 template <typename ft = field_type,
267 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
268 typename FieldTraits<ft>::real_type infinity_norm_real() const {
269 using real_type = typename FieldTraits<ft>::real_type;
270 using std::max;
271
272 real_type norm = 0;
273 for (auto const &xi : *this) {
274 real_type const a = Impl::asVector(xi).infinity_norm_real();
275 norm = max(a, norm);
276 }
277 return norm;
278 }
279
281 template <typename ft = field_type,
282 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
283 typename FieldTraits<ft>::real_type infinity_norm() const {
284 using real_type = typename FieldTraits<ft>::real_type;
285 using std::max;
286 using std::abs;
287
288 real_type norm = 0;
289 real_type isNaN = 1;
290
291 for (auto const &xi : *this) {
292 real_type const a = Impl::asVector(xi).infinity_norm();
293 norm = max(a, norm);
294 isNaN += a;
295 }
296 return norm * (isNaN / isNaN);
297 }
298
300 template <typename ft = field_type,
301 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
302 typename FieldTraits<ft>::real_type infinity_norm_real() const {
303 using real_type = typename FieldTraits<ft>::real_type;
304 using std::max;
305
306 real_type norm = 0;
307 real_type isNaN = 1;
308
309 for (auto const &xi : *this) {
310 real_type const a = Impl::asVector(xi).infinity_norm_real();
311 norm = max(a, norm);
312 isNaN += a;
313 }
314
315 return norm * (isNaN / isNaN);
316 }
317
318 //===== sizes
319
321 size_type N () const
322 {
323 return this->n;
324 }
325
327 size_type dim () const
328 {
329 size_type d=0;
330
331 for (size_type i=0; i<this->n; i++)
332 d += Impl::asVector((*this)[i]).dim();
333
334 return d;
335 }
336
337 protected:
339 block_vector_unmanaged () : base_array_unmanaged<B,A>()
340 { }
341 };
342
344
349 template<class F>
350 class ScopeGuard {
351 F cleanupFunc_;
352 public:
353 ScopeGuard(F cleanupFunc) : cleanupFunc_(std::move(cleanupFunc)) {}
354 ScopeGuard(const ScopeGuard &) = delete;
355 ScopeGuard(ScopeGuard &&) = delete;
356 ScopeGuard &operator=(ScopeGuard) = delete;
357 ~ScopeGuard() { cleanupFunc_(); }
358 };
359
361
370 template<class F>
371 ScopeGuard<F> makeScopeGuard(F cleanupFunc)
372 {
373 return { std::move(cleanupFunc) };
374 }
375
376} // end namespace Imp
391 template<class B, class A=std::allocator<B> >
392 class BlockVector : public Imp::block_vector_unmanaged<B,A>
393 {
394 public:
395
396 //===== type definitions and constants
397
399 using field_type = typename Imp::BlockTraits<B>::field_type;
400
402 typedef B block_type;
403
405 typedef A allocator_type;
406
408 typedef typename A::size_type size_type;
409
411 [[deprecated("Use free function blockLevel(). Will be removed after 2.8.")]]
412 static constexpr unsigned int blocklevel = blockLevel<B>()+1;
413
415 typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator;
416
418 typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
419
420 //===== constructors and such
421
424 {
425 syncBaseArray();
426 }
427
429 explicit BlockVector (size_type _n) : storage_(_n)
430 {
431 syncBaseArray();
432 }
433
435 BlockVector (std::initializer_list<B> const &l) : storage_(l)
436 {
437 syncBaseArray();
438 }
439
440
452 template<typename S>
453 BlockVector (size_type _n, S _capacity)
454 {
455 static_assert(std::numeric_limits<S>::is_integer,
456 "capacity must be an unsigned integral type (be aware, that this constructor does not set the default value!)" );
457 if((size_type)_capacity > _n)
458 storage_.reserve(_capacity);
459 storage_.resize(_n);
460 syncBaseArray();
461 }
462
463
474 {
475 [[maybe_unused]] const auto &guard =
476 Imp::makeScopeGuard([this]{ syncBaseArray(); });
477 storage_.reserve(capacity);
478 }
479
487 {
488 return storage_.capacity();
489 }
490
501 void resize(size_type size)
502 {
503 [[maybe_unused]] const auto &guard =
504 Imp::makeScopeGuard([this]{ syncBaseArray(); });
505 storage_.resize(size);
506 }
507
510 noexcept(noexcept(std::declval<BlockVector>().storage_ = a.storage_))
511 {
512 storage_ = a.storage_;
513 syncBaseArray();
514 }
515
518 noexcept(noexcept(std::declval<BlockVector>().swap(a)))
519 {
520 swap(a);
521 }
522
525 noexcept(noexcept(std::declval<BlockVector>().storage_ = a.storage_))
526 {
527 [[maybe_unused]] const auto &guard =
528 Imp::makeScopeGuard([this]{ syncBaseArray(); });
529 storage_ = a.storage_;
530 return *this;
531 }
532
535 noexcept(noexcept(std::declval<BlockVector>().swap(a)))
536 {
537 swap(a);
538 return *this;
539 }
540
542 void swap(BlockVector &other)
543 noexcept(noexcept(
544 std::declval<BlockVector&>().storage_.swap(other.storage_)))
545 {
546 [[maybe_unused]] const auto &guard = Imp::makeScopeGuard([&]{
547 syncBaseArray();
548 other.syncBaseArray();
549 });
550 storage_.swap(other.storage_);
551 }
552
555 {
556 // forward to operator= in base class
557 (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k;
558 return *this;
559 }
560
561 private:
562 void syncBaseArray() noexcept
563 {
564 this->p = storage_.data();
565 this->n = storage_.size();
566 }
567
568 std::vector<B, A> storage_;
569 };
570
576 template<class B, class A>
577 struct FieldTraits< BlockVector<B, A> >
578 {
579 typedef typename FieldTraits<B>::field_type field_type;
580 typedef typename FieldTraits<B>::real_type real_type;
581 };
587 template<class K, class A>
588 std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
589 {
590 typedef typename BlockVector<K, A>::size_type size_type;
591
592 for (size_type i=0; i<v.size(); i++)
593 s << v[i] << std::endl;
594
595 return s;
596 }
597
599namespace Imp {
600
619#ifndef DOXYGEN
620 template<class B, class A>
621#else
622 template<class B, class A=std::allocator<B> >
623#endif
624 class BlockVectorWindow : public Imp::block_vector_unmanaged<B,A>
625 {
626 public:
627
628 //===== type definitions and constants
629
631 using field_type = typename Imp::BlockTraits<B>::field_type;
632
634 typedef B block_type;
635
637 typedef A allocator_type;
638
640 typedef typename A::size_type size_type;
641
643 [[deprecated("Use free function blockLevel(). Will be removed after 2.8.")]]
644 static constexpr unsigned int blocklevel = blockLevel<B>()+1;
645
647 typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator;
648
650 typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
651
652
653 //===== constructors and such
655 BlockVectorWindow () : Imp::block_vector_unmanaged<B,A>()
656 { }
657
659 BlockVectorWindow (B* _p, size_type _n)
660 {
661 this->n = _n;
662 this->p = _p;
663 }
664
666 BlockVectorWindow (const BlockVectorWindow& a)
667 {
668 this->n = a.n;
669 this->p = a.p;
670 }
671
673 BlockVectorWindow& operator= (const BlockVectorWindow& a)
674 {
675 // check correct size
676#ifdef DUNE_ISTL_WITH_CHECKING
677 if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
678#endif
679
680 if (&a!=this) // check if this and a are different objects
681 {
682 // copy data
683 for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
684 }
685 return *this;
686 }
687
689 BlockVectorWindow& operator= (const field_type& k)
690 {
691 (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k;
692 return *this;
693 }
694
696 operator BlockVector<B, A>() const {
697 auto bv = BlockVector<B, A>(this->n);
698
699 std::copy(this->begin(), this->end(), bv.begin());
700
701 return bv;
702 }
703
704 //===== window manipulation methods
705
707 void set (size_type _n, B* _p)
708 {
709 this->n = _n;
710 this->p = _p;
711 }
712
714 void setsize (size_type _n)
715 {
716 this->n = _n;
717 }
718
720 void setptr (B* _p)
721 {
722 this->p = _p;
723 }
724
726 B* getptr ()
727 {
728 return this->p;
729 }
730
732 size_type getsize () const
733 {
734 return this->n;
735 }
736 };
737
738
739
750 template<class B, class A=std::allocator<B> >
751 class compressed_block_vector_unmanaged : public compressed_base_array_unmanaged<B,A>
752 {
753 public:
754
755 //===== type definitions and constants
756
758 using field_type = typename Imp::BlockTraits<B>::field_type;
759
761 typedef B block_type;
762
764 typedef A allocator_type;
765
767 typedef typename compressed_base_array_unmanaged<B,A>::iterator Iterator;
768
770 typedef typename compressed_base_array_unmanaged<B,A>::const_iterator ConstIterator;
771
773 typedef typename A::size_type size_type;
774
775 //===== assignment from scalar
776
777 compressed_block_vector_unmanaged& operator= (const field_type& k)
778 {
779 for (size_type i=0; i<this->n; i++)
780 (this->p)[i] = k;
781 return *this;
782 }
783
784
785 //===== vector space arithmetic
786
788 template<class V>
789 compressed_block_vector_unmanaged& operator+= (const V& y)
790 {
791#ifdef DUNE_ISTL_WITH_CHECKING
792 if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
793#endif
794 for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) += y.p[i];
795 return *this;
796 }
797
799 template<class V>
800 compressed_block_vector_unmanaged& operator-= (const V& y)
801 {
802#ifdef DUNE_ISTL_WITH_CHECKING
803 if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
804#endif
805 for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) -= y.p[i];
806 return *this;
807 }
808
810 template<class V>
811 compressed_block_vector_unmanaged& axpy (const field_type& a, const V& y)
812 {
813#ifdef DUNE_ISTL_WITH_CHECKING
814 if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
815#endif
816 for (size_type i=0; i<y.n; ++i)
817 Impl::asVector((*this)[y.j[i]]).axpy(a,Impl::asVector(y.p[i]));
818 return *this;
819 }
820
822 compressed_block_vector_unmanaged& operator*= (const field_type& k)
823 {
824 for (size_type i=0; i<this->n; ++i) (this->p)[i] *= k;
825 return *this;
826 }
827
829 compressed_block_vector_unmanaged& operator/= (const field_type& k)
830 {
831 for (size_type i=0; i<this->n; ++i) (this->p)[i] /= k;
832 return *this;
833 }
834
835
836 //===== Euclidean scalar product
837
839 field_type operator* (const compressed_block_vector_unmanaged& y) const
840 {
841#ifdef DUNE_ISTL_WITH_CHECKING
842 if (!includesindexset(y) || !y.includesindexset(*this) )
843 DUNE_THROW(ISTLError,"index set mismatch");
844#endif
845 field_type sum=0;
846 for (size_type i=0; i<this->n; ++i)
847 sum += (this->p)[i] * y[(this->j)[i]];
848 return sum;
849 }
850
851
852 //===== norms
853
855 typename FieldTraits<field_type>::real_type one_norm () const
856 {
857 typename FieldTraits<field_type>::real_type sum=0;
858 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm();
859 return sum;
860 }
861
863 typename FieldTraits<field_type>::real_type one_norm_real () const
864 {
865 typename FieldTraits<field_type>::real_type sum=0;
866 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm_real();
867 return sum;
868 }
869
871 typename FieldTraits<field_type>::real_type two_norm () const
872 {
873 using std::sqrt;
874 typename FieldTraits<field_type>::real_type sum=0;
875 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
876 return sqrt(sum);
877 }
878
880 typename FieldTraits<field_type>::real_type two_norm2 () const
881 {
882 typename FieldTraits<field_type>::real_type sum=0;
883 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
884 return sum;
885 }
886
888 template <typename ft = field_type,
889 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
890 typename FieldTraits<ft>::real_type infinity_norm() const {
891 using real_type = typename FieldTraits<ft>::real_type;
892 using std::max;
893
894 real_type norm = 0;
895 for (auto const &x : *this) {
896 real_type const a = x.infinity_norm();
897 norm = max(a, norm);
898 }
899 return norm;
900 }
901
903 template <typename ft = field_type,
904 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
905 typename FieldTraits<ft>::real_type infinity_norm_real() const {
906 using real_type = typename FieldTraits<ft>::real_type;
907 using std::max;
908
909 real_type norm = 0;
910 for (auto const &x : *this) {
911 real_type const a = x.infinity_norm_real();
912 norm = max(a, norm);
913 }
914 return norm;
915 }
916
918 template <typename ft = field_type,
919 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
920 typename FieldTraits<ft>::real_type infinity_norm() const {
921 using real_type = typename FieldTraits<ft>::real_type;
922 using std::max;
923
924 real_type norm = 0;
925 real_type isNaN = 1;
926 for (auto const &x : *this) {
927 real_type const a = x.infinity_norm();
928 norm = max(a, norm);
929 isNaN += a;
930 }
931 return norm * (isNaN / isNaN);
932 }
933
935 template <typename ft = field_type,
936 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
937 typename FieldTraits<ft>::real_type infinity_norm_real() const {
938 using real_type = typename FieldTraits<ft>::real_type;
939 using std::max;
940
941 real_type norm = 0;
942 real_type isNaN = 1;
943 for (auto const &x : *this) {
944 real_type const a = x.infinity_norm_real();
945 norm = max(a, norm);
946 isNaN += a;
947 }
948 return norm * (isNaN / isNaN);
949 }
950
951 //===== sizes
952
954 size_type N () const
955 {
956 return this->n;
957 }
958
960 size_type dim () const
961 {
962 size_type d=0;
963 for (size_type i=0; i<this->n; i++)
964 d += (this->p)[i].dim();
965 return d;
966 }
967
968 protected:
970 compressed_block_vector_unmanaged () : compressed_base_array_unmanaged<B,A>()
971 { }
972
974 template<class V>
975 bool includesindexset (const V& y)
976 {
977 typename V::ConstIterator e=this->end();
978 for (size_type i=0; i<y.n; i++)
979 if (this->find(y.j[i])==e)
980 return false;
981 return true;
982 }
983 };
984
985
1004 template<class B, class A=std::allocator<B> >
1005 class CompressedBlockVectorWindow : public compressed_block_vector_unmanaged<B,A>
1006 {
1007 public:
1008
1009 //===== type definitions and constants
1010
1012 using field_type = typename Imp::BlockTraits<B>::field_type;
1013
1015 typedef B block_type;
1016
1018 typedef A allocator_type;
1019
1021 typedef typename A::size_type size_type;
1022
1024 [[deprecated("Use free function blockLevel(). Will be removed after 2.8.")]]
1025 static constexpr unsigned int blocklevel = blockLevel<B>()+1;
1026
1028 typedef typename compressed_block_vector_unmanaged<B,A>::Iterator Iterator;
1029
1031 typedef typename compressed_block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
1032
1033
1034 //===== constructors and such
1036 CompressedBlockVectorWindow () : compressed_block_vector_unmanaged<B,A>()
1037 { }
1038
1040 CompressedBlockVectorWindow (B* _p, size_type* _j, size_type _n)
1041 {
1042 this->n = _n;
1043 this->p = _p;
1044 this->j = _j;
1045 }
1046
1048 CompressedBlockVectorWindow (const CompressedBlockVectorWindow& a)
1049 {
1050 this->n = a.n;
1051 this->p = a.p;
1052 this->j = a.j;
1053 }
1054
1056 CompressedBlockVectorWindow& operator= (const CompressedBlockVectorWindow& a)
1057 {
1058 // check correct size
1059#ifdef DUNE_ISTL_WITH_CHECKING
1060 if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
1061#endif
1062
1063 if (&a!=this) // check if this and a are different objects
1064 {
1065 // copy data
1066 for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
1067 for (size_type i=0; i<this->n; i++) this->j[i]=a.j[i];
1068 }
1069 return *this;
1070 }
1071
1073 CompressedBlockVectorWindow& operator= (const field_type& k)
1074 {
1075 (static_cast<compressed_block_vector_unmanaged<B,A>&>(*this)) = k;
1076 return *this;
1077 }
1078
1079
1080 //===== window manipulation methods
1081
1083 void set (size_type _n, B* _p, size_type* _j)
1084 {
1085 this->n = _n;
1086 this->p = _p;
1087 this->j = _j;
1088 }
1089
1091 void setsize (size_type _n)
1092 {
1093 this->n = _n;
1094 }
1095
1097 void setptr (B* _p)
1098 {
1099 this->p = _p;
1100 }
1101
1103 void setindexptr (size_type* _j)
1104 {
1105 this->j = _j;
1106 }
1107
1109 B* getptr ()
1110 {
1111 return this->p;
1112 }
1113
1115 size_type* getindexptr ()
1116 {
1117 return this->j;
1118 }
1119
1121 const B* getptr () const
1122 {
1123 return this->p;
1124 }
1125
1127 const size_type* getindexptr () const
1128 {
1129 return this->j;
1130 }
1132 size_type getsize () const
1133 {
1134 return this->n;
1135 }
1136 };
1137
1138} // end namespace 'Imp'
1139
1140
1142 template<typename B, typename A>
1143 struct AutonomousValueType<Imp::BlockVectorWindow<B,A>>
1144 {
1145 using type = BlockVector<B, A>;
1146 };
1147
1148
1149} // end namespace 'Dune'
1150
1151#endif
Implements several basic array containers.
Helper functions for determining the vector/matrix block level.
A vector of blocks with memory management.
Definition: bvector.hh:393
BlockVector()
makes empty vector
Definition: bvector.hh:423
void reserve(size_type capacity)
Reserve space.
Definition: bvector.hh:473
BlockVector(BlockVector &&a) noexcept(noexcept(std::declval< BlockVector >().swap(a)))
move constructor
Definition: bvector.hh:517
BlockVector(size_type _n)
make vector with _n components
Definition: bvector.hh:429
void resize(size_type size)
Resize the vector.
Definition: bvector.hh:501
Imp::block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:415
static constexpr unsigned int blocklevel
increment block level counter
Definition: bvector.hh:412
BlockVector(const BlockVector &a) noexcept(noexcept(std::declval< BlockVector >().storage_=a.storage_))
copy constructor
Definition: bvector.hh:509
A allocator_type
export the allocator type
Definition: bvector.hh:405
BlockVector & operator=(const BlockVector &a) noexcept(noexcept(std::declval< BlockVector >().storage_=a.storage_))
assignment
Definition: bvector.hh:524
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bvector.hh:399
A::size_type size_type
The type for the index access.
Definition: bvector.hh:408
BlockVector(std::initializer_list< B > const &l)
Construct from a std::initializer_list.
Definition: bvector.hh:435
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:486
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:453
B block_type
export the type representing the components
Definition: bvector.hh:402
void swap(BlockVector &other) noexcept(noexcept(std::declval< BlockVector & >().storage_.swap(other.storage_)))
swap operation
Definition: bvector.hh:542
Imp::block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:418
Provides the functions dot(a,b) := and dotT(a,b) := .
Traits for type conversions and type information.
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Type traits to determine the type of reals (when working with complex numbers)
Implements a vector constructed from a given type representing a field and a compile-time given size.
auto dot(const A &a, const B &b) -> typename std::enable_if<!IsVector< A >::value &&!std::is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type > ::value, decltype(conj(a) *b)>::type
computes the dot product for fundamental data types according to Petsc's VectDot function: dot(a,...
Definition: dotproduct.hh:40
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
Dune namespace.
Definition: alignedallocator.hh:11
STL namespace.
Compute type of the result of an arithmetic operation involving two different number types.
Implements a scalar vector view wrapper around an existing scalar.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)