1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 11240 11241 11242 11243 11244 11245 11246 11247 11248 11249 11250 11251 11252 11253 11254 11255 11256 11257 11258 11259 11260 11261 11262 11263 11264 11265 11266 11267 11268 11269 11270 11271 11272 11273 11274 11275 11276 11277 11278 11279 11280 11281 11282 11283 11284 11285 11286 11287 11288 11289 11290 11291 11292 11293 11294 11295 11296 11297 11298 11299 11300 11301 11302 11303 11304 11305 11306 11307 11308 11309 11310 11311 11312 11313 11314 11315 11316 11317 11318 11319 11320 11321 11322 11323 11324 11325 11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 11349 11350 11351 11352 11353 11354 11355 11356 11357 11358 11359 11360 11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 11411 11412 11413 11414 11415 11416 11417 11418 11419 11420 11421 11422 11423 11424 11425 11426 11427 11428 11429 11430 11431 11432 11433 11434 11435 11436 11437 11438 11439 11440 11441 11442 11443 11444 11445 11446 11447 11448 11449 11450 11451 11452 11453 11454 11455 11456 11457 11458 11459 11460 11461 11462 11463 11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 11477 11478 11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493 11494 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 11544 11545 11546 11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 11560 11561 11562 11563 11564 11565 11566 11567 11568 11569 11570 11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 11596 11597 11598 11599 11600 11601 11602 11603 11604 11605 11606 11607 11608 11609 11610 11611 11612 11613 11614 11615 11616 11617 11618 11619 11620 11621 11622 11623 11624 11625 11626 11627 11628 11629 11630 11631 11632 11633 11634 11635 11636 11637 11638 11639 11640 11641 11642 11643 11644 11645 11646 11647 11648 11649 11650 11651 11652 11653 11654 11655 11656 11657 11658 11659 11660 11661 11662 11663 11664 11665 11666 11667 11668 11669 11670 11671 11672 11673 11674 11675 11676 11677 11678 11679 11680 11681 11682 11683 11684 11685 11686 11687 11688 11689 11690 11691 11692 11693 11694 11695 11696 11697 11698 11699 11700 11701 11702 11703 11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 11777 11778 11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 11808 11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822 11823 11824 11825 11826 11827 11828 11829 11830 11831 11832 11833 11834 11835 11836 11837 11838 11839 11840 11841 11842 11843 11844 11845 11846 11847 11848 11849 11850 11851 11852 11853 11854 11855 11856 11857 11858 11859 11860 11861 11862 11863 11864 11865 11866 11867 11868 11869 11870 11871 11872 11873 11874 11875 11876 11877 11878 11879 11880 11881 11882 11883 11884 11885 11886 11887 11888 11889 11890 11891 11892 11893 11894 11895 11896 11897 11898 11899 11900 11901 11902 11903 11904 11905 11906 11907 11908 11909 11910 11911 11912 11913 11914 11915 11916 11917 11918 11919 11920 11921 11922 11923 11924 11925 11926 11927 11928 11929 11930 11931 11932 11933 11934 11935 11936 11937 11938 11939 11940 11941 11942 11943 11944 11945 11946 11947 11948 11949 11950 11951 11952 11953 11954 11955 11956 11957 11958 11959 11960 11961 11962 11963 11964 11965 11966 11967 11968 11969 11970 11971 11972 11973 11974 11975 11976 11977 11978 11979 11980 11981 11982 11983 11984 11985 11986 11987 11988 11989 11990 11991 11992 11993 11994 11995 11996 11997 11998 11999 12000 12001 12002 12003 12004 12005 12006 12007 12008 12009 12010 12011 12012 12013 12014 12015 12016 12017 12018 12019 12020 12021 12022 12023 12024 12025 12026 12027 12028 12029 12030 12031 12032 12033 12034 12035 12036 12037 12038 12039 12040 12041 12042 12043 12044 12045 12046 12047 12048 12049 12050 12051 12052 12053 12054 12055 12056 12057 12058 12059 12060 12061 12062 12063 12064 12065 12066 12067 12068 12069 12070 12071 12072 12073 12074 12075 12076 12077 12078 12079 12080 12081 12082 12083 12084 12085 12086 12087 12088 12089 12090 12091 12092 12093 12094 12095 12096 12097 12098 12099 12100 12101 12102 12103 12104 12105 12106 12107 12108 12109 12110 12111 12112 12113 12114 12115 12116 12117 12118 12119 12120 12121 12122 12123 12124 12125 12126 12127 12128 12129 12130 12131 12132 12133 12134 12135 12136 12137 12138 12139 12140 12141 12142 12143 12144 12145 12146 12147 12148 12149 12150 12151 12152 12153 12154 12155 12156 12157 12158 12159 12160 12161 12162 12163 12164 12165 12166 12167 12168 12169 12170 12171 12172 12173 12174 12175 12176 12177 12178 12179 12180 12181 12182 12183 12184 12185 12186 12187 12188 12189 12190 12191 12192 12193 12194 12195 12196 12197 12198 12199 12200 12201 12202 12203 12204 12205 12206 12207 12208 12209 12210 12211 12212 12213 12214 12215 12216 12217 12218 12219 12220 12221 12222 12223 12224 12225 12226 12227 12228 12229 12230 12231 12232 12233 12234 12235 12236 12237 12238 12239 12240 12241 12242 12243 12244 12245 12246 12247 12248 12249 12250 12251 12252 12253 12254 12255 12256 12257 12258 12259 12260 12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271 12272 12273 12274 12275 12276 12277 12278 12279 12280 12281 12282 12283 12284 12285 12286 12287 12288 12289 12290 12291 12292 12293 12294 12295 12296 12297 12298 12299 12300 12301 12302 12303 12304 12305 12306 12307 12308 12309 12310 12311 12312 12313 12314 12315 12316 12317 12318 12319 12320 12321 12322 12323 12324 12325 12326 12327 12328 12329 12330 12331 12332 12333 12334 12335 12336 12337 12338 12339 12340 12341 12342 12343 12344 12345 12346 12347 12348 12349 12350 12351 12352 12353 12354 12355 12356 12357 12358 12359 12360 12361 12362 12363 12364 12365 12366 12367 12368 12369 12370 12371 12372 12373 12374 12375 12376 12377 12378 12379 12380 12381 12382 12383 12384 12385 12386 12387 12388 12389 12390 12391 12392 12393 12394 12395 12396 12397 12398 12399 12400 12401 12402 12403 12404 12405 12406 12407 12408 12409 12410 12411 12412 12413 12414 12415 12416 12417 12418 12419 12420 12421 12422 12423 12424 12425 12426 12427 12428 12429 12430 12431 12432 12433 12434 12435 12436 12437 12438 12439 12440 12441 12442 12443 12444 12445 12446 12447 12448 12449 12450 12451 12452 12453 12454 12455 12456 12457 12458 12459 12460 12461 12462 12463 12464 12465 12466 12467 12468 12469 12470 12471 12472 12473 12474 12475 12476 12477 12478 12479 12480 12481 12482 12483 12484 12485 12486 12487 12488 12489 12490 12491 12492 12493 12494 12495 12496 12497 12498 12499 12500 12501 12502 12503 12504 12505 12506 12507 12508 12509 12510 12511 12512 12513 12514 12515 12516 12517 12518 12519 12520 12521 12522 12523 12524 12525 12526 12527 12528 12529 12530 12531 12532 12533 12534 12535 12536 12537 12538 12539 12540 12541 12542 12543 12544 12545 12546 12547 12548 12549 12550 12551 12552 12553 12554 12555 12556 12557 12558 12559 12560 12561 12562 12563 12564 12565 12566 12567 12568 12569 12570 12571 12572 12573 12574 12575 12576 12577 12578 12579 12580 12581 12582 12583 12584 12585 12586 12587 12588 12589 12590 12591 12592 12593 12594 12595 12596 12597 12598 12599 12600 12601 12602 12603 12604 12605 12606 12607 12608 12609 12610 12611 12612 12613 12614 12615 12616 12617 12618 12619 12620 12621 12622 12623 12624 12625 12626 12627 12628 12629 12630 12631 12632 12633 12634 12635 12636 12637 12638 12639 12640 12641 12642 12643 12644 12645 12646 12647 12648 12649 12650 12651 12652 12653 12654 12655 12656 12657 12658 12659 12660 12661 12662 12663 12664 12665 12666 12667 12668 12669 12670 12671 12672 12673 12674 12675 12676 12677 12678 12679 12680 12681 12682 12683 12684 12685 12686 12687 12688 12689 12690 12691 12692 12693 12694 12695 12696 12697 12698 12699 12700 12701 12702 12703 12704 12705 12706 12707 12708 12709 12710 12711 12712 12713 12714 12715 12716 12717 12718 12719 12720 12721 12722 12723 12724 12725 12726 12727 12728 12729 12730 12731 12732 12733 12734 12735 12736 12737 12738 12739 12740 12741 12742 12743 12744 12745 12746 12747 12748 12749 12750 12751 12752 12753 12754 12755 12756 12757 12758 12759 12760 12761 12762 12763 12764 12765 12766 12767 12768 12769 12770 12771 12772 12773 12774 12775 12776 12777 12778 12779 12780 12781 12782 12783 12784 12785 12786 12787 12788 12789 12790 12791 12792 12793 12794 12795 12796 12797 12798 12799 12800 12801 12802 12803 12804 12805 12806 12807 12808 12809 12810 12811 12812 12813 12814 12815 12816 12817 12818 12819 12820 12821 12822 12823 12824 12825 12826 12827 12828 12829 12830 12831 12832 12833 12834 12835 12836 12837 12838 12839 12840 12841 12842 12843 12844 12845 12846 12847 12848 12849 12850 12851 12852 12853 12854 12855 12856 12857 12858 12859 12860 12861 12862 12863 12864 12865 12866 12867 12868 12869 12870 12871 12872 12873 12874 12875 12876 12877 12878 12879 12880 12881 12882 12883 12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 12897 12898 12899 12900 12901 12902 12903 12904 12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931 12932 12933 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 12944 12945 12946 12947 12948 12949 12950 12951 12952 12953 12954 12955 12956 12957 12958 12959 12960 12961 12962 12963 12964 12965 12966 12967 12968 12969 12970 12971 12972 12973 12974 12975 12976 12977 12978 12979 12980 12981 12982 12983 12984 12985 12986 12987 12988 12989 12990 12991 12992 12993 12994 12995 12996 12997 12998 12999 13000 13001 13002 13003 13004 13005 13006 13007 13008 13009 13010 13011 13012 13013 13014 13015 13016 13017 13018 13019 13020 13021 13022 13023 13024 13025 13026 13027 13028 13029 13030 13031 13032 13033 13034 13035 13036 13037 13038 13039 13040 13041 13042 13043 13044 13045 13046 13047 13048 13049 13050 13051 13052 13053 13054 13055 13056 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 13070 13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 13082 13083 13084 13085 13086 13087 13088 13089 13090 13091 13092 13093 13094 13095 13096 13097 13098 13099 13100 13101 13102 13103 13104 13105 13106 13107 13108 13109 13110 13111 13112 13113 13114 13115 13116 13117 13118 13119 13120 13121 13122 13123 13124 13125 13126 13127 13128 13129 13130 13131 13132 13133 13134 13135 13136 13137 13138 13139 13140 13141 13142 13143 13144 13145 13146 13147 13148 13149 13150 13151 13152 13153 13154 13155 13156 13157 13158 13159 13160 13161 13162 13163 13164 13165 13166 13167 13168 13169 13170 13171 13172 13173 13174 13175 13176 13177 13178 13179 13180 13181 13182 13183 13184 13185 13186 13187 13188 13189 13190 13191 13192 13193 13194 13195 13196 13197 13198 13199 13200 13201 13202 13203 13204 13205 13206 13207 13208 13209 13210 13211 13212 13213 13214 13215 13216 13217 13218 13219 13220 13221 13222 13223 13224 13225 13226 13227 13228 13229 13230 13231 13232 13233 13234 13235 13236 13237 13238 13239 13240 13241 13242 13243 13244 13245 13246 13247 13248 13249 13250 13251 13252 13253 13254 13255 13256 13257 13258 13259 13260 13261 13262 13263 13264 13265 13266 13267 13268 13269 13270 13271 13272 13273 13274 13275 13276 13277 13278 13279 13280 13281 13282 13283 13284 13285 13286 13287 13288 13289 13290 13291 13292 13293 13294 13295 13296 13297 13298 13299 13300 13301 13302 13303 13304 13305 13306 13307 13308 13309 13310 13311 13312 13313 13314 13315 13316 13317 13318 13319 13320 13321 13322 13323 13324 13325 13326 13327 13328 13329 13330 13331 13332 13333 13334 13335 13336 13337 13338 13339 13340 13341 13342 13343 13344 13345 13346 13347 13348 13349 13350 13351 13352 13353 13354 13355 13356 13357 13358 13359 13360 13361 13362 13363 13364 13365 13366 13367 13368 13369 13370 13371 13372 13373 13374 13375 13376 13377 13378 13379 13380 13381 13382 13383 13384 13385 13386 13387 13388 13389 13390 13391 13392 13393 13394 13395 13396 13397 13398 13399 13400 13401 13402 13403 13404 13405 13406 13407 13408 13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 13423 13424 13425 13426 13427 13428 13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442 13443 13444 13445 13446 13447 13448 13449 13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 13462 13463 13464 13465 13466 13467 13468 13469 13470 13471 13472 13473 13474 13475 13476 13477 13478 13479 13480 13481 13482 13483 13484 13485 13486 13487 13488 13489 13490 13491 13492 13493 13494 13495 13496 13497 13498 13499 13500 13501 13502 13503 13504 13505 13506 13507 13508 13509 13510 13511 13512 13513 13514 13515 13516 13517 13518 13519 13520 13521 13522 13523 13524 13525 13526 13527 13528 13529 13530 13531 13532 13533 13534 13535 13536 13537 13538 13539 13540 13541 13542 13543 13544 13545 13546 13547 13548 13549 13550 13551 13552 13553 13554 13555 13556 13557 13558 13559 13560 13561 13562 13563 13564 13565 13566 13567 13568 13569 13570 13571 13572 13573 13574 13575 13576 13577 13578 13579 13580 13581 13582 13583 13584 13585 13586 13587 13588 13589 13590 13591 13592 13593 13594 13595 13596 13597 13598 13599 13600 13601 13602 13603 13604 13605 13606 13607 13608 13609 13610 13611 13612 13613 13614 13615 13616 13617 13618 13619 13620 13621 13622 13623 13624 13625 13626 13627 13628 13629 13630 13631 13632 13633 13634 13635 13636 13637 13638 13639 13640 13641 13642 13643 13644 13645 13646 13647 13648 13649 13650 13651 13652 13653 13654 13655 13656 13657 13658 13659 13660 13661 13662 13663 13664 13665 13666 13667 13668 13669 13670 13671 13672 13673 13674 13675 13676 13677 13678 13679 13680 13681 13682 13683 13684 13685 13686 13687 13688 13689 13690 13691 13692 13693 13694 13695 13696 13697 13698 13699 13700 13701 13702 13703 13704 13705 13706 13707 13708 13709 13710 13711 13712 13713 13714 13715 13716 13717 13718 13719 13720 13721 13722 13723 13724 13725 13726 13727 13728 13729 13730 13731 13732 13733 13734 13735 13736 13737 13738 13739 13740 13741 13742 13743 13744 13745 13746 13747 13748 13749 13750 13751 13752 13753 13754 13755 13756 13757 13758 13759 13760 13761 13762 13763 13764 13765 13766 13767 13768 13769 13770 13771 13772 13773 13774 13775 13776 13777 13778 13779 13780 13781 13782 13783 13784 13785 13786 13787 13788 13789 13790 13791 13792 13793 13794 13795 13796 13797 13798 13799 13800 13801 13802 13803 13804 13805 13806 13807 13808 13809 13810 13811 13812 13813 13814 13815 13816 13817 13818 13819 13820 13821 13822 13823 13824 13825 13826 13827 13828 13829 13830 13831 13832 13833 13834 13835 13836 13837 13838 13839 13840 13841 13842 13843 13844 13845 13846 13847 13848 13849 13850 13851 13852 13853 13854 13855 13856 13857 13858 13859 13860 13861 13862 13863 13864 13865 13866 13867 13868 13869 13870 13871 13872 13873 13874 13875 13876 13877 13878 13879 13880 13881 13882 13883 13884 13885 13886 13887 13888 13889 13890 13891 13892 13893 13894 13895 13896 13897 13898 13899 13900 13901 13902 13903 13904 13905 13906 13907 13908 13909 13910 13911 13912 13913 13914 13915 13916 13917 13918 13919 13920 13921 13922 13923 13924 13925 13926 13927 13928 13929 13930 13931 13932 13933 13934 13935 13936 13937 13938 13939 13940 13941 13942 13943 13944 13945 13946 13947 13948 13949 13950 13951 13952 13953 13954 13955 13956 13957 13958 13959 13960 13961 13962 13963 13964 13965 13966 13967 13968 13969 13970 13971 13972 13973 13974 13975 13976 13977 13978 13979 13980 13981 13982 13983 13984 13985 13986 13987 13988 13989 13990 13991 13992 13993 13994 13995 13996 13997 13998 13999 14000 14001 14002 14003 14004 14005 14006 14007 14008 14009 14010 14011 14012 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 14023 14024 14025 14026 14027 14028 14029 14030 14031 14032 14033 14034 14035 14036 14037 14038 14039 14040 14041 14042 14043 14044 14045 14046 14047 14048 14049 14050 14051 14052 14053 14054 14055 14056 14057 14058 14059 14060 14061 14062 14063 14064 14065 14066 14067 14068 14069 14070 14071 14072 14073 14074 14075 14076 14077 14078 14079 14080 14081 14082 14083 14084 14085 14086 14087 14088 14089 14090 14091 14092 14093 14094 14095 14096 14097 14098 14099 14100 14101 14102 14103 14104 14105 14106 14107 14108 14109 14110 14111 14112 14113 14114 14115 14116 14117 14118 14119 14120 14121 14122 14123 14124 14125 14126 14127 14128 14129 14130 14131 14132 14133 14134 14135 14136 14137 14138 14139 14140 14141 14142 14143 14144 14145 14146 14147 14148 14149 14150 14151 14152 14153 14154 14155 14156 14157 14158 14159 14160 14161 14162 14163 14164 14165 14166 14167 14168 14169 14170 14171 14172 14173 14174 14175 14176 14177 14178 14179 14180 14181 14182 14183 14184 14185 14186 14187 14188 14189 14190 14191 14192 14193 14194 14195 14196 14197 14198 14199 14200 14201 14202 14203 14204 14205 14206 14207 14208 14209 14210 14211 14212 14213 14214 14215 14216 14217 14218 14219 14220 14221 14222 14223 14224 14225 14226 14227 14228 14229 14230 14231 14232 14233 14234 14235 14236 14237 14238 14239 14240 14241 14242 14243 14244 14245 14246 14247 14248 14249 14250 14251 14252 14253 14254 14255 14256 14257 14258 14259 14260 14261 14262 14263 14264 14265 14266 14267 14268 14269 14270 14271 14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 14298 14299 14300 14301 14302 14303 14304 14305 14306 14307 14308 14309 14310 14311 14312 14313 14314 14315 14316 14317 14318 14319 14320 14321 14322 14323 14324 14325 14326 14327 14328 14329 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 14349 14350 14351 14352 14353 14354 14355 14356 14357 14358 14359 14360 14361 14362 14363 14364 14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 14381 14382 14383 14384 14385 14386 14387 14388 14389 14390 14391 14392 14393 14394 14395 14396 14397 14398 14399 14400 14401 14402 14403 14404 14405 14406 14407 14408 14409 14410 14411 14412 14413 14414 14415 14416 14417 14418 14419 14420 14421 14422 14423 14424 14425 14426 14427 14428 14429 14430 14431 14432 14433 14434 14435 14436 14437 14438 14439 14440 14441 14442 14443 14444 14445 14446 14447 14448 14449 14450 14451 14452 14453 14454 14455 14456 14457 14458 14459 14460 14461 14462 14463 14464 14465 14466 14467 14468 14469 14470 14471 14472 14473 14474 14475 14476 14477 14478 14479 14480 14481 14482 14483 14484 14485 14486 14487 14488 14489 14490 14491 14492 14493 14494 14495 14496 14497 14498 14499 14500 14501 14502 14503 14504 14505
|
/*****************************************************************************
*
* Copyright (c) 2000 - 2010, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400124
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtSiloFileFormat.C //
// ************************************************************************* //
#include <avtSiloFileFormat.h>
#include <avtSiloOptions.h>
// includes from visit_vtk/full
#ifndef MDSERVER
#include <vtkCSGGrid.h>
#endif
#include <float.h>
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkCellType.h>
#include <vtkCharArray.h>
#include <vtkDoubleArray.h>
#include <vtkFloatArray.h>
#include <vtkIdList.h>
#include <vtkIdTypeArray.h>
#include <vtkIntArray.h>
#include <vtkLongArray.h>
#include <vtkLongLongArray.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkRectilinearGrid.h>
#include <vtkShortArray.h>
#include <vtkStructuredGrid.h>
#include <vtkUnsignedCharArray.h>
#include <vtkUnsignedIntArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkVisItUtility.h>
#include <avtCallback.h>
#include <avtDatabase.h>
#include <avtDatabaseMetaData.h>
#include <avtFacelist.h>
#include <avtGhostData.h>
#include <avtIntervalTree.h>
#include <avtIOInformation.h>
#include <avtMaterial.h>
#include <avtMixedVariable.h>
#include <avtResampleSelection.h>
#include <avtSpecies.h>
#include <avtStructuredDomainBoundaries.h>
#include <avtStructuredDomainNesting.h>
#include <avtTypes.h>
#include <avtVariableCache.h>
#include <Utility.h>
#include <Expression.h>
#include <StringHelpers.h>
#include <BadDomainException.h>
#include <BadIndexException.h>
#include <BufferConnection.h>
#include <DBOptionsAttributes.h>
#include <DebugStream.h>
#include <ImproperUseException.h>
#include <InvalidFilesException.h>
#include <InvalidVariableException.h>
#include <InvalidZoneTypeException.h>
#include <SiloException.h>
#include <avtStructuredDomainBoundaries.h>
#include <visit-config.h>
#include <sstream>
#include <snprintf.h>
#include <stdlib.h> // for qsort
#ifdef PARALLEL
#include <mpi.h>
#include <avtParallel.h>
#endif
#include <string>
#include <vector>
#include <map>
#include <set>
using std::string;
using std::vector;
using std::map;
using std::set;
using std::ostringstream;
using namespace SiloDBOptions;
static void ExceptionGenerator(char *);
static char *GenerateName(const char *, const char *, const char *);
static string PrepareDirName(const char *, const char *);
static void SplitDirVarName(const char *dirvar, const char *curdir,
string &dir, string &var);
static void AddDefvars(const char *, avtDatabaseMetaData *);
static int SiloZoneTypeToVTKZoneType(int);
static void TranslateSiloWedgeToVTKWedge(const int *, vtkIdType [6]);
static void TranslateSiloPyramidToVTKPyramid(const int *, vtkIdType [5]);
static void TranslateSiloTetrahedronToVTKTetrahedron(const int *,
vtkIdType [4]);
static bool TetIsInverted(const vtkIdType *siloTetrahedron,
vtkUnstructuredGrid *ugrid);
static void ArbInsertArbitrary(vtkUnstructuredGrid *ugrid,
DBphzonelist *phzl, int gz, const vector<int> &nloffs,
const vector<int> &floffs, unsigned int ocdata[2],
vector<int> *cellReMap, vector<int> *nodeReMap);
static string GuessCodeNameFromTopLevelVars(DBfile *dbfile);
static void AddAle3drlxstatEnumerationInfo(avtScalarMetaData *smd);
static void HandleMrgtreeForMultimesh(DBfile *dbfile, DBmultimesh *mm,
const char *multimesh_name, avtMeshType *mt, int *num_groups,
vector<int> *group_ids, vector<string> *block_names, int dontForceSingle);
static void BuildDomainAuxiliaryInfoForAMRMeshes(DBfile *dbfile, DBmultimesh *mm,
const char *meshName, int timestate, int type, avtVariableCache *cache,
int dontForceSingle);
static int MultiMatHasAllMatInfo(const DBmultimat *const mm);
// the maximum number of nodelists any given single node can be in
static const int maxCoincidentNodelists = 12;
// ****************************************************************************
// Class: avtSiloFileFormat
//
// Purpose:
// A Silo file format reader.
//
// Arguments:
// fnames The filenames
// nf The number of files.
//
// Notes: It is assumed that the files are sorted so that the one with
// the multimesh/multivars/multimaterials comes first.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
//
// Hank Childs, Mon Apr 9 12:54:31 PDT 2001
// Have Silo throw an exception whenever a problem occurs.
//
// Hank Childs, Mon Apr 7 18:04:30 PDT 2003
// Do not make the global Silo calls repeatedly.
//
// Hank Childs, Sat Mar 5 19:13:05 PST 2005
// Don't do dynamic load balancing where we are in parallel.
//
// Mark C. Miller, Mon Jun 12 22:22:38 PDT 2006
// Enabled Silo's checksums
//
// Mark C. Miller, Wed Nov 29 15:08:21 PST 2006
// Initialized connectivityIsTimeVarying
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Added ability to turn forcing single precision off to support testing
//
// Mark C. Miller, Wed May 30 08:25:05 PDT 2007
// Added this bogus comment to test svn update behavior
//
// Hank Childs, Tue Feb 19 19:45:43 PST 2008
// Rename "dynamic" to "streaming", since we really care about whether we
// are streaming, not about whether we are doing dynamic load balancing.
// And the two are no longer synonymous.
//
// Mark C. Miller, Fri Apr 25 21:06:27 PDT 2008
// Initialize numNodeLists and broadcast info about nodelists if we
// have any.
//
// Mark C. Miller, Tue Apr 29 23:33:55 PDT 2008
// Added read options, re-organized the routine a bit. Fixed some
// seriously bogus code I had added for controlling force single behavior.
//
// Mark C. Miller, Tue Jun 10 22:36:25 PDT 2008
// Added logic to ignore spatial/data extents.
//
// Mark C. Miller, Wed Mar 4 08:54:57 PST 2009
// Improved logic to handle ignoring of spatial/data extents so that user
// can override explicitly or let plugin handle automatically.
//
// Mark C. Miller, Wed Mar 4 12:05:45 PST 2009
// Made option processing for extents compatible with 'old' way of doing
// them.
//
// Mark C. Miller, Mon Mar 16 23:33:32 PDT 2009
// Moved logic for 'old' extents interface to CommonPluginInfo where
// old (obsolete) options can be merged with current interface. Also, use
// const char* symbol names for options defined in avtSiloOptions.h.
//
// Mark C. Miller, Tue Dec 15 14:01:48 PST 2009
// Added metadataIsTimeVarying
//
// Mark C. Miller, Thu Jan 7 16:22:58 PST 2010
// Made it always call DBForceSingle so that you couldn't get into a
// situation where you opened a file with dontForceSingle false and later
// set dontForceSingle to true but would then neglect to call
// DBForceSingle unsetting the value.
//
// Cyrus Harrison, Wed Mar 24 10:39:30 PDT 2010
// Added init of haveAmrGroupInfo.
//
// ****************************************************************************
avtSiloFileFormat::avtSiloFileFormat(const char *toc_name,
DBOptionsAttributes *rdatts)
: avtSTMDFileFormat(&toc_name, 1)
{
//
// Initialize class variables BEFORE processing read options
//
dontForceSingle = 0;
numNodeLists = 0;
maxAnnotIntLists = 0;
tocIndex = 0;
ignoreSpatialExtentsAAN = Auto;
ignoreDataExtentsAAN = Auto;
ignoreSpatialExtents = false;
ignoreDataExtents = false;
searchForAnnotInt = false;
readGlobalInfo = false;
connectivityIsTimeVarying = false;
metadataIsTimeVarying = false;
groupInfo.haveGroups = false;
haveAmrGroupInfo = false;
hasDisjointElements = false;
topDir = "/";
dbfiles = new DBfile*[MAX_FILES];
for (int i = 0 ; i < MAX_FILES ; i++)
{
dbfiles[i] = NULL;
}
//
// Process any read options, potentially overriding default behaviors
//
for (int i = 0; rdatts != 0 && i < rdatts->GetNumberOfOptions(); ++i)
{
if (rdatts->GetName(i) == SILO_RDOPT_FORCE_SINGLE)
dontForceSingle = rdatts->GetBool(SILO_RDOPT_FORCE_SINGLE) ? 0 : 1;
else if (rdatts->GetName(i) == SILO_RDOPT_SEARCH_ANNOTINT)
searchForAnnotInt = rdatts->GetBool(SILO_RDOPT_SEARCH_ANNOTINT);
else if (rdatts->GetName(i) == SILO_RDOPT_IGNORE_SEXTS)
ignoreSpatialExtentsAAN = (AANTriState) rdatts->GetEnum(SILO_RDOPT_IGNORE_SEXTS);
else if (rdatts->GetName(i) == SILO_RDOPT_IGNORE_DEXTS)
ignoreDataExtentsAAN = (AANTriState) rdatts->GetEnum(SILO_RDOPT_IGNORE_DEXTS);
else
debug1 << "Ignoring unknown option \"" << rdatts->GetName(i) << "\"" << endl;
}
//
// Set any necessary Silo library behavior
//
DBForceSingle(!dontForceSingle);
//
// If there is ever a problem with Silo, we want it to throw an
// exception.
//
DBShowErrors(DB_ALL, ExceptionGenerator);
//
// Turn on silo's checksumming feature. This is harmless if the
// underlying file DOES NOT contain checksums and will cause only
// a small performance hit if it does.
//
#ifdef E_CHECKSUM
DBSetEnableChecksums(1);
#endif
}
// ****************************************************************************
// Method: avtSiloFileFormat destructor
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
//
// Hank Childs, Mon Jan 7 18:51:24 PST 2002
// Fixed memory leak.
//
// Kathleen Bonnell, Wed Oct 1 17:08:51 PDT 2003
// Call CloseFile so that files are unregistered.
//
// Hank Childs, Wed Jan 14 11:58:41 PST 2004
// Use CleanUpResources so there can be one routine that does all the clean
// up.
//
// ****************************************************************************
avtSiloFileFormat::~avtSiloFileFormat()
{
FreeUpResources();
delete [] dbfiles;
}
// ****************************************************************************
// Method: avtSiloFileFormat::ActivateTimestep
//
// Purpose: Provides a guarenteed collective entry point for operations
// that may involve collective parallel communication. Each of the GetMesh,
// GetVar, etc. calls in this file can, in turn, call OpenFile. However,
// if the file hasn't been opened with a previous call, here, those calls
// can lead to strange failures because not all processors make calls
// to GetMesh, GetVar, etc. All processors do call this method.
//
// Programmer: Mark C. Miller
// Creation: February 9, 2004
//
// ****************************************************************************
void
avtSiloFileFormat::ActivateTimestep(void)
{
OpenFile(tocIndex);
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetFile
//
// Purpose: Get file at specified index, assuming its already been opened
// and throw an exception if it hasn't. This is intended to replace various
// calls to OpenFile, that could ultimately result in MPI collective
// communication if the file had not been opened in the past, and could
// cause VisIt to deadlock.
//
// Programmer: Mark C. Miller
// Creation: February 10, 2004
//
// Modifications:
// Mark C. Miller, Tue Mar 9 08:44:23 PST 2004
// Added missing call to UsedFile
//
// ****************************************************************************
DBfile *
avtSiloFileFormat::GetFile(int f)
{
if (dbfiles[f] == NULL)
{
EXCEPTION1(InvalidFilesException, filenames[f]);
}
UsedFile(f);
return dbfiles[f];
}
// ****************************************************************************
// Method: avtSiloFileFormat::OpenFile
//
// Purpose:
// Opens a Silo file.
//
// Arguments:
// f The index of the file in our array.
//
// Returns: A handle to the open file.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
//
// Hank Childs, Mon Mar 11 17:29:06 PST 2002
// Made call to GetTimeVaryingInformation.
//
// Hank Childs, Fri Mar 22 10:32:33 PST 2002
// Added calls to support file descriptor management.
//
// Hank Childs, Thu Apr 10 08:45:44 PDT 2003
// Initialize global information.
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Added bool to skip global information
//
// Mark C. Miller, Wed Dec 8 17:12:28 PST 2004
// Changed open to try explicit silo drivers; PDB first, then HDF5
// then everything else
//
// Mark C. Miller, Tue Feb 13 16:24:58 PST 2007
// Made it fail if the file it opened didn't look like a silo file
//
// Mark C. Miller, Wed Feb 6 12:27:09 PST 2008
// Made it handle the case a single silo file contains the whole time
// series. In this case, the filename passed here contains a ':'
// separating the name of the file as the filesystem sees it and the dir
// in the file to be used as the 'top dir' for this timestep. Note also,
// That there has to exist in the filesystem a real file (usually a symlink)
// named as <filename>:<dirname> that opens to the desired file.
//
// Jeremy Meredith, Thu Aug 7 16:16:34 EDT 2008
// Added missing filename argument to an sprintf.
//
// Mark C. Miller, Fri Jan 30 12:48:09 PST 2009
// Changed order of opens from PDB then HDF5 to HDF5 then PDB.
//
// Hank Childs, Sun May 10 10:56:22 CDT 2009
// Switch back ordering of drivers (PDB to HDF5), since HDF5 driver chokes
// when dealing with large PDB files (>2GB).
//
// Hank Childs, Tue Sep 22 20:47:16 PDT 2009
// Remove assumption of new version of Silo library.
//
// ****************************************************************************
DBfile *
avtSiloFileFormat::OpenFile(int f, bool skipGlobalInfo)
{
//
// Make sure this is in range.
//
if (f < 0 || f >= nFiles)
{
EXCEPTION2(BadIndexException, f, nFiles);
}
//
// Check to see if the file is already open.
//
if (dbfiles[f] != NULL)
{
UsedFile(f);
return dbfiles[f];
}
debug4 << "Opening silo file " << filenames[f] << endl;
//
// Open the Silo file. Impose priority order on drivers by first
// trying PDB, then HDF5, then fall-back to UNKNOWN
//
if (((dbfiles[f] = DBOpen(filenames[f], DB_PDB, DB_READ)) == NULL) &&
((dbfiles[f] = DBOpen(filenames[f], DB_HDF5, DB_READ)) == NULL) &&
((dbfiles[f] = DBOpen(filenames[f], DB_UNKNOWN, DB_READ)) == NULL))
{
EXCEPTION1(InvalidFilesException, filenames[f]);
}
//
// Lets try to make absolutely sure this is really a Silo file and
// not just a PDB file that PD_Open succeeded on.
//
bool hasSiloLibInfo = DBInqVarExists(dbfiles[f], "_silolibinfo");
if (!hasSiloLibInfo) // newer silo files have this
{
//
// See how many silo objects we have
//
DBtoc *toc = DBGetToc(dbfiles[f]);
int nSiloObjects =
toc->ncurve + toc->ncsgmesh + toc->ncsgvar + toc->ndefvars +
toc->nmultimesh + toc->nmultimeshadj + toc->nmultivar +
toc->nmultimat + toc->nmultimatspecies + toc->nqmesh +
toc->nqvar + toc->nucdmesh + toc->nucdvar + toc->nptmesh +
toc->nptvar + toc->nvar + toc->nmat + toc->nobj + toc->ndir
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,1)
+ toc->nmrgtrees + toc->ngroupelmaps + toc->nmrgvars
#endif
#endif
+ toc->narrays;
//
// We don't appear to have any silo objects, so we'll fail it
//
if (nSiloObjects <= 0)
{
char str[1024];
SNPRINTF(str, sizeof(str), "Although the Silo library succesfully opened \"%s,\"\n"
"the file contains no silo objects. It may be a PDB file.",
filenames[f]);
EXCEPTION1(InvalidFilesException, str);
}
}
//
// Attempt to handle case where specified file is actually a silo
// filename followed by ':' followed by an internal silo directory
// name.
//
const char *baseFilename = StringHelpers::Basename(filenames[f]);
const char *pColon = strrchr(baseFilename, ':');
if (pColon != NULL)
{
pColon++; // move one past the ':' character
int triedDir = DBSetDir(dbfiles[f], pColon);
if (triedDir == 0)
{
debug1 << "Handling this silo file as though it is a file-dir combo" << endl;
debug1 << "for the case where an entire time series is in one silo file." << endl;
topDir = pColon;
}
}
RegisterFile(f);
if (f == 0 && !readGlobalInfo && !skipGlobalInfo)
{
ReadGlobalInformation(dbfiles[f]);
}
return dbfiles[f];
}
// ****************************************************************************
// Method: avtSiloFileFormat::ReadGlobalInformation
//
// Purpose:
// This is a method that is guaranteed to get called before 'ReadVar'
// calls are made. Formerly, much of this work was done in 'ReadDir',
// but ReadDir is not always called, leading to serious problems.
//
// Programmer: Hank Childs
// Creation: April 10, 2003
//
// Modifications:
//
// Hank Childs, Thu Aug 14 09:20:28 PDT 2003
// Remove support for vector defvars -- they are now correctly handled at a
// higher level.
//
// Mark C. Miller, Wed Dec 13 16:55:30 PST 2006
// Added call to GetMultivarToMultimeshMap
//
// ****************************************************************************
void
avtSiloFileFormat::ReadGlobalInformation(DBfile *dbfile)
{
//
// Get the cycle, dtime, etc.
//
GetTimeVaryingInformation(dbfile);
//
// We can fake ghost zones for block-structured grids. Read in
// information related to that.
//
GetConnectivityAndGroupInformation(dbfile);
//
// Read multi-var to multi-mesh mapping information.
//
GetMultivarToMultimeshMap(dbfile);
readGlobalInfo = true;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetCycle
//
// Purpose: Return the cycle number associated with this silo file
//
// Programmer: Mark C. Miller
// Creation: May 16, 2005
//
// Modifications:
// Mark C. Miller, Tue May 31 20:12:42 PDT 2005
// Made it return INVALID_CYCLE for a bad value
//
// Mark C. Miller, Wed Mar 21 10:37:01 PDT 2007
// Re-factored Silo work to a static function so it can be called from
// multiple places.
//
// Mark C. Miller, Sun Jul 5 10:40:30 PDT 2009
// Added logic to rethrow an invalid files exception to match test
// suite behavior.
// ****************************************************************************
static int GetCycle(DBfile *dbfile)
{
if (DBInqVarExists(dbfile, "cycle"))
{
int cycle;
DBReadVar(dbfile, "cycle", &cycle);
return cycle;
}
return avtFileFormat::INVALID_CYCLE;
}
int
avtSiloFileFormat::GetCycle()
{
int retval = avtFileFormat::INVALID_CYCLE;
TRY
{
const bool canSkipGlobalInfo = true;
DBfile *dbfile = OpenFile(tocIndex, canSkipGlobalInfo);
retval = ::GetCycle(dbfile);
}
CATCH(InvalidFilesException)
{
debug1 << "Unable to GetCycle()" << endl;
RETHROW;
}
CATCHALL
{
debug1 << "Unable to GetCycle()" << endl;
}
ENDTRY
return retval;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetCycleFromFilename
//
// Purpose: Try to get a cycle number from a file name
//
// Notes: Although all this method does is simply call the format's base
// class implementation of GuessCycle, doing this is a way for the Silo
// format to "bless" the guesses that that method makes. Otherwise, VisIt
// wouldn't know that Silo thinks those guesses are good. See notes in
// avtSTXXFileFormatInterface::SetDatabaseMetaData for further explanation.
//
// Programmer: Mark C. Miller
// Creation: May 16, 2005
//
// ****************************************************************************
int
avtSiloFileFormat::GetCycleFromFilename(const char *f) const
{
return GuessCycle(f);
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetTime
//
// Purpose: Return the time associated with this silo file
//
// Programmer: Mark C. Miller
// Creation: May 16, 2005
//
// Modifications:
// Mark C. Miller, Mon Mar 19 15:52:24 PDT 2007
// Added fall back to 'time' if can't filed 'dtime'
//
// Mark C. Miller, Wed Mar 21 10:37:01 PDT 2007
// Re-factored Silo work to a static function so it can be called from
// multiple places.
//
// Mark C. Miller, Sun Jul 5 10:40:30 PDT 2009
// Added logic to rethrow an invalid files exception to match test
// suite behavior.
// ****************************************************************************
static double GetTime(DBfile *dbfile)
{
if (DBInqVarExists(dbfile, "dtime"))
{
double dtime;
DBReadVar(dbfile, "dtime", &dtime);
return dtime;
}
else if (DBInqVarExists(dbfile, "time"))
{
float time;
DBReadVar(dbfile, "time", &time);
return (double) time;
}
return avtFileFormat::INVALID_TIME;
}
double avtSiloFileFormat::GetTime()
{
double retval = avtFileFormat::INVALID_TIME;
TRY
{
const bool canSkipGlobalInfo = true;
DBfile *dbfile = OpenFile(tocIndex, canSkipGlobalInfo);
retval = ::GetTime(dbfile);
}
CATCH(InvalidFilesException)
{
debug1 << "Unable to GetTime()" << endl;
RETHROW;
}
CATCHALL
{
debug1 << "Unable to GetTime()" << endl;
}
ENDTRY
return retval;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetTimeVaryingInformation
//
// Purpose:
// Gets the time varying information out of a Silo file. This is only
// called once and is for getting things like time and cycle out of the
// file.
//
// Programmer: Hank Childs
// Creation: March 11, 2002
//
// Modifications:
// Mark C. Miller, Thu Mar 18 10:40:50 PST 2004
// Added check for null metadata pointer and early return
//
// Mark C. Miller, Thu Mar 18 11:00:38 PST 2004
// Added optional md arg. Prefers setting metadata data member over
// using md arg, when metadata data member is non-NULL
//
// Mark C. Miller, Thu May 19 09:57:07 PDT 2005
// Made it indicate the specified timestep has accurate cycle/time
//
// Mark C. Miller, Wed Mar 21 10:37:01 PDT 2007
// Modified for re-factored GetCycle/GetTime static functions to
// ****************************************************************************
void
avtSiloFileFormat::GetTimeVaryingInformation(DBfile *dbfile,
avtDatabaseMetaData *md)
{
avtDatabaseMetaData *tmpMd = (metadata == 0) ? md : metadata;
if (tmpMd == 0)
return;
//
// Read out the cycle number and time.
//
int cycle = ::GetCycle(dbfile);
if (cycle != INVALID_CYCLE)
{
tmpMd->SetCycle(timestep, cycle);
tmpMd->SetCycleIsAccurate(true, timestep);
}
double dtime = ::GetTime(dbfile);
if (dtime != INVALID_TIME)
{
tmpMd->SetTime(timestep, dtime);
tmpMd->SetTimeIsAccurate(true, timestep);
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::OpenFile
//
// Purpose:
// Opens a file by asking for a file name; adds the file name to a list
// if we haven't heard of it before.
//
// Arguments:
// n The file name.
//
// Returns: A handle to the open file.
//
// Programmer: Hank Childs
// Creation: February 26, 2001
//
// Modifications:
// Brad Whitlock, Thu May 22 14:23:14 PST 2003
// I made it use VISIT_SLASH_STRING so it works better on Windows.
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Added bool to skip global info
//
// *****************************************************************************
DBfile *
avtSiloFileFormat::OpenFile(const char *n, bool skipGlobalInfo)
{
//
// The directory of this file is all relative to the directory of the
// table of contents. Reflect that here.
//
char name[1024];
char *tocFile = filenames[tocIndex];
char *thisSlash = tocFile, *lastSlash = tocFile;
while (thisSlash != NULL)
{
lastSlash = thisSlash;
thisSlash = strstr(lastSlash+1, VISIT_SLASH_STRING);
}
if (lastSlash == tocFile)
{
strcpy(name, n);
}
else
{
int amount = lastSlash-tocFile+1;
strncpy(name, tocFile, amount);
strcpy(name+amount, n);
}
int fileIndex = -1;
for (int i = 0 ; i < nFiles ; i++)
{
if (strcmp(filenames[i], name) == 0)
{
fileIndex = i;
break;
}
}
if (fileIndex == -1)
{
//
// We have asked for a previously unseen file. Add it to the list and
// continue. AddFile will automatically take care of overflow issues.
//
fileIndex = AddFile(name);
}
DBfile *dbfile = OpenFile(fileIndex, skipGlobalInfo);
return dbfile;
}
// ****************************************************************************
// Method: avtSiloFileFormat::CloseFile
//
// Purpose:
// Closes a Silo file.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
//
// Hank Childs, Fri Mar 22 11:10:18 PST 2002
// Added a method call to make sure that we are playing well with the file
// descriptor manager.
//
// ****************************************************************************
void
avtSiloFileFormat::CloseFile(int f)
{
if (dbfiles[f] != NULL)
{
debug4 << "Closing Silo file " << filenames[f] << endl;
DBClose(dbfiles[f]);
UnregisterFile(f);
dbfiles[f] = NULL;
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::FreeUpResources
//
// Purpose:
// Frees up the resources. This closes down file descriptors.
//
// Programmer: Hank Childs
// Creation: February 23, 2001
//
// Modifications:
//
// Hank Childs, Wed Jan 14 11:58:41 PST 2004
// Clean up all the cached multi- Silo objects.
//
// Mark C. Miller, Tue Apr 29 23:33:55 PDT 2008
// Clean up resources related to block structured code nodelists.
//
// Mark C. Miller, Wed Oct 28 20:41:02 PDT 2009
// Removed arbMeshZoneRangesToSkip. Intoduced better handling of arb.
// polyhedral meshes.
//
// Mark C. Miller, Wed Jan 27 13:14:03 PST 2010
// Added extra level of indirection to arbMeshXXXRemap objects to handle
// multi-block case.
// ****************************************************************************
void
avtSiloFileFormat::FreeUpResources(void)
{
int i;
debug4 << "Silo File Format instructed to free up resources." << endl;
for (i = 0 ; i < nFiles ; i++)
{
CloseFile(i);
}
firstSubMesh.clear();
firstSubMeshVarName.clear();
actualMeshName.clear();
allSubMeshDirs.clear();
blocksForMultivar.clear();
for (i = 0 ; i < multimeshes.size() ; i++)
DBFreeMultimesh(multimeshes[i]);
multimeshes.clear();
multimesh_name.clear();
for (i = 0 ; i < multivars.size() ; i++)
DBFreeMultivar(multivars[i]);
multivars.clear();
multivar_name.clear();
for (i = 0 ; i < multimats.size() ; i++)
DBFreeMultimat(multimats[i]);
multimats.clear();
multimat_name.clear();
for (i = 0 ; i < multimatspecies.size() ; i++)
DBFreeMultimatspecies(multimatspecies[i]);
multimatspecies.clear();
multimatspec_name.clear();
nlBlockToWindowsMap.clear();
pascalsTriangleMap.clear();
map<string, map<int, vector<int>* > >::iterator it1;
map<int, vector<int>* >::iterator it2;
for (it1 = arbMeshCellReMap.begin(); it1 != arbMeshCellReMap.end(); it1++)
{
for (it2 = it1->second.begin(); it2 != it1->second.end(); it2++)
delete it2->second;
it1->second.clear();
}
arbMeshCellReMap.clear();
for (it1 = arbMeshNodeReMap.begin(); it1 != arbMeshNodeReMap.end(); it1++)
{
for (it2 = it1->second.begin(); it2 != it1->second.end(); it2++)
delete it2->second;
it1->second.clear();
}
arbMeshNodeReMap.clear();
}
// ****************************************************************************
// Method: avtSiloFileFormat::PopulateDatabaseMetaData
//
// Purpose:
// Sets the database meta data.
//
// Programmer: Hank Childs
// Creation: February 26, 2001
//
// Modifications:
//
// Hank Childs, Thu Mar 15 19:34:19 PST 2001
// Fixed multi-variables to be more careful in determining what mesh they
// are defined on.
//
// Hank Childs, Mon Mar 19 17:22:35 PST 2001
// Added vectors through defvars.
//
// Hank Childs, Mon Apr 9 13:18:34 PDT 2001
// Added support for multi???s where the first domain is invalid.
//
// Hank Childs, Thu Oct 18 14:21:20 PDT 2001
// Don't assume that the bounds for the first timestep are the bounds for
// all timesteps.
//
// Brad Whitlock, Mon Oct 22 18:33:37 PST 2001
// Changed the exception keywords to macros.
//
// Jeremy Meredith, Thu Oct 25 13:02:18 PDT 2001
// Added code to read domain decomposition information.
//
// Hank Childs, Thu Oct 25 17:02:39 PDT 2001
// More changes for domain decomposition information.
//
// Hank Childs, Tue Oct 30 16:27:29 PST 2001
// Pushed code into a ReadDir routine.
//
// Hank Childs, Mon Mar 11 08:52:59 PST 2002
// Renamed to PopulateDatabaseMetaData.
//
// Jeremy Meredith, Tue Jul 15 09:44:15 PDT 2003
// Split some of the methods out of ReadDir so it could be
// parallelized.
//
// Mark C. Miller, Thu Mar 18 11:00:38 PST 2004
// Added call to set cycle/time
//
// Jeremy Meredith, Thu Mar 25 16:52:04 EDT 2010
// Error if we openend a file with nothing in it to prevent false
// positives when detecting Silo files. Happens only in strict mode.
//
// ****************************************************************************
void
avtSiloFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
{
DBfile *dbfile = OpenFile(tocIndex);
//
// Sub-vars from a multi-var are defined on the sub-meshes of a multi-mesh.
// To figure out which multi-mesh a multi-var is defined on, we need to
// determine it from the sub-vars. This array stores the names of the
// first sub-meshes so the sub-vars can check against them later.
//
firstSubMesh.clear();
actualMeshName.clear();
blocksForMesh.clear();
//
// We're just interested in metadata for now, so tell Silo not
// to read the extra data arrays, except for material names and
// numbers and colors.
//
DBSetDataReadMask(DBMatMatnames|DBMatMatnos|DBMatMatcolors);
//
// Do a recursive search through the subdirectories.
//
ReadDir(dbfile, topDir.c_str(), md);
BroadcastGlobalInfo(md);
DoRootDirectoryWork(md);
//
// Set time/cycle information
//
GetTimeVaryingInformation(dbfile, md);
// To be nice to other functions, tell Silo to turn back on reading all
// of the data.
DBSetDataReadMask(DBAll);
// If we got nothing, it may be that this was a PDB file or
// an HDF5 file, for example, but not really a Silo file.
if (GetStrictMode() &&
md->GetNumMeshes() == 0 &&
md->GetNumCurves() == 0)
{
EXCEPTION1(InvalidFilesException, filenames[0]);
}
}
// ****************************************************************************
// Methods for reading information about different classes of Silo objects.
//
// This comment block is kept here for legacy reasons as it contains
// information prior to re-factoring of avtSiloFileFormat::ReadDir(). Most
// of the meat of that function was re-factored into the ReadXXX() methods,
// below, one for each class of Silo object.
//
// DO NOT ADD ANY COMMENTS TO THIS BLOCK.
//
// Modifications:
// Jeremy Meredith, Wed Nov 21 14:11:35 PST 2001
// Fixed the logic so the structured domain boundary info works with
// more file types.
//
// Eric Brugger, Tue Nov 27 16:21:17 PST 2001
// I modified the routine to only search directories in _meshtv_searchpath
// if present.
//
// Hank Childs, Mon Dec 3 09:55:54 PST 2001
// Do not read in boundary information if we are only going to serve up
// meta-data.
//
// Eric Brugger, Tue Dec 4 15:05:56 PST 2001
// I modified the routine to read an alternate representation of the
// domain connectivity for a 3d structured mesh. If the alternate
// representation is present it uses it instead of the normal one. I
// also corrected a bug setting the extents for ucd meshes.
//
// Jeremy Meredith, Thu Dec 13 11:46:06 PST 2001
// Fixed a bug with the reading of 3d structured connectivity.
//
// Jeremy Meredith, Tue Dec 18 15:40:05 PST 2001
// Added multi-species support. Renamed individual species so they are
// one-origin.
//
// Hank Childs, Fri Jan 4 10:44:44 PST 2002
// Fix UMR.
//
// Jeremy Meredith, Thu Jan 17 10:44:33 PST 2002
// Reworked the interdomain connectivity reading. Now in parallel only
// the first processor reads it and then broadcasts it to the other
// processors. This can be a big speedup.
//
// Sean Ahern, Fri Feb 8 11:44:55 PST 2002
// Added support for material names. Also got rid of all but one
// GetComponent calls.
//
// Jeremy Meredith, Mon Feb 25 14:26:35 PST 2002
// Added code to make sure the assumed directories exist when reading
// interdomain connectivity. Some files use a different naming scheme.
//
// Hank Childs, Mon Apr 15 09:13:51 PDT 2002
// Add support for distributed Silo files. This used to happen
// automatically, but there have been some changes to DBGetComponent.
//
// Hank Childs, Mon Apr 15 14:45:53 PDT 2002
// Explicitly check if a directory exists rather than issuing a DBSetDir.
// This will clean up our log files.
//
// Hank Childs, Wed Apr 17 12:11:04 PDT 2002
// Add ENDTRY (this only breaks when we are using fake exceptions).
//
// Hank Childs, Sun Jun 16 19:55:52 PDT 2002
// Initialize the cell origin.
//
// Hank Childs, Mon Jun 24 12:45:09 PDT 2002
// Add support for groups.
//
// Hank Childs, Fri Jul 12 16:33:56 PDT 2002
// Added current directory name to directory tracking routines to better
// support multi-vars that have relative pathnames.
//
// Hank Childs, Sun Aug 18 11:53:02 PDT 2002
// Added support for meshes that are made up of all disjoint elements.
//
// Hank Childs, Wed Sep 4 16:43:34 PDT 2002
// Added a call to parse the defvars and put them in the meta-data object.
//
// Hank Childs, Fri Sep 27 14:58:14 PDT 2002
// Added support for mesh units.
//
// Kathleen Bonnell, Wed Oct 23 13:55:55 PDT 2002
// Added tdims, so that topological dimension for multi-point-meshes will
// be set correctly.
//
// Hank Childs, Fri Oct 25 15:44:28 PDT 2002
// Fix a bug where the topological dimension was not being set correctly,
// causing the facelist filter to not execute.
//
// Hank Childs, Tue Nov 12 09:50:12 PST 2002
// If a multi-mesh is located in a sub-directory, name the multi-mesh with
// the subdirectory name.
//
// Hank Childs, Tue Dec 10 12:43:46 PST 2002
// Do not give up on invalid variables. Just mark them as invalid.
//
// Jeremy Meredith, Wed Mar 19 12:26:35 PST 2003
// Added extra information needed to allow multivars defined on only
// some domains of its associated multimesh.
//
// Hank Childs, Thu Apr 10 08:45:44 PDT 2003
// Do not parse the defvars or read in the connectivity information, since
// that is now done when the file is opened (because ReadDir is not always
// called).
//
// Hank Childs, Tue May 6 18:16:40 PDT 2003
// Some calls were being made in every pass of ReadDir, although they were
// only necessary in the first pass. Also only register the domain
// directories for multi-meshes (the MeshTV method).
//
// Hank Childs, Fri May 16 18:21:20 PDT 2003
// Make sure that all return values are valid.
//
// Jeremy Meredith, Tue Jul 15 09:44:15 PDT 2003
// Split some of the methods out of ReadDir so it could be
// parallelized. Only allow the first process to read the root file.
//
// Hank Childs, Fri Sep 12 14:48:33 PDT 2003
// Allow for '0' to be a valid material.
//
// Jeremy Meredith, Wed Oct 15 17:04:33 PDT 2003
// Fixed up the multi-species check to "fail correctly" if the actual
// species object did not actually exist in the file.
// Also, added a workaround for a Silo bug where it will crash instead
// of returning NULL from DBGetMatspecies if you have registered a
// callback function. This workaround should be removed if Silo gets
// fixed.
//
// Hank Childs, Mon Dec 1 15:05:43 PST 2003
// Look for visit_defvars first. Only if it does not exist, then look for
// meshtv_defvars.
//
// Hank Childs, Wed Jan 14 11:19:24 PST 2004
// Use caching mechanism for DBGetMultiThing.
//
// Jeremy Meredith, Fri Jun 11 14:36:59 PDT 2004
// Fixed two problems with _meshtv_searchpath. First, it assumed there was
// at most one entry per semicolon, but you can have one less separator
// than num entries. Second, it was walking off the end of the string.
//
// Kathleen Bonnell, Thu Jul 22 12:30:22 PDT 2004
// Use value of ascii_labels option for variables to set treatAsASCII
// in ScalarMetaData.
//
// Brad Whitlock, Tue Jul 20 15:48:04 PST 2004
// Added support for passing the variable units back up to VisIt via
// the metadata. I also added support for labels and a database comment.
//
// Jeremy Meredith, Tue Jun 7 08:32:46 PDT 2005
// Added support for "EMPTY" domains in multi-objects.
//
// Mark C. Miller, Wed Jun 29 08:49:14 PDT 2005
// Made it NOT throw an exception if first non-empty mesh is invalid
//
// Mark C. Miller, Wed Aug 10 08:15:21 PDT 2005
// Added code to handle Silo's new defvars objects
//
// Eric Brugger, Fri Aug 12 08:28:04 PDT 2005
// Modified the handling of multi-meshes with all EMPTY blocks to
// avoid a crash.
//
// Eric Brugger, Fri Aug 12 11:36:35 PDT 2005
// Corrected a memory leak.
//
// Hank Childs, Fri Aug 19 08:31:47 PDT 2005
// Corrected another memory leak.
//
// Jeremy Meredith, Thu Aug 25 11:35:32 PDT 2005
// Added group origin to mesh metadata constructor.
//
// Mark C. Miller, Mon Sep 26 14:05:52 PDT 2005
// Added code to query for AlphabetizeVariables
//
// Jeremy Meredith, Fri Oct 7 17:08:21 PDT 2005
// Added VARTYPE to defvar defines to avoid namespace conflict.
//
// Mark C. Miller, Fri Nov 11 09:45:42 PST 2005
// Made it more fault tolerant when multimats are corrupted
//
// Mark C. Miller, Wed Nov 16 10:46:36 PST 2005
// Removed spoofing of CSG mesh as a surface mesh
//
// Mark C. Miller, Wed Jan 18 19:58:47 PST 2006
// Made it more fault tolerant for multivar, multimat and multimatspecies
// objects that contained all EMPTY pieces.
//
// Kathleen Bonnell, Wed Feb 8 09:41:45 PST 2006
// Set mmd->meshCoordType from coord_sys.
//
// Mark C. Miller, Thu Mar 2 00:03:40 PST 2006
// Added support for curve objects
//
// Hank Childs, Thu May 18 11:33:27 PDT 2006
// Fix UMR with mesh coord types and point meshes.
//
// Mark C. Miller, Thu Jul 13 22:41:56 PDT 2006
// Added reading of material colors, if available
//
// Mark C. Miller, Thu Jul 6 15:14:46 PDT 2006
// Fixed case where GetCsgmesh can return csgm but not csgm->zones
//
// Mark C. Miller, Wed Nov 29 15:08:21 PST 2006
// Set value for connectivityIsTimeVarying
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Removed all EXCEPTIONs from this routine except for NULL toc to make
// the plugin more fault tolerant. Added code to support multi-block CSG
// meshes
//
// Mark C. Miller, Wed Dec 13 16:55:30 PST 2006
// Added calls to RegisterDomainDirs to loops over multivars, multimats
// and multimatspecies
//
// Mark C. Miller, Wed Feb 6 12:27:09 PST 2008
// Changed DBSetDir("/") calls to use topDir instead. Changed interface
// to GenerateFileName to accept topDir too.
//
// Mark C. Miller, Mon Apr 14 15:41:21 PDT 2008
// Added setting of guiHide feature on many md objects.
// Added nodelist enumeration variables, when present42`
//
// Mark C. Miller, Wed Apr 23 12:08:56 PDT 2008
// Made material name parsing handle material names that point to NULL.
//
// Mark C. Miller, Tue Jun 10 22:36:25 PDT 2008
// Added logic to ignore data extents for block structured code
//
// Mark C. Miller, Tue Jul 29 18:16:59 PDT 2008
// Added logic to ensure _meshtv_defvars and _visit_defvars are indeed
// simple silo variables before reading them as such. This is to prevent
// situations where users have switched to using DBPutDefvars to create
// the same information but wind up also calling it the same thing.
//
// Brad Whitlock, Wed Sep 3 10:07:32 PDT 2008
// Prevent multimesh and multimat names from being printed when all entries
// are EMPTY since it was causing a crash (array out of bounds).
//
// Mark C. Miller, Tue Jan 6 22:11:33 PST 2009
// Added support for explicit specification of topological dimension of a
// ucd mesh from the database via the DBOPT_TOPO_DIM option.
//
// Mark C. Miller, Wed Feb 25 17:35:05 PST 2009
// Tightened logic for triggering ANNOTATION_INT nodelist search to ensure
// it happens only when ReadDir is in the root (topDir) directory. Also,
// Added a call to CloseFile(1) just prior to calling AddAnnotInt... as
// a work-around for a bug in HDF5.
//
// Mark C. Miller, Mon Mar 2 11:50:08 PST 2009
// Removed call to CloseFile(1) just prior to adding annot-int nodelists.
// The issue that addressed is now handled in the AddAnnotInt... routine.
//
// Mark C. Miller, Wed Mar 4 08:54:57 PST 2009
// Improved logic to handle ignoring of spatial/data extents so that user
// can override explicitly or let plugin handle automatically.
//
// Mark C. Miller, Wed Mar 4 13:39:58 PST 2009
// Backed out preceding change. It had backwards compatibility problems.
//
// Mark C. Miller, Fri Mar 20 04:38:56 PDT 2009
// Added logic to NOT descend to first non-EMPTY block of a multi-mat if
// the multi-mat appears to have enough information about the global
// material context (#mats, names and colors).
//
// Mark C. Miller, Tue Mar 24 11:46:22 PDT 2009
// Changed #if defined(SILO_VERSION_GE) && SILO_VERSION_GE(4,6,2) to nested
// #if statements. The former assumes short-circuit evaluation and not
// all C pre-processors apparently obey it.
//
// Mark C. Miller, Tue May 5 11:11:19 PDT 2009
// Changed level of info returned from MultiMatHasAllMatInfo necessary to
// skirt reading individual material object to 3 or greater. This fixes
// cases where material numbers are known at the multi-block level but
// all other material info is known only on the individual material blocks.
//
// Hank Childs, Mon May 25 11:07:17 PDT 2009
// Add support for Silo releases before 4.6.3.
//
// Mark C. Miller, Thu Jun 4 20:53:32 PDT 2009
// Added missing hideFromGUI support for several object types.
//
// Mark C. Miller, Tue Jun 16 18:20:18 PDT 2009
// Removed EXCEPTIONs from this function. PLEASE DON'T PUT ANY HERE. It
// can wind up making a whole file unuseable when only one object in the
// file is bad!
//
// Mark C. Miller, Wed Jun 17 10:39:48 PDT 2009
// Re-factored all of the loops over Silo objects into their own functions.
// This was done to easily wrap the loops in try/catch blocks so that
// Exceptions thrown below this function due to any single object being
// bad DO NOT result in invalidating the whole darn file.
//
// DO NOT ADD ANY MODIFICATIONS COMMENTS TO THIS BLOCK. SEE NOTE AT TOP.
// ****************************************************************************
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
// Modifications:
// Mark C. Miller, Thu Jun 18 20:55:49 PDT 2009
// Removed DBtoc* arg.
//
// Mark C. Miller, Tue Dec 15 14:01:48 PST 2009
// Added metadataIsTimeVarying
// ****************************************************************************
void
avtSiloFileFormat::ReadTopDirStuff(DBfile *dbfile, const char *dirname,
avtDatabaseMetaData *md, char **searchpath_strp)
{
TRY
{
//
// The dbfile will probably change, so read in the meshtv_defvars and
// meshtv_searchpath while we can.
//
char *searchpath_str = *searchpath_strp;
if (strcmp(dirname, topDir.c_str()) == 0)
{
codeNameGuess = GuessCodeNameFromTopLevelVars(dbfile);
// Decide whether or not to ignore data extents
if (ignoreDataExtentsAAN == Always)
ignoreDataExtents = true;
else if (ignoreDataExtentsAAN == Never)
ignoreDataExtents = false;
else // Auto
{
if (codeNameGuess == "BlockStructured")
ignoreDataExtents = true;
else if (codeNameGuess == "Ale3d")
ignoreDataExtents = true;
}
// Decide whether or not to ignore spatial extents
if (ignoreSpatialExtentsAAN == Always)
ignoreSpatialExtents = true;
else if (ignoreSpatialExtentsAAN == Never)
ignoreSpatialExtents = false;
else // Auto
{
// Nothing automaticly to do for sptail extents, yet
}
if (DBInqVarExists(dbfile, "ConnectivityIsTimeVarying"))
{
int tvFlag;
DBReadVar(dbfile, "ConnectivityIsTimeVarying", &tvFlag);
if (tvFlag == 1)
connectivityIsTimeVarying = true;
}
if (DBInqVarExists(dbfile, "MetadataIsTimeVarying"))
{
int mdFlag;
DBReadVar(dbfile, "MetadataIsTimeVarying", &mdFlag);
if (mdFlag == 1)
metadataIsTimeVarying = true;
}
if (DBInqVarExists(dbfile, "AlphabetizeVariables"))
{
int alphaFlag;
DBReadVar(dbfile, "AlphabetizeVariables", &alphaFlag);
if (alphaFlag == 0)
md->SetMustAlphabetizeVariables(false);
}
if (DBInqVarExists(dbfile, "_disjoint_elements"))
{
hasDisjointElements = true;
}
bool hadVisitDefvars = false;
if (DBInqVarExists(dbfile, "_visit_defvars") &&
DBInqVarType(dbfile, "_visit_defvars") == DB_VARIABLE)
{
int ldefvars = DBGetVarLength(dbfile, "_visit_defvars");
if (ldefvars > 0)
{
char *defvar_str = new char[ldefvars+1];
for (int i = 0 ; i < ldefvars+1 ; i++)
{
defvar_str[i] = '\0';
}
DBReadVar(dbfile, "_visit_defvars", defvar_str);
AddDefvars(defvar_str, md);
delete [] defvar_str;
}
hadVisitDefvars = true;
}
if (!hadVisitDefvars && DBInqVarExists(dbfile, "_meshtv_defvars") &&
DBInqVarType(dbfile, "_meshtv_defvars") == DB_VARIABLE)
{
int ldefvars = DBGetVarLength(dbfile, "_meshtv_defvars");
if (ldefvars > 0)
{
char *defvar_str = new char[ldefvars+1];
for (int i = 0 ; i < ldefvars+1 ; i++)
{
defvar_str[i] = '\0';
}
DBReadVar(dbfile, "_meshtv_defvars", defvar_str);
AddDefvars(defvar_str, md);
delete [] defvar_str;
}
}
if (DBInqVarExists(dbfile, "_meshtv_searchpath"))
{
int lsearchpath = DBGetVarLength(dbfile, "_meshtv_searchpath");
if (lsearchpath > 0)
{
searchpath_str = new char[lsearchpath+1];
DBReadVar(dbfile, "_meshtv_searchpath", searchpath_str);
}
}
if (DBInqVarExists(dbfile, "_fileinfo"))
{
int lfileinfo = DBGetVarLength(dbfile, "_fileinfo");
if (lfileinfo > 0)
{
char *fileinfo_str = new char[lfileinfo+1];
DBReadVar(dbfile, "_fileinfo", fileinfo_str);
md->SetDatabaseComment(fileinfo_str);
delete [] fileinfo_str;
}
}
}
}
CATCHALL
{
debug1 << "Giving up on top-level directory miscellaneous stuff" << endl;
}
ENDTRY
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names. Also added logic to
// handle freeing of multimesh object during exceptions.
//
// Cyrus Harrison, Tue Oct 13 08:59:59 PDT 2009
// Construct avtMeshMetaData object after mrgtree processing b/c this
// may change the mesh type to indicate an AMR mesh.
//
// Mark C. Miller, Mon Nov 9 10:41:48 PST 2009
// Added 'dontForceSingle' to call to HandleMrgtree
//
// Cyrus Harrison, Wed Mar 24 10:41:20 PDT 2010
// Set haveAmrGroupInfo if we have amr level info.
//
// ****************************************************************************
void
avtSiloFileFormat::ReadMultimeshes(DBfile *dbfile,
int nmultimesh, char **multimesh_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i;
map<string, bool> haveAddedNodelistEnumerations;
for (i = 0 ; i < nmultimesh ; i++)
{
char *name_w_dir = 0;
DBmultimesh *mm = 0;
TRY
{
name_w_dir = GenerateName(dirname, multimesh_names[i], topDir.c_str());
bool valid_var = true;
int silo_mt = -1;
int meshnum = 0;
mm = GetMultimesh(dirname, multimesh_names[i]);
if (mm)
{
RegisterDomainDirs(mm->meshnames, mm->nblocks, dirname);
// Find the first non-empty mesh
while (string(mm->meshnames[meshnum]) == "EMPTY")
{
meshnum++;
if (meshnum >= mm->nblocks)
{
debug1 << "Invalidating mesh \"" << multimesh_names[i]
<< "\" since all its blocks are EMPTY." << endl;
valid_var = false;
break;
}
}
if (valid_var)
silo_mt = GetMeshtype(dbfile, mm->meshnames[meshnum]);
}
else
{
debug1 << "Invalidating mesh \"" << multimesh_names[i] << "\"" << endl;
valid_var = false;
}
//
// CSG meshes require special handling because we use CSG
// "regions" in place of VisIt's notion of "domains" and the
// pieces of the multi-mesh as VisIt's "groups."
//
if (silo_mt == DB_CSGMESH)
{
AddCSGMultimesh(dirname, multimesh_names[i], md, mm, dbfile);
}
else
{
avtMeshType mt = AVT_UNKNOWN_MESH;
avtMeshCoordType mct = AVT_XY;
int ndims;
int tdims;
int cellOrigin;
int groupOrigin = 0;
string xUnits, yUnits, zUnits;
string xLabel, yLabel, zLabel;
switch (silo_mt)
{
case DB_UCDMESH:
{
mt = AVT_UNSTRUCTURED_MESH;
char *realvar;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(mm->meshnames[meshnum], correctFile,
0, realvar);
DBucdmesh *um = DBGetUcdmesh(correctFile, realvar);
if (um == NULL)
{
debug1 << "Invalidating mesh \"" << multimesh_names[i]
<< "\" since its first non-empty block (" << mm->meshnames[meshnum]
<< ") is invalid." << endl;
break;
}
ndims = um->ndims;
tdims = ndims;
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,1)
if (um->topo_dim != -1)
tdims = um->topo_dim;
#endif
#endif
cellOrigin = um->origin;
if (um->units[0] != NULL)
xUnits = um->units[0];
if (um->units[1] != NULL)
yUnits = um->units[1];
if (um->units[2] != NULL)
zUnits = um->units[2];
if (um->labels[0] != NULL)
xLabel = um->labels[0];
if (um->labels[1] != NULL)
yLabel = um->labels[1];
if (um->labels[2] != NULL)
zLabel = um->labels[2];
if (ndims ==2 && um->coord_sys == DB_CYLINDRICAL)
mct = AVT_RZ;
else
mct = AVT_XY;
DBFreeUcdmesh(um);
}
break;
case DB_POINTMESH:
{
mt = AVT_POINT_MESH;
char *realvar;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(mm->meshnames[meshnum], correctFile,
0, realvar);
DBpointmesh *pm = DBGetPointmesh(correctFile, realvar);
if (pm == NULL)
{
debug1 << "Invalidating mesh \"" << multimesh_names[i]
<< "\" since its first non-empty block (" << mm->meshnames[meshnum]
<< ") is invalid." << endl;
break;
}
ndims = pm->ndims;
tdims = 0;
cellOrigin = pm->origin;
if (pm->units[0] != NULL)
xUnits = pm->units[0];
if (pm->units[1] != NULL)
yUnits = pm->units[1];
if (pm->units[2] != NULL)
zUnits = pm->units[2];
if (pm->labels[0] != NULL)
xLabel = pm->labels[0];
if (pm->labels[1] != NULL)
yLabel = pm->labels[1];
if (pm->labels[2] != NULL)
zLabel = pm->labels[2];
DBFreePointmesh(pm);
}
break;
case DB_QUAD_RECT:
{
mt = AVT_RECTILINEAR_MESH;
char *realvar;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(mm->meshnames[meshnum], correctFile,
0, realvar);
DBquadmesh *qm = DBGetQuadmesh(correctFile, realvar);
if (qm == NULL)
{
debug1 << "Invalidating mesh \"" << multimesh_names[i]
<< "\" since its first non-empty block (" << mm->meshnames[meshnum]
<< ") is invalid." << endl;
break;
}
ndims = qm->ndims;
tdims = ndims;
cellOrigin = qm->origin;
if (qm->units[0] != NULL)
xUnits = qm->units[0];
if (qm->units[1] != NULL)
yUnits = qm->units[1];
if (qm->units[2] != NULL)
zUnits = qm->units[2];
if (qm->labels[0] != NULL)
xLabel = qm->labels[0];
if (qm->labels[1] != NULL)
yLabel = qm->labels[1];
if (qm->labels[2] != NULL)
zLabel = qm->labels[2];
if (ndims ==2 && qm->coord_sys == DB_CYLINDRICAL)
mct = AVT_RZ;
else
mct = AVT_XY;
DBFreeQuadmesh(qm);
}
break;
case DB_QUAD_CURV:
{
mt = AVT_CURVILINEAR_MESH;
char *realvar;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(mm->meshnames[meshnum], correctFile,
0, realvar);
DBquadmesh *qm = DBGetQuadmesh(correctFile, realvar);
if (qm == NULL)
{
debug1 << "Invalidating mesh \"" << multimesh_names[i]
<< "\" since its first non-empty block (" << mm->meshnames[meshnum]
<< ") is invalid." << endl;
break;
}
ndims = qm->ndims;
tdims = ndims;
cellOrigin = qm->origin;
if (qm->units[0] != NULL)
xUnits = qm->units[0];
if (qm->units[1] != NULL)
yUnits = qm->units[1];
if (qm->units[2] != NULL)
zUnits = qm->units[2];
if (qm->labels[0] != NULL)
xLabel = qm->labels[0];
if (qm->labels[1] != NULL)
yLabel = qm->labels[1];
if (qm->labels[2] != NULL)
zLabel = qm->labels[2];
if (ndims ==2 && qm->coord_sys == DB_CYLINDRICAL)
mct = AVT_RZ;
else
mct = AVT_XY;
DBFreeQuadmesh(qm);
}
break;
default:
{
mt = AVT_UNKNOWN_MESH;
ndims = 0;
tdims = 0;
cellOrigin = 0;
}
break;
}
avtMeshMetaData *mmd = new avtMeshMetaData(name_w_dir,
mm?mm->nblocks:0, mm?mm->blockorigin:0, cellOrigin,
groupOrigin, ndims, tdims, mt);
mmd->hideFromGUI = mm->guihide;
mmd->validVariable = valid_var;
mmd->groupTitle = "blocks";
mmd->groupPieceName = "block";
mmd->xUnits = xUnits;
mmd->yUnits = yUnits;
mmd->zUnits = zUnits;
mmd->xLabel = xLabel;
mmd->yLabel = yLabel;
mmd->zLabel = zLabel;
mmd->meshCoordType = mct;
//
// Handle mrgtree on the multimesh
//
int num_amr_groups = 0;
vector<int> amr_group_ids;
vector<string> amr_block_names;
#ifndef WIN32
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,2)
if (mm->mrgtree_name != 0)
{
// So far, we've coded only for MRG trees representing AMR hierarchies
HandleMrgtreeForMultimesh(dbfile, mm, multimesh_names[i],
&mt, &num_amr_groups, &amr_group_ids, &amr_block_names,
dontForceSingle);
}
#endif
#endif
#endif
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,2)
if (mt == AVT_UNSTRUCTURED_MESH)
mmd->disjointElements = hasDisjointElements || mm->disjoint_mode != 0;
#else
if (mt == AVT_UNSTRUCTURED_MESH)
mmd->disjointElements = hasDisjointElements;
#endif
#else
if (mt == AVT_UNSTRUCTURED_MESH)
mmd->disjointElements = hasDisjointElements;
#endif
if (num_amr_groups > 0)
{
mmd->numGroups = num_amr_groups;
mmd->groupTitle = "levels";
mmd->groupPieceName = "level";
mmd->blockNames = amr_block_names;
mmd->meshType = AVT_AMR_MESH;
md->Add(mmd);
groupInfo.haveGroups = false;
// On the engine groupInfo.haveGroups may get changed when connectivty
// info is read. To avoid clobbering amr group info we set haveAmrGroupInfo
// to true to guard against md->AddGroupInformation getting called in
// DoRootDirectroyWork()
haveAmrGroupInfo = true;
md->AddGroupInformation(num_amr_groups, mm?mm->nblocks:0, amr_group_ids);
debug1 << "Using AMR levels as Group Information"<<endl;
}
else
{
md->Add(mmd);
}
//
// Handle special case for enumerated scalar rep for nodelists
//
if (codeNameGuess == "BlockStructured" &&
!haveAddedNodelistEnumerations[name_w_dir])
{
haveAddedNodelistEnumerations[name_w_dir] = true;
AddNodelistEnumerations(dbfile, md, name_w_dir);
}
else if (searchForAnnotInt && strcmp(dirname, topDir.c_str()) == 0)
{
AddAnnotIntNodelistEnumerations(dbfile, md, name_w_dir, mm);
}
// Store off the important info about this multimesh
// so we can match other multi-objects to it later
StoreMultimeshInfo(dirname, name_w_dir, meshnum, mm);
}
}
CATCHALL
{
// We explicitly free the multimesh here in the catch block and NOT at
// the exit from this function because in 'normal' operation, the multimesh
// objects are actually cached by the plugin and free'd later.
if (mm)
{
// Make sure its removed from the plugin's cache, too.
RemoveMultimesh(mm);
DBFreeMultimesh(mm);
}
debug1 << "Invalidating multi-mesh \"" << multimesh_names[i] << "\"" << endl;
avtMeshMetaData *mmd = new avtMeshMetaData(name_w_dir,
0, 0, 0, 0, 0, 0, AVT_UNKNOWN_MESH);
mmd->validVariable = false;
md->Add(mmd);
}
ENDTRY
if (name_w_dir) delete [] name_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadQuadmeshes(DBfile *dbfile,
int nqmesh, char **qmesh_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i,j;
for (i = 0 ; i < nqmesh ; i++)
{
char *name_w_dir = 0;
DBquadmesh *qm = 0;
TRY
{
name_w_dir = GenerateName(dirname, qmesh_names[i], topDir.c_str());
char *realvar;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(qmesh_names[i], correctFile, 0, realvar);
qm = DBGetQuadmesh(correctFile, realvar);
if (qm == NULL)
{
valid_var = false;
qm = DBAllocQuadmesh(); // to fool code block below
}
avtMeshType mt;
switch (qm->coordtype)
{
case DB_QUAD_RECT:
mt = AVT_RECTILINEAR_MESH;
break;
case DB_QUAD_CURV:
mt = AVT_CURVILINEAR_MESH;
break;
default:
mt = AVT_UNKNOWN_MESH;
break;
}
double extents[6];
double *extents_to_use = NULL;
if (nTimesteps == 1 && valid_var)
{
if (qm->datatype == DB_DOUBLE)
{
double *min_extents_double = (double *) qm->min_extents;
double *max_extents_double = (double *) qm->max_extents;
for (j = 0 ; j < qm->ndims ; j++)
{
extents[2*j ] = min_extents_double[j];
extents[2*j + 1] = max_extents_double[j];
}
}
else
{
for (j = 0 ; j < qm->ndims ; j++)
{
extents[2*j ] = qm->min_extents[j];
extents[2*j + 1] = qm->max_extents[j];
}
}
extents_to_use = extents;
}
avtMeshMetaData *mmd = new avtMeshMetaData(extents_to_use,
name_w_dir, 1, 0,
qm->origin, 0,
qm->ndims, qm->ndims,
mt);
if (qm->units[0] != NULL)
mmd->xUnits = qm->units[0];
if (qm->units[1] != NULL)
mmd->yUnits = qm->units[1];
if (qm->units[2] != NULL)
mmd->zUnits = qm->units[2];
if (qm->labels[0] != NULL)
mmd->xLabel = qm->labels[0];
if (qm->labels[1] != NULL)
mmd->yLabel = qm->labels[1];
if (qm->labels[2] != NULL)
mmd->zLabel = qm->labels[2];
if (qm->ndims == 2 && qm->coord_sys == DB_CYLINDRICAL)
mmd->meshCoordType = AVT_RZ;
mmd->validVariable = valid_var;
mmd->groupTitle = "blocks";
mmd->groupPieceName = "block";
mmd->hideFromGUI = qm->guihide;
md->Add(mmd);
}
CATCHALL
{
debug1 << "Invalidating quad mesh \"" << qmesh_names[i] << "\"" << endl;
avtMeshMetaData *mmd = new avtMeshMetaData(name_w_dir,
0, 0, 0, 0, 0, 0, AVT_CURVILINEAR_MESH);
mmd->validVariable = false;
md->Add(mmd);
}
ENDTRY
if (name_w_dir) delete [] name_w_dir;
if (qm) DBFreeQuadmesh(qm);
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadUcdmeshes(DBfile *dbfile,
int nucdmesh, char **ucdmesh_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i,j;
for (i = 0 ; i < nucdmesh ; i++)
{
char *name_w_dir = 0;
DBucdmesh *um = 0;
TRY
{
name_w_dir = GenerateName(dirname, ucdmesh_names[i], topDir.c_str());
char *realvar;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(ucdmesh_names[i], correctFile, 0, realvar);
um = DBGetUcdmesh(correctFile, realvar);
if (um == NULL)
{
valid_var = false;
um = DBAllocUcdmesh(); // to fool code block below
}
double extents[6];
double *extents_to_use = NULL;
if (nTimesteps == 1 && valid_var)
{
if (um->datatype == DB_DOUBLE)
{
double *min_extents_double = (double *) um->min_extents;
double *max_extents_double = (double *) um->max_extents;
for (j = 0 ; j < um->ndims ; j++)
{
extents[2*j ] = min_extents_double[j];
extents[2*j + 1] = max_extents_double[j];
}
}
else
{
for (j = 0 ; j < um->ndims ; j++)
{
extents[2*j ] = um->min_extents[j];
extents[2*j + 1] = um->max_extents[j];
}
}
extents_to_use = extents;
}
// Handle data-specified topological dimension if its available
int tdims = um->ndims;
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,1)
if (um->topo_dim != -1)
tdims = um->topo_dim;
#endif
#endif
avtMeshMetaData *mmd = new avtMeshMetaData(extents_to_use, name_w_dir,
1, 0, um->origin, 0, um->ndims, tdims,
AVT_UNSTRUCTURED_MESH);
if (um->units[0] != NULL)
mmd->xUnits = um->units[0];
if (um->units[1] != NULL)
mmd->yUnits = um->units[1];
if (um->units[2] != NULL)
mmd->zUnits = um->units[2];
if (um->labels[0] != NULL)
mmd->xLabel = um->labels[0];
if (um->labels[1] != NULL)
mmd->yLabel = um->labels[1];
if (um->labels[2] != NULL)
mmd->zLabel = um->labels[2];
if (um->ndims == 2 && um->coord_sys == DB_CYLINDRICAL)
mmd->meshCoordType = AVT_RZ;
mmd->groupTitle = "blocks";
mmd->groupPieceName = "block";
mmd->disjointElements = hasDisjointElements;
mmd->validVariable = valid_var;
mmd->hideFromGUI = um->guihide;
md->Add(mmd);
}
CATCHALL
{
debug1 << "Invalidating ucd mesh \"" << ucdmesh_names[i] << "\"" << endl;
avtMeshMetaData *mmd = new avtMeshMetaData(name_w_dir,
0, 0, 0, 0, 0, 0, AVT_UNSTRUCTURED_MESH);
mmd->validVariable = false;
md->Add(mmd);
}
ENDTRY
if (um) DBFreeUcdmesh(um);
if (name_w_dir) delete [] name_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadPointmeshes(DBfile *dbfile,
int nptmesh, char **ptmesh_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i;
for (i = 0 ; i < nptmesh ; i++)
{
char *name_w_dir = 0;
DBpointmesh *pm = 0;
TRY
{
name_w_dir = GenerateName(dirname, ptmesh_names[i], topDir.c_str());
char *realvar;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(ptmesh_names[i], correctFile, 0, realvar);
pm = DBGetPointmesh(correctFile, realvar);
if (pm == NULL)
{
valid_var = false;
pm = DBAllocPointmesh(); // to fool code block below
}
avtMeshMetaData *mmd = new avtMeshMetaData(name_w_dir, 1, 0,pm->origin,
0, pm->ndims, 0, AVT_POINT_MESH); mmd->groupTitle = "blocks";
mmd->hideFromGUI = pm->guihide;
mmd->groupPieceName = "block";
mmd->validVariable = valid_var;
if (pm->units[0] != NULL)
mmd->xUnits = pm->units[0];
if (pm->units[1] != NULL)
mmd->yUnits = pm->units[1];
if (pm->units[2] != NULL)
mmd->zUnits = pm->units[2];
if (pm->labels[0] != NULL)
mmd->xLabel = pm->labels[0];
if (pm->labels[1] != NULL)
mmd->yLabel = pm->labels[1];
if (pm->labels[2] != NULL)
mmd->zLabel = pm->labels[2];
md->Add(mmd);
}
CATCHALL
{
debug1 << "Invalidating point mesh \"" << ptmesh_names[i] << "\"" << endl;
avtMeshMetaData *mmd = new avtMeshMetaData(name_w_dir,
0, 0, 0, 0, 0, 0, AVT_POINT_MESH);
mmd->validVariable = false;
md->Add(mmd);
}
ENDTRY
if (pm) DBFreePointmesh(pm);
if (name_w_dir) delete [] name_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadCurves(DBfile *dbfile,
int ncurves, char **curve_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i;
for (i = 0 ; i < ncurves; i++)
{
char *name_w_dir = 0;
DBcurve *cur = 0;
TRY
{
name_w_dir = GenerateName(dirname, curve_names[i], topDir.c_str());
char *realvar;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(curve_names[i], correctFile, 0, realvar);
cur = DBGetCurve(correctFile, realvar);
if (cur == NULL)
{
valid_var = false;
cur = DBAllocCurve(); // to fool code block below
}
avtCurveMetaData *cmd = new avtCurveMetaData(name_w_dir);
if (cur->xlabel != NULL)
cmd->xLabel = cur->xlabel;
if (cur->ylabel != NULL)
cmd->yLabel = cur->ylabel;
if (cur->xunits != NULL)
cmd->xUnits = cur->xunits;
if (cur->yunits != NULL)
cmd->yUnits = cur->yunits;
cmd->validVariable = valid_var;
cmd->hideFromGUI = cur->guihide;
md->Add(cmd);
}
CATCHALL
{
debug1 << "Invalidating curve \"" << curve_names[i] << "\"" << endl;
avtCurveMetaData *cmd = new avtCurveMetaData(name_w_dir);
cmd->validVariable = false;
md->Add(cmd);
}
ENDTRY
if (cur) DBFreeCurve(cur);
if (name_w_dir) delete [] name_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadCSGmeshes(DBfile *dbfile,
int ncsgmesh, char **csgmesh_names,
const char *dirname, avtDatabaseMetaData *md)
{
#ifdef DBCSG_INNER
int i,j;
for (i = 0 ; i < ncsgmesh ; i++)
{
char *name_w_dir = 0;
DBcsgmesh *csgm = 0;
TRY
{
name_w_dir = GenerateName(dirname, csgmesh_names[i], topDir.c_str());
char *realvar;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(csgmesh_names[i], correctFile, 0, realvar);
// We want to read the header for the csg zonelist too
// so we can serve up the "zones" of a csg mesh as "blocks"
long mask = DBGetDataReadMask();
DBSetDataReadMask(mask|DBCSGMZonelist|DBCSGZonelistZoneNames);
csgm = DBGetCsgmesh(correctFile, realvar);
DBSetDataReadMask(mask);
if (csgm == NULL || csgm->zones == NULL)
{
debug1 << "Unable to read mesh \"" << csgmesh_names[i]
<< "\". Skipping it" << endl;
valid_var = false;
csgm = DBAllocCsgmesh();
csgm->zones = DBAllocCSGZonelist();
}
double extents[6];
double *extents_to_use = NULL;
if (!((csgm->min_extents[0] == 0.0 && csgm->max_extents[0] == 0.0 &&
csgm->min_extents[1] == 0.0 && csgm->max_extents[1] == 0.0 &&
csgm->min_extents[2] == 0.0 && csgm->max_extents[2] == 0.0) ||
(csgm->min_extents[0] == -DBL_MAX && csgm->max_extents[0] == DBL_MAX &&
csgm->min_extents[1] == -DBL_MAX && csgm->max_extents[1] == DBL_MAX &&
csgm->min_extents[2] == -DBL_MAX && csgm->max_extents[2] == DBL_MAX)))
{
for (j = 0 ; j < csgm->ndims ; j++)
{
extents[2*j ] = csgm->min_extents[j];
extents[2*j + 1] = csgm->max_extents[j];
}
extents_to_use = extents;
}
avtMeshMetaData *mmd = new avtMeshMetaData(extents_to_use, name_w_dir,
csgm->zones->nzones, 0, csgm->origin, 0,
csgm->ndims, csgm->ndims, AVT_CSG_MESH);
if (csgm->units[0] != NULL)
mmd->xUnits = csgm->units[0];
if (csgm->units[1] != NULL)
mmd->yUnits = csgm->units[1];
if (csgm->units[2] != NULL)
mmd->zUnits = csgm->units[2];
if (csgm->labels[0] != NULL)
mmd->xLabel = csgm->labels[0];
if (csgm->labels[1] != NULL)
mmd->yLabel = csgm->labels[1];
if (csgm->labels[2] != NULL)
mmd->zLabel = csgm->labels[2];
mmd->blockTitle = "regions";
mmd->validVariable = valid_var;
mmd->hideFromGUI = csgm->guihide;
if (csgm->zones->zonenames)
{
vector<string> znames;
for (j = 0; j < csgm->zones->nzones; j++)
znames.push_back(csgm->zones->zonenames[j]);
mmd->blockNames = znames;
}
md->Add(mmd);
}
CATCHALL
{
debug1 << "Invalidating csg mesh \"" << csgmesh_names[i] << "\"" << endl;
avtMeshMetaData *mmd = new avtMeshMetaData(name_w_dir,
0, 0, 0, 0, 0, 0, AVT_CSG_MESH);
mmd->validVariable = false;
md->Add(mmd);
}
ENDTRY
if (csgm) DBFreeCsgmesh(csgm);
if (name_w_dir) delete [] name_w_dir;
}
#endif
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names. Also added logic to
// handle freeing of multivar during exceptions.
// ****************************************************************************
void
avtSiloFileFormat::ReadMultivars(DBfile *dbfile,
int nmultivar, char **multivar_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i;
for (i = 0 ; i < nmultivar ; i++)
{
char *name_w_dir = 0;
DBmultivar *mv = 0;
TRY
{
name_w_dir = GenerateName(dirname, multivar_names[i], topDir.c_str());
string meshname;
int meshnum = 0;
bool valid_var = true;
mv = GetMultivar(dirname, multivar_names[i]);
if (mv != NULL)
{
RegisterDomainDirs(mv->varnames, mv->nvars, dirname);
// Find the first non-empty mesh
while (string(mv->varnames[meshnum]) == "EMPTY")
{
meshnum++;
if (meshnum >= mv->nvars)
{
debug1 << "Invalidating variable \"" << multivar_names[i]
<< "\" since all its blocks are EMPTY." << endl;
valid_var = false;
break;
}
}
if (valid_var)
{
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,2)
if (mv->mmesh_name != 0)
{
meshname = mv->mmesh_name;
debug5 << "Variable \"" << multivar_names[i]
<< "\" indicates it is defined on mesh \""
<< meshname.c_str() << "\"" << endl;
}
else
#endif
#endif
{
// NOTE: There is an explicit assumption that the corresponding
// multimesh has already been read. Thus it must reside
// in the same directory (or a previously read one) as
// this variable.
meshname = DetermineMultiMeshForSubVariable(dbfile,
multivar_names[i], mv->varnames, mv->nvars, dirname);
debug5 << "Guessing variable \"" << multivar_names[i]
<< "\" is defined on mesh \""
<< meshname.c_str() << "\"" << endl;
}
}
}
else
{
debug1 << "Invalidating var \"" << multivar_names[i] << "\"" << endl;
valid_var = false;
}
//
// Get the centering and dimension information.
//
avtCentering centering;
bool treatAsASCII = false;
char *realvar = NULL;
DBfile *correctFile = dbfile;
string varUnits;
int nvals = 1;
if (valid_var)
{
DetermineFileAndDirectory(mv->varnames[meshnum], correctFile, 0, realvar);
switch (mv->vartypes[meshnum])
{
case DB_UCDVAR:
{
DBucdvar *uv = NULL;
uv = DBGetUcdvar(correctFile, realvar);
if (uv == NULL)
{
valid_var = false;
break;
}
centering = (uv->centering == DB_ZONECENT ? AVT_ZONECENT
: AVT_NODECENT);
nvals = uv->nvals;
treatAsASCII = (uv->ascii_labels);
if(uv->units != 0)
varUnits = string(uv->units);
DBFreeUcdvar(uv);
}
break;
case DB_QUADVAR:
{
DBquadvar *qv = DBGetQuadvar(correctFile, realvar);
if (qv == NULL)
{
valid_var = false;
break;
}
centering = (qv->align[0] == 0. ? AVT_NODECENT
: AVT_ZONECENT);
nvals = qv->nvals;
treatAsASCII = (qv->ascii_labels);
if(qv->units != 0)
varUnits = string(qv->units);
DBFreeQuadvar(qv);
}
break;
case DB_POINTVAR:
{
centering = AVT_NODECENT; // Only one possible
DBmeshvar *pv = DBGetPointvar(correctFile, realvar);
if (pv == NULL)
{
valid_var = false;
break;
}
nvals = pv->nvals;
treatAsASCII = (pv->ascii_labels);
if(pv->units != 0)
varUnits = string(pv->units);
DBFreeMeshvar(pv);
}
break;
#ifdef DBCSG_INNER
case DB_CSGVAR:
{
DBcsgvar *csgv = DBGetCsgvar(correctFile, realvar);
centering = csgv->centering == DB_BNDCENT ? AVT_NODECENT
: AVT_ZONECENT;
if (csgv == NULL)
{
valid_var = false;
break;
}
nvals = csgv->nvals;
treatAsASCII = (csgv->ascii_labels);
if(csgv->units != 0)
varUnits = string(csgv->units);
DBFreeCsgvar(csgv);
}
break;
#endif
default:
; // No-op. Compiler complains about a break here.
}
}
if (nvals == 1)
{
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
meshname, centering);
smd->validVariable = valid_var;
smd->treatAsASCII = treatAsASCII;
smd->hideFromGUI = mv->guihide;
if(varUnits != "")
{
smd->hasUnits = true;
smd->units = varUnits;
}
//
// Handle special cases for enumerated variables
//
if (valid_var && codeNameGuess == "Ale3d" &&
strstr(multivar_names[i], "rlxstat") != 0)
AddAle3drlxstatEnumerationInfo(smd);
md->Add(smd);
}
else
{
avtVectorMetaData *vmd = new avtVectorMetaData(name_w_dir,
meshname, centering, nvals);
vmd->validVariable = valid_var;
vmd->hideFromGUI = mv->guihide;
if(varUnits != "")
{
vmd->hasUnits = true;
vmd->units = varUnits;
}
md->Add(vmd);
}
}
CATCHALL
{
// We explicitly free the multivar here and NOT at the end of this function
// because in 'normal' operation, the multivar gets cached during the
// GetMultivar() call, above, and free'd later.
if (mv)
{
// Make sure its removed from the plugin's cache, too.
RemoveMultivar(mv);
DBFreeMultivar(mv);
}
debug1 << "Invalidating multi-var \"" << multivar_names[i] << "\"" << endl;
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
"unknown", AVT_UNKNOWN_CENT);
smd->validVariable = false;
md->Add(smd);
}
ENDTRY
if (name_w_dir) delete [] name_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadQuadvars(DBfile *dbfile,
int nqvar, char **qvar_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i;
for (i = 0 ; i < nqvar ; i++)
{
char *name_w_dir = 0;
char *meshname_w_dir = 0;
DBquadvar *qv = 0;
TRY
{
name_w_dir = GenerateName(dirname, qvar_names[i], topDir.c_str());
char *realvar = NULL;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(qvar_names[i], correctFile, 0, realvar);
DBquadvar *qv = DBGetQuadvar(correctFile, realvar);
if (qv == NULL)
{
valid_var = false;
qv = DBAllocQuadvar();
}
char meshname[256];
DBInqMeshname(correctFile, realvar, meshname);
meshname_w_dir = GenerateName(dirname, meshname, topDir.c_str());
//
// Get the centering information.
//
avtCentering centering = (qv->align[0] == 0. ? AVT_NODECENT :
AVT_ZONECENT);
bool guiHide = qv->guihide;
//
// Get the dimension of the variable.
//
if (qv->nvals == 1)
{
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
meshname_w_dir, centering);
smd->treatAsASCII = (qv->ascii_labels);
smd->validVariable = valid_var;
smd->hideFromGUI = guiHide;
if(qv->units != 0)
{
smd->hasUnits = true;
smd->units = string(qv->units);
}
md->Add(smd);
}
else
{
avtVectorMetaData *vmd = new avtVectorMetaData(name_w_dir,
meshname_w_dir, centering, qv->nvals);
vmd->validVariable = valid_var;
vmd->hideFromGUI = guiHide;
if(qv->units != 0)
{
vmd->hasUnits = true;
vmd->units = string(qv->units);
}
md->Add(vmd);
}
}
CATCHALL
{
debug1 << "Invalidating quad var \"" << qvar_names[i] << "\"" << endl;
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
"unknown", AVT_UNKNOWN_CENT);
smd->validVariable = false;
md->Add(smd);
}
ENDTRY
if (qv) DBFreeQuadvar(qv);
if (name_w_dir) delete [] name_w_dir;
if (meshname_w_dir) delete [] meshname_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadUcdvars(DBfile *dbfile,
int nucdvar, char **ucdvar_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i;
for (i = 0 ; i < nucdvar ; i++)
{
char *name_w_dir = 0;
char *meshname_w_dir = 0;
DBucdvar *uv = 0;
TRY
{
name_w_dir = GenerateName(dirname, ucdvar_names[i], topDir.c_str());
char *realvar = NULL;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(ucdvar_names[i], correctFile, 0, realvar);
uv = DBGetUcdvar(correctFile, realvar);
if (uv == NULL)
{
valid_var = false;
uv = DBAllocUcdvar();
}
char meshname[256];
DBInqMeshname(correctFile, realvar, meshname);
//
// Get the centering information.
//
avtCentering centering = (uv->centering == DB_ZONECENT ? AVT_ZONECENT
: AVT_NODECENT);
bool guiHide = uv->guihide;
//
// Get the dimension of the variable.
//
meshname_w_dir = GenerateName(dirname, meshname, topDir.c_str());
if (uv->nvals == 1)
{
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
meshname_w_dir, centering);
smd->validVariable = valid_var;
smd->treatAsASCII = (uv->ascii_labels);
smd->hideFromGUI = guiHide;
if(uv->units != 0)
{
smd->hasUnits = true;
smd->units = string(uv->units);
}
md->Add(smd);
}
else
{
avtVectorMetaData *vmd = new avtVectorMetaData(name_w_dir,
meshname_w_dir, centering, uv->nvals);
vmd->validVariable = valid_var;
vmd->hideFromGUI = guiHide;
if(uv->units != 0)
{
vmd->hasUnits = true;
vmd->units = string(uv->units);
}
md->Add(vmd);
}
}
CATCHALL
{
debug1 << "Invalidating ucd var \"" << ucdvar_names[i] << "\"" << endl;
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
"unknown", AVT_UNKNOWN_CENT);
smd->validVariable = false;
md->Add(smd);
}
ENDTRY
if (uv) DBFreeUcdvar(uv);
if (name_w_dir) delete [] name_w_dir;
if (meshname_w_dir) delete [] meshname_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadPointvars(DBfile *dbfile,
int nptvar, char **ptvar_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i;
for (i = 0 ; i < nptvar ; i++)
{
char *name_w_dir = 0;
char *meshname_w_dir = 0;
DBmeshvar *pv = 0;
TRY
{
name_w_dir = GenerateName(dirname, ptvar_names[i], topDir.c_str());
char *realvar = NULL;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(ptvar_names[i], correctFile, 0, realvar);
pv = DBGetPointvar(correctFile, realvar);
if (pv == NULL)
{
valid_var = false;
pv = DBAllocMeshvar();
}
char meshname[256];
DBInqMeshname(correctFile, realvar, meshname);
//
// Get the dimension of the variable.
//
bool guiHide = pv->guihide;
meshname_w_dir = GenerateName(dirname, meshname, topDir.c_str());
if (pv->nvals == 1)
{
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
meshname_w_dir, AVT_NODECENT);
smd->treatAsASCII = (pv->ascii_labels);
smd->validVariable = valid_var;
smd->hideFromGUI = guiHide;
if(pv->units != 0)
{
smd->hasUnits = true;
smd->units = string(pv->units);
}
md->Add(smd);
}
else
{
avtVectorMetaData *vmd = new avtVectorMetaData(name_w_dir,
meshname_w_dir, AVT_NODECENT, pv->nvals);
vmd->validVariable = valid_var;
vmd->hideFromGUI = guiHide;
if(pv->units != 0)
{
vmd->hasUnits = true;
vmd->units = string(pv->units);
}
md->Add(vmd);
}
}
CATCHALL
{
debug1 << "Invalidating point var \"" << ptvar_names[i] << "\"" << endl;
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
"unknown", AVT_UNKNOWN_CENT);
smd->validVariable = false;
md->Add(smd);
}
ENDTRY
if (pv) DBFreeMeshvar(pv);
if (name_w_dir) delete [] name_w_dir;
if (meshname_w_dir) delete [] meshname_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadCSGvars(DBfile *dbfile,
int ncsgvar, char **csgvar_names,
const char *dirname, avtDatabaseMetaData *md)
{
#ifdef DBCSG_INNER
int i;
for (i = 0 ; i < ncsgvar ; i++)
{
char *name_w_dir = 0;
char *meshname_w_dir = 0;
DBcsgvar *csgv = 0;
TRY
{
name_w_dir = GenerateName(dirname, csgvar_names[i], topDir.c_str());
char *realvar = NULL;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(csgvar_names[i], correctFile, 0, realvar);
csgv = DBGetCsgvar(correctFile, realvar);
if (csgv == NULL)
{
valid_var = false;
csgv = DBAllocCsgvar();
}
char meshname[256];
DBInqMeshname(correctFile, realvar, meshname);
//
// Get the centering information.
//
// AVT doesn't have a 'boundary centering'. So, use node centering.
avtCentering centering = (csgv->centering == DB_BNDCENT ? AVT_NODECENT
: AVT_ZONECENT);
bool guiHide = csgv->guihide;
//
// Get the dimension of the variable.
//
meshname_w_dir = GenerateName(dirname, meshname, topDir.c_str());
if (csgv->nvals == 1)
{
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
meshname_w_dir, centering);
smd->treatAsASCII = (csgv->ascii_labels);
smd->validVariable = valid_var;
smd->hideFromGUI = guiHide;
if(csgv->units != 0)
{
smd->hasUnits = true;
smd->units = string(csgv->units);
}
md->Add(smd);
}
else
{
avtVectorMetaData *vmd = new avtVectorMetaData(name_w_dir,
meshname_w_dir, centering, csgv->nvals);
vmd->validVariable = valid_var;
vmd->hideFromGUI = guiHide;
if(csgv->units != 0)
{
vmd->hasUnits = true;
vmd->units = string(csgv->units);
}
md->Add(vmd);
}
}
CATCHALL
{
debug1 << "Invalidating csg var \"" << csgvar_names[i] << "\"" << endl;
avtScalarMetaData *smd = new avtScalarMetaData(name_w_dir,
"unknown", AVT_UNKNOWN_CENT);
smd->validVariable = false;
md->Add(smd);
}
ENDTRY
if (csgv) DBFreeCsgvar(csgv);
if (name_w_dir) delete [] name_w_dir;
if (meshname_w_dir) delete [] meshname_w_dir;
}
#endif
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
//
// Mark C. Miller, Wed Aug 26 11:09:29 PDT 2009
// Uncommented hidFromGUI setting.
// ****************************************************************************
void
avtSiloFileFormat::ReadMaterials(DBfile *dbfile,
int nmat, char **mat_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i,j;
for (i = 0 ; i < nmat ; i++)
{
char *name_w_dir = 0;
char *meshname_w_dir = 0;
DBmaterial *mat = 0;
TRY
{
name_w_dir = GenerateName(dirname, mat_names[i], topDir.c_str());
char *realvar = NULL;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(mat_names[i], correctFile, 0, realvar);
mat = DBGetMaterial(correctFile, realvar);
if (mat == NULL)
{
valid_var = false;
mat = DBAllocMaterial();
}
char meshname[256];
DBInqMeshname(correctFile, realvar, meshname);
//
// Give the materials names based on their material number. If
// they have names in the Silo file, use those as well.
//
vector<string> matnames;
vector<string> matcolors;
for (j = 0 ; j < mat->nmat ; j++)
{
//
// Deal with material names
//
char *num = NULL;
int dlen = int(log10(float(mat->matnos[j]+1))) + 1;
if (mat->matnames == NULL || mat->matnames[j] == NULL)
{
num = new char[dlen + 2];
sprintf(num, "%d", mat->matnos[j]);
}
else
{
int len = strlen(mat->matnames[j]);
num = new char[len + 1 + dlen + 1];
sprintf(num, "%d %s", mat->matnos[j], mat->matnames[j]);
}
matnames.push_back(num);
delete[] num;
//
// Deal with material colors
//
#ifdef DBOPT_MATCOLORS
if (mat->matcolors)
{
if (mat->matcolors[j] && mat->matcolors[j][0])
matcolors.push_back(mat->matcolors[j]);
else
matcolors.push_back("");
}
#endif
}
meshname_w_dir = GenerateName(dirname, meshname, topDir.c_str());
avtMaterialMetaData *mmd;
if (matcolors.size())
mmd = new avtMaterialMetaData(name_w_dir, meshname_w_dir,
mat->nmat, matnames, matcolors);
else
mmd = new avtMaterialMetaData(name_w_dir, meshname_w_dir,
mat->nmat, matnames);
mmd->validVariable = valid_var;
mmd->hideFromGUI = mat->guihide;
md->Add(mmd);
}
CATCHALL
{
debug1 << "Invalidating material \"" << mat_names[i] << "\"" << endl;
vector<string> no_matnames;
avtMaterialMetaData *mmd = new avtMaterialMetaData(name_w_dir, "unknown",
0, no_matnames);
mmd->validVariable = false;
md->Add(mmd);
}
ENDTRY
if (mat) DBFreeMaterial(mat);
if (name_w_dir) delete [] name_w_dir;
if (meshname_w_dir) delete [] meshname_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names. Also added logic to
// handle free of multimat during exceptions.
//
// Mark C. Miller, Wed Aug 26 11:09:55 PDT 2009
// Uncommented hideFromGUI setting.
//
// Cyrus Harrison, Tue Nov 24 14:05:28 PST 2009
// Added guard to avoid crash from unset material name.
//
// ****************************************************************************
void
avtSiloFileFormat::ReadMultimats(DBfile *dbfile,
int nmultimat, char **multimat_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i,j;
for (i = 0 ; i < nmultimat ; i++)
{
char *name_w_dir = 0;
DBmultimat *mm = 0;
DBmaterial *mat = 0;
TRY
{
name_w_dir = GenerateName(dirname, multimat_names[i], topDir.c_str());
bool valid_var = true;
mm = GetMultimat(dirname, multimat_names[i]);
if (mm == NULL)
{
valid_var = false;
mm = DBAllocMultimat(0);
}
RegisterDomainDirs(mm->matnames, mm->nmats, dirname);
char *material = NULL;
if (MultiMatHasAllMatInfo(mm) < 3)
{
// Find the first non-empty mesh
int meshnum = 0;
while (string(mm->matnames[meshnum]) == "EMPTY")
{
meshnum++;
if (meshnum >= mm->nmats)
{
debug1 << "Invalidating material \"" << multimat_names[i]
<< "\" since all its blocks are EMPTY." << endl;
valid_var = false;
break;
}
}
material = valid_var ? mm->matnames[meshnum] : NULL;
char *realvar = NULL;
DBfile *correctFile = dbfile;
if (valid_var)
{
DetermineFileAndDirectory(material, correctFile, 0, realvar);
mat = DBGetMaterial(correctFile, realvar);
}
if (mat == NULL)
{
debug1 << "Invalidating material \"" << multimat_names[i]
<< "\" since its first non-empty block ";
if(valid_var)
debug1 << "(" << material << ") ";
debug1 << "is invalid." << endl;
valid_var = false;
}
else
{
bool invalidateVar = false;
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
if (mm->nmatnos > 0 && mm->nmatnos != mat->nmat)
invalidateVar = true;
#endif
#endif
if (invalidateVar)
{
debug1 << "Invalidating material \"" << multimat_names[i]
<< "\" since its first non-empty block ";
if(valid_var)
debug1 << "(" << material << ") ";
debug1 << "has different # materials than its parent multimat." << endl;
valid_var = false;
}
}
}
else
{
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
// Spoof the material object for code block below so it contains
// all the info from the multi-mat.
mat = DBAllocMaterial();
mat->nmat = mm->nmatnos;
mat->matnos = mm->matnos;
mat->matnames = mm->material_names;
mat->matcolors = mm->matcolors;
#endif
#endif
}
//
// Give the materials names based on their material number. If
// there are names in the Silo file, use those as well.
//
vector<string> matnames;
vector<string> matcolors;
string meshname;
if (valid_var)
{
for (j = 0 ; j < mat->nmat ; j++)
{
char *num = NULL;
int dlen = int(log10(float(mat->matnos[j]+1))) + 1;
if (mat->matnames == NULL || mat->matnames[j] == NULL)
{
num = new char[dlen + 2];
sprintf(num, "%d", mat->matnos[j]);
}
else
{
int len = strlen(mat->matnames[j]);
num = new char[len + 1 + dlen + 1];
sprintf(num, "%d %s", mat->matnos[j], mat->matnames[j]);
}
matnames.push_back(num);
delete[] num;
#ifdef DBOPT_MATCOLORS
if (mat->matcolors)
{
if (mat->matcolors[j] && mat->matcolors[j][0])
matcolors.push_back(mat->matcolors[j]);
else
matcolors.push_back("");
}
#endif
}
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,2)
if (mm->mmesh_name != 0)
{
meshname = mm->mmesh_name;
debug5 << "Material \"" << multimat_names[i]
<< "\" indicates it is defined on mesh \""
<< meshname.c_str() << "\"" << endl;
}
else
#endif
#endif
{
meshname = DetermineMultiMeshForSubVariable(dbfile,
multimat_names[i],
mm->matnames,
mm->nmats, dirname);
debug5 << "Guessing material \"" << multimat_names[i]
<< "\" is defined on mesh \""
<< meshname.c_str() << "\"" << endl;
}
}
avtMaterialMetaData *mmd;
if (matcolors.size())
mmd = new avtMaterialMetaData(name_w_dir, meshname,
mat ? mat->nmat : 0, matnames,
matcolors);
else
mmd = new avtMaterialMetaData(name_w_dir, meshname,
mat ? mat->nmat : 0, matnames);
mmd->validVariable = valid_var;
mmd->hideFromGUI = mm->guihide;
md->Add(mmd);
if (MultiMatHasAllMatInfo(mm) >= 2)
{
// Remove everything we stuck into the spoof'd material object
// before moving on to DBFreeMaterial call.
mat->nmat = 0;
mat->matnos = 0;
mat->matnames = 0;
mat->matcolors = 0;
}
}
CATCHALL
{
// We explicitly free the multimat here and NOT at the end of the loop
// becaue in 'normal' operation, it gets cached during the GetMultimat()
// call and free'd later.
if (mm)
{
// Make sure its removed from the plugin's cache too.
RemoveMultimat(mm);
DBFreeMultimat(mm);
}
debug1 << "Giving up on multi-mat \"" << multimat_names[i] << "\"" << endl;
vector<string> no_matnames;
avtMaterialMetaData *mmd = new avtMaterialMetaData(name_w_dir, "unknown",
0, no_matnames);
mmd->validVariable = false;
md->Add(mmd);
}
ENDTRY
if (mat) DBFreeMaterial(mat);
if (name_w_dir) delete [] name_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadSpecies(DBfile *dbfile,
int nmatspecies, char **matspecies_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i,j,k;
for (i = 0 ; i < nmatspecies ; i++)
{
char *name_w_dir = 0;
char *meshname_w_dir = 0;
DBmatspecies *spec = 0;
TRY
{
name_w_dir = GenerateName(dirname, matspecies_names[i], topDir.c_str());
char *realvar = NULL;
DBfile *correctFile = dbfile;
bool valid_var = true;
DetermineFileAndDirectory(matspecies_names[i], correctFile, 0, realvar);
spec = DBGetMatspecies(correctFile, realvar);
if (spec == NULL)
{
valid_var = false;
spec = DBAllocMatspecies();
}
char meshname[256];
GetMeshname(dbfile, spec->matname, meshname);
vector<int> numSpecies;
vector<vector<string> > speciesNames;
for (j = 0 ; j < spec->nmat ; j++)
{
numSpecies.push_back(spec->nmatspec[j]);
vector<string> tmp_string_vector;
//
// Species do not currently have names, so just use their index.
//
for (k = 0 ; k < spec->nmatspec[j] ; k++)
{
char num[16];
sprintf(num, "%d", k+1);
tmp_string_vector.push_back(num);
}
speciesNames.push_back(tmp_string_vector);
}
meshname_w_dir = GenerateName(dirname, meshname, topDir.c_str());
avtSpeciesMetaData *smd = new avtSpeciesMetaData(name_w_dir,
meshname_w_dir, spec->matname, spec->nmat,
numSpecies, speciesNames);
//smd->hideFromGUI = spec->guihide;
md->Add(smd);
}
CATCHALL
{
debug1 << "Giving up on species \"" << matspecies_names[i] << "\"" << endl;
vector<vector<string> > no_matspecies_names;
vector<int> no_num_species;
avtSpeciesMetaData *smd = new avtSpeciesMetaData(name_w_dir,
"unknown", "unknown", 0, no_num_species, no_matspecies_names);
smd->validVariable = false;
md->Add(smd);
}
ENDTRY
if (spec) DBFreeMatspecies(spec);
if (name_w_dir) delete [] name_w_dir;
if (meshname_w_dir) delete [] meshname_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names. Also added logic to
// handle freeing of multimat species during exceptions.
// ****************************************************************************
void
avtSiloFileFormat::ReadMultispecies(DBfile *dbfile,
int nmultimatspecies, char **multimatspecies_names,
const char *dirname, avtDatabaseMetaData *md)
{
int i,j,k;
for (i = 0 ; i < nmultimatspecies ; i++)
{
char *name_w_dir = 0;
DBmultimatspecies *ms = 0;
DBmatspecies *spec = 0;
TRY
{
ms = GetMultimatspec(dirname, multimatspecies_names[i]);
if (ms == NULL)
{
char msg[256];
SNPRINTF(msg,sizeof(msg),"Unable to read multimat-species object \"%s\"",
multimatspecies_names[i]);
EXCEPTION1(SiloException,msg);
}
char *name_w_dir = GenerateName(dirname, multimatspecies_names[i], topDir.c_str());
RegisterDomainDirs(ms->specnames, ms->nspec, dirname);
// Find the first non-empty mesh
int meshnum = 0;
bool valid_var = true;
while (string(ms->specnames[meshnum]) == "EMPTY")
{
meshnum++;
if (meshnum >= ms->nspec)
{
debug1 << "Invalidating species \"" << multimatspecies_names[i]
<< "\" since all its blocks are EMPTY." << endl;
valid_var = false;
break;
}
}
string meshname;
if (valid_var)
{
// get the associated multimat
// We can only get this "matname" using GetComponent. It it not
// yet a part of the DBmultimatspec structure, so this is the only
// way we can get this info.
char *multimatName = (char *) GetComponent(dbfile,
multimatspecies_names[i], "matname");
// get the multimesh for the multimat
DBmultimat *mm = GetMultimat(dirname, multimatName);
if (mm == NULL)
{
valid_var = false;
}
else
{
char *material = mm->matnames[meshnum];
meshname = DetermineMultiMeshForSubVariable(dbfile,
multimatspecies_names[i],
mm->matnames,
ms->nspec, dirname);
// get the species info
char *species = ms->specnames[meshnum];
char *realvar = NULL;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(species, correctFile, 0, realvar);
DBShowErrors(DB_NONE, NULL);
spec = DBGetMatspecies(correctFile, realvar);
DBShowErrors(DB_ALL, ExceptionGenerator);
if (spec == NULL)
{
debug1 << "Giving up on species \"" << multimatspecies_names[i]
<< "\" since its first non-empty block (" << species
<< ") is invalid." << endl;
valid_var = false;
}
}
}
vector<int> numSpecies;
vector< vector<string> > speciesNames;
if (valid_var)
{
for (j = 0 ; j < spec->nmat ; j++)
{
numSpecies.push_back(spec->nmatspec[j]);
vector<string> tmp_string_vector;
for (k = 0 ; k < spec->nmatspec[j] ; k++)
{
char num[16];
sprintf(num, "%d", k+1);
tmp_string_vector.push_back(num);
}
speciesNames.push_back(tmp_string_vector);
}
}
avtSpeciesMetaData *smd;
if (valid_var)
smd = new avtSpeciesMetaData(name_w_dir,
meshname, spec->matname, spec->nmat,
numSpecies, speciesNames);
else
smd = new avtSpeciesMetaData(name_w_dir, "", "", 0,
numSpecies, speciesNames);
//smd->hideFromGUI = ms->guihide;
smd->validVariable = valid_var;
md->Add(smd);
}
CATCHALL
{
// We explicitly free the multimat species object here and NOT and
// the end of the loop because in 'normal' operation, the object
// is cached in the plugin and free'd later.
if (ms)
{
// Make sure it's removed from the plugin's cache, too.
RemoveMultimatspec(ms);
DBFreeMultimatspecies(ms);
}
debug1 << "Giving up on species \"" << multimatspecies_names[i] << "\"" << endl;
vector<vector<string> > no_matspecies_names;
vector<int> no_num_species;
avtSpeciesMetaData *smd = new avtSpeciesMetaData(name_w_dir,
"unknown", "unknown", 0, no_num_species, no_matspecies_names);
smd->validVariable = false;
md->Add(smd);
}
ENDTRY
if (spec) DBFreeMatspecies(spec);
if (name_w_dir) delete [] name_w_dir;
}
}
// ****************************************************************************
// Programmer: Mark C. Miller (re-factored here from ReadDir()
// Created: Wed Jun 17 10:42:42 PDT 2009
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:56:08 PDT 2009
// Replaced DBtoc* arg. with list of object names.
// ****************************************************************************
void
avtSiloFileFormat::ReadDefvars(DBfile *dbfile,
int ndefvars, char **defvars_names,
const char *dirname, avtDatabaseMetaData *md)
{
#ifdef DB_VARTYPE_SCALAR
int i,j;
for (i = 0; i < ndefvars; i++)
{
DBdefvars *defv = 0;
TRY
{
defv = DBGetDefvars(dbfile, defvars_names[i]);
if (defv == NULL)
{
char msg[256];
SNPRINTF(msg,sizeof(msg),"Unable to read defvars object \"%s\"",
defvars_names[i]);
EXCEPTION1(SiloException,msg);
}
for (int j = 0; j < defv->ndefs; j++)
{
Expression::ExprType vartype = Expression::Unknown;
switch (defv->types[j])
{
case DB_VARTYPE_SCALAR: vartype = Expression::ScalarMeshVar; break;
case DB_VARTYPE_VECTOR: vartype = Expression::VectorMeshVar; break;
case DB_VARTYPE_TENSOR: vartype = Expression::TensorMeshVar; break;
#ifdef DB_VARTYPE_ARRAY
case DB_VARTYPE_ARRAY: vartype = Expression::ArrayMeshVar; break;
case DB_VARTYPE_MATERIAL: vartype = Expression::Material; break;
case DB_VARTYPE_SPECIES: vartype = Expression::Species ; break;
#endif
default: vartype = Expression::Unknown; break;
}
if (vartype == Expression::Unknown)
{
debug5 << "Warning: unknown defvar type for derived "
<< "variable \"" << defv->names[j] << "\"" << endl;
}
else
{
Expression expr;
expr.SetName(defv->names[j]);
expr.SetDefinition(defv->defns[j]);
expr.SetType(vartype);
md->AddExpression(&expr);
}
}
}
CATCHALL
{
debug1 << "Giving up on defvars object \"" << defvars_names[i] << "\"" << endl;
}
ENDTRY
if (defv) DBFreeDefvars(defv);
}
#endif
}
// ****************************************************************************
// Method: avtSiloFileFormat::ReadDir
//
// Purpose:
// Get all of the variables from a directory.
//
// Arguments:
// dbfile The handle to the Silo file.
// dirname The name of the current directory.
// md The meta-data object to put information into.
//
// Programmer: Mark C. Miller (Re-factored from orig. of Hank Childs)
// Creation: June 18, 2009
//
// Modifications:
// Note: If you are looking for modification comments prior to re-factor,
// that whole block of comments was moved above all the individual
// ReadXXX() methods which precede this method.
//
// Mark C. Miller, Wed Aug 19 11:21:37 PDT 2009
// Reformatted with TOC_ENTRY macros to reduce size.
// ****************************************************************************
#define COPY_TOC_ENTRY(NM) \
int n ## NM = toc->n ## NM; \
char **NM ## _names = new char*[n ## NM]; \
for (i = 0 ; i < n ## NM; i++) \
{ \
NM ## _names[i] = new char[strlen(toc->NM ## _names[i])+1]; \
strcpy(NM ## _names[i], toc->NM ## _names[i]); \
}
#define FREE_COPIED_TOC_ENTRY(NM) \
for (i = 0 ; i < n ## NM; i++) \
{ \
delete [] NM ## _names[i]; \
} \
delete [] NM ## _names;
void
avtSiloFileFormat::ReadDir(DBfile *dbfile, const char *dirname,
avtDatabaseMetaData *md)
{
#ifdef PARALLEL
if (PAR_Rank() != 0)
return;
#endif
int i, j, k;
DBtoc *toc = DBGetToc(dbfile);
if (toc == NULL)
return;
//
// Copy relevant info from the toc. Otherwise, it'll get lost on
// successive calls to DBSetDir().
//
int norigdir = toc->ndir;
char **origdir_names = new char*[norigdir];
for (i = 0 ; i < norigdir ; i++)
{
origdir_names[i] = new char[strlen(toc->dir_names[i])+1];
strcpy(origdir_names[i], toc->dir_names[i]);
}
COPY_TOC_ENTRY(dir);
COPY_TOC_ENTRY(multimesh);
COPY_TOC_ENTRY(qmesh);
COPY_TOC_ENTRY(ucdmesh);
COPY_TOC_ENTRY(ptmesh);
COPY_TOC_ENTRY(multivar);
COPY_TOC_ENTRY(qvar);
COPY_TOC_ENTRY(ucdvar);
COPY_TOC_ENTRY(ptvar);
COPY_TOC_ENTRY(mat);
COPY_TOC_ENTRY(multimat);
COPY_TOC_ENTRY(matspecies);
COPY_TOC_ENTRY(multimatspecies);
COPY_TOC_ENTRY(curve);
#ifdef DBCSG_INNER
COPY_TOC_ENTRY(csgvar);
COPY_TOC_ENTRY(csgmesh);
#endif
#ifdef DB_VARTYPE_SCALAR
COPY_TOC_ENTRY(defvars);
#endif
// Miscellany in the root directory
char *searchpath_str = NULL;
ReadTopDirStuff(dbfile, dirname, md, &searchpath_str);
// Meshes
ReadMultimeshes(dbfile, nmultimesh, multimesh_names, dirname, md);
ReadQuadmeshes(dbfile, nqmesh, qmesh_names, dirname, md);
ReadUcdmeshes(dbfile, nucdmesh, ucdmesh_names, dirname, md);
ReadPointmeshes(dbfile, nptmesh, ptmesh_names, dirname, md);
ReadCurves(dbfile, ncurve, curve_names, dirname, md);
ReadCSGmeshes(dbfile, ncsgmesh, csgmesh_names, dirname, md);
// Vars
ReadMultivars(dbfile, nmultivar, multivar_names, dirname, md);
ReadQuadvars(dbfile, nqvar, qvar_names, dirname, md);
ReadUcdvars(dbfile, nucdvar, ucdvar_names, dirname, md);
ReadPointvars(dbfile, nptvar, ptvar_names, dirname, md);
ReadCSGvars(dbfile, ncsgvar, csgvar_names, dirname, md);
// Mats and Species
ReadMaterials(dbfile, nmat, mat_names, dirname, md);
ReadMultimats(dbfile, nmultimat, multimat_names, dirname, md);
ReadSpecies(dbfile, nmatspecies, matspecies_names, dirname, md);
ReadMultispecies(dbfile, nmultimatspecies, multimatspecies_names, dirname, md);
// Defined variables
ReadDefvars(dbfile, ndefvars, defvars_names, dirname, md);
//
// If the meshtv searchpath is defined then replace the list of
// directories with the directories in the search path.
//
if (searchpath_str != NULL)
{
//
// Free up the old list of directories.
//
for (i = 0 ; i < ndir ; i++)
{
delete [] dir_names[i];
}
delete [] dir_names;
//
// Determine the maximum number of directories in the string.
//
int max_ndir = 1;
for (i = 0; searchpath_str[i] != '\0'; i++)
{
if (searchpath_str[i] == ';')
{
max_ndir++;
}
}
//
// Create the new list of directories.
//
dir_names = new char*[ndir];
ndir = 0;
int searchpath_strlen = strlen(searchpath_str);
for (i = 0; i < searchpath_strlen; i++)
{
char *dirname = &searchpath_str[i];
while (searchpath_str[i] != ';' && searchpath_str[i] != '\0')
{
i++;
}
searchpath_str[i] = '\0';
if (strlen(dirname) > 0)
{
dir_names[ndir] = new char[strlen(dirname)+1];
strcpy(dir_names[ndir], dirname);
ndir++;
}
}
delete [] searchpath_str;
}
//
// Call recursively on the sub-directories.
//
for (i = 0 ; i < ndir ; i++)
{
char path[1024];
TRY
{
int length = strlen(dirname);
if (length > 0 && dirname[length-1] != '/')
{
sprintf(path, "%s/%s", dirname, dir_names[i]);
}
else
{
sprintf(path, "%s%s", dirname, dir_names[i]);
}
if (ShouldGoToDir(path))
{
DBSetDir(dbfile, dir_names[i]);
ReadDir(dbfile, path, md);
DBSetDir(dbfile, "..");
}
}
CATCHALL
{
debug1 << "Giving up on directory \"" << path << "\"" << endl;
}
ENDTRY
}
//
// Ok, cleanup the info we copied from the toc.
//
for (i = 0 ; i < norigdir ; i++)
{
delete [] origdir_names[i];
}
delete [] origdir_names;
FREE_COPIED_TOC_ENTRY(multimesh);
FREE_COPIED_TOC_ENTRY(qmesh);
FREE_COPIED_TOC_ENTRY(ucdmesh);
FREE_COPIED_TOC_ENTRY(ptmesh);
FREE_COPIED_TOC_ENTRY(multivar);
FREE_COPIED_TOC_ENTRY(qvar);
FREE_COPIED_TOC_ENTRY(ucdvar);
FREE_COPIED_TOC_ENTRY(ptvar);
FREE_COPIED_TOC_ENTRY(mat);
FREE_COPIED_TOC_ENTRY(multimat);
FREE_COPIED_TOC_ENTRY(matspecies);
FREE_COPIED_TOC_ENTRY(multimatspecies);
FREE_COPIED_TOC_ENTRY(curve);
FREE_COPIED_TOC_ENTRY(dir);
#ifdef DBCSG_INNER
FREE_COPIED_TOC_ENTRY(csgmesh);
FREE_COPIED_TOC_ENTRY(csgvar);
#endif
#ifdef DB_VARTYPE_SCALAR
FREE_COPIED_TOC_ENTRY(defvars);
#endif
}
// ****************************************************************************
// Method: avtSiloFileFormat::BroadcastGlobalInfo
//
// Purpose:
// Send information collected only by the first processor to the other ones.
// This includes the avtDatabaseMetaData as well as some class data members.
//
// Arguments:
// metadata the avtDatabaseMetadata to broadcast.
//
// Programmer: Jeremy Meredith
// Creation: July 15, 2003
//
// Modifications:
//
// Hank Childs, Fri Aug 15 08:01:51 PDT 2003
// Remove broadcasting of defvars. This is now handled through a different
// mechanism at a higher level.
//
// Mark C. Miller, Mon Jan 22 22:09:01 PST 2007
// Changed MPI_COMM_WORLD to VISIT_MPI_COMM
//
// Brad Whitlock, Fri Mar 16 11:53:10 PDT 2007
// Make sure that SelectAll is called on the metadata so the atts and
// attVectors that it contains will figure into the message size.
//
// Mark C. Miller, Tue Apr 15 10:24:59 PDT 2008
// Added missing call to broadcast the code name guess
//
// Mark C. Miller, Tue Jun 10 22:36:25 PDT 2008
// Added logic to pass along ignore extents bools.
// ****************************************************************************
void
avtSiloFileFormat::BroadcastGlobalInfo(avtDatabaseMetaData *metadata)
{
#ifdef PARALLEL
int rank = PAR_Rank();
//
// Broadcast Full DatabaseMetaData
//
BufferConnection tmp;
int n;
if (rank==0)
{
metadata->SelectAll();
n = metadata->CalculateMessageSize(tmp);
}
BroadcastInt(n);
unsigned char *buff = new unsigned char[n];
if (rank == 0)
{
metadata->SelectAll();
metadata->Write(tmp);
for (int i=0; i<n; i++)
{
tmp.Read(&buff[i]);
}
}
MPI_Bcast(buff, n, MPI_UNSIGNED_CHAR, 0, VISIT_MPI_COMM);
if (rank != 0)
{
tmp.Append(buff, n);
metadata->Read(tmp);
}
delete[] buff;
//
// Broadcast Database-level Info
//
BroadcastStringVector(firstSubMesh, rank);
BroadcastStringVector(firstSubMeshVarName, rank);
BroadcastStringVectorVector(allSubMeshDirs, rank);
BroadcastStringVector(actualMeshName, rank);
BroadcastIntVector(blocksForMesh, rank);
BroadcastString(codeNameGuess, rank);
//
// Broadcast info about nodelists
//
BroadcastInt(numNodeLists);
if (numNodeLists > 0)
{
//
// Build the NChooseR map
//
avtScalarMetaData::BuildEnumNChooseRMap(numNodeLists, maxCoincidentNodelists, pascalsTriangleMap);
int nlMapSize = nlBlockToWindowsMap.size();
BroadcastInt(nlMapSize);
if (rank == 0)
{
map<int, vector<int> >::iterator nlit;
for (nlit = nlBlockToWindowsMap.begin(); nlit != nlBlockToWindowsMap.end(); nlit++)
{
int nlMapKey = nlit->first;
BroadcastInt(nlMapKey);
BroadcastIntVector(nlit->second, rank);
}
}
else
{
for (int k = 0; k < nlMapSize; k++)
{
int nlMapKey;
BroadcastInt(nlMapKey);
BroadcastIntVector(nlBlockToWindowsMap[nlMapKey], rank);
}
}
}
BroadcastInt(maxAnnotIntLists);
if (maxAnnotIntLists > 0)
avtScalarMetaData::BuildEnumNChooseRMap(maxAnnotIntLists, maxCoincidentNodelists, pascalsTriangleMap);
//
// Broadcast Group Info
//
int haveGroups = groupInfo.haveGroups;
BroadcastInt(haveGroups);
groupInfo.haveGroups = haveGroups;
BroadcastInt(groupInfo.ndomains);
BroadcastInt(groupInfo.numgroups);
BroadcastIntVector(groupInfo.ids, rank);
int ignore_extents = ignoreSpatialExtents;
BroadcastInt(ignore_extents);
ignoreSpatialExtents = ignore_extents;
ignore_extents = ignoreDataExtents;
BroadcastInt(ignore_extents);
ignoreDataExtents = ignore_extents;
#endif
}
// ****************************************************************************
// Method: avtSiloFileFormat::StoreMultimeshInfo
//
// Purpose: Update plugin's cache of multimesh variables and names used in
// facilitating matching variable to mesh
//
// Programmer: Mark C. Miller (moved from ReadDir)
// Creation: June 26, 2006
//
// Modifications:
// Mark C. Miller, Thu Jun 18 20:59:24 PDT 2009
// Removed which_mm argument. It was not necessary and caused confusion.
// ****************************************************************************
void
avtSiloFileFormat::StoreMultimeshInfo(const char *const dirname,
const char *const name_w_dir, int meshnum, const DBmultimesh *const mm)
{
actualMeshName.push_back(name_w_dir);
firstSubMesh.push_back((meshnum < mm->nblocks) ?
mm->meshnames[meshnum] : "");
blocksForMesh.push_back(mm->nblocks);
allSubMeshDirs.push_back(vector<string>());
for (int j=0; j<mm->nblocks; j++)
{
string dir,var;
SplitDirVarName(mm->meshnames[j], dirname, dir,var);
if (j==meshnum)
firstSubMeshVarName.push_back(var);
allSubMeshDirs[allSubMeshDirs.size()-1].push_back(dir);
}
if (meshnum >= mm->nblocks)
firstSubMeshVarName.push_back("");
}
// ****************************************************************************
// Method: avtSiloFileFormat::DoRootDirectoryWork
//
// Purpose:
// Does some collection of information that came from the root of the
// silo file.
//
// Note: this used to be part of PopulateDatabaseMetaData
//
// Arguments:
// md the avtDatabaseMetaData
//
// Programmer: Jeremy Meredith
// Creation: July 15, 2003
//
// Modifications:
//
// Hank Childs, Thu Aug 14 09:20:28 PDT 2003
// Removed explicit support for vector defvars -- it is all now handled
// correctly at a higher level.
//
// Hank Childs, Mon Oct 8 13:11:06 PDT 2007
// Code around the case where 'treatAllDBsAsTimeVarying' is turned on
// and we need to produce a good SIL, but haven't gotten the group info.
//
// Cyrus Harrison, Wed Mar 24 10:45:30 PDT 2010
// Don't set group information if we have already set it for an AMR
// dataset.
//
// ****************************************************************************
void
avtSiloFileFormat::DoRootDirectoryWork(avtDatabaseMetaData *md)
{
//
// We should only add the defvars if we are at the 'root' level.
// Ditto adding group information.
//
void_ref_ptr vr = cache->GetVoidRef("any_mesh",
AUXILIARY_DATA_DOMAIN_BOUNDARY_INFORMATION, -1, -1);
if (*vr != NULL && !groupInfo.haveGroups)
{
// The only way to get into this state is if we have selected
// "treatAllDBsAsTimeVarying". If that's the case, the domain boundary
// info is being re-used (incorrectly) and we decide not to use
// the group info.
//
// Correct that now.
DBfile *dbfile = OpenFile(tocIndex);
debug1 << "Forcing re-read of connectivity information." << endl;
debug1 << "This should only occur when treatAllDBsAsTimeVarying "
<< "is on." << endl;
GetConnectivityAndGroupInformation(dbfile, true);
}
if (!haveAmrGroupInfo && groupInfo.haveGroups)
{
md->AddGroupInformation(groupInfo.numgroups, groupInfo.ndomains,
groupInfo.ids);
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::FindDecomposedMeshType
//
// Purpose:
// Finds and returns the type of the first multimesh at the root of this
// Silo file. Returns AVT_UNKNOWN_MESH if no multimesh is found.
//
// Programmer: Cyrus Harrison
// Creation: Monday October 27, 2008
//
// Modifications:
//
// ****************************************************************************
avtMeshType
avtSiloFileFormat::FindDecomposedMeshType(DBfile *dbfile)
{
char current_dir[512];
DBGetDir(dbfile,current_dir);
DBSetDir(dbfile,"/");
avtMeshType res = AVT_UNKNOWN_MESH;
// read toc
DBtoc *toc = DBGetToc(dbfile);
if (toc == NULL)
EXCEPTION1(InvalidFilesException,
"Could not obtain Silo Table of Contents when looking for "
" decomposed mesh type.");
stringVector mmeshes;
int nmmesh = toc->nmultimesh;
for (int i = 0 ; i < nmmesh ; i++)
mmeshes.push_back(toc->multimesh_names[i]);
// loop over meshes and look for first non empty
for (int i = 0 ; i < nmmesh && res == AVT_UNKNOWN_MESH; i++)
{
DBmultimesh *mm = DBGetMultimesh(dbfile, mmeshes[i].c_str());
if (mm)
{
for(int j = 0; j < mm->nblocks && res == AVT_UNKNOWN_MESH; j++)
{
int silo_type= mm->meshtypes[j];
if(silo_type== DB_QUAD_RECT)
res = AVT_RECTILINEAR_MESH;
else if(silo_type == DB_QUAD_CURV || silo_type == DB_QUADMESH)
res = AVT_CURVILINEAR_MESH;
else if(silo_type == DB_POINTMESH)
res = AVT_POINT_MESH;
else if(silo_type == DB_UCDMESH)
res = AVT_UNSTRUCTURED_MESH;
}
// free multimesh
DBFreeMultimesh(mm);
}
}
debug4 << "avtSiloFileFormat::FindDecomposedMeshType result = " << res << endl;
// toc points to internal structure, so we do not need to free it.
// set current dir back to where we were before this method
DBSetDir(dbfile,current_dir);
return res;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetConnectivityAndGroupInformation
//
// Purpose:
// Traverses directory structures to find information about how blocks
// connect up and how what groups each block lies in.
//
// Notes: The original code comes from PopulateDatabaseMetaData and was
// written by Jeremy Meredith.
//
// Programmer: Hank Childs
// Creation: June 24, 2002
//
// Modifications:
//
// Hank Childs, Thu Apr 10 08:51:23 PDT 2003
// Removed meta-data argument, since the acquired data will now be stored
// off and used later when the meta-data is asked for.
//
// Hank Childs, Wed Nov 12 16:45:19 PST 2003
// Use curvilinear domain boundary as structured domain boundary is now
// an abstract type.
//
// Jeremy Meredith and Hank Childs, Thu Nov 20 15:28:24 PST 2003
// Do not try to re-read domain connectivity if it has already been
// cached. This provides a nice speedup when changing time steps. It also
// avoids a bug where changing time steps could cause problems because
// the processors with no data don't get back to this function anyway.
//
// Mark C. Miller, Wed Nov 29 14:56:26 PST 2006
// Cached connectivity and group information for given timestep or -1
// depending on database setting for "ConnectivityIsTimeVarying" var
//
// Mark C. Miller, Mon Jan 22 22:09:01 PST 2007
// Changed MPI_COMM_WORLD to VISIT_MPI_COMM
//
// Hank Childs, Mon Oct 8 13:01:31 PDT 2007
// Added an argument to force the operation.
//
// Hank Childs, Tue Feb 19 19:45:43 PST 2008
// Rename "dynamic" to "streaming", since we really care about whether we
// are streaming, not about whether we are doing dynamic load balancing.
// And the two are no longer synonymous.
//
// Added call to FindDecomposedMeshType() to help with creating the
// correct type of domain boundries object.
//
// ****************************************************************************
void
avtSiloFileFormat::GetConnectivityAndGroupInformation(DBfile *dbfile,
bool force)
{
int ts = (connectivityIsTimeVarying || force) ? timestep : -1;
void_ref_ptr vr = cache->GetVoidRef("any_mesh",
AUXILIARY_DATA_DOMAIN_BOUNDARY_INFORMATION, ts, -1);
if (*vr != NULL && !force)
{
// We've already got it from a previous time step;
// don't re-read it for later time steps.
return;
}
//
// Connectivity information.
//
int ndomains = -1;
int *extents = NULL;
int *nneighbors = NULL;
int lneighbors = -1;
int *neighbors = NULL;
//
// Group information.
//
int numGroups = -1;
int *groupIds = NULL;
#ifdef PARALLEL
int rank = 0;
MPI_Comm_rank(VISIT_MPI_COMM, &rank);
if (rank == 0)
{
#endif
GetConnectivityAndGroupInformationFromFile(dbfile, ndomains, nneighbors,
extents, lneighbors, neighbors, numGroups, groupIds);
#ifdef PARALLEL
}
//
// Communicate processor 0's information to the rest of the processors.
//
MPI_Bcast(&ndomains, 1, MPI_INT, 0, VISIT_MPI_COMM);
if (ndomains != -1)
{
if (rank != 0)
{
extents = new int[ndomains*6];
nneighbors = new int[ndomains];
}
MPI_Bcast(extents, ndomains*6, MPI_INT, 0, VISIT_MPI_COMM);
MPI_Bcast(nneighbors, ndomains, MPI_INT, 0, VISIT_MPI_COMM);
MPI_Bcast(&lneighbors, 1, MPI_INT, 0, VISIT_MPI_COMM);
if (rank != 0)
{
neighbors = new int[lneighbors];
}
MPI_Bcast(neighbors, lneighbors, MPI_INT, 0, VISIT_MPI_COMM);
}
MPI_Bcast(&numGroups, 1, MPI_INT, 0, VISIT_MPI_COMM);
if (numGroups > 0)
{
if (rank != 0)
{
groupIds = new int[ndomains];
}
MPI_Bcast(groupIds, ndomains, MPI_INT, 0, VISIT_MPI_COMM);
}
#endif
//
// If we found connectivity information, go ahead and create the
// appropriate data structure and register it.
//
if (ndomains > 0 && !avtDatabase::OnlyServeUpMetaData())
{
avtStructuredDomainBoundaries *dbi = NULL;
avtMeshType mesh_type = FindDecomposedMeshType(dbfile);
if(mesh_type == AVT_RECTILINEAR_MESH)
dbi =new avtRectilinearDomainBoundaries();
else if(mesh_type == AVT_CURVILINEAR_MESH)
dbi =new avtCurvilinearDomainBoundaries();
else
{
// Error: Unknown connectivity type!
EXCEPTION1(InvalidVariableException,
"Could not determine mesh type for Connectivity "
"and Group information.");
}
dbi->SetNumDomains(ndomains);
int l = 0;
for (int j = 0; j < ndomains; j++)
{
dbi->SetExtents(j, &extents[j*6]);
for (int k = 0; k < nneighbors[j]; k++)
{
dbi->AddNeighbor(j, neighbors[l+0], neighbors[l+1],
&neighbors[l+2], &neighbors[l+5]);
l += 11;
}
dbi->Finish(j);
}
void_ref_ptr vr = void_ref_ptr(dbi,
avtStructuredDomainBoundaries::Destruct);
cache->CacheVoidRef("any_mesh",
AUXILIARY_DATA_DOMAIN_BOUNDARY_INFORMATION, ts, -1, vr);
//
// Hard to characterize when we would or would not be
// able to do dynamic load balancing, so just turn it off.
//
canDoStreaming = false;
}
if (numGroups > 0)
{
vector<int> ids;
for (int i = 0 ; i < ndomains ; i++)
{
ids.push_back(groupIds[i]);
}
groupInfo.haveGroups = true;
groupInfo.ndomains = ndomains;
groupInfo.numgroups = numGroups;
groupInfo.ids = ids;
}
//
// Clean up memory.
//
if (neighbors != NULL)
{
delete [] neighbors;
}
if (nneighbors != NULL)
{
delete [] nneighbors;
}
if (extents != NULL)
{
delete [] extents;
}
if (groupIds != NULL)
{
delete [] groupIds;
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetConnectivityAndGroupInformationFromFile
//
// Purpose:
// Traverse the file and gets the connectivity information as well as the
// group information. This is done together because these pieces of
// information are located in the same subdirectory.
//
// Notes: The original code comes from PopulateDatabaseMetaData and was
// written by Jeremy Meredith.
//
// Programmer: Hank Childs
// Creation: June 24, 2002
//
// Modifications:
//
// Hank Childs, Sat Aug 10 09:10:08 PDT 2002
// Fix bug where codes that did not fully meet the interface for groups
// ended up with a partially completed structure that eventually caused a
// crash.
//
// Mark C. Miller, Tue Nov 22 13:28:31 PST 2005
// Added alternative group information
//
// Cyrus Harrison, Fri Sep 7 10:58:11 PDT 2007
// Added option for connectivity from the MultiMeshadj object.
//
// ****************************************************************************
void
avtSiloFileFormat::GetConnectivityAndGroupInformationFromFile(DBfile *dbfile,
int &ndomains, int *&nneighbors, int *&extents, int &lneighbors,
int *&neighbors, int &numGroups, int *&groupIds)
{
bool needGroupInfo = true;
bool needConnectivityInfo = !avtDatabase::OnlyServeUpMetaData();
//
// We can read in the connectivity info through this variable. We cannot
// assume its existence, though.
//
if (DBInqVarExists(dbfile, "ConnectivityNumDomains") != 0)
{
DBReadVar(dbfile, "ConnectivityNumDomains", &ndomains);
extents = new int[ndomains*6];
nneighbors = new int[ndomains];
DBReadVar(dbfile, "ConnectivityExtents", extents);
DBReadVar(dbfile, "ConnectivityNumNeighbors", nneighbors);
DBReadVar(dbfile, "ConnectivityLenNeighbors", &lneighbors);
neighbors = new int[lneighbors];
DBReadVar(dbfile, "ConnectivityNeighbors", neighbors);
needConnectivityInfo = false;
}
//
// Note that this 'if' test will always be true right now -- we will always
// need the group info.
//
if (needGroupInfo || needConnectivityInfo)
{
//
// We need to start looking through the subdirectories.
//
bool found = false;
bool hasGlobal = false;
if (DBInqVarType(dbfile, "Global") == DB_DIR)
{
hasGlobal = true;
}
bool hasDecomposition = false;
if (DBInqVarType(dbfile, "Decomposition") == DB_DIR)
{
hasDecomposition = true;
}
if (hasGlobal)
{
DBSetDir(dbfile, "Global");
if (DBSetDir(dbfile, "Decomposition") == 0)
{
found = true;
}
else
{
debug5 << "Has Global directory, but not "
<< " Decomposition underneath it." << endl;
DBSetDir(dbfile, "..");
}
}
if (!found && hasDecomposition)
{
DBSetDir(dbfile, "Decomposition");
found = true;
}
if (found)
{
if (DBInqVarType(dbfile, "gmap0") == DB_DIR)
{
FindGmapConnectivity(dbfile, ndomains, nneighbors, extents,
lneighbors, neighbors, numGroups,groupIds,
needConnectivityInfo, needGroupInfo);
}
else if(DBInqVarType(dbfile,"Domain_Decomposition") == DB_MULTIMESHADJ)
{
FindMultiMeshAdjConnectivity(dbfile, ndomains, nneighbors,
extents, lneighbors, neighbors,
numGroups, groupIds,
needConnectivityInfo, needGroupInfo);
}
else
{
FindStandardConnectivity(dbfile, ndomains, nneighbors, extents,
lneighbors, neighbors, numGroups,groupIds,
needConnectivityInfo, needGroupInfo);
}
DBSetDir(dbfile, topDir.c_str());
}
//
// Check for alternative definition of group information
// from "_visit_domain_groups"
//
if (numGroups == -1 && DBInqVarExists(dbfile, "_visit_domain_groups") != 0)
{
int numEntries = DBGetVarLength(dbfile, "_visit_domain_groups");
groupIds = new int[numEntries];
DBReadVar(dbfile, "_visit_domain_groups", groupIds);
map<int, bool> groupMap;
for (int i = 0; i < numEntries; i++)
groupMap[groupIds[i]] = true;
numGroups = groupMap.size();
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::FindStandardConnectivity
//
// Purpose:
// Finds the connectivity assuming the standard conventions --
// Domain_0, Domain_1, etc. We assume that we are already in the
// appropriate 'Decomposition' when this routine is called.
//
// Notes: The original code comes from PopulateDatabaseMetaData and was
// written by Jeremy Meredith.
//
// Programmer: Hank Childs
// Creation: October 15, 2002
//
// Modifications:
//
// Hank Childs, Tue Oct 15 11:18:42 PDT 2002
// Moved routine out of GetConnectivityAndGroupInformationFromFile. Also
// added some logic to not read group information if there is only one
// group.
//
// Cyrus Harrison, Fri Jul 6 13:54:15 PDT 2007
// Added support for packed connectivity info from Decomp_pack var.
//
// Cyrus Harrison, Fri Jul 20 09:28:40 PDT 2007
// Fixed typos (Decomp_Pack vs [correct] Decomp_pack)
//
// Jeremy Meredith, Thu Dec 18 12:15:02 EST 2008
// Recoded the section to read the non-packed representation so that it
// reads variables in the Domain_%d subdirectories directly; DBSetDir
// became very slow on some files with lots of domains, but reading
// the variables directly seemed to avoid these speed issues.
//
// Jeremy Meredith, Tue Dec 30 15:54:04 EST 2008
// DBInqVarExists turned out to be an unreliable test for the existence
// of a directory. Instead, just skip the test entirely and bail if
// there's an error.
//
// Mark C. Miller, Wed Jan 20 16:33:56 PST 2010
// Replaced the 'break' when err is set with a 'return'. Otherwise, the
// succeeding code block does work with uninitialized/bad lneighbors.
// Also, it looked like the succeeding code block assumed that err was
// never set as in that case, ndomains would be set to -1 and the loop
// over domains in the succeeding block would be meaningless anyways.
// ****************************************************************************
void
avtSiloFileFormat::FindStandardConnectivity(DBfile *dbfile, int &ndomains,
int *&nneighbors, int *&extents, int &lneighbors, int *&neighbors,
int &numGroups, int *&groupIds, bool needConnectivityInfo,
bool needGroupInfo)
{
bool packed_conn_info = DBInqVarExists(dbfile,"NumDecomp_pack") != 0;
DBReadVar(dbfile, "NumDomains", &ndomains);
if (needConnectivityInfo)
{
extents = new int[ndomains*6];
nneighbors = new int[ndomains];
lneighbors = 0;
}
if (needGroupInfo)
{
DBReadVar(dbfile, "NumBlocks", &numGroups);
if (numGroups > 1)
{
groupIds = new int[ndomains];
}
else if (numGroups == 1)
{
groupIds = new int[ndomains];
for (int i = 0 ; i < ndomains ; i++)
{
groupIds[i] = 0;
}
needGroupInfo = false;
}
else
{
needGroupInfo = false; // What else to do?!?
}
}
if (!packed_conn_info) // use standard connectivity info
{
debug1 << "avtSiloFileFormat: using standard connectivity info" <<endl;
for (int j = 0 ; j < ndomains ; j++)
{
bool err = false;
char varname[256];
if (needConnectivityInfo)
{
sprintf(varname, "Domain_%d/Extents", j);
err |= DBReadVar(dbfile, varname, &extents[j*6]) != 0;
sprintf(varname, "Domain_%d/NumNeighbors", j);
err |= DBReadVar(dbfile, varname, &nneighbors[j]) != 0;
lneighbors += nneighbors[j] * 11;
}
if (needGroupInfo)
{
sprintf(varname, "Domain_%d/BlockNum", j);
err |= DBReadVar(dbfile, varname, &(groupIds[j])) != 0;
}
if (err)
{
ndomains = -1;
numGroups = -1;
return;
}
}
if (needConnectivityInfo)
{
if (lneighbors > 0)
{
neighbors = new int[lneighbors];
int index = 0;
for (int j = 0 ; j < ndomains ; j++)
{
for (int k = 0 ; k < nneighbors[j] ; k++)
{
char neighborname[256];
sprintf(neighborname, "Domain_%d/Neighbor_%d",j,k);
DBReadVar(dbfile, neighborname, &neighbors[index]);
index += 11;
}
}
}
}
}
else // used packed connectivity info
{
debug1 << "avtSiloFileFormat: using Decomp_pack connectivity "
<< "info" <<endl;
int numdecomp_pack = 0;
DBReadVar(dbfile,"NumDecomp_pack",&numdecomp_pack);
int *decomp = new int[numdecomp_pack];
DBReadVar(dbfile,"Decomp_pack",decomp);
int *dc_ptr = decomp;
int i,j,k;
// skip header
int unblk = *dc_ptr++;
int gnblk = *dc_ptr++;
int nblk = *dc_ptr++;
dc_ptr += nblk;
for (i=0; i < unblk; i++)
{
int nbnd = *dc_ptr++;
dc_ptr += 6 + 11 * nbnd;
}
int *dc_start = dc_ptr;
for (i=0; i < gnblk; i++)
{
if(needGroupInfo)
groupIds[i] = *dc_ptr++;
else
dc_ptr++;
int nbnd = *dc_ptr++;
if(needConnectivityInfo)
{
nneighbors[i] = nbnd;
extents[6*i+0] = *dc_ptr++;
extents[6*i+1] = *dc_ptr++;
extents[6*i+2] = *dc_ptr++;
extents[6*i+3] = *dc_ptr++;
extents[6*i+4] = *dc_ptr++;
extents[6*i+5] = *dc_ptr++;
lneighbors += 11*nbnd;
dc_ptr += 11*nbnd;
}
else
{dc_ptr += 6 + 11*nbnd;}
}
dc_ptr = dc_start;
if(needConnectivityInfo)
{
neighbors = new int[lneighbors];
int *nei_ptr = neighbors;
// get boundary info
for (i=0; i < gnblk; i++)
{
dc_ptr +=1; // skip group id
int nbnd = *dc_ptr++;
dc_ptr +=6; // skip extents
for (k=0; k < nbnd; k++)
{
for(j=0; j< 11; j++)
*nei_ptr++ = *dc_ptr++;
}
}
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::FindMultiMeshAdjConnectivity
//
// Purpose:
// Finds the connectivity using the silo MultiMeshadj object.
// Currently only supports structured meshes.
// Assumes that we are already in the appropriate 'Decomposition'
// when this routine is called, and the name of the MultiMeshAdj object
// is "Domain_Decomposition"
//
// Programmer: Cyrus Harrison
// Creation: September 7, 2007
//
// Modifications:
//
// Cyrus Harrison, Thu Feb 14 11:26:40 PST 2008
// Guard against read mask problem that occurs with treat all dbs as time
// varying.
//
// Cyrus harrison, Fri Oct 9 14:40:02 PDT 2009
// Guard against corner case crash for disconnected mesh subset.
//
// Mark C. Miller, Wed Nov 11 12:28:25 PST 2009
// Added guard against case where some mmadj->nodelists arrays are null.
// ****************************************************************************
void
avtSiloFileFormat::FindMultiMeshAdjConnectivity(DBfile *dbfile, int &ndomains,
int *&nneighbors, int *&extents, int &lneighbors, int *&neighbors,
int &numGroups, int *&groupIds, bool needConnectivityInfo,
bool needGroupInfo)
{
debug1 << "avtSiloFileFormat: using MultiMeshadj Object" <<endl;
// loop indices
int i,j;
// guard against improper read mask that occurs when treat all dbs as
// time varying is enabled.
long prev_read_mask = DBGetDataReadMask();
DBSetDataReadMask(prev_read_mask | DBMMADJNodelists | DBMMADJZonelists);
// Get the MultiMeshAdjacency object
DBmultimeshadj *mmadj_obj = DBGetMultimeshadj(dbfile,
"Domain_Decomposition",
0,NULL);
// restore prev read mask
DBSetDataReadMask(prev_read_mask);
bool ok = true;
// Make sure we only have structured meshes.
DBReadVar(dbfile, "NumDomains", &ndomains);
for( i =0; i < ndomains && ok ; i++)
{
if(mmadj_obj->meshtypes[i] != DB_QUADMESH)
ok = false;
}
// make sure we have node lists
if( mmadj_obj->lnodelists == 0 || mmadj_obj->nodelists == NULL)
ok = false;
if(!ok)
{
// Clean the multi mesh adj object and throw an exception
DBFreeMultimeshadj(mmadj_obj);
EXCEPTION1(InvalidVariableException,
"Could not find a valid Silo MultiMeshadj object");
}
if (needConnectivityInfo)
{
extents = new int[ndomains*6];
nneighbors = new int[ndomains];
lneighbors = 0;
memcpy(nneighbors,mmadj_obj->nneighbors,ndomains*sizeof(int));
// for each neighbor visit expects the following packed info:
// neighbor domain id (from the mmadj neighbors - 1 value )
// index of current domain in the neighbor's neighbor list
// (from the mmadj back array - 1 value)
// orientation relationship (from nodelist - 3 values)
// overlap extents (from the nodelist - 6 values)
// (total of 11 values)
// we need to properly pack "neighbors" from the multimesh
// adj object neighbors array, back array and the node lists,
// and fill "extents" from extents info from the node lists.
// Note: Silo's MultiMesh Adjacency Object supports unstructured
// and point meshes - but so far we only support structured meshes.
int nnodelists = mmadj_obj->lneighbors;
lneighbors = nnodelists * 11;
neighbors = new int[lneighbors];
int *extents_ptr = extents;
int *neighbors_ptr = neighbors;
int idx = 0;
for( i =0; i < ndomains && idx < nnodelists; i++)
{
if (!mmadj_obj->nodelists[idx])
continue;
// the node list provides the overlap region between
// the current domain and each neighbor and an orientation
memcpy(extents_ptr, mmadj_obj->nodelists[idx],6*sizeof(int));
extents_ptr += 6;
for( j =0; j < nneighbors[i]; j++)
{
neighbors_ptr[0] = mmadj_obj->neighbors[idx];
neighbors_ptr[1] = mmadj_obj->back[idx];
memcpy(&neighbors_ptr[2],&mmadj_obj->nodelists[idx][12],3*sizeof(int));
memcpy(&neighbors_ptr[5],&mmadj_obj->nodelists[idx][6],6*sizeof(int));
idx++;
neighbors_ptr+=11;
}
}
}
if (needGroupInfo)
{
DBReadVar(dbfile, "NumBlocks", &numGroups);
if (numGroups > 1)
{
groupIds = new int[ndomains];
DBReadVar(dbfile,"Domains_BlockNums",groupIds);
}
else if (numGroups == 1)
{
groupIds = new int[ndomains];
for (int i = 0 ; i < ndomains ; i++)
{
groupIds[i] = 0;
}
needGroupInfo = false;
}
else
{
needGroupInfo = false; // What else to do?!?
}
}
// Free the multi mesh adjacnecy object.
DBFreeMultimeshadj(mmadj_obj);
}
// ****************************************************************************
// Method: avtSiloFileFormat::FindGmapConnectivity
//
// Purpose:
// Finds the connectivity assuming the gmap conventions -- gmap0, gmap1,
// etc. We assume that we are already in the appropriate 'Decomposition'
// when this routine is called.
//
// Programmer: Hank Childs
// Creation: October 15, 2002
//
// Modifications:
//
// Hank Childs, Thu Apr 10 11:42:56 PDT 2003
// The gmap information is slightly larger than what we were allocating
// for, leading to an ABW (array bounds write) of 1. This was enough to
// crash VisIt in some circumstances.
//
// Hank Childs, Wed Jun 1 10:41:59 PDT 2005
// The block numbers is gmap[0], not gmap[1]. gmap[1] is the domain number.
//
// ****************************************************************************
void
avtSiloFileFormat::FindGmapConnectivity(DBfile *dbfile, int &ndomains,
int *&nneighbors, int *&extents, int &lneighbors, int *&neighbors,
int &numGroups, int *&groupIds, bool needConnectivityInfo,
bool needGroupInfo)
{
DBReadVar(dbfile, "NumDomains", &ndomains);
if (needConnectivityInfo)
{
extents = new int[ndomains*6];
nneighbors = new int[ndomains];
lneighbors = 0;
}
if (needGroupInfo)
{
DBReadVar(dbfile, "NumBlocks", &numGroups);
if (numGroups > 1)
{
groupIds = new int[ndomains];
}
else if (numGroups == 1)
{
groupIds = new int[ndomains];
for (int i = 0 ; i < ndomains ; i++)
{
groupIds[i] = 0;
}
needGroupInfo = false;
}
else
{
needGroupInfo = false; // What else to do?!?
}
}
for (int j = 0 ; j < ndomains ; j++)
{
char dirname[256];
if (j > 0)
sprintf(dirname, "../gmap%d", j);
else
sprintf(dirname, "gmap%d", j);
if (DBSetDir(dbfile, dirname))
{
ndomains = -1;
numGroups = -1;
break;
}
int gmap_buff[1024];
DBReadVar(dbfile, "gmap", gmap_buff);
if (needConnectivityInfo)
{
extents[j*6+0] = gmap_buff[3];
extents[j*6+1] = gmap_buff[6];
extents[j*6+2] = gmap_buff[4];
extents[j*6+3] = gmap_buff[7];
extents[j*6+4] = gmap_buff[5];
extents[j*6+5] = gmap_buff[8];
DBReadVar(dbfile, "NumNeighbors", &nneighbors[j]);
lneighbors += nneighbors[j] * 11;
}
if (needGroupInfo)
{
groupIds[j] = gmap_buff[0];
}
}
DBSetDir(dbfile, "..");
if (needConnectivityInfo)
{
if (lneighbors > 0)
{
neighbors = new int[lneighbors];
int index = 0;
for (int j = 0 ; j < ndomains ; j++)
{
for (int k = 0 ; k < nneighbors[j] ; k++)
{
char neighborname[256];
sprintf(neighborname, "gmap%d/neighbor%d",j,k);
int neighbor_info[512]; // We only want 11, but it can
// be as big as 400.
DBReadVar(dbfile, neighborname, neighbor_info);
for (int l = 0 ; l < 11 ; l++)
{
neighbors[index+l] = neighbor_info[l];
}
index += 11;
}
}
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::AddDefvars
//
// Purpose:
// Parses the defvars out of the _meshtv_defvar string and adds them to
// the meta-data as expressions.
//
// Programmer: Hank Childs
// Creation: September 4, 2002
//
// Modifications:
//
// Sean Ahern, Fri Dec 13 17:31:21 PST 2002
// Changed how expressions are defined.
//
// Hank Childs, Mon Dec 1 14:43:59 PST 2003
// Add support for tensors.
//
// Hank Childs, Mon Jun 6 14:12:34 PDT 2005
// Add support for slash characters.
//
// Hank Childs, Thu Jul 21 14:12:39 PDT 2005
// Add support for array variables.
//
// ****************************************************************************
inline void GetWord(char *&s, char *word, bool allowSlash)
{
while (isspace(*s) && *s != '\0')
{
s++;
}
int len = 0;
while ((isalnum(*s) || *s == '_' || (allowSlash && *s == '/'))
&& *s != '\0')
{
word[len] = *s;
len++;
s++;
}
word[len] = '\0';
while (isspace(*s) && *s != '\0')
{
s++;
}
}
void
AddDefvars(const char *defvars, avtDatabaseMetaData *md)
{
char *dv_tmp = new char[strlen(defvars)+1];
strcpy(dv_tmp, defvars);
//
// First determine the individual statements by separating them based on
// semi-colons.
//
vector<char *> stmts;
char *start = dv_tmp;
char *end = NULL;
do
{
//
// Find the end of the substatement -- denoted by a semi-colon.
//
end = strstr(start, ";");
//
// Put a null character where the semi-colon used to be. If we hit
// the end of the string, then end will be NULL, so we don't need to
// do anything.
//
if (end != NULL)
{
*end = '\0';
}
//
// Push back the start of the string so we can work on it later.
//
stmts.push_back(start);
start = end+1;
}
while (end != NULL);
//
// Now go through each of the statements and determine whether they are
// vector statements and get the statement if it is.
//
int size = stmts.size();
for (int i = 0 ; i < size ; i++)
{
char *s = stmts[i];
//
// Get the name out.
//
char name[1024];
GetWord(s, name, true);
//
// Make sure what we are looking at really is a vector.
//
char vartype_str[1024];
GetWord(s, vartype_str, false);
Expression::ExprType vartype = Expression::Unknown;
if (strcmp(vartype_str, "mesh") == 0)
vartype = Expression::Mesh;
else if (strcmp(vartype_str, "scalar") == 0)
vartype = Expression::ScalarMeshVar;
else if (strcmp(vartype_str, "vector") == 0)
vartype = Expression::VectorMeshVar;
else if (strcmp(vartype_str, "tensor") == 0)
vartype = Expression::TensorMeshVar;
else if (strcmp(vartype_str, "array") == 0)
vartype = Expression::ArrayMeshVar;
else if (strcmp(vartype_str, "material") == 0)
vartype = Expression::Material;
else if (strcmp(vartype_str, "species") == 0)
vartype = Expression::Species;
if (vartype == Expression::Unknown)
{
debug5 << "Warning: unknown defvar type \"" << vartype_str << "\"."
<< endl;
continue;
}
Expression expr;
expr.SetName(name);
expr.SetDefinition(s);
expr.SetType(vartype);
md->AddExpression(&expr);
}
delete [] dv_tmp;
}
// ****************************************************************************
// Method: avtSiloFileFormat::AddCSGMultimesh
//
// Purpose: Handle special requirements for multi-meshes composed of CSG
// meshes
//
// Programmer: Mark C. Miller
// Creation: June 26, 2006
// ****************************************************************************
void
avtSiloFileFormat::AddCSGMultimesh(const char *const dirname,
const char *const multimesh_name, avtDatabaseMetaData *md,
const DBmultimesh *const mm, DBfile *dbfile)
{
int i,j;
int nregions = 0;
int ndims = -1;
int meshnum = -1;
vector<string> blockPieceNames;
vector<int> groupIds;
string xUnits, yUnits, zUnits;
string xLabel, yLabel, zLabel;
double extents[6] = {DBL_MAX, -DBL_MAX, DBL_MAX, -DBL_MAX, DBL_MAX, -DBL_MAX};
double *extents_to_use = NULL;
bool hideFromGUI;
long mask = DBGetDataReadMask();
DBSetDataReadMask(mask|DBCSGMZonelist|DBCSGZonelistZoneNames);
for (i = 0; i < mm->nblocks; i++)
{
if (string(mm->meshnames[i]) == "EMPTY")
continue;
char *realvar;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(mm->meshnames[i], correctFile, 0, realvar);
DBcsgmesh *csgm = DBGetCsgmesh(correctFile, realvar);
if (csgm == NULL)
EXCEPTION1(InvalidVariableException, multimesh_name);
if (!((csgm->min_extents[0] == 0.0 && csgm->max_extents[0] == 0.0 &&
csgm->min_extents[1] == 0.0 && csgm->max_extents[1] == 0.0 &&
csgm->min_extents[2] == 0.0 && csgm->max_extents[2] == 0.0) ||
(csgm->min_extents[0] == -DBL_MAX && csgm->max_extents[0] == DBL_MAX &&
csgm->min_extents[1] == -DBL_MAX && csgm->max_extents[1] == DBL_MAX &&
csgm->min_extents[2] == -DBL_MAX && csgm->max_extents[2] == DBL_MAX)))
{
for (j = 0 ; j < csgm->ndims ; j++)
{
if (csgm->min_extents[j] < extents[2*j])
extents[2*j] = csgm->min_extents[j];
if (csgm->max_extents[j] > extents[2*j+1])
extents[2*j+1] = csgm->max_extents[j];
}
extents_to_use = extents;
}
if (csgm->zones->zonenames)
{
for (j = 0; j < csgm->zones->nzones; j++)
{
blockPieceNames.push_back(csgm->zones->zonenames[j]);
groupIds.push_back(i);
}
}
nregions += csgm->zones->nzones;
if (csgm->ndims > ndims)
ndims = csgm->ndims;
if (meshnum == -1)
{
meshnum = i;
if (csgm->units[0] != NULL)
xUnits = csgm->units[0];
if (csgm->units[1] != NULL)
yUnits = csgm->units[1];
if (csgm->units[2] != NULL)
zUnits = csgm->units[2];
if (csgm->labels[0] != NULL)
xLabel = csgm->labels[0];
if (csgm->labels[1] != NULL)
yLabel = csgm->labels[1];
if (csgm->labels[2] != NULL)
zLabel = csgm->labels[2];
hideFromGUI = csgm->guihide;
}
DBFreeCsgmesh(csgm);
}
DBSetDataReadMask(mask);
// a value for meshnum of -1 at this point indicates
// no non-EMPTY blocks found
if (meshnum != -1)
{
char *name_w_dir = GenerateName(dirname, multimesh_name, topDir.c_str());
avtMeshMetaData *mmd = new avtMeshMetaData(extents_to_use, name_w_dir,
nregions, 0, 0, 0, ndims, ndims, AVT_CSG_MESH);
mmd->blockTitle = "regions";
mmd->blockPieceName = "region";
mmd->blockNames = blockPieceNames;
mmd->xUnits = xUnits;
mmd->yUnits = yUnits;
mmd->zUnits = zUnits;
mmd->xLabel = xLabel;
mmd->yLabel = yLabel;
mmd->zLabel = zLabel;
mmd->hideFromGUI = hideFromGUI;
//mmd->loadBalanceScheme = LOAD_BALANCE_DBPLUGIN_DYNAMIC;
if (mm->nblocks > 1)
{
mmd->numGroups = mm->nblocks;
mmd->groupTitle = "blocks";
mmd->groupPieceName = "block";
md->Add(mmd);
md->AddGroupInformation(mm->nblocks, nregions, groupIds);
}
else
{
md->Add(mmd);
}
// Store off the important info about this multimesh
// so we can match other multi-objects to it later
StoreMultimeshInfo(dirname, name_w_dir, meshnum, mm);
delete [] name_w_dir;
}
}
// ****************************************************************************
// Function: UpdateNodelistEntry
//
// Purpose: Re-factorization of code used to paint a single value into a
// nodelist 'variable'
//
// Programmer: Mark C. Miller
// Creation: December 19, 2008
//
// ****************************************************************************
static void
UpdateNodelistEntry(float *ptr, int nodeId, int val, float uval,
int numLists, const vector<vector<int> > &pascalsTriangleMap)
{
#ifdef USE_BIT_MASK_FOR_NODELIST_ENUMS
if (ptr[nodeId] == uval)
{
// If the value at this node is uninitialized, set it to val
ptr[nodeId] = 1<<val;
}
else
{
int curval = int(ptr[nodeId]);
curval |= (1<<val);
ptr[nodeId] = curval;
}
#else
if (ptr[nodeId] == uval)
{
// If the value at this node is uninitialized, set it to val
ptr[nodeId] = (float) val;
}
else
{
// Otherwise, we've already got a value at this node.
// We need to obtain a new value that represents all
// the sets this node is already in plus the new one
// we're adding. Use avtScalarMetaData helper method
// to do it.
double curval = ptr[nodeId];
avtScalarMetaData::UpdateValByInsertingDigit(&curval,
numLists, maxCoincidentNodelists, pascalsTriangleMap, val);
ptr[nodeId] = float(curval);
}
#endif
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetNodelistsVar
//
// Purpose: Return scalar variable representing (enumerated scalar) nodelists
// meshes
//
// Programmer: Mark C. Miller
// Creation: March 18, 2008
//
// Modifications:
// Mark C. Miller, Tue Apr 15 19:53:08 PDT 2008
// Made it deal with case where domain boundary info object is NOT
// available by falling back to attempting to get the actual mesh dataset.
// Also, deal with case where groupIds is NOT set.
//
// Mark C. Miller, Thu Apr 17 10:30:54 PDT 2008
// With help from Cyrus, fixed some indexing errors between domain-local
// and group-global indexing.
//
// Kathleen Bonnell, Wed Jul 2 14:43:22 PDT 2008
// Removed unreferenced variables.
//
// Mark C. Miller, Tue Mar 3 19:33:23 PST 2009
// Added logic to get blockNum from groupInfo before attempting to use
// special vtk array.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetNodelistsVar(int domain)
{
int i;
vtkDataArray *nlvar = 0;
string meshName = metadata->MeshForVar("Nodelists");
const avtMeshMetaData *mmd = metadata->GetMesh(meshName);
debug5 << "Generating Nodelists variable for domain " << domain << endl;
//
// Look up the mesh in the cache.
//
vtkDataSet *ds = (vtkDataSet *) cache->GetVTKObject(meshName.c_str(),
avtVariableCache::DATASET_NAME,
timestep, domain, "_all");
if (ds == 0)
{
char msg[256];
SNPRINTF(msg, sizeof(msg), "Cannot find cached mesh \"%s\" for domain %d to "
"paint Nodelists variable", meshName.c_str(), domain);
EXCEPTION1(ImproperUseException, msg);
}
// we expect really only two kinds of meshes here.
int dims[3];
if (ds->GetDataObjectType() == VTK_RECTILINEAR_GRID)
{
vtkRectilinearGrid *rgrid = vtkRectilinearGrid::SafeDownCast(ds);
rgrid->GetDimensions(dims);
}
else if (ds->GetDataObjectType() == VTK_STRUCTURED_GRID)
{
vtkStructuredGrid *sgrid = vtkStructuredGrid::SafeDownCast(ds);
sgrid->GetDimensions(dims);
}
else
{
char msg[256];
SNPRINTF(msg, sizeof(msg), "Do not recognize dataset type for mesh \"%s\" "
"for domain %d to paint Nodelists variable", meshName.c_str(), domain);
EXCEPTION1(ImproperUseException, msg);
}
vtkIntArray *arr = vtkIntArray::SafeDownCast(ds->GetFieldData()->GetArray("base_index"));
if (arr == 0)
{
char msg[256];
SNPRINTF(msg, sizeof(msg), "Cannot find field data array \"base_index\""
"on mesh \"%s\" for domain %d to paint Nodelists variable", meshName.c_str(), domain);
EXCEPTION1(ImproperUseException, msg);
}
int base_index[3];
base_index[0] = arr->GetValue(0) ? arr->GetValue(0)-1 : 0;
base_index[1] = arr->GetValue(1) ? arr->GetValue(1)-1 : 0;
base_index[2] = arr->GetValue(2) ? arr->GetValue(2)-1 : 0;
int blockNum = -1;
if (groupInfo.haveGroups)
{
blockNum = groupInfo.ids[domain];
}
else
{
vtkIntArray *arr1 = vtkIntArray::SafeDownCast(ds->GetFieldData()->GetArray("group_id"));
if (arr1 != 0)
blockNum = arr1->GetValue(0);
}
if (blockNum == -1)
{
char msg[256];
SNPRINTF(msg, sizeof(msg), "Cannot find obtain block number "
"on mesh \"%s\" for domain %d to paint Nodelists variable", meshName.c_str(), domain);
EXCEPTION1(ImproperUseException, msg);
}
int group_min_idx[3] = {0,0,0};
int group_max_idx[3] = {0,0,0};
group_min_idx[0] = base_index[0];
group_min_idx[1] = base_index[1];
group_min_idx[2] = base_index[2];
group_max_idx[0] = base_index[0] + dims[0] - 1;
group_max_idx[1] = base_index[1] + dims[1] - 1;
group_max_idx[2] = base_index[2] + dims[2] - 1;
//
// Initialize the return variable array with exlude value
//
nlvar = vtkFloatArray::New();
nlvar->SetNumberOfTuples(dims[0]*dims[1]*(dims[2]?dims[2]:1));
float *ptr = (float *) nlvar->GetVoidPointer(0);
for (i = 0; i < dims[0]*dims[1]*(dims[2]?dims[2]:1); i++)
ptr[i] = -1.0; // always exclude value
//
// Iterate over all nodesets for this block, finding those that have
// 'windows' on this block.
//
const vector<int> &windowsOnThisBlock = nlBlockToWindowsMap[blockNum];
for (i = 0; i < windowsOnThisBlock.size(); i += 7)
{
//
// Entries in windowsOnThisBlock vector come in groups of 7.
// First one is the nodelist id (value), next 6 are its window
//
int val = windowsOnThisBlock[i];
int winExtents[6];
for (int q = 0; q < 6; q++)
winExtents[q] = windowsOnThisBlock[i+1+q];
// find intersection between extents and group_min_idx & group_max_idx
int isec[6];
isec[0] = winExtents[0] > group_min_idx[0] ? winExtents[0] : group_min_idx[0];
isec[1] = winExtents[1] < group_max_idx[0] ? winExtents[1] : group_max_idx[0];
isec[2] = winExtents[2] > group_min_idx[1] ? winExtents[2] : group_min_idx[1];
isec[3] = winExtents[3] < group_max_idx[1] ? winExtents[3] : group_max_idx[1];
isec[4] = winExtents[4] > group_min_idx[2] ? winExtents[4] : group_min_idx[2];
isec[5] = winExtents[5] < group_max_idx[2] ? winExtents[5] : group_max_idx[2];
// shift back to domain logical coords
isec[0] -= base_index[0];
isec[1] -= base_index[0];
isec[2] -= base_index[1];
isec[3] -= base_index[1];
isec[4] -= base_index[2];
isec[5] -= base_index[2];
// For 2D, ensure we enter outermost loop, below, for one iteration
if (dims[2] == 0) isec[5] = isec[4] = 0;
//
// We've got a block window that overlaps with the current domain's
// extents. This mean's the domain contains nodes that are part of
// this window. So, now we need to 'paint' values for this nodelist
// into the variable array we are returning.
//
int nxy = dims[0] * dims[1];
for (int zi = isec[4]; zi <= isec[5]; zi++)
{
for (int yi = isec[2]; yi <= isec[3]; yi++)
{
for (int xi = isec[0]; xi <= isec[1]; xi++)
UpdateNodelistEntry(ptr, zi*nxy + yi*dims[0] + xi,
val, -1.0, numNodeLists, pascalsTriangleMap);
}
}
}
return nlvar;
}
// ****************************************************************************
// Function: compare_node_ids
//
// Purpose: Callback for qsort calls to sort vector of nodes of a face.
//
// Programmer: Mark C. Miller
// Creation: December 19, 2008
//
// Modifications
// Mark C. Miller, Fri Mar 20 11:05:22 PDT 2009
// Made it treat negative values (unspecified node ids) as really larger
// than any positive node. This way, negative valued node ids always wind
// up at the end of the sorted list.
// ****************************************************************************
static int
compare_node_ids(const void *a, const void *b)
{
int *ia = (int *) a;
int *ib = (int *) b;
if (*ia < 0)
{
if (*ib < 0)
return 0;
else
return 1;
}
else if (*ib < 0)
return -1;
else if (*ia < *ib)
return -1;
else if (*ia > *ib)
return 1;
else return 0;
}
// ****************************************************************************
// Function: compare_ev_pair
//
// Purpose: Callback for qsort calls to sort vector of elemid/elemvalue
// meshes
//
// Programmer: Mark C. Miller
// Creation: December 19, 2008
// ****************************************************************************
typedef struct {int id; int val;} ev_pair_t;
static int
compare_ev_pair(const void *a, const void *b)
{
ev_pair_t *eva = (ev_pair_t *) a;
ev_pair_t *evb = (ev_pair_t *) b;
if (eva->id < evb->id)
return -1;
else if (eva->id > evb->id)
return 1;
else return 0;
}
//
// ****************************************************************************
// Function: PaintNodesForAnnotIntFacelist
//
// Purpose: Traverse a zonelist in edge- or face-centered order and paint
// values into node-centered variable on nodes associated with
// specific edges or faces.
//
// We iterate over the zones in the zonelist. For each zone, we iterate over its
// faces (3D) or edges (2D). In 2D, each edge is represented by 2 integer node ids.
// In 3D, each face (tri or quad) is represented by 4 integer node ids. As we iterate,
// we update the faceIdx or edgeIdx indicating the identifier for the next edge or
// face we find. Whenever that identifier is equal to the identifier in the list of
// edges or faces we are looking for (in elemidv), we paint data onto the nodes
// associated with that edge or face. We use a multi level map to keep track of
// faces or edges we've already seen so we don't wind up counting them twice and
// screwing up the faceIdx or edgeIdx value.
//
// Programmer: Mark C. Miller
// Creation: December 19, 2008
//
// Modifications:
// Mark C. Miller, Sat Dec 20 08:31:29 PST 2008
// Added 3D code.
//
// Mark C. Miller, Fri Mar 20 11:10:04 PDT 2009
// Added comment regarding effect of compare_node_ids on negative valued
// node ids (-1) of 3-node faces.
// ****************************************************************************
static void
PaintNodesForAnnotIntFacelist(float *ptr,
const vector<ev_pair_t> &elemidv, DBucdmesh *um,
int maxAnnotIntLists,
const vector<vector<int> > &pascalsTriangleMap)
{
DBzonelist *zl = um->zones;
if (um->ndims == 2)
{
map<int, map<int, bool> > previouslySeenEdgesMap;
int edgeIdx = 0;
int nlIdx = 0;
int elemIdx = 0;
for (int seg = 0; seg < zl->nshapes; seg++)
{
for (int zn = 0; zn < zl->shapecnt[seg]; zn++)
{
//
// For each zone we build a tiny list of its edges where
// each edge is represented by 2 node ids in the zonelist's
// nodelist. Note that we are using counterclockwise order
// which is consistent with right-hand-rule for normal towards
// the eye-point and is also consistent with Silo user's
// manual for 2D meshes.
//
int nedges = 0;
int edge[4][2];
switch (zl->shapetype[seg])
{
case DB_ZONETYPE_TRIANGLE:
{
edge[0][0] = zl->nodelist[nlIdx+0];
edge[0][1] = zl->nodelist[nlIdx+1];
edge[1][0] = zl->nodelist[nlIdx+1];
edge[1][1] = zl->nodelist[nlIdx+2];
edge[2][0] = zl->nodelist[nlIdx+2];
edge[2][1] = zl->nodelist[nlIdx+0];
nedges = 3;
}
case DB_ZONETYPE_QUAD:
{
edge[0][0] = zl->nodelist[nlIdx+0];
edge[0][1] = zl->nodelist[nlIdx+1];
edge[1][0] = zl->nodelist[nlIdx+1];
edge[1][1] = zl->nodelist[nlIdx+2];
edge[2][0] = zl->nodelist[nlIdx+2];
edge[2][1] = zl->nodelist[nlIdx+3];
edge[3][0] = zl->nodelist[nlIdx+3];
edge[3][1] = zl->nodelist[nlIdx+0];
nedges = 4;
}
}
nlIdx += zl->shapesize[seg];
for (int i = 0; i < nedges; i++)
{
bool unseenEdge = false;
// Ensure list of nodes for edge is in sorted order
// so that when we lookup an edge in the previouslySeenEdgesMap
// we do it consistently with lowest node id first.
if (edge[i][0] > edge[i][1])
{
int tmp = edge[i][0];
edge[i][0] = edge[i][1];
edge[i][1] = tmp;
}
// Do a find on node id 0 of the edge.
map<int, map<int, bool> >::iterator e0it =
previouslySeenEdgesMap.find(edge[i][0]);
if (e0it == previouslySeenEdgesMap.end())
unseenEdge = true;
else
{
// Do a find on node id 1 of the edge.
map<int, bool>::iterator e1it =
e0it->second.find(edge[i][1]);
if (e1it == e0it->second.end())
unseenEdge = true;
else
{
//
// Since we know we'll only ever see any given edge at most
// twice, when we arrive here, we know we're seeing it for
// the second time and we can safely erase it, reducing
// storage a bit as we go. In theory, this would reduce by
// half the average storage requirement of the map.
e0it->second.erase(e1it);
if (e0it->second.size() == 0)
previouslySeenEdgesMap.erase(e0it);
}
}
if (unseenEdge)
{
previouslySeenEdgesMap[edge[i][0]][edge[i][1]] = true;
//
// If the edge id of the current edge (edgeIdx) is the
// same as the current one in the list we are here to paint,
// then paint it.
//
if (edgeIdx == elemidv[elemIdx].id)
{
UpdateNodelistEntry(ptr, edge[i][0], elemidv[elemIdx].val,
-1.0, maxAnnotIntLists, pascalsTriangleMap);
UpdateNodelistEntry(ptr, edge[i][1], elemidv[elemIdx].val,
-1.0, maxAnnotIntLists, pascalsTriangleMap);
elemIdx++;
//
// If we've reached the end of the list of edge ids we
// are here to paint, then we are done.
//
if (elemIdx >= elemidv.size())
return;
}
edgeIdx++;
}
}
}
}
}
else // 3D case
{
map<int, map<int, map<int, map<int,bool> > > > previouslySeenFacesMap;
int faceIdx = 0;
int nlIdx = 0;
int elemIdx = 0;
for (int seg = 0; seg < zl->nshapes; seg++)
{
for (int zn = 0; zn < zl->shapecnt[seg]; zn++)
{
//
// For each zone we build a tiny list of its faces where
// each face is represented by 4 node ids from the zonelist's
// nodelist. For tris, the last id is set to -1. The face
// and node orders represented below are taken directly from
// the Silo user's manual.
//
int nfaces = 0;
int face[6][4];
switch (zl->shapetype[seg])
{
case DB_ZONETYPE_TET:
{
face[0][0] = zl->nodelist[nlIdx+0];
face[0][1] = zl->nodelist[nlIdx+1];
face[0][2] = zl->nodelist[nlIdx+2];
face[0][3] = -1;
face[1][0] = zl->nodelist[nlIdx+0];
face[1][1] = zl->nodelist[nlIdx+2];
face[1][2] = zl->nodelist[nlIdx+3];
face[1][3] = -1;
face[2][0] = zl->nodelist[nlIdx+0];
face[2][1] = zl->nodelist[nlIdx+3];
face[2][2] = zl->nodelist[nlIdx+1];
face[2][3] = -1;
face[3][0] = zl->nodelist[nlIdx+1];
face[3][1] = zl->nodelist[nlIdx+3];
face[3][2] = zl->nodelist[nlIdx+2];
face[3][3] = -1;
nfaces = 4;
}
case DB_ZONETYPE_PYRAMID:
{
face[0][0] = zl->nodelist[nlIdx+0];
face[0][1] = zl->nodelist[nlIdx+1];
face[0][2] = zl->nodelist[nlIdx+2];
face[0][3] = zl->nodelist[nlIdx+3];
face[1][0] = zl->nodelist[nlIdx+0];
face[1][1] = zl->nodelist[nlIdx+3];
face[1][2] = zl->nodelist[nlIdx+4];
face[1][3] = -1;
face[2][0] = zl->nodelist[nlIdx+0];
face[2][1] = zl->nodelist[nlIdx+4];
face[2][2] = zl->nodelist[nlIdx+1];
face[2][3] = -1;
face[3][0] = zl->nodelist[nlIdx+1];
face[3][1] = zl->nodelist[nlIdx+4];
face[3][2] = zl->nodelist[nlIdx+2];
face[3][3] = -1;
face[4][0] = zl->nodelist[nlIdx+2];
face[4][1] = zl->nodelist[nlIdx+4];
face[4][2] = zl->nodelist[nlIdx+3];
face[4][3] = -1;
nfaces = 5;
}
case DB_ZONETYPE_PRISM:
{
face[0][0] = zl->nodelist[nlIdx+0];
face[0][1] = zl->nodelist[nlIdx+1];
face[0][2] = zl->nodelist[nlIdx+2];
face[0][3] = zl->nodelist[nlIdx+3];
face[1][0] = zl->nodelist[nlIdx+0];
face[1][1] = zl->nodelist[nlIdx+3];
face[1][2] = zl->nodelist[nlIdx+4];
face[1][3] = -1;
face[2][0] = zl->nodelist[nlIdx+0];
face[2][1] = zl->nodelist[nlIdx+4];
face[2][2] = zl->nodelist[nlIdx+5];
face[2][3] = zl->nodelist[nlIdx+1];
face[3][0] = zl->nodelist[nlIdx+1];
face[3][1] = zl->nodelist[nlIdx+5];
face[3][2] = zl->nodelist[nlIdx+2];
face[3][3] = -1;
face[4][0] = zl->nodelist[nlIdx+2];
face[4][1] = zl->nodelist[nlIdx+5];
face[4][2] = zl->nodelist[nlIdx+4];
face[4][3] = zl->nodelist[nlIdx+3];
nfaces = 5;
}
case DB_ZONETYPE_HEX:
{
face[0][0] = zl->nodelist[nlIdx+0];
face[0][1] = zl->nodelist[nlIdx+1];
face[0][2] = zl->nodelist[nlIdx+5];
face[0][3] = zl->nodelist[nlIdx+4];
face[1][0] = zl->nodelist[nlIdx+0];
face[1][1] = zl->nodelist[nlIdx+3];
face[1][2] = zl->nodelist[nlIdx+2];
face[1][3] = zl->nodelist[nlIdx+1];
face[2][0] = zl->nodelist[nlIdx+0];
face[2][1] = zl->nodelist[nlIdx+4];
face[2][2] = zl->nodelist[nlIdx+7];
face[2][3] = zl->nodelist[nlIdx+3];
face[3][0] = zl->nodelist[nlIdx+1];
face[3][1] = zl->nodelist[nlIdx+2];
face[3][2] = zl->nodelist[nlIdx+6];
face[3][3] = zl->nodelist[nlIdx+5];
face[4][0] = zl->nodelist[nlIdx+2];
face[4][1] = zl->nodelist[nlIdx+3];
face[4][2] = zl->nodelist[nlIdx+7];
face[4][3] = zl->nodelist[nlIdx+6];
face[5][0] = zl->nodelist[nlIdx+4];
face[5][1] = zl->nodelist[nlIdx+5];
face[5][2] = zl->nodelist[nlIdx+6];
face[5][3] = zl->nodelist[nlIdx+7];
nfaces = 6;
}
}
nlIdx += zl->shapesize[seg];
for (int i = 0; i < nfaces; i++)
{
bool unseenFace = false;
// Ensure list of nodes for face is in sorted order
// so that when we lookup an face in the previouslySeenEdgesMap
// we do it consistently with lowest node id first.
qsort(face[i], 4, sizeof(int), compare_node_ids);
// Do a find on node id 0 of the face.
map<int, map<int, map<int, map<int, bool> > > >::iterator f0it =
previouslySeenFacesMap.find(face[i][0]);
if (f0it == previouslySeenFacesMap.end())
unseenFace = true;
else
{
// Do a find on node id 1 of the face.
map<int, map<int, map<int, bool> > >::iterator f1it =
f0it->second.find(face[i][1]);
if (f1it == f0it->second.end())
unseenFace = true;
else
{
// Do a find on node id 2 of the face.
map<int, map<int, bool> >::iterator f2it =
f1it->second.find(face[i][2]);
if (f2it == f1it->second.end())
unseenFace = true;
else
{
// Do a find on node id 3 of the face.
map<int, bool>::iterator f3it =
f2it->second.find(face[i][3]);
if (f3it == f2it->second.end())
unseenFace = true;
else
{
// Since we know we'll only ever see any given face at most
// twice, when we arrive here, we know we're seeing it for
// the second time and we can safely erase it, reducing
// storage a bit as we go. In theory, this would reduce by
// half the average storage requirement of the map.
f2it->second.erase(f3it);
if (f2it->second.size() == 0)
{
f1it->second.erase(f2it);
if (f1it->second.size() == 0)
{
f0it->second.erase(f1it);
if (f0it->second.size() == 0)
previouslySeenFacesMap.erase(f0it);
}
}
}
}
}
}
if (unseenFace)
{
previouslySeenFacesMap[face[i][0]][face[i][1]]
[face[i][2]][face[i][3]] = true;
//
// If the face id of the current face (faceIdx) is the
// same as the current one in the list we are here to paint,
// then paint it.
//
if (faceIdx == elemidv[elemIdx].id)
{
UpdateNodelistEntry(ptr, face[i][0], elemidv[elemIdx].val,
-1.0, maxAnnotIntLists, pascalsTriangleMap);
UpdateNodelistEntry(ptr, face[i][1], elemidv[elemIdx].val,
-1.0, maxAnnotIntLists, pascalsTriangleMap);
UpdateNodelistEntry(ptr, face[i][2], elemidv[elemIdx].val,
-1.0, maxAnnotIntLists, pascalsTriangleMap);
// The compare_node_ids comparison method used to sort the nodes
// of the face in the call to qsort, above, is designed to cause
// all -1 valued nodes to wind up at the end of the sorted list.
if (face[i][3] != -1)
UpdateNodelistEntry(ptr, face[i][3], elemidv[elemIdx].val,
-1.0, maxAnnotIntLists, pascalsTriangleMap);
elemIdx++;
//
// If we've reached the end of the list of face ids we
// are here to paint, then we are done.
//
if (elemIdx >= elemidv.size())
return;
}
faceIdx++;
}
}
}
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetAnnotIntNodelistsVar
//
// Purpose: Return scalar variable representing (enumerated scalar) nodelists
// meshes based on contents of ANNOTATION_INT object.
//
// Programmer: Mark C. Miller
// Creation: December 18, 2008
//
// Modifications:
// Mark C. Miller, Wed Feb 25 17:36:51 PST 2009
// Add missing DBZonelistInfo flag from setting of data read mask just
// prior to getting the ucdmesh.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetAnnotIntNodelistsVar(int domain, string listsname)
{
int i;
vtkDataArray *nlvar = 0;
string meshName = metadata->MeshForVar(listsname);
//
// Look up the mesh in the cache.
//
vtkDataSet *ds = (vtkDataSet *) cache->GetVTKObject(meshName.c_str(),
avtVariableCache::DATASET_NAME,
timestep, domain, "_all");
if (ds == 0)
{
char msg[256];
SNPRINTF(msg, sizeof(msg), "Cannot find cached mesh \"%s\" for domain %d to "
"paint \"%s\" variable", meshName.c_str(), domain, listsname.c_str());
EXCEPTION1(InvalidVariableException, msg);
}
debug5 << "Generating " << listsname << " variable for domain " << domain << endl;
//
// Initialize the return variable array with exlude value
//
int npts = ds->GetNumberOfPoints();
nlvar = vtkFloatArray::New();
nlvar->SetNumberOfTuples(npts);
float *ptr = (float *) nlvar->GetVoidPointer(0);
for (i = 0; i < npts; i++)
ptr[i] = -1.0; // always exclude value
//
// Try to get the ANNOTATION_INT object. In theory, this could fail on a
// domain for which no annotation's were defined. Use the GetMeshHelper
// function to get the correct file to query for ANNOTATION_INT object.
//
DBfile *domain_file = GetFile(tocIndex);
GetMeshHelper(&domain, meshName.c_str(), 0, 0, &domain_file, 0, 0);
DBcompoundarray *ai = DBGetCompoundarray(domain_file, "ANNOTATION_INT");
if (ai == 0)
return nlvar;
//
// Using scalar metadata, determine the 'value' to be associated with
// each list name we find in the ANNOTATION_INT object.
//
const avtScalarMetaData *smd = metadata->GetScalar(listsname);
map<string, int> nameToValMap;
for (i = 0; i < smd->enumNames.size(); i++)
nameToValMap[smd->enumNames[i]] = (int) smd->enumRanges[2*i];
//
// As we iterate over this compound array's members, we need to
// take care that we inspect only the '_node' named ones if we're
// here to handle an AnnotInt_Nodelist object and the '_face' ones
// if we're here to handle an AnnotInt_Facelist object. This loop
// gathers all the node/face ids to be painted along with the values
// to paint into elemidv vector.
//
int elemoff = 0;
int *elemvals = (int *) ai->values;
vector<ev_pair_t> elemidv;
for (i = 0; i < ai->nelems; i++)
{
int len = strlen(ai->elemnames[i]);
if (listsname == "AnnotInt_Nodelists" &&
strncmp("_node",&(ai->elemnames[i][len-5]),5) == 0)
{
for (int j = 0; j < ai->elemlengths[i]; j++)
{
ev_pair_t idv = {elemvals[elemoff+j],
nameToValMap[string(ai->elemnames[i],0,len-5)]};
elemidv.push_back(idv);
}
}
else if (listsname == "AnnotInt_Facelists" &&
strncmp("_face",&(ai->elemnames[i][len-5]),5) == 0)
{
for (int j = 0; j < ai->elemlengths[i]; j++)
{
ev_pair_t idv = {elemvals[elemoff+j],
nameToValMap[string(ai->elemnames[i],0,len-5)]};
elemidv.push_back(idv);
}
}
elemoff += ai->elemlengths[i];
}
//
// If we're here for nodelists, then the elemidv already contains the
// node ids we need to paint enum values onto. So, just iterate over
// those nodes and set their values accordingly.
//
if (listsname == "AnnotInt_Nodelists")
{
for (i = 0; i < elemidv.size(); i++)
UpdateNodelistEntry(ptr, elemidv[i].id, elemidv[i].val,
-1.0, maxAnnotIntLists, pascalsTriangleMap);
}
else
{
//
// If we're in this block, we must be here for facelists. So, we now
// need to read and traverse the mesh's zonelist structure, enumerating
// faces so we can determine which nodes we need to paint values onto.
//
//
// Use mesh helper func. to determine file and mesh object name.
//
int type;
char *directory_mesh = NULL;
bool allocated_directory_mesh = false;
DBmultimesh *mm;
DBfile *dbfile = GetFile(tocIndex);
DBfile *domain_file = dbfile;
GetMeshHelper(&domain, meshName.c_str(), &mm, &type, &domain_file, &directory_mesh,
&allocated_directory_mesh);
//
// Read the mesh header and just the zonelist for it.
//
long oldMask = DBSetDataReadMask(DBUMZonelist|DBZonelistInfo);
DBucdmesh *um = DBGetUcdmesh(domain_file, directory_mesh);
DBSetDataReadMask(oldMask);
if (allocated_directory_mesh)
delete [] directory_mesh;
if (um == NULL)
{
char msg[256];
SNPRINTF(msg, sizeof(msg), "DBGetUcdmesh() failed for \"%s\" for domain %d to "
"paint \"%s\" variable", meshName.c_str(), domain, listsname.c_str());
EXCEPTION1(InvalidVariableException, msg);
}
//
// Call the method that traverses the zonelist, enumerating faces and then
// for each face specified in elemids, paint values onto the nodes. We
// need to sort the elemidv data in increasing face id first because the
// method we're calling is written to assume that.
//
qsort(&elemidv[0], elemidv.size(), sizeof(ev_pair_t), compare_ev_pair);
PaintNodesForAnnotIntFacelist(ptr, elemidv, um, maxAnnotIntLists,
pascalsTriangleMap);
DBFreeUcdmesh(um);
}
DBFreeCompoundarray(ai);
return nlvar;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetVar
//
// Purpose:
// Gets the variable and converts it to a vtkScalars object.
//
// Arguments:
// domain The domain to fetch.
// v The name of the variable to fetch.
//
// Returns: The variable as a vtkScalars.
//
// Programmer: Hank Childs
// Creation: November 1, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, made it work with Silo objects
// distributed across multiple files.
//
// Hank Childs, Thu Sep 27 10:29:46 PDT 2001
// Sent down the domain and variable name to some function calls for caching
// purposes.
//
// Kathleen Bonnell, Fri Feb 8 11:03:49 PST 2002
// vtkScalars has been deprecated in VTK 4.0, use vtkDataArray instead.
//
// Jeremy Meredith, Wed Mar 19 12:23:25 PST 2003
// Allow for the case where a multi-var is only defined on a subset
// of its associated multimesh.
//
// Hank Childs, Wed Jan 14 11:58:41 PST 2004
// Use the cached multi-var to prevent too many DBGetMultivar calls.
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Added code to convert domain id for CSG meshes; no-op for other meshes.
// Added support for CSG variables.
//
// Mark C. Miller, Tue Aug 28 19:17:44 PDT 2007
// Made it deal with case where multimesh and blocks are all in same
// dir in the file. In this case, the location return had to be constructed
// and allocated. So, needed to add bool indicating that.
//
// Mark C. Miller, Mon Apr 14 15:41:21 PDT 2008
// Handle special case for 'Nodelists' variable
//
// Mark C. Miller, Tue Dec 23 22:13:00 PST 2008
// Handle special case of ANNOTATION_INT nodelists.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetVar(int domain, const char *v)
{
// for CSG meshes, each domain is a csgregion and a group of regions
// forms a visit "domain". So, we need to re-map the domain id
metadata->ConvertCSGDomainToBlockAndRegion(v, &domain, 0);
//
// Handle possible special case of nodelists spoofed as a variable
//
if (codeNameGuess == "BlockStructured" && string(v) == "Nodelists")
{
vtkDataArray *nlvar = GetNodelistsVar(domain);
if (nlvar != 0)
return nlvar;
}
//
// Handle possible special case of annot int nodelists
//
if (string(v) == "AnnotInt_Nodelists" || string(v) == "AnnotInt_Facelists")
{
vtkDataArray *nlvar = GetAnnotIntNodelistsVar(domain, v);
if (nlvar != 0)
return nlvar;
}
int localdomain = domain;
if (blocksForMultivar.count(v))
{
localdomain = blocksForMultivar[v][domain];
if (localdomain == -1)
return NULL;
}
debug5 << "Reading in domain " << domain << ", variable " << v << endl;
debug5 << "Reading in from toc " << filenames[tocIndex] << endl;
//
// Get the file handle, throw an exception if it hasn't been opened
//
DBfile *dbfile = GetFile(tocIndex);
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *var = const_cast<char *>(v);
//
// Start off by finding out what kind of var it is. Note: we have
// already cached the multivars. See if we have a multivar in the
// cache already -- this could potentially save us a DBInqVarType call.
//
DBmultivar *mv = QueryMultivar("", var);
int type;
if (mv != NULL)
type = DB_MULTIVAR;
else
type = DBInqVarType(dbfile, var);
//
// Sort out the bad cases.
//
if (type != DB_UCDVAR && type != DB_QUADVAR && type != DB_POINTVAR
&& type != DB_CSGVAR && type != DB_MULTIVAR)
{
EXCEPTION1(InvalidVariableException, var);
}
char *varLocation = NULL;
if (type == DB_MULTIVAR)
{
if (mv == NULL)
mv = GetMultivar("", var);
if (mv == NULL)
EXCEPTION1(InvalidVariableException, var);
if (localdomain < 0 || localdomain >= mv->nvars)
{
EXCEPTION2(BadDomainException, localdomain, mv->nvars);
}
type = mv->vartypes[localdomain];
varLocation = new char[strlen(mv->varnames[localdomain])+1];
strcpy(varLocation, mv->varnames[localdomain]);
}
else
{
if (domain != 0)
{
EXCEPTION2(BadDomainException, domain, 1);
}
varLocation = new char[strlen(var)+1];
strcpy(varLocation, var);
}
//
// Some Silo objects are distributed across several files,
// so handle that here.
//
DBfile *domain_file = dbfile;
char *directory_var = NULL;
const char *varDirname = StringHelpers::Dirname(var);
bool allocated_directory_var;
DetermineFileAndDirectory(varLocation, domain_file, varDirname, directory_var,
&allocated_directory_var);
//
// We only need to worry about quadvars, ucdvars, and pointvars, since we
// have reduced the multivar case to one of those.
//
vtkDataArray *rv = NULL;
if (type == DB_UCDVAR)
{
rv = GetUcdVar(domain_file, directory_var, v, domain);
}
else if (type == DB_QUADVAR)
{
rv = GetQuadVar(domain_file, directory_var, v, domain);
}
else if (type == DB_POINTVAR)
{
rv = GetPointVar(domain_file, directory_var);
}
else if (type == DB_CSGVAR)
{
rv = GetCsgVar(domain_file, directory_var);
}
//
// This may be leaked if an exception is thrown after it is allocated.
// I'll live.
//
delete [] varLocation;
if (allocated_directory_var)
delete [] directory_var;
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetVectorVar
//
// Purpose:
// Gets the variable and converts it to a vtkVectors object.
//
// Arguments:
// domain The domain to fetch.
// v The name of the variable to fetch.
//
// Returns: The variable as a vtkVectors.
//
// Programmer: Hank Childs
// Creation: March 20, 2001
//
// Modifications:
//
// Kathleen Bonnell, Fri Feb 8 11:03:49 PST 2002
// vtkVectors has been deprecated in VTK 4.0, use vtkDataArray
// and vtkFloatArray instead.
//
// Hank Childs, Fri May 17 14:59:39 PDT 2002
// Made the routine a front-end to ones that retrieve standard vector
// vars and defvars.
//
// Hank Childs, Thu Apr 10 09:11:08 PDT 2003
// Force the defvars to get read in if they haven't been already.
//
// Hank Childs, Thu Aug 14 09:18:13 PDT 2003
// Removed all defvar support -- it is now handled correctly at a different
// level.
//
// Hank Childs, Wed Jan 14 12:04:19 PST 2004
// Remove redundant DBGetMultivar calls.
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Added code to convert domain id for CSG meshes; no-op for other meshes.
// Added support for CSG variables.
//
// Mark C. Miller, Tue Aug 28 19:17:44 PDT 2007
// Made it deal with case where multimesh and blocks are all in same
// dir in the file. In this case, the location return had to be constructed
// and allocated. So, needed to add bool indicating that.
//
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetVectorVar(int domain, const char *v)
{
// for CSG meshes, each domain is a csgregion and a group of regions
// forms a visit "domain". So, we need to re-map the domain id
metadata->ConvertCSGDomainToBlockAndRegion(v, &domain, 0);
debug5 << "Reading in vector variable " << v << ", domain " << domain
<< endl;
int localdomain = domain;
if (blocksForMultivar.count(v))
{
localdomain = blocksForMultivar[v][domain];
if (localdomain == -1)
return NULL;
}
//
// Get the file handle, throw an exception if it hasn't already been opened
//
DBfile *dbfile = GetFile(tocIndex);
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *var = const_cast<char *>(v);
//
// Start off by finding out what kind of var it is. Note: we have
// already cached the multivars. See if we have a multivar in the
// cache already -- this could potentially save us a DBInqVarType call.
//
DBmultivar *mv = QueryMultivar("", var);
int type;
if (mv != NULL)
type = DB_MULTIVAR;
else
type = DBInqVarType(dbfile, var);
//
// Sort out the bad cases.
//
if (type != DB_UCDVAR && type != DB_QUADVAR && type != DB_POINTVAR
&& type != DB_MULTIVAR)
{
EXCEPTION1(InvalidVariableException, var);
}
char *varLocation = NULL;
if (type == DB_MULTIVAR)
{
if (mv == NULL)
mv = GetMultivar("", var);
if (mv == NULL)
EXCEPTION1(InvalidVariableException, var);
if (localdomain < 0 || localdomain >= mv->nvars)
{
EXCEPTION2(BadDomainException, localdomain, mv->nvars);
}
type = mv->vartypes[localdomain];
varLocation = new char[strlen(mv->varnames[localdomain])+1];
strcpy(varLocation, mv->varnames[localdomain]);
}
else
{
if (domain != 0)
{
EXCEPTION2(BadDomainException, domain, 1);
}
varLocation = new char[strlen(var)+1];
strcpy(varLocation, var);
}
//
// Some Silo objects are distributed across several files,
// so handle that here.
//
DBfile *domain_file = dbfile;
char *directory_var = NULL;
const char *varDirname = StringHelpers::Dirname(var);
bool allocated_directory_var;
DetermineFileAndDirectory(varLocation, domain_file, varDirname, directory_var,
&allocated_directory_var);
//
// We only need to worry about quadvars, ucdvars, and pointvars, since we
// have reduced the multivar case to one of those.
//
vtkDataArray *rv = NULL;
if (type == DB_UCDVAR)
{
rv = GetUcdVectorVar(domain_file, directory_var, v, domain);
}
else if (type == DB_QUADVAR)
{
rv = GetQuadVectorVar(domain_file, directory_var, v, domain);
}
else if (type == DB_POINTVAR)
{
rv = GetPointVectorVar(domain_file, directory_var);
}
else if (type == DB_CSGVAR)
{
rv = GetCsgVectorVar(domain_file, directory_var);
}
//
// This may be leaked if an exception is thrown after it is allocated.
// I'll live.
//
delete [] varLocation;
if (allocated_directory_var)
delete [] directory_var;
return rv;
}
// ****************************************************************************
// Method: CopyUcdVar
//
// Purpose:
// Copies data from a ucdvar into a new vtkDataArray.
//
// Arguments:
//
// Returns:
//
// Note: I moved this code from GetUcdVar and I templated it.
//
// Programmer: Brad Whitlock
// Creation: Fri Aug 7 10:19:52 PDT 2009
//
// Modifications:
//
// Mark C. Miller, Mon Oct 19 20:23:08 PDT 2009
// Replaced skipping logic (old way) with remapping logic for arb.
// polyhedral meshes.
//
// Mark C. Miller, Tue Oct 20 16:51:06 PDT 2009
// Made it static.
//
// Mark C. Miller, Wed Oct 28 20:29:23 PDT 2009
// Added logic to handle vector variables too. If input ucdvar has 2
// components, it gets 'promoted' to 3 by inserting zeros for 3rd component.
// Otherwise, output vtkDataArray will have same number of components
// as input ucdvar.
// ****************************************************************************
template <typename T, typename Tarr>
static vtkDataArray *
CopyUcdVar(const DBucdvar *uv, const vector<int> &remap)
{
Tarr *vtkvar = Tarr::New();
T *ptr = 0;
size_t i;
int j, k, n, cnt;
//
// Handle remapping data to due zones that have been decomposed.
//
int nvtkcomps = uv->nvals==2?3:uv->nvals;
vtkvar->SetNumberOfComponents(nvtkcomps);
if (remap.size() > 0)
{
if (uv->centering == DB_ZONECENT)
{
vtkvar->SetNumberOfTuples(remap.size());
ptr = (T *) vtkvar->GetVoidPointer(0);
for (i = 0; i < remap.size(); i++)
{
for (j = 0; j < nvtkcomps; j++)
{
if (j < uv->nvals)
ptr[i*nvtkcomps+j] = ((T**)(uv->vals))[j][remap[i]];
else
ptr[i*nvtkcomps+j] = ((T)0);
}
}
}
else if (uv->centering == DB_NODECENT)
{
//
// Determine # of 'extra' nodes
//
n = 0;
i = 0;
while (i < remap.size())
{
cnt = remap[i++];
for (j = 0; j < cnt; j++)
i++;
n++;
}
//
// Add data from original nodes.
//
vtkvar->SetNumberOfTuples(uv->nels+n);
ptr = (T *) vtkvar->GetVoidPointer(0);
for (i = 0; i < uv->nels; i++)
{
for (j = 0; j < nvtkcomps; j++)
{
if (j < uv->nvals)
ptr[i*nvtkcomps+j] = ((T**)(uv->vals))[j][i];
else
ptr[i*nvtkcomps+j] = ((T)0);
}
}
//
// Remap data on 'extra' nodes. Note, this sum/average
// is almost certainly not appropriate for all variables.
// I think we need to know which are 'intensive' and which
// are 'extensive'. Silo still needs to be enhanced for
// that.
//
n = uv->nels;
i = 0;
while (i < remap.size())
{
double sum = 0.0;
cnt = remap[i++];
for (j = 0; j < nvtkcomps; j++)
{
if (j < uv->nvals)
{
int itmp;
for (k = 0, itmp = i; k < cnt; k++, itmp++)
sum += (double) ((T**)(uv->vals))[j][remap[itmp]];
}
else
{
sum = (double) 0;
}
ptr[n*nvtkcomps+j] = (T) (sum / cnt);
}
i+=cnt;
n++;
}
}
}
else
{
//
// Populate the variable as we normally would.
//
vtkvar->SetNumberOfTuples(uv->nels);
ptr = (T *) vtkvar->GetVoidPointer(0);
for (i = 0; i < uv->nels; i++)
{
for (j = 0; j < nvtkcomps; j++)
{
if (j < uv->nvals)
ptr[i*nvtkcomps+j] = ((T**)(uv->vals))[j][i];
else
ptr[i*nvtkcomps+j] = ((T)0);
}
}
}
return vtkvar;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetUcdVectorVar
//
// Purpose:
// Gets a single block of a vector ucdvar.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// vname The variable name. This may also have a prepended path.
// tvn The True Variable Name.
// domain The domain that this variable belongs to.
//
// Returns: A vtkDataArray of the vector ucdvar.
//
// Programmer: Hank Childs
// Creation: May 17, 2002
//
// Modifications:
// Eric Brugger, Tue Mar 2 16:50:47 PST 2004
// I modified the routine to use nvals as the number of components in
// the variable.
//
// Mark C. Miller, Thu Oct 21 22:11:28 PDT 2004
// Added code to remove values from the array for arb. zones that have
// been removed
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Mark C. Miller, Wed Oct 28 20:42:14 PDT 2009
// Replaced arb. polyhederal zone skipping logic with real remapping
// as now Silo plugin will read and decompose arb. polyhedral mesh.
// Replaced CopyUcdVectorVar a vector-enhanced version of CopyUcdVar.
//
// Mark C. Miller, Wed Jan 27 13:14:03 PST 2010
// Added extra level of indirection to arbMeshXXXRemap objects to handle
// multi-block case.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetUcdVectorVar(DBfile *dbfile, const char *vname,
const char *tvn, int domain)
{
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *varname = const_cast<char *>(vname);
//
// Get the Silo construct.
//
DBucdvar *uv = DBGetUcdvar(dbfile, varname);
if (uv == NULL)
{
EXCEPTION1(InvalidVariableException, varname);
}
string meshName = metadata->MeshForVar(tvn);
vector<int> noremap;
vector<int>* remap = &noremap;
map<string, map<int, vector<int>* > >::iterator domit;
if (uv->centering == DB_ZONECENT &&
(domit = arbMeshCellReMap.find(meshName)) != arbMeshCellReMap.end() &&
domit->second.find(domain) != domit->second.end())
{
remap = domit->second[domain];
}
else if (uv->centering == DB_NODECENT &&
(domit = arbMeshNodeReMap.find(meshName)) != arbMeshNodeReMap.end() &&
domit->second.find(domain) != domit->second.end())
{
remap = domit->second[domain];
}
vtkDataArray *vectors = 0;
if(uv->datatype == DB_DOUBLE)
vectors = CopyUcdVar<double,vtkDoubleArray>(uv, *remap);
else if(uv->datatype == DB_FLOAT)
vectors = CopyUcdVar<float,vtkFloatArray>(uv, *remap);
else if(uv->datatype == DB_INT)
vectors = CopyUcdVar<int,vtkIntArray>(uv, *remap);
else if(uv->datatype == DB_SHORT)
vectors = CopyUcdVar<short,vtkShortArray>(uv, *remap);
else if(uv->datatype == DB_CHAR)
vectors = CopyUcdVar<char,vtkCharArray>(uv, *remap);
DBFreeUcdvar(uv);
return vectors;
}
// ****************************************************************************
// Method: CopyQuadVectorVar
//
// Purpose:
// Copy quadvar vectors into a vtkDataArray.
//
// Arguments:
// qv : The vector to copy.
//
// Returns: A vtkDataArray.
//
// Note: I took this code from GetQuadVectorVar and templated it.
//
// Programmer: Brad Whitlock
// Creation: Thu Aug 6 15:37:55 PDT 2009
//
// Modifications:
// Mark C. Miller, Tue Oct 20 16:50:55 PDT 2009
// Made it static.
// ****************************************************************************
template <typename T, typename Tarr>
static vtkDataArray *
CopyQuadVectorVar(const DBquadvar *qv)
{
Tarr *vectors = Tarr::New();
vectors->SetNumberOfComponents(3);
vectors->SetNumberOfTuples(qv->nels);
const T *v1 = (const T *)qv->vals[0];
const T *v2 = (const T *)qv->vals[1];
if(qv->nvals == 3)
{
const T *v3 = (const T*)qv->vals[2];
for (int i = 0 ; i < qv->nels ; i++)
vectors->SetTuple3(i, v1[i], v2[i], v3[i]);
}
else
{
for (int i = 0 ; i < qv->nels ; i++)
vectors->SetTuple3(i, v1[i], v2[i], 0.);
}
return vectors;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetQuadVectorVar
//
// Purpose:
// Gets a single block of a vector quadvar.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// vname The variable name. This may also have a prepended path.
// tvn The True Variable Name.
// domain The domain that this variable belongs to.
//
// Returns: A vtkDataArray of the vector quadvar.
//
// Programmer: Hank Childs
// Creation: May 17, 2002
//
// Modifications:
// Eric Brugger, Tue Mar 2 16:50:47 PST 2004
// I modified the routine to use nvals as the number of components in
// the variable.
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Added support for double precision quad vars (for testing xform mngr)
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetQuadVectorVar(DBfile *dbfile, const char *vname,
const char *tvn, int domain)
{
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *varname = const_cast<char *>(vname);
//
// Get the Silo construct.
//
DBquadvar *qv = DBGetQuadvar(dbfile, varname);
if (qv == NULL)
{
EXCEPTION1(InvalidVariableException, varname);
}
//
// Populate the variable. This assumes it is a scalar variable.
//
vtkDataArray *vectors = 0;
if(qv->datatype == DB_DOUBLE)
vectors = CopyQuadVectorVar<double,vtkDoubleArray>(qv);
else if(qv->datatype == DB_FLOAT)
vectors = CopyQuadVectorVar<float,vtkFloatArray>(qv);
else if(qv->datatype == DB_INT)
vectors = CopyQuadVectorVar<int,vtkIntArray>(qv);
else if(qv->datatype == DB_SHORT)
vectors = CopyQuadVectorVar<short,vtkShortArray>(qv);
else if(qv->datatype == DB_CHAR)
vectors = CopyQuadVectorVar<char,vtkCharArray>(qv);
DBFreeQuadvar(qv);
return vectors;
}
// ****************************************************************************
// Method: CopyPointVectorVar
//
// Purpose:
// Copy Silo point data into a vtkDataArray.
//
// Arguments:
// mv : The DBmeshvar object that contains the data.
//
// Returns: A vtkDataArray of the appropriate type.
//
// Note: I took this code body from GetPointVectorVar and templated it.
//
// Programmer: Brad Whitlock
// Creation: Thu Aug 6 15:12:29 PDT 2009
//
// Modifications:
//
// Mark C. Miller, Tue Oct 20 16:50:41 PDT 2009
// Made it static.
//
// Kathleen Bonnell, Thu May 6 15:36:11 PDT 2010
// Fix error in vector dimensionality test.
//
// ****************************************************************************
template <typename T, typename Tarr>
static vtkDataArray *
CopyPointVectorVar(const DBmeshvar *mv)
{
Tarr *vectors = Tarr::New();
vectors->SetNumberOfComponents(3);
vectors->SetNumberOfTuples(mv->nels);
const T *v1 = ((const T**)mv->vals)[0];
const T *v2 = ((const T**)mv->vals)[1];
if(mv->nvals == 3)
{
const T *v3 = ((const T**)mv->vals)[2];
for (int i = 0 ; i < mv->nels ; i++)
vectors->SetTuple3(i, v1[i], v2[i], v3[i]);
}
else
{
for (int i = 0 ; i < mv->nels ; i++)
vectors->SetTuple3(i, v1[i], v2[i], 0.);
}
return vectors;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetPointVectorVar
//
// Purpose:
// Gets a single block of a vector pointvar.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// vname The variable name. This may also have a prepended path.
//
// Returns: A vtkDataArray of the vector pointvar.
//
// Programmer: Hank Childs
// Creation: Novemeber 1, 2000
//
// Modifications:
// Eric Brugger, Tue Mar 2 16:50:47 PST 2004
// I modified the routine to use nvals as the number of components in
// the variable.
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Brad Whitlock, Thu Aug 6 14:55:49 PDT 2009
// I added support for non-float data types.
//
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetPointVectorVar(DBfile *dbfile, const char *vname)
{
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *varname = const_cast<char *>(vname);
//
// Get the Silo construct.
//
DBmeshvar *mv = DBGetPointvar(dbfile, varname);
if (mv == NULL)
{
EXCEPTION1(InvalidVariableException, varname);
}
vtkDataArray *vectors = 0;
if(mv->datatype == DB_DOUBLE)
vectors = CopyPointVectorVar<double,vtkDoubleArray>(mv);
else if(mv->datatype == DB_FLOAT)
vectors = CopyPointVectorVar<float,vtkFloatArray>(mv);
else if(mv->datatype == DB_INT)
vectors = CopyPointVectorVar<int,vtkIntArray>(mv);
else if(mv->datatype == DB_SHORT)
vectors = CopyPointVectorVar<short,vtkShortArray>(mv);
else if(mv->datatype == DB_CHAR)
vectors = CopyPointVectorVar<char,vtkCharArray>(mv);
DBFreeMeshvar(mv);
return vectors;
}
vtkDataArray *
avtSiloFileFormat::GetCsgVectorVar(DBfile *dbfile, const char *vname)
{
EXCEPTION1(InvalidVariableException, vname);
return 0;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetMeshHelper
//
// Purpose: Preliminary work involved in getting a mesh, refactored here to
// support access to this functionality from multiple routines other than
// just GetMesh().
//
// Created: Tue Dec 23 22:17:53 PST 2008
// Programmer: Mark C. Miller
//
// Modifications:
// Mark C. Miller, Wed Dec 24 01:39:04 PST 2008
// Added this missing function pre-amble. Added missing delete of
// meshLocation.
//
// Jeremy Meredith, Mon Dec 29 16:57:31 EST 2008
// Can't delete meshLocation here because it's used after the function
// returns in most cases. Alas, can't defer to caller, because caller
// doesn't necessarily have a pointer to meshLocation (i.e.
// directory_mesh might point to meshlocation+N, so even if you
// didn't allocate directory_mesh, you can't delete it in the caller
// by deleting directory_mesh -- it's not the same chunk of memory
// in all cases). The only safe way around this is to always copy,
// then let the caller always delete.
//
// ****************************************************************************
void
avtSiloFileFormat::GetMeshHelper(int *_domain, const char *m, DBmultimesh **_mm,
int *_type, DBfile **_domain_file, char **_directory_mesh,
bool *_allocated_directory_mesh)
{
// for CSG meshes, each domain is a csgregion and a group of regions
// forms a visit "domain". So, we need to re-map the domain id
int domain = *_domain;
metadata->ConvertCSGDomainToBlockAndRegion(m, &domain, 0);
*_domain = domain;
debug5 << "Reading in domain " << domain << ", mesh " << m << endl;
debug5 << "Reading in from toc " << filenames[tocIndex] << endl;
//
// Get the file handle, throw an exception if it hasn't already been opened
//
DBfile *dbfile = GetFile(tocIndex);
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *mesh = const_cast<char *>(m);
//
// Start off by finding out what kind of mesh it is. Note: we have
// already cached the multimeshes. See if we have a multimesh in the
// cache already -- this could potentially save us a DBInqVarType call.
//
DBmultimesh *mm = QueryMultimesh("", mesh);
int type;
if (mm != NULL)
type = DB_MULTIMESH;
else
type = DBInqVarType(dbfile, mesh);
//
// Sort out the bad cases.
//
#ifdef DBCSG_INNER // remove after silo-4.5 is released
if (type != DB_UCDMESH && type != DB_QUADMESH && type != DB_QUAD_CURV &&
type != DB_QUAD_RECT && type != DB_POINTMESH && type != DB_MULTIMESH &&
type != DB_CSGMESH && type != DB_CURVE)
#else
if (type != DB_UCDMESH && type != DB_QUADMESH && type != DB_QUAD_CURV &&
type != DB_QUAD_RECT && type != DB_POINTMESH && type != DB_MULTIMESH &&
type != DB_CURVE)
#endif
{
EXCEPTION1(InvalidVariableException, mesh);
}
char *meshLocation = NULL;
if (type == DB_MULTIMESH)
{
if (mm == NULL)
mm = GetMultimesh("", mesh);
if (mm == NULL)
EXCEPTION1(InvalidVariableException, mesh);
if (domain < 0 || domain >= mm->nblocks)
{
EXCEPTION2(BadDomainException, domain, mm->nblocks);
}
type = mm->meshtypes[domain];
meshLocation = new char[strlen(mm->meshnames[domain])+1];
strcpy(meshLocation, mm->meshnames[domain]);
}
else
{
#ifdef DBCSG_INNER // remove after silo-4.5 is released
if (domain != 0 && type != DB_CSGMESH)
#else
if (domain != 0)
#endif
{
EXCEPTION2(BadDomainException, domain, 1);
}
meshLocation = new char[strlen(mesh)+1];
strcpy(meshLocation, mesh);
}
//
// Some Silo objects are distributed across several files,
// so handle that here.
//
DBfile *domain_file = dbfile;
char *directory_mesh = NULL;
const char *meshDirname = StringHelpers::Dirname(mesh);
bool allocated_directory_mesh;
DetermineFileAndDirectory(meshLocation, domain_file, meshDirname, directory_mesh,
&allocated_directory_mesh);
if (_mm) *_mm = mm;
if (_type) *_type = type;
if (_domain_file) *_domain_file = domain_file;
if (_directory_mesh && _allocated_directory_mesh)
{
// If it's already been allocated, don't bother making
// an additional copy.
if (allocated_directory_mesh)
*_directory_mesh = directory_mesh;
else
*_directory_mesh = CXX_strdup(directory_mesh);
// But always make a copy now; we're about to lose
// our only pointer the chunk of memory containing
// it, so if we don't make a copy then we can't
// delete it now and we'll leak it.
*_allocated_directory_mesh = true;
}
else
{
// Caller didn't ask for this info, so free the
// memory without passing it back to the caller.
if (allocated_directory_mesh)
delete [] directory_mesh;
// Just in case caller put a non-null value
// for one of these pointers, put the appropriate
// NULL/false response in that return value.
if (_allocated_directory_mesh)
*_allocated_directory_mesh = false;
if (_directory_mesh)
*_directory_mesh = NULL;
}
// We've now made a copy of any important chunk of this
// memory, so it's safe to delete it now.
delete [] meshLocation;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetMesh
//
// Purpose:
// Gets the mesh and converts it to a vtkDataSet object.
//
// Arguments:
// domain The domain to fetch.
// m The name of the mesh to fetch.
//
// Returns: The mesh as a vtkDataSet.
//
// Programmer: Hank Childs
// Creation: November 1, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, made it work with Silo objects
// distributed across multiple files.
//
// Hank Childs, Wed Jan 14 11:20:18 PST 2004
// Make use of cached multimeshes if available.
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// Kathleen Bonnell, Tue Feb 8 17:00:46 PST 2005
// Added domain to args for GetQuadMesh.
//
// Mark C. Miller, Mon Feb 14 20:28:47 PST 2005
// Added test for DB_QUAD_CURV/RECT for valid type
//
// Mark C. Miller, Thu Mar 2 00:03:40 PST 2006
// Added support for curves
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Added code convert domain id for CSG meshes; no-op for other meshes.
//
// Mark C. Miller, Tue Aug 28 19:17:44 PDT 2007
// Made it deal with case where multimesh and blocks are all in same
// dir in the file. In this case, the location return had to be constructed
// and allocated. So, needed to add bool indicating that.
//
// Mark C. Miller, Tue Nov 18 18:11:56 PST 2008
// Added support for mesh region grouping trees being used to spedify
// AMR representation in Silo.
//
// Mark C. Miller, Mon Nov 9 10:42:13 PST 2009
// Added dontForceSingle to call to BuildDomainAux... for AMR cases.
//
// Cyrus Harrison, Fri Mar 26 09:07:59 PDT 2010
// Resolve mesh type before constructing amr domain boundries.
//
// ****************************************************************************
vtkDataSet *
avtSiloFileFormat::GetMesh(int domain, const char *m)
{
int type;
char *directory_mesh = NULL;
bool allocated_directory_mesh;
DBmultimesh *mm;
DBfile *dbfile = GetFile(tocIndex);
DBfile *domain_file = dbfile;
GetMeshHelper(&domain, m, &mm, &type, &domain_file, &directory_mesh,
&allocated_directory_mesh);
//
// We only need to worry about quadmeshes, ucdmeshes, and pointmeshes,
// since we have reduced the multimesh case to one of those.
//
vtkDataSet *rv = NULL;
if (type == DB_UCDMESH)
{
rv = GetUnstructuredMesh(domain_file, directory_mesh, domain, m);
}
else if (type==DB_QUADMESH || type==DB_QUAD_RECT || type==DB_QUAD_CURV)
{
// We need to wait to create domain boundries until after we obtain
// the actual mesh so we know if it is rectilinear or curvilinear.
rv = GetQuadMesh(domain_file, directory_mesh, domain);
// DB_QUADMESH won't cut it for the call to BuildDomainAuxiliaryInfoForAMRMeshes
// we need DB_QUAD_RECT or DB_QUAD_CURV to be able to create the proper domain
// boundries.
//
// Resolve this using the type of the newly created mesh.
//
if (rv != NULL && metadata->GetMesh(m)->meshType == AVT_AMR_MESH)
{
int true_type = type;
if(type == DB_QUADMESH)
{
if(rv->IsA("vtkRectilinearGrid"))
true_type = DB_QUAD_RECT;
else
true_type = DB_QUAD_CURV;
}
BuildDomainAuxiliaryInfoForAMRMeshes(dbfile, mm, m, timestep,
true_type, cache,
dontForceSingle);
}
}
else if (type == DB_POINTMESH)
{
rv = GetPointMesh(domain_file, directory_mesh);
}
#ifdef DBCSG_INNER // remove after silo-4.5 is released
else if (type == DB_CSGMESH)
{
rv = GetCSGMesh(domain_file, directory_mesh, domain);
}
#endif
else if (type == DB_CURVE)
{
rv = GetCurve(domain_file, directory_mesh);
}
else
{
EXCEPTION0(ImproperUseException);
}
//
// This may be leaked if an exception is thrown after it is allocated.
// I'll live.
//
if (allocated_directory_mesh)
delete [] directory_mesh;
return rv;
}
// ****************************************************************************
// Method: CreateDataArray
//
// Purpose:
// Creates a vtkDataArray suitable for the given Silo type. Also return the
// size of 1 element.
//
// Arguments:
// silotype : The Silo type.
// sz : The size of 1 element.
//
// Returns: A suitable vtkDataArray instance.
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Fri Aug 7 10:39:35 PDT 2009
//
// Modifications:
//
// Mark C. Miller, Tue Jan 12 17:49:18 PST 2010
// Made it it able to push data into the resultant vtkDataArray. Added
// support for DB_LONG_LONG.
// ****************************************************************************
static vtkDataArray *
CreateDataArray(int silotype, void *data, int numvals)
{
vtkDataArray *da = 0;
switch(silotype)
{
case DB_DOUBLE:
{
vtkDoubleArray *d = vtkDoubleArray::New();
if (data) d->SetArray((double*)data, numvals, 0);
da = d;
break;
}
case DB_INT:
{
vtkIntArray *d = vtkIntArray::New();
if (data) d->SetArray((int*)data, numvals, 0);
da = d;
break;
}
case DB_LONG:
{
vtkLongArray *d = vtkLongArray::New();
if (data) d->SetArray((long*)data, numvals, 0);
da = d;
break;
}
case DB_SHORT:
{
vtkShortArray *d = vtkShortArray::New();
if (data) d->SetArray((short*)data, numvals, 0);
da = d;
break;
}
case DB_CHAR:
{
vtkCharArray *d = vtkCharArray::New();
if (data) d->SetArray((char*)data, numvals, 0);
da = d;
break;
}
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,7,1)
case DB_LONG_LONG:
{
vtkLongLongArray *d = vtkLongLongArray::New();
if (data) d->SetArray((long long*)data, numvals, 0);
da = d;
break;
}
#endif
#endif
case DB_FLOAT:
default:
{
vtkFloatArray *d = vtkFloatArray::New();
if (data) d->SetArray((float*)data, numvals, 0);
da = d;
break;
}
}
if (data) da->SetNumberOfComponents(1);
return da;
}
// ****************************************************************************
// Method: ConvertToFloat
//
// Purpose:
// Converts the input array to float, returning a new float array that must
// be freed by the caller. The exception is if the input was already float.
// In that case, the input array is returned unmodified.
//
// Arguments:
// silotype : The type of data stored in the data array.
// data : The data array.
// nels : The number of elements in the data array.
//
// Returns: A float array.
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Fri Aug 7 10:51:03 PDT 2009
//
// Modifications:
//
// ****************************************************************************
static float *
ConvertToFloat(int silotype, void *data, int nels)
{
float *retval = 0;
switch(silotype)
{
case DB_DOUBLE:
{ const double *ptr = (const double *)data;
retval = new float[nels];
for(int i = 0; i < nels; ++i)
retval[i] = (float)ptr[i];
}
break;
case DB_INT:
{ const int *ptr = (const int *)data;
retval = new float[nels];
for(int i = 0; i < nels; ++i)
retval[i] = (float)ptr[i];
}
break;
case DB_LONG:
{ const long *ptr = (const long *)data;
retval = new float[nels];
for(int i = 0; i < nels; ++i)
retval[i] = (float)ptr[i];
}
break;
case DB_SHORT:
{ const short *ptr = (const short *)data;
retval = new float[nels];
for(int i = 0; i < nels; ++i)
retval[i] = (float)ptr[i];
}
break;
case DB_CHAR:
{ const char *ptr = (const char *)data;
retval = new float[nels];
for(int i = 0; i < nels; ++i)
retval[i] = (float)ptr[i];
}
break;
case DB_FLOAT:
retval = (float*)data;
break;
default:
break;
}
return retval;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetUcdVar
//
// Purpose:
// Gets a single block of a ucdvar.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// vname The variable name. This may also have a prepended path.
// tvn The True Variable Name.
// domain The domain that this variable belongs to.
//
// Returns: A vtkScalars of the ucdvar.
//
// Programmer: Hank Childs
// Creation: Novmeber 1, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, added file argument to account for
// Silo objects distributed across multiple files.
//
// Hank Childs, Thu Apr 26 16:09:39 PDT 2001
// Sped up routine.
//
// Hank Childs, Thu Sep 27 10:21:30 PDT 2001
// Add support for mixed variables.
//
// Hank Childs, Tue Oct 16 07:53:35 PDT 2001
// Account for funny data files that write out all NULL mixval arrays.
//
// Kathleen Bonnell, Fri Feb 8 11:03:49 PST 2002
// vtkScalars has been deprecated in VTK 4.0, use vtkDataArray
// and vtkFloatArray instead.
//
// Hank Childs, Fri Jul 5 15:03:23 PDT 2002
// Add the name of the mixed variable to its constructor.
//
// Mark C. Miller, Thu Oct 21 22:11:28 PDT 2004
// Added code to remove values from array for arb. zones that were
// removed from the mesh
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Brad Whitlock, Fri Aug 7 10:19:32 PDT 2009
// I added support for non-float types.
//
// Mark C. Miller, Mon Oct 19 20:25:08 PDT 2009
// Replaced skipping logic with remapping logic.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetUcdVar(DBfile *dbfile, const char *vname,
const char *tvn, int domain)
{
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *varname = const_cast<char *>(vname);
//
// Get the Silo construct.
//
DBucdvar *uv = DBGetUcdvar(dbfile, varname);
if (uv == NULL)
{
EXCEPTION1(InvalidVariableException, varname);
}
string meshName = metadata->MeshForVar(tvn);
vector<int> noremap;
vector<int>* remap = &noremap;
map<string, map<int, vector<int>* > >::iterator domit;
if (uv->centering == DB_ZONECENT &&
(domit = arbMeshCellReMap.find(meshName)) != arbMeshCellReMap.end() &&
domit->second.find(domain) != domit->second.end())
{
remap = domit->second[domain];
}
else if (uv->centering == DB_NODECENT &&
(domit = arbMeshNodeReMap.find(meshName)) != arbMeshNodeReMap.end() &&
domit->second.find(domain) != domit->second.end())
{
remap = domit->second[domain];
}
vtkDataArray *scalars = 0;
if(uv->datatype == DB_DOUBLE)
scalars = CopyUcdVar<double,vtkDoubleArray>(uv, *remap);
else if(uv->datatype == DB_FLOAT)
scalars = CopyUcdVar<float,vtkFloatArray>(uv, *remap);
else if(uv->datatype == DB_INT)
scalars = CopyUcdVar<int,vtkIntArray>(uv, *remap);
else if(uv->datatype == DB_SHORT)
scalars = CopyUcdVar<short,vtkShortArray>(uv, *remap);
else if(uv->datatype == DB_CHAR)
scalars = CopyUcdVar<char,vtkCharArray>(uv, *remap);
if (uv->mixvals != NULL && uv->mixvals[0] != NULL)
{
float *mixvals = ConvertToFloat(uv->datatype, uv->mixvals[0], uv->mixlen);
avtMixedVariable *mv = new avtMixedVariable(mixvals, uv->mixlen, tvn);
void_ref_ptr vr = void_ref_ptr(mv, avtMixedVariable::Destruct);
cache->CacheVoidRef(tvn, AUXILIARY_DATA_MIXED_VARIABLE, timestep,
domain, vr);
if(mixvals != (float *)uv->mixvals[0])
delete [] mixvals;
}
DBFreeUcdvar(uv);
return scalars;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetQuadVar
//
// Purpose:
// Gets a single block of a quadvar.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// vname The variable name. This may also have a prepended path.
// tvn The True Variable Name.
// domain The domain that this variable belongs to.
//
// Returns: A vtkScalars of the quadvar.
//
// Programmer: Hank Childs
// Creation: Novemeber 1, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, added file argument to account for
// Silo objects distributed across multiple files.
//
// Hank Childs, Thu Apr 26 16:09:39 PDT 2001
// Sped up routine.
//
// Hank Childs, Thu Sep 27 10:21:30 PDT 2001
// Add support for mixed variables.
//
// Hank Childs, Tue Oct 16 07:53:35 PDT 2001
// Account for funny data files that write out all NULL mixval arrays.
//
// Kathleen Bonnell, Fri Feb 8 11:03:49 PST 2002
// vtkScalars has been deprecated in VTK 4.0, use vtkDataArray
// and vtkFloatArray instead.
//
// Eric Brugger, Thu May 23 14:23:23 PDT 2002
// I modified the routine to take into account the major order of
// the variable being read.
//
// Hank Childs, Fri Jul 5 15:03:23 PDT 2002
// Add the name of the mixed variable to its constructor.
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Added support for double precision quad vars (for testing xform mngr)
//
// Mark C. Miller, Tue Nov 18 18:12:54 PST 2008
// Add some additional datatypes to test behavior for non-4-byte sized
// types.
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Brad Whitlock, Fri Aug 7 10:33:26 PDT 2009
// I created more types of vtkDataArray to add support beyond float/double.
//
// Mark C. Miller, Tue Jan 12 17:50:52 PST 2010
// Use CreateDataArray.
// ****************************************************************************
template <class T>
static void CopyAndReorderQuadVar(T* var2, int nx, int ny, int nz, const void *const src)
{
const T *const var = (const T *const) src;
int nxy = nx * ny;
int nyz = ny * nz;
for (int k = 0; k < nz; k++)
{
for (int j = 0; j < ny; j++)
{
for (int i = 0; i < nx; i++)
{
var2[k*nxy + j*nx + i] = var[k + j*nz + i*nyz];
}
}
}
}
vtkDataArray *
avtSiloFileFormat::GetQuadVar(DBfile *dbfile, const char *vname,
const char *tvn, int domain)
{
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *varname = const_cast<char *>(vname);
//
// Get the Silo construct.
//
DBquadvar *qv = DBGetQuadvar(dbfile, varname);
if (qv == NULL)
{
EXCEPTION1(InvalidVariableException, varname);
}
//
// Populate the variable. This assumes it is a scalar variable.
//
vtkDataArray *scalars;
if (qv->major_order == DB_ROWMAJOR || qv->ndims <= 1)
{
scalars = CreateDataArray(qv->datatype, (void*) qv->vals[0], qv->nels);
qv->vals[0] = 0; // the vtkDataArray now owns the data.
}
else
{
scalars = CreateDataArray(qv->datatype, 0, 0);
scalars->SetNumberOfTuples(qv->nels);
void *var2 = scalars->GetVoidPointer(0);
void *var = qv->vals[0];
int nx = qv->dims[0];
int ny = qv->dims[1];
int nz = qv->ndims == 3 ? qv->dims[2] : 1;
if (qv->datatype == DB_DOUBLE)
CopyAndReorderQuadVar((double *) var2, nx, ny, nz, var);
else if (qv->datatype == DB_LONG)
CopyAndReorderQuadVar((long *) var2, nx, ny, nz, var);
else if (qv->datatype == DB_INT)
CopyAndReorderQuadVar((int *) var2, nx, ny, nz, var);
else if (qv->datatype == DB_SHORT)
CopyAndReorderQuadVar((short *) var2, nx, ny, nz, var);
else if (qv->datatype == DB_CHAR)
CopyAndReorderQuadVar((char *) var2, nx, ny, nz, var);
else
CopyAndReorderQuadVar((float *) var2, nx, ny, nz, var);
}
if (qv->mixvals != NULL && qv->mixvals[0] != NULL)
{
float *mixvals = ConvertToFloat(qv->datatype, qv->mixvals[0], qv->mixlen);
avtMixedVariable *mv = new avtMixedVariable(mixvals, qv->mixlen, tvn);
void_ref_ptr vr = void_ref_ptr(mv, avtMixedVariable::Destruct);
cache->CacheVoidRef(tvn, AUXILIARY_DATA_MIXED_VARIABLE, timestep,
domain, vr);
if(mixvals != (float*)qv->mixvals[0])
delete [] mixvals;
}
DBFreeQuadvar(qv);
return scalars;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetPointVar
//
// Purpose:
// Gets a single block of a pointvar.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// vname The variable name. This may also have a prepended path.
//
// Returns: A vtkScalars of the pointvar.
//
// Programmer: Hank Childs
// Creation: Novemeber 1, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, added file argument to account for
// Silo objects distributed across multiple files.
//
// Hank Childs, Thu Apr 26 16:09:39 PDT 2001
// Sped up routine.
//
// Kathleen Bonnell, Fri Feb 8 11:03:49 PST 2002
// vtkScalars has been deprecated in VTK 4.0, use vtkDataArray
// and vtkFloatArray instead.
//
// Brad Whitlock, Fri Aug 7 10:38:34 PDT 2009
// I added support for non-float data types.
//
// Mark C. Miller, Thu Nov 12 14:56:15 PST 2009
// Changed logic for exception for variable with more than 1 component
// to use 'nvals' instead of 'ndims'
//
// Mark C. Miller, Tue Jan 12 17:51:42 PST 2010
// Changed interface to CreateDataArray.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetPointVar(DBfile *dbfile, const char *vname)
{
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *varname = const_cast<char *>(vname);
//
// Get the Silo construct.
//
DBmeshvar *mv = DBGetPointvar(dbfile, varname);
if (mv == NULL)
{
EXCEPTION1(InvalidVariableException, varname);
}
if(mv->nvals > 1)
{
EXCEPTION1(InvalidVariableException, "Pointvar with more than 1 component. Fix Silo reader.");
}
//
// Populate the variable. This assumes it is a scalar variable.
//
vtkDataArray *scalars = CreateDataArray(mv->datatype, (void*)mv->vals[0], mv->nels);
mv->vals[0] = 0; // vtkDataArray now owns the data.
DBFreeMeshvar(mv);
return scalars;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetCsgVar
//
// Purpose: Gets a CSG variable
//
// Programmer: Mark C. Miller
// Creation: December 3, 2006
//
// Modifications:
// Brad Whitlock, Fri Aug 7 11:01:59 PDT 2009
// I added non-float support.
//
// Mark C. Miller, Tue Jan 12 17:51:59 PST 2010
// Changed interface to CreateDataArray.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetCsgVar(DBfile *dbfile, const char *vname)
{
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *varname = const_cast<char *>(vname);
//
// Get the Silo construct.
//
DBcsgvar *csgv = DBGetCsgvar(dbfile, varname);
if (csgv == NULL)
{
EXCEPTION1(InvalidVariableException, varname);
}
//
// Populate the variable. This assumes it is a scalar variable.
//
vtkDataArray *scalars = CreateDataArray(csgv->datatype, (void*)csgv->vals[0], csgv->nels);
csgv->vals[0] = 0; // vtkDataArray no owns the data.
DBFreeCsgvar(csgv);
return scalars;
}
// ****************************************************************************
// Method: CopyUnstructuredMeshCoordinates
//
// Purpose:
// This function copies ucdmesh coordinates into an interleaved vtkPoints array.
//
// Arguments:
// T : The destination array.
// um : The ucdmesh.
//
// Returns:
//
// Note: I moved this code from avtSiloFileFormat::GetUnstructuredMesh
// and templated it.
//
// Programmer: Brad Whitlock
// Creation: Thu Aug 6 11:59:25 PDT 2009
//
// Modifications:
//
// Mark C. Miller, Tue Oct 20 16:51:50 PDT 2009
// Made it static.
// ****************************************************************************
template <typename T>
static void
CopyUnstructuredMeshCoordinates(T *pts, const DBucdmesh *um)
{
int nnodes = um->nnodes;
bool dim3 = (um->coords[2] != NULL ? true : false);
T *tmp = pts;
const T *coords0 = (T*) um->coords[0];
const T *coords1 = (T*) um->coords[1];
if (um->coords[2] != NULL)
{
const T *coords2 = (T*) um->coords[2];
for (int i = 0 ; i < nnodes ; i++)
{
*tmp++ = *coords0++;
*tmp++ = *coords1++;
*tmp++ = *coords2++;
}
}
else if (um->coords[1] != NULL)
{
for (int i = 0 ; i < nnodes ; i++)
{
*tmp++ = *coords0++;
*tmp++ = *coords1++;
*tmp++ = 0.;
}
}
else if (um->coords[0] != NULL)
{
for (int i = 0 ; i < nnodes ; i++)
{
*tmp++ = *coords0++;
*tmp++ = 0.;
*tmp++ = 0.;
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::HandleGlobalZoneIds
//
// Purpose: Handle re-mapping global zone ids as per arb. poly remeshing
// and sticking global zone ids into cache.
//
// Programmer: Mark C. Miller, Thu Oct 29 15:00:54 PDT 2009
//
// Mark C. Miller, Fri Oct 30 14:03:13 PDT 2009
// Handle Silo's DB_DTPTR configuration option.
//
// Mark C. Miller, Tue Jan 12 17:52:15 PST 2010
// Handle different version of Silo interface. Added support for all of
// Silo's integral types and not just DB_INT.
//
// Mark C. Miller, Wed Jan 27 13:14:03 PST 2010
// Added extra level of indirection to arbMeshXXXRemap objects to handle
// multi-block case.
// ****************************************************************************
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,7,1)
void
avtSiloFileFormat::HandleGlobalZoneIds(const char *meshname, int domain,
void *gzoneno, int lgzoneno, int gnznodtype)
#else
void
avtSiloFileFormat::HandleGlobalZoneIds(const char *meshname, int domain,
int *gzoneno, int lgzoneno)
#endif
#else
void
avtSiloFileFormat::HandleGlobalZoneIds(const char *meshname, int domain,
int *gzoneno, int lgzoneno)
#endif
{
//
// Lookup an arb. poly remap data we might need.
//
vector<int> noremap;
vector<int> *remap = &noremap;
map<string, map<int, vector<int>* > >::iterator domit;
if ((domit = arbMeshCellReMap.find(meshname)) != arbMeshCellReMap.end() &&
domit->second.find(domain) != domit->second.end())
remap = domit->second[domain];
//
// Create a vtkInt array whose contents are the actual gzoneno data
// Create a temp. DBucdvar object so we can use CopyUcdVar
//
DBucdvar tmp;
tmp.centering = DB_ZONECENT;
tmp.datatype = DB_INT;
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,7,1)
tmp.datatype = gnznodtype;
#endif
#endif
tmp.nels = lgzoneno;
tmp.nvals = 1;
#ifdef DB_DTPTR
tmp.vals = (DB_DTPTR**) new DB_DTPTR*[1];
tmp.vals[0] = (DB_DTPTR*) gzoneno;
#else
tmp.vals = (float**) new float*[1];
tmp.vals[0] = (float*) gzoneno;
#endif
vtkDataArray *arr;
if (tmp.datatype == DB_SHORT)
arr = CopyUcdVar<short,vtkShortArray>(&tmp, *remap);
else if (tmp.datatype == DB_INT)
arr = CopyUcdVar<int,vtkIntArray>(&tmp, *remap);
else if (tmp.datatype == DB_LONG)
arr = CopyUcdVar<long,vtkLongArray>(&tmp, *remap);
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,7,1)
else if (tmp.datatype == DB_LONG_LONG)
arr = CopyUcdVar<long long,vtkLongLongArray>(&tmp, *remap);
#endif
#endif
delete [] tmp.vals;
//
// Cache this VTK object but in the VoidRefCache, not the VTK cache
// so that it can be obtained through the GetAuxiliaryData call
//
void_ref_ptr vr = void_ref_ptr(arr, avtVariableCache::DestructVTKObject);
cache->CacheVoidRef(meshname, AUXILIARY_DATA_GLOBAL_ZONE_IDS, timestep,
domain, vr);
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetUnstructuredMesh
//
// Purpose:
// Creates a VTK unstructured grid from a Silo unstructured mesh.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// mn The name of the mesh.
// domain The domain we are operating on.
// mesh The unqualified name of the mesh (for caching purposes).
//
// Returns: A VTK unstructured grid created from mn.
//
// Programmer: Hank Childs
// Creation: November 1, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, added file argument to account for
// Silo objects distributed across multiple files.
//
// Hank Childs, Thu Apr 26 16:09:39 PDT 2001
// Sped up routine.
//
// Kathleen Bonnell, Wed May 23 15:41:14 PDT 2001
// Added call to TranslateSiloPyramidToVTKPyramid.
//
// Kathleen Bonnell, Tue Jun 12 14:34:02 PDT 2001
// Added code to determine and set a ghost-levels array.
//
// Hank Childs, Thu Sep 20 16:08:21 PDT 2001
// Added argument domain. Captured facelist and added that to the variable
// cache.
//
// Kathleen Bonnell, Thu Nov 8 09:20:50 PST 2001
// VTK 4.0 API requires use of vtkIdType or vtkIdList for InsertNextCell
// methods, so created the arrays where necessary.
//
// Hank Childs, Mon Apr 15 14:38:31 PDT 2002
// Fix memory leak.
//
// Hank Childs, Fri May 17 14:27:18 PDT 2002
// Some Silo 2D-UCD meshes have facelists. They are worthless to us and
// they break the code since they don't have shapesizes and shapetypes, so
// don't read them in.
//
// Hank Childs, Sun Jun 16 19:55:52 PDT 2002
// Account for non 0-origin meshes.
//
// Hank Childs, Thu Jun 20 14:39:09 PDT 2002
// Separate reading the connectivity into its own routine. Also account
// for meshes that do not have connectivity, but have facelists to serve
// that role in its place.
//
// Hank Childs, Mon Dec 9 13:21:13 PST 2002
// Use the facelist's origin rather than the unstructured meshes.
//
// Hank Childs, Wed Jan 14 13:40:33 PST 2004
// Sped up routine by minimizing cache misses.
//
// Mark C. Miller, August 9, 2004
// Added code to read and cache optional global node and zone ids
//
// Mark C. Miller, Thu Oct 21 22:11:28 PDT 2004
// Added code to set arbMeshZoneRangesToSkip and issue warning for meshes
// that have arbitrary polyhedra embedded in an ordinary DBzonelist
//
// Hank Childs, Wed Mar 9 07:53:16 PST 2005
// Do not send a C-array into a C++-construct. It will eventually call
// "delete" when it should call "free".
//
// Jeremy Meredith, Tue Jun 7 08:32:46 PDT 2005
// Added support for "EMPTY" domains in multi-objects.
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Mark C. Miller, Wed Feb 11 23:22:37 PST 2009
// Added support for 1D unstructured mesh, mainly to test funky curves
//
// Brad Whitlock, Thu Aug 6 12:00:39 PDT 2009
// I added support for double coordinates.
//
// Mark C. Miller, Mon Oct 19 20:22:27 PDT 2009
// Added support to read in arbitrary polyhedral data.
//
// Mark C. Miller, Wed Oct 28 08:21:14 PDT 2009
// Added logic to deal with global zone numbers on arb. poly mesh.
//
// Mark C. Miller, Wed Oct 28 20:43:45 PDT 2009
// Removed logic/warning for skipping arb. polyhedral zones that are
// embedded in 'ordinary' zonelist. They are now correctly handled in
// ReadInConnectivity.
//
// Mark C. Miller, Tue Jan 12 17:53:17 PST 2010
// Use CreateDataArray for global node numbers and handle long long case
// as well. Vary interface to HandleGlobalZoneIds for versions of Silo.
// ****************************************************************************
vtkDataSet *
avtSiloFileFormat::GetUnstructuredMesh(DBfile *dbfile, const char *mn,
int domain, const char *mesh)
{
//
// Allow empty data sets
//
if (string(mn) == "EMPTY")
return NULL;
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *meshname = const_cast<char *>(mn);
//
// Get the Silo construct.
//
DBucdmesh *um = DBGetUcdmesh(dbfile, meshname);
if (um == NULL)
{
EXCEPTION1(InvalidVariableException, meshname);
}
vtkPoints *points = vtkPoints::New();
//
// vtkPoints assumes float data type
//
if (um->datatype == DB_DOUBLE)
points->SetDataTypeToDouble();
//
// Populate the coordinates. Put in 3D points with z=0 if the mesh is 2D.
//
points->SetNumberOfPoints(um->nnodes);
if(um->datatype == DB_DOUBLE)
CopyUnstructuredMeshCoordinates((double *)points->GetVoidPointer(0), um);
else if(um->datatype == DB_FLOAT)
CopyUnstructuredMeshCoordinates((float *)points->GetVoidPointer(0), um);
else
{
points->Delete();
DBFreeUcdmesh(um);
EXCEPTION1(InvalidVariableException, "The Silo reader supports only "
"float and double precision coordinates in unstructured meshes.");
}
//
// We already got the facelist read in free of charge. Let's use it.
// This is done before constructing the connectivity because this is used
// in place of the connectivity in some places.
//
avtFacelist *fl = NULL;
if (um->faces != NULL && um->ndims == 3)
{
DBfacelist *sfl = um->faces;
fl = new avtFacelist(sfl->nodelist, sfl->lnodelist,
sfl->nshapes, sfl->shapecnt, sfl->shapesize,
sfl->zoneno, sfl->origin);
void_ref_ptr vr = void_ref_ptr(fl, avtFacelist::Destruct);
cache->CacheVoidRef(mesh, AUXILIARY_DATA_EXTERNAL_FACELIST, timestep,
domain, vr);
}
//
// If we have global node ids, set them up and cache 'em
//
if (um->gnodeno != NULL)
{
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,7,1)
vtkDataArray *arr = CreateDataArray(um->gnznodtype, um->gnodeno, um->nnodes);
#else
vtkDataArray *arr = CreateDataArray(DB_INT, um->gnodeno, um->nnodes);
#endif
#else
vtkDataArray *arr = CreateDataArray(DB_INT, um->gnodeno, um->nnodes);
#endif
um->gnodeno = 0; // vtkDataArray now owns the data.
//
// Cache this VTK object but in the VoidRefCache, not the VTK cache
// so that it can be obtained through the GetAuxiliaryData call
//
void_ref_ptr vr = void_ref_ptr(arr, avtVariableCache::DestructVTKObject);
cache->CacheVoidRef(mesh, AUXILIARY_DATA_GLOBAL_NODE_IDS, timestep,
domain, vr);
}
//
// Some ucdmeshes uses facelists instead of zonelists. I think this is
// freakish behavior and should not be supported, but if there are files
// this way then we have to honor that.
//
vtkDataSet *rv = NULL;
if (um->zones != NULL)
{
vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
ugrid->SetPoints(points);
ReadInConnectivity(ugrid, um->zones, um->zones->origin,
mesh, domain);
rv = ugrid;
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,7,1)
if (um->zones->gzoneno != NULL)
HandleGlobalZoneIds(mesh, domain, um->zones->gzoneno,
um->zones->nzones, um->zones->gnznodtype);
#else
if (um->zones->gzoneno != NULL)
HandleGlobalZoneIds(mesh, domain, um->zones->gzoneno,
um->zones->nzones);
#endif
#else
if (um->zones->gzoneno != NULL)
HandleGlobalZoneIds(mesh, domain, um->zones->gzoneno,
um->zones->nzones);
#endif
}
else if (fl != NULL && um->phzones == NULL)
{
vtkPolyData *pd = vtkPolyData::New();
fl->CalcFacelistFromPoints(points, pd);
rv = pd;
}
//
// Handle arbitrary polyhedral zonelist
//
if (um->phzones != NULL)
{
vtkUnstructuredGrid *ugrid = 0;
if (rv == 0)
{
ugrid = vtkUnstructuredGrid::New();
ugrid->SetPoints(points);
rv = ugrid;
}
else
{
ugrid = vtkUnstructuredGrid::SafeDownCast(rv);
}
ReadInArbConnectivity(mesh, ugrid, um, domain);
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,7,1)
if (um->phzones->gzoneno != NULL)
HandleGlobalZoneIds(mesh, domain, um->phzones->gzoneno,
um->phzones->nzones, um->phzones->gnznodtype);
#else
if (um->phzones->gzoneno != NULL)
HandleGlobalZoneIds(mesh, domain, um->phzones->gzoneno,
um->phzones->nzones);
#endif
#else
if (um->phzones->gzoneno != NULL)
HandleGlobalZoneIds(mesh, domain, um->phzones->gzoneno,
um->phzones->nzones);
#endif
}
points->Delete();
DBFreeUcdmesh(um);
return rv;
}
// ****************************************************************************
// Function: MakePHZonelistFromZonelistArbFragment
//
// Purpose: Create a DBphzonelist object from a fragment of an ordinary
// zonelist defining DB_ZONETYPE_POLYHEDRON type zones.
//
// Programmer: Mark C. Miller, Wed Oct 28 20:46:22 PDT 2009
//
// ****************************************************************************
static DBphzonelist*
MakePHZonelistFromZonelistArbFragment(const int *nl, int shapecnt)
{
int i, j;
int ntotfaces = 0;
int nzones = 0;
vector<int> nodecnt, facecnt, nodelist, facelist;
while (nzones < shapecnt)
{
int nfaces = *nl++;
facecnt.push_back(nfaces);
for (i = 0; i < nfaces; i++)
{
facelist.push_back(ntotfaces++);
int nnodes = *nl++;
nodecnt.push_back(nnodes);
for (j = 0; j < nnodes; j++)
nodelist.push_back(*nl++);
}
nzones++;
}
//
// Use malloc here instead of new since we're creating a Silo structure
// that Silo will later expect to be able to call free on.
//
DBphzonelist *phzl = DBAllocPHZonelist();
phzl->nfaces = ntotfaces;
phzl->nodecnt = (int *) malloc(nodecnt.size() * sizeof(int));
memcpy(phzl->nodecnt, &nodecnt[0], nodecnt.size() * sizeof(int));
phzl->lnodelist = (int) nodelist.size();
phzl->nodelist = (int *) malloc(nodelist.size() * sizeof(int));
memcpy(phzl->nodelist, &nodelist[0], nodelist.size() * sizeof(int));
phzl->nzones = shapecnt;
phzl->facecnt = (int *) malloc(facecnt.size() * sizeof(int));
memcpy(phzl->facecnt, &facecnt[0], facecnt.size() * sizeof(int));
phzl->lfacelist = (int) facelist.size();
phzl->facelist = (int *) malloc(facelist.size() * sizeof(int));
memcpy(phzl->facelist, &facelist[0], facelist.size() * sizeof(int));
return phzl;
}
// ****************************************************************************
// Method: avtSiloFileFormat::ReadInConnectivity
//
// Purpose:
// Reads in the connectivity array. Also creates ghost zone information.
//
// Programmer: Hank Childs
// Creation: June 20, 2002
//
// Modifications:
//
// Hank Childs, Wed Jan 14 07:07:01 PST 2004
// Re-wrote to eliminate virtual function calls in inner loops.
//
// Hank Childs, Thu Jan 15 07:24:23 PST 2004
// Accounted for quads that are stored as hexahedrons.
//
// Hank Childs, Thu Jun 24 09:15:03 PDT 2004
// Make sure the cell locations for quads that are stored as hexahedrons
// is correct.
//
// Hank Childs, Fri Aug 27 17:18:37 PDT 2004
// Rename ghost zone arrays.
//
// Hank Childs, Tue Jan 11 14:48:38 PST 2005
// Translate tetrahedrons as well.
//
// Hank Childs, Tue Sep 5 17:19:35 PDT 2006
// Add logic for case where there really is one real zone and the rest
// are ghost ['7279].
//
// Hank Childs, Thu Jun 5 09:53:39 PDT 2008
// Add support for polygons that store the shapesize as 0.
//
// Mark C. Miller, Wed Oct 28 18:38:12 PDT 2009
// Handle arb. polyhedra better. Now uses same logic as truly arb. zonelist
// does.
//
// Mark C. Miller, Fri Oct 30 14:03:13 PDT 2009
// Handle Silo's DB_DTPTR configuration option.
//
// Mark C. Miller, Sun Nov 1 17:51:05 PST 2009
// Fixed off by one indexing problem for last+1...numCells loop to create
// ghost values. Fixed missing call to set VTK array name for ghost data.
// Fixed missing delete for gvals.
//
// Mark C. Miller, Wed Jan 27 13:14:03 PST 2010
// Added extra level of indirection to arbMeshXXXRemap objects to handle
// multi-block case.
//
// Mark C. Miller, Tue Apr 13 18:00:45 PDT 2010
// When handling 2D arbitrary polygons, if its 3 or 4 nodes, call it a
// triangle or quad instead of leaving it as a polygon.
// ****************************************************************************
void
avtSiloFileFormat::ReadInConnectivity(vtkUnstructuredGrid *ugrid,
DBzonelist *zl, int origin,
const char *meshname, int domain)
{
//
// A 'normal' zonelist in silo may contain some zones of arb. polyhedral
// type. In the past, the logic here simply 'skipped' these zones and we
// kept track of that skipping for zone-centered variables defined on
// the mesh. Now, we handle the arb. polyehdral zones 'correctly'. But,
// that is all handled here at the bottom of this function. All the
// logic prior to that simply walks over the arb. polyhedral zones but
// keeps track of where they occur in the zonelist so we can handle them
// later. Note that a setting of 'vtk_zonetype' of -2 represents the
// arb. polyhedral zonetype.
//
int i, j, k;
//
// Tell the ugrid how many cells it will have.
//
int numCells = 0;
int totalSize = 0;
const int *tmp = zl->nodelist;
for (i = 0 ; i < zl->nshapes ; i++)
{
int vtk_zonetype = SiloZoneTypeToVTKZoneType(zl->shapetype[i]);
if (vtk_zonetype != -2)
{
numCells += zl->shapecnt[i];
if (zl->shapesize[i] > 0)
{
totalSize += zl->shapecnt[i] * (zl->shapesize[i]+1);
tmp += zl->shapecnt[i] * zl->shapesize[i];
}
else
{
// Some polygons representations have the shapesize be 0 and
// each polygons # of nodes encoded as the first point ID.
for (j = 0 ; j < zl->shapecnt[i] ; j++)
{
totalSize += *tmp + 1;
tmp += *tmp+1;
}
}
}
}
//
// Tell the ugrid what its zones are.
//
int *nodelist = zl->nodelist;
vtkIdTypeArray *nlist = vtkIdTypeArray::New();
nlist->SetNumberOfValues(totalSize);
vtkIdType *nl = nlist->GetPointer(0);
vtkUnsignedCharArray *cellTypes = vtkUnsignedCharArray::New();
cellTypes->SetNumberOfValues(numCells);
unsigned char *ct = cellTypes->GetPointer(0);
vtkIdTypeArray *cellLocations = vtkIdTypeArray::New();
cellLocations->SetNumberOfValues(numCells);
vtkIdType *cl = cellLocations->GetPointer(0);
int currentIndex = 0;
int zoneIndex = 0;
bool mustResize = false;
vector<int> arbZoneIdxOffs;
vector<int> arbZoneCounts;
vector<int*> arbZoneNlOffs;
for (i = 0 ; i < zl->nshapes ; i++)
{
const int shapecnt = zl->shapecnt[i];
const int shapesize = zl->shapesize[i];
int vtk_zonetype = SiloZoneTypeToVTKZoneType(zl->shapetype[i]);
int effective_vtk_zonetype = vtk_zonetype;
int effective_shapesize = shapesize;
if (vtk_zonetype < 0 && vtk_zonetype != -2)
{
EXCEPTION1(InvalidZoneTypeException, zl->shapetype[i]);
}
//
// Some users store out quads as hexahedrons -- they store quad
// (a,b,c,d) as hex (a,b,c,d,a,b,c,d). Unfortunately, we have
// to detect this and account for it. I think it is safe to
// assume that if the first hex is that way, they all are.
// Similarly, if the first hex is not that way, none of them are.
//
if (vtk_zonetype == VTK_HEXAHEDRON)
{
if (shapecnt > 0) // Make sure there is at least 1 hex.
{
if ((nodelist[0] == nodelist[4]) &&
(nodelist[1] == nodelist[5]) &&
(nodelist[2] == nodelist[6]) &&
(nodelist[3] == nodelist[7]))
{
vtk_zonetype = -1;
effective_vtk_zonetype = VTK_QUAD;
effective_shapesize = 4;
mustResize = true;
}
}
}
//
// "Handle" arbitrary polyhedra by skipping over them here.
// We deal with them later on in this func.
//
if (vtk_zonetype == -2)
{
//
// There are shapecnt zones of arb. type in this segment
// of the zonelist. Record their count, indices and
// offset into nodelist for now.
//
arbZoneIdxOffs.push_back(zoneIndex);
arbZoneCounts.push_back(shapecnt);
arbZoneNlOffs.push_back(nodelist);
zoneIndex += shapecnt;
nodelist += shapesize;
}
else
{
bool tetsAreInverted = false;
bool firstTet = true;
for (j = 0 ; j < shapecnt ; j++, zoneIndex++)
{
*cl++ = currentIndex;
if (vtk_zonetype != VTK_WEDGE &&
vtk_zonetype != VTK_PYRAMID &&
vtk_zonetype != VTK_TETRA &&
vtk_zonetype != VTK_POLYGON &&
vtk_zonetype != -1)
{
*nl++ = shapesize;
for (k = 0 ; k < shapesize ; k++)
*nl++ = *(nodelist+k) - origin;
}
else if (vtk_zonetype == VTK_POLYGON)
{
// Handle both forms of storing polygons:
// 1) having all of the polygons with the same # of nodes
// in a group with a valid shapesize.
// 2) having the shapesize be 0 and each polygons # of nodes
// encoded as the first point ID.
if (shapesize > 0)
{
*nl++ = shapesize;
for (k = 0 ; k < shapesize ; k++)
*nl++ = *(nodelist+k) - origin;
/* correct stored cell type if its really a tri or quad */
if (shapesize == 3)
effective_vtk_zonetype = VTK_TRIANGLE;
else if (shapesize == 4)
effective_vtk_zonetype = VTK_QUAD;
}
else
{
int ss = *nodelist;
*nl++ = ss;
for (k = 0 ; k < ss; k++)
*nl++ = *(nodelist+k+1) - origin;
nodelist += ss+1;
/* correct stored cell type if its really a tri or quad */
if (ss == 3)
effective_vtk_zonetype = VTK_TRIANGLE;
else if (ss == 4)
effective_vtk_zonetype = VTK_QUAD;
effective_shapesize = ss;
}
}
else if (vtk_zonetype == VTK_WEDGE)
{
*nl++ = 6;
vtkIdType vtk_wedge[6];
TranslateSiloWedgeToVTKWedge(nodelist, vtk_wedge);
for (k = 0 ; k < 6 ; k++)
{
*nl++ = vtk_wedge[k]-origin;
}
}
else if (vtk_zonetype == VTK_PYRAMID)
{
*nl++ = 5;
vtkIdType vtk_pyramid[5];
TranslateSiloPyramidToVTKPyramid(nodelist, vtk_pyramid);
for (k = 0 ; k < 5 ; k++)
{
*nl++ = vtk_pyramid[k]-origin;
}
}
else if (vtk_zonetype == VTK_TETRA)
{
*nl++ = 4;
if (firstTet)
{
firstTet = false;
tetsAreInverted = TetIsInverted((vtkIdType*)nodelist, ugrid);
static bool haveIssuedWarning = false;
if (tetsAreInverted)
{
haveIssuedWarning = true;
char msg[1024];
SNPRINTF(msg, sizeof(msg), "An examination of the first tet "
"element in this mesh indicates that the node order is "
"inverted from Silo's standard conventions. All tets are "
"being automatically re-ordered.\n"
"Further messages of this issue will be suppressed.");
avtCallback::IssueWarning(msg);
}
}
vtkIdType vtk_tetra[4];
if (tetsAreInverted)
{
for (k = 0 ; k < 4 ; k++)
vtk_tetra[k] = nodelist[k];
}
else
{
TranslateSiloTetrahedronToVTKTetrahedron(nodelist,
vtk_tetra);
}
for (k = 0 ; k < 4 ; k++)
{
*nl++ = vtk_tetra[k]-origin;
}
}
else if (vtk_zonetype == -1)
{
*nl++ = 4;
for (k = 0 ; k < 4 ; k++)
*nl++ = *(nodelist+k);
}
*ct++ = effective_vtk_zonetype;
nodelist += shapesize;
currentIndex += effective_shapesize+1;
}
}
}
//
// This only comes up when somebody says they have hexahedrons, but they
// actually have quadrilaterals. In that case, we have allocated too much
// memory and need to resize. If we don't, VTK will get confused.
//
if (mustResize)
{
vtkIdTypeArray *nlist2 = vtkIdTypeArray::New();
vtkIdType *nl_orig = nlist->GetPointer(0);
int nvalues = nl-nl_orig;
nlist2->SetNumberOfValues(nvalues);
vtkIdType *nl2 = nlist2->GetPointer(0);
memcpy(nl2, nl_orig, nvalues*sizeof(vtkIdType));
nlist->Delete();
nlist = nlist2;
}
vtkCellArray *cells = vtkCellArray::New();
cells->SetCells(numCells, nlist);
nlist->Delete();
ugrid->SetCells(cellTypes, cellLocations, cells);
cellTypes->Delete();
cellLocations->Delete();
cells->Delete();
//
// Now, deal with any arbitrary polyhedral zones we encountered above.
//
vector<int> *cellReMap = 0;
if (arbZoneIdxOffs.size())
{
//
// Associate cell/node maps with the mesh so we can find and use 'em
// in subsequent GetVar calls.
//
cellReMap = new vector<int>;
vector<int> *nodeReMap = new vector<int>;
arbMeshCellReMap[meshname][domain] = cellReMap;
arbMeshNodeReMap[meshname][domain] = nodeReMap;
//
// Go ahead and add an empty avtOriginalCellNumbers array now.
// We'll populate it below.
//
vtkUnsignedIntArray *oca = vtkUnsignedIntArray::New();
oca->SetName("avtOriginalCellNumbers");
oca->SetNumberOfComponents(2);
ugrid->GetCellData()->AddArray(oca);
ugrid->GetCellData()->CopyFieldOn("avtOriginalCellNumbers");
//
// Build up the cellReMap array for all the non-arb. zones we've
// already put into the grid.
//
for (i = j = 0; i < zl->nzones; i++)
{
if (j < arbZoneIdxOffs.size() &&
i == arbZoneIdxOffs[j])
{
i += arbZoneCounts[j]-1; // -1 to undue i++ of for stmt.
j++;
continue;
}
unsigned int ocdata[2] = {domain, i};
oca->InsertNextTupleValue(ocdata);
cellReMap->push_back(i);
}
oca->Delete();
//
// Ok, we'll insert the arbitrary polyhedral zones by using
// ArbInsertArbitrary function.
//
for (i = 0; i < arbZoneIdxOffs.size(); i++)
{
int sum;
int *nl = arbZoneNlOffs[i];
int gz = arbZoneIdxOffs[i];
//
// Create a temp. Silo DBphzonelist object to call ArbInsertArbitrary.
//
DBphzonelist *phzl =
MakePHZonelistFromZonelistArbFragment(nl, arbZoneCounts[i]);
vector<int> nloffs, floffs;
for (j = 0, sum = 0; j < phzl->nfaces; sum += phzl->nodecnt[j], j++)
nloffs.push_back(sum);
for (j = 0, sum = 0; j < phzl->nzones; sum += phzl->facecnt[j], j++)
floffs.push_back(sum);
//
// Ok, now loop over this group of arb. polyhedral zones,
// adding them using ArbInsertArbitrary.
//
for (j = 0; j < arbZoneCounts[i]; j++, gz++)
{
unsigned int ocdata[2] = {domain, gz};
ArbInsertArbitrary(ugrid, phzl, j, nloffs, floffs,
ocdata, cellReMap, nodeReMap);
}
DBFreePHZonelist(phzl);
}
}
//
// Tell the ugrid which of its zones are real (avtGhostZone = 0),
// which are ghost (avtGhostZone = 1), but only create the ghost
// zones array if ghost zones are actually present.
//
const int first = zl->min_index; // where the real zones start
const int last = zl->max_index; // where the real zones end
if (first == 0 && last == 0 && numCells > 27)
{
debug5 << "Cannot tell if ghost zones are present"
<< " because min_index & max_index are both zero!" << endl;
}
else if (first < 0 || first >= numCells ||
last < 0 || last >= numCells)
{
// bad min or max index
debug5 << "Invalid min/max index for determining ghost zones: "
<< "\n\tnumCells: " << numCells
<< "\n\tmin_index: " << zl->min_index
<< "\n\tmax_index: " << zl->max_index << endl;
}
else if (first != 0 || last != numCells -1)
{
//
// We now know that ghost zones are present.
//
debug5 << "Creating ghost zones, real zones are indexed"
<< " from " << first << " to " << last
<< " of " << numCells << " Cells." << endl;
//
// Populate a zone-centered array of ghost zone values.
//
unsigned char *gvals = new unsigned char[numCells];
unsigned char val = 0;
avtGhostData::AddGhostZoneType(val, DUPLICATED_ZONE_INTERNAL_TO_PROBLEM);
for (i = 0; i < first; i++)
gvals[i] = val;
for (i = first; i <= last; i++)
gvals[i] = 0;
for (i = last+1; i < numCells; i++)
gvals[i] = val;
//
// Create a temp. DBucdvar object to call CopyUcdVar. That will handle
// both creation of the vtkUnsignedCharArray object as well as re-mapping
// of array as per existence of any arb. polyhedral zones.
//
DBucdvar tmp;
tmp.centering = DB_ZONECENT;
tmp.datatype = DB_CHAR;
tmp.nels = numCells;
tmp.nvals = 1;
#ifdef DB_DTPTR
tmp.vals = (DB_DTPTR**) new DB_DTPTR*[1];
tmp.vals[0] = (DB_DTPTR*) gvals;
#else
tmp.vals = (float**) new float*[1];
tmp.vals[0] = (float*) gvals;
#endif
vector<int> noremap;
vtkDataArray *ghostZones = CopyUcdVar<unsigned char,vtkUnsignedCharArray>(&tmp,
cellReMap?*cellReMap:noremap);
delete [] tmp.vals;
delete [] gvals;
ghostZones->SetName("avtGhostZones");
ugrid->GetCellData()->AddArray(ghostZones);
ghostZones->Delete();
// ugrid->SetUpdateGhostLevel(0);
}
}
static bool
QuadFaceIsTwisted(vtkUnstructuredGrid *ugrid, int *nids)
{
int i, j;
//
// initialize set of 4 points of quad
//
float *pts = (float *) ugrid->GetPoints()->GetVoidPointer(0);
float p[4][3];
for (i = 0; i < 4; i++)
{
for (j = 0; j < 3; j++)
p[i][j] = pts[3*nids[i] + j];
}
// Walk around quad, computing inner product of two edge vectors.
// You can have at most 2 negative inner products. If it is twisted,
// you will have 4 negative inner products. However, there
// is a numerical issue for a 'perfectly rectangular' quad because
// each inner product will be near zero but randomly to either
// side of it. So, we compare the inner product magnitude to
// an average of the two vector magnitudes and consider the
// inner product sign only when it is sufficiently. There is
// somewhat an assumption of planarity here. However, for near
// planar quads, the algorithm is expected to still work as the
// off-plane components that can skew the inner product are
// expected to be small. For very much non planar quads, this
// algorithm can fail.
int numNegiProds = 0;
for (i = 0; i < 4; i++)
{
float dotsum = 0.0;
float mag1sum = 0.0;
float mag2sum = 0.0;
for (j = 0; j < 3; j++)
{
float v1j = p[(i+1)%4][j] - p[(i+0)%4][j];
float v2j = p[(i+2)%4][j] - p[(i+1)%4][j];
mag1sum += v1j*v1j;
mag2sum += v2j*v2j;
dotsum += v1j * v2j;
}
if (dotsum < 0)
{
dotsum *= dotsum;
if (mag1sum * mag2sum > 0)
{
if (dotsum / (mag1sum * mag2sum) > 1e-8)
numNegiProds++;
}
}
}
if (numNegiProds > 2)
return true;
return false;
}
// ****************************************************************************
// Function: ArbInsertTet
//
// Purpose: Insert a tet element from the arbitrary connectivity.
//
// Programmer: Mark C. Miller, Wed Oct 7 11:24:34 PDT 2009
//
// ****************************************************************************
static void
ArbInsertTet(vtkUnstructuredGrid *ugrid, vtkIdType *nids, unsigned int ocdata[2],
vector<int> *cellReMap)
{
// Use the 'TetIsInverted' method here to determine whether this tet
// Is ordered correctly, relative to VTK. Note, in this context an
// affirmative response means that the Tet is 'ok' for VTK.
if (!TetIsInverted(nids, ugrid))
{
vtkIdType tmp = nids[0];
nids[0] = nids[1];
nids[1] = tmp;
}
ugrid->InsertNextCell(VTK_TETRA, 4, nids);
vtkUnsignedIntArray *oca = vtkUnsignedIntArray::SafeDownCast(
ugrid->GetCellData()->GetArray("avtOriginalCellNumbers"));
oca->InsertNextTupleValue(ocdata);
cellReMap->push_back(ocdata[1]);
}
// ****************************************************************************
// Function: ArbInsertPyramid
//
// Purpose: Insert a pyramid element from the arbitrary connectivity.
//
// Programmer: Mark C. Miller, Wed Oct 7 11:24:34 PDT 2009
//
// ****************************************************************************
static void
ArbInsertPyramid(vtkUnstructuredGrid *ugrid, vtkIdType *nids, unsigned int ocdata[2],
vector<int> *cellReMap)
{
// The nodes of the pyramid are given in the order that the
// first 4 define the quad 'base' and the last node defines
// the 'apex.'
// Now the idea is to compute a normal to the 'base' quad face
// and confirm the fifth point is on the correct side of that face.
// However, we already have code that basically does that for a tet,
// forming a plane with the first 3 nodes and then determining if
// the 4th node is on the INward or OUTward side of that plane.
// So, we spoof up a set of 4 nodes here to pass to that routine.
// The first three nodes are taken from the first three nodes of
// the base quad of the pyramid. The last node is the 5th node of the
// pyramid. Again, an affirmative from TetIsInverted means order
// is ok for VTK
vtkIdType tmpnids[5];
tmpnids[0] = nids[0];
tmpnids[1] = nids[1];
tmpnids[2] = nids[2];
tmpnids[3] = nids[4];
if (!TetIsInverted(tmpnids, ugrid))
{
// Reverse the order of the 'base' quad's nodes.
tmpnids[0] = nids[3];
tmpnids[1] = nids[2];
tmpnids[2] = nids[1];
tmpnids[3] = nids[0];
tmpnids[4] = nids[4];
ugrid->InsertNextCell(VTK_PYRAMID, 5, tmpnids);
}
else
{
ugrid->InsertNextCell(VTK_PYRAMID, 5, nids);
}
vtkUnsignedIntArray *oca = vtkUnsignedIntArray::SafeDownCast(
ugrid->GetCellData()->GetArray("avtOriginalCellNumbers"));
oca->InsertNextTupleValue(ocdata);
cellReMap->push_back(ocdata[1]);
}
// ****************************************************************************
// Function: ArbInsertWedge
//
// Purpose: Insert a wedge element from the arbitrary connectivity.
//
// Programmer: Mark C. Miller, Wed Oct 7 11:24:34 PDT 2009
//
// ****************************************************************************
static void
ArbInsertWedge(vtkUnstructuredGrid *ugrid, vtkIdType *nids, unsigned int ocdata[2],
vector<int> *cellReMap)
{
// The nodes of a wedge are specified such that the first
// 3 define one triangle end and the next 3 define the other
// triangle end. We only have to deal with whether their
// orders need to be reversed.
// Just as for pyramid, we use TetIsInverted to determine
// whether or not we have correct orientation the first of
// the latter 3 face nodes relative to the first 3. So, that
// just means use the first 4 nodes of nids for the test.
if (!TetIsInverted(nids, ugrid))
{
// Reverse the order of the first 3 nodes defining one
// face of the wedge.
int tmp = nids[2];
nids[2] = nids[0];
nids[0] = tmp;
}
// VTK's node order is such that a right hand rule normal
// to the other triangular end points inward.
vtkIdType tmpnids[4];
tmpnids[0] = nids[3];
tmpnids[1] = nids[4];
tmpnids[2] = nids[5];
tmpnids[3] = nids[0];
if (TetIsInverted(tmpnids, ugrid))
{
// Reverse the order of the latter 3 nodes defining other
// face of the wedge.
int tmp = nids[5];
nids[5] = nids[3];
nids[3] = tmp;
}
ugrid->InsertNextCell(VTK_WEDGE, 6, nids);
vtkUnsignedIntArray *oca = vtkUnsignedIntArray::SafeDownCast(
ugrid->GetCellData()->GetArray("avtOriginalCellNumbers"));
oca->InsertNextTupleValue(ocdata);
cellReMap->push_back(ocdata[1]);
}
// ****************************************************************************
// Function: ArbInsertHex
//
// Purpose: Insert a hex element from the arbitrary connectivity.
//
// Programmer: Mark C. Miller, Wed Oct 7 11:24:34 PDT 2009
//
// ****************************************************************************
static void
ArbInsertHex(vtkUnstructuredGrid *ugrid, vtkIdType *nids, unsigned int ocdata[2],
vector<int> *cellReMap)
{
// The nodes for a hex are specified here such that the
// the first 4 loop around 1 quad face and the second 4
// loop around the opposing face. Again, as in the other
// cases, we use TetIsInverted with the first 3 nodes of
// a quad face and one the nodes of the opposing face to
// determine whether the node order needs reversing. In
// the VTK ordering, right hand rule on the first 4 nodes
// defines an INward normal while on the last 4 defines
// an outward normal.
vtkIdType tmpnids[4];
tmpnids[0] = nids[0]; // first 3 nodes from first quad
tmpnids[1] = nids[1];
tmpnids[2] = nids[2];
tmpnids[3] = nids[4]; // last node from opposing quad
if (TetIsInverted(tmpnids, ugrid))
{
// Reverse the order of the first 4 nodes by swaping the
// ends and the middle nodes.
vtkIdType tmp = nids[3];
nids[3] = nids[0];
nids[0] = tmp;
tmp = nids[2];
nids[2] = nids[1];
nids[1] = tmp;
}
tmpnids[0] = nids[4]; // first 3 nodes from opposing quad
tmpnids[1] = nids[5];
tmpnids[2] = nids[6];
tmpnids[3] = nids[0]; // last node from first quad
if (!TetIsInverted(tmpnids, ugrid))
{
// Reverse the order of the last 4 nodes by swaping the
// ends and the middle nodes.
vtkIdType tmp = nids[7];
nids[7] = nids[4];
nids[4] = tmp;
tmp = nids[6];
nids[6] = nids[5];
nids[5] = tmp;
}
ugrid->InsertNextCell(VTK_HEXAHEDRON, 8, nids);
vtkUnsignedIntArray *oca = vtkUnsignedIntArray::SafeDownCast(
ugrid->GetCellData()->GetArray("avtOriginalCellNumbers"));
oca->InsertNextTupleValue(ocdata);
cellReMap->push_back(ocdata[1]);
}
// ****************************************************************************
// Function: ArbInsertArbitrary
//
// Purpose: Insert a truly 'arbitrary' zone into the ucdmesh object by
// decomposing it into zoo-type pyramid and tet cells. We do this by first
// computing a cell center. Then, for each face, find the node of lowest
// global node number. Start walking around the face from there in two
// directions; one up around the 'top' and the other down around the
// 'bottom.' Using either 4 or 3 nodes on the face along with the newly
// created cell center node (created above), define either pyramid or tet
// elements. If the number of nodes around the face is even, we'll have
// only pyramids. If it is odd, we'll have one tet, too. Otherwise, we'll
// have only pyramids. By starting on the node of lowest global node number,
// we ensure that a given face is always decomposed the same way by both
// zones that share the face. We repeat this process for each face of the
// arbitrary zone.
//
// Programmer: Mark C. Miller, Wed Oct 7 11:24:34 PDT 2009
//
// Modifications:
// Mark C. Miller, Wed Oct 21 03:48:24 PDT 2009
// Fixed setting of 'mingn' when a new min is found.
//
// Mark C. Miller, Wed Oct 28 20:47:40 PDT 2009
// Adjusted interface to take DBphzonelist* as second arg instead of
// DBucdmesh*.
// ****************************************************************************
static void
ArbInsertArbitrary(vtkUnstructuredGrid *ugrid, DBphzonelist *phzl, int gz,
const vector<int> &nloffs, const vector<int> &floffs, unsigned int ocdata[2],
vector<int> *cellReMap, vector<int> *nodeReMap)
{
//
// Compute cell center and insert it into the ugrid
//
double coord_sum[3] = {0.0, 0.0, 0.0};
int fcnt = phzl->facecnt[gz];
vector<int> lnmingnvec;
map<int,int> nodemap;
int ncnttot = 0, lf, k;
for (lf = 0; lf < fcnt; lf++) // lf = local face #
{
int lnmingn;
int mingn = INT_MAX;
int flidx = floffs[gz]+lf; // flidx = index into facelist
int sgf = phzl->facelist[flidx]; // sgf = signed global face #
int gf = sgf < 0 ? ~sgf : sgf; // gf = global face #
int ncnt = phzl->nodecnt[gf]; // ncnt = # nodes for this face
for (int ln = 0; ln < ncnt; ln++) // ln = local node #
{
int nlidx = nloffs[gf]+ln; // nlidx = index into nodelist
int gn = phzl->nodelist[nlidx]; // gn = global node #
if (gn < mingn)
{
mingn = gn;
lnmingn = ln;
}
if (nodemap.find(gn) != nodemap.end())
continue;
nodemap[gn] = 1;
for (k = 0; k < 3; k++)
coord_sum[k] += ugrid->GetPoints()->GetPoint(gn)[k];
ncnttot++;
}
lnmingnvec.push_back(lnmingn);
}
for (k = 0; k < 3; k++)
coord_sum[k] /= ncnttot;
int cmidn = ugrid->GetPoints()->InsertNextPoint(coord_sum);
nodeReMap->push_back(nodemap.size());
for (map<int,int>::iterator it = nodemap.begin(); it != nodemap.end(); it++)
nodeReMap->push_back(it->first);
//
// Loop over faces, creating pyramid and tets using 4 or
// 3 nodes on the face and the cell center.
//
for (lf = 0; lf < fcnt; lf++) // lf = local face #
{
int flidx = floffs[gz]+lf; // flidx = index into facelist
int sgf = phzl->facelist[flidx]; // sgf = signed global face #
int gf = sgf < 0 ? ~sgf : sgf; // gf = global face #
int ncnt = phzl->nodecnt[gf]; // ncnt = # nodes for this face
int newcellcnt = ncnt / 2 - ((ncnt%2)?0:1);
int lnmingn = lnmingnvec[lf];
int toplast = (lnmingn==ncnt-1)?0:lnmingn+1;
int botlast = lnmingn;
int topcur = (toplast==ncnt-1)?0:toplast+1;
int botcur = (botlast==0)?ncnt-1:botlast-1;
int nloff = nloffs[gf];
for (int c = 0; c < newcellcnt; c++)
{
if (c == newcellcnt-1 && ncnt%2)
{
vtkIdType nids[4];
nids[0] = phzl->nodelist[nloff+botcur];
nids[1] = phzl->nodelist[nloff+botlast];
nids[2] = phzl->nodelist[nloff+toplast];
nids[3] = cmidn;
ArbInsertTet(ugrid, nids, ocdata, cellReMap);
}
else
{
vtkIdType nids[5];
nids[0] = phzl->nodelist[nloff+botcur];
nids[1] = phzl->nodelist[nloff+botlast];
nids[2] = phzl->nodelist[nloff+toplast];
nids[3] = phzl->nodelist[nloff+topcur];
nids[4] = cmidn;
ArbInsertPyramid(ugrid, nids, ocdata, cellReMap);
}
toplast = topcur;
topcur = (topcur==ncnt-1)?0:topcur+1;
botlast = botcur;
botcur = (botcur==0)?ncnt-1:botcur-1;
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::ReadInArbConnectivity
//
// Purpose: Read arbitrary connectivity, smartly. That is, recognize elements
// stored here, using arbitrary connectivity that are really the known zoo
// type elements and then treat them as such. Otherwise, for all other zones,
// decompose them into collections of pyramids and tets by adding a single
// new node at the cell centers and 'fanning out' pyramids and tets for each
// face around the zone to fill in the volume of the zone.
//
// Programmer: Mark C. Miller, Wed Oct 7 11:24:34 PDT 2009
//
// Mark C. Miller, Wed Oct 28 08:20:41 PDT 2009
// Added logic to manage ghost zone information through the remap process.
//
// Mark C. Miller, Fri Oct 30 14:03:13 PDT 2009
// Handle Silo's DB_DTPTR configuration option.
//
// Mark C. Miller, Sun Nov 1 17:51:05 PST 2009
// Fixed off by one indexing problem for hi_off+1...numCells loop to create
// ghost values. Fixed missing delete for gvals.
//
// Mark C. Miller, Wed Jan 27 13:14:03 PST 2010
// Added extra level of indirection to arbMeshXXXRemap objects to handle
// multi-block case.
//
// Mark C. Miller, Mon Mar 29 17:28:33 PDT 2010
// Fixed cut-n-paste error where arbMeshCellReMap entry was NOT erased
// at the end of this routine if no new points were inserted.
// ****************************************************************************
void
avtSiloFileFormat::ReadInArbConnectivity(const char *meshname,
vtkUnstructuredGrid *ugrid, DBucdmesh *um, int domain)
{
int i, j, sum;
DBphzonelist *phzl = um->phzones;
if (!phzl)
return;
//
// Go ahead and add an empty avtOriginalCellNumbers array now.
// We'll populate it as we proceed but, if we never encounter
// truly arbitrary zones, we'll remove it at the end because we
// won't actually need it.
//
vtkUnsignedIntArray *oca = vtkUnsignedIntArray::New();
oca->SetName("avtOriginalCellNumbers");
oca->SetNumberOfComponents(2);
ugrid->GetCellData()->AddArray(oca);
ugrid->GetCellData()->CopyFieldOn("avtOriginalCellNumbers");
oca->Delete();
//
// Instantiate cell- and node- re-mapping arrays. Just as for
// avtOriginalCellNumbers, if we find out we don't need 'em, we
// remove them at the end. Note that due to the way we traverse
// the arb. polyhedral connectivity information and produce zones
// in the output mesh, the nodes will always be organized such
// that all the nodes of the original mesh come first, followed
// by all the nodes that get inserted for arb. polyhedra cell
// centers. For this reason, the nodeReMap vector is defined
// only for those 'extra' nodes.
//
vector<int> *nodeReMap = new vector<int>;
map<string, map<int, vector<int>* > >::iterator domit;
if ((domit = arbMeshNodeReMap.find(meshname)) != arbMeshNodeReMap.end() &&
domit->second.find(domain) != domit->second.end())
delete domit->second[domain];
arbMeshNodeReMap[meshname][domain] = nodeReMap;
vector<int> *cellReMap = new vector<int>;
if ((domit = arbMeshCellReMap.find(meshname)) != arbMeshCellReMap.end() &&
domit->second.find(domain) != domit->second.end())
delete domit->second[domain];
arbMeshCellReMap[meshname][domain] = cellReMap;
// build up random access offset indices into nodelist and facelist lists
vector<int> nloffs;
for (i = 0, sum = 0; i < phzl->nfaces; sum += phzl->nodecnt[i], i++)
nloffs.push_back(sum);
vector<int> floffs;
for (i = 0, sum = 0; i < phzl->nzones; sum += phzl->facecnt[i], i++)
floffs.push_back(sum);
for (int gz = 0; gz < phzl->nzones; gz++) // gz = global zone #
{
int fcnt = phzl->facecnt[gz]; // fcnt = # faces for this zone
unsigned int ocdata[2] = {domain, gz};
if (fcnt == 4 || // Must be tet
fcnt == 5 || // Maybe pyramid or prism/wedge
fcnt == 6) // Maybe hex
{
// Iterate over all faces for this zone finding the UNIQUE
// set of nodes the union of all the faces references. Also,
// along the way, keep track of total number of 3 node (tri)
// and 4 node (quad) faces as well as the first of these
// encountered and the face that 'opposes' those first faces,
// if any.
bool isNotZooElement = false;
int num3NodeFaces = 0;
int num4NodeFaces = 0;
int first3NodeFace = -INT_MAX;
int first4NodeFace = -INT_MAX;
int opposing3NodeFace = -INT_MAX;
int opposing4NodeFace = -INT_MAX;
map<int, int> nodemap; // Map used for unique node #'s
int nloff;
for (int lf = 0; lf < fcnt; lf++) // lf = local face #
{
int flidx = floffs[gz]+lf; // flidx = index into facelist
int sgf = phzl->facelist[flidx]; // sgf = signed global face #
int gf = sgf < 0 ? ~sgf : sgf; // gf = global face #
int ncnt = phzl->nodecnt[gf]; // ncnt = # nodes for this face
if (ncnt == 3)
{
if (num3NodeFaces == 0)
first3NodeFace = sgf;
num3NodeFaces++;
}
else if (ncnt == 4)
{
if (num4NodeFaces == 0)
first4NodeFace = sgf;
num4NodeFaces++;
}
else
{
// Since this face is neither a tri or quad, this
// cannot be a zoo element.
isNotZooElement = true;
break;
}
bool nodesInCommonWithFirst = false;
for (int ln = 0; ln < ncnt; ln++) // ln = local node #
{
int nlidx = nloffs[gf]+ln; // nlidx = index into nodelist
int gn = phzl->nodelist[nlidx]; // gn = global node #
nodemap[gn] = ln;
// See if this face has any nodes in common with 'first'
if (lf > 0 && !nodesInCommonWithFirst)
{
int gftmp;
if (first3NodeFace != -INT_MAX)
gftmp = first3NodeFace < 0 ? ~first3NodeFace: first3NodeFace;
else if (first4NodeFace != -INT_MAX)
gftmp = first4NodeFace < 0 ? ~first4NodeFace: first4NodeFace;
for (j = 0; j < phzl->nodecnt[gftmp]; j++)
{
if (gn == phzl->nodelist[nloffs[gftmp]+j])
{
nodesInCommonWithFirst = true;
break;
}
}
}
}
if (!nodesInCommonWithFirst)
{
if (ncnt == 3)
opposing3NodeFace = sgf;
else
opposing4NodeFace = sgf;
}
}
vtkIdType nids[8];
map<int, int>::iterator it;
if (isNotZooElement) // Arbitrary
{
ArbInsertArbitrary(ugrid, phzl, gz, nloffs, floffs, ocdata,
cellReMap, nodeReMap);
}
else if (fcnt == 4 && nodemap.size() == 4 &&
num3NodeFaces == 4 && num4NodeFaces == 0) // Tet
{
// Just get all 4 nodes from the nodemap
for (it = nodemap.begin(), j = 0; it != nodemap.end() && j < 4; it++, j++)
nids[j] = it->first;
ArbInsertTet(ugrid, nids, ocdata, cellReMap);
}
else if (fcnt == 5 && nodemap.size() == 5 &&
num3NodeFaces == 4 && num4NodeFaces == 1) // Pyramid
{
// Get first 4 nodes from first4NodeFace
nloff = nloffs[first4NodeFace<0?~first4NodeFace:first4NodeFace];
for (j = 0; j < 4; j++)
{
nids[j] = phzl->nodelist[nloff+j];
nodemap.erase(nids[j]);
}
// Get last node from only remaining node in nodemap
for (it = nodemap.begin(), j = 0; it != nodemap.end() && j < 1; it++, j++)
nids[4+j] = it->first;
ArbInsertPyramid(ugrid, nids, ocdata, cellReMap);
}
else if (fcnt == 5 && nodemap.size() == 6 &&
num3NodeFaces == 2 && num4NodeFaces == 3) // Prism/Wedge
{
// Get first 3 nodes from first3NodeFace
nloff = nloffs[first3NodeFace<0?~first3NodeFace:first3NodeFace];
for (j = 0; j < 3; j++)
nids[j] = phzl->nodelist[nloffs[nloff]+j];
// Get next 3 nodes from opposing3NodeFace
nloff = nloffs[opposing3NodeFace<0?~opposing3NodeFace:opposing3NodeFace];
for (j = 0; j < 3; j++)
nids[3+j] = phzl->nodelist[nloffs[nloff]+j];
ArbInsertWedge(ugrid, nids, ocdata, cellReMap);
}
else if (fcnt == 6 && nodemap.size() == 8 &&
num3NodeFaces == 0 && num4NodeFaces == 6) // Hex
{
// Get first 4 nodes from first4NodeFace
nloff = nloffs[first4NodeFace<0?~first4NodeFace:first4NodeFace];
for (j = 0; j < 4; j++)
nids[j] = phzl->nodelist[nloff+j];
// Get next 4 nodes from opposing4NodeFace
nloff = nloffs[opposing4NodeFace<0?~opposing4NodeFace:opposing4NodeFace];
for (j = 0; j < 4; j++)
nids[4+j] = phzl->nodelist[nloff+j];
ArbInsertHex(ugrid, nids, ocdata, cellReMap);
}
else // Arbitrary
{
ArbInsertArbitrary(ugrid, phzl, gz, nloffs, floffs, ocdata,
cellReMap, nodeReMap);
}
}
else // Arbitrary
{
ArbInsertArbitrary(ugrid, phzl, gz, nloffs, floffs, ocdata,
cellReMap, nodeReMap);
}
}
//
// Handle the ghost zoning, if necessary. We can do this easily now that
// the mesh has been re-mapped to all ucd elements. We use the cell
// centered re-mapping, if any, to make it work.
//
if (phzl->lo_offset != 0 || phzl->hi_offset != phzl->nzones-1)
{
//
// Populate a zone-centered array of ghost zone values.
//
unsigned char *gvals = new unsigned char[phzl->nzones];
unsigned char val = 0;
avtGhostData::AddGhostZoneType(val, DUPLICATED_ZONE_INTERNAL_TO_PROBLEM);
for (i = 0; i < phzl->lo_offset; i++)
gvals[i] = val;
for (i = phzl->lo_offset; i <= phzl->hi_offset; i++)
gvals[i] = 0;
for (i = phzl->hi_offset+1; i < phzl->nzones; i++)
gvals[i] = val;
//
// Remap the zone-centered array based on arb-poly remapping
// computed above.
//
vector<int> noremap;
vector<int> *remap = &noremap;
if (ugrid->GetNumberOfPoints() <= um->nnodes)
remap = cellReMap;
DBucdvar tmp;
tmp.centering = DB_ZONECENT;
tmp.datatype = DB_CHAR;
tmp.nels = phzl->nzones;
tmp.nvals = 1;
#ifdef DB_DTPTR
tmp.vals = (DB_DTPTR**) new DB_DTPTR*[1];
tmp.vals[0] = (DB_DTPTR*) gvals;
#else
tmp.vals = (float**) new float*[1];
tmp.vals[0] = (float*) gvals;
#endif
vtkDataArray *ghostZones = CopyUcdVar<unsigned char,vtkUnsignedCharArray>(&tmp, *remap);
delete [] tmp.vals;
delete [] gvals;
//
// Assign the ghost zone array to the ugrid object.
//
ghostZones->SetName("avtGhostZones");
ugrid->GetCellData()->AddArray(ghostZones);
ghostZones->Delete();
// ugrid->SetUpdateGhostLevel(0);
}
//
// Remove the avtOriginalCellNumbers array if we don't really
// need it. The indicator of that condtion is if new nodes were
// added to the ugrid object. That only happens for truly arbitrary
// polyhedra. In that case, the number of points in the ugrid
// object will be greater than the input DBucdmesh. In addition,
// if we didn't add any nodes, then we don't need to maintain
// any special cell-data or nodal-data remapping arrays.
//
if (ugrid->GetNumberOfPoints() <= um->nnodes)
{
ugrid->GetCellData()->RemoveArray("avtOriginalCellNumbers");
arbMeshNodeReMap.find(meshname)->second.erase(domain);
arbMeshCellReMap.find(meshname)->second.erase(domain);
delete cellReMap;
delete nodeReMap;
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetQuadMesh
//
// Purpose:
// Determines if the quadmesh is a rectilinear or curvilinear mesh and
// calls the right routine to fetch it.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// mn The mesh name.
// mn The domain.
//
// Returns: The vtkDataSet corresponding to mn.
//
// Programmer: Hank Childs
// Creation: November 1, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, added file argument to account for
// Silo objects distributed across multiple files.
//
// Kathleen Bonnell, Tue Jun 12 14:34:02 PDT 2001
// Added call to method GetQuadGhostZones.
//
// Hank Childs, Tue Mar 5 16:53:16 PST 2002
// Verify that the dimensions of a quadmesh are correct.
//
// Hank Childs, Tue Jun 25 16:29:12 PDT 2002
// Add the base indices as field data to the VTK dataset.
//
// Kathleen Bonnell, Tue Feb 8 13:41:05 PST 2005
// Added int arg for domain, to be used in retrieving connectivity extents
// for setting base_index when necessary.
//
// Jeremy Meredith, Tue Jun 7 08:32:46 PDT 2005
// Added support for "EMPTY" domains in multi-objects.
//
// Cyrus Harrison, Thu Apr 26 10:14:42 PDT 2007
// Added group_id as field data to the VTK dataset.
//
// Mark C. Miller, Tue Mar 3 19:35:35 PST 2009
// Predicated addition of "group_id" as field data on it having
// non-negative value.
//
// Brad Whitlock, Fri Aug 7 11:11:29 PDT 2009
// I added some exception handling.
//
// ****************************************************************************
vtkDataSet *
avtSiloFileFormat::GetQuadMesh(DBfile *dbfile, const char *mn, int domain)
{
//
// Allow empty data sets
//
if (string(mn) == "EMPTY")
return NULL;
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *meshname = const_cast<char *>(mn);
//
// Get the Silo construct.
//
DBquadmesh *qm = DBGetQuadmesh(dbfile, meshname);
if (qm == NULL)
{
EXCEPTION1(InvalidVariableException, meshname);
}
VerifyQuadmesh(qm, meshname);
vtkDataSet *ds = NULL;
TRY
{
if (qm->coordtype == DB_COLLINEAR)
ds = CreateRectilinearMesh(qm);
else
ds = CreateCurvilinearMesh(qm);
}
CATCH(VisItException)
{
DBFreeQuadmesh(qm);
RETHROW;
}
ENDTRY
GetQuadGhostZones(qm, ds);
//
// Add group id as field data
//
if (qm->group_no >= 0)
{
vtkIntArray *grp_id_arr = vtkIntArray::New();
grp_id_arr->SetNumberOfTuples(1);
grp_id_arr->SetValue(0, qm->group_no);
grp_id_arr->SetName("group_id");
ds->GetFieldData()->AddArray(grp_id_arr);
grp_id_arr->Delete();
}
//
// Determine the indices of the mesh within its group. Add that to the
// VTK dataset as field data.
//
vtkIntArray *arr = vtkIntArray::New();
arr->SetNumberOfTuples(3);
arr->SetValue(0, qm->base_index[0]);
arr->SetValue(1, qm->base_index[1]);
arr->SetValue(2, qm->base_index[2]);
arr->SetName("base_index");
//
// If we're not really sure that the base_index was set in the file,
// check for connectivity info.
//
if (qm->base_index[0] == 0 &&
qm->base_index[1] == 0 &&
qm->base_index[2] == 0)
{
void_ref_ptr vr = cache->GetVoidRef("any_mesh",
AUXILIARY_DATA_DOMAIN_BOUNDARY_INFORMATION, -1, -1);
if (*vr != NULL)
{
avtStructuredDomainBoundaries *dbi =
(avtStructuredDomainBoundaries*)*vr;
if (dbi != NULL)
{
int ext[6];
dbi->GetExtents(domain, ext);
arr->SetValue(0, ext[0]);
arr->SetValue(1, ext[2]);
arr->SetValue(2, ext[4]);
}
}
}
ds->GetFieldData()->AddArray(arr);
arr->Delete();
DBFreeQuadmesh(qm);
return ds;
}
// ****************************************************************************
// Method: avtSiloFileFormat::VerifyQuadmesh
//
// Purpose:
// Determines if a quadmesh has invalid dimensions and tries to
// compensate if it does.
//
// Arguments:
// qm A quad mesh.
// meshname The name of the mesh.
//
// Programmer: Hank Childs
// Creation: March 5, 2002
//
// Modifications:
//
// Hank Childs, Wed Mar 6 15:00:21 PST 2002
// Added better support for 2D, since sloppy coding had caused perfectly
// fine 2D meshes to be tagged as bad.
//
// ****************************************************************************
void
avtSiloFileFormat::VerifyQuadmesh(DBquadmesh *qm, const char *meshname)
{
if (qm->ndims == 3)
{
//
// Make sure the dimensions are correct.
//
if (qm->nnodes != qm->dims[0]*qm->dims[1]*qm->dims[2])
{
if (qm->dims[0] > 100000 || qm->dims[1] > 100000
|| qm->dims[2] > 100000)
{
int orig[3];
orig[0] = qm->dims[0];
orig[1] = qm->dims[1];
orig[2] = qm->dims[2];
//
// See if the max_index has any clues, first without ghost
// zones, then with.
//
if (qm->nnodes == qm->max_index[0] * qm->max_index[1]
* qm->max_index[2])
{
qm->dims[0] = qm->max_index[0];
qm->dims[1] = qm->max_index[1];
qm->dims[2] = qm->max_index[2];
}
else if (qm->nnodes == (qm->max_index[0]+1) *
(qm->max_index[1]+1) * (qm->max_index[2]+1))
{
qm->dims[0] = qm->max_index[0]+1;
qm->dims[1] = qm->max_index[1]+1;
qm->dims[2] = qm->max_index[2]+1;
}
else if (qm->nnodes == (qm->max_index[0]) *(qm->max_index[1]+1)
* (qm->max_index[2]+1))
{
qm->dims[0] = qm->max_index[0];
qm->dims[1] = qm->max_index[1]+1;
qm->dims[2] = qm->max_index[2]+1;
}
else if (qm->nnodes == (qm->max_index[0]+1) *(qm->max_index[1])
* (qm->max_index[2]+1))
{
qm->dims[0] = qm->max_index[0]+1;
qm->dims[1] = qm->max_index[1];
qm->dims[2] = qm->max_index[2]+1;
}
else if (qm->nnodes == (qm->max_index[0]+1) *
(qm->max_index[1]+1) * (qm->max_index[2]))
{
qm->dims[0] = qm->max_index[0]+1;
qm->dims[1] = qm->max_index[1]+1;
qm->dims[2] = qm->max_index[2];
}
else if (qm->nnodes == (qm->max_index[0]) * (qm->max_index[1])
* (qm->max_index[2]+1))
{
qm->dims[0] = qm->max_index[0];
qm->dims[1] = qm->max_index[1];
qm->dims[2] = qm->max_index[2]+1;
}
else if (qm->nnodes == (qm->max_index[0]) *(qm->max_index[1]+1)
* (qm->max_index[2]))
{
qm->dims[0] = qm->max_index[0];
qm->dims[1] = qm->max_index[1]+1;
qm->dims[2] = qm->max_index[2];
}
else if (qm->nnodes == (qm->max_index[0]+1) *(qm->max_index[1])
* (qm->max_index[2]))
{
qm->dims[0] = qm->max_index[0]+1;
qm->dims[1] = qm->max_index[1];
qm->dims[2] = qm->max_index[2];
}
else
{
debug1 << "The dimensions of the mesh did not match the "
<< "number of nodes, cannot continue" << endl;
EXCEPTION1(InvalidVariableException, meshname);
}
char msg[1024];
sprintf(msg, "A quadmesh had dimensions %d, %d, %d, which did "
"not result in the specified number of nodes (%d). "
"The dimensions are being adjusted to %d, %d, %d",
orig[0], orig[1], orig[2], qm->nnodes, qm->dims[0],
qm->dims[1], qm->dims[2]);
avtCallback::IssueWarning(msg);
}
else if (qm->nnodes > 10000000)
{
int orig = qm->nnodes;
qm->nnodes = qm->dims[0]*qm->dims[1]*qm->dims[2];
if (orig < 10000000)
{
char msg[1024];
sprintf(msg, "The number of nodes is stored as %d, but "
"that not agree with the dimensions "
"(= %d %d %d). Correcting to: %d",
orig, qm->dims[0], qm->dims[1], qm->dims[2],
qm->nnodes);
avtCallback::IssueWarning(msg);
}
else
{
debug1 << "The dimensions of the mesh did not match the "
<< "number of nodes, cannot continue" << endl;
EXCEPTION1(InvalidVariableException, meshname);
}
}
else
{
debug1 << "The dimensions of the mesh did not match the "
<< "number of nodes, cannot continue" << endl;
EXCEPTION1(InvalidVariableException, meshname);
}
}
}
else if (qm->ndims == 2)
{
//
// Make sure the dimensions are correct.
//
if (qm->nnodes != qm->dims[0]*qm->dims[1])
{
if (qm->dims[0] > 100000 || qm->dims[1] > 100000)
{
int orig[2];
orig[0] = qm->dims[0];
orig[1] = qm->dims[1];
//
// See if the max_index has any clues, first without ghost
// zones, then with.
//
if (qm->nnodes == qm->max_index[0] * qm->max_index[1])
{
qm->dims[0] = qm->max_index[0];
qm->dims[1] = qm->max_index[1];
}
else if (qm->nnodes == (qm->max_index[0]+1) *
(qm->max_index[1]+1))
{
qm->dims[0] = qm->max_index[0]+1;
qm->dims[1] = qm->max_index[1]+1;
}
else if (qm->nnodes == (qm->max_index[0])*(qm->max_index[1]+1))
{
qm->dims[0] = qm->max_index[0];
qm->dims[1] = qm->max_index[1]+1;
}
else if (qm->nnodes == (qm->max_index[0]+1)*(qm->max_index[1]))
{
qm->dims[0] = qm->max_index[0]+1;
qm->dims[1] = qm->max_index[1];
}
else
{
debug1 << "The dimensions of the mesh did not match the "
<< "number of nodes, cannot continue" << endl;
EXCEPTION1(InvalidVariableException, meshname);
}
char msg[1024];
sprintf(msg, "A quadmesh had dimensions %d, %d, which did "
"not result in the specified number of nodes (%d). "
"The dimensions are being adjusted to %d, %d",
orig[0], orig[1],qm->nnodes,qm->dims[0],qm->dims[1]);
avtCallback::IssueWarning(msg);
}
else if (qm->nnodes > 10000000)
{
int orig = qm->nnodes;
qm->nnodes = qm->dims[0]*qm->dims[1];
if (orig < 10000000)
{
char msg[1024];
sprintf(msg, "The number of nodes is stored as %d, but "
"that not agree with the dimensions "
"(= %d %d). Correcting to: %d",
orig, qm->dims[0], qm->dims[1], qm->nnodes);
avtCallback::IssueWarning(msg);
}
else
{
debug1 << "The dimensions of the mesh did not match the "
<< "number of nodes, cannot continue" << endl;
EXCEPTION1(InvalidVariableException, meshname);
}
}
else
{
debug1 << "The dimensions of the mesh did not match the "
<< "number of nodes, cannot continue" << endl;
EXCEPTION1(InvalidVariableException, meshname);
}
}
}
}
// ****************************************************************************
// Method: CreateCurve
//
// Purpose:
// Creates a curve from a DBcurve.
//
// Arguments:
// cur : The curve
// curvename : The curve name.
// vtkType : The type of coordinates to create.
//
// Returns: A new vtkRectilinearGrid.
//
// Note:
//
// Programmer: Mark Miller
// Creation: Thu Aug 6 12:16:00 PDT 2009
//
// Modifications:
// Brad Whitlock, Thu Aug 6 12:16:09 PDT 2009
// I moved this block out from GetCurve and I templated it.
//
// Mark C. Miller, Tue Oct 20 16:51:36 PDT 2009
// Made it static.
// ****************************************************************************
template <typename T, typename Tarr>
static vtkRectilinearGrid *
CreateCurve(DBcurve *cur, const char *curvename, int vtkType)
{
T *px = (T *) cur->x;
T *py = (T *) cur->y;
vtkRectilinearGrid *rg = vtkVisItUtility::Create1DRGrid(cur->npts, vtkType);
Tarr *xc = Tarr::SafeDownCast(rg->GetXCoordinates());
Tarr *yv = Tarr::New();
yv->SetNumberOfComponents(1);
yv->SetNumberOfTuples(cur->npts);
yv->SetName(curvename);
for (int i = 0 ; i < cur->npts; i++)
{
xc->SetValue(i, px[i]);
yv->SetValue(i, py[i]);
}
rg->GetPointData()->SetScalars(yv);
yv->Delete();
return rg;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetCurve
//
// Purpose: Read a Silo curve object and return a vtkDataSet for it
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// mn The curve name.
//
// Returns: The vtkDataSet corresponding to mn.
//
// Programmer: Mark C. Miller
// Creation: March 1, 2006
//
// Modifications:
// Kathleen Bonnell, Mon Jul 14 14:55:48 PDT 2008
// Specify curves as 1D rectilinear grids with yvalues stored in point data.
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Brad Whitlock, Thu Aug 6 12:15:50 PDT 2009
// Use templates.
//
// ****************************************************************************
vtkDataSet *
avtSiloFileFormat::GetCurve(DBfile *dbfile, const char *cn)
{
int i;
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *curvename = const_cast<char *>(cn);
//
// Get the Silo construct.
//
DBcurve *cur = DBGetCurve(dbfile, curvename);
if (cur == NULL)
{
EXCEPTION1(InvalidVariableException, curvename);
}
vtkRectilinearGrid *rg = 0;
if (cur->datatype == DB_FLOAT)
rg = CreateCurve<float,vtkFloatArray>(cur, curvename, VTK_FLOAT);
else if (cur->datatype == DB_DOUBLE)
rg = CreateCurve<double,vtkDoubleArray>(cur, curvename, VTK_DOUBLE);
else if (cur->datatype == DB_INT)
rg = CreateCurve<int,vtkIntArray>(cur, curvename, VTK_INT);
else if (cur->datatype == DB_SHORT)
rg = CreateCurve<short,vtkShortArray>(cur, curvename, VTK_SHORT);
else if (cur->datatype == DB_CHAR)
rg = CreateCurve<char,vtkCharArray>(cur, curvename, VTK_CHAR);
DBFreeCurve(cur);
return rg;
}
// ****************************************************************************
// Method: avtSiloFileFormat::CreateRectilinearMesh
//
// Purpose:
// Creates a rectilinear mesh from a DBquadmesh.
//
// Arguments:
// qm A quadmesh.
//
// Returns: A vtkRectilinearMesh from qm.
//
// Programmer: Hank Childs
// Creation: November 1, 2000
//
// Modifications:
//
// Kathleen Bonnell, Thu Nov 8 09:20:50 PST 2001
// Use vtkFloatArray instead of vtkScalars for rgrid coordinates in
// order to match VTK 4.0 API.
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Brad Whitlock, Thu Aug 6 11:38:58 PDT 2009
// Use doubles for the coordinates if they are doubles.
//
// ****************************************************************************
vtkDataSet *
avtSiloFileFormat::CreateRectilinearMesh(DBquadmesh *qm)
{
int i, j;
if(qm->datatype != DB_FLOAT && qm->datatype != DB_DOUBLE)
{
EXCEPTION1(InvalidVariableException, "The Silo reader expects float or "
"double precision coordinates for rectilinear meshes.");
}
vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New();
//
// Populate the coordinates. Put in 3D points with z=0 if the mesh is 2D.
//
int dims[3];
vtkDataArray *coords[3];
for (i = 0 ; i < 3 ; i++)
{
// Default number of components for an array is 1.
if(qm->datatype == DB_DOUBLE)
coords[i] = vtkDoubleArray::New();
else
coords[i] = vtkFloatArray::New();
if (i < qm->ndims)
{
dims[i] = qm->dims[i];
coords[i]->SetNumberOfTuples(dims[i]);
if(qm->datatype == DB_DOUBLE)
{
for (j = 0 ; j < dims[i] ; j++)
coords[i]->SetComponent(j, 0, ((double**)qm->coords)[i][j]);
}
else
{
for (j = 0 ; j < dims[i] ; j++)
coords[i]->SetComponent(j, 0, ((float**)qm->coords)[i][j]);
}
}
else
{
dims[i] = 1;
coords[i]->SetNumberOfTuples(1);
coords[i]->SetComponent(0, 0, 0.);
}
}
rgrid->SetDimensions(dims);
rgrid->SetXCoordinates(coords[0]);
coords[0]->Delete();
rgrid->SetYCoordinates(coords[1]);
coords[1]->Delete();
rgrid->SetZCoordinates(coords[2]);
coords[2]->Delete();
return rgrid;
}
// ****************************************************************************
// Method: avtSiloFileFormat::CreateCurvilinearMesh
//
// Purpose:
// Takes Silo representation of a curvilinear mesh and makes a VTK
// curvilinear mesh (ie structured grid).
//
// Arguments:
// qm A Silo quad mesh -- known to be a curvilinear mesh.
//
// Returns: The VTK curvilinear grid representation of qm.
//
// Programmer: Hank Childs
// Creation: November 1, 2000
//
// Modifications:
//
// Hank Childs, Thu Apr 26 16:09:39 PDT 2001
// Sped up routine.
//
// Eric Brugger, Thu May 23 14:23:23 PDT 2002
// I modified the routine to take into account the major order of
// the variable being read.
//
// Hank Childs, Wed Jan 14 13:40:33 PST 2004
// Marginal improvement in performance.
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Added support for double precision coordinates in a quad mesh
//
// Brad Whitlock, Fri Aug 7 11:21:16 PDT 2009
// I modified the row major case so it just uses increment for index
// calculations. Use unsigned int.
//
// ****************************************************************************
template <class T>
static void CopyQuadCoordinates(T *dest, int nx, int ny, int nz, int morder,
const T *const c0, const T *const c1, const T *const c2)
{
if (morder == DB_ROWMAJOR)
{
unsigned int nxnynz = nx * ny * nz;
for (unsigned int idx = 0; idx < nxnynz; ++idx)
{
*dest++ = c0 ? c0[idx] : 0.;
*dest++ = c1 ? c1[idx] : 0.;
*dest++ = c2 ? c2[idx] : 0.;
}
}
else
{
unsigned int nyz = ny * nz;
for (unsigned int k = 0; k < nz; k++)
{
for (unsigned int j = 0; j < ny; j++)
{
for (unsigned int i = 0; i < nx; i++)
{
unsigned int idx = k + j*nz + i*nyz;
*dest++ = c0 ? c0[idx] : 0.;
*dest++ = c1 ? c1[idx] : 0.;
*dest++ = c2 ? c2[idx] : 0.;
}
}
}
}
}
vtkDataSet *
avtSiloFileFormat::CreateCurvilinearMesh(DBquadmesh *qm)
{
if(qm->datatype != DB_FLOAT && qm->datatype != DB_DOUBLE)
{
EXCEPTION1(InvalidVariableException, "The Silo reader expects float or "
"double precision coordinates for curvilinear meshes.");
}
//
// Create the VTK objects and connect them up.
//
vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
vtkPoints *points = vtkPoints::New();
sgrid->SetPoints(points);
points->Delete();
//
// Tell the grid what its dimensions are and populate the points array.
//
int dims[3];
dims[0] = (qm->dims[0] > 0 ? qm->dims[0] : 1);
dims[1] = (qm->dims[1] > 0 ? qm->dims[1] : 1);
dims[2] = (qm->dims[2] > 0 ? qm->dims[2] : 1);
sgrid->SetDimensions(dims);
//
// vtkPoints assumes float data type
//
if (qm->datatype == DB_DOUBLE)
points->SetDataTypeToDouble();
//
// Populate the coordinates. Put in 3D points with z=0 if the mesh is 2D.
//
int nx = qm->dims[0];
int ny = qm->dims[1];
int nz = qm->ndims <= 2 ? 1 : qm->dims[2];
points->SetNumberOfPoints(qm->nnodes);
void *pts = points->GetVoidPointer(0);
if (qm->datatype == DB_DOUBLE)
{
CopyQuadCoordinates((double *) pts, nx, ny, nz, qm->major_order,
(double *) qm->coords[0], (double *) qm->coords[1],
qm->ndims <= 2 ? 0 : (double *) qm->coords[2]);
}
else
{
CopyQuadCoordinates((float *) pts, nx, ny, nz, qm->major_order,
(float *) qm->coords[0], (float *) qm->coords[1],
qm->ndims <= 2 ? 0 : (float *) qm->coords[2]);
}
return sgrid;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetQuadGhostZones
//
// Purpose:
// Retrieves ghost zone information from the quad mesh and adds it
// to the dataset.
//
// Arguments:
// qm A Silo quad mesh.
// ds The vtkDataSet in which to store the ghost level information.
//
// Programmer: Kathleen Bonnell
// Creation: June 12, 2001
//
// Modifications:
// Eric Brugger, Thu May 23 14:23:23 PDT 2002
// I modified the routine to always store the ghost zone array in row
// major order.
//
// Kathleen Bonnell, Wed Jul 10 16:02:56 PDT 2002
// I added a field-data array that indicates the extents of the real
// data. Used during ghostzone removal.
//
// Kathleen Bonnell, Wed Jun 25 13:45:04 PDT 2003
// Allocate space for realDims via SetNumberOfValues instead of Allocate.
// Allocate does not set some internal values needed for later calls to
// GetNumberOfTuples and the like.
//
// Hank Childs, Fri Aug 27 17:22:19 PDT 2004
// Rename ghost data array.
//
// ****************************************************************************
void
avtSiloFileFormat::GetQuadGhostZones(DBquadmesh *qm, vtkDataSet *ds)
{
//
// Find the dimensions of the quad mesh.
//
int dims[3];
dims[0] = (qm->dims[0] > 0 ? qm->dims[0] : 1);
dims[1] = (qm->dims[1] > 0 ? qm->dims[1] : 1);
dims[2] = (qm->dims[2] > 0 ? qm->dims[2] : 1);
//
// Determine if we have ghost points
//
int first[3];
int last[3];
bool ghostPresent = false;
bool badIndex = false;
for (int i = 0; i < 3; i++)
{
first[i] = (i < qm->ndims ? qm->min_index[i] : 0);
last[i] = (i < qm->ndims ? qm->max_index[i] : 0);
if (first[i] < 0 || first[i] >= dims[i])
{
debug1 << "bad Index on first[" << i << "] dims is: "
<< dims[i] << endl;
badIndex = true;
}
if (last[i] < 0 || last[i] >= dims[i])
{
debug1 << "bad Index on last[" << i << "] dims is: "
<< dims[i] << endl;
badIndex = true;
}
if (first[i] != 0 || last[i] != dims[i] -1)
{
ghostPresent = true;
}
}
//
// Create the ghost zones array if necessary
//
if (ghostPresent && !badIndex)
{
bool *ghostPoints = new bool[qm->nnodes];
//
// Initialize as all ghost levels
//
for (int ii = 0; ii < qm->nnodes; ii++)
ghostPoints[ii] = true;
//
// Set real values
//
for (int k = first[2]; k <= last[2]; k++)
for (int j = first[1]; j <= last[1]; j++)
for (int i = first[0]; i <= last[0]; i++)
{
int index = k*dims[1]*dims[0] + j*dims[0] + i;
ghostPoints[index] = false;
}
//
// okay, now we have ghost points, but what we really want
// are ghost cells ... convert: if all points associated with
// cell are 'real' then so is the cell.
//
unsigned char realVal = 0;
unsigned char ghostVal = 0;
avtGhostData::AddGhostZoneType(ghostVal,
DUPLICATED_ZONE_INTERNAL_TO_PROBLEM);
int ncells = ds->GetNumberOfCells();
vtkIdList *ptIds = vtkIdList::New();
vtkUnsignedCharArray *ghostCells = vtkUnsignedCharArray::New();
ghostCells->SetName("avtGhostZones");
ghostCells->Allocate(ncells);
for (int i = 0; i < ncells; i++)
{
ds->GetCellPoints(i, ptIds);
bool ghost = false;
for (int idx = 0; idx < ptIds->GetNumberOfIds(); idx++)
ghost |= ghostPoints[ptIds->GetId(idx)];
if (ghost)
ghostCells->InsertNextValue(ghostVal);
else
ghostCells->InsertNextValue(realVal);
}
ds->GetCellData()->AddArray(ghostCells);
delete [] ghostPoints;
ghostCells->Delete();
ptIds->Delete();
vtkIntArray *realDims = vtkIntArray::New();
realDims->SetName("avtRealDims");
realDims->SetNumberOfValues(6);
realDims->SetValue(0, first[0]);
realDims->SetValue(1, last[0]);
realDims->SetValue(2, first[1]);
realDims->SetValue(3, last[1]);
realDims->SetValue(4, first[2]);
realDims->SetValue(5, last[2]);
ds->GetFieldData()->AddArray(realDims);
ds->GetFieldData()->CopyFieldOn("avtRealDims");
realDims->Delete();
// ds->SetUpdateGhostLevel(0);
}
}
// ****************************************************************************
// Method: CopyPointMeshCoordinates
//
// Purpose:
// Copies DBpointmesh coordinates into an interleaved form for vtkPoints.
//
// Arguments:
// T : The destination array for the point data.
// pm : The source point mesh.
//
// Returns:
//
// Note: I moved this block from avtSiloFileFormat::GetPointMesh and
// templated it.
//
// Programmer: Brad Whitlock
// Creation: Thu Aug 6 11:48:54 PDT 2009
//
// Modifications:
//
// Mark C. Miller, Tue Oct 20 16:51:18 PDT 2009
// Made it static.
// ****************************************************************************
template <typename T>
static void
CopyPointMeshCoordinates(T *pts, const DBpointmesh *pm)
{
for (int i = 0 ; i < 3 ; i++)
{
T *tmp = pts + i;
if (pm->coords[i] != NULL)
{
for (int j = 0 ; j < pm->nels ; j++)
{
*tmp = ((T**)pm->coords)[i][j];
tmp += 3;
}
}
else
{
for (int j = 0 ; j < pm->nels ; j++)
{
*tmp = 0.;
tmp += 3;
}
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetPointMesh
//
// Purpose:
// Gets the Silo construct for mn and creates a vtkDataSet for it.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// mn The name of the point mesh.
//
// Returns: The vtkDataSet for mn.
//
// Programmer: Hank Childs
// Creation: June 22, 2002
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, added file argument to account for
// Silo objects distributed across multiple files.
//
// Hank Childs, Sat Jun 22 19:53:24 PDT 2002
// Finally populated routine.
//
// Jeremy Meredith, Tue Jun 7 08:32:46 PDT 2005
// Added support for "EMPTY" domains in multi-objects.
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Brad Whitlock, Thu Aug 6 11:50:13 PDT 2009
// I added support for double coordinates.
//
// ****************************************************************************
vtkDataSet *
avtSiloFileFormat::GetPointMesh(DBfile *dbfile, const char *mn)
{
//
// Allow empty data sets
//
if (string(mn) == "EMPTY")
return NULL;
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *meshname = const_cast<char *>(mn);
//
// Get the Silo construct.
//
DBpointmesh *pm = DBGetPointmesh(dbfile, meshname);
if (pm == NULL)
{
EXCEPTION1(InvalidVariableException, meshname);
}
if(pm->datatype != DB_FLOAT && pm->datatype != DB_DOUBLE)
{
DBFreePointmesh(pm);
EXCEPTION1(InvalidVariableException, "The Silo reader expects float or "
"double precision coordinates for point meshes.");
}
vtkPoints *points = vtkPoints::New();
//
// vtkPoints assumes float data type
//
if (pm->datatype == DB_DOUBLE)
points->SetDataTypeToDouble();
//
// Populate the coordinates. Put in 3D points with z=0 if the mesh is 2D.
//
points->SetNumberOfPoints(pm->nels);
if(pm->datatype == DB_DOUBLE)
CopyPointMeshCoordinates((double *)points->GetVoidPointer(0), pm);
else
CopyPointMeshCoordinates((float *)points->GetVoidPointer(0), pm);
//
// Create the VTK objects and connect them up.
//
vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
ugrid->SetPoints(points);
ugrid->Allocate(pm->nels);
vtkIdType onevertex[1];
for (int i = 0 ; i < pm->nels ; i++)
{
onevertex[0] = i;
ugrid->InsertNextCell(VTK_VERTEX, 1, onevertex);
}
points->Delete();
DBFreePointmesh(pm);
return ugrid;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetCSGMesh
//
// Purpose:
// Gets the Silo construct for a CSG mesh and creates a vtkDataSet for it.
//
// Arguments:
// dbfile A handle to the file this variable lives in.
// mn The name of the csg mesh.
//
// Returns: The vtkDataSet for mn.
//
// Programmer: Mark C. Miller
// Creation: August 8, 2005
//
// Modifications:
//
// Mark C. Miller, Wed Nov 16 10:46:36 PST 2005
// Added some more primitives. Moved discretization calls to
// generic database
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Changed interface to vtkCSGGrid class to accept raw Silo representation
//
// Mark C. Miller, Thu Aug 14 19:52:12 PDT 2008
// Added code to explicitly cache csg grid objects from within the plugin.
// Note that the plugin is caching its objects in the 'cache' object but
// is doing so in a 'place' that VisIt itself can never find due to
// different name of the 'type' of the cache.
//
// Mark C. Miller, Wed Aug 20 11:39:39 PDT 2008
// Had to force a copy on the csg object returned here to prevent collisions
// in the variable cache with stuff that generic database is doing.
// ****************************************************************************
vtkDataSet *
avtSiloFileFormat::GetCSGMesh(DBfile *dbfile, const char *mn, int dom)
{
#ifndef DBCSG_INNER // remove after silo-4.5 is released
return 0;
#else
#ifdef MDSERVER
return 0;
#else
//
// Allow empty data sets
//
if (string(mn) == "EMPTY")
return NULL;
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *meshname = const_cast<char *>(mn);
//
// Check in cache for this domain before trying to read it.
// We have to explicitly handle caching of CSG meshes here in the plugin
// because of single vtkCSGGrid object maps to many VisIt domains. Also,
// we cache the object using a 'type' (SILO_CSG_GRID) that is unique to
// the SILO plugin so that VisIt's Generic Database class will never
// find it.
//
vtkCSGGrid *cached_csggrid = (vtkCSGGrid*) cache->GetVTKObject(meshname,
"SILO_CSG_GRID", timestep, dom, "none");
if (cached_csggrid)
{
debug5 << "Avoiding re-read of CSG grid by returning cached grid: name=\""
<< meshname << "\", d=" << dom << ", t=" << timestep << endl;
vtkCSGGrid *cache_copy = vtkCSGGrid::New();
cache_copy->ShallowCopy(cached_csggrid);
return cache_copy;
}
//
// Get the Silo construct.
//
DBcsgmesh *csgm = DBGetCsgmesh(dbfile, meshname);
if (csgm == NULL)
{
EXCEPTION1(InvalidVariableException, meshname);
}
//
// Create the VTK objects and connect them up.
//
vtkCSGGrid *csggrid = vtkCSGGrid::New();
double minX = -10.0, minY = -10.0, minZ = -10.0;
double maxX = 10.0, maxY = 10.0, maxZ = 10.0;
// set bounds *before* anything else
if (!((csgm->min_extents[0] == 0.0 && csgm->max_extents[0] == 0.0 &&
csgm->min_extents[1] == 0.0 && csgm->max_extents[1] == 0.0 &&
csgm->min_extents[2] == 0.0 && csgm->max_extents[2] == 0.0) ||
(csgm->min_extents[0] == -DBL_MAX && csgm->max_extents[0] == DBL_MAX &&
csgm->min_extents[1] == -DBL_MAX && csgm->max_extents[1] == DBL_MAX &&
csgm->min_extents[2] == -DBL_MAX && csgm->max_extents[2] == DBL_MAX)))
{
minX = csgm->min_extents[0];
maxX = csgm->max_extents[0];
minY = csgm->min_extents[1];
maxY = csgm->max_extents[1];
minZ = csgm->min_extents[2];
maxZ = csgm->max_extents[2];
}
csggrid->SetBounds(minX, maxX, minY, maxY, minZ, maxZ);
if (csgm->datatype == DB_DOUBLE)
csggrid->AddBoundaries(csgm->nbounds, csgm->typeflags, csgm->lcoeffs, (double*) csgm->coeffs);
else
csggrid->AddBoundaries(csgm->nbounds, csgm->typeflags, csgm->lcoeffs, (float*) csgm->coeffs);
csggrid->AddRegions(csgm->zones->nregs, csgm->zones->leftids, csgm->zones->rightids,
csgm->zones->typeflags, 0, 0);
csggrid->AddZones(csgm->zones->nzones, csgm->zones->zonelist);
DBFreeCsgmesh(csgm);
//
// Cache this csggrid object. We'll probably be asked to read this same one
// many times, each for a different CSG region but all part of the same vtkCSGGrid
// object. So, we have to explicitly handle caching of CSG meshes here in the plugin
// because of single vtkCSGGrid object maps to many VisIt domains. Also,
// we cache the object using a 'type' (SILO_CSG_GRID) that is unique to
// the SILO plugin so that VisIt's Generic Database class will never
// find it.
//
cache->CacheVTKObject(meshname, "SILO_CSG_GRID", timestep, dom, "none", csggrid);
vtkCSGGrid *csgcopy = vtkCSGGrid::New();
csgcopy->ShallowCopy(csggrid);
return csgcopy;
#endif
return 0;
#endif
}
// ****************************************************************************
// Method: avtSiloFileFormat::DetermineFilenameAndDirectory
//
// Purpose:
// Parses a string from a Silo file that has form "filename:directory/var"
// and determines which part is "filename" and which is "directory/var".
//
// input The input string ("filename:directory/var")
// filename The "filename" part of the string. This will copy a string
// into a buffer, so a buffer must be provided as input.
// location The "directory/var" part of the string. This will just
// point into "input" so there is no memory management to
// worry about.
//
// Programmer: Hank Childs
// Creation: May 11, 2001
//
// Modifications:
// Mark C. Miller, Tue Aug 28 19:17:44 PDT 2007
// Made it deal with case where multimesh and blocks are all in same
// dir in the file. In this case, the location return had to be constructed
// and allocated. So, needed to add bool indicating that.
//
// Mark C. Miller, Thu Sep 13 20:51:56 PDT 2007
// Take care not to preprend mdirname if it 'looks' like it already has
// it. This logic isn't foolproof. Its a heuristic that should work 'most'
// of the time. We have no way of knowing for sure if the string
// 'foo/foo/bar' is really intended or not.
//
// ****************************************************************************
void
avtSiloFileFormat::DetermineFilenameAndDirectory(char *input,
const char *mdirname, char *filename, char *&location,
bool *allocated_location)
{
if (allocated_location)
*allocated_location = false;
//
// Figure out if there is a ':' in the string.
//
char *p = strstr(input, ":");
if (p == NULL)
{
//
// There is no colon, so the variable must be in the current file.
// Leave the file handle alone.
//
strcpy(filename, ".");
if (mdirname == 0 || strcmp(input, "EMPTY") == 0 || input[0] == '/' ||
(input[0] == '.' && input[1] == '/'))
{
location = input;
}
else
{
if (!strncmp(mdirname, input, strlen(mdirname)) == 0)
{
char tmp[1024];
sprintf(tmp, "%s/%s", mdirname, input);
location = CXX_strdup(tmp);
if (allocated_location)
*allocated_location = true;
}
else
{
location = input;
}
}
}
else
{
//
// Make a copy of the string all the way up to the colon.
//
strncpy(filename, input, p-input);
filename[p-input] = '\0';
//
// The location of the variable is *one after* the colon.
//
location = p+1;
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::DetermineFileAndDirectory
//
// Purpose:
// Takes a string from a Silo file that as "filename:directory/var" and
// returns the correct file as well as the substring that is only
// directory and var.
//
// Arguments:
// input The input string ("filename:directory/var")
// cFile The correct file corresponding to filename.
// location The "directory/var" part of the string. This will just
// point into the input so there is no memory management to
// worry about.
//
// Programmer: Hank Childs
// Creation: February 28, 2001
//
// Modifications:
//
// Hank Childs, Fri May 11 14:40:36 PDT 2001
// Call DetermineFilenameAndDirectory instead of calculating it ourselves.
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Added optional bool to tell OpenFile to skip global info as a
// pre-caution against opening the tocIndex file for the first time and
// winding up attempting to engage in collective communication for global
// information that other processors can't be guarenteed of reaching.
//
// Mark C. Miller, Tue Aug 28 19:17:44 PDT 2007
// Made it deal with case where multimesh and blocks are all in same
// dir in the file. In this case, the location return had to be constructed
// and allocated. So, needed to add bool indicating that.
//
// Kathleen Bonnell, Wed Jul 2 14:43:22 PDT 2008
// Removed unreferenced variables.
//
// ****************************************************************************
void
avtSiloFileFormat::DetermineFileAndDirectory(char *input, DBfile *&cFile,
const char *meshDirname, char *&location, bool *allocated_location)
{
char filename[1024];
DetermineFilenameAndDirectory(input, meshDirname, filename, location,
allocated_location);
if (strcmp(filename, ".") != 0)
{
//
// The variable is in a different file, so open that file. This will
// create the filename and add it to our registry if necessary.
//
// Since this call to OpenFile is made from within a GetMesh or GetVar
// call, it cannot wind up causing the plugin to engage in collective
// communication for global information. Typically, the tocIndex file
// would have already been opened by this point in execution. However,
// telling OpenFile to explicitly skip collective communication removes
// all doubt.
//
bool skipGlobalInfo = true;
cFile = OpenFile(filename, skipGlobalInfo);
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetRelativeVarName
//
// Purpose:
// If a variable (like "/block1/mesh") has pointers to other variables
// (like "fl") then they come unqualified with a path (should be
// "/block1/fl"). This routine qualifies the variable.
//
// Arguments:
// initVar The original variable ("/block1/mesh").
// newVar The variable initVar points to ("fl").
// outVar The relative variable name for newVar ("/block1/fl").
//
// Programmer: Hank Childs
// Creation: March 14, 2001
//
// Modifications:
//
// Hank Childs, Fri Nov 2 10:54:06 PST 2001
// Handle newVars that have a prepended path already gracefully.
//
// Hank Childs, Sat Jun 15 13:12:18 PDT 2002
// Respect built in filenames (identified with colons).
//
// Jeremy Meredith, Tue Sep 13 15:58:10 PDT 2005
// Make sure we add the filename to an otherwise fully-qualified variable
// name.
//
// ****************************************************************************
void
avtSiloFileFormat::GetRelativeVarName(const char *initVar, const char *newVar,
char *outVar)
{
//
// If the new variable starts with a slash, it is already qualified, so
// just return that.
//
int len = strlen(initVar);
if (newVar[0] == '/')
{
int colonPosition = -1;
for (int i = 0 ; i < len; i++)
{
if (initVar[i] == ':')
{
colonPosition = i;
break;
}
}
int numToCopy = (colonPosition < 0 ? 0 : colonPosition+1);
strncpy(outVar, initVar, numToCopy);
strcpy(outVar+numToCopy, newVar);
return;
}
int lastToken = -1;
for (int i = len-1 ; i >= 0 ; i--)
{
if (initVar[i] == '/' || initVar[i] == ':')
{
lastToken = i;
break;
}
}
int numToCopy = (lastToken < 0 ? 0 : lastToken+1);
strncpy(outVar, initVar, numToCopy);
strcpy(outVar+numToCopy, newVar);
}
// ****************************************************************************
// Method: avtSiloFileFormat::DetermineMultiMeshForSubVariable
//
// Purpose:
// Multi-vars are not defined on multi-meshes, so the only way to
// determine which mesh a var is defined on is to look at the first sub
// variable and see what mesh it is and compare that to the first
// sub mesh of the multi-mesh. This is not foolproof: it will fail
// for multi-meshes that share submeshes.
//
// Arguments:
// dbfile The currently open Silo file.
// varname The name of the sub-var.
// nblocks The number of blocks for 'varname'.
//
// Returns: The name of the multi-mesh that the multi-var is defined on.
//
// Programmer: Hank Childs
// Creation: March 15, 2001
//
// Modifications:
//
// Hank Childs, Fri Nov 2 15:36:31 PST 2001
// Added checks to make sure the number of blocks match up.
//
// Hank Childs, Mon Dec 9 16:20:15 PST 2002
// Throw an exception and let the levels above this routine handle it.
//
// Jeremy Meredith, Wed Mar 19 12:27:41 PST 2003
// Added some logic to handle the case where a multi-var is only
// defined on some domains of its associated multi-mesh.
//
// Jeremy Meredith, Tue Jun 7 10:55:18 PDT 2005
// Allowed EMPTY domains.
//
// Mark C. Miller, Fri Nov 11 09:45:42 PST 2005
// Added code to try an exact match with the leading slash, if one exists,
// removed from the meshname. This is to work around a bug in data files
// generated with earlier versions of the HDF5 driver.
//
// Mark C. Miller, Wed Dec 13 16:55:30 PST 2006
// Added code to use explicit multivar to multimesh mapping information,
// when available.
//
// Mark C. Miller, Tue Feb 6 19:39:35 PST 2007
// Added Brad's fix for reducing large amount of string matching in
// 'fuzzy' matching logic. Also added matching on block counts.
// ****************************************************************************
string
avtSiloFileFormat::DetermineMultiMeshForSubVariable(DBfile *dbfile,
const char *name,
char **varname,
int nblocks,
const char *curdir)
{
int i;
char subMesh[256];
char subMeshTmp[256];
//
// First, see if we've got the answer in the multivarToMultimeshMap
//
map<string,string>::const_iterator cit = multivarToMultimeshMap.find(name);
if (cit != multivarToMultimeshMap.end())
{
debug5 << "Matched multivar \"" << name << "\" to multimesh \""
<< cit->second << "\" using multivarToMultimeshMap" << endl;
return cit->second;
}
// Find the first non-empty mesh
int meshnum = 0;
while (string(varname[meshnum]) == "EMPTY")
{
meshnum++;
if (meshnum >= nblocks)
{
EXCEPTION1(InvalidVariableException, name);
}
}
GetMeshname(dbfile, varname[meshnum], subMesh);
//
// The code involving subMeshTmp is to maintain backward compability
// with Silo/HDF5 files in which HDF5 driver had a bug in that it
// *always* added a leading slash to the name of the mesh associated
// with an object. Eventually, this code can be eliminated
//
if (subMesh[0] == '/')
{
for (i = 0; i < strlen(subMesh); i++)
subMeshTmp[i] = subMesh[i+1];
}
//
// varname is very likely qualified with a file name. We need to figure
// out what it's mesh's name looks like the prepended file name, so we can
// meaningfully compare it with our list of submeshes.
//
char subMeshWithFile[1024];
char subMeshWithFileTmp[1024];
GetRelativeVarName(varname[meshnum], subMesh, subMeshWithFile);
if (subMesh[0] == '/')
GetRelativeVarName(varname[meshnum], subMeshTmp, subMeshWithFileTmp);
//
// Attempt an "exact" match, where the first mesh for the multivar is
// an exact match and the number of domains is the same.
//
int size = actualMeshName.size();
for (i = 0 ; i < size ; i++)
{
if (firstSubMesh[i] == subMeshWithFile && nblocks == blocksForMesh[i])
{
return actualMeshName[i];
}
}
if (subMesh[0] == '/')
{
for (i = 0 ; i < size ; i++)
{
if (firstSubMesh[i] == subMeshWithFileTmp && nblocks == blocksForMesh[i])
{
return actualMeshName[i];
}
}
}
//
// Couldn't find an exact match, so try something fuzzier:
// Look for a multimesh which has the same name as the mesh for
// the multivar, and match up domains by directory name.
//
debug5 << "Using fuzzy logic to match multivar \"" << name << "\" to a multimesh" << endl;
string dir,varmesh;
SplitDirVarName(subMesh, curdir, dir, varmesh);
for (i = 0 ; i < size ; i++)
{
if (firstSubMeshVarName[i] == varmesh &&
blocksForMesh[i] == nblocks)
{
#ifndef MDSERVER
string *dirs = new string[nblocks];
for (int k = 0; k < nblocks; k++)
SplitDirVarName(varname[k], curdir, dirs[k], varmesh);
for (int j = 0; j < allSubMeshDirs[i].size(); j++)
{
int match = -1;
for (int k = 0; k < nblocks && match == -1; k++)
{
if (dirs[k] == allSubMeshDirs[i][j])
{
match = k;
}
}
blocksForMultivar[name].push_back(match);
}
delete [] dirs;
#endif
return actualMeshName[i];
}
}
//
// We weren't able to find a match -- throw an exception and let the
// levels above us determine what the right thing to do is.
//
char str[1024];
SNPRINTF(str, sizeof(str), "Was not able to match multivar \"%s\" and its first \n"
"non-empty submesh \"%s\" in file %s to a multi-mesh.\n"
"This typically leads to the variable being invalidated\n"
"(grayed out) in the GUI",
name, varname[meshnum], subMeshWithFile);
EXCEPTION1(SiloException, str);
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetMeshtype
//
// Purpose:
// Gets the mesh type for a variable, even if it is in a different file.
//
// Arguments:
// dbfile The dbfile that mesh came from.
// mesh A mesh name, possibly with a prepended directory and filename
//
// Programmer: Hank Childs
// Creation: March 5, 2001
//
// Modifications:
//
// Sean Ahern, Fri Feb 8 13:57:12 PST 2002
// Added error checking.
//
// ****************************************************************************
int
avtSiloFileFormat::GetMeshtype(DBfile *dbfile, char *mesh)
{
char *dirvar;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(mesh, correctFile, 0, dirvar);
int rv = DBInqMeshtype(correctFile, dirvar);
if (rv < 0)
{
char str[1024];
sprintf(str, "Unable to determine mesh type for \"%s\".", mesh);
EXCEPTION1(SiloException, str);
}
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetMeshname
//
// Purpose:
// Gets the mesh name of a variable, even if it is in a different file.
//
// Arguments:
// dbfile The dbfile that mesh came from.
// var A var name, possibly with a prepended directory and filename.
// meshname A place to put the name of the mesh.
//
// Programmer: Hank Childs
// Creation: March 5, 2001
//
// Modification:
//
// Hank Childs, Thu Aug 16 11:06:27 PDT 2001
// Throw an exception here instead of in the handler.
//
// Mark C. Miller, Tue Sep 13 14:25:42 PDT 2005
// Permit absolute pathnames for meshes (leading slashes)
//
// Mark C. Miller, Thu Nov 10 21:12:36 PST 2005
// Undid above change.
//
// ****************************************************************************
void
avtSiloFileFormat::GetMeshname(DBfile *dbfile, char *var, char *meshname)
{
char *dirvar;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(var, correctFile, 0, dirvar);
int rv = DBInqMeshname(correctFile, dirvar, meshname);
if (rv < 0)
{
char str[1024];
sprintf(str, "Unable to determine mesh for %s.", var);
EXCEPTION1(SiloException, str);
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetComponent
//
// Purpose:
// Gets the component for a variable, even if it is in a different file.
//
// Arguments:
// dbfile The dbfile that mesh came from.
// var A var name, possibly with a prepended directory and filename.
// compname The name of the component.
//
// Returns: The return value of the DBGetComponent call, this should be
// free'd by the calling function.
//
// Programmer: Hank Childs
// Creation: March 5, 2001
//
// Modification:
//
// Hank Childs, Thu Aug 16 11:06:27 PDT 2001
// Throw an exception here instead of in the handler.
//
// Jeremy Meredith, Thu Aug 7 16:16:52 EDT 2008
// Accept const char*'s as input.
//
// ****************************************************************************
void *
avtSiloFileFormat::GetComponent(DBfile *dbfile, char *var,
const char *compname)
{
char *dirvar;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(var, correctFile, 0, dirvar);
void *rv = DBGetComponent(correctFile, dirvar, compname);
if (rv == NULL && strcmp(compname, "facelist") != 0)
{
char str[1024];
sprintf(str, "Unable to get component '%s' for variable '%s'",
compname, var);
EXCEPTION1(SiloException, str);
}
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetAuxiliaryData
//
// Purpose:
// Gets the auxiliary data from a Silo file.
//
// Arguments:
// var The variable of interest.
// domain The domain of interest.
// type The type of auxiliary data.
// <unnamed> The arguments for that -- not used for any Silo types.
//
// Returns: The auxiliary data. Throws an exception if this is not a
// supported data type.
//
// Programmer: Hank Childs
// Creation: February 28, 2001
//
// Modifications:
//
// Jeremy Meredith, Thu Dec 13 17:46:46 PST 2001
// Added species support.
//
// Hank Childs, Wed Sep 25 08:49:34 PDT 2002
// Add destructor functions.
//
// Mark C. Miller, August 9, 2004
// Added code to read global node and zone ids
//
// Mark C. Miller, Mon Oct 18 13:02:37 PDT 2004
// Added support for data/spatial extents
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Added code to convert CSG domain id; no-op for other meshes
//
// Mark C. Miller, Mon Apr 14 15:41:21 PDT 2008
// Removed disablement of spatial and data extents (for Ale3d)
//
// Mark C. Miller, Tue Jun 10 22:36:25 PDT 2008
// Added logic to ignore extents
// ****************************************************************************
void *
avtSiloFileFormat::GetAuxiliaryData(const char *var, int domain,
const char *type, void *, DestructorFunction &df)
{
// for CSG meshes, each domain is a csgregion and a group of regions
// forms a visit "domain". So, we need to re-map the domain id
metadata->ConvertCSGDomainToBlockAndRegion(var, &domain, 0);
void *rv = NULL;
if (strcmp(type, AUXILIARY_DATA_MATERIAL) == 0)
{
rv = (void *) GetMaterial(domain, var);
df = avtMaterial::Destruct;
}
else if (strcmp(type, AUXILIARY_DATA_SPECIES) == 0)
{
rv = (void *) GetSpecies(domain, var);
df = avtSpecies::Destruct;
}
else if (strcmp(type, AUXILIARY_DATA_EXTERNAL_FACELIST) == 0)
{
rv = (void *) GetExternalFacelist(domain, var);
df = avtFacelist::Destruct;
}
else if (strcmp(type, AUXILIARY_DATA_GLOBAL_NODE_IDS) == 0)
{
rv = (void *) GetGlobalNodeIds(domain, var);
df = avtVariableCache::DestructVTKObject;
}
else if (strcmp(type, AUXILIARY_DATA_GLOBAL_ZONE_IDS) == 0)
{
rv = (void *) GetGlobalZoneIds(domain, var);
df = avtVariableCache::DestructVTKObject;
}
else if (strcmp(type, AUXILIARY_DATA_SPATIAL_EXTENTS) == 0)
{
if (ignoreSpatialExtents)
{
debug1 << "Read options ignore request for spatial extents" << endl;
return 0;
}
rv = (void *) GetSpatialExtents(var);
df = avtIntervalTree::Destruct;
}
else if (strcmp(type, AUXILIARY_DATA_DATA_EXTENTS) == 0)
{
if (ignoreDataExtents)
{
debug1 << "Read options ignore request for data extents" << endl;
return 0;
}
rv = (void *) GetDataExtents(var);
df = avtIntervalTree::Destruct;
}
//
// Note -- although the Silo file format can get mixed variables, it does
// not return them this way. It instead caches them when it does a normal
// variable read. It does not try to get them here for performance
// reasons.
//
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetMaterial
//
// Purpose:
// Gets the material from the Silo file and converts it into an
// avtMaterial.
//
// Arguments:
// dom The domain of the material.
// mat The material we want.
//
// Returns: The material information.
//
// Programmer: Hank Childs
// Creation: November 7, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, made it work with Silo objects
// distributed across multiple files.
//
// Hank Childs, Wed Jan 14 12:04:19 PST 2004
// Avoid redundant DBGetMultimat calls.
//
// Hank Childs, Fri Feb 13 17:18:04 PST 2004
// Add the domain to the CalcMaterial call.
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// Jeremy Meredith, Tue Jun 7 08:32:46 PDT 2005
// Added support for "EMPTY" domains in multi-objects.
//
// ****************************************************************************
avtMaterial *
avtSiloFileFormat::GetMaterial(int dom, const char *mat)
{
debug5 << "Reading in domain " << dom << ", material " << mat << endl;
debug5 << "Reading in from toc " << filenames[tocIndex] << endl;
//
// Get the file handle, throw an exception if it hasn't already been opened
//
DBfile *dbfile = GetFile(tocIndex);
//
// Silo can't accept consts, so cast it away.
//
char *m = const_cast< char * >(mat);
//
// Start off by finding out what kind of mat it is. Note: we have
// already cached the multimats. See if we have a multimat in the
// cache already -- this could potentially save us a DBInqVarType call.
//
DBmultimat *mm = QueryMultimat("", m);
int type;
if (mm != NULL)
type = DB_MULTIMAT;
else
type = DBInqVarType(dbfile, m);
if (type != DB_MULTIMAT && type != DB_MATERIAL)
{
//
// This is not a material or a multi-mat. This is probably an error.
//
return NULL;
}
char *matname = NULL;
if (type == DB_MULTIMAT)
{
if (mm == NULL)
mm = GetMultimat("", m);
if (mm == NULL)
EXCEPTION1(InvalidVariableException, m);
if (dom >= mm->nmats || dom < 0 )
{
EXCEPTION2(BadDomainException, dom, mm->nmats);
}
if (strcmp(mm->matnames[dom], "EMPTY") == 0)
return NULL;
matname = CXX_strdup(mm->matnames[dom]);
}
else // (type == DB_MATERIAL)
{
if (dom != 0)
{
EXCEPTION2(BadDomainException, dom, 1);
}
matname = CXX_strdup(mat);
}
//
// Some Silo objects are distributed across several files,
// so handle that here.
//
DBfile *domain_file = dbfile;
char *directory_mat = NULL;
DetermineFileAndDirectory(matname, domain_file, 0, directory_mat);
avtMaterial *rv = CalcMaterial(domain_file, directory_mat, mat, dom);
if (matname != NULL)
{
delete [] matname;
matname = NULL;
}
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetSpecies
//
// Purpose:
// Gets the species from the Silo file and converts it into an
// avtSpecies.
//
// Arguments:
// dom The domain of the material.
// spec The species we want.
//
// Returns: The species information.
//
// Programmer: Jeremy Meredith
// Creation: December 13, 2001
//
// Modifications:
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// Jeremy Meredith, Tue Jun 7 08:32:46 PDT 2005
// Added support for "EMPTY" domains in multi-objects.
//
// ****************************************************************************
avtSpecies *
avtSiloFileFormat::GetSpecies(int dom, const char *spec)
{
debug5 << "Reading in domain " << dom << ", species " << spec << endl;
debug5 << "Reading in from toc " << filenames[tocIndex] << endl;
//
// Get the file handle, throw an exception if it hasn't already been opened
//
DBfile *dbfile = GetFile(tocIndex);
//
// Silo can't accept consts, so cast it away.
//
char *s = const_cast< char * >(spec);
//
// Start off by finding out what kind of species it is. Note: we have
// already cached the multispecies. See if we have a multispecies in the
// cache already -- this could potentially save us a DBInqVarType call.
//
DBmultimatspecies *mm = QueryMultimatspec("", s);
int type;
if (mm != NULL)
type = DB_MULTIMATSPECIES;
else
type = DBInqVarType(dbfile, s);
if (type != DB_MULTIMATSPECIES && type != DB_MATSPECIES)
{
//
// This is not a species or a multi-species. This is probably an error.
//
return NULL;
}
DBmultimatspecies *ms = NULL;
char *specname = NULL;
if (type == DB_MULTIMATSPECIES)
{
if (ms == NULL)
ms = GetMultimatspec("", s);
if (ms == NULL)
EXCEPTION1(InvalidVariableException, s);
if (dom >= ms->nspec || dom < 0 )
{
EXCEPTION2(BadDomainException, dom, ms->nspec);
}
if (strcmp(ms->specnames[dom], "EMPTY") == 0)
return NULL;
specname = CXX_strdup(ms->specnames[dom]);
}
else // (type == DB_MATSPECIES)
{
if (dom != 0)
{
EXCEPTION2(BadDomainException, dom, 1);
}
specname = CXX_strdup(spec);
}
//
// Some Silo objects are distributed across several files,
// so handle that here.
//
DBfile *domain_file = dbfile;
char *directory_spec = NULL;
DetermineFileAndDirectory(specname, domain_file, 0, directory_spec);
avtSpecies *rv = CalcSpecies(domain_file, directory_spec);
if (specname != NULL)
{
delete [] specname;
specname = NULL;
}
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::AllocAndDetermineMeshnameForUcdmesh
//
// Purpose:
// Allocate space for and determine the real mesh name for a ucd mesh,
// which may be a multimesh
//
// Arguments:
// dom The domain of the mesh.
// mesh The mesh we want the real name for
//
// Returns: The real mesh name
//
// Programmer: Mark C. Miller
// Creation: August 4, 2004
//
// ****************************************************************************
char *
avtSiloFileFormat::AllocAndDetermineMeshnameForUcdmesh(int dom, const char *mesh)
{
//
// Get the file handle, throw an exception if it hasn't already been opened
//
DBfile *dbfile = GetFile(tocIndex);
//
// Silo can't accept consts, so cast it away.
//
char *m = const_cast< char * >(mesh);
int type = DBInqVarType(dbfile, m);
if (type != DB_MULTIMESH && type != DB_UCDMESH)
{
//
// This is not a ucd mesh or a multi-mesh, so it does not have a
// facelist.
//
return NULL;
}
DBmultimesh *mm = NULL;
char *meshname = NULL;
if (type == DB_MULTIMESH)
{
mm = GetMultimesh("", m);
if (mm == NULL)
EXCEPTION1(InvalidFilesException, m);
if (dom >= mm->nblocks || dom < 0 )
{
EXCEPTION2(BadDomainException, dom, mm->nblocks);
}
if (mm->meshtypes[dom] != DB_UCDMESH)
{
return NULL;
}
meshname = CXX_strdup(mm->meshnames[dom]);
}
else // (type == DB_UCDMESH)
{
if (dom != 0)
{
EXCEPTION2(BadDomainException, dom, 1);
}
meshname = CXX_strdup(mesh);
}
return meshname;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetExternalFacelist
//
// Purpose:
// Gets the facelist from the Silo file and converts it into an
// avtFacelist.
//
// Arguments:
// dom The domain of the mesh.
// mesh The mesh we want a face list for.
//
// Returns: The facelist information.
//
// Programmer: Hank Childs
// Creation: October 27, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, made it work with Silo objects
// distributed across multiple files.
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// Mark C. Miller, August 9, 2004
// Moved code common to several auxiliary data 'Get' methods to
// AllocAndDetermineMeshnameForUcdmesh
//
// Mark C. Miller, Tue Jun 28 17:28:56 PDT 2005
// Made it handle the new "EMPTY" domain convention
//
// ****************************************************************************
avtFacelist *
avtSiloFileFormat::GetExternalFacelist(int dom, const char *mesh)
{
debug5 << "Reading in domain " << dom << ", facelist " << mesh << endl;
debug5 << "Reading in from toc " << filenames[tocIndex] << endl;
DBfile *dbfile = GetFile(tocIndex);
char *meshname = AllocAndDetermineMeshnameForUcdmesh(dom, mesh);
if (meshname == NULL || string(meshname) == "EMPTY")
return NULL;
//
// Some Silo objects are distributed across several files,
// so handle that here.
//
DBfile *domain_file = dbfile;
char *directory_mesh = NULL;
DetermineFileAndDirectory(meshname, domain_file, 0, directory_mesh);
avtFacelist *rv = CalcExternalFacelist(domain_file, directory_mesh);
if (meshname != NULL)
{
delete [] meshname;
meshname = NULL;
}
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetGlobalNodeIds
//
// Purpose:
// Gets the global node ids from the Silo file
//
// Programmer: Mark C. Miller
// Creation: August 4, 2004
//
// Modifications:
// Mark C. Miller, Thu Oct 14 15:18:31 PDT 2004
// Uncommented the data read mask
//
// Mark C. Miller, Tue Jun 28 17:28:56 PDT 2005
// Made it handle the new "EMPTY" domain convention
//
// Hank Childs, Wed Jul 13 10:04:33 PDT 2005
// Fix memory leak.
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Moved code to set data read mask back to its original value to *before*
// throwing of exeption.
//
// Mark C. Miller, Tue Jan 12 17:55:14 PST 2010
// Use CreateDataArray for global node numbers, handling long long case.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetGlobalNodeIds(int dom, const char *mesh)
{
debug5 << "Reading in domain " << dom << ", global node ids for " << mesh << endl;
debug5 << "Reading in from toc " << filenames[tocIndex] << endl;
DBfile *dbfile = GetFile(tocIndex);
char *meshname = AllocAndDetermineMeshnameForUcdmesh(dom, mesh);
if (meshname == NULL || string(meshname) == "EMPTY")
{
if (meshname != NULL)
delete [] meshname;
return NULL;
}
//
// Some Silo objects are distributed across several files,
// so handle that here.
//
DBfile *domain_file = dbfile;
char *directory_mesh = NULL;
DetermineFileAndDirectory(meshname, domain_file, 0, directory_mesh);
// We want to get just the global node ids. So we need to get the ReadMask,
// set it to read global node ids, then set it back.
long mask = DBGetDataReadMask();
DBSetDataReadMask(DBUMGlobNodeNo);
DBucdmesh *um = DBGetUcdmesh(domain_file, directory_mesh);
DBSetDataReadMask(mask);
if (um == NULL)
EXCEPTION1(InvalidVariableException, mesh);
vtkDataArray *rv = NULL;
if (um->gnodeno != NULL)
{
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,7,1)
rv = CreateDataArray(um->gnznodtype, um->gnodeno, um->nnodes);
#else
rv = CreateDataArray(DB_INT, um->gnodeno, um->nnodes);
#endif
#else
rv = CreateDataArray(DB_INT, um->gnodeno, um->nnodes);
#endif
um->gnodeno = 0; // vtkDataArray owns the data now.
}
DBFreeUcdmesh(um);
delete [] meshname;
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetGlobalZoneIds
//
// Purpose:
// Gets the global zone ids from the Silo file
//
// Programmer: Mark C. Miller
// Creation: August 9, 2004
//
// Modifications:
// Mark C. Miller, Thu Oct 14 15:18:31 PDT 2004
// Uncommented the data read mask
//
// Mark C. Miller, Tue Jun 28 17:28:56 PDT 2005
// Made it handle the new "EMPTY" domain convention
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Moved code to set data read mask back to its original value to *before*
// throwing of exeption.
//
// Mark C. Miller, Thu Oct 15 21:31:07 PDT 2009
// Add DBZonelistInfo to data read mask to work around a bug in Silo
// library where attempt to DBGetUcdmesh causes call to DBGetZonelist
// and a subsequent segv down in the bowels of Silo due to invalid
// assumptions regarding the existence of certain zonelist strutures.
//
// Mark C. Miller, Tue Jan 12 17:55:54 PST 2010
// Use CreateDataArray for global zone numbers, handling long long too.
// ****************************************************************************
vtkDataArray *
avtSiloFileFormat::GetGlobalZoneIds(int dom, const char *mesh)
{
debug5 << "Reading in domain " << dom << ", global zone ids for " << mesh << endl;
debug5 << "Reading in from toc " << filenames[tocIndex] << endl;
DBfile *dbfile = GetFile(tocIndex);
char *meshname = AllocAndDetermineMeshnameForUcdmesh(dom, mesh);
if (meshname == NULL || string(meshname) == "EMPTY")
return NULL;
//
// Some Silo objects are distributed across several files,
// so handle that here.
//
DBfile *domain_file = dbfile;
char *directory_mesh = NULL;
DetermineFileAndDirectory(meshname, domain_file, 0, directory_mesh);
// We want to get just the global node ids. So we need to get the ReadMask,
// set it to read global node ids, then set it back.
long mask = DBGetDataReadMask();
DBSetDataReadMask(DBUMZonelist|DBZonelistGlobZoneNo|DBZonelistInfo);
DBucdmesh *um = DBGetUcdmesh(domain_file, directory_mesh);
DBSetDataReadMask(mask);
if (um == NULL)
EXCEPTION1(InvalidVariableException, mesh);
vtkDataArray *rv = NULL;
if (um->zones->gzoneno != NULL)
{
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,7,1)
rv = CreateDataArray(um->zones->gnznodtype, um->zones->gzoneno, um->zones->nzones);
#else
rv = CreateDataArray(DB_INT, um->zones->gzoneno, um->zones->nzones);
#endif
#else
rv = CreateDataArray(DB_INT, um->zones->gzoneno, um->zones->nzones);
#endif
um->zones->gzoneno = 0; // vtkDataArray owns the data now.
}
DBFreeUcdmesh(um);
delete [] meshname;
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetSpatialExtents
//
// Purpose:
// Gets the spatial extents from a multimesh, if they exist in the file
//
// Programmer: Mark C. Miller
// Creation: October 14, 2004
//
// Modifications:
// Kathleen Bonnell, Mon Aug 14 16:40:30 PDT 2006
// API change for avtIntervalTree.
//
// ****************************************************************************
avtIntervalTree *
avtSiloFileFormat::GetSpatialExtents(const char *meshName)
{
debug5 << "Getting spatial extents for \"" << meshName << "\"" << endl;
debug5 << "Reading in from toc " << filenames[tocIndex] << endl;
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *mesh = const_cast<char *>(meshName);
//
// Start off by finding out what kind of mesh it is. Note: we have
// already cached the multimeshes. See if we have a multimesh in the
// cache already -- this could potentially save us a DBInqVarType call.
//
DBmultimesh *mm = QueryMultimesh("", mesh);
if (mm == NULL)
mm = GetMultimesh("", mesh);
// if this mesh doesn't exist or doesn't have extents, return nothing
if (mm == NULL || mm->extents == NULL)
return NULL;
int ndims = mm->extentssize / 2;
avtIntervalTree *itree = new avtIntervalTree(mm->nblocks, ndims);
for (int i = 0; i < mm->nblocks; i++)
{
double range[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
int esize = mm->extentssize;
// silo stores all the mins before all the maxs
for (int j = 0; j < ndims; j++)
{
range[j*2 ] = mm->extents[i*esize + j];
range[j*2+1] = mm->extents[i*esize + j + ndims];
}
itree->AddElement(i, range);
}
itree->Calculate(true);
return itree;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetDataExtents
//
// Purpose:
// Gets the data extents from a multivar, if they exist in the file
//
// Programmer: Mark C. Miller
// Creation: October 14, 2004
//
// Modifications:
// Kathleen Bonnell, Mon Aug 14 16:40:30 PDT 2006
// API change for avtIntervalTree.
//
// ****************************************************************************
avtIntervalTree *
avtSiloFileFormat::GetDataExtents(const char *varName)
{
debug5 << "Getting data extents for \"" << varName << "\"" << endl;
debug5 << "Reading in from toc " << filenames[tocIndex] << endl;
//
// It's ridiculous, but Silo does not have all of the `const's in their
// library, so let's cast it away.
//
char *var = const_cast<char *>(varName);
//
// Start off by finding out what kind of mesh it is. Note: we have
// already cached the multimeshes. See if we have a multimesh in the
// cache already -- this could potentially save us a DBInqVarType call.
//
DBmultivar *mv = QueryMultivar("", var);
if (mv == NULL)
mv = GetMultivar("", var);
// if this mesh doesn't exist or doesn't have extents, return nothing
if (mv == NULL || mv->extents == NULL)
return NULL;
int ncomps = mv->extentssize / 2;
int esize = mv->extentssize;
avtIntervalTree *itree = new avtIntervalTree(mv->nvars, ncomps);
double *range = new double[esize];
for (int i = 0; i < mv->nvars; i++)
{
// silo stores all the mins before all the maxs
for (int j = 0; j < ncomps; j++)
{
range[j*2 ] = mv->extents[i*esize + j];
range[j*2+1] = mv->extents[i*esize + j + ncomps];
}
itree->AddElement(i, range);
}
delete [] range;
itree->Calculate(true);
return itree;
}
// ****************************************************************************
// Method: avtSiloFileFormat::CalcMaterial
//
// Purpose:
// Gets the Silo material and creates an avtMaterial.
//
// Arguments:
// dbfile The Silo file handle to use.
// matname The name of the material.
//
// Returns: The material.
//
// Programmer: Hank Childs
// Creation: November 7, 2000
//
// Modifications:
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, added file argument to account for
// Silo objects distributed across multiple files.
//
// Sean Ahern, Fri Feb 8 11:12:38 PST 2002
// Added support for material names.
//
// Eric Brugger, Thu May 23 14:23:23 PDT 2002
// I modified the routine to take into account the major order of
// the variable being read.
//
// Hank Childs, Fri Feb 13 17:18:04 PST 2004
// Add the domain to the material constructor.
//
// Hank Childs, Wed Apr 14 07:52:48 PDT 2004
// Attach the material number to the material name.
//
// Mark C. Miller, Thu Oct 21 22:11:28 PDT 2004
// Added code to remove entries from matlist array for arb. zones that
// were removed from the mesh
//
// Cyrus Harrison, Thu Oct 4 11:11:26 PDT 200
// Removed limit of 128 characters for material names. I increased the
// limit to 256 + room for the material number - to safely handle valid
// silo material names. This resolves '8257.
//
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Mark C. Miller, Fri Mar 20 04:36:49 PDT 2009
// Added logic to obtain global material context (# materials, names and
// numbers) from parent multimat, if it exists and has that info. This has
// the effect of freeing the data-producer of having to re-enumerate that
// information on each and every individual material object in a large
// multi-mesh with many materials.
//
// Hank Childs, Mon May 25 11:07:17 PDT 2009
// Add support for Silo releases before 4.6.3.
//
// Tom Fogal, Mon May 25 18:53:30 MDT 2009
// Fixed some compilation errors && simplified some ifdef magic.
//
// Mark C. Miller, Thu Jun 4 20:43:29 PDT 2009
// Fixed a slew of syntax errors preventing compilation.
//
// Brad Whitlock, Fri Aug 7 11:40:37 PDT 2009
// Convert double mix_vf to float for now since avtMaterial can't store it.
//
// Mark C. Miller, Thu Oct 29 14:34:55 PDT 2009
// Replaced zone skipping logic (old way of handling meshes with arb. poly
// zones) to use remapping logic.
//
// Mark C. Miller, Fri Oct 30 14:03:13 PDT 2009
// Handle Silo's DB_DTPTR configuration option.
//
// Mark C. Miller, Wed Jan 27 13:14:03 PST 2010
// Added extra level of indirection to arbMeshXXXRemap objects to handle
// multi-block case.
// ****************************************************************************
avtMaterial *
avtSiloFileFormat::CalcMaterial(DBfile *dbfile, char *matname, const char *tmn,
int dom)
{
DBmaterial *silomat = DBGetMaterial(dbfile, matname);
if (silomat == NULL)
{
EXCEPTION1(InvalidVariableException, matname);
}
//
// Get the parent multi-mat object, if there is any, because it could
// have information about global material context that the individual
// material block object read here doesn't have.
//
DBmultimat *mm = QueryMultimat("", const_cast< char * >(tmn));
char dom_string[128];
sprintf(dom_string, "Domain %d", dom);
//
// If we have material names, create a new set of material names that have
// the material number encoded.
//
char **matnames = NULL;
char *buffer = NULL;
bool haveMatnames = silomat->matnames;
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
if (mm&&mm->material_names)
haveMatnames = true;
#endif
#endif
if (haveMatnames)
{
int nmat = silomat->nmat;
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
if (mm&&mm->nmatnos>0)
nmat = mm->nmatnos;
#endif
#endif
int max_dlen = 0;
for (int i = 0 ; i < nmat ; i++)
{
int matno = silomat->matnos[i];
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
if (mm&&mm->matnos)
matno = mm->matnos[i];
#endif
#endif
int dlen = int(log10(float(matno+1))) + 1;
if(dlen>max_dlen)
max_dlen = dlen;
}
matnames = new char*[nmat];
buffer = new char[nmat*256 + max_dlen];
for (int i = 0 ; i < nmat ; i++)
{
matnames[i] = buffer + (256+max_dlen)*i;
int matno = silomat->matnos[i];
const char *matname = silomat->matnames[i];
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
if (mm&&mm->matnos)
matno = mm->matnos[i];
if (mm&&mm->material_names)
matname = mm->material_names[i];
#endif
#endif
sprintf(matnames[i], "%d %s", matno, matname);
}
}
//
// Handle cases for arb. poly meshes where arb. zones have been
// decomposed into zoo-type zones. We need only do this for matlist
// array, even in the presence of mixing.
//
vtkDataArray *matListArr = 0;
string meshName = metadata->MeshForVar(tmn);
map<string, map<int, vector<int>* > >::iterator domit;
if ((domit = arbMeshCellReMap.find(meshName)) != arbMeshCellReMap.end() &&
domit->second.find(dom) != domit->second.end())
{
vector<int> *remap = domit->second[dom];
int nzones = 1;
for (int i = 0; i < silomat->ndims; i++)
nzones *= silomat->dims[i];
//
// Create a temp. ucdvar so we can use CopyUcdVar to remap matlist
//
DBucdvar tmp;
tmp.centering = DB_ZONECENT;
tmp.datatype = DB_INT;
tmp.nels = nzones;
tmp.nvals = 1;
#ifdef DB_DTPTR
tmp.vals = (DB_DTPTR**) new DB_DTPTR*[1];
tmp.vals[0] = (DB_DTPTR*) silomat->matlist;
#else
tmp.vals = (float**) new float*[1];
tmp.vals[0] = (float*) silomat->matlist;
#endif
matListArr = CopyUcdVar<int,vtkIntArray>(&tmp, *remap);
//
// Adjust the Silo DBmaterial object a bit for call to newMaterial
//
silomat->ndims = 1;
silomat->dims[0] = (int) remap->size();
silomat->dims[1] = 1;
silomat->dims[2] = 1;
delete [] tmp.vals;
}
int nummats = silomat->nmat;
int *matnos = silomat->matnos;
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
if (mm&&mm->nmatnos>0)
nummats = mm->nmatnos;
if (mm&&mm->matnos)
matnos = mm->matnos;
#endif
#endif
if(silomat->datatype != DB_FLOAT)
{
debug5 << "IMPORTANT: The Silo reader is converting mix_vf data for "
<< matname << " to single precision." << endl;
}
float *mix_vf = ConvertToFloat(silomat->datatype, silomat->mix_vf, silomat->mixlen);
avtMaterial *mat = new avtMaterial(nummats, matnos, matnames, silomat->ndims,
silomat->dims, silomat->major_order,
matListArr?(int*)(matListArr->GetVoidPointer(0)):silomat->matlist,
silomat->mixlen, silomat->mix_mat, silomat->mix_next, silomat->mix_zone,
mix_vf, dom_string
#ifdef DBOPT_ALLOWMAT0
,silomat->allowmat0
#endif
);
if(mix_vf != (float*)silomat->mix_vf)
delete [] mix_vf;
if (matListArr)
matListArr->Delete();
DBFreeMaterial(silomat);
if (matnames != NULL)
delete [] matnames;
if (buffer != NULL)
delete [] buffer;
return mat;
}
// ****************************************************************************
// Method: avtSiloFileFormat::CalcSpecies
//
// Purpose:
// Gets the Silo species and creates an avtSpecies.
//
// Arguments:
// dbfile The Silo file handle to use.
// specname The name of the species.
//
// Returns: The species.
//
// Programmer: Jeremy Meredith
// Creation: December 13, 2001
//
// Modifications:
// Mark C. Miller, Tue Dec 16 09:36:56 PST 2008
// Added casts to deal with new Silo API where datatype'd pointers
// have been changed from float* to void*.
//
// Brad Whitlock, Fri Aug 7 11:48:39 PDT 2009
// Convert other data types to float for now since avtSpecies can't
// store them.
//
// ****************************************************************************
avtSpecies *
avtSiloFileFormat::CalcSpecies(DBfile *dbfile, char *specname)
{
DBmatspecies *silospec = DBGetMatspecies(dbfile, specname);
if (silospec == NULL)
{
EXCEPTION1(InvalidVariableException, specname);
}
if(silospec->datatype != DB_FLOAT)
{
debug5 << "IMPORTANT: The Silo reader is converting species_mf data for "
<< specname << " to single precision." << endl;
}
float *species_mf = ConvertToFloat(silospec->datatype, silospec->species_mf,
silospec->mixlen);
avtSpecies *spec = new avtSpecies(silospec->nmat,
silospec->nmatspec,
silospec->ndims,
silospec->dims,
silospec->speclist,
silospec->mixlen,
silospec->mix_speclist,
silospec->nspecies_mf,
species_mf);
if(species_mf != (float*)silospec->species_mf)
delete [] species_mf;
DBFreeMatspecies(silospec);
return spec;
}
// ****************************************************************************
// Method: avtSiloFileFormat::CalcExternalFacelist
//
// Purpose:
// Reads the facelist in from the Silo file and creates an avtFacelist
// out of it.
//
// Arguments:
// dbfile The Silo file handle to use.
// mesh The name of the mesh to get the facelist for.
//
// Returns: The facelist, NULL if one doesn't exist.
//
// Programmer: Hank Childs
// Creation: October 30, 2000
//
// Modifications:
//
// Hank Childs, Mon Dec 18 13:05:44 PST 2000
// Turned off error handling when getting facelists in case they weren't
// there.
//
// Hank Childs, Wed Feb 28 10:49:17 PST 2001
// Moved code from avtSiloTimeStep, added file argument to account for
// Silo objects distributed across multiple files.
//
// Sean Ahern, Fri Feb 8 14:10:59 PST 2002
// Retrofitted to not use GetComponent.
//
// Hank Childs, Mon Jun 17 19:38:10 PDT 2002
// Respect non 0-origin facelists.
//
// Hank Childs, Mon Dec 9 13:21:13 PST 2002
// Use the facelist's origin rather than the unstructured meshes.
//
// Mark C. Miller, Thu Apr 21 09:37:41 PDT 2005
// Freed ucdmesh prior to early return for null facelist
//
// Hank Childs, Tue Jun 13 14:23:48 PDT 2006
// Add flag to read mask. The current flag works with PDB, but not HDF5.
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Moved code to set data read mask back to its original value to *before*
// throwing of exeption.
// ****************************************************************************
avtFacelist *
avtSiloFileFormat::CalcExternalFacelist(DBfile *dbfile, char *mesh)
{
char *realvar = NULL;
DBfile *correctFile = dbfile;
DetermineFileAndDirectory(mesh, correctFile, 0, realvar);
// We want to get just the facelist. So we need to get the ReadMask,
// set it to read facelists, then set it back.
long mask = DBGetDataReadMask();
DBSetDataReadMask(DBUMFacelist | DBFacelistInfo);
DBucdmesh *um = DBGetUcdmesh(correctFile, realvar);
DBSetDataReadMask(mask);
if (um == NULL)
EXCEPTION1(InvalidVariableException, mesh);
DBfacelist *fl = um->faces;
if (fl == NULL)
{
//
// There is no facelist object, this may be an interior block.
//
DBFreeUcdmesh(um);
return NULL;
}
avtFacelist *rv = new avtFacelist(fl->nodelist, fl->lnodelist, fl->nshapes,
fl->shapecnt, fl->shapesize, fl->zoneno,
fl->origin);
DBFreeUcdmesh(um);
return rv;
}
// ****************************************************************************
// Method: avtSiloFileFormat::PopulateIOInformation
//
// Purpose:
// Makes I/O groupings based on the layouts of the files.
//
// Arguments:
// ioInfo The information object to populate.
//
// Notes: Other routines could fail if there are multiple top level
// multi-meshes within the same root directory, so that case is
// not handled.
//
// Programmer: Hank Childs
// Creation: May 11, 2001
//
// Modifications:
//
// Hank Childs, Mon May 21 10:46:25 PDT 2001
// Added missing return statement.
//
// Jeremy Meredith, Thu Sep 20 01:05:19 PDT 2001
// Added setting of NDomains.
//
// Hank Childs, Thu Sep 20 17:43:31 PDT 2001
// Set nDomains with early returns.
//
// Mark C. Miller, Thu Feb 1 19:44:03 PST 2007
// Exclude CSG meshes from consideration
//
// ****************************************************************************
void
avtSiloFileFormat::PopulateIOInformation(avtIOInformation &ioInfo)
{
TRY
{
int i, j;
int nMeshes = metadata->GetNumMeshes();
if (nMeshes < 1)
{
debug1 << "Cannot populate I/O info since there are no meshes" << endl;
ioInfo.SetNDomains(0);
EXCEPTION0(ImproperUseException);
}
//
// If there are different sized meshes, then we need to give up.
// Check to see.
//
int blocks = -1;
int firstNonCSGMesh = -1;
for (i = 0 ; i < nMeshes ; i++)
{
if (metadata->GetMesh(i)->meshType == AVT_CSG_MESH)
continue;
if (blocks == -1)
blocks = metadata->GetMesh(i)->numBlocks;
if (firstNonCSGMesh == -1)
firstNonCSGMesh = i;
if (metadata->GetMesh(i)->numBlocks != blocks)
{
debug1 << "Cannot populate I/O Information since the meshes have "
<< "a different number of blocks." << endl;
ioInfo.SetNDomains(0);
EXCEPTION0(ImproperUseException);
}
}
if (blocks <= 1)
{
debug5 << "No need to do I/O optimization because there is only "
<< "one block" << endl;
ioInfo.SetNDomains(1);
EXCEPTION0(ImproperUseException);
}
//
// Looks like all of the meshes are the same size. ASSUME they are all
// the same and pick the first one. This is done for I/O optimizations, so
// it is okay to be wrong if our assumption is not true.
//
string meshname = metadata->GetMesh(firstNonCSGMesh)->name;
DBmultimesh *mm = GetMultimesh("", meshname.c_str());
if (mm == NULL)
{
debug1 << "Cannot populate I/O Information because unable "
<< "to get multimesh object \"" << meshname.c_str() << "\"." << endl;
ioInfo.SetNDomains(0);
EXCEPTION0(ImproperUseException);
}
vector<string> filenames;
vector<vector<int> > groups;
for (i = 0 ; i < mm->nblocks ; i++)
{
char filename[1024];
char *location = NULL;
DetermineFilenameAndDirectory(mm->meshnames[i], 0, filename, location);
int index = -1;
for (j = 0 ; j < filenames.size() ; j++)
{
if (filename == filenames[j])
{
index = j;
break;
}
}
if (index == -1)
{
filenames.push_back(string(filename));
vector<int> newvector_placeholder;
groups.push_back(newvector_placeholder);
index = filenames.size()-1;
}
groups[index].push_back(i);
}
ioInfo.SetNDomains(mm->nblocks);
ioInfo.AddHints(groups);
}
CATCHALL
{
debug1 << "Unable to populate I/O information" << endl;
}
ENDTRY
}
// ****************************************************************************
// Method: avtSiloFileFormat::ShouldGoToDir
//
// Purpose:
// Determines if the directory is one we should go to. If we have already
// seen a multi-var that has a block in that directory, don't bother going
// in there.
//
// Arguments:
// dirname The directory of interest.
//
// Returns: true if we should go in the directory, false otherwise.
//
// Programmer: Hank Childs
// Creation: October 31, 2001
//
// Modifications:
// Jeremy Meredith, Tue Sep 13 16:00:16 PDT 2005
// Changed domainDirs to a set to ensure log(n) access times.
//
// Jeremy Meredith, Thu Dec 18 12:17:40 EST 2008
// Avoid descending through the top-level decomposition directories.
// In that convention, there will be no mesh variables in those trees,
// but in files with many domains, walking that subtree can be very slow.
// Also, re-use the count of dirname in domainDirs; don't check twice.
//
// ****************************************************************************
bool
avtSiloFileFormat::ShouldGoToDir(const char *dirname)
{
bool shouldGo = (domainDirs.count(dirname) == 0);
if (shouldGo)
debug5 << "Deciding to go into dir \"" << dirname << "\"" << endl;
else
debug5 << "Skipping dir \"" << dirname << "\"" << endl;
if (strcmp(dirname, "/Decomposition") == 0)
shouldGo = false;
if (strcmp(dirname, "/Global") == 0)
shouldGo = false;
return (shouldGo);
}
// ****************************************************************************
// Method: avtSiloFileFormat::RegisterDomainDirs
//
// Purpose:
// Registers directories that we know have blocks from a domain in them.
// This way we won't traverse that directory later.
//
// Arguments:
// dirlist A list of directories (with appended variable names).
// nList The number of elements in dirlist.
// curDir The name of the current directory.
//
// Programmer: Hank Childs
// Creation: October 31, 2001
//
// Modifications:
//
// Hank Childs, Fri Jul 12 16:22:02 PDT 2002
// Add support for variables that are specified absolutely instead of
// relatively.
//
// Jeremy Meredith, Tue Sep 13 16:00:16 PDT 2005
// Changed domainDirs to a set to ensure log(n) access times.
// Added check to make sure we don't even bother for an EMPTY domain.
//
// ****************************************************************************
void
avtSiloFileFormat::RegisterDomainDirs(const char * const *dirlist, int nList,
const char *curDir)
{
for (int i = 0 ; i < nList ; i++)
{
if (strcmp(dirlist[i], "EMPTY") == 0)
continue;
string str = PrepareDirName(dirlist[i], curDir);
domainDirs.insert(str);
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::QueryMultimesh
//
// Purpose:
// Returns a multimesh from the cache. Only returns a multimesh if
// we have called "GetMultimesh" on it before. It is entirely possible
// that "QueryMultimesh" returns NULL and there *is* a multi-mesh.
//
// Programmer: Hank Childs
// Creation: January 14, 2004
//
// ****************************************************************************
DBmultimesh *
avtSiloFileFormat::QueryMultimesh(const char *path, const char *name)
{
char combined_name[1024];
if ((path == NULL) || (strcmp(path, "") == 0) || (strcmp(path, "/") == 0))
strcpy(combined_name, name);
else
sprintf(combined_name, "%s/%s", path, name);
//
// First, check to see if we have already gotten the multi-mesh.
//
for (int i = 0 ; i < multimeshes.size() ; i++)
if (multimesh_name[i] == combined_name)
return multimeshes[i];
return NULL;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetMultimesh
//
// Purpose:
// Gets a multimesh and caches it for later use.
//
// Programmer: Hank Childs
// Creation: January 14, 2004
//
// Modifications:
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// ****************************************************************************
DBmultimesh *
avtSiloFileFormat::GetMultimesh(const char *path, const char *name)
{
//
// First, check to see if we have already gotten the multi-mesh.
//
DBmultimesh *qm = QueryMultimesh(path, name);
if (qm != NULL)
return qm;
char combined_name[1024];
if ((path == NULL) || (strcmp(path, "") == 0) || (strcmp(path, "/") == 0))
strcpy(combined_name, name);
else
sprintf(combined_name, "%s/%s", path, name);
//
// We haven't seen this multimesh before -- read it in.
//
DBfile *dbfile = GetFile(tocIndex);
DBmultimesh *mm = DBGetMultimesh(dbfile, combined_name);
multimesh_name.push_back(combined_name);
multimeshes.push_back(mm);
return mm;
}
// ****************************************************************************
// Programmer: Mark C. Miller
// Created: Thu Jun 18 20:08:47 PDT 2009
// ****************************************************************************
void avtSiloFileFormat::RemoveMultimesh(DBmultimesh *mm)
{
vector<DBmultimesh*>::iterator itm;
vector<string>::iterator itn;
for (itm = multimeshes.begin(), itn = multimesh_name.begin();
itm != multimeshes.end(); itm++, itn++)
{
if (*itm == mm)
{
multimeshes.erase(itm);
multimesh_name.erase(itn);
break;
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::QueryMultivar
//
// Purpose:
// Returns a multivar from the cache. Only returns a multivar if
// we have called "GetMultivar" on it before. It is entirely possible
// that "QueryMultivar" returns NULL and there *is* a multi-var.
//
// Programmer: Hank Childs
// Creation: January 14, 2004
//
// ****************************************************************************
DBmultivar *
avtSiloFileFormat::QueryMultivar(const char *path, const char *name)
{
//
// First, check to see if we have already gotten the multi-var.
//
char combined_name[1024];
if ((path == NULL) || (strcmp(path, "") == 0) || (strcmp(path, "/") == 0))
strcpy(combined_name, name);
else
sprintf(combined_name, "%s/%s", path, name);
for (int i = 0 ; i < multivars.size() ; i++)
if (multivar_name[i] == combined_name)
return multivars[i];
return NULL;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetMultivar
//
// Purpose:
// Gets a multivar and caches it for later use.
//
// Programmer: Hank Childs
// Creation: January 14, 2004
//
// Modifications:
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// ****************************************************************************
DBmultivar *
avtSiloFileFormat::GetMultivar(const char *path, const char *name)
{
//
// First, check to see if we have already gotten the multi-var.
//
DBmultivar *qm = QueryMultivar(path, name);
if (qm != NULL)
return qm;
char combined_name[1024];
if ((path == NULL) || (strcmp(path, "") == 0) || (strcmp(path, "/") == 0))
strcpy(combined_name, name);
else
sprintf(combined_name, "%s/%s", path, name);
//
// We haven't seen this multivar before -- read it in.
//
DBfile *dbfile = GetFile(tocIndex);
DBmultivar *mm = DBGetMultivar(dbfile, combined_name);
multivar_name.push_back(combined_name);
multivars.push_back(mm);
return mm;
}
// ****************************************************************************
// Programmer: Mark C. Miller
// Created: Thu Jun 18 20:08:47 PDT 2009
// ****************************************************************************
void avtSiloFileFormat::RemoveMultivar(DBmultivar *mv)
{
vector<DBmultivar*>::iterator itv;
vector<string>::iterator itn;
for (itv = multivars.begin(), itn = multivar_name.begin();
itv != multivars.end(); itv++, itn++)
{
if (*itv == mv)
{
multivars.erase(itv);
multivar_name.erase(itn);
break;
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::QueryMultimat
//
// Purpose:
// Returns a multimat from the cache. Only returns a multimat if
// we have called "GetMultimat" on it before. It is entirely possible
// that "QueryMultimat" returns NULL and there *is* a multi-mat.
//
// Programmer: Hank Childs
// Creation: January 14, 2004
//
// ****************************************************************************
DBmultimat *
avtSiloFileFormat::QueryMultimat(const char *path, const char *name)
{
//
// First, check to see if we have already gotten the multi-mat.
//
char combined_name[1024];
if ((path == NULL) || (strcmp(path, "") == 0) || (strcmp(path, "/") == 0))
strcpy(combined_name, name);
else
sprintf(combined_name, "%s/%s", path, name);
for (int i = 0 ; i < multimats.size() ; i++)
if (multimat_name[i] == combined_name)
return multimats[i];
return NULL;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetMultimat
//
// Purpose:
// Gets a multimat and caches it for later use.
//
// Programmer: Hank Childs
// Creation: January 14, 2004
//
// Modifications:
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// ****************************************************************************
DBmultimat *
avtSiloFileFormat::GetMultimat(const char *path, const char *name)
{
//
// First, check to see if we have already gotten the multi-mat.
//
DBmultimat *qm = QueryMultimat(path, name);
if (qm != NULL)
return qm;
char combined_name[1024];
if ((path == NULL) || (strcmp(path, "") == 0) || (strcmp(path, "/") == 0))
strcpy(combined_name, name);
else
sprintf(combined_name, "%s/%s", path, name);
//
// We haven't seen this multimat before -- read it in.
//
DBfile *dbfile = GetFile(tocIndex);
DBmultimat *mm = DBGetMultimat(dbfile, combined_name);
multimat_name.push_back(combined_name);
multimats.push_back(mm);
return mm;
}
// ****************************************************************************
// Programmer: Mark C. Miller
// Created: Thu Jun 18 20:08:47 PDT 2009
// ****************************************************************************
void avtSiloFileFormat::RemoveMultimat(DBmultimat *mm)
{
vector<DBmultimat*>::iterator itm;
vector<string>::iterator itn;
for (itm = multimats.begin(), itn = multimat_name.begin();
itm != multimats.end(); itm++, itn++)
{
if (*itm == mm)
{
multimats.erase(itm);
multimat_name.erase(itn);
break;
}
}
}
// ****************************************************************************
// Method: avtSiloFileFormat::QueryMultimatspec
//
// Purpose:
// Returns a multimatspec from the cache. Only returns a multimatspec if
// we have called "GetMultimatspec" on it before. It is entirely possible
// that "QueryMultimatspec" returns NULL and there *is* a multi-matspec.
//
// Programmer: Hank Childs
// Creation: January 14, 2004
//
// ****************************************************************************
DBmultimatspecies *
avtSiloFileFormat::QueryMultimatspec(const char *path, const char *name)
{
//
// First, check to see if we have already gotten the multi-matspec.
//
char combined_name[1024];
if ((path == NULL) || (strcmp(path, "") == 0) || (strcmp(path, "/") == 0))
strcpy(combined_name, name);
else
sprintf(combined_name, "%s/%s", path, name);
for (int i = 0 ; i < multimatspecies.size() ; i++)
if (multimatspec_name[i] == combined_name)
return multimatspecies[i];
return NULL;
}
// ****************************************************************************
// Method: avtSiloFileFormat::GetMultimatspec
//
// Purpose:
// Gets a multimatspec and caches it for later use.
//
// Programmer: Hank Childs
// Creation: January 14, 2004
//
// Modifications:
//
// Mark C. Miller, Mon Feb 23 12:02:24 PST 2004
// Changed call to OpenFile() to GetFile()
//
// ****************************************************************************
DBmultimatspecies *
avtSiloFileFormat::GetMultimatspec(const char *path, const char *name)
{
//
// First, check to see if we have already gotten the multi-matspec.
//
DBmultimatspecies *qm = QueryMultimatspec(path, name);
if (qm != NULL)
return qm;
char combined_name[1024];
if ((path == NULL) || (strcmp(path, "") == 0) || (strcmp(path, "/") == 0))
strcpy(combined_name, name);
else
sprintf(combined_name, "%s/%s", path, name);
//
// We haven't seen this multimatspec before -- read it in.
//
DBfile *dbfile = GetFile(tocIndex);
DBmultimatspecies *mm = DBGetMultimatspecies(dbfile, combined_name);
multimatspec_name.push_back(combined_name);
multimatspecies.push_back(mm);
return mm;
}
// ****************************************************************************
// Programmer: Mark C. Miller
// Created: Thu Jun 18 20:08:47 PDT 2009
// ****************************************************************************
void avtSiloFileFormat::RemoveMultimatspec(DBmultimatspecies *ms)
{
vector<DBmultimatspecies*>::iterator itm;
vector<string>::iterator itn;
for (itm = multimatspecies.begin(), itn = multimatspec_name.begin();
itm != multimatspecies.end(); itm++, itn++)
{
if (*itm == ms)
{
multimatspecies.erase(itm);
multimatspec_name.erase(itn);
break;
}
}
}
// ****************************************************************************
// Function: ExceptionGenerator
//
// Purpose:
// Generates a Silo exception so that Silo's error handling can hook into
// VisIt's error handling library.
//
// Programmer: Hank Childs
// Creation: April 9, 2001
//
// Modifications:
//
// Hank Childs, Thu Aug 16 11:06:27 PDT 2001
// No longer throw an exception.
//
// Jeremy Meredith, Tue Oct 4 16:08:28 PDT 2005
// The msg variable can actually be NULL as sent from Silo. Trying to
// print this to a debug log can actually put the log itself into a
// bad state. (It's clearly not a good idea anyway.) I changed the
// error message for when msg==NULL.
//
// ****************************************************************************
void
ExceptionGenerator(char *msg)
{
if (msg)
{
debug1 << "The following Silo error occurred: " << msg << endl;
}
else
{
debug1 << "A Silo error occurred, but the Silo library did not "
<< "generate an error message." << endl;
}
}
// ****************************************************************************
// Function: GenerateName
//
// Purpose:
// Generates a name from a directory and a file name.
//
// Arguments:
// dirname A directory name.
// varname The name of the variable.
//
// Returns: A string for the directory and variable.
//
// Notes: The caller must free the return value.
//
// Programmer: Hank Childs
// Creation: October 30, 2001
//
// Modifications:
//
// Hank Childs, Mon Dec 1 14:13:30 PST 2003
// Do a better job of handling variables that have absolute paths.
//
// Mark C. Miller, Wed Feb 6 12:23:56 PST 2008
// Made it handle the case where a single silo file contains multiple
// timesteps -- topDir is NOT "/". In this case, it has to filter everything
// out of either dirname or varname that is the top directory name.
//
// Tom Fogal, Mon Jul 21 14:43:14 EDT 2008
// I added an early exit clause for the case where we lack a '/' in the
// directory name. This fixes an invalid read.
//
// ****************************************************************************
char *
GenerateName(const char *dirname, const char *varname, const char *topdirname)
{
if (varname[0] == '/')
{
//
// Figure out any adjustment necessary in the case that we're treating this
// silo file as though the 'top' dir is not "/" -- this is the case where
// a single silo file contains a whole time series in separate dirs.
//
int partOfPathThatIsReallyTopDirName = 0;
if (! (topdirname[0] == '/' && topdirname[1] == '\0'))
{
while (varname[partOfPathThatIsReallyTopDirName] ==
topdirname[partOfPathThatIsReallyTopDirName])
partOfPathThatIsReallyTopDirName++;
}
int tdOffset = partOfPathThatIsReallyTopDirName; // shorter name
int len = strlen(&varname[tdOffset]);
int num_slash = 0;
for (int i = 0 ; i < len ; i++)
if (varname[tdOffset+i] == '/')
num_slash++;
//
// If there are lots of slashes, then we have a fully qualified path,
// so leave them all in. If there is only one slash (and it is the
// first one), then take out the slash -- since the var would be
// referred to as "Mesh", not "/Mesh".
//
int offset = (num_slash > 1 ? 0 : 1);
char *rv = new char[strlen(varname+tdOffset)+1];
strcpy(rv, varname+offset+tdOffset);
return rv;
}
//
// Figure out any adjustment necessary in the case that we're treating this
// silo file as though the 'top' dir is not "/" -- this is the case where
// a single silo file contains a whole time series in separate dirs.
//
int partOfPathThatIsReallyTopDirName2 = 0;
if (! (topdirname[0] == '/' && topdirname[1] == '\0'))
{
while (dirname[partOfPathThatIsReallyTopDirName2] ==
topdirname[partOfPathThatIsReallyTopDirName2] &&
dirname[partOfPathThatIsReallyTopDirName2] != '\0')
partOfPathThatIsReallyTopDirName2++;
}
int tdOffset2 = partOfPathThatIsReallyTopDirName2; // shorter name
int amtForSlash = 1;
int amtForNullChar = 1;
int amtForMiddleSlash = 1;
int len = strlen(dirname) + strlen(varname) - amtForSlash + amtForNullChar
+ amtForMiddleSlash;
char *rv = new char[len];
// In the case that the string is `simple', then the calculation
// tdOffset2+1 actually points beyond the end of the string. We need to
// make sure we don't deref the pointer we'll make with it, so check for
// that simple case and bail out here if possible.
if (strlen(dirname) < tdOffset2+1)
{
sprintf(rv, "%s", varname);
return rv;
}
const char *dir_without_leading_slash = dirname+1+tdOffset2;
bool needMiddleSlash = false;
if (*dir_without_leading_slash != '\0')
{
needMiddleSlash = true;
}
if (needMiddleSlash)
{
sprintf(rv, "%s/%s", dir_without_leading_slash, varname);
}
else
{
sprintf(rv, "%s%s", dir_without_leading_slash, varname);
}
return rv;
}
// ****************************************************************************
// Function: PrepareDirName
//
// Purpose:
// Removes the appended variable and '/' from a character string and
// returns a directory name.
//
// Arguments:
// dirvar The directory and variable name in a string.
// curdir The current directory.
//
// Programmer: Hank Childs
// Creation: October 31, 2001
//
// Modifications:
//
// Hank Childs, Fri Jul 12 16:33:56 PDT 2002
// Renamed routine from RemoveVarName and added support for relative
// directory names.
//
// Jeremy Meredith, Wed Mar 19 09:19:52 PST 2003
// Changed a '>=' test to a '>' test to prevent a possible ABR. Renamed
// to PrepareDirName to match its intended use a little better.
//
// ****************************************************************************
string
PrepareDirName(const char *dirvar, const char *curdir)
{
int len = strlen(dirvar);
const char *last = dirvar + (len-1);
while (*last != '/' && last > dirvar)
{
last--;
}
if (*last != '/')
{
debug1 << "Unexpected case -- no dirs what-so-ever." << endl;
}
char str[1024];
int dirlen = 0;
if (dirvar[0] != '/')
{
//
// We have a relative path -- prepend the current directory.
//
strcpy(str, curdir);
dirlen = strlen(str);
}
strncpy(str+dirlen, dirvar, last-dirvar);
str[dirlen + (last-dirvar)] = '\0';
return string(str);
}
// ****************************************************************************
// Function: SplitDirVarName
//
// Purpose:
// Removes the prepended directory and '/' from a character string and
// returns the directory and variable name.
//
// Arguments:
// dirvar The directory and variable name in a string.
// curdir The current directory in a string.
//
// Programmer: Jeremy Meredith
// Creation: March 19, 2003
//
// Modifications:
//
// Mark C. Miller, Sun Dec 3 12:20:11 PST 2006
// Fixed memory problem when strlen dirvar is zero
// ****************************************************************************
void
SplitDirVarName(const char *dirvar, const char *curdir,
string &dir, string &var)
{
dir="";
var="";
int len;
if (!dirvar || ((len = strlen(dirvar)) == 0))
{
dir=curdir;
var="";
return;
}
const char *last = dirvar + (len-1);
while (*last != '/' && last > dirvar)
{
last--;
}
if (*last != '/')
{
dir=curdir;
var=dirvar;
return;
}
char str[1024];
int dirlen = 0;
if (dirvar[0] != '/')
{
//
// We have a relative path -- prepend the current directory.
//
strcpy(str, curdir);
dirlen = strlen(str);
}
strcpy(str+dirlen, dirvar);
str[dirlen + (last-dirvar)] = '\0';
dir=str;
var=str + dirlen + (last-dirvar) + 1;
}
// ****************************************************************************
// Function: SiloZoneTypeToVTKZoneType
//
// Purpose:
// Converts a zone type in Silo to a zone type in VTK.
//
// Arguments:
// zonetype The zone type in Silo.
//
// Returns: The zone type in VTK.
//
// Programmer: Hank Childs
// Creation: August 15, 2000
//
// ****************************************************************************
int
SiloZoneTypeToVTKZoneType(int zonetype)
{
int vtk_zonetype = -1;
switch (zonetype)
{
case DB_ZONETYPE_POLYGON:
vtk_zonetype = VTK_POLYGON;
break;
case DB_ZONETYPE_TRIANGLE:
vtk_zonetype = VTK_TRIANGLE;
break;
case DB_ZONETYPE_QUAD:
vtk_zonetype = VTK_QUAD;
break;
case DB_ZONETYPE_POLYHEDRON:
vtk_zonetype = -2;
break;
case DB_ZONETYPE_TET:
vtk_zonetype = VTK_TETRA;
break;
case DB_ZONETYPE_PYRAMID:
vtk_zonetype = VTK_PYRAMID;
break;
case DB_ZONETYPE_PRISM:
vtk_zonetype = VTK_WEDGE;
break;
case DB_ZONETYPE_HEX:
vtk_zonetype = VTK_HEXAHEDRON;
break;
case DB_ZONETYPE_BEAM:
vtk_zonetype = VTK_LINE;
break;
}
return vtk_zonetype;
}
// ****************************************************************************
// Function: TranslateSiloWedgeToVTKWedge
//
// Purpose:
// The silo and VTK wedges are stored differently; translate between them.
//
// Arguments:
// siloWedge A list of nodes from a Silo node list.
// vtkWedge The list of nodes in VTK ordering.
//
// Programmer: Hank Childs
// Creation: September 26, 2000
//
// Modifications:
//
// Kathleen Bonnell, Wed May 23 17:09:48 PDT 2001
// Changed orientation.
//
// Kathleen Bonnell, Thu Aug 9 15:50:15 PDT 2001
// Changed parameters from int to vtkIdType to match VTK 4.0 API.
//
// Hank Childs, Tue Jan 11 14:48:38 PST 2005
// We were following the comment in vtkWedge.h, which turns out to be
// wrong. Correct it now.
//
// ****************************************************************************
void
TranslateSiloWedgeToVTKWedge(const int *siloWedge, vtkIdType vtkWedge[6])
{
//
// The Silo wedge stores the four base nodes as 0, 1, 2, 3 and the two
// top nodes as 4, 5. The VTK wedge stores them as two triangles. When
// getting the exact translation, it is useful to look at the face lists
// and edge lists in vtkWedge.cxx.
//
vtkWedge[0] = siloWedge[2];
vtkWedge[1] = siloWedge[1];
vtkWedge[2] = siloWedge[5];
vtkWedge[3] = siloWedge[3];
vtkWedge[4] = siloWedge[0];
vtkWedge[5] = siloWedge[4];
}
// ****************************************************************************
// Function: TranslateSiloPyramidToVTKPyramid
//
// Purpose:
// The silo and VTK pyramids are stored differently; translate between them.
//
// Arguments:
// siloPyramid A list of nodes from a Silo node list.
// vtkPyramid The list of nodes in VTK ordering.
//
// Programmer: Kathleen Bonnell
// Creation: May 23, 2001
//
// Modifications:
//
// Kathleen Bonnell, Thu Aug 9 15:50:15 PDT 2001
// Changed parameters from int to vtkIdType to match VTK 4.0 API.
//
// ****************************************************************************
void
TranslateSiloPyramidToVTKPyramid(const int *siloPyramid, vtkIdType vtkPyramid[5])
{
//
// The Silo pyramid stores the four base nodes as 0, 1, 2, 3 in
// opposite order from the VTK wedge. When getting the exact translation,
// it is useful to look at the face lists and edge lists in
// vtkPyramid.cxx.
//
vtkPyramid[0] = siloPyramid[0];
vtkPyramid[1] = siloPyramid[3];
vtkPyramid[2] = siloPyramid[2];
vtkPyramid[3] = siloPyramid[1];
vtkPyramid[4] = siloPyramid[4];
}
// ****************************************************************************
// Function: TranslateSiloTetrahedronToVTKTetrahedron
//
// Purpose:
// The silo and VTK tetrahedrons are stored differently; translate between
// them.
//
// Arguments:
// siloTetrahedron A list of nodes from a Silo node list.
// vtkTetrahedron The list of nodes in VTK ordering.
//
// Programmer: Hank Childs
// Creation: January 11, 2005
//
// ****************************************************************************
void
TranslateSiloTetrahedronToVTKTetrahedron(const int *siloTetrahedron,
vtkIdType vtkTetrahedron[4])
{
//
// The Silo and VTK tetrahedrons are inverted.
//
vtkTetrahedron[0] = siloTetrahedron[1];
vtkTetrahedron[1] = siloTetrahedron[0];
vtkTetrahedron[2] = siloTetrahedron[2];
vtkTetrahedron[3] = siloTetrahedron[3];
}
// ****************************************************************************
// Function: TetIsInverted
//
// Purpose: Determine if Tets in Silo are inverted from Silo's Normal ordering
//
// Programmer: Mark C. Miller
// Creation: March 21, 2007
//
// ****************************************************************************
bool
TetIsInverted(const vtkIdType *siloTetrahedron, vtkUnstructuredGrid *ugrid)
{
//
// initialize set of 4 points of tet
//
float *pts = (float *) ugrid->GetPoints()->GetVoidPointer(0);
float p[4][3];
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 3; j++)
p[i][j] = pts[3*siloTetrahedron[i] + j];
}
//
// Compute a vector normal to plane of first 3 points
//
float n1[3] = {p[1][0] - p[0][0], p[1][1] - p[0][1], p[1][2] - p[0][2]};
float n2[3] = {p[2][0] - p[0][0], p[2][1] - p[0][1], p[2][2] - p[0][2]};
float n1Xn2[3] = { n1[1]*n2[2] - n1[2]*n2[1],
-(n1[0]*n2[2] - n1[2]*n2[0]),
n1[0]*n2[1] - n1[1]*n2[0]};
//
// Compute a dot-product of normal with a vector to the 4th point.
// If the tet is specified as Silo normally expects it, this dot
// product should be negative. If it is not negative, then tets
// are inverted
//
float n3[3] = {p[3][0] - p[0][0], p[3][1] - p[0][1], p[3][2] - p[0][2]};
float n3Dotn1Xn2 = n3[0]*n1Xn2[0] + n3[1]*n1Xn2[1] + n3[2]*n1Xn2[2];
if (n3Dotn1Xn2 > 0)
return true;
else
return false;
}
// ****************************************************************************
// Function: GetMultivarToMultimeshMap
//
// Purpose: Handle explicit multivar to multimesh mapping convention
//
// Programmer: Mark C. Miller
// Creation: December 12, 2006
//
// ****************************************************************************
void
avtSiloFileFormat::GetMultivarToMultimeshMap(DBfile *dbfile)
{
int lvars = DBGetVarLength(dbfile, "MultivarToMultimeshMap_vars");
int lmeshes = DBGetVarLength(dbfile, "MultivarToMultimeshMap_meshes");
if (lvars > 0 && lmeshes > 0)
{
int i;
string tmpStr;
char *vars = new char[lvars+1];
for (i = 0 ; i < lvars+1 ; i++)
vars[i] = '\0';
DBReadVar(dbfile, "MultivarToMultimeshMap_vars", vars);
vector<string> varVec;
tmpStr.clear();
for (i = 0 ; i < lvars+1; i++)
{
if (vars[i] == ';' || (i == lvars))
{
varVec.push_back(tmpStr);
tmpStr.clear();
}
else
{
tmpStr += vars[i];
}
}
delete [] vars;
char *meshes = new char[lmeshes+1];
for (i = 0 ; i < lmeshes+1 ; i++)
meshes[i] = '\0';
DBReadVar(dbfile, "MultivarToMultimeshMap_meshes", meshes);
vector<string> meshVec;
tmpStr.clear();
for (i = 0 ; i < lmeshes+1; i++)
{
if (meshes[i] == ';' || (i == lmeshes))
{
meshVec.push_back(tmpStr);
tmpStr.clear();
}
else
{
tmpStr += meshes[i];
}
}
delete [] meshes;
if (varVec.size() != meshVec.size())
{
debug1 << "Unable to build multivarToMultimeshMap because "
<< "varVec.size()=" << varVec.size() << ", but "
<< "meshVec.size()=" << meshVec.size() << endl;
}
debug5 << "Building multivarToMultimeshMap" << endl;
for (i = 0; i < varVec.size(); i++)
{
debug5 << " var \"" << varVec[i] << "\" : mesh \"" << meshVec[i] << "\"" << endl;
multivarToMultimeshMap[varVec[i]] = meshVec[i];
}
}
}
// ****************************************************************************
// Function: GuessCodeNameFromTopLevelVars
//
// Purpose: Guess name of the code that produced the data
//
// Programmer: Mark C. Miller
// Creation: July 9, 2007
//
// Modifications:
//
// Hank Childs, Fri Oct 5 09:16:29 PDT 2007
// Fix typo in print statement.
//
// Mark C. Miller, Thu Mar 27 09:57:06 PST 2008
// Added Block Structured code detection.
//
// ****************************************************************************
static string
GuessCodeNameFromTopLevelVars(DBfile *dbfile)
{
string retval = "Unknown";
if (DBInqVarExists(dbfile, "lineage") &&
DBInqVarExists(dbfile, "version_number") &&
DBInqVarExists(dbfile, "znburn_flag") &&
DBInqVarExists(dbfile, "chemistry_flag"))
{
retval = "Ale3d";
}
else if (DBInqVarExists(dbfile, "silo_file_date") &&
DBInqVarType(dbfile, "Global") == DB_DIR &&
DBInqVarType(dbfile, "Decomposition") == DB_DIR)
{
retval = "BlockStructured";
}
debug5 << "Guessing this Silo file was produced by code \"" << retval << "\"" << endl;
return retval;
}
// ****************************************************************************
// Function: AddAle3drlxstatEnumerationInfo
//
// Purpose: Add enumeration info for Ale3d's rlxstat variable. These names and
// values were taken directly from Ale3d's RelaxTest.h file.
//
// Programmer: Mark C. Miller
// Creation: July 9, 2007
//
// Modifications:
// Mark C. Miller, Mon Apr 14 15:41:21 PDT 2008
// Changed interface to enumerated scalars
// ****************************************************************************
static void
AddAle3drlxstatEnumerationInfo(avtScalarMetaData *smd)
{
smd->SetEnumerationType(avtScalarMetaData::ByValue);
smd->AddEnumNameValue("RLX_Uninitialized_-1",-1);
smd->AddEnumNameValue("RLX_Constrained_0",0);
smd->AddEnumNameValue("RLX_JustRelaxed_1",1);
smd->AddEnumNameValue("RLX_Relaxing_2",2);
smd->AddEnumNameValue("RLX_MustRelax_3",3);
smd->AddEnumNameValue("RLX_DispShortEdge_4",4);
smd->AddEnumNameValue("RLX_DispLagMotion_5",5);
smd->AddEnumNameValue("RLX_InflowOutflow_6",6);
smd->AddEnumNameValue("RLX_Symmetry_7",7);
smd->AddEnumNameValue("RLX_AngleWall_8",8);
smd->AddEnumNameValue("RLX_MustRelaxLimited_9",9);
smd->AddEnumNameValue("RLX_AdvectTangential_10",10);
smd->AddEnumNameValue("RLX_Reaction_13",13);
smd->AddEnumNameValue("RLX_ChemGrad_14",14);
smd->AddEnumNameValue("RLX_HoldNodeset_15",15);
smd->AddEnumNameValue("RLX_IntHist_16",16);
smd->AddEnumNameValue("RLX_Velocity_20",20);
smd->AddEnumNameValue("RLX_LightingTime_21",21);
smd->AddEnumNameValue("RLX_Region_22",22);
smd->AddEnumNameValue("RLX_ZNBurn_23",23);
smd->AddEnumNameValue("RLX_PlasticStrain_24",24);
smd->AddEnumNameValue("RLX_SALE_25",25);
smd->AddEnumNameValue("RLX_AdvTime_26",26);
smd->AddEnumNameValue("RLX_HoldUntilActive_27",27);
smd->AddEnumNameValue("RLX_SlaveExtension_29",29);
smd->AddEnumNameValue("RLX_PartialInvalid_30",30);
smd->AddEnumNameValue("RLX_FreeSurface_31",31);
smd->AddEnumNameValue("RLX_MixedNode_32",32);
smd->AddEnumNameValue("RLX_IgnitionPt_33",33);
smd->AddEnumNameValue("RLX_SlideMaster_34",34);
smd->AddEnumNameValue("RLX_PeriodicRelax_35",35);
smd->AddEnumNameValue("RLX_HoldUntilGrace_36",36);
smd->AddEnumNameValue("RLX_HeldIntHist_37",37);
smd->AddEnumNameValue("RLX_Equilibrated_38",38);
smd->AddEnumNameValue("RLX_ShellNode_39",39);
smd->AddEnumNameValue("RLX_BeamNode_40",40);
}
// ****************************************************************************
// Method: AddNodelistEnumerations
//
// Purpose: Add node list enumerations for block structured codes.
//
// Programmer: Mark C. Miller
// Creation: March 18, 2008
//
// Modifications:
// Mark C. Miller, Tue Apr 29 23:33:55 PDT 2008
// Added call to clear nlBlockToWindowsMap before build-it, or possibly
// re-building from a second or more call to this method.
//
// Mark C. Miller, Tue Mar 3 19:31:37 PST 2009
// As per Cyrus' recommendation, forced it to work only if mesh name
// is specifically 'hydro_mesh' but left all other logic (which supports
// perhaps multiple meshes) in place.
// ****************************************************************************
void
avtSiloFileFormat::AddNodelistEnumerations(DBfile *dbfile, avtDatabaseMetaData *md,
string meshname)
{
if (meshname != "hydro_mesh")
return;
if (DBInqVarType(dbfile, "/Global/Nodelists") != DB_DIR)
return;
DBReadVar(dbfile, "/Global/Nodelists/NumberNodelists", &numNodeLists);
// Note, if we ever remove the restriction on meshname, above, we need
// to make sure we don't wind up defining the same name scalar on different
// meshes.
avtScalarMetaData *smd = new avtScalarMetaData("Nodelists",
meshname, AVT_NODECENT);
#ifdef USE_BIT_MASK_FOR_NODELIST_ENUMS
smd->SetEnumerationType(avtScalarMetaData::ByBitMask);
#else
smd->SetEnumerationType(avtScalarMetaData::ByNChooseR);
smd->SetEnumNChooseRN(numNodeLists);
smd->SetEnumNChooseRMaxR(maxCoincidentNodelists);
#endif
smd->hideFromGUI = true;
int i;
nlBlockToWindowsMap.clear();
for (i = 0; i < numNodeLists; i++)
{
char *tmpName = 0; char tmpVarName[256];
SNPRINTF(tmpVarName, sizeof(tmpVarName), "/Global/Nodelists/Nodelist%d/Name", i);
tmpName = (char*) DBGetVar(dbfile, tmpVarName);
debug5 << "For nodelist \"" << tmpName << "\", value = " << i << endl;
smd->AddEnumNameValue(tmpName, i);
free(tmpName);
SNPRINTF(tmpVarName, sizeof(tmpVarName), "/Global/Nodelists/Nodelist%d/NumberWindows", i);
int numWindows;
DBReadVar(dbfile, tmpVarName, &numWindows);
debug5 << " NumberWindows = " << numWindows << endl;
for (int j = 0; j < numWindows; j++)
{
debug5 << " For Window " << j << endl;
SNPRINTF(tmpVarName, sizeof(tmpVarName), "/Global/Nodelists/Nodelist%d/Block%d", i, j);
int blockNum;
DBReadVar(dbfile, tmpVarName, &blockNum);
nlBlockToWindowsMap[blockNum].push_back(i);
debug5 << " Block = " << blockNum << endl;
debug5 << " Extents = ";
SNPRINTF(tmpVarName, sizeof(tmpVarName), "/Global/Nodelists/Nodelist%d/Extents%d", i, j);
int extents[6];
DBReadVar(dbfile, tmpVarName, extents);
for (int k = 0; k < 6; k++)
{
nlBlockToWindowsMap[blockNum].push_back(extents[k]);
debug5 << extents[k] << ", ";
}
debug5 << endl;
}
}
// record the always exclude value as blocknum=-1
smd->SetEnumAlwaysExcludeValue(-1.0);
smd->SetEnumPartialCellMode(avtScalarMetaData::Dissect);
md->Add(smd);
//
// Build the pascal triangle map for updating nodelist variable values
//
avtScalarMetaData::BuildEnumNChooseRMap(numNodeLists, maxCoincidentNodelists, pascalsTriangleMap);
}
// ****************************************************************************
// Method: AddAnnotIntNodelistEnumerations
//
// Purpose: Add ANNOTATION_INT node list enumerations
//
// Programmer: Mark C. Miller
// Creation: December 18, 2008
//
// Modifications:
// Mark C. Miller, Tue Dec 23 11:12:31 PST 2008
// Fixed wrong parameter based to setting of NChoosR min/max values.
//
// Mark C. Miller, Tue Feb 24 16:58:31 PST 2009
// Replaced use of DetermineFileAndDirectory with
// DetermineFilenameAndDirectory and explicit opens. The latter DOES NOT
// use the plugin's file management routines and this is important because
// this method is being called from within ReadDir we cannot allow file
// pointer stuff to change out from underneath ReadDir while it is still
// completing.
//
// Mark C. Miller, Mon Mar 2 11:46:47 PST 2009
// Undid previous change and instead added a call to the loop which has
// the effect of keeping the toc file open. The previous logic failed
// whenever the file being opened was not in '.' and it made more sense to
// just try to re-use the file opening logic and management routines of
// the plugin instead of solve problems with file naming here. Also, added
// logic to deal with EMTPY blocks in the mesh.
// ****************************************************************************
void
avtSiloFileFormat::AddAnnotIntNodelistEnumerations(DBfile *dbfile, avtDatabaseMetaData *md,
string meshname, DBmultimesh *mm)
{
//
// This is expensive as it will wind up iterating over all subfiles.
// But, we have no choice. Fortunately, we ONLY get here if the user
// explicitly set the read option that controls it. We also make use
// of the fact that DetermineFileAndDirectory, will wind up opening
// each unique silo file only once. Otherwise, we'd have to make this
// loop smart. We do this so we can collect up all the names of all
// the different nodelist objects.
//
map<string,int> arr_names;
bool haveFaceLists = false;
bool haveNodeLists = false;
for (int i = 0; i < mm->nblocks; i++)
{
if (string(mm->meshnames[i]) == "EMPTY")
continue;
char *realvar;
DBfile *correctFile;
DetermineFileAndDirectory(mm->meshnames[i], correctFile, 0, realvar);
if (correctFile == 0)
continue;
DBcompoundarray *ai = DBGetCompoundarray(correctFile, "ANNOTATION_INT");
if (ai)
{
debug5 << "Found ANNOTATION_INT object for block " << i << endl;
for (int j = 0; j < ai->nelems; j++)
{
arr_names[ai->elemnames[j]] = 1;
int len = strlen(ai->elemnames[j]);
if (strncmp("_face",&(ai->elemnames[j][len-5]),5) == 0)
haveFaceLists = true;
else if (strncmp("_node",&(ai->elemnames[j][len-5]),5) == 0)
haveNodeLists = true;
}
DBFreeCompoundarray(ai);
}
//
// Ensure that the toc file remains open while iterating through
// this loop because the caller, ReadDir(), will expect that it
// will not be closed.
//
OpenFile(tocIndex);
}
//
// If we didn't find anything, we're done.
//
if (!haveNodeLists && !haveFaceLists)
return;
//
// Populate the enumeration names. This is a two pass loop;
// first for nodelists, second for facelists.
//
for (int pass = 0; pass < 2; pass++)
{
if ((pass == 0 && !haveNodeLists) || (pass == 1 && !haveFaceLists))
continue;
avtScalarMetaData *smd = new avtScalarMetaData(
pass == 0 ? "AnnotInt_Nodelists" : "AnnotInt_Facelists",
meshname, AVT_NODECENT);
map<string, int>::const_iterator it;
int j = 0;
for (it = arr_names.begin(); it != arr_names.end(); it++)
{
int len = strlen(it->first.c_str());
if (strncmp(pass==0?"_node":"_face",&(it->first.c_str()[len-5]),5) == 0)
{
smd->AddEnumNameValue(string(it->first,0,len-5), j++);
debug5 << "Adding \"" << string(it->first,0,len-5) << "\"," << j << " to" <<
(pass == 0 ? " nodelist " : " zonelist ") << "enumeration" << endl;
}
}
if (pass == 0)
maxAnnotIntLists = smd->enumNames.size();
else
{
if (smd->enumNames.size() > maxAnnotIntLists)
maxAnnotIntLists = smd->enumNames.size();
}
#ifdef USE_BIT_MASK_FOR_NODELIST_ENUMS
smd->SetEnumerationType(avtScalarMetaData::ByBitMask);
#else
smd->SetEnumerationType(avtScalarMetaData::ByNChooseR);
smd->SetEnumNChooseRN(maxAnnotIntLists);
smd->SetEnumNChooseRMaxR(maxCoincidentNodelists);
#endif
smd->hideFromGUI = true;
// record the always exclude value as -1
smd->SetEnumAlwaysExcludeValue(-1.0);
smd->SetEnumPartialCellMode(avtScalarMetaData::Dissect);
md->Add(smd);
}
//
// Build the pascal triangle map for updating nodelist variable values
//
avtScalarMetaData::BuildEnumNChooseRMap(maxAnnotIntLists, maxCoincidentNodelists, pascalsTriangleMap);
}
// ****************************************************************************
// Function: GetCondensedGroupelMap
//
// Purpose: Simplify handling groupel maps for levels/children. Whether the
// maps are stored on level/patches nodes, arrays of children of these nodes
// or individual children of these nodes, returns a single groupel map object
// representing the same information as the possibly one or more groupel maps
// in the database.
//
// Programmer: Mark C. Miller
// Creation: November 18, 2008
//
// Modifications
// Mark C. Miller Wed Nov 19 20:30:19 PST 2008
// Changed conditional for Silo version to 4.6.3
//
// Mark C. Miller, Mon Nov 24 17:33:20 PST 2008
// Testing gpl commit hook
//
// Mark C. Miller, Mon Nov 24 17:33:47 PST 2008
// Testing gpl commit hook with gnu general
// public license text.
//
// Hank Childs, Mon May 25 11:26:25 PDT 2009
// Fix macro compilation problem with old versions of Silo.
//
// Mark C. Miller, Mon Nov 9 08:54:28 PST 2009
// Protected calls to DBForceSingle with check for whether plugin is
// actually forcing single precision.
//
// Mark C. Miller, Wed Jan 20 16:35:37 PST 2010
// Made calls to ForceSingle on and off UNconditional.
// ****************************************************************************
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
static DBgroupelmap *
GetCondensedGroupelMap(DBfile *dbfile, DBmrgtnode *rootNode, int dontForceSingle)
{
int i,j,k,q,pass;
DBgroupelmap *retval = 0;
// We do this to prevent Silo for re-interpreting integer data in
// groupel maps
DBForceSingle(0);
if (rootNode->num_children == 1 && rootNode->children[0]->narray == 0)
{
retval = DBAllocGroupelmap(0, DB_NOTYPE);
}
else if ((rootNode->num_children == 1 && rootNode->children[0]->narray > 0) ||
(rootNode->num_children > 1 && rootNode->maps_name))
{
int nseg_mult = 1;
DBmrgtnode *mapNode;
if (rootNode->num_children == 1 && rootNode->children[0]->narray > 0)
{
nseg_mult = rootNode->children[0]->narray;
mapNode = rootNode->children[0];
}
else
mapNode = rootNode;
//
// Get the groupel map.
//
string mapsName = mapNode->maps_name;
DBgroupelmap *gm = DBGetGroupelmap(dbfile, mapsName.c_str());
//
// One pass to count parts of map we'll be needing and a 2nd
// pass to allocate and transfer those parts to the returned map.
//
for (pass = 0; pass < 2; pass++)
{
if (pass == 1) /* allocate on 2nd pass */
{
retval = DBAllocGroupelmap(q, DB_NOTYPE);
/* We won't need segment_ids because the map is condensed */
free(retval->segment_ids);
retval->segment_ids = 0;
}
q = 0;
for (k = 0; k < mapNode->nsegs * nseg_mult; k++)
{
for (i = 0; i < gm->num_segments; i++)
{
int gm_seg_id = gm->segment_ids ? gm->segment_ids[i] : i;
int tnode_seg_id = mapNode->seg_ids ? mapNode->seg_ids[k] : k;
int gm_seg_type = gm->groupel_types[i];
int tnode_seg_type = mapNode->seg_types[k];
if (gm_seg_id != tnode_seg_id ||
tnode_seg_type != DB_BLOCKCENT ||
gm_seg_type != DB_BLOCKCENT)
continue;
if (pass == 1) /* populate on 2nd pass */
{
retval->groupel_types[q] = DB_BLOCKCENT;
retval->segment_lengths[q] = gm->segment_lengths[tnode_seg_id];
/* Transfer ownership of segment_data to the condensed map */
retval->segment_data[q] = gm->segment_data[tnode_seg_id];
gm->segment_data[tnode_seg_id] = 0;
}
q++;
}
}
}
DBFreeGroupelmap(gm);
}
else
{
//
// Multiple groupel maps are stored, one for each node
//
retval = DBAllocGroupelmap(rootNode->num_children, DB_NOTYPE);
for (q = 0; q < rootNode->num_children; q++)
{
DBmrgtnode *rootChild = rootNode->children[q];
string mapsName = rootChild->maps_name;
DBgroupelmap *gm = DBGetGroupelmap(dbfile, mapsName.c_str());
for (k = 0; k < rootChild->nsegs; k++)
{
for (i = 0; i < gm->num_segments; i++)
{
int gm_seg_id = gm->segment_ids ? gm->segment_ids[i] : i;
int tnode_seg_id = rootChild->seg_ids ? rootChild->seg_ids[k] : k;
int gm_seg_type = gm->groupel_types[i];
int tnode_seg_type = rootChild->seg_types[k];
if (gm_seg_id != tnode_seg_id ||
tnode_seg_type != DB_BLOCKCENT ||
gm_seg_type != DB_BLOCKCENT)
continue;
retval->groupel_types[q] = DB_BLOCKCENT;
retval->segment_lengths[q] = gm->segment_lengths[i];
retval->segment_data[q] = gm->segment_data[i];
gm->segment_data[i] = 0;
}
}
DBFreeGroupelmap(gm);
}
}
DBForceSingle(!dontForceSingle);
return retval;
}
#endif
#endif
// ****************************************************************************
// Function: HandleMrgtreeForMultimesh
//
// Purpose: Process the AMR parts of a mesh region grouping (mrg) tree. Also
// handles whatever naming scheme the database specifies for levels and
// patches.
//
// Programmer: Mark C. Miller
// Creation: November 18, 2008
//
// Modifications
//
// Mark C. Miller Wed Nov 19 20:30:19 PST 2008
// Changed conditional for Silo version to 4.6.3
//
// Hank Childs, Mon May 25 11:26:25 PDT 2009
// Fix macro compilation problem with old versions of Silo.
//
// Mark C. Miller, Mon Nov 9 10:43:05 PST 2009
// Added dontForceSingle arg.
// ****************************************************************************
static void
HandleMrgtreeForMultimesh(DBfile *dbfile, DBmultimesh *mm, const char *multimesh_name,
avtMeshType *mt, int *num_groups, vector<int> *group_ids, vector<string> *block_names,
int dontForceSingle)
{
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
int i, j, k, q;
char tmpName[256];
bool probablyAnAMRMesh = true;
DBgroupelmap *gm = 0;
if (mm == 0)
return;
if (*mt != AVT_CURVILINEAR_MESH && *mt != AVT_RECTILINEAR_MESH)
return;
//
// Get the mesh region grouping tree
//
if (mm->mrgtree_name == 0)
{
debug3 << "No mrgtree specified for mesh \"" << multimesh_name << "\"" << endl;
return;
}
DBmrgtree *mrgTree = DBGetMrgtree(dbfile, mm->mrgtree_name);
if (mrgTree == 0)
{
debug3 << "Unable to find mrgtree named \"" << mm->mrgtree_name << "\"" << endl;
return;
}
//
// Try to go to the amr_decomp node in the tree
//
if (DBSetCwr(mrgTree, "amr_decomp") < 0)
{
debug3 << "Although mrgtree \"" << mm->mrgtree_name << "\" exists, "
<< "it does not contain node named \"amr_decomp\"." << endl;
DBFreeMrgtree(mrgTree);
return;
}
//
// Try to go to the 'levels' part of the amr_decomp
//
if (DBSetCwr(mrgTree, "levels") < 0)
{
debug3 << "Although a node named \"amr_decomp\" exists in \" "
<< mm->mrgtree_name << "\", it does not contain a child node"
<< "named \"levels\"." << endl;
DBFreeMrgtree(mrgTree);
return;
}
DBmrgtnode *levelsNode= mrgTree->cwr;
//
// Get level grouping information from the levels subtree
//
DBgroupelmap *lvlgm = GetCondensedGroupelMap(dbfile, levelsNode, dontForceSingle);
*num_groups = lvlgm->num_segments;
group_ids->resize(mm->nblocks,-1);
for (i = 0; i < lvlgm->num_segments; i++)
{
for (j = 0; j < lvlgm->segment_lengths[i]; j++)
{
int patch_no = ((int**) lvlgm->segment_data)[i][j];
(*group_ids)[patch_no] = i;
}
}
DBFreeGroupelmap(lvlgm);
DBSetCwr(mrgTree, "..");
if (DBSetCwr(mrgTree, "patches") < 0)
{
debug3 << "Although a node named \"amr_decomp\" exists in \" "
<< mm->mrgtree_name << "\", it does not contain a child node"
<< "named \"patches\"." << endl;
*num_groups = 0;
group_ids->clear();
DBFreeMrgtree(mrgTree);
return;
}
//
// Override the mesh type to be an AMR mesh
//
*mt = AVT_AMR_MESH;
//
// Set the block names according to contents of MRG Tree
//
DBmrgtnode *patchesNode = mrgTree->cwr;
if (patchesNode->num_children == 1)
{
if (patchesNode->children[0]->narray > 0 &&
patchesNode->children[0]->names)
{
//
// Array-based representation for the patches
//
DBmrgtnode *patchesArrayNode = patchesNode->children[0];
//
// Handle the names of the patches
//
if (strchr(patchesArrayNode->names[0],'%') == 0)
{
// Explicitly stored names
for (i = 0; i < patchesArrayNode->narray; i++)
block_names->push_back(patchesArrayNode->names[i]);
}
else
{
//
// Handle any array-refs in the naming scheme
//
int nrefs = 0;
char *p = strchr(patchesArrayNode->names[0],'$');
int *refs[] = {0,0,0,0,0,0,0,0,0,0};
DBmrgvar *vars[] = {0,0,0,0,0,0,0,0,0,0};
while (p != 0 && nrefs < sizeof(refs)/sizeof(refs[0]))
{
char *p1 = strchr(p, '[');
char tmpName[256];
strncpy(tmpName,p+1,p1-p-1);
vars[nrefs] = DBGetMrgvar(dbfile, tmpName);
if (vars[nrefs])
{
// assume its an integer valued variable
refs[nrefs] = (int*) (vars[nrefs]->data[0]);
nrefs++;
}
p = strchr(p,'$');
}
//
// Construct the names using the namescheme
//
DBnamescheme *ns = DBMakeNamescheme(patchesArrayNode->names[0],
refs[0],refs[1],refs[2],refs[3],refs[4]);
for (i = 0; i < patchesArrayNode->narray; i++)
block_names->push_back(DBGetName(ns, i));
//
// Free up everything
//
DBFreeNamescheme(ns);
for (i = 0; i < nrefs; i++)
DBFreeMrgvar(vars[i]);
}
}
else if (patchesNode->children[0]->narray == 0)
{
//
// Single block case.
//
block_names->push_back(patchesNode->children[0]->name);
}
}
else if (patchesNode->num_children > 1)
{
//
// Individual MRG Tree nodes for each patch
//
for (q = 0; q < patchesNode->num_children; q++)
{
DBmrgtnode *patchChild = patchesNode->children[q];
block_names->push_back(patchChild->name);
}
}
DBFreeMrgtree(mrgTree);
return;
#endif
#endif
}
// ****************************************************************************
// Function: BuildDomainAuxiliaryInfoForAMRMeshes
//
// Purpose: Builds domain nesting and boundary objects for AMR meshes.
// patches.
//
// Programmer: Mark C. Miller
// Creation: November 18, 2008
//
// Modifications
// Mark C. Miller Wed Nov 19 20:30:19 PST 2008
// Changed conditional for Silo version to 4.6.3
//
// Mark C. Miller, Tue Dec 9 00:26:27 PST 2008
// Testing hooks so adding comment to force update
//
// Mark C. Miller, Tue Dec 9 23:34:39 PST 2008
// Testing hooks by adding tab characters
//
// Hank Childs, Mon May 25 11:26:25 PDT 2009
// Add support for old versions of Silo.
//
// Mark C. Miller, Mon Nov 9 08:54:59 PST 2009
// Protecting calls to DBForceSingle with check to see if plugin is
// really forcing single.
//
// Mark C. Miller, Wed Jan 20 16:35:37 PST 2010
// Made calls to ForceSingle on and off UNconditional.
//
// Cyrus Harrison, Mon Mar 22 15:07:25 PDT 2010
// Use curvi domain boundries if db_mesh_type == DB_QUADMESH.
//
// Cyrus Harrison, Mon Mar 22 15:07:25 PDT 2010
// This function requires db_mesh_type to be either DB_QUAD_RECT or DB_QUAD_CURV
// (DB_QUADMESH is ambiguous).
//
// ****************************************************************************
static void
BuildDomainAuxiliaryInfoForAMRMeshes(DBfile *dbfile, DBmultimesh *mm,
const char *meshName, int timestate, int db_mesh_type,
avtVariableCache *cache, int dontForceSingle)
{
#ifdef MDSERVER
return;
#else
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
int i, j;
int num_levels = 0;
int num_patches = 0;
int num_dims = 0;
//
// First, look to see if we don't already have it cached
// Note that we compute BOTH domain nesting and domain boundary
// information here. However, we use only existance of domain
// nesting object in cache as trigger for whether to compute
// both objects or not.
//
void_ref_ptr vrTmp = cache->GetVoidRef("any_mesh",
AUXILIARY_DATA_DOMAIN_NESTING_INFORMATION,
timestate, -1);
if (*vrTmp != NULL)
return;
//
// Get the mesh region grouping tree
//
if (mm->mrgtree_name == 0)
{
debug3 << "No mrgtree specified for mesh \"" << meshName << "\"" << endl;
return;
}
DBmrgtree *mrgTree = DBGetMrgtree(dbfile, mm->mrgtree_name);
if (mrgTree == 0)
{
debug3 << "Unable to find mrgtree named \"" << mm->mrgtree_name << "\"" << endl;
return;
}
//
// Look through all the mrgtree's variable object names to see if
// any define 'ratios' or 'ijk' extents. They are needed to
// compute domain nesting and neighbor information.
//
char **vname = mrgTree->mrgvar_onames;
string ratioVarName;
string ijkExtsVarName;
while (vname && *vname != 0)
{
string vnameTmp = *vname;
for (size_t k = 0; k < vnameTmp.size(); k++)
vnameTmp[k] = tolower(vnameTmp[k]);
if (vnameTmp.find("ratio") != string::npos)
ratioVarName = *vname;
if (vnameTmp.find("ijk") != string::npos)
ijkExtsVarName = *vname;
vname++;
}
if (ratioVarName == "")
{
debug3 << "Although mrgtree \"" << mm->mrgtree_name << "\" exists, "
<< "it does not appear to have either a ratios variable." << endl;
DBFreeMrgtree(mrgTree);
return;
}
if (ijkExtsVarName == "")
{
debug3 << "Although mrgtree \"" << mm->mrgtree_name << "\" exists, "
<< "it does not appear to have either an ijk extents variable." << endl;
DBFreeMrgtree(mrgTree);
return;
}
//
// Try to go to the amr_decomp node in the tree
//
if (DBSetCwr(mrgTree, "amr_decomp") < 0)
{
debug3 << "Although mrgtree \"" << mm->mrgtree_name << "\" exists, "
<< "it does not contain node named \"amr_decomp\"." << endl;
DBFreeMrgtree(mrgTree);
return;
}
//
// Try to go to the 'levels' part of the amr_decomp
//
if (DBSetCwr(mrgTree, "levels") < 0)
{
debug3 << "Although a node named \"amr_decomp\" exists in \" "
<< mm->mrgtree_name << "\", it does not contain a child node"
<< "named \"levels\"." << endl;
DBFreeMrgtree(mrgTree);
return;
}
DBmrgtnode *levelsNode = mrgTree->cwr;
//
// Get level grouping information from tree
//
DBgroupelmap *lvlgm = GetCondensedGroupelMap(dbfile, levelsNode, dontForceSingle);
num_levels = lvlgm->num_segments;
debug5 << "num_levels = " << num_levels << endl;
vector<int> levelId;
levelId.resize(mm->nblocks,-1);
for (i = 0; i < lvlgm->num_segments; i++)
{
for (j = 0; j < lvlgm->segment_lengths[i]; j++)
{
int patch_no = ((int**) lvlgm->segment_data)[i][j];
levelId[patch_no] = i;
}
}
DBFreeGroupelmap(lvlgm);
//
// Try to go to the patches part of the amr_decomp
//
DBSetCwr(mrgTree, "..");
if (DBSetCwr(mrgTree, "patches") < 0)
{
debug3 << "Although a node named \"amr_decomp\" exists in \" "
<< mm->mrgtree_name << "\", it does not contain a child node"
<< "named \"patches\"." << endl;
DBFreeMrgtree(mrgTree);
return;
}
DBmrgtnode *childsNode = mrgTree->cwr;
//
// Get Parent/Child maps
//
DBgroupelmap *chldgm = GetCondensedGroupelMap(dbfile, childsNode, dontForceSingle);
//
// Read the ratios variable (on the levels) and the parent/child
// map.
//
DBForceSingle(0);
DBmrgvar *ratvar = DBGetMrgvar(dbfile, ratioVarName.c_str());
DBmrgvar *ijkvar = DBGetMrgvar(dbfile, ijkExtsVarName.c_str());
DBForceSingle(!dontForceSingle);
//
// The number of patches can be inferred from the size of the child groupel map.
//
num_patches = chldgm->num_segments;
debug5 << "num_patches = " << num_patches << endl;
//
// The number of dimensions can be inferred from the number of components in
// the ratios variable.
//
num_dims = ratvar->ncomps;
debug5 << "num_dims = " << num_dims << endl;
//
// build the avtDomainNesting object
//
avtStructuredDomainNesting *dn =
new avtStructuredDomainNesting(num_patches, num_levels);
dn->SetNumDimensions(num_dims);
//
// Set refinement level ratio information
//
vector<int> ratios(3,1);
dn->SetLevelRefinementRatios(0, ratios);
for (i = 1; i < num_levels; i++)
{
int **ratvar_data = (int **) ratvar->data;
ratios[0] = ratvar_data[0][i];
ratios[1] = ratvar_data[1][i];
ratios[2] = num_dims == 3 ? (int) ratvar_data[2][i]: 0;
debug5 << "ratios = " << ratios[0] << ", " << ratios[1] << ", " << ratios[2] << endl;
dn->SetLevelRefinementRatios(i, ratios);
}
//
// set each domain's level, children and logical extents
//
for (i = 0; i < num_patches; i++)
{
vector<int> childPatches;
for (j = 0; j < chldgm->segment_lengths[i]; j++)
childPatches.push_back(chldgm->segment_data[i][j]);
vector<int> logExts(6,0);
int **ijkvar_data = (int **) ijkvar->data;
logExts[0] = (int) ijkvar_data[0][i];
logExts[1] = (int) ijkvar_data[2][i];
logExts[2] = num_dims == 3 ? (int) ijkvar_data[4][i] : 0;
logExts[3] = (int) ijkvar_data[1][i];
logExts[4] = (int) ijkvar_data[3][i];
logExts[5] = num_dims == 3 ? (int) ijkvar_data[5][i] : 0;
debug5 << "logExts = " << logExts[0] << ", " << logExts[1] << ", " << logExts[2] << endl;
debug5 << " " << logExts[3] << ", " << logExts[4] << ", " << logExts[5] << endl;
dn->SetNestingForDomain(i, levelId[i], childPatches, logExts);
}
//
// Cache the domain nesting object we've just created
//
void_ref_ptr vr = void_ref_ptr(dn, avtStructuredDomainNesting::Destruct);
cache->CacheVoidRef("any_mesh", AUXILIARY_DATA_DOMAIN_NESTING_INFORMATION,
timestate, -1, vr);
//
// Ok, now move on to compute domain boundary information
//
bool canComputeNeighborsFromExtents = true;
avtStructuredDomainBoundaries *sdb = 0;
if (db_mesh_type == DB_QUAD_RECT)
{
sdb = new avtRectilinearDomainBoundaries(canComputeNeighborsFromExtents);
debug5 << "using rectilinear boundaries" << endl;
}
else if(db_mesh_type == DB_QUAD_CURV)
{
sdb = new avtCurvilinearDomainBoundaries(canComputeNeighborsFromExtents);
debug5 << "using curvilinear boundaries" << endl;
}
else
{
// DB_QUADMESH is ambiguous in this case, we need either
// DB_QUAD_RECT or DB_QUAD_CURV.
// throw an exception if we end up here to warn a developer.
ostringstream oss;
oss << "Could not determine coordinate type for AMR mesh=\""
<< meshName << "\".\n"
<< "Expected: QB_QUAD_RECT (DB_COLLINEAR) or "
<< "DB_QUAD_CURV (DB_NONCOLLINEAR).";
EXCEPTION1(ImproperUseException, oss.str().c_str());
}
sdb->SetNumDomains(num_patches);
for (int i = 0 ; i < num_patches ; i++)
{
int **ijkvar_data = (int **) ijkvar->data;
int e[6];
e[0] = (int) ijkvar_data[0][i];
e[1] = (int) ijkvar_data[1][i]+1;
e[2] = (int) ijkvar_data[2][i];
e[3] = (int) ijkvar_data[3][i]+1;
e[4] = num_dims == 3 ? (int) ijkvar_data[4][i] : 0;
e[5] = num_dims == 3 ? (int) ijkvar_data[5][i]+1 : 1;
sdb->SetIndicesForAMRPatch(i, levelId[i], e);
}
sdb->CalculateBoundaries();
//
// Cache the domain boundary object we've created
//
void_ref_ptr vsdb = void_ref_ptr(sdb,avtStructuredDomainBoundaries::Destruct);
cache->CacheVoidRef("any_mesh", AUXILIARY_DATA_DOMAIN_BOUNDARY_INFORMATION,
timestate, -1, vsdb);
if (ratvar)
DBFreeMrgvar(ratvar);
if (ijkvar)
DBFreeMrgvar(ijkvar);
if (chldgm)
DBFreeGroupelmap(chldgm);
#endif
#endif
#endif
}
// ****************************************************************************
// Function: MultiMatHasAllMatInfo
//
// Purpose: Return an int indicating if a multi-mat object has all the
// pieces of information necessary to correctly define a material variable.
//
// 0 ==> don't even know how many materials there are
// 1 ==> know how many materials, but not their numbers, names or colors
// 2 ==> know how many materials and their numbers, but not names or colors
// 3 ==> know how many materials, their numbers and names but not colors
// 4 ==> know everything.
//
// Programmer: Mark C. Miller
// Creation: March 19, 2009
//
// Modifications:
//
// Hank Childs, Mon May 25 11:07:17 PDT 2009
// Add support for Silo releases before 4.6.3.
//
// ****************************************************************************
static int
MultiMatHasAllMatInfo(const DBmultimat *const mm)
{
#ifdef SILO_VERSION_GE
#if SILO_VERSION_GE(4,6,3)
if (mm->nmatnos <= 0)
return 0; // has nothing
if (mm->matnos)
{
if (mm->material_names)
{
if (mm->matcolors)
return 4; // has everything
else
return 3; // has everything but matcolors
}
else
return 2; // has just enough to be workable
}
else
return 1;
#endif
#endif
return 0;
}
|