Dune Core Modules (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 
19 #include <dune/common/ftraits.hh>
20 #include <dune/common/fmatrix.hh>
21 #include <dune/common/fvector.hh>
25 
26 #include <dune/istl/blocklevel.hh>
27 
28 #include "basearray.hh"
29 #include "istlexception.hh"
30 
38 namespace Dune {
39 
41 namespace 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 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 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 
468  void reserve(size_type capacity)
469  {
470  [[maybe_unused]] const auto &guard =
471  Imp::makeScopeGuard([this]{ syncBaseArray(); });
472  storage_.reserve(capacity);
473  }
474 
481  size_type capacity() const
482  {
483  return storage_.capacity();
484  }
485 
496  void resize(size_type size)
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  std::vector<B, A> storage_;
564  };
565 
571  template<class B, class A>
572  struct FieldTraits< BlockVector<B, A> >
573  {
574  typedef typename FieldTraits<B>::field_type field_type;
575  typedef typename FieldTraits<B>::real_type real_type;
576  };
582  template<class K, class A>
583  std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
584  {
585  typedef typename BlockVector<K, A>::size_type size_type;
586 
587  for (size_type i=0; i<v.size(); i++)
588  s << v[i] << std::endl;
589 
590  return s;
591  }
592 
594 namespace Imp {
595 
614 #ifndef DOXYGEN
615  template<class B, class A>
616 #else
617  template<class B, class A=std::allocator<B> >
618 #endif
619  class BlockVectorWindow : public Imp::block_vector_unmanaged<B,typename A::size_type>
620  {
621  public:
622 
623  //===== type definitions and constants
624 
626  using field_type = typename Imp::BlockTraits<B>::field_type;
627 
629  typedef B block_type;
630 
632  typedef A allocator_type;
633 
635  typedef typename A::size_type size_type;
636 
638  typedef typename Imp::block_vector_unmanaged<B,size_type>::Iterator Iterator;
639 
641  typedef typename Imp::block_vector_unmanaged<B,size_type>::ConstIterator ConstIterator;
642 
643 
644  //===== constructors and such
646  BlockVectorWindow () : Imp::block_vector_unmanaged<B,size_type>()
647  { }
648 
650  BlockVectorWindow (B* _p, size_type _n)
651  {
652  this->n = _n;
653  this->p = _p;
654  }
655 
657  BlockVectorWindow (const BlockVectorWindow& a)
658  {
659  this->n = a.n;
660  this->p = a.p;
661  }
662 
664  BlockVectorWindow& operator= (const BlockVectorWindow& a)
665  {
666  // check correct size
667 #ifdef DUNE_ISTL_WITH_CHECKING
668  if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
669 #endif
670 
671  if (&a!=this) // check if this and a are different objects
672  {
673  // copy data
674  for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
675  }
676  return *this;
677  }
678 
680  BlockVectorWindow& operator= (const field_type& k)
681  {
682  (static_cast<Imp::block_vector_unmanaged<B,size_type>&>(*this)) = k;
683  return *this;
684  }
685 
687  operator BlockVector<B, A>() const {
688  auto bv = BlockVector<B, A>(this->n);
689 
690  std::copy(this->begin(), this->end(), bv.begin());
691 
692  return bv;
693  }
694 
695  //===== window manipulation methods
696 
698  void set (size_type _n, B* _p)
699  {
700  this->n = _n;
701  this->p = _p;
702  }
703 
705  void setsize (size_type _n)
706  {
707  this->n = _n;
708  }
709 
711  void setptr (B* _p)
712  {
713  this->p = _p;
714  }
715 
717  B* getptr ()
718  {
719  return this->p;
720  }
721 
723  size_type getsize () const
724  {
725  return this->n;
726  }
727  };
728 
729 
730 
741  template<class B, class ST=std::size_t >
742  class compressed_block_vector_unmanaged : public compressed_base_array_unmanaged<B,ST>
743  {
744  public:
745 
746  //===== type definitions and constants
747 
749  using field_type = typename Imp::BlockTraits<B>::field_type;
750 
752  typedef B block_type;
753 
755  typedef typename compressed_base_array_unmanaged<B,ST>::iterator Iterator;
756 
758  typedef typename compressed_base_array_unmanaged<B,ST>::const_iterator ConstIterator;
759 
761  typedef ST size_type;
762 
763  //===== assignment from scalar
764 
765  compressed_block_vector_unmanaged& operator= (const field_type& k)
766  {
767  for (size_type i=0; i<this->n; i++)
768  (this->p)[i] = k;
769  return *this;
770  }
771 
772 
773  //===== vector space arithmetic
774 
776  template<class V>
777  compressed_block_vector_unmanaged& operator+= (const V& y)
778  {
779 #ifdef DUNE_ISTL_WITH_CHECKING
780  if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
781 #endif
782  for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) += y.p[i];
783  return *this;
784  }
785 
787  template<class V>
788  compressed_block_vector_unmanaged& operator-= (const V& y)
789  {
790 #ifdef DUNE_ISTL_WITH_CHECKING
791  if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
792 #endif
793  for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) -= y.p[i];
794  return *this;
795  }
796 
798  template<class V>
799  compressed_block_vector_unmanaged& axpy (const field_type& a, const V& y)
800  {
801 #ifdef DUNE_ISTL_WITH_CHECKING
802  if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
803 #endif
804  for (size_type i=0; i<y.n; ++i)
805  Impl::asVector((*this)[y.j[i]]).axpy(a,Impl::asVector(y.p[i]));
806  return *this;
807  }
808 
810  compressed_block_vector_unmanaged& operator*= (const field_type& k)
811  {
812  for (size_type i=0; i<this->n; ++i) (this->p)[i] *= k;
813  return *this;
814  }
815 
817  compressed_block_vector_unmanaged& operator/= (const field_type& k)
818  {
819  for (size_type i=0; i<this->n; ++i) (this->p)[i] /= k;
820  return *this;
821  }
822 
823 
824  //===== Euclidean scalar product
825 
827  field_type operator* (const compressed_block_vector_unmanaged& y) const
828  {
829 #ifdef DUNE_ISTL_WITH_CHECKING
830  if (!includesindexset(y) || !y.includesindexset(*this) )
831  DUNE_THROW(ISTLError,"index set mismatch");
832 #endif
833  field_type sum=0;
834  for (size_type i=0; i<this->n; ++i)
835  sum += (this->p)[i] * y[(this->j)[i]];
836  return sum;
837  }
838 
839 
840  //===== norms
841 
843  typename FieldTraits<field_type>::real_type one_norm () const
844  {
845  typename FieldTraits<field_type>::real_type sum=0;
846  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm();
847  return sum;
848  }
849 
851  typename FieldTraits<field_type>::real_type one_norm_real () const
852  {
853  typename FieldTraits<field_type>::real_type sum=0;
854  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm_real();
855  return sum;
856  }
857 
859  typename FieldTraits<field_type>::real_type two_norm () const
860  {
861  using std::sqrt;
862  typename FieldTraits<field_type>::real_type sum=0;
863  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
864  return sqrt(sum);
865  }
866 
868  typename FieldTraits<field_type>::real_type two_norm2 () const
869  {
870  typename FieldTraits<field_type>::real_type sum=0;
871  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
872  return sum;
873  }
874 
876  template <typename ft = field_type,
877  typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
878  typename FieldTraits<ft>::real_type infinity_norm() const {
879  using real_type = typename FieldTraits<ft>::real_type;
880  using std::max;
881 
882  real_type norm = 0;
883  for (auto const &x : *this) {
884  real_type const a = x.infinity_norm();
885  norm = max(a, norm);
886  }
887  return norm;
888  }
889 
891  template <typename ft = field_type,
892  typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
893  typename FieldTraits<ft>::real_type infinity_norm_real() const {
894  using real_type = typename FieldTraits<ft>::real_type;
895  using std::max;
896 
897  real_type norm = 0;
898  for (auto const &x : *this) {
899  real_type const a = x.infinity_norm_real();
900  norm = max(a, norm);
901  }
902  return norm;
903  }
904 
906  template <typename ft = field_type,
907  typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
908  typename FieldTraits<ft>::real_type infinity_norm() const {
909  using real_type = typename FieldTraits<ft>::real_type;
910  using std::max;
911 
912  real_type norm = 0;
913  real_type isNaN = 1;
914  for (auto const &x : *this) {
915  real_type const a = x.infinity_norm();
916  norm = max(a, norm);
917  isNaN += a;
918  }
919  return norm * (isNaN / isNaN);
920  }
921 
923  template <typename ft = field_type,
924  typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
925  typename FieldTraits<ft>::real_type infinity_norm_real() const {
926  using real_type = typename FieldTraits<ft>::real_type;
927  using std::max;
928 
929  real_type norm = 0;
930  real_type isNaN = 1;
931  for (auto const &x : *this) {
932  real_type const a = x.infinity_norm_real();
933  norm = max(a, norm);
934  isNaN += a;
935  }
936  return norm * (isNaN / isNaN);
937  }
938 
939  //===== sizes
940 
942  size_type N () const
943  {
944  return this->n;
945  }
946 
948  size_type dim () const
949  {
950  size_type d=0;
951  for (size_type i=0; i<this->n; i++)
952  d += (this->p)[i].dim();
953  return d;
954  }
955 
956  protected:
958  compressed_block_vector_unmanaged () : compressed_base_array_unmanaged<B,ST>()
959  { }
960 
962  template<class V>
963  bool includesindexset (const V& y)
964  {
965  typename V::ConstIterator e=this->end();
966  for (size_type i=0; i<y.n; i++)
967  if (this->find(y.j[i])==e)
968  return false;
969  return true;
970  }
971  };
972 
973 
992  template<class B, class ST=std::size_t >
993  class CompressedBlockVectorWindow : public compressed_block_vector_unmanaged<B,ST>
994  {
995  public:
996 
997  //===== type definitions and constants
998 
1000  using field_type = typename Imp::BlockTraits<B>::field_type;
1001 
1003  typedef B block_type;
1004 
1006  typedef ST size_type;
1007 
1009  typedef typename compressed_block_vector_unmanaged<B,ST>::Iterator Iterator;
1010 
1012  typedef typename compressed_block_vector_unmanaged<B,ST>::ConstIterator ConstIterator;
1013 
1014 
1015  //===== constructors and such
1017  CompressedBlockVectorWindow () : compressed_block_vector_unmanaged<B,ST>()
1018  { }
1019 
1021  CompressedBlockVectorWindow (B* _p, size_type* _j, size_type _n)
1022  {
1023  this->n = _n;
1024  this->p = _p;
1025  this->j = _j;
1026  }
1027 
1029  CompressedBlockVectorWindow (const CompressedBlockVectorWindow& a)
1030  {
1031  this->n = a.n;
1032  this->p = a.p;
1033  this->j = a.j;
1034  }
1035 
1037  CompressedBlockVectorWindow& operator= (const CompressedBlockVectorWindow& a)
1038  {
1039  // check correct size
1040 #ifdef DUNE_ISTL_WITH_CHECKING
1041  if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
1042 #endif
1043 
1044  if (&a!=this) // check if this and a are different objects
1045  {
1046  // copy data
1047  for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
1048  for (size_type i=0; i<this->n; i++) this->j[i]=a.j[i];
1049  }
1050  return *this;
1051  }
1052 
1054  CompressedBlockVectorWindow& operator= (const field_type& k)
1055  {
1056  (static_cast<compressed_block_vector_unmanaged<B,ST>&>(*this)) = k;
1057  return *this;
1058  }
1059 
1060 
1061  //===== window manipulation methods
1062 
1064  void set (size_type _n, B* _p, size_type* _j)
1065  {
1066  this->n = _n;
1067  this->p = _p;
1068  this->j = _j;
1069  }
1070 
1072  void setsize (size_type _n)
1073  {
1074  this->n = _n;
1075  }
1076 
1078  void setptr (B* _p)
1079  {
1080  this->p = _p;
1081  }
1082 
1084  void setindexptr (size_type* _j)
1085  {
1086  this->j = _j;
1087  }
1088 
1090  B* getptr ()
1091  {
1092  return this->p;
1093  }
1094 
1096  size_type* getindexptr ()
1097  {
1098  return this->j;
1099  }
1100 
1102  const B* getptr () const
1103  {
1104  return this->p;
1105  }
1106 
1108  const size_type* getindexptr () const
1109  {
1110  return this->j;
1111  }
1113  size_type getsize () const
1114  {
1115  return this->n;
1116  }
1117  };
1118 
1119 } // end namespace 'Imp'
1120 
1121 
1123  template<typename B, typename A>
1124  struct AutonomousValueType<Imp::BlockVectorWindow<B,A>>
1125  {
1126  using type = BlockVector<B, A>;
1127  };
1128 
1129 
1130 } // end namespace 'Dune'
1131 
1132 #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 & operator=(const BlockVector &a) noexcept(noexcept(std::declval< BlockVector >().storage_=a.storage_))
assignment
Definition: bvector.hh:519
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
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bvector.hh:398
A::size_type size_type
The type for the index access.
Definition: bvector.hh:407
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:42
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
Dune namespace.
Definition: alignedallocator.hh:13
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  |  generated with Hugo v0.80.0 (May 2, 22:35, 2024)