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
|
// ATC headers
#include "ATC_Method.h"
#include "LammpsInterface.h"
#include "FE_Engine.h"
#include "Array.h"
#include "Array2D.h"
#include "ATC_Error.h"
#include "Function.h"
#include "PrescribedDataManager.h"
#include "TimeIntegrator.h"
#include "PhysicsModel.h"
#include "PerAtomQuantityLibrary.h"
#include "TransferLibrary.h"
#include "KernelFunction.h"
#include "Utility.h"
#include "FieldManager.h"
#include <fstream>
#include <sstream>
#include <iostream>
using ATC_Utility::sgn;
using ATC_Utility::to_string;
using ATC_Utility::is_dbl;
using std::stringstream;
using std::ifstream;
using std::ofstream;
using std::string;
using std::map;
using std::set;
using std::vector;
using std::pair;
namespace ATC {
ATC_Method::ATC_Method(string groupName, double ** & perAtomArray, LAMMPS_NS::Fix * thisFix) :
nodalAtomicVolume_(nullptr),
needReset_(true),
lammpsInterface_(LammpsInterface::instance()),
interscaleManager_(this),
timeFilterManager_(this),
integrateInternalAtoms_(false),
atomTimeIntegrator_(nullptr),
ghostManager_(this),
feEngine_(nullptr),
initialized_(false),
meshDataInitialized_(false),
localStep_(0),
sizeComm_(8), // 3 positions + 1 material id * 2 for output
atomCoarseGrainingPositions_(nullptr),
atomGhostCoarseGrainingPositions_(nullptr),
atomProcGhostCoarseGrainingPositions_(nullptr),
atomReferencePositions_(nullptr),
nNodes_(0),
nsd_(lammpsInterface_->dimension()),
xref_(nullptr),
readXref_(false),
needXrefProcessorGhosts_(false),
trackDisplacement_(false),
needsAtomToElementMap_(true),
atomElement_(nullptr),
atomGhostElement_(nullptr),
internalElementSet_(""),
atomMasses_(nullptr),
atomPositions_(nullptr),
atomVelocities_(nullptr),
atomForces_(nullptr),
parallelConsistency_(true),
outputNow_(false),
outputTime_(true),
outputFrequency_(0),
sampleFrequency_(0),
sampleCounter_(0),
peScale_(1./(lammpsInterface_->mvv2e())),
keScale_(1.),
scalarFlag_(0),
vectorFlag_(0),
sizeVector_(0),
scalarVectorFreq_(0),
sizePerAtomCols_(4),
perAtomOutput_(nullptr),
perAtomArray_(perAtomArray),
extScalar_(0),
extVector_(0),
extList_(nullptr),
thermoEnergyFlag_(0),
atomVolume_(nullptr),
atomicWeightsWriteFlag_(false),
atomicWeightsWriteFrequency_(0),
atomWeightType_(LATTICE),
domainDecomposition_(REPLICATED_MEMORY),
groupbit_(0),
groupbitGhost_(0),
needProcGhost_(false),
groupTag_(groupName),
nLocal_(0),
nLocalTotal_(0),
nLocalGhost_(0),
atomToElementMapType_(LAGRANGIAN),
atomToElementMapFrequency_(0),
regionID_(-1),
mdMassNormalization_(false),
kernelBased_(false),
kernelOnTheFly_(false),
kernelFunction_(nullptr),
bondOnTheFly_(false),
accumulant_(nullptr),
accumulantMol_(nullptr),
accumulantMolGrad_(nullptr),
accumulantWeights_(nullptr),
accumulantInverseVolumes_(&invNodeVolumes_),
accumulantBandwidth_(0),
useRestart_(false),
hasRefPE_(false),
setRefPE_(false),
setRefPEvalue_(false),
refPEvalue_(0.),
readRefPE_(false),
nodalRefPotentialEnergy_(nullptr),
simTime_(0.0),
stepCounter_(0)
{
lammpsInterface_->print_msg_once("version "+version());
lammpsInterface_->set_fix_pointer(thisFix);
interscaleManager_.set_lammps_data_prefix();
grow_arrays(lammpsInterface_->nmax());
feEngine_ = new FE_Engine(lammpsInterface_->world());
lammpsInterface_->create_compute_pe_peratom();
}
ATC_Method::~ATC_Method()
{
lammpsInterface_->destroy_2d_double_array(xref_);
lammpsInterface_->destroy_2d_double_array(perAtomOutput_);
if (atomTimeIntegrator_) delete atomTimeIntegrator_;
if (feEngine_) delete feEngine_;
}
//--------------------------------------------------
// pack_fields
// bundle all allocated field matrices into a list
// for output needs
//--------------------------------------------------
void ATC_Method::pack_fields(RESTART_LIST & data)
{
map<FieldName,int>::const_iterator field;
for (field = fieldSizes_.begin(); field!=fieldSizes_.end(); field++) {
FieldName thisField = field->first;
string fieldName = field_to_string(thisField);
string matrixName;
// copy all fields from ATC_Method.h
matrixName = "fields_" + fieldName;
data[matrixName] = & fields_[thisField].set_quantity();
matrixName = "dot_fields_" + fieldName;
data[matrixName] = & dot_fields_[thisField].set_quantity();
matrixName = "ddot_fields_" + fieldName;
data[matrixName] = & ddot_fields_[thisField].set_quantity();
matrixName = "dddot_fields_" + fieldName;
data[matrixName] = & dddot_fields_[thisField].set_quantity();
matrixName = "NodalAtomicFieldsRoc_" + fieldName;
data[matrixName] = & nodalAtomicFieldsRoc_[thisField].set_quantity();
}
}
//--------------------------------------------------
// write_restart_file
// bundle matrices that need to be saved and call
// fe_engine to write the file
//--------------------------------------------------
void ATC_Method::write_restart_data(string fileName, RESTART_LIST & data)
{
pack_fields(data);
feEngine_->write_restart_file(fileName,&data);
}
//--------------------------------------------------
// read_restart_file
// bundle matrices that need to be saved and call
// fe_engine to write the file
//--------------------------------------------------
void ATC_Method::read_restart_data(string fileName, RESTART_LIST & data)
{
pack_fields(data);
feEngine_->read_restart_file(fileName,&data);
}
//--------------------------------------------------
// Interactions with LAMMPS fix commands
// parse input command and pass on to finite element engine
// or physics specific transfers if necessary
// revert to physics-specific transfer if no command matches input
// first keyword is unique to particular class
// base class keyword matching must apply to ALL physics
// order: derived, base, owned objects
//--------------------------------------------------
bool ATC_Method::modify(int narg, char **arg)
{
int argIdx=0;
bool match = false;
// gateways to other modules e.g. extrinsic, control, mesh
// pass off to fe engine
if (strcmp(arg[argIdx],"mesh")==0) {
match = feEngine_->modify(narg, arg);
if (feEngine_->has_mesh() && !meshDataInitialized_)
this->initialize_mesh_data();
}
// pass off to time filter
else if (strcmp(arg[argIdx],"filter")==0) {
argIdx++;
match = timeFilterManager_.modify(narg-argIdx,&arg[argIdx]);
// consistentInitialization_ = false;
}
// pass off to kernel function manager
else if (strcmp(arg[argIdx],"kernel")==0) {
argIdx++;
if (kernelFunction_) {
//delete kernelFunction_;
//resetKernelFunction_ = true;
}
kernelFunction_ = KernelFunctionMgr::instance()->function(&arg[argIdx],narg-argIdx);
if (kernelFunction_) match = true;
else ATC_Error("no matching kernel found");
feEngine_->set_kernel(kernelFunction_);
accumulantMol_=&kernelAccumulantMol_; // KKM add
accumulantMolGrad_=&kernelAccumulantMolGrad_; // KKM add
}
// pass off to ghost manager
else if (strcmp(arg[argIdx],"boundary_dynamics")==0) {
argIdx++;
match = ghostManager_.modify(narg-argIdx,&arg[argIdx]);
}
// parsing handled here
else {
if (strcmp(arg[argIdx],"parallel_consistency")==0) {
argIdx++;
//if (!kernelFunction_) { throw ATC_Error("on_the_fly requires a kernel function"); }
if (strcmp(arg[argIdx],"off")==0) parallelConsistency_ = false;
else parallelConsistency_ = true;
match = true;
}
/*! \page man_hardy_on_the_fly fix_modify AtC on_the_fly
\section syntax
fix_modify AtC on_the_fly <bond | kernel> <optional on | off> \n - bond | kernel (keyword) = specifies on-the-fly calculation of bond or
kernel matrix elements \n
- on | off (keyword) = activate or discontinue on-the-fly mode \n
\section examples
<TT> fix_modify AtC on_the_fly bond on </TT> \n <TT> fix_modify AtC on_the_fly kernel </TT> \n
<TT> fix_modify AtC on_the_fly kernel off </TT> \n
\section description
Overrides normal mode of pre-calculating and storing bond pair-to-node a
nd
kernel atom-to-node matrices. If activated, will calculate elements of t
hese
matrices during repeated calls of field computations (i.e. "on-the-fly") and not store them for
future use. \n on flag is optional - if omitted, on_the_fly will be activated for the s
pecified
matrix. Can be deactivated using off flag. \n
\section restrictions
Must be used with the hardy/field type of AtC fix
( see \ref man_fix_atc )
\section related
\section default
By default, on-the-fly calculation is not active (i.e. off). However, code does a memory allocation check to determine if it can store all needed bond and kernel matrix ele ments. If this allocation fails, on-the-fly is activated. \n
*/
else if (strcmp(arg[argIdx],"on_the_fly")==0) {
argIdx++;
//if (!kernelFunction_) { throw ATC_Error("on_the_fly requires a kernel function"); }
if (strcmp(arg[argIdx],"bond")==0) {
argIdx++;
bondOnTheFly_ = true;
if (narg > argIdx && strcmp(arg[argIdx],"off")==0) bondOnTheFly_ = false;
}
else if (strcmp(arg[argIdx],"kernel")==0) {
argIdx++;
kernelOnTheFly_ = true;
if (narg > argIdx && strcmp(arg[argIdx],"off")==0) kernelOnTheFly_ = false;
}
else { throw ATC_Error("unsupported on_the_fly type"); }
match = true;
}
/*! \page man_output fix_modify AtC output
\section syntax
fix_modify AtC output <filename_prefix> <frequency>
[text | full_text | binary | vector_components | tensor_components ]
fix_modify AtC output index [step | time ]
- filename_prefix (string) = prefix for data files
- frequency (integer) = frequency of output in time-steps
- options (keyword/s): \n
text = creates text output of index, step and nodal variable values for unique nodes \n
full_text = creates text output index, nodal id, step, nodal coordinates and nodal variable values for unique and image nodes \n
binary = creates binary Ensight output \n
vector_components = outputs vectors as scalar components \n
tensor_components = outputs tensor as scalar components
(use this for Paraview)\n
\section examples
<TT> fix_modify AtC output heatFE 100 </TT> \n
<TT> fix_modify AtC output hardyFE 1 text tensor_components </TT> \n
<TT> fix_modify AtC output hardyFE 10 text binary tensor_components </TT> \n
<TT> fix_modify AtC output index step </TT> \n
\section description
Creates text and/or binary (Ensight, "gold" format) output of nodal/mesh data
which is transfer/physics specific. Output indexed by step or time is possible.
\section restrictions
\section related
see \ref man_fix_atc
\section default
no default format
output indexed by time
*/
else if (strcmp(arg[argIdx],"output")==0) {
argIdx++;
/*! \page man_output_nodeset fix_modify AtC output nodeset
\section syntax
fix_modify AtC output nodeset <nodeset_name> <operation>
- nodeset_name (string) = name of nodeset to be operated on
- operation (keyword/s): \n
sum = creates nodal sum over nodes in specified nodeset \n
\section examples
<TT> fix_modify AtC output nodeset nset1 sum </TT> \n
\section description
Performs operation over the nodes belonging to specified nodeset
and outputs resulting variable values to GLOBALS file.
\section restrictions
\section related
see \ref man_fix_atc
\section default
none
*/
if (strcmp(arg[argIdx],"nodeset")==0) {
argIdx++;
string nset = arg[argIdx++];
if (strcmp(arg[argIdx],"sum")==0) {
argIdx++;
string field = arg[argIdx];
pair < string, FieldName > id(nset,string_to_field(field));
nsetData_[id] = NODESET_SUM;
match = true;
}
else if (strcmp(arg[argIdx],"average")==0) {
argIdx++;
string field = arg[argIdx];
pair < string, FieldName > id(nset,string_to_field(field));
nsetData_[id] = NODESET_AVERAGE;
match = true;
}
}
/*! \page man_boundary_integral fix_modify AtC output boundary_integral
\section syntax
fix_modify AtC output boundary_integral [field] faceset [name]
- field (string) : name of hardy field
- name (string) : name of faceset
\section examples
<TT> fix_modify AtC output boundary_integral stress faceset loop1 </TT> \n
\section description
Calculates a surface integral of the given field dotted with the
outward normal of the faces and puts output in the "GLOBALS" file
\section restrictions
Must be used with the hardy/field type of AtC fix
( see \ref man_fix_atc )
\section related
\section default
none
*/
/*! \page man_contour_integral fix_modify AtC output contour_integral
\section syntax
fix_modify AtC output contour_integral [field] faceset [name] <axis [x | y | z
]>
- field (string) : name of hardy field
- name (string) : name of faceset
- axis (string) : x or y or z
\section examples
<TT> fix_modify AtC output contour_integral stress faceset loop1 </TT> \n
\section description
Calculates a surface integral of the given field dotted with the
outward normal of the faces and puts output in the "GLOBALS" file
\section restrictions
Must be used with the hardy/field type of AtC fix
( see \ref man_fix_atc )
\section related
\section default
none
*/
else if ( (strcmp(arg[argIdx],"boundary_integral")==0)
|| (strcmp(arg[argIdx],"contour_integral")==0) ) {
FacesetIntegralType type = BOUNDARY_INTEGRAL;
if (strcmp(arg[argIdx],"contour_integral")==0)
type = CONTOUR_INTEGRAL;
argIdx++;
string field(arg[argIdx++]);
if(strcmp(arg[argIdx],"faceset")==0) {
argIdx++;
string name(arg[argIdx++]);
pair <string,string> pair_name(name,field);
fsetData_[pair_name] = type;
match = true;
}
} // end "boundary_integral" || "contour_integral"
/*! \page man_output_elementset fix_modify AtC output elementset
\section syntax
fix_modify AtC output volume_integral <eset_name> <field>
- set_name (string) = name of elementset to be integrated over
- fieldname (string) = name of field to integrate
csum = creates nodal sum over nodes in specified nodeset \n
\section examples
<TT> fix_modify AtC output eset1 mass_density </TT> \n
\section description
Performs volume integration of specified field over elementset
and outputs resulting variable values to GLOBALS file.
\section restrictions
\section related
see \ref man_fix_atc
\section default
none
*/
else if ( (strcmp(arg[argIdx],"volume_integral")==0) ) {
argIdx++;
string name(arg[argIdx++]);
string field(arg[argIdx++]);
pair <string,FieldName> pair_name(name,string_to_field(field));
if (++argIdx < narg) { // keyword average
esetData_[pair_name] = ELEMENTSET_AVERAGE;
}
else {
esetData_[pair_name] = ELEMENTSET_TOTAL;
}
match = true;
}
else if (strcmp(arg[argIdx],"now")==0) {
argIdx++;
double dt = 1.0;
if (argIdx < narg) {
dt = atof(arg[argIdx++]);
}
update_time(dt);
update_step();
outputNow_ = true;
this->output();
outputNow_ = false;
match = true;
}
else
if (strcmp(arg[argIdx],"index")==0) {
argIdx++;
if (strcmp(arg[argIdx],"step")==0) { outputTime_ = false; }
else { outputTime_ = true; }
match = true;
}
else {
outputPrefix_ = arg[argIdx++];
outputFrequency_ = atoi(arg[argIdx++]);
bool ensight_output = false, full_text_output = false;
bool text_output = false, vect_comp = false, tensor_comp = false;
int rank = lammpsInterface_->comm_rank();
for (int i = argIdx; i<narg; ++i) {
if (strcmp(arg[i],"full_text")==0) full_text_output = true;
else if (strcmp(arg[i],"text")==0) text_output = true;
else if (strcmp(arg[i],"binary")==0) ensight_output = true;
else if (strcmp(arg[i],"vector_components")==0) vect_comp = true;
else if (strcmp(arg[i],"tensor_components")==0) tensor_comp = true;
else { throw ATC_Error(" output: unknown keyword "); }
}
if (outputFrequency_>0) {
set<int> otypes;
if (full_text_output || text_output) {
lammpsInterface_->print_msg_once("Warning : text output can create _LARGE_ files");
}
if (full_text_output) otypes.insert(FULL_GNUPLOT);
if (text_output) otypes.insert(GNUPLOT);
if (ensight_output) otypes.insert(ENSIGHT);
if (ntracked() > 0) {
string fstem = field_to_string(SPECIES_CONCENTRATION);
string istem = field_to_intrinsic_name(SPECIES_CONCENTRATION);
vector<string> tnames = tracked_names();
vector<string> fnames;
vector<string> inames;
for (unsigned int i = 0; i < tnames.size(); i++) {
fnames.push_back(fstem+tnames[i]);
inames.push_back(istem+tnames[i]);
}
feEngine_->add_field_names(fstem,fnames);
feEngine_->add_field_names(istem,inames);
}
feEngine_->initialize_output(rank,outputPrefix_,otypes);
if (vect_comp)
feEngine_->output_manager()
->set_option(OUTPUT_VECTOR_COMPONENTS,true);
if (tensor_comp)
feEngine_->output_manager()
->set_option(OUTPUT_TENSOR_COMPONENTS,true);
}
match = true;
}
}
else if (strcmp(arg[argIdx],"write")==0) {
argIdx++;
FieldName thisField;
int thisIndex;
parse_field(arg,argIdx,thisField,thisIndex);
string nsetName(arg[argIdx++]);
string filename(arg[argIdx++]);
stringstream f;
set<int> nodeSet = (feEngine_->fe_mesh())->nodeset(nsetName);
set<int>::const_iterator iset;
const DENS_MAT & field =(fields_.find(thisField)->second).quantity();
for (iset = nodeSet.begin(); iset != nodeSet.end(); iset++) {
int inode = *iset;
double v = field(inode,thisIndex);
f << inode << " " << std::setprecision(17) << v << "\n";
}
LammpsInterface::instance()->write_file(filename,f.str());
match = true;
}
// add a species for tracking
/*! \page man_add_species fix_modify AtC add_species
\section syntax
fix_modify_AtC add_species <TAG> <group|type> <ID> \n
- <TAG> = tag for tracking a species \n
- group|type = LAMMPS defined group or type of atoms \n
- <ID> = name of group or type number \n
\section examples
<TT> fix_modify AtC add_species gold type 1 </TT> \n
<TT> group GOLDGROUP type 1 </TT> \n
<TT> fix_modify AtC add_species gold group GOLDGROUP </TT>
\section description
Associates a tag with all atoms of a specified type or within a specified group. \n
\section restrictions
\section related
\section default
No defaults for this command.
*/
else if (strcmp(arg[argIdx],"add_species")==0) {
argIdx++;
string speciesTag = arg[argIdx];
string tag = arg[argIdx];
argIdx++;
if (strcmp(arg[argIdx],"group")==0) {
if (narg-argIdx == 2) {
string name = arg[++argIdx];
int id = lammpsInterface_->group_bit(name);
groupList_.push_back(id);
groupNames_.push_back(tag);
}
else {
while (++argIdx < narg) {
string name = arg[argIdx];
int id = lammpsInterface_->group_bit(name);
string tag = speciesTag+"-"+name;
groupList_.push_back(id);
groupNames_.push_back(tag);
}
}
}
else if (strcmp(arg[argIdx],"type")==0) {
if (narg-argIdx == 2) {
int id = atoi(arg[++argIdx]);
typeList_.push_back(id);
typeNames_.push_back(tag);
}
else {
while (++argIdx < narg) {
int id = atoi(arg[argIdx]);
string tag = speciesTag+"_"+to_string(id);
typeList_.push_back(id);
typeNames_.push_back(tag);
}
}
}
else {
throw ATC_Error("ATC_Method: add_species only handles groups or types"); }
match = true;
}
// remove species from tracking
/*! \page man_remove_species fix_modify AtC remove_species
\section syntax
fix_modify_AtC delete_species <TAG> \n
- <TAG> = tag for tracking a species \n
\section examples
<TT> fix_modify AtC remove_species gold </TT> \n
\section description
Removes tag designated for tracking a specified species. \n
\section restrictions
\section related
\section default
No defaults for this command.
*/
else if (strcmp(arg[argIdx],"delete_species")==0) {
argIdx++;
string tag = arg[argIdx++];
if (strcmp(arg[argIdx],"group")==0) {
for (unsigned int j = 0; j < groupList_.size(); j++) {
if (tag == groupNames_[j]) {
groupList_.erase(groupList_.begin()+j);
groupNames_.erase(groupNames_.begin()+j);
break;
}
}
}
else if (strcmp(arg[argIdx],"type")==0) {
for (unsigned int j = 0; j < typeList_.size(); j++) {
if (tag == typeNames_[j]) {
typeList_.erase(typeList_.begin()+j);
typeNames_.erase(typeNames_.begin()+j);
break;
}
}
}
else {
throw ATC_Error("ATC_Method: delete_species only handles groups or types"); }
match = true;
}
// add a molecule for tracking
/*! \page man_add_molecule fix_modify AtC add_molecule
\section syntax
fix_modify_AtC add_molecule <small|large> <TAG> <GROUP_NAME> \n
- small|large = can be small if molecule size < cutoff radius, must be large otherwise \n
- <TAG> = tag for tracking a species \n
- <GROUP_NAME> = name of group that tracking will be applied to \n
\section examples
<TT> group WATERGROUP type 1 2 </TT> \n
<TT> fix_modify AtC add_molecule small water WATERGROUP </TT> \n
\section description
Associates a tag with all molecules corresponding to a specified group. \n
\section restrictions
\section related
\section default
No defaults for this command.
*/
else if (strcmp(arg[argIdx],"add_molecule")==0) {
argIdx++;
MolSize size;
if (strcmp(arg[argIdx],"small")==0) {
size = MOL_SMALL;
//needXrefProcessorGhosts_ = true;
needProcGhost_ = true;
}
else
throw ATC_Error("ATC_CouplingMass: Bad molecule size in add_molecule");
argIdx++;
string moleculeTag = arg[argIdx];
argIdx++;
int groupBit = lammpsInterface_->group_bit(arg[argIdx]);
moleculeIds_[moleculeTag] = pair<MolSize,int>(size,groupBit);
match = true;
}
// remove molecule from tracking
/*! \page man_remove_molecule fix_modify AtC remove_molecule
\section syntax
fix_modify_AtC remove_molecule <TAG> \n
- <TAG> = tag for tracking a molecule type \n
\section examples
<TT> fix_modify AtC remove_molecule water </TT> \n
\section description
Removes tag designated for tracking a specified set of molecules. \n
\section restrictions
\section related
\section default
No defaults for this command.
*/
else if (strcmp(arg[argIdx],"remove_molecule")==0) {
argIdx++;
string moleculeTag = arg[argIdx];
moleculeIds_.erase(moleculeTag);
taggedDensMan_.erase(moleculeTag);
}
/*! \page man_boundary fix_modify AtC boundary
\section syntax
fix_modify AtC boundary type <atom-type-id>
- <atom-type-id> = type id for atoms that represent a fictitious
boundary internal to the FE mesh
\section examples
<TT> fix_modify AtC boundary type ghost_atoms </TT>
\section description
Command to define the atoms that represent the fictitious
boundary internal to the FE mesh. For fully overlapped MD/FE
domains with periodic boundary conditions no boundary atoms should
be defined.
\section restrictions
\section default
none
*/
else if (strcmp(arg[argIdx],"boundary")==0) {
argIdx++;
groupTagGhost_ = arg[argIdx++];
match = true;
}
/*! \page man_internal_atom_integrate fix_modify AtC internal_atom_integrate
\section syntax
fix_modify AtC internal_atom_integrate <on | off>
<TT> fix_modify AtC internal_atom_integrate on </TT>
\section description
Has AtC perform time integration for the atoms in the group on which it operates. This does not include boundary atoms.
\section restrictions
AtC must be created before any fixes doing time integration. It must be on for coupling methods which impose constraints on velocities during the first verlet step, e.g. control momentum glc_velocity.
\section default
on for coupling methods, off for post-processors
off
*/
else if (strcmp(arg[argIdx],"internal_atom_integrate")==0) {
argIdx++;
if (strcmp(arg[argIdx],"off")==0) {
integrateInternalAtoms_ = false;
match = true;
}
else {
integrateInternalAtoms_ = true;
match = true;
}
}
/*! \page man_internal_element_set fix_modify AtC internal_element_set
\section syntax
fix_modify AtC internal_element_set <element-set-name>
- <element-set-name> = name of element set defining internal region, or off
\section examples
<TT> fix_modify AtC internal_element_set myElementSet </TT>
<TT> fix_modify AtC internal_element_set off </TT>
\section description
Enables AtC to base the region for internal atoms to be an element set.
If no ghost atoms are used, all the AtC atoms must be constrained to remain
in this element set by the user, e.g., with walls. If boundary atoms are
used in conjunction with Eulerian atom maps
AtC will partition all atoms of a boundary or internal type to be of type internal
if they are in the internal region or to be of type boundary otherwise.
\section restrictions
If boundary atoms are used in conjunction with Eulerian atom maps, the Eulerian
reset frequency must be an integer multiple of the Lammps reneighbor frequency
\section related
see \ref atom_element_map_type and \ref boundary
\section default
off
*/
else if (strcmp(arg[argIdx],"internal_element_set")==0) {
argIdx++;
if (strcmp(arg[argIdx],"off")==0) {
internalElementSet_ = "";
match = true;
}
else {
internalElementSet_ = string(arg[argIdx]);
const set<int> & elementSet((feEngine_->fe_mesh())->elementset(internalElementSet_)); // check it exists and is not trivial
if (elementSet.size()==0) throw ATC_Error("internal_element_set - element set " + internalElementSet_ + " has no elements");
match = true;
}
}
/*! \page man_atom_weight fix_modify AtC atom_weight
\section syntax
fix_modify AtC atom_weight <method> <arguments>
- <method> = \n
value: atoms in specified group assigned constant value given \n
lattice: volume per atom for specified lattice type (e.g. fcc) and parameter \n
element: element volume divided among atoms within element \n
region: volume per atom determined based on the atom count in the MD regions and their volumes. Note: meaningful only if atoms completely fill all the regions. \n
group: volume per atom determined based on the atom count in a group and its volume\n
read_in: list of values for atoms are read-in from specified file \n
\section examples
<TT> fix_modify atc atom_weight constant myatoms 11.8 </TT> \n
<TT> fix_modify atc atom_weight lattice </TT> \n
<TT> fix_modify atc atom_weight read-in atm_wt_file.txt </TT> \n
\section description
Command for assigning the value of atomic weights used for atomic integration in
atom-continuum coupled simulations.
\section restrictions
Use of lattice option requires a lattice type and parameter is already specified.
\section related
\section default
lattice
*/
else if (strcmp(arg[argIdx],"atom_weight")==0) {
argIdx++;
if (strcmp(arg[argIdx],"constant")==0) {
argIdx++;
atomWeightType_ = USER;
int groupbit = -1;
if (strcmp(arg[argIdx],"all")==0) {
}
else {
groupbit = lammpsInterface_->group_bit(arg[argIdx]);
}
argIdx++;
double value = atof(arg[argIdx]);
Valpha_[groupbit] = value;
match = true;
}
else if (strcmp(arg[argIdx],"lattice")==0) {
atomWeightType_ = LATTICE;
match = true;
}
else if (strcmp(arg[argIdx],"element")==0) {
atomWeightType_ = ELEMENT;
match = true;
}
else if (strcmp(arg[argIdx],"region")==0) {
atomWeightType_ = REGION;
match = true;
}
else if (strcmp(arg[argIdx],"group")==0) {
atomWeightType_ = GROUP;
match = true;
}
else if (strcmp(arg[argIdx],"multiscale")==0) {
atomWeightType_ = MULTISCALE;
match = true;
}
else if (strcmp(arg[argIdx],"node")==0) {
atomWeightType_ = NODE;
match = true;
}
else if (strcmp(arg[argIdx],"node_element")==0) {
atomWeightType_ = NODE_ELEMENT;
match = true;
}
else if (strcmp(arg[argIdx],"read_in")==0) {
atomWeightType_ = READ_IN;
argIdx++;
atomicWeightsFile_ = arg[argIdx];
match = true;
}
if (match) {
needReset_ = true;
}
}
/*! \page man_decomposition fix_modify AtC decomposition
\section syntax
fix_modify AtC decomposition <type>
- <type> = \n
replicated_memory: nodal information replicated on each processor \n
distributed_memory: only owned nodal information on processor \n
\section examples
<TT> fix_modify atc decomposition distributed_memory </TT> \n
\section description
Command for assigning the distribution of work and memory for parallel runs.
\section restrictions
replicated_memory is appropriate for simulations were the number of nodes << number of atoms
\section related
\section default
replicated_memory
*/
else if (strcmp(arg[argIdx],"decomposition")==0) {
argIdx++;
if (strcmp(arg[argIdx],"replicated_memory")==0) {
domainDecomposition_ = REPLICATED_MEMORY;
match = true;
}
else if (strcmp(arg[argIdx],"distributed_memory")==0) {
domainDecomposition_ = DISTRIBUTED_MEMORY;
match = true;
}
}
/*! \page man_write_atom_weights fix_modify AtC write_atom_weights
\section syntax
fix_modify AtC write_atom_weights <filename> <frequency>
- <filename> = name of file that atomic weights are written to \n
- <frequency> = how often writes will occur \n
\section examples
<TT> fix_modify atc write_atom_weights atm_wt_file.txt 10 </TT> \n
\section description
Command for writing the values of atomic weights to a specified file.
\section restrictions
\section related
\section default
*/
else if (strcmp(arg[argIdx],"write_atom_weights")==0) {
argIdx++;
atomicWeightsFile_ = arg[argIdx];
argIdx++;
atomicWeightsWriteFrequency_ = atoi(arg[argIdx]);
atomicWeightsWriteFlag_ = true;
match = true;
}
/*! \page man_reset_time fix_modify AtC reset_time
\section syntax
fix_modify AtC reset_time <value>
\section examples
<TT> fix_modify atc reset_time 0.0 </TT> \n
\section description
Resets the simulation time counter.
\section restrictions
\section related
\section default
*/
else if (strcmp(arg[argIdx],"reset_time")==0) {
argIdx++;
set_time();
if (narg > argIdx) {
double time = atof(arg[argIdx]);
set_time(time);
}
match = true;
}
/*! \page man_reset_time fix_modify AtC kernel_bandwidth
\section syntax
fix_modify AtC kernel_bandwidth <value>
\section examples
<TT> fix_modify atc kernel_bandwidth 8 </TT> \n
\section description
Sets a maximum parallel bandwidth for the kernel functions during parallel communication. If the command is not issued, the default will be to assume the bandwidth of the kernel matrix corresponds to the number of sampling locations.
\section restrictions
Only is used if kernel functions are being used.
\section related
\section default
Number of sample locations.
*/
else if (strcmp(arg[argIdx],"kernel_bandwidth")==0) {
argIdx++;
accumulantBandwidth_ = atoi(arg[argIdx]);
match = true;
}
/*! \page man_reset_atomic_reference_positions fix_modify AtC reset_atomic_reference_positions
\section syntax
fix_modify AtC reset_atomic_reference_positions
\section examples
<TT> fix_modify atc reset_atomic_reference_positions
\section description
Resets the atomic positions ATC uses to perform point to field operations.
In can be used to use perfect lattice sites in ATC but a thermalized or
deformed lattice in LAMMPS.
\section restrictions
\section related
\section default
Default is off
*/
else if (strcmp(arg[argIdx],"reset_atomic_reference_positions")==0) {
argIdx++;
xRefFile_ = arg[argIdx];
readXref_ = true;
match = true;
}
/*! \page man_set fix_modify AtC set
\section syntax
fix_modify AtC set reference_potential_energy <value_or_filename(optional)>
- value (double) : optional user specified zero point for PE in native LAMMPS energy units \n
- filename (string) : optional user specified string for file of nodal PE values to be read-in
\section examples
<TT> fix_modify AtC set reference_potential_energy </TT> \n
<TT> fix_modify AtC set reference_potential_energy -0.05 </TT> \n
<TT> fix_modify AtC set reference_potential_energy myPEvalues </TT> \n
\section description
Used to set various quantities for the post-processing algorithms.
It sets the zero point for the potential energy density using
the value provided for all nodes, or from the current
configuration of the lattice if no value is provided, or
values provided within the specified filename.
\section restrictions
Must be used with the hardy/field type of AtC fix
( see \ref man_fix_atc )
\section related
\section default
Defaults to lammps zero point i.e. isolated atoms
*/
else if (strcmp(arg[argIdx],"set")==0) {
argIdx++;
if (strcmp(arg[argIdx],"reference_potential_energy")==0) {
argIdx++;
setRefPE_ = true;
if (narg > argIdx) {
string a(arg[argIdx]);
if (is_dbl(a)) {
double value = atof(arg[argIdx]);
refPEvalue_ = value;
setRefPEvalue_ = true;
}
else {
nodalRefPEfile_ = arg[argIdx];
readRefPE_ = true;
}
}
match = true;
}
} // end "set"
/*! \page man_atom_element_map fix_modify AtC atom_element_map
\section syntax
fix_modify AtC atom_element_map <eulerian|lagrangian> <frequency> \n
- frequency (int) : frequency of updating atom-to-continuum maps based on the
current configuration - only for eulerian
\section examples
<TT> fix_modify atc atom_element_map eulerian 100 </TT>
\section description
Changes frame of reference from eulerian to lagrangian and sets the
frequency for which the map from atoms to elements is reformed and
all the attendant data is recalculated.
\section restrictions
Cannot change map type after initialization.
\section related
\section default
lagrangian
*/
else if (strcmp(arg[argIdx],"atom_element_map")==0) {
argIdx++;
if (strcmp(arg[argIdx],"eulerian")==0) {
atomToElementMapType_ = EULERIAN;
argIdx++;
atomToElementMapFrequency_ = atoi(arg[argIdx]);
}
else {
atomToElementMapType_ = LAGRANGIAN;
atomToElementMapFrequency_ = 0;
}
match = true;
needReset_ = true;
}
/*! \page man_read_restart fix_modify AtC read_restart
\section syntax
fix_modify AtC read_restart [file_name] \n
\section examples
<TT> fix_modify AtC read_restart ATC_state </TT> \n
\section description
Reads the current state of the fields from a named text-based restart
file.
\section restrictions
The restart file only contains fields and their time derivatives.
The reference positions of the atoms and the commands that initialize
the fix are not saved e.g. an identical mesh containing the same atoms
will have to be recreated.
\section related
see write_restart \ref man_write_restart
\section default
none
*/
else if (strcmp(arg[argIdx],"read_restart")==0) {
argIdx++;
restartFileName_ = arg[argIdx];
useRestart_ = true;
match = true;
}
/*! \page man_write_restart fix_modify AtC write_restart
\section syntax
fix_modify AtC write_restart [file_name] \n
\section examples
<TT> fix_modify AtC write_restart restart.mydata </TT> \n
\section description
Dumps the current state of the fields to a named text-based restart file.
This done when the command is invoked and not repeated, unlike the
similar lammps command.
\section restrictions
The restart file only contains fields and their time derivatives.
The reference positions of the atoms and the commands that initialize
the fix are not saved e.g. an identical mesh containing the same atoms
will have to be recreated.
\section related
see read_restart \ref man_read_restart
\section default
none
*/
else if (strcmp(arg[argIdx],"write_restart")==0) {
argIdx++;
string restartFileName(arg[argIdx]);
RESTART_LIST data;
write_restart_data(restartFileName,data);
match = true;
}
} // end else
return match; // return to FixATC
}
//--------------------------------------------------
// helper function for parser
// handles : "displacement x" and "temperature" by indexing argIdx
// for fluxes : only normal fluxes can be prescribed
//--------------------------------------------------
void ATC_Method::parse_field(/*const*/ char ** args, int & argIdx,
FieldName & thisField)
{
string thisName = args[argIdx++];
thisField = string_to_field(thisName);
map<FieldName,int>::const_iterator iter = fieldSizes_.find(thisField);
if (iter == fieldSizes_.end()) {
throw ATC_Error("Bad field name: "+thisName);
}
}
//--------------------------------------------------
// helper function for parser
// handles : "displacement x" and "temperature" by indexing argIdx
// for fluxes : only normal fluxes can be prescribed
//--------------------------------------------------
void ATC_Method::parse_field(/*const*/ char ** args, int & argIdx,
FieldName & thisField, int & thisIndex)
{
string thisName = args[argIdx++];
if (args[argIdx] == nullptr) {
throw ATC_Error("Need to give field '"+thisName+"' more args");
}
thisField = string_to_field(thisName);
map<FieldName,int>::const_iterator iter = fieldSizes_.find(thisField);
if (iter == fieldSizes_.end()) {
throw ATC_Error("Bad field name: "+thisName);
}
string thisDim = args[argIdx];
thisIndex = 0;
if (string_to_index(thisDim,thisIndex)) {
if ( !( thisIndex < fieldSizes_[thisField]) ) {
throw ATC_Error("Bad field dimension "+thisDim);
}
argIdx++;
}
}
//-------------------------------------------------------------------
// this sets the peratom output
void ATC_Method::update_peratom_output()
{
perAtomArray_ = perAtomOutput_;
// copy values
for (int i = 0; i < lammpsInterface_->nlocal(); i++) {
for (int j = 0; j < nsd_; j++) {
perAtomOutput_[i][j] = xref_[i][j];
}
for (int j = nsd_; j < sizePerAtomCols_; j++) {
perAtomOutput_[i][j] = 0;
}
}
int indx = nsd_;
if (atomVolume_->nRows() > 0) { // kernel Hardy does not compute these
const DIAG_MAT & myAtomicWeights(atomVolume_->quantity());
for (int i = 0; i < nLocal_; i++) {
double wg = myAtomicWeights(i,i);
if (wg > 0) {
int ii = internalToAtom_(i);
perAtomOutput_[ii][indx] = 1./wg;
}
}
}
}
void ATC_Method::adjust_xref_pbc()
{
int nlocal = lammpsInterface_->nlocal();
int xperiodic = lammpsInterface_->xperiodic();
int yperiodic = lammpsInterface_->yperiodic();
int zperiodic = lammpsInterface_->zperiodic();
double **x = lammpsInterface_->xatom();
double boxxlo,boxxhi;
double boxylo,boxyhi;
double boxzlo,boxzhi;
lammpsInterface_->box_bounds(boxxlo,boxxhi,
boxylo,boxyhi,
boxzlo,boxzhi);
// bool changed = false;
for (int i = 0; i < nlocal; i++) {
if (xperiodic) {
if (x[i][0] < boxxlo) {
xref_[i][0] += Xprd_;
// changed = true;
}
if (x[i][0] >= boxxhi) {
xref_[i][0] -= Xprd_;
// changed = true;
}
}
if (yperiodic) {
if (x[i][1] < boxylo) {
xref_[i][1] += Yprd_;
// changed = true;
}
if (x[i][1] >= boxyhi) {
xref_[i][1] -= Yprd_;
// changed = true;
}
}
if (zperiodic) {
if (x[i][2] < boxzlo) {
xref_[i][2] += Zprd_;
// changed = true;
}
if (x[i][2] >= boxzhi) {
xref_[i][2] -= Zprd_;
// changed = true;
}
}
}
// propagate reset if needed
if (atomToElementMapType_ == LAGRANGIAN) {
if (atomCoarseGrainingPositions_) {
atomCoarseGrainingPositions_->force_reset();
}
}
else if (atomReferencePositions_) {
atomReferencePositions_->force_reset();
}
}
//-------------------------------------------------------------------
void ATC_Method::initialize()
{
feEngine_->partition_mesh();
// initialized_ is set to true by derived class initialize()
// localStep_ is a counter within a run or minimize
localStep_ = 0;
// STEP 1) get basic information data from Lammps/fix
// 1a) group ids for all internal atoms
groupbit_ = lammpsInterface_->group_bit(groupTag_);
// 1b) group ids for ghost atoms
groupbitGhost_ = 0;
if (!groupTagGhost_.empty()) {
groupbitGhost_ = lammpsInterface_->group_bit(groupTagGhost_);
}
// 1c) periodicity and box bounds/lengths
if (!initialized_) {
lammpsInterface_->box_periodicity(periodicity[0],
periodicity[1],
periodicity[2]);
lammpsInterface_->box_bounds(box_bounds[0][0],box_bounds[1][0],
box_bounds[0][1],box_bounds[1][1],
box_bounds[0][2],box_bounds[1][2]);
for (int k = 0; k < nsd_; k++) {
box_length[k] = box_bounds[1][k] - box_bounds[0][k];
}
lammpsInterface_->set_reference_box();
// get periodicity data from lammps for parallel exchange to adjust for periodicity
Xprd_ = lammpsInterface_->domain_xprd();
Yprd_ = lammpsInterface_->domain_yprd();
Zprd_ = lammpsInterface_->domain_zprd();
// box_length[0] = Xprd_;
// box_length[1] = Yprd_;
// box_length[2] = Zprd_;
XY_ = lammpsInterface_->domain_xy();
XZ_ = lammpsInterface_->domain_xz();
YZ_ = lammpsInterface_->domain_yz();
}
// STEP 2 computational geometry
// 2a) get basic information from continuum/FE
this->set_continuum_data();
// STEP 2b) set up data structures for computational geometry
if (this->reset_methods()) {
// clear memory manager
interscaleManager_.clear_temporary_data();
atomVolume_ = nullptr;
// reference positions and energy
if (!initialized_) {
double **x = lammpsInterface_->xatom();
for (int i = 0; i < lammpsInterface_->nmax(); i++) {
for (int j = 0; j < nsd_; j++) {
xref_[i][j] = x[i][j];
}
}
// re-write non-ghosts' xref with values from a file
if (readXref_) {
bool success = read_atomic_ref_positions(xRefFile_.c_str());
if (!success)
throw ATC_Error("Error reading atomic reference positions");
readXref_ = false;
}
// ensure initial configuration is consistent with element set
if (internalElementSet_.size() && groupbitGhost_) {
int *mask = lammpsInterface_->atom_mask();
int nlocal = lammpsInterface_->nlocal();
const FE_Mesh * feMesh = feEngine_->fe_mesh();
const set<int> & elementSet(feMesh->elementset(internalElementSet_));
int element;
DENS_VEC coords(nsd_);
for (int i = 0; i < nlocal; ++i) {
if (mask[i] & groupbit_ || mask[i] & groupbitGhost_) {
for (int j = 0; j < nsd_; j++) {
coords(j) = xref_[i][j];
}
element = feMesh->map_to_element(coords);
if (elementSet.find(element) == elementSet.end()) {
mask[i] |= groupbitGhost_;
mask[i] &= ~groupbit_;
}
else {
mask[i] &= ~groupbitGhost_;
mask[i] |= groupbit_;
}
}
}
}
// set up maps from lammps to atc indexing
reset_nlocal();
}
this->set_computational_geometry();
}
// 2c) basic data regarding atomic system, e.g. atom coordinates
if (atomToElementMapType_ == EULERIAN) {
reset_coordinates();
}
// STEP 3) set up variables which will be integrated in time
this->construct_time_integration_data();
// STEP 4) instantiate all the various specific algorithms and methods
this->construct_methods();
// STEP 5) construct dependency-managed data
// 5b) all other transfer operators
// needs to be done before every run in case options have changed or the atoms have been changed by the user
if (this->reset_methods()) {
// construct all the needed data structures
this->construct_transfers();
// allocate all space needed for lammps arrays
interscaleManager_.grow_arrays(lammpsInterface_->nmax());
}
// reset all computes invoked flags and lammps data
interscaleManager_.lammps_force_reset();
// STEP 6) initialize data
// 6b) size quantities which use pack_comm
interscaleManager_.size_comm_quantities();
// 6c) set coarse-graining functions and atomic weights
if (!initialized_) {
// FE_Engine allocates all required memory
// assume initial atomic position is the reference position for now
// \int_\Omega N_I dV : static if the mesh is
NodeVolumes_.reset(nNodes_,nNodes_);
invNodeVolumes_.reset(nNodes_,nNodes_);
feEngine_->compute_lumped_mass_matrix(NodeVolumes_);
invNodeVolumes_.set_quantity() = NodeVolumes_.inv();
}
atomVolume_->set_reset();
// 6d) reference values
this->set_reference_potential_energy();
// 6e) atomic output for 0th step
update_peratom_output();
massMatInv_.reset(nNodes_,nNodes_);
feEngine_->compute_lumped_mass_matrix(massMatInv_);
for (int i = 0; i < nNodes_; ++i) {
massMatInv_(i,i) = 1./massMatInv_(i,i);
}
// clear need for resets
needReset_ = false;
}
//-------------------------------------------------------------------
void ATC_Method::set_continuum_data()
{
// initialize finite element engine and get basic properties
if (!initialized_) {
feEngine_->initialize();
if (nsd_!=feEngine_->nsd()) {
throw ATC_Error("Spatial dimensions inconsistent between LAMMPS and ATC");
}
nNodes_ = feEngine_->num_nodes();
}
}
//-------------------------------------------------------------------
void ATC_Method::set_computational_geometry()
{
// set positions used for coarse-graining operators
if (!initialized_) {
if (atomToElementMapType_ == EULERIAN) {
FundamentalAtomQuantity * atomPositionsAll = interscaleManager_.fundamental_atom_quantity(LammpsInterface::ATOM_POSITION,ALL);
ClonedAtomQuantity<double> * myAtomPositions =
new ClonedAtomQuantity<double>(this,atomPositionsAll,INTERNAL);
atomCoarseGrainingPositions_ = myAtomPositions;
interscaleManager_.add_per_atom_quantity(myAtomPositions,
"AtomicCoarseGrainingPositions");
if (trackDisplacement_) {
XrefWrapper * myAtomReferencePositions = new XrefWrapper(this);
atomReferencePositions_ = myAtomReferencePositions;
interscaleManager_.add_per_atom_quantity(myAtomReferencePositions,
"AtomicReferencePositions");
atomReferencePositions_->set_memory_type(PERSISTENT);
}
if (groupbitGhost_) {
myAtomPositions = new ClonedAtomQuantity<double>(this,atomPositionsAll,GHOST);
atomGhostCoarseGrainingPositions_ = myAtomPositions;
interscaleManager_.add_per_atom_quantity(myAtomPositions,
"AtomicGhostCoarseGrainingPositions");
}
if(needProcGhost_){
FundamentalAtomQuantity * atomPositionsAll = interscaleManager_.fundamental_atom_quantity(LammpsInterface::ATOM_POSITION,PROC_GHOST);
ClonedAtomQuantity<double> * myAtomPositions =
new ClonedAtomQuantity<double>(this,atomPositionsAll,PROC_GHOST);
atomProcGhostCoarseGrainingPositions_ = myAtomPositions;
interscaleManager_.add_per_atom_quantity(myAtomPositions,
"AtomicProcGhostCoarseGrainingPositions");
}
}
else {
XrefWrapper * myAtomPositions = new XrefWrapper(this);
atomCoarseGrainingPositions_ = myAtomPositions;
interscaleManager_.add_per_atom_quantity(myAtomPositions,
"AtomicCoarseGrainingPositions");
atomReferencePositions_ = atomCoarseGrainingPositions_;
if (groupbitGhost_) {
myAtomPositions = new XrefWrapper(this,GHOST);
atomGhostCoarseGrainingPositions_ = myAtomPositions;
interscaleManager_.add_per_atom_quantity(myAtomPositions,
"AtomicGhostCoarseGrainingPositions");
}
if (needProcGhost_) {
XrefWrapper * myAtomPositions = new XrefWrapper(this);
atomProcGhostCoarseGrainingPositions_ = myAtomPositions;
interscaleManager_.add_per_atom_quantity(myAtomPositions,
"AtomicProcGhostCoarseGrainingPositions");
}
}
atomCoarseGrainingPositions_->set_memory_type(PERSISTENT);
if (atomGhostCoarseGrainingPositions_) atomGhostCoarseGrainingPositions_->set_memory_type(PERSISTENT);
if (atomProcGhostCoarseGrainingPositions_) atomProcGhostCoarseGrainingPositions_->set_memory_type(PERSISTENT);
}
// Add in atom to element map if using shape functions
if (needsAtomToElementMap_) {
atomElement_ = new AtomToElementMap(this);
interscaleManager_.add_per_atom_int_quantity(atomElement_,"AtomElement");
}
}
//-------------------------------------------------------------------
void ATC_Method::construct_methods()
{
if (this->reset_methods()) {
if (atomTimeIntegrator_) delete atomTimeIntegrator_;
if (integrateInternalAtoms_) {
atomTimeIntegrator_ = new AtomTimeIntegratorType(this,INTERNAL);
}
else {
atomTimeIntegrator_ = new AtomTimeIntegrator();
}
// set up integration schemes for ghosts
ghostManager_.construct_methods();
}
}
//-------------------------------------------------------------------
void ATC_Method::construct_transfers()
{
this->construct_interpolant();
this->construct_molecule_transfers();
atomTimeIntegrator_->construct_transfers();
ghostManager_.construct_transfers();
}
//-------------------------------------------------------------------
PerAtomDiagonalMatrix<double> * ATC_Method::create_atom_volume()
{
if (atomVolume_) {
return atomVolume_;
}
else {
// set variables to compute atomic weights
DENS_MAN * nodalVolume(nullptr);
switch (atomWeightType_) {
case USER:
atomVolume_ = new AtomVolumeUser(this,Valpha_);
break;
case LATTICE:
atomVolume_ = new AtomVolumeLattice(this);
break;
case ELEMENT:
atomVolume_ = new AtomVolumeElement(this);
break;
case REGION:
atomVolume_ = new AtomVolumeRegion(this);
break;
case GROUP:
atomVolume_ = new AtomVolumeGroup(this,Valpha_);
break;
case MULTISCALE:
if (!shpFcn_) {
throw ATC_Error("ATC_Method::create_atom_volume - Multiscale algorithm requires an interpolant");
}
nodalVolume = new NodalAtomVolume(this,shpFcn_);
interscaleManager_.add_dense_matrix(nodalVolume,"NodalAtomVolume");
atomVolume_ = new FtaShapeFunctionProlongationDiagonalMatrix(this,nodalVolume,shpFcn_);
break;
case NODE:
if (!shpFcn_) {
throw ATC_Error("ATC_Method::create_atom_volume - Node algorithm requires an interpolant");
}
nodalVolume = new NodalVolume(this,shpFcn_);
interscaleManager_.add_dense_matrix(nodalVolume,"NodalVolume");
atomVolume_ = new FtaShapeFunctionProlongationDiagonalMatrix(this,nodalVolume,shpFcn_);
break;
case NODE_ELEMENT:
if (!shpFcn_) {
throw ATC_Error("ATC_Method::create_atom_volume - Node-Element algorithm requires an interpolant");
}
nodalVolume = new NodalAtomVolumeElement(this,shpFcn_);
interscaleManager_.add_dense_matrix(nodalVolume,"NodalAtomVolumeElement");
atomVolume_ = new FtaShapeFunctionProlongationDiagonalMatrix(this,nodalVolume,shpFcn_);
break;
case READ_IN:
atomVolume_ = new AtomVolumeFile(this,atomicWeightsFile_);
break;
}
if (atomVolume_) {
interscaleManager_.add_per_atom_diagonal_matrix(atomVolume_,"AtomVolume");
}
else {
throw ATC_Error("ATC_Method::create_atom_volume - bad option for atom volume algorithm");
}
return atomVolume_;
}
}
//--------------------------------------------------------
void ATC_Method::init_integrate()
{
atomTimeIntegrator_->init_integrate_velocity(dt());
ghostManager_.init_integrate_velocity(dt());
// account for other fixes doing time integration
interscaleManager_.fundamental_force_reset(LammpsInterface::ATOM_VELOCITY);
atomTimeIntegrator_->init_integrate_position(dt());
ghostManager_.init_integrate_position(dt());
// account for other fixes doing time integration
interscaleManager_.fundamental_force_reset(LammpsInterface::ATOM_POSITION);
}
//-------------------------------------------------------------------
void ATC_Method::post_init_integrate()
{
ghostManager_.post_init_integrate();
}
//-------------------------------------------------------------------
void ATC_Method::pre_exchange()
{
adjust_xref_pbc();
// call interscale manager to sync atc per-atom data with lammps array ahead of parallel communication
interscaleManager_.prepare_exchange();
// change types based on moving from internal region to ghost region
if ((atomToElementMapType_ == EULERIAN) && (step() % atomToElementMapFrequency_ == 0)) {
ghostManager_.pre_exchange();
}
}
//-------------------------------------------------------------------
void ATC_Method::setup_pre_exchange()
{
adjust_xref_pbc();
// call interscale manager to sync atc per-atom data with lammps array ahead of parallel communication
interscaleManager_.prepare_exchange();
}
//-------------------------------------------------------------------
void ATC_Method::pre_neighbor()
{
// reset quantities arising from atom exchange
reset_nlocal();
interscaleManager_.post_exchange();
// forward_comm should go here
}
//-------------------------------------------------------------------
void ATC_Method::min_post_force()
{
post_force();
}
//-------------------------------------------------------------------
void ATC_Method::post_force()
{
// this resets allow for the possibility of other fixes modifying positions and velocities, e.g. walls, but reduces efficiency
interscaleManager_.lammps_force_reset();
}
//--------------------------------------------------------
void ATC_Method::final_integrate()
{
atomTimeIntegrator_->final_integrate(dt());
ghostManager_.final_integrate(dt());
// account for other fixes doing time integration
interscaleManager_.fundamental_force_reset(LammpsInterface::ATOM_VELOCITY);
}
//-------------------------------------------------------------------
void ATC_Method::post_final_integrate()
{
if (atomicWeightsWriteFlag_ && (step() % atomicWeightsWriteFrequency_ == 0)) {
write_atomic_weights(atomicWeightsFile_,atomVolume_->quantity());
}
}
//-------------------------------------------------------------------
void ATC_Method::end_of_step()
{
localStep_ += 1;
}
//--------------------------------------------------------------
void ATC_Method::finish()
{
// FE Engine
if (feEngine_) feEngine_->finish();
feEngine_->departition_mesh();
}
//--------------------------------------------------------------
/** method to add new fields to the included list */
//--------------------------------------------------------------
void ATC_Method::add_fields(map<FieldName,int> & newFieldSizes)
{
map<FieldName,int>::const_iterator field;
for (field = newFieldSizes.begin(); field!=newFieldSizes.end(); field++) {
FieldName thisField = field->first;
int thisSize = field->second;
if (fieldSizes_.find(thisField)==fieldSizes_.end()) {
fieldSizes_[thisField] = thisSize;
}
}
}
//-------------------------------------------------------------------
void ATC_Method::set_reference_potential_energy(void)
{
if (setRefPE_) {
if (setRefPEvalue_) {
nodalRefPotentialEnergy_->set_quantity() = refPEvalue_;
setRefPEvalue_ = false;
}
else if (readRefPE_) {
if (LammpsInterface::instance()->rank_zero()) {
stringstream ss;
ss << "reading reference potential energy from " << nodalRefPEfile_;
LammpsInterface::instance()->print_msg(ss.str());
}
(nodalRefPotentialEnergy_->set_quantity()).from_file(nodalRefPEfile_);
readRefPE_ = false;
}
else {
hasRefPE_ = false;
SPAR_MAN * referenceAccumulant = interscaleManager_.sparse_matrix("ReferenceAccumulant");
if (referenceAccumulant) {
referenceAccumulant->set_quantity() = accumulant_->quantity();
}
DIAG_MAN * referenceAccumulantInverseVolumes = interscaleManager_.diagonal_matrix("ReferenceAccumulantInverseVolumes");
if (referenceAccumulantInverseVolumes) {
referenceAccumulantInverseVolumes->set_quantity() = accumulantInverseVolumes_->quantity();
}
PAQ * atomicRefPe = interscaleManager_.per_atom_quantity("AtomicReferencePotential");
if (!atomicRefPe) {
throw ATC_Error("ATC_Method::set_reference_potential_energy - atomic reference PE object was not created during construct_transfers");
}
PAQ* pe = interscaleManager_.per_atom_quantity("AtomicPotentialEnergy");
if (!pe) {
throw ATC_Error("ATC_Method::set_reference_potential_energy - atomic PE object was not created during construct_transfers");
}
atomicRefPe->set_quantity() = pe->quantity();
atomicRefPe->fix_quantity();
}
setRefPE_ = false;
hasRefPE_ = true;
}
}
//-------------------------------------------------------------------
//=================================================================
// memory management and processor information exchange
//=================================================================
//-----------------------------------------------------------------
// number of doubles
//-----------------------------------------------------------------
int ATC_Method::doubles_per_atom() const
{
int doubles = 4;
doubles += interscaleManager_.memory_usage();
return doubles;
}
//-----------------------------------------------------------------
// memory usage of local atom-based arrays
//-----------------------------------------------------------------
int ATC_Method::memory_usage()
{
int bytes = doubles_per_atom();
bytes *= lammpsInterface_->nmax() * sizeof(double);
return bytes;
}
//-----------------------------------------------------------------
// allocate local atom-based arrays
//-----------------------------------------------------------------
void ATC_Method::grow_arrays(int nmax)
{
xref_ =
lammpsInterface_->grow_2d_double_array(xref_,nmax,3,"fix_atc:xref");
perAtomOutput_ =
lammpsInterface_->grow_2d_double_array(perAtomOutput_,nmax,sizePerAtomCols_,"fix_atc:perAtomOutput");
interscaleManager_.grow_arrays(nmax);
}
//-----------------------------------------------------------------
// copy values within local atom-based arrays
//-----------------------------------------------------------------
void ATC_Method::copy_arrays(int i, int j)
{
xref_[j][0] = xref_[i][0];
xref_[j][1] = xref_[i][1];
xref_[j][2] = xref_[i][2];
for (int ii = 0 ; ii < sizePerAtomCols_ ; ii++ ) {
perAtomOutput_[j][ii] = perAtomOutput_[i][ii];
}
interscaleManager_.copy_arrays(i,j);
}
//-----------------------------------------------------------------
// pack values in local atom-based arrays for exchange with another proc
//-----------------------------------------------------------------
int ATC_Method::pack_exchange(int i, double *buf)
{
buf[0] = xref_[i][0];
buf[1] = xref_[i][1];
buf[2] = xref_[i][2];
int j = 4;
for (int ii = 0 ; ii < sizePerAtomCols_ ; ii++ ) {
buf[j++] = perAtomOutput_[i][ii];
}
int interscaleSizeComm = interscaleManager_.pack_exchange(i,&buf[j]);
return sizeComm_ + interscaleSizeComm;
}
//-----------------------------------------------------------------
// unpack values in local atom-based arrays from exchange with another proc
//-----------------------------------------------------------------
int ATC_Method::unpack_exchange(int nlocal, double *buf)
{
xref_[nlocal][0] = buf[0];
xref_[nlocal][1] = buf[1];
xref_[nlocal][2] = buf[2];
int j = 4;
for (int ii = 0 ; ii < sizePerAtomCols_ ; ii++ ) {
perAtomOutput_[nlocal][ii] = buf[j++];
}
int interscaleSizeComm = interscaleManager_.unpack_exchange(nlocal,&buf[j]);
return sizeComm_ + interscaleSizeComm;
}
//-----------------------------------------------------------------
// pack values in local atom-based arrays from exchange with another proc
//-----------------------------------------------------------------
int ATC_Method::pack_comm(int n, int *list, double *buf,
int pbc_flag, int *pbc)
{
int i,j,m;
double dx = 0,dy = 0,dz = 0;
int * num_bond = lammpsInterface_->num_bond();
int ** bond_atom = lammpsInterface_->bond_atom();
m = 0;
if (pbc_flag == 0) {
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = xref_[j][0];
buf[m++] = xref_[j][1];
buf[m++] = xref_[j][2];
if (num_bond) {
buf[m++] = num_bond[j];
for (int ii = 0; ii < lammpsInterface_->bond_per_atom(); ii++) {
buf[m++] = bond_atom[j][ii];
}
}
}
}
else {
if (lammpsInterface_->domain_triclinic() == 0) {
dx = pbc[0]*Xprd_;
dy = pbc[1]*Yprd_;
dz = pbc[2]*Zprd_;
}
else {
dx = pbc[0]*Xprd_ + pbc[5]*XY_ + pbc[4]*XZ_;
dy = pbc[1]*Yprd_ + pbc[3]*YZ_;
dz = pbc[2]*Zprd_;
}
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = xref_[j][0] + dx;
buf[m++] = xref_[j][1] + dy;
buf[m++] = xref_[j][2] + dz;
if (num_bond) {
buf[m++] = num_bond[j];
for (int ii = 0; ii < lammpsInterface_->bond_per_atom(); ii++) {
buf[m++] = bond_atom[j][ii];
}
}
}
}
return m; // total amount of data sent
}
//-----------------------------------------------------------------
// unpack values in local atom-based arrays from exchange with another proc
//-----------------------------------------------------------------
void ATC_Method::unpack_comm(int n, int first, double *buf)
{
int i,m,last;
int * num_bond = lammpsInterface_->num_bond();
int ** bond_atom = lammpsInterface_->bond_atom();
m = 0;
last = first + n;
for (i = first; i < last; i++) {
xref_[i][0] = buf[m++];
xref_[i][1] = buf[m++];
xref_[i][2] = buf[m++];
if (num_bond) {
num_bond[i] = static_cast<int>(buf[m++]);
for (int ii = 0; ii < lammpsInterface_->bond_per_atom(); ii++) {
bond_atom[i][ii] = static_cast<int>(buf[m++]);
}
}
}
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
int ATC_Method::comm_forward()
{
int size = 3;
if (lammpsInterface_->num_bond())
{ size += lammpsInterface_->bond_per_atom()+1; }
return size;
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
void ATC_Method::reset_nlocal()
{
nLocalTotal_ = lammpsInterface_->nlocal();
const int * mask = lammpsInterface_->atom_mask();
nLocal_ = 0;
nLocalGhost_ = 0;
for (int i = 0; i < nLocalTotal_; ++i) {
if (mask[i] & groupbit_) nLocal_++;
if (mask[i] & groupbitGhost_) nLocalGhost_++;
}
// set up internal & ghost maps
if (nLocal_>0) {
// set map
internalToAtom_.resize(nLocal_);
int j = 0;
// construct internalToAtom map
// : internal index -> local lammps atom index
for (int i = 0; i < nLocalTotal_; ++i) {
if (mask[i] & groupbit_) internalToAtom_(j++) = i;
}
#ifdef EXTENDED_ERROR_CHECKING
stringstream ss;
ss << "Nlocal = " << nLocal_ << " but only found " << j << "atoms";
if (j!=nLocal_) throw ATC_Error(ss.str());
#endif
// construct reverse map
atomToInternal_.clear();
for (int i = 0; i < nLocal_; ++i) {
atomToInternal_[internalToAtom_(i)] = i;
}
}
if (nLocalGhost_>0) {
// set map
ghostToAtom_.resize(nLocalGhost_);
int j = 0;
for (int i = 0; i < nLocalTotal_; ++i) {
if (mask[i] & groupbitGhost_) ghostToAtom_(j++) = i;
}
}
//WIP_JAT this should not be needed at all, but a memory problem with sparse matrices requires them to be reset (possibly related to note in SparseMatrix-inl.h::_delete())
interscaleManager_.reset_nlocal();
}
//-------------------------------------------------------------------
void ATC_Method::reset_coordinates()
{
// update coarse graining positions for internal and ghost atoms
atomCoarseGrainingPositions_->unfix_quantity();
atomCoarseGrainingPositions_->quantity();
atomCoarseGrainingPositions_->fix_quantity();
if (atomGhostCoarseGrainingPositions_) {
atomGhostCoarseGrainingPositions_->unfix_quantity();
atomGhostCoarseGrainingPositions_->quantity();
atomGhostCoarseGrainingPositions_->fix_quantity();
}
if (atomProcGhostCoarseGrainingPositions_) {
atomProcGhostCoarseGrainingPositions_->unfix_quantity();
atomProcGhostCoarseGrainingPositions_->quantity();
atomProcGhostCoarseGrainingPositions_->fix_quantity();
}
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
void ATC_Method::write_atomic_weights(const string filename, const DIAG_MAT & atomicVolumeMatrix)
{
int nlocal = lammpsInterface_->nlocal();
int nlocalmax;
LammpsInterface::instance()->int_allmax(&nlocal,&nlocalmax);
int natoms = int(lammpsInterface_->natoms());
ofstream out;
const char* fname = &filename[0];
// create tag to local id map for this processor
map <int,int> id2tag;
map <int,int>::const_iterator itr;
int * atom_tag = lammpsInterface_->atom_tag();
for (int i = 0; i < nlocal; ++i) {
id2tag[i] = atom_tag[i];
}
int comm_rank = LammpsInterface::instance()->comm_rank();
int nprocs;
LammpsInterface::instance()->int_allmax(&comm_rank,&nprocs);
nprocs += 1;
if (comm_rank == 0) {
out.open(fname);
// print header lines
out << "Atomic Weights for LAMMPS/atc analysis\n";
out << " \n";
out << natoms << " Atoms in system\n";
out << " \n";
// print atomic weights from proc 0
for(int i = 0; i < nlocal; i++) {
out << id2tag[i] << " " << atomicVolumeMatrix(i,i) << "\n";
}
}
if (nprocs > 1) {
int max_size,send_size;
send_size = nlocal;
LammpsInterface::instance()->int_allmax(&send_size,&max_size);
if (comm_rank == 0) {
int *intbuf = new int[max_size];
double *buf = new double[max_size];
for (int iproc = 1; iproc < nprocs; iproc++) {
LammpsInterface::instance()->int_recv(intbuf,max_size,iproc);
LammpsInterface::instance()->recv(buf,max_size,iproc);
for (int i = 0; i < max_size; i++) {
out << intbuf[i] << " " << buf[i] << "\n";
}
}
delete[] intbuf;
delete[] buf;
} else {
int *intbuf = new int[send_size];
double *buf = new double[send_size];
for (int i = 0; i < send_size; i++) {
intbuf[i] = id2tag[i];
buf[i] = atomicVolumeMatrix(i,i);
}
LammpsInterface::instance()->int_send(intbuf,send_size);
LammpsInterface::instance()->send(buf,send_size);
delete[] intbuf;
delete[] buf;
}
}
if (comm_rank == 0) {
out.close();
}
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
void ATC_Method::compute_consistent_md_mass_matrix(const SPAR_MAT & shapeFunctionMatrix,
SPAR_MAT & mdMassMatrix) const
{
int nCols = shapeFunctionMatrix.nCols();
DENS_MAT massMatrixLocal(nCols,nCols);
DENS_MAT denseMdMassMatrix(nCols,nCols);
if (nLocal_>0)
massMatrixLocal = shapeFunctionMatrix.transMat(shapeFunctionMatrix);
lammpsInterface_->allsum(massMatrixLocal.ptr(),
denseMdMassMatrix.ptr(),
denseMdMassMatrix.size());
mdMassMatrix.reset(denseMdMassMatrix,1.e-10);
}
//=================================================================
// Interscale operators
//=================================================================
// in the spirit of the current design of ATC: atoms local, nodes global
bool ATC_Method::nodal_influence(const int groupbit,
set<int> & nset, set<int> & aset, double tol)
{
int nghost = nodal_influence(groupbit,nset,aset,true,tol);
int local_nghost = nghost;
lammpsInterface_->int_allsum(&local_nghost,&nghost);
if (nghost == 0) {
nodal_influence(groupbit,nset,aset,false,tol);
}
return (nghost > 0);
}
int ATC_Method::nodal_influence(const int groupbit,
set<int> & nset, set<int> & aset, bool ghost, double tol)
{
Array<int> & amap = (ghost) ? ghostToAtom_ : internalToAtom_;
int natoms = (ghost) ? nLocalGhost_ : nLocal_;
DENS_MAT influence(nNodes_,1);
DENS_MAT atomInfluence(natoms,1);
const int *mask = lammpsInterface_->atom_mask();
for (int i = 0; i < natoms; i++) {
if (mask[amap(i)] & groupbit) {
atomInfluence(i,0) = 1;
aset.insert(i);
}
}
// relies on shape functions
if (ghost) {
restrict_volumetric_quantity(atomInfluence,influence,(interscaleManager_.per_atom_sparse_matrix("InterpolantGhost"))->quantity());
}
else {
restrict_volumetric_quantity(atomInfluence,influence);
}
DENS_MAT localInfluence = influence;
lammpsInterface_->allsum(localInfluence.ptr(),
influence.ptr(),
influence.size());
for (int i = 0; i < nNodes_; i++) {
if (fabs(influence(i,0)) > tol) { nset.insert(i); }
}
return aset.size();
}
//--------------------------------------------------------
void ATC_Method::restrict_volumetric_quantity(const MATRIX & atomData,
MATRIX & nodeData,
const SPAR_MAT & shpFcn)
{
// computes nodeData = N*DeltaVAtom*atomData where N are the shape functions
DENS_MAT workNodeArray(nodeData.nRows(),nodeData.nCols());
//DENS_MAT workNodeArray;
if (atomData.nRows() > 0) { // or shpFcn_???
workNodeArray = shpFcn.transMat(atomData);
}
int count = nodeData.nRows()*nodeData.nCols();
lammpsInterface_->allsum(workNodeArray.ptr(),nodeData.ptr(),count);
return;
}
//--------------------------------------------------------
void ATC_Method::restrict_volumetric_quantity(const MATRIX & atomData,
MATRIX & nodeData)
{
restrict_volumetric_quantity(atomData,nodeData,shpFcn_->quantity());
return;
}
//--------------------------------------------------------
void ATC_Method::prolong(const MATRIX & nodeData,
MATRIX & atomData)
{
// computes the finite element interpolation at atoms atomData = N*nodeData
if (nLocal_>0) {
atomData = (shpFcn_->quantity())*nodeData;
}
return;
}
//========================================================
// FE functions
//========================================================
//--------------------------------------------------------
void ATC_Method::output()
{
// if (lammpsInterface_->comm_rank() == 0) {
compute_nodeset_output();
compute_faceset_output();
compute_elementset_output();
// }
}
//--------------------------------------------------------
void ATC_Method::compute_nodeset_output(void)
{
map< pair <string, FieldName>, NodesetOperationType >::const_iterator iter;
for (iter = nsetData_.begin(); iter != nsetData_.end();iter++){
pair <string, FieldName> id = iter->first;
string nsetName = id.first;
FieldName field = id.second;
double sum = 0.0;
const set<int> nset = feEngine_->fe_mesh()->nodeset(nsetName);
const DENS_MAT & thisField = (fields_.find(field)->second).quantity();
set< int >::const_iterator itr;
for (itr = nset.begin(); itr != nset.end();itr++){
int node = *itr;
sum += thisField(node,0);
}
string name = nsetName + "_" + field_to_string(field);
if (iter->second == NODESET_AVERAGE) {
sum /= nset.size();
name = "average_"+name;
}
feEngine_->add_global(name, sum);
}
}
//--------------------------------------------------------
void ATC_Method::compute_faceset_output(void)
{
map < pair<string,string>, FacesetIntegralType >::const_iterator iter;
DENS_MAT values;
for (iter = fsetData_.begin(); iter != fsetData_.end(); iter++) {
string bndyName = (iter->first).first;
string fieldName = (iter->first).second;
const set< PAIR > & faceSet = (feEngine_->fe_mesh())->faceset(bndyName);
ATOMIC_DATA::iterator data_iter = filteredData_.find(fieldName);
if (data_iter == filteredData_.end()) {
string msg = "Specified fieldName "+fieldName+
" not found in filteredData_ while attempting surface integration";
throw ATC_Error(msg);
}
const DENS_MAT & data = ((data_iter->second).quantity());
string stem = bndyName + "_" + fieldName + "_";
bool tf = false;
if (iter->second == CONTOUR_INTEGRAL) {
stem = "contour_"+stem;
tf = true;
}
feEngine_->field_surface_flux(data,faceSet,values,tf);
for (int i = 0; i < values.nRows() ; ++i ) {
string name = stem + to_string(i+1);
feEngine_->add_global(name, values(i,0));
}
}
}
//--------------------------------------------------------
void ATC_Method::compute_elementset_output(void)
{
map< pair <string, FieldName>, ElementsetOperationType >::const_iterator iter;
for (iter = esetData_.begin(); iter != esetData_.end();iter++){
pair <string, FieldName> id = iter->first;
string esetName = id.first;
FieldName field = id.second;
const ESET eset = feEngine_->fe_mesh()->elementset(esetName);
const DENS_MAT & thisField = (fields_.find(field)->second).quantity();
DENS_VEC total = feEngine_->integrate(thisField,eset);
string name = esetName + "_" + field_to_string(field);
if (iter->second == ELEMENTSET_AVERAGE) {
DENS_MAT ones(nNodes_,0); ones = 1;
DENS_VEC V = feEngine_->integrate(ones,eset);
total /= V[0];
name = "average_"+name;
}
if (total.size() == 1) {
feEngine_->add_global(name, total[0]);
}
else {
for (int i = 0; i < total.size(); i++) {
feEngine_->add_global(name+to_string(i), total[i]);
}
}
}
}
//=================================================================
//
//=================================================================
//--------------------------------------------------------
bool ATC_Method::read_atomic_ref_positions(const char * filename)
{
int nlocal = lammpsInterface_->nlocal();
ifstream in;
const int lineSize = 256;
char line[lineSize];
// create tag to local id map for this processor
map <int,int> tag2id;
map <int,int>::const_iterator itr;
int * atom_tag = lammpsInterface_->atom_tag();
for (int i = 0; i < nlocal; ++i) {
tag2id[atom_tag[i]] = i;
}
// get number of atoms
int natoms = 0;
int ncols = 0;
int style = LammpsInterface::CHARGE_STYLE;
if (LammpsInterface::instance()->rank_zero()) {
in.open(filename);
string msg;
string name = filename;
msg = "no "+name+" reference file found";
if (! in.good()) throw ATC_Error(msg);
in.getline(line,lineSize); // header
in.getline(line,lineSize); // blank line
in >> natoms;
stringstream ss;
ss << "found " << natoms << " atoms in reference " << filename ;
while(in.good()) {
in.getline(line,lineSize);
string str(line);
int pos = str.find("Atoms");
if (pos > -1) {
in.getline(line,lineSize); // blank line
break;
}
}
in.getline(line,lineSize);
std::vector<std::string> tokens;
ATC_Utility::command_strings(line, tokens);
ncols = tokens.size();
switch (ncols) {
// atomic: id type x y z
case 5:
case 8:
ss << " style:atomic";
style = LammpsInterface::ATOMIC_STYLE;
break;
// charge: id type q x y z
// molecule : id molecule-ID type x y z
case 6:
ss << " style:charge";
style = LammpsInterface::CHARGE_STYLE;
break;
// full : id molecule-ID type q x y z
case 7:
ss << " style:full";
style = LammpsInterface::FULL_STYLE;
break;
default:
throw ATC_Error("cannot determine atom style, columns:"+to_string(ncols));
break;
}
LammpsInterface::instance()->print_msg(ss.str());
in.close();
}
LammpsInterface::instance()->int_broadcast(&natoms);
// read atoms and assign
if (LammpsInterface::instance()->rank_zero()) {
in.open(filename);
while(in.good()) {
in.getline(line,lineSize);
string str(line);
int pos = str.find("Atoms");
if (pos > -1) {
in.getline(line,lineSize); // blank line
break;
}
}
}
int nread = 0,type = -1, tag = -1, count = 0, mId = -1;
double x[3]={0,0,0}, q =0;
while (nread < natoms) {
if (LammpsInterface::instance()->rank_zero()) {
in.getline(line,lineSize);
stringstream ss (line,stringstream::in | stringstream::out);
if (style == LammpsInterface::CHARGE_STYLE)
ss >> tag >> type >> q >> x[0] >> x[1] >> x[2];
else if (style == LammpsInterface::FULL_STYLE)
ss >> tag >> mId >> type >> q >> x[0] >> x[1] >> x[2];
else
ss >> tag >> type >> x[0] >> x[1] >> x[2];
nread++;
}
LammpsInterface::instance()->int_broadcast(&nread);
LammpsInterface::instance()->int_broadcast(&tag);
LammpsInterface::instance()->broadcast(x,3);
itr = tag2id.find(tag);
if (itr != tag2id.end()) {
int iatom = itr->second;
xref_[iatom][0] = x[0];
xref_[iatom][1] = x[1];
xref_[iatom][2] = x[2];
count++;
}
}
if (LammpsInterface::instance()->rank_zero()) {
in.close();
stringstream ss;
ss << "read " << natoms << " reference positions";
LammpsInterface::instance()->print_msg(ss.str());
}
if (count != nlocal)
throw ATC_Error("reset "+to_string(count)+" atoms vs "+to_string(nlocal));
return true;
}
//--------------------------------------------------------
void ATC_Method::remap_ghost_ref_positions(void)
{
int nlocal = lammpsInterface_->nlocal();
int nghost = lammpsInterface_->nghost();
double box_bounds[2][3];
lammpsInterface_->box_bounds(box_bounds[0][0],box_bounds[1][0],
box_bounds[0][1],box_bounds[1][1],
box_bounds[0][2],box_bounds[1][2]);
double xlo = box_bounds[0][0], xhi = box_bounds[1][0];
double ylo = box_bounds[0][1], yhi = box_bounds[1][1];
double zlo = box_bounds[0][2], zhi = box_bounds[1][2];
double box_length[3];
for (int k = 0; k < 3; k++) {
box_length[k] = box_bounds[1][k] - box_bounds[0][k];
}
double Lx = box_length[0], Ly = box_length[1], Lz = box_length[2];
// create tag to local id map for this processor
map <int,int> tag2id;
map <int,int>::const_iterator itr;
int * atom_tag = lammpsInterface_->atom_tag();
for (int i = 0; i < nlocal; ++i) {
tag2id[atom_tag[i]] = i;
}
// loop over ghosts
double ** x = lammpsInterface_->xatom();
for (int j = nlocal; j < nlocal + nghost; j++) {
int tag = atom_tag[j];
int i = tag2id[tag];
//itr = tag2id.find(tag);
//if (itr != tag2id.end())
double* xj = x[j];
double* Xj = xref_[j];
//double Xj[3];
double* Xi = xref_[i];
// the assumption is that xref_[j] has been shuffled
// so make an image of xref_[i] that is close to x[j]
if (xj[0] <= xlo) Xj[0] = Xi[0] -Lx;
if (xj[0] >= xhi) Xj[0] = Xi[0] +Lx;
if (xj[1] <= ylo) Xj[1] = Xi[1] -Ly;
if (xj[1] >= yhi) Xj[1] = Xi[1] +Ly;
if (xj[2] <= zlo) Xj[2] = Xi[2] -Lz;
if (xj[2] >= zhi) Xj[2] = Xi[2] +Lz;
}
}
};
|