/usr/include/deal.II/lac/full_matrix.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 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 | // ---------------------------------------------------------------------
// $Id: full_matrix.h 31917 2013-12-07 16:30:01Z bangerth $
//
// 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__full_matrix_h
#define __deal2__full_matrix_h
#include <deal.II/base/config.h>
#include <deal.II/base/numbers.h>
#include <deal.II/base/table.h>
#include <deal.II/lac/exceptions.h>
#include <deal.II/lac/identity_matrix.h>
#include <deal.II/base/tensor.h>
#include <vector>
#include <iomanip>
#include <cstring>
DEAL_II_NAMESPACE_OPEN
// forward declarations
template <typename number> class Vector;
template <typename number> class LAPACKFullMatrix;
/*! @addtogroup Matrix1
*@{
*/
/**
* Implementation of a classical rectangular scheme of numbers. The
* data type of the entries is provided in the template argument
* <tt>number</tt>. The interface is quite fat and in fact has grown every
* time a new feature was needed. So, a lot of functions are provided.
*
* Internal calculations are usually done with the accuracy of the
* vector argument to functions. If there is no argument with a number
* type, the matrix number type is used.
*
* @note Instantiations for this template are provided for
* <tt>@<float@>, @<double@>, @<long double@>,
* @<std::complex@<float@>@>, @<std::complex@<double@>@>,
* @<std::complex@<long double@>@></tt>; others can be generated in
* application programs (see the section on @ref Instantiations in the
* manual).
*
* @author Guido Kanschat, Franz-Theo Suttmeier, Wolfgang Bangerth, 1993-2004
*/
template <typename number>
class FullMatrix : public Table<2,number>
{
public:
/**
* A type of used to index into this container. Because we can not
* expect to store matrices bigger than what can be indexed by a regular
* unsigned integer, <code>unsigned int</code> is completely sufficient
* as an index type.
*/
typedef unsigned int size_type;
/**
* Type of matrix entries. In analogy to
* the STL container classes.
*/
typedef number value_type;
/**
* Declare a type that has holds
* real-valued numbers with the
* same precision as the template
* argument to this class. If the
* template argument of this
* class is a real data type,
* then real_type equals the
* template argument. If the
* template argument is a
* std::complex type then
* real_type equals the type
* underlying the complex
* numbers.
*
* This typedef is used to
* represent the return type of
* norms.
*/
typedef typename numbers::NumberTraits<number>::real_type real_type;
class const_iterator;
/**
* Accessor class for iterators
*/
class Accessor
{
public:
/**
* Constructor. Since we use
* accessors only for read
* access, a const matrix
* pointer is sufficient.
*/
Accessor (const FullMatrix<number> *matrix,
const size_type row,
const size_type col);
/**
* 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.
*/
number value() const;
protected:
/**
* The matrix accessed.
*/
const FullMatrix<number> *matrix;
/**
* Current row number.
*/
size_type a_row;
/**
* Current column number.
*/
unsigned short a_col;
/*
* Make enclosing class a
* friend.
*/
friend class const_iterator;
};
/**
* STL conforming iterator.
*/
class const_iterator
{
public:
/**
* Constructor.
*/
const_iterator(const FullMatrix<number> *matrix,
const size_type row,
const size_type col);
/**
* 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;
/**
* Comparison operator. Compares just
* the other way around than the
* operator above.
*/
bool operator > (const const_iterator &) const;
private:
/**
* Store an object of the
* accessor class.
*/
Accessor accessor;
};
/**
* @name Constructors and initalization.
* See also the base class Table.
*/
//@{
/**
* Constructor. Initialize the
* matrix as a square matrix with
* dimension <tt>n</tt>.
*
* In order to avoid the implicit
* conversion of integers and
* other types to a matrix, this
* constructor is declared
* <tt>explicit</tt>.
*
* By default, no memory is
* allocated.
*/
explicit FullMatrix (const size_type n = 0);
/**
* Constructor. Initialize the
* matrix as a rectangular
* matrix.
*/
FullMatrix (const size_type rows,
const size_type cols);
/**
* Copy constructor. This
* constructor does a deep copy
* of the matrix. Therefore, it
* poses a possible efficiency
* problem, if for example,
* function arguments are passed
* by value rather than by
* reference. Unfortunately, we
* can't mark this copy
* constructor <tt>explicit</tt>,
* since that prevents the use of
* this class in containers, such
* as <tt>std::vector</tt>. The
* responsibility to check
* performance of programs must
* therefore remain with the
* user of this class.
*/
FullMatrix (const FullMatrix &);
/**
* Constructor initializing from
* an array of numbers. The array
* is arranged line by line. No
* range checking is performed.
*/
FullMatrix (const size_type rows,
const size_type cols,
const number *entries);
/**
* Construct a full matrix that
* equals the identity matrix of
* the size of the
* argument. Using this
* constructor, one can easily
* create an identity matrix of
* size <code>n</code> by saying
* @code
* FullMatrix<double> M(IdentityMatrix(n));
* @endcode
*/
FullMatrix (const IdentityMatrix &id);
/**
* @}
*/
/**
* @name Copying into and out of other matrices
*/
/**
* @{
*/
/**
* Assignment operator.
*/
FullMatrix<number> &
operator = (const FullMatrix<number> &);
/**
* Variable assignment operator.
*/
template <typename number2>
FullMatrix<number> &
operator = (const FullMatrix<number2> &);
/**
* This operator assigns a scalar
* to a matrix. To avoid
* confusion with the semantics
* of this function, zero is the
* only value allowed for
* <tt>d</tt>, allowing you to
* clear a matrix in an intuitive
* way.
*/
FullMatrix<number> &
operator = (const number d);
/**
* Copy operator to create a full
* matrix that equals the
* identity matrix of the size of
* the argument. This way, one can easily
* create an identity matrix of
* size <code>n</code> by saying
* @code
* M = IdentityMatrix(n);
* @endcode
*/
FullMatrix<number> &
operator = (const IdentityMatrix &id);
/**
* Assignment operator for a
* LapackFullMatrix. The calling matrix
* must be of the same size as the
* LAPACK matrix.
*/
template <typename number2>
FullMatrix<number> &
operator = (const LAPACKFullMatrix<number2> &);
/**
* Assignment from different
* matrix classes. This
* assignment operator uses
* iterators of the class
* MATRIX. Therefore, sparse
* matrices are possible sources.
*/
template <class MATRIX>
void copy_from (const MATRIX &);
/**
* Transposing assignment from
* different matrix classes. This
* assignment operator uses
* iterators of the class
* MATRIX. Therefore, sparse
* matrices are possible sources.
*/
template <class MATRIX>
void copy_transposed (const MATRIX &);
/**
* Fill matrix with elements
* extracted from a tensor,
* taking rows included between
* <tt>r_i</tt> and <tt>r_j</tt>
* and columns between
* <tt>c_i</tt> and
* <tt>c_j</tt>. The resulting
* matrix is then inserted in the
* destination matrix at position
* <tt>(dst_r, dst_c)</tt> Checks
* on the indices are made.
*/
template <int dim>
void
copy_from (const Tensor<2,dim> &T,
const size_type src_r_i=0,
const size_type src_r_j=dim-1,
const size_type src_c_i=0,
const size_type src_c_j=dim-1,
const size_type dst_r=0,
const size_type dst_c=0);
/**
* Insert a submatrix (also
* rectangular) into a tensor,
* putting its upper left element
* at the specified position
* <tt>(dst_r, dst_c)</tt> and
* the other elements
* consequently. Default values
* are chosen so that no
* parameter needs to be specified
* if the size of the tensor and
* that of the matrix coincide.
*/
template <int dim>
void
copy_to(Tensor<2,dim> &T,
const size_type src_r_i=0,
const size_type src_r_j=dim-1,
const size_type src_c_i=0,
const size_type src_c_j=dim-1,
const size_type dst_r=0,
const size_type dst_c=0) const;
/**
* Copy a subset of the rows and columns of another matrix into the
* current object.
*
* @param matrix The matrix from which a subset is to be taken from.
* @param row_index_set The set of rows of @p matrix from which to extract.
* @param column_index_set The set of columns of @p matrix from which to extract.
* @pre The number of elements in @p row_index_set and
* @p column_index_set shall be equal to the number of
* rows and columns in the current object. In other words,
* the current object is not resized for this operation.
*/
template <typename MatrixType, typename index_type>
void extract_submatrix_from (const MatrixType &matrix,
const std::vector<index_type> &row_index_set,
const std::vector<index_type> &column_index_set);
/**
* Copy the elements of the current matrix object into a specified
* set of rows and columns of another matrix. Thus, this is a scatter operation.
*
* @param row_index_set The rows of @p matrix into which to write.
* @param column_index_set The columns of @p matrix into which to write.
* @param matrix The matrix within which certain elements are to be replaced.
* @pre The number of elements in @p row_index_set and
* @p column_index_set shall be equal to the number of
* rows and columns in the current object. In other words,
* the current object is not resized for this operation.
*/
template <typename MatrixType, typename index_type>
void
scatter_matrix_to (const std::vector<index_type> &row_index_set,
const std::vector<index_type> &column_index_set,
MatrixType &matrix) const;
/**
* Fill rectangular block.
*
* A rectangular block of the
* matrix <tt>src</tt> is copied into
* <tt>this</tt>. The upper left
* corner of the block being
* copied is
* <tt>(src_offset_i,src_offset_j)</tt>.
* The upper left corner of the
* copied block is
* <tt>(dst_offset_i,dst_offset_j)</tt>.
* The size of the rectangular
* block being copied is the
* maximum size possible,
* determined either by the size
* of <tt>this</tt> or <tt>src</tt>.
*/
template <typename number2>
void fill (const FullMatrix<number2> &src,
const size_type dst_offset_i = 0,
const size_type dst_offset_j = 0,
const size_type src_offset_i = 0,
const size_type src_offset_j = 0);
/**
* Make function of base class
* available.
*/
template <typename number2>
void fill (const number2 *);
/**
* Fill with permutation of
* another matrix.
*
* The matrix <tt>src</tt> is copied
* into the target. The two
* permutation <tt>p_r</tt> and
* <tt>p_c</tt> operate in a way, such
* that <tt>result(i,j) =
* src(p_r[i], p_c[j])</tt>.
*
* The vectors may also be a
* selection from a larger set of
* integers, if the matrix
* <tt>src</tt> is bigger. It is also
* possible to duplicate rows or
* columns by this method.
*/
template <typename number2>
void fill_permutation (const FullMatrix<number2> &src,
const std::vector<size_type> &p_rows,
const std::vector<size_type> &p_cols);
/**
* Set a particular entry of the matrix to a value. Thus, calling
* <code>A.set(1,2,3.141);</code> is entirely equivalent to the operation
* <code>A(1,2) = 3.141;</code>. This function exists for compatibility
* with the various sparse matrix objects.
*
* @param i The row index of the element to be set.
* @param j The columns index of the element to be set.
* @param value The value to be written into the element.
*/
void set (const size_type i,
const size_type j,
const number value);
/**
* @}
*/
/**
* @name Non-modifying operators
*/
/**
* @{
*/
/**
* Comparison operator. Be
* careful with this thing, it
* may eat up huge amounts of
* computing time! It is most
* commonly used for internal
* consistency checks of
* programs.
*/
bool operator == (const FullMatrix<number> &) const;
/**
* Number of rows of this matrix.
* To remember: this matrix is an
* <i>m x n</i>-matrix.
*/
size_type m () const;
/**
* Number of columns of this matrix.
* To remember: this matrix is an
* <i>m x n</i>-matrix.
*/
size_type n () const;
/**
* Return whether the matrix
* contains only elements with
* value zero. This function is
* mainly for internal
* consistency checks and should
* seldom be used when not in
* debug mode since it uses quite
* some time.
*/
bool all_zero () const;
/**
* Return the square of the norm
* of the vector <tt>v</tt> induced by
* this matrix,
* i.e. <i>(v,Mv)</i>. This is
* useful, e.g. in the finite
* element context, where the
* <i>L<sup>2</sup></i> norm of a
* function equals the matrix
* norm with respect to the mass
* matrix of the vector
* representing the nodal values
* of the finite element
* function.
*
* Obviously, the matrix needs to be
* quadratic for this operation, and for
* the result to actually be a norm it
* also needs to be either real symmetric
* or complex hermitian.
*
* The underlying template types of both
* this matrix and the given vector
* should either both be real or
* complex-valued, but not mixed, for
* this function to make sense.
*/
template <typename number2>
number2 matrix_norm_square (const Vector<number2> &v) const;
/**
* Build the matrix scalar
* product <tt>u<sup>T</sup> M
* v</tt>. This function is
* mostly useful when building
* the cellwise scalar product of
* two functions in the finite
* element context.
*
* The underlying template types of both
* this matrix and the given vector
* should either both be real or
* complex-valued, but not mixed, for
* this function to make sense.
*/
template <typename number2>
number2 matrix_scalar_product (const Vector<number2> &u,
const Vector<number2> &v) const;
/**
* Return the
* <i>l<sub>1</sub></i>-norm of
* the matrix, where
* $||M||_1 = \max_j \sum_i
* |M_{ij}|$ (maximum of
* the sums over columns).
*/
real_type l1_norm () const;
/**
* Return the $l_\infty$-norm of
* the matrix, where
* $||M||_\infty = \max_i \sum_j
* |M_{ij}|$ (maximum of the sums
* over rows).
*/
real_type linfty_norm () const;
/**
* Compute the Frobenius norm of
* the matrix. Return value is
* the root of the square sum of
* all matrix entries.
*
* @note For the timid among us:
* this norm is not the norm
* compatible with the
* <i>l<sub>2</sub></i>-norm of
* the vector space.
*/
real_type frobenius_norm () const;
/**
* Compute the relative norm of
* the skew-symmetric part. The
* return value is the Frobenius
* norm of the skew-symmetric
* part of the matrix divided by
* that of the matrix.
*
* Main purpose of this function
* is to check, if a matrix is
* symmetric within a certain
* accuracy, or not.
*/
real_type relative_symmetry_norm2 () const;
/**
* Computes the determinant of a
* matrix. This is only
* implemented for one, two, and
* three dimensions, since for
* higher dimensions the
* numerical work explodes.
* Obviously, the matrix needs to
* be quadratic for this function.
*/
number determinant () const;
/**
* Return the trace of the matrix,
* i.e. the sum of the diagonal values
* (which happens to also equal the sum
* of the eigenvalues of a matrix).
* Obviously, the matrix needs to
* be quadratic for this function.
*/
number trace () const;
/**
* Output of the matrix in user-defined format given by the specified
* precision and width. This function saves width and precision of the
* stream before setting these given values for output, and restores the
* previous values after output.
*/
template <class STREAM>
void print (STREAM &s,
const unsigned int width=5,
const unsigned int precision=2) const;
/**
* Print the matrix and allow
* formatting of entries.
*
* The parameters allow for a
* flexible setting of the output
* format:
*
* @arg <tt>precision</tt>
* denotes the number of trailing
* digits.
*
* @arg <tt>scientific</tt> is
* used to determine the number
* format, where
* <tt>scientific</tt> =
* <tt>false</tt> means fixed
* point notation.
*
* @arg <tt>width</tt> denotes
* the with of each column. A
* zero entry for <tt>width</tt>
* makes the function compute a
* width, but it may be changed
* to a positive value, if output
* is crude.
*
* @arg <tt>zero_string</tt>
* specifies a string printed for
* zero entries.
*
* @arg <tt>denominator</tt>
* Multiply the whole matrix by
* this common denominator to get
* nicer numbers.
*
* @arg <tt>threshold</tt>: all
* entries with absolute value
* smaller than this are
* considered zero.
*/
void print_formatted (std::ostream &out,
const unsigned int precision=3,
const bool scientific = true,
const unsigned int width = 0,
const char *zero_string = " ",
const double denominator = 1.,
const double threshold = 0.) const;
/**
* Determine an estimate for the
* memory consumption (in bytes)
* of this object.
*/
std::size_t memory_consumption () const;
//@}
///@name Iterator functions
//@{
/**
* 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 <tt>r</tt>.
*/
const_iterator begin (const size_type r) const;
/**
* Final iterator of row <tt>r</tt>.
*/
const_iterator end (const size_type r) const;
//@}
///@name Modifying operators
//@{
/**
* Scale the entire matrix by a
* fixed factor.
*/
FullMatrix &operator *= (const number factor);
/**
* Scale the entire matrix by the
* inverse of the given factor.
*/
FullMatrix &operator /= (const number factor);
/**
* Simple addition of a scaled
* matrix, i.e. <tt>*this +=
* a*A</tt>.
*
* The matrix <tt>A</tt> may be a
* full matrix over an arbitrary
* underlying scalar type, as
* long as its data type is
* convertible to the data type
* of this matrix.
*/
template <typename number2>
void add (const number a,
const FullMatrix<number2> &A);
/**
* Multiple addition of scaled
* matrices, i.e. <tt>*this +=
* a*A + b*B</tt>.
*
* The matrices <tt>A</tt> and
* <tt>B</tt> may be a full
* matrix over an arbitrary
* underlying scalar type, as
* long as its data type is
* convertible to the data type
* of this matrix.
*/
template <typename number2>
void add (const number a,
const FullMatrix<number2> &A,
const number b,
const FullMatrix<number2> &B);
/**
* Multiple addition of scaled
* matrices, i.e. <tt>*this +=
* a*A + b*B + c*C</tt>.
*
* The matrices <tt>A</tt>,
* <tt>B</tt> and <tt>C</tt> may
* be a full matrix over an
* arbitrary underlying scalar
* type, as long as its data type
* is convertible to the data
* type of this matrix.
*/
template <typename number2>
void add (const number a,
const FullMatrix<number2> &A,
const number b,
const FullMatrix<number2> &B,
const number c,
const FullMatrix<number2> &C);
/**
* Add rectangular block.
*
* A rectangular block of the matrix
* <tt>src</tt> is added to
* <tt>this</tt>. The upper left corner
* of the block being copied is
* <tt>(src_offset_i,src_offset_j)</tt>.
* The upper left corner of the copied
* block is
* <tt>(dst_offset_i,dst_offset_j)</tt>.
* The size of the rectangular block
* being copied is the maximum size
* possible, determined either by the
* size of <tt>this</tt> or <tt>src</tt>
* and the given offsets.
*/
template <typename number2>
void add (const FullMatrix<number2> &src,
const number factor,
const size_type dst_offset_i = 0,
const size_type dst_offset_j = 0,
const size_type src_offset_i = 0,
const size_type src_offset_j = 0);
/**
* Weighted addition of the
* transpose of <tt>B</tt> to
* <tt>this</tt>.
*
* <i>A += s B<sup>T</sup></i>
*/
template <typename number2>
void Tadd (const number s,
const FullMatrix<number2> &B);
/**
* Add transpose of a rectangular block.
*
* A rectangular block of the
* matrix <tt>src</tt> is
* transposed and addedadded to
* <tt>this</tt>. The upper left
* corner of the block being
* copied is
* <tt>(src_offset_i,src_offset_j)</tt>
* in the coordinates of the
* <b>non</b>-transposed matrix.
* The upper left corner of the
* copied block is
* <tt>(dst_offset_i,dst_offset_j)</tt>.
* The size of the rectangular
* block being copied is the
* maximum size possible,
* determined either by the size
* of <tt>this</tt> or
* <tt>src</tt>.
*/
template <typename number2>
void Tadd (const FullMatrix<number2> &src,
const number factor,
const size_type dst_offset_i = 0,
const size_type dst_offset_j = 0,
const size_type src_offset_i = 0,
const size_type src_offset_j = 0);
/**
* Add a single element at the
* given position.
*/
void add (const size_type row,
const size_type column,
const number value);
/**
* Add an array of values given by
* <tt>values</tt> in the given global
* matrix row at columns specified by
* col_indices in the full matrix. This
* function is present for
* compatibility with the various
* sparse matrices in deal.II. In
* particular, the two boolean fields
* @p elide_zero_values and @p
* col_indices_are_sorted do not impact
* the performance of this routine, as
* opposed to the sparse matrix case
* and are indeed ignored in the
* implementation.
*/
template <typename number2, typename index_type>
void add (const size_type row,
const unsigned int n_cols,
const index_type *col_indices,
const number2 *values,
const bool elide_zero_values = true,
const bool col_indices_are_sorted = false);
/**
* <i>A(i,1...n) +=
* s*A(j,1...n)</i>. Simple
* addition of rows of this
*/
void add_row (const size_type i,
const number s,
const size_type j);
/**
* <i>A(i,1...n) += s*A(j,1...n) +
* t*A(k,1...n)</i>. Multiple
* addition of rows of this.
*/
void add_row (const size_type i,
const number s, const size_type j,
const number t, const size_type k);
/**
* <i>A(1...n,i) += s*A(1...n,j)</i>.
* Simple addition of columns of this.
*/
void add_col (const size_type i,
const number s,
const size_type j);
/**
* <i>A(1...n,i) += s*A(1...n,j) +
* t*A(1...n,k)</i>. Multiple
* addition of columns of this.
*/
void add_col (const size_type i,
const number s, const size_type j,
const number t, const size_type k);
/**
* Swap <i>A(i,1...n) <->
* A(j,1...n)</i>. Swap rows i
* and j of this
*/
void swap_row (const size_type i,
const size_type j);
/**
* Swap <i>A(1...n,i) <->
* A(1...n,j)</i>. Swap columns
* i and j of this
*/
void swap_col (const size_type i,
const size_type j);
/**
* Add constant to diagonal
* elements of this, i.e. add a
* multiple of the identity
* matrix.
*/
void diagadd (const number s);
/**
* Assignment <tt>*this =
* a*A</tt>.
*/
template <typename number2>
void equ (const number a,
const FullMatrix<number2> &A);
/**
* Assignment <tt>*this = a*A +
* b*B</tt>.
*/
template <typename number2>
void equ (const number a,
const FullMatrix<number2> &A,
const number b,
const FullMatrix<number2> &B);
/**
* Assignment <tt>*this = a*A +
* b*B + c*C</tt>.
*/
template <typename number2>
void equ (const number a,
const FullMatrix<number2> &A,
const number b,
const FullMatrix<number2> &B,
const number c,
const FullMatrix<number2> &C);
/**
* Symmetrize the matrix by
* forming the mean value between
* the existing matrix and its
* transpose, <i>A =
* 1/2(A+A<sup>T</sup>)</i>.
*
* Obviously the matrix must be
* quadratic for this operation.
*/
void symmetrize ();
/**
* A=Inverse(A). A must be a square matrix.
* Inversion of
* this matrix by Gauss-Jordan
* algorithm with partial
* pivoting. This process is
* well-behaved for positive
* definite matrices, but be
* aware of round-off errors in
* the indefinite case.
*
* In case deal.II was configured with
* LAPACK, the functions Xgetrf and
* Xgetri build an LU factorization and
* invert the matrix upon that
* factorization, providing best
* performance up to matrices with a
* few hundreds rows and columns.
*
* The numerical effort to invert
* an <tt>n x n</tt> matrix is of the
* order <tt>n**3</tt>.
*/
void gauss_jordan ();
/**
* Assign the inverse of the given matrix
* to <tt>*this</tt>. This function is
* hardcoded for quadratic matrices of
* dimension one to four. However, since
* the amount of code needed grows
* quickly, the method gauss_jordan() is
* invoked implicitly if the dimension is
* larger.
*/
template <typename number2>
void invert (const FullMatrix<number2> &M);
/**
* Assign the Cholesky decomposition
* of the given matrix to <tt>*this</tt>.
* The given matrix must be symmetric
* positive definite.
*
* ExcMatrixNotPositiveDefinite
* will be thrown in the case that the
* matrix is not positive definite.
*/
template <typename number2>
void cholesky (const FullMatrix<number2> &A);
/**
* <tt>*this(i,j)</tt> = $V(i) W(j)$
* where $V,W$
* are vectors of the same length.
*/
template <typename number2>
void outer_product (const Vector<number2> &V,
const Vector<number2> &W);
/**
* Assign the left_inverse of the given matrix
* to <tt>*this</tt>. The calculation being
* performed is <i>(A<sup>T</sup>*A)<sup>-1</sup>
* *A<sup>T</sup></i>.
*/
template <typename number2>
void left_invert (const FullMatrix<number2> &M);
/**
* Assign the right_inverse of the given matrix
* to <tt>*this</tt>. The calculation being
* performed is <i>A<sup>T</sup>*(A*A<sup>T</sup>)
* <sup>-1</sup></i>.
*/
template <typename number2>
void right_invert (const FullMatrix<number2> &M);
//@}
///@name Multiplications
//@{
/**
* Matrix-matrix-multiplication.
*
* The optional parameter
* <tt>adding</tt> determines, whether the
* result is stored in <tt>C</tt> or added
* to <tt>C</tt>.
*
* if (adding)
* <i>C += A*B</i>
*
* if (!adding)
* <i>C = A*B</i>
*
* Assumes that <tt>A</tt> and
* <tt>B</tt> have compatible sizes and
* that <tt>C</tt> already has the
* right size.
*
* This function uses the BLAS function
* Xgemm if the calling matrix has more
* than 15 rows and BLAS was detected
* during configuration. Using BLAS
* usually results in considerable
* performance gains.
*/
template <typename number2>
void mmult (FullMatrix<number2> &C,
const FullMatrix<number2> &B,
const bool adding=false) const;
/**
* Matrix-matrix-multiplication using
* transpose of <tt>this</tt>.
*
* The optional parameter
* <tt>adding</tt> determines, whether the
* result is stored in <tt>C</tt> or added
* to <tt>C</tt>.
*
* if (adding)
* <i>C += A<sup>T</sup>*B</i>
*
* if (!adding)
* <i>C = A<sup>T</sup>*B</i>
*
* Assumes that <tt>A</tt> and
* <tt>B</tt> have compatible
* sizes and that <tt>C</tt>
* already has the right size.
*
* This function uses the BLAS function
* Xgemm if the calling matrix has more
* than 15 columns and BLAS was
* detected during configuration. Using
* BLAS usually results in considerable
* performance gains.
*/
template <typename number2>
void Tmmult (FullMatrix<number2> &C,
const FullMatrix<number2> &B,
const bool adding=false) const;
/**
* Matrix-matrix-multiplication using
* transpose of <tt>B</tt>.
*
* The optional parameter
* <tt>adding</tt> determines, whether the
* result is stored in <tt>C</tt> or added
* to <tt>C</tt>.
*
* if (adding)
* <i>C += A*B<sup>T</sup></i>
*
* if (!adding)
* <i>C = A*B<sup>T</sup></i>
*
* Assumes that <tt>A</tt> and
* <tt>B</tt> have compatible sizes and
* that <tt>C</tt> already has the
* right size.
*
* This function uses the BLAS function
* Xgemm if the calling matrix has more
* than 15 rows and BLAS was detected
* during configuration. Using BLAS
* usually results in considerable
* performance gains.
*/
template <typename number2>
void mTmult (FullMatrix<number2> &C,
const FullMatrix<number2> &B,
const bool adding=false) const;
/**
* Matrix-matrix-multiplication using
* transpose of <tt>this</tt> and
* <tt>B</tt>.
*
* The optional parameter
* <tt>adding</tt> determines, whether the
* result is stored in <tt>C</tt> or added
* to <tt>C</tt>.
*
* if (adding)
* <i>C += A<sup>T</sup>*B<sup>T</sup></i>
*
* if (!adding)
* <i>C = A<sup>T</sup>*B<sup>T</sup></i>
*
* Assumes that <tt>A</tt> and
* <tt>B</tt> have compatible
* sizes and that <tt>C</tt>
* already has the right size.
*
* This function uses the BLAS function
* Xgemm if the calling matrix has more
* than 15 columns and BLAS was
* detected during configuration. Using
* BLAS usually results in considerable
* performance gains.
*/
template <typename number2>
void TmTmult (FullMatrix<number2> &C,
const FullMatrix<number2> &B,
const bool adding=false) const;
/**
* Add to the current matrix the
* triple product <b>B A
* D</b>. Optionally, use the
* transposes of the matrices
* <b>B</b> and <b>D</b>. The
* scaling factor scales the
* whole product, which is
* helpful when adding a multiple
* of the triple product to the
* matrix.
*
* This product was written with
* the Schur complement
* <b>B<sup>T</sup>
* A<sup>-1</sup> D</b> in mind.
* Note that in this case the
* argument for <tt>A</tt> must be
* the inverse of the matrix <b>A</b>.
*/
void triple_product(const FullMatrix<number> &A,
const FullMatrix<number> &B,
const FullMatrix<number> &D,
const bool transpose_B = false,
const bool transpose_D = false,
const number scaling = number(1.));
/**
* Matrix-vector-multiplication.
*
* The optional parameter
* <tt>adding</tt> determines, whether the
* result is stored in <tt>w</tt> or added
* to <tt>w</tt>.
*
* if (adding)
* <i>w += A*v</i>
*
* if (!adding)
* <i>w = A*v</i>
*
* Source and destination must
* not be the same vector.
*/
template <typename number2>
void vmult (Vector<number2> &w,
const Vector<number2> &v,
const bool adding=false) const;
/**
* Adding Matrix-vector-multiplication.
* <i>w += A*v</i>
*
* Source and destination must
* not be the same vector.
*/
template <typename number2>
void vmult_add (Vector<number2> &w,
const Vector<number2> &v) const;
/**
* Transpose
* matrix-vector-multiplication.
*
* The optional parameter
* <tt>adding</tt> determines, whether the
* result is stored in <tt>w</tt> or added
* to <tt>w</tt>.
*
* if (adding)
* <i>w += A<sup>T</sup>*v</i>
*
* if (!adding)
* <i>w = A<sup>T</sup>*v</i>
*
*
* Source and destination must
* not be the same vector.
*/
template <typename number2>
void Tvmult (Vector<number2> &w,
const Vector<number2> &v,
const bool adding=false) const;
/**
* Adding transpose
* matrix-vector-multiplication.
* <i>w += A<sup>T</sup>*v</i>
*
* Source and destination must
* not be the same vector.
*/
template <typename number2>
void Tvmult_add (Vector<number2> &w,
const Vector<number2> &v) const;
/**
* Apply the Jacobi
* preconditioner, which
* multiplies every element of
* the <tt>src</tt> vector by the
* inverse of the respective
* diagonal element and
* multiplies the result with the
* damping factor <tt>omega</tt>.
*/
template <typename somenumber>
void precondition_Jacobi (Vector<somenumber> &dst,
const Vector<somenumber> &src,
const number omega = 1.) const;
/**
* <i>dst=b-A*x</i>. Residual calculation,
* returns the <i>l<sub>2</sub></i>-norm
* |<i>dst</i>|.
*
* Source <i>x</i> and destination
* <i>dst</i> must not be the same
* vector.
*/
template <typename number2, typename number3>
number residual (Vector<number2> &dst,
const Vector<number2> &x,
const Vector<number3> &b) const;
/**
* Forward elimination of lower
* triangle. Inverts the lower
* triangle of a rectangular matrix
* for a given right hand side.
*
* If the matrix has more columns
* than rows, this function only
* operates on the left quadratic
* submatrix. If there are more
* rows, the upper quadratic part
* of the matrix is considered.
*
* @note It is safe to use the
* same object for @p dst and @p
* src.
*/
template <typename number2>
void forward (Vector<number2> &dst,
const Vector<number2> &src) const;
/**
* Backward elimination of upper
* triangle.
*
* See forward()
*
* @note It is safe to use the
* same object for @p dst and @p
* src.
*/
template <typename number2>
void backward (Vector<number2> &dst,
const Vector<number2> &src) const;
//@}
/** @addtogroup Exceptions
* @{ */
/**
* Exception
*/
DeclException0 (ExcEmptyMatrix);
/**
* Exception
*/
DeclException1 (ExcNotRegular,
number,
<< "The maximal pivot is " << arg1
<< ", which is below the threshold. The matrix may be singular.");
/**
* Exception
*/
DeclException3 (ExcInvalidDestination,
size_type, size_type, size_type,
<< "Target region not in matrix: size in this direction="
<< arg1 << ", size of new matrix=" << arg2
<< ", offset=" << arg3);
/**
* Exception
*/
DeclException0 (ExcSourceEqualsDestination);
/**
* Exception
*/
DeclException0 (ExcMatrixNotPositiveDefinite);
//@}
friend class Accessor;
};
/**@}*/
#ifndef DOXYGEN
/*-------------------------Inline functions -------------------------------*/
template <typename number>
inline
typename FullMatrix<number>::size_type
FullMatrix<number>::m() const
{
return this->n_rows();
}
template <typename number>
inline
typename FullMatrix<number>::size_type
FullMatrix<number>::n() const
{
return this->n_cols();
}
template <typename number>
FullMatrix<number> &
FullMatrix<number>::operator = (const number d)
{
Assert (d==number(0), ExcScalarAssignmentOnlyForZeroValue());
(void)d; // removes -Wunused-parameter warning in optimized mode
if (this->n_elements() != 0)
std::memset (&this->values[0], 0, this->n_elements()*sizeof(number));
return *this;
}
template <typename number>
template <typename number2>
inline
void FullMatrix<number>::fill (const number2 *src)
{
Table<2,number>::fill(src);
}
template <typename number>
template <class MATRIX>
void
FullMatrix<number>::copy_from (const MATRIX &M)
{
this->reinit (M.m(), M.n());
// loop over the elements of the argument matrix row by row, as suggested
// in the documentation of the sparse matrix iterator class, and
// copy them into the current object
for (size_type row = 0; row < M.m(); ++row)
{
const typename MATRIX::const_iterator end_row = M.end(row);
for (typename MATRIX::const_iterator entry = M.begin(row);
entry != end_row; ++entry)
this->el(row, entry->column()) = entry->value();
}
}
template <typename number>
template <class MATRIX>
void
FullMatrix<number>::copy_transposed (const MATRIX &M)
{
this->reinit (M.n(), M.m());
// loop over the elements of the argument matrix row by row, as suggested
// in the documentation of the sparse matrix iterator class, and
// copy them into the current object
for (size_type row = 0; row < M.m(); ++row)
{
const typename MATRIX::const_iterator end_row = M.end(row);
for (typename MATRIX::const_iterator entry = M.begin(row);
entry != end_row; ++entry)
this->el(entry->column(), row) = entry->value();
}
}
template <typename number>
template <typename MatrixType, typename index_type>
inline
void
FullMatrix<number>::extract_submatrix_from (const MatrixType &matrix,
const std::vector<index_type> &row_index_set,
const std::vector<index_type> &column_index_set)
{
AssertDimension(row_index_set.size(), this->n_rows());
AssertDimension(column_index_set.size(), this->n_cols());
const size_type n_rows_submatrix = row_index_set.size();
const size_type n_cols_submatrix = column_index_set.size();
for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
(*this)(sub_row, sub_col) = matrix.el(row_index_set[sub_row], column_index_set[sub_col]);
}
template <typename number>
template <typename MatrixType, typename index_type>
inline
void
FullMatrix<number>::scatter_matrix_to (const std::vector<index_type> &row_index_set,
const std::vector<index_type> &column_index_set,
MatrixType &matrix) const
{
AssertDimension(row_index_set.size(), this->n_rows());
AssertDimension(column_index_set.size(), this->n_cols());
const size_type n_rows_submatrix = row_index_set.size();
const size_type n_cols_submatrix = column_index_set.size();
for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
matrix.set(row_index_set[sub_row],
column_index_set[sub_col],
(*this)(sub_row, sub_col));
}
template <typename number>
inline
void
FullMatrix<number>::set (const size_type i,
const size_type j,
const number value)
{
(*this)(i,j) = value;
}
template <typename number>
template <typename number2>
void
FullMatrix<number>::vmult_add (Vector<number2> &w,
const Vector<number2> &v) const
{
vmult(w, v, true);
}
template <typename number>
template <typename number2>
void
FullMatrix<number>::Tvmult_add (Vector<number2> &w,
const Vector<number2> &v) const
{
Tvmult(w, v, true);
}
//---------------------------------------------------------------------------
template <typename number>
inline
FullMatrix<number>::Accessor::
Accessor (const FullMatrix<number> *matrix,
const size_type r,
const size_type c)
:
matrix(matrix),
a_row(r),
a_col(c)
{}
template <typename number>
inline
typename FullMatrix<number>::size_type
FullMatrix<number>::Accessor::row() const
{
return a_row;
}
template <typename number>
inline
typename FullMatrix<number>::size_type
FullMatrix<number>::Accessor::column() const
{
return a_col;
}
template <typename number>
inline
number
FullMatrix<number>::Accessor::value() const
{
Assert (numbers::is_finite( matrix->el(a_row, a_col) ), ExcNumberNotFinite());
return matrix->el(a_row, a_col);
}
template <typename number>
inline
FullMatrix<number>::const_iterator::
const_iterator(const FullMatrix<number> *matrix,
const size_type r,
const size_type c)
:
accessor(matrix, r, c)
{}
template <typename number>
inline
typename FullMatrix<number>::const_iterator &
FullMatrix<number>::const_iterator::operator++ ()
{
Assert (accessor.a_row < accessor.matrix->m(), ExcIteratorPastEnd());
++accessor.a_col;
if (accessor.a_col >= accessor.matrix->n())
{
accessor.a_col = 0;
accessor.a_row++;
}
return *this;
}
template <typename number>
inline
const typename FullMatrix<number>::Accessor &
FullMatrix<number>::const_iterator::operator* () const
{
return accessor;
}
template <typename number>
inline
const typename FullMatrix<number>::Accessor *
FullMatrix<number>::const_iterator::operator-> () const
{
return &accessor;
}
template <typename number>
inline
bool
FullMatrix<number>::const_iterator::
operator == (const const_iterator &other) const
{
return (accessor.row() == other.accessor.row() &&
accessor.column() == other.accessor.column());
}
template <typename number>
inline
bool
FullMatrix<number>::const_iterator::
operator != (const const_iterator &other) const
{
return ! (*this == other);
}
template <typename number>
inline
bool
FullMatrix<number>::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 <typename number>
inline
bool
FullMatrix<number>::const_iterator::
operator > (const const_iterator &other) const
{
return (other < *this);
}
template <typename number>
inline
typename FullMatrix<number>::const_iterator
FullMatrix<number>::begin () const
{
return const_iterator(this, 0, 0);
}
template <typename number>
inline
typename FullMatrix<number>::const_iterator
FullMatrix<number>::end () const
{
return const_iterator(this, m(), 0);
}
template <typename number>
inline
typename FullMatrix<number>::const_iterator
FullMatrix<number>::begin (const size_type r) const
{
Assert (r<m(), ExcIndexRange(r,0,m()));
return const_iterator(this, r, 0);
}
template <typename number>
inline
typename FullMatrix<number>::const_iterator
FullMatrix<number>::end (const size_type r) const
{
Assert (r<m(), ExcIndexRange(r,0,m()));
return const_iterator(this, r+1, 0);
}
template <typename number>
inline
void
FullMatrix<number>::add (const size_type r, const size_type c, const number v)
{
AssertIndexRange(r, this->m());
AssertIndexRange(c, this->n());
this->operator()(r,c) += v;
}
template <typename number>
template <typename number2, typename index_type>
inline
void
FullMatrix<number>::add (const size_type row,
const unsigned int n_cols,
const index_type *col_indices,
const number2 *values,
const bool,
const bool)
{
AssertIndexRange(row, this->m());
for (size_type col=0; col<n_cols; ++col)
{
AssertIndexRange(col_indices[col], this->n());
this->operator()(row,col_indices[col]) += values[col];
}
}
template <typename number>
template <class STREAM>
inline
void
FullMatrix<number>::print (STREAM &s,
const unsigned int w,
const unsigned int p) const
{
Assert (!this->empty(), ExcEmptyMatrix());
// save the state of out stream
const unsigned int old_precision = s.precision (p);
const unsigned int old_width = s.width (w);
for (size_type i=0; i<this->m(); ++i)
{
for (size_type j=0; j<this->n(); ++j)
{
s.width(w);
s.precision(p);
s << this->el(i,j);
}
s << std::endl;
}
// reset output format
s.precision(old_precision);
s.width(old_width);
}
#endif // DOXYGEN
DEAL_II_NAMESPACE_CLOSE
#endif
|