/usr/include/deal.II/numerics/mesh_worker_assembler.h is in libdeal.ii-dev 6.3.1-1.1.
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 | //---------------------------------------------------------------------------
// $Id: mesh_worker_assembler.h 21094 2010-05-07 14:37:24Z janssen $
//
// Copyright (C) 2010 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__mesh_worker_assembler_h
#define __deal2__mesh_worker_assembler_h
#include <numerics/mesh_worker_info.h>
#include <base/named_data.h>
#include <base/smartpointer.h>
#include <lac/block_vector.h>
#include <base/mg_level_object.h>
DEAL_II_NAMESPACE_OPEN
namespace MeshWorker
{
/**
* The namespace containing objects that can be used to assemble data
* computed on cells and faces into global objects. This can reach
* from collecting the total error estimate from cell and face
* contributions to assembling matrices and multilevel matrices.
*
* <h3>Data models</h3>
*
* The class chosen from this namespace determines which data model is
* used. For the local as well as the global objects, we have the
* choice between two models:
*
* <h4>The comprehensive data model</h4>
*
* This is the structure set up by the FESystem class. Globally, this
* means, data is assembled into one residual vector and into one
* matrix. These objects may be block vectors and block matrices, but
* the process of assembling ignores this fact.
*
* Similarly, there is only a single cell vector and cell matrix,
* respectively, which is indexed by all degrees of freedom of the
* FESystem. When building the cell matrix, it is necessary to
* distinguish between the different components of the system and
* select the right operator for each pair.
*
* <h4>The blocked data model</h4>
*
* Here, all the blocks are treated separately (in spite of using
* FESystem for its convenience in other places). For instance, no
* block matrix is assembled, but a list of blocks, which can be
* combined later by BlockMatrixArray. Locally, this means, that each
* matrix block of a system is generated separately and assembled into
* the corresponding global block.
*
* This approach is advantageous, if the number of matrices for each
* block position in the global system is different. For instance,
* block preconditioners for the Oseen problem require 3 pressure
* matrices, but only one divergence and one advection-diffusion
* operator for velocities.
*
* Additionally, this approach enables the construction of a system of
* equations from building blocks for each equation and coupling
* operator.
*
* Nevertheless, since a separate FEValues object must be created for
* each base element, it is not quite clear a priori, which data model
* is more efficient.
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
namespace Assembler
{
/**
* The class assembling local contributions to a functional into the
* global functionals.
*
*
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
template <typename number = double>
class Functional
{
public:
/**
* Initialize local data to
* store functionals.
*/
void initialize(unsigned int n);
/**
* Initialize the local data
* in the
* DoFInfo
* object used later for
* assembling.
*
* The second parameter is
* used to distinguish
* between the data used on
* cells and boundary faces
* on the one hand and
* interior faces on the
* other. Interior faces may
* require additional data
* being initialized.
*/
template <int dim>
void initialize_info(DoFInfo<dim>& info,
bool interior_face);
/**
* Assemble the local values
* into the global vectors.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info);
/**
* Assemble both local values
* into the global vectors.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2);
/**
* The value of the ith entry
* in #results.
*/
number operator() (unsigned int i) const;
private:
/**
* The values into which the
* results are added.
*/
std::vector<double> results;
};
/**
* Compute cell and face contributions of one or several functionals,
* typically for error estimates.
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
template <typename number = double>
class CellsAndFaces
{
public:
/**
* The data type for
* communicating the cell and
* face vectors.
*/
typedef NamedData<BlockVector<number>*> DataVectors;
/**
* The initialization
* function, specifying the
* #results vectors and
* whether face data should
* be collected separately.
*
* #results should contain
* two block vectors named
* "cells" and "faces" (the
* latter only if
* #separate_faces is
* true). In each of the two,
* each block should have
* equal size and be large
* enough to accomodate all
* user indices set in the
* cells and faces covered by
* the loop it is used
* in. Typically, for
* estimators, this is
* Triangulation::n_active_cells()
* and
* Triangulation::n_faces(),
* respectively.
*
* The use of BlockVector may
* seem cumbersome, but it
* allows us to assemble
* several functionals at the
* same time, one in each
* block. The typical
* situation for error
* estimate is just having a
* single block in each vector.
*/
void initialize(DataVectors& results,
bool separate_faces = true);
/**
* Initialize the local data
* in the
* DoFInfo
* object used later for
* assembling.
*
* The second parameter is
* used to distinguish
* between the data used on
* cells and boundary faces
* on the one hand and
* interior faces on the
* other. Interior faces may
* require additional data
* being initialized.
*/
template <int dim>
void initialize_info(DoFInfo<dim>& info,
bool interior_face) const;
/**
* Assemble the local values
* into the global vectors.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info);
/**
* Assemble both local values
* into the global vectors.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2);
/**
* The value of the ith entry
* in #results.
*/
number operator() (unsigned int i) const;
private:
DataVectors results;
bool separate_faces;
};
/**
* Assemble residuals without block structure.
*
* The data structure for this Assembler class is a simple vector on
* each cell with entries from zero to
* FiniteElementData::dofs_per_cell and a simple global vector with
* entries numbered from zero to DoFHandler::n_dofs(). No BlockInfo is
* required and the global vector may be any type of vector having
* element access through <tt>operator() (unsigned int)</tt>
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
template <class VECTOR>
class ResidualSimple
{
public:
void initialize(NamedData<VECTOR*>& results);
/**
* Initialize the constraints.
*/
void initialize(const ConstraintMatrix& constraints);
/**
* Initialize the local data
* in the
* DoFInfo
* object used later for
* assembling.
*
* The second parameter is
* used to distinguish
* between the data used on
* cells and boundary faces
* on the one hand and
* interior faces on the
* other. Interior faces may
* require additional data
* being initialized.
*/
template <int dim>
void initialize_info(DoFInfo<dim>& info,
bool interior_face) const;
/**
* Assemble the local residuals
* into the global residuals.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info);
/**
* Assemble both local residuals
* into the global residuals.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2);
private:
/**
* The global residal vectors
* filled by assemble().
*/
NamedData<SmartPointer<VECTOR,ResidualSimple<VECTOR> > > residuals;
/**
* A pointer to the object containing constraints.
*/
SmartPointer<const ConstraintMatrix,ResidualSimple<VECTOR> > constraints;
};
/**
* Assemble local residuals into global residuals.
*
* The global residuals are expected as an FEVectors object.
* The local residuals are block vectors.
*
* Depending on whether the BlockInfo object was initialize with
* BlockInfo::initialize_local(), the comprehensive or block data
* model is used locally.
*
* In the block model, each of the blocks of the local vectors
* corresponds to the restriction of a single block of the system to
* this cell (@ref GlossBlock). Thus, the size of this local block is
* the number of degrees of freedom of the corresponding base element
* of the FESystem.
*
* @todo Comprehensive model currently not implemented.
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
template <class VECTOR>
class ResidualLocalBlocksToGlobalBlocks
{
public:
/**
* Copy the BlockInfo and the
* matrix pointers into local
* variables.
*/
void initialize(const BlockInfo* block_info,
NamedData<VECTOR*>& residuals);
/**
* Initialize the constraints.
*/
void initialize(const ConstraintMatrix& constraints);
/**
* Initialize the local data
* in the
* DoFInfo
* object used later for
* assembling.
*
* The second parameter is
* used to distinguish
* between the data used on
* cells and boundary faces
* on the one hand and
* interior faces on the
* other. Interior faces may
* require additional data
* being initialized.
*/
template <int dim>
void initialize_info(DoFInfo<dim>& info,
bool interior_face) const;
/**
* Assemble the local residuals
* into the global residuals.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info);
/**
* Assemble both local residuals
* into the global residuals.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2);
private:
/**
* Assemble a single local
* residual into the global.
*/
void assemble(VECTOR& global,
const BlockVector<double>& local,
const std::vector<unsigned int>& dof);
/**
* The global matrices,
* stored as a vector of
* pointers.
*/
NamedData<SmartPointer<VECTOR,
ResidualLocalBlocksToGlobalBlocks<VECTOR> > > residuals;
/**
* A pointer to the object containing the block structure.
*/
SmartPointer<const BlockInfo,
ResidualLocalBlocksToGlobalBlocks<VECTOR> > block_info;
/**
* A pointer to the object containing constraints.
*/
SmartPointer<const ConstraintMatrix,
ResidualLocalBlocksToGlobalBlocks<VECTOR> > constraints;
};
/**
* Assemble local matrices into a single global matrix without using
* block structure.
*
* After being initialized with a SparseMatrix object (or another
* matrix offering the same functionality as SparseMatrix::add()),
* this class can be used in a MeshWorker::loop() to assemble the cell
* and face matrices into the global matrix.
*
* @todo On locally refined meshes, a ConstraintMatrix should be used
* to automatically eliminate hanging nodes.
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
template <class MATRIX>
class MatrixSimple
{
public:
/**
* Constructor, initializing
* the #threshold, which
* limits how small numbers
* may be to be entered into
* the matrix.
*/
MatrixSimple(double threshold = 1.e-12);
/**
* Store the result matrix
* for later assembling.
*/
void initialize(MATRIX& m);
/**
* Initialize the constraints.
*/
void initialize(const ConstraintMatrix& constraints);
/**
* Initialize the local data
* in the
* DoFInfo
* object used later for
* assembling.
*
* The second parameter is
* used to distinguish
* between the data used on
* cells and boundary faces
* on the one hand and
* interior faces on the
* other. Interior faces may
* require additional data
* being initialized.
*/
template <int dim>
void initialize_info(DoFInfo<dim>& info,
bool interior_face) const;
/**
* Assemble the matrix
* DoFInfo::M1[0]
* into the global matrix.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info);
/**
* Assemble both local
* matrices in the info
* objects into the global
* matrix.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2);
private:
/**
* Assemble a single matrix
* into #matrix.
*/
void assemble(const FullMatrix<double>& M,
const std::vector<unsigned int>& i1,
const std::vector<unsigned int>& i2);
/**
* The global matrix being
* assembled.
*/
SmartPointer<MATRIX,MatrixSimple<MATRIX> > matrix;
/**
* A pointer to the object containing constraints.
*/
SmartPointer<const ConstraintMatrix,MatrixSimple<MATRIX> > constraints;
/**
* The smallest positive
* number that will be
* entered into the global
* matrix. All smaller
* absolute values will be
* treated as zero and will
* not be assembled.
*/
const double threshold;
};
/**
* Assemble local matrices into level matrices without using
* block structure.
*
* @todo The matrix structures needed for assembling level matrices
* with local refinement and continuous elements are missing.
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
template <class MATRIX>
class MGMatrixSimple
{
public:
/**
* Constructor, initializing
* the #threshold, which
* limits how small numbers
* may be to be entered into
* the matrix.
*/
MGMatrixSimple(double threshold = 1.e-12);
/**
* Store the result matrix
* for later assembling.
*/
void initialize(MGLevelObject<MATRIX>& m);
/**
* Initialize the matrices
* #flux_up and #flux_down
* used for local refinement
* with discontinuous
* Galerkin methods.
*/
void initialize_fluxes(MGLevelObject<MATRIX>& flux_up,
MGLevelObject<MATRIX>& flux_down);
/**
* Initialize the matrices
* #interface_up and #interface_down
* used for local refinement
* with continuous
* Galerkin methods.
*/
void initialize_interfaces(MGLevelObject<MATRIX>& interface_up,
MGLevelObject<MATRIX>& interface_down);
/**
* Initialize the local data
* in the
* DoFInfo
* object used later for
* assembling.
*
* The second parameter is
* used to distinguish
* between the data used on
* cells and boundary faces
* on the one hand and
* interior faces on the
* other. Interior faces may
* require additional data
* being initialized.
*/
template <int dim>
void initialize_info(DoFInfo<dim>& info,
bool interior_face) const;
/**
* Assemble the matrix
* DoFInfo::M1[0]
* into the global matrix.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info);
/**
* Assemble both local
* matrices in the info
* objects into the global
* matrices.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2);
private:
/**
* Assemble a single matrix
* into a global matrix.
*/
void assemble(MATRIX& G,
const FullMatrix<double>& M,
const std::vector<unsigned int>& i1,
const std::vector<unsigned int>& i2);
/**
* Assemble a single matrix
* into a global matrix.
*/
void assemble_transpose(MATRIX& G,
const FullMatrix<double>& M,
const std::vector<unsigned int>& i1,
const std::vector<unsigned int>& i2);
/**
* The global matrix being
* assembled.
*/
SmartPointer<MGLevelObject<MATRIX>,MGMatrixSimple<MATRIX> > matrix;
/**
* The matrix used for face
* flux terms across the
* refinement edge, coupling
* coarse to fine.
*/
SmartPointer<MGLevelObject<MATRIX>,MGMatrixSimple<MATRIX> > flux_up;
/**
* The matrix used for face
* flux terms across the
* refinement edge, coupling
* fine to coarse.
*/
SmartPointer<MGLevelObject<MATRIX>,MGMatrixSimple<MATRIX> > flux_down;
/**
* The matrix used for face
* contributions for continuous
* elements across the
* refinement edge, coupling
* coarse to fine.
*/
SmartPointer<MGLevelObject<MATRIX>,MGMatrixSimple<MATRIX> > interface_up;
/**
* The matrix used for face
* contributions for continuous
* elements across the
* refinement edge, coupling
* fine to coarse.
*/
SmartPointer<MGLevelObject<MATRIX>,MGMatrixSimple<MATRIX> > interface_down;
/**
* The smallest positive
* number that will be
* entered into the global
* matrix. All smaller
* absolute values will be
* treated as zero and will
* not be assembled.
*/
const double threshold;
};
/**
* A helper class assembling local matrices into global matrices.
*
* The global matrices are expected as a vector of MatrixBlock
* objects, each containing a matrix object with a function
* corresponding to SparseMatrix::add() and information on the block
* row and column this matrix represents in a block system.
*
* The local matrices are expected as a similar vector of MatrixBlock
* objects, but containing a FullMatrix.
*
* Like with ResidualLocalBlocksToGlobalBlocks, the initialization of
* the BlockInfo object decides whether the comprehensive data model
* or the block model is used.
*
* In the comprehensive model, each of the LocalMatrixBlocks has
* coordinates (0,0) and dimensions equal to the number of degrees of
* freedom of the FESystem.
*
* In the comprehensive model, each block has its own block
* coordinates and the size depends on the associated
* FESystem::base_element(). These blocks can be generated separately
* and will be assembled into the correct matrix block by this object.
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
template <class MATRIX, typename number = double>
class MatrixLocalBlocksToGlobalBlocks
{
public:
/**
* Constructor, initializing
* the #threshold, which
* limits how small numbers
* may be to be entered into
* the matrix.
*/
MatrixLocalBlocksToGlobalBlocks(double threshold = 1.e-12);
/**
* Copy the BlockInfo and the
* matrix pointers into local
* variables and initialize
* cell matrix vectors.
*/
void initialize(const BlockInfo* block_info,
MatrixBlockVector<MATRIX>& matrices);
/**
* Initialize the constraints.
*/
void initialize(const ConstraintMatrix& constraints);
/**
* Initialize the local data
* in the
* DoFInfo
* object used later for
* assembling.
*
* The second parameter is
* used to distinguish
* between the data used on
* cells and boundary faces
* on the one hand and
* interior faces on the
* other. Interior faces may
* require additional data
* being initialized.
*/
template <int dim>
void initialize_info(DoFInfo<dim>& info,
bool interior_face) const;
/**
* Assemble the local matrices
* into the global matrices.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info);
/**
* Assemble all local matrices
* into the global matrices.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2);
private:
/**
* Assemble a single local
* matrix into a global one.
*/
void assemble(
MatrixBlock<MATRIX>& global,
const FullMatrix<number>& local,
unsigned int block_row,
unsigned int block_col,
const std::vector<unsigned int>& dof1,
const std::vector<unsigned int>& dof2);
/**
* The global matrices,
* stored as a vector of
* pointers.
*/
SmartPointer<MatrixBlockVector<MATRIX>,
MatrixLocalBlocksToGlobalBlocks<MATRIX, number> > matrices;
/**
* A pointer to the object containing the block structure.
*/
SmartPointer<const BlockInfo,
MatrixLocalBlocksToGlobalBlocks<MATRIX, number> > block_info;
/**
* A pointer to the object containing constraints.
*/
SmartPointer<const ConstraintMatrix,
MatrixLocalBlocksToGlobalBlocks<MATRIX,number> > constraints;
/**
* The smallest positive
* number that will be
* entered into the global
* matrix. All smaller
* absolute values will be
* treated as zero and will
* not be assembled.
*/
const double threshold;
};
/**
* A helper class assembling local matrices into global multilevel
* matrices. This class is the multilevel equivalent of
* MatrixLocalBlocksToGlobalBlocks and documentation of that class
* applies here to a large extend.
*
* The global matrices are expected as a vector of pointers to MatrixBlock
* objects, each containing a MGLevelObject with matrices with a function
* corresponding to SparseMatrix::add() and information on the block
* row and column this matrix represents in a block system.
*
* The local matrices are a similar vector of MatrixBlock objects, but
* containing a FullMatrix.
*
* If local refinement occurs, the Multigrid method needs more
* matrices, two for continuous elements and another two if numerical
* fluxes are computed on interfaces. The second set can be added
* using initialize_edge_flux(). Once added, the contributions in all
* participating matrices will be assembled from the cell and face
* matrices automatically.
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
template <class MATRIX, typename number = double>
class MGMatrixLocalBlocksToGlobalBlocks
{
public:
/// The object that is stored
typedef boost::shared_ptr<MatrixBlock<MGLevelObject<MATRIX> > > MatrixPtr;
/**
* Constructor, initializing
* the #threshold, which
* limits how small numbers
* may be to be entered into
* the matrix.
*/
MGMatrixLocalBlocksToGlobalBlocks(double threshold = 1.e-12);
/**
* Copy the BlockInfo and the
* matrix pointers into local
* variables and initialize
* cell matrix vectors.
*/
void initialize(const BlockInfo* block_info,
std::vector<MatrixPtr>& matrices);
/**
* Multigrid methods on
* locally refined meshes
* need additional
* matrices. For
* discontinuous Galerkin
* methods, these are two
* flux matrices across the
* refinement edge, which are
* set by this method.
*/
void initialize_edge_flux(std::vector<MatrixPtr>& up, std::vector<MatrixPtr>& down);
/**
* Initialize the local data
* in the
* DoFInfo
* object used later for
* assembling.
*
* The second parameter is
* used to distinguish
* between the data used on
* cells and boundary faces
* on the one hand and
* interior faces on the
* other. Interior faces may
* require additional data
* being initialized.
*/
template <int dim>
void initialize_info(DoFInfo<dim>& info,
bool interior_face) const;
/**
* Assemble the local matrices
* into the global matrices.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info);
/**
* Assemble all local matrices
* into the global matrices.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2);
private:
/**
* Assemble a single local
* matrix into a global one.
*/
void assemble(
MATRIX& global,
const FullMatrix<number>& local,
unsigned int block_row,
unsigned int block_col,
const std::vector<unsigned int>& dof1,
const std::vector<unsigned int>& dof2,
unsigned int level1,
unsigned int level2,
bool transpose = false);
/**
* The level matrices,
* stored as a vector of
* pointers.
*/
std::vector<MatrixPtr> matrices;
/**
* The flux matrix between
* the fine and the coarse
* level at refinement edges.
*/
std::vector<MatrixPtr> flux_down;
/**
* The flux matrix between
* the coarse and the fine
* level at refinement edges.
*/
std::vector<MatrixPtr> flux_up;
/**
* The interface matrix between
* the fine and the coarse
* level at refinement edges.
*/
std::vector<MatrixPtr> interface_down;
/**
* The interface matrix between
* the coarse and the fine
* level at refinement edges.
*/
std::vector<MatrixPtr> interface_up;
/**
* A pointer to the object containing the block structure.
*/
SmartPointer<const BlockInfo, MGMatrixLocalBlocksToGlobalBlocks<MATRIX, number> > block_info;
/**
* The smallest positive
* number that will be
* entered into the global
* matrix. All smaller
* absolute values will be
* treated as zero and will
* not be assembled.
*/
const double threshold;
};
/**
* Assemble a simple matrix and a simple right hand side at once. We
* use a combination of MatrixSimple and ResidualSimple to achieve
* this. Cell and face operators should fill the matrix and vector
* objects in LocalResults and this class will assemble
* them into matrix and vector objects.
*
* @ingroup MeshWorker
* @author Guido Kanschat, 2009
*/
template <class MATRIX, class VECTOR>
class SystemSimple :
private MatrixSimple<MATRIX>,
private ResidualSimple<VECTOR>
{
public:
/**
* Constructor setting the
* threshold value in
* MatrixSimple.
*/
SystemSimple(double threshold = 1.e-12);
/**
* Store the two objects data
* is assembled into.
*/
void initialize(MATRIX& m, VECTOR& rhs);
/**
* Initialize the local data
* in the
* DoFInfo
* object used later for
* assembling.
*
* The second parameter is
* used to distinguish
* between the data used on
* cells and boundary faces
* on the one hand and
* interior faces on the
* other. Interior faces may
* require additional data
* being initialized.
*/
template <int dim>
void initialize_info(DoFInfo<dim>& info, bool) const;
/**
* Assemble the matrix
* DoFInfo::M1[0]
* into the global matrix.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info);
/**
* Assemble both local
* matrices in the info
* objects into the global
* matrix.
*/
template<int dim>
void assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2);
};
//----------------------------------------------------------------------//
template <typename number>
inline void
Functional<number>::initialize(unsigned int n)
{
results.resize(n);
}
template <typename number>
template<int dim>
inline void
Functional<number>::assemble(const DoFInfo<dim>& info)
{
for (unsigned int i=0;i<results.size();++i)
results[i] += info.value(i);
}
template <typename number>
template<int dim>
inline void
Functional<number>::assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2)
{
for (unsigned int i=0;i<results.size();++i)
{
results[i] += info1.value(i);
results[i] += info2.value(i);
}
}
template <typename number>
inline number
Functional<number>::operator() (unsigned int i) const
{
AssertIndexRange(i, results.size());
return results[i];
}
//----------------------------------------------------------------------//
template <typename number>
inline void
CellsAndFaces<number>::initialize(DataVectors& r, bool sep)
{
Assert(r.name(0) == "cells", typename DataVectors::ExcNameMismatch(0, "cells"));
if (sep)
{
Assert(r.name(1) == "faces", typename DataVectors::ExcNameMismatch(1, "faces"));
AssertDimension(r(0)->n_blocks(), r(1)->n_blocks());
}
results = r;
separate_faces = sep;
}
template <typename number>
template <int dim>
inline void
CellsAndFaces<number>::initialize_info(DoFInfo<dim>& info, bool) const
{
info.initialize_numbers(results(0)->n_blocks());
}
template <typename number>
template<int dim>
inline void
CellsAndFaces<number>::assemble(const DoFInfo<dim>& info)
{
for (unsigned int i=0;i<info.n_values();++i)
{
if (separate_faces &&
info.face_number != deal_II_numbers::invalid_unsigned_int)
results(1)->block(i)(info.face->user_index()) += info.value(i);
else
results(0)->block(i)(info.cell->user_index()) += info.value(i);
}
}
template <typename number>
template<int dim>
inline void
CellsAndFaces<number>::assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2)
{
for (unsigned int i=0;i<info1.n_values();++i)
{
if (separate_faces)
{
const double J = info1.value(i) + info2.value(i);
results(1)->block(i)(info1.face->user_index()) += J;
if (info2.face != info1.face)
results(1)->block(i)(info2.face->user_index()) += J;
}
else
{
results(0)->block(i)(info1.cell->user_index()) += .5*info1.value(i);
results(0)->block(i)(info2.cell->user_index()) += .5*info2.value(i);
}
}
}
//----------------------------------------------------------------------//
template <class VECTOR>
inline void
ResidualSimple<VECTOR>::initialize(NamedData<VECTOR*>& results)
{
residuals = results;
}
template <class VECTOR>
inline void
ResidualSimple<VECTOR>::initialize(const ConstraintMatrix& c)
{
constraints = &c;
}
template <class VECTOR>
template<int dim>
inline void
ResidualSimple<VECTOR>::initialize_info(DoFInfo<dim>& info, bool) const
{
info.initialize_vectors(residuals.size());
}
template <class VECTOR>
template<int dim>
inline void
ResidualSimple<VECTOR>::assemble(const DoFInfo<dim>& info)
{
for (unsigned int k=0;k<residuals.size();++k)
{
if(constraints == 0)
{
for (unsigned int i=0;i<info.vector(k).block(0).size();++i)
(*residuals(k))(info.indices[i]) += info.vector(k).block(0)(i);
}
else
constraints->distribute_local_to_global(
info.vector(k).block(0), info.indices, (*residuals(k)));
}
}
template <class VECTOR>
template<int dim>
inline void
ResidualSimple<VECTOR>::assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2)
{
for (unsigned int k=0;k<residuals.size();++k)
{
if(constraints == 0)
{
for (unsigned int i=0;i<info1.vector(k).block(0).size();++i)
(*residuals(k))(info1.indices[i]) += info1.vector(k).block(0)(i);
for (unsigned int i=0;i<info2.vector(k).block(0).size();++i)
(*residuals(k))(info2.indices[i]) += info2.vector(k).block(0)(i);
}
else
{
constraints->distribute_local_to_global(
info1.vector(k).block(0), info1.indices, (*residuals(k)));
constraints->distribute_local_to_global(
info2.vector(k).block(0), info2.indices, (*residuals(k)));
}
}
}
//----------------------------------------------------------------------//
template <class VECTOR>
inline void
ResidualLocalBlocksToGlobalBlocks<VECTOR>::initialize(const BlockInfo* b,
NamedData<VECTOR*>& m)
{
block_info = b;
residuals = m;
}
template <class VECTOR>
inline void
ResidualLocalBlocksToGlobalBlocks<VECTOR>::initialize(
const ConstraintMatrix& c)
{
constraints = &c;
}
template <class VECTOR>
template <int dim>
inline void
ResidualLocalBlocksToGlobalBlocks<VECTOR>::initialize_info(
DoFInfo<dim>& info, bool) const
{
info.initialize_vectors(residuals.size());
}
template <class VECTOR>
inline void
ResidualLocalBlocksToGlobalBlocks<VECTOR>::assemble(
VECTOR& global,
const BlockVector<double>& local,
const std::vector<unsigned int>& dof)
{
if(constraints == 0)
{
for (unsigned int b=0;b<local.n_blocks();++b)
for (unsigned int j=0;j<local.block(b).size();++j)
{
// The coordinates of
// the current entry in
// DoFHandler
// numbering, which
// differs from the
// block-wise local
// numbering we use in
// our local vectors
const unsigned int jcell = this->block_info->local().local_to_global(b, j);
global(dof[jcell]) += local.block(b)(j);
}
}
else
constraints->distribute_local_to_global(local, dof, global);
}
template <class VECTOR>
template <int dim>
inline void
ResidualLocalBlocksToGlobalBlocks<VECTOR>::assemble(
const DoFInfo<dim>& info)
{
for (unsigned int i=0;i<residuals.size();++i)
assemble(*residuals(i), info.vector(i), info.indices);
}
template <class VECTOR>
template <int dim>
inline void
ResidualLocalBlocksToGlobalBlocks<VECTOR>::assemble(
const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2)
{
for (unsigned int i=0;i<residuals.size();++i)
{
assemble(*residuals(i), info1.vector(i), info1.indices);
assemble(*residuals(i), info2.vector(i), info2.indices);
}
}
//----------------------------------------------------------------------//
template <class MATRIX>
inline
MatrixSimple<MATRIX>::MatrixSimple(double threshold)
:
threshold(threshold)
{}
template <class MATRIX>
inline void
MatrixSimple<MATRIX>::initialize(MATRIX& m)
{
matrix = &m;
}
template <class MATRIX>
inline void
MatrixSimple<MATRIX>::initialize(const ConstraintMatrix& c)
{
constraints = &c;
}
template <class MATRIX >
template <int dim>
inline void
MatrixSimple<MATRIX>::initialize_info(DoFInfo<dim>& info,
bool interior_face) const
{
info.initialize_matrices(1, interior_face);
}
template <class MATRIX>
inline void
MatrixSimple<MATRIX>::assemble(const FullMatrix<double>& M,
const std::vector<unsigned int>& i1,
const std::vector<unsigned int>& i2)
{
AssertDimension(M.m(), i1.size());
AssertDimension(M.n(), i2.size());
if(constraints == 0)
{
for (unsigned int j=0; j<i1.size(); ++j)
for (unsigned int k=0; k<i2.size(); ++k)
if (std::fabs(M(j,k)) >= threshold)
matrix->add(i1[j], i2[k], M(j,k));
}
else
constraints->distribute_local_to_global(
M, i1, i2, *matrix);
}
template <class MATRIX>
template <int dim>
inline void
MatrixSimple<MATRIX>::assemble(const DoFInfo<dim>& info)
{
assemble(info.matrix(0,false).matrix, info.indices, info.indices);
}
template <class MATRIX>
template <int dim>
inline void
MatrixSimple<MATRIX>::assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2)
{
assemble(info1.matrix(0,false).matrix, info1.indices, info1.indices);
assemble(info1.matrix(0,true).matrix, info1.indices, info2.indices);
assemble(info2.matrix(0,false).matrix, info2.indices, info2.indices);
assemble(info2.matrix(0,true).matrix, info2.indices, info1.indices);
}
//----------------------------------------------------------------------//
template <class MATRIX>
inline
MGMatrixSimple<MATRIX>::MGMatrixSimple(double threshold)
:
threshold(threshold)
{}
template <class MATRIX>
inline void
MGMatrixSimple<MATRIX>::initialize(MGLevelObject<MATRIX>& m)
{
matrix = &m;
}
template <class MATRIX>
inline void
MGMatrixSimple<MATRIX>::initialize_fluxes(
MGLevelObject<MATRIX>& up, MGLevelObject<MATRIX>& down)
{
flux_up = &up;
flux_down = &down;
}
template <class MATRIX>
inline void
MGMatrixSimple<MATRIX>::initialize_interfaces(
MGLevelObject<MATRIX>& up, MGLevelObject<MATRIX>& down)
{
interface_up = &up;
interface_down = &down;
}
template <class MATRIX >
template <int dim>
inline void
MGMatrixSimple<MATRIX>::initialize_info(DoFInfo<dim>& info,
bool interior_face) const
{
info.initialize_matrices(1, interior_face);
}
template <class MATRIX>
inline void
MGMatrixSimple<MATRIX>::assemble(
MATRIX& G,
const FullMatrix<double>& M,
const std::vector<unsigned int>& i1,
const std::vector<unsigned int>& i2)
{
AssertDimension(M.m(), i1.size());
AssertDimension(M.n(), i2.size());
for (unsigned int j=0; j<i1.size(); ++j)
for (unsigned int k=0; k<i2.size(); ++k)
if (std::fabs(M(j,k)) >= threshold)
G.add(i1[j], i2[k], M(j,k));
}
template <class MATRIX>
inline void
MGMatrixSimple<MATRIX>::assemble_transpose(
MATRIX& G,
const FullMatrix<double>& M,
const std::vector<unsigned int>& i1,
const std::vector<unsigned int>& i2)
{
AssertDimension(M.n(), i1.size());
AssertDimension(M.m(), i2.size());
for (unsigned int j=0; j<i1.size(); ++j)
for (unsigned int k=0; k<i2.size(); ++k)
if (std::fabs(M(k,j)) >= threshold)
G.add(i1[j], i2[k], M(k,j));
}
template <class MATRIX>
template <int dim>
inline void
MGMatrixSimple<MATRIX>::assemble(const DoFInfo<dim>& info)
{
const unsigned int level = info.cell->level();
assemble((*matrix)[level], info.matrix(0,false).matrix, info.indices, info.indices);
}
template <class MATRIX>
template <int dim>
inline void
MGMatrixSimple<MATRIX>::assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2)
{
const unsigned int level1 = info1.cell->level();
const unsigned int level2 = info2.cell->level();
if (level1 == level2)
{
assemble((*matrix)[level1], info1.matrix(0,false).matrix, info1.indices, info1.indices);
assemble((*matrix)[level1], info1.matrix(0,true).matrix, info1.indices, info2.indices);
assemble((*matrix)[level1], info2.matrix(0,false).matrix, info2.indices, info2.indices);
assemble((*matrix)[level1], info2.matrix(0,true).matrix, info2.indices, info1.indices);
}
else
{
Assert(level1 > level2, ExcInternalError());
// Do not add info2.M1,
// which is done by
// the coarser cell
assemble((*matrix)[level1], info1.matrix(0,false).matrix, info1.indices, info1.indices);
assemble_transpose((*flux_up)[level1],info1.matrix(0,true).matrix, info2.indices, info1.indices);
assemble((*flux_down)[level1], info2.matrix(0,true).matrix, info2.indices, info1.indices);
}
}
//----------------------------------------------------------------------//
template <class MATRIX, typename number>
inline
MatrixLocalBlocksToGlobalBlocks<MATRIX, number>::MatrixLocalBlocksToGlobalBlocks(
double threshold)
:
threshold(threshold)
{}
template <class MATRIX, typename number>
inline void
MatrixLocalBlocksToGlobalBlocks<MATRIX, number>::initialize(
const BlockInfo* b,
MatrixBlockVector<MATRIX>& m)
{
block_info = b;
matrices = &m;
}
template <class MATRIX, typename number>
inline void
MatrixLocalBlocksToGlobalBlocks<MATRIX, number>::initialize(
const ConstraintMatrix& c)
{
constraints = &c;
}
template <class MATRIX ,typename number>
template <int dim>
inline void
MatrixLocalBlocksToGlobalBlocks<MATRIX, number>::initialize_info(
DoFInfo<dim>& info,
bool interior_face) const
{
info.initialize_matrices(*matrices, interior_face);
}
template <class MATRIX, typename number>
inline void
MatrixLocalBlocksToGlobalBlocks<MATRIX, number>::assemble(
MatrixBlock<MATRIX>& global,
const FullMatrix<number>& local,
unsigned int block_row,
unsigned int block_col,
const std::vector<unsigned int>& dof1,
const std::vector<unsigned int>& dof2)
{
if(constraints == 0)
{
for (unsigned int j=0;j<local.n_rows();++j)
for (unsigned int k=0;k<local.n_cols();++k)
if (std::fabs(local(j,k)) >= threshold)
{
// The coordinates of
// the current entry in
// DoFHandler
// numbering, which
// differs from the
// block-wise local
// numbering we use in
// our local matrices
const unsigned int jcell = this->block_info->local().local_to_global(block_row, j);
const unsigned int kcell = this->block_info->local().local_to_global(block_col, k);
global.add(dof1[jcell], dof2[kcell], local(j,k));
}
}
else
{
const BlockIndices &bi = this->block_info->local();
std::vector<unsigned int> sliced_row_indices (bi.block_size(block_row));
for(unsigned int i=0; i<sliced_row_indices.size(); ++i)
sliced_row_indices[i] = dof1[bi.block_start(block_row)+i];
std::vector<unsigned int> sliced_col_indices (bi.block_size(block_col));
for(unsigned int i=0; i<sliced_col_indices.size(); ++i)
sliced_col_indices[i] = dof2[bi.block_start(block_col)+i];
constraints->distribute_local_to_global(local,
sliced_row_indices, sliced_col_indices, global);
}
}
template <class MATRIX, typename number>
template <int dim>
inline void
MatrixLocalBlocksToGlobalBlocks<MATRIX, number>::assemble(
const DoFInfo<dim>& info)
{
for (unsigned int i=0;i<matrices->size();++i)
{
// Row and column index of
// the block we are dealing with
const unsigned int row = matrices->block(i).row;
const unsigned int col = matrices->block(i).column;
assemble(matrices->block(i), info.matrix(i,false).matrix, row, col, info.indices, info.indices);
}
}
template <class MATRIX, typename number>
template <int dim>
inline void
MatrixLocalBlocksToGlobalBlocks<MATRIX, number>::assemble(
const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2)
{
for (unsigned int i=0;i<matrices->size();++i)
{
// Row and column index of
// the block we are dealing with
const unsigned int row = matrices->block(i).row;
const unsigned int col = matrices->block(i).column;
assemble(matrices->block(i), info1.matrix(i,false).matrix, row, col, info1.indices, info1.indices);
assemble(matrices->block(i), info1.matrix(i,true).matrix, row, col, info1.indices, info2.indices);
assemble(matrices->block(i), info2.matrix(i,false).matrix, row, col, info2.indices, info2.indices);
assemble(matrices->block(i), info2.matrix(i,true).matrix, row, col, info2.indices, info1.indices);
}
}
// ----------------------------------------------------------------------//
template <class MATRIX, typename number>
inline
MGMatrixLocalBlocksToGlobalBlocks<MATRIX, number>::MGMatrixLocalBlocksToGlobalBlocks(
double threshold)
:
threshold(threshold)
{}
template <class MATRIX, typename number>
inline void
MGMatrixLocalBlocksToGlobalBlocks<MATRIX, number>::initialize(const BlockInfo* b,
std::vector<MatrixPtr>& m)
{
block_info = b;
matrices = m;
}
template <class MATRIX ,typename number>
template <int dim>
inline void
MGMatrixLocalBlocksToGlobalBlocks<MATRIX, number>::initialize_info(
DoFInfo<dim>& info,
bool interior_face) const
{
info.initialize_matrices(matrices, interior_face);
}
template <class MATRIX, typename number>
inline void
MGMatrixLocalBlocksToGlobalBlocks<MATRIX, number>::initialize_edge_flux(
std::vector<MatrixPtr>& up,
std::vector<MatrixPtr>& down)
{
flux_up = up;
flux_down = down;
}
template <class MATRIX, typename number>
inline void
MGMatrixLocalBlocksToGlobalBlocks<MATRIX, number>::assemble(
MATRIX& global,
const FullMatrix<number>& local,
unsigned int block_row,
unsigned int block_col,
const std::vector<unsigned int>& dof1,
const std::vector<unsigned int>& dof2,
unsigned int level1,
unsigned int level2,
bool transpose)
{
for (unsigned int j=0;j<local.n_rows();++j)
for (unsigned int k=0;k<local.n_cols();++k)
if (std::fabs(local(j,k)) >= threshold)
{
// The coordinates of
// the current entry in
// DoFHandler
// numbering, which
// differs from the
// block-wise local
// numbering we use in
// our local matrices
const unsigned int jcell = this->block_info->local().local_to_global(block_row, j);
const unsigned int kcell = this->block_info->local().local_to_global(block_col, k);
// The global dof
// indices to assemble
// in. Since we may
// have face matrices
// coupling two
// different cells, we
// provide two sets of
// dof indices.
const unsigned int jglobal = this->block_info->level(level1).global_to_local(dof1[jcell]).second;
const unsigned int kglobal = this->block_info->level(level2).global_to_local(dof2[kcell]).second;
if (transpose)
global.add(kglobal, jglobal, local(j,k));
else
global.add(jglobal, kglobal, local(j,k));
}
}
template <class MATRIX, typename number>
template <int dim>
inline void
MGMatrixLocalBlocksToGlobalBlocks<MATRIX, number>::assemble(
const DoFInfo<dim>& info)
{
const unsigned int level = info.cell->level();
for (unsigned int i=0;i<matrices.size();++i)
{
// Row and column index of
// the block we are dealing with
const unsigned int row = matrices[i]->row;
const unsigned int col = matrices[i]->column;
assemble(matrices[i]->matrix[level], info.matrix(i,false).matrix, row, col,
info.indices, info.indices, level, level);
}
}
template <class MATRIX, typename number>
template <int dim>
inline void
MGMatrixLocalBlocksToGlobalBlocks<MATRIX, number>::assemble(
const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2)
{
const unsigned int level1 = info1.cell->level();
const unsigned int level2 = info2.cell->level();
for (unsigned int i=0;i<matrices.size();++i)
{
// Row and column index of
// the block we are dealing with
const unsigned int row = matrices[i]->row;
const unsigned int col = matrices[i]->column;
if (level1 == level2)
{
assemble(matrices[i]->matrix[level1], info1.matrix(i,false).matrix, row, col, info1.indices, info1.indices, level1, level1);
assemble(matrices[i]->matrix[level1], info1.matrix(i,true).matrix, row, col, info1.indices, info2.indices, level1, level2);
assemble(matrices[i]->matrix[level1], info2.matrix(i,false).matrix, row, col, info2.indices, info2.indices, level2, level2);
assemble(matrices[i]->matrix[level1], info2.matrix(i,true).matrix, row, col, info2.indices, info1.indices, level2, level1);
}
else
{
Assert(level1 > level2, ExcNotImplemented());
if (flux_up.size() != 0)
{
// Do not add M22,
// which is done by
// the coarser cell
assemble(matrices[i]->matrix[level1], info1.matrix(i,false).matrix, row, col,
info1.indices, info1.indices, level1, level1);
assemble(flux_up[i]->matrix[level1], info1.matrix(i,true).matrix, row, col,
info1.indices, info2.indices, level1, level2, true);
assemble(flux_down[i]->matrix[level1], info2.matrix(i,true).matrix, row, col,
info2.indices, info1.indices, level2, level1);
}
}
}
}
//----------------------------------------------------------------------//
template <class MATRIX, class VECTOR>
SystemSimple<MATRIX,VECTOR>::SystemSimple(double t)
:
MatrixSimple<MATRIX>(t)
{}
template <class MATRIX, class VECTOR>
inline void
SystemSimple<MATRIX,VECTOR>::initialize(MATRIX& m, VECTOR& rhs)
{
NamedData<VECTOR*> data;
VECTOR* p = &rhs;
data.add(p, "right hand side");
MatrixSimple<MATRIX>::initialize(m);
ResidualSimple<VECTOR>::initialize(data);
}
template <class MATRIX, class VECTOR>
template <int dim>
inline void
SystemSimple<MATRIX,VECTOR>::initialize_info(DoFInfo<dim>& info,
bool interior_face) const
{
MatrixSimple<MATRIX>::initialize_info(info, interior_face);
ResidualSimple<VECTOR>::initialize_info(info, interior_face);
}
template <class MATRIX, class VECTOR>
template<int dim>
inline void
SystemSimple<MATRIX,VECTOR>::assemble(const DoFInfo<dim>& info)
{
MatrixSimple<MATRIX>::assemble(info);
ResidualSimple<VECTOR>::assemble(info);
}
template <class MATRIX, class VECTOR>
template<int dim>
inline void
SystemSimple<MATRIX,VECTOR>::assemble(const DoFInfo<dim>& info1,
const DoFInfo<dim>& info2)
{
MatrixSimple<MATRIX>::assemble(info1, info2);
ResidualSimple<VECTOR>::assemble(info1, info2);
}
}
}
DEAL_II_NAMESPACE_CLOSE
#endif
|