/usr/include/dune/istl/bvector.hh is in libdune-istl-dev 2.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_BVECTOR_HH
#define DUNE_BVECTOR_HH
#include<cmath>
#include<complex>
#include<memory>
#include "istlexception.hh"
#include "basearray.hh"
/*! \file
\brief This file implements a vector space as a tensor product of
a given vector space. The number of components can be given at
run-time.
*/
namespace Dune {
/**
\brief An unmanaged vector of blocks.
block_vector_unmanaged extends the base_array_unmanaged by
vector operations such as addition and scalar multiplication.
No memory management is added.
Error checking: no error checking is provided normally.
Setting the compile time switch DUNE_ISTL_WITH_CHECKING
enables error checking.
*/
template<class B, class A=std::allocator<B> >
class block_vector_unmanaged : public base_array_unmanaged<B,A>
{
public:
//===== type definitions and constants
//! export the type representing the field
typedef typename B::field_type field_type;
//! export the type representing the components
typedef B block_type;
//! export the allocator type
typedef A allocator_type;
//! The size type for the index access
typedef typename A::size_type size_type;
//! make iterators available as types
typedef typename base_array_unmanaged<B,A>::iterator Iterator;
//! make iterators available as types
typedef typename base_array_unmanaged<B,A>::const_iterator ConstIterator;
//! for STL compatibility
typedef B value_type;
//===== assignment from scalar
//! Assignment from a scalar
block_vector_unmanaged& operator= (const field_type& k)
{
for (size_type i=0; i<this->n; i++)
(*this)[i] = k;
return *this;
}
//===== vector space arithmetic
//! vector space addition
block_vector_unmanaged& operator+= (const block_vector_unmanaged& y)
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
#endif
for (size_type i=0; i<this->n; ++i) (*this)[i] += y[i];
return *this;
}
//! vector space subtraction
block_vector_unmanaged& operator-= (const block_vector_unmanaged& y)
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
#endif
for (size_type i=0; i<this->n; ++i) (*this)[i] -= y[i];
return *this;
}
//! vector space multiplication with scalar
block_vector_unmanaged& operator*= (const field_type& k)
{
for (size_type i=0; i<this->n; ++i) (*this)[i] *= k;
return *this;
}
//! vector space division by scalar
block_vector_unmanaged& operator/= (const field_type& k)
{
for (size_type i=0; i<this->n; ++i) (*this)[i] /= k;
return *this;
}
//! vector space axpy operation
block_vector_unmanaged& axpy (const field_type& a, const block_vector_unmanaged& y)
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
#endif
for (size_type i=0; i<this->n; ++i) (*this)[i].axpy(a,y[i]);
return *this;
}
//===== Euclidean scalar product
//! scalar product
field_type operator* (const block_vector_unmanaged& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (this->n!=y.N()) DUNE_THROW(ISTLError,"vector size mismatch");
#endif
field_type sum=0;
for (size_type i=0; i<this->n; ++i) sum += (*this)[i]*y[i];
return sum;
}
//===== norms
//! one norm (sum over absolute values of entries)
double one_norm () const
{
double sum=0;
for (size_type i=0; i<this->n; ++i) sum += (*this)[i].one_norm();
return sum;
}
//! simplified one norm (uses Manhattan norm for complex values)
double one_norm_real () const
{
double sum=0;
for (size_type i=0; i<this->n; ++i) sum += (*this)[i].one_norm_real();
return sum;
}
//! two norm sqrt(sum over squared values of entries)
double two_norm () const
{
double sum=0;
for (size_type i=0; i<this->n; ++i) sum += (*this)[i].two_norm2();
return sqrt(sum);
}
//! sqare of two norm (sum over squared values of entries), need for block recursion
double two_norm2 () const
{
double sum=0;
for (size_type i=0; i<this->n; ++i) sum += (*this)[i].two_norm2();
return sum;
}
//! infinity norm (maximum of absolute values of entries)
double infinity_norm () const
{
double max=0;
for (size_type i=0; i<this->n; ++i) max = std::max(max,(*this)[i].infinity_norm());
return max;
}
//! simplified infinity norm (uses Manhattan norm for complex values)
double infinity_norm_real () const
{
double max=0;
for (size_type i=0; i<this->n; ++i) max = std::max(max,(*this)[i].infinity_norm_real());
return max;
}
//===== sizes
//! number of blocks in the vector (are of size 1 here)
size_type N () const
{
return this->n;
}
//! dimension of the vector space
size_type dim () const
{
size_type d=0;
for (size_type i=0; i<this->n; i++)
d += (*this)[i].dim();
return d;
}
protected:
//! make constructor protected, so only derived classes can be instantiated
block_vector_unmanaged () : base_array_unmanaged<B,A>()
{ }
};
/**
@addtogroup ISTL_SPMV
@{
*/
/**
\brief A vector of blocks with memory management.
BlockVector adds memory management with ordinary
copy semantics to the block_vector_unmanaged template.
Error checking: no error checking is provided normally.
Setting the compile time switch DUNE_ISTL_WITH_CHECKING
enables error checking.
*/
template<class B, class A=std::allocator<B> >
class BlockVector : public block_vector_unmanaged<B,A>
{
public:
//===== type definitions and constants
//! export the type representing the field
typedef typename B::field_type field_type;
//! export the type representing the components
typedef B block_type;
//! export the allocator type
typedef A allocator_type;
//! The type for the index access
typedef typename A::size_type size_type;
//! increment block level counter
enum {
//! The number of blocklevel we contain.
blocklevel = B::blocklevel+1};
//! make iterators available as types
typedef typename block_vector_unmanaged<B,A>::Iterator Iterator;
//! make iterators available as types
typedef typename block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
//===== constructors and such
//! makes empty vector
BlockVector () : block_vector_unmanaged<B,A>(),
capacity_(0)
{}
//! make vector with _n components
explicit BlockVector (size_type _n)
{
this->n = _n;
capacity_ = _n;
if (capacity_>0) {
this->p = this->allocator_.allocate(capacity_);
// actually construct the objects
new(this->p) B[capacity_];
} else
{
this->p = 0;
this->n = 0;
capacity_ = 0;
}
}
/** \brief Make vector with _n components but preallocating capacity components
If _n > capacity then space for _n entries is allocated.
\note This constructor is somewhat dangerous. People may be tempted to
write something like
\code
BlockVector<FieldVector<double,1> > my_vector(100,0);
\endcode
expecting to obtain a vector of 100 doubles initialized with zero.
However, the code calls this constructor which tacitly does something else!
*/
BlockVector (size_type _n, size_type capacity)
{
this->n = _n;
if(this->n > capacity)
capacity_ = _n;
else
capacity_ = capacity;
if (capacity_>0) {
this->p = this->allocator_.allocate(capacity_);
new (this->p) B[capacity_];
} else
{
this->p = 0;
this->n = 0;
capacity_ = 0;
}
}
/**
* @brief Reserve space.
*
* After calling this method the vector can hold up to
* capacity values. If the specified capacity is smaller
* than the current capacity and bigger than the current size
* space will be freed.
*
* If the template parameter copyOldValues is true the values will
* be copied. If it is false the old values are lost.
*
* @param capacity The maximum number of elements the vector
* needs to hold.
* @param copyOldValues If false no object will be copied and the data might be
* lost. Default value is true.
*/
void reserve(size_type capacity, bool copyOldValues=true)
{
if(capacity >= block_vector_unmanaged<B,A>::N() && capacity != capacity_){
// save the old data
B* pold = this->p;
if(capacity>0){
// create new array with capacity
this->p = this->allocator_.allocate(capacity);
new (this->p) B[capacity];
if(copyOldValues){
// copy the old values
B* to = this->p;
B* from = pold;
for(size_type i=0; i < block_vector_unmanaged<B,A>::N(); ++i, ++from, ++to)
*to = *from;
if(capacity_ > 0) {
// Destruct old objects and free memory
int i=capacity_;
while (i)
pold[--i].~B();
this->allocator_.deallocate(pold,capacity_);
}
}
}else{
if(capacity_ > 0)
// free old data
this->p = 0;
capacity_ = 0;
}
capacity_ = capacity;
}
}
/**
* @brief Get the capacity of the vector.
*
* I. e. the maximum number of elements the vector can hold.
* @return The capacity of the vector.
*/
size_type capacity() const
{
return capacity_;
}
/**
* @brief Resize the vector.
*
* After calling this method BlockVector::N() will return size
* If the capacity of the vector is smaller than the specified
* size then reserve(size) will be called.
*
* If the template parameter copyOldValues is true the values
* will be copied if the capacity changes. If it is false
* the old values are lost.
* @param size The new size of the vector.
* @param copyOldValues If false no object will be copied and the data might be
* lost.
*/
void resize(size_type size, bool copyOldValues=true)
{
if(size > block_vector_unmanaged<B,A>::N())
if(capacity_ < size)
this->reserve(size, copyOldValues);
if(size >=0)
this->n=size;
}
//! copy constructor
BlockVector (const BlockVector& a) :
block_vector_unmanaged<B,A>(a)
{
// allocate memory with same size as a
this->n = a.n;
capacity_ = a.capacity_;
if (capacity_>0) {
this->p = this->allocator_.allocate(capacity_);
new (this->p) B[capacity_];
} else
{
this->n = 0;
this->p = 0;
}
// and copy elements
for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
}
//! construct from base class object
BlockVector (const block_vector_unmanaged<B,A>& _a)
{
// upcast, because protected data inaccessible
const BlockVector& a = static_cast<const BlockVector&>(_a);
// allocate memory with same size as a
this->n = a.n;
capacity_ = a.capacity_;
if (capacity_>0) {
this->p = this->allocator_.allocate(capacity_);
new (this->p) B[capacity_];
} else
{
this->n = 0;
this->p = 0;
capacity_ = 0;
}
// and copy elements
for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
}
//! free dynamic memory
~BlockVector ()
{
if (capacity_>0) {
int i=capacity_;
while (i)
this->p[--i].~B();
this->allocator_.deallocate(this->p,capacity_);
}
}
//! assignment
BlockVector& operator= (const BlockVector& a)
{
if (&a!=this) // check if this and a are different objects
{
// adjust size of vector
if (capacity_!=a.capacity_) // check if size is different
{
if (capacity_>0) {
int i=capacity_;
while (i)
this->p[--i].~B();
this->allocator_.deallocate(this->p,capacity_); // free old memory
}
capacity_ = a.capacity_;
if (capacity_>0) {
this->p = this->allocator_.allocate(capacity_);
new (this->p) B[capacity_];
} else
{
this->p = 0;
capacity_ = 0;
}
}
this->n = a.n;
// copy data
for (size_type i=0; i<this->n; i++)
this->p[i]=a.p[i];
}
return *this;
}
//! assign from base class object
BlockVector& operator= (const block_vector_unmanaged<B,A>& a)
{
// forward to regular assignement operator
return this->operator=(static_cast<const BlockVector&>(a));
}
//! assign from scalar
BlockVector& operator= (const field_type& k)
{
// forward to operator= in base class
(static_cast<block_vector_unmanaged<B,A>&>(*this)) = k;
return *this;
}
protected:
size_type capacity_;
A allocator_;
};
/** @} */
//! Send BlockVector to an output stream
template<class K, class A>
std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
{
typedef typename BlockVector<K, A>::size_type size_type;
for (size_type i=0; i<v.size(); i++)
s << v[i] << std::endl;
return s;
}
/** BlockVectorWindow adds window manipulation functions
to the block_vector_unmanaged template.
This class has no memory management. It assumes that the storage
for the entries of the vector is maintained outside of this class.
But you can copy objects of this class and of the base class
with reference semantics.
Assignment copies the data, if the format is incopmpatible with
the argument an exception is thrown in debug mode.
Error checking: no error checking is provided normally.
Setting the compile time switch DUNE_ISTL_WITH_CHECKING
enables error checking.
*/
template<class B, class A=std::allocator<B> >
class BlockVectorWindow : public block_vector_unmanaged<B,A>
{
public:
//===== type definitions and constants
//! export the type representing the field
typedef typename B::field_type field_type;
//! export the type representing the components
typedef B block_type;
//! export the allocator type
typedef A allocator_type;
//! The type for the index access
typedef typename A::size_type size_type;
//! increment block level counter
enum {
//! The number of blocklevels we contain
blocklevel = B::blocklevel+1
};
//! make iterators available as types
typedef typename block_vector_unmanaged<B,A>::Iterator Iterator;
//! make iterators available as types
typedef typename block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
//===== constructors and such
//! makes empty array
BlockVectorWindow () : block_vector_unmanaged<B,A>()
{ }
//! make array from given pointer and size
BlockVectorWindow (B* _p, size_type _n)
{
this->n = _n;
this->p = _p;
}
//! copy constructor, this has reference semantics!
BlockVectorWindow (const BlockVectorWindow& a)
{
this->n = a.n;
this->p = a.p;
}
//! construct from base class object with reference semantics!
BlockVectorWindow (const block_vector_unmanaged<B,A>& _a)
{
// cast needed to access protected data
const BlockVectorWindow& a = static_cast<const BlockVectorWindow&>(_a);
// make me point to the other's data
this->n = a.n;
this->p = a.p;
}
//! assignment
BlockVectorWindow& operator= (const BlockVectorWindow& a)
{
// check correct size
#ifdef DUNE_ISTL_WITH_CHECKING
if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
#endif
if (&a!=this) // check if this and a are different objects
{
// copy data
for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
}
return *this;
}
//! assign from base class object
BlockVectorWindow& operator= (const block_vector_unmanaged<B,A>& a)
{
// forward to regular assignment operator
return this->operator=(static_cast<const BlockVectorWindow&>(a));
}
//! assign from scalar
BlockVectorWindow& operator= (const field_type& k)
{
(static_cast<block_vector_unmanaged<B,A>&>(*this)) = k;
return *this;
}
//===== window manipulation methods
//! set size and pointer
void set (size_type _n, B* _p)
{
this->n = _n;
this->p = _p;
}
//! set size only
void setsize (size_type _n)
{
this->n = _n;
}
//! set pointer only
void setptr (B* _p)
{
this->p = _p;
}
//! get pointer
B* getptr ()
{
return this->p;
}
//! get size
size_type getsize ()
{
return this->n;
}
};
/** compressed_block_vector_unmanaged extends the compressed base_array_unmanaged by
vector operations such as addition and scalar multiplication.
No memory management is added.
Error checking: no error checking is provided normally.
Setting the compile time switch DUNE_ISTL_WITH_CHECKING
enables error checking.
*/
template<class B, class A=std::allocator<B> >
class compressed_block_vector_unmanaged : public compressed_base_array_unmanaged<B,A>
{
public:
//===== type definitions and constants
//! export the type representing the field
typedef typename B::field_type field_type;
//! export the type representing the components
typedef B block_type;
//! export the allocator type
typedef A allocator_type;
//! make iterators available as types
typedef typename compressed_base_array_unmanaged<B,A>::iterator Iterator;
//! make iterators available as types
typedef typename compressed_base_array_unmanaged<B,A>::const_iterator ConstIterator;
//! The type for the index access
typedef typename A::size_type size_type;
//===== assignment from scalar
compressed_block_vector_unmanaged& operator= (const field_type& k)
{
for (size_type i=0; i<this->n; i++)
(this->p)[i] = k;
return *this;
}
//===== vector space arithmetic
//! vector space addition
template<class V>
compressed_block_vector_unmanaged& operator+= (const V& y)
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
#endif
for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) += y.p[i];
return *this;
}
//! vector space subtraction
template<class V>
compressed_block_vector_unmanaged& operator-= (const V& y)
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
#endif
for (size_type i=0; i<y.n; ++i) this->operator[](y.j[i]) -= y.p[i];
return *this;
}
//! vector space axpy operation
template<class V>
compressed_block_vector_unmanaged& axpy (const field_type& a, const V& y)
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (!includesindexset(y)) DUNE_THROW(ISTLError,"index set mismatch");
#endif
for (size_type i=0; i<y.n; ++i) (this->operator[](y.j[i])).axpy(a,y.p[i]);
return *this;
}
//! vector space multiplication with scalar
compressed_block_vector_unmanaged& operator*= (const field_type& k)
{
for (size_type i=0; i<this->n; ++i) (this->p)[i] *= k;
return *this;
}
//! vector space division by scalar
compressed_block_vector_unmanaged& operator/= (const field_type& k)
{
for (size_type i=0; i<this->n; ++i) (this->p)[i] /= k;
return *this;
}
//===== Euclidean scalar product
//! scalar product
field_type operator* (const compressed_block_vector_unmanaged& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (!includesindexset(y) || !y.includesindexset(*this) )
DUNE_THROW(ISTLError,"index set mismatch");
#endif
field_type sum=0;
for (size_type i=0; i<this->n; ++i)
sum += (this->p)[i] * y[(this->j)[i]];
return sum;
}
//===== norms
//! one norm (sum over absolute values of entries)
double one_norm () const
{
double sum=0;
for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm();
return sum;
}
//! simplified one norm (uses Manhattan norm for complex values)
double one_norm_real () const
{
double sum=0;
for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].one_norm_real();
return sum;
}
//! two norm sqrt(sum over squared values of entries)
double two_norm () const
{
double sum=0;
for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
return sqrt(sum);
}
//! sqare of two norm (sum over squared values of entries), need for block recursion
double two_norm2 () const
{
double sum=0;
for (size_type i=0; i<this->n; ++i) sum += (this->p)[i].two_norm2();
return sum;
}
//! infinity norm (maximum of absolute values of entries)
double infinity_norm () const
{
double max=0;
for (size_type i=0; i<this->n; ++i) max = std::max(max,(this->p)[i].infinity_norm());
return max;
}
//! simplified infinity norm (uses Manhattan norm for complex values)
double infinity_norm_real () const
{
double max=0;
for (size_type i=0; i<this->n; ++i) max = std::max(max,(this->p)[i].infinity_norm_real());
return max;
}
//===== sizes
//! number of blocks in the vector (are of size 1 here)
size_type N () const
{
return this->n;
}
//! dimension of the vector space
size_type dim () const
{
size_type d=0;
for (size_type i=0; i<this->n; i++)
d += (this->p)[i].dim();
return d;
}
protected:
//! make constructor protected, so only derived classes can be instantiated
compressed_block_vector_unmanaged () : compressed_base_array_unmanaged<B,A>()
{ }
//! return true if index sets coincide
template<class V>
bool includesindexset (const V& y)
{
typename V::ConstIterator e=this->end();
for (size_type i=0; i<y.n; i++)
if (find(y.j[i])==e)
return false;
return true;
}
};
/** CompressedBlockVectorWindow adds window manipulation functions
to the compressed_block_vector_unmanaged template.
This class has no memory management. It assumes that the storage
for the entries of the vector and its index set is maintained outside of this class.
But you can copy objects of this class and of the base class
with reference semantics.
Assignment copies the data, if the format is incopmpatible with
the argument an exception is thrown in debug mode.
Error checking: no error checking is provided normally.
Setting the compile time switch DUNE_ISTL_WITH_CHECKING
enables error checking.
*/
template<class B, class A=std::allocator<B> >
class CompressedBlockVectorWindow : public compressed_block_vector_unmanaged<B,A>
{
public:
//===== type definitions and constants
//! export the type representing the field
typedef typename B::field_type field_type;
//! export the type representing the components
typedef B block_type;
//! export the allocator type
typedef A allocator_type;
//! The type for the index access
typedef typename A::size_type size_type;
//! increment block level counter
enum {
//! The number of block level this vector contains.
blocklevel = B::blocklevel+1};
//! make iterators available as types
typedef typename compressed_block_vector_unmanaged<B,A>::Iterator Iterator;
//! make iterators available as types
typedef typename compressed_block_vector_unmanaged<B,A>::ConstIterator ConstIterator;
//===== constructors and such
//! makes empty array
CompressedBlockVectorWindow () : compressed_block_vector_unmanaged<B,A>()
{ }
//! make array from given pointers and size
CompressedBlockVectorWindow (B* _p, size_type* _j, size_type _n)
{
this->n = _n;
this->p = _p;
this->j = _j;
}
//! copy constructor, this has reference semantics!
CompressedBlockVectorWindow (const CompressedBlockVectorWindow& a)
{
this->n = a.n;
this->p = a.p;
this->j = a.j;
}
//! construct from base class object with reference semantics!
CompressedBlockVectorWindow (const compressed_block_vector_unmanaged<B,A>& _a)
{
// cast needed to access protected data (upcast)
const CompressedBlockVectorWindow& a = static_cast<const CompressedBlockVectorWindow&>(_a);
// make me point to the other's data
this->n = a.n;
this->p = a.p;
this->j = a.j;
}
//! assignment
CompressedBlockVectorWindow& operator= (const CompressedBlockVectorWindow& a)
{
// check correct size
#ifdef DUNE_ISTL_WITH_CHECKING
if (this->n!=a.N()) DUNE_THROW(ISTLError,"vector size mismatch");
#endif
if (&a!=this) // check if this and a are different objects
{
// copy data
for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
for (size_type i=0; i<this->n; i++) this->j[i]=a.j[i];
}
return *this;
}
//! assign from base class object
CompressedBlockVectorWindow& operator= (const compressed_block_vector_unmanaged<B,A>& a)
{
// forward to regular assignment operator
return this->operator=(static_cast<const CompressedBlockVectorWindow&>(a));
}
//! assign from scalar
CompressedBlockVectorWindow& operator= (const field_type& k)
{
(static_cast<compressed_block_vector_unmanaged<B,A>&>(*this)) = k;
return *this;
}
//===== window manipulation methods
//! set size and pointer
void set (size_type _n, B* _p, size_type* _j)
{
this->n = _n;
this->p = _p;
this->j = _j;
}
//! set size only
void setsize (size_type _n)
{
this->n = _n;
}
//! set pointer only
void setptr (B* _p)
{
this->p = _p;
}
//! set pointer only
void setindexptr (size_type* _j)
{
this->j = _j;
}
//! get pointer
B* getptr ()
{
return this->p;
}
//! get pointer
size_type* getindexptr ()
{
return this->j;
}
//! get pointer
const B* getptr () const
{
return this->p;
}
//! get pointer
const size_type* getindexptr () const
{
return this->j;
}
//! get size
size_type getsize () const
{
return this->n;
}
};
} // end namespace
#endif
|