DUNE-FEM (unstable)

bvector.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © 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 ST=std::size_t >
84 class block_vector_unmanaged : public base_array_unmanaged<B,ST>
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 ST size_type;
96
98 typedef typename base_array_unmanaged<B,ST>::iterator Iterator;
99
101 typedef typename base_array_unmanaged<B,ST>::const_iterator ConstIterator;
102
104 typedef B value_type;
105
107 typedef B& reference;
108
110 typedef const B& const_reference;
111
112 //===== assignment from scalar
114
115 block_vector_unmanaged& operator= (const field_type& k)
116 {
117 for (size_type i=0; i<this->n; i++)
118 (*this)[i] = k;
119 return *this;
120 }
121
122 //===== vector space arithmetic
124 block_vector_unmanaged& operator+= (const block_vector_unmanaged& y)
125 {
126#ifdef DUNE_ISTL_WITH_CHECKING
127 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
128#endif
129 for (size_type i=0; i<this->n; ++i) (*this)[i] += y[i];
130 return *this;
131 }
132
134 block_vector_unmanaged& operator-= (const block_vector_unmanaged& y)
135 {
136#ifdef DUNE_ISTL_WITH_CHECKING
137 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
138#endif
139 for (size_type i=0; i<this->n; ++i) (*this)[i] -= y[i];
140 return *this;
141 }
142
144 block_vector_unmanaged& operator*= (const field_type& k)
145 {
146 for (size_type i=0; i<this->n; ++i) (*this)[i] *= k;
147 return *this;
148 }
149
151 block_vector_unmanaged& operator/= (const field_type& k)
152 {
153 for (size_type i=0; i<this->n; ++i) (*this)[i] /= k;
154 return *this;
155 }
156
158 block_vector_unmanaged& axpy (const field_type& a, const block_vector_unmanaged& y)
159 {
160#ifdef DUNE_ISTL_WITH_CHECKING
161 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
162#endif
163 for (size_type i=0; i<this->n; ++i)
164 Impl::asVector((*this)[i]).axpy(a,Impl::asVector(y[i]));
165
166 return *this;
167 }
168
169
177 template<class OtherB, class OtherST>
178 auto operator* (const block_vector_unmanaged<OtherB,OtherST>& y) const
179 {
180 typedef typename PromotionTraits<field_type,typename BlockTraits<OtherB>::field_type>::PromotedType PromotedType;
181 PromotedType sum(0);
182#ifdef DUNE_ISTL_WITH_CHECKING
183 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
184#endif
185 for (size_type i=0; i<this->n; ++i) {
186 sum += PromotedType(((*this)[i])*y[i]);
187 }
188 return sum;
189 }
190
198 template<class OtherB, class OtherST>
199 auto dot(const block_vector_unmanaged<OtherB,OtherST>& y) const
200 {
201 typedef typename PromotionTraits<field_type,typename BlockTraits<OtherB>::field_type>::PromotedType PromotedType;
202 PromotedType sum(0);
203#ifdef DUNE_ISTL_WITH_CHECKING
204 if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
205#endif
206
207 for (size_type i=0; i<this->n; ++i)
208 sum += Impl::asVector((*this)[i]).dot(Impl::asVector(y[i]));
209
210 return sum;
211 }
212
213 //===== norms
214
216 typename FieldTraits<field_type>::real_type one_norm () const
217 {
218 typename FieldTraits<field_type>::real_type sum=0;
219 for (size_type i=0; i<this->n; ++i)
220 sum += Impl::asVector((*this)[i]).one_norm();
221 return sum;
222 }
223
225 typename FieldTraits<field_type>::real_type one_norm_real () const
226 {
227 typename FieldTraits<field_type>::real_type sum=0;
228 for (size_type i=0; i<this->n; ++i)
229 sum += Impl::asVector((*this)[i]).one_norm_real();
230 return sum;
231 }
232
234 typename FieldTraits<field_type>::real_type two_norm () const
235 {
236 using std::sqrt;
237 return sqrt(two_norm2());
238 }
239
241 typename FieldTraits<field_type>::real_type two_norm2 () const
242 {
243 typename FieldTraits<field_type>::real_type sum=0;
244 for (size_type i=0; i<this->n; ++i)
245 sum += Impl::asVector((*this)[i]).two_norm2();
246 return sum;
247 }
248
250 template <typename ft = field_type,
251 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
252 typename FieldTraits<ft>::real_type infinity_norm() const {
253 using real_type = typename FieldTraits<ft>::real_type;
254 using std::max;
255
256 real_type norm = 0;
257 for (auto const &xi : *this) {
258 real_type const a = Impl::asVector(xi).infinity_norm();
259 norm = max(a, norm);
260 }
261 return norm;
262 }
263
265 template <typename ft = field_type,
266 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
267 typename FieldTraits<ft>::real_type infinity_norm_real() const {
268 using real_type = typename FieldTraits<ft>::real_type;
269 using std::max;
270
271 real_type norm = 0;
272 for (auto const &xi : *this) {
273 real_type const a = Impl::asVector(xi).infinity_norm_real();
274 norm = max(a, norm);
275 }
276 return norm;
277 }
278
280 template <typename ft = field_type,
281 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
282 typename FieldTraits<ft>::real_type infinity_norm() const {
283 using real_type = typename FieldTraits<ft>::real_type;
284 using std::max;
285 using std::abs;
286
287 real_type norm = 0;
288 real_type isNaN = 1;
289
290 for (auto const &xi : *this) {
291 real_type const a = Impl::asVector(xi).infinity_norm();
292 norm = max(a, norm);
293 isNaN += a;
294 }
295 return norm * (isNaN / isNaN);
296 }
297
299 template <typename ft = field_type,
300 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
301 typename FieldTraits<ft>::real_type infinity_norm_real() const {
302 using real_type = typename FieldTraits<ft>::real_type;
303 using std::max;
304
305 real_type norm = 0;
306 real_type isNaN = 1;
307
308 for (auto const &xi : *this) {
309 real_type const a = Impl::asVector(xi).infinity_norm_real();
310 norm = max(a, norm);
311 isNaN += a;
312 }
313
314 return norm * (isNaN / isNaN);
315 }
316
317 //===== sizes
318
320 size_type N () const
321 {
322 return this->n;
323 }
324
326 size_type dim () const
327 {
328 size_type d=0;
329
330 for (size_type i=0; i<this->n; i++)
331 d += Impl::asVector((*this)[i]).dim();
332
333 return d;
334 }
335
336 protected:
338 block_vector_unmanaged () : base_array_unmanaged<B,ST>()
339 { }
340 };
341
343
348 template<class F>
349 class ScopeGuard {
350 F cleanupFunc_;
351 public:
352 ScopeGuard(F cleanupFunc) : cleanupFunc_(std::move(cleanupFunc)) {}
353 ScopeGuard(const ScopeGuard &) = delete;
354 ScopeGuard(ScopeGuard &&) = delete;
355 ScopeGuard &operator=(ScopeGuard) = delete;
356 ~ScopeGuard() { cleanupFunc_(); }
357 };
358
360
369 template<class F>
370 ScopeGuard<F> makeScopeGuard(F cleanupFunc)
371 {
372 return { std::move(cleanupFunc) };
373 }
374
375} // end namespace Imp
390 template<class B, class A=std::allocator<B> >
391 class BlockVector : public Imp::block_vector_unmanaged<B,typename std::allocator_traits<A>::size_type>
392 {
393 public:
394
395 //===== type definitions and constants
396
398 using field_type = typename Imp::BlockTraits<B>::field_type;
399
401 typedef B block_type;
402
404 typedef A allocator_type;
405
407 typedef typename std::allocator_traits<A>::size_type size_type;
408
410 typedef typename Imp::block_vector_unmanaged<B,size_type>::Iterator Iterator;
411
413 typedef typename Imp::block_vector_unmanaged<B,size_type>::ConstIterator ConstIterator;
414
415 //===== constructors and such
416
419 {
420 syncBaseArray();
421 }
422
424 explicit BlockVector (size_type _n) : storage_(_n)
425 {
426 syncBaseArray();
427 }
428
430 BlockVector (std::initializer_list<B> const &l) : storage_(l)
431 {
432 syncBaseArray();
433 }
434
435
447 template<typename S>
448 BlockVector (size_type _n, S _capacity)
449 {
450 static_assert(std::numeric_limits<S>::is_integer,
451 "capacity must be an unsigned integral type (be aware, that this constructor does not set the default value!)" );
452 if((size_type)_capacity > _n)
453 storage_.reserve(_capacity);
454 storage_.resize(_n);
455 syncBaseArray();
456 }
457
458
469 {
470 [[maybe_unused]] const auto &guard =
471 Imp::makeScopeGuard([this]{ syncBaseArray(); });
472 storage_.reserve(capacity);
473 }
474
482 {
483 return storage_.capacity();
484 }
485
497 {
498 [[maybe_unused]] const auto &guard =
499 Imp::makeScopeGuard([this]{ syncBaseArray(); });
500 storage_.resize(size);
501 }
502
505 noexcept(noexcept(std::declval<BlockVector>().storage_ = a.storage_))
506 {
507 storage_ = a.storage_;
508 syncBaseArray();
509 }
510
513 noexcept(noexcept(std::declval<BlockVector>().swap(a)))
514 {
515 swap(a);
516 }
517
520 noexcept(noexcept(std::declval<BlockVector>().storage_ = a.storage_))
521 {
522 [[maybe_unused]] const auto &guard =
523 Imp::makeScopeGuard([this]{ syncBaseArray(); });
524 storage_ = a.storage_;
525 return *this;
526 }
527
530 noexcept(noexcept(std::declval<BlockVector>().swap(a)))
531 {
532 swap(a);
533 return *this;
534 }
535
537 void swap(BlockVector &other)
538 noexcept(noexcept(
539 std::declval<BlockVector&>().storage_.swap(other.storage_)))
540 {
541 [[maybe_unused]] const auto &guard = Imp::makeScopeGuard([&]{
542 syncBaseArray();
543 other.syncBaseArray();
544 });
545 storage_.swap(other.storage_);
546 }
547
550 {
551 // forward to operator= in base class
552 (static_cast<Imp::block_vector_unmanaged<B,size_type>&>(*this)) = k;
553 return *this;
554 }
555
556 private:
557 void syncBaseArray() noexcept
558 {
559 this->p = storage_.data();
560 this->n = storage_.size();
561 }
562
563 using block_allocator_t = typename std::allocator_traits<A>::template rebind_alloc<B>;
564
565 std::vector<B, block_allocator_t> storage_;
566 };
567
573 template<class B, class A>
574 struct FieldTraits< BlockVector<B, A> >
575 {
576 typedef typename FieldTraits<B>::field_type field_type;
577 typedef typename FieldTraits<B>::real_type real_type;
578 };
584 template<class K, class A>
585 std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
586 {
587 typedef typename BlockVector<K, A>::size_type size_type;
588
589 for (size_type i=0; i<v.size(); i++)
590 s << v[i] << std::endl;
591
592 return s;
593 }
594
596namespace Imp {
597
616#ifndef DOXYGEN
617 template<class B, class A>
618#else
619 template<class B, class A=std::allocator<B> >
620#endif
621 class BlockVectorWindow : public Imp::block_vector_unmanaged<B,typename A::size_type>
622 {
623 public:
624
625 //===== type definitions and constants
626
628 using field_type = typename Imp::BlockTraits<B>::field_type;
629
631 typedef B block_type;
632
634 typedef A allocator_type;
635
637 typedef typename A::size_type size_type;
638
640 typedef typename Imp::block_vector_unmanaged<B,size_type>::Iterator Iterator;
641
643 typedef typename Imp::block_vector_unmanaged<B,size_type>::ConstIterator ConstIterator;
644
645
646 //===== constructors and such
648 BlockVectorWindow () : Imp::block_vector_unmanaged<B,size_type>()
649 { }
650
652 BlockVectorWindow (B* _p, size_type _n)
653 {
654 this->n = _n;
655 this->p = _p;
656 }
657
659 BlockVectorWindow (const BlockVectorWindow& a)
660 {
661 this->n = a.n;
662 this->p = a.p;
663 }
664
666 BlockVectorWindow& operator= (const BlockVectorWindow& a)
667 {
668 // check correct size
669#ifdef DUNE_ISTL_WITH_CHECKING
670 if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
671#endif
672
673 if (&a!=this) // check if this and a are different objects
674 {
675 // copy data
676 for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
677 }
678 return *this;
679 }
680
682 BlockVectorWindow& operator= (const field_type& k)
683 {
684 (static_cast<Imp::block_vector_unmanaged<B,size_type>&>(*this)) = k;
685 return *this;
686 }
687
689 operator BlockVector<B, A>() const {
690 auto bv = BlockVector<B, A>(this->n);
691
692 std::copy(this->begin(), this->end(), bv.begin());
693
694 return bv;
695 }
696
697 //===== window manipulation methods
698
700 void set (size_type _n, B* _p)
701 {
702 this->n = _n;
703 this->p = _p;
704 }
705
707 void setsize (size_type _n)
708 {
709 this->n = _n;
710 }
711
713 void setptr (B* _p)
714 {
715 this->p = _p;
716 }
717
719 B* getptr ()
720 {
721 return this->p;
722 }
723
725 size_type getsize () const
726 {
727 return this->n;
728 }
729 };
730
731
732
743 template<class B, class ST=std::size_t >
744 class compressed_block_vector_unmanaged : public compressed_base_array_unmanaged<B,ST>
745 {
746 public:
747
748 //===== type definitions and constants
749
751 using field_type = typename Imp::BlockTraits<B>::field_type;
752
754 typedef B block_type;
755
757 typedef typename compressed_base_array_unmanaged<B,ST>::iterator Iterator;
758
760 typedef typename compressed_base_array_unmanaged<B,ST>::const_iterator ConstIterator;
761
763 typedef ST size_type;
764
765 //===== assignment from scalar
766
767 compressed_block_vector_unmanaged& operator= (const field_type& k)
768 {
769 for (size_type i=0; i<this->n; i++)
770 (this->p)[i] = k;
771 return *this;
772 }
773
774
775 //===== vector space arithmetic
776
778 template<class V>
779 compressed_block_vector_unmanaged& operator+= (const V& y)
780 {
781#ifdef DUNE_ISTL_WITH_CHECKING
782 if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
783#endif
784 for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) += y.p[i];
785 return *this;
786 }
787
789 template<class V>
790 compressed_block_vector_unmanaged& operator-= (const V& y)
791 {
792#ifdef DUNE_ISTL_WITH_CHECKING
793 if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
794#endif
795 for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) -= y.p[i];
796 return *this;
797 }
798
800 template<class V>
801 compressed_block_vector_unmanaged& axpy (const field_type& a, const V& y)
802 {
803#ifdef DUNE_ISTL_WITH_CHECKING
804 if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
805#endif
806 for (size_type i=0; i<y.n; ++i)
807 Impl::asVector((*this)[y.j[i]]).axpy(a,Impl::asVector(y.p[i]));
808 return *this;
809 }
810
812 compressed_block_vector_unmanaged& operator*= (const field_type& k)
813 {
814 for (size_type i=0; i<this->n; ++i) (this->p)[i] *= k;
815 return *this;
816 }
817
819 compressed_block_vector_unmanaged& operator/= (const field_type& k)
820 {
821 for (size_type i=0; i<this->n; ++i) (this->p)[i] /= k;
822 return *this;
823 }
824
825
826 //===== Euclidean scalar product
827
829 field_type operator* (const compressed_block_vector_unmanaged& y) const
830 {
831#ifdef DUNE_ISTL_WITH_CHECKING
832 if (!includesindexset(y) || !y.includesindexset(*this) )
833 DUNE_THROW(ISTLError,"index set mismatch");
834#endif
835 field_type sum=0;
836 for (size_type i=0; i<this->n; ++i)
837 sum += (this->p)[i] * y[(this->j)[i]];
838 return sum;
839 }
840
841
842 //===== norms
843
845 typename FieldTraits<field_type>::real_type one_norm () const
846 {
847 typename FieldTraits<field_type>::real_type sum=0;
848 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm();
849 return sum;
850 }
851
853 typename FieldTraits<field_type>::real_type one_norm_real () const
854 {
855 typename FieldTraits<field_type>::real_type sum=0;
856 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm_real();
857 return sum;
858 }
859
861 typename FieldTraits<field_type>::real_type two_norm () const
862 {
863 using std::sqrt;
864 typename FieldTraits<field_type>::real_type sum=0;
865 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
866 return sqrt(sum);
867 }
868
870 typename FieldTraits<field_type>::real_type two_norm2 () const
871 {
872 typename FieldTraits<field_type>::real_type sum=0;
873 for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
874 return sum;
875 }
876
878 template <typename ft = field_type,
879 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
880 typename FieldTraits<ft>::real_type infinity_norm() const {
881 using real_type = typename FieldTraits<ft>::real_type;
882 using std::max;
883
884 real_type norm = 0;
885 for (auto const &x : *this) {
886 real_type const a = x.infinity_norm();
887 norm = max(a, norm);
888 }
889 return norm;
890 }
891
893 template <typename ft = field_type,
894 typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
895 typename FieldTraits<ft>::real_type infinity_norm_real() const {
896 using real_type = typename FieldTraits<ft>::real_type;
897 using std::max;
898
899 real_type norm = 0;
900 for (auto const &x : *this) {
901 real_type const a = x.infinity_norm_real();
902 norm = max(a, norm);
903 }
904 return norm;
905 }
906
908 template <typename ft = field_type,
909 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
910 typename FieldTraits<ft>::real_type infinity_norm() const {
911 using real_type = typename FieldTraits<ft>::real_type;
912 using std::max;
913
914 real_type norm = 0;
915 real_type isNaN = 1;
916 for (auto const &x : *this) {
917 real_type const a = x.infinity_norm();
918 norm = max(a, norm);
919 isNaN += a;
920 }
921 return norm * (isNaN / isNaN);
922 }
923
925 template <typename ft = field_type,
926 typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
927 typename FieldTraits<ft>::real_type infinity_norm_real() const {
928 using real_type = typename FieldTraits<ft>::real_type;
929 using std::max;
930
931 real_type norm = 0;
932 real_type isNaN = 1;
933 for (auto const &x : *this) {
934 real_type const a = x.infinity_norm_real();
935 norm = max(a, norm);
936 isNaN += a;
937 }
938 return norm * (isNaN / isNaN);
939 }
940
941 //===== sizes
942
944 size_type N () const
945 {
946 return this->n;
947 }
948
950 size_type dim () const
951 {
952 size_type d=0;
953 for (size_type i=0; i<this->n; i++)
954 d += (this->p)[i].dim();
955 return d;
956 }
957
958 protected:
960 compressed_block_vector_unmanaged () : compressed_base_array_unmanaged<B,ST>()
961 { }
962
964 template<class V>
965 bool includesindexset (const V& y)
966 {
967 typename V::ConstIterator e=this->end();
968 for (size_type i=0; i<y.n; i++)
969 if (this->find(y.j[i])==e)
970 return false;
971 return true;
972 }
973 };
974
975
997 template<class B, class ST=std::size_t >
998 class CompressedBlockVectorWindow : public compressed_block_vector_unmanaged<B,ST>
999 {
1000 public:
1001
1002 //===== type definitions and constants
1003
1005 using field_type = typename Imp::BlockTraits<B>::field_type;
1006
1008 typedef B block_type;
1009
1011 typedef ST size_type;
1012
1014 typedef typename compressed_block_vector_unmanaged<B,ST>::Iterator Iterator;
1015
1017 typedef typename compressed_block_vector_unmanaged<B,ST>::ConstIterator ConstIterator;
1018
1019
1020 //===== constructors and such
1022 CompressedBlockVectorWindow () : compressed_block_vector_unmanaged<B,ST>()
1023 { }
1024
1026 CompressedBlockVectorWindow (B* _p, size_type* _j, size_type _n)
1027 {
1028 this->n = _n;
1029 this->p = _p;
1030 this->j = _j;
1031 }
1032
1033 [[deprecated("Reference semantics (i.e., assignment does shallow copy) will be removed due to ambiguity. "
1034 "Instead, use other explicit constructors or populate objects with the setter methods. "
1035 "This will be removed after Dune 2.11.")]]
1036 CompressedBlockVectorWindow(const CompressedBlockVectorWindow &a) = default;
1037
1038 [[deprecated("Reference semantics (i.e., assignment does shallow copy) will be removed due to ambiguity. "
1039 "Instead, use other explicit constructors or populate objects with the setter methods. "
1040 "This will be removed after Dune 2.11.")]]
1041 CompressedBlockVectorWindow (CompressedBlockVectorWindow&& a) = default;
1042
1044 CompressedBlockVectorWindow& operator= (const CompressedBlockVectorWindow& a)
1045 {
1046 // check correct size
1047#ifdef DUNE_ISTL_WITH_CHECKING
1048 if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
1049#endif
1050
1051 if (&a!=this) // check if this and a are different objects
1052 {
1053 // copy data
1054 for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
1055 for (size_type i=0; i<this->n; i++) this->j[i]=a.j[i];
1056 }
1057 return *this;
1058 }
1059
1061 CompressedBlockVectorWindow& operator= (const field_type& k)
1062 {
1063 (static_cast<compressed_block_vector_unmanaged<B,ST>&>(*this)) = k;
1064 return *this;
1065 }
1066
1067 [[deprecated("Reference semantics (i.e., assignment does shallow copy) will be removed due to ambiguity. "
1068 "Instead, use other explicit constructors or populate objects with the setter methods. "
1069 "This will be removed after Dune 2.11.")]]
1070 CompressedBlockVectorWindow& operator= (CompressedBlockVectorWindow&& a)
1071 {
1072 return (*this = std::as_const(a));
1073 }
1074
1075 //===== window manipulation methods
1076
1078 void set (size_type _n, B* _p, size_type* _j)
1079 {
1080 this->n = _n;
1081 this->p = _p;
1082 this->j = _j;
1083 }
1084
1086 void setsize (size_type _n)
1087 {
1088 this->n = _n;
1089 }
1090
1092 void setptr (B* _p)
1093 {
1094 this->p = _p;
1095 }
1096
1098 void setindexptr (size_type* _j)
1099 {
1100 this->j = _j;
1101 }
1102
1104 B* getptr ()
1105 {
1106 return this->p;
1107 }
1108
1110 size_type* getindexptr ()
1111 {
1112 return this->j;
1113 }
1114
1116 const B* getptr () const
1117 {
1118 return this->p;
1119 }
1120
1122 const size_type* getindexptr () const
1123 {
1124 return this->j;
1125 }
1127 size_type getsize () const
1128 {
1129 return this->n;
1130 }
1131 };
1132
1133} // end namespace 'Imp'
1134
1135
1137 template<typename B, typename A>
1138 struct AutonomousValueType<Imp::BlockVectorWindow<B,A>>
1139 {
1140 using type = BlockVector<B, A>;
1141 };
1142
1143
1144} // end namespace 'Dune'
1145
1146#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:392
BlockVector()
makes empty vector
Definition: bvector.hh:418
Imp::block_vector_unmanaged< B, size_type >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:413
void reserve(size_type capacity)
Reserve space.
Definition: bvector.hh:468
BlockVector(BlockVector &&a) noexcept(noexcept(std::declval< BlockVector >().swap(a)))
move constructor
Definition: bvector.hh:512
BlockVector(size_type _n)
make vector with _n components
Definition: bvector.hh:424
void resize(size_type size)
Resize the vector.
Definition: bvector.hh:496
Imp::block_vector_unmanaged< B, size_type >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:410
BlockVector(const BlockVector &a) noexcept(noexcept(std::declval< BlockVector >().storage_=a.storage_))
copy constructor
Definition: bvector.hh:504
A allocator_type
export the allocator type
Definition: bvector.hh:404
BlockVector & operator=(const BlockVector &a) noexcept(noexcept(std::declval< BlockVector >().storage_=a.storage_))
assignment
Definition: bvector.hh:519
std::allocator_traits< A >::size_type size_type
The type for the index access.
Definition: bvector.hh:407
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bvector.hh:398
BlockVector(std::initializer_list< B > const &l)
Construct from a std::initializer_list.
Definition: bvector.hh:430
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:481
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:448
B block_type
export the type representing the components
Definition: bvector.hh:401
void swap(BlockVector &other) noexcept(noexcept(std::declval< BlockVector & >().storage_.swap(other.storage_)))
swap operation
Definition: bvector.hh:537
Provides the functions dot(a,b) := and dotT(a,b) := .
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:40
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:489
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether any entry is NaN.
Definition: fvector.hh:458
Dune namespace
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
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.
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 8, 23:37, 2026)