Dune Core Modules (2.7.1)

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 
18 #include <dune/common/ftraits.hh>
19 #include <dune/common/fmatrix.hh>
20 #include <dune/common/fvector.hh>
23 #include <dune/common/unused.hh>
25 
26 #include "basearray.hh"
27 #include "istlexception.hh"
28 
36 namespace Dune {
37 
39 namespace 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  static constexpr unsigned int blockLevel()
56  {
57  return 0;
58  }
59  };
60 
61  template <class B>
62  class BlockTraitsImp<B,false>
63  {
64  public:
65  using field_type = typename B::field_type;
66 
67  static constexpr unsigned int blockLevel()
68  {
69  return B::blocklevel;
70  }
71  };
72 
75  template <class B>
76  using BlockTraits = BlockTraitsImp<B,IsNumber<B>::value>;
77 
91  template<class B, class A=std::allocator<B> >
92  class block_vector_unmanaged : public base_array_unmanaged<B,A>
93  {
94  public:
95 
96  //===== type definitions and constants
97  using field_type = typename Imp::BlockTraits<B>::field_type;
98 
100  typedef B block_type;
101 
103  typedef A allocator_type;
104 
106  typedef typename A::size_type size_type;
107 
109  typedef typename base_array_unmanaged<B,A>::iterator Iterator;
110 
112  typedef typename base_array_unmanaged<B,A>::const_iterator ConstIterator;
113 
115  typedef B value_type;
116 
118  typedef B& reference;
119 
121  typedef const B& const_reference;
122 
123  //===== assignment from scalar
125 
126  block_vector_unmanaged& operator= (const field_type& k)
127  {
128  for (size_type i=0; i<this->n; i++)
129  (*this)[i] = k;
130  return *this;
131  }
132 
133  //===== vector space arithmetic
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 block_vector_unmanaged& y)
146  {
147 #ifdef DUNE_ISTL_WITH_CHECKING
148  if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
149 #endif
150  for (size_type i=0; i<this->n; ++i) (*this)[i] -= y[i];
151  return *this;
152  }
153 
155  block_vector_unmanaged& operator*= (const field_type& k)
156  {
157  for (size_type i=0; i<this->n; ++i) (*this)[i] *= k;
158  return *this;
159  }
160 
162  block_vector_unmanaged& operator/= (const field_type& k)
163  {
164  for (size_type i=0; i<this->n; ++i) (*this)[i] /= k;
165  return *this;
166  }
167 
169  block_vector_unmanaged& axpy (const field_type& a, const block_vector_unmanaged& y)
170  {
171 #ifdef DUNE_ISTL_WITH_CHECKING
172  if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
173 #endif
174  for (size_type i=0; i<this->n; ++i)
175  Impl::asVector((*this)[i]).axpy(a,Impl::asVector(y[i]));
176 
177  return *this;
178  }
179 
180 
188  template<class OtherB, class OtherA>
189  auto operator* (const block_vector_unmanaged<OtherB,OtherA>& y) const
190  {
191  typedef typename PromotionTraits<field_type,typename BlockTraits<OtherB>::field_type>::PromotedType PromotedType;
192  PromotedType sum(0);
193 #ifdef DUNE_ISTL_WITH_CHECKING
194  if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
195 #endif
196  for (size_type i=0; i<this->n; ++i) {
197  sum += PromotedType(((*this)[i])*y[i]);
198  }
199  return sum;
200  }
201 
209  template<class OtherB, class OtherA>
210  auto dot(const block_vector_unmanaged<OtherB,OtherA>& y) const
211  {
212  typedef typename PromotionTraits<field_type,typename BlockTraits<OtherB>::field_type>::PromotedType PromotedType;
213  PromotedType sum(0);
214 #ifdef DUNE_ISTL_WITH_CHECKING
215  if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
216 #endif
217 
218  for (size_type i=0; i<this->n; ++i)
219  sum += Impl::asVector((*this)[i]).dot(Impl::asVector(y[i]));
220 
221  return sum;
222  }
223 
224  //===== norms
225 
227  typename FieldTraits<field_type>::real_type one_norm () const
228  {
229  typename FieldTraits<field_type>::real_type sum=0;
230  for (size_type i=0; i<this->n; ++i)
231  sum += Impl::asVector((*this)[i]).one_norm();
232  return sum;
233  }
234 
236  typename FieldTraits<field_type>::real_type one_norm_real () const
237  {
238  typename FieldTraits<field_type>::real_type sum=0;
239  for (size_type i=0; i<this->n; ++i)
240  sum += Impl::asVector((*this)[i]).one_norm_real();
241  return sum;
242  }
243 
245  typename FieldTraits<field_type>::real_type two_norm () const
246  {
247  using std::sqrt;
248  return sqrt(two_norm2());
249  }
250 
252  typename FieldTraits<field_type>::real_type two_norm2 () const
253  {
254  typename FieldTraits<field_type>::real_type sum=0;
255  for (size_type i=0; i<this->n; ++i)
256  sum += Impl::asVector((*this)[i]).two_norm2();
257  return sum;
258  }
259 
261  template <typename ft = field_type,
262  typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
263  typename FieldTraits<ft>::real_type infinity_norm() const {
264  using real_type = typename FieldTraits<ft>::real_type;
265  using std::max;
266 
267  real_type norm = 0;
268  for (auto const &xi : *this) {
269  real_type const a = Impl::asVector(xi).infinity_norm();
270  norm = max(a, norm);
271  }
272  return norm;
273  }
274 
276  template <typename ft = field_type,
277  typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
278  typename FieldTraits<ft>::real_type infinity_norm_real() const {
279  using real_type = typename FieldTraits<ft>::real_type;
280  using std::max;
281 
282  real_type norm = 0;
283  for (auto const &xi : *this) {
284  real_type const a = Impl::asVector(xi).infinity_norm_real();
285  norm = max(a, norm);
286  }
287  return norm;
288  }
289 
291  template <typename ft = field_type,
292  typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
293  typename FieldTraits<ft>::real_type infinity_norm() const {
294  using real_type = typename FieldTraits<ft>::real_type;
295  using std::max;
296  using std::abs;
297 
298  real_type norm = 0;
299  real_type isNaN = 1;
300 
301  for (auto const &xi : *this) {
302  real_type const a = Impl::asVector(xi).infinity_norm();
303  norm = max(a, norm);
304  isNaN += a;
305  }
306  return norm * (isNaN / isNaN);
307  }
308 
310  template <typename ft = field_type,
311  typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
312  typename FieldTraits<ft>::real_type infinity_norm_real() const {
313  using real_type = typename FieldTraits<ft>::real_type;
314  using std::max;
315 
316  real_type norm = 0;
317  real_type isNaN = 1;
318 
319  for (auto const &xi : *this) {
320  real_type const a = Impl::asVector(xi).infinity_norm_real();
321  norm = max(a, norm);
322  isNaN += a;
323  }
324 
325  return norm * (isNaN / isNaN);
326  }
327 
328  //===== sizes
329 
331  size_type N () const
332  {
333  return this->n;
334  }
335 
337  size_type dim () const
338  {
339  size_type d=0;
340 
341  for (size_type i=0; i<this->n; i++)
342  d += Impl::asVector((*this)[i]).dim();
343 
344  return d;
345  }
346 
347  protected:
349  block_vector_unmanaged () : base_array_unmanaged<B,A>()
350  { }
351  };
352 
354 
359  template<class F>
360  class ScopeGuard {
361  F cleanupFunc_;
362  public:
363  ScopeGuard(F cleanupFunc) : cleanupFunc_(std::move(cleanupFunc)) {}
364  ScopeGuard(const ScopeGuard &) = delete;
365  ScopeGuard(ScopeGuard &&) = delete;
366  ScopeGuard &operator=(ScopeGuard) = delete;
367  ~ScopeGuard() { cleanupFunc_(); }
368  };
369 
371 
380  template<class F>
381  ScopeGuard<F> makeScopeGuard(F cleanupFunc)
382  {
383  return { std::move(cleanupFunc) };
384  }
385 
386 } // end namespace Imp
401  template<class B, class A=std::allocator<B> >
402  class BlockVector : public Imp::block_vector_unmanaged<B,A>
403  {
404  public:
405 
406  //===== type definitions and constants
407 
409  using field_type = typename Imp::BlockTraits<B>::field_type;
410 
412  typedef B block_type;
413 
415  typedef A allocator_type;
416 
418  typedef typename A::size_type size_type;
419 
421  static constexpr unsigned int blocklevel = Imp::BlockTraits<B>::blockLevel()+1;
422 
424  typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator;
425 
427  typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
428 
429  //===== constructors and such
430 
433  {
434  syncBaseArray();
435  }
436 
438  explicit BlockVector (size_type _n) : storage_(_n)
439  {
440  syncBaseArray();
441  }
442 
444  BlockVector (std::initializer_list<B> const &l) : storage_(l)
445  {
446  syncBaseArray();
447  }
448 
449 
461  template<typename S>
462  BlockVector (size_type _n, S _capacity)
463  {
464  static_assert(std::numeric_limits<S>::is_integer,
465  "capacity must be an unsigned integral type (be aware, that this constructor does not set the default value!)" );
466  if((size_type)_capacity > _n)
467  storage_.reserve(_capacity);
468  storage_.resize(_n);
469  syncBaseArray();
470  }
471 
472 
483  {
484  DUNE_UNUSED const auto &guard =
485  Imp::makeScopeGuard([this]{ syncBaseArray(); });
486  storage_.reserve(capacity);
487  }
488 
508  DUNE_DEPRECATED_MSG("Use the overload without the second parameter, "
509  "values are always copied")
510  void reserve(size_type capacity, bool copyOldValues)
511  {
512  reserve(capacity);
513  }
514 
522  {
523  return storage_.capacity();
524  }
525 
536  void resize(size_type size)
537  {
538  DUNE_UNUSED const auto &guard =
539  Imp::makeScopeGuard([this]{ syncBaseArray(); });
540  storage_.resize(size);
541  }
542 
560  DUNE_DEPRECATED_MSG("Use the overload without the second parameter, "
561  "values are always copied")
562  void resize(size_type size, bool copyOldValues)
563  {
564  resize(size);
565  }
566 
567 
568 
569 
572  noexcept(noexcept(std::declval<BlockVector>().storage_ = a.storage_))
573  {
574  storage_ = a.storage_;
575  syncBaseArray();
576  }
577 
580  noexcept(noexcept(std::declval<BlockVector>().swap(a)))
581  {
582  swap(a);
583  }
584 
587  noexcept(noexcept(std::declval<BlockVector>().storage_ = a.storage_))
588  {
589  DUNE_UNUSED const auto &guard =
590  Imp::makeScopeGuard([this]{ syncBaseArray(); });
591  storage_ = a.storage_;
592  return *this;
593  }
594 
597  noexcept(noexcept(std::declval<BlockVector>().swap(a)))
598  {
599  swap(a);
600  return *this;
601  }
602 
604  void swap(BlockVector &other)
605  noexcept(noexcept(
606  std::declval<BlockVector&>().storage_.swap(other.storage_)))
607  {
608  DUNE_UNUSED const auto &guard = Imp::makeScopeGuard([&]{
609  syncBaseArray();
610  other.syncBaseArray();
611  });
612  storage_.swap(other.storage_);
613  }
614 
617  {
618  // forward to operator= in base class
619  (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k;
620  return *this;
621  }
622 
623  private:
624  void syncBaseArray() noexcept
625  {
626  this->p = storage_.data();
627  this->n = storage_.size();
628  }
629 
630  std::vector<B, A> storage_;
631  };
632 
638  template<class B, class A>
639  struct FieldTraits< BlockVector<B, A> >
640  {
641  typedef typename FieldTraits<B>::field_type field_type;
642  typedef typename FieldTraits<B>::real_type real_type;
643  };
649  template<class K, class A>
650  std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
651  {
652  typedef typename BlockVector<K, A>::size_type size_type;
653 
654  for (size_type i=0; i<v.size(); i++)
655  s << v[i] << std::endl;
656 
657  return s;
658  }
659 
661 namespace Imp {
662 
681 #ifndef DOXYGEN
682  template<class B, class A>
683 #else
684  template<class B, class A=std::allocator<B> >
685 #endif
686  class BlockVectorWindow : public Imp::block_vector_unmanaged<B,A>
687  {
688  public:
689 
690  //===== type definitions and constants
691 
693  using field_type = typename Imp::BlockTraits<B>::field_type;
694 
696  typedef B block_type;
697 
699  typedef A allocator_type;
700 
702  typedef typename A::size_type size_type;
703 
705  static constexpr unsigned int blocklevel = Imp::BlockTraits<B>::blockLevel()+1;
706 
708  typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator;
709 
711  typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
712 
713 
714  //===== constructors and such
716  BlockVectorWindow () : Imp::block_vector_unmanaged<B,A>()
717  { }
718 
720  BlockVectorWindow (B* _p, size_type _n)
721  {
722  this->n = _n;
723  this->p = _p;
724  }
725 
727  BlockVectorWindow (const BlockVectorWindow& a)
728  {
729  this->n = a.n;
730  this->p = a.p;
731  }
732 
734  BlockVectorWindow& operator= (const BlockVectorWindow& a)
735  {
736  // check correct size
737 #ifdef DUNE_ISTL_WITH_CHECKING
738  if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
739 #endif
740 
741  if (&a!=this) // check if this and a are different objects
742  {
743  // copy data
744  for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
745  }
746  return *this;
747  }
748 
750  BlockVectorWindow& operator= (const field_type& k)
751  {
752  (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k;
753  return *this;
754  }
755 
757  operator BlockVector<B, A>() const {
758  auto bv = BlockVector<B, A>(this->n);
759 
760  std::copy(this->begin(), this->end(), bv.begin());
761 
762  return bv;
763  }
764 
765  //===== window manipulation methods
766 
768  void set (size_type _n, B* _p)
769  {
770  this->n = _n;
771  this->p = _p;
772  }
773 
775  void setsize (size_type _n)
776  {
777  this->n = _n;
778  }
779 
781  void setptr (B* _p)
782  {
783  this->p = _p;
784  }
785 
787  B* getptr ()
788  {
789  return this->p;
790  }
791 
793  size_type getsize () const
794  {
795  return this->n;
796  }
797  };
798 
799 
800 
811  template<class B, class A=std::allocator<B> >
812  class compressed_block_vector_unmanaged : public compressed_base_array_unmanaged<B,A>
813  {
814  public:
815 
816  //===== type definitions and constants
817 
819  using field_type = typename Imp::BlockTraits<B>::field_type;
820 
822  typedef B block_type;
823 
825  typedef A allocator_type;
826 
828  typedef typename compressed_base_array_unmanaged<B,A>::iterator Iterator;
829 
831  typedef typename compressed_base_array_unmanaged<B,A>::const_iterator ConstIterator;
832 
834  typedef typename A::size_type size_type;
835 
836  //===== assignment from scalar
837 
838  compressed_block_vector_unmanaged& operator= (const field_type& k)
839  {
840  for (size_type i=0; i<this->n; i++)
841  (this->p)[i] = k;
842  return *this;
843  }
844 
845 
846  //===== vector space arithmetic
847 
849  template<class V>
850  compressed_block_vector_unmanaged& operator+= (const V& y)
851  {
852 #ifdef DUNE_ISTL_WITH_CHECKING
853  if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
854 #endif
855  for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) += y.p[i];
856  return *this;
857  }
858 
860  template<class V>
861  compressed_block_vector_unmanaged& operator-= (const V& y)
862  {
863 #ifdef DUNE_ISTL_WITH_CHECKING
864  if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
865 #endif
866  for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) -= y.p[i];
867  return *this;
868  }
869 
871  template<class V>
872  compressed_block_vector_unmanaged& axpy (const field_type& a, const V& y)
873  {
874 #ifdef DUNE_ISTL_WITH_CHECKING
875  if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
876 #endif
877  for (size_type i=0; i<y.n; ++i)
878  Impl::asVector((*this)[y.j[i]]).axpy(a,Impl::asVector(y.p[i]));
879  return *this;
880  }
881 
883  compressed_block_vector_unmanaged& operator*= (const field_type& k)
884  {
885  for (size_type i=0; i<this->n; ++i) (this->p)[i] *= k;
886  return *this;
887  }
888 
890  compressed_block_vector_unmanaged& operator/= (const field_type& k)
891  {
892  for (size_type i=0; i<this->n; ++i) (this->p)[i] /= k;
893  return *this;
894  }
895 
896 
897  //===== Euclidean scalar product
898 
900  field_type operator* (const compressed_block_vector_unmanaged& y) const
901  {
902 #ifdef DUNE_ISTL_WITH_CHECKING
903  if (!includesindexset(y) || !y.includesindexset(*this) )
904  DUNE_THROW(ISTLError,"index set mismatch");
905 #endif
906  field_type sum=0;
907  for (size_type i=0; i<this->n; ++i)
908  sum += (this->p)[i] * y[(this->j)[i]];
909  return sum;
910  }
911 
912 
913  //===== norms
914 
916  typename FieldTraits<field_type>::real_type one_norm () const
917  {
918  typename FieldTraits<field_type>::real_type sum=0;
919  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm();
920  return sum;
921  }
922 
924  typename FieldTraits<field_type>::real_type one_norm_real () const
925  {
926  typename FieldTraits<field_type>::real_type sum=0;
927  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm_real();
928  return sum;
929  }
930 
932  typename FieldTraits<field_type>::real_type two_norm () const
933  {
934  using std::sqrt;
935  typename FieldTraits<field_type>::real_type sum=0;
936  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
937  return sqrt(sum);
938  }
939 
941  typename FieldTraits<field_type>::real_type two_norm2 () const
942  {
943  typename FieldTraits<field_type>::real_type sum=0;
944  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
945  return sum;
946  }
947 
949  template <typename ft = field_type,
950  typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
951  typename FieldTraits<ft>::real_type infinity_norm() const {
952  using real_type = typename FieldTraits<ft>::real_type;
953  using std::max;
954 
955  real_type norm = 0;
956  for (auto const &x : *this) {
957  real_type const a = x.infinity_norm();
958  norm = max(a, norm);
959  }
960  return norm;
961  }
962 
964  template <typename ft = field_type,
965  typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
966  typename FieldTraits<ft>::real_type infinity_norm_real() const {
967  using real_type = typename FieldTraits<ft>::real_type;
968  using std::max;
969 
970  real_type norm = 0;
971  for (auto const &x : *this) {
972  real_type const a = x.infinity_norm_real();
973  norm = max(a, norm);
974  }
975  return norm;
976  }
977 
979  template <typename ft = field_type,
980  typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
981  typename FieldTraits<ft>::real_type infinity_norm() const {
982  using real_type = typename FieldTraits<ft>::real_type;
983  using std::max;
984 
985  real_type norm = 0;
986  real_type isNaN = 1;
987  for (auto const &x : *this) {
988  real_type const a = x.infinity_norm();
989  norm = max(a, norm);
990  isNaN += a;
991  }
992  return norm * (isNaN / isNaN);
993  }
994 
996  template <typename ft = field_type,
997  typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
998  typename FieldTraits<ft>::real_type infinity_norm_real() const {
999  using real_type = typename FieldTraits<ft>::real_type;
1000  using std::max;
1001 
1002  real_type norm = 0;
1003  real_type isNaN = 1;
1004  for (auto const &x : *this) {
1005  real_type const a = x.infinity_norm_real();
1006  norm = max(a, norm);
1007  isNaN += a;
1008  }
1009  return norm * (isNaN / isNaN);
1010  }
1011 
1012  //===== sizes
1013 
1015  size_type N () const
1016  {
1017  return this->n;
1018  }
1019 
1021  size_type dim () const
1022  {
1023  size_type d=0;
1024  for (size_type i=0; i<this->n; i++)
1025  d += (this->p)[i].dim();
1026  return d;
1027  }
1028 
1029  protected:
1031  compressed_block_vector_unmanaged () : compressed_base_array_unmanaged<B,A>()
1032  { }
1033 
1035  template<class V>
1036  bool includesindexset (const V& y)
1037  {
1038  typename V::ConstIterator e=this->end();
1039  for (size_type i=0; i<y.n; i++)
1040  if (this->find(y.j[i])==e)
1041  return false;
1042  return true;
1043  }
1044  };
1045 
1046 
1065  template<class B, class A=std::allocator<B> >
1066  class CompressedBlockVectorWindow : public compressed_block_vector_unmanaged<B,A>
1067  {
1068  public:
1069 
1070  //===== type definitions and constants
1071 
1073  using field_type = typename Imp::BlockTraits<B>::field_type;
1074 
1076  typedef B block_type;
1077 
1079  typedef A allocator_type;
1080 
1082  typedef typename A::size_type size_type;
1083 
1085  static constexpr unsigned int blocklevel = Imp::BlockTraits<B>::blockLevel()+1;
1086 
1088  typedef typename compressed_block_vector_unmanaged<B,A>::Iterator Iterator;
1089 
1091  typedef typename compressed_block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
1092 
1093 
1094  //===== constructors and such
1096  CompressedBlockVectorWindow () : compressed_block_vector_unmanaged<B,A>()
1097  { }
1098 
1100  CompressedBlockVectorWindow (B* _p, size_type* _j, size_type _n)
1101  {
1102  this->n = _n;
1103  this->p = _p;
1104  this->j = _j;
1105  }
1106 
1108  CompressedBlockVectorWindow (const CompressedBlockVectorWindow& a)
1109  {
1110  this->n = a.n;
1111  this->p = a.p;
1112  this->j = a.j;
1113  }
1114 
1116  CompressedBlockVectorWindow& operator= (const CompressedBlockVectorWindow& a)
1117  {
1118  // check correct size
1119 #ifdef DUNE_ISTL_WITH_CHECKING
1120  if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
1121 #endif
1122 
1123  if (&a!=this) // check if this and a are different objects
1124  {
1125  // copy data
1126  for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
1127  for (size_type i=0; i<this->n; i++) this->j[i]=a.j[i];
1128  }
1129  return *this;
1130  }
1131 
1133  CompressedBlockVectorWindow& operator= (const field_type& k)
1134  {
1135  (static_cast<compressed_block_vector_unmanaged<B,A>&>(*this)) = k;
1136  return *this;
1137  }
1138 
1139 
1140  //===== window manipulation methods
1141 
1143  void set (size_type _n, B* _p, size_type* _j)
1144  {
1145  this->n = _n;
1146  this->p = _p;
1147  this->j = _j;
1148  }
1149 
1151  void setsize (size_type _n)
1152  {
1153  this->n = _n;
1154  }
1155 
1157  void setptr (B* _p)
1158  {
1159  this->p = _p;
1160  }
1161 
1163  void setindexptr (size_type* _j)
1164  {
1165  this->j = _j;
1166  }
1167 
1169  B* getptr ()
1170  {
1171  return this->p;
1172  }
1173 
1175  size_type* getindexptr ()
1176  {
1177  return this->j;
1178  }
1179 
1181  const B* getptr () const
1182  {
1183  return this->p;
1184  }
1185 
1187  const size_type* getindexptr () const
1188  {
1189  return this->j;
1190  }
1192  size_type getsize () const
1193  {
1194  return this->n;
1195  }
1196  };
1197 
1198 } // end namespace 'Imp'
1199 
1200 
1202  template<typename B, typename A>
1203  struct AutonomousValueType<Imp::BlockVectorWindow<B,A>>
1204  {
1205  using type = BlockVector<B, A>;
1206  };
1207 
1208 
1209 } // end namespace 'Dune'
1210 
1211 #endif
Implements several basic array containers.
A vector of blocks with memory management.
Definition: bvector.hh:403
BlockVector()
makes empty vector
Definition: bvector.hh:432
void reserve(size_type capacity)
Reserve space.
Definition: bvector.hh:482
BlockVector & operator=(const BlockVector &a) noexcept(noexcept(std::declval< BlockVector >().storage_=a.storage_))
assignment
Definition: bvector.hh:586
BlockVector(BlockVector &&a) noexcept(noexcept(std::declval< BlockVector >().swap(a)))
move constructor
Definition: bvector.hh:579
BlockVector(size_type _n)
make vector with _n components
Definition: bvector.hh:438
void resize(size_type size)
Resize the vector.
Definition: bvector.hh:536
Imp::block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:424
static constexpr unsigned int blocklevel
increment block level counter
Definition: bvector.hh:421
BlockVector(const BlockVector &a) noexcept(noexcept(std::declval< BlockVector >().storage_=a.storage_))
copy constructor
Definition: bvector.hh:571
A allocator_type
export the allocator type
Definition: bvector.hh:415
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bvector.hh:409
A::size_type size_type
The type for the index access.
Definition: bvector.hh:418
BlockVector(std::initializer_list< B > const &l)
Construct from a std::initializer_list.
Definition: bvector.hh:444
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:521
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:462
B block_type
export the type representing the components
Definition: bvector.hh:412
void swap(BlockVector &other) noexcept(noexcept(std::declval< BlockVector & >().storage_.swap(other.storage_)))
swap operation
Definition: bvector.hh:604
Imp::block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:427
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
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<!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_UNUSED
A macro for marking variables that the compiler mistakenly flags as unused, which sometimes happens d...
Definition: unused.hh:16
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
#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:14
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.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 9, 22:29, 2024)