Dune Core Modules (2.9.0)

bvector.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_ISTL_BVECTOR_HH
7#define DUNE_ISTL_BVECTOR_HH
8
9#include <algorithm>
10#include <cmath>
11#include <complex>
12#include <initializer_list>
13#include <limits>
14#include <memory>
15#include <utility>
16#include <vector>
17
25
27
28#include "basearray.hh"
29#include "istlexception.hh"
30
38namespace Dune {
39
41namespace Imp {
42
48 template <class B, bool isNumber>
49 class BlockTraitsImp;
50
51 template <class B>
52 class BlockTraitsImp<B,true>
53 {
54 public:
55 using field_type = B;
56 };
57
58 template <class B>
59 class BlockTraitsImp<B,false>
60 {
61 public:
62 using field_type = typename B::field_type;
63 };
64
67 template <class B>
68 using BlockTraits = BlockTraitsImp<B,IsNumber<B>::value>;
69
83 template<class B, class A=std::allocator<B> >
84 class block_vector_unmanaged : public base_array_unmanaged<B,A>
85 {
86 public:
87
88 //===== type definitions and constants
89 using field_type = typename Imp::BlockTraits<B>::field_type;
90
92 typedef B block_type;
93
95 typedef A allocator_type;
96
98 typedef typename A::size_type size_type;
99
101 typedef typename base_array_unmanaged<B,A>::iterator Iterator;
102
104 typedef typename base_array_unmanaged<B,A>::const_iterator ConstIterator;
105
107 typedef B value_type;
108
110 typedef B& reference;
111
113 typedef const B& const_reference;
114
115 //===== assignment from scalar
117
118 block_vector_unmanaged& operator= (const field_type& k)
119 {
120 for (size_type i=0; i<this->n; i++)
121 (*this)[i] = k;
122 return *this;
123 }
124
125 //===== vector space arithmetic
127 block_vector_unmanaged& operator+= (const block_vector_unmanaged& y)
128 {
129#ifdef DUNE_ISTL_WITH_CHECKING
130 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
131#endif
132 for (size_type i=0; i<this->n; ++i) (*this)[i] += y[i];
133 return *this;
134 }
135
137 block_vector_unmanaged& operator-= (const block_vector_unmanaged& y)
138 {
139#ifdef DUNE_ISTL_WITH_CHECKING
140 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
141#endif
142 for (size_type i=0; i<this->n; ++i) (*this)[i] -= y[i];
143 return *this;
144 }
145
147 block_vector_unmanaged& operator*= (const field_type& k)
148 {
149 for (size_type i=0; i<this->n; ++i) (*this)[i] *= k;
150 return *this;
151 }
152
154 block_vector_unmanaged& operator/= (const field_type& k)
155 {
156 for (size_type i=0; i<this->n; ++i) (*this)[i] /= k;
157 return *this;
158 }
159
161 block_vector_unmanaged& axpy (const field_type& a, const block_vector_unmanaged& y)
162 {
163#ifdef DUNE_ISTL_WITH_CHECKING
164 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
165#endif
166 for (size_type i=0; i<this->n; ++i)
167 Impl::asVector((*this)[i]).axpy(a,Impl::asVector(y[i]));
168
169 return *this;
170 }
171
172
180 template<class OtherB, class OtherA>
181 auto operator* (const block_vector_unmanaged<OtherB,OtherA>& y) const
182 {
183 typedef typename PromotionTraits<field_type,typename BlockTraits<OtherB>::field_type>::PromotedType PromotedType;
184 PromotedType sum(0);
185#ifdef DUNE_ISTL_WITH_CHECKING
186 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
187#endif
188 for (size_type i=0; i<this->n; ++i) {
189 sum += PromotedType(((*this)[i])*y[i]);
190 }
191 return sum;
192 }
193
201 template<class OtherB, class OtherA>
202 auto dot(const block_vector_unmanaged<OtherB,OtherA>& y) const
203 {
204 typedef typename PromotionTraits<field_type,typename BlockTraits<OtherB>::field_type>::PromotedType PromotedType;
205 PromotedType sum(0);
206#ifdef DUNE_ISTL_WITH_CHECKING
207 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
208#endif
209
210 for (size_type i=0; i<this->n; ++i)
211 sum += Impl::asVector((*this)[i]).dot(Impl::asVector(y[i]));
212
213 return sum;
214 }
215
216 //===== norms
217
219 typename FieldTraits<field_type>::real_type one_norm () const
220 {
221 typename FieldTraits<field_type>::real_type sum=0;
222 for (size_type i=0; i<this->n; ++i)
223 sum += Impl::asVector((*this)[i]).one_norm();
224 return sum;
225 }
226
228 typename FieldTraits<field_type>::real_type one_norm_real () const
229 {
230 typename FieldTraits<field_type>::real_type sum=0;
231 for (size_type i=0; i<this->n; ++i)
232 sum += Impl::asVector((*this)[i]).one_norm_real();
233 return sum;
234 }
235
237 typename FieldTraits<field_type>::real_type two_norm () const
238 {
239 using std::sqrt;
240 return sqrt(two_norm2());
241 }
242
244 typename FieldTraits<field_type>::real_type two_norm2 () const
245 {
246 typename FieldTraits<field_type>::real_type sum=0;
247 for (size_type i=0; i<this->n; ++i)
248 sum += Impl::asVector((*this)[i]).two_norm2();
249 return sum;
250 }
251
253 template <typename ft = field_type,
254 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
255 typename FieldTraits<ft>::real_type infinity_norm() const {
256 using real_type = typename FieldTraits<ft>::real_type;
257 using std::max;
258
259 real_type norm = 0;
260 for (auto const &xi : *this) {
261 real_type const a = Impl::asVector(xi).infinity_norm();
262 norm = max(a, norm);
263 }
264 return norm;
265 }
266
268 template <typename ft = field_type,
269 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
270 typename FieldTraits<ft>::real_type infinity_norm_real() const {
271 using real_type = typename FieldTraits<ft>::real_type;
272 using std::max;
273
274 real_type norm = 0;
275 for (auto const &xi : *this) {
276 real_type const a = Impl::asVector(xi).infinity_norm_real();
277 norm = max(a, norm);
278 }
279 return norm;
280 }
281
283 template <typename ft = field_type,
284 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
285 typename FieldTraits<ft>::real_type infinity_norm() const {
286 using real_type = typename FieldTraits<ft>::real_type;
287 using std::max;
288 using std::abs;
289
290 real_type norm = 0;
291 real_type isNaN = 1;
292
293 for (auto const &xi : *this) {
294 real_type const a = Impl::asVector(xi).infinity_norm();
295 norm = max(a, norm);
296 isNaN += a;
297 }
298 return norm * (isNaN / isNaN);
299 }
300
302 template <typename ft = field_type,
303 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
304 typename FieldTraits<ft>::real_type infinity_norm_real() const {
305 using real_type = typename FieldTraits<ft>::real_type;
306 using std::max;
307
308 real_type norm = 0;
309 real_type isNaN = 1;
310
311 for (auto const &xi : *this) {
312 real_type const a = Impl::asVector(xi).infinity_norm_real();
313 norm = max(a, norm);
314 isNaN += a;
315 }
316
317 return norm * (isNaN / isNaN);
318 }
319
320 //===== sizes
321
323 size_type N () const
324 {
325 return this->n;
326 }
327
329 size_type dim () const
330 {
331 size_type d=0;
332
333 for (size_type i=0; i<this->n; i++)
334 d += Impl::asVector((*this)[i]).dim();
335
336 return d;
337 }
338
339 protected:
341 block_vector_unmanaged () : base_array_unmanaged<B,A>()
342 { }
343 };
344
346
351 template<class F>
352 class ScopeGuard {
353 F cleanupFunc_;
354 public:
355 ScopeGuard(F cleanupFunc) : cleanupFunc_(std::move(cleanupFunc)) {}
356 ScopeGuard(const ScopeGuard &) = delete;
357 ScopeGuard(ScopeGuard &&) = delete;
358 ScopeGuard &operator=(ScopeGuard) = delete;
359 ~ScopeGuard() { cleanupFunc_(); }
360 };
361
363
372 template<class F>
373 ScopeGuard<F> makeScopeGuard(F cleanupFunc)
374 {
375 return { std::move(cleanupFunc) };
376 }
377
378} // end namespace Imp
393 template<class B, class A=std::allocator<B> >
394 class BlockVector : public Imp::block_vector_unmanaged<B,A>
395 {
396 public:
397
398 //===== type definitions and constants
399
401 using field_type = typename Imp::BlockTraits<B>::field_type;
402
404 typedef B block_type;
405
407 typedef A allocator_type;
408
410 typedef typename A::size_type size_type;
411
413 [[deprecated("Use free function blockLevel(). Will be removed after 2.8.")]]
414 static constexpr unsigned int blocklevel = blockLevel<B>()+1;
415
417 typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator;
418
420 typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
421
422 //===== constructors and such
423
426 {
427 syncBaseArray();
428 }
429
431 explicit BlockVector (size_type _n) : storage_(_n)
432 {
433 syncBaseArray();
434 }
435
437 BlockVector (std::initializer_list<B> const &l) : storage_(l)
438 {
439 syncBaseArray();
440 }
441
442
454 template<typename S>
455 BlockVector (size_type _n, S _capacity)
456 {
457 static_assert(std::numeric_limits<S>::is_integer,
458 "capacity must be an unsigned integral type (be aware, that this constructor does not set the default value!)" );
459 if((size_type)_capacity > _n)
460 storage_.reserve(_capacity);
461 storage_.resize(_n);
462 syncBaseArray();
463 }
464
465
476 {
477 [[maybe_unused]] const auto &guard =
478 Imp::makeScopeGuard([this]{ syncBaseArray(); });
479 storage_.reserve(capacity);
480 }
481
489 {
490 return storage_.capacity();
491 }
492
503 void resize(size_type size)
504 {
505 [[maybe_unused]] const auto &guard =
506 Imp::makeScopeGuard([this]{ syncBaseArray(); });
507 storage_.resize(size);
508 }
509
512 noexcept(noexcept(std::declval<BlockVector>().storage_ = a.storage_))
513 {
514 storage_ = a.storage_;
515 syncBaseArray();
516 }
517
520 noexcept(noexcept(std::declval<BlockVector>().swap(a)))
521 {
522 swap(a);
523 }
524
527 noexcept(noexcept(std::declval<BlockVector>().storage_ = a.storage_))
528 {
529 [[maybe_unused]] const auto &guard =
530 Imp::makeScopeGuard([this]{ syncBaseArray(); });
531 storage_ = a.storage_;
532 return *this;
533 }
534
537 noexcept(noexcept(std::declval<BlockVector>().swap(a)))
538 {
539 swap(a);
540 return *this;
541 }
542
544 void swap(BlockVector &other)
545 noexcept(noexcept(
546 std::declval<BlockVector&>().storage_.swap(other.storage_)))
547 {
548 [[maybe_unused]] const auto &guard = Imp::makeScopeGuard([&]{
549 syncBaseArray();
550 other.syncBaseArray();
551 });
552 storage_.swap(other.storage_);
553 }
554
557 {
558 // forward to operator= in base class
559 (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k;
560 return *this;
561 }
562
563 private:
564 void syncBaseArray() noexcept
565 {
566 this->p = storage_.data();
567 this->n = storage_.size();
568 }
569
570 std::vector<B, A> storage_;
571 };
572
578 template<class B, class A>
579 struct FieldTraits< BlockVector<B, A> >
580 {
581 typedef typename FieldTraits<B>::field_type field_type;
582 typedef typename FieldTraits<B>::real_type real_type;
583 };
589 template<class K, class A>
590 std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
591 {
592 typedef typename BlockVector<K, A>::size_type size_type;
593
594 for (size_type i=0; i<v.size(); i++)
595 s << v[i] << std::endl;
596
597 return s;
598 }
599
601namespace Imp {
602
621#ifndef DOXYGEN
622 template<class B, class A>
623#else
624 template<class B, class A=std::allocator<B> >
625#endif
626 class BlockVectorWindow : public Imp::block_vector_unmanaged<B,A>
627 {
628 public:
629
630 //===== type definitions and constants
631
633 using field_type = typename Imp::BlockTraits<B>::field_type;
634
636 typedef B block_type;
637
639 typedef A allocator_type;
640
642 typedef typename A::size_type size_type;
643
645 [[deprecated("Use free function blockLevel(). Will be removed after 2.8.")]]
646 static constexpr unsigned int blocklevel = blockLevel<B>()+1;
647
649 typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator;
650
652 typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
653
654
655 //===== constructors and such
657 BlockVectorWindow () : Imp::block_vector_unmanaged<B,A>()
658 { }
659
661 BlockVectorWindow (B* _p, size_type _n)
662 {
663 this->n = _n;
664 this->p = _p;
665 }
666
668 BlockVectorWindow (const BlockVectorWindow& a)
669 {
670 this->n = a.n;
671 this->p = a.p;
672 }
673
675 BlockVectorWindow& operator= (const BlockVectorWindow& a)
676 {
677 // check correct size
678#ifdef DUNE_ISTL_WITH_CHECKING
679 if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
680#endif
681
682 if (&a!=this) // check if this and a are different objects
683 {
684 // copy data
685 for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
686 }
687 return *this;
688 }
689
691 BlockVectorWindow& operator= (const field_type& k)
692 {
693 (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k;
694 return *this;
695 }
696
698 operator BlockVector<B, A>() const {
699 auto bv = BlockVector<B, A>(this->n);
700
701 std::copy(this->begin(), this->end(), bv.begin());
702
703 return bv;
704 }
705
706 //===== window manipulation methods
707
709 void set (size_type _n, B* _p)
710 {
711 this->n = _n;
712 this->p = _p;
713 }
714
716 void setsize (size_type _n)
717 {
718 this->n = _n;
719 }
720
722 void setptr (B* _p)
723 {
724 this->p = _p;
725 }
726
728 B* getptr ()
729 {
730 return this->p;
731 }
732
734 size_type getsize () const
735 {
736 return this->n;
737 }
738 };
739
740
741
752 template<class B, class A=std::allocator<B> >
753 class compressed_block_vector_unmanaged : public compressed_base_array_unmanaged<B,A>
754 {
755 public:
756
757 //===== type definitions and constants
758
760 using field_type = typename Imp::BlockTraits<B>::field_type;
761
763 typedef B block_type;
764
766 typedef A allocator_type;
767
769 typedef typename compressed_base_array_unmanaged<B,A>::iterator Iterator;
770
772 typedef typename compressed_base_array_unmanaged<B,A>::const_iterator ConstIterator;
773
775 typedef typename A::size_type size_type;
776
777 //===== assignment from scalar
778
779 compressed_block_vector_unmanaged& operator= (const field_type& k)
780 {
781 for (size_type i=0; i<this->n; i++)
782 (this->p)[i] = k;
783 return *this;
784 }
785
786
787 //===== vector space arithmetic
788
790 template<class V>
791 compressed_block_vector_unmanaged& operator+= (const V& y)
792 {
793#ifdef DUNE_ISTL_WITH_CHECKING
794 if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
795#endif
796 for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) += y.p[i];
797 return *this;
798 }
799
801 template<class V>
802 compressed_block_vector_unmanaged& operator-= (const V& y)
803 {
804#ifdef DUNE_ISTL_WITH_CHECKING
805 if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
806#endif
807 for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) -= y.p[i];
808 return *this;
809 }
810
812 template<class V>
813 compressed_block_vector_unmanaged& axpy (const field_type& a, const V& y)
814 {
815#ifdef DUNE_ISTL_WITH_CHECKING
816 if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
817#endif
818 for (size_type i=0; i<y.n; ++i)
819 Impl::asVector((*this)[y.j[i]]).axpy(a,Impl::asVector(y.p[i]));
820 return *this;
821 }
822
824 compressed_block_vector_unmanaged& operator*= (const field_type& k)
825 {
826 for (size_type i=0; i<this->n; ++i) (this->p)[i] *= k;
827 return *this;
828 }
829
831 compressed_block_vector_unmanaged& operator/= (const field_type& k)
832 {
833 for (size_type i=0; i<this->n; ++i) (this->p)[i] /= k;
834 return *this;
835 }
836
837
838 //===== Euclidean scalar product
839
841 field_type operator* (const compressed_block_vector_unmanaged& y) const
842 {
843#ifdef DUNE_ISTL_WITH_CHECKING
844 if (!includesindexset(y) || !y.includesindexset(*this) )
845 DUNE_THROW(ISTLError,"index set mismatch");
846#endif
847 field_type sum=0;
848 for (size_type i=0; i<this->n; ++i)
849 sum += (this->p)[i] * y[(this->j)[i]];
850 return sum;
851 }
852
853
854 //===== norms
855
857 typename FieldTraits<field_type>::real_type one_norm () const
858 {
859 typename FieldTraits<field_type>::real_type sum=0;
860 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm();
861 return sum;
862 }
863
865 typename FieldTraits<field_type>::real_type one_norm_real () const
866 {
867 typename FieldTraits<field_type>::real_type sum=0;
868 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm_real();
869 return sum;
870 }
871
873 typename FieldTraits<field_type>::real_type two_norm () const
874 {
875 using std::sqrt;
876 typename FieldTraits<field_type>::real_type sum=0;
877 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
878 return sqrt(sum);
879 }
880
882 typename FieldTraits<field_type>::real_type two_norm2 () const
883 {
884 typename FieldTraits<field_type>::real_type sum=0;
885 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
886 return sum;
887 }
888
890 template <typename ft = field_type,
891 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
892 typename FieldTraits<ft>::real_type infinity_norm() const {
893 using real_type = typename FieldTraits<ft>::real_type;
894 using std::max;
895
896 real_type norm = 0;
897 for (auto const &x : *this) {
898 real_type const a = x.infinity_norm();
899 norm = max(a, norm);
900 }
901 return norm;
902 }
903
905 template <typename ft = field_type,
906 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
907 typename FieldTraits<ft>::real_type infinity_norm_real() const {
908 using real_type = typename FieldTraits<ft>::real_type;
909 using std::max;
910
911 real_type norm = 0;
912 for (auto const &x : *this) {
913 real_type const a = x.infinity_norm_real();
914 norm = max(a, norm);
915 }
916 return norm;
917 }
918
920 template <typename ft = field_type,
921 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
922 typename FieldTraits<ft>::real_type infinity_norm() const {
923 using real_type = typename FieldTraits<ft>::real_type;
924 using std::max;
925
926 real_type norm = 0;
927 real_type isNaN = 1;
928 for (auto const &x : *this) {
929 real_type const a = x.infinity_norm();
930 norm = max(a, norm);
931 isNaN += a;
932 }
933 return norm * (isNaN / isNaN);
934 }
935
937 template <typename ft = field_type,
938 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
939 typename FieldTraits<ft>::real_type infinity_norm_real() const {
940 using real_type = typename FieldTraits<ft>::real_type;
941 using std::max;
942
943 real_type norm = 0;
944 real_type isNaN = 1;
945 for (auto const &x : *this) {
946 real_type const a = x.infinity_norm_real();
947 norm = max(a, norm);
948 isNaN += a;
949 }
950 return norm * (isNaN / isNaN);
951 }
952
953 //===== sizes
954
956 size_type N () const
957 {
958 return this->n;
959 }
960
962 size_type dim () const
963 {
964 size_type d=0;
965 for (size_type i=0; i<this->n; i++)
966 d += (this->p)[i].dim();
967 return d;
968 }
969
970 protected:
972 compressed_block_vector_unmanaged () : compressed_base_array_unmanaged<B,A>()
973 { }
974
976 template<class V>
977 bool includesindexset (const V& y)
978 {
979 typename V::ConstIterator e=this->end();
980 for (size_type i=0; i<y.n; i++)
981 if (this->find(y.j[i])==e)
982 return false;
983 return true;
984 }
985 };
986
987
1006 template<class B, class A=std::allocator<B> >
1007 class CompressedBlockVectorWindow : public compressed_block_vector_unmanaged<B,A>
1008 {
1009 public:
1010
1011 //===== type definitions and constants
1012
1014 using field_type = typename Imp::BlockTraits<B>::field_type;
1015
1017 typedef B block_type;
1018
1020 typedef A allocator_type;
1021
1023 typedef typename A::size_type size_type;
1024
1026 [[deprecated("Use free function blockLevel(). Will be removed after 2.8.")]]
1027 static constexpr unsigned int blocklevel = blockLevel<B>()+1;
1028
1030 typedef typename compressed_block_vector_unmanaged<B,A>::Iterator Iterator;
1031
1033 typedef typename compressed_block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
1034
1035
1036 //===== constructors and such
1038 CompressedBlockVectorWindow () : compressed_block_vector_unmanaged<B,A>()
1039 { }
1040
1042 CompressedBlockVectorWindow (B* _p, size_type* _j, size_type _n)
1043 {
1044 this->n = _n;
1045 this->p = _p;
1046 this->j = _j;
1047 }
1048
1050 CompressedBlockVectorWindow (const CompressedBlockVectorWindow& a)
1051 {
1052 this->n = a.n;
1053 this->p = a.p;
1054 this->j = a.j;
1055 }
1056
1058 CompressedBlockVectorWindow& operator= (const CompressedBlockVectorWindow& a)
1059 {
1060 // check correct size
1061#ifdef DUNE_ISTL_WITH_CHECKING
1062 if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
1063#endif
1064
1065 if (&a!=this) // check if this and a are different objects
1066 {
1067 // copy data
1068 for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
1069 for (size_type i=0; i<this->n; i++) this->j[i]=a.j[i];
1070 }
1071 return *this;
1072 }
1073
1075 CompressedBlockVectorWindow& operator= (const field_type& k)
1076 {
1077 (static_cast<compressed_block_vector_unmanaged<B,A>&>(*this)) = k;
1078 return *this;
1079 }
1080
1081
1082 //===== window manipulation methods
1083
1085 void set (size_type _n, B* _p, size_type* _j)
1086 {
1087 this->n = _n;
1088 this->p = _p;
1089 this->j = _j;
1090 }
1091
1093 void setsize (size_type _n)
1094 {
1095 this->n = _n;
1096 }
1097
1099 void setptr (B* _p)
1100 {
1101 this->p = _p;
1102 }
1103
1105 void setindexptr (size_type* _j)
1106 {
1107 this->j = _j;
1108 }
1109
1111 B* getptr ()
1112 {
1113 return this->p;
1114 }
1115
1117 size_type* getindexptr ()
1118 {
1119 return this->j;
1120 }
1121
1123 const B* getptr () const
1124 {
1125 return this->p;
1126 }
1127
1129 const size_type* getindexptr () const
1130 {
1131 return this->j;
1132 }
1134 size_type getsize () const
1135 {
1136 return this->n;
1137 }
1138 };
1139
1140} // end namespace 'Imp'
1141
1142
1144 template<typename B, typename A>
1145 struct AutonomousValueType<Imp::BlockVectorWindow<B,A>>
1146 {
1147 using type = BlockVector<B, A>;
1148 };
1149
1150
1151} // end namespace 'Dune'
1152
1153#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:395
BlockVector()
makes empty vector
Definition: bvector.hh:425
void reserve(size_type capacity)
Reserve space.
Definition: bvector.hh:475
BlockVector(BlockVector &&a) noexcept(noexcept(std::declval< BlockVector >().swap(a)))
move constructor
Definition: bvector.hh:519
BlockVector(size_type _n)
make vector with _n components
Definition: bvector.hh:431
void resize(size_type size)
Resize the vector.
Definition: bvector.hh:503
Imp::block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:417
static constexpr unsigned int blocklevel
increment block level counter
Definition: bvector.hh:414
BlockVector(const BlockVector &a) noexcept(noexcept(std::declval< BlockVector >().storage_=a.storage_))
copy constructor
Definition: bvector.hh:511
A allocator_type
export the allocator type
Definition: bvector.hh:407
BlockVector & operator=(const BlockVector &a) noexcept(noexcept(std::declval< BlockVector >().storage_=a.storage_))
assignment
Definition: bvector.hh:526
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bvector.hh:401
A::size_type size_type
The type for the index access.
Definition: bvector.hh:410
BlockVector(std::initializer_list< B > const &l)
Construct from a std::initializer_list.
Definition: bvector.hh:437
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:488
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:455
B block_type
export the type representing the components
Definition: bvector.hh:404
void swap(BlockVector &other) noexcept(noexcept(std::declval< BlockVector & >().storage_.swap(other.storage_)))
swap operation
Definition: bvector.hh:544
Imp::block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:420
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< IsNumber< A >::value &&!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:42
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
Dune namespace.
Definition: alignedallocator.hh:13
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 21, 23:30, 2024)