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
|
#include "Kinetostat.h"
#include "ATC_Error.h"
#include "ATC_Coupling.h"
#include "LammpsInterface.h"
#include "PerAtomQuantityLibrary.h"
#include "PrescribedDataManager.h"
#include "ElasticTimeIntegrator.h"
#include "TransferOperator.h"
using std::set;
using std::pair;
using std::string;
namespace ATC {
//--------------------------------------------------------
//--------------------------------------------------------
// Class Kinetostat
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
//--------------------------------------------------------
Kinetostat::Kinetostat(ATC_Coupling * atc,
const string & regulatorPrefix) :
AtomicRegulator(atc,regulatorPrefix)
{
// do nothing
}
//--------------------------------------------------------
// modify:
// parses and adjusts kinetostat state based on
// user input, in the style of LAMMPS user input
//--------------------------------------------------------
bool Kinetostat::modify(int narg, char **arg)
{
bool foundMatch = false;
int argIndex = 0;
if (strcmp(arg[argIndex],"momentum")==0) {
argIndex++;
// fluxstat type
/*! \page man_control_momentum fix_modify AtC control momentum
\section syntax
fix_modify AtC control momentum none \n
fix_modify AtC control momentum rescale <frequency>\n
- frequency (int) = time step frequency for applying displacement and velocity rescaling \n
fix_modify AtC control momentum glc_displacement \n
fix_modify AtC control momentum glc_velocity \n
fix_modify AtC control momentum hoover \n
fix_modify AtC control momentum flux [faceset face_set_id, interpolate]
- face_set_id (string) = id of boundary face set, if not specified
(or not possible when the atomic domain does not line up with
mesh boundaries) defaults to an atomic-quadrature approximate
evaulation\n
\section examples
fix_modify AtC control momentum glc_velocity \n
fix_modify AtC control momentum flux faceset bndy_faces \n
\section description
\section restrictions
only to be used with specific transfers :
elastic \n
rescale not valid with time filtering activated
\section related
\section default
none
*/
boundaryIntegrationType_ = NO_QUADRATURE;
howOften_ = 1;
if (strcmp(arg[argIndex],"none")==0) { // restore defaults
regulatorTarget_ = NONE;
couplingMode_ = UNCOUPLED;
foundMatch = true;
}
else if (strcmp(arg[argIndex],"glc_displacement")==0) {
regulatorTarget_ = FIELD;
couplingMode_ = FIXED;
foundMatch = true;
}
else if (strcmp(arg[argIndex],"glc_velocity")==0) {
regulatorTarget_ = DERIVATIVE;
couplingMode_ = FIXED;
foundMatch = true;
}
else if (strcmp(arg[argIndex],"hoover")==0) {
regulatorTarget_ = DYNAMICS;
couplingMode_ = FIXED;
foundMatch = true;
}
else if (strcmp(arg[argIndex],"flux")==0) {
regulatorTarget_ = DYNAMICS;
couplingMode_ = FLUX;
argIndex++;
boundaryIntegrationType_ = atc_->parse_boundary_integration(narg-argIndex,&arg[argIndex],boundaryFaceSet_);
foundMatch = true;
}
else if (strcmp(arg[argIndex],"ghost_flux")==0) {
regulatorTarget_ = DYNAMICS;
couplingMode_ = GHOST_FLUX;
foundMatch = true;
}
}
if (!foundMatch)
foundMatch = AtomicRegulator::modify(narg,arg);
if (foundMatch)
needReset_ = true;
return foundMatch;
}
//--------------------------------------------------------
// reset_lambda_contribution
// resets the kinetostat generated force to a
// prescribed value
//--------------------------------------------------------
void Kinetostat::reset_lambda_contribution(const DENS_MAT & target)
{
DENS_MAN * lambdaForceFiltered = regulator_data("LambdaForceFiltered",nsd_);
lambdaForceFiltered->set_quantity() = target;
}
//--------------------------------------------------------
// initialize:
// sets up methods before a run
// dependence, but in general there is also a
// time integrator dependence. In general the
// precedence order is:
// time filter -> time integrator -> kinetostat
// In the future this may need to be added if
// different types of time integrators can be
// specified.
//--------------------------------------------------------
void Kinetostat::construct_methods()
{
// get data associated with stages 1 & 2 of ATC_Method::initialize
AtomicRegulator::construct_methods();
if (atc_->reset_methods()) {
// eliminate existing methods
delete_method();
DENS_MAT nodalGhostForceFiltered;
TimeIntegrator::TimeIntegrationType myIntegrationType = (atc_->time_integrator(VELOCITY))->time_integration_type();
TimeFilterManager * timeFilterManager = atc_->time_filter_manager();
if (timeFilterManager->end_equilibrate() && regulatorTarget_==AtomicRegulator::DYNAMICS) {
StressFlux * myMethod;
myMethod = dynamic_cast<StressFlux *>(regulatorMethod_);
nodalGhostForceFiltered = (myMethod->filtered_ghost_force()).quantity();
}
// update time filter
if (timeFilterManager->need_reset()) {
if (myIntegrationType == TimeIntegrator::FRACTIONAL_STEP) {
timeFilter_ = timeFilterManager->construct(TimeFilterManager::EXPLICIT_IMPLICIT);
}
else {
timeFilter_ = timeFilterManager->construct(TimeFilterManager::IMPLICIT_UPDATE);
}
}
if (timeFilterManager->filter_dynamics()) {
switch (regulatorTarget_) {
case NONE: {
regulatorMethod_ = new RegulatorMethod(this);
break;
}
case FIELD: {
regulatorMethod_ = new DisplacementGlcFiltered(this);
break;
}
case DERIVATIVE: {
regulatorMethod_ = new VelocityGlcFiltered(this);
break;
}
case DYNAMICS: {
throw ATC_Error("Kinetostat::initialize - force based kinetostats not yet implemented with time filtering");
regulatorMethod_ = new StressFluxFiltered(this);
if (timeFilterManager->end_equilibrate()) {
StressFlux * myMethod;
myMethod = dynamic_cast<StressFlux *>(regulatorMethod_);
myMethod->reset_filtered_ghost_force(nodalGhostForceFiltered);
}
break;
}
default:
throw ATC_Error("Kinetostat::construct_methods - Unknown filtered kinetostat type");
}
}
else {
switch (regulatorTarget_) {
case NONE: {
regulatorMethod_ = new RegulatorMethod(this);
break;
}
case FIELD: {
regulatorMethod_ = new DisplacementGlc(this);
break;
}
case DERIVATIVE: {
regulatorMethod_ = new VelocityGlc(this);
break;
}
case DYNAMICS: {
if (myIntegrationType == TimeIntegrator::FRACTIONAL_STEP) {
if (couplingMode_ == GHOST_FLUX) {
if (md_fixed_nodes(VELOCITY)) {
if (!md_flux_nodes(VELOCITY) && (boundaryIntegrationType_ == NO_QUADRATURE)) {
// there are fixed nodes but no fluxes
regulatorMethod_ = new KinetostatFixed(this);
}
else {
// there are both fixed and flux nodes
regulatorMethod_ = new KinetostatFluxFixed(this);
}
}
else {
// there are only flux nodes
regulatorMethod_ = new KinetostatFluxGhost(this);
}
}
else if (couplingMode_ == FIXED) {
if (md_flux_nodes(VELOCITY)) {
if (!md_fixed_nodes(VELOCITY) && (boundaryIntegrationType_ == NO_QUADRATURE)) {
// there are fluxes but no fixed or coupled nodes
regulatorMethod_ = new KinetostatFlux(this);
}
else {
// there are both fixed and flux nodes
regulatorMethod_ = new KinetostatFluxFixed(this);
}
}
else {
// there are only fixed nodes
regulatorMethod_ = new KinetostatFixed(this);
}
}
else if (couplingMode_ == FLUX) {
if (md_fixed_nodes(VELOCITY)) {
if (!md_flux_nodes(VELOCITY) && (boundaryIntegrationType_ == NO_QUADRATURE)) {
// there are fixed nodes but no fluxes
regulatorMethod_ = new KinetostatFixed(this);
}
else {
// there are both fixed and flux nodes
regulatorMethod_ = new KinetostatFluxFixed(this);
}
}
else {
// there are only flux nodes
regulatorMethod_ = new KinetostatFlux(this);
}
}
break;
}
if (myIntegrationType == TimeIntegrator::GEAR) {
if (couplingMode_ == FIXED) {
regulatorMethod_ = new KinetostatFixed(this);
}
else if (couplingMode_ == FLUX) {
regulatorMethod_ = new KinetostatFlux(this);
}
break;
}
else {
if (couplingMode_ == GHOST_FLUX) {
regulatorMethod_ = new StressFluxGhost(this);
}
else {
regulatorMethod_ = new StressFlux(this);
}
break;
}
}
default:
throw ATC_Error("Kinetostat::construct_methods - Unknown kinetostat type");
}
AtomicRegulator::reset_method();
}
}
else {
set_all_data_to_used();
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class KinetostatShapeFunction
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
KinetostatShapeFunction::KinetostatShapeFunction(AtomicRegulator *kinetostat,
const string & regulatorPrefix) :
RegulatorShapeFunction(kinetostat,regulatorPrefix),
mdMassMatrix_(atc_->set_mass_mat_md(VELOCITY)),
timeFilter_(atomicRegulator_->time_filter()),
nodalAtomicLambdaForce_(nullptr),
lambdaForceFiltered_(nullptr),
atomKinetostatForce_(nullptr),
atomVelocities_(nullptr),
atomMasses_(nullptr)
{
// data associated with stage 3 in ATC_Method::initialize
lambda_ = atomicRegulator_->regulator_data(regulatorPrefix_+"LambdaMomentum",nsd_);
lambdaForceFiltered_ = atomicRegulator_->regulator_data("LambdaForceFiltered",nsd_);
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void KinetostatShapeFunction::construct_transfers()
{
InterscaleManager & interscaleManager(atc_->interscale_manager());
// needed fundamental quantities
atomVelocities_ = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_VELOCITY);
atomMasses_ = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_MASS);
// base class transfers
RegulatorShapeFunction::construct_transfers();
// lambda interpolated to the atomic coordinates
atomLambdas_ = new FtaShapeFunctionProlongation(atc_,
lambda_,
interscaleManager.per_atom_sparse_matrix("Interpolant"));
interscaleManager.add_per_atom_quantity(atomLambdas_,
regulatorPrefix_+"AtomLambdaMomentum");
}
//--------------------------------------------------------
// set_weights
// sets diagonal weighting matrix used in
// solve_for_lambda
//--------------------------------------------------------
void KinetostatShapeFunction::set_weights()
{
if (this->use_local_shape_functions()) {
ConstantQuantityMapped<double> * myWeights = new ConstantQuantityMapped<double>(atc_,1.,lambdaAtomMap_);
weights_ = myWeights;
(atc_->interscale_manager()).add_per_atom_quantity(myWeights,
"AtomOnesMapped");
}
else {
weights_ = (atc_->interscale_manager()).per_atom_quantity("AtomicOnes");
if (!weights_) {
weights_ = new ConstantQuantity<double>(atc_,1.);
(atc_->interscale_manager()).add_per_atom_quantity(weights_,
"AtomicOnes");
}
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class GlcKinetostat
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
GlcKinetostat::GlcKinetostat(AtomicRegulator *kinetostat) :
KinetostatShapeFunction(kinetostat),
atomPositions_(nullptr)
{
// do nothing
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void GlcKinetostat::construct_transfers()
{
InterscaleManager & interscaleManager(atc_->interscale_manager());
// needed fundamental quantities
atomPositions_ = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_POSITION);
// base class transfers
KinetostatShapeFunction::construct_transfers();
}
//--------------------------------------------------------
// initialize
// initializes all method data
//--------------------------------------------------------
void GlcKinetostat::initialize()
{
KinetostatShapeFunction::initialize();
// set up list of nodes using Hoover coupling
// (a) nodes with prescribed values
PrescribedDataManager * prescribedDataMgr(atc_->prescribed_data_manager());
for (int i = 0; i < nNodes_; ++i)
for (int j = 0; j < nsd_; ++j)
if (prescribedDataMgr->is_fixed(i,VELOCITY,j))
hooverNodes_.insert(pair<int,int>(i,j));
// (b) AtC coupling nodes
if (atomicRegulator_->coupling_mode()==AtomicRegulator::FIXED) {
InterscaleManager & interscaleManager(atc_->interscale_manager());
const INT_ARRAY & nodeType((interscaleManager.dense_matrix_int("NodalGeometryType"))->quantity());
if (atomicRegulator_->use_localized_lambda()) {
for (int i = 0; i < nNodes_; ++i) {
if (nodeType(i,0)==BOUNDARY) {
for (int j = 0; j < nsd_; ++j) {
hooverNodes_.insert(pair<int,int>(i,j));
}
}
}
}
else {
for (int i = 0; i < nNodes_; ++i) {
if (nodeType(i,0)==BOUNDARY || nodeType(i,0)==MD_ONLY) {
for (int j = 0; j < nsd_; ++j) {
hooverNodes_.insert(pair<int,int>(i,j));
}
}
}
}
}
}
//--------------------------------------------------------
// apply_lambda_to_atoms
// uses existing lambda to modify given
// atomic quantity
//--------------------------------------------------------
void GlcKinetostat::apply_to_atoms(PerAtomQuantity<double> * quantity,
const DENS_MAT & lambdaAtom,
double /* dt */)
{
*quantity -= lambdaAtom;
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class DisplacementGlc
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
DisplacementGlc::DisplacementGlc(AtomicRegulator * kinetostat) :
GlcKinetostat(kinetostat),
nodalAtomicMassWeightedDisplacement_(nullptr),
nodalDisplacements_(atc_->field(DISPLACEMENT))
{
// do nothing
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void DisplacementGlc::construct_transfers()
{
InterscaleManager & interscaleManager(atc_->interscale_manager());
// set up node mappings
create_node_maps();
// set up shape function matrix
if (this->use_local_shape_functions()) {
lambdaAtomMap_ = new AtomToElementset(atc_,elementMask_);
interscaleManager.add_per_atom_int_quantity(lambdaAtomMap_,
regulatorPrefix_+"LambdaAtomMap");
shapeFunctionMatrix_ = new LocalLambdaCouplingMatrix(atc_,
lambdaAtomMap_,
nodeToOverlapMap_);
}
else {
shapeFunctionMatrix_ = new LambdaCouplingMatrix(atc_,nodeToOverlapMap_);
}
interscaleManager.add_per_atom_sparse_matrix(shapeFunctionMatrix_,
regulatorPrefix_+"LambdaCouplingMatrixMomentum");
// set linear solver strategy
if (atomicRegulator_->use_lumped_lambda_solve()) {
linearSolverType_ = AtomicRegulator::RSL_SOLVE;
}
else {
linearSolverType_ = AtomicRegulator::CG_SOLVE;
}
// base class transfers
GlcKinetostat::construct_transfers();
// atomic force induced by kinetostat
atomKinetostatForce_ = new AtomicKinetostatForceDisplacement(atc_);
interscaleManager.add_per_atom_quantity(atomKinetostatForce_,
regulatorPrefix_+"AtomKinetostatForce");
// restricted force due to kinetostat
nodalAtomicLambdaForce_ = new AtfShapeFunctionRestriction(atc_,
atomKinetostatForce_,
interscaleManager.per_atom_sparse_matrix("Interpolant"));
interscaleManager.add_dense_matrix(nodalAtomicLambdaForce_,
regulatorPrefix_+"NodalAtomicLambdaForce");
// nodal displacement restricted from atoms
nodalAtomicMassWeightedDisplacement_ = interscaleManager.dense_matrix("NodalAtomicMassWeightedDisplacement");
}
//--------------------------------------------------------
// initialize
// initializes all method data
//--------------------------------------------------------
void DisplacementGlc::initialize()
{
GlcKinetostat::initialize();
// sets up time filter for cases where variables temporally filtered
TimeFilterManager * timeFilterManager = atc_->time_filter_manager();
if (!timeFilterManager->end_equilibrate()) {
*lambdaForceFiltered_ = 0.;
timeFilter_->initialize(lambdaForceFiltered_->quantity());
}
}
//--------------------------------------------------------
// apply:
// apply the kinetostat to the atoms
//--------------------------------------------------------
void DisplacementGlc::apply_post_predictor(double dt)
{
compute_kinetostat(dt);
}
//--------------------------------------------------------
// compute_kinetostat
// manages the solution and application of the
// kinetostat equations and variables
//--------------------------------------------------------
void DisplacementGlc::compute_kinetostat(double dt)
{
// initial filtering update
apply_pre_filtering(dt);
// set up rhs
DENS_MAT rhs(nNodes_,nsd_);
set_kinetostat_rhs(rhs,dt);
// solve linear system for lambda
solve_for_lambda(rhs,lambda_->set_quantity());
// compute nodal atomic power
compute_nodal_lambda_force(dt);
// apply kinetostat to atoms
apply_to_atoms(atomPositions_,atomLambdas_->quantity());
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the right-hand side of the
// kinetostat equations
//--------------------------------------------------------
void DisplacementGlc::set_kinetostat_rhs(DENS_MAT & rhs, double /* dt */)
{
// form rhs : sum_a (hatN_Ia * x_ai) - (Upsilon)_Ii
rhs = nodalAtomicMassWeightedDisplacement_->quantity();
rhs -= (mdMassMatrix_.quantity())*(nodalDisplacements_.quantity());
}
//--------------------------------------------------------
// compute_nodal_lambda_force
// compute the effective FE force applied
// by the kinetostat
//--------------------------------------------------------
void DisplacementGlc::compute_nodal_lambda_force(double dt)
{
const DENS_MAT & myNodalAtomicLambdaForce(nodalAtomicLambdaForce_->quantity());
timeFilter_->apply_post_step1(lambdaForceFiltered_->set_quantity(),
myNodalAtomicLambdaForce,dt);
// update FE displacements for localized thermostats
apply_localization_correction(myNodalAtomicLambdaForce,
nodalDisplacements_.set_quantity(),
dt*dt);
}
//--------------------------------------------------------
// apply_pre_filtering
// applies first step of filtering to
// relevant variables
//--------------------------------------------------------
void DisplacementGlc::apply_pre_filtering(double dt)
{
// apply time filtered lambda force
DENS_MAT lambdaZero(nNodes_,nsd_);
timeFilter_->apply_pre_step1(lambdaForceFiltered_->set_quantity(),(-1./dt/dt)*lambdaZero,dt);
}
//--------------------------------------------------------
// set_weights
// sets diagonal weighting matrix used in
// solve_for_lambda
//--------------------------------------------------------
void DisplacementGlc::set_weights()
{
if (lambdaAtomMap_) {
MappedAtomQuantity * myWeights = new MappedAtomQuantity(atc_,atomMasses_,lambdaAtomMap_);
weights_ = myWeights;
(atc_->interscale_manager()).add_per_atom_quantity(myWeights,
"AtomMassesMapped");
}
else {
weights_ = atomMasses_;
}
}
//--------------------------------------------------------
// apply_localization_correction
// corrects for localized kinetostats only
// solving kinetostat equations on a subset
// of the MD region
//--------------------------------------------------------
void DisplacementGlc::apply_localization_correction(const DENS_MAT & source,
DENS_MAT & nodalField,
double weight)
{
DENS_MAT nodalLambdaRoc(nNodes_,nsd_);
atc_->apply_inverse_mass_matrix(source,
nodalLambdaRoc,
VELOCITY);
set<pair<int,int> >::const_iterator iter;
for (iter = hooverNodes_.begin(); iter != hooverNodes_.end(); ++iter) {
nodalLambdaRoc(iter->first,iter->second) = 0.;
}
nodalField += weight*nodalLambdaRoc;
}
//--------------------------------------------------------
// output:
// adds all relevant output to outputData
//--------------------------------------------------------
void DisplacementGlc::output(OUTPUT_LIST & outputData)
{
_nodalAtomicLambdaForceOut_ = nodalAtomicLambdaForce_->quantity();
DENS_MAT & lambda(lambda_->set_quantity());
if ((atc_->lammps_interface())->rank_zero()) {
outputData[regulatorPrefix_+"LambdaMomentum"] = λ
outputData[regulatorPrefix_+"NodalLambdaForce"] = &(_nodalAtomicLambdaForceOut_);
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class DisplacementGlcFiltered
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
DisplacementGlcFiltered::DisplacementGlcFiltered(AtomicRegulator * kinetostat) :
DisplacementGlc(kinetostat),
nodalAtomicDisplacements_(atc_->nodal_atomic_field(DISPLACEMENT))
{
// do nothing
}
//--------------------------------------------------------
// apply_pre_filtering
// applies first step of filtering to
// relevant variables
//--------------------------------------------------------
void DisplacementGlcFiltered::apply_pre_filtering(double dt)
{
// apply time filtered lambda to atomic fields
DisplacementGlc::apply_pre_filtering(dt);
DENS_MAT nodalAcceleration(nNodes_,nsd_);
atc_->apply_inverse_md_mass_matrix(lambdaForceFiltered_->set_quantity(),
nodalAcceleration,
VELOCITY);
nodalAtomicDisplacements_ += dt*dt*nodalAcceleration;
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the right-hand side of the
// kinetostat equations
//--------------------------------------------------------
void DisplacementGlcFiltered::set_kinetostat_rhs(DENS_MAT & rhs, double dt)
{
// form rhs : sum_a (hatN_Ia * x_ai) - (Upsilon)_Ii
double coef = 1./(timeFilter_->unfiltered_coefficient_pre_s1(dt));
rhs = coef*(mdMassMatrix_.quantity())*(nodalAtomicDisplacements_.quantity() - nodalDisplacements_.quantity());
}
//--------------------------------------------------------
// compute_nodal_lambda_force
// compute the effective FE force applied
// by the kinetostat
//--------------------------------------------------------
void DisplacementGlcFiltered::compute_nodal_lambda_force(double dt)
{
const DENS_MAT & myNodalAtomicLambdaForce(nodalAtomicLambdaForce_->quantity());
DENS_MAT & myLambdaForceFiltered(lambdaForceFiltered_->set_quantity());
timeFilter_->apply_post_step1(myLambdaForceFiltered,
myNodalAtomicLambdaForce,dt);
// update filtered atomic displacements
DENS_MAT nodalLambdaRoc(myNodalAtomicLambdaForce.nRows(),myNodalAtomicLambdaForce.nCols());
atc_->apply_inverse_md_mass_matrix(myNodalAtomicLambdaForce,
nodalLambdaRoc,
VELOCITY);
timeFilter_->apply_post_step1(nodalAtomicDisplacements_.set_quantity(),dt*dt*nodalLambdaRoc,dt);
// update FE displacements for localized thermostats
apply_localization_correction(myLambdaForceFiltered,
nodalDisplacements_.set_quantity(),
dt*dt);
}
//--------------------------------------------------------
// output:
// adds all relevant output to outputData
//--------------------------------------------------------
void DisplacementGlcFiltered::output(OUTPUT_LIST & outputData)
{
DENS_MAT & lambda(lambda_->set_quantity());
DENS_MAT & lambdaForceFiltered(lambdaForceFiltered_->set_quantity());
if ((atc_->lammps_interface())->rank_zero()) {
outputData[regulatorPrefix_+"LambdaMomentum"] = λ
outputData[regulatorPrefix_+"NodalLambdaForce"] = &lambdaForceFiltered;
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class VelocityGlc
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
VelocityGlc::VelocityGlc(AtomicRegulator * kinetostat) :
GlcKinetostat(kinetostat),
nodalAtomicMomentum_(nullptr),
nodalVelocities_(atc_->field(VELOCITY))
{
// do nothing
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void VelocityGlc::construct_transfers()
{
InterscaleManager & interscaleManager(atc_->interscale_manager());
// set up node mappings
create_node_maps();
// set up shape function matrix
shapeFunctionMatrix_ = interscaleManager.per_atom_sparse_matrix(regulatorPrefix_+"LambdaCouplingMatrixMomentum");
if (!shapeFunctionMatrix_) {
if (this->use_local_shape_functions()) {
lambdaAtomMap_ = new AtomToElementset(atc_,elementMask_);
interscaleManager.add_per_atom_int_quantity(lambdaAtomMap_,
regulatorPrefix_+"LambdaAtomMap");
shapeFunctionMatrix_ = new LocalLambdaCouplingMatrix(atc_,
lambdaAtomMap_,
nodeToOverlapMap_);
}
else {
shapeFunctionMatrix_ = new LambdaCouplingMatrix(atc_,nodeToOverlapMap_);
}
interscaleManager.add_per_atom_sparse_matrix(shapeFunctionMatrix_,
regulatorPrefix_+"LambdaCouplingMatrixMomentum");
}
// set linear solver strategy
if (atomicRegulator_->use_lumped_lambda_solve()) {
linearSolverType_ = AtomicRegulator::RSL_SOLVE;
}
else {
linearSolverType_ = AtomicRegulator::CG_SOLVE;
}
// base class transfers
GlcKinetostat::construct_transfers();
// atomic force induced by kinetostat
atomKinetostatForce_ = new AtomicKinetostatForceVelocity(atc_);
interscaleManager.add_per_atom_quantity(atomKinetostatForce_,
regulatorPrefix_+"AtomKinetostatForce");
// restricted force due to kinetostat
nodalAtomicLambdaForce_ = new AtfShapeFunctionRestriction(atc_,
atomKinetostatForce_,
interscaleManager.per_atom_sparse_matrix("Interpolant"));
interscaleManager.add_dense_matrix(nodalAtomicLambdaForce_,
regulatorPrefix_+"NodalAtomicLambdaForce");
// nodal momentum restricted from atoms
nodalAtomicMomentum_ = interscaleManager.dense_matrix("NodalAtomicMomentum");
}
//--------------------------------------------------------
// initialize
// initializes all method data
//--------------------------------------------------------
void VelocityGlc::initialize()
{
GlcKinetostat::initialize();
// sets up time filter for cases where variables temporally filtered
TimeFilterManager * timeFilterManager = atc_->time_filter_manager();
if (!timeFilterManager->end_equilibrate()) {
lambdaForceFiltered_->set_quantity() = 0.;
timeFilter_->initialize(lambdaForceFiltered_->quantity());
}
}
//--------------------------------------------------------
// apply_mid_corrector:
// apply the kinetostat during the middle of the
// predictor phase
//--------------------------------------------------------
void VelocityGlc::apply_mid_predictor(double dt)
{
double dtLambda = 0.5*dt;
compute_kinetostat(dtLambda);
apply_kinetostat(dtLambda);
}
//--------------------------------------------------------
// apply_post_corrector:
// apply the kinetostat after the corrector phase
//--------------------------------------------------------
void VelocityGlc::apply_post_corrector(double dt)
{
double dtLambda = 0.5*dt;
compute_kinetostat(dtLambda);
apply_kinetostat(dtLambda);
}
//--------------------------------------------------------
// apply_pre_filtering
// applies first step of filtering to
// relevant variables
//--------------------------------------------------------
void VelocityGlc::apply_pre_filtering(double dt)
{
// apply time filtered lambda to atomic fields
DENS_MAT lambdaZero(nNodes_,nsd_);
timeFilter_->apply_pre_step1(lambdaForceFiltered_->set_quantity(),(-1./dt)*lambdaZero,dt);
}
//--------------------------------------------------------
// compute_kinetostat
// manages the solution and application of the
// kinetostat equations and variables
//--------------------------------------------------------
void VelocityGlc::compute_kinetostat(double dt)
{
// initial filtering update
apply_pre_filtering(dt);
// set up rhs
DENS_MAT rhs(nNodes_,nsd_);
this->set_kinetostat_rhs(rhs,dt);
// solve linear system for lambda
solve_for_lambda(rhs,lambda_->set_quantity());
#ifdef OBSOLETE
// compute nodal atomic power
compute_nodal_lambda_force(dt);
// apply kinetostat to atoms
apply_to_atoms(atomVelocities_,atomLambdas_->quantity());
#endif
}
//--------------------------------------------------------
// apply_kinetostat
// manages the application of the
// kinetostat equations and variables
//--------------------------------------------------------
void VelocityGlc::apply_kinetostat(double dt)
{
// compute nodal atomic power
compute_nodal_lambda_force(dt);
// apply kinetostat to atoms
apply_to_atoms(atomVelocities_,atomLambdas_->quantity());
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the right-hand side of the
// kinetostat equations
//--------------------------------------------------------
void VelocityGlc::set_kinetostat_rhs(DENS_MAT & rhs, double /* dt */)
{
// form rhs : sum_a (hatN_Ia * x_ai) - (\dot{Upsilon})_Ii
rhs = nodalAtomicMomentum_->quantity();
rhs -= (mdMassMatrix_.quantity())*(nodalVelocities_.quantity());
}
//--------------------------------------------------------
// compute_nodal_lambda_force
// compute the effective FE force applied
// by the kinetostat
//--------------------------------------------------------
void VelocityGlc::compute_nodal_lambda_force(double dt)
{
const DENS_MAT & myNodalAtomicLambdaForce(nodalAtomicLambdaForce_->quantity());
timeFilter_->apply_pre_step1(lambdaForceFiltered_->set_quantity(),
myNodalAtomicLambdaForce,dt);
// update FE displacements for localized thermostats
apply_localization_correction(myNodalAtomicLambdaForce,
nodalVelocities_.set_quantity(),
dt);
}
//--------------------------------------------------------
// set_weights
// sets diagonal weighting matrix used in
// solve_for_lambda
//--------------------------------------------------------
void VelocityGlc::set_weights()
{
if (lambdaAtomMap_) {
MappedAtomQuantity * myWeights = new MappedAtomQuantity(atc_,atomMasses_,lambdaAtomMap_);
weights_ = myWeights;
(atc_->interscale_manager()).add_per_atom_quantity(myWeights,
"AtomMassesMapped");
}
else {
weights_ = atomMasses_;
}
}
//--------------------------------------------------------
// apply_localization_correction
// corrects for localized kinetostats only
// solving kinetostat equations on a subset
// of the MD region
//--------------------------------------------------------
void VelocityGlc::apply_localization_correction(const DENS_MAT & source,
DENS_MAT & nodalField,
double weight)
{
DENS_MAT nodalLambdaRoc(nNodes_,nsd_);
atc_->apply_inverse_mass_matrix(source,
nodalLambdaRoc,
VELOCITY);
set<pair<int,int> >::const_iterator iter;
for (iter = hooverNodes_.begin(); iter != hooverNodes_.end(); ++iter) {
nodalLambdaRoc(iter->first,iter->second) = 0.;
}
nodalField += weight*nodalLambdaRoc;
}
//--------------------------------------------------------
// output:
// adds all relevant output to outputData
//--------------------------------------------------------
void VelocityGlc::output(OUTPUT_LIST & outputData)
{
_nodalAtomicLambdaForceOut_ = nodalAtomicLambdaForce_->quantity();
if ((atc_->lammps_interface())->rank_zero()) {
outputData[regulatorPrefix_+"LambdaMomentum"] = &(lambda_->set_quantity());
outputData[regulatorPrefix_+"NodalLambdaForce"] = &(_nodalAtomicLambdaForceOut_);
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class VelocityGlcFiltered
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
VelocityGlcFiltered::VelocityGlcFiltered(AtomicRegulator *kinetostat)
: VelocityGlc(kinetostat),
nodalAtomicVelocities_(atc_->nodal_atomic_field(VELOCITY))
{
// do nothing
}
//--------------------------------------------------------
// apply_pre_filtering
// applies first step of filtering to
// relevant variables
//--------------------------------------------------------
void VelocityGlcFiltered::apply_pre_filtering(double dt)
{
// apply time filtered lambda to atomic fields
VelocityGlc::apply_pre_filtering(dt);
DENS_MAT nodalAcceleration(nNodes_,nsd_);
atc_->apply_inverse_md_mass_matrix(lambdaForceFiltered_->quantity(),
nodalAcceleration,
VELOCITY);
nodalAtomicVelocities_ += dt*nodalAcceleration;
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the right-hand side of the
// kinetostat equations
//--------------------------------------------------------
void VelocityGlcFiltered::set_kinetostat_rhs(DENS_MAT & rhs, double dt)
{
// form rhs : sum_a (hatN_Ia * x_ai) - (Upsilon)_Ii
double coef = 1./(timeFilter_->unfiltered_coefficient_pre_s1(dt));
rhs = coef*(mdMassMatrix_.quantity())*(nodalAtomicVelocities_.quantity() - nodalVelocities_.quantity());
}
//--------------------------------------------------------
// compute_nodal_lambda_force
// compute the effective FE force applied
// by the kinetostat
//--------------------------------------------------------
void VelocityGlcFiltered::compute_nodal_lambda_force(double dt)
{
const DENS_MAT & myNodalAtomicLambdaForce(nodalAtomicLambdaForce_->quantity());
DENS_MAT & myLambdaForceFiltered(lambdaForceFiltered_->set_quantity());
timeFilter_->apply_post_step1(myLambdaForceFiltered,myNodalAtomicLambdaForce,dt);
// update filtered atomic displacements
DENS_MAT nodalLambdaRoc(myNodalAtomicLambdaForce.nRows(),myNodalAtomicLambdaForce.nCols());
atc_->apply_inverse_md_mass_matrix(myNodalAtomicLambdaForce,
nodalLambdaRoc,
VELOCITY);
timeFilter_->apply_post_step1(nodalAtomicVelocities_.set_quantity(),dt*nodalLambdaRoc,dt);
// update FE displacements for localized thermostats
apply_localization_correction(myLambdaForceFiltered,
nodalVelocities_.set_quantity(),
dt);
}
//--------------------------------------------------------
// output:
// adds all relevant output to outputData
//--------------------------------------------------------
void VelocityGlcFiltered::output(OUTPUT_LIST & outputData)
{
if ((atc_->lammps_interface())->rank_zero()) {
outputData[regulatorPrefix_+"Lambda"] = &(lambda_->set_quantity());
outputData[regulatorPrefix_+"NodalLambdaForce"] = &(lambdaForceFiltered_->set_quantity());
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class StressFlux
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
StressFlux::StressFlux(AtomicRegulator * kinetostat) :
GlcKinetostat(kinetostat),
nodalForce_(atc_->field_rhs(VELOCITY)),
nodalAtomicForce_(nullptr),
nodalGhostForce_(nullptr),
momentumSource_(atc_->atomic_source(VELOCITY))
{
// flag for performing boundary flux calculation
fieldMask_(VELOCITY,FLUX) = true;
}
StressFlux::~StressFlux()
{
// do nothing
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void StressFlux::construct_transfers()
{
InterscaleManager & interscaleManager(atc_->interscale_manager());
// set up node mappings
create_node_maps();
// set up shape function matrix
if (this->use_local_shape_functions()) {
lambdaAtomMap_ = new AtomToElementset(atc_,elementMask_);
interscaleManager.add_per_atom_int_quantity(lambdaAtomMap_,
regulatorPrefix_+"LambdaAtomMap");
shapeFunctionMatrix_ = new LocalLambdaCouplingMatrix(atc_,
lambdaAtomMap_,
nodeToOverlapMap_);
}
else {
shapeFunctionMatrix_ = new LambdaCouplingMatrix(atc_,nodeToOverlapMap_);
}
interscaleManager.add_per_atom_sparse_matrix(shapeFunctionMatrix_,
regulatorPrefix_+"LambdaCouplingMatrixMomentum");
// set linear solver strategy
if (atomicRegulator_->use_lumped_lambda_solve()) {
linearSolverType_ = AtomicRegulator::RSL_SOLVE;
}
else {
linearSolverType_ = AtomicRegulator::CG_SOLVE;
}
// base class transfers
GlcKinetostat::construct_transfers();
// force at nodes due to atoms
nodalAtomicForce_ = interscaleManager.dense_matrix("NodalAtomicForce");
// atomic force induced by kinetostat
atomKinetostatForce_ = new AtomicKinetostatForceStress(atc_,atomLambdas_);
interscaleManager.add_per_atom_quantity(atomKinetostatForce_,
regulatorPrefix_+"AtomKinetostatForce");
// restricted force due to kinetostat
nodalAtomicLambdaForce_ = new AtfShapeFunctionRestriction(atc_,
atomKinetostatForce_,
interscaleManager.per_atom_sparse_matrix("Interpolant"));
interscaleManager.add_dense_matrix(nodalAtomicLambdaForce_,
regulatorPrefix_+"NodalAtomicLambdaForce");
// sets up space for ghost force related variables
if (atc_->groupbit_ghost()) {
GhostCouplingMatrix * shapeFunctionGhost = new GhostCouplingMatrix(atc_,interscaleManager.per_atom_sparse_matrix("InterpolantGhost"),
regulatedNodes_,nodeToOverlapMap_);
interscaleManager.add_sparse_matrix(shapeFunctionGhost,
regulatorPrefix_+"GhostCouplingMatrix");
FundamentalAtomQuantity * atomGhostForce = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_FORCE,
GHOST);
nodalGhostForce_ = new AtfShapeFunctionRestriction(atc_,atomGhostForce,
shapeFunctionGhost);
interscaleManager.add_dense_matrix(nodalGhostForce_,
regulatorPrefix_+"NodalGhostForce");
nodalGhostForceFiltered_.reset(nNodes_,nsd_);
}
}
//--------------------------------------------------------
// compute_boundary_flux:
// computes the boundary flux to be consistent with
// the controller
//--------------------------------------------------------
void StressFlux::compute_boundary_flux(FIELDS & fields)
{
GlcKinetostat::compute_boundary_flux(fields);
}
//--------------------------------------------------------
// apply_pre_predictor:
// apply the kinetostat to the atoms in the
// mid-predictor integration phase
//--------------------------------------------------------
void StressFlux::apply_pre_predictor(double dt)
{
double dtLambda = 0.5*dt;
// apply lambda force to atoms
apply_to_atoms(atomVelocities_,atomKinetostatForce_->quantity(),dtLambda);
}
//--------------------------------------------------------
// apply_post_corrector:
// apply the kinetostat to the atoms in the
// post-corrector integration phase
//--------------------------------------------------------
void StressFlux::apply_post_corrector(double dt)
{
double dtLambda = 0.5*dt;
// apply lambda force to atoms
apply_to_atoms(atomVelocities_,atomKinetostatForce_->quantity(),dtLambda);
}
//--------------------------------------------------------
// compute_kinetostat
// manages the solution and application of the
// kinetostat equations and variables
//--------------------------------------------------------
void StressFlux::compute_kinetostat(double dt)
{
// initial filtering update
apply_pre_filtering(dt);
// set up rhs
DENS_MAT rhs(nNodes_,nsd_);
set_kinetostat_rhs(rhs,dt);
// solve linear system for lambda
solve_for_lambda(rhs,lambda_->set_quantity());
// compute nodal atomic power
compute_nodal_lambda_force(dt);
}
//--------------------------------------------------------
// apply_pre_filtering
// applies first step of filtering to
// relevant variables
//--------------------------------------------------------
void StressFlux::apply_pre_filtering(double dt)
{
// apply time filtered lambda force
DENS_MAT lambdaZero(nNodes_,nsd_);
timeFilter_->apply_pre_step1(lambdaForceFiltered_->set_quantity(),lambdaZero,dt);
if (nodalGhostForce_) {
timeFilter_->apply_pre_step1(nodalGhostForceFiltered_.set_quantity(),
nodalGhostForce_->quantity(),dt);
}
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the RHS of the kinetostat equations
// for the coupling parameter lambda
//--------------------------------------------------------
void StressFlux::set_kinetostat_rhs(DENS_MAT & rhs, double /* dt */)
{
// (a) for flux based :
// form rhs : \int N_I r dV - \sum_g N_Ig^* f_g
// sources are set in ATC transfer
rhs.reset(nNodes_,nsd_);
rhs = momentumSource_.quantity();
if (nodalGhostForce_) {
rhs -= nodalGhostForce_->quantity();
}
// (b) for ess. bcs
// form rhs : {sum_a (N_Ia * f_ia) - M_md * (ddupsilon/dt)_I}
DENS_MAT rhsPrescribed = -1.*nodalForce_.quantity();
atc_->apply_inverse_mass_matrix(rhsPrescribed,VELOCITY);
rhsPrescribed = (mdMassMatrix_.quantity())*rhsPrescribed;
rhsPrescribed += nodalAtomicForce_->quantity();
set<pair<int,int> >::const_iterator iter;
for (iter = hooverNodes_.begin(); iter != hooverNodes_.end(); ++iter) {
rhs(iter->first,iter->second) = rhsPrescribed(iter->first,iter->second);
}
}
//--------------------------------------------------------
// compute_nodal_lambda_force
// computes the force induced on the FE
// by applying lambdaForce on the atoms
//--------------------------------------------------------
void StressFlux::compute_nodal_lambda_force(double dt)
{
DENS_MAT myNodalAtomicLambdaForce = nodalAtomicLambdaForce_->quantity();
set<pair<int,int> >::const_iterator iter;
for (iter = hooverNodes_.begin(); iter != hooverNodes_.end(); ++iter) {
myNodalAtomicLambdaForce(iter->first,iter->second) = 0.;
}
timeFilter_->apply_post_step1(lambdaForceFiltered_->set_quantity(),
myNodalAtomicLambdaForce,dt);
}
//--------------------------------------------------------
// add_to_rhs:
// determines what if any contributions to the
// finite element equations are needed for
// consistency with the kinetostat
//--------------------------------------------------------
void StressFlux::add_to_rhs(FIELDS & rhs)
{
// compute the kinetostat force
compute_kinetostat(atc_->dt());
rhs[VELOCITY] += nodalAtomicLambdaForce_->quantity() + boundaryFlux_[VELOCITY].quantity();
}
//--------------------------------------------------------
// apply_lambda_to_atoms
// uses existing lambda to modify given
// atomic quantity
//--------------------------------------------------------
void StressFlux::apply_to_atoms(PerAtomQuantity<double> * atomVelocities,
const DENS_MAT & lambdaForce,
double dt)
{
_deltaVelocity_ = lambdaForce;
_deltaVelocity_ /= atomMasses_->quantity();
_deltaVelocity_ *= dt;
*atomVelocities += _deltaVelocity_;
}
//--------------------------------------------------------
// reset_filtered_ghost_force:
// resets the kinetostat generated ghost force to a
// prescribed value
//--------------------------------------------------------
void StressFlux::reset_filtered_ghost_force(DENS_MAT & target)
{
nodalGhostForceFiltered_ = target;
}
//--------------------------------------------------------
// output:
// adds all relevant output to outputData
//--------------------------------------------------------
void StressFlux::output(OUTPUT_LIST & outputData)
{
_nodalAtomicLambdaForceOut_ = nodalAtomicLambdaForce_->quantity();
DENS_MAT & lambda(lambda_->set_quantity());
if ((atc_->lammps_interface())->rank_zero()) {
outputData[regulatorPrefix_+"Lambda"] = λ
outputData[regulatorPrefix_+"NodalLambdaForce"] = &(_nodalAtomicLambdaForceOut_);
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class StressFluxGhost
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
StressFluxGhost::StressFluxGhost(AtomicRegulator * kinetostat) :
StressFlux(kinetostat)
{
// flag for performing boundary flux calculation
fieldMask_(VELOCITY,FLUX) = false;
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void StressFluxGhost::construct_transfers()
{
StressFlux::construct_transfers();
if (!nodalGhostForce_) {
throw ATC_Error("StressFluxGhost::StressFluxGhost - ghost atoms must be specified");
}
}
//--------------------------------------------------------
// compute_boundary_flux:
// computes the boundary flux to be consistent with
// the controller
//--------------------------------------------------------
void StressFluxGhost::compute_boundary_flux(FIELDS & /* fields */)
{
// This is only used in computation of atomic sources
boundaryFlux_[VELOCITY] = 0.;
}
//--------------------------------------------------------
// add_to_rhs:
// determines what if any contributions to the
// finite element equations are needed for
// consistency with the kinetostat
//--------------------------------------------------------
void StressFluxGhost::add_to_rhs(FIELDS & rhs)
{
// compute the kinetostat force
compute_kinetostat(atc_->dt());
// uses ghost force as the boundary flux to add to the RHS
rhs[VELOCITY] += nodalAtomicLambdaForce_->quantity() + nodalGhostForce_->quantity();
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the RHS of the kinetostat equations
// for the coupling parameter lambda
//--------------------------------------------------------
void StressFluxGhost::set_kinetostat_rhs(DENS_MAT & rhs, double /* dt */)
{
// (a) for flux based :
// form rhs : \int N_I r dV - \sum_g N_Ig^* f_g
// sources are set in ATC transfer
rhs.reset(nNodes_,nsd_);
rhs = momentumSource_.quantity();
// (b) for ess. bcs
// form rhs : {sum_a (N_Ia * f_ia) - M_md * (ddupsilon/dt)_I}
DENS_MAT rhsPrescribed = -1.*nodalForce_.quantity();
atc_->apply_inverse_mass_matrix(rhsPrescribed,VELOCITY);
rhsPrescribed = (mdMassMatrix_.quantity())*rhsPrescribed;
rhsPrescribed += nodalAtomicForce_->quantity();
set<pair<int,int> >::const_iterator iter;
for (iter = hooverNodes_.begin(); iter != hooverNodes_.end(); ++iter) {
rhs(iter->first,iter->second) = rhsPrescribed(iter->first,iter->second);
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class StressFluxFiltered
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
//--------------------------------------------------------
StressFluxFiltered::StressFluxFiltered(AtomicRegulator * kinetostat) :
StressFlux(kinetostat),
nodalAtomicVelocity_(atc_->nodal_atomic_field(VELOCITY))
{
// do nothing
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the RHS of the kinetostat equations
// for the coupling parameter lambda
//--------------------------------------------------------
void StressFluxFiltered::set_kinetostat_rhs(DENS_MAT & rhs, double dt)
{
// set basic terms
// (a) for flux based :
// form rhs : \int N_I r dV - \sum_g N_Ig^* f_g
// sources are set in ATC transfer
rhs.reset(nNodes_,nsd_);
rhs = momentumSource_.quantity() - nodalGhostForceFiltered_.quantity();
// (b) for ess. bcs
// form rhs : {sum_a (N_Ia * f_ia) - M_md * (ddupsilon/dt)_I}
DENS_MAT rhsPrescribed = -1.*nodalForce_.quantity();
atc_->apply_inverse_mass_matrix(rhsPrescribed,VELOCITY);
rhsPrescribed = (mdMassMatrix_.quantity())*rhsPrescribed;
rhsPrescribed += nodalAtomicForce_->quantity();
set<pair<int,int> >::const_iterator iter;
for (iter = hooverNodes_.begin(); iter != hooverNodes_.end(); ++iter) {
rhs(iter->first,iter->second) = rhsPrescribed(iter->first,iter->second);
}
// adjust for application of current lambda force
rhs += lambdaForceFiltered_->quantity();
// correct for time filtering
rhs *= 1./(timeFilter_->unfiltered_coefficient_pre_s1(dt));
}
//--------------------------------------------------------
// apply_lambda_to_atoms
// uses existing lambda to modify given
// atomic quantity
//--------------------------------------------------------
void StressFluxFiltered::apply_to_atoms(PerAtomQuantity<double> * atomVelocities,
const DENS_MAT & lambdaForce,
double dt)
{
StressFlux::apply_to_atoms(atomVelocities,lambdaForce,dt);
// add in corrections to filtered nodal atomice velocity
DENS_MAT velocityRoc(nNodes_,nsd_);
atc_->apply_inverse_md_mass_matrix(lambdaForceFiltered_->quantity(),
velocityRoc,
VELOCITY);
nodalAtomicVelocity_ += dt*velocityRoc;
}
//--------------------------------------------------------
// add_to_rhs:
// determines what if any contributions to the
// finite element equations are needed for
// consistency with the kinetostat
//--------------------------------------------------------
void StressFluxFiltered::add_to_rhs(FIELDS & rhs)
{
// compute kinetostat forces
compute_kinetostat(atc_->dt());
rhs[VELOCITY] += lambdaForceFiltered_->quantity() + boundaryFlux_[VELOCITY].quantity();
}
//--------------------------------------------------------
// output:
// adds all relevant output to outputData
//--------------------------------------------------------
void StressFluxFiltered::output(OUTPUT_LIST & outputData)
{
DENS_MAT & lambda(lambda_->set_quantity());
DENS_MAT & lambdaForceFiltered(lambdaForceFiltered_->set_quantity());
if ((atc_->lammps_interface())->rank_zero()) {
outputData[regulatorPrefix_+"Lambda"] = λ
outputData[regulatorPrefix_+"NodalLambdaForce"] = &lambdaForceFiltered;
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class KinetostatGlcFs
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
KinetostatGlcFs::KinetostatGlcFs(AtomicRegulator * kinetostat,
const string & regulatorPrefix) :
KinetostatShapeFunction(kinetostat,regulatorPrefix),
velocity_(atc_->field(VELOCITY)),
//timeFilter_(atomicRegulator_->time_filter()),
//nodalAtomicLambdaForce_(nullptr),
//lambdaPowerFiltered_(nullptr),
//atomKinetostatForces_(nullptr),
//atomMasses_(nullptr),
nodalAtomicMomentum_(nullptr),
isFirstTimestep_(true),
atomPredictedVelocities_(nullptr),
nodalAtomicPredictedMomentum_(nullptr),
dtFactor_(0.)
{
// constuct/obtain data corresponding to stage 3 of ATC_Method::initialize
nodalAtomicLambdaForce_ = atomicRegulator_->regulator_data(regulatorPrefix_+"NodalAtomicLambdaForce",nsd_);
lambdaForceFiltered_ = atomicRegulator_->regulator_data(regulatorPrefix_+"LambdaForceFiltered",1);
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void KinetostatGlcFs::construct_transfers()
{
// base class transfers
KinetostatShapeFunction::construct_transfers();
InterscaleManager & interscaleManager(atc_->interscale_manager());
// get data from manager
nodalAtomicMomentum_ = interscaleManager.dense_matrix("NodalAtomicMomentum");
// atomic force induced by kinetostat
PerAtomQuantity<double> * atomLambdas = interscaleManager.per_atom_quantity(regulatorPrefix_+"AtomLambdaMomentum");
atomKinetostatForce_ = new AtomicKinetostatForceStress(atc_,atomLambdas);
interscaleManager.add_per_atom_quantity(atomKinetostatForce_,
regulatorPrefix_+"AtomKinetostatForce");
// predicted momentum quantities: atom velocities, atom momenta, and restricted atom momenta
// MAKE THINGS WORK WITH ONLY ONE PREDICTED VELOCITY AND DERIVED QUANTITIES, CHECK IT EXISTS
atomPredictedVelocities_ = new AtcAtomQuantity<double>(atc_,nsd_);
interscaleManager.add_per_atom_quantity(atomPredictedVelocities_,
regulatorPrefix_+"AtomicPredictedVelocities");
AtomicMomentum * atomPredictedMomentum = new AtomicMomentum(atc_,
atomPredictedVelocities_);
interscaleManager.add_per_atom_quantity(atomPredictedMomentum,
regulatorPrefix_+"AtomicPredictedMomentum");
nodalAtomicPredictedMomentum_ = new AtfShapeFunctionRestriction(atc_,
atomPredictedMomentum,
interscaleManager.per_atom_sparse_matrix("Interpolant"));
interscaleManager.add_dense_matrix(nodalAtomicPredictedMomentum_,
regulatorPrefix_+"NodalAtomicPredictedMomentum");
}
//--------------------------------------------------------
// initialize
// initializes all method data
//--------------------------------------------------------
void KinetostatGlcFs::initialize()
{
KinetostatShapeFunction::initialize();
TimeFilterManager * timeFilterManager = atc_->time_filter_manager();
if (!timeFilterManager->end_equilibrate()) {
// we should reset lambda and lambdaForce to zero in this case
// implies an initial condition of 0 for the filtered nodal lambda power
// initial conditions will always be needed when using time filtering
// however, the fractional step scheme must assume the instantaneous
// nodal lambda power is 0 initially because all quantities are in delta form
*lambda_ = 0.; // ensures initial lambda force is zero
*nodalAtomicLambdaForce_ = 0.; // momentum change due to kinetostat
*lambdaForceFiltered_ = 0.; // filtered momentum change due to kinetostats
}
else {
// we can grab lambda power variables using time integrator and atc transfer in cases for equilibration
}
// sets up time filter for cases where variables temporally filtered
if (timeFilterManager->need_reset()) {
// the form of this integrator implies no time filters that require history data can be used
timeFilter_->initialize(nodalAtomicLambdaForce_->quantity());
}
atomKinetostatForce_->quantity(); // initialize
}
//--------------------------------------------------------
// apply_lambda_to_atoms
// uses existing lambda to modify given
// atomic quantity
//--------------------------------------------------------
void KinetostatGlcFs::apply_to_atoms(PerAtomQuantity<double> * atomVelocity,
const DENS_MAN * nodalAtomicMomentum,
const DENS_MAT & lambdaForce,
DENS_MAT & nodalAtomicLambdaForce,
double dt)
{
// compute initial contributions to lambda force
nodalAtomicLambdaForce = nodalAtomicMomentum->quantity();
nodalAtomicLambdaForce *= -1.;
// apply lambda force to atoms
_velocityDelta_ = lambdaForce;
_velocityDelta_ /= atomMasses_->quantity();
_velocityDelta_ *= dt;
(*atomVelocity) += _velocityDelta_;
// finalize lambda force
nodalAtomicLambdaForce += nodalAtomicMomentum->quantity();
}
//--------------------------------------------------------
// full_prediction:
// flag to perform a full prediction calcalation
// for lambda rather than using the old value
//--------------------------------------------------------
bool KinetostatGlcFs::full_prediction()
{
if (isFirstTimestep_ || ((atc_->atom_to_element_map_type() == EULERIAN)
&& (atc_->atom_to_element_map_frequency() > 1)
&& (atc_->step() % atc_->atom_to_element_map_frequency() == 0 ))) {
return true;
}
return false;
}
//--------------------------------------------------------
// apply_pre_predictor:
// apply the kinetostat to the atoms in the
// pre-predictor integration phase
//--------------------------------------------------------
void KinetostatGlcFs::apply_pre_predictor(double dt)
{
DENS_MAT & lambdaForceFiltered(lambdaForceFiltered_->set_quantity());
DENS_MAT & nodalAtomicLambdaForce(nodalAtomicLambdaForce_->set_quantity());
// update filtered forces
timeFilter_->apply_pre_step1(lambdaForceFiltered,nodalAtomicLambdaForce,dt);
// apply lambda force to atoms and compute instantaneous lambda force
this->apply_to_atoms(atomVelocities_,nodalAtomicMomentum_,
atomKinetostatForce_->quantity(),
nodalAtomicLambdaForce,0.5*dt);
// update nodal variables for first half of timestep
this->add_to_momentum(nodalAtomicLambdaForce,deltaMomentum_,0.5*dt);
atc_->apply_inverse_mass_matrix(deltaMomentum_,VELOCITY);
velocity_ += deltaMomentum_;
// start update of filtered lambda force
nodalAtomicLambdaForce = 0.;
timeFilter_->apply_post_step1(lambdaForceFiltered,nodalAtomicLambdaForce,dt);
}
//--------------------------------------------------------
// apply_pre_corrector:
// apply the thermostat to the atoms in the first part
// of the corrector step of the Verlet algorithm
//--------------------------------------------------------
void KinetostatGlcFs::apply_pre_corrector(double dt)
{
(*atomPredictedVelocities_) = atomVelocities_->quantity();
// do full prediction if we just redid the shape functions
if (full_prediction()) {
this->compute_lambda(dt);
}
// apply lambda force to atoms and compute instantaneous lambda power to predict second half of time step
DENS_MAT & myNodalAtomicLambdaForce(nodalAtomicLambdaForce_->set_quantity());
apply_to_atoms(atomPredictedVelocities_,
nodalAtomicPredictedMomentum_,
atomKinetostatForce_->quantity(),
myNodalAtomicLambdaForce,0.5*dt);
// update predicted nodal variables for second half of time step
this->add_to_momentum(myNodalAtomicLambdaForce,deltaMomentum_,0.5*dt);
atc_->apply_inverse_mass_matrix(deltaMomentum_,VELOCITY);
velocity_ += deltaMomentum_;
}
//--------------------------------------------------------
// apply_post_corrector:
// apply the kinetostat to the atoms in the
// post-corrector integration phase
//--------------------------------------------------------
void KinetostatGlcFs::apply_post_corrector(double dt)
{
// remove predicted force effects
DENS_MAT & myVelocity(velocity_.set_quantity());
myVelocity -= deltaMomentum_;
// compute the kinetostat equation and update lambda
this->compute_lambda(dt);
// apply lambda force to atoms and compute instantaneous lambda force for second half of time step
DENS_MAT & nodalAtomicLambdaForce(nodalAtomicLambdaForce_->set_quantity());
this->apply_to_atoms(atomVelocities_,nodalAtomicMomentum_,
atomKinetostatForce_->quantity(),
nodalAtomicLambdaForce,0.5*dt);
// start update of filtered lambda force
timeFilter_->apply_post_step2(lambdaForceFiltered_->set_quantity(),
nodalAtomicLambdaForce,dt);
// update nodal variables for first half of timestep
this->add_to_momentum(nodalAtomicLambdaForce,deltaMomentum_,0.5*dt);
atc_->apply_inverse_mass_matrix(deltaMomentum_,VELOCITY);
velocity_ += deltaMomentum_;
isFirstTimestep_ = false;
}
//--------------------------------------------------------
// compute_kinetostat
// manages the solution and application of the
// kinetostat equations and variables
//--------------------------------------------------------
void KinetostatGlcFs::compute_lambda(double dt)
{
// set up rhs for lambda equation
this->set_kinetostat_rhs(rhs_,0.5*dt);
// solve linear system for lambda
DENS_MAT & lambda(lambda_->set_quantity());
solve_for_lambda(rhs_,lambda);
}
//--------------------------------------------------------
// output:
// adds all relevant output to outputData
//--------------------------------------------------------
void KinetostatGlcFs::output(OUTPUT_LIST & outputData)
{
_lambdaForceOutput_ = nodalAtomicLambdaForce_->quantity();
// approximate value for lambda force
double dt = LammpsInterface::instance()->dt();
_lambdaForceOutput_ *= (2./dt);
DENS_MAT & lambda(lambda_->set_quantity());
if ((atc_->lammps_interface())->rank_zero()) {
outputData[regulatorPrefix_+"LambdaMomentum"] = λ
outputData[regulatorPrefix_+"NodalLambdaForce"] = &(_lambdaForceOutput_);
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class KinetostatFlux
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
KinetostatFlux::KinetostatFlux(AtomicRegulator * kinetostat,
const string & regulatorPrefix) :
KinetostatGlcFs(kinetostat,regulatorPrefix),
momentumSource_(atc_->atomic_source(VELOCITY)),
nodalGhostForce_(nullptr),
nodalGhostForceFiltered_(nullptr)
{
// flag for performing boundary flux calculation
fieldMask_(VELOCITY,FLUX) = true;
// constuct/obtain data corresponding to stage 3 of ATC_Method::initialize
nodalGhostForceFiltered_ = atomicRegulator_->regulator_data(regulatorPrefix_+"NodalGhostForceFiltered",nsd_);
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void KinetostatFlux::construct_transfers()
{
InterscaleManager & interscaleManager(atc_->interscale_manager());
// set up node mappings
create_node_maps();
// set up data for linear solver
shapeFunctionMatrix_ = new LambdaCouplingMatrix(atc_,nodeToOverlapMap_);
interscaleManager.add_per_atom_sparse_matrix(shapeFunctionMatrix_,
regulatorPrefix_+"LambdaCouplingMatrixMomentum");
if (elementMask_) {
lambdaAtomMap_ = new AtomToElementset(atc_,elementMask_);
interscaleManager.add_per_atom_int_quantity(lambdaAtomMap_,
regulatorPrefix_+"LambdaAtomMap");
}
if (atomicRegulator_->use_localized_lambda()) {
linearSolverType_ = AtomicRegulator::RSL_SOLVE;
}
else {
linearSolverType_ = AtomicRegulator::CG_SOLVE;
}
// base class transfers
KinetostatGlcFs::construct_transfers();
// sets up space for ghost force related variables
if (atc_->groupbit_ghost()) {
MatrixDependencyManager<DenseMatrix, int> * nodeToOverlapMap =
interscaleManager.dense_matrix_int(regulatorPrefix_+"NodeToOverlapMap");
GhostCouplingMatrix * shapeFunctionGhost = new GhostCouplingMatrix(atc_,interscaleManager.per_atom_sparse_matrix("InterpolantGhost"),
regulatedNodes_,
nodeToOverlapMap);
interscaleManager.add_sparse_matrix(shapeFunctionGhost,
regulatorPrefix_+"GhostCouplingMatrix");
FundamentalAtomQuantity * atomGhostForce = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_FORCE,
GHOST);
nodalGhostForce_ = new AtfShapeFunctionRestriction(atc_,atomGhostForce,
shapeFunctionGhost);
interscaleManager.add_dense_matrix(nodalGhostForce_,
regulatorPrefix_+"NodalGhostForce");
}
}
//--------------------------------------------------------
// initialize
// initializes all method data
//--------------------------------------------------------
void KinetostatFlux::initialize()
{
KinetostatGlcFs::initialize();
TimeFilterManager * timeFilterManager = atc_->time_filter_manager();
if (!timeFilterManager->end_equilibrate()) {
// we should reset lambda and lambdaForce to zero in this case
// implies an initial condition of 0 for the filtered nodal lambda power
// initial conditions will always be needed when using time filtering
// however, the fractional step scheme must assume the instantaneous
// nodal lambda power is 0 initially because all quantities are in delta form
*nodalGhostForceFiltered_ = 0.; // filtered force from ghost atoms
}
else {
// we can grab lambda power variables using time integrator and atc transfer in cases for equilibration
}
// timestep factor
dtFactor_ = 1.;
}
//--------------------------------------------------------
// construct_regulated_nodes:
// constructs the set of nodes being regulated
//--------------------------------------------------------
void KinetostatFlux::construct_regulated_nodes()
{
InterscaleManager & interscaleManager(atc_->interscale_manager());
// matrix requires all entries even if localized for correct lumping
regulatedNodes_ = interscaleManager.set_int(regulatorPrefix_+"KinetostatRegulatedNodes");
if (!regulatedNodes_) {
regulatedNodes_ = new RegulatedNodes(atc_);
interscaleManager.add_set_int(regulatedNodes_,
regulatorPrefix_+"KinetostatRegulatedNodes");
}
// if localized monitor nodes with applied fluxes
if (atomicRegulator_->use_localized_lambda()) {
if ((atomicRegulator_->coupling_mode() == Kinetostat::FLUX) && (atomicRegulator_->boundary_integration_type() != NO_QUADRATURE)) {
// include boundary nodes
applicationNodes_ = new FluxBoundaryNodes(atc_);
boundaryNodes_ = new BoundaryNodes(atc_);
interscaleManager.add_set_int(boundaryNodes_,
regulatorPrefix_+"KinetostatBoundaryNodes");
}
else {
// fluxed nodes only
applicationNodes_ = new FluxNodes(atc_);
}
interscaleManager.add_set_int(applicationNodes_,
regulatorPrefix_+"KinetostatApplicationNodes");
}
else {
applicationNodes_ = regulatedNodes_;
}
// special set of boundary elements for boundary flux quadrature
if ((atomicRegulator_->boundary_integration_type() == FE_INTERPOLATION)
&& (atomicRegulator_->use_localized_lambda())) {
elementMask_ = interscaleManager.dense_matrix_bool(regulatorPrefix_+"BoundaryElementMask");
if (!elementMask_) {
elementMask_ = new ElementMaskNodeSet(atc_,applicationNodes_);
interscaleManager.add_dense_matrix_bool(elementMask_,
regulatorPrefix_+"BoundaryElementMask");
}
}
}
//--------------------------------------------------------
// apply_pre_predictor:
// apply the kinetostat to the atoms in the
// pre-predictor integration phase
//--------------------------------------------------------
void KinetostatFlux::apply_pre_predictor(double dt)
{
// update filtered forces
if (nodalGhostForce_) {
timeFilter_->apply_pre_step1(nodalGhostForceFiltered_->set_quantity(),
nodalGhostForce_->quantity(),dt);
}
KinetostatGlcFs::apply_pre_predictor(dt);
}
//--------------------------------------------------------
// apply_post_corrector:
// apply the kinetostat to the atoms in the
// post-corrector integration phase
//--------------------------------------------------------
void KinetostatFlux::apply_post_corrector(double dt)
{
// update filtered ghost force
if (nodalGhostForce_) {
timeFilter_->apply_post_step1(nodalGhostForceFiltered_->set_quantity(),
nodalGhostForce_->quantity(),dt);
}
// compute the kinetostat equation and update lambda
KinetostatGlcFs::apply_post_corrector(dt);
}
//--------------------------------------------------------
// add_to_momentum:
// determines what if any contributions to the
// finite element equations are needed for
// consistency with the kinetostat
//--------------------------------------------------------
void KinetostatFlux::add_to_momentum(const DENS_MAT & nodalLambdaForce,
DENS_MAT & deltaMomentum,
double dt)
{
deltaMomentum.resize(nNodes_,nsd_);
const DENS_MAT & boundaryFlux(boundaryFlux_[VELOCITY].quantity());
for (int i = 0; i < nNodes_; i++) {
for (int j = 0; j < nsd_; j++) {
deltaMomentum(i,j) = nodalLambdaForce(i,j) + dt*boundaryFlux(i,j);
}
}
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the RHS of the kinetostat equations
// for the coupling parameter lambda
//--------------------------------------------------------
void KinetostatFlux::set_kinetostat_rhs(DENS_MAT & rhs, double /* dt */)
{
// (a) for flux based :
// form rhs : \int N_I r dV - \sum_g N_Ig^* f_g
// sources are set in ATC transfer
rhs.reset(nNodes_,nsd_);
const DENS_MAT & momentumSource(momentumSource_.quantity());
const set<int> & applicationNodes(applicationNodes_->quantity());
set<int>::const_iterator iNode;
for (iNode = applicationNodes.begin(); iNode != applicationNodes.end(); iNode++) {
for (int j = 0; j < nsd_; j++) {
rhs(*iNode,j) = momentumSource(*iNode,j);
}
}
// add ghost forces, if needed
if (nodalGhostForce_) {
const DENS_MAT & nodalGhostForce(nodalGhostForce_->quantity());
for (iNode = applicationNodes.begin(); iNode != applicationNodes.end(); iNode++) {
for (int j = 0; j < nsd_; j++) {
rhs(*iNode,j) -= nodalGhostForce(*iNode,j);
}
}
}
}
//--------------------------------------------------------
// reset_filtered_ghost_force:
// resets the kinetostat generated ghost force to a
// prescribed value
//--------------------------------------------------------
void KinetostatFlux::reset_filtered_ghost_force(DENS_MAT & target)
{
(*nodalGhostForceFiltered_) = target;
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class KinetostatFluxGhost
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
KinetostatFluxGhost::KinetostatFluxGhost(AtomicRegulator * kinetostat,
const string & regulatorPrefix) :
KinetostatFlux(kinetostat,regulatorPrefix)
{
// flag for performing boundary flux calculation
fieldMask_(VELOCITY,FLUX) = false;
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void KinetostatFluxGhost::construct_transfers()
{
KinetostatFlux::construct_transfers();
if (!nodalGhostForce_) {
throw ATC_Error("KinetostatFluxGhost::KinetostatFluxGhost - ghost atoms must be specified");
}
}
//--------------------------------------------------------
// compute_boundary_flux:
// computes the boundary flux to be consistent with
// the controller
//--------------------------------------------------------
void KinetostatFluxGhost::compute_boundary_flux(FIELDS & /* fields */)
{
// This is only used in computation of atomic sources
boundaryFlux_[VELOCITY] = 0.;
}
//--------------------------------------------------------
// add_to_momentum:
// determines what if any contributions to the
// finite element equations are needed for
// consistency with the kinetostat
//--------------------------------------------------------
void KinetostatFluxGhost::add_to_momentum(const DENS_MAT & nodalLambdaForce,
DENS_MAT & deltaMomentum,
double dt)
{
deltaMomentum.resize(nNodes_,nsd_);
const DENS_MAT & boundaryFlux(nodalGhostForce_->quantity());
for (int i = 0; i < nNodes_; i++) {
for (int j = 0; j < nsd_; j++) {
deltaMomentum(i,j) = nodalLambdaForce(i,j) + dt*boundaryFlux(i,j);
}
}
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the RHS of the kinetostat equations
// for the coupling parameter lambda
//--------------------------------------------------------
void KinetostatFluxGhost::set_kinetostat_rhs(DENS_MAT & rhs, double /* dt */)
{
// (a) for flux based :
// form rhs : \int N_I r dV - \sum_g N_Ig^* f_g
// sources are set in ATC transfer
rhs.reset(nNodes_,nsd_);
const DENS_MAT & momentumSource(momentumSource_.quantity());
const set<int> & applicationNodes(applicationNodes_->quantity());
set<int>::const_iterator iNode;
for (iNode = applicationNodes.begin(); iNode != applicationNodes.end(); iNode++) {
for (int j = 0; j < nsd_; j++) {
rhs(*iNode,j) = momentumSource(*iNode,j);
}
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class KinetostatFixed
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
// Grab references to ATC and kinetostat data
//--------------------------------------------------------
KinetostatFixed::KinetostatFixed(AtomicRegulator * kinetostat,
const string & regulatorPrefix) :
KinetostatGlcFs(kinetostat,regulatorPrefix),
filterCoefficient_(1.)
{
// do nothing
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void KinetostatFixed::construct_transfers()
{
InterscaleManager & interscaleManager(atc_->interscale_manager());
// set up node mappings
create_node_maps();
// determine if map is needed and set up if so
if (this->use_local_shape_functions()) {
lambdaAtomMap_ = new AtomToElementset(atc_,elementMask_);
interscaleManager.add_per_atom_int_quantity(lambdaAtomMap_,
regulatorPrefix_+"LambdaAtomMap");
shapeFunctionMatrix_ = new LocalLambdaCouplingMatrix(atc_,
lambdaAtomMap_,
nodeToOverlapMap_);
}
else {
shapeFunctionMatrix_ = new LambdaCouplingMatrix(atc_,nodeToOverlapMap_);
}
interscaleManager.add_per_atom_sparse_matrix(shapeFunctionMatrix_,
regulatorPrefix_+"LambdaCouplingMatrixMomentum");
linearSolverType_ = AtomicRegulator::CG_SOLVE;
// base class transfers
KinetostatGlcFs::construct_transfers();
}
//--------------------------------------------------------
// initialize
// initializes all method data
//--------------------------------------------------------
void KinetostatFixed::initialize()
{
KinetostatGlcFs::initialize();
// reset data to zero
deltaFeMomentum_.reset(nNodes_,nsd_);
deltaNodalAtomicMomentum_.reset(nNodes_,nsd_);
// initialize filtered energy
TimeFilterManager * timeFilterManager = atc_->time_filter_manager();
if (!timeFilterManager->end_equilibrate()) {
nodalAtomicMomentumFiltered_ = nodalAtomicMomentum_->quantity();
}
// timestep factor
dtFactor_ = 0.5;
}
//--------------------------------------------------------
// halve_force:
// flag to halve the lambda force for improved
// accuracy
//--------------------------------------------------------
bool KinetostatFixed::halve_force()
{
if (isFirstTimestep_ || ((atc_->atom_to_element_map_type() == EULERIAN)
&& (atc_->atom_to_element_map_frequency() > 1)
&& (atc_->step() % atc_->atom_to_element_map_frequency() == 1))) {
return true;
}
return false;
}
//--------------------------------------------------------
// construct_regulated_nodes:
// constructs the set of nodes being regulated
//--------------------------------------------------------
void KinetostatFixed::construct_regulated_nodes()
{
InterscaleManager & interscaleManager(atc_->interscale_manager());
regulatedNodes_ = interscaleManager.set_int(regulatorPrefix_+"RegulatedNodes");
if (!regulatedNodes_) {
if (!atomicRegulator_->use_localized_lambda()) {
regulatedNodes_ = new RegulatedNodes(atc_);
}
else if (atomicRegulator_->coupling_mode() == Kinetostat::FLUX) {
regulatedNodes_ = new FixedNodes(atc_);
}
else if (atomicRegulator_->coupling_mode() == Kinetostat::FIXED) {
// include boundary nodes
regulatedNodes_ = new FixedBoundaryNodes(atc_);
}
else {
throw ATC_Error("KinetostatFixed::construct_regulated_nodes - couldn't determine set of regulated nodes");
}
interscaleManager.add_set_int(regulatedNodes_,
regulatorPrefix_+"RegulatedNodes");
}
applicationNodes_ = regulatedNodes_;
// special set of boundary elements for defining regulated atoms
if (atomicRegulator_->use_localized_lambda()) {
elementMask_ = interscaleManager.dense_matrix_bool(regulatorPrefix_+"BoundaryElementMask");
if (!elementMask_) {
elementMask_ = new ElementMaskNodeSet(atc_,applicationNodes_);
interscaleManager.add_dense_matrix_bool(elementMask_,
regulatorPrefix_+"BoundaryElementMask");
}
}
}
//--------------------------------------------------------
// initialize_delta_nodal_atomic_momentum:
// initializes storage for the variable tracking
// the change in the nodal atomic momentum
// that has occurred over the past timestep
//--------------------------------------------------------
void KinetostatFixed::initialize_delta_nodal_atomic_momentum(double dt)
{
// initialize delta energy
const DENS_MAT & myNodalAtomicMomentum(nodalAtomicMomentum_->quantity());
initialNodalAtomicMomentum_ = myNodalAtomicMomentum;
initialNodalAtomicMomentum_ *= -1.; // initially stored as negative for efficiency
timeFilter_->apply_pre_step1(nodalAtomicMomentumFiltered_.set_quantity(),
myNodalAtomicMomentum,dt);
}
//--------------------------------------------------------
// compute_delta_nodal_atomic_momentum:
// computes the change in the nodal atomic momentum
// that has occurred over the past timestep
//--------------------------------------------------------
void KinetostatFixed::compute_delta_nodal_atomic_momentum(double dt)
{
// set delta energy based on predicted atomic velocities
const DENS_MAT & myNodalAtomicMomentum(nodalAtomicMomentum_->quantity());
timeFilter_->apply_post_step1(nodalAtomicMomentumFiltered_.set_quantity(),
myNodalAtomicMomentum,dt);
deltaNodalAtomicMomentum_ = initialNodalAtomicMomentum_;
deltaNodalAtomicMomentum_ += myNodalAtomicMomentum;
}
//--------------------------------------------------------
// compute_lambda
// sets up and solves linear system for lambda
//--------------------------------------------------------
void KinetostatFixed::compute_lambda(double dt)
{
// compute predicted changes in nodal atomic momentum
compute_delta_nodal_atomic_momentum(dt);
// change in finite element momentum
deltaFeMomentum_ = initialFeMomentum_;
deltaFeMomentum_ += (mdMassMatrix_.quantity())*(velocity_.quantity());
// set up rhs for lambda equation
KinetostatGlcFs::compute_lambda(dt);
}
//--------------------------------------------------------
// apply_pre_predictor:
// apply the kinetostat to the atoms in the
// pre-predictor integration phase
//--------------------------------------------------------
void KinetostatFixed::apply_pre_predictor(double dt)
{
// initialize values to be track change in finite element energy over the timestep
initialize_delta_nodal_atomic_momentum(dt);
initialFeMomentum_ = -1.*((mdMassMatrix_.quantity())*(velocity_.quantity())); // initially stored as negative for efficiency
KinetostatGlcFs::apply_pre_predictor(dt);
}
//--------------------------------------------------------
// apply_pre_corrector:
// apply the kinetostat to the atoms in the first part
// of the corrector step of the Verlet algorithm
//--------------------------------------------------------
void KinetostatFixed::apply_pre_corrector(double dt)
{
// do full prediction if we just redid the shape functions
if (full_prediction()) {
_tempNodalAtomicMomentumFiltered_ = nodalAtomicMomentumFiltered_.quantity();
}
KinetostatGlcFs::apply_pre_corrector(dt);
if (full_prediction()) {
// reset temporary variables
nodalAtomicMomentumFiltered_ = _tempNodalAtomicMomentumFiltered_;
}
}
//--------------------------------------------------------
// apply_post_corrector:
// apply the kinetostat to the atoms in the
// post-corrector integration phase
//--------------------------------------------------------
void KinetostatFixed::apply_post_corrector(double dt)
{
bool halveForce = halve_force();
KinetostatGlcFs::apply_post_corrector(dt);
// update filtered momentum with lambda force
DENS_MAT & myNodalAtomicLambdaForce(nodalAtomicLambdaForce_->set_quantity());
timeFilter_->apply_post_step2(nodalAtomicMomentumFiltered_.set_quantity(),
myNodalAtomicLambdaForce,dt);
if (halveForce) {
// Halve lambda force due to fixed temperature constraints
// 1) makes up for poor initial condition
// 2) accounts for possibly large value of lambda when atomic shape function values change
// from eulerian mapping after more than 1 timestep
// avoids unstable oscillations arising from
// thermostat having to correct for error introduced in lambda changing the
// shape function matrices
*lambda_ *= 0.5;
}
}
//--------------------------------------------------------
// add_to_momentum:
// determines what if any contributions to the
// finite element equations are needed for
// consistency with the kinetostat
//--------------------------------------------------------
void KinetostatFixed::add_to_momentum(const DENS_MAT & nodalLambdaForce,
DENS_MAT & deltaMomentum,
double /* dt */)
{
deltaMomentum.resize(nNodes_,nsd_);
const set<int> & regulatedNodes(regulatedNodes_->quantity());
for (int i = 0; i < nNodes_; i++) {
if (regulatedNodes.find(i) != regulatedNodes.end()) {
for (int j = 0; j < nsd_; j++) {
deltaMomentum(i,j) = 0.;
}
}
else {
for (int j = 0; j < nsd_; j++) {
deltaMomentum(i,j) = nodalLambdaForce(i,j);
}
}
}
}
//--------------------------------------------------------
// set_kinetostat_rhs
// sets up the RHS of the kinetostat equations
// for the coupling parameter lambda
//--------------------------------------------------------
void KinetostatFixed::set_kinetostat_rhs(DENS_MAT & rhs, double dt)
{
// for essential bcs (fixed nodes) :
// form rhs : (delUpsV - delUps)/dt
const set<int> & regulatedNodes(regulatedNodes_->quantity());
double factor = (1./dt);
for (int i = 0; i < nNodes_; i++) {
if (regulatedNodes.find(i) != regulatedNodes.end()) {
for (int j = 0; j < nsd_; j++) {
rhs(i,j) = factor*(deltaNodalAtomicMomentum_(i,j) - deltaFeMomentum_(i,j));
}
}
else {
for (int j = 0; j < nsd_; j++) {
rhs(i,j) = 0.;
}
}
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class KinetostatFluxFixed
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
//--------------------------------------------------------
KinetostatFluxFixed::KinetostatFluxFixed(AtomicRegulator * kinetostat,
bool constructKinetostats) :
RegulatorMethod(kinetostat),
kinetostatFlux_(nullptr),
kinetostatFixed_(nullptr),
kinetostatBcs_(nullptr)
{
if (constructKinetostats) {
if (kinetostat->coupling_mode(VELOCITY) == AtomicRegulator::GHOST_FLUX) {
kinetostatFlux_ = new KinetostatFluxGhost(kinetostat,regulatorPrefix_+"Flux");
}
else {
kinetostatFlux_ = new KinetostatFlux(kinetostat,regulatorPrefix_+"Flux");
}
kinetostatFixed_ = new KinetostatFixed(kinetostat,regulatorPrefix_+"Fixed");
// need to choose BC type based on coupling mode
if (kinetostat->coupling_mode() == AtomicRegulator::FLUX || kinetostat->coupling_mode(VELOCITY) == AtomicRegulator::GHOST_FLUX) {
kinetostatBcs_ = kinetostatFlux_;
}
else if (kinetostat->coupling_mode() == AtomicRegulator::FIXED) {
kinetostatBcs_ = kinetostatFixed_;
}
else {
throw ATC_Error("KinetostatFluxFixed::constructor - invalid kinetostat type provided");
}
}
}
//--------------------------------------------------------
// Destructor
//--------------------------------------------------------
KinetostatFluxFixed::~KinetostatFluxFixed()
{
if (kinetostatFlux_) delete kinetostatFlux_;
if (kinetostatFixed_) delete kinetostatFixed_;
}
//--------------------------------------------------------
// constructor_transfers
// instantiates or obtains all dependency managed data
//--------------------------------------------------------
void KinetostatFluxFixed::construct_transfers()
{
kinetostatFlux_->construct_transfers();
kinetostatFixed_->construct_transfers();
}
//--------------------------------------------------------
// initialize
// initializes all method data
//--------------------------------------------------------
void KinetostatFluxFixed::initialize()
{
kinetostatFlux_->initialize();
kinetostatFixed_->initialize();
}
//--------------------------------------------------------
// apply_predictor:
// apply the thermostat to the atoms in the first step
// of the Verlet algorithm
//--------------------------------------------------------
void KinetostatFluxFixed::apply_pre_predictor(double dt)
{
kinetostatFlux_->apply_pre_predictor(dt);
kinetostatFixed_->apply_pre_predictor(dt);
}
//--------------------------------------------------------
// apply_pre_corrector:
// apply the thermostat to the atoms in the first part
// of the corrector step of the Verlet algorithm
//--------------------------------------------------------
void KinetostatFluxFixed::apply_pre_corrector(double dt)
{
kinetostatFlux_->apply_pre_corrector(dt);
if (kinetostatFixed_->full_prediction()) {
atc_->set_fixed_nodes();
}
kinetostatFixed_->apply_pre_corrector(dt);
}
//--------------------------------------------------------
// apply_post_corrector:
// apply the thermostat to the atoms in the second part
// of the corrector step of the Verlet algorithm
//--------------------------------------------------------
void KinetostatFluxFixed::apply_post_corrector(double dt)
{
kinetostatFlux_->apply_post_corrector(dt);
atc_->set_fixed_nodes();
kinetostatFixed_->apply_post_corrector(dt);
}
//--------------------------------------------------------
// output:
// adds all relevant output to outputData
//--------------------------------------------------------
void KinetostatFluxFixed::output(OUTPUT_LIST & outputData)
{
kinetostatFlux_->output(outputData);
kinetostatFixed_->output(outputData);
}
};
|