Dune Core Modules (2.6.0)

bvector.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_ISTL_BVECTOR_HH
5 #define DUNE_ISTL_BVECTOR_HH
6 
7 #include <cmath>
8 #include <complex>
9 #include <memory>
10 #include <limits>
11 
14 #include <dune/common/ftraits.hh>
15 
16 #include "istlexception.hh"
17 #include "basearray.hh"
18 
26 namespace Dune {
27 
28  template<class B, class A=std::allocator<B> >
29  class BlockVectorWindow;
30 
32 namespace Imp {
33 
47  template<class B, class A=std::allocator<B> >
48  class block_vector_unmanaged : public base_array_unmanaged<B,A>
49  {
50  public:
51 
52  //===== type definitions and constants
53 
55  typedef typename B::field_type field_type;
56 
58  typedef B block_type;
59 
61  typedef A allocator_type;
62 
64  typedef typename A::size_type size_type;
65 
67  typedef typename base_array_unmanaged<B,A>::iterator Iterator;
68 
70  typedef typename base_array_unmanaged<B,A>::const_iterator ConstIterator;
71 
73  typedef B value_type;
74 
76  typedef B& reference;
77 
79  typedef const B& const_reference;
80 
81  //===== assignment from scalar
83 
84  block_vector_unmanaged& operator= (const field_type& k)
85  {
86  for (size_type i=0; i<this->n; i++)
87  (*this)[i] = k;
88  return *this;
89  }
90 
91  //===== vector space arithmetic
93  block_vector_unmanaged& operator+= (const block_vector_unmanaged& y)
94  {
95 #ifdef DUNE_ISTL_WITH_CHECKING
96  if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
97 #endif
98  for (size_type i=0; i<this->n; ++i) (*this)[i] += y[i];
99  return *this;
100  }
101 
103  block_vector_unmanaged& operator-= (const block_vector_unmanaged& y)
104  {
105 #ifdef DUNE_ISTL_WITH_CHECKING
106  if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
107 #endif
108  for (size_type i=0; i<this->n; ++i) (*this)[i] -= y[i];
109  return *this;
110  }
111 
113  block_vector_unmanaged& operator*= (const field_type& k)
114  {
115  for (size_type i=0; i<this->n; ++i) (*this)[i] *= k;
116  return *this;
117  }
118 
120  block_vector_unmanaged& operator/= (const field_type& k)
121  {
122  for (size_type i=0; i<this->n; ++i) (*this)[i] /= k;
123  return *this;
124  }
125 
127  block_vector_unmanaged& axpy (const field_type& a, 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].axpy(a,y[i]);
133  return *this;
134  }
135 
136 
144  template<class OtherB, class OtherA>
145  typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType operator* (const block_vector_unmanaged<OtherB,OtherA>& y) const
146  {
147  typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
148  PromotedType sum(0);
149 #ifdef DUNE_ISTL_WITH_CHECKING
150  if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
151 #endif
152  for (size_type i=0; i<this->n; ++i) {
153  sum += PromotedType(((*this)[i])*y[i]);
154  }
155  return sum;
156  }
157 
165  template<class OtherB, class OtherA>
166  typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType dot(const block_vector_unmanaged<OtherB,OtherA>& y) const
167  {
168  typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
169  PromotedType sum(0);
170 #ifdef DUNE_ISTL_WITH_CHECKING
171  if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
172 #endif
173  for (size_type i=0; i<this->n; ++i) sum += ((*this)[i]).dot(y[i]);
174  return sum;
175  }
176 
177  //===== norms
178 
180  typename FieldTraits<field_type>::real_type one_norm () const
181  {
182  typename FieldTraits<field_type>::real_type sum=0;
183  for (size_type i=0; i<this->n; ++i) sum += (*this)[i].one_norm();
184  return sum;
185  }
186 
188  typename FieldTraits<field_type>::real_type one_norm_real () const
189  {
190  typename FieldTraits<field_type>::real_type sum=0;
191  for (size_type i=0; i<this->n; ++i) sum += (*this)[i].one_norm_real();
192  return sum;
193  }
194 
196  typename FieldTraits<field_type>::real_type two_norm () const
197  {
198  typename FieldTraits<field_type>::real_type sum=0;
199  for (size_type i=0; i<this->n; ++i) sum += (*this)[i].two_norm2();
200  return sqrt(sum);
201  }
202 
204  typename FieldTraits<field_type>::real_type two_norm2 () const
205  {
206  typename FieldTraits<field_type>::real_type sum=0;
207  for (size_type i=0; i<this->n; ++i) sum += (*this)[i].two_norm2();
208  return sum;
209  }
210 
212  template <typename ft = field_type,
213  typename std::enable_if<!has_nan<ft>::value, int>::type = 0>
214  typename FieldTraits<ft>::real_type infinity_norm() const {
215  using real_type = typename FieldTraits<ft>::real_type;
216  using std::max;
217 
218  real_type norm = 0;
219  for (auto const &x : *this) {
220  real_type const a = x.infinity_norm();
221  norm = max(a, norm);
222  }
223  return norm;
224  }
225 
227  template <typename ft = field_type,
228  typename std::enable_if<!has_nan<ft>::value, int>::type = 0>
229  typename FieldTraits<ft>::real_type infinity_norm_real() const {
230  using real_type = typename FieldTraits<ft>::real_type;
231  using std::max;
232 
233  real_type norm = 0;
234  for (auto const &x : *this) {
235  real_type const a = x.infinity_norm_real();
236  norm = max(a, norm);
237  }
238  return norm;
239  }
240 
242  template <typename ft = field_type,
243  typename std::enable_if<has_nan<ft>::value, int>::type = 0>
244  typename FieldTraits<ft>::real_type infinity_norm() const {
245  using real_type = typename FieldTraits<ft>::real_type;
246  using std::max;
247 
248  real_type norm = 0;
249  real_type isNaN = 1;
250  for (auto const &x : *this) {
251  real_type const a = x.infinity_norm();
252  norm = max(a, norm);
253  isNaN += a;
254  }
255  isNaN /= isNaN;
256  return norm * isNaN;
257  }
258 
260  template <typename ft = field_type,
261  typename std::enable_if<has_nan<ft>::value, int>::type = 0>
262  typename FieldTraits<ft>::real_type infinity_norm_real() const {
263  using real_type = typename FieldTraits<ft>::real_type;
264  using std::max;
265 
266  real_type norm = 0;
267  real_type isNaN = 1;
268  for (auto const &x : *this) {
269  real_type const a = x.infinity_norm_real();
270  norm = max(a, norm);
271  isNaN += a;
272  }
273  isNaN /= isNaN;
274  return norm * isNaN;
275  }
276 
277  //===== sizes
278 
280  size_type N () const
281  {
282  return this->n;
283  }
284 
286  size_type dim () const
287  {
288  size_type d=0;
289  for (size_type i=0; i<this->n; i++)
290  d += (*this)[i].dim();
291  return d;
292  }
293 
294  protected:
296  block_vector_unmanaged () : base_array_unmanaged<B,A>()
297  { }
298  };
299 
300 } // end namespace Imp
315  template<class B, class A=std::allocator<B> >
316  class BlockVector : public Imp::block_vector_unmanaged<B,A>
317  {
318  public:
319 
320  //===== type definitions and constants
321 
323  typedef typename B::field_type field_type;
324 
326  typedef B block_type;
327 
329  typedef A allocator_type;
330 
332  typedef typename A::size_type size_type;
333 
335  enum {
337  blocklevel = B::blocklevel+1
338  };
339 
341  typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator;
342 
344  typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
345 
346  //===== constructors and such
347 
349  BlockVector () : Imp::block_vector_unmanaged<B,A>(),
350  capacity_(0)
351  {}
352 
354  explicit BlockVector (size_type _n)
355  {
356  this->n = _n;
357  capacity_ = _n;
358  if (capacity_>0) {
359  this->p = this->allocator_.allocate(capacity_);
360  // actually construct the objects
361  new(this->p)B[capacity_];
362  } else
363  {
364  this->p = 0;
365  this->n = 0;
366  capacity_ = 0;
367  }
368  }
369 
371  BlockVector (std::initializer_list<B> const &l)
372  {
373  this->n = l.size();
374  capacity_ = l.size();
375  if (capacity_>0) {
376  this->p = this->allocator_.allocate(capacity_);
377  // actually construct the objects
378  new(this->p)B[capacity_];
379 
380  std::copy_n(l.begin(), l.size(), this->p);
381  } else
382  {
383  this->p = 0;
384  this->n = 0;
385  capacity_ = 0;
386  }
387  }
388 
389 
401  template<typename S>
402  BlockVector (size_type _n, S _capacity)
403  {
404  static_assert(std::numeric_limits<S>::is_integer,
405  "capacity must be an unsigned integral type (be aware, that this constructor does not set the default value!)" );
406  size_type capacity = _capacity;
407  this->n = _n;
408  if(this->n > capacity)
409  capacity_ = _n;
410  else
411  capacity_ = capacity;
412 
413  if (capacity_>0) {
414  this->p = this->allocator_.allocate(capacity_);
415  new (this->p)B[capacity_];
416  } else
417  {
418  this->p = 0;
419  this->n = 0;
420  capacity_ = 0;
421  }
422  }
423 
424 
441  void reserve(size_type capacity, bool copyOldValues=true)
442  {
443  if(capacity >= Imp::block_vector_unmanaged<B,A>::N() && capacity != capacity_) {
444  // save the old data
445  B* pold = this->p;
446 
447  if(capacity>0) {
448  // create new array with capacity
449  this->p = this->allocator_.allocate(capacity);
450  new (this->p)B[capacity];
451 
452  if(copyOldValues) {
453  // copy the old values
454  B* to = this->p;
455  B* from = pold;
456 
457  for(size_type i=0; i < Imp::block_vector_unmanaged<B,A>::N(); ++i, ++from, ++to)
458  *to = *from;
459  }
460  if(capacity_ > 0) {
461  // Destruct old objects and free memory
462  int i=capacity_;
463  while (i)
464  pold[--i].~B();
465  this->allocator_.deallocate(pold,capacity_);
466  }
467  }else{
468  if(capacity_ > 0)
469  // free old data
470  this->p = 0;
471  capacity_ = 0;
472  }
473 
474  capacity_ = capacity;
475  }
476  }
477 
485  {
486  return capacity_;
487  }
488 
503  void resize(size_type size, bool copyOldValues=true)
504  {
505  if (size > Imp::block_vector_unmanaged<B,A>::N())
506  if(capacity_ < size)
507  this->reserve(size, copyOldValues);
508  this->n = size;
509  }
510 
511 
512 
513 
516  Imp::block_vector_unmanaged<B,A>(a)
517  {
518  // allocate memory with same size as a
519  this->n = a.n;
520  capacity_ = a.capacity_;
521 
522  if (capacity_>0) {
523  this->p = this->allocator_.allocate(capacity_);
524  new (this->p)B[capacity_];
525  } else
526  {
527  this->n = 0;
528  this->p = 0;
529  }
530 
531  // and copy elements
532  for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
533  }
534 
537  {
538  if (capacity_>0) {
539  int i=capacity_;
540  while (i)
541  this->p[--i].~B();
542  this->allocator_.deallocate(this->p,capacity_);
543  }
544  }
545 
548  {
549  if (&a!=this) // check if this and a are different objects
550  {
551  // adjust size of vector
552  if (capacity_!=a.capacity_) // check if size is different
553  {
554  if (capacity_>0) {
555  int i=capacity_;
556  while (i)
557  this->p[--i].~B();
558  this->allocator_.deallocate(this->p,capacity_); // free old memory
559  }
560  capacity_ = a.capacity_;
561  if (capacity_>0) {
562  this->p = this->allocator_.allocate(capacity_);
563  new (this->p)B[capacity_];
564  } else
565  {
566  this->p = 0;
567  capacity_ = 0;
568  }
569  }
570  this->n = a.n;
571  // copy data
572  for (size_type i=0; i<this->n; i++)
573  this->p[i]=a.p[i];
574  }
575  return *this;
576  }
577 
580  {
581  // forward to operator= in base class
582  (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k;
583  return *this;
584  }
585 
587  template<class OtherAlloc>
588  BlockVector& operator= (const BlockVectorWindow<B,OtherAlloc>& other)
589  {
590  resize(other.size());
591  for(std::size_t i=0; i<other.size(); ++i)
592  (*this)[i] = other[i];
593  return *this;
594  }
595 
596  protected:
597  size_type capacity_;
598 
599  A allocator_;
600 
601  };
602 
608  template<class B, class A>
609  struct FieldTraits< BlockVector<B, A> >
610  {
611  typedef typename FieldTraits<B>::field_type field_type;
612  typedef typename FieldTraits<B>::real_type real_type;
613  };
619  template<class K, class A>
620  std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
621  {
622  typedef typename BlockVector<K, A>::size_type size_type;
623 
624  for (size_type i=0; i<v.size(); i++)
625  s << v[i] << std::endl;
626 
627  return s;
628  }
629 
631 namespace Imp {
632 
651 #ifndef DOXYGEN
652  template<class B, class A>
653 #else
654  template<class B, class A=std::allocator<B> >
655 #endif
656  class BlockVectorWindow : public Imp::block_vector_unmanaged<B,A>
657  {
658  public:
659 
660  //===== type definitions and constants
661 
663  typedef typename B::field_type field_type;
664 
666  typedef B block_type;
667 
669  typedef A allocator_type;
670 
672  typedef typename A::size_type size_type;
673 
675  enum {
677  blocklevel = B::blocklevel+1
678  };
679 
681  typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator;
682 
684  typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
685 
686 
687  //===== constructors and such
689  BlockVectorWindow () : Imp::block_vector_unmanaged<B,A>()
690  { }
691 
693  BlockVectorWindow (B* _p, size_type _n)
694  {
695  this->n = _n;
696  this->p = _p;
697  }
698 
700  BlockVectorWindow (const BlockVectorWindow& a)
701  {
702  this->n = a.n;
703  this->p = a.p;
704  }
705 
707  BlockVectorWindow& operator= (const BlockVectorWindow& a)
708  {
709  // check correct size
710 #ifdef DUNE_ISTL_WITH_CHECKING
711  if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
712 #endif
713 
714  if (&a!=this) // check if this and a are different objects
715  {
716  // copy data
717  for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
718  }
719  return *this;
720  }
721 
723  BlockVectorWindow& operator= (const field_type& k)
724  {
725  (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k;
726  return *this;
727  }
728 
729 
730  //===== window manipulation methods
731 
733  void set (size_type _n, B* _p)
734  {
735  this->n = _n;
736  this->p = _p;
737  }
738 
740  void setsize (size_type _n)
741  {
742  this->n = _n;
743  }
744 
746  void setptr (B* _p)
747  {
748  this->p = _p;
749  }
750 
752  B* getptr ()
753  {
754  return this->p;
755  }
756 
758  size_type getsize ()
759  {
760  return this->n;
761  }
762  };
763 
764 
765 
776  template<class B, class A=std::allocator<B> >
777  class compressed_block_vector_unmanaged : public compressed_base_array_unmanaged<B,A>
778  {
779  public:
780 
781  //===== type definitions and constants
782 
784  typedef typename B::field_type field_type;
785 
787  typedef B block_type;
788 
790  typedef A allocator_type;
791 
793  typedef typename compressed_base_array_unmanaged<B,A>::iterator Iterator;
794 
796  typedef typename compressed_base_array_unmanaged<B,A>::const_iterator ConstIterator;
797 
799  typedef typename A::size_type size_type;
800 
801  //===== assignment from scalar
802 
803  compressed_block_vector_unmanaged& operator= (const field_type& k)
804  {
805  for (size_type i=0; i<this->n; i++)
806  (this->p)[i] = k;
807  return *this;
808  }
809 
810 
811  //===== vector space arithmetic
812 
814  template<class V>
815  compressed_block_vector_unmanaged& operator+= (const V& y)
816  {
817 #ifdef DUNE_ISTL_WITH_CHECKING
818  if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
819 #endif
820  for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) += y.p[i];
821  return *this;
822  }
823 
825  template<class V>
826  compressed_block_vector_unmanaged& operator-= (const V& y)
827  {
828 #ifdef DUNE_ISTL_WITH_CHECKING
829  if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
830 #endif
831  for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) -= y.p[i];
832  return *this;
833  }
834 
836  template<class V>
837  compressed_block_vector_unmanaged& axpy (const field_type& a, const V& y)
838  {
839 #ifdef DUNE_ISTL_WITH_CHECKING
840  if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
841 #endif
842  for (size_type i=0; i<y.n; ++i) (this->operator[](y.j[i])).axpy(a,y.p[i]);
843  return *this;
844  }
845 
847  compressed_block_vector_unmanaged& operator*= (const field_type& k)
848  {
849  for (size_type i=0; i<this->n; ++i) (this->p)[i] *= k;
850  return *this;
851  }
852 
854  compressed_block_vector_unmanaged& operator/= (const field_type& k)
855  {
856  for (size_type i=0; i<this->n; ++i) (this->p)[i] /= k;
857  return *this;
858  }
859 
860 
861  //===== Euclidean scalar product
862 
864  field_type operator* (const compressed_block_vector_unmanaged& y) const
865  {
866 #ifdef DUNE_ISTL_WITH_CHECKING
867  if (!includesindexset(y) || !y.includesindexset(*this) )
868  DUNE_THROW(ISTLError,"index set mismatch");
869 #endif
870  field_type sum=0;
871  for (size_type i=0; i<this->n; ++i)
872  sum += (this->p)[i] * y[(this->j)[i]];
873  return sum;
874  }
875 
876 
877  //===== norms
878 
880  typename FieldTraits<field_type>::real_type one_norm () const
881  {
882  typename FieldTraits<field_type>::real_type sum=0;
883  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm();
884  return sum;
885  }
886 
888  typename FieldTraits<field_type>::real_type one_norm_real () const
889  {
890  typename FieldTraits<field_type>::real_type sum=0;
891  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm_real();
892  return sum;
893  }
894 
896  typename FieldTraits<field_type>::real_type two_norm () const
897  {
898  typename FieldTraits<field_type>::real_type sum=0;
899  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
900  return sqrt(sum);
901  }
902 
904  typename FieldTraits<field_type>::real_type two_norm2 () const
905  {
906  typename FieldTraits<field_type>::real_type sum=0;
907  for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
908  return sum;
909  }
910 
912  template <typename ft = field_type,
913  typename std::enable_if<!has_nan<ft>::value, int>::type = 0>
914  typename FieldTraits<ft>::real_type infinity_norm() const {
915  using real_type = typename FieldTraits<ft>::real_type;
916  using std::max;
917 
918  real_type norm = 0;
919  for (auto const &x : *this) {
920  real_type const a = x.infinity_norm();
921  norm = max(a, norm);
922  }
923  return norm;
924  }
925 
927  template <typename ft = field_type,
928  typename std::enable_if<!has_nan<ft>::value, int>::type = 0>
929  typename FieldTraits<ft>::real_type infinity_norm_real() const {
930  using real_type = typename FieldTraits<ft>::real_type;
931  using std::max;
932 
933  real_type norm = 0;
934  for (auto const &x : *this) {
935  real_type const a = x.infinity_norm_real();
936  norm = max(a, norm);
937  }
938  return norm;
939  }
940 
942  template <typename ft = field_type,
943  typename std::enable_if<has_nan<ft>::value, int>::type = 0>
944  typename FieldTraits<ft>::real_type infinity_norm() const {
945  using real_type = typename FieldTraits<ft>::real_type;
946  using std::max;
947 
948  real_type norm = 0;
949  real_type isNaN = 1;
950  for (auto const &x : *this) {
951  real_type const a = x.infinity_norm();
952  norm = max(a, norm);
953  isNaN += a;
954  }
955  isNaN /= isNaN;
956  return norm * isNaN;
957  }
958 
960  template <typename ft = field_type,
961  typename std::enable_if<has_nan<ft>::value, int>::type = 0>
962  typename FieldTraits<ft>::real_type infinity_norm_real() const {
963  using real_type = typename FieldTraits<ft>::real_type;
964  using std::max;
965 
966  real_type norm = 0;
967  real_type isNaN = 1;
968  for (auto const &x : *this) {
969  real_type const a = x.infinity_norm_real();
970  norm = max(a, norm);
971  isNaN += a;
972  }
973  isNaN /= isNaN;
974  return norm * isNaN;
975  }
976 
977  //===== sizes
978 
980  size_type N () const
981  {
982  return this->n;
983  }
984 
986  size_type dim () const
987  {
988  size_type d=0;
989  for (size_type i=0; i<this->n; i++)
990  d += (this->p)[i].dim();
991  return d;
992  }
993 
994  protected:
996  compressed_block_vector_unmanaged () : compressed_base_array_unmanaged<B,A>()
997  { }
998 
1000  template<class V>
1001  bool includesindexset (const V& y)
1002  {
1003  typename V::ConstIterator e=this->end();
1004  for (size_type i=0; i<y.n; i++)
1005  if (this->find(y.j[i])==e)
1006  return false;
1007  return true;
1008  }
1009  };
1010 
1011 
1030  template<class B, class A=std::allocator<B> >
1031  class CompressedBlockVectorWindow : public compressed_block_vector_unmanaged<B,A>
1032  {
1033  public:
1034 
1035  //===== type definitions and constants
1036 
1038  typedef typename B::field_type field_type;
1039 
1041  typedef B block_type;
1042 
1044  typedef A allocator_type;
1045 
1047  typedef typename A::size_type size_type;
1048 
1050  enum {
1052  blocklevel = B::blocklevel+1
1053  };
1054 
1056  typedef typename compressed_block_vector_unmanaged<B,A>::Iterator Iterator;
1057 
1059  typedef typename compressed_block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
1060 
1061 
1062  //===== constructors and such
1064  CompressedBlockVectorWindow () : compressed_block_vector_unmanaged<B,A>()
1065  { }
1066 
1068  CompressedBlockVectorWindow (B* _p, size_type* _j, size_type _n)
1069  {
1070  this->n = _n;
1071  this->p = _p;
1072  this->j = _j;
1073  }
1074 
1076  CompressedBlockVectorWindow (const CompressedBlockVectorWindow& a)
1077  {
1078  this->n = a.n;
1079  this->p = a.p;
1080  this->j = a.j;
1081  }
1082 
1084  CompressedBlockVectorWindow& operator= (const CompressedBlockVectorWindow& a)
1085  {
1086  // check correct size
1087 #ifdef DUNE_ISTL_WITH_CHECKING
1088  if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
1089 #endif
1090 
1091  if (&a!=this) // check if this and a are different objects
1092  {
1093  // copy data
1094  for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
1095  for (size_type i=0; i<this->n; i++) this->j[i]=a.j[i];
1096  }
1097  return *this;
1098  }
1099 
1101  CompressedBlockVectorWindow& operator= (const field_type& k)
1102  {
1103  (static_cast<compressed_block_vector_unmanaged<B,A>&>(*this)) = k;
1104  return *this;
1105  }
1106 
1107 
1108  //===== window manipulation methods
1109 
1111  void set (size_type _n, B* _p, size_type* _j)
1112  {
1113  this->n = _n;
1114  this->p = _p;
1115  this->j = _j;
1116  }
1117 
1119  void setsize (size_type _n)
1120  {
1121  this->n = _n;
1122  }
1123 
1125  void setptr (B* _p)
1126  {
1127  this->p = _p;
1128  }
1129 
1131  void setindexptr (size_type* _j)
1132  {
1133  this->j = _j;
1134  }
1135 
1137  B* getptr ()
1138  {
1139  return this->p;
1140  }
1141 
1143  size_type* getindexptr ()
1144  {
1145  return this->j;
1146  }
1147 
1149  const B* getptr () const
1150  {
1151  return this->p;
1152  }
1153 
1155  const size_type* getindexptr () const
1156  {
1157  return this->j;
1158  }
1160  size_type getsize () const
1161  {
1162  return this->n;
1163  }
1164  };
1165 
1166 } // end namespace 'Imp'
1167 
1168 } // end namespace 'Dune'
1169 
1170 #endif
Implements several basic array containers.
A vector of blocks with memory management.
Definition: bvector.hh:317
BlockVector()
makes empty vector
Definition: bvector.hh:349
void resize(size_type size, bool copyOldValues=true)
Resize the vector.
Definition: bvector.hh:503
BlockVector(size_type _n)
make vector with _n components
Definition: bvector.hh:354
@ blocklevel
The number of blocklevel we contain.
Definition: bvector.hh:337
Imp::block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:341
void reserve(size_type capacity, bool copyOldValues=true)
Reserve space.
Definition: bvector.hh:441
BlockVector & operator=(const BlockVector &a)
assignment
Definition: bvector.hh:547
A allocator_type
export the allocator type
Definition: bvector.hh:329
BlockVector(const BlockVector &a)
copy constructor
Definition: bvector.hh:515
A::size_type size_type
The type for the index access.
Definition: bvector.hh:332
~BlockVector()
free dynamic memory
Definition: bvector.hh:536
BlockVector(std::initializer_list< B > const &l)
Construct from a std::initializer_list.
Definition: bvector.hh:371
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:484
B::field_type field_type
export the type representing the field
Definition: bvector.hh:323
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:402
B block_type
export the type representing the components
Definition: bvector.hh:326
Imp::block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:344
Provides the functions dot(a,b) := and dotT(a,b) := .
Type traits to determine the type of reals (when working with complex numbers)
auto dot(const A &a, const B &b) -> typename std::enable_if<!IsVector< A >::value &&!std::is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type > ::value, decltype(conj(a) *b)>::type
computes the dot product for fundamental data types according to Petsc's VectDot function: dot(a,...
Definition: dotproduct.hh:40
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
Compute type of the result of an arithmetic operation involving two different number types.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 24, 22:30, 2024)