/usr/include/deal.II/lac/precondition_block.h is in libdeal.ii-dev 8.1.0-4.
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 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 | // ---------------------------------------------------------------------
// $Id: precondition_block.h 30040 2013-07-18 17:06:48Z maier $
//
// Copyright (C) 1999 - 2013 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#ifndef __deal2__precondition_block_h
#define __deal2__precondition_block_h
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/subscriptor.h>
#include <deal.II/base/smartpointer.h>
#include <deal.II/lac/precondition_block_base.h>
#include <vector>
DEAL_II_NAMESPACE_OPEN
template<class MATRIX, typename inverse_type>
class PreconditionBlockJacobi;
/*! @addtogroup Preconditioners
*@{
*/
/**
* Base class for actual block preconditioners. This class assumes the
* <tt>MATRIX</tt> consisting of invertible blocks of @p blocksize on
* the diagonal and provides the inversion of the diagonal blocks of
* the matrix. It is not necessary for this class that the matrix be
* block diagonal; rather, it applies to
* matrices of arbitrary structure with the minimal property of having
* invertible blocks on the diagonal. Still the matrix must have
* access to single matrix entries. Therefore, BlockMatrixArray and similar
* classes are not a possible matrix class template arguments.
*
* The block matrix structure used by this class is given, e.g., for
* the DG method for the transport equation. For a downstream
* numbering the matrices even have got a block lower left matrix
* structure, i.e. the matrices are empty above the diagonal blocks.
*
* @note This class is intended to be used for matrices whose structure
* is given by local contributions from disjoint cells, such as for DG
* methods. It is not intended for problems where the block structure
* results from different physical variables such as in the Stokes
* equations considered in step-22.
*
* For all matrices that are empty above and below the diagonal blocks
* (i.e. for all block diagonal matrices) the @p BlockJacobi
* preconditioner is a direct solver. For all matrices that are empty
* only above the diagonal blocks (e.g. the matrices one gets by the
* DG method with downstream numbering) @p BlockSOR is a direct
* solver.
*
* This first implementation of the @p PreconditionBlock assumes the
* matrix has blocks each of the same block size. Varying block sizes
* within the matrix must still be implemented if needed.
*
* The first template parameter denotes the type of number
* representation in the sparse matrix, the second denotes the type of
* number representation in which the inverted diagonal block matrices
* are stored within this class by <tt>invert_diagblocks()</tt>. If you
* don't want to use the block inversion as an exact solver, but
* rather as a preconditioner, you may probably want to store the
* inverted blocks with less accuracy than the original matrix; for
* example, <tt>number==double, inverse_type=float</tt> might be a viable
* choice.
*
* @see @ref GlossBlockLA "Block (linear algebra)"
* @author Ralf Hartmann, Guido Kanschat
* @date 1999, 2000, 2010
*/
template<class MATRIX, typename inverse_type = typename MATRIX::value_type>
class PreconditionBlock
: public virtual Subscriptor,
protected PreconditionBlockBase<inverse_type>
{
private:
/**
* Define number type of matrix.
*/
typedef typename MATRIX::value_type number;
/**
* Value type for inverse matrices.
*/
typedef inverse_type value_type;
public:
/**
* Declare type for container size.
*/
typedef types::global_dof_index size_type;
/**
* Parameters for block preconditioners.
*/
class AdditionalData
{
public:
/**
* Constructor. Block size
* must be given since there
* is no reasonable default
* parameter.
*/
AdditionalData (const size_type block_size,
const double relaxation = 1.,
const bool invert_diagonal = true,
const bool same_diagonal = false);
/**
* Relaxation parameter.
*/
double relaxation;
/**
* Block size.
*/
size_type block_size;
/**
* Invert diagonal during initialization.
*/
bool invert_diagonal;
/**
* Assume all diagonal blocks
* are equal to save memory.
*/
bool same_diagonal;
/**
* Choose the inversion
* method for the blocks.
*/
typename PreconditionBlockBase<inverse_type>::Inversion inversion;
/**
* The if #inversion is SVD,
* the threshold below which
* a singular value will be
* considered zero and thus
* not inverted. This
* parameter is used in the
* call to LAPACKFullMatrix::compute_inverse_svd().
*/
double threshold;
};
/**
* Constructor.
*/
PreconditionBlock(bool store_diagonals = false);
/**
* Destructor.
*/
~PreconditionBlock();
/**
* Initialize matrix and block
* size. We store the matrix and
* the block size in the
* preconditioner object. In a
* second step, the inverses of
* the diagonal blocks may be
* computed.
*
* Additionally, a relaxation
* parameter for derived classes
* may be provided.
*/
void initialize (const MATRIX &A,
const AdditionalData parameters);
protected:
/**
* Initialize matrix and block
* size for permuted
* preconditioning. Additionally
* to the parameters of the other
* initalize() function, we hand
* over two index vectors with
* the permutation and its
* inverse. For the meaning of
* these vectors see
* PreconditionBlockSOR.
*
* In a second step, the inverses
* of the diagonal blocks may be
* computed. Make sure you use
* invert_permuted_diagblocks()
* to yield consistent data.
*
* Additionally, a relaxation
* parameter for derived classes
* may be provided.
*/
void initialize (const MATRIX &A,
const std::vector<size_type> &permutation,
const std::vector<size_type> &inverse_permutation,
const AdditionalData parameters);
/**
* Set either the permutation of
* rows or the permutation of
* blocks, depending on the size
* of the vector.
*
* If the size of the permutation
* vectors is equal to the
* dimension of the linear
* system, it is assumed that
* rows are permuted
* individually. In this case,
* set_permutation() must be
* called before initialize(),
* since the diagonal blocks are
* built from the permuted
* entries of the matrix.
*
* If the size of the permutation
* vector is not equal to the
* dimension of the system, the
* diagonal blocks are computed
* from the unpermuted
* entries. Instead, the
* relaxation methods step() and
* Tstep() are executed applying
* the blocks in the order given
* by the permutation
* vector. They will throw an
* exception if length of this
* vector is not equal to the
* number of blocks.
*
* @note Permutation of blocks
* can only be applied to the
* relaxation operators step()
* and Tstep(), not to the
* preconditioning operators
* vmult() and Tvmult().
*
* @note It is safe to call
* set_permutation() before
* initialize(), while the other
* order is only admissible for
* block permutation.
*/
void set_permutation(const std::vector<size_type> &permutation,
const std::vector<size_type> &inverse_permutation);
/**
* Replacement of
* invert_diagblocks() for
* permuted preconditioning.
*/
void invert_permuted_diagblocks(
const std::vector<size_type> &permutation,
const std::vector<size_type> &inverse_permutation);
public:
/**
* Deletes the inverse diagonal
* block matrices if existent,
* sets the blocksize to 0, hence
* leaves the class in the state
* that it had directly after
* calling the constructor.
*/
void clear();
/**
* Checks whether the object is empty.
*/
bool empty () const;
/**
* Read-only access to entries.
* This function is only possible
* if the inverse diagonal blocks
* are stored.
*/
value_type el(size_type i,
size_type j) const;
/**
* Stores the inverse of the
* diagonal blocks in
* @p inverse. This costs some
* additional memory - for DG
* methods about 1/3 (for double
* inverses) or 1/6 (for float
* inverses) of that used for the
* matrix - but it makes the
* preconditioning much faster.
*
* It is not allowed to call this
* function twice (will produce
* an error) before a call of
* <tt>clear(...)</tt> because at the
* second time there already
* exist the inverse matrices.
*
* After this function is called,
* the lock on the matrix given
* through the @p use_matrix
* function is released, i.e. you
* may overwrite of delete it.
* You may want to do this in
* case you use this matrix to
* precondition another matrix.
*/
void invert_diagblocks();
/**
* Perform one block relaxation
* step in forward numbering.
*
* Depending on the arguments @p
* dst and @p pref, this performs
* an SOR step (both reference
* the same vector) of a Jacobi
* step (botha different
* vectors). For the Jacobi step,
* the calling function must copy
* @p dst to @p pref after this.
*
* @note If a permutation is set,
* it is automatically honored by
* this function.
*/
template <typename number2>
void forward_step (
Vector<number2> &dst,
const Vector<number2> &prev,
const Vector<number2> &src,
const bool transpose_diagonal) const;
/**
* Perform one block relaxation
* step in backward numbering.
*
* Depending on the arguments @p
* dst and @p pref, this performs
* an SOR step (both reference
* the same vector) of a Jacobi
* step (botha different
* vectors). For the Jacobi step,
* the calling function must copy
* @p dst to @p pref after this.
*
* @note If a permutation is set,
* it is automatically honored by
* this function.
*/
template <typename number2>
void backward_step (
Vector<number2> &dst,
const Vector<number2> &prev,
const Vector<number2> &src,
const bool transpose_diagonal) const;
/**
* Return the size of the blocks.
*/
size_type block_size () const;
/**
* @deprecated Use size()
* instead.
*
* The number of blocks of the
* matrix.
*/
unsigned int n_blocks() const DEAL_II_DEPRECATED;
/**
* Determine an estimate for the
* memory consumption (in bytes)
* of this object.
*/
std::size_t memory_consumption () const;
/** @addtogroup Exceptions
* @{ */
/**
* For non-overlapping block
* preconditioners, the block
* size must divide the matrix
* size. If not, this exception
* gets thrown.
*/
DeclException2 (ExcWrongBlockSize,
int, int,
<< "The blocksize " << arg1
<< " and the size of the matrix " << arg2
<< " do not match.");
/**
* Exception
*/
DeclException0 (ExcInverseMatricesAlreadyExist);
//@}
protected:
/**
* Size of the blocks. Each
* diagonal block is assumed to
* be of the same size.
*/
size_type blocksize;
/**
* Pointer to the matrix. Make
* sure that the matrix exists as
* long as this class needs it,
* i.e. until calling
* @p invert_diagblocks, or (if
* the inverse matrices should
* not be stored) until the last
* call of the preconditoining
* @p vmult function of the
* derived classes.
*/
SmartPointer<const MATRIX,PreconditionBlock<MATRIX,inverse_type> > A;
/**
* Relaxation parameter to be
* used by derived classes.
*/
double relaxation;
/**
* The permutation vector
*/
std::vector<size_type> permutation;
/**
* The inverse permutation vector
*/
std::vector<size_type> inverse_permutation;
/**
* Flag for diagonal compression.
* @ref set_same_diagonal()
*/
};
/**
* Block Jacobi preconditioning.
* See PreconditionBlock for requirements on the matrix.
*
* @note Instantiations for this template are provided for <tt>@<float@> and
* @<double@></tt>; others can be generated in application programs (see the
* section on @ref Instantiations in the manual).
*
* @author Ralf Hartmann, Guido Kanschat, 1999, 2000, 2003
*/
template<class MATRIX, typename inverse_type = typename MATRIX::value_type>
class PreconditionBlockJacobi : public virtual Subscriptor,
private PreconditionBlock<MATRIX, inverse_type>
{
private:
/**
* Define number type of matrix.
*/
typedef typename MATRIX::value_type number;
public:
/**
* Declare type for container size.
*/
typedef types::global_dof_index size_type;
/**
* STL conforming iterator.
*/
class const_iterator
{
private:
/**
* Accessor class for iterators
*/
class Accessor
{
public:
/**
* Constructor. Since we use
* accessors only for read
* access, a const matrix
* pointer is sufficient.
*/
Accessor (const PreconditionBlockJacobi<MATRIX, inverse_type> *matrix,
const size_type row);
/**
* Row number of the element
* represented by this
* object.
*/
size_type row() const;
/**
* Column number of the
* element represented by
* this object.
*/
size_type column() const;
/**
* Value of this matrix entry.
*/
inverse_type value() const;
protected:
/**
* The matrix accessed.
*/
const PreconditionBlockJacobi<MATRIX, inverse_type> *matrix;
/**
* Save block size here
* for further reference.
*/
size_type bs;
/**
* Current block number.
*/
size_type a_block;
/**
* Iterator inside block.
*/
typename FullMatrix<inverse_type>::const_iterator b_iterator;
/**
* End of current block.
*/
typename FullMatrix<inverse_type>::const_iterator b_end;
/**
* Make enclosing class a
* friend.
*/
friend class const_iterator;
};
public:
/**
* Constructor.
*/
const_iterator(const PreconditionBlockJacobi<MATRIX, inverse_type> *matrix,
const size_type row);
/**
* Prefix increment.
*/
const_iterator &operator++ ();
/**
* Postfix increment.
*/
const_iterator &operator++ (int);
/**
* Dereferencing operator.
*/
const Accessor &operator* () const;
/**
* Dereferencing operator.
*/
const Accessor *operator-> () const;
/**
* Comparison. True, if
* both iterators point to
* the same matrix
* position.
*/
bool operator == (const const_iterator &) const;
/**
* Inverse of <tt>==</tt>.
*/
bool operator != (const const_iterator &) const;
/**
* Comparison
* operator. Result is true
* if either the first row
* number is smaller or if
* the row numbers are
* equal and the first
* index is smaller.
*/
bool operator < (const const_iterator &) const;
private:
/**
* Store an object of the
* accessor class.
*/
Accessor accessor;
};
/**
* import functions from private base class
*/
using PreconditionBlock<MATRIX, inverse_type>::initialize;
using PreconditionBlock<MATRIX, inverse_type>::clear;
using PreconditionBlock<MATRIX, inverse_type>::empty;
using PreconditionBlock<MATRIX, inverse_type>::el;
using PreconditionBlock<MATRIX, inverse_type>::set_same_diagonal;
using PreconditionBlock<MATRIX, inverse_type>::invert_diagblocks;
using PreconditionBlock<MATRIX, inverse_type>::block_size;
using PreconditionBlockBase<inverse_type>::size;
using PreconditionBlockBase<inverse_type>::inverse;
using PreconditionBlockBase<inverse_type>::inverse_householder;
using PreconditionBlockBase<inverse_type>::inverse_svd;
using PreconditionBlockBase<inverse_type>::log_statistics;
/**
* @deprecated Use size() instead
*/
using PreconditionBlock<MATRIX, inverse_type>::n_blocks;
using PreconditionBlock<MATRIX, inverse_type>::set_permutation;
/**
* Execute block Jacobi
* preconditioning.
*
* This function will
* automatically use the inverse
* matrices if they exist, if not
* then BlockJacobi will need
* much time inverting the
* diagonal block matrices in
* each preconditioning step.
*/
template <typename number2>
void vmult (Vector<number2> &, const Vector<number2> &) const;
/**
* Same as @p vmult, since Jacobi is symmetric.
*/
template <typename number2>
void Tvmult (Vector<number2> &, const Vector<number2> &) const;
/**
* Execute block Jacobi
* preconditioning, adding to @p dst.
*
* This function will
* automatically use the inverse
* matrices if they exist, if not
* then BlockJacobi will need
* much time inverting the
* diagonal block matrices in
* each preconditioning step.
*/
template <typename number2>
void vmult_add (Vector<number2> &, const Vector<number2> &) const;
/**
* Same as @p vmult_add, since
* Jacobi is symmetric.
*/
template <typename number2>
void Tvmult_add (Vector<number2> &, const Vector<number2> &) const;
/**
* Perform one step of the Jacobi
* iteration.
*/
template <typename number2>
void step (Vector<number2> &dst, const Vector<number2> &rhs) const;
/**
* Perform one step of the Jacobi
* iteration.
*/
template <typename number2>
void Tstep (Vector<number2> &dst, const Vector<number2> &rhs) const;
/**
* STL-like iterator with the
* first entry.
*/
const_iterator begin () const;
/**
* Final iterator.
*/
const_iterator end () const;
/**
* STL-like iterator with the
* first entry of row @p r.
*/
const_iterator begin (const size_type r) const;
/**
* Final iterator of row @p r.
*/
const_iterator end (const size_type r) const;
private:
/**
* Actual implementation of the
* preconditioner.
*
* Depending on @p adding, the
* result of preconditioning is
* added to the destination vector.
*/
template <typename number2>
void do_vmult (Vector<number2> &,
const Vector<number2> &,
bool adding) const;
friend class Accessor;
friend class const_iterator;
};
/**
* Block SOR preconditioning.
*
* The functions @p vmult and @p Tvmult execute a (transposed)
* block-SOR step, based on the blocks in PreconditionBlock. The
* elements outside the diagonal blocks may be distributed
* arbitrarily.
*
* See PreconditionBlock for requirements on the matrix. The blocks
* used in this class must be contiguous and non-overlapping. An
* overlapping Schwarz relaxation method can be found in
* RelaxationBlockSOR; that class does not offer preconditioning,
* though.
*
* <h3>Permutations</h3>
*
* Optionally, the entries of the source vector can be treated in the
* order of the indices in the permutation vector set by
* #set_permutation (or the opposite order for Tvmult()). The inverse
* permutation is used for storing elements back into this
* vector. This functionality is automatically enabled after a call to
* set_permutation() with vectors of nonzero size.
*
* @note The diagonal blocks, like the matrix, are not permuted!
* Therefore, the permutation vector can only swap whole blocks. It
* may not change the order inside blocks or swap single indices
* between blocks.
*
* <h3>Instantiations</h3>
*
* @note Instantiations for this template are provided for <tt>@<float@> and
* @<double@></tt>; others can be generated in application programs (see the
* section on @ref Instantiations in the manual).
*
* @author Ralf Hartmann, Guido Kanschat, 1999, 2000, 2001, 2002, 2003
*/
template<class MATRIX, typename inverse_type = typename MATRIX::value_type>
class PreconditionBlockSOR : public virtual Subscriptor,
protected PreconditionBlock<MATRIX, inverse_type>
{
public:
/**
* Declare type for container size.
*/
typedef types::global_dof_index size_type;
/**
* Default constructor.
*/
PreconditionBlockSOR();
/**
* Define number type of matrix.
*/
typedef typename MATRIX::value_type number;
/**
* import types and functions from protected base class.
*/
using typename PreconditionBlock<MATRIX,inverse_type>::AdditionalData;
using PreconditionBlock<MATRIX, inverse_type>::initialize;
using PreconditionBlock<MATRIX, inverse_type>::clear;
using PreconditionBlock<MATRIX, inverse_type>::empty;
using PreconditionBlockBase<inverse_type>::size;
using PreconditionBlockBase<inverse_type>::inverse;
using PreconditionBlockBase<inverse_type>::inverse_householder;
using PreconditionBlockBase<inverse_type>::inverse_svd;
using PreconditionBlock<MATRIX, inverse_type>::el;
using PreconditionBlock<MATRIX, inverse_type>::set_same_diagonal;
using PreconditionBlock<MATRIX, inverse_type>::invert_diagblocks;
using PreconditionBlock<MATRIX, inverse_type>::set_permutation;
using PreconditionBlockBase<inverse_type>::log_statistics;
/**
* Execute block SOR
* preconditioning.
*
* This function will
* automatically use the inverse
* matrices if they exist, if not
* then BlockSOR will waste much
* time inverting the diagonal
* block matrices in each
* preconditioning step.
*
* For matrices which are empty
* above the diagonal blocks
* BlockSOR is a direct solver.
*/
template <typename number2>
void vmult (Vector<number2> &, const Vector<number2> &) const;
/**
* Execute block SOR
* preconditioning.
*
* Warning: this function
* performs normal @p vmult
* without adding. The reason for
* its existence is that
* BlockMatrixArray
* requires the adding version by
* default. On the other hand,
* adding requires an additional
* auxiliary vector, which is not
* desirable.
*
* @see vmult
*/
template <typename number2>
void vmult_add (Vector<number2> &, const Vector<number2> &) const;
/**
* Backward application of vmult().
*
* In the current implementation,
* this is not the transpose of
* vmult(). It is a
* transposed Gauss-Seidel
* algorithm applied to the whole
* matrix, but the diagonal
* blocks being inverted are not
* transposed. Therefore, it is
* the transposed, if the
* diagonal blocks are symmetric.
*/
template <typename number2>
void Tvmult (Vector<number2> &, const Vector<number2> &) const;
/**
* Execute backward block SOR
* preconditioning.
*
* Warning: this function
* performs normal @p vmult
* without adding. The reason for
* its existence is that
* BlockMatrixArray
* requires the adding version by
* default. On the other hand,
* adding requires an additional
* auxiliary vector, which is not
* desirable.
*
* @see vmult
*/
template <typename number2>
void Tvmult_add (Vector<number2> &, const Vector<number2> &) const;
/**
* Perform one step of the SOR
* iteration.
*/
template <typename number2>
void step (Vector<number2> &dst, const Vector<number2> &rhs) const;
/**
* Perform one step of the
* transposed SOR iteration.
*/
template <typename number2>
void Tstep (Vector<number2> &dst, const Vector<number2> &rhs) const;
protected:
/**
* Constructor to be used by
* PreconditionBlockSSOR.
*/
PreconditionBlockSOR(bool store);
/**
* Implementation of the forward
* substitution loop called by
* vmult() and vmult_add().
*
* If a #permutation is set by
* set_permutation(), it will
* automatically be honored by
* this function.
*
* The parameter @p adding does
* not have any function, yet.
*/
template <typename number2>
void forward (Vector<number2> &,
const Vector<number2> &,
const bool transpose_diagonal,
const bool adding) const;
/**
* Implementation of the backward
* substitution loop called by
* Tvmult() and Tvmult_add().
*
* If a #permutation is set by
* set_permutation(), it will
* automatically be honored by
* this function.
*
* The parameter @p adding does
* not have any function, yet.
*/
template <typename number2>
void backward (Vector<number2> &,
const Vector<number2> &,
const bool transpose_diagonal,
const bool adding) const;
};
/**
* Block SSOR preconditioning.
*
* The functions @p vmult and @p Tvmult execute a block-SSOR step,
* based on the implementation in PreconditionBlockSOR. This
* class requires storage of the diagonal blocks and their inverses.
*
* See PreconditionBlock for requirements on the matrix. The blocks
* used in this class must be contiguous and non-overlapping. An
* overlapping Schwarz relaxation method can be found in
* RelaxationBlockSSOR; that class does not offer preconditioning,
* though.
*
* @note Instantiations for this template are provided for <tt>@<float@> and
* @<double@></tt>; others can be generated in application programs (see the
* section on @ref Instantiations in the manual).
*
* @author Ralf Hartmann, Guido Kanschat, 1999, 2000
*/
template<class MATRIX, typename inverse_type = typename MATRIX::value_type>
class PreconditionBlockSSOR : public virtual Subscriptor,
private PreconditionBlockSOR<MATRIX, inverse_type>
{
public:
/**
* Declare type for container size.
*/
typedef types::global_dof_index size_type;
/**
* Define number type of matrix.
*/
typedef typename MATRIX::value_type number;
/**
* Constructor.
*/
PreconditionBlockSSOR ();
// Keep AdditionalData accessible
using typename PreconditionBlockSOR<MATRIX,inverse_type>::AdditionalData;
// The following are the
// functions of the base classes
// which we want to keep
// accessible.
/**
* Make initialization function
* publicly available.
*/
using PreconditionBlockSOR<MATRIX,inverse_type>::initialize;
using PreconditionBlockSOR<MATRIX,inverse_type>::clear;
using PreconditionBlockBase<inverse_type>::size;
using PreconditionBlockBase<inverse_type>::inverse;
using PreconditionBlockBase<inverse_type>::inverse_householder;
using PreconditionBlockBase<inverse_type>::inverse_svd;
using PreconditionBlockBase<inverse_type>::log_statistics;
using PreconditionBlockSOR<MATRIX,inverse_type>::set_permutation;
using PreconditionBlockSOR<MATRIX, inverse_type>::empty;
using PreconditionBlockSOR<MATRIX, inverse_type>::el;
using PreconditionBlockSOR<MATRIX,inverse_type>::set_same_diagonal;
using PreconditionBlockSOR<MATRIX,inverse_type>::invert_diagblocks;
/**
* Execute block SSOR
* preconditioning.
*
* This function will
* automatically use the inverse
* matrices if they exist, if not
* then BlockSOR will waste much
* time inverting the diagonal
* block matrices in each
* preconditioning step.
*/
template <typename number2>
void vmult (Vector<number2> &, const Vector<number2> &) const;
/**
* Same as vmult()
*/
template <typename number2>
void Tvmult (Vector<number2> &, const Vector<number2> &) const;
/**
* Perform one step of the SOR
* iteration.
*/
template <typename number2>
void step (Vector<number2> &dst, const Vector<number2> &rhs) const;
/**
* Perform one step of the
* transposed SOR iteration.
*/
template <typename number2>
void Tstep (Vector<number2> &dst, const Vector<number2> &rhs) const;
};
/*@}*/
//---------------------------------------------------------------------------
#ifndef DOXYGEN
template<class MATRIX, typename inverse_type>
inline bool
PreconditionBlock<MATRIX, inverse_type>::empty () const
{
if (A == 0)
return true;
return A->empty();
}
template<class MATRIX, typename inverse_type>
inline unsigned int
PreconditionBlock<MATRIX, inverse_type>::n_blocks () const
{
return this->size();
}
template<class MATRIX, typename inverse_type>
inline inverse_type
PreconditionBlock<MATRIX, inverse_type>::el (
size_type i,
size_type j) const
{
const size_type bs = blocksize;
const unsigned int nb = i/bs;
const FullMatrix<inverse_type> &B = this->inverse(nb);
const size_type ib = i % bs;
const size_type jb = j % bs;
if (jb + nb*bs != j)
{
return 0.;
}
return B(ib, jb);
}
//---------------------------------------------------------------------------
template<class MATRIX, typename inverse_type>
inline
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::Accessor::
Accessor (const PreconditionBlockJacobi<MATRIX, inverse_type> *matrix,
const size_type row)
:
matrix(matrix),
b_iterator(&matrix->inverse(0), 0, 0),
b_end(&matrix->inverse(0), 0, 0)
{
bs = matrix->block_size();
a_block = row / bs;
// This is the end accessor, which
// does not hava a valid block.
if (a_block == matrix->size())
return;
const size_type r = row % bs;
b_iterator = matrix->inverse(a_block).begin(r);
b_end = matrix->inverse(a_block).end();
Assert (a_block < matrix->size(),
ExcIndexRange(a_block, 0, matrix->size()));
}
template<class MATRIX, typename inverse_type>
inline
typename PreconditionBlockJacobi<MATRIX, inverse_type>::size_type
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::Accessor::row() const
{
Assert (a_block < matrix->size(),
ExcIteratorPastEnd());
return bs * a_block + b_iterator->row();
}
template<class MATRIX, typename inverse_type>
inline
typename PreconditionBlockJacobi<MATRIX, inverse_type>::size_type
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::Accessor::column() const
{
Assert (a_block < matrix->size(),
ExcIteratorPastEnd());
return bs * a_block + b_iterator->column();
}
template<class MATRIX, typename inverse_type>
inline
inverse_type
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::Accessor::value() const
{
Assert (a_block < matrix->size(),
ExcIteratorPastEnd());
return b_iterator->value();
}
template<class MATRIX, typename inverse_type>
inline
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::
const_iterator(const PreconditionBlockJacobi<MATRIX, inverse_type> *matrix,
const size_type row)
:
accessor(matrix, row)
{}
template<class MATRIX, typename inverse_type>
inline
typename PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator &
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::operator++ ()
{
Assert (*this != accessor.matrix->end(), ExcIteratorPastEnd());
++accessor.b_iterator;
if (accessor.b_iterator == accessor.b_end)
{
++accessor.a_block;
if (accessor.a_block < accessor.matrix->size())
{
accessor.b_iterator = accessor.matrix->inverse(accessor.a_block).begin();
accessor.b_end = accessor.matrix->inverse(accessor.a_block).end();
}
}
return *this;
}
template<class MATRIX, typename inverse_type>
inline
const typename PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::Accessor &
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::operator* () const
{
return accessor;
}
template<class MATRIX, typename inverse_type>
inline
const typename PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::Accessor *
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::operator-> () const
{
return &accessor;
}
template<class MATRIX, typename inverse_type>
inline
bool
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::
operator == (const const_iterator &other) const
{
if (accessor.a_block == accessor.matrix->size() &&
accessor.a_block == other.accessor.a_block)
return true;
if (accessor.a_block != other.accessor.a_block)
return false;
return (accessor.row() == other.accessor.row() &&
accessor.column() == other.accessor.column());
}
template<class MATRIX, typename inverse_type>
inline
bool
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::
operator != (const const_iterator &other) const
{
return ! (*this == other);
}
template<class MATRIX, typename inverse_type>
inline
bool
PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator::
operator < (const const_iterator &other) const
{
return (accessor.row() < other.accessor.row() ||
(accessor.row() == other.accessor.row() &&
accessor.column() < other.accessor.column()));
}
template<class MATRIX, typename inverse_type>
inline
typename PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator
PreconditionBlockJacobi<MATRIX, inverse_type>::begin () const
{
return const_iterator(this, 0);
}
template<class MATRIX, typename inverse_type>
inline
typename PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator
PreconditionBlockJacobi<MATRIX, inverse_type>::end () const
{
return const_iterator(this, this->size() * this->block_size());
}
template<class MATRIX, typename inverse_type>
inline
typename PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator
PreconditionBlockJacobi<MATRIX, inverse_type>::begin (
const size_type r) const
{
Assert (r < this->A->m(), ExcIndexRange(r, 0, this->A->m()));
return const_iterator(this, r);
}
template<class MATRIX, typename inverse_type>
inline
typename PreconditionBlockJacobi<MATRIX, inverse_type>::const_iterator
PreconditionBlockJacobi<MATRIX, inverse_type>::end (
const size_type r) const
{
Assert (r < this->A->m(), ExcIndexRange(r, 0, this->A->m()));
return const_iterator(this, r+1);
}
#endif // DOXYGEN
DEAL_II_NAMESPACE_CLOSE
#endif
|