1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408
|
"""Chemical Engineering Design Library (ChEDL). Utilities for process modeling.
Copyright (C) 2016, 2017, 2018, 2019, 2020 Caleb Bell.
<Caleb.Andrew.Bell@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This module contains functionality for calculating parameters about different
geometrical forms that come up in engineering practice.
Implemented geometry objects are tanks, helical coils, cooling towers,
air coolers, compact heat exchangers, and plate and frame heat exchangers.
Additional functionality for typical catalyst/adsorbent pellet shapes is also
included.
For reporting bugs, adding feature requests, or submitting pull requests,
please use the `GitHub issue tracker <https://github.com/CalebBell/fluids/>`_
or contact the author at Caleb.Andrew.Bell@gmail.com.
.. contents:: :local:
Main Interfaces
---------------
.. autoclass :: TANK
:members:
:undoc-members:
:show-inheritance:
.. autofunction:: V_tank
.. autofunction:: V_from_h
.. autofunction:: SA_tank
.. autofunction:: SA_from_h
.. autoclass :: HelicalCoil
:members:
:undoc-members:
:show-inheritance:
.. autoclass :: PlateExchanger
:members:
:undoc-members:
:show-inheritance:
.. autoclass :: AirCooledExchanger
:members:
:undoc-members:
:show-inheritance:
.. autoclass :: HyperbolicCoolingTower
:members:
:undoc-members:
:show-inheritance:
.. autoclass :: RectangularFinExchanger
:members:
:undoc-members:
:show-inheritance:
.. autoclass :: RectangularOffsetStripFinExchanger
:members:
:undoc-members:
:show-inheritance:
Tank Volume Functions
---------------------
.. autofunction:: V_partial_sphere
.. autofunction:: V_horiz_conical
.. autofunction:: V_horiz_ellipsoidal
.. autofunction:: V_horiz_guppy
.. autofunction:: V_horiz_spherical
.. autofunction:: V_horiz_torispherical
.. autofunction:: V_vertical_conical
.. autofunction:: V_vertical_ellipsoidal
.. autofunction:: V_vertical_spherical
.. autofunction:: V_vertical_torispherical
.. autofunction:: V_vertical_conical_concave
.. autofunction:: V_vertical_ellipsoidal_concave
.. autofunction:: V_vertical_spherical_concave
.. autofunction:: V_vertical_torispherical_concave
Tank Surface Area Functions
---------------------------
.. autofunction:: SA_partial_sphere
.. autofunction:: SA_ellipsoidal_head
.. autofunction:: SA_conical_head
.. autofunction:: SA_guppy_head
.. autofunction:: SA_torispheroidal
.. autofunction:: SA_partial_cylindrical_body
.. autofunction:: SA_partial_horiz_conical_head
.. autofunction:: SA_partial_horiz_spherical_head
.. autofunction:: SA_partial_horiz_ellipsoidal_head
.. autofunction:: SA_partial_horiz_guppy_head
.. autofunction:: SA_partial_horiz_torispherical_head
.. autofunction:: SA_partial_vertical_conical_head
.. autofunction:: SA_partial_vertical_ellipsoidal_head
.. autofunction:: SA_partial_vertical_spherical_head
.. autofunction:: SA_partial_vertical_torispherical_head
Miscellaneous Geometry Functions
--------------------------------
.. autofunction:: pitch_angle_solver
.. autofunction:: plate_enlargement_factor
.. autofunction:: a_torispherical
.. autofunction:: A_partial_circle
.. autofunction:: circle_segment_h_from_A
Pellet Properties
-----------------
.. autofunction:: sphericity
.. autofunction:: aspect_ratio
.. autofunction:: circularity
.. autofunction:: A_cylinder
.. autofunction:: V_cylinder
.. autofunction:: A_hollow_cylinder
.. autofunction:: V_hollow_cylinder
.. autofunction:: A_multiple_hole_cylinder
.. autofunction:: V_multiple_hole_cylinder
"""
from cmath import sqrt as csqrt
from math import acos, acosh, asin, atan, cos, degrees, isclose, log, log1p, pi, radians, sin, sqrt, tan
from fluids.numerics import cacos, catan, chebval, derivative, ellipe, ellipeinc, ellipkinc, linspace, newton, quad, secant, translate_bound_func
__all__ = ['TANK', 'HelicalCoil', 'PlateExchanger', 'RectangularFinExchanger',
'RectangularOffsetStripFinExchanger', 'HyperbolicCoolingTower',
'AirCooledExchanger',
'SA_partial_sphere',
'V_partial_sphere', 'V_horiz_conical',
'V_horiz_ellipsoidal', 'V_horiz_guppy', 'V_horiz_spherical',
'V_horiz_torispherical', 'V_vertical_conical',
'V_vertical_ellipsoidal', 'V_vertical_spherical',
'V_vertical_torispherical', 'V_vertical_conical_concave',
'V_vertical_ellipsoidal_concave', 'V_vertical_spherical_concave',
'V_vertical_torispherical_concave', 'a_torispherical',
'SA_ellipsoidal_head', 'SA_conical_head', 'SA_guppy_head',
'SA_torispheroidal', 'SA_partial_cylindrical_body',
'A_partial_circle', 'SA_partial_horiz_conical_head',
'SA_partial_horiz_spherical_head', 'SA_partial_horiz_guppy_head',
'SA_partial_horiz_ellipsoidal_head', 'SA_partial_horiz_torispherical_head',
'SA_partial_vertical_conical_head', 'SA_partial_vertical_spherical_head',
'SA_partial_vertical_torispherical_head', 'SA_partial_vertical_ellipsoidal_head',
'V_from_h', 'V_tank', 'SA_from_h', 'SA_tank', 'sphericity',
'aspect_ratio', 'circularity', 'A_cylinder', 'V_cylinder',
'A_hollow_cylinder', 'V_hollow_cylinder',
'A_multiple_hole_cylinder', 'V_multiple_hole_cylinder',
'pitch_angle_solver', 'plate_enlargement_factor', 'circle_segment_h_from_A']
### Spherical Vessels, partially filled
def SA_partial_sphere(D, h):
r'''Calculates surface area of a partial sphere according to [1]_.
If h is half of D, the shape is half a sphere. No bottom is considered in
this function. Valid inputs are positive values of D and h, with h always
smaller or equal to D.
.. math::
a = \sqrt{h(2r - h)}
.. math::
A = \pi(a^2 + h^2)
Parameters
----------
D : float
Diameter of the sphere, [m]
h : float
Height, as measured from the cap to where the sphere is cut off [m]
Returns
-------
SA : float
Surface area [m^2]
Examples
--------
>>> SA_partial_sphere(1., 0.7)
2.199114857512855
References
----------
.. [1] Weisstein, Eric W. "Spherical Cap." Text. Accessed December 22, 2015.
http://mathworld.wolfram.com/SphericalCap.html.
'''
if h > D:
h = D
elif h < 0.0:
h = 0.0
r = D*0.5
a = sqrt(h*(2.*r - h))
return pi*(a*a + h*h)
def V_partial_sphere(D, h):
r'''Calculates volume of a partial sphere according to [1]_.
If h is half of D, the shape is half a sphere. No bottom is considered in
this function. Valid inputs are positive values of D and h, with h always
smaller or equal to D.
.. math::
a = \sqrt{h(2r - h)}
.. math::
V = 1/6 \pi h(3a^2 + h^2)
Parameters
----------
D : float
Diameter of the sphere, [m]
h : float
Height, as measured up to where the sphere is cut off, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
>>> V_partial_sphere(1., 0.7)
0.4105014400690663
References
----------
.. [1] Weisstein, Eric W. "Spherical Cap." Text. Accessed December 22, 2015.
http://mathworld.wolfram.com/SphericalCap.html.
'''
if h <= 0.0:
return 0.0
if h > D:
h = D
r = 0.5*D
a = sqrt(h*(2.*r - h))
return (1/6.)*pi*h*(3.*a*a + h*h)
### Functions as developed by Dan Jones
def V_horiz_conical(D, L, a, h, headonly=False):
r'''Calculates volume of a tank with conical ends, according to [1]_.
.. math::
V_f = A_fL + \frac{2aR^2}{3}K, \;\;0 \le h < R\\
.. math::
V_f = A_fL + \frac{2aR^2}{3}\pi/2,\;\; h = R\\
.. math::
V_f = A_fL + \frac{2aR^2}{3}(\pi-K), \;\; R< h \le 2R
.. math::
K = \cos^{-1} M + M^3\cosh^{-1} \frac{1}{M} - 2M\sqrt{1 - M^2}
.. math::
M = \left|\frac{R-h}{R}\right|
.. math::
A_f = R^2\cos^{-1}\frac{R-h}{R} - (R-h)\sqrt{2Rh - h^2}
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
L : float
Length of the main cylindrical section, [m]
a : float
Distance the cone head extends on one side, [m]
h : float
Height, as measured up to where the fluid ends, [m]
headonly : bool, optional
Function returns only the volume of a single head side if True
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_conical(D=108., L=156., a=42., h=36)/231
2041.1923581273443
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
if h <= 0.0:
return 0.0
elif h > D:
h = D
R = 0.5*D
R_third = R*(1.0/3.0)
t0 = (R-h)/R
Af = R*R*acos(t0) - (R-h)*sqrt(h*(R + R - h))
M = abs(t0)
if h == R:
Vf = a*R*R_third*pi
else:
K = acos(M) + M*M*M*acosh(1./M) - 2.*M*sqrt(1.-M*M)
if 0. <= h < R:
Vf = 2.*a*R*R_third*K
else:
# elif R < h <= 2.0*R:
Vf = 2.*a*R*R_third*(pi - K)
if headonly:
Vf = 0.5*Vf
else:
Vf += Af*L
return Vf
def V_horiz_ellipsoidal(D, L, a, h, headonly=False):
r'''Calculates volume of a tank with ellipsoidal ends, according to [1]_.
.. math::
V_f = A_fL + \pi a h^2\left(1 - \frac{h}{3R}\right)
.. math::
A_f = R^2\cos^{-1}\frac{R-h}{R} - (R-h)\sqrt{2Rh - h^2}
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
L : float
Length of the main cylindrical section, [m]
a : float
Distance the ellipsoidal head extends on one side, [m]
h : float
Height, as measured up to where the fluid ends, [m]
headonly : bool, optional
Function returns only the volume of a single head side if True
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_ellipsoidal(D=108, L=156, a=42, h=36)/231.
2380.9565415578145
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
if h <= 0.0:
return 0.0
elif h > D:
h = D
R = 0.5*D
Af = R*R*acos((R-h)/R) - (R-h)*sqrt(2*R*h - h*h)
Vf = pi*a*h*h*(1 - h/(3.*R))
if headonly:
Vf = 0.5*Vf
else:
Vf += Af*L
return Vf
def V_horiz_guppy(D, L, a, h, headonly=False):
r'''Calculates volume of a tank with guppy heads, according to [1]_.
.. math::
V_f = A_fL + \frac{2aR^2}{3}\cos^{-1}\left(1 - \frac{h}{R}\right)
+\frac{2a}{9R}\sqrt{2Rh - h^2}(2h-3R)(h+R)
.. math::
A_f = R^2\cos^{-1}\frac{R-h}{R} - (R-h)\sqrt{2Rh - h^2}
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
L : float
Length of the main cylindrical section, [m]
a : float
Distance the guppy head extends on one side, [m]
h : float
Height, as measured up to where the fluid ends, [m]
headonly : bool, optional
Function returns only the volume of a single head side if True
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_guppy(D=108., L=156., a=42., h=36)/231.
1931.7208029476762
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
if h <= 0.0:
return 0.0
elif h > D:
h = D
R = 0.5*D
x0 = sqrt(2.*R*h - h*h)
Af = R*R*acos((R-h)/R) - (R-h)*x0
Vf = (2./3.0)*a*R*R*acos(1. - h/R) + (2./9.)*a/R*x0*(2.0*h - 3.0*R)*(h + R)
if headonly:
Vf = Vf*0.5
else:
Vf += Af*L
return Vf
def _V_horiz_spherical_toint(x, r2, R2, den_inv):
x2 = x*x
return (r2 - x2)*atan(sqrt((R2 - x2)*den_inv))
def V_horiz_spherical(D, L, a, h, headonly=False):
r'''Calculates volume of a tank with spherical heads, according to [1]_.
.. math::
V_f = A_fL + \frac{\pi a}{6}(3R^2 + a^2),\;\; h = R, |a|\le R
.. math::
V_f = A_fL + \frac{\pi a}{3}(3R^2 + a^2),\;\; h = D, |a|\le R
.. math::
V_f = A_fL + \pi a h^2\left(1 - \frac{h}{3R}\right),\;\; h = 0,
\text{ or } |a| = 0, R, -R
.. math::
V_f = A_fL + \frac{a}{|a|}\left\{\frac{2r^3}{3}\left[\cos^{-1}
\frac{R^2 - rw}{R(w-r)} + \cos^{-1}\frac{R^2 + rw}{R(w+r)}
- \frac{z}{r}\left(2 + \left(\frac{R}{r}\right)^2\right)
\cos^{-1}\frac{w}{R}\right] - 2\left(wr^2 - \frac{w^3}{3}\right)
\tan^{-1}\frac{y}{z} + \frac{4wyz}{3}\right\}
,\;\; h \ne R, D; a \ne 0, R, -R, |a| \ge 0.01D
.. math::
V_f = A_fL + \frac{a}{|a|}\left[2\int_w^R(r^2 - x^2)\tan^{-1}
\sqrt{\frac{R^2-x^2}{r^2-R^2}}dx - A_f z\right]
,\;\; h \ne R, D; a \ne 0, R, -R, |a| < 0.01D
.. math::
A_f = R^2\cos^{-1}\frac{R-h}{R} - (R-h)\sqrt{2Rh - h^2}
.. math::
r = \frac{a^2 + R^2}{2|a|}
.. math::
w = R - h
.. math::
y = \sqrt{2Rh-h^2}
.. math::
z = \sqrt{r^2 - R^2}
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
L : float
Length of the main cylindrical section, [m]
a : float
Distance the spherical head extends on one side, [m]
h : float
Height, as measured up to where the fluid ends, [m]
headonly : bool, optional
Function returns only the volume of a single head side if True
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_spherical(D=108., L=156., a=42., h=36)/231.
2303.96151169861
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
if h <= 0.0:
return 0.0
elif h > D:
h = D
R = 0.5*D
r = 0.5*(a*a + R*R)/abs(a)
w = R - h
y = sqrt(2.0*R*h - h*h)
if isclose(r, R, rel_tol=2e-15):
# Handle the case of small issues in calculation of `r` blowing up the calculation
z = 0.0
else:
z = sqrt(r*r - R*R)
Af = R*R*acos((R-h)/R) - (R-h)*sqrt(2.0*R*h - h*h)
if h == R and abs(a) <= R:
Vf = (pi/6.0)*a*(3.0*R*R + a*a)
elif h == D and abs(a) <= R:
Vf = (pi/3.0)*a*(3.0*R*R + a*a)
elif h == 0 or a in (0.0, R, -R) or z == 0.0:
Vf = pi*a*h*h*(1.0 - h/R*(1.0/3.0))
elif abs(a) >= 0.01*D:
R_r = R/r
Vf = a/abs(a)*(
(2.0/3.0)*r*r*r*(acos((R*R - r*w)/(R*(w-r))) + acos((R*R+r*w)/(R*(w+r)))
- z/r*(2.0+R_r*R_r)*acos(w/R))
- 2.0*(w*r*r - w*w*w*(1.0/3.0))*atan(y/z) + (4.0/3.0)*w*y*z)
else:
r2 = r*r
R2 = R*R
den_inv = 1.0/(r2 - R2)
integrated = quad(_V_horiz_spherical_toint, w, R, args=(r2, R2, den_inv))[0] # , epsrel=1.49e-13,
Vf = a/abs(a)*(2.0*integrated - Af*z)
if headonly:
Vf = 0.5*Vf
else:
Vf += Af*L
return Vf
def V_horiz_torispherical_toint_1(x, w, c10, c11):
# No analytical integral available in MP
n = c11 + sqrt(c10 - x*x)
n2 = n*n
t = sqrt(n2 - w*w)
return n2*asin(t/n) - w*t
def V_horiz_torispherical_toint_2(x, w, c10, c11, g, g2):
# No analytical integral available in MP
n = c11 + sqrt(c10 - x*x)
n2 = n*n
n_inv = 1.0/n
ans = n2*(acos(w*n_inv) - acos(g*n_inv)) - w*sqrt(n2 - w*w) + g*sqrt(n2 - g2)
return ans
def V_horiz_torispherical_toint_3(x, r2, g2, z_inv):
# There is an analytical integral in MP, but for all cases we seem to
# get ZeroDivisionError: 0.0 cannot be raised to a negative power
x2 = x*x
return (r2 - x2)*atan(sqrt(g2 - x2)*z_inv)
def V_horiz_torispherical(D, L, f, k, h, headonly=False):
r'''Calculates volume of a tank with torispherical heads, according to [1]_.
.. math::
V_f = A_fL + 2V_1, \;\; 0 \le h \le h_1\\
V_f = A_fL + 2(V_{1,max} + V_2 + V_3), \;\; h_1 < h < h_2\\
V_f = A_fL + 2[2V_{1,max} - V_1(h=D-h) + V_{2,max} + V_{3,max}]
, \;\; h_2 \le h \le D
.. math::
V_1 = \int_0^{\sqrt{2kDh - h^2}} \left[n^2\sin^{-1}\frac{\sqrt
{n^2-w^2}}{n} - w\sqrt{n^2-w^2}\right]dx
.. math::
V_2 = \int_0^{kD\cos\alpha}\left[n^2\left(\cos^{-1}\frac{w}{n}
- \cos^{-1}\frac{g}{n}\right) - w\sqrt{n^2 - w^2} + g\sqrt{n^2
- g^2}\right]dx
.. math::
V_3 = \int_w^g(r^2 - x^2)\tan^{-1}\frac{\sqrt{g^2 - x^2}}{z}dx
- \frac{z}{2}\left(g^2\cos^{-1}\frac{w}{g} - w\sqrt{2g(h-h_1)
- (h-h_1)^2}\right)
.. math::
V_{1,max} = v_1(h=h_1)
.. math::
v_{2,max} = v_2(h=h_2)
.. math::
v_{3,max} = \frac{\pi a_1}{6}(3g^2 + a_1^2)
.. math::
a_1 = fD(1-\cos\alpha)
.. math::
\alpha = \sin^{-1}\frac{1-2k}{2(f-k)}
.. math::
n = R - kD + \sqrt{k^2D^2-x^2}
.. math::
g = r\sin\alpha
.. math::
r = fD
.. math::
h_2 = D - h_1
.. math::
w = R - h
.. math::
z = \sqrt{r^2- g^2}
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
L : float
Length of the main cylindrical section, [m]
f : float
Dimensionless dish-radius parameter; also commonly given as the
product of `f` and `D` (`fD`), which is called both dish radius and
also crown radius and has units of length, [-]
k : float
Dimensionless knuckle-radius parameter; also commonly given as the
product of `k` and `D` (`kD`), which is called the knuckle radius
and has units of length, [-]
h : float
Height, as measured up to where the fluid ends, [m]
headonly : bool, optional
Function returns only the volume of a single head side if True
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_torispherical(D=108., L=156., f=1., k=0.06, h=36)/231.
2028.62667
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
# print((D, L, f, k, h, headonly))
if h <= 0.0:
return 0.0
if h > D or isclose(h, D, rel_tol=2e-15):
h = D
if f is None or k is None:
raise ValueError("Missing f or k")
R = 0.5*D
R2 = R*R
hh = h*h
Af = R2*acos((R-h)/R) - (R-h)*sqrt(2.0*R*h - hh)
r = f*D
alpha = asin((1.0 - 2.0*k)/(2.*(f - k)))
cos_alpha = cos(alpha)
sin_alpha = sin(alpha)
a1 = r*(1.0 - cos_alpha)
g = r*sin_alpha
z = r*cos_alpha
h1 = k*D*(1.0 - sin_alpha)
h2 = D - h1
# Chebfun in Python failed on these functions
c10 = k*k*D*D
c11 = R - k*D
g2 = g*g
r2 = r*r
if 0.0 <= h <= h1:
w = R - h
Vf = 2.0*quad(V_horiz_torispherical_toint_1, 0.0, sqrt(2.0*k*D*h - hh), (w, c10, c11))[0]
elif h1 < h < h2:
w = R - h
wmax1 = R - h1
V1max = quad(V_horiz_torispherical_toint_1, 0.0, sqrt(2.0*k*D*h1 - h1*h1), (wmax1,c10, c11))[0]
V2 = quad(V_horiz_torispherical_toint_2, 0.0, k*D*cos_alpha, (w, c10, c11, g, g2))[0]
V3 = quad(V_horiz_torispherical_toint_3, w, g , (r2, g2, 1.0/z))[0] - 0.5*z*(g*g*acos(w/g) -w*sqrt(2.0*g*(h-h1) - (h-h1)*(h-h1)))
Vf = 2.0*(V1max + V2 + V3)
else:
w = R - h
wmax1 = R - h1
wmax2 = R - h2
wwerird = R - (D - h)
upper_1 = sqrt(2.0*k*D*h1-h1*h1)
upper_2 = sqrt(2.0*k*D*(D-h)-(D-h)*(D-h))
upper_3 = k*D*cos_alpha
V1max = quad(V_horiz_torispherical_toint_1, 0.0, upper_1, (wmax1,c10, c11))[0]
if upper_2 != 0.0:
V1weird = quad(V_horiz_torispherical_toint_1, 0.0, upper_2, (wwerird,c10, c11))[0]
else:
V1weird = 0.0
V2max = quad(V_horiz_torispherical_toint_2, 0.0, upper_3, (wmax2, c10, c11, g, g2))[0]
V3max = (pi/6.0)*a1*(3.0*g*g + a1*a1)
Vf = 2.0*(2.0*V1max - V1weird + V2max + V3max)
if headonly:
Vf = 0.5*Vf
else:
Vf += Af*L
return Vf
### Begin vertical tanks
def V_vertical_conical(D, a, h):
r'''Calculates volume of a vertical tank with a convex conical bottom,
according to [1]_. No provision for the top of the tank is made here.
.. math::
V_f = \frac{\pi}{4}\left(\frac{Dh}{a}\right)^2\left(\frac{h}{3}\right),\; h < a
.. math::
V_f = \frac{\pi D^2}{4}\left(h - \frac{2a}{3}\right),\; h\ge a
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the cone head extends under the main cylinder, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_conical(132., 33., 24)/231.
250.67461381371024
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
if h <= 0.0:
return 0.0
# vertical tanks can have `h` arbitrarily high unlike horizontal tanks
if h < a:
ratio = D*h/a
Vf = 0.25*pi*ratio*ratio*(1.0/3.0)*h
else:
Vf = 0.25*pi*D*D*(h - a*(2.0/3.))
return Vf
def V_vertical_ellipsoidal(D, a, h):
r'''Calculates volume of a vertical tank with a convex ellipsoidal bottom,
according to [1]_. No provision for the top of the tank is made here.
.. math::
V_f = \frac{\pi}{4}\left(\frac{Dh}{a}\right)^2 \left(a - \frac{h}{3}\right),\; h < a
.. math::
V_f = \frac{\pi D^2}{4}\left(h - \frac{a}{3}\right),\; h \ge a
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the ellipsoid head extends under the main cylinder, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_ellipsoidal(132., 33., 24)/231.
783.3581681678445
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
if h <= 0.0:
return 0.0
if h < a:
ratio = D*h/a
Vf = 0.25*pi*ratio*ratio*(a - h*(1.0/3.))
else:
Vf = 0.25*pi*D*D*(h - a*(1.0/3.))
return Vf
def V_vertical_spherical(D, a, h):
r'''Calculates volume of a vertical tank with a convex spherical bottom,
according to [1]_. No provision for the top of the tank is made here.
.. math::
V_f = \frac{\pi h^2}{4}\left(2a + \frac{D^2}{2a} - \frac{4h}{3}\right),\; h < a
.. math::
V_f = \frac{\pi}{4}\left(\frac{2a^3}{3} - \frac{aD^2}{2} + hD^2\right),\; h\ge a
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the spherical head extends under the main cylinder, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_spherical(132., 33., 24)/231.
583.6018352850442
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
if h <= 0.0:
return 0.0
if h < a:
Vf = 0.25*pi*h*h*(2.0*a + 0.5*D*D/a - (4/3.0)*h)
else:
Vf = 0.25*pi*((2.0/3.0)*a*a*a - 0.5*a*D*D+ h*D*D)
return Vf
def V_vertical_torispherical(D, f, k, h):
r'''Calculates volume of a vertical tank with a convex torispherical bottom,
according to [1]_. No provision for the top of the tank is made here.
.. math::
V_f = \frac{\pi h^2}{4}\left(2a_1 + \frac{D_1^2}{2a_1}
- \frac{4h}{3}\right),\; 0 \le h \le a_1
.. math::
V_f = \frac{\pi}{4}\left(\frac{2a_1^3}{3} + \frac{a_1D_1^2}{2}\right)
+\pi u\left[\left(\frac{D}{2}-kD\right)^2 +s\right]
+ \frac{\pi tu^2}{2} - \frac{\pi u^3}{3} + \pi D(1-2k)\left[
\frac{2u-t}{4}\sqrt{s+tu-u^2} + \frac{t\sqrt{s}}{4}
+ \frac{k^2D^2}{2}\left(\cos^{-1}\frac{t-2u}{2kD}-\alpha\right)\right]
,\; a_1 < h \le a_1 + a_2
.. math::
V_f = \frac{\pi}{4}\left(\frac{2a_1^3}{3} + \frac{a_1D_1^2}{2}\right)
+\frac{\pi t}{2}\left[\left(\frac{D}{2}-kD\right)^2 +s\right]
+\frac{\pi t^3}{12} + \pi D(1-2k)\left[\frac{t\sqrt{s}}{4}
+ \frac{k^2D^2}{2}\sin^{-1}(\cos\alpha)\right]
+ \frac{\pi D^2}{4}[h-(a_1+a_2)] ,\; a_1 + a_2 < h
.. math::
\alpha = \sin^{-1}\frac{1-2k}{2(f-k)}
.. math::
a_1 = fD(1-\cos\alpha)
.. math::
a_2 = kD\cos\alpha
.. math::
D_1 = 2fD\sin\alpha
.. math::
s = (kD\sin\alpha)^2
.. math::
t = 2a_2
.. math::
u = h - fD(1-\cos\alpha)
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
f : float
Dimensionless dish-radius parameter; also commonly given as the
product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
k : float
Dimensionless knuckle-radius parameter; also commonly given as the
product of `k` and `D` (`kD`), which is called the knuckle radius
and has units of length, [-]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_torispherical(D=132., f=1.0, k=0.06, h=24)/231.
904.0688283793
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
if h <= 0.0:
return 0.0
if f is None or k is None:
raise ValueError("f and k are required")
alpha = asin((1.0 - 2.0*k)/(2.0*(f-k)))
sin_alpha = sin(alpha)
cos_alpha = cos(alpha)
a1 = f*D*(1.0 - cos_alpha)
a2 = k*D*cos_alpha
D1 = 2.0*f*D*sin_alpha
x1 = k*D*sin_alpha
s = x1*x1
t = a2 + a2
u = h - f*D*(1.0 - cos_alpha)
h2 = h*h
if 0.0 <= h <= a1:
Vf = 0.25*pi*h2*(a1 + a1 + 0.5*D1*D1/a1 - (4.0/3.0)*h)
elif a1 < h <= a1 + a2:
x2 = (0.5*D - k*D)
u2 = u*u
Vf = (0.25*pi*a1*((2.0/3.0)*a1*a1 + 0.5*D1*D1) + pi*u*(x2*x2 + s)
+ pi*u2*(0.5*t - u*(1.0/3.)) + pi*D*(1.0 - 2.0*k)*(0.25*(2.0*u - t)*sqrt(s + t*u
- u2) + 0.25*t*sqrt(s) + 0.5*k*k*D*D*(acos((t - 2.0*u)/(2.0*k*D)) - alpha)))
else:
ratio = (0.5*D - k*D)
Vf = 0.25*pi*((2.0/3.0)*a1*a1*a1 + 0.5*a1*D1*D1) + 0.5*pi*t*(ratio*ratio
+ s) + pi*t*t*t*(1.0/12.) + pi*D*(1.0 - 2.0*k)*(0.25*t*sqrt(s)
+ k*k*D*D*(1.0/2.0)*asin(cos(alpha))) + 0.25*pi*D*D*(h - (a1 + a2))
return Vf
### Begin vertical tanks with concave heads
def V_vertical_conical_concave(D, a, h):
r'''Calculates volume of a vertical tank with a concave conical bottom,
according to [1]_. No provision for the top of the tank is made here.
.. math::
V = \frac{\pi D^2}{12} \left(3h + a - \frac{(a+h)^3}{a^2}\right)
,\;\; 0 \le h < |a|
.. math::
V = \frac{\pi D^2}{12} (3h + a ),\;\; h \ge |a|
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Negative distance the cone head extends inside the main cylinder, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_conical_concave(D=113., a=-33, h=15)/231
251.158255657951
References
----------
.. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical
Processing. December 18, 2003.
http://www.chemicalprocessing.com/articles/2003/193/
'''
if h <= 0.0:
return 0.0
if h < abs(a):
a_plus_h = a + h
Vf = pi*D*D*(1.0/12.)*(3.0*h + a - a_plus_h*a_plus_h*a_plus_h/(a*a))
else:
Vf = pi*D*D*(1.0/12.)*(3.0*h + a)
return Vf
def V_vertical_ellipsoidal_concave(D, a, h):
r'''Calculates volume of a vertical tank with a concave ellipsoidal bottom,
according to [1]_. No provision for the top of the tank is made here.
.. math::
V = \frac{\pi D^2}{12} \left(3h + 2a - \frac{(a+h)^2(2a-h)}{a^2}\right)
,\;\; 0 \le h < |a|
.. math::
V = \frac{\pi D^2}{12} (3h + 2a ),\;\; h \ge |a|
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Negative distance the eppilsoid head extends inside the main cylinder, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_ellipsoidal_concave(D=113., a=-33, h=15)/231
44.84968851034856
References
----------
.. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical
Processing. December 18, 2003.
http://www.chemicalprocessing.com/articles/2003/193/
'''
if h <= 0.0:
return 0.0
if h < abs(a):
a_plus_h = a + h
Vf = pi*D*D*(1.0/12.)*(3.0*h + 2.0*a - a_plus_h*a_plus_h*(2.0*a-h)/(a*a))
else:
Vf = pi*D*D*(1.0/12.)*(3.0*h + 2.0*a)
return Vf
def V_vertical_spherical_concave(D, a, h):
r'''Calculates volume of a vertical tank with a concave spherical bottom,
according to [1]_. No provision for the top of the tank is made here.
.. math::
V = \frac{\pi}{12}\left[3D^2h + \frac{a}{2}(3D^2 + 4a^2) + (a+h)^3
\left(4 - \frac{3D^2 + 12a^2}{2a(a+h)}\right)\right],\;\; 0 \le h < |a|
.. math::
V = \frac{\pi}{12}\left[3D^2h + \frac{a}{2}(3D^2 + 4a^2) \right]
,\;\; h \ge |a|
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Negative distance the spherical head extends inside the main cylinder, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_spherical_concave(D=113., a=-33, h=15)/231
112.81405437348528
References
----------
.. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical
Processing. December 18, 2003.
http://www.chemicalprocessing.com/articles/2003/193/
'''
if h <= 0.0:
return 0.0
D2 = D*D
a2 = a*a
if h < abs(a):
a_plus_h = a + h
Vf = pi*(1.0/12)*(3.0*D2*h + a*(1.0/2.)*(3.0*D2 + 4.0*a2) + a_plus_h*a_plus_h*a_plus_h*(4.0 - (3.0*D2+12.0*a2)/(2.*a*a_plus_h)))
else:
Vf = pi*(1.0/12)*(3.0*D2*h + a*(1.0/2.)*(3.0*D2 + 4.0*a2))
return Vf
def V_vertical_torispherical_concave(D, f, k, h):
r'''Calculates volume of a vertical tank with a concave torispherical bottom,
according to [1]_. No provision for the top of the tank is made here.
.. math::
V = \frac{\pi D^2 h}{4} - v_1(h=a_1+a_2) + v_1(h=a_1 + a_2 -h),\; 0 \le h < a_2
.. math::
V = \frac{\pi D^2 h}{4} - v_1(h=a_1+a_2) + v_2(h=a_1 + a_2 -h),\; a_2 \le h < a_1 + a_2
.. math::
V = \frac{\pi D^2 h}{4} - v_1(h=a_1+a_2) + 0,\; h \ge a_1 + a_2
.. math::
v_1 = \frac{\pi}{4}\left(\frac{2a_1^3}{3} + \frac{a_1D_1^2}{2}\right)
+\pi u\left[\left(\frac{D}{2}-kD\right)^2 +s\right]
+ \frac{\pi tu^2}{2} - \frac{\pi u^3}{3} + \pi D(1-2k)\left[
\frac{2u-t}{4}\sqrt{s+tu-u^2} + \frac{t\sqrt{s}}{4}
+ \frac{k^2D^2}{2}\left(\cos^{-1}\frac{t-2u}{2kD}-\alpha\right)\right]
.. math::
v_2 = \frac{\pi h^2}{4}\left(2a_1 + \frac{D_1^2}{2a_1} - \frac{4h}{3}\right)
.. math::
\alpha = \sin^{-1}\frac{1-2k}{2(f-k)}
.. math::
a_1 = fD(1-\cos\alpha)
.. math::
a_2 = kD\cos\alpha
.. math::
D_1 = 2fD\sin\alpha
.. math::
s = (kD\sin\alpha)^2
.. math::
t = 2a_2
.. math::
u = h - fD(1-\cos\alpha)
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
f : float
Dimensionless dish-radius parameter; also commonly given as the
product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
k : float
Dimensionless knuckle-radius parameter; also commonly given as the
product of `k` and `D` (`kD`), which is called the knuckle radius
and has units of length, [-]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_torispherical_concave(D=113., f=0.71, k=0.081, h=15)/231
103.88569287163769
References
----------
.. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical
Processing. December 18, 2003.
http://www.chemicalprocessing.com/articles/2003/193/
'''
if h <= 0.0:
return 0.0
alpha = asin((1.0-2.0*k)/(2.*(f-k)))
cos_alpha = cos(alpha)
sin_alpha = sin(alpha)
a1 = f*D*(1-cos_alpha)
a2 = k*D*cos_alpha
D1 = 2.0*f*D*sin_alpha
s = (k*D*sin_alpha)
s *= s
t = 2.0*a2
def V1(h):
u = h-f*D*(1.0-cos_alpha)
ratio = (0.5*D-k*D)
v1 = 0.25*pi*((2.0/3.0)*a1*a1*a1 + 0.5*a1*D1*D1) + pi*u*(ratio*ratio +s)
v1 += u*u*(0.5*pi*t - pi*(1.0/3.)*u)
v1 += pi*D*(1.0-2.0*k)*((2.0*u-t)*0.25*sqrt(s+t*u-u*u) + 0.25*t*sqrt(s)
+ k*k*D*D*0.5*(acos((t-2.0*u)/(2.0*k*D)) -alpha))
return v1
def V2(h):
v2 = 0.25*pi*h*h*(2.0*a1 + D1*D1/(2.*a1) - 4/3.0*h)
return v2
if 0 <= h < a2:
Vf = 0.25*pi*D*D*h - V1(a1+a2) + V1(a1+a2-h)
elif a2 <= h < a1 + a2:
Vf = 0.25*pi*D*D*h - V1(a1+a2) + V2(a1+a2-h)
else:
Vf = 0.25*pi*D*D*h - V1(a1+a2)
return Vf
### Total surface area of heads, orientation-independent
def SA_ellipsoidal_head(D, a):
r'''Calculates the surface area of an ellipsoidal head according to [1]_ and [2]_.
The formula below is for the full shape, the result of which is halved. The
formula is for :math:`a < R`. In the equations, `a` is the same and `c` is `D`.
.. math::
\text{SA} = 2\pi a^2 + \frac{\pi c^2}{e_1}\ln\left(\frac{1+e_1}{1-e_1}
\right)
.. math::
e_1 = \sqrt{1 - \frac{c^2}{a^2}}
For the case of :math:`a \ge R` from [2]_, which is needed to make the tank
head volume grow linearly with length:
.. math::
\text{SA} = 2\pi R^2 + \frac{2\pi a^2 R}{\sqrt{a^2 - R^2}}\cos^{-1}\frac{R}{|a|}
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the ellipsoidal head extends, [m]
Returns
-------
SA : float
Surface area [m^2]
Examples
--------
Spherical case
>>> SA_ellipsoidal_head(2, 1)
6.283185307179586
>>> SA_ellipsoidal_head(2, 1.5)
8.459109081729984
References
----------
.. [1] Weisstein, Eric W. "Spheroid." Text. Accessed March 14, 2016.
http://mathworld.wolfram.com/Spheroid.html.
.. [2] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
if D == a*2.0:
return 0.5*pi*D*D # necessary to avoid a division by zero when D == a
R = 0.5*D
if a < R:
R, a = min((R, a)), max((R, a))
e1 = sqrt(1.0 - R*R/(a*a))
if e1 != 1.0:
log_term = log1p(e1) - log1p(-e1)
else:
# Limit as a goes to zero relative to D; may only be ~6 orders of
# magnitude smaller than D and will still occur
log_term = 0.0
return (2.0*pi*a*a + pi*R*R/e1*log_term)*0.5
else:
return pi*R*R + pi*a*a*R*1.0/sqrt(a*a - R*R)*acos(R/abs(a))
def SA_conical_head(D, a):
r'''Calculates the surface area of a conical head according to [1]_.
.. math::
SA = \frac{\pi D}{2} \sqrt{a^2 + \left(\frac{D}{2}\right)^2}
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the conical head extends, [m]
Returns
-------
SA : float
Surface area [m^2]
Examples
--------
>>> SA_conical_head(2, 1)
4.442882938158366
References
----------
.. [1] Weisstein, Eric W. "Cone." Text. Accessed March 14, 2016.
http://mathworld.wolfram.com/Cone.html.
'''
return 0.5*pi*D*sqrt(a*a + 0.25*D*D)
def SA_guppy_head(D, a):
r'''Calculates the surface area of a guppy head according to [1]_.
Some work was involved in combining formulas for the ellipse of the head,
and the conic section on the sides.
.. math::
SA = \frac{\pi D}{4}\sqrt{D^2 + a^2} + \frac{\pi D}{2}a
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the conical head extends, [m]
Returns
-------
SA : float
Surface area [m^2]
Examples
--------
>>> SA_guppy_head(2, 1)
6.654000019110157
References
----------
.. [1] Weisstein, Eric W. "Cone." Text. Accessed March 14, 2016.
http://mathworld.wolfram.com/Cone.html.
'''
return 0.25*pi*D*sqrt(a*a + D*D) + 0.5*pi*D*a
def SA_torispheroidal(D, f, k):
r'''Calculates surface area of a torispherical head according to [1]_.
Somewhat involved. Equations are adapted to be used for a full head.
.. math::
SA = S_1 + S_2
.. math::
S_1 = 2\pi D^2 f_d \alpha
.. math::
S_2 = 2\pi D^2 f_k\left(\alpha - \alpha_1 + (0.5 - f_k)\left(\sin^{-1}
\left(\frac{\alpha-\alpha_2}{f_k}\right) - \sin^{-1}\left(\frac{
\alpha_1-\alpha_2}{f_k}\right)\right)\right)
.. math::
\alpha_1 = f_d\left(1 - \sqrt{1 - \left(\frac{0.5 - f_k}{f_d-f_k}
\right)^2}\right)
.. math::
\alpha_2 = f_d - \sqrt{f_d^2 - 2f_d f_k + f_k - 0.25}
.. math::
\alpha = \frac{a}{D_i}
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
f : float
Dimensionless dish-radius parameter; also commonly given as the
product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
k : float
Dimensionless knuckle-radius parameter; also commonly given as the
product of `k` and `D` (`kD`), which is called the knuckle radius
and has units of length, [-]
Returns
-------
SA : float
Surface area [m^2]
Examples
--------
Example from [1]_.
>>> SA_torispheroidal(D=2.54, f=1.039370079, k=0.062362205)
6.00394283477063
References
----------
.. [1] Honeywell. "Calculate Surface Areas and Cross-sectional Areas in
Vessels with Dished Heads". https://www.honeywellprocess.com/library/marketing/whitepapers/WP-VesselsWithDishedHeads-UniSimDesign.pdf
Whitepaper. 2014.
'''
D2 = D*D
x1 = 2.0*pi*D2
k_inv = 1.0/k
x2 = ((0.5 - k)/(f-k))
alpha_1 = f*(1.0 - sqrt(1.0 - x2*x2))
alpha_2 = f - sqrt(f*f - 2.0*f*k + k - 0.25)
alpha = alpha_1 # Up to top of dome
S1 = x1*f*alpha_1
alpha = alpha_2 # up to top of torus
S2_sub = asin((alpha-alpha_2)*k_inv) - asin((alpha_1-alpha_2)*k_inv)
S2 = x1*k*(alpha - alpha_1 + (0.5 - k) *S2_sub)
return S1 + S2
def SA_tank(D, L, sideA=None, sideB=None, sideA_a=0,
sideB_a=0, sideA_f=None, sideA_k=None, sideB_f=None, sideB_k=None):
r'''Calculates the surface are of a cylindrical tank with optional heads.
In the degenerate case of being provided with only `D` and `L`, provides
the surface area of a cylinder.
Parameters
----------
D : float
Diameter of the cylindrical section of the tank, [m]
L : float
Length of the main cylindrical section of the tank, [m]
sideA : string, optional
The left (or bottom for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical'].
sideB : string, optional
The right (or top for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical'].
sideA_a : float, optional
The distance the head as specified by sideA extends down or to the left
from the main cylindrical section, [m]
sideB_a : float, optional
The distance the head as specified by sideB extends up or to the right
from the main cylindrical section, [m]
sideA_f : float, optional
Dish-radius parameter for side A; fD = dish radius [1/m]
sideA_k : float, optional
knuckle-radius parameter for side A; kD = knuckle radius [1/m]
sideB_f : float, optional
Dish-radius parameter for side B; fD = dish radius [1/m]
sideB_k : float, optional
knuckle-radius parameter for side B; kD = knuckle radius [1/m]
Returns
-------
SA : float
Surface area of the tank [m^2]
sideA_SA : float
Surface area of only `sideA` [m^2]
sideB_SA : float
Surface area of only `sideB` [m^2]
lateral_SA : float
Surface area of cylindrical section of tank [m^2]
Examples
--------
Cylinder, Spheroid, Long Cones, and spheres. All checked.
>>> SA_tank(D=2, L=2)[0]
18.84955592153876
>>> SA_tank(D=1., L=0, sideA='ellipsoidal', sideA_a=2, sideB='ellipsoidal',
... sideB_a=2)[0]
10.124375616183
>>> SA_tank(D=1., L=5, sideA='conical', sideA_a=2, sideB='conical',
... sideB_a=2)[0]
22.18452243965
>>> SA_tank(D=1., L=5, sideA='spherical', sideA_a=0.5, sideB='spherical',
... sideB_a=0.5)[0]
18.8495559215
'''
# Side A
if sideA == 'conical':
sideA_SA = SA_conical_head(D=D, a=sideA_a)
elif sideA == 'ellipsoidal':
sideA_SA = SA_ellipsoidal_head(D=D, a=sideA_a)
elif sideA == 'guppy':
sideA_SA = SA_guppy_head(D=D, a=sideA_a)
elif sideA == 'spherical':
sideA_SA = pi * (sideA_a * sideA_a + 0.25 * D * D)
elif sideA == 'torispherical':
if sideA_f is None or sideA_k is None:
raise ValueError("Missing torispherical 'f' or 'k' parameter for sideA")
sideA_SA = SA_torispheroidal(D=D, f=sideA_f, k=sideA_k)
else:
sideA_SA = 0.25*pi*D*D # Circle
# Side B
# Calculate side B (reuse side A calculation if parameters are identical)
if (sideA == sideB and sideA_a == sideB_a and
sideA_f == sideB_f and sideA_k == sideB_k):
sideB_SA = sideA_SA
else:
if sideB == 'conical':
sideB_SA = SA_conical_head(D=D, a=sideB_a)
elif sideB == 'ellipsoidal':
sideB_SA = SA_ellipsoidal_head(D=D, a=sideB_a)
elif sideB == 'guppy':
sideB_SA = SA_guppy_head(D=D, a=sideB_a)
elif sideB == 'spherical':
sideB_SA = pi*(sideB_a*sideB_a + 0.25*D*D)#SA_partial_sphere(D=D, h=sideB_a)
elif sideB == 'torispherical':
if sideB_f is None or sideB_k is None:
raise ValueError("Missing torispherical 'f' or 'k' parameter for sideB")
sideB_SA = SA_torispheroidal(D=D, f=sideB_f, k=sideB_k)
else:
sideB_SA = 0.25*pi*D*D # Circle
lateral_SA = pi*D*L
SA = sideA_SA + sideB_SA + lateral_SA
return SA, sideA_SA, sideB_SA, lateral_SA
def V_tank(D, L, horizontal=True, sideA=None, sideB=None, sideA_a=0.0,
sideB_a=0.0, sideA_f=None, sideA_k=None, sideB_f=None, sideB_k=None):
r'''Calculates the total volume of a vertical or horizontal tank with
different head types.
Parameters
----------
D : float
Diameter of the cylindrical section of the tank, [m]
L : float
Length of the main cylindrical section of the tank, [m]
horizontal : bool, optional
Whether or not the tank is a horizontal or vertical tank
sideA : string, optional
The left (or bottom for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical'].
sideB : string, optional
The right (or top for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical'].
sideA_a : float, optional
The distance the head as specified by sideA extends down or to the left
from the main cylindrical section, [m]
sideB_a : float, optional
The distance the head as specified by sideB extends up or to the right
from the main cylindrical section, [m]
sideA_f : float, optional
Dimensionless dish-radius parameter for side A; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideA_k : float, optional
Dimensionless knuckle-radius parameter for side A; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
sideB_f : float, optional
Dimensionless dish-radius parameter for side B; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideB_k : float, optional
Dimensionless knuckle-radius parameter for side B; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
Returns
-------
V : float
Total volume [m^3]
sideA_V : float
Volume of only `sideA` [m^3]
sideB_V : float
Volume of only `sideB` [m^3]
lateral_V : float
Volume of cylindrical section of tank [m^3]
Examples
--------
>>> V_tank(D=1.5, L=5., horizontal=False, sideA='conical',
... sideB='conical', sideA_a=2., sideB_a=1.)
(10.602875205865551, 1.1780972450961726, 0.5890486225480863, 8.835729338221293)
'''
if sideA is not None and sideA not in ('conical', 'ellipsoidal', 'torispherical', 'spherical', 'guppy'):
raise ValueError('Unspoorted head type for side A')
if sideB is not None and sideB not in ('conical', 'ellipsoidal', 'torispherical', 'spherical', 'guppy'):
raise ValueError('Unspoorted head type for side B')
R = 0.5*D
sideA_V = sideB_V = lateral_V = 0.0
if horizontal:
# Conical case
if sideA == 'conical' and sideB == 'conical' and sideA_a == sideB_a:
sideB_V = sideA_V = V_horiz_conical(D, L, sideA_a, D, headonly=True)
else:
if sideA == 'conical':
sideA_V = V_horiz_conical(D, L, sideA_a, D, headonly=True)
if sideB == 'conical':
sideB_V = V_horiz_conical(D, L, sideB_a, D, headonly=True)
# Elliosoidal case
if sideA == 'ellipsoidal' and sideB == 'ellipsoidal' and sideA_a == sideB_a:
sideB_V = sideA_V = V_horiz_ellipsoidal(D, L, sideA_a, D, headonly=True)
else:
if sideA == 'ellipsoidal':
sideA_V = V_horiz_ellipsoidal(D, L, sideA_a, D, headonly=True)
if sideB == 'ellipsoidal':
sideB_V = V_horiz_ellipsoidal(D, L, sideB_a, D, headonly=True)
# Guppy case
if sideA == 'guppy' and sideB == 'guppy' and sideA_a == sideB_a:
sideB_V = sideA_V = V_horiz_guppy(D, L, sideA_a, D, headonly=True)
else:
if sideA == 'guppy':
sideA_V = V_horiz_guppy(D, L, sideA_a, D, headonly=True)
if sideB == 'guppy':
sideB_V = V_horiz_guppy(D, L, sideB_a, D, headonly=True)
# Spherical case
if sideA == 'spherical' and sideB == 'spherical' and sideA_a == sideB_a:
sideB_V = sideA_V = V_horiz_spherical(D, L, sideA_a, D, headonly=True)
else:
if sideA == 'spherical':
sideA_V = V_horiz_spherical(D, L, sideA_a, D, headonly=True)
if sideB == 'spherical':
sideB_V = V_horiz_spherical(D, L, sideB_a, D, headonly=True)
# Torispherical case
if (sideA == 'torispherical' and sideB == 'torispherical'
and (sideA_f == sideB_f) and (sideA_k == sideB_k)):
sideB_V = sideA_V = V_horiz_torispherical(D, L, sideA_f, sideA_k, D, headonly=True)
else:
if sideA == 'torispherical':
sideA_V = V_horiz_torispherical(D, L, sideA_f, sideA_k, D, headonly=True)
if sideB == 'torispherical':
sideB_V = V_horiz_torispherical(D, L, sideB_f, sideB_k, D, headonly=True)
Af = R*R*acos((R-D)/R) - (R-D)*sqrt(2.0*R*D - D*D)
lateral_V = L*Af
else:
# Bottom head
if sideA == 'conical' and sideB == 'conical' and sideA_a == sideB_a:
sideB_V = sideA_V = V_vertical_conical(D, sideA_a, h=sideA_a)
else:
if sideA == 'conical':
sideA_V = V_vertical_conical(D, sideA_a, h=sideA_a)
if sideB == 'conical':
sideB_V = V_vertical_conical(D, sideB_a, h=sideB_a)
if sideA == 'ellipsoidal' and sideB == 'ellipsoidal' and sideA_a == sideB_a:
sideB_V = sideA_V = V_vertical_ellipsoidal(D, sideA_a, h=sideA_a)
else:
if sideA == 'ellipsoidal':
sideA_V = V_vertical_ellipsoidal(D, sideA_a, h=sideA_a)
if sideB == 'ellipsoidal':
sideB_V = V_vertical_ellipsoidal(D, sideB_a, h=sideB_a)
if sideA == 'spherical' and sideB == 'spherical' and sideA_a == sideB_a:
sideB_V = sideA_V = V_vertical_spherical(D, sideA_a, h=sideA_a)
else:
if sideA == 'spherical':
sideA_V = V_vertical_spherical(D, sideA_a, h=sideA_a)
if sideB == 'spherical':
sideB_V = V_vertical_spherical(D, sideB_a, h=sideB_a)
if sideA == 'torispherical' and sideB == 'torispherical' and sideA_f == sideB_f and sideA_k == sideB_k:
sideB_V = sideA_V = V_vertical_torispherical(D, sideA_f, sideA_k, h=sideA_a)
else:
if sideA == 'torispherical':
sideA_V = V_vertical_torispherical(D, sideA_f, sideA_k, h=sideA_a)
if sideB == 'torispherical':
sideB_V = V_vertical_torispherical(D, sideB_f, sideB_k, h=sideB_a)
# Cylindrical section
lateral_V = 0.25 * pi * D * D * L
return lateral_V + sideA_V + sideB_V, sideA_V, sideB_V, lateral_V
def SA_partial_cylindrical_body(L, D, h):
r'''Calculates the partial area of a cylinder's body in the context of
a horizontal cylindrical vessel and liquid partially
filling it. This computes the wetted surface area of the bottom of the
cylinder.
.. math::
\text{SA} = L D \cos^{-1}\left(\frac{D - 2h}{D}\right)
Parameters
----------
L : float
Length of the cylinder, [m]
D : float
Diameter of the cylinder, [m]
h : float
Height measured from bottom of cylinder to liquid level, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area, [m^2]
Notes
-----
This method is undefined for :math:`h > D`. and :math:`h < 0`, but those
cases are handled by returning the full surface area and the zero
respectively.
Examples
--------
>>> SA_partial_cylindrical_body(L=200.0, D=96., h=22.0)
19168.852890279868
References
----------
.. [1] Weisstein, Eric W. "Circular Segment." Text. Wolfram Research, Inc.
Accessed May 10, 2020. https://mathworld.wolfram.com/CircularSegment.html.
'''
if h < 0.0:
return 0.0
elif h > D:
h = D
C = D*acos((D - h - h)/D)
return C*L
def A_partial_circle(D, h):
r'''Calculates the partial area of a circle, in the context of the circle
being an end cap to a horizontal cylindrical vessel and liquid partially
filling it. This computes the wetted surface area of one of the end caps.
Multiply this by two to obtain the wetted area of two end caps.
.. math::
\text{SA} = R^2\cos^{-1}\frac{(R - h)}{R} - (R - h)\sqrt{(2Rh - h^2)}
Parameters
----------
D : float
Diameter of the circle, [m]
h : float
Height measured from bottom of circle to liquid level, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area, [m^2]
Notes
-----
This method is undefined for :math:`h > D` and :math:`h < 0`, but those
cases are handled by returning the full surface area and the zero
respectively.
Examples
--------
>>> A_partial_circle(D=96., h=22.0)
1251.2018147383194
References
----------
.. [1] Weisstein, Eric W. "Circular Segment." Text. Wolfram Research, Inc.
Accessed May 10, 2020. https://mathworld.wolfram.com/CircularSegment.html.
'''
if h > D:
h = D # Catch the case of a computed `h` being trivially larger than `D` due to floating point
elif h < 0.0:
return 0.0
R = 0.5*D
SA = R*R*acos((R - h)/R) - (R - h)*sqrt(2.0*R*h - h*h)
if SA < 0.0:
SA = 0.0 # Catch trig errors
return SA
def circle_segment_area_inner(h, R, A_expect):
# 2 sqrt, 1 acos, 4 division
x0 = R*R
x1 = -h
x2 = R + x1
x3 = sqrt(h*(2.0*R + x1))
x4 = x2*x2
A_err = x0*acos(x2/R) - x2*x3 - A_expect
der = R/sqrt(1.0 - x4/x0) + x3 - x4/x3
return A_err, der
def circle_segment_h_from_A(A, D):
r'''Calculates the height of a chord of a circle given the area of that
circle segment. This is a numerical problem, solving the
following equation for `h`.
.. math::
\text{A} = R^2\cos^{-1}\frac{(R - h)}{R} - (R - h)\sqrt{(2Rh - h^2)}
Parameters
----------
A : float
Circle section area, [m^2]
D : float
Diameter of the circle, [m]
Returns
-------
h : float
Height measured from bottom of circle to the end of the circle section,
[m]
Notes
-----
Examples
--------
>>> circle_segment_h_from_A(A=1251.2018147383194, D=96.)
22.0
References
----------
.. [1] Weisstein, Eric W. "Circular Segment." Text. Wolfram Research, Inc.
Accessed May 10, 2020. https://mathworld.wolfram.com/CircularSegment.html.
'''
if A == 0.0:
return 0.0
R = 0.5*D
return newton(circle_segment_area_inner, x0=0.25*R, fprime=True, high=R, low=0.0,
args=(R, A), xtol=1e-12, bisection=True)
def SA_partial_horiz_conical_head(D, a, h):
r'''Calculates the partial area of a conical tank head in the context of
a horizontal vessel and liquid partially
filling it. This computes the wetted surface area of one of the conical
heads only.
.. math::
\text{SA} = \frac{\sqrt{(a^2 + R^2)}}{R}\left[R^2\cos^{-1}\left(\frac{
(R-h)}{R}\right) - (R-h)\sqrt{(2Rh - h^2)}\right]
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the cone head extends on one side, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area of one conical tank head, [m^2]
Notes
-----
This method is undefined for :math:`h > D` and :math:`h < 0`, but those
cases are handled by returning the full surface area and the zero
respectively.
Examples
--------
>>> SA_partial_horiz_conical_head(D=72., a=48.0, h=24.0)
1980.0498315169873
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
if h > D:
h = D
elif h < 0:
return 0.0
R = 0.5*D
R_inv = 1.0/R
return sqrt(a*a + R*R)*R_inv*(R*R*acos((R-h)*R_inv) - (R-h)*sqrt(2.0*R*h - h*h))
def _SA_partial_horiz_spherical_head_to_int(x, R2, a4, c1, c2):
x2 = x*x
to_pow = (R2 - x2)/(c2 - a4*x2)
if to_pow < 0.0:
to_pow = 0.0
num = c1*sqrt(to_pow)
if num > 1.0:
# Sometimes, the numerical error will result in trying to asin a number just slightly higher than 1 unless we catch it
return 0.5*pi
return asin(num)
def SA_partial_horiz_spherical_head(D, a, h):
r'''Calculates the partial area of a spherical tank head in the context of
a horizontal vessel and liquid partially
filling it. This computes the wetted surface area of one of the spherical
heads only.
.. math::
\text{SA} = \frac{a^2 + R^2}{|a|}\int_{R-h}^R
\sin^{-1} \frac{2|a|\sqrt{R^2-x^2}} {\sqrt{(a^2+R^2)^2 - (2ax)^2}} dx
For the special case of :math:`|a| = R` :
.. math::
\text{SA} = \pi R h
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the spherical head extends on one side, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area of one spherical tank head, [m^2]
Notes
-----
This method is undefined for :math:`h > D` and :math:`h < 0`, but those
cases are handled by returning the full surface area and the zero
respectively.
A symbolic attempt did not suggest any analytical integrals were available.
Examples
--------
>>> SA_partial_horiz_spherical_head(D=72., a=48.0, h=24.0)
2027.2672
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
R = 0.5*D
if a == R:
return pi*R*h
elif h < 0.0:
return 0.0
elif h > D:
h = D
fact = (a*a + R*R)/abs(a)
R2 = R*R
a2 = a + a
a4 = a2*a2
c1 = 2.0*abs(a)
c2 = (a*a + R2)*(a*a + R2)
SA = fact*quad(_SA_partial_horiz_spherical_head_to_int, R-h, R, args=(R2, a4, c1, c2))[0]
return SA
def _SA_partial_horiz_ellipsoidal_head_to_int_dbl(x, y, c1, R2, R4, h):
y2 = y*y
x2 = x*x
num = c1*(x2 + y2) - R4
den = x2 + (y2 - R2) # Brackets help numerical truncation; zero div without it
to_sqrt = num/den
if to_sqrt < 0.0:
# Equation is undefined for y == R when x is zero; avoid it
return _SA_partial_horiz_ellipsoidal_head_to_int_dbl(x, y*(1.0 - 1e-12), c1, R2, R4, h)
return sqrt(to_sqrt)
def _SA_partial_horiz_ellipsoidal_head_limits(x, c1, R2, R4, h):
return [0.0, sqrt(R2 - x*x)]
def _SA_partial_horiz_ellipsoidal_head_limits2(c1, R2, R4, h):
R = sqrt(R2)
return [R-h, R]
def _SA_partial_horiz_ellipsoidal_head_to_int(y, c1, R2, R4):
y2 = y*y
t0 = c1*y2
x6 = c1*(y2 - R2)/(t0 - R4)
ans = sqrt(R4 - t0)*float(ellipe(x6))
return ans
def SA_partial_horiz_ellipsoidal_head(D, a, h):
r'''Calculates the partial area of a ellipsoidal tank head in the context of
a horizontal vessel and liquid partially
filling it. This computes the wetted surface area of one of the ellipsoidal
heads only.
.. math::
\text{SA} = \frac{2}{R} \int_{R-h}^R \int_0^{\sqrt{R^2 - x^2}}
\sqrt{ \frac{(R^2 - a^2)x^2
+ (R^2 - a^2)y^2 - R^4} {x^2 + y^2 - R^2}} dy dx
After extensive manipulation, the first integral was solved analytically,
extending the result of [1]_ with greater performance.
.. math::
\text{SA} = \frac{2}{R} \int_{R-h}^R \frac{\left(\frac{R^{4} - R^{2}
\left(R^{2} - a^{2}\right)}{R^{2} - y^{2}}\right)^{0.5} \left(R^{2}
- y^{2}\right)^{0.5} E{\left(\frac{\left(- R^{2} + y^{2}\right) \left(R^{2}
- a^{2}\right)}{- R^{4} + y^{2} \left(R^{2} - a^{2}\right)} \right)}}
{\left(\frac{R^{4} - R^{2} \left(R^{2} - a^{2}\right)}{R^{4} - y^{2}
\left(R^{2} - a^{2}\right)}\right)^{0.5}}
Where :math:`E(x)` is the complete elliptic integral of the second kind,
calculated with SciPy's link to the cephes library.
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the ellipsoidal head extends on one side, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area of one ellipsoidal tank head, [m^2]
Notes
-----
This method is undefined for :math:`h > D` and :math:`h < 0`, but those
cases are handled by returning the full surface area and the zero
respectively.
The original numerical double integral is extremely nasty - there are places
where f(x) -> infinity but that have a bounded area. quadpack's numerical
integration handles this well, but adaptive inetgration which is not
aware of singularities does not.
Examples
--------
>>> SA_partial_horiz_ellipsoidal_head(D=72., a=48.0, h=24.0)
3401.233622547
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
R = 0.5*D
if h < 0.0:
return 0.0
elif h > D:
h = D
R2 = R*R
R4 = R2*R2
a2 = a*a
c1 = R2 - a2
# from fluids.numerics import dblquad
# from scipy.integrate import dblquad, nquad
## quad_val = nquad(_SA_partial_horiz_ellipsoidal_head_to_int, ranges=[_SA_partial_horiz_ellipsoidal_head_limits, _SA_partial_horiz_ellipsoidal_head_limits2],
## args=(c1, R2, R4, h))[0]
# quad_val = dblquad(_SA_partial_horiz_ellipsoidal_head_to_int, R-h, R, lambda x: 0.0, lambda x: (R2 - x*x)**0.5,
# args=(c1, R2, R4, h))[0]
quad_val = quad(_SA_partial_horiz_ellipsoidal_head_to_int, R-h, R, args=(c1, R2, R4))[0]
SA = 2.0/R*quad_val
return SA
def _SA_partial_horiz_guppy_head_to_int(x, a, R):
x0 = a*a
x1 = R - x
x2 = x1*x1
x3 = 1.0/x2
x4 = x0*x3 + 1.0
x5 = R*R
x6 = x*x
x7 = x5 - x6
x8 = sqrt(x7)
x9 = x4*x8
x10 = x0 + 4.0*x5
x17 = sqrt(sqrt(x10))
x11 = x17*x17
x12 = 1.0/x11
x13 = a*x7
x14 = x12*x13*x3 + 1.0
x15 = a*x12
x16 = sqrt(a)
x18 = 2*atan(x16*x8/(x1*x17))
x19 = 0.5 - 0.5*x15
x100 = (-2.0*R*x*x11 + x11*x5 + x11*x6 + x13)
x20 = x1*x14*sqrt(x2*x5*(x0 + x2)/(x100*x100))/x5
return 0.08333333333333333*(
(-4.0*x10**0.75*x16*x20*ellipeinc(x18, x19) + 4.0*x9
+ 2.0*x17*x20*(a*x11 + x10)*ellipkinc(x18, x19)/x16
+ 8.0*x15*x9/x14)*1.0/sqrt(x4))
def SA_partial_horiz_guppy_head(D, a, h):
r'''Calculates the partial area of a guppy tank head in the context of
a horizontal vessel and liquid partially
filling it. This computes the wetted surface area of one of the guppy
heads only.
.. math::
\text{SA} = 2\int_{-R}^{h-R}\int_{0}^{\sqrt{R^2 - x^2}}
\sqrt{1 + \left(\frac{a}{2R}\left(1 - \frac{y^2}{(R-x)^2} \right)
\right)^2
+ \left(\frac{ay}{R(R-x)} \right)^2 } dy dx
After extensive manipulation, the first integral was solved analytically,
extending the result of [1]_. Even with the special functions, this
form has somewhat greater performance (and improved precision).
.. math::
\text{SA} = 2 \int_{-R}^{h-R} \frac{\frac{2 a \left(4 + \frac{a^{2}
\left(2 R^{2} - 2 R y\right)^{2}}{R^{2} \left(R - y\right)^{4}}\right)
\sqrt{R^{2} - y^{2}}}{\sqrt{4 R^{2} + a^{2}} \left(\frac{a \left(R^{2}
- y^{2}\right)}{\left(R - y\right)^{2} \sqrt{4 R^{2} + a^{2}}}
+ 1\right)} + \left(4 + \frac{a^{2} \left(2 R^{2} - 2 R y\right)
^{2}}{R^{2} \left(R - y\right)^{4}}\right) \sqrt{R^{2} - y^{2}}
- \frac{2 \sqrt{a} \sqrt{\frac{4 R^{2} \left(R - y\right)^{4}
+ a^{2} \left(2 R^{2} - 2 R y\right)^{2}}{\left(R^{2} \sqrt{4 R^{2}
+ a^{2}} - 2 R y \sqrt{4 R^{2} + a^{2}} + a \left(R^{2}
- y^{2}\right) + y^{2} \sqrt{4 R^{2} + a^{2}}\right)^{2}}}
\left(R - y\right) \left(4 R^{2} + a^{2}\right)^{0.75}
\left(\frac{a \left(R^{2} - y^{2}\right)}{\left(R - y\right)^{2}
\sqrt{4 R^{2} + a^{2}}} + 1\right) \operatorname{ellipeinc}{\left(2
\operatorname{atan}{\left(\frac{\sqrt{a} \sqrt{R^{2} - y^{2}}}
{\left(R - y\right) \left(4 R^{2} + a^{2}\right)^{0.25}} \right)},
- \frac{a}{2 \sqrt{4 R^{2} + a^{2}}} + 0.5 \right)}}{R^{2}}
+ \frac{1.0 \sqrt{\frac{4 R^{2} \left(R - y\right)^{4} + a^{2}
\left(2 R^{2} - 2 R y\right)^{2}}{\left(R^{2} \sqrt{4 R^{2}
+ a^{2}} - 2 R y \sqrt{4 R^{2} + a^{2}} + a \left(R^{2} - y^{2}\right)
+ y^{2} \sqrt{4 R^{2} + a^{2}}\right)^{2}}} \left(R - y\right)
\left(4 R^{2} + a^{2}\right)^{0.25} \left(\frac{a \left(R^{2}
- y^{2}\right)}{\left(R - y\right)^{2} \sqrt{4 R^{2} + a^{2}}}
+ 1\right) \left(4 R^{2} + a^{2} + a \sqrt{4 R^{2} + a^{2}}\right)
\operatorname{ellipkinc}{\left(2 \operatorname{atan}{\left(\frac{\sqrt{a}
\sqrt{R^{2} - y^{2}}}{\left(R - y\right) \left(4 R^{2}
+ a^{2}\right)^{0.25}} \right)},- \frac{a}{2 \sqrt{4 R^{2} + a^{2}}}
+ 0.5 \right)}}{R^{2} \sqrt{a}}}{6 \sqrt{4 + \frac{a^{2} \left(2 R^{2}
- 2 R y\right)^{2}}{R^{2} \left(R - y\right)^{4}}}}
Where ellipeinc is the incomplete elliptic integral of the second kind,
and ellipkinc is the incomplete elliptic integral of the first kind,
both calculated with SciPy's link to the cephes library.
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the guppy head extends on one side, [m]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area of one guppy tank head, [m^2]
Notes
-----
This method is undefined for :math:`h > D` and :math:`h < 0`, but those
cases are handled by returning the full surface area and the zero
respectively.
The analytical integral was derived with Rubi.
Examples
--------
>>> SA_partial_horiz_guppy_head(D=72., a=48.0, h=24.0)
1467.8949
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
R = 0.5*D
if a == R:
return pi*R*h
elif h < 0.0:
return 0.0
elif h > D:
h = D
if -R == h-R:
return 0.0
# c1 = a/(2.0*R)
# c2 = c1*c1
# a_R_ratio = a/R
# a_R_ratio2 = a_R_ratio*a_R_ratio
# from scipy.integrate import dblquad
# def to_quad(y, x):
# t1 = y/(R-x)
# t1 *= t1
# t2 = (1.0 - t1)
# return (1.0 + c2*t2*t2 + a_R_ratio2*t1)**0.5
# quad_val = dblquad(to_quad, -R, h-R, lambda x: 0.0, lambda x: (R*R - x*x)**0.5)[0]
quad_val = float(quad(_SA_partial_horiz_guppy_head_to_int, -R, h-R, args=(a, R))[0])
SA = 2.0*quad_val
return SA
def _SA_partial_horiz_torispherical_head_int_1(x, b, c):
x = float(x) # double check python float here to avoid numpy not erroring on sqrt
# May be best to always use complex numbers here
# print('_SA_partial_horiz_torispherical_head_int_1', x, b, c)
x0 = x*x
x1 = b - x0
x2 = sqrt(x1)
x3 = -b + x0
x4 = c*c
try:
x5 = 1.0/sqrt(x1 - x4)
except:
x5 = 1.0/csqrt(x1 - x4)
x6 = x3 + x4
x7 = sqrt(b)
try:
x3_pow = x3**(-1.5)
except:
x3_pow = (x3+0j)**(-1.5)
ans = (x*cacos(c/x2) + x3_pow*x5*(-c*x1*csqrt(-x6*x6)*catan(x*x2/(csqrt(x3)*csqrt(x6)))
+ x6*x7*csqrt(-x1*x1)*catan(c*x*x5/x7))/csqrt(-x6/x1))
# print('_SA_partial_horiz_torispherical_head_int_1', abs(ans.real))
return abs(ans.real)
def _SA_partial_horiz_torispherical_head_int_2(y, t2, s, c1):
# May be best to always use complex numbers here
# from mpmath import mp, mpf, atanh as catanh
# mp.dps=30
# y, t2, s, c1 = mpf(y), mpf(t2), mpf(s), mpf(c1)
y = float(y) # double check python float here to avoid numpy not erroring on sqrt
y2 = y*y
try:
x10 = sqrt(t2 - y2)
try:
# Some tiny heights make the square root slightly under 0
x = (sqrt(c1 - y2 + (s+s)*x10)).real
except:
# Python 2 compat - don't take the square root of a negative number with no complex part
x = (csqrt(c1 - y2 + (s+s)*x10 + 0.0j)).real
except:
x10 = csqrt(t2 - y2+0.0j)
x = (csqrt(c1 - y2 + (s+s)*x10 + 0.0j)).real
try:
x0 = t2 - y2
x1 = s*x10.real
t10 = x1 + x1 + s*s + x0
# x3, x4 present a very nasty numerical problem.
# issue occurs when h == R, x3 is really equal to R**2 - 2*R*h + h**2
x3 = t10 - x*x
x4 = sqrt(x3)
# One solution is to use higher precision everywhere
ans = x4*sqrt(t2*t10/(x0*x3))*catan(x/x4).real
except:
ans = 0.0
# ans = sqrt((t2* (s**2+t2-x**2+2.0*s* sqrt(t2-x**2)))/((t2-x**2)* (s**2+t2-x**2+2 *s* sqrt(t2-x**2)-y**2)))* sqrt(s**2+t2-x**2+2 *s* sqrt(t2-x**2)-y**2) *atan(y/sqrt(s**2+t2-x**2+2 *s* sqrt(t2-x**2)-y**2))
# print(float(y), float(t2), float(s), float(c1), float(ans.real))
# return float(ans.real)
return ans.real
def _SA_partial_horiz_torispherical_head_int_3(y, x, s, t2):
x2 = x*x
y2 = y*y
x10 = sqrt(t2 - x2)
num = (s + x10)*(s + x10)*x2 + (t2 - x2)*y2
den = (t2 - x2)*(s*s + t2 - x2 - y2 + 2.0*s*x10)
f = sqrt(1.0 + num/den)
return f
def SA_partial_horiz_torispherical_head(D, f, k, h):
r'''Calculates the partial area of a torispherical tank head in the context of
a horizontal vessel and liquid partially
filling it. This computes the wetted surface area of one of the torispherical
heads only.
The expressions used are quite complicated; see [1]_ for more details.
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
f : float
Dimensionless dish-radius parameter; also commonly given as the
product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
k : float
Dimensionless knuckle-radius parameter; also commonly given as the
product of `k` and `D` (`kD`), which is called the knuckle radius
and has units of length, [-]
h : float
Height, as measured up to where the fluid ends, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area of one torispherical tank head, [m^2]
Notes
-----
This method is undefined for :math:`h > D` and :math:`h < 0`, but those
cases are handled by returning the full surface area and the zero
respectively.
One integral:
.. math::
\int_{R-h}^{fD\sin \alpha} \cos^{-1} \frac{fD\cos \alpha}{\sqrt{f^2 D^2
- x^2}} dx
Can be computed as follows, using WolframAlpha.
.. math::
x \operatorname{acos}{\left(\frac{c}{\sqrt{b - x^{2}}} \right)} + \frac{\sqrt{b}
\sqrt{- \left(b - x^{2}\right)^{2}} \left(- b + c^{2} + x^{2}\right)
\operatorname{atan}{\left(\frac{c x}{\sqrt{b} \sqrt{b - c^{2} - x^{2}}}
\right)} + c \sqrt{- \left(- b + c^{2} + x^{2}\right)^{2}} \left(- b
+ x^{2}\right) \operatorname{atan}{\left(\frac{x \sqrt{b - x^{2}}}
{\sqrt{- b + x^{2}} \sqrt{- b + c^{2} + x^{2}}} \right)}}{\sqrt{
\frac{- b + c^{2} + x^{2}}{- b + x^{2}}} \left(- b + x^{2}\right)^{1.5}
\sqrt{b - c^{2} - x^{2}}}
With the following constants:
.. math::
c = fD\cos \alpha
.. math::
b = f^2 D^2
The other integral is a double integral. There is an analytical integral
available for the first integral, which takes the form:
.. math::
2 \sqrt{\frac{R^{2} k^{2} \left(4 R^{2} k^{2} - y^{2} + \left(- 2 R k
+ R\right)^{2} + 2 \left(- 2 R k + R\right) \sqrt{4 R^{2} k^{2} - y^{2}}
\right)}{\left(4 R^{2} k^{2} - y^{2}\right) \left(\left(R
- h\right)^{2} - \left(- 4 R k + 2 R\right) \sqrt{4 R^{2} k^{2}
- y^{2}} + 2 \left(- 2 R k + R\right) \sqrt{4 R^{2} k^{2} - y^{2}}
\right)}} \sqrt{\left(R - h\right)^{2} - \left(- 4 R k + 2 R\right)
\sqrt{4 R^{2} k^{2} - y^{2}} + 2 \left(- 2 R k + R\right)
\sqrt{4 R^{2} k^{2} - y^{2}}} \operatorname{atan}{\left(\frac{
\sqrt{4 R^{2} k^{2} - y^{2} - \left(R - h\right)^{2} + \left(- 4 R k
+ 2 R\right) \sqrt{4 R^{2} k^{2} - y^{2}} + \left(- 2 R k + R\right)
^{2}}}{\sqrt{\left(R - h\right)^{2} - \left(- 4 R k + 2 R\right)
\sqrt{4 R^{2} k^{2} - y^{2}} + 2 \left(- 2 R k + R\right)
\sqrt{4 R^{2} k^{2} - y^{2}}}} \right)}
Examples
--------
>>> SA_partial_horiz_torispherical_head(D=72., f=1, k=.06, h=24.0)
1471.201832459
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
if h <= 0.0:
return 0.0
elif h > D:
h = D
R = D/2.
r = f*D
alpha = asin((1.0 - 2.0*k)/(2.*(f-k)))
cos_alpha = cos(alpha)
sin_alpha = sin(alpha)
s = R - k*D
t = k*D
s2 = s*s
t2 = t*t
a1 = r*(1.0 - cos_alpha)
a2 = k*D*cos_alpha
c = f*D*cos_alpha
b = f*f*D*D
c1 = s2 + t2 - (R - h)**2
def G_lim(x): # numba: delete
x2 = x*x # numba: delete
try: # numba: delete
G = sqrt(c1 - x2 + (s+s)*sqrt(t2 - x2)) # numba: delete
except: # numba: delete
# Python 2 compat - don't take the square root of a negative number with no complex part # numba: delete
G = sqrt(c1 - x2 + (s+s)*sqrt(t2 - x2+0.0j) + 0.0j) # numba: delete
return G.real # Some tiny heights make the square root slightly under 0 # numba: delete
limit_1 = k*D*(1.0 - sin_alpha)
if h < limit_1:
SA = quad(_SA_partial_horiz_torispherical_head_int_2, 0.0, sqrt(2*k*D*h - h*h), args=(t2, s, c1))[0]
return 2.0*SA
elif limit_1 < h <= R:
if (D*.499 < h < D*.501): # numba: delete
from scipy.integrate import dblquad # numba: delete
SA = 2.0*dblquad(_SA_partial_horiz_torispherical_head_int_3, 0.0, a2, lambda x: 0, G_lim, args=(s, t2))[0] # numba: delete
# print(SA/2.)
else: # numba: delete
# Numerical issues
SA = 2.0*quad(_SA_partial_horiz_torispherical_head_int_2, 0.0, a2, args=(t2, s, c1))[0] # numba: delete
# print('SA', SA)
# SA = 2.0*quad(_SA_partial_horiz_torispherical_head_int_2, 0.0, a2, args=(t2, s, c1))[0] # numba: uncomment
try:
high = _SA_partial_horiz_torispherical_head_int_1(f*D*sin_alpha, b, c)
except:
# Expression with the substitution is equally complicated
high = _SA_partial_horiz_torispherical_head_int_1(f*D*sin_alpha*(1.0 + 1e-14), b, c)
int_1_term1 = high - _SA_partial_horiz_torispherical_head_int_1(R-h, b, c)
SA += 2.0*f*D*int_1_term1
else:
SA = 2.0*pi*f*D*a1 + 2.0*pi*k*D*(a2 + (R - k*D)*asin(a2/(k*D)))
SA -= SA_partial_horiz_torispherical_head(D, f, k, h=D-h)
return SA
def SA_partial_vertical_conical_head(D, a, h):
r'''Calculates the partial area of a conical tank head in the context of
a vertical vessel and liquid partially
filling it. This computes the wetted surface area of one of the conical
heads only, and is valid for `h` up to `a` only.
.. math::
\text{SA} = \frac{\pi R h^2 \sqrt{a^2 + R^2}}{a^2}
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the cone head extends beneath the vertical tank, [m]
h : float
Height, as measured up to where the fluid ends or the top of the
conical head, whichever is less, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area of one conical tank head extending
beneath the vessel, [m^2]
Notes
-----
This method is undefined for :math:`h < 0`, but this is handled
by returning zero.
Examples
--------
>>> SA_partial_vertical_conical_head(D=72., a=48.0, h=24.0)
1696.4600329384882
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
if a == 0.0:
return 0.25*pi*D*D
elif h <= 0.0:
return 0.0
elif h > a:
h = a
R = 0.5*D
SA = pi*R*h*h*sqrt(a*a + R*R)/(a*a)
return SA
def SA_partial_vertical_ellipsoidal_head(D, a, h):
r'''Calculates the partial area of a ellipsoidal tank head in the context of
a vertical vessel and liquid partially
filling it. This computes the wetted surface area of one of the ellipsoidal
heads only, and is valid for `h` up to `a` only.
If :math:`a > R`:
.. math::
\text{SA} = \pi R^2 - \frac{\pi (a - h)R\sqrt{a^4 - (a-h)^2(a^2-R^2)}}{a^2}
+ \frac{\pi a^2 R}{\sqrt{a^2 - R^2}}\left(
\cos^{-1} \frac{R}{a} - \sin^{-1} \frac{(a-h)\sqrt{a^2-R^2}}{a^2}
\right)
Otherwise for :math:`0 < a < R`:
.. math::
\text{SA} = \pi R^2 - \frac{\pi (a - h)R\sqrt{a^4 - (a-h)^2(a^2-R^2)}}{a^2}
+ \frac{\pi a^2 R}{\sqrt{a^2 - R^2}}\ln \left(\frac{a(\sqrt{R^2 - a^2} + R)}
{(a-h)\sqrt{R^2 - a^2} + \sqrt{a^4 + (a-h)^2(R^2 - a^2)}}
\right)
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the ellipsoidal head extends beneath the vertical tank, [m]
h : float
Height, as measured up to where the fluid ends or the top of the
ellipsoidal head, whichever is less, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area of one ellipsoidal tank head extending
beneath the vessel, [m^2]
Notes
-----
This method is undefined for :math:`h < 0`, but this is handled
by returning zero.
Examples
--------
>>> SA_partial_vertical_ellipsoidal_head(D=72., a=48.0, h=24.0)
4675.23789137632
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
if a == 0.0:
return 0.25*pi*D*D
elif h <= 0.0:
return 0.0
elif h > a:
h = a
# h should be less than a
R = 0.5*D
SA = pi*R*R
a2 = a*a
a_inv = 1.0/a
R2 = R*R
SA -= pi*(a - h)*R*sqrt(a2*a2 - (a-h)*(a-h)*(a2 - R2))*a_inv*a_inv
if a > R:
# This one has issues around a == R
SA += pi*a2*R/sqrt(a2 - R2)*(acos(R*a_inv) - asin((a-h)*sqrt(a2 - R2)*a_inv*a_inv))
elif a == R:
# Special case avoids zero division
return pi*D*h
else:
x1 = sqrt(R2 - a2)
num = a*(x1 + R)
den = (a-h)*x1 + sqrt(a2*a2 + (a-h)*(a-h)*(R2 - a2))
SA += pi*a2*R/x1*log(num/den)
return SA
def SA_partial_vertical_spherical_head(D, a, h):
r'''Calculates the partial area of a spherical tank head in the context of
a vertical vessel and liquid partially
filling it. This computes the wetted surface area of one of the conical
heads only, and is valid for `h` up to `a` only.
.. math::
\text{SA} = \pi h \left(\frac{a^2 + R^2}{a}\right)
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
a : float
Distance the spherical head extends beneath the vertical tank, [m]
h : float
Height, as measured up to where the fluid ends or the top of the
spherical head, whichever is less, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area of one spherical tank head extending
beneath the vessel, [m^2]
Notes
-----
This method is undefined for :math:`h < 0`, but this is handled
by returning zero.
Examples
--------
>>> SA_partial_vertical_spherical_head(72, a=24, h=12)
2940.5307237600464
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
if a == 0.0:
return 0.25*pi*D*D
elif h <= 0.0:
return 0.0
elif h > a:
h = a
R = 0.5*D
SA = pi*h*((a*a + R*R)/a)
return SA
def SA_partial_vertical_torispherical_head(D, f, k, h):
r'''Calculates the partial area of a torispherical tank head in the context of
a vertical vessel and liquid partially
filling it. This computes the wetted surface area of one of the torispherical
heads only.
if :math:`a_1 <= h`:
.. math::
\text{SA} = 2\pi f D h
if :math:`a_1 \le h \le a`:
.. math::
\text{SA} = 2\pi f D a_1 + 2\pi k D\left(
h - a_1 + (R - kD) \left(
\sin^{-1} \frac{a_2}{kD} - \sin^{-1} \frac{a-h}{kD} \right) \right)
.. math::
\alpha = \sin^{-1}\frac{1-2k}{2(f-k)}
.. math::
a_1 = fD(1-\cos\alpha)
.. math::
a_2 = kD\cos\alpha
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
f : float
Dimensionless dish-radius parameter; also commonly given as the
product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
k : float
Dimensionless knuckle-radius parameter; also commonly given as the
product of `k` and `D` (`kD`), which is called the knuckle radius
and has units of length, [-]
h : float
Height, as measured up to where the fluid ends or the top of the
torispherical head, whichever is less, [m]
Returns
-------
SA_partial : float
Partial (wetted) surface area of one torispherical tank head, [m^2]
Notes
-----
This method is undefined for :math:`h > D` and :math:`h < 0`, but those
cases are handled by returning the full surface area and the zero
respectively.
Examples
--------
This method is undefined for :math:`h < 0`, but this is handled
by returning zero.
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
'''
if h <= 0.0:
return 0.0
R = 0.5*D
alpha = asin((1.0 - 2.0*k)/(2.0*(f-k)))
cos_alpha = cos(alpha)
a1 = f*D*(1.0 - cos_alpha)
a2 = k*D*cos_alpha
a = a1 + a2
if h > a:
h = a
if h < a1:
SA = 2.0*pi*f*D*h
elif a1 <= h <= a:
SA = 2.0*pi*f*D*a1
kD_inv = 1.0/(k*D)
SA += 2.0*pi*k*D*(h - a1 + (R - k*D)*(asin(a2*kD_inv) - asin((a-h)*kD_inv)))
else:
# This case should not occur due to the earlier checks
return 0.0
return SA
def a_torispherical(D, f, k):
r'''Calculates depth of a torispherical head according to [1]_.
.. math::
a = a_1 + a_2
.. math::
\alpha = \sin^{-1}\frac{1-2k}{2(f-k)}
.. math::
a_1 = fD(1-\cos\alpha)
.. math::
a_2 = kD\cos\alpha
Parameters
----------
D : float
Diameter of the main cylindrical section, [m]
f : float
Dimensionless dish-radius parameter; also commonly given as the
product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
k : float
Dimensionless knuckle-radius parameter; also commonly given as the
product of `k` and `D` (`kD`), which is called the knuckle radius
and has units of length, [-]
Returns
-------
a : float
Depth of head [m]
Examples
--------
Example from [1]_.
>>> a_torispherical(D=96., f=0.9, k=0.2)
25.684268924767125
References
----------
.. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
http://www.webcalc.com.br/blog/Tank_Volume.PDF
'''
alpha = asin((1.0-2.0*k)/(2.0*(f-k)))
cos_alpha = cos(alpha)
a1 = f*D*(1 - cos_alpha)
a2 = k*D*cos_alpha
return a1 + a2
def V_from_h(h, D, L, horizontal=True, sideA=None, sideB=None, sideA_a=0,
sideB_a=0, sideA_f=None, sideA_k=None, sideB_f=None, sideB_k=None):
r'''Calculates partially full volume of a vertical or horizontal tank with
different head types according to [1]_.
If the height specified is above the height of the tank, it is truncated
to the top of the tank.
Parameters
----------
h : float
Height of the liquid in the tank, [m]
D : float
Diameter of the cylindrical section of the tank, [m]
L : float
Length of the main cylindrical section of the tank, [m]
horizontal : bool, optional
Whether or not the tank is a horizontal or vertical tank
sideA : string, optional
The left (or bottom for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical'].
sideB : string, optional
The right (or top for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical'].
sideA_a : float, optional
The distance the head as specified by sideA extends down or to the left
from the main cylindrical section, [m]
sideB_a : float, optional
The distance the head as specified by sideB extends up or to the right
from the main cylindrical section, [m]
sideA_f : float, optional
Dimensionless dish-radius parameter for side A; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideA_k : float, optional
Dimensionless knuckle-radius parameter for side A; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
sideB_f : float, optional
Dimensionless dish-radius parameter for side B; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideB_k : float, optional
Dimensionless knuckle-radius parameter for side B; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
Returns
-------
V : float
Volume up to h [m^3]
Examples
--------
>>> V_from_h(h=7, D=1.5, L=5., horizontal=False, sideA='conical',
... sideB='conical', sideA_a=2., sideB_a=1.)
10.013826583317465
References
----------
.. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical
Processing. December 18, 2003.
http://www.chemicalprocessing.com/articles/2003/193/
'''
if sideA is not None and sideA not in ('conical', 'ellipsoidal', 'torispherical', 'spherical', 'guppy'):
raise ValueError('Unspoorted head type for side A')
if sideB is not None and sideB not in ('conical', 'ellipsoidal', 'torispherical', 'spherical', 'guppy'):
raise ValueError('Unspoorted head type for side B')
R = 0.5*D
V = 0.0
if horizontal:
if h > D: # Must be before Af, which will raise a domain error
h = D
# Conical case
if sideA == 'conical' and sideB == 'conical' and sideA_a == sideB_a:
V += 2.0*V_horiz_conical(D, L, sideA_a, h, headonly=True)
else:
if sideA == 'conical':
V += V_horiz_conical(D, L, sideA_a, h, headonly=True)
if sideB == 'conical':
V += V_horiz_conical(D, L, sideB_a, h, headonly=True)
# Elliosoidal case
if sideA == 'ellipsoidal' and sideB == 'ellipsoidal' and sideA_a == sideB_a:
V += 2.0*V_horiz_ellipsoidal(D, L, sideA_a, h, headonly=True)
else:
if sideA == 'ellipsoidal':
V += V_horiz_ellipsoidal(D, L, sideA_a, h, headonly=True)
if sideB == 'ellipsoidal':
V += V_horiz_ellipsoidal(D, L, sideB_a, h, headonly=True)
# Guppy case
if sideA == 'guppy' and sideB == 'guppy' and sideA_a == sideB_a:
V += 2.0*V_horiz_guppy(D, L, sideA_a, h, headonly=True)
else:
if sideA == 'guppy':
V += V_horiz_guppy(D, L, sideA_a, h, headonly=True)
if sideB == 'guppy':
V += V_horiz_guppy(D, L, sideB_a, h, headonly=True)
# Spherical case
if sideA == 'spherical' and sideB == 'spherical' and sideA_a == sideB_a:
V += 2.0*V_horiz_spherical(D, L, sideA_a, h, headonly=True)
else:
if sideA == 'spherical':
V += V_horiz_spherical(D, L, sideA_a, h, headonly=True)
if sideB == 'spherical':
V += V_horiz_spherical(D, L, sideB_a, h, headonly=True)
# Torispherical case
if (sideA == 'torispherical' and sideB == 'torispherical'
and (sideA_f == sideB_f) and (sideA_k == sideB_k)):
V += 2.0*V_horiz_torispherical(D, L, sideA_f, sideA_k, h, headonly=True)
else:
if sideA == 'torispherical':
V += V_horiz_torispherical(D, L, sideA_f, sideA_k, h, headonly=True)
if sideB == 'torispherical':
V += V_horiz_torispherical(D, L, sideB_f, sideB_k, h, headonly=True)
Af = R*R*acos((R-h)/R) - (R-h)*sqrt(2.0*R*h - h*h)
V += L*Af
else:
max_h = L + sideA_a + sideB_a
if h > max_h:
h = max_h
# Bottom head
if sideA in ('conical', 'ellipsoidal', 'torispherical', 'spherical'):
if sideA == 'conical':
V += V_vertical_conical(D, sideA_a, h=min(sideA_a, h))
if sideA == 'ellipsoidal':
V += V_vertical_ellipsoidal(D, sideA_a, h=min(sideA_a, h))
if sideA == 'spherical':
V += V_vertical_spherical(D, sideA_a, h=min(sideA_a, h))
if sideA == 'torispherical':
V += V_vertical_torispherical(D, sideA_f, sideA_k, h=min(sideA_a, h))
# Cylindrical section
if h >= sideA_a + L:
V += 0.25*pi*D*D*L # All middle
elif h > sideA_a:
V += 0.25*pi*D*D*(h - sideA_a) # Partial middle
# Top head
if h > sideA_a + L:
h2 = sideB_a - (h - sideA_a - L)
if sideB == 'conical':
V += V_vertical_conical(D, sideB_a, h=sideB_a)
V -= V_vertical_conical(D, sideB_a, h=h2)
if sideB == 'ellipsoidal':
V += V_vertical_ellipsoidal(D, sideB_a, h=sideB_a)
V -= V_vertical_ellipsoidal(D, sideB_a, h=h2)
if sideB == 'spherical':
V += V_vertical_spherical(D, sideB_a, h=sideB_a)
V -= V_vertical_spherical(D, sideB_a, h=h2)
if sideB == 'torispherical':
V += V_vertical_torispherical(D, sideB_f, sideB_k, h=sideB_a)
V -= max(0.0, V_vertical_torispherical(D, sideB_f, sideB_k, h=h2))
return V
def SA_from_h(h, D, L, horizontal=True, sideA=None, sideB=None, sideA_a=0.0,
sideB_a=0.0, sideA_f=None, sideA_k=None, sideB_f=None, sideB_k=None):
r'''Calculates partially full wetted surface area of a vertical or horizontal tank with
different head types according to [1]_.
Parameters
----------
h : float
Height of the liquid in the tank, [m]
D : float
Diameter of the cylindrical section of the tank, [m]
L : float
Length of the main cylindrical section of the tank, [m]
horizontal : bool, optional
Whether or not the tank is a horizontal or vertical tank
sideA : string, optional
The left (or bottom for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical'].
sideB : string, optional
The right (or top for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical'].
sideA_a : float, optional
The distance the head as specified by sideA extends down or to the left
from the main cylindrical section, [m]
sideB_a : float, optional
The distance the head as specified by sideB extends up or to the right
from the main cylindrical section, [m]
sideA_f : float, optional
Dimensionless dish-radius parameter for side A; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideA_k : float, optional
Dimensionless knuckle-radius parameter for side A; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
sideB_f : float, optional
Dimensionless dish-radius parameter for side B; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideB_k : float, optional
Dimensionless knuckle-radius parameter for side B; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
Returns
-------
SA : float
Wetted wall surface area up to h [m^3]
Examples
--------
>>> SA_from_h(h=7, D=1.5, L=5., horizontal=False, sideA='conical',
... sideB='conical', sideA_a=2., sideB_a=1.)
28.59477853914843
References
----------
.. [1] Jones, D. "Calculating Tank Wetted Area." Text. Chemical Processing.
April 2017. https://www.chemicalprocessing.com/assets/Uploads/calculating-tank-wetted-area.pdf
http://www.chemicalprocessing.com/articles/2003/193/
'''
if sideA is not None and sideA not in ('conical', 'ellipsoidal', 'torispherical', 'spherical', 'guppy'):
raise ValueError('Unspoorted head type for side A')
if sideB is not None and sideB not in ('conical', 'ellipsoidal', 'torispherical', 'spherical', 'guppy'):
raise ValueError('Unspoorted head type for side B')
R = 0.5*D
SA = 0.0
if horizontal:
if h > D:
h = D
# Conical case
if sideA == 'conical':
SA += SA_partial_horiz_conical_head(D, sideA_a, h)
if sideB == 'conical':
SA += SA_partial_horiz_conical_head(D, sideB_a, h)
# Elliosoidal case
if sideA == 'ellipsoidal':
SA += SA_partial_horiz_ellipsoidal_head(D, sideA_a, h)
if sideB == 'ellipsoidal':
SA += SA_partial_horiz_ellipsoidal_head(D, sideB_a, h)
# Guppy case
if sideA == 'guppy':
SA += SA_partial_horiz_guppy_head(D, sideA_a, h)
if sideB == 'guppy':
SA += SA_partial_horiz_guppy_head(D, sideB_a, h)
# Spherical case
if sideA == 'spherical':
SA += SA_partial_horiz_spherical_head(D, sideA_a, h)
if sideB == 'spherical':
SA += SA_partial_horiz_spherical_head(D, sideB_a, h)
# Torispherical case
if sideA == 'torispherical':
if sideA_f is not None and sideA_k is not None:
SA += SA_partial_horiz_torispherical_head(D, sideA_f, sideA_k, h)
else:
raise ValueError("Torispherical sideA but no `f` and `k` provided")
if sideB == 'torispherical':
if sideB_f is not None and sideB_k is not None:
SA += SA_partial_horiz_torispherical_head(D, sideB_f, sideB_k, h)
else:
raise ValueError("Torispherical sideB but no `f` and `k` provided")
# Flat case
if sideA is None:
SA += A_partial_circle(D, h)
if sideB is None:
SA += A_partial_circle(D, h)
SA += L*D*acos((D - h - h)/D)
else:
max_h = L + sideA_a + sideB_a
if h > max_h:
h = max_h
# Bottom head
if sideA in ('conical', 'ellipsoidal', 'torispherical', 'spherical'):
if sideA == 'conical':
SA += SA_partial_vertical_conical_head(D, sideA_a, h=min(sideA_a, h))
elif sideA == 'ellipsoidal':
SA += SA_partial_vertical_ellipsoidal_head(D, sideA_a, h=min(sideA_a, h))
elif sideA == 'spherical':
SA += SA_partial_vertical_spherical_head(D, sideA_a, h=min(sideA_a, h))
elif sideA == 'torispherical':
if sideA_f is not None and sideA_k is not None:
SA += SA_partial_vertical_torispherical_head(D, sideA_f, sideA_k, h=min(sideA_a, h))
else:
raise ValueError("Torispherical sideA but no `f` and `k` provided")
elif sideA is None:
SA += 0.25*pi*D*D
# Cylindrical section
if h >= sideA_a + L:
SA += pi*D*L # All middle
elif h > sideA_a:
SA += pi*D*(h - sideA_a) # Partial middle
# Top head
if h >= sideA_a + L: # greater or equals is needed! Flat head on top adds lots of area.
h2 = sideB_a - (h - sideA_a - L)
if sideB == 'conical':
if sideB_a == 0.0:
SA += 0.25*pi*D*D
else:
SA += SA_partial_vertical_conical_head(D, sideB_a, h=sideB_a)
SA -= SA_partial_vertical_conical_head(D, sideB_a, h=h2)
elif sideB == 'ellipsoidal':
if sideB_a == 0.0:
SA += 0.25*pi*D*D
else:
SA += SA_partial_vertical_ellipsoidal_head(D, sideB_a, h=sideB_a)
SA -= SA_partial_vertical_ellipsoidal_head(D, sideB_a, h=h2)
elif sideB == 'spherical':
if sideB_a == 0.0:
SA += 0.25*pi*D*D
else:
SA += SA_partial_vertical_spherical_head(D, sideB_a, h=sideB_a)
SA -= SA_partial_vertical_spherical_head(D, sideB_a, h=h2)
elif sideB == 'torispherical':
if sideB_a == 0.0:
SA += 0.25*pi*D*D
else:
if sideB_f is not None and sideB_k is not None:
SA += SA_partial_vertical_torispherical_head(D, sideB_f, sideB_k, h=sideB_a)
SA -= max(0.0, SA_partial_vertical_torispherical_head(D, sideB_f, sideB_k, h=h2))
else:
raise ValueError("Torispherical sideB but no `f` and `k` provided")
elif sideB is None and h == sideA_a + L:
# End cap if flat
SA += 0.25*pi*D*D
return SA
def tank_from_two_specs_err(guess, spec0, spec1, spec0_name, spec1_name,
h, horizontal, sideA, sideB, sideA_a, sideB_a,
sideA_f, sideA_k, sideB_f, sideB_k,
sideA_a_ratio, sideB_a_ratio):
D, L_over_D = float(guess[0]), float(guess[1])
obj = TANK(D=D, L_over_D=L_over_D, horizontal=horizontal,
sideA=sideA, sideB=sideB, sideA_a=sideA_a, sideB_a=sideB_a,
sideA_f=sideA_f, sideA_k=sideA_k, sideB_f=sideB_f, sideB_k=sideB_k,
sideA_a_ratio=sideA_a_ratio, sideB_a_ratio=sideB_a_ratio)
# ensure h is always under the top
h = min(h, obj.h_max)
if spec0_name == 'V':
err0 = obj.V_total - spec0
elif spec0_name == 'SA':
err0 = obj.A - spec0
elif spec0_name == 'V_partial':
err0 = obj.V_from_h(h) - spec0
elif spec0_name == 'SA_partial':
err0 = obj.SA_from_h(h) - spec0
elif spec0_name == 'A_cross':
err0 = obj.A_cross_sectional(h) - spec0
if spec1_name == 'V':
err1 = obj.V_total - spec1
elif spec1_name == 'SA':
err1 = obj.A - spec1
elif spec1_name == 'V_partial':
err1 = obj.V_from_h(h) - spec1
elif spec1_name == 'SA_partial':
err1 = obj.SA_from_h(h) - spec1
elif spec1_name == 'A_cross':
err1 = obj.A_cross_sectional(h) - spec1
# print(err0, err1, D, L_over_D, h)
return [err0, err1]
class TANK:
"""Class representing tank volumes and levels. All parameters are also
attributes.
Parameters
----------
D : float
Diameter of the cylindrical section of the tank, [m]
L : float
Length of the main cylindrical section of the tank, [m]
horizontal : bool, optional
Whether or not the tank is a horizontal or vertical tank
sideA : string, optional
The left (or bottom for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical',
'same'].
sideB : string, optional
The right (or top for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical',
'same'].
sideA_a : float, optional
The distance the head as specified by sideA extends down or to the left
from the main cylindrical section, [m]
sideB_a : float, optional
The distance the head as specified by sideB extends up or to the right
from the main cylindrical section, [m]
sideA_f : float, optional
Dimensionless dish-radius parameter for side A; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideA_k : float, optional
Dimensionless knuckle-radius parameter for side A; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
sideB_f : float, optional
Dimensionless dish-radius parameter for side B; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideB_k : float, optional
Dimensionless knuckle-radius parameter for side B; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
sideA_a_ratio : float, optional
Ratio for `a` parameter; can be used instead of specifying an absolute
value, [-]
sideB_a_ratio : float, optional
Ratio for `a` parameter; can be used instead of specifying an absolute
value, [-]
L_over_D : float, optional
Ratio of length over diameter, used only when D and L are both
unspecified but V is, [-]
V : float, optional
Volume of the tank; solved for if specified, using
sideA_a_ratio/sideB_a_ratio, sideA, sideB, horizontal, and one
of L_over_D, L, or D, [m^3]
Attributes
----------
h_max : float
Height of the tank, [m]
V_total : float
Total volume of the tank as calculated [m^3]
sideA_V : float
Volume of only `sideA` [m^3]
sideB_V : float
Volume of only `sideB` [m^3]
lateral_V : float
Volume of cylindrical section of tank [m^3]
A : float
Total surface area of the tank, [m^2]
A_sideA : float
Surface area of sideA, [m^2]
A_sideB : float
Surface area of sideB, [m^2]
A_lateral : float
Surface area of the lateral side, [m^2]
A_sideA_extra : float
Additional surface area of sideA beyond that of a flat disk, [m^2]
A_sideB_extra : float
Additional surface area of sideB beyond that of a flat disk, [m^2]
table : bool
Whether or not a table of heights-volumes has been generated
heights : ndarray
Array of heights between 0 and h_max, [m]
volumes : ndarray
Array of volumes calculated from the heights, [m^3]
c_forward : ndarray
Coefficients for the Chebyshev approximations in calculating V from h,
[-]
c_backward : ndarray
Coefficients for the Chebyshev approximations in calculating h from V,
[-]
Notes
-----
For torpsherical tank heads, the following `f` and `k` parameters are used
in standards. The default is ASME F&D.
+----------------------+-----+-------+
| | f | k |
+======================+=====+=======+
| 2:1 semi-elliptical | 0.9 | 0.17 |
+----------------------+-----+-------+
| ASME F&D | 1 | 0.06 |
+----------------------+-----+-------+
| ASME 80/6 | 0.8 | 0.06 |
+----------------------+-----+-------+
| ASME 80/10 F&D | 0.8 | 0.1 |
+----------------------+-----+-------+
| DIN 28011 | 1 | 0.1 |
+----------------------+-----+-------+
| DIN 28013 | 0.8 | 0.154 |
+----------------------+-----+-------+
For the following cases, numerical integrals are used.
V_horiz_spherical
V_horiz_torispherical
SA_partial_horiz_spherical_head
SA_partial_horiz_ellipsoidal_head
SA_partial_horiz_guppy_head
SA_partial_horiz_torispherical_head
Examples
--------
Total volume of a tank:
>>> TANK(D=1.2, L=4, horizontal=False).V_total
4.523893421169302
Volume of a tank at a given height:
>>> TANK(D=1.2, L=4, horizontal=False).V_from_h(.5)
0.5654866776461628
Height of liquid for a given volume:
>>> TANK(D=1.2, L=4, horizontal=False).h_from_V(.5)
0.442097064
Surface area of a tank with a conical head:
>>> T1 = TANK(V=10, L_over_D=0.7, sideB='conical', sideB_a=0.5)
>>> T1.A, T1.A_sideA, T1.A_sideB, T1.A_lateral
(24.94775907, 5.118555, 5.497246, 14.331956)
Solving for tank volumes, first horizontal, then vertical:
>>> TANK(D=10., horizontal=True, sideA='conical', sideB='conical', V=500).L
4.699531
>>> TANK(L=4.69953105701, horizontal=True, sideA='conical', sideB='conical', V=500).D
9.9999999
>>> TANK(L_over_D=0.469953105701, horizontal=True, sideA='conical', sideB='conical', V=500).L
4.6995310
>>> TANK(D=10., horizontal=False, sideA='conical', sideB='conical', V=500).L
4.699531
>>> TANK(L=4.69953105701, horizontal=False, sideA='conical', sideB='conical', V=500).D
9.99999999
>>> TANK(L_over_D=0.469953105701, horizontal=False, sideA='conical', sideB='conical', V=500).L
4.699531057
"""
table = False
chebyshev = False
__full_path__ = __module__ + '.TANK'
def __str__(self): # pragma: no cover
orient = 'Horizontal' if self.horizontal else 'Vertical'
if self.sideA is None and self.sideB is None:
sides = 'no heads'
elif self.sideA == self.sideB:
if self.sideA_a == self.sideB_a:
sides = self.sideA + (f' heads, a={self.sideA_a:f} m')
else:
sides = self.sideA + f' heads, sideA a={self.sideA_a:f} m, sideB a={self.sideB_a:f} m'
else:
if self.sideA:
A = f'{self.sideA} head on sideA with a={self.sideA_a:f} m'
else:
A = 'no head on sideA'
if self.sideB:
B = f' and {self.sideB} head on sideB with a={self.sideB_a:f} m'
else:
B = ' and no head on sideB'
sides = A + B
return f'<{orient} tank, V={self.V_total:f} m^3, D={self.D:f} m, L={self.L:f} m, {sides}.>'
def __repr__(self):
attributes = ', '.join(f"{slot}={getattr(self, slot)!r}" for slot in self.model_inputs if getattr(self, slot) is not None)
return f"{self.__class__.__name__}({attributes})"
def __hash__(self):
return hash(tuple(getattr(self, slot) for slot in self.model_inputs))
model_inputs = ('D', 'L', 'horizontal', 'sideA', 'sideB', 'sideA_a', 'sideB_a',
'sideA_f', 'sideA_k', 'sideB_f', 'sideB_k', 'sideA_a_ratio', 'sideB_a_ratio', 'L_over_D', 'V')
def __init__(self, D=None, L=None, horizontal=True,
sideA=None, sideB=None, sideA_a=None, sideB_a=None,
sideA_f=None, sideA_k=None, sideB_f=None, sideB_k=None,
sideA_a_ratio=None, sideB_a_ratio=None, L_over_D=None, V=None):
self.D = D
self.L = L
self.L_over_D = L_over_D
self.V = V
self.horizontal = horizontal
sideA_same, sideB_same = sideA == 'same', sideB == 'same'
if sideA_same and not sideB_same:
sideA, sideA_a, sideA_a_ratio, sideA_f, sideA_k = sideB, sideB_a, sideB_a_ratio, sideB_f, sideB_k
elif sideB_same and not sideA_same:
sideB, sideB_a, sideB_a_ratio, sideB_f, sideB_k = sideA, sideA_a, sideA_a_ratio, sideA_f, sideA_k
elif sideA_same and sideB_same:
raise ValueError("Cannot specify both sides as same")
self.sideA = sideA
if sideA is None and sideA_a is None:
sideA_a = 0.0
self.sideA_a = sideA_a
if sideA_a is None and sideA_a_ratio is None and (sideA is not None and sideA != 'torispherical'):
sideA_a_ratio = 0.25
self.sideA_a_ratio = sideA_a_ratio
if sideA_a is None and sideA == 'torispherical':
if sideA_f is None:
sideA_f = 1.0
if sideA_k is None:
sideA_k = 0.06
self.sideA_f = sideA_f
self.sideA_k = sideA_k
self.sideB = sideB
if sideB is None and sideB_a is None:
sideB_a = 0.0
self.sideB_a = sideB_a
if sideB_a is None and sideB_a_ratio is None and (sideB is not None and sideB != 'torispherical'):
sideB_a_ratio = 0.25
self.sideB_a_ratio = sideB_a_ratio
if sideB_a is None and sideB == 'torispherical':
if sideB_f is None:
sideB_f = 1.0
if sideB_k is None:
sideB_k = 0.06
self.sideB_f = sideB_f
self.sideB_k = sideB_k
if self.horizontal:
self.vertical = False
self.orientation = 'horizontal'
self.angle = 0
else:
self.vertical = True
self.orientation = 'vertical'
self.angle = 90
# If V is specified and either L or D are known, solve for L, D, L_over_D
if self.V:
self._solve_tank_for_V()
self.set_misc()
def set_misc(self):
"""Set more parameters, after the tank is better defined than in the
__init__ function.
Notes
-----
Two of D, L, and L_over_D must be known when this function runs.
The other one is set from the other two first thing in this function.
a_ratio parameters are used to calculate a values for the heads here,
if applicable.
Radius is calculated here.
Maximum tank height is calculated here.
V_total is calculated here.
"""
if self.D is not None and self.L is not None:
# If L and D are known, get L_over_D
self.L_over_D = self.L/self.D
elif self.D is not None and self.L_over_D is not None:
# Otherwise, if L_over_D and D are provided, get L
self.L = self.D*self.L_over_D
elif self.L is not None and self.L_over_D is not None:
# Otherwise, if L_over_D and L are provided, get D
self.D = self.L/self.L_over_D
D = self.D
# Calculate diameter
self.R = self.D/2.
# If a_ratio is provided for either heads, use it.
if self.sideA is not None and D is not None and self.sideA_a is None and self.sideA in ('conical', 'ellipsoidal', 'guppy', 'spherical'):
self.sideA_a = D*self.sideA_a_ratio
if self.sideB is not None and D is not None and self.sideB_a is None and self.sideB in ('conical', 'ellipsoidal', 'guppy', 'spherical'):
self.sideB_a = D*self.sideB_a_ratio
# Calculate a for torispherical heads
if self.sideA == 'torispherical' and self.sideA_f is not None and self.sideA_k is not None:
self.sideA_a = a_torispherical(D, self.sideA_f, self.sideA_k)
if self.sideB == 'torispherical' and self.sideB_f is not None and self.sideB_k is not None:
self.sideB_a = a_torispherical(D, self.sideB_f, self.sideB_k)
# Ensure the correct a_ratios are set, whether there is a default being used or not
if self.sideA_a_ratio is None and self.sideA_a is not None:
self.sideA_a_ratio = self.sideA_a/D
elif self.sideA_a_ratio is not None and self.sideA_a is not None and self.sideA_a != D*self.sideA_a_ratio:
self.sideA_a_ratio = self.sideA_a/D
if self.sideB_a_ratio is None and self.sideB_a is not None:
self.sideB_a_ratio = self.sideB_a/D
elif self.sideB_a_ratio is not None and self.sideB_a is not None and self.sideB_a != D*self.sideB_a_ratio:
self.sideB_a_ratio = self.sideB_a/D
# Calculate maximum tank height, h_max
if self.horizontal:
self.h_max = D
else:
self.h_max = self.L
if self.sideA_a:
self.h_max += self.sideA_a
if self.sideB_a:
self.h_max += self.sideB_a
# Set maximum height
# self.V_total = self.V_from_h(self.h_max)
self.V_total, self.V_sideA, self.V_sideB, self.V_lateral = V_tank(
D=D, L=self.L, sideA=self.sideA, sideB=self.sideB, sideA_a=self.sideA_a,
sideB_a=self.sideB_a, sideA_f=self.sideA_f, sideA_k=self.sideA_k,
sideB_f=self.sideB_f, sideB_k=self.sideB_k, horizontal=self.horizontal)
# Set surface areas
self.A, self.A_sideA, self.A_sideB, self.A_lateral = SA_tank(
D=D, L=self.L, sideA=self.sideA, sideB=self.sideB, sideA_a=self.sideA_a,
sideB_a=self.sideB_a, sideA_f=self.sideA_f, sideA_k=self.sideA_k,
sideB_f=self.sideB_f, sideB_k=self.sideB_k)
A_circular_plate = 0.25*pi*D*D
self.A_sideA_extra = self.A_sideA - A_circular_plate
self.A_sideB_extra = self.A_sideB - A_circular_plate
@staticmethod
def from_two_specs(spec0, spec1, spec0_name='V', spec1_name='A_cross',
h=None, horizontal=True,
sideA=None, sideB=None, sideA_a=None, sideB_a=None,
sideA_f=None, sideA_k=None, sideB_f=None, sideB_k=None,
sideA_a_ratio=None, sideB_a_ratio=None):
r'''Method to create a new tank instance according to two
specifications which are not direct geometry parameters.
The allowable options are 'V', 'SA', 'V_partial', 'SA_partial',
and 'A_cross', the later three of which require `h` to be specified.
Parameters
----------
spec0 : float
Goal for `spec0_name`, [-]
spec1 : float
Goal for `spec1_name`, [-]
spec0_name : str
One of 'V', 'SA', 'V_partial', 'SA_partial', and 'A_cross' [-]
spec1_name : str
One of 'V', 'SA', 'V_partial', 'SA_partial', and 'A_cross' [-]
h : float
Height at which to calculate the specs, [m]
horizontal : bool, optional
Whether or not the tank is a horizontal or vertical tank
sideA : string, optional
The left (or bottom for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical',
'same'].
sideB : string, optional
The right (or top for vertical) head of the tank's type; one of
[None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical',
'same'].
sideA_a : float, optional
The distance the head as specified by sideA extends down or to the left
from the main cylindrical section, [m]
sideB_a : float, optional
The distance the head as specified by sideB extends up or to the right
from the main cylindrical section, [m]
sideA_f : float, optional
Dimensionless dish-radius parameter for side A; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideA_k : float, optional
Dimensionless knuckle-radius parameter for side A; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
sideB_f : float, optional
Dimensionless dish-radius parameter for side B; also commonly given as
the product of `f` and `D` (`fD`), which is called dish radius and
has units of length, [-]
sideB_k : float, optional
Dimensionless knuckle-radius parameter for side B; also commonly given
as the product of `k` and `D` (`kD`), which is called the knuckle
radius and has units of length, [-]
Returns
-------
TANK : TANK
Tank object at solved specifications, [-]
Notes
-----
Limited testing has been done on this method. The bounds are D between
0.1 mm and 10 km, with L_D ratios of 1e-4 to 1e4.
'''
args = (spec0, spec1, spec0_name, spec1_name,
h, horizontal, sideA, sideB, sideA_a, sideB_a,
sideA_f, sideA_k, sideB_f, sideB_k,
sideA_a_ratio, sideB_a_ratio)
new_f, translate_into, translate_outof = translate_bound_func(tank_from_two_specs_err,
bounds=[(1e-4, 1e4), (1e-4, 1e4)])
# Diameter and length/diameter as iteration variables
guess = translate_into([1.0, 3.0])
from scipy.optimize import fsolve
ans = fsolve(new_f, guess, args=args, xtol=1e-10, factor=.1)
val0, val1 = translate_outof(ans)
return TANK(D=float(val0), L_over_D=float(val1), horizontal=horizontal,
sideA=sideA, sideB=sideB, sideA_a=sideA_a, sideB_a=sideB_a,
sideA_f=sideA_f, sideA_k=sideA_k, sideB_f=sideB_f, sideB_k=sideB_k,
sideA_a_ratio=sideA_a_ratio, sideB_a_ratio=sideB_a_ratio,)
def add_thickness(self, thickness, sideA_thickness=None,
sideB_thickness=None):
r'''Method to create a new tank instance with the same parameters as
itself, except with an added thickness to it. This is useful to obtain
ex. the inside of a tank and the outside; their different in volumes is
the volume of the shell, and could be used to determine weight.
Parameters
----------
thickness : float
Thickness to add to the tank diameter, [m]
sideA_thickness : float, optional
The thickness to add to the sideA head; if not specified,
it will be `thickness`, [m]
sideB_thickness : float, optional
The thickness to add to the sideB head; if not specified,
it will be `thickness`, [m]
Returns
-------
TANK : TANK
Tank object, [-]
Notes
-----
Be careful not to specify a negative thickness larger than the heads'
lengths, or the head will become concave! The same applies to adding
a thickness to convex heads - they can become convex.
'''
kwargs = dict(D=self.D, L=self.L, horizontal=self.horizontal,
sideA=self.sideA, sideB=self.sideB, sideA_a=self.sideA_a,
sideB_a=self.sideB_a, sideA_f=self.sideA_f,
sideA_k=self.sideA_k, sideB_f=self.sideB_f, sideB_k=self.sideB_k)
if sideA_thickness is None:
sideA_thickness = thickness
if sideB_thickness is None:
sideB_thickness = thickness
# Do not transfer a_ratios or volume or L_over_D
kwargs['D'] += 2.0*thickness
kwargs['L'] += sideA_thickness + sideB_thickness
# For torispherical vessels, the heads are defined from the `f` and `k`
# parameters which are already functions of diameter, and so will be
# fixed automatically; if the `a` parameters are specified they would
# not be corrected
if self.sideA != 'torispherical':
kwargs['sideA_a'] += sideA_thickness
else:
del kwargs['sideA_a']
if self.sideB != 'torispherical':
kwargs['sideB_a'] += sideB_thickness
else:
del kwargs['sideB_a']
return TANK(**kwargs)
def SA_from_h(self, h, method='full'):
r'''Method to calculate the volume of liquid in a fully defined tank
given a specified height `h`. `h` must be under the maximum height.
Parameters
----------
h : float
Height specified, [m]
method : str, optional
'full' (calculated rigorously) ; nothing else is implemented
Returns
-------
SA : float
Surface area of liquid in the tank up to the specified height, [m^2]
Notes
-----
'''
if method == 'full':
return SA_from_h(h, self.D, self.L, self.horizontal, self.sideA,
self.sideB, self.sideA_a, self.sideB_a,
self.sideA_f, self.sideA_k, self.sideB_f,
self.sideB_k)
else:
raise ValueError("Allowable methods are 'full' .")
def V_from_h(self, h, method='full'):
r'''Method to calculate the volume of liquid in a fully defined tank
given a specified height `h`. `h` must be under the maximum height.
If the method is 'chebyshev', and the coefficients have not yet been
calculated, they are created by calling `set_chebyshev_approximators`.
Parameters
----------
h : float
Height specified, [m]
method : str
One of 'full' (calculated rigorously) or 'chebyshev'
Returns
-------
V : float
Volume of liquid in the tank up to the specified height, [m^3]
Notes
-----
'''
if method == 'full':
return V_from_h(h, self.D, self.L, self.horizontal, self.sideA,
self.sideB, self.sideA_a, self.sideB_a,
self.sideA_f, self.sideA_k, self.sideB_f,
self.sideB_k)
elif method == 'chebyshev':
if not self.chebyshev:
self.set_chebyshev_approximators()
return self.V_from_h_cheb(h)
else:
raise ValueError("Allowable methods are 'full' or 'chebyshev'.")
def h_from_V(self, V, method='spline'):
r'''Method to calculate the height of liquid in a fully defined tank
given a specified volume of liquid in it `V`. `V` must be under the
maximum volume. If the method is 'spline', and the interpolation table
is not yet defined, creates it by calling the method set_table. If the
method is 'chebyshev', and the coefficients have not yet been
calculated, they are created by calling `set_chebyshev_approximators`.
Parameters
----------
V : float
Volume of liquid in the tank up to the desired height, [m^3]
method : str
One of 'spline', 'chebyshev', or 'brenth'
Returns
-------
h : float
Height of liquid at which the volume is as desired, [m]
'''
if method == 'spline':
try:
if not self.table:
self.set_table()
return float(self.interp_h_from_V(V))
except:
# Missing scipy
return self.h_from_V(V, 'brenth')
elif method == 'chebyshev':
if not self.chebyshev:
self.set_chebyshev_approximators()
return self.h_from_V_cheb(V)
elif method == 'brenth':
to_solve = lambda h : self.V_from_h(h, method='full') - V
return secant(to_solve, x0=0.5*self.h_max, low=0, high=self.h_max, bisection=True)
else:
raise ValueError("Allowable methods are 'full' or 'chebyshev', "
"or 'brenth'.")
def A_cross_sectional(self, h, method='full'):
r'''Method to calculate the cross-sectional liquid surface area
from which gas can evolve in a fully defined tank
given a specified height `h`. `h` must be under the maximum height.
This is calculated by numeric differentiation for most cases.
Parameters
----------
h : float
Height specified, [m]
method : str, optional
'full' (calculated rigorously) or 'chebyshev', [-]
Returns
-------
A_cross : float
Surface area of liquid in the tank up to the specified height, [m^2]
Notes
-----
'''
# The derivative will give bad values in some cases, when right up against boundaries
# Analytical formulations can be done, but will be lots of code
if h in (self.h_max, 0.0):
return 0.0
return derivative(lambda h: self.V_from_h(h), h, dx=1e-7*h, order=3, n=1)
def set_table(self, n=100, dx=None):
r'''Method to set an interpolation table of liquids levels versus
volumes in the tank, for a fully defined tank. Normally run by the
h_from_V method, this may be run prior to its use with a custom
specification. Either the number of points on the table, or the
vertical distance between steps may be specified.
Parameters
----------
n : float, optional
Number of points in the interpolation table, [-]
dx : float, optional
Vertical distance between steps in the interpolation table, [m]
'''
if dx:
self.heights = linspace(0.0, self.h_max, int(self.h_max/dx)+1)
else:
self.heights = linspace(0.0, self.h_max, n)
self.volumes = [self.V_from_h(h) for h in self.heights]
from scipy.interpolate import UnivariateSpline
# TODO replace with splrep/splev to avoid the object
self.interp_h_from_V = UnivariateSpline(self.volumes, self.heights, ext=3, s=0.0)
self.table = True
def set_chebyshev_approximators(self, deg_forward=50, deg_backwards=200):
r'''Method to derive and set coefficients for chebyshev polynomial
function approximation of the height-volume and volume-height
relationship.
A single set of chebyshev coefficients is used for the entire height-
volume and volume-height relationships respectively.
The forward relationship, `V_from_h`, requires
far fewer coefficients in its fit than the reverse to obtain the same
relative accuracy.
Optionally, deg_forward or deg_backwards can be set to None to try to
automatically fit the series to machine precision.
Parameters
----------
deg_forward : int, optional
The degree of the chebyshev polynomial to be created for the
`V_from_h` curve, [-]
deg_backwards : int, optional
The degree of the chebyshev polynomial to be created for the
`h_from_V` curve, [-]
'''
import numpy as np
from fluids.optional.pychebfun import Chebfun
to_fit = lambda h: self.V_from_h(h, 'full')
# These high-degree polynomials cannot safety be evaluated using Horner's methods
# chebval is 2.5x as slow but 100% required; depending on the geometry, but
# experience shows typically at around 40 coefficients the results are become junk
self.c_forward = Chebfun.from_function(np.vectorize(to_fit),
[0.0, self.h_max], N=deg_forward).coefficients().tolist()
self.V_from_h_cheb = lambda x : chebval((2.0*x-self.h_max)/(self.h_max), self.c_forward)
to_fit = lambda h: self.h_from_V(h, 'brenth')
self.c_backward = Chebfun.from_function(np.vectorize(to_fit), [0.0, self.V_total], N=deg_backwards).coefficients().tolist()
# TODO do not use lambda
self.h_from_V_cheb = lambda x : chebval((2.0*x-self.V_total)/(self.V_total), self.c_backward)
self.chebyshev = True
def _V_solver_error(self, Vtarget, D, L, horizontal, sideA, sideB, sideA_a,
sideB_a, sideA_f, sideA_k, sideB_f, sideB_k,
sideA_a_ratio, sideB_a_ratio):
"""Function which uses only the variables given, and the TANK class
itself, to determine how far from the desired volume, Vtarget, the
volume produced by the specified parameters in a new TANK instance is.
Should only be used by _solve_tank_for_V method.
"""
# print('Vtarget, D, L, L_D', Vtarget, D, L, L/D)
a = TANK(D=float(D), L=float(L), horizontal=horizontal, sideA=sideA, sideB=sideB,
sideA_a=sideA_a, sideB_a=sideB_a, sideA_f=sideA_f,
sideA_k=sideA_k, sideB_f=sideB_f, sideB_k=sideB_k,
sideA_a_ratio=sideA_a_ratio, sideB_a_ratio=sideB_a_ratio)
error = (Vtarget - a.V_total)
# print(error, 'error')
return error
def _solve_tank_for_V(self):
"""Method which is called to solve for tank geometry when a certain
volume is specified. Will be called by the __init__ method if V is set.
Notes
-----
Raises an error if L and either of sideA_a or sideB_a are specified;
these can only be set once D is known.
Raises an error if more than one of D, L, or L_over_D are specified.
Raises an error if the head ratios are not provided.
Calculates initial guesses assuming no heads are present, and then uses
fsolve to determine the correct dimensions for the tank.
Tested, but bugs and limitations are expected here.
"""
if self.L and (self.sideA_a or self.sideB_a):
raise ValueError('Cannot specify head sizes when solving for V')
if (self.D and self.L) or (self.D and self.L_over_D) or (self.L and self.L_over_D):
raise ValueError('Only one of D, L, or L_over_D can be specified\
when solving for V')
if ((self.sideA is not None and (self.sideA_a_ratio is None and self.sideA_a is None) and self.sideA != 'torispherical')
or (self.sideB is not None and (self.sideB_a_ratio is None and self.sideB_a is None) and self.sideB != 'torispherical')):
raise ValueError('When heads are specified, head parameter ratios are required')
if self.D:
# Iterate until L is appropriate
solve_L = lambda L: self._V_solver_error(self.V, self.D, L, self.horizontal, self.sideA, self.sideB, self.sideA_a, self.sideB_a, self.sideA_f, self.sideA_k, self.sideB_f, self.sideB_k, self.sideA_a_ratio, self.sideB_a_ratio)
Lguess = self.V/(pi/4*self.D**2)
self.L = float(secant(solve_L, Lguess, xtol=1e-13))
elif self.L:
# Iterate until D is appropriate
solve_D = lambda D: self._V_solver_error(self.V, D, self.L, self.horizontal, self.sideA, self.sideB, self.sideA_a, self.sideB_a, self.sideA_f, self.sideA_k, self.sideB_f, self.sideB_k, self.sideA_a_ratio, self.sideB_a_ratio)
Dguess = sqrt(4*self.V/pi/self.L)
self.D = float(secant(solve_D, Dguess, xtol=1e-13))
else:
# Use L_over_D until L and D are appropriate
Lguess = (4*self.V*self.L_over_D**2/pi)**(1/3.)
solve_L_D = lambda L: self._V_solver_error(self.V, L/self.L_over_D, L, self.horizontal, self.sideA, self.sideB, self.sideA_a, self.sideB_a, self.sideA_f, self.sideA_k, self.sideB_f, self.sideB_k, self.sideA_a_ratio, self.sideB_a_ratio)
self.L = float(secant(solve_L_D, Lguess, xtol=1e-13))
self.D = self.L/self.L_over_D
class HelicalCoil:
r'''Class representing a helical coiled tube, as are found in many heated
tanks and some small nuclear reactors. All parameters are also attributes.
One set of the following parameters is required; inner tube diameter is
optional.
* Tube outer diameter, coil outer diameter, pitch, number of coil turns
* Tube outer diameter, coil outer diameter, pitch, height
* Tube outer diameter, coil outer diameter, number of coil turns, height
Parameters
----------
Dt : float
Outer diameter of the tube wound to make up the helical spiral, [m]
Do : float
Diameter of the spiral as measured from the center of the coil on one
side to the center of the coil on the other side, [m]
Do_total : float, optional
Diameter of the spiral as measured from one edge of the tube to the
other edge; equal to Do + Dt; either `Do` or `Do_total` may be
specified and the other will be calculated [m]
pitch : float, optional
Height change from one coil to the next as measured from the middles
of the tube, [m]
H : float, optional
Height of the spiral, as measured from the middle of the bottom of the
tube to the middle of the top of the tube, [m]
H_total : float, optional
Height of the spiral as measured from one edge of the tube to the other
edge; equal to `H_total` + `Dt`; either may be specified and the other
will be calculated [m]
N : float, optional
Number of coil turns; may be specified along with `pitch` instead of
specifying `H` or `H_total`, [-]
Di : float, optional
Inner diameter of the tube; if specified, inside and annulus properties
will be calculated, [m]
Attributes
----------
tube_circumference : float
Circumference of the tube as measured though its center, not inner or
outer edges; :math:`C = \pi D_o`, [m]
tube_length : float
Length of tube used to make the helical coil;
:math:`L = \sqrt{(\pi D_o\cdot N)^2 + H^2}`, [m]
surface_area : float
Surface area of the outer surface of the helical coil;
:math:`A_t = \pi D_t L`, [m^2]
inner_surface_area : float
Surface area of the inner surface of the helical coil; calculated if
`Di` is supplied; :math:`A_{inside} = \pi D_i L`, [m^2]
inlet_area : float
Area of the inlet to the helical coil; calculated if
`Di` is supplied; :math:`A_{inlet} = \frac{\pi}{4} D_i^2`, [m^2]
inner_volume : float
Volume of the tube as would be filled by a fluid, useful for weight
calculations; calculated if `Di` is supplied;
:math:`V_{inside} = A_i L`, [m^3]
annulus_area : float
Area of the annulus (wall of the pipe); calculated if `Di` is supplied;
:math:`A_a = \frac{\pi}{4} (D_t^2 - D_i^2)`, [m^2]
annulus_volume : float
Volume of the annulus (wall of the pipe); calculated if `Di`
is supplied, useful for weight calculations; :math:`V_a = A_a L`, [m^3]
total_volume : float
Total volume occupied by the pipe and the fluid inside it;
:math:`V = D_t L`, [m^3]
helix_angle : float
Angle between the pitch and coil diameter; used in some calculations;
:math:`\alpha = \arctan \left(\frac{p_t}{\pi D_o}\right)`, [radians]
curvature : float
Coil curvature, useful in some calculations;
:math:`\delta = \frac{D_t}{D_o[1 + 4\pi^2 \tan^2(\alpha)]}`, [-]
Notes
-----
`Do` must be larger than `Dt`.
Examples
--------
>>> C1 = HelicalCoil(Do=30, H=20, pitch=5, Dt=2)
>>> C1.N, C1.tube_length, C1.surface_area
(4.0, 377.5212621504738, 2372.0360474917497)
Same coil, with the inputs one would physically measure from the coil,
and a specified inlet diameter:
>>> C1 = HelicalCoil(Do_total=32, H_total=22, pitch=5, Dt=2, Di=1.8)
>>> C1.N, C1.tube_length, C1.surface_area
(4.0, 377.5212621504738, 2372.0360474917497)
>>> C1.inner_surface_area, C1.inlet_area, C1.inner_volume, C1.total_volume, C1.annulus_volume
(2134.832442742575, 2.5446900494077327, 960.6745992341587, 1186.0180237458749, 225.3434245117162)
References
----------
.. [1] El-Genk, Mohamed S., and Timothy M. Schriener. "A Review and
Correlations for Convection Heat Transfer and Pressure Losses in
Toroidal and Helically Coiled Tubes." Heat Transfer Engineering 0, no. 0
(June 7, 2016): 1-28. doi:10.1080/01457632.2016.1194693.
'''
def __repr__(self): # pragma : no cover
s = f'<Helical coil, total height={self.H_total} m, total outer diameter={self.Do_total} m, tube \
outer diameter={self.Dt} m, number of turns={self.N}, pitch={self.pitch} m'
if self.Di:
s += f', inside diameter {self.Di} m'
s += '>'
return s
def __init__(self, Dt, Do=None, pitch=None, H=None, N=None, H_total=None,
Do_total=None, Di=None):
# H goes from center of tube in bottom of coil to center of tube in top of coil
# Do goes from the center of the spiral to the center of the outer tube
if H_total is not None:
H = H_total - Dt
if Do_total is not None:
Do = Do_total - Dt
self.Do = Do
self.Dt = Dt
self.Do_total = self.Do+self.Dt
if N is not None and pitch is not None:
self.N = N
self.pitch = pitch
self.H = N*pitch
elif N is not None and H is not None:
self.N = N
self.H = H
self.pitch = self.H/N
if self.pitch < self.Dt:
raise ValueError('Pitch is too small - tubes are colliding')#; maximum number of spirals is %f.'%(self.H/self.Dt))
elif H is not None and pitch is not None:
self.pitch = pitch
self.H = H
self.N = self.H/self.pitch
if self.pitch < self.Dt:
raise ValueError('Pitch is too small - tubes are colliding; pitch must be larger than tube diameter.')
if self.H is not None: # numba
self.H_total = self.Dt + self.H
if self.Dt > self.Do:
raise ValueError('Tube diameter is larger than helix outer diameter - not feasible.')
self.tube_circumference = pi*self.Do
self.tube_length = sqrt((self.tube_circumference*self.N)**2 + self.H**2)
self.surface_area = self.tube_length*pi*self.Dt
#print(pi*self.tube_length*self.Dt) == surface_area
self.helix_angle = atan(self.pitch/(pi*self.Do))
self.curvature = self.Dt/self.Do/(1. + 4*pi**2*tan(self.helix_angle)**2)
#print(self.N*pi*self.Do/cos(self.helix_angle)) # Confirms the length with another formula
self.total_inlet_area = pi/4.*self.Dt**2
self.total_volume = self.total_inlet_area*self.tube_length
if Di is not None:
self.Di = Di
self.inner_surface_area = self.tube_length*pi*self.Di
self.inlet_area = pi/4.*self.Di**2
self.inner_volume = self.inlet_area*self.tube_length
self.annulus_area = self.total_inlet_area - self.inlet_area
self.annulus_volume = self.total_volume - self.inner_volume
def plate_enlargement_factor(amplitude, wavelength):
r'''Calculates the enhancement factor of the sinusoidal waves of the
plate heat exchanger. This is the multiplier for the flat plate area
to obtain the actual area available for heat transfer. Obtained from
the following integral:
.. math::
\phi = \frac{\text{Effective area}}{\text{Projected area}}
= \frac{\int_0^\lambda\sqrt{1 + \left(\frac{\gamma\pi}{2}\right)^2
\cos^2\left(\frac{2\pi}{\lambda}x\right)}dx}{\lambda}
.. math::
\gamma = \frac{4a}{\lambda}
The solution to the integral is:
.. math::
\phi = \frac{2E\left(\frac{-4a^2\pi^2}{\lambda^2}\right)}{\pi}
where E is the complete elliptic integral of the second kind,
calculated with SciPy.
Parameters
----------
amplitude : float
Half the height of the wave of the ridges, [m]
wavelength : float
Distance between the bottoms of two of the ridges (sometimes called
pitch), [m]
Returns
-------
plate_enlargement_factor : float
The extra surface area multiplier as compared to a flat plate
caused the corrugations, [-]
Notes
-----
This is the exact analytical integral, obtained via Mathematica, Maple,
and quite a bit of trial and error. It is confirmed via numerical
integration. The expression normally given is an
approximation as follows:
.. math::
\phi = \frac{1}{6}\left(1+\sqrt{1+A^2} + 4\sqrt{1+A^2/2}\right)
.. math::
A = \frac{2\pi a}{\lambda}
Most plate heat exchangers approximate a sinusoidal geometry only.
Examples
--------
>>> plate_enlargement_factor(amplitude=5E-4, wavelength=3.7E-3)
1.1611862034509677
'''
b = 2.*amplitude
return 2.*float(ellipe(-b*b*pi*pi/(wavelength*wavelength)))/pi
class PlateExchanger:
r'''Class representing a plate heat exchanger with sinusoidal ridges.
All parameters are also attributes.
Parameters
----------
amplitude : float
Half the height of the wave of the ridges, [m]
wavelength : float
Distance between the bottoms of two of the ridges (sometimes called
pitch), [m]
chevron_angle : float, optional
Angle of the plate corrugations with respect to the vertical axis
(the direction of flow if the plates were straight), between 0 and
90, [degrees]
chevron_angles : tuple(2), optional
Many plate exchangers use two alternating patterns; for those cases
provide tuple of the two angles for that situation and the argument
`chevron_angle` is ignored, [degrees]
width : float, optional
Width of the plates in the heat exchanger, between the gaskets, [m]
length : float, optional
Length of the heat exchanger as measured from one port to the other,
excluding the diameter of the ports themselves (little useful heat
transfer happens there), [m]
thickness : float, optional
Thickness of the metal making up the plates, [m]
d_port : float, optional
The diameter of the ports in the plates, [m]
plates : int, optional
The number of plates in the heat exchanger, including the two not
used for heat transfer at the beginning and end [-]
Attributes
----------
chevron_angles : tuple(2)
The two specified angles (repeated value if only one specified), [degrees]
chevron_angle : float
The averaged angle of the chevrons, [degrees]
inclination_angle : float
90 - `chevron_angle`, used in many publications instead of `chevron_angle`,
[degrees]
plate_corrugation_aspect_ratio : float
The aspect ratio of the corrugations
:math:`\gamma = \frac{4a}{\lambda}`, [-]
plate_enlargement_factor : float
The extra surface area multiplier as compared to a flat plate
caused the corrugations, [-]
D_eq : float
Equivalent diameter of the channels, :math:`D_{eq} = 4a` [m]
D_hydraulic : float
Hydraulic diameter of the channels, :math:`D_{hyd} = \frac{4a}{\phi}` [m]
length_port : float
Port center to port center along the direction of flow, [m]
A_plate_surface : float
The surface area of one plate in the heat exchanger, including the
extra due to corrugations (excluding the bit between the ports),
:math:`A_p = L\cdot W\cdot \phi` [m^2]
A_heat_transfer : float
The total surface area available for heat transfer in the exchanger,
the multiple of `A_plate_surface` by the number of plates after
removing the two on the edges, [m^2]
A_channel_flow : float
The area for the fluid to flow in one channel, :math:`W\cdot b` [m^2]
channels : int
The number of plates minus one, [-]
channels_per_fluid : int
Half the number of total channels, [-]
Notes
-----
Only wavelength and amplitude are required as inputs to this function.
Examples
--------
>>> PlateExchanger(amplitude=5E-4, wavelength=3.7E-3, length=1.2, width=.3,
... d_port=.05, plates=51)
<Plate heat exchanger, amplitude=0.0005 m, wavelength=0.0037 m, chevron_angles=45/45 degrees, area enhancement factor=1.16119, width=0.3 m, length=1.2 m, port diameter=0.05 m, heat transfer area=20.4833 m^2, 51 plates>
References
----------
.. [1] Amalfi, Raffaele L., Farzad Vakili-Farahani, and John R. Thome.
"Flow Boiling and Frictional Pressure Gradients in Plate Heat Exchangers.
Part 1: Review and Experimental Database." International Journal of
Refrigeration 61 (January 2016): 166-84. doi:10.1016/j.ijrefrig.2015.07.010.
'''
def __repr__(self): # pragma : no cover
s = '<Plate heat exchanger, amplitude={:g} m, wavelength={:g} m, \
chevron_angles={} degrees, area enhancement factor={:g}'.format(self.a, self.wavelength, '/'.join([str(i) for i in self.chevron_angles]), self.plate_enlargement_factor)
if self.width and self.length:
s += f', width={self.width:g} m, length={self.length:g} m'
if self.d_port:
s += f', port diameter={self.d_port:g} m'
if self.plates:
s += f', heat transfer area={self.A_heat_transfer:g} m^2, {self.plates:g} plates>'
else:
s += '>'
return s
@property
def plate_exchanger_identifier(self):
"""Method to create an identifying string in format 'L' + wavelength +
'A' + amplitude + 'B' + chevron angle-chevron angle.
Wavelength and amplitude are specified in units of mm and rounded to two
decimal places.
"""
wave_rounded = round(self.wavelength*1000, 2)
amplitude_rounded = round(self.amplitude*1000, 2)
a1 = self.chevron_angles[0]
a2 = self.chevron_angles[1]
s = (f'L{wave_rounded}A{amplitude_rounded}B{a1}-{a2}')
return s
def __init__(self, amplitude, wavelength, chevron_angle=45,
chevron_angles=None, width=None, length=None, thickness=None,
d_port=None, plates=None):
self.amplitude = self.a = amplitude # half a sine wave's height
self.b = 2*self.amplitude # Used in some models. From a flat plate, a press goes down this far into the plate. Also called the hot and cold gap
self.wavelength = self.pitch = wavelength # self.lambda
if chevron_angles is not None:
self.chevron_angles = chevron_angles
self.chevron_angle = self.beta = 0.5*(chevron_angles[0] + chevron_angles[1])
else:
self.chevron_angle = self.beta = chevron_angle # between 0 and 90
self.chevron_angles = (chevron_angle, chevron_angle)
self.inclination_angle = 90 - self.chevron_angle # Used in some definitions instead
self.plate_corrugation_aspect_ratio = self.gamma = 4*self.a/self.wavelength
self.plate_enlargement_factor = plate_enlargement_factor(self.amplitude, self.wavelength)
self.D_eq = 4*self.amplitude # Equivalent diameter for inter-plate spacing
self.D_hydraulic = 4*self.amplitude/self.plate_enlargement_factor # Get better results when correlations use this
if width is not None:
self.width = width
if length is not None:
self.length = length
if thickness is not None:
self.thickness = thickness
if d_port is not None:
self.d_port = d_port
if plates is not None:
self.plates = plates
if d_port is not None and length is not None:
self.length_port = length + d_port # port center to port center along the direction of flow
# There is another larger length as well, including both port diameters
if width is not None and length is not None:
self.A_plate_surface = length*width*self.plate_enlargement_factor # use this in Q = UAdT
if plates is not None:
self.A_heat_transfer = (plates-2)*self.A_plate_surface # the two outermost sides aren't used
if width is not None:
self.A_channel_flow = self.width*self.b # Use this to get G, kg/s/m^2
if plates is not None:
self.channels = self.plates - 1
self.channels_per_fluid = 0.5*self.channels
class RectangularFinExchanger:
r'''Class representing a plate-fin heat exchanger with straight rectangular
fins. All parameters are also attributes.
Parameters
----------
fin_height : float
The total distance between the two metal plates sandwiching the fins
and holding them together (abbreviated `h`), [m]
fin_thickness : float
The thickness of the material the fins were formed from
(abbreviated `t`), [m]
fin_spacing : float
The unit cell spacing from one fin to the next; the space between the
sides of two fins plus one thickness (abbreviated `s`), [m]
length : float, optional
The total length of the flow passage of the plate-fin exchanger
(abbreviated `L`), [m]
width : float, optional
The total width of the space the fins are in; this is also
:math:`N_{fins}\times s` (abbreviated `W`), [m]
layers : int, optional
The number of layers in the plate-fin exchanger; note these HX almost
always single-pass only, [-]
plate_thickness : float, optional
The thickness of the metal separator between layers, [m]
flow : str, optional
One of 'counterflow', 'crossflow', or 'parallelflow'
Attributes
----------
channel_height : float
The height of the channel the fluid flows in
:math:`\text{channel height } = \text{fin height} - \text{fin thickness}`, [m]
channel_width : float
The width of the channel the fluid flows in
:math:`\text{channel width } = \text{fin spacing} - \text{fin thickness}`, [m]
fin_count : int
The number of fins per unit length of the layer,
:math:`\text{fin count} = \frac{1}{\text{fin spacing}}`, [1/m]
blockage_ratio : float
The fraction of the layer which is blocked to flow by the fins,
:math:`\text{blockage ratio} = \frac{s\cdot h - s\cdot t - t(h-t)}{s\cdot h}`,
[m]
A_channel : float
Flow area of a single channel in a single layer,
:math:`\text{channel area} = (s-t)(h-t)`, [m]
P_channel : float
Wetted perimeter of a single channel in a single layer,
:math:`\text{channel perimeter} = 2(s-t) + 2(h-t)`, [m]
Dh : float
Hydraulic diameter of a single channel in a single layer,
:math:`D_{hydraulic} = \frac{4 A_{channel}}{P_{channel}}`, [m]
layer_thickness : float
The thickness of a single layer - the sum of a fin height and
a plate thickness, [m]
layer_fin_count : int
The number of fins in a layer; rounded to the nearest whole fin, [-]
A_HX_layer : float
The surface area including fins for heat transfer in one layer of the
HX, [m^2]
A_HX : float
The total surface area of the heat exchanger with all layers combined,
[m^2]
height : float
The height of all the layers of the heat exchanger combined, plus one
extra plate thickness, [m]
volume : float
The product of the height, width, and length of the HX, [m^3]
A_specific_HX : float
The specific surface area of the heat exchanger - square meters per
meter cubed, [m^3]
Notes
-----
The only required parameters are the fin geometry itself; `fin_height`,
`fin_thickness`, and `fin_spacing`.
Examples
--------
>>> PFE = RectangularFinExchanger(0.03, 0.001, 0.012)
>>> PFE.Dh
0.01595
References
----------
.. [1] Yang, Yujie, and Yanzhong Li. "General Prediction of the Thermal
Hydraulic Performance for Plate-Fin Heat Exchanger with Offset Strip
Fins." International Journal of Heat and Mass Transfer 78 (November 1,
2014): 860-70. doi:10.1016/j.ijheatmasstransfer.2014.07.060.
.. [2] Sheik Ismail, L., R. Velraj, and C. Ranganayakulu. "Studies on
Pumping Power in Terms of Pressure Drop and Heat Transfer
Characteristics of Compact Plate-Fin Heat Exchangers-A Review."
Renewable and Sustainable Energy Reviews 14, no. 1 (January 2010):
478-85. doi:10.1016/j.rser.2009.06.033.
'''
def __init__(self, fin_height, fin_thickness, fin_spacing, length=None, width=None, layers=None, plate_thickness=None, flow='crossflow'):
self.h = self.fin_height = fin_height # including 2x thickness
self.t = self.fin_thickness = fin_thickness
self.s = self.fin_spacing = fin_spacing
self.L = self.length = length
self.W = self.width = width
self.layers = layers
self.flow = flow
self.plate_thickness = plate_thickness
self.channel_height = self.fin_height - self.fin_thickness
self.channel_width = self.fin_spacing - self.fin_thickness
self.fin_count = 1./self.fin_spacing
self.blockage_ratio = (self.s*self.h - self.s*self.t - (self.h-self.t)*self.t)/(self.s*self.h)
self.A_channel = (self.s-self.t)*(self.h-self.t)
self.P_channel = 2*(self.s-self.t) + 2*(self.h-self.t)
self.Dh = 4*self.A_channel/self.P_channel
self.set_overall_geometry()
def set_overall_geometry(self):
if self.plate_thickness:
self.layer_thickness = self.plate_thickness + self.fin_height
if self.length and self.width:
self.layer_fin_count = round(self.fin_count*self.width, 0)
if hasattr(self, 'SA_fin'):
self.A_HX_layer = self.layer_fin_count*self.SA_fin*self.length
else:
self.A_HX_layer = self.P_channel*self.length*self.layer_fin_count
if self.layers:
self.A_HX = self.layers*self.A_HX_layer
if self.plate_thickness:
self.height = self.layer_thickness*self.layers + self.plate_thickness
self.volume = (self.length*self.width*self.height)
self.A_specific_HX = self.A_HX/self.volume
class RectangularOffsetStripFinExchanger(RectangularFinExchanger):
def __init__(self, fin_length, fin_height, fin_thickness, fin_spacing, length=None, width=None, layers=None, plate_thickness=None, flow='crossflow'):
self.l = self.fin_length = fin_length
self.h = self.fin_height = fin_height
self.t = self.fin_thickness = fin_thickness
self.s = self.fin_spacing = fin_spacing
self.blockage_ratio = self.omega = 2*self.t/self.s*(1. - self.t/self.h) + self.t/self.h*(1 - 2*self.t/self.s)
# Kim blockage ratio beta
self.blockage_ratio_Kim = self.t/self.h + self.t/self.s - self.t**2/(self.h*self.s)
# Definitions as in the paper with the most common correlation
self.alpha = self.s/self.h # "General prediction" uses t/h here
self.delta = self.t/self.l
self.gamma = self.t/self.s
# free flow area
self.A_channel = (self.h - self.t)*(self.s - self.t)
self.A = 2.*(self.l*(self.h-self.t) + self.l*(self.s-self.t) + self.t*(self.h-self.t)) + self.t*(self.s-2*self.t)
self.Dh = 4.*self.l*self.A_channel/self.A # not the standard definition
self.P_channel = 2*(self.s-self.t) + 2*(self.h-self.t)
self.Dh_Kays_London = 4*self.A_channel/(2*(self.h -self.t)+ 2*(self.s -self.t))
# Does not consider the fronts of backs of the fins, only the 2d shape
self.Dh_Joshi_Webb = 2*self.l*(self.h - self.t)*(self.s - 2*self.t)/(self.l*(self.h-self.t) + self.l*(self.s - self.t) + self.t*(self.h - self.t))
self.L = self.length = length
self.W = self.width = width
self.layers = layers
self.flow = flow
self.plate_thickness = plate_thickness
self.fin_count = 1./self.fin_spacing
self.set_overall_geometry()
class HyperbolicCoolingTower:
r'''Class representing the geometry of a hyperbolic cooling tower, as used
in many industries especially the poewr industry. All parameters are also
attributes.
`H_inlet`, `D_outlet`, and `H_outlet` are always required. Additionally,
one set of the following parameters is required; `H_support`, `D_support`,
`n_support`, and `inlet_rounding` are all optional as well.
* Inlet diameter
* Inlet diameter and throat diameter
* Inlet diameter and throat height
* Inlet diameter, throat diameter, and throat height
* Base diameter, throat diameter, and throat height
If the inlet diameter is provided but the throat diameter and/or the throat
height are missing, two heuristics are used to estimate them (to avoid
these heuristics simply specify the values):
* Assume the throat elevation is 2/3 the elevation of the tower.
* Assume the throat diameter is 63% the diameter of the inlet.
Parameters
----------
H_inlet : float
Height of the inlet zone of the cooling tower (also called rain zone),
[m]
D_outlet : float
The inside diameter of the cooling tower outlet (top of the tower; the
elevation the concrete section ends), [m]
H_outlet : float
The height of the cooling tower outlet (top of the tower;the
elevation the concrete section ends), [m]
D_inlet : float, optional
The inside diameter of the cooling tower inlet at the elevation the
concrete section begins, [m]
D_base : float, optional
The diameter of the cooling tower at the very base of the tower (the
bottom of the inlet zone, at the elevation of the ground), [m]
D_throat : float, optional
The diameter of the cooling tower at its minimum section, called its
throat; where the two hyperbolas meet, [m]
h_throat : float, optional
The elevation of the cooling tower's throat (its minimum section; where
the two hyperbolas meet), [m]
inlet_rounding : float, optional
Radius of an optional rounded protrusion from the lip of the cooling
tower shell base, which curves upwards from the lip (used to reduce
the dead zone area rather than having a flat lip), [m]
H_support : float, optional
The height of each support column, [m]
D_support : float, optional
The diameter of each support column, [m]
n_support : int, optional
The number of support columns of the cooling tower, [m]
Attributes
----------
b_lower : float
The `b` parameter in the hyperbolic equation for the lower section of
the cooling tower, [m]
b_upper : float
The `b` parameter in the hyperbolic equation for the upper section of
the cooling tower, [m]
Notes
-----
Note there are two hyperbolas in a hyperbolic cooling tower - one under the
throat and one above it; they are not necessarily the same.
A hyperbolic cooling tower is not the absolute optimal design, but is is
close. The optimality is determined by the amount of material required to
build it while maintaining its rigidity. For thermal design purposes,
a hyperbolic model covers any minor variation quite well.
Examples
--------
>>> ct = HyperbolicCoolingTower(D_outlet=89.0, H_outlet=200, D_inlet=136.18, H_inlet=14.5)
>>> ct
<Hyperbolic cooling tower, inlet diameter=136.18 m, outlet diameter=89 m, inlet height=14.5 m, outlet height=200 m, throat diameter=85.7934 m, throat height=133.333 m, base diameter=146.427 m>
>>> ct.diameter(5)
142.84514486126062
References
----------
.. [1] Chen, W. F., and E. M. Lui, eds. Handbook of Structural Engineering,
Second Edition. Boca Raton, Fla: CRC Press, 2005.
.. [2] Ansary, A. M. El, A. A. El Damatty, and A. O. Nassef. Optimum Shape
and Design of Cooling Towers, 2011.
'''
def __repr__(self): # pragma : no cover
s = """<Hyperbolic cooling tower, inlet diameter=%g m, outlet diameter=%g m, inlet height=%g m, \
outlet height=%g m, throat diameter=%g m, throat height=%g m, base diameter=%g m>"""
s = s%(self.D_inlet, self.D_outlet, self.H_inlet, self.H_outlet, self.D_throat, self.H_throat, self.D_base)
return s
def __init__(self, H_inlet, D_outlet, H_outlet, D_inlet=None, D_base=None,
D_throat=None, H_throat=None,
H_support=None, D_support=None, n_support=None,
inlet_rounding=None):
self.D_outlet = D_outlet
self.H_inlet = H_inlet
self.H_outlet = H_outlet
if H_throat is None:
H_throat = 2/3.0*H_outlet
self.H_throat = H_throat
if D_throat is None:
if D_inlet is not None:
D_throat = 0.63*D_inlet
else:
raise ValueError('Provide either `D_throat`, or `D_inlet` so it may be estimated.')
self.D_throat = D_throat
if D_inlet is None and D_base is None:
raise ValueError('Need `D_inlet` or `D_base`')
if D_base is not None:
b = self.D_throat*self.H_throat/sqrt(D_base**2 - self.D_throat**2)
D_inlet = 2*self.D_throat*sqrt((self.H_throat-H_inlet)**2 + b**2)/(2*b)
elif D_inlet is not None:
b = self.D_throat*(self.H_throat-H_inlet)/sqrt(D_inlet**2 - self.D_throat**2)
D_base = 2*self.D_throat*sqrt(self.H_throat**2 + b**2)/(2*b)
self.D_inlet = D_inlet
self.D_base = D_base
self.b_lower = b
# Upper b parameter
self.b_upper = self.D_throat*(self.H_outlet - self.H_throat)/sqrt((self.D_outlet)**2 - self.D_throat**2)
# May or may not be specified
self.H_support = H_support
self.D_support = D_support
self.n_support = n_support
self.inlet_rounding = inlet_rounding
def plot(self, pts=100): # pragma: no cover
import matplotlib.pyplot as plt
Zs = linspace(0, self.H_outlet, pts)
Rs = [self.diameter(Z)*0.5 for Z in Zs]
plt.plot(Zs, Rs)
plt.plot(Zs, [-v for v in Rs])
plt.show()
def diameter(self, H):
r'''Calculates cooling tower diameter at a specified height, using
the formulas for either hyperbola, depending on the height specified.
.. math::
D = D_{throat}\frac{\sqrt{H^2 + b^2}}{b}
The value of `H` and `b` used in the above equation is as follows:
* `H_throat` - H and `b_lower` if under the throat
* `H` - `H_throat` and `b_upper`, if above the throat
Parameters
----------
H : float
Height at which to calculate the cooling tower diameter, [m]
Returns
-------
D : float
Diameter of the cooling tower at the specified height, [m]
'''
# Compute the diameter at H
if H <= self.H_throat:
# Height relative to throat height
H = self.H_throat - H
b = self.b_lower
else:
H = H - self.H_throat
b = self.b_upper
R = self.D_throat*sqrt(H*H + b*b)/(2.0*b)
return R*2.0
class AirCooledExchanger:
r'''Class representing the geometry of an air cooled heat exchanger with
one or more tube bays, fans, or bundles.
All parameters are also attributes.
The minimum information required to describe an air cooler is as follows:
* `tube_rows`
* `tube_passes`
* `tubes_per_row`
* `tube_length`
* `tube_diameter`
* `fin_thickness`
Two of `angle`, `pitch`, `pitch_parallel`, and `pitch_normal`
(`pitch_ratio` may take the place of `pitch`)
Either `fin_diameter` or `fin_height`.
Either `fin_density` or `fin_interval`.
Parameters
----------
tube_rows : int
Number of tube rows per bundle, [-]
tube_passes : int
Number of tube passes (times the fluid travels across one tube length),
[-]
tubes_per_row : float
Number of tubes per row per bundle, [-]
tube_length : float
Total length of the tube bundle tubes, [m]
tube_diameter : float
Diameter of the bare tube, [m]
fin_thickness : float
Thickness of the fins, [m]
angle : float, optional
Angle of the tube layout, [degrees]
pitch : float, optional
Shortest distance between tube centers; defined in relation to the
flow direction only, [m]
pitch_parallel : float, optional
Distance between tube center along a line parallel to the flow;
has been called `longitudinal` pitch, `pp`, `s2`, `SL`, and `p2`, [m]
pitch_normal : float, optional
Distance between tube centers in a line 90° to the line of flow;
has been called the `transverse` pitch, `pn`, `s1`, `ST`, and `p1`, [m]
pitch_ratio : float, optional
Ratio of the pitch to bare tube diameter, [-]
fin_diameter : float, optional
Outer diameter of each tube after including the fin on both sides,
[m]
fin_height : float, optional
Height above bare tube of the tube fins, [m]
fin_density : float, optional
Number of fins per meter of tube, [1/m]
fin_interval : float, optional
Space between each fin, including the thickness of one fin at its
base, [m]
parallel_bays : int, optional
Number of bays in the unit, [-]
bundles_per_bay : int, optional
Number of tube bundles per bay, [-]
fans_per_bay : int, optional
Number of fans per bay, [-]
corbels : bool, optional
Whether or not the air cooler has corbels, which increase the air
velocity by adding half a tube to the sides for the case of
non-rectangular tube layouts, [-]
tube_thickness : float, optional
Thickness of the bare metal tubes, [m]
fan_diameter : float, optional
Diameter of air cooler fan, [m]
Attributes
----------
bare_length : float
Length of bare tube between two fins
:math:`\text{bare length} = \text{fin interval} - t_{fin}`, [m]
tubes_per_bundle : float
Total number of tubes per bundle
:math:`N_{tubes/bundle} = N_{tubes/row} \cdot N_{rows}`, [-]
tubes_per_bay : float
Total number of tubes per bay
:math:`N_{tubes/bay} = N_{tubes/bundle} \cdot N_{bundles/bay}`, [-]
tubes : float
Total number of tubes in all bundles in all bays combined
:math:`N_{tubes} = N_{tubes/bay} \cdot N_{bays}`, [-]
pitch_diagonal : float
Distance between tube centers in a diagonal line between one normal
tube and one parallel tube;
:math:`s_D = \left[s_L^2 + \left(\frac{s_T}{2}\right)^2\right]^{0.5}`,
[m]
A_bare_tube_per_tube : float
Area of the bare tube including the portion hidden by the fin per
tube :math:`A_{bare,total/tube} = \pi D_{tube} L_{tube}`, [m^2]
A_bare_tube_per_row : float
Area of the bare tube including the portion hidden by the fin per
tube row
:math:`A_{bare,total/row} = \pi D_{tube} L_{tube} N_{tubes/row}`, [m^2]
A_bare_tube_per_bundle : float
Area of the bare tube including the portion hidden by the fin per
bundle :math:`A_{bare,total/bundle} = \pi D_{tube} L_{tube}
N_{tubes/bundle}`, [m^2]
A_bare_tube_per_bay : float
Area of the bare tube including the portion hidden by the fin per
bay :math:`A_{bare,total/bay} = \pi D_{tube} L_{tube} N_{tubes/bay}`,
[m^2]
A_bare_tube : float
Area of the bare tube including the portion hidden by the fin per
in all bundles and bays combined :math:`A_{bare,total} = \pi D_{tube}
L_{tube} N_{tubes}`, [m^2]
A_tube_showing_per_tube : float
Area of the bare tube which is exposed per tube :math:`A_{bare,
showing/tube} = \pi D_{tube} L_{tube} \left(1 - \frac{t_{fin}}
{\text{fin interval}} \right)`, [m^2]
A_tube_showing_per_row : float
Area of the bare tube which is exposed per tube row, [m^2]
A_tube_showing_per_bundle : float
Area of the bare tube which is exposed per bundle, [m^2]
A_tube_showing_per_bay : float
Area of the bare tube which is exposed per bay, [m^2]
A_tube_showing : float
Area of the bare tube which is exposed in all bundles and bays
combined, [m^2]
A_per_fin : float
Surface area per fin :math:`A_{fin} = 2 \frac{\pi}{4} (D_{fin}^2 -
D_{tube}^2) + \pi D_{fin} t_{fin}`, [m^2]
A_fin_per_tube : float
Surface area of all fins per tube
:math:`A_{fin/tube} = N_{fins/m} L_{tube} A_{fin}`, [m^2]
A_fin_per_row : float
Surface area of all fins per row, [m^2]
A_fin_per_bundle : float
Surface area of all fins per bundle, [m^2]
A_fin_per_bay : float
Surface area of all fins per bay, [m^2]
A_fin : float
Surface area of all fins in all bundles and bays combined, [m^2]
A_per_tube : float
Surface area of combined finned and non-fined area exposed for heat
transfer per tube :math:`A_{tube} = A_{bare, showing/tube}
+ A_{fin/tube}`, [m^2]
A_per_row : float
Surface area of combined finned and non-finned area exposed for heat
transfer per tube row, [m^2]
A_per_bundle : float
Surface area of combined finned and non-finned area exposed for heat
transfer per tube bundle, [m^2]
A_per_bay : float
Surface area of combined finned and non-finned area exposed for heat
transfer per bay, [m^2]
A : float
Surface area of combined finned and non-finned area exposed for heat
transfer in all bundles and bays combined, [m^2]
A_increase : float
Ratio of actual surface area to bare tube surface area
:math:`A_{increase} = \frac{A_{tube}}{A_{bare, total/tube}}`, [-]
A_tube_flow : float
The area for the fluid to flow in one tube, :math:`\pi/4\cdot D_i^2`,
[m^2]
A_tube_flow_per_row : float
The area for the fluid to flow in one row, :math:`\pi/4\cdot D_i^2 N_{tubes/row}`,
[m^2]
A_tube_flow_per_bundle : float
The area for the fluid to flow in one bundle, :math:`\pi/4\cdot D_i^2 N_{tubes/bundle}`,
[m^2]
A_tube_flow_per_bay : float
The area for the fluid to flow in one bay, :math:`\pi/4\cdot D_i^2 N_{tubes/bay}`,
[m^2]
A_tube_flow_total : float
The area for the fluid to flow in all tubes combined, as if there
were a single pass [m^2]
channels : int
The number of tubes the fluid flows through at the inlet header, [-]
tube_volume_per_tube : float
Fluid volume per tube inside :math:`V_{tube, flow} = \frac{\pi}{4}
D_{i}^2 L_{tube}`, [m^3]
tube_volume_per_row : float
Fluid volume of tubes per row, [m^3]
tube_volume_per_bundle : float
Fluid volume of tubes per bundle, [m^3]
tube_volume_per_bay : float
Fluid volume of tubes per bay, [m^3]
tube_volume : float
Fluid volume of tubes in all bundles and bays combined, [m^3]
A_diagonal_per_bundle : float
Air flow area along the diagonal plane per bundle
:math:`A_d = 2 N_{tubes/row} L_{tube} (P_d - D_{tube} - 2 N_{fins/m} h_{fin} t_{fin}) + A_\text{extra,side}`, [m^2]
A_normal_per_bundle : float
Air flow area along the normal (transverse) plane; this is normally
the minimum flow area, except for some staggered configurations
:math:`A_t = N_{tubes/row} L_{tube} (P_t - D_{tube} - 2 N_{fins/m} h_{fin} t_{fin}) + A_\text{extra,side}`, [m^2]
A_min_per_bundle : float
Minimum air flow area per bundle; this is the characteristic area for
velocity calculation in most finned tube convection correlations
:math:`A_{min} = min(A_d, A_t)`, [m^2]
A_min_per_bay : float
Minimum air flow area per bay, [m^2]
A_min : float
Minimum air flow area, [m^2]
A_face_per_bundle : float
Face area per bundle :math:`A_{face} = P_{T} (1+N_{tubes/row})
L_{tube}`; if corbels are used, add 0.5 to tubes/row instead of 1,
[m^2]
A_face_per_bay : float
Face area per bay, [m^2]
A_face : float
Total face area, [m^2]
flow_area_contraction_ratio : float
Ratio of `A_min` to `A_face`, [-]
Notes
-----
Examples
--------
>>> from scipy.constants import inch
>>> AC = AirCooledExchanger(tube_rows=4, tube_passes=4, tubes_per_row=56, tube_length=10.9728,
... tube_diameter=1*inch, fin_thickness=0.013*inch, fin_density=10/inch,
... angle=30, pitch=2.5*inch, fin_height=0.625*inch, tube_thickness=0.00338,
... bundles_per_bay=2, parallel_bays=3, corbels=True)
References
----------
.. [1] Schlunder, Ernst U, and International Center for Heat and Mass
Transfer. Heat Exchanger Design Handbook. Washington:
Hemisphere Pub. Corp., 1983.
'''
def __repr__(self):
attributes = ', '.join(f"{slot}={getattr(self, slot)!r}" for slot in self.model_inputs)
return f"{self.__class__.__name__}({attributes})"
def __hash__(self):
return hash(tuple(getattr(self, slot) for slot in self.model_inputs))
# pitch_ratio is skipped in favor of pitch;
model_inputs = ('tube_rows', 'tube_passes', 'tubes_per_row', 'tube_length', 'tube_diameter',
'fin_thickness', 'angle', 'pitch', 'pitch_parallel', 'pitch_normal', 'fin_diameter',
'fin_height', 'fin_density', 'fin_interval', 'parallel_bays', 'bundles_per_bay',
'fans_per_bay', 'corbels', 'tube_thickness', 'fan_diameter')
def __init__(self, tube_rows, tube_passes, tubes_per_row, tube_length,
tube_diameter, fin_thickness,
angle=None, pitch=None, pitch_parallel=None, pitch_normal=None,
pitch_ratio=None,
fin_diameter=None, fin_height=None,
fin_density=None, fin_interval=None,
parallel_bays=1, bundles_per_bay=1, fans_per_bay=1,
corbels=False, tube_thickness=None, fan_diameter=None):
# TODO: fin types
self.tube_rows = tube_rows
self.tube_passes = tube_passes
self.tubes_per_row = tubes_per_row
self.tube_length = tube_length
self.tube_diameter = tube_diameter
self.fin_thickness = fin_thickness
self.fan_diameter = fan_diameter
if pitch_ratio is not None:
if pitch is not None:
pitch = self.tube_diameter*pitch_ratio
else:
raise ValueError('Specify only one of `pitch_ratio` or `pitch`')
angle, pitch, pitch_parallel, pitch_normal = pitch_angle_solver(
angle=angle, pitch=pitch, pitch_parallel=pitch_parallel,
pitch_normal=pitch_normal)
self.angle = angle
self.pitch = pitch
self.pitch_ratio = pitch/self.tube_diameter
self.pitch_parallel = pitch_parallel
self.pitch_normal = pitch_normal
self.pitch_diagonal = sqrt(pitch_parallel**2 + (0.5*pitch_normal)**2)
if fin_diameter is None and fin_height is None:
raise ValueError('Specify only one of `fin_diameter` or `fin_height`')
elif fin_diameter is not None:
fin_height = 0.5*(fin_diameter - tube_diameter)
elif fin_height is not None:
fin_diameter = tube_diameter + 2.0*fin_height
self.fin_height = fin_height
self.fin_diameter = fin_diameter
if fin_density is None and fin_interval is None:
raise ValueError('Specify only one of `fin_density` or `fin_interval`')
elif fin_density is not None:
fin_interval = 1.0/fin_density
elif fin_interval is not None:
fin_density = 1.0/fin_interval
self.fin_interval = fin_interval
self.fin_density = fin_density
self.parallel_bays = parallel_bays
self.bundles_per_bay = bundles_per_bay
self.fans_per_bay = fans_per_bay
self.corbels = corbels
self.tube_thickness = tube_thickness
if self.fin_interval:
self.bare_length = self.fin_interval - self.fin_thickness
else:
self.bare_length = None
self.tubes_per_bundle = self.tubes_per_row*self.tube_rows
self.tubes_per_bay = self.tubes_per_bundle*self.bundles_per_bay
self.tubes = self.tubes_per_bay*self.parallel_bays
self.A_bare_tube_per_tube = pi*self.tube_diameter*self.tube_length
self.A_bare_tube_per_row = self.A_bare_tube_per_tube*self.tubes_per_row
self.A_bare_tube_per_bundle = self.A_bare_tube_per_tube*self.tubes_per_bundle
self.A_bare_tube_per_bay = self.A_bare_tube_per_tube*self.tubes_per_bay
self.A_bare_tube = self.A_bare_tube_per_tube*self.tubes
self.A_tube_showing_per_tube = pi*self.tube_diameter*self.tube_length*(1.0 - self.fin_thickness/self.fin_interval)
self.A_tube_showing_per_row = self.A_tube_showing_per_tube*self.tubes_per_row
self.A_tube_showing_per_bundle = self.A_tube_showing_per_tube*self.tubes_per_bundle
self.A_tube_showing_per_bay = self.A_tube_showing_per_tube*self.tubes_per_bay
self.A_tube_showing = self.A_tube_showing_per_tube*self.tubes
self.A_per_fin = (2.0*pi/4.0*(self.fin_diameter**2 - self.tube_diameter**2)
+ pi*self.fin_diameter*self.fin_thickness) # pi*D*L(fin)
self.A_fin_per_tube = self.fin_density*self.tube_length*self.A_per_fin
self.A_fin_per_row = self.A_fin_per_tube*self.tubes_per_row
self.A_fin_per_bundle = self.A_fin_per_tube*self.tubes_per_bundle
self.A_fin_per_bay = self.A_fin_per_tube*self.tubes_per_bay
self.A_fin = self.A_fin_per_tube*self.tubes
self.A_per_tube = self.A_tube_showing_per_tube + self.A_fin_per_tube
self.A_per_row = self.A_tube_showing_per_row + self.A_fin_per_row
self.A_per_bundle = self.A_tube_showing_per_bundle + self.A_fin_per_bundle
self.A_per_bay = self.A_tube_showing_per_bay + self.A_fin_per_bay
self.A = self.A_tube_showing + self.A_fin
self.A_increase = self.A/self.A_bare_tube
# TODO A_extra could be calculated based on a fixed width and height of the bay
A_extra = 0.0
self.A_diagonal_per_bundle = 2.0*self.tubes_per_row*self.tube_length*(self.pitch_diagonal - self.tube_diameter - 2.0*fin_density*self.fin_height*self.fin_thickness) + A_extra
self.A_normal_per_bundle = self.tubes_per_row*self.tube_length*(self.pitch_normal - self.tube_diameter - 2.0*fin_density*self.fin_height*self.fin_thickness) + A_extra
self.A_min_per_bundle = min(self.A_diagonal_per_bundle, self.A_normal_per_bundle)
self.A_min_per_bay = self.A_min_per_bundle*self.bundles_per_bay
self.A_min = self.A_min_per_bay*self.parallel_bays
i = 0.5 if self.corbels else 1.0
self.A_face_per_bundle = self.pitch_normal*self.tube_length*(self.tubes_per_row + i)
self.A_face_per_bay = self.A_face_per_bundle*self.bundles_per_bay
self.A_face = self.A_face_per_bay*self.parallel_bays
self.flow_area_contraction_ratio = self.A_min/self.A_face
if self.tube_thickness is not None:
self.Di = self.tube_diameter - self.tube_thickness*2.0
self.A_tube_flow = pi/4.0*self.Di*self.Di
self.A_tube_flow_per_row = self.A_tube_flow*self.tubes_per_row
self.A_tube_flow_per_bundle = self.A_tube_flow*self.tubes_per_bundle
self.A_tube_flow_per_bay = self.A_tube_flow*self.tubes_per_bay
self.A_tube_flow_total = self.A_tube_flow*self.tubes
self.tube_volume_per_tube = self.A_tube_flow*self.tube_length
self.tube_volume_per_row = self.tube_volume_per_tube*self.tubes_per_row
self.tube_volume_per_bundle = self.tube_volume_per_tube*self.tubes_per_bundle
self.tube_volume_per_bay = self.tube_volume_per_tube*self.tubes_per_bay
self.tube_volume = self.tube_volume_per_tube*self.tubes
else:
self.Di = None
self.A_tube_flow = None
self.tube_volume_per_tube = None
self.tube_volume_per_row = None
self.tube_volume_per_bundle = None
self.tube_volume_per_bay = None
self.tube_volume = None
# TODO: Support different numbers of tube rows per pass - maybe pass
# a list of rows per pass to tube_passes?
if self.tube_rows % self.tube_passes == 0:
self.channels = self.tubes_per_bundle/self.tube_passes
else:
self.channels = self.tubes_per_row
if self.angle == 30:
self.pitch_str = 'triangular'
self.pitch_class = 'staggered'
elif self.angle == 60:
self.pitch_str = 'rotated triangular'
self.pitch_class = 'staggered'
elif self.angle == 45:
self.pitch_str = 'rotated square'
self.pitch_class = 'in-line'
elif self.angle == 90:
self.pitch_str = 'square'
self.pitch_class = 'in-line'
else:
self.pitch_str = 'custom'
self.pitch_class = 'custom'
def pitch_angle_solver(angle=None, pitch=None, pitch_parallel=None,
pitch_normal=None):
r'''Utility to take any two of `angle`, `pitch`, `pitch_parallel`, and
`pitch_normal` and calculate the other two. This is useful for applications
with tube banks, as in shell and tube heat exchangers or air coolers and
allows for a wider range of user input.
.. math::
\text{pitch normal} = \text{pitch} \cdot \sin(\text{angle})
.. math::
\text{pitch parallel} = \text{pitch} \cdot \cos(\text{angle})
Parameters
----------
angle : float, optional
The angle of the tube layout, [degrees]
pitch : float, optional
The shortest distance between tube centers; defined in relation to the
flow direction only, [m]
pitch_parallel : float, optional
The distance between tube center along a line parallel to the flow;
has been called `longitudinal` pitch, `pp`, `s2`, `SL`, and `p2`, [m]
pitch_normal : float, optional
The distance between tube centers in a line 90° to the line of flow;
has been called the `transverse` pitch, `pn`, `s1`, `ST`, and `p1`, [m]
Returns
-------
angle : float
The angle of the tube layout, [degrees]
pitch : float
The shortest distance between tube centers; defined in relation to the
flow direction only, [m]
pitch_parallel : float
The distance between tube center along a line parallel to the flow;
has been called `longitudinal` pitch, `pp`, `s2`, `SL`, and `p2`, [m]
pitch_normal : float
The distance between tube centers in a line 90° to the line of flow;
has been called the `transverse` pitch, `pn`, `s1`, `ST`, and `p1`, [m]
Notes
-----
For the 90 and 0 degree case, the normal or parallel pitches can be zero;
given the angle and the zero value, obviously is it not possible to
calculate the pitch and a math error will be raised.
No exception will be raised if three or four inputs are provided; the other
two will simply be calculated according to the list of if statements used.
An exception will be raised if only one input is provided.
Examples
--------
>>> pitch_angle_solver(pitch=1, angle=30)
(30, 1, 0.8660254037844387, 0.49999999999999994)
References
----------
.. [1] Schlunder, Ernst U, and International Center for Heat and Mass
Transfer. Heat Exchanger Design Handbook. Washington:
Hemisphere Pub. Corp., 1983.
'''
if angle is not None and pitch is not None:
pitch_normal = pitch*sin(radians(angle))
pitch_parallel = pitch*cos(radians(angle))
elif angle is not None and pitch_normal is not None:
pitch = pitch_normal/sin(radians(angle))
pitch_parallel = pitch*cos(radians(angle))
elif angle is not None and pitch_parallel is not None:
pitch = pitch_parallel/cos(radians(angle))
pitch_normal = pitch*sin(radians(angle))
elif pitch_normal is not None and pitch is not None:
angle = degrees(asin(pitch_normal/pitch))
pitch_parallel = pitch*cos(radians(angle))
elif pitch_parallel is not None and pitch is not None:
angle = degrees(acos(pitch_parallel/pitch))
pitch_normal = pitch*sin(radians(angle))
elif pitch_parallel is not None and pitch_normal is not None:
angle = degrees(asin(pitch_normal/sqrt(pitch_normal**2 + pitch_parallel**2)))
pitch = sqrt(pitch_normal**2 + pitch_parallel**2)
else:
raise ValueError('Two of the arguments are required')
return angle, pitch, pitch_parallel, pitch_normal
def sphericity(A, V):
r'''Returns the sphericity of a particle of surface area `A` and volume
`V`. Sphericity is the ratio of the surface area of a sphere with the same
volume as the particle (equivalent diameter) to the actual surface area of
the particle.
.. math::
\Psi = \frac{\text{A of sphere with } V_p } {{A}_p}
= \frac{\pi^{\frac{1}{3}}(6V_p)^{\frac{2}{3}}}{A_p}
Parameters
----------
A : float
Surface area of particle, [m^2]
V : float
Volume of particle, [m^3]
Returns
-------
Psi : float
Sphericity [-]
Notes
-----
All non-spherical particles have spericities less than 1 but greater than 0.
Many common geometrical shapes have their results calculated exactly in [2]_.
Examples
--------
>>> sphericity(10., 2.)
0.767663317071005
For a cube of side length a=3, the surface area is 6*a^2=54 and volume a^3=27.
Its sphericity is then:
>>> sphericity(A=54, V=27)
0.8059959770082346
References
----------
.. [1] Rhodes, Martin J., ed. Introduction to Particle Technology. 2E.
Chichester, England ; Hoboken, NJ: Wiley, 2008.
.. [2] "Sphericity." Wikipedia, March 8, 2017.
https://en.wikipedia.org/w/index.php?title=Sphericity&oldid=769183043
'''
return pi**(1/3.)*(6*V)**(2/3.)/A
def aspect_ratio(Dmin, Dmax):
r'''Returns the aspect ratio of a shape with minimum and maximum dimension,
`Dmin` and `Dmax`.
.. math::
A_R = \frac{D_{min}}{D_{max}}
Parameters
----------
Dmin : float
Minimum dimension, [m]
Dmax : float
Maximum dimension, [m]
Returns
-------
a_r : float
Aspect ratio [-]
Examples
--------
>>> aspect_ratio(.2, 2)
0.1
'''
return Dmin/Dmax
def circularity(A, P):
r'''Returns the circularity of a shape with area `A` and perimeter `P`.
.. math::
f_{circ} = \frac {4 \pi A} {P^2}
Defined to be 1 for a circle. Used to characterize particles. Any
non-circular shape must have a circularity less than one.
Parameters
----------
A : float
Area of the shape, [m^2]
P : float
Perimeter of the shape, [m]
Returns
-------
f_circ : float
Circularity of the shape [-]
Examples
--------
Square, side length = 2 (all squares are the same):
>>> circularity(A=(2*2), P=4*2)
0.7853981633974483
Rectangle, one side length = 1, second side length = 100
>>> D1 = 1
>>> D2 = 100
>>> A = D1*D2
>>> P = 2*D1 + 2*D2
>>> circularity(A, P)
0.030796908671598795
'''
return 4*pi*A/P**2
def A_cylinder(D, L):
r'''Returns the surface area of a cylinder.
.. math::
A = \pi D L + 2\cdot \frac{\pi D^2}{4}
Parameters
----------
D : float
Diameter of the cylinder, [m]
L : float
Length of the cylinder, [m]
Returns
-------
A : float
Surface area [m^2]
Examples
--------
>>> A_cylinder(0.01, .1)
0.0032986722862692833
'''
cap = pi*D**2/4*2
side = pi*D*L
return cap + side
def V_cylinder(D, L):
r'''Returns the volume of a cylinder.
.. math::
V = \frac{\pi D^2}{4}L
Parameters
----------
D : float
Diameter of the cylinder, [m]
L : float
Length of the cylinder, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
>>> V_cylinder(0.01, .1)
7.853981633974484e-06
'''
return pi*D**2/4*L
def A_hollow_cylinder(Di, Do, L):
r'''Returns the surface area of a hollow cylinder.
.. math::
A = \pi D_o L + \pi D_i L + 2\cdot \frac{\pi D_o^2}{4}
- 2\cdot \frac{\pi D_i^2}{4}
Parameters
----------
Di : float
Diameter of the hollow in the cylinder, [m]
Do : float
Diameter of the exterior of the cylinder, [m]
L : float
Length of the cylinder, [m]
Returns
-------
A : float
Surface area [m^2]
Examples
--------
>>> A_hollow_cylinder(0.005, 0.01, 0.1)
0.004830198704894308
'''
side_o = pi*Do*L
side_i = pi*Di*L
cap_circle = pi*Do**2/4*2
cap_removed = pi*Di**2/4*2
return side_o + side_i + cap_circle - cap_removed
def V_hollow_cylinder(Di, Do, L):
r'''Returns the volume of a hollow cylinder.
.. math::
V = \frac{\pi D_o^2}{4}L - L\frac{\pi D_i^2}{4}
Parameters
----------
Di : float
Diameter of the hollow in the cylinder, [m]
Do : float
Diameter of the exterior of the cylinder, [m]
L : float
Length of the cylinder, [m]
Returns
-------
V : float
Volume [m^3]
Examples
--------
>>> V_hollow_cylinder(0.005, 0.01, 0.1)
5.890486225480862e-06
'''
return pi*Do**2/4*L - pi*Di**2/4*L
def A_multiple_hole_cylinder(Do, L, holes):
r'''Returns the surface area of a cylinder with multiple holes.
Calculation will naively return a negative value or other impossible
result if the number of cylinders added is physically impossible.
Holes may be of different shapes, but must be perpendicular to the
axis of the cylinder.
.. math::
A = \pi D_o L + 2\cdot \frac{\pi D_o^2}{4} +
\sum_{i}^n \left( \pi D_i L - 2\cdot \frac{\pi D_i^2}{4}\right)
Parameters
----------
Do : float
Diameter of the exterior of the cylinder, [m]
L : float
Length of the cylinder, [m]
holes : list
List of tuples containing (diameter, count) pairs of descriptions for
each of the holes sizes.
Returns
-------
A : float
Surface area [m^2]
Examples
--------
>>> A_multiple_hole_cylinder(0.01, 0.1, [(0.005, 1)])
0.004830198704894308
'''
side_o = pi*Do*L
cap_circle = pi*Do**2/4*2
A = cap_circle + side_o
for Di, n in holes:
side_i = pi*Di*L
cap_removed = pi*Di**2/4*2
A = A + side_i*n - cap_removed*n
return A
def V_multiple_hole_cylinder(Do, L, holes):
r'''Returns the solid volume of a cylinder with multiple cylindrical holes.
Calculation will naively return a negative value or other impossible
result if the number of cylinders added is physically impossible.
.. math::
V = \frac{\pi D_o^2}{4}L - L\frac{\pi D_i^2}{4}
Parameters
----------
Do : float
Diameter of the exterior of the cylinder, [m]
L : float
Length of the cylinder, [m]
holes : list
List of tuples containing (diameter, count) pairs of descriptions for
each of the holes sizes.
Returns
-------
V : float
Volume [m^3]
Examples
--------
>>> V_multiple_hole_cylinder(0.01, 0.1, [(0.005, 1)])
5.890486225480862e-06
'''
V = pi*Do**2/4*L
for Di, n in holes:
V -= pi*Di*Di/4*L*n
return V
|