/usr/include/alberta/alberta_inlines.h is in libalberta-dev 3.0.1-1+b2.
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 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 | #ifndef _ALBERT_INLINES_H_
#define _ALBERT_INLINES_H_
/*--------------------------------------------------------------------------*/
/* ALBERT: an Adaptive multi Level finite element toolbox using */
/* Bisectioning refinement and Error control by Residual */
/* Techniques */
/* */
/* www.alberta-fem.de */
/* */
/*--------------------------------------------------------------------------*/
/* */
/* file: albert_inlines.h */
/* */
/* */
/* description: Blas-like inline functions for REAL_Ds and REAL_DDs, */
/* REAL_Bs & friends. */
/* */
/*--------------------------------------------------------------------------*/
/* */
/* authors: Alfred Schmidt */
/* Zentrum fuer Technomathematik */
/* Fachbereich 3 Mathematik/Informatik */
/* Universitaet Bremen */
/* Bibliothekstr. 2 */
/* D-28359 Bremen, Germany */
/* */
/* Kunibert G. Siebert */
/* Istitut fuer Mathematik */
/* Universitaet Augsburg */
/* Universitaetsstr. 14 */
/* D-86159 Augsburg, Germany */
/* */
/* Claus-Justus Heine */
/* Abteilung fuer Angewandte Mathematik */
/* Albert-Ludwigs-Universitaet Freiburg */
/* Hermann-Herder-Str. 10 */
/* D-79104 Freiburg im Breisgau, Germany */
/* */
/* */
/* (c) by A. Schmidt, K.G. Siebert, C.-J. Heine (1996-2007) */
/* */
/*--------------------------------------------------------------------------*/
#include "alberta.h" /* essentially a no-op when included from alberta.h */
#ifndef DIM_OF_WORLD
# error Need to know the dimension of the World :)
#endif
/* multiple invocations of macro-arguments can be harmful, if the macro
* argument is, e.g., a function-call.
*
* NOTE: as DIM_OF_WORLD is a constant, the C-compiler should unroll all
* loops when compiling with optimizations, so there should be no need
* for hand-unrolling, except in some simple 1D cases.
*
* Also, all modern compilers do function inlining, so the
* function-call over-head is _not_ a problem.
*
* Note: the function may be nested, they return the address of the
* _modified_ operand. So AXPY(a, AX(b, x), y) is valid.
*/
/* In addition to BLAS-like routines for REAL_D vectors and REAL_DD
* matrices this file also defines the access to the per-element
* quadrature and geometry caches:
*
* fill_el_geom_cache()
* fill_quad_el_cache()
*/
/* The following functions are defined here:
*
* AX(a, x) -- x *= a (alias SCAL_DOW is also defined)
* AXEY(a, x, y) -- y = a x
* AXPBY(a, x, b, y, z) -- z = a x + by
* AXPBYPCZ(a, x, b, y, c, z, w) -- w = a x + by + cz
* AXPBYP(a, x, b, y, z) -- z += a x + by
* AXPY(a, x, y) -- y += a x
* COPY(src, dst) -- dst := src
* DIST(x, y) -- sqrt(DST2(x, y))
* DST2(x, y) -- SCP(x-y, x-y)
* NRM2(x) -- SCP(x, x)
* NORM(x) -- sqrt(NRM2(x))
* NORM1(x) -- fabs(x[0]) + ... + fabs(x[DOW-1])
* DIST1(x, y) -- NORM1(x-y)
* PNORMP(x, p) -- (pow(fabs(x[0]), p) + ... + pow(fabs(x[0]), p))
* NORMP(x, p) -- pow(PNORMP(x), 1.0/p)
* NORM8(x) -- max{fabs(x[0]), ..., fabs(x[DOW-1])} (8==infty)
* DIST8(x, y) -- NORM8(x-y)
* SUM(x) -- x[0] + ... + x[DOW-1]
* MTV(m, v, b) -- b += m^t v
* MV(m, v, b) -- b += m v (m is a matrix)
* MDIV(m, v, b) -- scale v by the inverse of the diagonal -> b
* SCP(x, y) -- <x, y>
* SET(val, x) -- x[i] = val, i=1, ..., DOW
* WEDGE(x, y, n) -- n = x /\ y in 3D
* WEDGE(x, y) -- x0 * y1 - x1 * y0 in 2D
*
* The actual function named is generated by adding a _DOW() suffix.
*
* Prefix Version
* none REAL_D
* M REAL_DD
* DM diagonal matrix, diagonal stored in REAL_D vector
* SCM scalar matrix, data type REAL (albert.h)
*
* Further:
* Macros EXPAND and FORMAT (with named pre- and suffixes) for easier
* print-out of REAL_D and REAL_DD, use like this:
*
* printf("text"MFORMAT_DOW"more text\n", MEXPAND_DOW(m));
*
* Some more functions for barycentric coordinates. NOTE: works best
* with constant dim. Use with care w.r.t. to optimization.
*
* SET_BAR(dim, a, x)
* SCAL_BAR(dim, a, x)
* SCP_BAR(dim, x, y)
* AXPY_BAR(dim, a, x, y)
* AXPBY_BAR(dim, a, x, b, y, z)
* COPY_BAR(dim, from, to)
* GRAD_DOW(dim, Lambda, b_grd, x_grd) -- conversion from barycentric
* to cartesian gradients. The function computes x_grd = b_grd Lambda.
*
* Some of these functions are also available as matrix versions
* (e.g. MAXPY_BAR()).
*
* Further: to add matrices of higher symmetry to those of lower
* symmetry the following functions exist. The first prefix is alway
* the type of the destination matrix. Only the well defined functions
* are implemented. Grin. (Hint: the limiting factor is the structure
* of the destination matrix ...)
*
* {M,DM,SCM}{M,DM,SCM}AXPY_DOW(alpha, a, b) b += alpha*a
* {M,DM,SCM}{M,DM,SCM}AXEY_DOW(alpha, a, b) b = alpha*a
* {M,DM,SCM}{M,DM,SCM}COPY_DOW(a, b) b = a
*
* Some more: DOW x DOW matrix multiplication etc.:
*
* MM_DOW(), MMT_DOW(), MTM_DOW(), MDET_DOW(), MINVERT_DOW()
*
*/
static inline REAL POW_DOW(REAL a)
{
#if DIM_OF_WORLD == 0
return 1.0;
#elif DIM_OF_WORLD == 1
return a;
#elif DIM_OF_WORLD == 2
return a*a;
#elif DIM_OF_WORLD == 3
return a*a*a;
#else
int i;
REAL res = a;
for (i = 1; i < DIM_OF_WORLD; i++) {
res *= a;
}
return res;
#endif
}
#define SCAL_DOW(a, x) AX_DOW(a, x)
static inline REAL *AX_DOW(REAL a, REAL_D x)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
x[i] *= a;
}
return x;
}
#define MSCAL_DOW(a, m) MAX_DOW(a, m)
static inline REAL_D *MAX_DOW(REAL a, REAL_DD m)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
AX_DOW(a, m[i]);
}
return m;
}
#define DMAX_DOW(a, m) AX_DOW(a, m)
#define DMSCAL_DOW(a, m) DMAX_DOW(a, m)
#define SCMAX_DOW(a, m) (m) *= (a)
#define SCMSCAL_DOW(a, m) SCMAX_DOW(a, m)
static inline REAL *AXEY_DOW(REAL a, const REAL_D x, REAL_D y)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
y[i] = a * x[i];
}
return y;
}
static inline REAL_D *MAXEY_DOW(REAL a, const REAL_DD x, REAL_DD y)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
AXEY_DOW(a, x[i], y[i]);
}
return y;
}
#define DMAXEY_DOW(a, x, y) AXEY_DOW(a, x, y)
#define SCMAXEY_DOW(a, x, y) (y) = (a)*(x)
static inline REAL *AXPY_DOW(REAL a, const REAL_D x, REAL_D y)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
y[i] += a * x[i];
}
return y;
}
static inline REAL_D *MAXPY_DOW(REAL a, const REAL_DD x, REAL_DD y)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
AXPY_DOW(a, x[i], y[i]);
}
return y;
}
/* same as above, but add the transposed matrix to y */
static inline REAL_D *MAXTPY_DOW(REAL a, const REAL_DD x, REAL_DD y)
{
REAL tmp;
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
y[i][i] += a*x[i][i];
for (j = i+1; j < DIM_OF_WORLD; j++) {
tmp = x[i][j];
y[i][j] += a*x[j][i];
y[j][i] += a*tmp;
}
}
return y;
}
#define DMAXPY_DOW(a, x, y) AXPY_DOW(a, x, y)
#define DMAXTPY_DOW(a, x, y) DMAXPY_DOW(a, x, y) /* transpose of diagonal matrix :) */
#define SCMAXPY_DOW(a, x, y) (y) += (a)*(x)
#define SCMAXTPY_DOW(a, x, y) SCMAXPY_DOW(a, x, y)
static inline REAL *AXPBY_DOW(REAL a, const REAL_D x, REAL b, const REAL_D y,
REAL_D z)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
z[i] = b*y[i] + a * x[i];
}
return z;
}
static inline REAL_D *MAXPBY_DOW(REAL a, const REAL_DD x,
REAL b, const REAL_DD y,
REAL_DD z)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
AXPBY_DOW(a, x[i], b, y[i], z[i]);
}
return z;
}
#define DMAXPBY_DOW(a, x, b, y, z) AXPBY_DOW(a, x, b, y, z)
#define SCMAXPBY_DOW(a, x, b, y, z) (z) = (a)*(x) + (b)*(y)
static inline REAL *AXPBYPCZ_DOW(REAL a, const REAL_D x,
REAL b, const REAL_D y,
REAL c, const REAL_D z,
REAL_D w)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
w[i] = c*z[i] + b*y[i] + a * x[i];
}
return w;
}
static inline REAL_D *MAXPBYPCZ_DOW(REAL a, const REAL_DD x,
REAL b, const REAL_DD y,
REAL c, const REAL_DD z,
REAL_DD w)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
AXPBYPCZ_DOW(a, x[i], b, y[i], c, z[i], w[i]);
}
return w;
}
#define DMAXPBYPCZ_DOW(a, x, b, y, c, z, w) AXPBYPCZ_DOW(a, x, b, y, c, z, w)
#define SCMAXPBYPCZ_DOW(a, x, b, y, c, z, w) ((w) = (a)*(x) + (b)*(y) + (c)*(z))
static inline REAL *AXPBYP_DOW(REAL a, const REAL_D x, REAL b, const REAL_D y,
REAL_D z)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
z[i] += b*y[i] + a * x[i];
}
return z;
}
static inline REAL_D *MAXPBYP_DOW(REAL a, const REAL_DD x,
REAL b, const REAL_DD y,
REAL_DD z)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
AXPBYP_DOW(a, x[i], b, y[i], z[i]);
}
return z;
}
#define DMAXPBYP_DOW(a, x, b, y, z) AXPBYP_DOW(a, x, b, y, z)
#define SCMAXPBYP_DOW(a, x, b, y, z) ((z) += (a)*(x) + (b)*(y))
static inline REAL *AXPBYPCZP_DOW(REAL a, const REAL_D x,
REAL b, const REAL_D y,
REAL c, const REAL_D z,
REAL_D w)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
w[i] += c*z[i] + b*y[i] + a*x[i];
}
return w;
}
static inline REAL_D *MAXPBYPCZP_DOW(REAL a, const REAL_DD x,
REAL b, const REAL_DD y,
REAL c, const REAL_DD z,
REAL_DD w)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
AXPBYPCZP_DOW(a, x[i], b, y[i], c, z[i], w[i]);
}
return w;
}
#define DMAXPBYPCZP_DOW(a, x, b, y, z) \
AXPBYPCZP_DOW(a, x, b, y, z)
#define SCMAXPBYPCZP_DOW(a, x, b, y, c, z, w) \
((w) += (a)*(x) + (b)*(y) + (c)*(z))
/***********************/
/* Matrix - Matrix addition */
#define MMAXPY_DOW(s, a, b) MAXPY_DOW(s, a, b)
#define DMDMAXPY_DOW(s, a, b) DMAXPY_DOW(s, a, b)
#define SCMSCMAXPY_DOW(s, a, b) SCMAXPY_DOW(s, a, b)
/* Transpose addition, only different for the MM case */
#define MMAXTPY_DOW(s, a, b) MAXTPY_DOW(s, a, b)
#define MDMAXTPY_DOW(s, a, b) MDMAXPY_DOW(s, a, b)
#define MSCMAXTPY_DOW(s, a, b) MSCMAXPY_DOW(s, a, b)
#define DMDMAXTPY_DOW(s, a, b) DMAXPY_DOW(s, a, b)
#define DMSCMAXTPY_DOW(s, a, b) DMSCMAXPY_DOW(s, a, b)
#define SCMSCMAXTPY_DOW(s, a, b) SCMAXPY_DOW(s, a, b)
static inline REAL_D *MDMAXPY_DOW(REAL a, const REAL_D x, REAL_DD y)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
y[i][i] += a * x[i];
}
return y;
}
static inline REAL_D *MSCMAXPY_DOW(REAL a, const REAL x, REAL_DD y)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
y[i][i] += a * x;
}
return y;
}
static inline REAL *DMSCMAXPY_DOW(REAL a, REAL x, REAL *y)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
y[i] += a*x;
}
return y;
}
/* Matrix - Matrix initialization */
#define MMAXEY_DOW(s, a, b) MAXEY_DOW(s, a, b)
#define DMDMAXEY_DOW(s, a, b) DMAXEY_DOW(s, a, b)
#define SCMSCMAXEY_DOW(s, a, b) SCMAXEY_DOW(s, a, b)
static inline REAL_D *MDMAXEY_DOW(REAL a, const REAL_D x, REAL_DD y)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
y[i][i] = a * x[i];
for (j = i+1; j < DIM_OF_WORLD; j++) {
y[i][j] = y[j][i] = 0.0;
}
}
return y;
}
static inline REAL_D *MSCMAXEY_DOW(REAL a, const REAL x, REAL_DD y)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
y[i][i] = a * x;
for (j = i+1; j < DIM_OF_WORLD; j++) {
y[i][j] = y[j][i] = 0.0;
}
}
return y;
}
static inline REAL *DMSCMAXEY_DOW(REAL a, REAL x, REAL *y)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
y[i] = a*x;
}
return y;
}
/* Matrix - Matrix initialization */
#define MMMAXPBY_DOW(a, x, b, y, z) MAXPBY_DOW(a, x, b, y, z)
#define DMDMDMAXPBY_DOW(a, x, b, y, z) DMAXPBY_DOW(a, x, b, y, z)
#define SCMSCMSCMAXPBY_DOW(a, x, b, y, z) SCMAXPBY_DOW(a, x, b, y, z)
static inline REAL_D *MMDMAXPBY_DOW(REAL a, const REAL_DD x,
REAL b, const REAL_D y,
REAL_DD z)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
z[i][i] = a * x[i][i] + b * y[i];
for (j = i+1; j < DIM_OF_WORLD; j++) {
z[i][j] = a * x[i][j];
z[j][i] = a * x[j][i];
}
}
return z;
}
static inline REAL_D *MMSCMAXPBY_DOW(REAL a, const REAL_DD x,
REAL b, const REAL y,
REAL_DD z)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
z[i][i] = a * x[i][i] + b * y;
for (j = i+1; j < DIM_OF_WORLD; j++) {
z[i][j] = a * x[i][j];
z[j][i] = a * x[j][i];
}
}
return z;
}
static inline REAL_D *MDMDMAXPBY_DOW(REAL a, const REAL_D x,
REAL b, const REAL_D y,
REAL_DD z)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
z[i][i] = a * x[i] + b * y[i];
for (j = i+1; j < DIM_OF_WORLD; j++) {
z[i][j] = z[j][i] = 0.0;
}
}
return z;
}
static inline REAL_D *MDMSCMAXPBY_DOW(REAL a, REAL *x,
REAL b, REAL y,
REAL_DD z)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
z[i][i] = a * x[i] + b * y;
for (j = i+1; j < DIM_OF_WORLD; j++) {
z[i][j] = z[j][i] = 0.0;
}
}
return z;
}
static inline REAL_D *MSCMSCMAXPBY_DOW(REAL a, REAL x,
REAL b, REAL y,
REAL_DD z)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
z[i][i] = a * x + b * y;
for (j = i+1; j < DIM_OF_WORLD; j++) {
z[i][j] = z[j][i] = 0.0;
}
}
return z;
}
static inline REAL *DMDMSCMAXPBY_DOW(REAL a, const REAL_D x,
REAL b, const REAL y,
REAL_D z)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
z[i] = a * x[i] + b * y;
}
return z;
}
static inline REAL *DMSCMSCMAXPBY_DOW(REAL a, const REAL x,
REAL b, const REAL y,
REAL_D z)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
z[i] = a * x + b * y;
}
return z;
}
/* Matrix - Matrix copy */
#define MMCOPY_DOW(a, b) MCOPY_DOW(a, b)
#define MDMCOPY_DOW(a, b) MDMAXEY_DOW(1.0, a, b)
#define MSCMCOPY_DOW(a, b) MSCMAXEY_DOW(1.0, a, b)
#define DMDMCOPY_DOW(a, b) DMCOPY_DOW(a, b)
#define DMSCMCOPY_DOW(a, b) DMSCMAXEY_DOW(1.0, a, b)
#define SCMSCMCOPY_DOW(a, b) (b) = (a)
/***********************/
static inline REAL *COPY_DOW(const REAL_D x, REAL_D y)
{
memcpy(y, x, sizeof(REAL_D));
return y;
}
static inline REAL_D *MCOPY_DOW(const REAL_DD x, REAL_DD y)
{
memcpy(y, x, sizeof(REAL_DD));
return y;
}
#define DMCOPY_DOW(src, dst) COPY_DOW(src, dst)
static inline REAL DST2_DOW(const REAL_D x, const REAL_D y)
{
# if DIM_OF_WORLD == 1
return SQR(ABS(x[0] - y[0]));
# else
int i;
REAL accu;
accu = SQR(x[0] - y[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
accu += SQR(x[i] - y[i]);
}
return accu;
# endif
}
static inline REAL MDST2_DOW(const REAL_DD a, const REAL_DD b)
{
int i;
REAL res;
res = DST2_DOW(a[0], b[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
res += DST2_DOW(a[i], b[i]);
}
return res;
}
#define DMDST2_DOW(x, y) DST2_DOW(x, y)
static inline REAL NRM2_DOW(const REAL_D x)
{
int i;
REAL accu;
accu = SQR(x[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
accu += SQR(x[i]);
}
return accu;
}
static inline REAL MNRM2_DOW(const REAL_DD m)
{
int i;
REAL res;
res = NRM2_DOW(m[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
res += NRM2_DOW(m[i]);
}
return res;
}
#define DMNRM2_DOW(m) NRM2_DOW(x)
static inline REAL NORM1_DOW(const REAL_D x)
{
int i;
REAL sum;
sum = fabs(x[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
sum += fabs(x[i]);
}
return sum;
}
static inline REAL DIST1_DOW(const REAL_D x, const REAL_D y)
{
int i;
REAL sum;
sum = fabs(x[0]-y[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
sum += fabs(x[i]-y[i]);
}
return sum;
}
static inline REAL NORM8_DOW(const REAL_D x)
{
int i;
REAL max;
max = fabs(x[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
max = MAX(max, fabs(x[i]));
}
return max;
}
static inline REAL DIST8_DOW(const REAL_D x, const REAL_D y)
{
int i;
REAL max;
max = fabs(x[0]-y[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
max = MAX(max, fabs(x[i]-y[i]));
}
return max;
}
static inline REAL SUM_DOW(const REAL_D x)
{
int i;
REAL sum;
sum = x[0];
for (i = 1; i < DIM_OF_WORLD; i++) {
sum += x[i];
}
return sum;
}
static inline REAL PNRMP_DOW(const REAL_D x, REAL p)
{
int i;
REAL sum;
sum = pow(fabs(x[0]), p);
for (i = 1; i < DIM_OF_WORLD; i++) {
sum += pow(fabs(x[i]), p);
}
return sum;
}
static inline REAL NRMP_DOW(const REAL_D x, REAL p)
{
return pow(PNRMP_DOW(x, p), 1.0/p);
}
static inline REAL MNORM1_DOW(const REAL_DD x)
{
int i;
REAL sum;
sum = NORM1_DOW(x[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
sum += NORM1_DOW(x[0]);
}
return sum;
}
static inline REAL MDIST1_DOW(const REAL_DD x, const REAL_DD y)
{
int i;
REAL sum;
sum = DIST1_DOW(x[0], y[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
sum += DIST1_DOW(x[i], y[i]);
}
return sum;
}
static inline REAL MNORM8_DOW(const REAL_DD x)
{
int i;
REAL max;
max = NORM8_DOW(x[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
max = MAX(max, NORM8_DOW(x[i]));
}
return max;
}
static inline REAL MDIST8_DOW(const REAL_DD x, const REAL_DD y)
{
int i;
REAL max;
max = DIST8_DOW(x[0], y[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
max = MAX(max, DIST8_DOW(x[i], y[i]));
}
return max;
}
static inline REAL MSUM_DOW(const REAL_DD x)
{
int i;
REAL sum;
sum = SUM_DOW(x[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
sum += SUM_DOW(x[0]);
}
return sum;
}
static inline REAL MPNRMP_DOW(const REAL_DD x, REAL p)
{
int i;
REAL sum;
sum = PNRMP_DOW(x[0], p);
for (i = 1; i < DIM_OF_WORLD; i++) {
sum += PNRMP_DOW(x[i], p);
}
return sum;
}
static inline REAL MNRMP_DOW(const REAL_DD x, REAL p)
{
return pow(MPNRMP_DOW(x, p), 1.0/p);
}
static inline REAL SCP_DOW(const REAL_D x, const REAL_D y)
{
REAL res;
int i;
res = x[0] * y[0];
for (i = 1; i < DIM_OF_WORLD; i++) {
res += x[i]*y[i];
}
return res;
}
static inline REAL GRAMSCP_DOW(const REAL_DD M, const REAL_D x, const REAL_D y)
{
REAL res = 0.0;
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
for (j = 0; j < DIM_OF_WORLD; j++) {
res += x[i] * M[i][j] * y[j];
}
}
return res;
}
#define MGRAMSCP_DOW(M, x, y) GRAMSCP_DOW(M, x, y)
static inline REAL DMGRAMSCP_DOW(const REAL_D M, const REAL_D x, const REAL_D y)
{
REAL res = 0.0;
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
res += x[i] * M[i] * y[i];
}
return res;
}
static inline REAL SCMGRAMSCP_DOW(REAL s, const REAL_D x, const REAL_D y)
{
return s*SCP_DOW(x, y);
}
static inline REAL *MTV_DOW(const REAL_DD m, const REAL_D v, REAL_D b)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
for (j = 0; j < DIM_OF_WORLD; j++) {
b[i] += m[j][i] * v[j];
}
}
return b;
}
#define SCMV_DOW(m, v, b) AXPY_DOW(m, v, b)
#define DMTV_DOW(m, v, b) DMV_DOW(m, v, b)
#define SCMTV_DOW(m, v, b) SCMV_DOW(m, v, b)
static inline REAL *MDIV_DOW(const REAL_DD m, const REAL_D v, REAL_D b)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
b[i] = v[i] / m[i][i];
}
return b;
}
static inline REAL *DMDIV_DOW(const REAL_D m, const REAL_D y, REAL_D r)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
r[i] = y[i] / m[i];
}
return r;
}
#define SCMDIV_DOW(m, y, r) AXEY_DOW(1.0/(m), y, r)
static inline REAL *DMV_DOW(const REAL_D x, const REAL_D y, REAL_D r)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
r[i] += x[i]*y[i];
}
return r;
}
static inline REAL *MV_DOW(const REAL_DD m, const REAL_D v, REAL_D b)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
b[i] += SCP_DOW(m[i], v);
}
return b;
}
static inline REAL *MVEQ_DOW(const REAL_DD m, const REAL_D v, REAL_D b)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
b[i] = SCP_DOW(m[i], v);
}
return b;
}
static inline REAL *MTVEQ_DOW(const REAL_DD m, const REAL_D v, REAL_D b)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
b[i] = 0.0;
for (j = 0; j < DIM_OF_WORLD; j++) {
b[i] += m[j][i] * v[j];
}
}
return b;
}
static inline REAL *DMVEQ_DOW(const REAL_D x, const REAL_D y, REAL_D r)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
r[i] = x[i]*y[i];
}
return r;
}
#define SCMVEQ_DOW(m, v, b) AXEY_DOW(m, v, b)
static inline REAL *
MMBIMV_DOW(REAL a, const REAL_DD A, REAL b, const REAL_DD B, const REAL_D v,
REAL c, REAL_D w)
{
int i, j;
REAL sum;
for (i = 0; i < DIM_OF_WORLD; i++) {
sum = 0.0;
for (j = 0; j < DIM_OF_WORLD; j++) {
sum += (a * A[i][j] + b * B[i][j]) * v[j];
}
w[i] = c*w[i] + sum;
}
return w;
}
static inline REAL *
MDMBIMV_DOW(REAL a, const REAL_DD A, REAL b, const REAL_D B, const REAL_D v,
REAL c, REAL_D w)
{
int i, j;
REAL sum;
for (i = 0; i < DIM_OF_WORLD; i++) {
sum = 0.0;
for (j = 0; j < DIM_OF_WORLD; j++) {
sum += a * A[i][j] * v[j];
}
w[i] = c*w[i] + sum + b * B[i] * v[i];
}
return w;
}
static inline REAL *
DMMBIMV_DOW(REAL a, const REAL_D A, REAL b, const REAL_DD B, const REAL_D v,
REAL c, REAL_D w)
{
return MDMBIMV_DOW(b, B, a, A, v, c, w);
}
static inline REAL *
MSCMBIMV_DOW(REAL a, const REAL_DD A, REAL b, REAL B, const REAL_D v,
REAL c, REAL_D w)
{
int i, j;
REAL sum;
for (i = 0; i < DIM_OF_WORLD; i++) {
sum = 0.0;
for (j = 0; j < DIM_OF_WORLD; j++) {
sum += a * A[i][j] * v[j];
}
w[i] = c*w[i] + sum + b * B * v[i];
}
return w;
}
static inline REAL *
SCMMBIMV_DOW(REAL a, REAL A, REAL b, const REAL_DD B, const REAL_D v,
REAL c, REAL_D w)
{
return MSCMBIMV_DOW(b, B, a, A, v, c, w);
}
static inline REAL *
DMDMBIMV_DOW(REAL a, const REAL_D A, REAL b, const REAL_D B, const REAL_D v,
REAL c, REAL_D w)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
w[i] = c*w[i] + (a * A[i] + b * B[i]) * v[i];
}
return w;
}
static inline REAL *
DMSCMBIMV_DOW(REAL a, const REAL_D A, REAL b, REAL B, const REAL_D v,
REAL c, REAL_D w)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
w[i] = c*w[i] + (a * A[i] + b * B) * v[i];
}
return w;
}
static inline REAL *
SCMDMBIMV_DOW(REAL a, REAL A, REAL b, const REAL_D B, const REAL_D v,
REAL c, REAL_D w)
{
return DMSCMBIMV_DOW(b, B, a, A, v, c, w);
}
static inline REAL *
SCMSCMBIMV_DOW(REAL a, REAL A, REAL b, REAL B, const REAL_D v,
REAL c, REAL_D w)
{
return AXPBY_DOW(a*A + b*B, v, c, w, w);
}
static inline REAL *MGEMV_DOW(REAL a, const REAL_DD m,
const REAL_D v, REAL beta,
REAL_D b)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
b[i] = beta*b[i] + a * SCP_DOW(m[i], v);
}
return b;
}
/* Same as above, but without diagonal. */
static inline REAL *MGEMV_ND_DOW(REAL a, const REAL_DD m,
const REAL_D v, REAL beta,
REAL_D b)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
REAL tmp = 0.0;
for (j = 0; j < DIM_OF_WORLD; j++) {
if (i == j) {
continue;
}
tmp += m[i][j] * v[j];
}
b[i] = beta*b[i] + a * tmp;
}
return b;
}
#define GEMV_DOW(a, m, v, beta, b) MGEMV_DOW(a, m, v, beta, b)
#define GEMV_ND_DOW(a, m, v, beta, b) MGEMV_ND_DOW(a, m, v, beta, b)
static inline REAL *DMGEMV_DOW(REAL a, const REAL_D x, const REAL_D y,
REAL beta, REAL_D r)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
r[i] = beta*r[i] + a*x[i]*y[i];
}
return r;
}
static inline REAL *DMGEMV_ND_DOW(REAL a, const REAL_D x, const REAL_D y,
REAL beta, REAL_D r)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
r[i] *= beta;
}
return r;
}
static inline REAL *MGEMTV_DOW(REAL a, const REAL_DD m,
const REAL_D v, REAL beta,
REAL_D b)
{
int i, j;
REAL tmp;
for (i = 0; i < DIM_OF_WORLD; i++) {
b[i] *= beta;
tmp = m[0][i] * v[0];
for (j = 1; j < DIM_OF_WORLD; j++) {
tmp += m[j][i] * v[j];
}
b[i] += a*tmp;
}
return b;
}
#define GEMTV_DOW(a, m, v, beta, b) MGEMTV_DOW(a, m, v, beta, b)
static inline REAL *SCMGEMV_DOW(REAL a, REAL m, const REAL_D v, REAL beta,
REAL_D b)
{
int i;
m *= a;
for (i = 0; i < DIM_OF_WORLD; i++) {
b[i] *= beta;
b[i] += m*v[i];
}
return b;
}
static inline REAL *SCMGEMV_ND_DOW(REAL a, REAL m, const REAL_D v, REAL beta,
REAL_D b)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
b[i] *= beta;
}
return b;
}
#define DMGEMTV_DOW(a, m, v, beta, b) DMGEMV_DOW(a, m, v, beta, b)
#define SCMGEMTV_DOW(a, m, v, beta, b) SCMGEMV_DOW(a, m, v, beta, b)
static inline REAL MSCP_DOW(const REAL_DD x, const REAL_DD y)
{
REAL res;
int i;
res = SCP_DOW(x[0], y[0]);
for (i = 1; i < DIM_OF_WORLD; i++) {
res += SCP_DOW(x[i], y[i]);
}
return res;
}
#define DMSCP_DOW(x, y) SCP_DOW(x, y)
static inline REAL *SET_DOW(REAL val, REAL_D x)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
x[i] = val;
}
return x;
}
static inline REAL_D *MSET_DOW(REAL val, REAL_DD m)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
m[i][i] = val;
for (j = i+1; j < DIM_OF_WORLD; j++) {
m[j][i] = m[i][j] = 0.0;
}
}
return m;
}
#define DMSET_DOW(val, m) SET_DOW(val, m)
#define SCMSET_DOW(val, m) (m) = (val)
static inline bool CMP_DOW(REAL val, const REAL_D a)
{
int i;
for (i = 0; i < DIM_OF_WORLD; i++) {
if (a[i] != val) {
return false;
}
}
return true;
}
static inline bool MCMP_DOW(REAL val, const REAL_DD a)
{
int i, j;
for (i = 0; i < DIM_OF_WORLD; i++) {
if (a[i][i] != val) {
return false;
}
for (j = i+1; j < DIM_OF_WORLD; j++) {
if (a[i][j] != 0.0 || a[j][i] != 0.0) {
return false;
}
}
}
return true;
}
#define DMCMP_DOW(val, m) CMP_DOW(val, m)
#define SCMCMP_DOW(val, m) ((m) == (val))
#if DIM_OF_WORLD == 2
static inline REAL WEDGE_DOW(const REAL_D a, const REAL_D b)
{
return a[0]*b[1] - a[1]*b[0];
}
#endif
#if DIM_OF_WORLD == 3
static inline REAL *WEDGE_DOW(const REAL_D a, const REAL_D b, REAL_D r)
{
r[0] = a[1]*b[2] - a[2]*b[1];
r[1] = a[2]*b[0] - a[0]*b[2];
r[2] = a[0]*b[1] - a[1]*b[0];
return r;
}
#endif
#define MAT_SWITCH_TYPE(type, body_f, body_d, body_sc) \
switch (type) { \
case MATENT_REAL_DD: body_f; break; \
case MATENT_REAL_D: body_d; break; \
case MATENT_REAL: body_sc; break; \
default: ERROR_EXIT("Unknown MATENT_TYPE (%d)\n", type); \
}
/* MAT_BODY(PFX, CONSTCAST, CAST, SUF, TYPE) is supposed to be a
* "multiplex" macro where BLAS routines are accessed via
" * PFX##AXPY_DOW(..., CONSTCAST var##SUF, ...)
*
* PFX is one of M, DM, SCM
* CAST and CONSTCAST specify type-casts s.t. the ...._DOW() functions
* compile without error.
* SUF is the suffix attached to some block-matrix types, one of
* real, real_d, real_dd
* TYPE is the actual type corresponding to SUF, one of
* REAL, RELA_D, REAL_DD
*/
#define MAT_EMIT_BODY_SWITCH(type) \
MAT_SWITCH_TYPE( \
type, \
MAT_BODY(M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD), \
MAT_BODY(DM, , , real_d, REAL_D), \
MAT_BODY(SCM, , , real, REAL))
/* BI_MAT_BODY(PFX1, CONSTCAST1, CAST1, SUF1, TYPE1,
* PFX2, CONSTCAST2, CAST2, SUF2, TYPE2)
*
* is supposed to be a "multiplex" macro where BLAS routines are
* accessed via " * PFX##AXPY_DOW(..., CONSTCAST var##SUF, ...) etc.
*/
#define MAT_EMIT_BI_BODY_SWITCH(type1, type2) \
MAT_SWITCH_TYPE( \
type1, \
MAT_SWITCH_TYPE( \
type2, \
MAT_BI_BODY(M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD, \
M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD), \
MAT_BI_BODY(M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD, \
DM, , , real_d, REAL_D), \
MAT_BI_BODY(M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD, \
SCM, , , real, REAL)), \
MAT_SWITCH_TYPE( \
type2, \
MAT_BI_BODY(DM, , , real_d, REAL_D, \
M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD), \
MAT_BI_BODY(DM, , , real_d, REAL_D, \
DM, , , real_d, REAL_D), \
MAT_BI_BODY(DM, , , real_d, REAL_D, \
SCM, , , real, REAL)), \
MAT_SWITCH_TYPE( \
type2, \
MAT_BI_BODY(SCM, , , real, REAL, \
M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD), \
MAT_BI_BODY(SCM, , , real, REAL, \
DM, , , real_d, REAL_D), \
MAT_BI_BODY(SCM, , , real, REAL, \
SCM, , , real, REAL)))
/* TRI_MAT_BODY(PFX1, CONSTCAST1, CAST1, SUF1, TYPE1,
* PFX2, CONSTCAST2, CAST2, SUF2, TYPE2)
*
* is supposed to be a "multiplex" macro where BLAS routines are
* accessed via " * PFX##AXPY_DOW(..., CONSTCAST var##SUF, ...) etc.
*/
#define MAT_EMIT_TRI_BODY_SWITCH(type1, type2) \
MAT_SWITCH_TYPE( \
type1, \
MAT_SWITCH_TYPE( \
type2, \
MAT_TRI_BODY(M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD, \
M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD), \
MAT_TRI_BODY(M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD, \
DM, , , real_d, REAL_D), \
MAT_TRI_BODY(M, (const REAL_D *), (REAL_D *), real_dd, REAL_DD, \
SCM, , , real, REAL)), \
if (type2 == MATENT_REAL_D) { \
MAT_TRI_BODY(DM, , , real_d, REAL_D, \
DM, , , real_d, REAL_D); \
} else if (type2 == MATENT_REAL) { \
MAT_TRI_BODY(DM, , , real_d, REAL_D, \
SCM, , , real, REAL); \
}, \
if (type2 == MATENT_REAL) { \
MAT_TRI_BODY(SCM, , , real, REAL, \
SCM, , , real, REAL); \
})
/* defines where only DOW == 1 plays a special role */
# if DIM_OF_WORLD == 1
# define DIST_DOW(x,y) ABS((x)[0]-(y)[0])
# define NORM_DOW(x) ABS((x)[0])
# define MNRM_DOW(m) ABS((m)[0][0])
# define DMNRM_DOW(m) NRM_DOW(m)
# define MDIST_DOW(a,b) ABS((a)[0][0] - (b)[0][0])
# define DMDIST_DOW(a,b) DIST_DOW(a, b)
# define SCMDIST_DOW(a,b) ABS((a)-(b))
# else
# define NORM_DOW(x) sqrt(NRM2_DOW(x))
# define DIST_DOW(x,y) sqrt(DST2_DOW(x, y))
# define MNORM_DOW(m) sqrt(MNRM2_DOW(m))
# define DMNORM_DOW(m) sqrt(DMNRM2_DOW(m))
# define MDIST_DOW(a,b) sqrt(MDST2_DOW(a, b))
# define DMDIST_DOW(a,b) sqrt(DMDST2_DOW(a, b))
# define SCMDIST_DOW(a,b) sqrt(SCMDST2_DOW(a, b))
# endif
/* defines different for all DOWs */
# if DIM_OF_WORLD == 1
# define EXPAND_DOW(x) (x)[0]
# define FORMAT_DOW "%10.5le"
# define SCAN_FORMAT_DOW "%f"
# define SCAN_EXPAND_DOW(v) &(v)[0]
# define MEXPAND_DOW(m) (m)[0][0]
# define SCAN_MFORMAT_DOW "%f %f"
# define SCAN_MEXPAND_DOW(m) &(m)[0][0]
# define MFORMAT_DOW FORMAT_DOW
# define DMEXPAND_DOW(m) EXPAND_DOW(m)
# define DMFORMAT_DOW FORMAT_DOW
# define SCMEXPAND_DOW(m) (m)
# define SCMFORMAT_DOW "[%10.5le]"
# elif DIM_OF_WORLD == 2
# define EXPAND_DOW(x) (x)[0], (x)[1]
# define FORMAT_DOW "[%10.5le, %10.5le]"
# define SCAN_FORMAT_DOW "%f %f"
# define SCAN_EXPAND_DOW(v) &(v)[0], &(v)[1]
# define MEXPAND_DOW(m) EXPAND_DOW((m)[0]), EXPAND_DOW((m)[1])
# define SCAN_MEXPAND_DOW(m) SCAN_EXPAND_DOW((m)[0]), SCAN_EXPAND_DOW((m)[1])
# define SCAN_MFORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW
# define MFORMAT_DOW "[" FORMAT_DOW ", " FORMAT_DOW "]"
# define DMEXPAND_DOW(m) EXPAND_DOW(m)
# define DMFORMAT_DOW FORMAT_DOW
# define SCMEXPAND_DOW(m) (m)
# define SCMFORMAT_DOW "[%10.5le]"
# elif DIM_OF_WORLD == 3
# define EXPAND_DOW(x) (x)[0], (x)[1], (x)[2]
# define FORMAT_DOW "[%10.5le, %10.5le, %10.5le]"
# define SCAN_FORMAT_DOW "%f %f %f"
# define SCAN_EXPAND_DOW(v) &(v)[0], &(v)[1], &(v)[2]
# define MEXPAND_DOW(m) \
EXPAND_DOW((m)[0]), EXPAND_DOW((m)[1]), EXPAND_DOW((m)[2])
# define SCAN_MEXPAND_DOW(m) \
SCAN_EXPAND_DOW((m)[0]), SCAN_EXPAND_DOW((m)[1]), SCAN_EXPAND_DOW((m)[2])
# define MFORMAT_DOW "[" FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW "]"
# define SCAN_MFORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW
# define DMEXPAND_DOW(m) EXPAND_DOW(m)
# define DMFORMAT_DOW FORMAT_DOW
# define SCMEXPAND_DOW(m) (m)
# define SCMFORMAT_DOW "[%10.5le]"
# elif DIM_OF_WORLD == 4
# define EXPAND_DOW(x) (x)[0], (x)[1], (x)[2], (x)[3]
# define FORMAT_DOW "[%10.5le, %10.5le, %10.5le, %10.5le]"
# define SCAN_FORMAT_DOW "%f %f %f %f"
# define SCAN_EXPAND_DOW(v) &(v)[0], &(v)[1], &(v)[2], &(v)[3]
# define MEXPAND_DOW(m) \
EXPAND_DOW((m)[0]), EXPAND_DOW((m)[1]), EXPAND_DOW((m)[2]), EXPAND_DOW((m)[3])
# define SCAN_MEXPAND_DOW(m) \
SCAN_EXPAND_DOW((m)[0]), SCAN_EXPAND_DOW((m)[1]), \
SCAN_EXPAND_DOW((m)[2]), SCAN_EXPAND_DOW((m)[3])
# define MFORMAT_DOW \
"[" FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW "]"
# define SCAN_MFORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW
# define DMEXPAND_DOW(m) EXPAND_DOW(m)
# define DMFORMAT_DOW FORMAT_DOW
# define SCMEXPAND_DOW(m) (m)
# define SCMFORMAT_DOW "[%10.5le]"
# elif DIM_OF_WORLD == 5
# define EXPAND_DOW(x) (x)[0], (x)[1], (x)[2], (x)[3], (x)[4]
# define FORMAT_DOW "[%10.5le, %10.5le, %10.5le, %10.5le, %10.5le]"
# define SCAN_FORMAT_DOW "%f %f %f %f %f"
# define SCAN_EXPAND_DOW(v) &(v)[0], &(v)[1], &(v)[2], &(v)[3], &(v)[4]
# define MEXPAND_DOW(m) \
EXPAND_DOW((m)[0]), EXPAND_DOW((m)[1]), EXPAND_DOW((m)[2]), \
EXPAND_DOW((m)[3]), EXPAND_DOW((m)[4])
# define SCAN_MEXPAND_DOW(m) \
SCAN_EXPAND_DOW((m)[0]), SCAN_EXPAND_DOW((m)[1]), SCAN_EXPAND_DOW((m)[2]), \
SCAN_EXPAND_DOW((m)[3]), SCAN_EXPAND_DOW((m)[4])
# define MFORMAT_DOW \
"[" FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW "]"
# define SCAN_MFORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW
# define DMEXPAND_DOW(m) EXPAND_DOW(m)
# define DMFORMAT_DOW FORMAT_DOW
# define SCMEXPAND_DOW(m) (m)
# define SCMFORMAT_DOW "[%10.5le]"
# elif DIM_OF_WORLD == 6
# define EXPAND_DOW(x) (x)[0], (x)[1], (x)[2], (x)[3], (x)[4], (x)[5]
# define FORMAT_DOW \
# define SCAN_FORMAT_DOW "%f %f %f %f %f %f"
# define SCAN_EXPAND_DOW(v) \
&(v)[0], &(v)[1], &(v)[2], &(v)[3], &(v)[4], &(v)[5]
# define MFORMAT_DOW \
"[%10.5le, %10.5le, %10.5le, %10.5le, %10.5le, %10.5le]"
# define MEXPAND_DOW(m) \
EXPAND_DOW((m)[0]), EXPAND_DOW((m)[1]), EXPAND_DOW((m)[2]), \
EXPAND_DOW((m)[3]), EXPAND_DOW((m)[4]), EXPAND_DOW((m)[5])
# define SCAN_MEXPAND_DOW(m) \
SCAN_EXPAND_DOW((m)[0]), SCAN_EXPAND_DOW((m)[1]), SCAN_EXPAND_DOW((m)[2]), \
SCAN_EXPAND_DOW((m)[3]), SCAN_EXPAND_DOW((m)[4]), SCAN_EXPAND_DOW((m)[5])
# define MFORMAT_DOW \
"[" FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", " \
FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW "]"
# define SCAN_MFORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW
# define DMEXPAND_DOW(m) EXPAND_DOW(m)
# define DMFORMAT_DOW FORMAT_DOW
# define SCMEXPAND_DOW(m) (m)
# define SCMFORMAT_DOW "[%10.5le]"
# elif DIM_OF_WORLD == 7
# define EXPAND_DOW(x) \
(x)[0], (x)[1], (x)[2], (x)[3], (x)[4], (x)[5], (x)[6]
# define FORMAT_DOW \
"[%10.5le, %10.5le, %10.5le, %10.5le, %10.5le, %10.5le, %10.5le]"
# define SCAN_FORMAT_DOW "%f %f %f %f %f %f %f"
# define SCAN_EXPAND_DOW(v) \
&(v)[0], &(v)[1], &(v)[2], &(v)[3], &(v)[4], &(v)[5], &(v)[6]
# define MEXPAND_DOW(m) \
EXPAND_DOW((m)[0]), EXPAND_DOW((m)[1]), EXPAND_DOW((m)[2]), \
EXPAND_DOW((m)[3]), EXPAND_DOW((m)[4]), EXPAND_DOW((m)[5]), \
EXPAND_DOW((m)[6])
# define SCAN_MEXPAND_DOW(m) \
SCAN_EXPAND_DOW((m)[0]), SCAN_EXPAND_DOW((m)[1]), SCAN_EXPAND_DOW((m)[2]), \
SCAN_EXPAND_DOW((m)[3]), SCAN_EXPAND_DOW((m)[4]), SCAN_EXPAND_DOW((m)[5]) \
SCAN_EXPAND_DOW((m)[6])
# define MFORMAT_DOW \
"[" FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", " \
FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW "]"
# define SCAN_MFORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW
# define DMEXPAND_DOW(m) EXPAND_DOW(m)
# define DMFORMAT_DOW FORMAT_DOW
# define SCMEXPAND_DOW(m) (m)
# define SCMFORMAT_DOW "[%10.5le]"
# elif DIM_OF_WORLD == 8
# define EXPAND_DOW(x) \
(x)[0], (x)[1], (x)[2], (x)[3], (x)[4], (x)[5], (x)[6], (x)[7]
# define FORMAT_DOW \
"[%10.5le, %10.5le, %10.5le, %10.5le, %10.5le, %10.5le, %10.5le, %10.5le]"
# define SCAN_FORMAT_DOW "%f %f %f %f %f %f %f %f"
# define SCAN_EXPAND_DOW(v) \
&(v)[0], &(v)[1], &(v)[2], &(v)[3], &(v)[4], &(v)[5], &(v)[6], &(v)[7]
# define MEXPAND_DOW(m) \
EXPAND_DOW((m)[0]), EXPAND_DOW((m)[1]), EXPAND_DOW((m)[2]), \
EXPAND_DOW((m)[3]), EXPAND_DOW((m)[4]), EXPAND_DOW((m)[5]), \
EXPAND_DOW((m)[6]), EXPAND_DOW((m)[7])
# define SCAN_MEXPAND_DOW(m) \
SCAN_EXPAND_DOW((m)[0]), SCAN_EXPAND_DOW((m)[1]), SCAN_EXPAND_DOW((m)[2]), \
SCAN_EXPAND_DOW((m)[3]), SCAN_EXPAND_DOW((m)[4]), SCAN_EXPAND_DOW((m)[5]) \
SCAN_EXPAND_DOW((m)[6]), SCAN_EXPAND_DOW((m)[7])
# define MFORMAT_DOW \
"[" FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", "\
FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW "]"
# define SCAN_MFORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW
# define DMEXPAND_DOW(m) EXPAND_DOW(m)
# define DMFORMAT_DOW FORMAT_DOW
# define SCMEXPAND_DOW(m) (m)
# define SCMFORMAT_DOW "[%10.5le]"
# elif DIM_OF_WORLD == 9
# define EXPAND_DOW(x) \
(x)[0], (x)[1], (x)[2], (x)[3], (x)[4], (x)[5], (x)[6], (x)[7], (x)[8]
# define FORMAT_DOW \
"[%10.5le, %10.5le, %10.5le, %10.5le, " \
"%10.5le, %10.5le, %10.5le, %10.5le, %10.5le]"
# define SCAN_FORMAT_DOW "%f %f %f %f %f %f %f %f %f"
# define SCAN_EXPAND_DOW(v) \
&(v)[0], &(v)[1], &(v)[2], &(v)[3], &(v)[4], \
&(v)[5], &(v)[6], &(v)[7], &(v)[8]
# define MEXPAND_DOW(m) \
EXPAND_DOW((m)[0]), EXPAND_DOW((m)[1]), EXPAND_DOW((m)[2]), \
EXPAND_DOW((m)[3]), EXPAND_DOW((m)[4]), EXPAND_DOW((m)[5]), \
EXPAND_DOW((m)[6]), EXPAND_DOW((m)[7]), EXPAND_DOW((m)[8])
# define SCAN_MEXPAND_DOW(m) \
SCAN_EXPAND_DOW((m)[0]), SCAN_EXPAND_DOW((m)[1]), SCAN_EXPAND_DOW((m)[2]), \
SCAN_EXPAND_DOW((m)[3]), SCAN_EXPAND_DOW((m)[4]), SCAN_EXPAND_DOW((m)[5]) \
SCAN_EXPAND_DOW((m)[6]), SCAN_EXPAND_DOW((m)[7]), SCAN_EXPAND_DOW((m)[8])
# define MFORMAT_DOW \
"[" FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW ", "\
FORMAT_DOW ", " FORMAT_DOW ", " FORMAT_DOW "]"
# define SCAN_MFORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW \
SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW SCAN_FORMAT_DOW \
SCAN_FORMAT_DOW
# define DMEXPAND_DOW(m) EXPAND_DOW(m)
# define DMFORMAT_DOW FORMAT_DOW
# define SCMEXPAND_DOW(m) (m)
# define SCMFORMAT_DOW "[%10.5le]"
# endif
/* Some inline functions for barycentric coordinates, and conversion
* between barycentric gradients and cartesian gradients.
*/
/** x = a */
static inline const REAL *SET_BAR(int dim, REAL a, REAL_B x)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
x[i] = a;
}
for (; i < N_LAMBDA_MAX; i++) {
x[i] = 0.0;
}
return x;
}
static inline const REAL_B *MSET_BAR(int dim, REAL a, REAL_BB x)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
SET_BAR(dim, a, x[i]);
}
return (const REAL_B *)x;
}
/** x *= a */
static inline const REAL *SCAL_BAR(int dim, REAL a, REAL_B x)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
x[i] *= a;
}
return x;
}
static inline const REAL_B *MSCAL_BAR(int dim, REAL a, REAL_BB x)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
SCAL_BAR(dim, a, x[i]);
}
return (const REAL_B *)x;
}
/** z = a*x + b*y, x, y, z are barycentric coordinate tuples.
*/
static inline REAL SCP_BAR(int dim, const REAL_B x, const REAL_B y)
{
int i;
REAL res;
res = x[0] * y[0];
for (i = 1; i < N_LAMBDA(dim); i++) {
res += x[i] * y[i];
}
return res;
}
/** y = a*x, x and y are barycentric coordinate tuples.
*/
static inline const REAL *AXEY_BAR(int dim, REAL a, const REAL_B x, REAL_B y)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
y[i] = a * x[i];
}
return y;
}
static inline const REAL_B *MAXEY_BAR(int dim,
REAL a, const REAL_BB x, REAL_BB y)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
AXEY_BAR(dim, a, x[i], y[i]);
}
return (const REAL_B *)y;
}
/** y += a*x, x and y are barycentric coordinate tuples.
*/
static inline const REAL *AXPY_BAR(int dim, REAL a, const REAL_B x, REAL_B y)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
y[i] += a * x[i];
}
return y;
}
static inline const REAL_B *MAXPY_BAR(int dim,
REAL a, const REAL_BB x, REAL_BB y)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
AXPY_BAR(dim, a, x[i], y[i]);
}
return (const REAL_B *)y;
}
/** z = a*x + b*y, x, y, z are barycentric coordinate tuples.
*/
static inline const REAL *AXPBY_BAR(int dim,
REAL a, const REAL_B x,
REAL b, const REAL_B y,
REAL_B z)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
z[i] = b*y[i] + a * x[i];
}
return z;
}
static inline const REAL_B *MAXPBY_BAR(int dim,
REAL a, const REAL_BB x,
REAL b, const REAL_BB y,
REAL_BB z)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
AXPBY_BAR(dim, a, x[i], b, y[i], z[i]);
}
return (const REAL_B *)z;
}
static inline const REAL *AXPBYPCZ_BAR(int dim,
REAL a, const REAL_B x,
REAL b, const REAL_B y,
REAL c, const REAL_B z,
REAL_B w)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
w[i] = a * x[i] + b*y[i] + c*z[i];
}
return w;
}
/** b = a, a and b are barycentric coordinate tuples.
*/
static inline const REAL *COPY_BAR(int dim, const REAL_B a, REAL_B b)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
b[i] = a[i];
}
return b;
}
static inline const REAL_B *MCOPY_BAR(int dim, const REAL_BB a, REAL_BB b)
{
int i;
for (i = 0; i < N_LAMBDA(dim); i++) {
COPY_BAR(dim, a[i], b[i]);
}
return (const REAL_B *)b;
}
/** Convert a barycentric gradient to a world gradient, given the
* gradient of the transformation to the reference element. (VM means
* vector-matrix).
*/
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL *GRAD_DOW(int dim,
const REAL_BD Lambda,
const REAL_B b_grd,
REAL_D x_grd)
{
static REAL_D res;
int i, j;
if (__UNLIKELY__(x_grd == NULL)) {
x_grd = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
x_grd[i] = b_grd[0] * Lambda[0][i];
for (j = 1; j < N_LAMBDA(dim); j++) {
x_grd[i] += b_grd[j] * Lambda[j][i];
}
}
return x_grd;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL_D *MGRAD_DOW(int dim,
const REAL_BD Lambda,
const REAL_DB b_grd,
REAL_DD x_grd)
{
static REAL_DD res;
int i;
if (__UNLIKELY__(x_grd == NULL)) {
x_grd = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
GRAD_DOW(dim, Lambda, b_grd[i], x_grd[i]);
}
return (const REAL_D *)x_grd;
}
/* Compute the divergence */
static inline REAL DIV_DOW(int dim, const REAL_BD Lambda, const REAL_DB b_grd)
{
REAL div = 0.0;
int i, alpha;
for (i = 0; i < DIM_OF_WORLD; i++) {
for (alpha = 0; alpha < N_LAMBDA(dim); ++alpha) {
div += Lambda[alpha][i] * b_grd[i][alpha];
}
}
return div;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL *GRAD_P_DOW(int dim,
const REAL_BD Lambda,
const REAL_B b_grd,
REAL_D x_grd)
{
static REAL_D res;
int i, j;
if (__UNLIKELY__(x_grd == NULL)) {
x_grd = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
for (j = 0; j < N_LAMBDA(dim); j++) {
x_grd[i] += b_grd[j] * Lambda[j][i];
}
}
return x_grd;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL_D *MGRAD_P_DOW(int dim,
const REAL_BD Lambda,
const REAL_DB b_grd,
REAL_DD x_grd)
{
static REAL_DD res;
int i;
if (__UNLIKELY__(x_grd == NULL)) {
x_grd = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
GRAD_P_DOW(dim, Lambda, b_grd[i], x_grd[i]);
}
return (const REAL_D *)x_grd;
}
/** Convert a barycentric Hesse matrix to a world Hesse matrix, given
* the gradient of the transformation to the reference element.
*/
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL_D *D2_DOW(int dim,
const REAL_BD Lambda,
const REAL_BB b_hesse,
REAL_DD x_hesse)
{
static REAL_DD res;
int i, j, k, l;
if (__UNLIKELY__(x_hesse == NULL)) {
x_hesse = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
x_hesse[i][i] = 0.0;
for (k = 0; k < N_LAMBDA(dim); k++) {
x_hesse[i][i] += Lambda[k][i] * b_hesse[k][k] * Lambda[k][i];
for (l = k+1; l < N_LAMBDA(dim); l++) {
x_hesse[i][i] += 2.0 * Lambda[k][i] * b_hesse[k][l] * Lambda[l][i];
}
}
for (j = i+1; j < DIM_OF_WORLD; j++) {
x_hesse[i][j] = 0.0;
for (k = 0; k < N_LAMBDA(dim); k++) {
x_hesse[i][j] += Lambda[k][i] * b_hesse[k][k] * Lambda[k][j];
for (l = k+1; l < N_LAMBDA(dim); l++) {
x_hesse[i][j] += b_hesse[k][l]*(Lambda[k][i] * Lambda[l][j]
+
Lambda[l][i] * Lambda[k][j]);
}
}
x_hesse[j][i] = x_hesse[i][j];
}
}
return (const REAL_D *)x_hesse;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL_DD *MD2_DOW(int dim,
const REAL_BD Lambda,
const REAL_BB *b_hesse,
REAL_DDD x_hesse)
{
static REAL_DDD res;
int i;
if (__UNLIKELY__(x_hesse == NULL)) {
x_hesse = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
D2_DOW(dim, Lambda, b_hesse[i], x_hesse[i]);
}
return (const REAL_DD *)x_hesse;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL_D *D2_P_DOW(int dim,
const REAL_BD Lambda,
const REAL_BB b_hesse,
REAL_DD x_hesse)
{
static REAL_DD res;
int i, j, k, l;
if (__UNLIKELY__(x_hesse == NULL)) {
x_hesse = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
for (k = 0; k < N_LAMBDA(dim); k++) {
x_hesse[i][i] += Lambda[k][i] * b_hesse[k][k] * Lambda[k][i];
for (l = k+1; l < N_LAMBDA(dim); l++) {
x_hesse[i][i] += 2.0 * Lambda[k][i] * b_hesse[k][l] * Lambda[l][i];
}
}
for (j = i+1; j < DIM_OF_WORLD; j++) {
REAL tmp = 0.0;
for (k = 0; k < N_LAMBDA(dim); k++) {
tmp += Lambda[k][i] * b_hesse[k][k] * Lambda[k][j];
for (l = k+1; l < N_LAMBDA(dim); l++) {
tmp += b_hesse[k][l]*(Lambda[k][i] * Lambda[l][j]
+
Lambda[l][i] * Lambda[k][j]);
}
}
x_hesse[i][j] += tmp;
x_hesse[j][i] += tmp;
}
}
return (const REAL_D *)x_hesse;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL_DD *MD2_P_DOW(int dim,
const REAL_BD Lambda,
const REAL_BB *b_hesse,
REAL_DDD x_hesse)
{
static REAL_DDD res;
int i;
if (__UNLIKELY__(x_hesse == NULL)) {
x_hesse = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
D2_P_DOW(dim, Lambda, b_hesse[i], x_hesse[i]);
}
return (const REAL_DD *)x_hesse;
}
/**Compute the Laplacian from a given Hessian in barycentric co-ordinates. */
static inline REAL LAPLACE_DOW(int dim,
const REAL_BD Lambda,
const REAL_BB b_hesse)
{
REAL res = 0.0;
int i, k, l;
for (i = 0; i < DIM_OF_WORLD; i++) {
for (k = 0; k < N_LAMBDA(dim); k++) {
res += Lambda[k][i] * b_hesse[k][k] * Lambda[k][i];
for (l = k+1; l < N_LAMBDA(dim); l++) {
res += 2.0 * Lambda[k][i] * b_hesse[k][l] * Lambda[l][i];
}
}
}
return res;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL *MLAPLACE_DOW(int dim,
const REAL_BD Lambda,
const REAL_BB *b_hesse,
REAL_D laplace)
{
static REAL_D res;
int i;
if (__UNLIKELY__(laplace == NULL)) {
laplace = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
laplace[i] = LAPLACE_DOW(dim, Lambda, b_hesse[i]);
}
return (const REAL *)laplace;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL *MLAPLACE_P_DOW(int dim,
const REAL_BD Lambda,
const REAL_BB *b_hesse,
REAL_D laplace)
{
static REAL_D res;
int i;
if (__UNLIKELY__(laplace == NULL)) {
laplace = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
laplace[i] += LAPLACE_DOW(dim, Lambda, b_hesse[i]);
}
return (const REAL *)laplace;
}
/** Convert a cartesian gradient to a barycentric gradient, given the
* vertices of the element (in the parametric case "coords" is just
* the barycentric gradient of the coordinate functions).
*/
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL *GRAD_BAR(int dim,
const REAL_D *coords,
const REAL_D x_grd,
REAL_B b_grd)
{
static REAL_B res;
int i;
if (__UNLIKELY__(b_grd == NULL)) {
b_grd = res;
}
for (i = 0; i < N_LAMBDA(dim); i++) {
b_grd[i] = SCP_DOW(x_grd, coords[i]);
}
return b_grd;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL_B *MGRAD_BAR(int dim,
const REAL_D *coords,
const REAL_DD x_grd,
REAL_DB b_grd)
{
static REAL_B res[DIM_OF_WORLD];
int i;
if (__UNLIKELY__(b_grd == NULL)) {
b_grd = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
GRAD_BAR(dim, coords, x_grd[i], b_grd[i]);
}
return (const REAL_B *)b_grd;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL_B *D2_BAR(int dim,
const REAL_D *coords,
const REAL_DD x_D2,
REAL_BB b_D2)
{
static REAL_BB res;
int i, j, k, l;
if (__UNLIKELY__(b_D2 == NULL)) {
b_D2 = res;
}
for (i = 0; i < N_LAMBDA(dim); i++) {
b_D2[i][i] = 0.0;
for (k = 0; k < DIM_OF_WORLD; k++) {
b_D2[i][i] += SQR(coords[i][k])*x_D2[k][k];
for (l = k+1; l < DIM_OF_WORLD; l++) {
b_D2[i][i] += coords[i][k]*2.0*x_D2[k][l]*coords[i][l];
}
}
for (j = i+1; j < N_LAMBDA(dim); j++) {
b_D2[i][j] = 0.0;
for (k = 0; k < DIM_OF_WORLD; k++) {
b_D2[i][j] += coords[i][k]*x_D2[k][k]*coords[j][k];
for (l = k+1; l < DIM_OF_WORLD; l++) {
b_D2[i][j] += x_D2[k][l] * (coords[i][k] * coords[j][l]
+
coords[i][l] * coords[j][k]);
}
}
b_D2[j][i] = b_D2[i][j];
}
}
return (const REAL_B *)b_D2;
}
__FORCE_INLINE_ATTRIBUTE__
static inline const REAL_BB *MD2_BAR(int dim,
const REAL_D *coords,
const REAL_DD *x_D2,
REAL_BB *b_D2)
{
static REAL_BB res[DIM_OF_WORLD];
int i;
if (__UNLIKELY__(b_D2 == NULL)) {
b_D2 = res;
}
for (i = 0; i < DIM_OF_WORLD; i++) {
D2_BAR(dim, coords, x_D2[i], b_D2[i]);
}
return (const REAL_BB *)b_D2;
}
static inline REAL_D *MM_DOW(const REAL_DD a,
const REAL_DD b, REAL_DD c)
{
int i, j, k;
for (i = 0; i < DIM_OF_WORLD; i++) {
for (j = 0; j < DIM_OF_WORLD; j++) {
c[i][j] = 0.0;
for (k = 0; k < DIM_OF_WORLD; k++) {
c[i][j] += a[i][k]*b[k][j];
}
}
}
return c;
}
static inline REAL_D *MMT_DOW(const REAL_DD a,
const REAL_DD b, REAL_DD c)
{
int i, j, k;
for (i = 0; i < DIM_OF_WORLD; i++) {
for (j = 0; j < DIM_OF_WORLD; j++) {
c[i][j] = 0.0;
for (k = 0; k < DIM_OF_WORLD; k++) {
c[i][j] += a[i][k]*b[j][k];
}
}
}
return c;
}
static inline REAL_D *MTM_DOW(const REAL_DD a,
const REAL_DD b,
REAL_DD c)
{
int i, j, k;
for (i = 0; i < DIM_OF_WORLD; i++) {
for (j = 0; j < DIM_OF_WORLD; j++) {
c[i][j] = a[0][i]*b[j][0];
for (k = 1; k < DIM_OF_WORLD; k++) {
c[i][j] += a[k][i]*b[j][k];
}
}
}
return c;
}
#if DIM_OF_WORLD == 1
static inline REAL MDET_DOW(const REAL_DD m)
{
return m[0][0];
}
static inline REAL MINVERT_DOW(const REAL_DD m, REAL_DD mi)
{
if (mi[0][0] != 0.0) {
mi[0][0] = 1.0/m[0][0];
}
return m[0][0];
}
#elif DIM_OF_WORLD == 2
static inline REAL MDET_DOW(const REAL_DD m)
{
return m[0][0]*m[1][1] - m[1][0]*m[0][1];
}
static inline REAL MINVERT_DOW(const REAL_DD m, REAL_DD mi)
{
REAL det = m[0][0]*m[1][1] - m[1][0]*m[0][1];
if (det != 0.0) {
mi[0][0] = m[1][1] / det;
mi[1][1] = m[0][0] / det;
mi[0][1] = -m[0][1] / det;
mi[1][0] = -m[1][0] / det;
}
return det;
}
#elif DIM_OF_WORLD == 3
static inline REAL MDET_DOW(const REAL_DD m)
{
#if 0
int j;
REAL_D tmp;
REAL det;
det = 0;
for (j = 0; j < DIM_OF_WORLD; j++) {
WEDGE_DOW(m[(j+1)%DIM_OF_WORLD], m[(j+2)%DIM_OF_WORLD], tmp);
det += SCP_DOW(tmp, m[j]);
}
return det / (REAL)DIM_OF_WORLD;
#else
return
+(m[1][1]*m[2][2] - m[2][1]*m[1][2]) * m[0][0]
-(m[0][1]*m[2][2] - m[2][1]*m[0][2]) * m[1][0]
+(m[0][1]*m[1][2] - m[1][1]*m[0][2]) * m[2][0];
#endif
}
static inline REAL MINVERT_DOW(const REAL_DD m, REAL_DD mi)
{
#if 0
int i, j;
REAL_D tmp;
for (j = 0; j < DIM_OF_WORLD; j++) {
WEDGE_DOW(m[(j+1)%DIM_OF_WORLD], m[(j+2)%DIM_OF_WORLD], tmp);
SCAL_DOW(1.0/SCP_DOW(tmp, m[j]), tmp);
for (i = 0; i < DIM_OF_WORLD; i++) {
mi[i][j] = tmp[i];
}
}
return mi;
#else
REAL det;
int i;
mi[0][0] = +(m[1][1]*m[2][2] - m[2][1]*m[1][2]);
mi[0][1] = -(m[0][1]*m[2][2] - m[2][1]*m[0][2]);
mi[0][2] = +(m[0][1]*m[1][2] - m[1][1]*m[0][2]);
det = mi[0][0] * m[0][0] + mi[0][1] * m[1][0] + mi[0][2]*m[2][0];
if (det != 0.0) {
for (i = 0; i < DIM_OF_WORLD; i++) {
mi[0][i] /= det;
}
mi[1][0] = (m[1][2]*m[2][0] - m[1][0]*m[2][2])/det;
mi[1][1] = (m[0][0]*m[2][2] - m[2][0]*m[0][2])/det;
mi[1][2] = (m[1][0]*m[0][2] - m[0][0]*m[1][2])/det;
mi[2][0] = (m[1][0]*m[2][1] - m[1][1]*m[2][0])/det;
mi[2][1] = (m[2][0]*m[0][1] - m[0][0]*m[2][1])/det;
mi[2][2] = (m[0][0]*m[1][1] - m[0][1]*m[1][0])/det;
}
return det;
#endif
}
#else
static inline REAL MDET_DOW(const REAL_DD m)
{
FUNCNAME("MDET_DOW");
REAL_DD tmpM;
REAL_D b;
REAL det;
int i;
SET_DOW(0.0, b); /* dummy */
MCOPY_DOW(m, tmpM); /* destructive Gauss destroys M */
square_gauss((REAL *)tmpM, b, b, DIM_OF_WORLD, 1);
det = 1.0;
for (i = 0; i < DIM_OF_WORLD; ++i) {
det *= tmpM[i][i];
}
return det;
}
static inline REAL_D *MINVERT_DOW(const REAL_DD m, REAL_DD mi)
{
FUNCNAME("MINVERT_DOW");
REAL_DD tmpM, b;
MSET_DOW(1.0, b); /* unit matrix */
MCOPY_DOW(m, tmpM); /* destructive Gauss destroys M */
square_gauss((REAL *)tmpM, (REAL *)b, (REAL *)mi, DIM_OF_WORLD, DIM_OF_WORLD);
return mi;
}
#endif
static const AFF_TRAFO aff_identity = {
{ { 1.0, },
#if DIM_OF_WORLD > 1
{ 0.0, 1.0, },
#endif
#if DIM_OF_WORLD > 2
{ 0.0, 0.0, 1.0, },
#endif
#if DIM_OF_WORLD > 3
{ 0.0, 0.0, 0.0, 1.0, },
#endif
#if DIM_OF_WORLD > 4
{ 0.0, 0.0, 0.0, 0.0, 1.0, },
#endif
#if DIM_OF_WORLD > 5
{ 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, },
#endif
#if DIM_OF_WORLD > 6
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, },
#endif
#if DIM_OF_WORLD > 7
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, },
#endif
#if DIM_OF_WORLD > 8
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, },
#endif
},
{ 0.0 }
};
static inline const AFF_TRAFO *AFFINE_IDENTITY(void)
{
return &aff_identity;
}
static inline void GET_AFF_TRAFO(int info, const char *key, AFF_TRAFO *T)
{
GET_PARAMETER(info, key,
SCAN_MFORMAT_DOW SCAN_FORMAT_DOW,
SCAN_MEXPAND_DOW(T->M), SCAN_EXPAND_DOW(T->t));
}
static inline REAL *AFFINE_DOW(const AFF_TRAFO *trafo,
const REAL_D x,
REAL_D y)
{
SET_DOW(0.0, y);
MV_DOW((const REAL_D *)trafo->M, x, y);
AXPY_DOW(1.0, trafo->t, y);
return y;
}
/* Apply the inverse of the affine transformation. trafo->M is
* assumed to be orthogonal.
*/
static inline REAL *AFFINV_DOW(const AFF_TRAFO *trafo,
const REAL_D x,
REAL_D y)
{
REAL_D tmp = { 0.0, };
MTV_DOW((const REAL_D *)trafo->M, trafo->t, tmp);
SET_DOW(0.0, y);
MTV_DOW((const REAL_D *)trafo->M, x, y);
AXPY_DOW(-1.0, tmp, y);
return y;
}
static inline AFF_TRAFO *INVAFF_DOW(const AFF_TRAFO *A,
AFF_TRAFO *B)
{
int i, j;
SET_DOW(0.0, B->t);
MTV_DOW((const REAL_D *)A->M, A->t, B->t);
SCAL_DOW(-1.0, B->t);
for (i = 0; i < DIM_OF_WORLD; i++ ) {
for (j = 0; j < DIM_OF_WORLD; j++) {
B->M[i][j] = A->M[j][i];
}
}
return B;
}
static inline AFF_TRAFO *AFFAFF_DOW(const AFF_TRAFO *A,
const AFF_TRAFO *B,
AFF_TRAFO *C)
{
MM_DOW(A->M, B->M, C->M);
COPY_DOW(A->t, C->t);
MV_DOW(A->M, B->t, C->t);
return C;
}
/* filling of the geometry and the quadrature cache */
static inline const EL_GEOM_CACHE *
fill_el_geom_cache(const EL_INFO *el_info, FLAGS fill_flag)
{
EL_GEOM_CACHE *elgc;
FLAGS need;
int dim, wall;
elgc = (EL_GEOM_CACHE *)&el_info->el_geom_cache;
if (elgc->current_el != el_info->el) {
elgc->fill_flag = 0;
elgc->current_el = el_info->el;
}
if (!(need = (elgc->fill_flag ^ fill_flag) & fill_flag)) {
return elgc;
}
dim = el_info->mesh->dim;
if (need & FILL_EL_LAMBDA) {
elgc->det = el_grd_lambda_dim(dim, el_info, elgc->Lambda);
elgc->fill_flag |= FILL_EL_LAMBDA|FILL_EL_DET;
} else if (need & FILL_EL_DET) {
elgc->det = el_det_dim(dim, el_info);
elgc->fill_flag |= FILL_EL_DET;
}
for (wall = 0; wall < N_WALLS_MAX; wall++) {
if (need & FILL_EL_WALL_ORIENTATION(wall)) {
EL *el = el_info->el;
elgc->orientation[wall][0] = wall_orientation(dim, el, wall);
if ((el_info->fill_flag & FILL_NEIGH) && el_info->neigh[wall]) {
EL *neigh = el_info->neigh[wall];
int oppv = el_info->opp_vertex[wall];
elgc->orientation[wall][1] = wall_orientation(dim, neigh, oppv);
} else {
elgc->orientation[wall][1] = -1;
}
elgc->fill_flag |= FILL_EL_WALL_ORIENTATION(wall);
}
if (need & FILL_EL_WALL_REL_ORIENTATION(wall)) {
DEBUG_TEST_FLAG(FILL_NEIGH, el_info);
if (el_info->neigh[wall]) {
EL *el = el_info->el;
EL *neigh = el_info->neigh[wall];
int oppv = el_info->opp_vertex[wall];
elgc->rel_orientation[wall] =
wall_rel_orientation(dim, el, neigh, wall, oppv);
elgc->fill_flag |= FILL_EL_WALL_REL_ORIENTATION(wall);
}
}
if (need & (FILL_EL_WALL_NORMAL(wall)|FILL_EL_WALL_DET(wall))) {
elgc->wall_det[wall] =
get_wall_normal_dim(dim, el_info, wall, elgc->wall_normal[wall]);
elgc->fill_flag |= FILL_EL_WALL_NORMAL(wall)|FILL_EL_WALL_DET(wall);
}
}
return elgc;
}
/* Fill the quadrature cache for the given element. Maybe this should
* be made an inline function. This function does not call
* parametric->init_element(); it is assumed that this has been done
* before if necessary. We also do not call any INIT_ELEMENT() method.
*/
static inline const QUAD_EL_CACHE *fill_quad_el_cache(const EL_INFO *el_info,
const QUAD *quad,
FLAGS fill)
{
QUAD_EL_CACHE *qelc = (QUAD_EL_CACHE *)quad->metadata;
FLAGS need;
int iq, wall;
if (qelc->current_el != el_info->el) {
qelc->fill_flag = 0;
qelc->current_el = el_info->el;
INIT_ELEMENT(el_info, quad);
}
if (!(need = (qelc->fill_flag ^ fill) & fill)) {
return qelc;
}
if (el_info->fill_flag & FILL_COORDS) {
if (need & FILL_EL_QUAD_WORLD) {
for (iq = 0; iq < quad->n_points; iq++) {
coord_to_world(el_info, quad->lambda[iq], qelc->world[iq]);
}
qelc->fill_flag |= FILL_EL_QUAD_WORLD;
}
} else {
PARAMETRIC *parametric = el_info->mesh->parametric;
TEST_EXIT(parametric,
"FILL_COORDS not set in el_info->fill_flag and "
"not on a parametric mesh.\n");
if (need & FILL_EL_QUAD_WORLD) {
parametric->coord_to_world(el_info, quad, -1, NULL, qelc->world);
}
if (need &
(FILL_EL_QUAD_GRD_WORLD|FILL_EL_QUAD_D2_WORLD|FILL_EL_QUAD_D3_WORLD)) {
parametric->grd_world(el_info, quad, -1, NULL,
(need & FILL_EL_QUAD_GRD_WORLD)
? qelc->param.grd_world : NULL,
(need & FILL_EL_QUAD_D2_WORLD)
? qelc->param.D2_world : NULL,
(need & FILL_EL_QUAD_D3_WORLD)
? qelc->param.D3_world : NULL);
qelc->fill_flag |= need &
(FILL_EL_QUAD_GRD_WORLD|FILL_EL_QUAD_D2_WORLD|FILL_EL_QUAD_D3_WORLD);
}
if (need & FILL_EL_QUAD_DLAMBDA) {
parametric->grd_lambda(el_info, quad, -1, NULL,
qelc->param.Lambda,
qelc->param.DLambda,
qelc->param.det);
qelc->fill_flag |=
FILL_EL_QUAD_DLAMBDA|FILL_EL_QUAD_LAMBDA|FILL_EL_QUAD_DET;
} else if (need & FILL_EL_QUAD_LAMBDA) {
parametric->grd_lambda(el_info, quad, -1, NULL,
qelc->param.Lambda, NULL, qelc->param.det);
qelc->fill_flag |= FILL_EL_QUAD_LAMBDA|FILL_EL_QUAD_DET;
} else if (need & FILL_EL_QUAD_DET) {
parametric->det(el_info, quad, -1, NULL, qelc->param.det);
qelc->fill_flag |= FILL_EL_QUAD_DET;
}
if (need & (FILL_EL_QUAD_WALL_DET |
FILL_EL_QUAD_WALL_NORMAL |
FILL_EL_QUAD_GRD_NORMAL |
FILL_EL_QUAD_D2_NORMAL)) {
DEBUG_TEST_EXIT(quad->codim == 1,
"Wall normals make only sense for co-dim 1.\n");
wall = quad->subsplx;
if (need & FILL_EL_QUAD_D2_NORMAL) {
parametric->wall_normal(el_info, wall, quad, -1, NULL,
qelc->param.wall_normal,
qelc->param.grd_normal,
qelc->param.D2_normal,
qelc->param.wall_det);
qelc->fill_flag |=
(FILL_EL_QUAD_WALL_DET |
FILL_EL_QUAD_WALL_NORMAL |
FILL_EL_QUAD_GRD_NORMAL |
FILL_EL_QUAD_D2_NORMAL);
} else if (need & FILL_EL_QUAD_GRD_NORMAL) {
parametric->wall_normal(el_info, wall, quad, -1, NULL,
qelc->param.wall_normal,
qelc->param.grd_normal,
NULL,
qelc->param.wall_det);
qelc->fill_flag |=
(FILL_EL_QUAD_WALL_DET |
FILL_EL_QUAD_WALL_NORMAL |
FILL_EL_QUAD_GRD_NORMAL);
} else if (need & FILL_EL_QUAD_WALL_NORMAL) {
parametric->wall_normal(el_info, wall, quad, -1, NULL,
qelc->param.wall_normal, NULL, NULL,
qelc->param.wall_det);
qelc->fill_flag |= FILL_EL_QUAD_WALL_DET|FILL_EL_QUAD_WALL_NORMAL;
} else {
parametric->wall_normal(el_info, wall, quad, -1, NULL,
NULL /* no normals */, NULL, NULL,
qelc->param.wall_det);
qelc->fill_flag |= FILL_EL_QUAD_WALL_DET;
}
}
}
return qelc;
}
/* Compute the value of some really vector-valued basis function. */
static inline const REAL *
phi_dow(REAL_D result,
int i, const REAL_B lambda, const BAS_FCTS *thisptr)
{
AXEY_DOW(PHI(thisptr, i, lambda), PHI_D(thisptr, i, lambda), result);
return result;
}
/* Compute the barycentric gradient of some really vector-valued basis
* function.
*/
static inline const REAL_B *
grd_phi_dow(REAL_DB result,
int i, const REAL_B lambda, const BAS_FCTS *thisptr)
{
int n;
const REAL *grd_phi = GRD_PHI(thisptr, i, lambda);
const REAL *phi_d = PHI_D(thisptr, i, lambda);
for (n = 0; n < DIM_OF_WORLD; n++) {
AXEY_BAR(DIM_MAX, phi_d[n], grd_phi, result[n]);
}
if (!thisptr->dir_pw_const) {
REAL phi = PHI(thisptr, i, lambda);
const REAL_B *grd_phi_d = GRD_PHI_D(thisptr, i, lambda);
for (n = 0; n < DIM_OF_WORLD; n++) {
AXPY_BAR(DIM_MAX, phi, grd_phi_d[n], result[n]);
}
}
return (const REAL_B *)result;
}
/* Compute the barycentric second derivatives of some really
* vector-valued basis functions.
*/
#endif /* _ALBERT_INLINES_H_ */
|