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
|
/*
Copyright 2018 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_MODULE UDQTests
#include <boost/test/unit_test.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/common/utility/TimeService.hpp>
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
#include <opm/input/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
#include <opm/input/eclipse/EclipseState/Runspec.hpp>
#include <opm/input/eclipse/Python/Python.hpp>
#include <opm/input/eclipse/Schedule/MSW/SegmentMatcher.hpp>
#include <opm/input/eclipse/Schedule/MSW/WellSegments.hpp>
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#include <opm/input/eclipse/Schedule/ScheduleState.hpp>
#include <opm/input/eclipse/Schedule/SummaryState.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQActive.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQAssign.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQConfig.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQContext.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQFunction.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQFunctionTable.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQSet.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQState.hpp>
#include <opm/input/eclipse/Schedule/Well/NameOrder.hpp>
#include <opm/input/eclipse/Schedule/Well/Well.hpp>
#include <opm/input/eclipse/Schedule/Well/WellMatcher.hpp>
#include <opm/input/eclipse/Utility/Typetools.hpp>
#include <opm/input/eclipse/Parser/ErrorGuard.hpp>
#include <opm/input/eclipse/Parser/InputErrorAction.hpp>
#include <opm/input/eclipse/Parser/ParseContext.hpp>
#include <opm/input/eclipse/Parser/Parser.hpp>
#include <opm/input/eclipse/Deck/Deck.hpp>
#include <opm/input/eclipse/Deck/UDAValue.hpp>
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <memory>
#include <limits>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
using namespace Opm;
namespace {
Schedule make_schedule(const std::string& input)
{
auto deck = Parser{}.parseString(input);
if (deck.hasKeyword("DIMENS")) {
EclipseState es(deck);
return { deck, es, std::make_shared<Python>() };
}
else {
EclipseGrid grid(10,10,10);
TableManager table(deck);
FieldPropsManager fp(deck, Phases{true, true, true}, grid, table);
Runspec runspec(deck);
return { deck, grid, fp, runspec, std::make_shared<Python>() };
}
}
Opm::Segment makeSegment(const int segmentNumber)
{
return { segmentNumber, 1, 1, 1.0, 0.0, 0.5, 0.01, 0.25, 1.23, true, 0.0, 0.0 };
}
std::shared_ptr<Opm::WellSegments> makeSegments(const int numSegments)
{
auto segments = std::vector<Opm::Segment>{};
segments.reserve(numSegments);
for (auto segment = 0; segment < numSegments; ++segment) {
segments.push_back(makeSegment(segment + 1));
}
return std::make_shared<Opm::WellSegments>
(Opm::WellSegments::CompPressureDrop::HFA, segments);
}
Opm::Well makeProducerWell(const std::string& wname,
const std::size_t insert,
const int numSegments)
{
auto w = Opm::Well {
wname, "G", 0, insert, 1, 2, {},
Opm::WellType { true, Opm::Phase::OIL }, // Oil producer
Opm::Well::ProducerCMode::ORAT,
Opm::Connection::Order::INPUT,
Opm::UnitSystem::newMETRIC(),
-3.0e+20, // UDQ undefined
0.0, true, true, 0,
Opm::Well::GasInflowEquation::STD
};
if (numSegments > 0) {
w.updateSegments(makeSegments(numSegments));
}
return w;
}
Opm::Well makeInjectionWell(const std::string& wname,
const std::size_t insert,
const int numSegments)
{
auto w = Opm::Well {
wname, "G", 0, insert, 1, 2, {},
Opm::WellType { false, Opm::Phase::GAS }, // Gas injector
Opm::Well::ProducerCMode::ORAT,
Opm::Connection::Order::INPUT,
Opm::UnitSystem::newMETRIC(),
-3.0e+20, // UDQ undefined
0.0, true, true, 0,
Opm::Well::GasInflowEquation::STD
};
if (numSegments > 0) {
w.updateSegments(makeSegments(numSegments));
}
return w;
}
// Collection of wells
// OP-01: Producer, MSW, 20 segments (1 .. 20)
// OP-02: Producer, MSW, 5 segments (1 .. 5)
// OP-06: Producer, Standard well
// OPROD: Producer, MSW, 2 segments (1 .. 2)
//
// GI-01: Injector, MSW, 10 segments (1 .. 10)
// GI-08: Injector, Standard well
// I-45: Injector, MSW, 1 segment (1)
Opm::ScheduleState dynamicInputData()
{
auto block = Opm::ScheduleState { Opm::TimeService::now() };
block.wells.update(makeProducerWell("OP-01", 0, 20));
block.wells.update(makeProducerWell("OP-02", 1, 5));
block.wells.update(makeProducerWell("OP-06", 2, 0));
block.wells.update(makeProducerWell("OPROD", 3, 2));
block.wells.update(makeInjectionWell("GI-01", 4, 10));
block.wells.update(makeInjectionWell("GI-08", 5, 0));
block.wells.update(makeInjectionWell("I-45", 6, 1));
block.well_order.update(Opm::NameOrder {
"OP-01", "OP-02", "OP-06", "OPROD", "GI-01", "GI-08", "I-45",
});
return block;
}
} // Anonymous namespace
BOOST_AUTO_TEST_CASE(TYPE_COERCION) {
BOOST_CHECK( UDQVarType::SCALAR == UDQ::coerce(UDQVarType::SCALAR, UDQVarType::SCALAR) );
BOOST_CHECK( UDQVarType::WELL_VAR == UDQ::coerce(UDQVarType::SCALAR, UDQVarType::WELL_VAR));
BOOST_CHECK( UDQVarType::WELL_VAR == UDQ::coerce(UDQVarType::WELL_VAR, UDQVarType::FIELD_VAR));
BOOST_CHECK( UDQVarType::GROUP_VAR == UDQ::coerce(UDQVarType::SCALAR, UDQVarType::GROUP_VAR));
BOOST_CHECK( UDQVarType::GROUP_VAR == UDQ::coerce(UDQVarType::GROUP_VAR, UDQVarType::FIELD_VAR));
BOOST_CHECK_THROW( UDQ::coerce(UDQVarType::GROUP_VAR, UDQVarType::WELL_VAR), std::logic_error );
BOOST_CHECK_THROW( UDQ::coerce(UDQVarType::WELL_VAR, UDQVarType::GROUP_VAR), std::logic_error );
}
BOOST_AUTO_TEST_CASE(GROUP_VARIABLES)
{
KeywordLocation location;
UDQParams udqp;
UDQFunctionTable udqft;
UDQDefine def_group(udqp, "GUOPRL", 0, location, {"(", "5000", "-", "GOPR", "LOWER", "*", "0.13", "-", "GOPR", "UPPER", "*", "0.15", ")" , "*", "0.89"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
UDQContext context(udqft, {}, {}, UDQContext::MatcherFactories{}, st, udq_state);
double gopr_lower = 1234;
double gopr_upper = 4321;
st.update_group_var("LOWER", "GOPR", gopr_lower);
st.update_group_var("UPPER", "GOPR", gopr_upper);
auto res_group = def_group.eval(context);
BOOST_CHECK_EQUAL( res_group["UPPER"].get(), (5000 - gopr_lower*0.13 - gopr_upper*0.15)*0.89);
BOOST_CHECK_EQUAL( res_group["UPPER"].get(), (5000 - gopr_lower*0.13 - gopr_upper*0.15)*0.89);
BOOST_CHECK_THROW(context.get_group_var("LOWER", "GGPR"), std::exception);
auto empty_value = context.get_group_var("NO_SUCH_GROUP", "GOPR");
BOOST_CHECK(!empty_value);
}
BOOST_AUTO_TEST_CASE(SINGLE_SEGMENT_VARIABLES)
{
const auto location = KeywordLocation{};
const auto udqp = UDQParams{};
const auto udqft = UDQFunctionTable{};
const auto def_seg = UDQDefine {
udqp, "SU_OFR", 0, location,
{ "(", "5000", "-", "SOFR", "'OP-*'", "3", "*", "0.13", ")" , "*", "0.89" }
};
auto st = SummaryState { TimeService::now(), udqp.undefinedValue() };
auto udq_state = UDQState { udqp.undefinedValue() };
auto factories = UDQContext::MatcherFactories{};
factories.segments = [sched_state = dynamicInputData()]()
{
return std::make_unique<SegmentMatcher>(sched_state);
};
auto context = UDQContext {
udqft, {}, {}, factories, st, udq_state
};
const auto sofr_p1_3 = 1234.0;
const auto sofr_p2_3 = 4321.0;
st.update_segment_var("OP-01", "SOFR", 3, sofr_p1_3);
st.update_segment_var("OP-02", "SOFR", 3, sofr_p2_3);
const auto res_seg = def_seg.eval(context);
BOOST_CHECK_EQUAL(res_seg("OP-01", 3).get(), (5000.0 - sofr_p1_3*0.13) * 0.89);
BOOST_CHECK_EQUAL(res_seg("OP-02", 3).get(), (5000.0 - sofr_p2_3*0.13) * 0.89);
}
BOOST_AUTO_TEST_CASE(SUBTRACT)
{
KeywordLocation location;
UDQParams udqp;
UDQFunctionTable udqft;
UDQDefine def(udqp, "WU", 0, location, {"16", "-", "8", "-", "4", "-", "2", "-", "1"});
UDQDefine scalar(udqp, "WU", 0, location, {"16"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"P1"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WOPR", 4);
auto res = def.eval(context);
BOOST_CHECK_EQUAL( res[0].get(), 1.0);
auto res2 = scalar.eval(context);
BOOST_CHECK_EQUAL( res2[0].get(), 16.0);
}
BOOST_AUTO_TEST_CASE(TEST)
{
KeywordLocation location;
UDQParams udqp;
UDQFunctionTable udqft;
UDQDefine def1(udqp, "WUWI3",0, location, {"GOPR" , "MAU", "*", "2.0", "*", "0.25", "*", "10"});
UDQDefine def2(udqp, "WUWI3",0, location, {"2.0", "*", "0.25", "*", "3"});
UDQDefine def3(udqp, "WUWI3",0, location, {"GOPR" , "FIELD", "-", "2.0", "*", "3"});
UDQDefine def4(udqp, "WUWI3",0, location, {"FOPR" , "/", "2"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"P1", "P2"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_group_var("MAU", "GOPR", 4);
st.update_group_var("XXX", "GOPR", 5);
st.update_group_var("FIELD", "GOPR", 6);
st.update_well_var("P1", "WBHP", 0.5);
st.update_well_var("P2", "WBHP", 0.5);
st.update("FOPR", 2);
auto res1 = def1.eval(context);
BOOST_CHECK_EQUAL( res1["P1"].get(), 20 );
BOOST_CHECK_EQUAL( res1["P2"].get(), 20 );
auto res2 = def2.eval(context);
BOOST_CHECK_EQUAL( res2["P1"].get(), 1.50 );
BOOST_CHECK_EQUAL( res2["P2"].get(), 1.50 );
auto res3 = def3.eval(context);
BOOST_CHECK_EQUAL( res3["P1"].get(), 0.00 );
BOOST_CHECK_EQUAL( res3["P2"].get(), 0.00 );
auto res4 = def4.eval(context);
BOOST_CHECK_EQUAL( res4["P1"].get(), 1.00 );
BOOST_CHECK_EQUAL( res4["P2"].get(), 1.00 );
// This expression has a well set as target type, and involves group
// with wildcard that is not supported by flow.
BOOST_CHECK_THROW( UDQDefine(udqp, "GUPR2",0, location, {"GOPR", "G*", "*", "2.0"}), OpmInputError);
// UDQVarType == BLOCK is not yet supported.
BOOST_CHECK_THROW( UDQDefine(udqp, "BUPR2",0, location, {"BPR", "1","1", "1", "*", "2.0"}), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(MIX_SCALAR) {
UDQFunctionTable udqft;
UDQParams udqp;
KeywordLocation location;
UDQDefine def_add(udqp, "WU",0, location, {"WOPR", "+", "1"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"P1"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WOPR", 1);
auto res_add = def_add.eval(context);
BOOST_CHECK_EQUAL( res_add["P1"].get() , 2);
}
BOOST_AUTO_TEST_CASE(UDQFieldSetTest) {
KeywordLocation location;
UDQParams udqp;
UDQFunctionTable udqft(udqp);
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"P1", "P2", "P3", "P4"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WOPR", 1.0);
st.update_well_var("P2", "WOPR", 2.0);
st.update_well_var("P3", "WOPR", 3.0);
st.update_well_var("P4", "WOPR", 4.0);
#if 0
{
UDQDefine def_fxxx(udqp, "FU_SCALAR", {"123"});
auto fxxx_res = def_fxxx.eval(context);
BOOST_CHECK_EQUAL( fxxx_res[0].get(), 123.0 );
BOOST_CHECK( fxxx_res.var_type() == UDQVarType::FIELD_VAR);
}
#endif
{
UDQDefine def_fopr(udqp, "FUOPR",0, location, {"SUM", "(", "WOPR", ")"});
auto fopr_res = def_fopr.eval(context);
BOOST_CHECK_EQUAL( fopr_res[0].get(), 10.0 );
}
}
BOOST_AUTO_TEST_CASE(UDQWellSetNANTest) {
std::vector<std::string> wells = {"P1", "P2", "I1", "I2"};
UDQSet ws = UDQSet::wells("NAME", wells);
UDQSet ws2 = UDQSet::wells("NAME", wells);
BOOST_CHECK(ws == ws2);
for (std::size_t i = 0; i < 4; i++)
ws.assign(i, i*1.0);
BOOST_CHECK_EQUAL(ws.defined_size(), 4U);
ws.assign(1,std::numeric_limits<double>::quiet_NaN());
ws.assign(3,std::numeric_limits<double>::quiet_NaN());
BOOST_CHECK_EQUAL(ws.defined_size(), 2U);
BOOST_CHECK(ws.has("P1"));
BOOST_CHECK(ws.has("P2"));
}
BOOST_AUTO_TEST_CASE(UDQWellSetTest) {
std::vector<std::string> wells = {"P1", "P2", "I1", "I2"};
UDQSet ws = UDQSet::wells("NAME", wells);
UDQSet ws2 = UDQSet::wells("NAME", wells, 100.0);
BOOST_CHECK_EQUAL(4U, ws.size());
ws.assign("P1", 1.0);
const auto& value = ws["P1"];
BOOST_CHECK_EQUAL(value.get(), 1.0);
BOOST_CHECK_EQUAL(ws["P1"].get(), 1.0);
BOOST_REQUIRE_THROW(ws.assign("NO_SUCH_WELL", 1.0), std::out_of_range);
BOOST_REQUIRE_THROW(ws[10], std::out_of_range);
BOOST_REQUIRE_THROW(ws["NO_SUCH_WELL"], std::out_of_range);
ws.assign("*", 2.0);
for (const auto& w : wells)
BOOST_CHECK_EQUAL(ws[w].get(), 2.0);
ws.assign(3.0);
for (const auto& w : wells)
BOOST_CHECK_EQUAL(ws[w].get(), 3.0);
ws.assign("P*", 4.0);
BOOST_CHECK_EQUAL(ws["P1"].get(), 4.0);
BOOST_CHECK_EQUAL(ws["P2"].get(), 4.0);
ws.assign("I2", 5.0);
BOOST_CHECK_EQUAL(ws["I2"].get(), 5.0);
for (const auto& w : wells)
BOOST_CHECK_EQUAL(ws2[w].get(), 100.0);
UDQSet scalar = UDQSet::scalar("NAME", 1.0);
BOOST_CHECK_EQUAL(scalar.size() , 1U);
BOOST_CHECK_EQUAL(scalar[0].get(), 1.0);
UDQSet empty = UDQSet::empty("EMPTY");
BOOST_CHECK_EQUAL(empty.size() , 0U);
}
BOOST_AUTO_TEST_CASE(UDQ_GROUP_TEST) {
std::vector<std::string> groups = {"G1", "G2", "G3", "G4"};
UDQSet gs = UDQSet::groups("NAME", groups);
BOOST_CHECK_EQUAL(4U, gs.size());
gs.assign("G1", 1.0);
const auto& value = gs["G1"];
BOOST_CHECK_EQUAL(value.get(), 1.0);
{
KeywordLocation location;
UDQParams udqp;
UDQFunctionTable udqft(udqp);
UDQDefine def_fopr(udqp, "FUOPR",0, location, {"SUM", "(", "GOPR", ")"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
UDQContext context(udqft, {}, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_group_var("G1", "GOPR", 1.0);
st.update_group_var("G2", "GOPR", 2.0);
st.update_group_var("G3", "GOPR", 3.0);
st.update_group_var("G4", "GOPR", 4.0);
auto res = def_fopr.eval(context);
BOOST_CHECK_EQUAL(res[0].get(), 10.0);
}
}
BOOST_AUTO_TEST_CASE(UDQ_DEFINETEST) {
UDQParams udqp;
UDQFunctionTable udqft(udqp);
KeywordLocation location;
{
UDQDefine def(udqp, "WUBHP",0, location, {"WBHP"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"W1", "W2", "W3"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("W1", "WBHP", 11);
st.update_well_var("W2", "WBHP", 2);
st.update_well_var("W3", "WBHP", 3);
auto res = def.eval(context);
BOOST_CHECK_EQUAL(res.size(), 3U);
BOOST_CHECK_EQUAL( res["W1"].get(), 11 );
BOOST_CHECK_EQUAL( res["W2"].get(), 2 );
BOOST_CHECK_EQUAL( res["W3"].get(), 3 );
BOOST_CHECK_THROW( context.get_well_var("W3", "WWCT"), std::exception);
auto empty_value = context.get_well_var("NO_SUCH_WELL", "WBHP");
BOOST_CHECK(!empty_value);
}
{
UDQDefine def(udqp, "WUBHP",0, location, {"WBHP" , "'P*'"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"I1", "I2", "P1", "P2"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WBHP", 1);
st.update_well_var("P2", "WBHP", 2);
st.update_well_var("I1", "WBHP", 1);
st.update_well_var("I2", "WBHP", 2);
auto res = def.eval(context);
BOOST_CHECK_EQUAL(res.size(), 4U);
BOOST_CHECK_EQUAL( res["P1"].get(), 1 );
BOOST_CHECK_EQUAL( res["P2"].get(), 2 );
BOOST_CHECK_EQUAL( res["I1"].defined(), false);
BOOST_CHECK_EQUAL( res["I1"].defined(), false);
}
{
UDQDefine def(udqp, "WUBHP",0, location, {"NINT" , "(", "WBHP", ")"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"P1", "P2", "I1", "I2"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WBHP", 4);
st.update_well_var("P2", "WBHP", 3);
st.update_well_var("I1", "WBHP", 2);
st.update_well_var("I2", "WBHP", 1);
auto res = def.eval(context);
BOOST_CHECK_EQUAL( res["P1"].get(), 4 );
BOOST_CHECK_EQUAL( res["P2"].get(), 3 );
BOOST_CHECK_EQUAL( res["I1"].get(), 2 );
BOOST_CHECK_EQUAL( res["I2"].get(), 1 );
}
}
BOOST_AUTO_TEST_CASE(KEYWORDS) {
const std::string input = R"(
RUNSPEC
UDQDIMS
10* 'N'/
UDQPARAM
3* 0.25 /
)";
Parser parser;
auto deck = parser.parseString(input);
auto runspec = Runspec(deck);
auto udq_params = runspec.udqParams();
BOOST_CHECK_EQUAL(0.25, udq_params.cmpEpsilon());
// The reseed parameter is set to false, so the repeated calls to reseedRNG() should have
// no effect.
udq_params.reseedRNG(100);
auto r1 = udq_params.true_rng()();
udq_params.reseedRNG(100);
auto r2 = udq_params.true_rng()();
BOOST_CHECK( r1 != r2 );
}
BOOST_AUTO_TEST_CASE(ENUM_CONVERSION) {
BOOST_CHECK_THROW(UDQ::varType("WWCT"), std::invalid_argument);
BOOST_CHECK_THROW(UDQ::varType("XUCT"), std::invalid_argument);
BOOST_CHECK(UDQ::varType("WUBHP") == UDQVarType::WELL_VAR);
BOOST_CHECK(UDQ::varType("GUBHP") == UDQVarType::GROUP_VAR);
BOOST_CHECK(UDQ::varType("CUBHP") == UDQVarType::CONNECTION_VAR);
BOOST_CHECK(UDQ::varType("FUBHP") == UDQVarType::FIELD_VAR);
BOOST_CHECK(UDQ::varType("RUBHP") == UDQVarType::REGION_VAR);
BOOST_CHECK(UDQ::varType("AUBHP") == UDQVarType::AQUIFER_VAR);
BOOST_CHECK(UDQ::varType("SUBHP") == UDQVarType::SEGMENT_VAR);
BOOST_CHECK(UDQ::targetType("WBHP") == UDQVarType::WELL_VAR);
BOOST_CHECK(UDQ::targetType("GBHP") == UDQVarType::GROUP_VAR);
BOOST_CHECK(UDQ::targetType("CBHP") == UDQVarType::CONNECTION_VAR);
BOOST_CHECK(UDQ::targetType("FBHP") == UDQVarType::FIELD_VAR);
BOOST_CHECK(UDQ::targetType("RBHP") == UDQVarType::REGION_VAR);
BOOST_CHECK(UDQ::targetType("ABHP") == UDQVarType::AQUIFER_VAR);
BOOST_CHECK(UDQ::targetType("SBHP") == UDQVarType::SEGMENT_VAR);
BOOST_REQUIRE_THROW( UDQ::actionType("INVALID_ACTION"), std::invalid_argument);
BOOST_CHECK(UDQ::actionType("DEFINE") == UDQAction::DEFINE );
BOOST_CHECK(UDQ::actionType("UNITS") == UDQAction::UNITS );
BOOST_CHECK(UDQ::actionType("ASSIGN") == UDQAction::ASSIGN );
}
BOOST_AUTO_TEST_CASE(UDQ_KEWYORDS) {
const std::string input = R"(
RUNSPEC
UDQDIMS
10* 'Y'/
UDQPARAM
3* 0.25 /
SCHEDULE
UDQ
ASSIGN WUBHP 0.0 /
UNITS WUBHP 'BARSA' /
DEFINE FUOPR AVEG(WOPR) + 1/
ASSIGN WUXUNIT 0.0 /
DEFINE FUOPR AVEG(WOPR)/
/
DATES
10 'JAN' 2010 /
/
UDQ
ASSIGN WUBHP 0.0 /
DEFINE FUOPR AVEG(WOPR)/
UNITS WUBHP 'BARSA' / -- Repeating the same unit multiple times is superfluous but OK
/
)";
auto schedule = make_schedule(input);
const auto& udq = schedule.getUDQConfig(0);
BOOST_CHECK_EQUAL(2U, udq.assignments().size());
BOOST_CHECK_THROW( udq.unit("NO_SUCH_KEY"), std::invalid_argument );
BOOST_CHECK_EQUAL( udq.unit("WUBHP"), "BARSA");
BOOST_CHECK( udq.has_keyword("WUBHP") );
BOOST_CHECK( !udq.has_keyword("NO_SUCH_KEY") );
BOOST_CHECK( !udq.has_unit("WUXUNIT"));
BOOST_CHECK( udq.has_unit("WUBHP"));
Parser parser;
auto deck = parser.parseString(input);
auto udq_params1 = UDQParams(deck);
BOOST_CHECK_EQUAL(0.25, udq_params1.cmpEpsilon());
auto& sim_rng1 = udq_params1.sim_rng();
auto& true_rng1 = udq_params1.true_rng();
auto udq_params2 = UDQParams(deck);
auto& sim_rng2 = udq_params2.sim_rng();
auto& true_rng2 = udq_params2.true_rng();
BOOST_CHECK( sim_rng1() == sim_rng2() );
BOOST_CHECK( true_rng1() != true_rng2() );
udq_params1.reseedRNG(100);
udq_params2.reseedRNG(100);
BOOST_CHECK( true_rng1() == true_rng2() );
}
BOOST_AUTO_TEST_CASE(UDQ_CHANGE_UNITS_ILLEGAL) {
const std::string input = R"(
RUNSPEC
UDQDIMS
10* 'Y'/
UDQPARAM
3* 0.25 /
SCHEDULE
UDQ
ASSIGN WUBHP 0.0 /
UNITS WUBHP 'BARSA' /
DEFINE FUOPR AVEG(WOPR) + 1/
/
DATES
10 'JAN' 2010 /
/
UDQ
ASSIGN WUBHP 0.0 /
DEFINE FUOPR AVEG(WOPR) + 1/
UNITS WUBHP 'HOURS' / -- Changing unit runtime is *not* supported
/
)";
BOOST_CHECK_THROW( make_schedule(input), std::exception);
}
BOOST_AUTO_TEST_CASE(UDQ_DEFINE_WITH_SLASH) {
const std::string input = R"(
UDQ
DEFINE WUWCT WWPR / ( WWPR + WOPR ) /
/
)";
Parser parser;
auto deck = parser.parseString(input);
const auto& udq = deck["UDQ"].back();
const auto& record = udq.getRecord(0);
const auto& data_item = record.getItem("DATA");
const auto& data = RawString::strings( data_item.getData<RawString>() );
std::vector<std::string> exp = {"WWPR", "/", "(", "WWPR", "+", "WOPR", ")"};
BOOST_CHECK_EQUAL_COLLECTIONS(data.begin(), data.end(),
exp.begin(), exp.end());
}
BOOST_AUTO_TEST_CASE(UDQ_ASSIGN_DATA) {
const std::string input = R"(
RUNSPEC
UDQDIMS
10* 'Y'/
UDQPARAM
3* 0.25 /
SCHEDULE
UDQ
ASSIGN WU1 P12 4.0 /
ASSIGN WU2 8.0 /
/
)";
const auto schedule = make_schedule(input);
const auto& udq = schedule.getUDQConfig(0);
const auto& assignments = udq.assignments();
const auto& ass0 = assignments[0];
const auto& ass1 = assignments[1];
auto w1 = ass0.eval({"P1", "P2", "P12"});
auto w2 = ass1.eval({"P1", "P2", "P12"});
BOOST_CHECK_EQUAL(w1.name(), "WU1");
BOOST_CHECK_EQUAL(w2.name(), "WU2");
BOOST_CHECK_EQUAL( w1["P12"].get(), 4.0 );
BOOST_CHECK_EQUAL( w1["P1"].defined(), false );
BOOST_CHECK_EQUAL( w1["P2"].defined(), false );
BOOST_CHECK_EQUAL( w2["P12"].get(), 8.0 );
BOOST_CHECK_EQUAL( w2["P1"].get(), 8.0 );
BOOST_CHECK_EQUAL( w2["P2"].get(), 8.0 );
}
BOOST_AUTO_TEST_CASE(UDQ_CONTEXT) {
UDQParams udqp;
UDQFunctionTable func_table;
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
UDQContext ctx(func_table, {}, {}, UDQContext::MatcherFactories{}, st, udq_state);
BOOST_CHECK_EQUAL(*ctx.get("JAN"), 1.0);
BOOST_CHECK_THROW(ctx.get("NO_SUCH_KEY"), std::out_of_range);
for (const std::string& key : std::vector<std::string>({"MSUMLINS", "MSUMNEWT", "NEWTON", "TCPU"}))
BOOST_CHECK_NO_THROW( ctx.get(key) );
st.update("SX:KEY", 1.0);
BOOST_CHECK_EQUAL(*ctx.get("SX:KEY") , 1.0 );
}
BOOST_AUTO_TEST_CASE(UDQ_SET) {
UDQSet s1("NAME", 5);
for (const auto& v : s1) {
BOOST_CHECK_EQUAL(false, v.defined());
BOOST_REQUIRE_THROW( v.get(), std::invalid_argument);
}
BOOST_CHECK_EQUAL(s1.defined_size(), 0U);
s1.assign(1);
for (const auto& v : s1) {
BOOST_CHECK_EQUAL(true, v.defined());
BOOST_CHECK_EQUAL( v.get(), 1.0);
}
BOOST_CHECK_EQUAL(s1.defined_size(), s1.size());
s1.assign(0,0.0);
{
UDQSet s2("NAME", 6);
BOOST_REQUIRE_THROW(s1 + s2, std::logic_error);
}
{
UDQSet s2("NAME", 5);
s2.assign(0, 25);
auto s3 = s1 + s2;
auto v0 = s3[0];
BOOST_CHECK_EQUAL(v0.get(), 25);
auto v4 = s3[4];
BOOST_CHECK( !v4.defined() );
}
s1.assign(0,1.0);
{
UDQSet s2 = s1 + 1.0;
UDQSet s3 = s2 * 2.0;
UDQSet s4 = s1 - 1.0;
for (const auto& v : s2) {
BOOST_CHECK_EQUAL(true, v.defined());
BOOST_CHECK_EQUAL( v.get(), 2.0);
}
for (const auto& v : s3) {
BOOST_CHECK_EQUAL(true, v.defined());
BOOST_CHECK_EQUAL( v.get(), 4.0);
}
for (const auto& v : s4) {
BOOST_CHECK_EQUAL(true, v.defined());
BOOST_CHECK_EQUAL( v.get(), 0);
}
}
}
BOOST_AUTO_TEST_CASE(UDQ_FUNCTION_TABLE) {
UDQFunctionTable udqft;
BOOST_CHECK(udqft.has_function("SUM"));
BOOST_CHECK(!udqft.has_function("NO_SUCH_FUNCTION"));
UDQSet arg("NAME", 5);
arg.assign(0,1);
arg.assign(2,2);
arg.assign(4,4);
{
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("SUM"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL(result[0].get(), 7);
}
{
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("NORM1"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL(result[0].get(), 7);
}
{
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("NORM2"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL(result[0].get(), std::sqrt(1 + 4+ 16));
}
{
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("NORMI"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL(result[0].get(), 4);
}
{
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("MIN"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL(result[0].get(), 1);
}
{
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("MAX"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL(result[0].get(), 4);
}
{
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("AVEA"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL(result[0].get(), 7.0/3);
}
{
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("AVEG"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL(result[0].get(), std::exp((std::log(1) + std::log(2.0) + std::log(4))/3));
}
{
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("PROD"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL(result[0].get(), 8.0);
}
{
UDQSet arg2("NAME", 4);
arg2.assign(0,1);
arg2.assign(2,4);
arg2.assign(3,4);
const auto& func = dynamic_cast<const UDQScalarFunction&>(udqft.get("AVEH"));
auto result = func.eval(arg2);
BOOST_CHECK_EQUAL(result[0].get(), 2.0);
}
}
BOOST_AUTO_TEST_CASE(CMP_FUNCTIONS) {
UDQFunctionTable udqft;
UDQSet arg1("NAME", 5);
UDQSet arg2("NAME", 5);
UDQSet arg3("NAME", 3);
arg1.assign(1,1);
arg1.assign(0,1);
arg1.assign(2,2);
arg1.assign(4,4);
arg2.assign(0, 0.9);
arg2.assign(2, 2.5);
arg2.assign(4, 4.0);
BOOST_CHECK_THROW(UDQBinaryFunction::EQ(0.25, arg1, arg3), std::logic_error);
{
auto result = UDQBinaryFunction::EQ(0, arg1, arg2);
BOOST_CHECK_EQUAL( result.defined_size(), 3U );
BOOST_CHECK_EQUAL( result[0].get(), 0);
BOOST_CHECK_EQUAL( result[2].get(), 0);
BOOST_CHECK_EQUAL( result[4].get(), 1);
result = UDQBinaryFunction::EQ(0.20, arg1, arg2);
BOOST_CHECK_EQUAL( result[0].get(), 1);
BOOST_CHECK_EQUAL( result[2].get(), 0);
BOOST_CHECK_EQUAL( result[4].get(), 1);
const auto& func = dynamic_cast<const UDQBinaryFunction&>(udqft.get("=="));
result = func.eval(arg1, arg2);
BOOST_CHECK_EQUAL( result[0].get(), 0);
BOOST_CHECK_EQUAL( result[2].get(), 0);
BOOST_CHECK_EQUAL( result[4].get(), 1);
}
{
const auto& func = dynamic_cast<const UDQBinaryFunction&>(udqft.get("<"));
auto result = func.eval(arg1, arg2);
BOOST_CHECK_EQUAL( result.defined_size(), 3U );
BOOST_CHECK_EQUAL( result[0].get(), 0);
BOOST_CHECK_EQUAL( result[2].get(), 1);
BOOST_CHECK_EQUAL( result[4].get(), 0);
}
{
const auto& func = dynamic_cast<const UDQBinaryFunction&>(udqft.get(">"));
auto result = func.eval(arg1, arg2);
BOOST_CHECK_EQUAL( result.defined_size(), 3U );
BOOST_CHECK_EQUAL( result[0].get(), 1);
BOOST_CHECK_EQUAL( result[2].get(), 0);
BOOST_CHECK_EQUAL( result[4].get(), 0);
}
{
const auto& func = dynamic_cast<const UDQBinaryFunction&>(udqft.get("^"));
UDQSet arg1_local("NAME", 4);
UDQSet arg2_local("NAME", 4);
for (std::size_t i=0; i < arg1_local.size(); i++) {
arg1_local.assign(i, i + 1);
arg2_local.assign(i, 2);
}
auto result = func.eval(arg1_local, arg2_local);
for (std::size_t i=0; i < arg1_local.size(); i++)
BOOST_CHECK_EQUAL( result[i].get(), (i+1)*(i+1));
}
{
auto result = UDQBinaryFunction::GE(1.0, arg1, arg2);
BOOST_CHECK_EQUAL( result[0].get(), 1);
// This is bisarre - but due to the large epsilon 2 and 2.5 compare as
// equal; and then we evaluate 2 >= 2.5 as TRUE!
BOOST_CHECK_EQUAL( result[2].get(), 1);
BOOST_CHECK_EQUAL( result[4].get(), 1);
}
{
const auto& func = dynamic_cast<const UDQBinaryFunction&>(udqft.get("<="));
auto result = func.eval(arg1, arg2);
BOOST_CHECK_EQUAL( result[0].get(), 0);
BOOST_CHECK_EQUAL( result[2].get(), 1);
BOOST_CHECK_EQUAL( result[4].get(), 1);
}
}
BOOST_AUTO_TEST_CASE(CMP_FUNCTIONS2) {
UDQFunctionTable udqft;
auto arg1 = UDQSet::scalar("NAME", 0);
auto arg2 = UDQSet::scalar("NAME", 0);
auto eq = UDQBinaryFunction::EQ(0, arg1, arg2);
BOOST_CHECK_EQUAL(eq[0].get(), 1);
}
BOOST_AUTO_TEST_CASE(ELEMENTAL_UNARY_FUNCTIONS) {
UDQFunctionTable udqft;
UDQSet arg("NAME", 5);
arg.assign(0,1);
arg.assign(2,2);
arg.assign(4,4);
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("ABS"));
UDQSet arg2("NAME", 5);
arg2.assign(0,1);
arg2.assign(2,-2);
arg2.assign(4,4);
auto result = func.eval(arg2);
BOOST_CHECK_EQUAL( result[0].get(), 1);
BOOST_CHECK_EQUAL( result[2].get(), 2);
BOOST_CHECK_EQUAL( result[4].get(), 4);
}
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("DEF"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL( result[0].get(), 1);
BOOST_CHECK_EQUAL( result[2].get(), 1);
BOOST_CHECK_EQUAL( result[4].get(), 1);
}
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("UNDEF"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL( result[1].get(), 1);
BOOST_CHECK_EQUAL( result[3].get(), 1);
BOOST_CHECK_EQUAL( result.defined_size(), 2U);
}
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("EXP"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL( result[0].get(), std::exp(1));
BOOST_CHECK_EQUAL( result[2].get(), std::exp(2));
BOOST_CHECK_EQUAL( result[4].get(), std::exp(4));
}
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("IDV"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL( result[0].get(), 1);
BOOST_CHECK_EQUAL( result[1].get(), 0);
BOOST_CHECK_EQUAL( result[2].get(), 1);
BOOST_CHECK_EQUAL( result[3].get(), 0);
BOOST_CHECK_EQUAL( result[4].get(), 1);
}
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("LOG"));
UDQSet arg_local("NAME", 3);
arg_local.assign(0, 10);
arg_local.assign(2,1000);
auto result = func.eval(arg_local);
BOOST_CHECK_EQUAL( result[0].get(), 1);
BOOST_CHECK( !result[1] );
BOOST_CHECK_EQUAL( result[2].get(), 3);
}
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("NINT"));
UDQSet arg_local("NAME", 3);
arg_local.assign(0, 0.75);
arg_local.assign(2, 1.25);
auto result = func.eval(arg_local);
BOOST_CHECK_EQUAL( result[0].get(), 1);
BOOST_CHECK( !result[1] );
BOOST_CHECK_EQUAL( result[2].get(), 1);
}
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("RANDN"));
UDQSet arg_local("NAME", 3);
arg_local.assign(0, -1.0);
arg_local.assign(2, -1.0);
auto result1 = func.eval(arg_local);
auto result2 = func.eval(arg_local);
BOOST_CHECK( result1[0].get() != -1.0);
BOOST_CHECK( !result1[1] );
BOOST_CHECK( result1[2].get() != -1.0);
BOOST_CHECK( result1[0].get() != result2[0].get());
BOOST_CHECK( result1[2].get() != result2[2].get());
}
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("SORTA"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL( result[0].get(), 1);
BOOST_CHECK( !result[1] );
BOOST_CHECK_EQUAL( result[2].get(), 2);
BOOST_CHECK( !result[3] );
BOOST_CHECK_EQUAL( result[4].get(), 3);
}
{
const auto& func = dynamic_cast<const UDQUnaryElementalFunction&>(udqft.get("SORTD"));
auto result = func.eval(arg);
BOOST_CHECK_EQUAL( result[0].get(), 3);
BOOST_CHECK( !result[1] );
BOOST_CHECK_EQUAL( result[2].get(), 2);
BOOST_CHECK( !result[3] );
BOOST_CHECK_EQUAL( result[4].get(), 1);
}
}
BOOST_AUTO_TEST_CASE(UNION_FUNCTIONS) {
UDQFunctionTable udqft;
UDQSet arg1("NAME", 5);
UDQSet arg2("NAME", 5);
arg1.assign(0,1);
arg1.assign(2,2);
arg2.assign(0, 1.0);
arg2.assign(3, 3 );
const auto& func = dynamic_cast<const UDQBinaryFunction&>(udqft.get("UADD"));
auto result = func.eval(arg1, arg2);
BOOST_CHECK_EQUAL( 3U, result.defined_size() );
BOOST_CHECK_EQUAL( 2, result[0].get() );
BOOST_CHECK_EQUAL( 2, result[2].get() );
BOOST_CHECK_EQUAL( 3, result[3].get() );
}
BOOST_AUTO_TEST_CASE(FUNCTIONS_INVALID_ARGUMENT) {
UDQSet arg("NAME",3);
arg.assign(0, -1);
BOOST_REQUIRE_THROW( UDQScalarFunction::AVEG(arg), std::invalid_argument);
BOOST_REQUIRE_THROW( UDQUnaryElementalFunction::LOG(arg), std::invalid_argument);
BOOST_REQUIRE_THROW( UDQUnaryElementalFunction::LN(arg), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(UDQ_SET_DIV) {
UDQSet s("NAME", 6);
s.assign(0,1);
s.assign(2,2);
s.assign(4,5);
s.assign(5,0);
auto result = 10 / s;
BOOST_CHECK_EQUAL( result.defined_size(), 3U);
BOOST_CHECK_EQUAL( result[0].get(), 10);
BOOST_CHECK_EQUAL( result[2].get(), 5);
BOOST_CHECK_EQUAL( result[4].get(), 2);
}
BOOST_AUTO_TEST_CASE(UDQASSIGN_TEST) {
UDQAssign as1("WUPR", std::vector<std::string>{}, 1.0, 1);
UDQAssign as2("WUPR", std::vector<std::string>{"P*"}, 2.0, 2);
UDQAssign as3("WUPR", std::vector<std::string>{"P1"}, 4.0, 3);
std::vector<std::string> ws1 = {"P1", "P2", "I1", "I2"};
auto res1 = as1.eval(ws1);
BOOST_CHECK_EQUAL(res1.size(), 4U);
BOOST_CHECK_EQUAL(res1["P1"].get(), 1.0);
BOOST_CHECK_EQUAL(res1["I2"].get(), 1.0);
auto res2 = as2.eval(ws1);
BOOST_CHECK_EQUAL(res2["P1"].get(), 2.0);
BOOST_CHECK_EQUAL(res2["P2"].get(), 2.0);
BOOST_CHECK(!res2["I1"].defined());
BOOST_CHECK(!res2["I2"].defined());
auto res3 = as3.eval(ws1);
BOOST_CHECK_EQUAL(res3["P1"].get(), 4.0);
BOOST_CHECK(!res3["P2"].defined());
BOOST_CHECK(!res3["I1"].defined());
BOOST_CHECK(!res3["I2"].defined());
}
BOOST_AUTO_TEST_CASE(UDQASSIGN_NUMBERED_ITEMS_TEST) {
using Vsz = std::vector<std::size_t>;
const auto selector = UDQSet::EnumeratedItems {
"PROD01", Vsz { 1, 3, 5, 7 }
};
const auto as = UDQAssign {
"SUVTRIG", std::vector { selector }, 0.123, 42
};
const auto segments = std::vector {
UDQSet::EnumeratedItems { "PROD01", Vsz { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, } },
UDQSet::EnumeratedItems { "PROD02", Vsz { 1, 2, 3, 4, 5, } },
UDQSet::EnumeratedItems { "PROD06", Vsz { 2, 4, 6, 8, 10, } },
UDQSet::EnumeratedItems { "I-45", Vsz { 1, 2, 3, } },
};
const auto us = as.eval(segments);
BOOST_CHECK_EQUAL(us.size(), std::size_t{23});
BOOST_CHECK_CLOSE(us("PROD01", 1).get(), 0.123, 1.0e-8);
BOOST_CHECK_MESSAGE(!us("PROD01", 2).defined(), R"(SUVTRIG("PROD01", 2) must not be defined)");
BOOST_CHECK_CLOSE(us("PROD01", 3).get(), 0.123, 1.0e-8);
BOOST_CHECK_MESSAGE(!us("PROD01", 4).defined(), R"(SUVTRIG("PROD01", 4) must not be defined)");
BOOST_CHECK_CLOSE(us("PROD01", 5).get(), 0.123, 1.0e-8);
BOOST_CHECK_MESSAGE(!us("PROD01", 6).defined(), R"(SUVTRIG("PROD01", 6) must not be defined)");
BOOST_CHECK_CLOSE(us("PROD01", 7).get(), 0.123, 1.0e-8);
BOOST_CHECK_MESSAGE(!us("PROD01", 8).defined(), R"(SUVTRIG("PROD01", 8) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD01", 9).defined(), R"(SUVTRIG("PROD01", 9) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD01", 10).defined(), R"(SUVTRIG("PROD01", 10) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD02", 1).defined(), R"(SUVTRIG("PROD02", 1) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD02", 2).defined(), R"(SUVTRIG("PROD02", 2) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD02", 3).defined(), R"(SUVTRIG("PROD02", 3) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD02", 4).defined(), R"(SUVTRIG("PROD02", 4) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD02", 5).defined(), R"(SUVTRIG("PROD02", 5) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD06", 2).defined(), R"(SUVTRIG("PROD06", 2) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD06", 4).defined(), R"(SUVTRIG("PROD06", 4) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD06", 6).defined(), R"(SUVTRIG("PROD06", 6) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD06", 8).defined(), R"(SUVTRIG("PROD06", 8) must not be defined)");
BOOST_CHECK_MESSAGE(!us("PROD06", 10).defined(), R"(SUVTRIG("PROD06", 10) must not be defined)");
BOOST_CHECK_THROW(us("PROD06", 3).defined(), std::out_of_range);
BOOST_CHECK_MESSAGE(!us("I-45", 1).defined(), R"(SUVTRIG("I-45", 1) must not be defined)");
BOOST_CHECK_MESSAGE(!us("I-45", 2).defined(), R"(SUVTRIG("I-45", 2) must not be defined)");
BOOST_CHECK_MESSAGE(!us("I-45", 3).defined(), R"(SUVTRIG("I-45", 3) must not be defined)");
BOOST_CHECK_THROW(us("Hello", 42).defined(), std::out_of_range);
}
BOOST_AUTO_TEST_CASE(UDQ_POW_TEST) {
KeywordLocation location;
UDQFunctionTable udqft;
UDQParams udqp;
UDQDefine def_pow1(udqp, "WU",0, location, {"WOPR", "+", "WWPR", "*", "WGOR", "^", "WWIR"});
UDQDefine def_pow2(udqp, "WU",0, location, {"(", "WOPR", "+", "WWPR", ")", "^", "(", "WOPR", "+" , "WGOR", "*", "WWIR", "-", "WBHP", ")"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
NameOrder wo; wo.add("P1");
WellMatcher wm(wo);
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WOPR", 1);
st.update_well_var("P1", "WWPR", 2);
st.update_well_var("P1", "WGOR", 3);
st.update_well_var("P1", "WWIR", 4);
st.update_well_var("P1", "WBHP", 7);
auto res_pow1 = def_pow1.eval(context);
auto res_pow2 = def_pow2.eval(context);
BOOST_CHECK_EQUAL( res_pow1["P1"].get() , 1 + 2 * std::pow(3,4));
BOOST_CHECK_EQUAL( res_pow2["P1"].get() , std::pow(1 + 2, 1 + 3*4 - 7));
}
BOOST_AUTO_TEST_CASE(UDQ_CMP_TEST) {
KeywordLocation location;
UDQFunctionTable udqft;
UDQParams udqp;
UDQDefine def_cmp(udqp, "WU",0, location, {"WOPR", ">", "WWPR", "+", "WGOR", "*", "WWIR"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"P1", "P2"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WOPR", 0);
st.update_well_var("P1", "WWPR", 10);
st.update_well_var("P1", "WGOR", -3);
st.update_well_var("P1", "WWIR", 4);
st.update_well_var("P2", "WOPR", 0);
st.update_well_var("P2", "WWPR", -2);
st.update_well_var("P2", "WGOR", 4);
st.update_well_var("P2", "WWIR", 1);
auto res_cmp = def_cmp.eval(context);
BOOST_CHECK_EQUAL( res_cmp["P1"].get() , 1.0);
BOOST_CHECK_EQUAL( res_cmp["P2"].get() , 0.0);
}
#if 0
BOOST_AUTO_TEST_CASE(UDQPARSE_ERROR) {
setUDQFunctionTable udqft;
UDQDefine def1(udqft, "WUBHP", {"WWCT", "+"});
}
#endif
BOOST_AUTO_TEST_CASE(UDQ_SCALAR_SET) {
KeywordLocation location;
UDQParams udqp;
UDQFunctionTable udqft;
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"PA1", "PB2", "PC3", "PD4"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("PA1", "WOPR", 1);
st.update_well_var("PB2", "WOPR", 2);
st.update_well_var("PC3", "WOPR", 3);
st.update_well_var("PD4", "WOPR", 4);
st.update_well_var("PA1", "WWPR", 1);
st.update_well_var("PB2", "WWPR", 2);
st.update_well_var("PC3", "WWPR", 3);
st.update_well_var("PD4", "WWPR", 4);
{
UDQDefine def(udqp, "WUOPR",0, location, {"WOPR", "'PA*'"});
auto res = def.eval(context);
BOOST_CHECK_EQUAL(4U, res.size());
auto well1 = res["PA1"];
BOOST_CHECK( well1.defined() );
BOOST_CHECK_EQUAL(well1.get() , 1);
auto well2 = res["PB2"];
BOOST_CHECK( !well2.defined() );
auto well4 = res["PD4"];
BOOST_CHECK( !well4.defined() );
}
{
UDQDefine def(udqp, "WUOPR",0, location, {"1"});
auto res = def.eval(context);
BOOST_CHECK_EQUAL(4U, res.size());
auto well1 = res["PA1"];
BOOST_CHECK( well1.defined() );
BOOST_CHECK_EQUAL(well1.get() , 1);
auto well2 = res["PB2"];
BOOST_CHECK( well2.defined() );
BOOST_CHECK_EQUAL(well2.get() , 1);
auto well4 = res["PD4"];
BOOST_CHECK( well4.defined() );
BOOST_CHECK_EQUAL(well4.get() , 1);
}
{
UDQDefine def(udqp, "WUOPR",0, location, {"WOPR", "'PA1'"});
auto res = def.eval(context);
BOOST_CHECK_EQUAL(4U, res.size());
auto well1 = res["PA1"];
BOOST_CHECK( well1.defined() );
BOOST_CHECK_EQUAL(well1.get() , 1);
auto well2 = res["PB2"];
BOOST_CHECK( well2.defined() );
BOOST_CHECK_EQUAL(well2.get() , 1);
auto well4 = res["PD4"];
BOOST_CHECK( well4.defined() );
BOOST_CHECK_EQUAL(well4.get() , 1);
BOOST_CHECK_EQUAL( "WUOPR", res.name() );
}
}
BOOST_AUTO_TEST_CASE(UDQ_SORTD_NAN) {
UDQParams udqp;
UDQFunctionTable udqft;
KeywordLocation location;
UDQDefine def(udqp, "WUPR1" ,0, location, {"1", "/", "(", "WWIR", "'OP*'" , ")"});
UDQDefine def_sort(udqp , "WUPR3",0, location, {"SORTD", "(", "WUPR1", ")" });
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"OP1", "OP2", "OP3", "OP4"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("OP1", "WWIR", 1.0);
st.update_well_var("OP2", "WWIR", 2.0);
st.update_well_var("OP3", "WWIR", 3.0);
st.update_well_var("OP4", "WWIR", 4.0);
auto res1 = def.eval(context);
context.update_define(0, def.keyword(), res1);
auto res_sort1 = def_sort.eval(context);
context.update_define(0, def_sort.keyword(), res_sort1);
BOOST_CHECK_EQUAL(res_sort1["OP1"].get(), 1.0);
BOOST_CHECK_EQUAL(res_sort1["OP2"].get(), 2.0);
BOOST_CHECK_EQUAL(res_sort1["OP3"].get(), 3.0);
BOOST_CHECK_EQUAL(res_sort1["OP4"].get(), 4.0);
BOOST_CHECK( st.has_well_var("OP1", "WUPR3"));
BOOST_CHECK( st.has_well_var("OP4", "WUPR3"));
st.update_well_var("OP1", "WWIR", 0);
auto res2 = def.eval(context);
BOOST_CHECK_EQUAL(res2.defined_size(), 3U);
context.update_define(0, def.keyword(), res2);
BOOST_CHECK( st.has_well_var("OP4", "WUPR1"));
auto res_sort2 = def_sort.eval(context);
context.update_define(0, def.keyword(), res2);
BOOST_CHECK_EQUAL(res_sort2.defined_size(), 3U);
BOOST_CHECK_EQUAL(res_sort2["OP2"].get(), 1.0);
BOOST_CHECK_EQUAL(res_sort2["OP3"].get(), 2.0);
BOOST_CHECK_EQUAL(res_sort2["OP4"].get(), 3.0);
BOOST_CHECK( st.has_well_var("OP4", "WUPR3"));
}
BOOST_AUTO_TEST_CASE(UDQ_SORTA) {
KeywordLocation location;
UDQParams udqp;
UDQFunctionTable udqft;
UDQDefine def1(udqp, "WUPR1" ,0, location, {"1", "/", "(", "WWCT", "'OP*'", "+", "0.00001", ")"});
UDQDefine def_sort(udqp , "WUPR3",0, location, {"SORTA", "(", "WUPR1", ")" });
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"OPL01", "OPL02", "OPU01", "OPU02"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("OPL01", "WWCT", 0.7);
st.update_well_var("OPL02", "WWCT", 0.8);
st.update_well_var("OPU01", "WWCT", 0.0);
st.update_well_var("OPU02", "WWCT", 0.0);
auto res1 = def1.eval(context);
context.update_define(0, def1.keyword(), res1);
auto res_sort = def_sort.eval(context);
BOOST_CHECK_EQUAL(res_sort["OPL02"].get(), 1.0);
BOOST_CHECK_EQUAL(res_sort["OPL01"].get(), 2.0);
BOOST_CHECK_EQUAL(res_sort["OPU01"].get() + res_sort["OPU02"].get(), 7.0);
}
BOOST_AUTO_TEST_CASE(UDQ_BASIC_MATH_TEST) {
UDQParams udqp;
UDQFunctionTable udqft;
KeywordLocation location;
UDQDefine def_add(udqp, "WU2OPR",0, location, {"WOPR", "+", "WOPR"});
UDQDefine def_sub(udqp, "WU2OPR",0, location, {"WOPR", "-", "WOPR"});
UDQDefine def_mul(udqp, "WU2OPR",0, location, {"WOPR", "*", "WOPR"});
UDQDefine def_div(udqp, "WU2OPR",0, location, {"WOPR", "/", "WOPR"});
UDQDefine def_muladd(udqp, "WUX",0, location, {"WOPR", "+", "WOPR", "*", "WOPR"});
UDQDefine def_wuwct(udqp , "WUWCT",0, location, {"WWPR", "/", "(", "WOPR", "+", "WWPR", ")"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"P1", "P2", "P3", "P4"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WOPR", 1);
st.update_well_var("P2", "WOPR", 2);
st.update_well_var("P3", "WOPR", 3);
st.update_well_var("P4", "WOPR", 4);
st.update_well_var("P1", "WWPR", 1);
st.update_well_var("P2", "WWPR", 2);
st.update_well_var("P3", "WWPR", 3);
st.update_well_var("P4", "WWPR", 4);
auto res_add = def_add.eval(context);
BOOST_CHECK_EQUAL( res_add.size(), 4U);
BOOST_CHECK_EQUAL( res_add["P1"].get(), 2);
BOOST_CHECK_EQUAL( res_add["P2"].get(), 4);
BOOST_CHECK_EQUAL( res_add["P3"].get(), 6);
BOOST_CHECK_EQUAL( res_add["P4"].get(), 8);
auto res_sub = def_sub.eval(context);
BOOST_CHECK_EQUAL( res_sub.size(), 4U);
BOOST_CHECK_EQUAL( res_sub["P1"].get(), 0);
BOOST_CHECK_EQUAL( res_sub["P2"].get(), 0);
BOOST_CHECK_EQUAL( res_sub["P3"].get(), 0);
BOOST_CHECK_EQUAL( res_sub["P4"].get(), 0);
auto res_div = def_div.eval(context);
BOOST_CHECK_EQUAL( res_div.size(), 4U);
BOOST_CHECK_EQUAL( res_div["P1"].get(), 1);
BOOST_CHECK_EQUAL( res_div["P2"].get(), 1);
BOOST_CHECK_EQUAL( res_div["P3"].get(), 1);
BOOST_CHECK_EQUAL( res_div["P4"].get(), 1);
auto res_mul = def_mul.eval(context);
BOOST_CHECK_EQUAL( res_mul.size(), 4U);
BOOST_CHECK_EQUAL( res_mul["P1"].get(), 1);
BOOST_CHECK_EQUAL( res_mul["P2"].get(), 4);
BOOST_CHECK_EQUAL( res_mul["P3"].get(), 9);
BOOST_CHECK_EQUAL( res_mul["P4"].get(),16);
auto res_muladd = def_muladd.eval(context);
BOOST_CHECK_EQUAL( res_muladd.size(), 4U);
BOOST_CHECK_EQUAL( res_muladd["P1"].get(), 1 + 1);
BOOST_CHECK_EQUAL( res_muladd["P2"].get(), 4 + 2);
BOOST_CHECK_EQUAL( res_muladd["P3"].get(), 9 + 3);
BOOST_CHECK_EQUAL( res_muladd["P4"].get(),16 + 4);
auto res_wuwct= def_wuwct.eval(context);
BOOST_CHECK_EQUAL( res_wuwct.size(), 4U);
BOOST_CHECK_EQUAL( res_wuwct["P1"].get(),0.50);
BOOST_CHECK_EQUAL( res_wuwct["P2"].get(),0.50);
BOOST_CHECK_EQUAL( res_wuwct["P3"].get(),0.50);
BOOST_CHECK_EQUAL( res_wuwct["P4"].get(),0.50);
}
BOOST_AUTO_TEST_CASE(DECK_TEST) {
KeywordLocation location;
UDQParams udqp;
UDQFunctionTable udqft(udqp);
UDQDefine def(udqp, "WUOPRL",0, location, {"(", "WOPR", "OP1", "-", "150", ")", "*", "0.90"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"OP1", "OP2", "OP3"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("OP1", "WOPR", 300);
st.update_well_var("OP2", "WOPR", 3000);
st.update_well_var("OP3", "WOPR", 30000);
auto res = def.eval(context);
BOOST_CHECK_EQUAL(res.size(), 3U);
for (std::size_t index = 0; index < res.size(); index++)
BOOST_CHECK( res[index].get() == (300 - 150)*0.90);
}
BOOST_AUTO_TEST_CASE(UDQPARSE_TEST1) {
KeywordLocation location;
UDQParams udqp;
UDQDefine def1(udqp, "WUBHP",0, location, {"1/(WWCT", "'W1*')"});
BOOST_CHECK_EQUAL( def1.input_string() , "1 / (WWCT 'W1*')");
UDQDefine def2(udqp, "WUBHP",0, location, {"2 * (1", "+" , "WBHP)"});
BOOST_CHECK_EQUAL( def2.input_string() , "2 * (1 + WBHP)");
}
BOOST_AUTO_TEST_CASE(INPUT_STRING_SCIENTIFIC_NOTATION) {
const auto schedule = make_schedule(R"(
SCHEDULE
UDQ
DEFINE FU_THREE (3000000 + FU_ONE*1500000 + 1000000*FU_TWO)/365 /
/
)");
const auto& udq = schedule.getUDQConfig(0);
const auto def = udq.definitions();
BOOST_CHECK_EQUAL(def.size(), 1ULL);
const auto expect_input_string = std::string {
"(3E+06 + FU_ONE * 1.5E+06 + 1E+06 * FU_TWO) / 365"
};
BOOST_CHECK_EQUAL(def[0].input_string(), expect_input_string);
}
BOOST_AUTO_TEST_CASE(UDQ_PARSE_ERROR) {
UDQParams udqp;
ParseContext parseContext;
ErrorGuard errors;
std::vector<std::string> tokens = {"WBHP", "+"};
KeywordLocation location;
parseContext.update(ParseContext::UDQ_PARSE_ERROR, InputErrorAction::IGNORE);
{
UDQDefine def1(udqp, "WUBHP",0, location, tokens, parseContext, errors);
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQFunctionTable udqft(udqp);
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"P1"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WBHP", 1);
auto res = def1.eval(context);
BOOST_CHECK_EQUAL(res["P1"].get(), udqp.undefinedValue());
}
parseContext.update(ParseContext::UDQ_PARSE_ERROR, InputErrorAction::THROW_EXCEPTION);
BOOST_CHECK_THROW( UDQDefine(udqp, "WUBHP",0, location, tokens, parseContext, errors), OpmInputError);
}
BOOST_AUTO_TEST_CASE(UDQ_TYPE_ERROR) {
UDQParams udqp;
ParseContext parseContext;
ErrorGuard errors;
std::vector<std::string> tokens1 = {"WBHP", "+", "1"};
std::vector<std::string> tokens2 = {"SUM", "(", "WBHP", ")"};
KeywordLocation location;
parseContext.update(ParseContext::UDQ_TYPE_ERROR, InputErrorAction::IGNORE);
{
UDQDefine def1(udqp, "FUBHP",0, location, tokens1, parseContext, errors);
UDQDefine def2(udqp, "WUBHP",0, location, tokens2, parseContext, errors);
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQFunctionTable udqft(udqp);
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"P1", "P2"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("P1", "WBHP", 1);
st.update_well_var("P2", "WBHP", 2);
auto res1 = def1.eval(context);
BOOST_CHECK_EQUAL(res1[0].get(), udqp.undefinedValue());
auto res2 = def2.eval(context);
BOOST_CHECK_EQUAL(res2.size(), st.num_wells());
for (std::size_t index = 0; index < res2.size(); index++)
BOOST_CHECK_EQUAL(res2[index].get(), 3);
}
parseContext.update(ParseContext::UDQ_TYPE_ERROR, InputErrorAction::THROW_EXCEPTION);
// This fails because the well expression (WBHP + 1) is assigned to the field variable FUBHP
BOOST_CHECK_THROW( UDQDefine(udqp, "FUBHP",0, location, tokens1, parseContext, errors), OpmInputError);
}
BOOST_AUTO_TEST_CASE(UDA_VALUE) {
UDAValue value0;
BOOST_CHECK(value0.is<double>());
BOOST_CHECK(!value0.is<std::string>());
BOOST_CHECK_EQUAL( value0.get<double>(), 0);
BOOST_CHECK_THROW( value0.get<std::string>(), std::invalid_argument);
value0.update(10);
BOOST_CHECK_EQUAL( value0.get<double>(), 10);
BOOST_CHECK_THROW( value0.get<std::string>(), std::invalid_argument);
value0.update("STRING");
BOOST_CHECK_EQUAL( value0.get<std::string>(), std::string("STRING"));
BOOST_CHECK_THROW( value0.get<double>(), std::invalid_argument);
UDAValue value1(10);
BOOST_CHECK(value1.is<double>());
BOOST_CHECK(!value1.is<std::string>());
BOOST_CHECK_EQUAL( value1.get<double>(), 10);
BOOST_CHECK_NO_THROW( value1.assert_numeric() );
value1 *= 10;
BOOST_CHECK_EQUAL( value1.get<double>(), 100);
UDAValue value2("FUBHP");
BOOST_CHECK(!value2.is<double>());
BOOST_CHECK(value2.is<std::string>());
BOOST_CHECK_EQUAL( value2.get<std::string>(), std::string("FUBHP"));
BOOST_CHECK_THROW( value2.get<double>(), std::invalid_argument);
BOOST_CHECK_THROW( value2.assert_numeric("SHould contain numeric value"), std::invalid_argument);
BOOST_CHECK_THROW( value2 *= 10, std::exception );
}
// The unit/dimension handling in the UDAvalue is hacky at best.
BOOST_AUTO_TEST_CASE(UDA_VALUE_DIM) {
UDAValue value0(1);
Dimension dim(10);
UDAValue value1(1, dim);
BOOST_CHECK_EQUAL( value0.get<double>(), 1);
BOOST_CHECK_EQUAL( value0.getSI(), 1);
BOOST_CHECK_EQUAL( value1.get<double>(), 1);
BOOST_CHECK_EQUAL( value1.getSI(), 10);
}
BOOST_AUTO_TEST_CASE(UDQ_INPUT_BASIC) {
std::string deck_string = R"(
SCHEDULE
UDQ
ASSIGN WUBHP1 11 / 0
ASSIGN WUOPR 20 / 1
ASSIGN WUBHP2 P2 12 / 2
UNITS WUBHP 'BARSA' /
UNITS WUOPR 'SM3/DAY' /
DEFINE WUWCT WWPR / (WWPR + WOPR) / 3
UNITS WUWCT '1' /
DEFINE FUOPR SUM(WOPR) / 4
UNITS FUOPR 'SM3/DAY' /
UNITS FUXXX 'SM3/DAY' /
/
UDQ
ASSIGN WUBHPX P2 12 / 5
DEFINE FUOPRX SUM(WOPR) / 6
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
const auto& input = udq.input();
const auto& def = udq.definitions();
BOOST_CHECK_EQUAL(input.size(), 7U);
BOOST_CHECK_EQUAL(udq.size(), 7U);
BOOST_CHECK( input[0].is<UDQAssign>() );
BOOST_CHECK( input[1].is<UDQAssign>() );
BOOST_CHECK( input[2].is<UDQAssign>() );
BOOST_CHECK( input[3].is<UDQDefine>() );
BOOST_CHECK( input[4].is<UDQDefine>() );
BOOST_CHECK( input[5].is<UDQAssign>() );
BOOST_CHECK( input[6].is<UDQDefine>() );
BOOST_CHECK_EQUAL( input[1].unit(), "SM3/DAY" );
BOOST_CHECK_EQUAL(def[0].keyword(), "WUWCT");
BOOST_CHECK_EQUAL(def[1].keyword(), "FUOPR");
BOOST_CHECK_EQUAL(def[2].keyword(), "FUOPRX");
BOOST_CHECK_EQUAL( input[3].get<UDQDefine>().keyword(), "WUWCT");
BOOST_CHECK_EQUAL( input[4].get<UDQDefine>().keyword(), "FUOPR");
BOOST_CHECK_EQUAL( input[6].get<UDQDefine>().keyword(), "FUOPRX");
BOOST_CHECK( !udq.has_keyword("FUXXX") );
const auto wubhp1 = udq["WUBHP1"];
BOOST_CHECK( wubhp1.is<UDQAssign>() );
}
BOOST_AUTO_TEST_CASE(UDQ_INPUT_OVERWRITE) {
std::string deck_string = R"(
SCHEDULE
UDQ
ASSIGN WUBHP1 11 /
ASSIGN WUOPR 20 /
ASSIGN WUBHP2 P2 12 /
--ASSIGN WUBHP 0 / --DUMMY
UNITS WUBHP 'BARSA' /
UNITS WUOPR 'SM3/DAY' /
DEFINE WUWCT WWPR / (WWPR + WOPR) /
UNITS WUWCT '1' /
DEFINE FUOPR SUM(WOPR) /
UNITS FUOPR 'SM3/DAY' /
/
UDQ
DEFINE WUBHP1 SUM(WOPR) /
DEFINE FUOPR MAX(WOPR) /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
const auto& input = udq.input();
BOOST_CHECK_EQUAL(input.size(), 5U);
BOOST_CHECK_EQUAL(udq.size(), 5U);
BOOST_CHECK( input[0].is<UDQDefine>());
BOOST_CHECK_EQUAL( input[0].keyword(), "WUBHP1");
const auto fuopr = udq["FUOPR"];
BOOST_CHECK( fuopr.is<UDQDefine>() );
const auto& def2 = fuopr.get<UDQDefine>();
BOOST_CHECK_EQUAL(def2.input_string(), "MAX(WOPR)");
}
BOOST_AUTO_TEST_CASE(UDQ_USAGE) {
UDQActive usage;
UDQParams params;
UDQConfig conf(params);
BOOST_CHECK_EQUAL( usage.iuad().size(), 0U );
UDAValue uda1("WUX");
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
conf.add_assign(uda1.get<std::string>(), segmentMatcherFactory, std::vector<std::string>{}, 100, 0);
const auto& iuad = usage.iuad();
usage.update(conf, uda1, "W1", UDAControl::WCONPROD_ORAT);
BOOST_CHECK_EQUAL( usage.iuad().size(), 1U);
BOOST_CHECK_EQUAL( iuad[0].use_count, 1U);
usage.update(conf, uda1, "W1", UDAControl::WCONPROD_GRAT);
BOOST_CHECK_EQUAL( usage.iuad().size(), 2U);
BOOST_CHECK_EQUAL( iuad[1].use_count, 1U);
const auto& rec = iuad[0];
BOOST_CHECK_EQUAL(rec.udq, "WUX");
BOOST_CHECK(rec.control == UDAControl::WCONPROD_ORAT);
for (std::size_t index = 0; index < usage.iuad().size(); index++) {
const auto& record = iuad[index];
BOOST_CHECK_EQUAL(record.input_index, 0U);
if (index == 0)
BOOST_CHECK(record.control == UDAControl::WCONPROD_ORAT);
else
BOOST_CHECK(record.control == UDAControl::WCONPROD_GRAT);
}
}
BOOST_AUTO_TEST_CASE(UDQControl_Keyword)
{
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONPROD_ORAT) == UDAKeyword::WCONPROD, "WCONPROD_ORAT control keyword must be WCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONPROD_GRAT) == UDAKeyword::WCONPROD, "WCONPROD_GRAT control keyword must be WCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONPROD_WRAT) == UDAKeyword::WCONPROD, "WCONPROD_WRAT control keyword must be WCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONPROD_LRAT) == UDAKeyword::WCONPROD, "WCONPROD_LRAT control keyword must be WCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONPROD_RESV) == UDAKeyword::WCONPROD, "WCONPROD_RESV control keyword must be WCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONPROD_BHP) == UDAKeyword::WCONPROD, "WCONPROD_BHP control keyword must be WCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONPROD_THP) == UDAKeyword::WCONPROD, "WCONPROD_THP control keyword must be WCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONINJE_RATE) == UDAKeyword::WCONINJE, "WCONINJE_RATE control keyword must be WCONINJE");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONINJE_RESV) == UDAKeyword::WCONINJE, "WCONINJE_RESV control keyword must be WCONINJE");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONINJE_BHP) == UDAKeyword::WCONINJE, "WCONINJE_BHP control keyword must be WCONINJE");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WCONINJE_THP) == UDAKeyword::WCONINJE, "WCONINJE_THP control keyword must be WCONINJE");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::GCONPROD_OIL_TARGET) == UDAKeyword::GCONPROD, "GCONPROD_OIL_TARGET control keyword must be GCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::GCONPROD_WATER_TARGET) == UDAKeyword::GCONPROD, "GCONPROD_WATER_TARGET control keyword must be GCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::GCONPROD_GAS_TARGET) == UDAKeyword::GCONPROD, "GCONPROD_GAS_TARGET control keyword must be GCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::GCONPROD_LIQUID_TARGET) == UDAKeyword::GCONPROD, "GCONPROD_LIQUID_TARGET control keyword must be GCONPROD");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::GCONINJE_SURFACE_MAX_RATE) == UDAKeyword::GCONINJE, "GCONINJE_SURFACE_MAX_RATE control keyword must be GCONINJE");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::GCONINJE_RESV_MAX_RATE) == UDAKeyword::GCONINJE, "GCONINJE_RESV_MAX_RATE control keyword must be GCONINJE");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::GCONINJE_TARGET_REINJ_FRACTION) == UDAKeyword::GCONINJE, "GCONINJE_TARGET_REINJ_FRACTION control keyword must be GCONINJE");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::GCONINJE_TARGET_VOID_FRACTION) == UDAKeyword::GCONINJE, "GCONINJE_TARGET_VOID_FRACTION control keyword must be GCONINJE");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WELTARG_ORAT) == UDAKeyword::WELTARG, "WELTARG_ORAT control keyword must be WELTARG");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WELTARG_WRAT) == UDAKeyword::WELTARG, "WELTARG_WRAT control keyword must be WELTARG");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WELTARG_GRAT) == UDAKeyword::WELTARG, "WELTARG_GRAT control keyword must be WELTARG");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WELTARG_LRAT) == UDAKeyword::WELTARG, "WELTARG_LRAT control keyword must be WELTARG");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WELTARG_RESV) == UDAKeyword::WELTARG, "WELTARG_RESV control keyword must be WELTARG");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WELTARG_BHP) == UDAKeyword::WELTARG, "WELTARG_BHP control keyword must be WELTARG");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WELTARG_THP) == UDAKeyword::WELTARG, "WELTARG_THP control keyword must be WELTARG");
BOOST_CHECK_MESSAGE(UDQ::keyword(UDAControl::WELTARG_LIFT) == UDAKeyword::WELTARG, "WELTARG_LIFT control keyword must be WELTARG");
BOOST_CHECK_THROW(UDQ::keyword(static_cast<UDAControl>(1729)),
std::logic_error);
}
BOOST_AUTO_TEST_CASE(UDAControl_IUAD_0)
{
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONPROD_ORAT), 300'004);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONPROD_GRAT), 500'004);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONPROD_WRAT), 400'004);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONPROD_LRAT), 600'004);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONPROD_RESV), 700'004);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONPROD_BHP), 800'004);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONPROD_THP), 900'004);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONINJE_RATE), 400'003);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONINJE_RESV), 500'003);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONINJE_BHP), 600'003);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WCONINJE_THP), 700'003);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::GCONPROD_OIL_TARGET), 200'019);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::GCONPROD_WATER_TARGET), 300'019);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::GCONPROD_GAS_TARGET), 400'019);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::GCONPROD_LIQUID_TARGET), 500'019);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::GCONINJE_SURFACE_MAX_RATE), 300'017);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::GCONINJE_RESV_MAX_RATE), 400'017);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::GCONINJE_TARGET_REINJ_FRACTION), 500'017);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::GCONINJE_TARGET_VOID_FRACTION), 600'017);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WELTARG_ORAT), 16);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WELTARG_WRAT), 100'016);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WELTARG_GRAT), 200'016);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WELTARG_LRAT), 300'016);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WELTARG_RESV), 400'016);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WELTARG_BHP), 500'016);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WELTARG_THP), 600'016);
BOOST_CHECK_EQUAL(UDQ::udaCode(UDAControl::WELTARG_LIFT), 1'000'016);
BOOST_CHECK_THROW(UDQ::udaCode(static_cast<UDAControl>(1729)),
std::logic_error);
}
BOOST_AUTO_TEST_CASE(IntegrationTest) {
#include "data/integration_tests/udq.data"
auto schedule = make_schedule(deck_string);
{
const auto& udq_active = schedule[1].udq_active.get();
const auto& active = udq_active.iuad();
BOOST_CHECK_EQUAL(active.size(), 6U);
BOOST_CHECK(active[0].control == UDAControl::WCONPROD_ORAT);
BOOST_CHECK(active[1].control == UDAControl::WCONPROD_LRAT);
BOOST_CHECK(active[2].control == UDAControl::WCONPROD_ORAT);
BOOST_CHECK(active[3].control == UDAControl::WCONPROD_LRAT);
BOOST_CHECK(active[4].control == UDAControl::GCONPROD_LIQUID_TARGET);
BOOST_CHECK(active[5].control == UDAControl::GCONPROD_LIQUID_TARGET);
BOOST_CHECK(active[0].udq == "WUOPRL");
BOOST_CHECK(active[1].udq == "WULPRL");
BOOST_CHECK(active[2].udq == "WUOPRU");
BOOST_CHECK(active[3].udq == "WULPRU");
BOOST_CHECK(active[4].udq == "GULPR1");
BOOST_CHECK(active[5].udq == "GUOPR1");
BOOST_CHECK(active[0].input_index == 0);
BOOST_CHECK(active[1].input_index == 1);
BOOST_CHECK(active[2].input_index == 2);
BOOST_CHECK(active[3].input_index == 3);
BOOST_CHECK(active[4].input_index == 4);
BOOST_CHECK(active[5].input_index == 5);
BOOST_CHECK(active[0].use_count == 1);
BOOST_CHECK(active[1].use_count == 1);
BOOST_CHECK(active[2].use_count == 1);
BOOST_CHECK(active[3].use_count == 1);
BOOST_CHECK(active[4].use_count == 2);
BOOST_CHECK(active[5].use_count == 1);
}
}
namespace {
Schedule make_udq_schedule(const std::string& schedule_string)
{
#include "data/integration_tests/udq2.data"
deck_string += schedule_string;
return make_schedule(deck_string);
}
} // Namespace anonymous
BOOST_AUTO_TEST_CASE(IntegrationTest2) {
const std::string udq_string = R"(
UDQ
DEFINE WUOPRL (WOPR PROD1 - 150) * 0.90 /
DEFINE WULPRL (WLPR PROD1 - 200) * 0.90 /
DEFINE WUOPRU (WOPR PROD2 - 250) * 0.80 /
DEFINE WULPRU (WLPR PROD2 - 300) * 0.80 /
DEFINE WUOPRL (WOPR PROD1 - 170) * 0.60 /
DEFINE WUXO (WOPR PROD1 - 170) * 0.60 /
DEFINE WUXL (WOPR PROD1 - 170) * 0.60 /
-- units
UNITS WUOPRL SM3/DAY /
UNITS WULPRL SM3/DAY /
UNITS WUOPRU SM3/DAY /
UNITS WULPRU SM3/DAY /
/
WCONPROD
'PROD1' 'OPEN' 'GRUP' WUOPRU 1* 1* WULPRU 1* 60.0 / single wells
/
WCONPROD
'PROD2' 'OPEN' 'GRUP' WUOPRU 1* 1* WULPRU 1* 60.0 / single wells
/
WCONINJE
'WINJ1' 'WAT' 'OPEN' 'BHP' 1* 1200 3500 1* /
'WINJ2' 'WAT' 'OPEN' 'BHP' 1* 800 3500 1* /
/
TSTEP
5 /
WCONPROD
'PROD2' 'OPEN' 'GRUP' WUXO 1* 1* WUXL 1* 60.0 / single wells
/
TSTEP
5 /
WCONPROD
'PROD1' 'OPEN' 'GRUP' 100 1* 1* 100 1* 60.0 / single wells
/
)";
auto schedule = make_udq_schedule(udq_string);
// First timestep
{
const auto& udq_active = schedule[0].udq_active.get();
BOOST_CHECK(udq_active);
const auto& iuad = udq_active.iuad();
BOOST_CHECK_EQUAL(iuad.size(), 2U);
const auto& record0 = iuad[0];
BOOST_CHECK_EQUAL( record0.uda_code, 300004);
BOOST_CHECK_EQUAL( record0.input_index, 2U);
BOOST_CHECK_EQUAL( record0.use_count, 2U);
BOOST_CHECK_EQUAL( record0.use_index, 0U);
const auto& record1 = iuad[1];
BOOST_CHECK_EQUAL( record1.uda_code, 600004);
BOOST_CHECK_EQUAL( record1.input_index, 3U);
BOOST_CHECK_EQUAL( record1.use_count, 2U);
BOOST_CHECK_EQUAL( record1.use_index, 2U);
}
{
// Second timestep
// - The WUOPRU and WULPRU udq are still used in the same manner for the PROD1 well.
// - The new UDQs WUXO and WUXL are now used for the PROD2 well.
const auto& udq_active = schedule[1].udq_active.get();
BOOST_CHECK(udq_active);
const auto& iuad = udq_active.iuad();
BOOST_CHECK_EQUAL(iuad.size(), 4U);
const auto& record0 = iuad[0];
BOOST_CHECK_EQUAL( record0.uda_code, 300004);
BOOST_CHECK_EQUAL( record0.input_index, 2U);
BOOST_CHECK_EQUAL( record0.use_count, 1U);
BOOST_CHECK_EQUAL( record0.use_index, 0U);
const auto& record1 = iuad[1];
BOOST_CHECK_EQUAL( record1.uda_code, 600004);
BOOST_CHECK_EQUAL( record1.input_index, 3U);
BOOST_CHECK_EQUAL( record1.use_count, 1U);
BOOST_CHECK_EQUAL( record1.use_index, 1U);
const auto& record2 = iuad[2];
BOOST_CHECK_EQUAL( record2.uda_code, 300004);
BOOST_CHECK_EQUAL( record2.input_index, 4U);
BOOST_CHECK_EQUAL( record2.use_count, 1U);
BOOST_CHECK_EQUAL( record2.use_index, 2U);
const auto& record3 = iuad[3];
BOOST_CHECK_EQUAL( record3.uda_code, 600004);
BOOST_CHECK_EQUAL( record3.input_index, 5U);
BOOST_CHECK_EQUAL( record3.use_count, 1U);
BOOST_CHECK_EQUAL( record3.use_index, 3U);
}
{
// Third timestep
// - The new UDQs WUXO and WUXL are now used for the PROD2 well.
// - The PROD1 well does not use UDQ
const auto& udq_active = schedule[2].udq_active.get();
BOOST_CHECK(udq_active);
const auto& iuad = udq_active.iuad();
BOOST_CHECK_EQUAL(iuad.size(), 2U);
const auto& record0 = iuad[0];
BOOST_CHECK_EQUAL( record0.uda_code, 300004);
BOOST_CHECK_EQUAL( record0.input_index, 4U);
BOOST_CHECK_EQUAL( record0.use_count, 1U);
BOOST_CHECK_EQUAL( record0.use_index, 0U);
const auto& record1 = iuad[1];
BOOST_CHECK_EQUAL( record1.uda_code, 600004);
BOOST_CHECK_EQUAL( record1.input_index, 5U);
BOOST_CHECK_EQUAL( record1.use_count, 1U);
BOOST_CHECK_EQUAL( record1.use_index, 1U);
}
{
const auto& udq_config = schedule.getUDQConfig(2);
const auto& def = udq_config.definitions();
const auto& def1 = def[0];
const auto& tokens = def1.func_tokens();
BOOST_CHECK_EQUAL( tokens.count( UDQTokenType::number ), 1U);
BOOST_CHECK_EQUAL( tokens.count( UDQTokenType::ecl_expr), 1U);
BOOST_CHECK_EQUAL( tokens.count( UDQTokenType::binary_op_sub), 1U);
BOOST_CHECK_EQUAL( tokens.count( UDQTokenType::binary_op_mul), 1U);
BOOST_CHECK_THROW( udq_config[1000], std::exception );
BOOST_CHECK(udq_config[0] == udq_config["WUOPRL"]);
BOOST_CHECK(udq_config[2] == udq_config["WUOPRU"]);
}
}
BOOST_AUTO_TEST_CASE(UDQ_SCIENTIFIC_LITERAL) {
std::string deck_string = R"(
SCHEDULE
UDQ
DEFINE FU 0 -1.25E-2*(1.0E-1 + 2E-1) /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
UDQParams udqp;
auto def0 = udq.definitions()[0];
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQFunctionTable udqft(udqp);
UDQState udq_state(udqp.undefinedValue());
UDQContext context(udqft, {}, {}, UDQContext::MatcherFactories{}, st, udq_state);
auto res0 = def0.eval(context);
BOOST_CHECK_CLOSE( res0[0].get(), -0.00125*3, 1e-6);
}
BOOST_AUTO_TEST_CASE(UDQ_NEGATIVE_PREFIX_BASIC) {
std::string deck_string = R"(
SCHEDULE
UDQ
DEFINE FUMIN0 - 1.5*FWPR /
DEFINE FUMIN1 - 1.5*FWPR*(FGPR + FOPR)^3 - 2*FLPR /
DEFINE FU -2.539E-14 * (FXP1+FXP2)^3 + 1.4464E-8 *(FXP1+FXP2)^2 +0.00028875*(FXP1+FXP2)+2.8541 /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
UDQParams udqp;
auto def0 = udq.definitions()[0];
auto def1 = udq.definitions()[1];
auto def2 = udq.definitions()[2];
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQFunctionTable udqft(udqp);
UDQState udq_state(udqp.undefinedValue());
UDQContext context(udqft, {}, {}, UDQContext::MatcherFactories{}, st, udq_state);
const double fwpr = 7;
const double fopr = 4;
const double fgpr = 7;
const double flpr = 13;
const double fxp1 = 1025;
const double fxp2 = 107;
st.update("FWPR", fwpr);
st.update("FOPR", fopr);
st.update("FGPR", fgpr);
st.update("FLPR", flpr);
st.update("FXP1", fxp1);
st.update("FXP2", fxp2);
auto res0 = def0.eval(context);
BOOST_CHECK_EQUAL( res0[0].get(), -1.5*fwpr);
auto res1 = def1.eval(context);
BOOST_CHECK_EQUAL( res1[0].get(), -1.5*fwpr*std::pow(fgpr+fopr, 3) - 2*flpr );
auto res2 = def2.eval(context);
auto right = -2.5394E-14 * std::pow(fxp1 + fxp2, 3) + 1.4464E-8*std::pow(fxp1 + fxp2, 2) + 0.00028875*(fxp1 + fxp2) + 2.8541;
BOOST_CHECK_CLOSE( res2[0].get(), right, 1e-6);
}
BOOST_AUTO_TEST_CASE(UDQ_STARSTAR) {
std::string deck_string = R"(
SCHEDULE
UDQ
DEFINE WUOPR2 WOPR '*' * WOPR '*' /
DEFINE WUGASRA 3 - WGLIR '*' /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
UDQParams udqp;
auto def0 = udq.definitions()[0];
auto def1 = udq.definitions()[1];
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQFunctionTable udqft(udqp);
UDQState udq_state(udqp.undefinedValue());
WellMatcher wm(NameOrder({"W1", "W2", "W3"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("W1", "WOPR", 1);
st.update_well_var("W2", "WOPR", 2);
st.update_well_var("W3", "WOPR", 3);
st.update_well_var("W1", "WGLIR", 1);
st.update_well_var("W2", "WGLIR", 2);
st.update_well_var("W3", "WGLIR", 3);
auto res0 = def0.eval(context);
BOOST_CHECK_EQUAL( res0["W1"].get(), 1);
BOOST_CHECK_EQUAL( res0["W2"].get(), 4);
BOOST_CHECK_EQUAL( res0["W3"].get(), 9);
auto res1 = def1.eval(context);
BOOST_CHECK_EQUAL( res1["W1"].get(), 2);
BOOST_CHECK_EQUAL( res1["W2"].get(), 1);
BOOST_CHECK_EQUAL( res1["W3"].get(), 0);
}
BOOST_AUTO_TEST_CASE(UDQ_UADD_PARSER) {
std::string deck_string = R"(
SCHEDULE
UDQ
ASSIGN FU_PAR1 10.0 /
ASSIGN FU_PAR2 2.0 /
ASSIGN FU_PAR3 3.0 /
DEFINE FU_UADD FU_PAR1 UADD FU_PAR2 /
DEFINE FU_UMUL FU_PAR1 UMUL FU_PAR2 + FU_PAR3 /
DEFINE FU_UMIN FU_PAR1 UMIN FU_PAR2 + FU_PAR3 /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
const auto undefined_value = udq.params().undefinedValue();
SummaryState st(TimeService::now(), undefined_value);
UDQState udq_state(undefined_value);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, {}, segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
BOOST_CHECK_EQUAL( st.get("FU_UADD"), 12); // 10 + 2
// The Uxxx binary set functions have absolutely lowest priority; i.e. the
// FU_PAR2 + FU_PAR3 expression is evaluated *before* the UMUL and UMIN operations.
BOOST_CHECK_EQUAL( st.get("FU_UMUL"), 50); // 10 * (2 + 3)
BOOST_CHECK_EQUAL( st.get("FU_UMIN"), 5); // min(10, 2+3)
}
BOOST_AUTO_TEST_CASE(UDQ_DEFINE_ORDER) {
std::string deck_string = R"(
SCHEDULE
UDQ
ASSIGN FU_PAR1 1.0 /
DEFINE FU_PAR3 FMWPR /
ASSIGN FU_PAR2 0.0 /
DEFINE FU_PAR2 FU_PAR3 /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
const auto undefined_value = udq.params().undefinedValue();
SummaryState st(TimeService::now(), undefined_value);
UDQState udq_state(undefined_value);
st.update("FMWPR", 100);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, {}, segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
BOOST_CHECK_EQUAL(st.get("FU_PAR2"), 100);
}
BOOST_AUTO_TEST_CASE(UDQ_UNDEFINED2) {
std::string deck_string = R"(
SCHEDULE
UDQ
DEFINE FU_PAR2 FU_PAR1 + 1/
DEFINE FU_PAR3 FU_PAR2 + 1/
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
const auto undefined_value = udq.params().undefinedValue();
SummaryState st(TimeService::now(), undefined_value);
UDQState udq_state(undefined_value);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, {}, segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
BOOST_CHECK_EQUAL(st.get("FU_PAR2"), undefined_value);
BOOST_CHECK_EQUAL(st.get("FU_PAR3"), undefined_value);
}
BOOST_AUTO_TEST_CASE(UDQSTATE) {
double undefined_value = 1234;
UDQState st(undefined_value);
BOOST_CHECK(!st.has("FUXX"));
BOOST_CHECK(!st.has_well_var("OP1", "WUXX"));
BOOST_CHECK(!st.has_group_var("G1", "GUXX"));
// Try to get from symbol which is not UDQ -> logic_error
BOOST_CHECK_THROW(st.get("FOPR"), std::logic_error);
// Try to get from a UDQ which has not registered -> out_of_range
BOOST_CHECK_THROW(st.get("FUPR"), std::out_of_range);
auto fxpr = UDQSet::scalar("FXPR", 100);
BOOST_CHECK_THROW(st.add_define(0, "FXPR", fxpr), std::logic_error);
BOOST_CHECK_THROW(st.get_well_var("OP1", "WUPR"), std::out_of_range);
auto fupr = UDQSet::scalar("FUPR", 100);
st.add_define(0, "FUPR", fupr);
// This is not a well quantity
BOOST_CHECK_THROW(st.get_well_var("OP1", "FUPR"), std::logic_error);
BOOST_CHECK_EQUAL(100, st.get("FUPR"));
auto wupr = UDQSet::wells("WUPR", {"P1", "P2"});
wupr.assign("P1", 75);
st.add_define(0, "WUPR", wupr);
BOOST_CHECK(st.has_well_var("P1", "WUPR"));
// We have a well P2 - but we have not assigned a value to it!
BOOST_CHECK(!st.has_well_var("P2", "WUPR"));
BOOST_CHECK_EQUAL(st.get_well_var("P1", "WUPR"), 75);
BOOST_CHECK_EQUAL(st.get_well_var("P2", "WUPR"), undefined_value);
}
BOOST_AUTO_TEST_CASE(UDQ_UADD_PARSER2) {
std::string deck_string = R"(
SCHEDULE
UDQ
ASSIGN FU_PAR1 1.0 / -- xxxxxxxxxxxxxxxxxxxxxx
ASSIGN FU_PAR2 0.0 /
ASSIGN FU_PAR3 0.0 /
ASSIGN FU_PAR4 0.0 /
ASSIGN FU_PAR5 0.0 /
-- xxxxx xxxx
DEFINE FU_PAR6 FMWPR /
-- xxxxxxxxxxxxxxxxxxxx
DEFINE FU_PAR7 FMWIN /
DEFINE FU_PAR8 FMWPA /
DEFINE FU_PAR9 FMWIA /
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DEFINE FU_PAR10 (FU_PAR6 - FU_PAR2) + (FU_PAR8 - FU_PAR4) /
DEFINE FU_PAR11 (FU_PAR7 - FU_PAR3) + (FU_PAR9 - FU_PAR5) /
DEFINE FU_PAR12 FU_PAR10 > 0 /
DEFINE FU_PAR13 FU_PAR11 > 0 /
DEFINE FU_PAR14 FU_PAR12 * FU_PAR10 /
DEFINE FU_PAR15 FU_PAR13 * FU_PAR11 /
DEFINE FU_PAR2 FU_PAR6 /
DEFINE FU_PAR3 FU_PAR7 /
DEFINE FU_PAR4 FU_PAR8 /
DEFINE FU_PAR5 FU_PAR9 /
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ASSIGN FU_PAR16 0.08 /
ASSIGN FU_PAR17 100.0 /
ASSIGN FU_PAR18 6.0 /
ASSIGN FU_PAR19 0.0 /
-- xxxxxxxxxxxxx
DEFINE FU_PAR19 FU_PAR19 + TIMESTEP /
ASSIGN FU_PAR20 800.0 /
ASSIGN FU_PAR21 0.0 /
-- xxxxxxxxxxxxxxxxx
DEFINE FU_PAR21 FU_PAR21 UADD FU_PAR20 * (FU_PAR14 + FU_PAR15) / ((1.0 + 0.08 ) ^ (FU_PAR19 /365)) /
-- xxxxxxxxxxxxxxxxxxxx
ASSIGN FU_PAR22 0.0 /
DEFINE FU_PAR22 FU_PAR22 + FOPR * TIMESTEP * 1E-06 * 6.29 * FU_PAR17 * FU_PAR18 / ((1.0 + 0.08 ) ^ (FU_PAR19 /365)) /
DEFINE FU_PAR23 FU_PAR22 - FU_PAR21 /
-- xxxxxxxxxxxxxxxxxxxxxxxx
ASSIGN FU_PAR24 0.9 /
DEFINE FU_PAR24 FU_PAR24 UADD (FU_PAR14 + FU_PAR15) /
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxx
DEFINE WUGASRA 750000 - WGLIR '*' /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
const auto undefined_value = udq.params().undefinedValue();
UDQState udq_state(undefined_value);
SummaryState st(TimeService::now(), undefined_value);
st.update("TIMESTEP", 100);
st.update("FMWPR", 100);
st.update("FMWIN", 100);
st.update("FMWPA", 100);
st.update("FMWIA", 100);
st.update("FOPR", 100);
st.update_well_var("W1", "WGLIR", 1);
st.update_well_var("W2", "WGLIR", 2);
st.update_well_var("W3", "WGLIR", 3);
NameOrder wo({"W1", "W2", "W3"});
WellMatcher wm(wo);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, wm, segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
const auto required_keys = [&udq]()
{
auto keys = std::unordered_set<std::string>{};
udq.required_summary(keys);
auto required = std::vector<std::string>{ keys.begin(), keys.end() };
std::sort(required.begin(), required.end());
return required;
}();
const auto expected_keys = std::vector<std::string> {
"FMWIA",
"FMWIN",
"FMWPA",
"FMWPR",
"FOPR",
"TIMESTEP",
"WGLIR",
};
BOOST_CHECK_EQUAL_COLLECTIONS(required_keys.begin(), required_keys.end(),
expected_keys.begin(), expected_keys.end());
}
BOOST_AUTO_TEST_CASE(UDQ_UNDEFINED) {
std::string deck_string = R"(
SCHEDULE
-- udq #2
UDQ
----XX xxxx xxx
--xxxx xxxx xxxx xxxx
ASSIGN FU_VAR1 0 /
DEFINE FU_VAR1 -2.539E-14 * (FU_VAR91+FU_VAR90)^3 + 1.4464E-8 *(FU_VAR91+FU_VAR90)^2 +0.00028875*(FU_VAR91+FU_VAR90)+2.8541 /
--xxxx xx xxxx xxx xxxx xxxx
ASSIGN FU_VAR2 0 /
DEFINE FU_VAR3 FU_VAR1 > 10 /
DEFINE FU_VAR2 NINT(FU_VAR91 / 35000 + 0.499) * FU_VAR3 /
--xxxx xxx XX xxx xxxx xxxx
ASSIGN FU_VAR4 0 /
--Xxxx xxx XX xxx xxxx, xxxx
ASSIGN FU_VAR5 0 /
DEFINE FU_VAR6 FU_VAR2 != 0 /
DEFINE FU_VAR7 FU_VAR6 * FU_VAR2 - 999 * (1 - FU_VAR6) / --Avoiding div by 0
DEFINE FU_VAR5 FU_VAR6 * FU_VAR91 / FU_VAR7 / 24 / 0.95 /
--Xxx xxx XX xxx xxx, xxxxx
DEFINE FU_VAR8 FU_VAR4 != 0 /
ASSIGN FU_VAR9 0 /
--XX Xxx xxxxx xxxxx xxxxx
ASSIGN FU_VAR10 0 /
DEFINE FU_VAR10 -0.00000041232 * FU_VAR5 ^ 2 + 0.0010395 * FU_VAR5 + 0.16504 /
--XX xxx xxxxx xxxxx xxxxx
ASSIGN FU_VAR11 0 /
--xxxxx xxxxx xxxxx xxxxx, xX
ASSIGN FU_VAR12 0 /
ASSIGN FU_VAR13 0 /
ASSIGN FU_VAR14 0 /
DEFINE FU_VAR12 FU_VAR2 * FU_VAR5 * 1E5 * ((FU_VAR1 - 10) / 3600) / 1000 / FU_VAR10 / 0.8938 /
DEFINE FU_VAR14 FU_VAR12 + FU_VAR13 /
-----Xxxxx xxxxx xxxxx
--xxxxx xx XX xxxxx xxxxx xxxxx
ASSIGN FU_VAR15 0 /
DEFINE FU_VAR15 NINT((FU_P1SWI + FU_P1WPR) / 30000 + 0.499) /
--xxxxx xx XX xxxxx xxxxx xxxxx
ASSIGN FU_VAR16 0 /
--xxxx xx XX XZ, xx/x
ASSIGN FU_VAR17 0 /
DEFINE FU_VAR18 FU_VAR15 != 0 /
DEFINE FU_VAR17 FU_P1WPB * (FU_P1WPR + FU_P1SWI) / (FU_VAR15 + 0.0001) / 24 / 0.95 /
--xxxx xxx xxxx xxxx xxxx, xxxx
DEFINE FU_VAR19 FU_VAR16 != 0 /
ASSIGN FU_VAR20 0 /
--xxxx xxxx xxxx xxxx
ASSIGN FU_VAR21 0 /
DEFINE FU_VAR21 -0.00000035417*FU_VAR17^2 +0.0010673*FU_VAR17 + 0.029286 /
--XX xxxx xxxx xxxx
ASSIGN FU_VAR22 0 /
--XX XX xxxx xxxx, xX
ASSIGN FU_VAR23 0 /
DEFINE FU_VAR23 FU_VAR15 * FU_VAR17 * 1E5 * ((150-10)/3600) / 1000 / FU_VAR21 / 0.8938 /
--xx XX xx xx, xX
ASSIGN FU_VAR24 0 /
--xxxx xxxx xxxx xxxx, xxxx
DEFINE FU_VAR25 FU_VAR23 + FU_VAR24 /
-----xxxx xxxx
--xxxx xxxx xxxx, X xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
ASSIGN FU_VAR26 0 /
--xxxx xxxx xxxx xxxx
ASSIGN FU_VAR27 0 /
DEFINE FU_VAR27 ((FU_P1TGP/1E6*4546.667)/0.9215+1474) * (1-FU_VAR26) + ((FU_P1TGP/1E6*4911)/0.9215+1474) * FU_VAR26 /
--xxxx xxxx xxxx xxxx
ASSIGN FU_VAR28 0 /
--xxxx xxxx xxxx
ASSIGN FU_VAR29 0 /
DEFINE FU_VAR29 FU_VAR27 + FU_VAR28 /
-----xxxx xxxx
ASSIGN FU_VAR30 6682 /
ASSIGN FU_VAR31 0 /
ASSIGN FU_VAR32 4155 / --xxxx xx xxxx xxxx XX xxxx
ASSIGN FU_VAR33 9685 /
ASSIGN FU_VAR34 4000 /
ASSIGN FU_VAR35 1230 / --xxxx xx xxxx xxxx XX xxxx
--Total base load
ASSIGN FU_VAR36 0 /
DEFINE FU_VAR36 FU_P1BL + FU_P2BL + FU_VAR32 + FU_VAR33 + FU_VAR34 + FU_VAR35 /
-----XX xxxx xxxx
ASSIGN FU_VAR37 2300 /
ASSIGN FU_VAR38 0 / -- xxxxxx xx xxxx xxxx XX xxxx
ASSIGN FU_VAR39 2300 / -- xxxx * Y xxxx xx Z xxxx XX xxxx
-- xxxx xxxx xxxx xxxx
ASSIGN FU_VAR40 0 /
DEFINE FU_VAR40 FU_VAR37 + FU_VAR38 + FU_VAR39 /
-----xxxx xxxx xxxx xxxx
--xxxx xxxx
ASSIGN FU_VAR41 0 /
DEFINE FU_VAR41 0.005 * FU_VAR90 /
DEFINE FU_VAR42 FU_P2WPR < FU_VAR41 /
ASSIGN FU_VAR43 0 /
--xxxx xxxx
ASSIGN FU_VAR44 0 /
--xxxx xxxx xxxx
ASSIGN FU_VAR45 0 /
DEFINE FU_VAR45 FU_VAR43 + FU_VAR44 /
-----xxxx xxxx xxxx
ASSIGN FU_VAR46 0 /
DEFINE FU_VAR47 FU_P1SWI > 10 /
DEFINE FU_VAR46 NINT(FU_P1SWI / 36000 + 0.499) * 761 / 0.9025 * FU_VAR47 /
ASSIGN FU_VAR48 0 /
DEFINE FU_VAR49 FU_P1WPR > 10 /
DEFINE FU_VAR48 NINT(FU_P1WPR / 30576 + 0.499) * 864 / 0.9025 * FU_VAR49 /
DEFINE FU_VAR50 FU_P2SWI > 10 /
ASSIGN FU_VAR51 0 /
DEFINE FU_VAR52 FU_P2WPR > 10 /
ASSIGN FU_VAR53 0 /
--xxxx xxxx xxxx
ASSIGN FU_VAR54 0 /
DEFINE FU_VAR54 FU_VAR46 + FU_VAR48 + FU_VAR51 + FU_VAR53 /
-----xxxx xxxx loadxxxxs
--xxxx xxxx xxxx xxxx xxxx, xxxxxxxx
ASSIGN FU_VAR55 0 /
DEFINE FU_VAR55 FU_VAR91 * 30.6571 / 1000 / 0.8754 /
--xxxx xxxx xxxx xxxx xxxx, xxxx
ASSIGN FU_VAR56 0 /
--xxxx
ASSIGN FU_VAR57 0 /
DEFINE FU_VAR57 FU_VAR91 * 61.4286 / 1000 / 0.9215 + 280 /
--xxxx
ASSIGN FU_VAR58 0 /
--xxxx
ASSIGN FU_VAR59 0 /
DEFINE FU_VAR59 FU_P1TGP * 120 / 1E6 /
--xxxx xxxx xxxx xxxx, xxxx
ASSIGN FU_VAR60 0 /
DEFINE FU_VAR60 (FU_VAR91 + FU_VAR90) * 5.52 / 1000 /
--xxxx xxxx xxxx xxxx, xxxx
ASSIGN FU_VAR61 0 /
DEFINE FU_VAR61 FU_VAR60 + FU_VAR59 + FU_VAR58 + FU_VAR57 + FU_VAR56 + FU_VAR55 /
-----xxxx-xxxx, xxxx
ASSIGN FU_VAR62 0 /
DEFINE FU_VAR62 (FU_VAR61 + FU_VAR54 + FU_VAR45 + FU_VAR40 + FU_VAR36 + FU_VAR29 + FU_VAR25 + FU_VAR14)/1000 /
--xxxx xxxx, xxxx
ASSIGN FU_VAR63 0 / -- xxxx xxxx xxxx xxxx xxxx xxxx xxxx
--Allowance, MW
ASSIGN FU_VAR64 5 / --xxxx xxxx xxxx MxxxxW xxxx xxxx XX xxxx
--xxxx
ASSIGN FU_VAR65 0 /
DEFINE FU_VAR65 0.02 * FU_VAR62 /
-----xxxx xxxx xxxx xxxx, xxxx
ASSIGN FU_VAR66 0 /
DEFINE FU_VAR66 FU_VAR65 + FU_VAR64 + FU_VAR63 + FU_VAR62 /
---- xxxx xxxx xxxx
DEFINE FU_VAR67 0 /
DEFINE FU_VAR67 FU_VAR66 * 0.79 /
---- xxxx xxxx xxxx xxxx
DEFINE FU_VAR68 0 /
DEFINE FU_VAR68 FU_VAR67 * 1.08 /
/
-- udq #6
UDQ
ASSIGN FU_VAR90 0.0 /
DEFINE FU_VAR91 GOPR TEST /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
const auto undefined_value = udq.params().undefinedValue();
UDQState udq_state(undefined_value);
SummaryState st(TimeService::now(), undefined_value);
st.update("FMWPR", 100);
st.update("FMWIN", 100);
st.update("FMWPA", 100);
st.update("FMWIA", 100);
st.update("FOPR", 100);
st.update("TIMESTEP", 100);
st.update_well_var("W1", "WGLIR", 1);
st.update_well_var("W2", "WGLIR", 2);
st.update_well_var("W3", "WGLIR", 3);
st.update_group_var("TEST", "GOPR", 1);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, {}, segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
}
BOOST_AUTO_TEST_CASE(UDQ_KEY_ERROR) {
std::string deck_string = R"(
-- udq #2
SCHEDULE
UDQ
DEFINE FU_VAR1 FOPR * 5 /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
const auto undefined_value = udq.params().undefinedValue();
UDQState udq_state(undefined_value);
SummaryState st(TimeService::now(), undefined_value);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
BOOST_CHECK_THROW(udq.eval(0, schedule, {}, segmentMatcherFactory, regionSetMatcherFactory, st, udq_state), std::exception);
}
BOOST_AUTO_TEST_CASE(UDQ_ASSIGN) {
std::string deck_string = R"(
-- udq #2
SCHEDULE
UDQ
ASSIGN FU_VAR1 5 /
DEFINE FU_VAR1 FU_VAR1 + 5 /
/
)";
auto schedule = make_schedule(deck_string);
const auto& udq = schedule.getUDQConfig(0);
const auto undefined_value = udq.params().undefinedValue();
UDQState udq_state(undefined_value);
SummaryState st(TimeService::now(), undefined_value);
const auto required_keys = [&udq]()
{
auto keys = std::unordered_set<std::string>{};
udq.required_summary(keys);
auto required = std::vector<std::string>{ keys.begin(), keys.end() };
std::sort(required.begin(), required.end());
return required;
}();
const auto expected_keys = std::vector<std::string> {};
BOOST_CHECK_EQUAL_COLLECTIONS(required_keys.begin(), required_keys.end(),
expected_keys.begin(), expected_keys.end());
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, {}, segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
BOOST_CHECK_EQUAL(st.get("FU_VAR1"), 10);
}
BOOST_AUTO_TEST_CASE(UDQ_ASSIGN_REASSIGN) {
std::string deck_string = R"(
-- udq #2
SCHEDULE
UDQ
ASSIGN FU_VAR1 0 /
DEFINE FU_VAR1 FU_VAR1 + 1 /
/
TSTEP
1 1 1 1 1 /
UDQ
ASSIGN FU_VAR1 0 /
DEFINE FU_VAR1 FU_VAR1 + 1 /
/
TSTEP
1 1 1 1 1 /
UDQ
ASSIGN FU_VAR1 0 /
/
TSTEP
1 1 1 1 1 /
)";
auto schedule = make_schedule(deck_string);
UDQState udq_state(0);
SummaryState st(TimeService::now(), schedule.back().udq().params().undefinedValue());
// Counting: 1,2,3,4,5
for (std::size_t report_step = 0; report_step < 5; report_step++) {
const auto& udq = schedule.getUDQConfig(report_step);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(report_step, schedule, schedule.wellMatcher(report_step), segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
auto fu_var1 = st.get("FU_VAR1");
BOOST_CHECK_EQUAL(fu_var1, report_step + 1);
}
// Reset to zero and count: 1,2,3,4,5
for (std::size_t report_step = 5; report_step < 10; report_step++) {
const auto& udq = schedule.getUDQConfig(report_step);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(report_step, schedule, schedule.wellMatcher(report_step), segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
auto fu_var1 = st.get("FU_VAR1");
BOOST_CHECK_EQUAL(fu_var1, report_step - 4);
}
// Reset to zero and stay there.
for (std::size_t report_step = 10; report_step < 15; report_step++) {
const auto& udq = schedule.getUDQConfig(report_step);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(report_step, schedule, schedule.wellMatcher(report_step), segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
auto fu_var1 = st.get("FU_VAR1");
BOOST_CHECK_EQUAL(fu_var1, 0);
}
const auto& unique = schedule.unique<UDQConfig>();
BOOST_CHECK_EQUAL( unique.size(), 3 );
BOOST_CHECK_EQUAL( unique[0].first, 0 );
BOOST_CHECK_EQUAL( unique[1].first, 5 );
BOOST_CHECK_EQUAL( unique[2].first, 10 );
BOOST_CHECK( unique[0].second == schedule.getUDQConfig(0));
BOOST_CHECK( unique[1].second == schedule.getUDQConfig(5));
BOOST_CHECK( unique[2].second == schedule.getUDQConfig(10));
}
BOOST_AUTO_TEST_CASE(UDQ_DIV_TEST) {
KeywordLocation location;
UDQFunctionTable udqft;
UDQParams udqp;
UDQDefine def_div(udqp, "FU",0, location, {"128", "/", "2", "/", "4", "/", "8"});
SummaryState st(TimeService::now(), udqp.undefinedValue());
UDQState udq_state(udqp.undefinedValue());
UDQContext context(udqft, {}, {}, UDQContext::MatcherFactories{}, st, udq_state);
auto res_div = def_div.eval(context);
BOOST_CHECK_EQUAL( res_div[0].get() , 2.0);
}
BOOST_AUTO_TEST_CASE(UDQ_LEADING_SIGN) {
std::string deck_string = R"(
SCHEDULE
UDQ
DEFINE FU_VAR1 - 100 + 215 /
DEFINE FU_VAR2 (-100 + 200) / 10 /
DEFINE FU_VAR3 -(100 + 200) * -10 /
DEFINE FU_VAR4 2^-1 /
ASSIGN FU_VAR6 2 /
ASSIGN FU_VAR7 3 /
DEFINE FU_VAR5 (-0.00000041232 * (FU_VAR6 ^ 2)) + (0.0010395 * FU_VAR7) + 0.16504 /
/
)";
auto schedule = make_schedule(deck_string);
UDQState udq_state(0);
SummaryState st(TimeService::now(), schedule.back().udq().params().undefinedValue());
const auto& udq = schedule.getUDQConfig(0);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, {}, segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
auto fu_var1 = st.get("FU_VAR1");
auto fu_var2 = st.get("FU_VAR2");
auto fu_var3 = st.get("FU_VAR3");
auto fu_var4 = st.get("FU_VAR4");
auto fu_var5 = st.get("FU_VAR5");
BOOST_CHECK_EQUAL(fu_var1, 115);
BOOST_CHECK_EQUAL(fu_var2, 10);
BOOST_CHECK_EQUAL(fu_var3, 3000);
BOOST_CHECK_EQUAL(fu_var4, 0.5);
BOOST_CHECK_CLOSE(fu_var5, -0.00000041232 * 4 + 0.0010395 * 3 + 0.16504, 1e-5);
}
BOOST_AUTO_TEST_CASE(UDQ_WLIST) {
std::string deck_string = R"(
SCHEDULE
WELSPECS
'P1' 'OP' 20 51 3.92 'OIL' 3* NO /
'P2' 'OP' 20 51 3.92 'OIL' 3* NO /
'P3' 'OP' 20 51 3.92 'OIL' 3* NO /
'P4' 'OP' 20 51 3.92 'OIL' 3* NO /
/
WLIST
'*ILIST' 'NEW' P1 P2 P3 /
/
UDQ
DEFINE FU_VAR1 SUM(WOPR '*ILIST') /
DEFINE FU_VAR2 SUM(WOPR '*') /
DEFINE FU_VAR3 WOPR 'P4' /
/
)";
auto schedule = make_schedule(deck_string);
UDQState udq_state(0);
SummaryState st(TimeService::now(), schedule.back().udq().params().undefinedValue());
const auto& udq = schedule.getUDQConfig(0);
st.update_well_var("P1", "WOPR", 1);
st.update_well_var("P2", "WOPR", 2);
st.update_well_var("P3", "WOPR", 3);
st.update_well_var("P4", "WOPR", 4);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, schedule.wellMatcher(0), segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
auto fu_var1 = st.get("FU_VAR1");
auto fu_var2 = st.get("FU_VAR2");
auto fu_var3 = st.get("FU_VAR3");
BOOST_CHECK_EQUAL(fu_var1, 6);
BOOST_CHECK_EQUAL(fu_var2, 10);
BOOST_CHECK_EQUAL(fu_var3, 4);
}
BOOST_AUTO_TEST_CASE(UDQ_MINUS_PAREN) {
std::string deck_string = R"(
SCHEDULE
UDQ
DEFINE FU_VAR1 -( -10 + 15) * 10 /
DEFINE FU_VAR2 -( -(10) + 15) * 10 /
DEFINE FU_VAR3 -(-10 + 15)*-10 /
DEFINE FU_VAR4 -(-(10) + 15)*-10 /
/
)";
auto schedule = make_schedule(deck_string);
UDQState udq_state(0);
SummaryState st(TimeService::now(), schedule.back().udq().params().undefinedValue());
const auto& udq = schedule.getUDQConfig(0);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, schedule.wellMatcher(0), segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
auto fu_var1 = st.get("FU_VAR1");
auto fu_var2 = st.get("FU_VAR2");
auto fu_var3 = st.get("FU_VAR3");
auto fu_var4 = st.get("FU_VAR4");
BOOST_CHECK_EQUAL(fu_var1, -50);
BOOST_CHECK_EQUAL(fu_var2, -50);
BOOST_CHECK_EQUAL(fu_var3, 50);
BOOST_CHECK_EQUAL(fu_var4, 50);
}
BOOST_AUTO_TEST_CASE(UDQ_UPDATE) {
std::string invalid1 = R"(
SCHEDULE
UDQ
UPDATE FU_XXX /
/
)";
std::string valid = R"(
SCHEDULE
UDQ
DEFINE FU_TIME TIME /
/
TSTEP
1 /
UDQ
UPDATE FU_TIME OFF /
/
TSTEP
1 /
TSTEP
1 /
UDQ
UPDATE FU_TIME NEXT /
/
TSTEP
1 /
TSTEP
1 /
UDQ
UPDATE FU_TIME OFF /
/
TSTEP
1 /
)";
BOOST_CHECK_THROW(make_schedule(invalid1), std::exception);
auto schedule = make_schedule(valid);
UDQState udq_state(0);
SummaryState st(TimeService::now(), schedule.back().udq().params().undefinedValue());
UDQSet result = UDQSet::scalar("RES", 0);
{
const auto& udq = schedule.getUDQConfig(0);
const auto& def = udq.define("FU_TIME");
BOOST_CHECK( udq_state.define(def.keyword(), def.status()));
udq_state.add_define(0, def.keyword(), result);
}
{
const auto& udq = schedule.getUDQConfig(1);
const auto& def = udq.define("FU_TIME");
BOOST_CHECK( !udq_state.define(def.keyword(), def.status()));
}
{
const auto& udq = schedule.getUDQConfig(2);
const auto& def = udq.define("FU_TIME");
BOOST_CHECK( !udq_state.define(def.keyword(), def.status()));
}
{
const auto& udq = schedule.getUDQConfig(3);
const auto& def = udq.define("FU_TIME");
BOOST_CHECK( udq_state.define(def.keyword(), def.status()));
udq_state.add_define(3, def.keyword(), result);
}
{
const auto& udq = schedule.getUDQConfig(4);
const auto& def = udq.define("FU_TIME");
BOOST_CHECK( !udq_state.define(def.keyword(), def.status()));
}
{
const auto& udq = schedule.getUDQConfig(5);
const auto& def = udq.define("FU_TIME");
BOOST_CHECK( !udq_state.define(def.keyword(), def.status()));
}
}
BOOST_AUTO_TEST_CASE(UDQ_TYPE_CAST) {
std::string valid = R"(
SCHEDULE
UDQ
ASSIGN FUBHPP1 100 /
/
TSTEP
10 /
UDQ
DEFINE FU_TIME TIME /
DEFINE WUDELTA WBHP '*' - FUBHPP1 /
DEFINE WU_TEST WUBHPINI '*' - (WGPR '*')/2000.0 /
/
)";
auto schedule = make_schedule(valid);
UDQState udq_state(0);
SummaryState st(TimeService::now(), schedule.back().udq().params().undefinedValue());
UDQFunctionTable udqft;
WellMatcher wm(NameOrder({"W1", "W2", "W3"}));
UDQContext context(udqft, wm, {}, UDQContext::MatcherFactories{}, st, udq_state);
st.update_well_var("W1", "WBHP", 400);
st.update_well_var("W2", "WBHP", 300);
st.update_well_var("W3", "WBHP", 200);
const auto& udq = schedule.getUDQConfig(1);
{
const auto& ass = udq.assign("FUBHPP1");
context.update_assign("FUBHPP1", ass.eval());
}
const auto& def = udq.define("WUDELTA");
auto res = def.eval(context);
BOOST_CHECK_EQUAL(res["W1"].get(), 300);
BOOST_CHECK_EQUAL(res["W2"].get(), 200);
BOOST_CHECK_EQUAL(res["W3"].get(), 100);
}
BOOST_AUTO_TEST_CASE(UDQ_TRAILING_COMMENT) {
std::string valid = R"(
SCHEDULE
UDQ
ASSIGN FUBHPP1 100 /
/ Comment here
)";
BOOST_CHECK_NO_THROW( make_schedule(valid) );
}
BOOST_AUTO_TEST_CASE(UDQ_ASSIGN_RST) {
std::unordered_set<std::string> selector{"W1", "W2"};
UDQAssign assign("WUBHP", selector, 100, 2);
auto res = assign.eval( {"W1", "W2", "W3"});
BOOST_CHECK_EQUAL(res.size(), 3);
BOOST_CHECK_EQUAL(res["W1"].get(), 100);
BOOST_CHECK_EQUAL(res["W2"].get(), 100);
BOOST_CHECK_EQUAL(res["W3"].defined(), false);
}
BOOST_AUTO_TEST_CASE(UDQ_ASSIGN_SEGMENT)
{
auto segmentMatcherFactory = [sched_state = dynamicInputData()]()
{
return std::make_unique<SegmentMatcher>(sched_state);
};
auto cfg = UDQConfig{};
cfg.add_assign("SUSPECT" , segmentMatcherFactory, {"OP-01"}, 17.29, 42);
cfg.add_assign("SUSPECT" , segmentMatcherFactory, {"OP-02", "3"}, 9.876e-5, 42);
cfg.add_assign("SUSPECT" , segmentMatcherFactory, {"OP-06", "1"}, 0.123, 42); // Not an MSW
cfg.add_assign("SUPER" , segmentMatcherFactory, {}, 2.71828, 42);
cfg.add_assign("SUCCINCT", segmentMatcherFactory, {"OP*", "2"}, 3.1415, 42);
{
const auto all = cfg.assignments();
BOOST_CHECK_EQUAL(all.size(), std::size_t{3}); // Three different SU* variables
}
}
BOOST_AUTO_TEST_CASE(UDQ_Update_SummaryState)
{
const double udq_undefined = 987.6;
auto st = SummaryState { TimeService::now(), udq_undefined };
// P2 not yet online
st.update_well_var("P1", "WBHP", 42.0);
st.update_well_var("P2", "WBHP", 0.0);
st.update_well_var("P3", "WBHP", 121.2);
// BB not yet online
st.update_group_var("G1", "GOPR", 1222.0);
st.update_group_var("BB", "GOPR", 0.0);
st.update_group_var("AA", "GOPR", 1234.5);
// P2 not yet online
st.update_udq(UDQSet::wells("WUBAR", { "P1", "P3" }, 17.29));
BOOST_CHECK_CLOSE(st.get_well_var("P1", "WUBAR"), 17.29, 1.0e-8);
BOOST_CHECK_CLOSE(st.get_well_var("P2", "WUBAR"), udq_undefined, 1.0e-8);
BOOST_CHECK_CLOSE(st.get_well_var("P3", "WUBAR"), 17.29, 1.0e-8);
// BB not yet online
st.update_udq(UDQSet::groups("GUNDA_ST", { "G1", "AA" }, 652.44));
BOOST_CHECK_CLOSE(st.get_group_var("AA", "GUNDA_ST"), 652.44, 1.0e-8);
BOOST_CHECK_CLOSE(st.get_group_var("BB", "GUNDA_ST"), udq_undefined, 1.0e-8);
BOOST_CHECK_CLOSE(st.get_group_var("G1", "GUNDA_ST"), 652.44, 1.0e-8);
}
BOOST_AUTO_TEST_CASE(UDQ_WITH_UDT_FIELD)
{
std::string valid = R"(
SCHEDULE
UDT
'TU_FBHP' 1 /
'LC' 100.0 500.0 / -- FOPR values
100.0 180.0 / -- FBHP values
/
/
UDQ
ASSIGN FU_FOPR 110.0 /
ASSIGN FU_WBHP 0 /
DEFINE FU_WBHP0 FU_WBHP /
DEFINE FU_WBHP TU_FBHP[FU_FOPR] UMIN FU_WBHP0 /
/
)";
auto schedule = make_schedule(valid);
UDQState udq_state(0);
SummaryState st(TimeService::now(), schedule.back().udq().params().undefinedValue());
UDQFunctionTable udqft;
WellMatcher wm(NameOrder({"W1", "W2", "W3"}));
const auto& udq = schedule.getUDQConfig(0);
UDQContext context(udqft, wm, udq.tables(), UDQContext::MatcherFactories{}, st, udq_state);
const auto& ass = udq.assign("FU_WBHP");
context.update_assign("FU_WBHP", ass.eval());
const auto& ass2 = udq.assign("FU_FOPR");
context.update_assign("FU_FOPR", ass2.eval());
udq.define("FU_WBHP0");
const auto& def = udq.define("FU_WBHP");
auto res = def.eval(context);
BOOST_CHECK_EQUAL(res.size(), 1U);
BOOST_CHECK_EQUAL(res[0].get(), 100.0 + (180.0 - 100.0) * (110.0 - 100.0) / (500.0 - 100.0));
}
BOOST_AUTO_TEST_CASE(UDQ_WITH_UDT_WELL)
{
std::string valid = R"(
SCHEDULE
WELSPECS
'PROD1' 'TEST' 5 1 1* 'OIL' 2* 'STOP' 4* /
'PROD2' 'TEST' 1 1 1* 'OIL' 2* 'STOP' 4* /
/
UDT
'TU_FBHP' 1 /
'LC' 100.0 500.0 / -- FOPR values
100.0 180.0 / -- FBHP values
/
/
UDQ
ASSIGN WU_WBHP 0 /
DEFINE WU_WBHP0 FU_WBHP /
DEFINE WU_WBHP TU_FBHP[WOPR] UMIN WU_WBHP0 /
/
)";
auto schedule = make_schedule(valid);
UDQState udq_state(0);
SummaryState st(TimeService::now(), schedule.back().udq().params().undefinedValue());
UDQFunctionTable udqft;
WellMatcher wm(NameOrder({"PROD1", "PROD2"}));
const auto& udq = schedule.getUDQConfig(0);
st.update_well_var("PROD1", "WOPR", 120.0);
st.update_well_var("PROD2", "WOPR", 450.0);
auto segmentMatcherFactory = []() { return std::make_unique<SegmentMatcher>(ScheduleState {}); };
auto regionSetMatcherFactory = []() { return std::make_unique<RegionSetMatcher>(FIPRegionStatistics {}); };
udq.eval(0, schedule, wm, segmentMatcherFactory, regionSetMatcherFactory, st, udq_state);
const double wu_wbhp1 = st.get_well_var("PROD1", "WU_WBHP");
const double wu_wbhp2 = st.get_well_var("PROD2", "WU_WBHP");
BOOST_CHECK_EQUAL(wu_wbhp1, 100.0 + (180.0 - 100.0) * (120.0 - 100.0) / (500.0 - 100.0));
BOOST_CHECK_EQUAL(wu_wbhp2, 100.0 + (180.0 - 100.0) * (450.0 - 100.0) / (500.0 - 100.0));
}
|