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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkExodusIIReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*----------------------------------------------------------------------------
Copyright (c) Sandia Corporation
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/
#include "vtkExodusIIReader.h"
#include "vtkExodusIICache.h"
#include "vtkCellData.h"
#include "vtkCellType.h"
#include "vtkCharArray.h"
#include "vtkDoubleArray.h"
#include "vtkExodusModel.h"
#include "vtkFloatArray.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkIntArray.h"
#include "vtkMath.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMutableDirectedGraph.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkSortDataArray.h"
#include "vtkStdString.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkUnstructuredGrid.h"
#include "vtkXMLParser.h"
#include "vtkStringArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkVariantArray.h"
#include "vtkSmartPointer.h"
#include "vtkExodusIIReaderParser.h"
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <string>
#include "vtksys/SystemTools.hxx"
#include "vtksys/RegularExpression.hxx"
#include "vtk_exodusII.h"
#include <stdio.h>
#include <stdlib.h> /* for free() */
#include <string.h> /* for memset() */
#include <ctype.h> /* for toupper(), isgraph() */
#include <math.h> /* for cos() */
#ifdef EXODUSII_HAVE_MALLOC_H
# include <malloc.h>
#endif /* EXODUSII_HAVE_MALLOC_H */
#if defined(_WIN32) && !defined(__CYGWIN__)
# define SNPRINTF _snprintf
#else
# define SNPRINTF snprintf
#endif
/// Define this to get printouts summarizing array glomming process
#undef VTK_DBG_GLOM
#define VTK_EXO_FUNC(funcall,errmsg)\
if ( (funcall) < 0 ) \
{ \
vtkErrorMacro( errmsg ); \
return 1; \
}
// ------------------------------------------------------------------- CONSTANTS
static int obj_types[] = {
EX_EDGE_BLOCK,
EX_FACE_BLOCK,
EX_ELEM_BLOCK,
EX_NODE_SET,
EX_EDGE_SET,
EX_FACE_SET,
EX_SIDE_SET,
EX_ELEM_SET,
EX_NODE_MAP,
EX_EDGE_MAP,
EX_FACE_MAP,
EX_ELEM_MAP,
EX_NODAL
};
static int num_obj_types = (int)(sizeof(obj_types)/sizeof(obj_types[0]));
static int obj_sizes[] = {
EX_INQ_EDGE_BLK,
EX_INQ_FACE_BLK,
EX_INQ_ELEM_BLK,
EX_INQ_NODE_SETS,
EX_INQ_EDGE_SETS,
EX_INQ_FACE_SETS,
EX_INQ_SIDE_SETS,
EX_INQ_ELEM_SETS,
EX_INQ_NODE_MAP,
EX_INQ_EDGE_MAP,
EX_INQ_FACE_MAP,
EX_INQ_ELEM_MAP,
EX_INQ_NODES
};
static const char* objtype_names[] = {
"Edge block",
"Face block",
"Element block",
"Node set",
"Edge set",
"Face set",
"Side set",
"Element set",
"Node map",
"Edge map",
"Face map",
"Element map",
"Nodal"
};
static const char* obj_typestr[] = {
"L",
"F",
"E",
"M",
"D",
"A",
"S",
"T",
0, /* maps have no result variables */
0,
0,
0,
"N"
};
#define OBJTYPE_IS_BLOCK(i) ((i>=0)&&(i<3))
#define OBJTYPE_IS_SET(i) ((i>2)&&(i<8))
#define OBJTYPE_IS_MAP(i) ((i>7)&&(i<12))
#define OBJTYPE_IS_NODAL(i) (i==12)
// Unlike obj* items above:
// - conn* arrays only reference objects that generate connectivity information
// - conn* arrays are ordered the way users expect the output (*not* the same as above)
static int conn_types[] = {
vtkExodusIIReader::ELEM_BLOCK_ELEM_CONN,
vtkExodusIIReader::FACE_BLOCK_CONN,
vtkExodusIIReader::EDGE_BLOCK_CONN,
vtkExodusIIReader::ELEM_SET_CONN,
vtkExodusIIReader::SIDE_SET_CONN,
vtkExodusIIReader::FACE_SET_CONN,
vtkExodusIIReader::EDGE_SET_CONN,
vtkExodusIIReader::NODE_SET_CONN
};
static const char* conn_types_names[] = {
"Element Blocks",
"Face Blocks",
"Edge Blocks",
"Element Sets",
"Side Sets",
"Face Sets",
"Edge Sets",
"Node Sets"
};
static int num_conn_types = (int)(sizeof(conn_types)/sizeof(conn_types[0]));
// Given a conn_type index, what is its matching obj_type index?
static int conn_obj_idx_cvt[] = {
2, 1, 0, 7, 6, 5, 4, 3
};
#define CONNTYPE_IS_BLOCK(i) ((i>=0)&&(i<3))
#define CONNTYPE_IS_SET(i) ((i>2)&&(i<8))
static const char* glomTypeNames[] = {
"Scalar",
"Vector2",
"Vector3",
"Symmetric Tensor",
"Integration Point Values"
};
// used to store pointer to ex_get_node_num_map or ex_get_elem_num_map:
extern "C" { typedef int (*vtkExodusIIGetMapFunc)( int, int* ); }
// --------------------------------------------------- PRIVATE CLASS DECLARATION
#include "vtkExodusIIReaderPrivate.h"
#include "vtkExodusIIReaderVariableCheck.h"
// --------------------------------------------------- PRIVATE CLASS Implementations
vtkExodusIIReaderPrivate::BlockSetInfoType::BlockSetInfoType(
const vtkExodusIIReaderPrivate::BlockSetInfoType &block):
vtkExodusIIReaderPrivate::ObjectInfoType(block),
FileOffset(block.FileOffset),
PointMap(block.PointMap),
ReversePointMap(block.ReversePointMap),
CachedConnectivity(0)
{
//this is needed to properly manage memory.
//when vectors are resized or reserved the container
//might be copied to a memory spot, so we need a proper copy constructor
//so that the cache remains valid
this->CachedConnectivity = block.CachedConnectivity;
}
vtkExodusIIReaderPrivate::BlockSetInfoType::~BlockSetInfoType()
{
if (this->CachedConnectivity)
{
this->CachedConnectivity->Delete();
}
}
// ----------------------------------------------------------- UTILITY ROUTINES
// This function exists because FORTRAN ordering sucks.
static void extractTruthForVar( int num_obj, int num_vars, const int* truth_tab, int var, std::vector<int>& truth )
{
truth.clear();
int obj;
int ttObj; // truth table entry for variable var on object obj.
for ( obj = 0; obj < num_obj; ++obj )
{
ttObj = truth_tab[ var + obj * num_vars ];
truth.push_back( ttObj );
}
}
static void printBlock( ostream& os, vtkIndent indent, int btyp,
vtkExodusIIReaderPrivate::BlockInfoType& binfo )
{
int b = 0;
while ( obj_types[b] >= 0 && obj_types[b] != btyp )
++b;
const char* btypnam = objtype_names[b];
os << indent << btypnam << " " << binfo.Id << " \"" << binfo.Name.c_str()
<< "\" (" << binfo.Size << ")\n";
os << indent << " FileOffset: " << binfo.FileOffset << "\n";
os << indent << " CachedConn: " << binfo.CachedConnectivity << " ("
<< binfo.Status << ")\n";
os << indent << " PointMap: " << binfo.PointMap.size() << " entries, "
<< "ReversePointMap: " << binfo.ReversePointMap.size() << " entries\n";
os << indent << " Type: " << binfo.TypeName.c_str() << "\n";
os << indent << " Bounds per entry, Node: " << binfo.BdsPerEntry[0]
<< " Edge: " << binfo.BdsPerEntry[1] << " Face: " << binfo.BdsPerEntry[2]
<< "\n";
os << indent << " Attributes (" << binfo.AttributesPerEntry << "):";
int a;
for ( a = 0; a < binfo.AttributesPerEntry; ++a )
{
os << " \"" << binfo.AttributeNames[a].c_str() << "\"("
<< binfo.AttributeStatus[a] << ")";
}
os << "\n";
}
static void printSet( ostream& os, vtkIndent indent, int styp,
vtkExodusIIReaderPrivate::SetInfoType& sinfo )
{
int s = 0;
while ( obj_types[s] >= 0 && obj_types[s] != styp )
++s;
const char* stypnam = objtype_names[s];
os << indent << stypnam << " " << sinfo.Id << " \"" << sinfo.Name.c_str()
<< "\" (" << sinfo.Size << ")\n";
os << indent << " FileOffset: " << sinfo.FileOffset << "\n";
os << indent << " CachedConn: " << sinfo.CachedConnectivity << " ("
<< sinfo.Status << ")\n";
os << indent << " PointMap: " << sinfo.PointMap.size() << " entries, "
<< "ReversePointMap: " << sinfo.ReversePointMap.size() << " entries\n";
os << indent << " DistFact: " << sinfo.DistFact << "\n";
}
static void printMap( ostream& os,
vtkIndent indent,
int mtyp,
vtkExodusIIReaderPrivate::MapInfoType& minfo )
{
int m = 0;
while ( obj_types[m] >= 0 && obj_types[m] != mtyp )
++m;
const char* mtypnam = objtype_names[m];
os << indent << mtypnam << " " << minfo.Id << " \"" << minfo.Name.c_str()
<< "\" (" << minfo.Size << ")\n";
os << indent << " Status: " << minfo.Status << "\n";
}
static void printArray( ostream& os, vtkIndent indent, int atyp,
vtkExodusIIReaderPrivate::ArrayInfoType& ainfo )
{
(void)atyp;
os << indent << " " << ainfo.Name.c_str() << " [" << ainfo.Status << "] ( "
<< ainfo.Components << " = { ";
os << ainfo.OriginalIndices[0] << " \"" << ainfo.OriginalNames[0] << "\"";
int i;
for ( i = 1; i < (int) ainfo.OriginalIndices.size(); ++i )
{
os << ", " << ainfo.OriginalIndices[i] << " \"" << ainfo.OriginalNames[i]
<< "\"";
}
os << " } )\n";
os << indent << " " << glomTypeNames[ ainfo.GlomType ] << " Truth:";
for ( i = 0; i < (int)ainfo.ObjectTruth.size(); ++i )
{
os << " " << ainfo.ObjectTruth[i];
}
os << "\n";
}
// --------------------------------------------------- PRIVATE SUBCLASS MEMBERS
void vtkExodusIIReaderPrivate::ArrayInfoType::Reset()
{
if ( ! this->Name.empty() )
{
this->Name.erase( this->Name.begin(), this->Name.end() );
}
this->Components = 0;
this->GlomType = -1;
this->Status = 0;
this->Source = -1;
this->OriginalNames.clear();
this->OriginalIndices.clear();
this->ObjectTruth.clear();
}
// ------------------------------------------------------- PRIVATE CLASS MEMBERS
vtkStandardNewMacro(vtkExodusIIReaderPrivate);
//-----------------------------------------------------------------------------
vtkExodusIIReaderPrivate::vtkExodusIIReaderPrivate()
{
this->Exoid = -1;
this->ExodusVersion = -1.;
this->AppWordSize = 8;
this->DiskWordSize = 8;
this->Cache = vtkExodusIICache::New();
this->CacheSize = 0;
this->TimeStep = 0;
this->HasModeShapes = 0;
this->ModeShapeTime = -1.;
this->AnimateModeShapes = 1;
this->GenerateObjectIdArray = 1;
this->GenerateGlobalElementIdArray = 0;
this->GenerateGlobalNodeIdArray = 0;
this->GenerateImplicitElementIdArray = 0;
this->GenerateImplicitNodeIdArray = 0;
this->GenerateGlobalIdArray = 0;
this->GenerateFileIdArray = 0;
this->FileId = 0;
this->ApplyDisplacements = 1;
this->DisplacementMagnitude = 1.;
this->SqueezePoints = 1;
this->Parser = 0;
this->FastPathObjectType = vtkExodusIIReader::NODAL;
this->FastPathIdType = NULL;
this->FastPathObjectId = -1;
this->SIL = vtkMutableDirectedGraph::New();
this->ProducedFastPathOutput = false;
memset( (void*)&this->ModelParameters, 0, sizeof(this->ModelParameters) );
}
//-----------------------------------------------------------------------------
vtkExodusIIReaderPrivate::~vtkExodusIIReaderPrivate()
{
this->CloseFile();
this->Cache->Delete();
this->CacheSize = 0;
this->ClearConnectivityCaches();
this->SetFastPathIdType( 0 );
if(this->Parser)
{
this->Parser->Delete();
this->Parser = 0;
}
this->SIL->Delete();
this->SIL = 0;
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::GlomArrayNames( int objtyp,
int num_obj,
int num_vars,
char** var_names,
int* truth_tab )
{
// Clear out existing array names since we are re-reading them in.
this->ArrayInfo[objtyp].clear();
// Create some objects that try to glom names together in different ways.
const char endRZ[] = "RZ";
const char endV2[] = "xy";
const char endV3[] = "xYz";
const char endST23[] = "XXYYZZXYXZYZ";
const char endST34[] = "XXXYYYZZZWWWXXYXXZXXWXYYXYZXYWXZZXZWXWWYYZYYWYZZYZWYWWZZWZWW";
vtkExodusIIReaderScalarCheck* scalar = new vtkExodusIIReaderScalarCheck;
//vtkExodusIIReaderVectorCheck* vecx2 = new vtkExodusIIReaderVectorCheck( endV2, 2 );
//vtkExodusIIReaderVectorCheck* vecx3 = new vtkExodusIIReaderVectorCheck( endV3, 3 );
//vtkExodusIIReaderVectorCheck* vecrz = new vtkExodusIIReaderVectorCheck( endRZ, 2 );
vtkExodusIIReaderTensorCheck* vecx2 = new vtkExodusIIReaderTensorCheck( endV2, 2, 1, 2 );
vtkExodusIIReaderTensorCheck* vecx3 = new vtkExodusIIReaderTensorCheck( endV3, 3, 1, 3 );
vtkExodusIIReaderTensorCheck* vecrz = new vtkExodusIIReaderTensorCheck( endRZ, 2, 1, 2 );
vtkExodusIIReaderTensorCheck* ten23 = new vtkExodusIIReaderTensorCheck( endST23, 6, 2, 3 );
vtkExodusIIReaderTensorCheck* ten34 = new vtkExodusIIReaderTensorCheck( endST34, 20, 3, 4 );
vtkExodusIIReaderIntPointCheck* intpt = new vtkExodusIIReaderIntPointCheck;
typedef std::vector<vtkExodusIIReaderVariableCheck*> glomVec;
glomVec glommers;
glommers.push_back( scalar );
glommers.push_back( vecx2 );
glommers.push_back( vecx3 );
glommers.push_back( vecrz );
glommers.push_back( ten23 );
glommers.push_back( ten34 );
glommers.push_back( intpt );
glomVec::iterator glommer;
typedef std::vector<vtkExodusIIReaderPrivate::ArrayInfoType> varVec;
varVec arrays;
std::vector<int> tmpTruth;
// Advance through the variable names.
for ( int i = 0; i < num_vars; ++ i )
{
// Prepare all the glommers with the next unused variable name
extractTruthForVar( num_obj, num_vars, truth_tab, i, tmpTruth );
bool stop = true;
for ( glommer = glommers.begin(); glommer != glommers.end(); ++ glommer )
{
if ( (*glommer)->Start( var_names[i], &tmpTruth[0], num_obj ) )
{
stop = false;
}
}
int j = i + 1;
// If any glommers can continue accepting names, give them more names until no more can accept names
while ( j < num_vars && ! stop )
{
stop = true;
for ( glommer = glommers.begin(); glommer != glommers.end(); ++ glommer )
{
if ( (*glommer)->Add( var_names[j], &tmpTruth[0] ) )
{
stop = false;
}
}
++ j;
}
// Find longest glom that worked. (The scalar glommer always works with Length() 1.)
unsigned int longestGlom = 0;
glomVec::iterator longestGlommer = glommers.end();
for ( glommer = glommers.begin(); glommer != glommers.end(); ++ glommer )
{
if ( (*glommer)->Length() > longestGlom )
{
longestGlom = static_cast<unsigned int>( (*glommer)->Length() );
longestGlommer = glommer;
}
}
if ( longestGlommer != glommers.end() )
{
i += (*longestGlommer)->Accept( this->ArrayInfo[objtyp], i, this, objtyp ) - 1; // the ++i takes care of length 1
}
}
// Now see what the gloms were.
/*
for ( varVec::iterator it = this->ArrayInfo[objtyp].begin(); it != this->ArrayInfo[objtyp].end(); ++ it )
{
cout << "Name: \"" << it->Name.c_str() << "\" (" << it->Components << ")\n";
}
*/
delete scalar;
delete vecx2;
delete vecx3;
delete vecrz;
delete ten23;
delete ten34;
delete intpt;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::AssembleOutputConnectivity(
vtkIdType timeStep, int otyp, int oidx, int conntypidx,
BlockSetInfoType* bsinfop, vtkUnstructuredGrid* output )
{
// FIXME: Don't think I need this, since we ShallowCopy over it... right?
output->Reset();
if ( bsinfop->CachedConnectivity )
{
output->ShallowCopy( bsinfop->CachedConnectivity );
return 1;
}
// OK, we needed to remake the cache...
bsinfop->CachedConnectivity = vtkUnstructuredGrid::New();
bsinfop->CachedConnectivity->Allocate( bsinfop->Size );
if ( this->SqueezePoints )
{
bsinfop->NextSqueezePoint = 0;
bsinfop->PointMap.clear();
bsinfop->ReversePointMap.clear();
}
// Need to assemble connectivity array from smaller ones.
// Call GetCacheOrRead() for each smaller array
// Might want to experiment with the effectiveness of caching connectivity...
// set up the ExodusIICache class with the ability to never cache some
// key types.
// Might also want to experiment with policies other than LRU, especially
// applied to arrays that are not time-varying. During animations, they
// will most likely get dropped even though that might not be wise.
if ( CONNTYPE_IS_BLOCK(conntypidx) )
{
this->InsertBlockCells( otyp, oidx, conn_types[conntypidx],
timeStep, static_cast<BlockInfoType*>( bsinfop ) );
}
else if ( CONNTYPE_IS_SET(conntypidx) )
{
this->InsertSetCells( otyp, oidx, conn_types[conntypidx],
timeStep, static_cast<SetInfoType*>( bsinfop ) );
}
else
{
vtkErrorMacro( "Bad connectivity object type. Harass the responsible programmer." );
}
// OK, now copy our cache to the output...
output->ShallowCopy( bsinfop->CachedConnectivity );
//this->CachedConnectivity->ShallowCopy( output );
if ( this->SqueezePoints )
{
vtkDebugMacro( << "Squeezed down to " << bsinfop->NextSqueezePoint << " points\n" );
}
return 0;
}
int vtkExodusIIReaderPrivate::AssembleOutputPoints(
vtkIdType timeStep, BlockSetInfoType* bsinfop, vtkUnstructuredGrid* output )
{
(void)timeStep;
vtkPoints* pts = output->GetPoints();
if ( ! pts )
{
pts = vtkPoints::New();
output->SetPoints( pts );
pts->FastDelete();
}
else
{
pts->Reset();
}
int ts = -1; // If we don't have displacements, only cache the array under one key.
if ( this->ApplyDisplacements && this->FindDisplacementVectors( timeStep ) )
{ // Otherwise, each time step's array will be different.
ts = timeStep;
}
vtkDataArray* arr = this->GetCacheOrRead( vtkExodusIICacheKey( ts, vtkExodusIIReader::NODAL_COORDS, 0, 0 ) );
if ( ! arr )
{
vtkErrorMacro( "Unable to read points from file." );
return 0;
}
if ( this->SqueezePoints )
{
pts->SetNumberOfPoints( bsinfop->NextSqueezePoint );
std::map<vtkIdType,vtkIdType>::iterator it;
for ( it = bsinfop->PointMap.begin(); it != bsinfop->PointMap.end(); ++ it )
{
pts->SetPoint( it->second, arr->GetTuple( it->first ) );
}
}
else
{
pts->SetData( arr );
}
return 1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::AssembleOutputPointArrays(
vtkIdType timeStep, BlockSetInfoType* bsinfop, vtkUnstructuredGrid* output )
{
int status = 1;
std::vector<ArrayInfoType>::iterator ai;
int aidx = 0;
for (
ai = this->ArrayInfo[ vtkExodusIIReader::NODAL ].begin();
ai != this->ArrayInfo[ vtkExodusIIReader::NODAL ].end();
++ai, ++aidx )
{
if ( ! ai->Status )
continue; // Skip arrays we don't want.
vtkExodusIICacheKey key( timeStep, vtkExodusIIReader::NODAL, 0, aidx );
vtkDataArray* src = this->GetCacheOrRead( key );
if ( !src )
{
vtkDebugMacro( "Unable to read point array " << ai->Name.c_str() << " at time step " << timeStep );
status = 0;
continue;
}
this->AddPointArray( src, bsinfop, output );
}
return status;
}
//-----------------------------------------------------------------------------
#if 0
// Copy tuples from one array to another, possibly with a different number of components per tuple.
static void vtkEmbedTuplesInLargerArray(
vtkDataSetAttributes* attr, vtkDataArray* dst, vtkDataArray* src, vtkIdType numTuples, vtkIdType offset )
{
vtkIdType i;
int srcNumComp = src->GetNumberOfComponents();
int dstNumComp = dst->GetNumberOfComponents();
if ( dstNumComp != srcNumComp )
{ // We've promoted the array from 2-D to 3-D... can't use CopyTuple
if ( dst->GetDataType() != src->GetDataType() )
{
return;
}
vtkIdType sid = 0;
vtkIdType did = offset * dstNumComp;
int minNumComp = dstNumComp < srcNumComp ? dstNumComp : srcNumComp;
switch( dst->GetDataType() )
{
vtkTemplateMacro(
{
VTK_TT* srcTuple = (VTK_TT*) src->GetVoidPointer( sid );
VTK_TT* dstTuple = (VTK_TT*) dst->GetVoidPointer( did );
for ( i = 0; i < numTuples; ++i, srcTuple += srcNumComp, dstTuple += dstNumComp )
{
for ( int j = 0; j < minNumComp; ++j )
{
dstTuple[j] = srcTuple[j];
}
}
}
);
}
}
else
{
for ( i = 0; i < numTuples; ++i )
{
attr->CopyTuple( src, dst, i, i + offset );
}
}
}
#endif // 0
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::AssembleOutputCellArrays(
vtkIdType timeStep, int otyp, int obj, BlockSetInfoType* bsinfop,
vtkUnstructuredGrid* output )
{
// Don't create arrays for deselected objects
if ( !output || ! bsinfop->Status )
{
return 1;
}
// Panic if we're given a bad otyp.
std::map<int,std::vector<ArrayInfoType> >::iterator ami = this->ArrayInfo.find( otyp );
if ( ami == this->ArrayInfo.end() )
{
#if 0
vtkErrorMacro( "Unknown block or set type \"" << otyp << "\" encountered." );
for ( ami = this->ArrayInfo.begin(); ami != this->ArrayInfo.end(); ++ ami )
{
cerr << " Have type: \"" << ami->first << "\"\n";
}
return 0;
#else
return 1;
#endif // 0
}
vtkCellData* cd = output->GetCellData();
// For each array defined on objects of the same type as our output,
// look for ones that are turned on (Status != 0) and have a truth
// table indicating values are present for object obj in the file.
std::vector<ArrayInfoType>::iterator ai;
int aidx = 0;
for ( ai = ami->second.begin(); ai != ami->second.end(); ++ai, ++aidx )
{
if ( ! ai->Status )
continue;
if ( ! ai->ObjectTruth[obj] )
continue;
vtkDataArray* arr = this->GetCacheOrRead( vtkExodusIICacheKey( timeStep, ami->first, obj, aidx ) );
if ( arr )
{
cd->AddArray( arr );
}
}
return 1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::AssembleOutputProceduralArrays(
vtkIdType timeStep, int otyp, int obj,
vtkUnstructuredGrid* output )
{
(void)timeStep;
int status = 7;
vtkCellData* cd = output->GetCellData();
if ( this->GenerateObjectIdArray )
{
vtkExodusIICacheKey key( -1, vtkExodusIIReader::OBJECT_ID, otyp, obj );
vtkDataArray* arr = this->GetCacheOrRead( key );
if ( arr )
{
cd->AddArray( arr );
status -= 1;
}
}
if ( this->GenerateGlobalElementIdArray && ! OBJTYPE_IS_SET( otyp ) )
{
// This retrieves the first new-style map, or if that is not present,
// the solitary old-style map (which always exists but may be
// procedurally generated if it is not stored with the file).
vtkExodusIICacheKey key( -1, vtkExodusIIReader::GLOBAL_ELEMENT_ID, otyp, obj );
vtkDataArray* arr = this->GetCacheOrRead( key );
if ( arr )
{
vtkDataArray* ped = vtkIdTypeArray::New();
ped->DeepCopy( arr );
ped->SetName( vtkExodusIIReader::GetPedigreeElementIdArrayName() );
cd->SetGlobalIds( arr );
cd->SetPedigreeIds( ped );
ped->FastDelete();
status -= 2;
}
}
if ( this->GenerateGlobalNodeIdArray )
{
// This retrieves the first new-style map, or if that is not present,
// the solitary old-style map (which always exists but may be
// procedurally generated if it is not stored with the file).
vtkExodusIICacheKey key( -1, vtkExodusIIReader::GLOBAL_NODE_ID, otyp, obj );
vtkDataArray* arr = this->GetCacheOrRead( key );
vtkPointData* pd = output->GetPointData();
if ( arr )
{
vtkDataArray* ped = vtkIdTypeArray::New();
ped->DeepCopy( arr );
ped->SetName( vtkExodusIIReader::GetPedigreeNodeIdArrayName() );
pd->SetGlobalIds( arr );
pd->SetPedigreeIds( ped );
ped->FastDelete();
status -= 4;
}
}
if ( this->GenerateImplicitElementIdArray )
{
// This retrieves the old style map if it is a parallel data set. The old
// style map stores the global implicit id if parallel. Otherwise it
// generates the implicit id.
vtkExodusIICacheKey key( -1, vtkExodusIIReader::IMPLICIT_ELEMENT_ID, otyp, obj );
vtkDataArray* arr = this->GetCacheOrRead( key );
if ( arr )
{
cd->AddArray( arr );
}
}
if ( this->GenerateImplicitNodeIdArray )
{
// This retrieves the old style map if it is a parallel data set. The old
// style map stores the global implicit id if parallel. Otherwise it
// generates the implicit id.
vtkExodusIICacheKey key( -1, vtkExodusIIReader::IMPLICIT_NODE_ID, otyp, obj );
vtkDataArray* arr = this->GetCacheOrRead( key );
vtkPointData* pd = output->GetPointData();
if ( arr )
{
pd->AddArray( arr );
}
}
if ( this->GenerateFileIdArray )
{ // Don't cache this... it's not worth it.
vtkIdType numCells = output->GetNumberOfCells();
vtkIntArray* iarr = vtkIntArray::New();
iarr->SetNumberOfComponents( 1 );
iarr->SetNumberOfTuples( numCells );
iarr->SetName( this->GetFileIdArrayName() );
cd->AddArray( iarr );
iarr->FastDelete();
for ( vtkIdType i = 0; i < numCells; ++ i )
{
iarr->SetValue( i, this->FileId );
}
}
return status;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::AssembleOutputGlobalArrays(
vtkIdType vtkNotUsed(timeStep), int otyp, int obj, BlockSetInfoType* bsinfop,
vtkUnstructuredGrid* output )
{
(void)obj;
vtkFieldData *ofieldData = output->GetFieldData();
int status = 1;
std::vector<ArrayInfoType>::iterator ai;
int aidx = 0;
for (
ai = this->ArrayInfo[ vtkExodusIIReader::GLOBAL ].begin();
ai != this->ArrayInfo[ vtkExodusIIReader::GLOBAL ].end();
++ai, ++aidx )
{
if ( ! ai->Status )
{
continue;
}
// Add time-varying global data
vtkExodusIICacheKey tdKey( -1, vtkExodusIIReader::GLOBAL_TEMPORAL, -1, aidx );
vtkDataArray* temporalData = this->GetCacheOrRead( tdKey );
if ( ! temporalData )
{
vtkDebugMacro( "Unable to read array " << ai->Name.c_str() );
status = 0;
continue;
}
ofieldData->AddArray(temporalData);
}
// Add block id information for the exodus writer (if we're an element block)
if ( otyp == vtkExodusIIReader::ELEM_BLOCK )
{
vtkIntArray *elemBlockIdArray = vtkIntArray::New();
elemBlockIdArray->SetNumberOfComponents( 1 );
elemBlockIdArray->SetNumberOfValues( 1 ); // one elem block per unstructured grid
elemBlockIdArray->SetName( "ElementBlockIds" );
elemBlockIdArray->SetValue( 0, bsinfop->Id );
ofieldData->AddArray( elemBlockIdArray );
elemBlockIdArray->Delete();
}
// Add QA record and INFO record metadata from the Exodus II file
vtkExodusIICacheKey qakey( -1, vtkExodusIIReader::QA_RECORDS, 0, 0 );
vtkDataArray* arr = this->GetCacheOrRead( qakey );
if ( arr )
{
ofieldData->AddArray(arr);
}
vtkExodusIICacheKey infokey( -1, vtkExodusIIReader::INFO_RECORDS, 0, 0 );
arr = this->GetCacheOrRead( infokey );
if ( arr )
{
ofieldData->AddArray(arr);
}
return status;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::AssembleOutputPointMaps( vtkIdType timeStep,
BlockSetInfoType* bsinfop, vtkUnstructuredGrid* output )
{
(void)timeStep;
int status = 1;
std::vector<MapInfoType>::iterator mi;
int midx = 0;
for (
mi = this->MapInfo[ vtkExodusIIReader::NODE_MAP ].begin();
mi != this->MapInfo[ vtkExodusIIReader::NODE_MAP ].end();
++mi, ++midx )
{
if ( ! mi->Status )
continue; // Skip arrays we don't want.
vtkIdTypeArray* src = vtkIdTypeArray::SafeDownCast( this->GetCacheOrRead(
vtkExodusIICacheKey( -1, vtkExodusIIReader::NODE_MAP, 0, midx ) ) );
if ( !src )
{
vtkDebugMacro(
"Unable to read point map array \""
<< mi->Name.c_str() << "\" (" << midx << ")" );
status = 0;
continue;
}
this->AddPointArray( src, bsinfop, output );
}
return status;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::AssembleOutputCellMaps(
vtkIdType vtkNotUsed(timeStep), int otyp, int obj, BlockSetInfoType* bsinfop,
vtkUnstructuredGrid* output )
{
(void)obj;
// Don't create arrays for deselected objects
if ( ! output || ! bsinfop->Status )
{
return 1;
}
// Ignore invalid otyp values (sets cannot have maps, only blocks).
int mtyp = this->GetMapTypeFromObjectType( otyp );
std::map<int,std::vector<MapInfoType> >::iterator mmi =
this->MapInfo.find( mtyp );
if ( mmi == this->MapInfo.end() )
{
return 1;
}
vtkCellData* cd = output->GetCellData();
// For each map defined on objects of the same type as our output,
// look for ones that are turned on (Status != 0).
std::vector<MapInfoType>::iterator mi;
int midx = 0;
for ( mi = mmi->second.begin(); mi != mmi->second.end(); ++mi, ++midx )
{
if ( ! mi->Status )
continue;
vtkDataArray* src = this->GetCacheOrRead(
vtkExodusIICacheKey( -1, mmi->first, 0, midx ) );
if ( ! src )
continue;
if ( otyp == vtkExodusIIReader::ELEM_BLOCK )
{
if (
bsinfop->Size == src->GetNumberOfTuples() &&
bsinfop->FileOffset == 1 &&
this->BlockInfo[otyp].size() == 1 )
{
cd->AddArray( src );
}
else
{
// Create the array and copy the applicable subset from the map
vtkIdTypeArray* arr = vtkIdTypeArray::New();
arr->SetName( mi->Name.c_str() );
arr->SetNumberOfComponents( 1 );
arr->SetNumberOfTuples( bsinfop->Size );
memcpy( arr->GetVoidPointer(0), src->GetVoidPointer( bsinfop->FileOffset - 1 ),
bsinfop->Size * sizeof(vtkIdType) );
cd->AddArray( arr );
arr->FastDelete();
}
}
else
{
// FIXME: We have a set (no maps are defined on sets but we could determine
// map values given the set generators) or an edge/face block (unclear
// whether maps are useful/possible on these block types).
}
}
return 1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::AssembleArraysOverTime(vtkMultiBlockDataSet* output )
{
if ( this->FastPathObjectId < 0 )
{
// No downstream filter has requested temporal data from this reader.
return 0;
}
std::vector<ArrayInfoType>::iterator ai;
vtkFieldData* ofd = output->GetFieldData();
vtkIdType internalExodusId = -1;
int status = 1;
int aidx = 0;
int objId = -1;
// We need to get the internal id used by the exodus file from either the
// VTK index, or from the global id
if (strcmp( this->FastPathIdType, "GLOBAL" ) == 0)
{
vtkExodusIICacheKey globalIdMapKey;
switch ( this->FastPathObjectType )
{
case vtkExodusIIReader::NODAL:
globalIdMapKey =
vtkExodusIICacheKey( -1, vtkExodusIIReader::NODE_ID, 0, 0 );
break;
case vtkExodusIIReader::ELEM_BLOCK:
globalIdMapKey =
vtkExodusIICacheKey( -1, vtkExodusIIReader::ELEMENT_ID, 0, 0 );
break;
default:
vtkDebugMacro( "Unsupported object type for fast path." );
return 0;
}
vtkIdTypeArray* globalIdMap = vtkIdTypeArray::SafeDownCast(
this->GetCacheOrRead( globalIdMapKey ) );
if (!globalIdMap)
{
return 0;
}
vtkIdType index = globalIdMap->LookupValue(this->FastPathObjectId);
if (index >= 0)
{
internalExodusId = index + 1;
}
}
// This will happen if the data does not reside in this file
if (internalExodusId < 0)
{
//vtkDebugMacro( "Unable to map id to internal exodus id." );
return 0;
}
for (ai = this->ArrayInfo[this->FastPathObjectType].begin();
ai != this->ArrayInfo[this->FastPathObjectType].end(); ++ai, ++aidx)
{
if (! ai->Status)
{
continue; // Skip arrays we don't want.
}
// If this array isn't defined over the block that the element resides in,
// skip. Right now this is only done when the fast-path id type is "INDEX".
if ( objId >= 0 &&
this->FastPathObjectType == vtkExodusIIReader::ELEM_BLOCK &&
! strcmp( this->FastPathIdType, "INDEX" ) )
{
if ( ! ai->ObjectTruth[objId] )
{
continue;
}
}
vtkExodusIICacheKey temporalDataKey(
-1, this->GetTemporalTypeFromObjectType( this->FastPathObjectType ),
internalExodusId, aidx );
vtkDataArray* temporalData = this->GetCacheOrRead( temporalDataKey );
if ( !temporalData )
{
vtkDebugMacro( "Unable to read array " << ai->Name.c_str() );
status = 0;
continue;
}
ofd->AddArray(temporalData);
}
return status;
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::InsertBlockCells(
int otyp, int obj, int conn_type, int timeStep, BlockInfoType* binfo )
{
(void)timeStep;
(void)otyp;
if ( binfo->Size == 0 )
{
// No entries in this block.
// This happens in parallel filesets when all elements are distributed to other files.
// Silently ignore.
return;
}
vtkIntArray* ent = 0;
if ( binfo->PointsPerCell == 0 )
{
int arrId;
if (conn_type == vtkExodusIIReader::ELEM_BLOCK_ELEM_CONN)
{
arrId = 0;
}
else
{
arrId = 1;
}
ent = vtkIntArray::SafeDownCast(
this->GetCacheOrRead( vtkExodusIICacheKey( -1, vtkExodusIIReader::ENTITY_COUNTS, obj, arrId ) ) );
if ( ! ent )
{
vtkErrorMacro( "Entity used 0 points per cell, but didn't return poly_hedra correctly" );
binfo->Status = 0;
return;
}
ent->Register (this);
}
vtkIntArray* arr;
arr = vtkIntArray::SafeDownCast( this->GetCacheOrRead( vtkExodusIICacheKey( -1, conn_type, obj, 0 ) ) );
if ( ! arr )
{
vtkWarningMacro( "Block wasn't present in file? Working around it. Expect trouble." );
binfo->Status = 0;
return;
}
if ( this->SqueezePoints )
{
std::vector<vtkIdType> cellIds;
cellIds.resize( binfo->PointsPerCell );
int* srcIds = arr->GetPointer( 0 );
for ( int i = 0; i < binfo->Size; ++i )
{
int entitiesPerCell;
if ( ent != 0)
{
entitiesPerCell = ent->GetValue (i);
cellIds.resize( entitiesPerCell );
}
else
{
entitiesPerCell = binfo->PointsPerCell;
}
for ( int p = 0; p < entitiesPerCell; ++p )
{
cellIds[p] = this->GetSqueezePointId( binfo, srcIds[p] );
//cout << " " << srcIds[p] << "(" << cellIds[p] << ")";
}
//cout << "\n";
//cout << " " <<
binfo->CachedConnectivity->InsertNextCell( binfo->CellType, entitiesPerCell, &cellIds[0] );
srcIds += entitiesPerCell;
}
//cout << "\n";
}
else
{
#ifdef VTK_USE_64BIT_IDS
std::vector<vtkIdType> cellIds;
cellIds.resize( binfo->PointsPerCell );
int* srcIds = arr->GetPointer( 0 );
for ( int i = 0; i < binfo->Size; ++i )
{
int entitiesPerCell = binfo->PointsPerCell;
if ( ent != 0)
{
entitiesPerCell = ent->GetValue (i);
cellIds.resize( entitiesPerCell );
}
for ( int p = 0; p < entitiesPerCell; ++p )
{
cellIds[p] = srcIds[p];
//cout << " " << srcIds[p];
}
//cout << "\n";
binfo->CachedConnectivity->InsertNextCell( binfo->CellType, entitiesPerCell, &cellIds[0] );
srcIds += entitiesPerCell;
}
#else // VTK_USE_64BIT_IDS
vtkIdType* srcIds = (vtkIdType*) arr->GetPointer( 0 );
for ( int i = 0; i < binfo->Size; ++i )
{
int entitiesPerCell = binfo->PointsPerCell;
if ( ent != 0)
{
entitiesPerCell = ent->GetValue (i);
}
binfo->CachedConnectivity->InsertNextCell( binfo->CellType, entitiesPerCell, srcIds );
srcIds += entitiesPerCell;
//for ( int k = 0; k < binfo->PointsPerCell; ++k )
//cout << " " << srcIds[k];
//cout << "\n";
}
#endif // VTK_USE_64BIT_IDS
}
if (ent)
{
ent->UnRegister (this);
}
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::InsertSetCells(
int otyp, int obj, int conn_type, int timeStep,
SetInfoType* sinfo )
{
(void)timeStep;
if ( sinfo->Size == 0 )
{
// No entries in this set.
// This happens in parallel filesets when all elements are distributed to other files.
// Silently ignore.
return;
}
vtkIntArray* arr = vtkIntArray::SafeDownCast(
this->GetCacheOrRead( vtkExodusIICacheKey( -1, conn_type, obj, 0 ) ) );
if ( ! arr )
{
vtkWarningMacro( "Set wasn't present in file? Working around it. Expect trouble." );
sinfo->Status = 0;
return;
}
switch ( otyp )
{
case vtkExodusIIReader::NODE_SET:
// Easy
this->InsertSetNodeCopies( arr, otyp, obj, sinfo );
break;
case vtkExodusIIReader::EDGE_SET:
// Not so fun. We must copy cells from possibly many edge blocks.
this->InsertSetCellCopies( arr, vtkExodusIIReader::EDGE_BLOCK, obj, sinfo );
break;
case vtkExodusIIReader::FACE_SET:
// Not so fun. We must copy cells from possibly many face blocks.
this->InsertSetCellCopies( arr, vtkExodusIIReader::FACE_BLOCK, obj, sinfo );
break;
case vtkExodusIIReader::SIDE_SET:
// Way hard even when we let Exodus do a lot for us.
this->InsertSetSides( arr, otyp, obj, sinfo );
break;
case vtkExodusIIReader::ELEM_SET:
// Not so fun. We must copy cells from possibly many element blocks.
this->InsertSetCellCopies( arr, vtkExodusIIReader::ELEM_BLOCK, obj, sinfo );
break;
}
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::AddPointArray(
vtkDataArray* src, BlockSetInfoType* bsinfop, vtkUnstructuredGrid* output )
{
vtkPointData* pd = output->GetPointData();
if ( this->SqueezePoints )
{
// subset the array using PointMap
vtkDataArray* dest = vtkDataArray::CreateDataArray( src->GetDataType() );
dest->SetName( src->GetName() );
dest->SetNumberOfComponents( src->GetNumberOfComponents() );
dest->SetNumberOfTuples( bsinfop->NextSqueezePoint );
std::map<vtkIdType,vtkIdType>::iterator it;
for ( it = bsinfop->PointMap.begin(); it != bsinfop->PointMap.end(); ++ it )
{
pd->CopyTuple( src, dest, it->first, it->second );
}
pd->AddArray( dest );
dest->FastDelete();
}
else
{
pd->AddArray( src );
}
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::InsertSetNodeCopies( vtkIntArray* refs, int otyp, int obj, SetInfoType* sinfo )
{
(void)otyp;
(void)obj;
// Insert a "VERTEX" cell for each node in the set.
vtkIdType ref;
vtkIdType tmp;
int* iptr = refs->GetPointer( 0 );
if ( this->SqueezePoints )
{ // this loop is separated out to handle case (stride > 1 && pref[1] < 0 && this->SqueezePoints)
for ( ref = 0; ref < refs->GetNumberOfTuples(); ++ref, ++iptr )
{
tmp = *iptr;
vtkIdType x = this->GetSqueezePointId( sinfo, tmp );
sinfo->CachedConnectivity->InsertNextCell( VTK_VERTEX, 1, &x );
}
}
else
{
for ( ref = 0; ref < refs->GetNumberOfTuples(); ++ref, ++iptr )
{
tmp = *iptr;
sinfo->CachedConnectivity->InsertNextCell( VTK_VERTEX, 1, &tmp );
}
}
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::InsertSetCellCopies(
vtkIntArray* refs, int otyp, int obj, SetInfoType* sinfo )
{
(void)obj;
// First, sort the set by entry number (element, face, or edge ID)
// so that we can refer to each block just once as we process cells.
vtkSortDataArray::SortArrayByComponent( refs, 0 );
refs->Register( this ); // Don't let the cache delete this array when we fetch others...
vtkIdType nrefs = refs->GetNumberOfTuples();
vtkIdType ref = 0;
vtkIdType bnum = -1;
vtkIdType lastBlockEntry = -1;
int* pref = refs->GetPointer( 0 );
int stride = refs->GetNumberOfComponents();
BlockInfoType* binfop = 0; //&this->BlockInfo[otyp][bnum];
int* nodeconn = 0;
vtkIdType* cellConn;
int nnpe = 0;
vtkIntArray* nconn;
std::vector<vtkIdType> tmpTuple;
while ( ref < nrefs )
{
int loadNewBlk = 0;
while ( pref[0] >= lastBlockEntry )
{ // advance to the next block (always true first time through parent loop)
++bnum;
if ( bnum >= (int) this->BlockInfo[otyp].size() )
return;
binfop = &this->BlockInfo[otyp][bnum];
lastBlockEntry = binfop->FileOffset + binfop->Size - 1;
loadNewBlk = 1;
}
if ( loadNewBlk )
{
nconn = vtkIntArray::SafeDownCast(
this->GetCacheOrRead( vtkExodusIICacheKey( -1, this->GetBlockConnTypeFromBlockType( otyp ), bnum, 0 ) )
);
if ( ! nconn )
{
vtkErrorMacro( "Unable to read block \"" << binfop->Name.c_str() << "\" (" << binfop->Id << ")" );
break;
}
nodeconn = nconn->GetPointer( 0 );
nnpe = nconn->GetNumberOfComponents();
if ( stride > 1 || this->SqueezePoints )
{
tmpTuple.resize( nnpe );
}
}
if ( stride > 1 && pref[1] < 0 )
{ // negative orientation => reverse cell connectivity
vtkIdType off = (pref[0] + 2 - binfop->FileOffset) * nnpe - 1;
for ( int k = 0; k < nnpe; ++k )
tmpTuple[k] = nodeconn[off-k];
cellConn = &tmpTuple[0];
}
else
#ifndef VTK_USE_64BIT_IDS
if ( this->SqueezePoints )
#endif // VTK_USE_64BIT_IDS
{
vtkIdType off = (pref[0] + 1 - binfop->FileOffset) * nnpe;
for ( int k = 0; k < nnpe; ++k )
tmpTuple[k] = nodeconn[off+k];
cellConn = &tmpTuple[0];
}
#ifndef VTK_USE_64BIT_IDS
else
{
cellConn = (int*)nodeconn + (pref[0] + 1 - binfop->FileOffset) * nnpe;
}
#endif // VTK_USE_64BIT_IDS
if ( this->SqueezePoints )
{ // this loop is separated out to handle case (stride > 1 && pref[1] < 0 && this->SqueezePoints)
for ( int k = 0; k < nnpe; ++k )
{ // FIXME: Double-check that cellConn[k] should be in-place re-assigned.
cellConn[k] = this->GetSqueezePointId( sinfo, cellConn[k] );
}
}
sinfo->CachedConnectivity->InsertNextCell( binfop->CellType, nnpe, cellConn );
pref += stride;
++ref;
}
refs->UnRegister( this );
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::InsertSetSides(
vtkIntArray* refs, int otyp, int obj, SetInfoType* sinfo )
{
static const int sideCellTypes[] =
{
VTK_EMPTY_CELL, // don't support any cells with 0 nodes per side
VTK_VERTEX,
VTK_LINE,
VTK_TRIANGLE,
VTK_QUAD,
VTK_EMPTY_CELL, // don't support any cells with 5 nodes per side
VTK_QUADRATIC_TRIANGLE,
VTK_EMPTY_CELL, // don't support any cells with 7 nodes per side
VTK_QUADRATIC_QUAD,
VTK_BIQUADRATIC_QUAD
};
int numSides = this->SetInfo[otyp][obj].Size;
int* nodesPerSide = refs->GetPointer( 0 );
int* sideNodes = nodesPerSide + numSides;
std::vector<vtkIdType> cellConn;
cellConn.resize( 9 );
if ( this->SqueezePoints )
{
int nnpe;
for ( int side = 0; side < numSides; ++side )
{
nnpe = nodesPerSide[side];
for ( int k = 0; k < nnpe; ++k )
{
cellConn[k] = this->GetSqueezePointId( sinfo, sideNodes[k] );
}
sinfo->CachedConnectivity->InsertNextCell( sideCellTypes[nnpe], nnpe, &cellConn[0] );
sideNodes += nnpe;
}
}
else
{
int nnpe;
for ( int side = 0; side < numSides; ++side )
{
nnpe = nodesPerSide[side];
#ifdef VTK_USE_64BIT_IDS
for ( int k = 0; k < nnpe; ++k )
{
cellConn[k] = sideNodes[k];
}
sinfo->CachedConnectivity->InsertNextCell( sideCellTypes[nnpe], nnpe, &cellConn[0] );
#else // VTK_USE_64BIT_IDS
sinfo->CachedConnectivity->InsertNextCell( sideCellTypes[nnpe], nnpe, sideNodes );
#endif // VTK_USE_64BIT_IDS
sideNodes += nnpe;
}
}
}
//-----------------------------------------------------------------------------
vtkDataArray* vtkExodusIIReaderPrivate::GetCacheOrRead( vtkExodusIICacheKey key )
{
vtkDataArray* arr;
// Never cache points deflected for a mode shape animation... doubles don't make good keys.
if ( this->HasModeShapes && key.ObjectType == vtkExodusIIReader::NODAL_COORDS )
{
arr = 0;
}
else
{
arr = this->Cache->Find( key );
}
if ( arr )
{
//
return arr;
}
int exoid = this->Exoid;
// If array is NULL, try reading it from file.
if ( key.ObjectType == vtkExodusIIReader::GLOBAL )
{
// need to assemble result array from smaller ones.
// call GetCacheOrRead() for each smaller array
// pay attention to SqueezePoints
//ArrayInfoType* ainfop = &this->ArrayInfo[vtkExodusIIReader::GLOBAL][key.ArrayId];
arr = vtkDataArray::CreateDataArray( VTK_DOUBLE );
arr->SetName( this->GetGlobalVariableValuesArrayName() );
arr->SetNumberOfComponents( 1 );
arr->SetNumberOfTuples( this->ArrayInfo[ vtkExodusIIReader::GLOBAL ].size() );
if ( ex_get_glob_vars( exoid, key.Time + 1, arr->GetNumberOfTuples(),
arr->GetVoidPointer( 0 ) ) < 0 )
{
vtkErrorMacro( "Could not read global variable " << this->GetGlobalVariableValuesArrayName() << "." );
arr->Delete();
arr = 0;
}
}
else if ( key.ObjectType == vtkExodusIIReader::NODAL )
{
// read nodal array
ArrayInfoType* ainfop = &this->ArrayInfo[vtkExodusIIReader::NODAL][key.ArrayId];
int ncomps = ( this->ModelParameters.num_dim == 2 && ainfop->Components == 2 ) ? 3 : ainfop->Components;
arr = vtkDataArray::CreateDataArray( ainfop->StorageType );
arr->SetName( ainfop->Name.c_str() );
arr->SetNumberOfComponents( ncomps );
arr->SetNumberOfTuples( this->ModelParameters.num_nodes );
if ( ncomps != ainfop->Components )
{
arr->FillComponent( 2, 0. );
}
if ( ncomps == 1 )
{
if ( ex_get_var( exoid, key.Time + 1, static_cast<ex_entity_type>( key.ObjectType ),
ainfop->OriginalIndices[0], 0, arr->GetNumberOfTuples(),
arr->GetVoidPointer( 0 ) ) < 0 )
{
vtkErrorMacro( "Could not read nodal result variable " << ainfop->Name.c_str() << "." );
arr->Delete();
arr = 0;
}
}
else
{
// Exodus doesn't support reading with a stride, so we have to manually interleave the arrays. Bleh.
std::vector<std::vector<double> > tmpVal;
tmpVal.resize( ainfop->Components );
int c;
for ( c = 0; c < ainfop->Components; ++c )
{
vtkIdType N = this->ModelParameters.num_nodes;
tmpVal[c].resize( N );
if ( ex_get_var( exoid, key.Time + 1, static_cast<ex_entity_type>( key.ObjectType ),
ainfop->OriginalIndices[c], 0, arr->GetNumberOfTuples(),
&tmpVal[c][0] ) < 0)
{
vtkErrorMacro( "Could not read nodal result variable " << ainfop->OriginalNames[c].c_str() << "." );
arr->Delete();
arr = 0;
return 0;
}
}
int t;
std::vector<double> tmpTuple;
tmpTuple.resize( ncomps );
tmpTuple[ncomps - 1] = 0.; // In case we're embedding a 2-D vector in 3-D
for ( t = 0; t < arr->GetNumberOfTuples(); ++t )
{
for ( c = 0; c < ainfop->Components; ++c )
{
tmpTuple[c] = tmpVal[c][t];
}
arr->SetTuple( t, &tmpTuple[0] );
}
}
}
else if ( key.ObjectType == vtkExodusIIReader::GLOBAL_TEMPORAL )
{
// read temporal nodal array
ArrayInfoType* ainfop = &this->ArrayInfo[vtkExodusIIReader::GLOBAL][key.ArrayId];
arr = vtkDataArray::CreateDataArray( ainfop->StorageType );
//vtkStdString newArrayName = ainfop->Name + "OverTime";
arr->SetName( ainfop->Name );
arr->SetNumberOfComponents( ainfop->Components );
arr->SetNumberOfTuples( this->GetNumberOfTimeSteps() );
if ( ainfop->Components != 1 )
{
// Exodus doesn't support reading with a stride, so we have to manually interleave the arrays. Bleh.
std::vector<std::vector<double> > tmpVal;
tmpVal.resize( ainfop->Components );
int c;
for ( c = 0; c < ainfop->Components; ++c )
{
vtkIdType N = this->GetNumberOfTimeSteps();
tmpVal[c].resize( N );
if ( ex_get_var_time( exoid, EX_GLOBAL,
ainfop->OriginalIndices[c], key.ObjectId,
1, this->GetNumberOfTimeSteps(), &tmpVal[c][0] ) < 0 )
{
vtkErrorMacro(
"Could not read temporal global result variable "
<< ainfop->OriginalNames[c].c_str() << "." );
arr->Delete();
arr = 0;
return 0;
}
}
int t;
std::vector<double> tmpTuple;
tmpTuple.resize( ainfop->Components );
for ( t = 0; t < arr->GetNumberOfTuples(); ++t )
{
for ( c = 0; c < ainfop->Components; ++c )
{
tmpTuple[c] = tmpVal[c][t];
}
arr->SetTuple( t, &tmpTuple[0] );
}
}
else if ( ex_get_var_time( exoid, EX_GLOBAL,
ainfop->OriginalIndices[0], key.ObjectId,
1, this->GetNumberOfTimeSteps(), arr->GetVoidPointer( 0 ) ) < 0 )
{
vtkErrorMacro(
"Could not read global result variable "
<< ainfop->Name.c_str() << "." );
arr->Delete();
arr = 0;
}
}
else if ( key.ObjectType == vtkExodusIIReader::NODAL_TEMPORAL )
{
// read temporal nodal array
ArrayInfoType* ainfop = &this->ArrayInfo[vtkExodusIIReader::NODAL][key.ArrayId];
arr = vtkDataArray::CreateDataArray( ainfop->StorageType );
vtkStdString newArrayName = ainfop->Name + "OverTime";
arr->SetName( newArrayName.c_str() );
arr->SetNumberOfComponents( ainfop->Components );
arr->SetNumberOfTuples( this->GetNumberOfTimeSteps() );
if ( ainfop->Components == 1 )
{
if ( ex_get_var_time( exoid, EX_NODAL,
ainfop->OriginalIndices[0], key.ObjectId,
1, this->GetNumberOfTimeSteps(), arr->GetVoidPointer( 0 ) ) < 0 )
{
vtkErrorMacro( "Could not read nodal result variable " << ainfop->Name.c_str() << "." );
arr->Delete();
arr = 0;
}
}
else
{
// Exodus doesn't support reading with a stride, so we have to manually interleave the arrays. Bleh.
std::vector<std::vector<double> > tmpVal;
tmpVal.resize( ainfop->Components );
int c;
for ( c = 0; c < ainfop->Components; ++c )
{
vtkIdType N = this->GetNumberOfTimeSteps();
tmpVal[c].resize( N );
if ( ex_get_var_time( exoid, EX_NODAL,
ainfop->OriginalIndices[c], key.ObjectId,
1, this->GetNumberOfTimeSteps(), &tmpVal[c][0] ) < 0 )
{
vtkErrorMacro( "Could not read temporal nodal result variable " << ainfop->OriginalNames[c].c_str() << "." );
arr->Delete();
arr = 0;
return 0;
}
}
int t;
std::vector<double> tmpTuple;
tmpTuple.resize( ainfop->Components );
for ( t = 0; t < arr->GetNumberOfTuples(); ++t )
{
for ( c = 0; c < ainfop->Components; ++c )
{
tmpTuple[c] = tmpVal[c][t];
}
arr->SetTuple( t, &tmpTuple[0] );
}
}
}
else if ( key.ObjectType == vtkExodusIIReader::ELEM_BLOCK_TEMPORAL )
{
// read temporal element array
ArrayInfoType* ainfop = &this->ArrayInfo[vtkExodusIIReader::ELEM_BLOCK][key.ArrayId];
arr = vtkDataArray::CreateDataArray( ainfop->StorageType );
vtkStdString newArrayName = ainfop->Name + "OverTime";
arr->SetName( newArrayName.c_str() );
arr->SetNumberOfComponents( ainfop->Components );
arr->SetNumberOfTuples( this->GetNumberOfTimeSteps() );
if ( ainfop->Components == 1 )
{
if ( ex_get_var_time( exoid, EX_ELEM_BLOCK,
ainfop->OriginalIndices[0], key.ObjectId,
1, this->GetNumberOfTimeSteps(), arr->GetVoidPointer( 0 ) ) < 0 )
{
vtkErrorMacro( "Could not read element result variable " << ainfop->Name.c_str() << "." );
arr->Delete();
arr = 0;
}
}
else
{
// Exodus doesn't support reading with a stride, so we have to manually interleave the arrays. Bleh.
std::vector<std::vector<double> > tmpVal;
tmpVal.resize( ainfop->Components );
int c;
for ( c = 0; c < ainfop->Components; ++c )
{
vtkIdType N = this->GetNumberOfTimeSteps();
tmpVal[c].resize( N );
if ( ex_get_var_time( exoid, EX_ELEM_BLOCK,
ainfop->OriginalIndices[c], key.ObjectId,
1, this->GetNumberOfTimeSteps(), &tmpVal[c][0] ) < 0 )
{
vtkErrorMacro( "Could not read temporal element result variable " << ainfop->OriginalNames[c].c_str() << "." );
arr->Delete();
arr = 0;
return 0;
}
}
int t;
std::vector<double> tmpTuple;
tmpTuple.resize( ainfop->Components );
for ( t = 0; t < arr->GetNumberOfTuples(); ++t )
{
for ( c = 0; c < ainfop->Components; ++c )
{
tmpTuple[c] = tmpVal[c][t];
}
arr->SetTuple( t, &tmpTuple[0] );
}
}
}
else if (
key.ObjectType == vtkExodusIIReader::EDGE_BLOCK ||
key.ObjectType == vtkExodusIIReader::FACE_BLOCK ||
key.ObjectType == vtkExodusIIReader::ELEM_BLOCK ||
key.ObjectType == vtkExodusIIReader::NODE_SET ||
key.ObjectType == vtkExodusIIReader::EDGE_SET ||
key.ObjectType == vtkExodusIIReader::FACE_SET ||
key.ObjectType == vtkExodusIIReader::SIDE_SET ||
key.ObjectType == vtkExodusIIReader::ELEM_SET
)
{
int otypidx = this->GetObjectTypeIndexFromObjectType( key.ObjectType );
ArrayInfoType* ainfop = &this->ArrayInfo[key.ObjectType][key.ArrayId];
ObjectInfoType* oinfop = this->GetObjectInfo( otypidx, key.ObjectId );
arr = vtkDataArray::CreateDataArray( ainfop->StorageType );
arr->SetName( ainfop->Name.c_str() );
if ( ainfop->Components == 2 && this->ModelParameters.num_dim == 2 )
{
// Promote 2-component arrays to 3-component arrays when we have 2-D coordinates
arr->SetNumberOfComponents( 3 );
}
else
{
arr->SetNumberOfComponents( ainfop->Components );
}
arr->SetNumberOfTuples( oinfop->Size );
if ( ainfop->Components == 1 )
{
if ( ex_get_var( exoid, key.Time + 1, static_cast<ex_entity_type>( key.ObjectType ),
ainfop->OriginalIndices[0], oinfop->Id, arr->GetNumberOfTuples(),
arr->GetVoidPointer( 0 ) ) < 0)
{
vtkErrorMacro( "Could not read result variable " << ainfop->Name.c_str() <<
" for " << objtype_names[otypidx] << " " << oinfop->Id << "." );
arr->Delete();
arr = 0;
}
}
else
{
// Exodus doesn't support reading with a stride, so we have to manually interleave the arrays. Bleh.
std::vector<std::vector<double> > tmpVal;
tmpVal.resize( ainfop->Components );
int c;
for ( c = 0; c < ainfop->Components; ++c )
{
vtkIdType N = arr->GetNumberOfTuples();
tmpVal[c].resize( N+1 ); // + 1 to avoid errors when N == 0.
// BUG #8746.
if ( ex_get_var( exoid, key.Time + 1, static_cast<ex_entity_type>( key.ObjectType ),
ainfop->OriginalIndices[c], oinfop->Id, arr->GetNumberOfTuples(),
&tmpVal[c][0] ) < 0)
{
vtkErrorMacro( "Could not read result variable " << ainfop->OriginalNames[c].c_str() <<
" for " << objtype_names[otypidx] << " " << oinfop->Id << "." );
arr->Delete();
arr = 0;
}
}
// Carefully use arr->GetNumberOfComponents() when sizing
// output as we may have promoted 2-D arrays to 3-D.
int t = arr->GetNumberOfComponents();
std::vector<double> tmpTuple;
tmpTuple.resize( t );
tmpTuple[t - 1] = 0.;
for ( t = 0; t < arr->GetNumberOfTuples(); ++t )
{
for ( c = 0; c < ainfop->Components; ++c )
{
tmpTuple[c] = tmpVal[c][t];
}
arr->SetTuple( t, &tmpTuple[0] );
}
}
}
else if (
key.ObjectType == vtkExodusIIReader::NODE_MAP ||
key.ObjectType == vtkExodusIIReader::EDGE_MAP ||
key.ObjectType == vtkExodusIIReader::FACE_MAP ||
key.ObjectType == vtkExodusIIReader::ELEM_MAP
)
{
MapInfoType* minfop = &this->MapInfo[key.ObjectType][key.ArrayId];
vtkIdTypeArray* iarr = vtkIdTypeArray::New();
arr = iarr;
arr->SetName( minfop->Name.c_str() );
arr->SetNumberOfComponents( 1 );
switch ( key.ObjectType )
{
case vtkExodusIIReader::NODE_MAP:
arr->SetNumberOfTuples( this->ModelParameters.num_nodes );
break;
case vtkExodusIIReader::EDGE_MAP:
arr->SetNumberOfTuples( this->ModelParameters.num_edge );
break;
case vtkExodusIIReader::FACE_MAP:
arr->SetNumberOfTuples( this->ModelParameters.num_face );
break;
case vtkExodusIIReader::ELEM_MAP:
arr->SetNumberOfTuples( this->ModelParameters.num_elem );
break;
}
#ifdef VTK_USE_64BIT_IDS
{
std::vector<int> tmpMap( arr->GetNumberOfTuples() );
if ( ex_get_num_map( exoid, static_cast<ex_entity_type>( key.ObjectType ), minfop->Id, &tmpMap[0] ) < 0 )
{
vtkErrorMacro( "Could not read map \"" << minfop->Name.c_str() << "\" (" << minfop->Id << ") from disk." );
arr->Delete();
arr = 0;
return 0;
}
for ( vtkIdType i = 0; i < arr->GetNumberOfTuples(); ++i )
{
iarr->SetValue( i, tmpMap[i] );
}
}
#else
if ( ex_get_num_map( exoid, static_cast<ex_entity_type>( key.ObjectType ), minfop->Id, (int*)arr->GetVoidPointer( 0 ) ) < 0 )
{
vtkErrorMacro( "Could not read nodal map variable " << minfop->Name.c_str() << "." );
arr->Delete();
arr = 0;
}
#endif // VTK_USE_64BIT_IDS
}
else if ( key.ObjectType == vtkExodusIIReader::GLOBAL_ELEMENT_ID )
{
// Yes, the next 2 statements are an intentional misuse of key
// fields reserved for the ObjectId and ArrayId (since ObjectType
// is used to signal that we want IDs instead of a field value).
int otypidx = this->GetObjectTypeIndexFromObjectType( key.ObjectId );
int obj = key.ArrayId;
BlockSetInfoType* bsinfop = (BlockSetInfoType*) this->GetObjectInfo( otypidx, obj );
vtkExodusIICacheKey ckey( -1, -1, 0, 0 );
switch ( key.ObjectId )
{
case vtkExodusIIReader::EDGE_BLOCK:
ckey.ObjectType = vtkExodusIIReader::EDGE_ID;
break;
case vtkExodusIIReader::FACE_BLOCK:
ckey.ObjectType = vtkExodusIIReader::FACE_ID;
break;
case vtkExodusIIReader::ELEM_BLOCK:
default:
ckey.ObjectType = vtkExodusIIReader::ELEMENT_ID;
break;
}
vtkIdTypeArray* src = vtkIdTypeArray::SafeDownCast( this->GetCacheOrRead( ckey ) );
if ( ! src )
{
arr = 0;
return 0;
}
vtkIdTypeArray* iarr = vtkIdTypeArray::New();
iarr->SetName( vtkExodusIIReader::GetGlobalElementIdArrayName() );
iarr->SetNumberOfComponents( 1 );
iarr->SetNumberOfTuples( bsinfop->Size );
vtkIdType* gloIds = iarr->GetPointer( 0 );
vtkIdType* srcIds = src->GetPointer( bsinfop->FileOffset - 1 );
memcpy( gloIds, srcIds, sizeof(vtkIdType) * bsinfop->Size );
arr = iarr;
}
else if ( key.ObjectType == vtkExodusIIReader::IMPLICIT_ELEMENT_ID )
{
// Yes, the next 2 statements are an intentional misuse of key
// fields reserved for the ObjectId and ArrayId (since ObjectType
// is used to signal that we want IDs instead of a field value).
int otypidx = this->GetObjectTypeIndexFromObjectType( key.ObjectId );
int obj = key.ArrayId;
BlockSetInfoType* bsinfop = (BlockSetInfoType*) this->GetObjectInfo( otypidx, obj );
vtkExodusIICacheKey ckey( -1, -1, 0, 0 );
vtkIdType mapSize;
int nMaps;
switch ( key.ObjectId )
{
case vtkExodusIIReader::EDGE_BLOCK:
ckey.ObjectType = vtkExodusIIReader::EDGE_ID;
mapSize = this->ModelParameters.num_edge;
nMaps = this->ModelParameters.num_edge_maps;
break;
case vtkExodusIIReader::FACE_BLOCK:
ckey.ObjectType = vtkExodusIIReader::FACE_ID;
mapSize = this->ModelParameters.num_face;
nMaps = this->ModelParameters.num_face_maps;
break;
case vtkExodusIIReader::ELEM_BLOCK:
default:
ckey.ObjectType = vtkExodusIIReader::ELEMENT_ID;
mapSize = this->ModelParameters.num_elem;
nMaps = this->ModelParameters.num_elem_maps;
break;
}
vtkIdTypeArray* src = vtkIdTypeArray::New ();
src->SetNumberOfComponents( 1 );
src->SetNumberOfTuples( mapSize );
if (nMaps > 0) // FIXME correctly detect parallel
{
#ifdef VTK_USE_64BIT_IDS
std::vector<int> tmpMap( src->GetNumberOfTuples() );
if ( ex_get_id_map( exoid, static_cast<ex_entity_type>( ckey.ObjectType ), &tmpMap[0] ) < 0 )
{
vtkErrorMacro( "Could not read elem num map for global implicit id" );
src->Delete();
return 0;
}
else
{
for ( vtkIdType i = 0; i < src->GetNumberOfTuples(); ++i )
{
src->SetValue( i, tmpMap[i] );
}
}
#else
if ( ex_get_id_map( exoid, static_cast<ex_entity_type>( ckey.ObjectType ), (int*)src->GetPointer( 0 ) ) < 0 )
{
vtkErrorMacro( "Could not read elem num map for global implicit id" );
src->Delete();
return 0;
}
#endif // VTK_USE_64BIT_IDS
}
else // single file, just make the implicit index explicit
{
for (vtkIdType i = 0; i < src->GetNumberOfTuples (); i ++)
{
src->SetValue (i, i + 1);
}
}
vtkIdTypeArray* iarr = vtkIdTypeArray::New();
iarr->SetName( vtkExodusIIReader::GetImplicitElementIdArrayName() );
iarr->SetNumberOfComponents( 1 );
iarr->SetNumberOfTuples( bsinfop->Size );
vtkIdType* gloIds = iarr->GetPointer( 0 );
vtkIdType* srcIds = src->GetPointer( bsinfop->FileOffset - 1 );
memcpy( gloIds, srcIds, sizeof(vtkIdType) * bsinfop->Size );
arr = iarr;
src->Delete ();
}
else if ( key.ObjectType == vtkExodusIIReader::GLOBAL_NODE_ID )
{ // subset the NODE_ID array choosing only entries for nodes in output grid (using PointMap)
// Yes, the next 2 statements are an intentional misuse of key
// fields reserved for the ObjectId and ArrayId (since ObjectType
// is used to signal that we want IDs instead of a field value).
int otypidx = this->GetObjectTypeIndexFromObjectType( key.ObjectId );
int obj = key.ArrayId;
BlockSetInfoType* bsinfop = (BlockSetInfoType*) this->GetObjectInfo( otypidx, obj );
vtkIdTypeArray* src = vtkIdTypeArray::SafeDownCast(
this->GetCacheOrRead( vtkExodusIICacheKey( -1, vtkExodusIIReader::NODE_ID, 0, 0 ) ) );
if ( this->SqueezePoints && src )
{
vtkIdTypeArray* iarr = vtkIdTypeArray::New();
iarr->SetName( vtkExodusIIReader::GetGlobalNodeIdArrayName() );
iarr->SetNumberOfComponents( 1 );
iarr->SetNumberOfTuples( bsinfop->NextSqueezePoint );
vtkIdType* gloIds = iarr->GetPointer( 0 );
vtkIdType* srcIds = src->GetPointer( 0 );
std::map<vtkIdType,vtkIdType>::iterator it;
for ( it = bsinfop->PointMap.begin(); it != bsinfop->PointMap.end(); ++ it )
{
gloIds[it->second] = srcIds[it->first];
}
arr = iarr;
}
else
{
arr = src;
}
}
else if ( key.ObjectType == vtkExodusIIReader::IMPLICIT_NODE_ID )
{ // subset the NODE_ID array choosing only entries for nodes in output grid (using PointMap)
// Yes, the next 2 statements are an intentional misuse of key
// fields reserved for the ObjectId and ArrayId (since ObjectType
// is used to signal that we want IDs instead of a field value).
int otypidx = this->GetObjectTypeIndexFromObjectType( key.ObjectId );
int obj = key.ArrayId;
BlockSetInfoType* bsinfop = (BlockSetInfoType*) this->GetObjectInfo( otypidx, obj );
vtkIdTypeArray* src = vtkIdTypeArray::New ();
src->SetNumberOfComponents( 1 );
src->SetNumberOfTuples( this->ModelParameters.num_nodes );
if (this->ModelParameters.num_node_maps > 0) // FIXME correctly detect parallel
{
#ifdef VTK_USE_64BIT_IDS
std::vector<int> tmpMap( src->GetNumberOfTuples() );
if ( ex_get_id_map( exoid, (ex_entity_type)( vtkExodusIIReader::NODE_MAP ), &tmpMap[0] ) < 0 )
{
vtkErrorMacro( "Could not read node num map for global implicit id" );
src->Delete();
return 0;
}
else
{
for ( vtkIdType i = 0; i < src->GetNumberOfTuples(); ++i )
{
src->SetValue( i, tmpMap[i] );
}
}
#else
if ( ex_get_id_map( exoid, (ex_entity_type)( vtkExodusIIReader::NODE_MAP ), (int*)src->GetPointer( 0 ) ) < 0 )
{
vtkErrorMacro( "Could not node node num map for global implicit id" );
src->Delete();
return 0;
}
#endif // VTK_USE_64BIT_IDS
}
else // single file, just make the implicit index explicit
{
for (vtkIdType i = 0; i < src->GetNumberOfTuples (); i ++)
{
src->SetValue (i, i + 1);
}
}
if ( this->SqueezePoints && src )
{
vtkIdTypeArray* iarr = vtkIdTypeArray::New();
iarr->SetName( vtkExodusIIReader::GetImplicitNodeIdArrayName() );
iarr->SetNumberOfComponents( 1 );
iarr->SetNumberOfTuples( bsinfop->NextSqueezePoint );
vtkIdType* gloIds = iarr->GetPointer( 0 );
vtkIdType* srcIds = src->GetPointer( 0 );
std::map<vtkIdType,vtkIdType>::iterator it;
for ( it = bsinfop->PointMap.begin(); it != bsinfop->PointMap.end(); ++ it )
{
gloIds[it->second] = srcIds[it->first];
}
arr = iarr;
}
else
{
arr = src;
}
src->Delete ();
}
else if (
key.ObjectType == vtkExodusIIReader::ELEMENT_ID ||
key.ObjectType == vtkExodusIIReader::EDGE_ID ||
key.ObjectType == vtkExodusIIReader::FACE_ID ||
key.ObjectType == vtkExodusIIReader::NODE_ID
)
{
vtkIdTypeArray* iarr;
int nMaps;
vtkIdType mapSize;
vtkExodusIICacheKey ktmp;
if ( key.ObjectType == vtkExodusIIReader::ELEMENT_ID )
{
nMaps = this->ModelParameters.num_elem_maps;
mapSize = this->ModelParameters.num_elem;
ktmp = vtkExodusIICacheKey( -1, vtkExodusIIReader::ELEM_MAP, 0, 0 );
}
else if ( key.ObjectType == vtkExodusIIReader::FACE_ID )
{
nMaps = this->ModelParameters.num_face_maps;
mapSize = this->ModelParameters.num_face;
ktmp = vtkExodusIICacheKey( -1, vtkExodusIIReader::FACE_MAP, 0, 0 );
}
else if ( key.ObjectType == vtkExodusIIReader::EDGE_ID )
{
nMaps = this->ModelParameters.num_edge_maps;
mapSize = this->ModelParameters.num_edge;
ktmp = vtkExodusIICacheKey( -1, vtkExodusIIReader::EDGE_MAP, 0, 0 );
}
else // ( key.ObjectType == vtkExodusIIReader::NODE_ID )
{
nMaps = this->ModelParameters.num_node_maps;
mapSize = this->ModelParameters.num_nodes;
ktmp = vtkExodusIICacheKey( -1, vtkExodusIIReader::NODE_MAP, 0, 0 );
}
// If there are no new-style maps, get the old-style map (which creates a default if nothing is stored on disk).
if ( nMaps < 1 || ! (iarr = vtkIdTypeArray::SafeDownCast(this->GetCacheOrRead( ktmp ))) )
{
iarr = vtkIdTypeArray::New();
iarr->SetNumberOfComponents( 1 );
iarr->SetNumberOfTuples( mapSize );
if ( mapSize )
{
#ifdef VTK_USE_64BIT_IDS
std::vector<int> tmpMap( iarr->GetNumberOfTuples() );
if ( ex_get_id_map( exoid, static_cast<ex_entity_type>( ktmp.ObjectType ), &tmpMap[0] ) < 0 )
{
vtkErrorMacro( "Could not read old-style node or element map." );
iarr->Delete();
iarr = 0;
}
else
{
for ( vtkIdType i = 0; i < iarr->GetNumberOfTuples(); ++i )
{
iarr->SetValue( i, tmpMap[i] );
}
}
#else
if ( ex_get_id_map( exoid, static_cast<ex_entity_type>( ktmp.ObjectType ), (int*)iarr->GetPointer( 0 ) ) < 0 )
{
vtkErrorMacro( "Could not read old-style node or element map." );
iarr->Delete();
iarr = 0;
}
#endif // VTK_USE_64BIT_IDS
}
}
else
{
// FastDelete will be called below (because we are assumed to have created the array with New()).
// So we must reference the array one extra time here to account for the extra delete...
iarr->Register( this );
}
arr = iarr;
}
else if ( key.ObjectType == vtkExodusIIReader::GLOBAL_CONN )
{
vtkErrorMacro(
"Global connectivity is created in AssembleOutputConnectivity since it can't be cached\n"
"with a single vtkDataArray. Who told you to call this routine to get it?"
);
}
else if ( key.ObjectType == vtkExodusIIReader::ENTITY_COUNTS )
{
int ctypidx;
if (key.ArrayId == 0)
{
ctypidx = 0;
}
else
{
ctypidx = 1;
}
int otypidx = conn_obj_idx_cvt[ctypidx];
int otyp = obj_types[ otypidx ];
BlockInfoType* binfop = (BlockInfoType*) this->GetObjectInfo( otypidx, key.ObjectId );
vtkIntArray* iarr = vtkIntArray::New();
iarr->SetNumberOfComponents (1);
iarr->SetNumberOfTuples (binfop->Size);
if ( ex_get_entity_count_per_polyhedra ( exoid, static_cast<ex_entity_type>( otyp ), binfop->Id,
iarr->GetPointer(0)) < 0 )
{
vtkErrorMacro( "Unable to read " << binfop->Id << " (index " << key.ObjectId <<
") entity count per polyhedra" );
iarr->Delete();
iarr = 0;
}
arr = iarr;
}
else if (
key.ObjectType == vtkExodusIIReader::ELEM_BLOCK_ELEM_CONN ||
key.ObjectType == vtkExodusIIReader::FACE_BLOCK_CONN ||
key.ObjectType == vtkExodusIIReader::EDGE_BLOCK_CONN
)
{
int ctypidx = this->GetConnTypeIndexFromConnType( key.ObjectType );
int otypidx = conn_obj_idx_cvt[ctypidx];
int otyp = obj_types[ otypidx ];
BlockInfoType* binfop = (BlockInfoType*) this->GetObjectInfo( otypidx, key.ObjectId );
vtkIntArray* iarr = vtkIntArray::New();
if (binfop->CellType == VTK_POLYGON || binfop->CellType == VTK_POLYHEDRON)
{
iarr->SetNumberOfValues (binfop->BdsPerEntry[0]);
}
else
{
iarr->SetNumberOfComponents( binfop->BdsPerEntry[0] );
iarr->SetNumberOfTuples( binfop->Size );
}
if ( ex_get_conn( exoid, static_cast<ex_entity_type>( otyp ), binfop->Id, iarr->GetPointer(0), 0, 0 ) < 0 )
{
vtkErrorMacro( "Unable to read " << objtype_names[otypidx] << " " << binfop->Id << " (index " << key.ObjectId <<
") nodal connectivity." );
iarr->Delete();
iarr = 0;
}
vtkIdType c;
int* ptr = iarr->GetPointer( 0 );
if (
binfop->CellType == VTK_QUADRATIC_HEXAHEDRON ||
binfop->CellType == VTK_TRIQUADRATIC_HEXAHEDRON
)
{
// Edge order for VTK is different than Exodus edge order.
for ( c = 0; c < iarr->GetNumberOfTuples(); ++c )
{
int k;
int itmp[4];
for ( k = 0; k < 12; ++k, ++ptr)
*ptr = *ptr - 1;
for ( k = 0; k < 4; ++k, ++ptr)
{
itmp[k] = *ptr;
*ptr = ptr[4] - 1;
}
for ( k = 0; k < 4; ++k, ++ptr )
*ptr = itmp[k] - 1;
if ( binfop->CellType == VTK_TRIQUADRATIC_HEXAHEDRON )
{ // Face/body order for VTK is different than Exodus (Patran) order.
for ( k = 0; k < 4; ++k, ++ptr )
{
itmp[k] = *ptr;
*ptr = ptr[3] - 1;
}
*(ptr++) = itmp[1] - 1;
*(ptr++) = itmp[2] - 1;
*(ptr++) = itmp[0] - 1;
}
}
ptr += binfop->BdsPerEntry[0] - binfop->PointsPerCell;
}
else if (binfop->CellType == VTK_QUADRATIC_WEDGE)
{
int k;
int itmp[3];
for ( c = 0; c < iarr->GetNumberOfTuples(); ++c )
{
for (k = 0; k < 9; ++k, ++ptr)
*ptr = *ptr - 1;
for (k = 0; k < 3; ++k, ++ptr)
{
itmp[k] = *ptr;
*ptr = ptr[3] - 1;
}
for (k = 0; k < 3; ++k, ++ptr)
{
*ptr = itmp[k] - 1;
}
}
ptr += binfop->BdsPerEntry[0] - binfop->PointsPerCell;
}
else
{
for ( c = 0; c <= iarr->GetMaxId(); ++c, ++ptr )
{
*ptr = *ptr - 1;
}
}
arr = iarr;
}
else if ( key.ObjectType == vtkExodusIIReader::ELEM_BLOCK_FACE_CONN )
{
// FIXME: Call ex_get_conn with non-NULL face conn pointer
// This won't be needed until the Exodus reader outputs multiblock data with vtkGenericDataSet blocks for higher order meshes.
arr = 0;
}
else if ( key.ObjectType == vtkExodusIIReader::ELEM_BLOCK_EDGE_CONN )
{
// FIXME: Call ex_get_conn with non-NULL edge conn pointer
// This won't be needed until the Exodus reader outputs multiblock data with vtkGenericDataSet blocks for higher order meshes.
arr = 0;
}
else if (
key.ObjectType == vtkExodusIIReader::NODE_SET_CONN ||
key.ObjectType == vtkExodusIIReader::ELEM_SET_CONN
)
{
int otyp = this->GetSetTypeFromSetConnType( key.ObjectType );
int otypidx = this->GetObjectTypeIndexFromObjectType( otyp );
SetInfoType* sinfop = &this->SetInfo[otyp][key.ObjectId];
vtkIntArray* iarr = vtkIntArray::New();
iarr->SetNumberOfComponents( 1 );
iarr->SetNumberOfTuples( sinfop->Size );
int* iptr = iarr->GetPointer( 0 );
if ( ex_get_set( exoid, static_cast<ex_entity_type>( otyp ), sinfop->Id, iptr, 0 ) < 0 )
{
vtkErrorMacro( "Unable to read " << objtype_names[otypidx] << " " << sinfop->Id << " (index " << key.ObjectId <<
") nodal connectivity." );
iarr->Delete();
iarr = 0;
}
vtkIdType id;
for ( id = 0; id < sinfop->Size; ++id, ++iptr )
{ // VTK uses 0-based indexing, unlike Exodus:
--(*iptr);
}
arr = iarr;
}
else if ( key.ObjectType == vtkExodusIIReader::EDGE_SET_CONN || key.ObjectType == vtkExodusIIReader::FACE_SET_CONN )
{
int otyp = this->GetSetTypeFromSetConnType( key.ObjectType );
int otypidx = this->GetObjectTypeIndexFromObjectType( otyp );
SetInfoType* sinfop = &this->SetInfo[otyp][key.ObjectId];
vtkIntArray* iarr = vtkIntArray::New();
iarr->SetNumberOfComponents( 2 );
iarr->SetNumberOfTuples( sinfop->Size );
std::vector<int> tmpOrient; // hold the edge/face orientation information until we can interleave it.
tmpOrient.resize( sinfop->Size );
if ( ex_get_set( exoid, static_cast<ex_entity_type>( otyp ), sinfop->Id, iarr->GetPointer(0), &tmpOrient[0] ) < 0 )
{
vtkErrorMacro( "Unable to read " << objtype_names[otypidx] << " " << sinfop->Id << " (index " << key.ObjectId <<
") nodal connectivity." );
iarr->Delete();
iarr = 0;
return 0;
}
int* iap = iarr->GetPointer( 0 );
vtkIdType c;
for ( c = sinfop->Size - 1; c >= 0; --c )
{
iap[2*c] = iap[c] - 1; // VTK uses 0-based indexing
iap[2*c + 1] = tmpOrient[c];
}
arr = iarr;
}
else if ( key.ObjectType == vtkExodusIIReader::SIDE_SET_CONN )
{
// Stick all of side_set_node_list and side_set_node_count and side_set_nodes_per_side in one array
// let InsertSetSides() figure it all out. Except for 0-based indexing
SetInfoType* sinfop = &this->SetInfo[vtkExodusIIReader::SIDE_SET][key.ObjectId];
int ssnllen; // side set node list length
if ( ex_get_side_set_node_list_len( exoid, sinfop->Id, &ssnllen ) < 0 )
{
vtkErrorMacro( "Unable to fetch side set \"" << sinfop->Name.c_str() << "\" (" << sinfop->Id << ") node list length" );
arr = 0;
return 0;
}
vtkIntArray* iarr = vtkIntArray::New();
vtkIdType ilen = ssnllen + sinfop->Size;
iarr->SetNumberOfComponents( 1 );
iarr->SetNumberOfTuples( ilen );
int* dat = iarr->GetPointer( 0 );
if ( ex_get_side_set_node_list( exoid, sinfop->Id, dat, dat + sinfop->Size ) < 0 )
{
vtkErrorMacro( "Unable to fetch side set \"" << sinfop->Name.c_str() << "\" (" << sinfop->Id << ") node list" );
iarr->Delete();
arr = 0;
return 0;
}
while ( ilen > sinfop->Size )
{ // move to 0-based indexing on nodes, don't touch nodes/side counts at head of array
--dat[--ilen];
}
arr = iarr;
}
else if ( key.ObjectType == vtkExodusIIReader::NODAL_COORDS )
{
// read node coords
vtkDataArray* displ = 0;
if ( this->ApplyDisplacements && key.Time >= 0 )
{
displ = this->FindDisplacementVectors( key.Time );
}
std::vector<double> coordTmp;
vtkDoubleArray* darr = vtkDoubleArray::New();
arr = darr;
arr->SetNumberOfComponents( 3 );
arr->SetNumberOfTuples( this->ModelParameters.num_nodes );
int dim = this->ModelParameters.num_dim;
int c;
vtkIdType t;
double* xc = 0;
double* yc = 0;
double* zc = 0;
coordTmp.resize( this->ModelParameters.num_nodes );
for ( c = 0; c < dim; ++c )
{
switch ( c )
{
case 0:
xc = &coordTmp[0];
break;
case 1:
yc = xc;
xc = 0;
break;
case 2:
zc = yc;
yc = 0;
break;
default:
vtkErrorMacro( "Bad coordinate index " << c << " when reading point coordinates." );
xc = yc = zc = 0;
}
if ( ex_get_coord( exoid, xc, yc, zc ) < 0 )
{
vtkErrorMacro( "Unable to read node coordinates for index " << c << "." );
arr->Delete();
arr = 0;
break;
}
double* cptr = darr->GetPointer( c );
for ( t = 0; t < this->ModelParameters.num_nodes; ++t )
{
*cptr = coordTmp[t];
cptr += 3;
}
}
if ( dim < 3 )
{
double* cptr = darr->GetPointer( 2 );
for ( t = 0; t < this->ModelParameters.num_nodes; ++t, cptr += 3 )
{
*cptr = 0.;
}
}
if ( displ )
{
double* coords = darr->GetPointer( 0 );
if ( this->HasModeShapes && this->AnimateModeShapes )
{
for ( vtkIdType idx = 0; idx < displ->GetNumberOfTuples(); ++idx )
{
double* dispVal = displ->GetTuple( idx );
for ( c = 0; c < dim; ++c )
coords[c] += dispVal[c] * this->DisplacementMagnitude * cos( 2. * vtkMath::Pi() * this->ModeShapeTime );
coords += 3;
}
}
else
{
for ( vtkIdType idx = 0; idx < displ->GetNumberOfTuples(); ++idx )
{
double* dispVal = displ->GetTuple( idx );
for ( c = 0; c < dim; ++c )
coords[c] += dispVal[c] * this->DisplacementMagnitude;
coords += 3;
}
}
}
}
else if ( key.ObjectType == vtkExodusIIReader::OBJECT_ID )
{
BlockSetInfoType* bsinfop;
// Yes, the next 2 statements are an intentional misuse of key
// fields reserved for the ObjectId and ArrayId (since ObjectType
// is used to signal that we want IDs instead of a field value).
int otypidx = this->GetObjectTypeIndexFromObjectType( key.ObjectId );
int obj = key.ArrayId;
bsinfop = (BlockSetInfoType*) this->GetObjectInfo( otypidx, obj );
arr = vtkIntArray::New();
arr->SetName( this->GetObjectIdArrayName() );
arr->SetNumberOfComponents( 1 );
arr->SetNumberOfTuples( bsinfop->Size );
arr->FillComponent( 0, bsinfop->Id );
}
else if (
key.ObjectType == vtkExodusIIReader::ELEM_BLOCK_ATTRIB ||
key.ObjectType == vtkExodusIIReader::FACE_BLOCK_ATTRIB ||
key.ObjectType == vtkExodusIIReader::EDGE_BLOCK_ATTRIB
)
{
BlockInfoType* binfop = &this->BlockInfo[key.ObjectType][key.ObjectId];
vtkDoubleArray* darr = vtkDoubleArray::New();
arr = darr;
darr->SetName( binfop->AttributeNames[key.ArrayId].c_str() );
darr->SetNumberOfComponents( 1 );
darr->SetNumberOfTuples( binfop->Size );
if ( ex_get_one_attr( exoid, static_cast<ex_entity_type>( key.ObjectType ), key.ObjectId, key.ArrayId, darr->GetVoidPointer( 0 ) ) < 0 )
{ // NB: The error message references the file-order object id, not the numerically sorted index presented to users.
vtkErrorMacro( "Unable to read attribute " << key.ArrayId
<< " for object " << key.ObjectId << " of type " << key.ObjectType << "." );
arr->Delete();
arr = 0;
}
}
else if ( key.ObjectType == vtkExodusIIReader::INFO_RECORDS )
{
// Get Exodus II INFO records. Each INFO record is a single character string.
int num_info = 0;
float fdum;
char* cdum = 0;
int i;
vtkCharArray* carr = vtkCharArray::New();
carr->SetName("Info_Records");
carr->SetNumberOfComponents( MAX_LINE_LENGTH+1 );
if( ex_inquire( exoid, EX_INQ_INFO, &num_info, &fdum, cdum ) < 0 )
{
vtkErrorMacro( "Unable to get number of INFO records from ex_inquire" );
carr->Delete();
arr = 0;
}
else
{
if ( num_info > 0 )
{
carr->SetNumberOfTuples(num_info);
char** info = (char**) calloc( num_info, sizeof(char*) );
for ( i = 0; i < num_info; ++i )
info[i] = (char *) calloc ( ( MAX_LINE_LENGTH + 1 ), sizeof(char) );
if ( ex_get_info( exoid, info ) < 0 )
{
vtkErrorMacro( "Unable to read INFO records from ex_get_info");
carr->Delete();
arr = 0;
}
else
{
for ( i = 0; i < num_info; ++i )
{
carr->InsertTupleValue( i, info[i] );
}
arr = carr;
}
for ( i = 0; i < num_info; ++i )
{
free(info[i]);
}
free(info);
}
else
{
carr->Delete();
arr = 0;
}
}
}
else if ( key.ObjectType == vtkExodusIIReader::QA_RECORDS )
{
// Get Exodus II QA records. Each QA record is made up of 4 character strings.
int num_qa_rec = 0;
float fdum;
char* cdum = 0;
int i,j;
vtkCharArray* carr = vtkCharArray::New();
carr->SetName( "QA_Records" );
carr->SetNumberOfComponents( MAX_STR_LENGTH + 1 );
if ( ex_inquire( exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum ) < 0 )
{
vtkErrorMacro( "Unable to get number of QA records from ex_inquire" );
carr->Delete();
arr = 0;
}
else
{
if( num_qa_rec > 0 )
{
carr->SetNumberOfTuples(num_qa_rec*4);
char* (*qa_record)[4] = (char* (*)[4]) calloc(num_qa_rec, sizeof(*qa_record));
for ( i = 0; i < num_qa_rec; ++i )
{
for ( j = 0; j < 4 ; ++j )
{
qa_record[i][j] = (char *) calloc( ( MAX_STR_LENGTH + 1 ), sizeof(char) );
}
}
if ( ex_get_qa( exoid, qa_record ) < 0 )
{
vtkErrorMacro( "Unable to read QA records from ex_get_qa");
carr->Delete();
arr = 0;
}
else
{
for ( i = 0; i < num_qa_rec; ++i )
{
for ( j = 0; j < 4 ; ++j )
{
carr->InsertTupleValue( ( i * 4 ) + j, qa_record[i][j] );
}
}
arr = carr;
}
for ( i = 0; i < num_qa_rec; ++i )
{
for ( j = 0; j < 4 ; ++j )
{
free( qa_record[i][j] );
}
}
free( qa_record );
}
else
{
carr->Delete();
arr = 0;
}
}
}
else
{
vtkWarningMacro( "You requested an array for objects of type " << key.ObjectType <<
" which I know nothing about" );
arr = 0;
}
// Even if the array is larger than the allowable cache size, it will keep the most recent insertion.
// So, we delete our reference knowing that the Cache will keep the object "alive" until whatever
// called GetCacheOrRead() references the array. But, once you get an array from GetCacheOrRead(),
// you better start running!
if ( arr )
{
this->Cache->Insert( key, arr );
arr->FastDelete();
}
return arr;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetConnTypeIndexFromConnType( int ctyp )
{
int i;
for ( i = 0; i < num_conn_types; ++i )
{
if ( conn_types[i] == ctyp )
{
return i;
}
}
return -1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetObjectTypeIndexFromObjectType( int otyp )
{
int i;
for ( i = 0; i < num_obj_types; ++i )
{
if ( obj_types[i] == otyp )
{
return i;
}
}
return -1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetNumberOfObjectsAtTypeIndex( int typeIndex )
{
if ( typeIndex < 0 )
{
return 0;
}
else if ( typeIndex < 3 )
{
return (int) this->BlockInfo[obj_types[typeIndex]].size();
}
else if ( typeIndex < 8 )
{
return (int) this->SetInfo[obj_types[typeIndex]].size();
}
else if ( typeIndex < 12 )
{
return (int) this->MapInfo[obj_types[typeIndex]].size();
}
return 0;
}
//-----------------------------------------------------------------------------
vtkExodusIIReaderPrivate::ObjectInfoType* vtkExodusIIReaderPrivate::GetObjectInfo( int typeIndex, int objectIndex )
{
if ( typeIndex < 0 )
{
return 0;
}
else if ( typeIndex < 3 )
{
return &this->BlockInfo[obj_types[typeIndex]][objectIndex];
}
else if ( typeIndex < 8 )
{
return &this->SetInfo[obj_types[typeIndex]][objectIndex];
}
else if ( typeIndex < 12 )
{
return &this->MapInfo[obj_types[typeIndex]][objectIndex];
}
return 0;
}
//-----------------------------------------------------------------------------
vtkExodusIIReaderPrivate::ObjectInfoType* vtkExodusIIReaderPrivate::GetSortedObjectInfo( int otyp, int k )
{
int i = this->GetObjectTypeIndexFromObjectType( otyp );
if ( i < 0 )
{
vtkDebugMacro( "Could not find collection of objects with type " << otyp << "." );
return 0;
}
int N = this->GetNumberOfObjectsAtTypeIndex( i );
if ( k < 0 || k >= N )
{
const char* otname = i >= 0 ? objtype_names[i] : "object";
static_cast<void>(otname); // not referenced warning
vtkDebugMacro( "You requested " << otname << " " << k << " in a collection of only " << N << " objects." );
return 0;
}
return this->GetObjectInfo( i, this->SortedObjectIndices[otyp][k] );
}
//-----------------------------------------------------------------------------
vtkExodusIIReaderPrivate::ObjectInfoType* vtkExodusIIReaderPrivate::GetUnsortedObjectInfo( int otyp, int k )
{
int i = this->GetObjectTypeIndexFromObjectType( otyp );
if ( i < 0 )
{
vtkDebugMacro( "Could not find collection of objects with type " << otyp << "." );
return 0;
}
int N = this->GetNumberOfObjectsAtTypeIndex( i );
if ( k < 0 || k >= N )
{
const char* otname = i >= 0 ? objtype_names[i] : "object";
static_cast<void>(otname); // not referenced warning
vtkDebugMacro( "You requested " << otname << " " << k << " in a collection of only " << N << " objects." );
return 0;
}
return this->GetObjectInfo( i, k );
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetBlockIndexFromFileGlobalId( int otyp, int refId )
{
std::vector<BlockInfoType>::iterator bi;
int i = 0;
for ( bi = this->BlockInfo[otyp].begin(); bi != this->BlockInfo[otyp].end(); ++bi, ++i )
{
if ( refId >= bi->FileOffset && refId <= bi->FileOffset + bi->Size )
return i;
}
return -1;
}
//-----------------------------------------------------------------------------
vtkExodusIIReaderPrivate::BlockInfoType* vtkExodusIIReaderPrivate::GetBlockFromFileGlobalId( int otyp, int refId )
{
int blk = this->GetBlockIndexFromFileGlobalId( otyp, refId );
if ( blk >= 0 )
{
return &this->BlockInfo[otyp][blk];
}
return 0;
}
//-----------------------------------------------------------------------------
vtkIdType vtkExodusIIReaderPrivate::GetSqueezePointId( BlockSetInfoType* bsinfop, int i )
{
if (i<0)
{
vtkGenericWarningMacro("Invalid point id: " << i
<< ". Data file may be incorrect.");
i = 0;
}
vtkIdType x;
std::map<vtkIdType,vtkIdType>::iterator it = bsinfop->PointMap.find( i );
if ( it == bsinfop->PointMap.end() )
{ // Nothing found; add a new entry to the map.
x = bsinfop->NextSqueezePoint ++ ;
bsinfop->PointMap[i] = x;
bsinfop->ReversePointMap[x] = i;
}
else
{
x = it->second;
}
return x;
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::DetermineVtkCellType( BlockInfoType& binfo )
{
vtkStdString elemType( vtksys::SystemTools::UpperCase( binfo.TypeName ) );
// Check for quadratic elements
if ((elemType.substr(0,3) == "TRI") && (binfo.BdsPerEntry[0] == 6))
{ binfo.CellType=VTK_QUADRATIC_TRIANGLE; binfo.PointsPerCell = 6; }
else if ((elemType.substr(0,3) == "SHE") && (binfo.BdsPerEntry[0] == 8))
{ binfo.CellType=VTK_QUADRATIC_QUAD; binfo.PointsPerCell = 8; }
else if ((elemType.substr(0,3) == "SHE") && (binfo.BdsPerEntry[0] == 9))
{ binfo.CellType=VTK_QUADRATIC_QUAD; binfo.PointsPerCell = 8; }
else if ((elemType.substr(0,3) == "TET") && (binfo.BdsPerEntry[0] == 10))
{ binfo.CellType=VTK_QUADRATIC_TETRA; binfo.PointsPerCell = 10; }
else if ((elemType.substr(0,3) == "TET") && (binfo.BdsPerEntry[0] == 11))
{ binfo.CellType=VTK_QUADRATIC_TETRA; binfo.PointsPerCell = 10; }
else if ((elemType.substr(0,3) == "WED") && (binfo.BdsPerEntry[0] == 15))
{ binfo.CellType=VTK_QUADRATIC_WEDGE; binfo.PointsPerCell = 15; }
else if ((elemType.substr(0,3) == "HEX") && (binfo.BdsPerEntry[0] == 20))
{ binfo.CellType=VTK_QUADRATIC_HEXAHEDRON; binfo.PointsPerCell = 20; }
else if ((elemType.substr(0,3) == "HEX") && (binfo.BdsPerEntry[0] == 21))
{ binfo.CellType=VTK_QUADRATIC_HEXAHEDRON; binfo.PointsPerCell = 20; }
else if ((elemType.substr(0,3) == "HEX") && (binfo.BdsPerEntry[0] == 27))
{ binfo.CellType=VTK_TRIQUADRATIC_HEXAHEDRON; binfo.PointsPerCell = 27; }
else if ((elemType.substr(0,3) == "QUA") && (binfo.BdsPerEntry[0] == 8))
{ binfo.CellType=VTK_QUADRATIC_QUAD; binfo.PointsPerCell = 8; }
else if ((elemType.substr(0,3) == "QUA") && (binfo.BdsPerEntry[0] == 9))
{ binfo.CellType=VTK_BIQUADRATIC_QUAD; binfo.PointsPerCell = 9; }
else if ((elemType.substr(0,3) == "TRU") && (binfo.BdsPerEntry[0] == 3))
{ binfo.CellType=VTK_QUADRATIC_EDGE; binfo.PointsPerCell = 3; }
else if ((elemType.substr(0,3) == "BEA") && (binfo.BdsPerEntry[0] == 3))
{ binfo.CellType=VTK_QUADRATIC_EDGE; binfo.PointsPerCell = 3; }
else if ((elemType.substr(0,3) == "BAR") && (binfo.BdsPerEntry[0] == 3))
{ binfo.CellType=VTK_QUADRATIC_EDGE; binfo.PointsPerCell = 3; }
else if ((elemType.substr(0,3) == "EDG") && (binfo.BdsPerEntry[0] == 3))
{ binfo.CellType=VTK_QUADRATIC_EDGE; binfo.PointsPerCell = 3; }
// Check for regular elements
else if (elemType.substr(0,3) == "CIR") { binfo.CellType = VTK_VERTEX; binfo.PointsPerCell = 1; }
else if (elemType.substr(0,3) == "SPH") { binfo.CellType = VTK_VERTEX; binfo.PointsPerCell = 1; }
else if (elemType.substr(0,3) == "BAR") { binfo.CellType = VTK_LINE; binfo.PointsPerCell = 2; }
else if (elemType.substr(0,3) == "TRU") { binfo.CellType = VTK_LINE; binfo.PointsPerCell = 2; }
else if (elemType.substr(0,3) == "BEA") { binfo.CellType = VTK_LINE; binfo.PointsPerCell = 2; }
else if (elemType.substr(0,3) == "EDG") { binfo.CellType = VTK_LINE; binfo.PointsPerCell = 2; }
else if (elemType.substr(0,3) == "TRI") { binfo.CellType = VTK_TRIANGLE; binfo.PointsPerCell = 3; }
else if (elemType.substr(0,3) == "QUA") { binfo.CellType = VTK_QUAD; binfo.PointsPerCell = 4; }
else if (elemType.substr(0,3) == "TET") { binfo.CellType = VTK_TETRA; binfo.PointsPerCell = 4; }
else if (elemType.substr(0,3) == "PYR") { binfo.CellType = VTK_PYRAMID; binfo.PointsPerCell = 5; }
else if (elemType.substr(0,3) == "WED") { binfo.CellType = VTK_WEDGE; binfo.PointsPerCell = 6; }
else if (elemType.substr(0,3) == "HEX") { binfo.CellType = VTK_HEXAHEDRON; binfo.PointsPerCell = 8; }
else if (elemType.substr(0,3) == "NSI") { binfo.CellType = VTK_POLYGON; binfo.PointsPerCell = 0; }
else if (elemType.substr(0,3) == "NFA") { binfo.CellType = VTK_POLYHEDRON; binfo.PointsPerCell = 0; }
else if ((elemType.substr(0,3) == "SHE") && (binfo.BdsPerEntry[0] == 3))
{ binfo.CellType = VTK_TRIANGLE; binfo.PointsPerCell = 3; }
else if ((elemType.substr(0,3) == "SHE") && (binfo.BdsPerEntry[0] == 4))
{ binfo.CellType = VTK_QUAD; binfo.PointsPerCell = 4; }
else if ((elemType.substr(0,8) == "STRAIGHT") && (binfo.BdsPerEntry[0] == 2 ))
{ binfo.CellType = VTK_LINE; binfo.PointsPerCell = 2; }
else if (elemType.substr(0,3) == "SUP")
{
binfo.CellType=VTK_POLY_VERTEX;
binfo.PointsPerCell = binfo.BdsPerEntry[0];
}
else if ((elemType.substr(0,8) == "NULL") && (binfo.Size == 0))
{
(void)binfo; // silently ignore empty element blocks
}
else
{
vtkErrorMacro("Unsupported element type: " << elemType.c_str());
}
//cell types not currently handled
//quadratic wedge - 15,16 nodes
//quadratic pyramid - 13 nodes
}
//-----------------------------------------------------------------------------
vtkExodusIIReaderPrivate::ArrayInfoType* vtkExodusIIReaderPrivate::FindArrayInfoByName( int otyp, const char* name )
{
std::vector<ArrayInfoType>::iterator ai;
for ( ai = this->ArrayInfo[otyp].begin(); ai != this->ArrayInfo[otyp].end(); ++ai )
{
if ( ai->Name == name )
return &(*ai);
}
return 0;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::IsObjectTypeBlock( int otyp )
{
return (otyp == vtkExodusIIReader::ELEM_BLOCK || otyp == vtkExodusIIReader::EDGE_BLOCK || otyp == vtkExodusIIReader::FACE_BLOCK);
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::IsObjectTypeSet( int otyp )
{
return (otyp == vtkExodusIIReader::ELEM_SET || otyp == vtkExodusIIReader::EDGE_SET || otyp == vtkExodusIIReader::FACE_SET || otyp == vtkExodusIIReader::NODE_SET || otyp == vtkExodusIIReader::SIDE_SET);
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::IsObjectTypeMap( int otyp )
{
return (otyp == vtkExodusIIReader::ELEM_MAP || otyp == vtkExodusIIReader::EDGE_MAP || otyp == vtkExodusIIReader::FACE_MAP || otyp == vtkExodusIIReader::NODE_MAP);
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetObjectTypeFromMapType( int mtyp )
{
switch (mtyp)
{
case vtkExodusIIReader::ELEM_MAP:
return vtkExodusIIReader::ELEM_BLOCK;
case vtkExodusIIReader::FACE_MAP:
return vtkExodusIIReader::FACE_BLOCK;
case vtkExodusIIReader::EDGE_MAP:
return vtkExodusIIReader::EDGE_BLOCK;
case vtkExodusIIReader::NODE_MAP:
return vtkExodusIIReader::NODAL;
}
return -1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetMapTypeFromObjectType( int otyp )
{
switch (otyp)
{
case vtkExodusIIReader::ELEM_BLOCK:
return vtkExodusIIReader::ELEM_MAP;
case vtkExodusIIReader::FACE_BLOCK:
return vtkExodusIIReader::FACE_MAP;
case vtkExodusIIReader::EDGE_BLOCK:
return vtkExodusIIReader::EDGE_MAP;
case vtkExodusIIReader::NODAL:
return vtkExodusIIReader::NODE_MAP;
}
return -1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetTemporalTypeFromObjectType( int otyp )
{
switch (otyp)
{
case vtkExodusIIReader::ELEM_BLOCK:
return vtkExodusIIReader::ELEM_BLOCK_TEMPORAL;
//case vtkExodusIIReader::FACE_BLOCK:
// return vtkExodusIIReader::FACE_MAP;
//case vtkExodusIIReader::EDGE_BLOCK:
// return vtkExodusIIReader::EDGE_MAP;
case vtkExodusIIReader::NODAL:
return vtkExodusIIReader::NODAL_TEMPORAL;
case vtkExodusIIReader::GLOBAL:
return vtkExodusIIReader::GLOBAL_TEMPORAL;
}
return -1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetSetTypeFromSetConnType( int sctyp )
{
switch ( sctyp )
{
case vtkExodusIIReader::NODE_SET_CONN:
return vtkExodusIIReader::NODE_SET;
case vtkExodusIIReader::EDGE_SET_CONN:
return vtkExodusIIReader::EDGE_SET;
case vtkExodusIIReader::FACE_SET_CONN:
return vtkExodusIIReader::FACE_SET;
case vtkExodusIIReader::SIDE_SET_CONN:
return vtkExodusIIReader::SIDE_SET;
case vtkExodusIIReader::ELEM_SET_CONN:
return vtkExodusIIReader::ELEM_SET;
}
return -1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetBlockConnTypeFromBlockType( int btyp )
{
switch ( btyp )
{
case vtkExodusIIReader::EDGE_BLOCK:
return vtkExodusIIReader::EDGE_BLOCK_CONN;
case vtkExodusIIReader::FACE_BLOCK:
return vtkExodusIIReader::FACE_BLOCK_CONN;
case vtkExodusIIReader::ELEM_BLOCK:
return vtkExodusIIReader::ELEM_BLOCK_ELEM_CONN;
}
return -1;
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::RemoveBeginningAndTrailingSpaces( int len, char **names )
{
int i, j;
for (i=0; i<len; i++)
{
char *c = names[i];
int nmlen = (int)strlen(c);
char *cbegin = c;
char *cend = c + nmlen - 1;
// remove spaces or non-printing character from start and end
for (j=0; j<nmlen; j++)
{
if (!isgraph(*cbegin)) cbegin++;
else break;
}
for (j=0; j<nmlen; j++)
{
if (!isgraph(*cend)) cend--;
else break;
}
if (cend < cbegin)
{
sprintf(names[i], "null_%d", i);
continue;
}
int newlen = cend - cbegin + 1;
if (newlen < nmlen)
{
for (j=0; j<newlen; j++)
{
*c++ = *cbegin++;
}
*c = '\0';
}
}
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::ClearConnectivityCaches()
{
std::map<int,std::vector<BlockInfoType> >::iterator blksit;
for ( blksit = this->BlockInfo.begin(); blksit != this->BlockInfo.end(); ++ blksit )
{
std::vector<BlockInfoType>::iterator blkit;
for ( blkit = blksit->second.begin(); blkit != blksit->second.end(); ++ blkit )
{
if ( blkit->CachedConnectivity )
{
blkit->CachedConnectivity->Delete();
blkit->CachedConnectivity = 0;
}
}
}
std::map<int,std::vector<SetInfoType> >::iterator setsit;
for ( setsit = this->SetInfo.begin(); setsit != this->SetInfo.end(); ++ setsit )
{
std::vector<SetInfoType>::iterator setit;
for ( setit = setsit->second.begin(); setit != setsit->second.end(); ++ setit )
{
if ( setit->CachedConnectivity )
{
setit->CachedConnectivity->Delete();
setit->CachedConnectivity = 0;
}
}
}
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::SetParser(vtkExodusIIReaderParser *parser)
{
// Properly sets the parser object but does not call Modified. The parser
// represents the state of the data in files, not the state of this object.
if (this->Parser != parser)
{
vtkExodusIIReaderParser *oldParser = this->Parser;
this->Parser = parser;
if (this->Parser) this->Parser->Register(this);
if (oldParser) oldParser->UnRegister(this);
}
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetNumberOfParts()
{
return static_cast<int>( this->PartInfo.size() );
}
//-----------------------------------------------------------------------------
const char* vtkExodusIIReaderPrivate::GetPartName(int idx)
{
return this->PartInfo[idx].Name.c_str();
}
//-----------------------------------------------------------------------------
const char* vtkExodusIIReaderPrivate::GetPartBlockInfo(int idx)
{
char buffer[80];
vtkStdString blocks;
std::vector<int> blkIndices = this->PartInfo[idx].BlockIndices;
for (unsigned int i=0;i<blkIndices.size();i++)
{
sprintf(buffer,"%d, ",blkIndices[i]);
blocks += buffer;
}
blocks.erase(blocks.size()-2,blocks.size()-1);
return blocks.c_str();
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetPartStatus(int idx)
{
//a part is only active if all its blocks are active
std::vector<int> blkIndices = this->PartInfo[idx].BlockIndices;
for (unsigned int i=0;i<blkIndices.size();i++)
{
if (!this->GetUnsortedObjectStatus(vtkExodusIIReader::ELEM_BLOCK,blkIndices[i]))
{
return 0;
}
}
return 1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetPartStatus(vtkStdString name)
{
for (unsigned int i=0;i<this->PartInfo.size();i++)
{
if (this->PartInfo[i].Name==name)
{
return this->GetPartStatus(i);
}
}
return -1;
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::SetPartStatus(int idx, int on)
{
//update the block status for all the blocks in this part
std::vector<int> blkIndices = this->PartInfo[idx].BlockIndices;
for (unsigned int i=0;i<blkIndices.size();i++)
{
this->SetUnsortedObjectStatus(vtkExodusIIReader::ELEM_BLOCK, blkIndices[i], on);
}
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::SetPartStatus(vtkStdString name, int flag)
{
for(unsigned int idx=0; idx<this->PartInfo.size(); ++idx)
{
if ( name == this->PartInfo[idx].Name )
{
this->SetPartStatus(idx,flag);
return;
}
}
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetNumberOfMaterials()
{
return static_cast<int>( this->MaterialInfo.size() );
}
//-----------------------------------------------------------------------------
const char* vtkExodusIIReaderPrivate::GetMaterialName(int idx)
{
return this->MaterialInfo[idx].Name.c_str();
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetMaterialStatus(int idx)
{
std::vector<int> blkIndices = this->MaterialInfo[idx].BlockIndices;
for (unsigned int i=0;i<blkIndices.size();i++)
{
if (!this->GetUnsortedObjectStatus(vtkExodusIIReader::ELEM_BLOCK,blkIndices[i]))
{
return 0;
}
}
return 1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetMaterialStatus(vtkStdString name)
{
for (unsigned int i=0;i<this->MaterialInfo.size();i++)
{
if (this->MaterialInfo[i].Name==name)
{
return this->GetMaterialStatus(i);
}
}
return -1;
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::SetMaterialStatus(int idx, int on)
{
//update the block status for all the blocks in this material
std::vector<int> blkIndices = this->MaterialInfo[idx].BlockIndices;
for (unsigned int i=0;i<blkIndices.size();i++)
{
this->SetUnsortedObjectStatus(vtkExodusIIReader::ELEM_BLOCK,blkIndices[i],on);
}
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::SetMaterialStatus(vtkStdString name, int flag)
{
for(unsigned int idx=0; idx<this->MaterialInfo.size(); ++idx)
{
if ( name == this->MaterialInfo[idx].Name )
{
this->SetMaterialStatus(idx,flag);
return;
}
}
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetNumberOfAssemblies()
{
return static_cast<int>( this->AssemblyInfo.size() );
}
//-----------------------------------------------------------------------------
const char* vtkExodusIIReaderPrivate::GetAssemblyName(int idx)
{
return this->AssemblyInfo[idx].Name.c_str();
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetAssemblyStatus(int idx)
{
std::vector<int> blkIndices = this->AssemblyInfo[idx].BlockIndices;
for (unsigned int i=0;i<blkIndices.size();i++)
{
if (!this->GetUnsortedObjectStatus(vtkExodusIIReader::ELEM_BLOCK,blkIndices[i]))
{
return 0;
}
}
return 1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::GetAssemblyStatus(vtkStdString name)
{
for (unsigned int i=0;i<this->AssemblyInfo.size();i++)
{
if (this->AssemblyInfo[i].Name==name)
{
return this->GetAssemblyStatus(i);
}
}
return -1;
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::SetAssemblyStatus(int idx, int on)
{
std::vector<int> blkIndices = this->AssemblyInfo[idx].BlockIndices;
//update the block status for all the blocks in this material
for (unsigned int i=0;i<blkIndices.size();i++)
{
this->SetUnsortedObjectStatus(vtkExodusIIReader::ELEM_BLOCK,blkIndices[i],on);
}
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::SetAssemblyStatus(vtkStdString name, int flag)
{
for(unsigned int idx=0; idx<this->AssemblyInfo.size(); ++idx)
{
if ( name == this->AssemblyInfo[idx].Name )
{
this->SetAssemblyStatus(idx,flag);
return;
}
}
}
//-----------------------------------------------------------------------------
// Normally, this would be below with all the other vtkExodusIIReader member definitions,
// but the Tcl PrintSelf test script is really lame.
void vtkExodusIIReader::PrintSelf( ostream& os, vtkIndent indent )
{
this->Superclass::PrintSelf( os, indent );
os << indent << "FileName: " << ( this->FileName ? this->FileName : "(null)" ) << "\n";
os << indent << "XMLFileName: " << ( this->XMLFileName ? this->XMLFileName : "(null)" ) << "\n";
os << indent << "DisplayType: " << this->DisplayType << "\n";
os << indent << "TimeStep: " << this->TimeStep << "\n";
os << indent << "TimeStepRange: [" << this->TimeStepRange[0] << ", " << this->TimeStepRange[1] << "]\n";
os << indent << "ExodusModelMetadata: " << (this->ExodusModelMetadata ? "ON" : "OFF" ) << "\n";
os << indent << "PackExodusModelOntoOutput: " << (this->PackExodusModelOntoOutput ? "ON" : "OFF" ) << "\n";
os << indent << "ExodusModel: " << this->ExodusModel << "\n";
os << indent << "SILUpdateStamp: " << this->SILUpdateStamp << "\n";
os << indent << "ProducedFastPathOutput: " << this->ProducedFastPathOutput << "\n";
if ( this->Metadata )
{
os << indent << "Metadata:\n";
this->Metadata->PrintData( os, indent.GetNextIndent() );
}
else
{
os << indent << "Metadata: (null)\n";
}
}
void vtkExodusIIReaderPrivate::PrintData( ostream& os, vtkIndent indent )
{
//this->Superclass::Print Self( os, indent );
os << indent << "Exoid: " << this->Exoid << "\n";
os << indent << "AppWordSize: " << this->AppWordSize << "\n";
os << indent << "DiskWordSize: " << this->DiskWordSize << "\n";
os << indent << "ExodusVersion: " << this->ExodusVersion << "\n";
os << indent << "ModelParameters:\n";
vtkIndent inden2 = indent.GetNextIndent();
os << inden2 << "Title: " << this->ModelParameters.title << "\n";
os << inden2 << "Dimension: " << this->ModelParameters.num_dim << "\n";
os << inden2 << "Nodes: " << this->ModelParameters.num_nodes << "\n";
os << inden2 << "Edges: " << this->ModelParameters.num_edge << "\n";
os << inden2 << "Faces: " << this->ModelParameters.num_face << "\n";
os << inden2 << "Elements: " << this->ModelParameters.num_elem << "\n";
os << inden2 << "Edge Blocks: " << this->ModelParameters.num_edge_blk << "\n";
os << inden2 << "Face Blocks: " << this->ModelParameters.num_face_blk << "\n";
os << inden2 << "Element Blocks: " << this->ModelParameters.num_elem_blk << "\n";
os << inden2 << "Node Sets: " << this->ModelParameters.num_node_sets << "\n";
os << inden2 << "Edge Sets: " << this->ModelParameters.num_edge_sets << "\n";
os << inden2 << "Face Sets: " << this->ModelParameters.num_face_sets << "\n";
os << inden2 << "Side Sets: " << this->ModelParameters.num_side_sets << "\n";
os << inden2 << "Element Sets: " << this->ModelParameters.num_elem_sets << "\n";
os << inden2 << "Node Maps: " << this->ModelParameters.num_node_maps << "\n";
os << inden2 << "Edge Maps: " << this->ModelParameters.num_edge_maps << "\n";
os << inden2 << "Face Maps: " << this->ModelParameters.num_face_maps << "\n";
os << inden2 << "Element Maps: " << this->ModelParameters.num_elem_maps << "\n";
os << indent << "Time steps (" << this->Times.size() << "):";
int i;
for ( i = 0; i < (int)this->Times.size(); ++i )
{
os << " " << this->Times[i];
}
os << "\n";
os << indent << "TimeStep: " << this->TimeStep << "\n";
os << indent << "HasModeShapes: " << this->HasModeShapes << "\n";
os << indent << "ModeShapeTime: " << this->ModeShapeTime << "\n";
os << indent << "AnimateModeShapes: " << this->AnimateModeShapes << "\n";
// Print nodal variables
if ( this->ArrayInfo[ vtkExodusIIReader::NODAL ].size() > 0 )
{
os << indent << "Nodal Arrays:\n";
std::vector<ArrayInfoType>::iterator ai;
for ( ai = this->ArrayInfo[ vtkExodusIIReader::NODAL ].begin(); ai != this->ArrayInfo[ vtkExodusIIReader::NODAL ].end(); ++ai )
{
printArray( os, indent, vtkExodusIIReader::NODAL, *ai );
}
}
// Print blocks
os << indent << "Blocks:\n";
std::map<int,std::vector<BlockInfoType> >::iterator bti;
for ( bti = this->BlockInfo.begin(); bti != this->BlockInfo.end(); ++bti )
{
std::vector<BlockInfoType>::iterator bi;
for ( bi = bti->second.begin(); bi != bti->second.end(); ++bi )
{
printBlock( os, indent.GetNextIndent(), bti->first, *bi );
}
if ( this->ArrayInfo[ bti->first ].size() > 0 )
{
os << indent << " Results variables:\n";
std::vector<ArrayInfoType>::iterator ai;
for ( ai = this->ArrayInfo[ bti->first ].begin(); ai != this->ArrayInfo[ bti->first ].end(); ++ai )
{
printArray( os, indent.GetNextIndent(), bti->first, *ai );
}
}
}
// Print sets
os << indent << "Sets:\n";
std::map<int,std::vector<SetInfoType> >::iterator sti;
for ( sti = this->SetInfo.begin(); sti != this->SetInfo.end(); ++sti )
{
std::vector<SetInfoType>::iterator si;
for ( si = sti->second.begin(); si != sti->second.end(); ++si )
{
printSet( os, indent.GetNextIndent(), sti->first, *si );
}
if ( this->ArrayInfo[ sti->first ].size() > 0 )
{
os << indent << " Results variables:\n";
std::vector<ArrayInfoType>::iterator ai;
for ( ai = this->ArrayInfo[ sti->first ].begin(); ai != this->ArrayInfo[ sti->first ].end(); ++ai )
{
printArray( os, indent.GetNextIndent(), sti->first, *ai );
}
}
}
// Print maps
os << indent << "Maps:\n";
std::map<int,std::vector<MapInfoType> >::iterator mti;
for ( mti = this->MapInfo.begin(); mti != this->MapInfo.end(); ++mti )
{
std::vector<MapInfoType>::iterator mi;
for ( mi = mti->second.begin(); mi != mti->second.end(); ++mi )
{
printMap( os, indent.GetNextIndent(), mti->first, *mi );
}
}
os << indent << "Array Cache:\n";
this->Cache->PrintSelf( os, inden2 );
os << indent << "SqueezePoints: " << this->SqueezePoints << "\n";
os << indent << "ApplyDisplacements: " << this->ApplyDisplacements << "\n";
os << indent << "DisplacementMagnitude: " << this->DisplacementMagnitude << "\n";
os << indent << "GenerateObjectIdArray: " << this->GenerateObjectIdArray << "\n";
os << indent << "GenerateFileIdArray: " << this->GenerateFileIdArray << "\n";
os << indent << "FileId: " << this->FileId << "\n";
}
int vtkExodusIIReaderPrivate::OpenFile( const char* filename )
{
if ( ! filename || ! strlen( filename ) )
{
vtkErrorMacro( "Exodus filename pointer was NULL or pointed to an empty string." );
return 0;
}
if ( this->Exoid >= 0 )
{
this->CloseFile();
}
this->Exoid = ex_open( filename, EX_READ,
&this->AppWordSize, &this->DiskWordSize, &this->ExodusVersion );
if ( this->Exoid <= 0 )
{
vtkErrorMacro( "Unable to open \"" << filename << "\" for reading" );
return 0;
}
int numNodesInFile;
char dummyChar;
float dummyFloat;
ex_inquire(this->Exoid, EX_INQ_NODES, &numNodesInFile, &dummyFloat, &dummyChar);
return 1;
}
int vtkExodusIIReaderPrivate::CloseFile()
{
if ( this->Exoid >= 0 )
{
VTK_EXO_FUNC( ex_close( this->Exoid ), "Could not close an open file (" << this->Exoid << ")" );
this->Exoid = -1;
}
return 0;
}
int vtkExodusIIReaderPrivate::UpdateTimeInformation()
{
int exoid = this->Exoid;
int itmp[5];
int num_timesteps;
VTK_EXO_FUNC( ex_inquire( exoid, EX_INQ_TIME, itmp, 0, 0 ), "Inquire for EX_INQ_TIME failed" );
num_timesteps = itmp[0];
this->Times.clear();
if ( num_timesteps > 0 )
{
this->Times.resize( num_timesteps );
VTK_EXO_FUNC( ex_get_all_times( this->Exoid, &this->Times[0] ), "Could not retrieve time values." );
}
return 0;
}
//-----------------------------------------------------------------------------
void vtkExodusIIReaderPrivate::BuildSIL()
{
// Initialize the SIL, dump all previous information.
this->SIL->Initialize();
if (this->Parser)
{
// The parser has built the SIL for us,
// use that.
this->SIL->ShallowCopy(this->Parser->GetSIL());
return;
}
// Else build a minimal SIL with only the blocks.
vtkSmartPointer<vtkVariantArray> childEdge =
vtkSmartPointer<vtkVariantArray>::New();
childEdge->InsertNextValue(0);
vtkSmartPointer<vtkVariantArray> crossEdge =
vtkSmartPointer<vtkVariantArray>::New();
crossEdge->InsertNextValue(0);
// CrossEdge is an edge linking hierarchies.
vtkUnsignedCharArray* crossEdgesArray = vtkUnsignedCharArray::New();
crossEdgesArray->SetName("CrossEdges");
this->SIL->GetEdgeData()->AddArray(crossEdgesArray);
crossEdgesArray->Delete();
std::deque<std::string> names;
std::deque<vtkIdType> crossEdgeIds; // ids for edges between trees.
int cc;
// Now build the hierarchy.
vtkIdType rootId = this->SIL->AddVertex();
names.push_back("SIL");
// Add the ELEM_BLOCK subtree.
vtkIdType blocksRoot = this->SIL->AddChild(rootId, childEdge);
names.push_back("Blocks");
// Add the assembly subtree
this->SIL->AddChild(rootId, childEdge);
names.push_back("Assemblies");
// Add the materials subtree
this->SIL->AddChild(rootId, childEdge);
names.push_back("Materials");
// This is the map of block names to node ids.
std::map<std::string, vtkIdType> blockids;
int numBlocks = this->GetNumberOfObjectsOfType(vtkExodusIIReader::ELEM_BLOCK);
for (cc=0; cc < numBlocks; cc++)
{
vtkIdType child = this->SIL->AddChild(blocksRoot, childEdge);
std::string block_name =
this->GetObjectName(vtkExodusIIReader::ELEM_BLOCK, cc);
names.push_back(block_name);
blockids[block_name] = child;
}
// This array is used to assign names to nodes.
vtkStringArray* namesArray = vtkStringArray::New();
namesArray->SetName("Names");
namesArray->SetNumberOfTuples(this->SIL->GetNumberOfVertices());
this->SIL->GetVertexData()->AddArray(namesArray);
namesArray->Delete();
std::deque<std::string>::iterator iter;
for (cc=0, iter = names.begin(); iter != names.end(); ++iter, ++cc)
{
namesArray->SetValue(cc, (*iter).c_str());
}
}
//-----------------------------------------------------------------------------
int vtkExodusIIReaderPrivate::RequestInformation()
{
int exoid = this->Exoid;
//int itmp[5];
int* ids;
int nids;
int obj;
int i, j;
int num_timesteps;
char** obj_names;
char** obj_typenames = 0;
char** var_names = 0;
int have_var_names;
int num_vars = 0; /* number of variables per object */
char tmpName[256];
tmpName[255] = '\0';
this->InformationTimeStamp.Modified(); // Update MTime so that it will be newer than parent's FileNameMTime
VTK_EXO_FUNC( ex_get_init_ext( exoid, &this->ModelParameters ),
"Unable to read database parameters." );
VTK_EXO_FUNC( this->UpdateTimeInformation(), "" );
//VTK_EXO_FUNC( ex_inquire( exoid, EX_INQ_TIME, itmp, 0, 0 ), "Inquire for EX_INQ_TIME failed" );
//num_timesteps = itmp[0];
std::vector<BlockInfoType> bitBlank;
std::vector<SetInfoType> sitBlank;
std::vector<MapInfoType> mitBlank;
std::vector<ArrayInfoType> aitBlank;
num_timesteps = static_cast<int>( this->Times.size() );
/*
this->Times.clear();
if ( num_timesteps > 0 )
{
this->Times.resize( num_timesteps );
VTK_EXO_FUNC( ex_get_all_times( this->Exoid, &this->Times[0] ), "Could not retrieve time values." );
}
*/
for ( i = 0; i < num_obj_types; ++i )
{
if(OBJTYPE_IS_NODAL(i))
{
continue;
}
vtkIdType blockEntryFileOffset = 1;
vtkIdType setEntryFileOffset = 1;
std::map<int,int> sortedObjects;
int* truth_tab = 0;
have_var_names = 0;
VTK_EXO_FUNC( ex_inquire( exoid, obj_sizes[i], &nids, 0, 0 ), "Object ID list size could not be determined." );
if ( nids )
{
ids = (int*) malloc( nids * sizeof(int) );
obj_names = (char**) malloc( nids * sizeof(char*) );
for ( obj = 0; obj < nids; ++obj )
obj_names[obj] = (char*) malloc( (MAX_STR_LENGTH + 1) * sizeof(char) );
if ( OBJTYPE_IS_BLOCK(i) )
{
obj_typenames = (char**) malloc( nids * sizeof(char*) );
for ( obj = 0; obj < nids; ++obj )
{
obj_typenames[obj] = (char*) malloc( (MAX_STR_LENGTH + 1) * sizeof(char) );
obj_typenames[obj][0] = '\0';
}
}
}
else
{
ids = 0;
obj_names = 0;
obj_typenames = 0;
}
if ( nids == 0 && ! OBJTYPE_IS_MAP(i) )
continue;
if ( nids )
{
VTK_EXO_FUNC( ex_get_ids( exoid, static_cast<ex_entity_type>( obj_types[i] ), ids ),
"Could not read object ids for i=" << i << " and otyp=" << obj_types[i] << "." );
VTK_EXO_FUNC( ex_get_names( exoid, static_cast<ex_entity_type>( obj_types[i] ), obj_names ),
"Could not read object names." );
}
BlockInfoType binfo;
SetInfoType sinfo;
MapInfoType minfo;
if ( OBJTYPE_IS_BLOCK(i) )
{
this->BlockInfo[obj_types[i]] = bitBlank;
this->BlockInfo[obj_types[i]].reserve( nids );
}
else if ( OBJTYPE_IS_SET(i) )
{
this->SetInfo[obj_types[i]] = sitBlank;
this->SetInfo[obj_types[i]].reserve( nids );
}
else
{
this->MapInfo[obj_types[i]] = mitBlank;
this->MapInfo[obj_types[i]].reserve( nids );
}
if ( (OBJTYPE_IS_BLOCK(i)) || (OBJTYPE_IS_SET(i)))
{
VTK_EXO_FUNC( ex_get_var_param( exoid, obj_typestr[i], &num_vars ), "Could not read number of variables." );
if (num_vars && num_timesteps > 0)
{
truth_tab = (int*) malloc(num_vars * nids * sizeof(int));
VTK_EXO_FUNC( ex_get_var_tab( exoid, obj_typestr[i], nids, num_vars, truth_tab ), "Could not read truth table." );
var_names = (char**) malloc(num_vars * sizeof(char*));
for (j = 0; j < num_vars; ++j)
var_names[j] = (char*) malloc( (MAX_STR_LENGTH + 1) * sizeof(char));
VTK_EXO_FUNC( ex_get_var_names( exoid, obj_typestr[i], num_vars, var_names ), "Could not read variable names." );
this->RemoveBeginningAndTrailingSpaces(num_vars, var_names);
have_var_names = 1;
}
}
if ( !have_var_names)
var_names = 0;
for (obj = 0; obj < nids; ++obj)
{
if ( OBJTYPE_IS_BLOCK(i))
{
binfo.Name = obj_names[obj];
binfo.Id = ids[obj];
binfo.CachedConnectivity = 0;
binfo.NextSqueezePoint = 0;
if (obj_types[i] == vtkExodusIIReader::ELEM_BLOCK)
{
VTK_EXO_FUNC( ex_get_block( exoid, static_cast<ex_entity_type>( obj_types[i] ), ids[obj], obj_typenames[obj],
&binfo.Size, &binfo.BdsPerEntry[0], &binfo.BdsPerEntry[1], &binfo.BdsPerEntry[2], &binfo.AttributesPerEntry ),
"Could not read block params." );
binfo.Status = 1; // load element blocks by default
binfo.TypeName = obj_typenames[obj];
}
else
{
VTK_EXO_FUNC( ex_get_block( exoid, static_cast<ex_entity_type>( obj_types[i] ), ids[obj], obj_typenames[obj],
&binfo.Size, &binfo.BdsPerEntry[0], &binfo.BdsPerEntry[1], &binfo.BdsPerEntry[2], &binfo.AttributesPerEntry ),
"Could not read block params." );
binfo.Status = 0; // don't load edge/face blocks by default
binfo.TypeName = obj_typenames[obj];
binfo.BdsPerEntry[1] = binfo.BdsPerEntry[2] = 0;
}
this->GetInitialObjectStatus(obj_types[i], &binfo);
//num_entries = binfo.Size;
binfo.FileOffset = blockEntryFileOffset;
blockEntryFileOffset += binfo.Size;
if (binfo.Name.length() == 0)
{
SNPRINTF( tmpName, 255, "Unnamed block ID: %d Type: %s",
ids[obj], binfo.TypeName.length() ? binfo.TypeName.c_str() : "NULL");
binfo.Name = tmpName;
}
binfo.OriginalName = binfo.Name;
this->DetermineVtkCellType(binfo);
if (binfo.AttributesPerEntry)
{
char** attr_names;
attr_names
= (char**) malloc(binfo.AttributesPerEntry * sizeof(char*));
for (j = 0; j < binfo.AttributesPerEntry; ++j)
attr_names[j]
= (char*) malloc( (MAX_STR_LENGTH + 1) * sizeof(char));
VTK_EXO_FUNC( ex_get_attr_names( exoid, static_cast<ex_entity_type>( obj_types[i] ), ids[obj], attr_names ),
"Could not read attributes names." );
for (j = 0; j < binfo.AttributesPerEntry; ++j)
{
binfo.AttributeNames.push_back(attr_names[j]);
binfo.AttributeStatus.push_back( 0); // don't load attributes by default
}
for (j = 0; j < binfo.AttributesPerEntry; ++j)
free(attr_names[j]);
free(attr_names);
}
// Check to see if there is metadata that defines what part, material,
// and assembly(ies) this block belongs to.
if (this->Parser && this->Parser->HasInformationAboutBlock(binfo.Id))
{
// Update the block name using the XML.
binfo.Name = this->Parser->GetBlockName(binfo.Id);
// int blockIdx = static_cast<int>( this->BlockInfo[obj_types[i]].size() );
//// Add this block to our parts, materials, and assemblies collections
//unsigned int k;
//int found = 0;
//// Look to see if this part has already been created
//for (k=0;k<this->PartInfo.size();k++)
// {
// if (this->PartInfo[k].Name==partName)
// {
// //binfo.PartId = k;
// this->PartInfo[k].BlockIndices.push_back(blockIdx);
// found=1;
// }
// }
//if (!found)
// {
// PartInfoType pinfo;
// pinfo.Name = partName;
// pinfo.Id = static_cast<int>( this->PartInfo.size() );
// //binfo.PartId = k;
// pinfo.BlockIndices.push_back(blockIdx);
// this->PartInfo.push_back(pinfo);
// }
//
//found=0;
//for (k=0;k<this->MaterialInfo.size();k++)
// {
// if (this->MaterialInfo[k].Name==materialName)
// {
// //binfo.MaterialId = k;
// this->MaterialInfo[k].BlockIndices.push_back(blockIdx);
// found=1;
// }
// }
//if (!found)
// {
// MaterialInfoType matinfo;
// matinfo.Name = materialName;
// matinfo.Id = static_cast<int>( this->MaterialInfo.size() );
// //binfo.MaterialId = k;
// matinfo.BlockIndices.push_back(blockIdx);
// this->MaterialInfo.push_back(matinfo);
// }
//
//for (k=0;k<localAssemblyNames.size();k++)
// {
// vtkStdString assemblyName=localAssemblyNames[k];
// found=0;
// for (unsigned int n=0;n<this->AssemblyInfo.size();n++)
// {
// if (this->AssemblyInfo[n].Name==assemblyName){
// //binfo.AssemblyIds.push_back(j);
// this->AssemblyInfo[n].BlockIndices.push_back(blockIdx);
// found=1;
// }
// }
// if (!found)
// {
// AssemblyInfoType ainfo;
// ainfo.Name = assemblyName;
// ainfo.Id = static_cast<int>( this->AssemblyInfo.size() );
// //binfo.AssemblyIds.push_back(k);
// ainfo.BlockIndices.push_back(blockIdx);
// this->AssemblyInfo.push_back(ainfo);
// }
// }
}
sortedObjects[binfo.Id]
= static_cast<int>(this->BlockInfo[obj_types[i]].size());
this->BlockInfo[obj_types[i]].push_back(binfo);
}
else if ( OBJTYPE_IS_SET(i))
{
sinfo.Name = obj_names[obj];
sinfo.Status = 0;
sinfo.Id = ids[obj];
sinfo.CachedConnectivity = 0;
sinfo.NextSqueezePoint = 0;
VTK_EXO_FUNC( ex_get_set_param( exoid, static_cast<ex_entity_type>( obj_types[i] ), ids[obj], &sinfo.Size, &sinfo.DistFact),
"Could not read set parameters." );
//num_entries = sinfo.Size;
sinfo.FileOffset = setEntryFileOffset;
setEntryFileOffset += sinfo.Size;
this->GetInitialObjectStatus(obj_types[i], &sinfo);
if (sinfo.Name.length() == 0)
{
SNPRINTF( tmpName, 255, "Unnamed set ID: %d", ids[obj]);
sinfo.Name = tmpName;
}
sortedObjects[sinfo.Id] = (int) this->SetInfo[obj_types[i]].size();
this->SetInfo[obj_types[i]].push_back(sinfo);
}
else
{ /* object is map */
minfo.Id = ids[obj];
minfo.Status = obj == 0 ? 1 : 0; // only load the first map by default
switch (obj_types[i])
{
case vtkExodusIIReader::NODE_MAP:
minfo.Size = this->ModelParameters.num_nodes;
break;
case vtkExodusIIReader::EDGE_MAP:
minfo.Size = this->ModelParameters.num_edge;
break;
case vtkExodusIIReader::FACE_MAP:
minfo.Size = this->ModelParameters.num_face;
break;
case vtkExodusIIReader::ELEM_MAP:
minfo.Size = this->ModelParameters.num_elem;
break;
default:
minfo.Size = 0;
}
minfo.Name = obj_names[obj];
if (minfo.Name.length() == 0)
{ // make up a name. FIXME: Possible buffer overflow w/ sprintf
SNPRINTF( tmpName, 255, "Unnamed map ID: %d", ids[obj] );
minfo.Name = tmpName;
}
sortedObjects[minfo.Id] = (int) this->MapInfo[obj_types[i]].size();
this->MapInfo[obj_types[i]].push_back(minfo);
}
} // end of loop over all object ids
// Now that we have all objects of that type in the sortedObjects, we can
// iterate over it to fill in the SortedObjectIndices (the map is a *sorted*
// associative container)
std::map<int,int>::iterator soit;
for ( soit = sortedObjects.begin(); soit != sortedObjects.end(); ++soit )
{
this->SortedObjectIndices[obj_types[i]].push_back( soit->second );
}
if ( ((OBJTYPE_IS_BLOCK(i)) || (OBJTYPE_IS_SET(i))) && num_vars && num_timesteps > 0 )
{
this->ArrayInfo[obj_types[i]] = aitBlank;
// Fill in ArrayInfo entries, combining array names into vectors/tensors where appropriate:
this->GlomArrayNames( obj_types[i], nids, num_vars, var_names, truth_tab );
}
if ( var_names )
{
for ( j = 0; j < num_vars; ++j )
free( var_names[j] );
free( var_names );
}
if ( truth_tab )
free( truth_tab );
if ( nids )
{
free( ids );
for ( obj = 0; obj < nids; ++obj )
free( obj_names[obj] );
free( obj_names );
if ( OBJTYPE_IS_BLOCK(i) )
{
for ( obj = 0; obj < nids; ++obj )
free( obj_typenames[obj] );
free( obj_typenames );
}
}
} // end of loop over all object types
//this->ComputeGridOffsets();
// Now read information for nodal arrays
VTK_EXO_FUNC( ex_get_var_param( exoid, "n", &num_vars ), "Unable to read number of nodal variables." );
if ( num_vars > 0 )
{
ArrayInfoType ainfo;
var_names = (char**) malloc( num_vars * sizeof(char*) );
for ( j = 0; j < num_vars; ++j )
var_names[j] = (char*) malloc( (MAX_STR_LENGTH + 1) * sizeof(char) );
VTK_EXO_FUNC( ex_get_var_names( exoid, "n", num_vars, var_names ), "Could not read nodal variable names." );
this->RemoveBeginningAndTrailingSpaces( num_vars, var_names );
nids = 1;
std::vector<int> dummy_truth;
dummy_truth.reserve( num_vars );
for ( j = 0; j < num_vars; ++j )
{
dummy_truth.push_back( 1 );
}
this->GlomArrayNames( vtkExodusIIReader::NODAL, nids, num_vars, var_names, &dummy_truth[0] );
for ( j = 0; j < num_vars; ++j )
{
free( var_names[j] );
}
free( var_names );
var_names = 0;
}
// Now read information for global variables
VTK_EXO_FUNC( ex_get_var_param( exoid, "g", &num_vars ), "Unable to read number of global variables." );
if ( num_vars > 0 )
{
ArrayInfoType ainfo;
var_names = (char**) malloc( num_vars * sizeof(char*) );
for ( j = 0; j < num_vars; ++j )
var_names[j] = (char*) malloc( (MAX_STR_LENGTH + 1) * sizeof(char) );
VTK_EXO_FUNC( ex_get_var_names( exoid, "g", num_vars, var_names ), "Could not read global variable names." );
this->RemoveBeginningAndTrailingSpaces( num_vars, var_names );
nids = 1;
std::vector<int> dummy_truth;
dummy_truth.reserve( num_vars );
for ( j = 0; j < num_vars; ++j )
{
dummy_truth.push_back( 1 );
}
this->GlomArrayNames( vtkExodusIIReader::GLOBAL, nids, num_vars, var_names, &dummy_truth[0] );
for ( j = 0; j < num_vars; ++j )
{
free( var_names[j] );
}
free( var_names );
var_names = 0;
}
return 0;
}
int vtkExodusIIReaderPrivate::RequestData( vtkIdType timeStep, vtkMultiBlockDataSet* output )
{
// The work done here depends on several conditions:
// - Has connectivity changed (i.e., has block/set status changed)?
// - If so, AND if point "squeeze" turned on, must reload points and re-squeeze.
// - If so, must re-assemble all arrays
// - Must recreate block/set id array.
// - Has requested time changed?
// - If so, AND if "deflect mesh" turned on, must load new deflections and compute new points.
// - If so, must assemble all time-varying arrays for new time.
// - Has array status changed?
// - If so, must delete old and/or load new arrays.
// Obviously, many of these tasks overlap. For instance, it would be
// foolish to re-assemble all the arrays when the connectivity has
// changed and then toss them out in order to load arrays for a
// different time step.
// Caching strategy: use GLOBAL "object type" for assembled arrays.
// If connectivity hasn't changed, then these arrays can be used;
// otherwise, "raw" arrays must be used.
// Pro:
// - single cache == easier bookkeeping (two caches would require us to decide how to equitably split avail mem between them)
// - many different operations are accelerated:
// - just changing which variables are loaded
// - changing which blocks are in output (doesn't require disk access if cache hit)
// - possible extension to single-node/cell over time
// Con:
// - higher memory consumption for caching the same set of arrays (or, holding cache size fixed: fewer arrays fit)
if ( ! output )
{
vtkErrorMacro( "You must specify an output mesh" );
}
// Iterate over all block and set types, creating a
// multiblock dataset to hold objects of each type.
int conntypidx;
int nbl = 0;
output->SetNumberOfBlocks( num_conn_types );
for ( conntypidx = 0; conntypidx < num_conn_types; ++conntypidx )
{
int otypidx = conn_obj_idx_cvt[conntypidx];
int otyp = obj_types[otypidx];
// Loop over all blocks/sets of this type
int numObj = this->GetNumberOfObjectsOfType( otyp );
vtkMultiBlockDataSet* mbds;
mbds = vtkMultiBlockDataSet::New();
mbds->SetNumberOfBlocks( numObj );
output->SetBlock( conntypidx, mbds );
output->GetMetaData(conntypidx)->Set(vtkCompositeDataSet::NAME(),
conn_types_names[conntypidx]);
mbds->FastDelete();
//cout << "++ Block: " << mbds << " ObjectType: " << otyp << "\n";
int obj;
int sortIdx;
for ( sortIdx = 0; sortIdx < numObj; ++sortIdx )
{
const char* object_name = this->GetObjectName(otyp, sortIdx);
// Preserve the "sorted" order when concatenating
obj = this->SortedObjectIndices[otyp][sortIdx];
BlockSetInfoType* bsinfop = static_cast<BlockSetInfoType*>( this->GetObjectInfo( otypidx, obj ) );
//cout << ( bsinfop->Status ? "++" : "--" ) << " ObjectId: " << bsinfop->Id;
if ( ! bsinfop->Status )
{
mbds->SetBlock( sortIdx, 0 );
if (object_name)
{
mbds->GetMetaData(sortIdx)->Set(vtkCompositeDataSet::NAME(), object_name);
}
continue;
}
vtkUnstructuredGrid* ug = vtkUnstructuredGrid::New();
mbds->SetBlock( sortIdx, ug );
if (object_name)
{
mbds->GetMetaData(sortIdx)->Set(vtkCompositeDataSet::NAME(), object_name);
}
ug->FastDelete();
//cout << " Grid: " << ug << "\n";
// Connectivity first. Either from the cache in bsinfop or read from disk.
// Connectivity isn't allowed to change with time.
this->AssembleOutputConnectivity( timeStep, otyp, obj, conntypidx, bsinfop, ug );
// Now prepare points.
// These shouldn't change unless the connectivity has changed.
this->AssembleOutputPoints( timeStep, bsinfop, ug );
// Then, add the desired arrays from cache (or disk)
// Point and cell arrays are handled differently because they
// have different problems to solve.
// Point arrays must use the PointMap index to subset values.
// Cell arrays may be used as-is.
this->AssembleOutputPointArrays( timeStep, bsinfop, ug );
this->AssembleOutputCellArrays( timeStep, otyp, obj, bsinfop, ug );
// Some arrays may be procedurally generated (e.g., the ObjectId
// array, global element and node number arrays). This constructs
// them as required.
this->AssembleOutputProceduralArrays( timeStep, otyp, obj, ug );
// QA and informational records in the ExodusII file are appended
// to each and every output unstructured grid.
this->AssembleOutputGlobalArrays( timeStep, otyp, obj, bsinfop, ug );
// Maps (as distinct from the global element and node arrays above)
// are per-cell or per-node integers. As with point arrays, the
// PointMap is used to subset node maps. Cell arrays are stored in
// ExodusII files for all elements (across all blocks of a given type)
// and thus must be subset for the unstructured grid of interest.
this->AssembleOutputPointMaps( timeStep, bsinfop, ug );
this->AssembleOutputCellMaps( timeStep, otyp, obj, bsinfop, ug );
++nbl;
}
}
// Pack temporal data onto output field data arrays if fast path.
// option is available:
this->ProducedFastPathOutput = (this->AssembleArraysOverTime(output) != 0);
this->CloseFile();
return 0;
}
int vtkExodusIIReaderPrivate::SetUpEmptyGrid( vtkMultiBlockDataSet* output )
{
if ( ! output )
{
vtkErrorMacro( "You must specify an output mesh" );
}
// Iterate over all block and set types, creating a
// multiblock dataset to hold objects of each type.
int conntypidx;
int nbl = 0;
output->SetNumberOfBlocks( num_conn_types );
for ( conntypidx = 0; conntypidx < num_conn_types; ++conntypidx )
{
int otypidx = conn_obj_idx_cvt[conntypidx];
int otyp = obj_types[otypidx];
// Loop over all blocks/sets of this type
int numObj = this->GetNumberOfObjectsOfType( otyp );
vtkMultiBlockDataSet* mbds;
mbds = vtkMultiBlockDataSet::New();
mbds->SetNumberOfBlocks( numObj );
output->SetBlock( conntypidx, mbds );
mbds->FastDelete();
int obj;
int sortIdx;
for ( sortIdx = 0; sortIdx < numObj; ++sortIdx )
{
// Preserve the "sorted" order when concatenating
obj = this->SortedObjectIndices[otyp][sortIdx];
BlockSetInfoType* bsinfop = static_cast<BlockSetInfoType*>( this->GetObjectInfo( otypidx, obj ) );
//cout << ( bsinfop->Status ? "++" : "--" ) << " ObjectId: " << bsinfop->Id;
if ( ! bsinfop->Status )
{
//cout << "\n";
mbds->SetBlock( sortIdx, 0 );
continue;
}
vtkUnstructuredGrid* ug = vtkUnstructuredGrid::New();
mbds->SetBlock( sortIdx, ug );
ug->FastDelete();
++nbl;
}
}
#if 0
int idx;
vtkUnstructuredGrid* leaf;
// Set up an empty unstructured grid
leaf->Allocate(0);
// Create new points
vtkPoints* newPoints = vtkPoints::New();
newPoints->SetNumberOfPoints( 0 );
leaf->SetPoints( newPoints );
newPoints->Delete();
newPoints = NULL;
// Create point and cell arrays
int typ;
for ( typ = 0; typ < numObjResultTypes; ++typ )
{
int otyp = objResultTypes[typ];
int nObjArr = this->GetNumberOfObjectArrays( otyp );
for ( idx = 0; idx < nObjArr; ++idx )
{
vtkDoubleArray* da = vtkDoubleArray::New();
da->SetName( this->GetObjectArrayName( otyp, idx ) );
da->SetNumberOfComponents( this->GetNumberOfObjectArrayComponents( otyp, idx ) );
if ( otyp == vtkExodusIIReader::NODAL )
{
leaf->GetPointData()->AddArray( da );
}
else
{
leaf->GetCellData()->AddArray( da );
}
da->FastDelete();
}
}
for ( typ = 0; typ < numObjAttribTypes; ++typ )
{
int otyp = objAttribTypes[typ];
int nObj = this->GetNumberOfObjects( otyp );
for ( idx = 0; idx < nObj; ++ idx )
{
// Attributes are defined per block, not per block type.
int nObjAtt = this->GetNumberOfObjectAttributes( otyp, idx );
for ( int aidx = 0; aidx < nObjAtt; ++ aidx )
{
vtkDoubleArray* da = vtkDoubleArray::New();
da->SetName( this->GetObjectAttributeName( otyp, idx, aidx ) );
da->SetNumberOfComponents( 1 );
// All attributes are cell data
leaf->GetCellData()->AddArray( da );
da->FastDelete();
}
}
}
if ( this->GetGenerateObjectIdCellArray() )
{
vtkIntArray* ia = vtkIntArray::New();
ia->SetName( this->GetObjectIdArrayName() );
ia->SetNumberOfComponents( 1 );
leaf->GetCellData()->AddArray( ia );
ia->FastDelete();
}
if ( this->GetGenerateGlobalNodeIdArray() )
{
vtkIntArray* ia = vtkIntArray::New();
ia->SetName( this->GetGlobalNodeIdArrayName() );
ia->SetNumberOfComponents( 1 );
leaf->GetPointData()->AddArray( ia );
ia->FastDelete();
}
if ( this->GetGenerateGlobalElementIdArray() )
{
vtkIntArray* ia = vtkIntArray::New();
ia->SetName( this->GetGlobalElementIdArrayName() );
ia->SetNumberOfComponents( 1 );
leaf->GetCellData()->AddArray( ia );
ia->FastDelete();
}
#endif // 0
return 1;
}
void vtkExodusIIReaderPrivate::Reset()
{
this->CloseFile();
this->ResetCache(); // must come before BlockInfo and SetInfo are cleared.
this->BlockInfo.clear();
this->SetInfo.clear();
this->MapInfo.clear();
this->PartInfo.clear();
this->MaterialInfo.clear();
this->AssemblyInfo.clear();
this->SortedObjectIndices.clear();
this->ArrayInfo.clear();
this->ExodusVersion = -1.;
this->Times.clear();
this->TimeStep = 0;
memset( (void*)&this->ModelParameters, 0, sizeof(this->ModelParameters) );
this->FastPathObjectId = -1;
// Don't clear file id since it's not part of meta-data that's read from the
// file, it's set externally (by vtkPExodusIIReader).
// Refer to BUG #7633.
//this->FileId = 0;
this->Modified();
}
void vtkExodusIIReaderPrivate::ResetSettings()
{
this->GenerateGlobalElementIdArray = 0;
this->GenerateGlobalNodeIdArray = 0;
this->GenerateImplicitElementIdArray = 0;
this->GenerateImplicitNodeIdArray = 0;
this->GenerateGlobalIdArray = 0;
this->GenerateObjectIdArray = 1;
this->GenerateFileIdArray = 0;
this->ApplyDisplacements = 1;
this->DisplacementMagnitude = 1.;
this->HasModeShapes = 0;
this->ModeShapeTime = -1.;
this->AnimateModeShapes = 1;
this->SqueezePoints = 1;
this->InitialArrayInfo.clear();
this->InitialObjectInfo.clear();
this->FastPathObjectType = vtkExodusIIReader::NODAL;
this->FastPathObjectId = -1;
this->SetFastPathIdType( 0 );
}
void vtkExodusIIReaderPrivate::ResetCache()
{
this->Cache->Clear();
this->Cache->SetCacheCapacity(this->CacheSize); // FIXME: Perhaps Cache should have a Reset and a Clear method?
this->ClearConnectivityCaches();
}
void vtkExodusIIReaderPrivate::SetCacheSize( double size )
{
if (this->CacheSize != size)
{
this->CacheSize = size;
this->Cache->SetCacheCapacity(this->CacheSize);
this->Modified();
}
}
bool vtkExodusIIReaderPrivate::IsXMLMetadataValid()
{
// Make sure that each block id referred to in the metadata arrays exist
// in the data
std::set<int> blockIdsFromXml;
this->Parser->GetBlockIds(blockIdsFromXml);
std::vector<BlockInfoType> blocksFromData = this->BlockInfo[vtkExodusIIReader::ELEM_BLOCK];
std::vector<BlockInfoType>::iterator iter2;
std::set<int>::iterator iter;
bool isBlockValid = false;
for(iter = blockIdsFromXml.begin(); iter!=blockIdsFromXml.end(); ++iter)
{
isBlockValid = false;
for(iter2 = blocksFromData.begin(); iter2!=blocksFromData.end(); ++iter2)
{
if(*iter == (*iter2).Id)
{
isBlockValid = true;
break;
}
}
if(!isBlockValid)
{
break;
}
}
return isBlockValid;
}
void vtkExodusIIReaderPrivate::SetSqueezePoints( int sp )
{
if ( this->SqueezePoints == sp )
return;
this->SqueezePoints = sp;
this->Modified();
// Invalidate global "topology" cache
// The point maps should be invalidated
// FIXME: bsinfop->NextSqueezePoint = 0 for all bsinfop
// FIXME: bsinfop->CachedConnectivity = 0 for all bsinfop
// FIXME: bsinfop->PointMap.clear() for all bsinfop
// FIXME: bsinfop->ReversePointMap.clear() for all bsinfop
}
int vtkExodusIIReaderPrivate::GetNumberOfNodes()
{
return this->ModelParameters.num_nodes;
}
int vtkExodusIIReaderPrivate::GetNumberOfObjectsOfType( int otyp )
{
int i = this->GetObjectTypeIndexFromObjectType( otyp );
if ( i < 0 )
{
// Could signal warning here, but might not want it if file simply doesn't have objects of some obscure type (e.g., edge sets)
return 0;
}
return this->GetNumberOfObjectsAtTypeIndex( i );
}
int vtkExodusIIReaderPrivate::GetNumberOfObjectArraysOfType( int otyp )
{
std::map<int,std::vector<ArrayInfoType> >::iterator it = this->ArrayInfo.find( otyp );
if ( it != this->ArrayInfo.end() )
{
return (int) it->second.size();
}
// Could signal warning here, but might not want it if file simply doesn't have objects of some obscure type (e.g., edge sets)
return 0;
}
const char* vtkExodusIIReaderPrivate::GetObjectName( int otyp, int k )
{
ObjectInfoType* oinfop = this->GetSortedObjectInfo( otyp, k );
return oinfop ? oinfop->Name.c_str() : 0;
}
int vtkExodusIIReaderPrivate::GetObjectId( int otyp, int k )
{
ObjectInfoType* oinfop = this->GetSortedObjectInfo( otyp, k );
return oinfop ? oinfop->Id : -1;
}
int vtkExodusIIReaderPrivate::GetObjectSize( int otyp, int k )
{
ObjectInfoType* oinfop = this->GetSortedObjectInfo( otyp, k );
return oinfop ? oinfop->Size : 0;
}
int vtkExodusIIReaderPrivate::GetObjectStatus( int otyp, int k )
{
ObjectInfoType* oinfop = this->GetSortedObjectInfo( otyp, k );
return oinfop ? oinfop->Status : 0;
}
int vtkExodusIIReaderPrivate::GetUnsortedObjectStatus( int otyp, int k )
{
ObjectInfoType* oinfop = this->GetUnsortedObjectInfo( otyp, k );
return oinfop ? oinfop->Status : 0;
}
void vtkExodusIIReaderPrivate::GetInitialObjectStatus( int otyp, ObjectInfoType *objType )
{
for(unsigned int oidx=0; oidx<this->InitialObjectInfo[otyp].size(); oidx++)
{
if( (this->InitialObjectInfo[otyp][oidx].Name != "" &&
objType->Name == this->InitialObjectInfo[otyp][oidx].Name) ||
(this->InitialObjectInfo[otyp][oidx].Id != -1 &&
objType->Id == this->InitialObjectInfo[otyp][oidx].Id) )
{
objType->Status = this->InitialObjectInfo[otyp][oidx].Status;
break;
}
}
}
void vtkExodusIIReaderPrivate::SetObjectStatus( int otyp, int k, int stat )
{
stat = (stat != 0); // Force stat to be either 0 or 1
// OK, found the object
ObjectInfoType* oinfop = this->GetSortedObjectInfo( otyp, k );
if ( ! oinfop )
{ // error message will have been generated by GetSortedObjectInfo()
return;
}
if ( oinfop->Status == stat )
{ // no change => do nothing
return;
}
oinfop->Status = stat;
this->Modified();
}
void vtkExodusIIReaderPrivate::SetUnsortedObjectStatus( int otyp, int k, int stat )
{
stat = (stat != 0); // Force stat to be either 0 or 1
// OK, found the object
ObjectInfoType* oinfop = this->GetUnsortedObjectInfo( otyp, k );
if ( ! oinfop )
{ // error message will have been generated by GetSortedObjectInfo()
return;
}
if ( oinfop->Status == stat )
{ // no change => do nothing
return;
}
oinfop->Status = stat;
this->Modified();
}
void vtkExodusIIReaderPrivate::SetInitialObjectStatus( int objectType, const char* objName, int status )
{
ObjectInfoType info;
vtkStdString nm = objName;
int idx = 0;
int idlen = 0;
int id = -1;
// When no name is found for an object, it is given one of a certain format.
// Parse the id out of that string and use it to identify the object later.
if ( ( idx = static_cast<int>( nm.find( "ID: " ) ) ) != (int) vtkStdString::npos )
{
idx += 4;
idlen = 0;
while(idx+idlen < static_cast<int>(nm.length()) && nm.at(idx+idlen) != ' ' )
{
idlen++;
}
id = atoi(nm.substr(idx,idlen).c_str());
}
else
{
info.Name = objName;
}
info.Id = id;
info.Status = status;
this->InitialObjectInfo[objectType].push_back(info);
}
const char* vtkExodusIIReaderPrivate::GetObjectArrayName( int otyp, int i )
{
std::map<int,std::vector<ArrayInfoType> >::iterator it = this->ArrayInfo.find( otyp );
if ( it != this->ArrayInfo.end() )
{
int N = (int) it->second.size();
if ( i < 0 || i >= N )
{
vtkDebugMacro( "You requested array " << i << " in a collection of only " << N << " arrays." );
return 0;
}
return it->second[i].Name.c_str();
}
vtkDebugMacro( "Could not find collection of arrays for objects of type " << otyp <<
" (" << objtype_names[this->GetObjectTypeIndexFromObjectType(otyp)] << ")." );
return 0;
}
int vtkExodusIIReaderPrivate::GetNumberOfObjectArrayComponents( int otyp, int i )
{
std::map<int,std::vector<ArrayInfoType> >::iterator it = this->ArrayInfo.find( otyp );
if ( it != this->ArrayInfo.end() )
{
int N = (int) it->second.size();
if ( i < 0 || i >= N )
{
vtkDebugMacro( "You requested array " << i << " in a collection of only " << N << " arrays." );
return 0;
}
return it->second[i].Components;
}
vtkDebugMacro( "Could not find collection of arrays for objects of type " << otyp <<
" (" << objtype_names[this->GetObjectTypeIndexFromObjectType(otyp)] << ")." );
return 0;
}
int vtkExodusIIReaderPrivate::GetObjectArrayStatus( int otyp, int i )
{
std::map<int,std::vector<ArrayInfoType> >::iterator it = this->ArrayInfo.find( otyp );
if ( it != this->ArrayInfo.end() )
{
int N = (int) it->second.size();
if ( i < 0 || i >= N )
{
vtkDebugMacro( "You requested array " << i << " in a collection of only " << N << " arrays." );
return 0;
}
return it->second[i].Status;
}
vtkDebugMacro( "Could not find collection of arrays for objects of type " << otyp <<
" (" << objtype_names[this->GetObjectTypeIndexFromObjectType(otyp)] << ")." );
return 0;
}
void vtkExodusIIReaderPrivate::GetInitialObjectArrayStatus( int otyp, ArrayInfoType *objType )
{
for(unsigned int oidx=0; oidx<this->InitialArrayInfo[otyp].size(); oidx++)
{
if(objType->Name == this->InitialArrayInfo[otyp][oidx].Name)
{
objType->Status = this->InitialArrayInfo[otyp][oidx].Status;
break;
}
}
}
void vtkExodusIIReaderPrivate::SetObjectArrayStatus( int otyp, int i, int stat )
{
stat = ( stat != 0 ); // Force stat to be either 0 or 1
std::map<int,std::vector<ArrayInfoType> >::iterator it = this->ArrayInfo.find( otyp );
if ( it != this->ArrayInfo.end() )
{
int N = (int) it->second.size();
if ( i < 0 || i >= N )
{
vtkDebugMacro( "You requested array " << i << " in a collection of only " << N << " arrays." );
return;
}
if ( it->second[i].Status == stat )
{
// no change => do nothing
return;
}
it->second[i].Status = stat;
this->Modified();
// FIXME: Mark something so we know what's changed since the last RequestData?!
// For the "global" (assembled) array, this is tricky because we really only want
// to invalidate a range of the total array... For now, we'll just force the "global"
// array to be reassembled even if it does mean a lot more copying -- it's not like
// it was any faster before.
//vtkExodusIICacheKey key( 0, GLOBAL, 0, i );
//vtkExodusIICacheKey pattern( 0, 1, 0, 1 );
this->Cache->Invalidate(
vtkExodusIICacheKey( 0, vtkExodusIIReader::GLOBAL, otyp, i ),
vtkExodusIICacheKey( 0, 1, 1, 1 ) );
}
else
{
vtkDebugMacro( "Could not find collection of arrays for objects of type " << otyp <<
" (" << objtype_names[this->GetObjectTypeIndexFromObjectType(otyp)] << ")." );
}
}
void vtkExodusIIReaderPrivate::SetInitialObjectArrayStatus( int objectType, const char* arrayName, int status )
{
ArrayInfoType ainfo;
ainfo.Name = arrayName;
ainfo.Status = status;
this->InitialArrayInfo[objectType].push_back(ainfo);
}
int vtkExodusIIReaderPrivate::GetNumberOfObjectAttributes( int otyp, int oi )
{
std::map<int,std::vector<BlockInfoType> >::iterator it = this->BlockInfo.find( otyp );
if ( it != this->BlockInfo.end() )
{
int N = (int) it->second.size();
if ( oi < 0 || oi >= N )
{
int otypIdx = this->GetObjectTypeIndexFromObjectType(otyp);
const char* btname = otypIdx >= 0 ? objtype_names[otypIdx] : "block";
static_cast<void>(btname); // not referenced warning
vtkDebugMacro( "You requested " << btname << " " << oi << " in a collection of only " << N << " blocks." );
return 0;
}
oi = this->SortedObjectIndices[otyp][oi]; // index into sorted list of objects (block order, not file order)
return (int) it->second[oi].AttributeNames.size();
}
return 0;
}
const char* vtkExodusIIReaderPrivate::GetObjectAttributeName( int otyp, int oi, int ai )
{
std::map<int,std::vector<BlockInfoType> >::iterator it = this->BlockInfo.find( otyp );
if ( it != this->BlockInfo.end() )
{
int N = (int) it->second.size();
if ( oi < 0 || oi >= N )
{
vtkDebugMacro( "You requested block " << oi << " in a collection of only " << N << " blocks." );
return 0;
}
oi = this->SortedObjectIndices[otyp][oi]; // index into sorted list of objects (block order, not file order)
N = (int) it->second[oi].AttributeNames.size();
if ( ai < 0 || ai >= N )
{
vtkDebugMacro( "You requested attribute " << ai << " in a collection of only " << N << " attributes." );
return 0;
}
else
{
return it->second[oi].AttributeNames[ai].c_str();
}
}
vtkDebugMacro( "Could not find collection of blocks of type " << otyp <<
" (" << objtype_names[this->GetObjectTypeIndexFromObjectType(otyp)] << ")." );
return 0;
}
int vtkExodusIIReaderPrivate::GetObjectAttributeIndex( int otyp, int oi, const char* attribName )
{
std::map<int,std::vector<BlockInfoType> >::iterator it = this->BlockInfo.find( otyp );
if ( it != this->BlockInfo.end() )
{
int N = (int) it->second.size();
if ( oi < 0 || oi >= N )
{
vtkDebugMacro( "You requested block " << oi << " in a collection of only " << N << " blocks." );
return -1;
}
oi = this->SortedObjectIndices[otyp][oi]; // index into sorted list of objects (block order, not file order)
N = (int) it->second[oi].AttributeNames.size();
int ai;
for ( ai = 0; ai < N; ++ai )
{
if ( it->second[oi].AttributeNames[ai] == attribName )
{
return ai;
}
}
return -1;
}
vtkDebugMacro( "Could not find collection of blocks of type " << otyp <<
" (" << objtype_names[this->GetObjectTypeIndexFromObjectType(otyp)] << ")." );
return -1;
}
int vtkExodusIIReaderPrivate::GetObjectAttributeStatus( int otyp, int oi, int ai )
{
std::map<int,std::vector<BlockInfoType> >::iterator it = this->BlockInfo.find( otyp );
if ( it != this->BlockInfo.end() )
{
int N = (int) it->second.size();
if ( oi < 0 || oi >= N )
{
vtkDebugMacro( "You requested block " << oi << " in a collection of only " << N << " blocks." );
return 0;
}
oi = this->SortedObjectIndices[otyp][oi]; // index into sorted list of objects (block order, not file order)
N = (int) it->second[oi].AttributeStatus.size();
if ( ai < 0 || ai >= N )
{
vtkDebugMacro( "You requested attribute " << ai << " in a collection of only " << N << " attributes." );
return 0;
}
else
{
return it->second[oi].AttributeStatus[ai];
}
}
vtkDebugMacro( "Could not find collection of blocks of type " << otyp <<
" (" << objtype_names[this->GetObjectTypeIndexFromObjectType(otyp)] << ")." );
return 0;
}
void vtkExodusIIReaderPrivate::SetObjectAttributeStatus( int otyp, int oi, int ai, int status )
{
status = status ? 1 : 0;
std::map<int,std::vector<BlockInfoType> >::iterator it = this->BlockInfo.find( otyp );
if ( it != this->BlockInfo.end() )
{
int N = (int) it->second.size();
if ( oi < 0 || oi >= N )
{
vtkDebugMacro( "You requested block " << oi << " in a collection of only " << N << " blocks." );
return;
}
oi = this->SortedObjectIndices[otyp][oi]; // index into sorted list of objects (block order, not file order)
N = (int) it->second[oi].AttributeStatus.size();
if ( ai < 0 || ai >= N )
{
vtkDebugMacro( "You requested attribute " << ai << " in a collection of only " << N << " attribute." );
return;
}
else
{
if ( it->second[oi].AttributeStatus[ai] == status )
{
return;
}
it->second[oi].AttributeStatus[ai] = status;
this->Modified();
}
}
vtkDebugMacro( "Could not find collection of blocks of type " << otyp <<
" (" << objtype_names[this->GetObjectTypeIndexFromObjectType(otyp)] << ")." );
}
void vtkExodusIIReaderPrivate::SetApplyDisplacements( int d )
{
if ( this->ApplyDisplacements == d )
return;
this->ApplyDisplacements = d;
this->Modified();
// Require the coordinates to be recomputed:
this->Cache->Invalidate(
vtkExodusIICacheKey( 0, vtkExodusIIReader::NODAL_COORDS, 0, 0 ),
vtkExodusIICacheKey( 0, 1, 0, 0 ) );
}
void vtkExodusIIReaderPrivate::SetDisplacementMagnitude( double s )
{
if ( this->DisplacementMagnitude == s )
return;
this->DisplacementMagnitude = s;
this->Modified();
// Require the coordinates to be recomputed:
this->Cache->Invalidate(
vtkExodusIICacheKey( 0, vtkExodusIIReader::NODAL_COORDS, 0, 0 ),
vtkExodusIICacheKey( 0, 1, 0, 0 ) );
}
vtkDataArray* vtkExodusIIReaderPrivate::FindDisplacementVectors( int timeStep )
{
std::map<int,std::vector<ArrayInfoType> >::iterator it = this->ArrayInfo.find( vtkExodusIIReader::NODAL );
if ( it != this->ArrayInfo.end() )
{
int N = (int) it->second.size();
for ( int i = 0; i < N; ++i )
{
std::string upperName = vtksys::SystemTools::UpperCase( it->second[i].Name.substr( 0, 3 ) );
if ( upperName == "DIS" && it->second[i].Components == this->ModelParameters.num_dim )
{
return this->GetCacheOrRead( vtkExodusIICacheKey( timeStep, vtkExodusIIReader::NODAL, 0, i ) );
}
}
}
return 0;
}
// -------------------------------------------------------- PUBLIC CLASS MEMBERS
vtkStandardNewMacro(vtkExodusIIReader);
vtkCxxSetObjectMacro(vtkExodusIIReader,Metadata,vtkExodusIIReaderPrivate);
vtkCxxSetObjectMacro(vtkExodusIIReader,ExodusModel,vtkExodusModel);
vtkExodusIIReader::vtkExodusIIReader()
{
this->FileName = 0;
this->XMLFileName = 0;
this->Metadata = vtkExodusIIReaderPrivate::New();
this->Metadata->Parent = this;
this->Metadata->SetCacheSize(0.0);
this->TimeStep = 0;
this->TimeStepRange[0] = 0;
this->TimeStepRange[1] = 0;
this->ExodusModelMetadata = 0;
this->PackExodusModelOntoOutput = 1;
this->ExodusModel = 0;
this->DisplayType = 0;
this->SILUpdateStamp = -1;
this->ProducedFastPathOutput = false;
this->SetNumberOfInputPorts( 0 );
}
vtkExodusIIReader::~vtkExodusIIReader()
{
this->SetXMLFileName( 0 );
this->SetFileName( 0 );
this->SetMetadata( 0 );
this->SetExodusModel( 0 );
}
// Normally, vtkExodusIIReader::PrintSelf would be here.
// But it's above to prevent PrintSelf-Hybrid from failing because it assumes
// the first PrintSelf method is the one for the class declared in the header file.
int vtkExodusIIReader::CanReadFile( const char* fname )
{
int exoid;
int appWordSize = 8;
int diskWordSize = 8;
float version;
if ( (exoid = ex_open( fname, EX_READ, &appWordSize, &diskWordSize, &version )) < 0 )
{
return 0;
}
if ( ex_close( exoid ) != 0 )
{
vtkWarningMacro( "Unable to close \"" << fname << "\" opened for testing." );
return 0;
}
return 1;
}
#if 0
void vtkExodusIIReaderPrivate::Modified()
{
cout << "E2RP modified\n"; this->Superclass::Modified();
}
void vtkExodusIIReader::Modified()
{
cout << "E2R modified\n"; this->Superclass::Modified();
}
#endif // 0
unsigned long vtkExodusIIReader::GetMTime()
{
//return this->MTime.GetMTime();
/*
unsigned long mtime1, mtime2;
unsigned long readerMTime = this->MTime.GetMTime();
unsigned long privateMTime = this->Metadata->GetMTime();
unsigned long fileNameMTime = this->FileNameMTime.GetMTime();
unsigned long xmlFileNameMTime = this->XMLFileNameMTime.GetMTime();
mtime1 = privateMTime > readerMTime ? privateMTime : readerMTime;
mtime2 = fileNameMTime > xmlFileNameMTime ? fileNameMTime : xmlFileNameMTime;
return mtime1 > mtime2 ? mtime1 : mtime2;
*/
unsigned long readerMTime = this->MTime.GetMTime();
unsigned long privateMTime = this->Metadata->GetMTime();
return privateMTime > readerMTime ? privateMTime : readerMTime;
}
unsigned long vtkExodusIIReader::GetMetadataMTime()
{
return this->Metadata->InformationTimeStamp < this->Metadata->GetMTime() ?
this->Metadata->InformationTimeStamp : this->Metadata->GetMTime();
}
#define vtkSetStringMacroBody(propName,fname) \
int modified = 0; \
if ( fname == this->propName ) \
return; \
if ( fname && this->propName && !strcmp( fname, this->propName ) ) \
return; \
modified = 1; \
if ( this->propName ) \
delete [] this->propName; \
if ( fname ) \
{ \
size_t fnl = strlen( fname ) + 1; \
char* dst = new char[fnl]; \
const char* src = fname; \
this->propName = dst; \
do { *dst++ = *src++; } while ( --fnl ); \
} \
else \
{ \
this->propName = 0; \
}
void vtkExodusIIReader::SetFileName( const char* fname )
{
vtkSetStringMacroBody(FileName,fname);
if ( modified )
{
this->Metadata->Reset();
this->FileNameMTime.Modified();
}
}
void vtkExodusIIReader::SetXMLFileName( const char* fname )
{
vtkSetStringMacroBody(XMLFileName,fname);
if ( modified )
{
this->XMLFileNameMTime.Modified();
}
}
//----------------------------------------------------------------------------
int vtkExodusIIReader::ProcessRequest(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
{
return this->RequestData(request, inputVector, outputVector);
}
// execute information
if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
{
return this->RequestInformation(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
//----------------------------------------------------------------------------
int vtkExodusIIReader::RequestInformation(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector )
{
int newMetadata = 0;
vtkInformation* outInfo = outputVector->GetInformationObject(0);
// If the metadata is older than the filename
if ( this->GetMetadataMTime() < this->FileNameMTime )
{
if ( this->Metadata->OpenFile( this->FileName ) )
{
// We need to initialize the XML parser before calling RequestInformation
// on the metadata
if ( this->FindXMLFile() )
{
vtkExodusIIReaderParser *parser = vtkExodusIIReaderParser::New();
this->Metadata->SetParser(parser);
// Now overwrite any names in the exodus file with names from XML file.
parser->Go(this->XMLFileName);
parser->Delete();
}
this->Metadata->RequestInformation();
// Now check to see if the DART metadata is valid
if(this->Metadata->Parser && !this->Metadata->IsXMLMetadataValid())
{
this->Metadata->Parser->Delete();
this->Metadata->Parser = 0;
// Reset block names.
int numBlocks = this->Metadata->GetNumberOfObjectsOfType(vtkExodusIIReader::ELEM_BLOCK);
for (int cc=0; cc < numBlocks; cc++)
{
vtkExodusIIReaderPrivate::BlockInfoType* binfop =
static_cast<vtkExodusIIReaderPrivate::BlockInfoType*>(
this->Metadata->GetSortedObjectInfo(vtkExodusIIReader::ELEM_BLOCK, cc));
binfop->Name = binfop->OriginalName;
}
}
// Once meta-data has been refreshed we update the SIL.
this->Metadata->BuildSIL();
this->SILUpdateStamp++; // update the timestamp.
this->Metadata->CloseFile();
newMetadata = 1;
}
else
{
vtkErrorMacro( "Unable to open file \"" << (this->FileName ? this->FileName : "(null)") << "\" to read metadata" );
return 0;
}
}
this->AdvertiseTimeSteps( outInfo );
// Advertize the SIL.
outInfo->Set(vtkDataObject::SIL(), this->Metadata->GetSIL());
if ( newMetadata )
{
// update ExodusModelMetadata
}
return 1;
}
int vtkExodusIIReader::RequestData(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector )
{
this->ProducedFastPathOutput = false;
if ( ! this->FileName || ! this->Metadata->OpenFile( this->FileName ) )
{
vtkErrorMacro( "Unable to open file \"" << (this->FileName ? this->FileName : "(null)") << "\" to read data" );
return 0;
}
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkMultiBlockDataSet *output = vtkMultiBlockDataSet::SafeDownCast( outInfo->Get( vtkDataObject::DATA_OBJECT() ) );
// Check if a particular time was requested.
if ( outInfo->Has( vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP() ) )
{ // Get the requested time step. We only support requests of a single time step in this reader right now
double requestedTimeStep = outInfo->Get( vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
// Save the time value in the output data information.
int length = outInfo->Length( vtkStreamingDemandDrivenPipeline::TIME_STEPS() );
double* steps = outInfo->Get( vtkStreamingDemandDrivenPipeline::TIME_STEPS() );
if ( ! this->GetHasModeShapes() )
{
// find the highest time step with a time value that is smaller than the requested time.
//timeStep = 0;
//while (timeStep < length - 1 && steps[timeStep] < requestedTimeStep)
// {
// timeStep++;
// }
//this->TimeStep = timeStep;
//find the timestep with the closest value
int cnt=0;
int closestStep=0;
double minDist=-1;
for (cnt=0;cnt<length;cnt++)
{
double tdist=(steps[cnt]-requestedTimeStep>requestedTimeStep-steps[cnt])?
steps[cnt]-requestedTimeStep:
requestedTimeStep-steps[cnt];
if (minDist<0 || tdist<minDist)
{
minDist=tdist;
closestStep=cnt;
}
}
this->TimeStep=closestStep;
//cout << "Requested value: " << requestedTimeStep << " Step: " << this->TimeStep << endl;
output->GetInformation()->Set( vtkDataObject::DATA_TIME_STEP(), steps[this->TimeStep] );
}
else if (this->GetAnimateModeShapes())
{
// Let the metadata know the time value so that the Metadata->RequestData call below will generate
// the animated mode shape properly.
this->Metadata->ModeShapeTime = requestedTimeStep;
output->GetInformation()->Set( vtkDataObject::DATA_TIME_STEP(), this->Metadata->ModeShapeTime );
//output->GetInformation()->Remove( vtkDataObject::DATA_TIME_STEP() );
}
}
// Look for fast-path keys.
// All keys must be present for the fast-path to work.
bool haveFastPath = false;
vtkIdType oldFastPathObjId = -1;
ObjectType oldFastPathObjType = ELEM_BLOCK;
char* oldFastPathIdType = 0;
if (
outInfo->Has( vtkStreamingDemandDrivenPipeline::FAST_PATH_OBJECT_TYPE() ) &&
outInfo->Has( vtkStreamingDemandDrivenPipeline::FAST_PATH_OBJECT_ID() ) &&
outInfo->Has( vtkStreamingDemandDrivenPipeline::FAST_PATH_ID_TYPE() ) )
{
const char *objectType = outInfo->Get(
vtkStreamingDemandDrivenPipeline::FAST_PATH_OBJECT_TYPE() );
vtkIdType objectId = outInfo->Get(
vtkStreamingDemandDrivenPipeline::FAST_PATH_OBJECT_ID() );
const char *idType = outInfo->Get(
vtkStreamingDemandDrivenPipeline::FAST_PATH_ID_TYPE() );
oldFastPathObjId = this->Metadata->FastPathObjectId;
oldFastPathObjType = this->Metadata->FastPathObjectType;
oldFastPathIdType = vtksys::SystemTools::DuplicateString( this->Metadata->FastPathIdType );
this->SetFastPathObjectType( objectType );
this->SetFastPathObjectId( objectId );
this->SetFastPathIdType( idType );
haveFastPath = true;
}
//cout << "Requesting step " << this->TimeStep << " for output " << output << "\n";
this->Metadata->RequestData( this->TimeStep, output );
this->ProducedFastPathOutput = this->Metadata->ProducedFastPathOutput;
// Restore previous fastpath values so we don't respond to old pipeline requests
if ( haveFastPath )
{
this->Metadata->FastPathObjectType = oldFastPathObjType;
this->SetFastPathObjectId( oldFastPathObjId );
this->SetFastPathIdType( oldFastPathIdType );
delete [] oldFastPathIdType;
}
return 1;
}
void vtkExodusIIReader::SetGenerateObjectIdCellArray( int x ) { this->Metadata->SetGenerateObjectIdArray( x ); }
int vtkExodusIIReader::GetGenerateObjectIdCellArray() { return this->Metadata->GetGenerateObjectIdArray(); }
void vtkExodusIIReader::SetGenerateGlobalElementIdArray( int x ) { this->Metadata->SetGenerateGlobalElementIdArray( x ); }
int vtkExodusIIReader::GetGenerateGlobalElementIdArray() { return this->Metadata->GetGenerateGlobalElementIdArray(); }
void vtkExodusIIReader::SetGenerateGlobalNodeIdArray( int x ) { this->Metadata->SetGenerateGlobalNodeIdArray( x ); }
int vtkExodusIIReader::GetGenerateGlobalNodeIdArray() { return this->Metadata->GetGenerateGlobalNodeIdArray(); }
void vtkExodusIIReader::SetGenerateImplicitElementIdArray( int x ) { this->Metadata->SetGenerateImplicitElementIdArray( x ); }
int vtkExodusIIReader::GetGenerateImplicitElementIdArray() { return this->Metadata->GetGenerateImplicitElementIdArray(); }
void vtkExodusIIReader::SetGenerateImplicitNodeIdArray( int x ) { this->Metadata->SetGenerateImplicitNodeIdArray( x ); }
int vtkExodusIIReader::GetGenerateImplicitNodeIdArray() { return this->Metadata->GetGenerateImplicitNodeIdArray(); }
void vtkExodusIIReader::SetGenerateFileIdArray( int x ) { this->Metadata->SetGenerateFileIdArray( x ); }
int vtkExodusIIReader::GetGenerateFileIdArray() { return this->Metadata->GetGenerateFileIdArray(); }
void vtkExodusIIReader::SetFileId( int x ) { this->Metadata->SetFileId( x ); }
int vtkExodusIIReader::GetFileId() { return this->Metadata->GetFileId(); }
// FIXME: Implement the four functions that return ID_NOT_FOUND below.
int vtkExodusIIReader::GetGlobalElementID( vtkDataSet* data, int localID )
{ return GetGlobalElementID( data, localID, SEARCH_TYPE_ELEMENT_THEN_NODE ); }
int vtkExodusIIReader::GetGlobalElementID ( vtkDataSet* data, int localID, int searchType )
{ (void)data; (void)localID; (void)searchType; return ID_NOT_FOUND; }
int vtkExodusIIReader::GetGlobalFaceID( vtkDataSet* data, int localID )
{ return GetGlobalFaceID( data, localID, SEARCH_TYPE_ELEMENT_THEN_NODE ); }
int vtkExodusIIReader::GetGlobalFaceID ( vtkDataSet* data, int localID, int searchType )
{ (void)data; (void)localID; (void)searchType; return ID_NOT_FOUND; }
int vtkExodusIIReader::GetGlobalEdgeID( vtkDataSet* data, int localID )
{ return GetGlobalEdgeID( data, localID, SEARCH_TYPE_ELEMENT_THEN_NODE ); }
int vtkExodusIIReader::GetGlobalEdgeID ( vtkDataSet* data, int localID, int searchType )
{ (void)data; (void)localID; (void)searchType; return ID_NOT_FOUND; }
int vtkExodusIIReader::GetGlobalNodeID( vtkDataSet* data, int localID )
{ return GetGlobalNodeID( data, localID, SEARCH_TYPE_NODE_THEN_ELEMENT ); }
int vtkExodusIIReader::GetGlobalNodeID( vtkDataSet* data, int localID, int searchType )
{ (void)data; (void)localID; (void)searchType; return ID_NOT_FOUND; }
void vtkExodusIIReader::SetApplyDisplacements( int d )
{
this->Metadata->SetApplyDisplacements( d );
}
int vtkExodusIIReader::GetApplyDisplacements()
{
return this->Metadata->GetApplyDisplacements();
}
void vtkExodusIIReader::SetDisplacementMagnitude( float s )
{
this->Metadata->SetDisplacementMagnitude( s );
}
float vtkExodusIIReader::GetDisplacementMagnitude()
{
return this->Metadata->GetDisplacementMagnitude();
}
void vtkExodusIIReader::SetHasModeShapes( int ms )
{
this->Metadata->SetHasModeShapes(ms);
}
int vtkExodusIIReader::GetHasModeShapes()
{
return this->Metadata->GetHasModeShapes();
}
void vtkExodusIIReader::SetModeShapeTime( double phase )
{
// Phase should repeat outside the bounds [0,1]. For example, 0.25 is
// equivalent to 1.25, 2.25, -0.75, and -1.75.
double x = phase - floor(phase);
this->Metadata->SetModeShapeTime( x );
}
double vtkExodusIIReader::GetModeShapeTime()
{
return this->Metadata->GetModeShapeTime();
}
void vtkExodusIIReader::SetAnimateModeShapes(int flag)
{
this->Metadata->SetAnimateModeShapes(flag);
}
int vtkExodusIIReader::GetAnimateModeShapes()
{
return this->Metadata->GetAnimateModeShapes();
}
const char* vtkExodusIIReader::GetTitle() { return this->Metadata->ModelParameters.title; }
int vtkExodusIIReader::GetDimensionality() { return this->Metadata->ModelParameters.num_dim; }
int vtkExodusIIReader::GetNumberOfTimeSteps() { return (int) this->Metadata->Times.size(); }
int vtkExodusIIReader::GetNumberOfNodesInFile() { return this->Metadata->ModelParameters.num_nodes; }
int vtkExodusIIReader::GetNumberOfEdgesInFile() { return this->Metadata->ModelParameters.num_edge; }
int vtkExodusIIReader::GetNumberOfFacesInFile() { return this->Metadata->ModelParameters.num_face; }
int vtkExodusIIReader::GetNumberOfElementsInFile() { return this->Metadata->ModelParameters.num_elem; }
int vtkExodusIIReader::GetNumberOfObjects( int objectType )
{
return this->Metadata->GetNumberOfObjectsOfType( objectType );
}
int vtkExodusIIReader::GetObjectTypeFromName( const char* name )
{
vtkStdString tname( name );
if ( tname == "edge" ) return EDGE_BLOCK;
else if ( tname == "face" ) return FACE_BLOCK;
else if ( tname == "element" ) return ELEM_BLOCK;
else if ( tname == "node set" ) return NODE_SET;
else if ( tname == "edge set" ) return EDGE_SET;
else if ( tname == "face set" ) return FACE_SET;
else if ( tname == "side set" ) return SIDE_SET;
else if ( tname == "element set" ) return ELEM_SET;
else if ( tname == "node map" ) return NODE_MAP;
else if ( tname == "edge map" ) return EDGE_MAP;
else if ( tname == "face map" ) return FACE_MAP;
else if ( tname == "element map" ) return ELEM_MAP;
else if ( tname == "grid" ) return GLOBAL;
else if ( tname == "node" ) return NODAL;
else if ( tname == "assembly" ) return ASSEMBLY;
else if ( tname == "part" ) return PART;
else if ( tname == "material" ) return MATERIAL;
else if ( tname == "hierarchy" ) return HIERARCHY;
else if ( tname == "cell" ) return GLOBAL_CONN;
else if ( tname == "element block cell" ) return ELEM_BLOCK_ELEM_CONN;
else if ( tname == "element block face" ) return ELEM_BLOCK_FACE_CONN;
else if ( tname == "element block edge" ) return ELEM_BLOCK_EDGE_CONN;
else if ( tname == "face block cell" ) return FACE_BLOCK_CONN;
else if ( tname == "edge block cell" ) return EDGE_BLOCK_CONN;
else if ( tname == "element set cell" ) return ELEM_SET_CONN;
else if ( tname == "side set cell" ) return SIDE_SET_CONN;
else if ( tname == "face set cell" ) return FACE_SET_CONN;
else if ( tname == "edge set cell" ) return EDGE_SET_CONN;
else if ( tname == "node set cell" ) return NODE_SET_CONN;
else if ( tname == "nodal coordinates" ) return NODAL_COORDS;
else if ( tname == "object id" ) return OBJECT_ID;
else if ( tname == "implicit element id" ) return IMPLICIT_ELEMENT_ID;
else if ( tname == "implicit node id" ) return IMPLICIT_NODE_ID;
else if ( tname == "global element id" ) return GLOBAL_ELEMENT_ID;
else if ( tname == "global node id" ) return GLOBAL_NODE_ID;
else if ( tname == "element id" ) return ELEMENT_ID;
else if ( tname == "node id" ) return NODE_ID;
else if ( tname == "pointmap" ) return NODAL_SQUEEZEMAP;
return -1;
}
const char* vtkExodusIIReader::GetObjectTypeName( int otyp )
{
switch ( otyp )
{
case EDGE_BLOCK: return "edge";
case FACE_BLOCK: return "face";
case ELEM_BLOCK: return "element";
case NODE_SET: return "node set";
case EDGE_SET: return "edge set";
case FACE_SET: return "face set";
case SIDE_SET: return "side set";
case ELEM_SET: return "element set";
case NODE_MAP: return "node map";
case EDGE_MAP: return "edge map";
case FACE_MAP: return "face map";
case ELEM_MAP: return "element map";
case GLOBAL: return "grid";
case NODAL: return "node";
case ASSEMBLY: return "assembly";
case PART: return "part";
case MATERIAL: return "material";
case HIERARCHY: return "hierarchy";
case GLOBAL_CONN: return "cell";
case ELEM_BLOCK_ELEM_CONN: return "element block cell";
case ELEM_BLOCK_FACE_CONN: return "element block face";
case ELEM_BLOCK_EDGE_CONN: return "element block edge";
case FACE_BLOCK_CONN: return "face block cell";
case EDGE_BLOCK_CONN: return "edge block cell";
case ELEM_SET_CONN: return "element set cell";
case SIDE_SET_CONN: return "side set cell";
case FACE_SET_CONN: return "face set cell";
case EDGE_SET_CONN: return "edge set cell";
case NODE_SET_CONN: return "node set cell";
case NODAL_COORDS: return "nodal coordinates";
case OBJECT_ID: return "object id";
case IMPLICIT_ELEMENT_ID: return "implicit element id";
case IMPLICIT_NODE_ID: return "implicit node id";
case GLOBAL_ELEMENT_ID: return "global element id";
case GLOBAL_NODE_ID: return "global node id";
case ELEMENT_ID: return "element id";
case NODE_ID: return "node id";
case NODAL_SQUEEZEMAP: return "pointmap";
}
return 0;
}
int vtkExodusIIReader::GetNumberOfNodes() { return this->Metadata->GetNumberOfNodes(); }
int vtkExodusIIReader::GetNumberOfEntriesInObject( int objectType, int objectIndex )
{
return this->Metadata->GetObjectSize( objectType, objectIndex );
}
int vtkExodusIIReader::GetObjectId( int objectType, int objectIndex )
{
return this->Metadata->GetObjectId( objectType, objectIndex );
}
int vtkExodusIIReader::GetObjectStatus( int objectType, int objectIndex )
{
return this->Metadata->GetObjectStatus( objectType, objectIndex );
}
void vtkExodusIIReader::SetObjectStatus( int objectType, int objectIndex, int status )
{
this->Metadata->SetObjectStatus( objectType, objectIndex, status );
}
void vtkExodusIIReader::SetObjectStatus( int objectType, const char* objectName, int status )
{
if(objectName && strlen(objectName)>0)
{
if(this->GetNumberOfObjects(objectType) == 0)
{
// The object status is being set before the meta data has been finalized
// so cache this value for later and use as the initial value
// If the number of objects really is zero then this doesn't do any harm.
this->Metadata->SetInitialObjectStatus(objectType, objectName, status);
return;
}
this->SetObjectStatus( objectType, this->GetObjectIndex( objectType, objectName ), status );
}
}
const char* vtkExodusIIReader::GetObjectName( int objectType, int objectIndex )
{
return this->Metadata->GetObjectName( objectType, objectIndex );
}
int vtkExodusIIReader::GetObjectIndex( int objectType, const char* objectName )
{
if ( ! objectName )
{
vtkErrorMacro( "You must specify a non-NULL name" );
return -1;
}
int nObj = this->GetNumberOfObjects( objectType );
if ( nObj == 0 )
{
vtkDebugMacro( "No objects of that type (" << objectType << ") to find index for given name " << objectName << "." );
return -1;
}
vtkStdString objectRealName(objectName);
size_t i = objectRealName.find(" Size: ");
if(i!= vtkStdString::npos)
{
objectRealName.erase(i);
}
for ( int obj = 0; obj < nObj; ++obj )
{
const char* storedObjName = this->GetObjectName( objectType, obj );
if(objectRealName == vtkStdString(storedObjName))
{
return obj;
}
}
vtkDebugMacro( "No objects named \"" << objectName << "\" of the specified type (" << objectType << ")." );
return -1;
}
int vtkExodusIIReader::GetObjectIndex( int objectType, int id )
{
int nObj = this->GetNumberOfObjects( objectType );
if ( nObj == 0 )
{
vtkDebugMacro( "No objects of that type (" << objectType << ") to find index for given id " << id << "." );
return -1;
}
for ( int obj = 0; obj < nObj; ++obj )
{
if ( this->GetObjectId( objectType, obj ) == id)
{
return obj;
}
}
vtkDebugMacro( "No objects with id \"" << id << "\" of the specified type (" << objectType << ")." );
return -1;
}
int vtkExodusIIReader::GetNumberOfObjectArrays( int objectType )
{
return this->Metadata->GetNumberOfObjectArraysOfType( objectType );
}
const char* vtkExodusIIReader::GetObjectArrayName( int objectType, int arrayIndex )
{
return this->Metadata->GetObjectArrayName( objectType, arrayIndex );
}
int vtkExodusIIReader::GetNumberOfObjectArrayComponents( int objectType, int arrayIndex )
{
return this->Metadata->GetNumberOfObjectArrayComponents( objectType, arrayIndex );
}
int vtkExodusIIReader::GetObjectArrayStatus( int objectType, int arrayIndex )
{
return this->Metadata->GetObjectArrayStatus( objectType, arrayIndex );
}
void vtkExodusIIReader::SetObjectArrayStatus( int objectType, int arrayIndex, int status )
{
this->Metadata->SetObjectArrayStatus( objectType, arrayIndex, status );
}
void vtkExodusIIReader::SetObjectArrayStatus( int objectType, const char* arrayName, int status )
{
if(arrayName && strlen(arrayName)>0)
{
if(this->GetNumberOfObjectArrays( objectType ) == 0)
{
// The array status is being set before the meta data has been finalized
// so cache this value for later and use as the initial value
// If the number of arrays really is zero then this doesn't do any harm.
this->Metadata->SetInitialObjectArrayStatus(objectType, arrayName, status);
return;
}
this->SetObjectArrayStatus( objectType, this->GetObjectArrayIndex( objectType, arrayName ), status );
}
}
int vtkExodusIIReader::GetNumberOfObjectAttributes( int objectType, int objectIndex )
{
return this->Metadata->GetNumberOfObjectAttributes( objectType, objectIndex );
}
const char* vtkExodusIIReader::GetObjectAttributeName( int objectType, int objectIndex, int attribIndex )
{
return this->Metadata->GetObjectAttributeName( objectType, objectIndex, attribIndex );
}
int vtkExodusIIReader::GetObjectAttributeIndex( int objectType, int objectIndex, const char* attribName )
{
return this->Metadata->GetObjectAttributeIndex( objectType, objectIndex, attribName );
}
int vtkExodusIIReader::GetObjectAttributeStatus( int objectType, int objectIndex, int attribIndex )
{
return this->Metadata->GetObjectAttributeStatus( objectType, objectIndex, attribIndex );
}
void vtkExodusIIReader::SetObjectAttributeStatus( int objectType, int objectIndex, int attribIndex, int status )
{
this->Metadata->SetObjectAttributeStatus( objectType, objectIndex, attribIndex, status );
}
int vtkExodusIIReader::GetObjectArrayIndex( int objectType, const char* arrayName )
{
if ( ! arrayName )
{
vtkErrorMacro( "You must specify a non-NULL name" );
return -1;
}
int nObj = this->GetNumberOfObjectArrays( objectType );
if ( nObj == 0 )
{
vtkDebugMacro( "No objects of that type (" << objectType << ") to find index for given array " << arrayName << "." );
return -1;
}
for ( int obj = 0; obj < nObj; ++obj )
{
if ( !strcmp( arrayName, this->GetObjectArrayName( objectType, obj ) ) )
{
return obj;
}
}
vtkDebugMacro( "No arrays named \"" << arrayName << "\" of the specified type (" << objectType << ")." );
return -1;
}
vtkIdType vtkExodusIIReader::GetTotalNumberOfNodes() { return this->Metadata->GetModelParams()->num_nodes; }
vtkIdType vtkExodusIIReader::GetTotalNumberOfEdges() { return this->Metadata->GetModelParams()->num_edge; }
vtkIdType vtkExodusIIReader::GetTotalNumberOfFaces() { return this->Metadata->GetModelParams()->num_face; }
vtkIdType vtkExodusIIReader::GetTotalNumberOfElements() { return this->Metadata->GetModelParams()->num_elem; }
// %---------------------------------------------------------------------------
int vtkExodusIIReader::GetNumberOfPartArrays()
{
return this->Metadata->GetNumberOfParts();
}
const char* vtkExodusIIReader::GetPartArrayName( int arrayIdx )
{
return this->Metadata->GetPartName(arrayIdx);
}
int vtkExodusIIReader::GetPartArrayID( const char *name )
{
int numArrays = this->GetNumberOfPartArrays();
for ( int i=0;i<numArrays;i++ )
{
if ( strcmp( name, this->GetPartArrayName( i ) ) == 0 )
{
return i;
}
}
return -1;
}
const char* vtkExodusIIReader::GetPartBlockInfo( int arrayIdx )
{
return this->Metadata->GetPartBlockInfo(arrayIdx);
}
void vtkExodusIIReader::SetPartArrayStatus( int index, int flag )
{
// Only modify if we are 'out of sync'
if (this->Metadata->GetPartStatus(index) != flag)
{
this->Metadata->SetPartStatus(index, flag);
// Because which parts are on/off affects the
// geometry we need to remake the mesh cache
//this->RemakeDataCacheFlag = 1;
this->Modified();
}
}
void vtkExodusIIReader::SetPartArrayStatus( const char* name, int flag )
{
// Only modify if we are 'out of sync'
if (this->Metadata->GetPartStatus(name) != flag)
{
this->Metadata->SetPartStatus(name, flag);
// Because which parts are on/off affects the
// geometry we need to remake the mesh cache
//this->RemakeDataCacheFlag = 1;
this->Modified();
}
}
int vtkExodusIIReader::GetPartArrayStatus( int index )
{
return this->Metadata->GetPartStatus(index);
}
int vtkExodusIIReader::GetPartArrayStatus( const char* part )
{
return this->Metadata->GetPartStatus(part);
}
int vtkExodusIIReader::GetNumberOfMaterialArrays()
{
return this->Metadata->GetNumberOfMaterials();
}
const char* vtkExodusIIReader::GetMaterialArrayName( int arrayIdx )
{
return this->Metadata->GetMaterialName(arrayIdx);
}
int vtkExodusIIReader::GetMaterialArrayID( const char* matl )
{
(void)matl;
return 0;
}
void vtkExodusIIReader::SetMaterialArrayStatus( int index, int flag )
{
// Only modify if we are 'out of sync'
if (this->Metadata->GetMaterialStatus(index) != flag)
{
this->Metadata->SetMaterialStatus(index, flag);
// Because which materials are on/off affects the
// geometry we need to remake the mesh cache
//this->RemakeDataCacheFlag = 1;
this->Modified();
}
}
void vtkExodusIIReader::SetMaterialArrayStatus( const char* matl, int flag )
{
// Only modify if we are 'out of sync'
if (this->Metadata->GetMaterialStatus(matl) != flag)
{
this->Metadata->SetMaterialStatus(matl, flag);
// Because which materials are on/off affects the
// geometry we need to remake the mesh cache
//this->RemakeDataCacheFlag = 1;
this->Modified();
}
}
int vtkExodusIIReader::GetMaterialArrayStatus( int index )
{
return this->Metadata->GetMaterialStatus(index);
}
int vtkExodusIIReader::GetMaterialArrayStatus( const char* matl )
{
return this->Metadata->GetMaterialStatus(matl);
}
int vtkExodusIIReader::GetNumberOfAssemblyArrays()
{
return this->Metadata->GetNumberOfAssemblies();
}
const char* vtkExodusIIReader::GetAssemblyArrayName( int arrayIdx )
{
return this->Metadata->GetAssemblyName(arrayIdx);
}
int vtkExodusIIReader::GetAssemblyArrayID( const char* name )
{
int numArrays = this->GetNumberOfAssemblyArrays();
for ( int i=0;i<numArrays;i++ )
{
if ( strcmp( name, this->GetAssemblyArrayName( i ) ) == 0 )
{
return i;
}
}
return -1;
}
void vtkExodusIIReader::SetAssemblyArrayStatus(int index, int flag)
{
// Only modify if we are 'out of sync'
if (this->Metadata->GetAssemblyStatus(index) != flag)
{
this->Metadata->SetAssemblyStatus(index, flag);
// Because which materials are on/off affects the
// geometry we need to remake the mesh cache
//this->RemakeDataCacheFlag = 1;
this->Modified();
}
}
void vtkExodusIIReader::SetAssemblyArrayStatus(const char* name, int flag)
{
// Only modify if we are 'out of sync'
if (this->Metadata->GetAssemblyStatus(name) != flag)
{
this->Metadata->SetAssemblyStatus(name, flag);
// Because which materials are on/off affects the
// geometry we need to remake the mesh cache
//this->RemakeDataCacheFlag = 1;
this->Modified();
}
}
int vtkExodusIIReader::GetAssemblyArrayStatus(int index)
{
return this->Metadata->GetAssemblyStatus(index);
}
int vtkExodusIIReader::GetAssemblyArrayStatus(const char* name)
{
return this->Metadata->GetAssemblyStatus(name);
}
int vtkExodusIIReader::GetNumberOfHierarchyArrays()
{
//if (this->Metadata->Parser)
// {
// return this->Metadata->Parser->GetNumberOfHierarchyEntries();
// }
return 0;
}
const char* vtkExodusIIReader::GetHierarchyArrayName(int vtkNotUsed(arrayIdx))
{
//if (this->Metadata->Parser)
// {
// this->Metadata->Parser->SetCurrentHierarchyEntry(arrayIdx);
// return this->Metadata->Parser->GetCurrentHierarchyEntry();
// }
return "Should not see this";
}
void vtkExodusIIReader::SetHierarchyArrayStatus(int vtkNotUsed(index), int vtkNotUsed(flag))
{
//// Only modify if we are 'out of sync'
////if (this->GetHierarchyArrayStatus(index) != flag)
//// {
//if (this->Metadata->Parser)
// {
// std::vector<int> blocksIds = this->Metadata->Parser->GetBlocksForEntry(index);
// for (std::vector<int>::size_type i=0;i<blocksIds.size();i++)
// {
// this->Metadata->SetObjectStatus(vtkExodusIIReader::ELEM_BLOCK,
// this->GetObjectIndex(ELEM_BLOCK,blocksIds[i]),flag);
// }
//
// // Because which materials are on/off affects the
// // geometry we need to remake the mesh cache
// //this->RemakeDataCacheFlag = 1;
// this->Modified();
// }
}
void vtkExodusIIReader::SetHierarchyArrayStatus(const char* vtkNotUsed(name), int vtkNotUsed(flag))
{
//// Only modify if we are 'out of sync'
////if (this->GetHierarchyArrayStatus(name) != flag)
////{
//if (this->Metadata->Parser)
// {
// std::vector<int> blocksIds=this->Metadata->Parser->GetBlocksForEntry
// (vtkStdString(name));
// for (std::vector<int>::size_type i=0;i<blocksIds.size();i++)
// {
// //cout << "turning block " << blocks[i] << " " << flag << endl;
// this->Metadata->SetObjectStatus(vtkExodusIIReader::ELEM_BLOCK,
// this->GetObjectIndex(ELEM_BLOCK,blocksIds[i]),flag);
// }
//
// // Because which materials are on/off affects the
// // geometry we need to remake the mesh cache
// //this->RemakeDataCacheFlag = 1;
// this->Modified();
// }
}
//-----------------------------------------------------------------------------
int vtkExodusIIReader::GetHierarchyArrayStatus(int vtkNotUsed(index))
{
//if (this->Metadata->Parser)
// {
// std::vector<int> blocksIds=this->Metadata->Parser->GetBlocksForEntry(index);
// for (std::vector<int>::size_type i=0;i<blocksIds.size();i++)
// {
// if (this->Metadata->GetObjectStatus(vtkExodusIIReader::ELEM_BLOCK,
// this->GetObjectIndex(ELEM_BLOCK,blocksIds[i]))==0)
// return 0;
// }
// }
return 1;
}
//-----------------------------------------------------------------------------
int vtkExodusIIReader::GetHierarchyArrayStatus(const char* vtkNotUsed(name))
{
//if (this->Metadata->Parser)
// {
// std::vector<int> blocksIds=this->Metadata->Parser->GetBlocksForEntry(name);
// for (std::vector<int>::size_type i=0;i<blocksIds.size();i++)
// {
// if (this->Metadata->GetObjectStatus(vtkExodusIIReader::ELEM_BLOCK,
// this->GetObjectIndex(ELEM_BLOCK,blocksIds[i]))==0)
// return 0;
// }
// }
return 1;
}
//-----------------------------------------------------------------------------
vtkGraph* vtkExodusIIReader::GetSIL()
{
return this->Metadata->GetSIL();
}
//-----------------------------------------------------------------------------
void vtkExodusIIReader::SetDisplayType( int typ )
{
if ( typ == this->DisplayType || typ < 0 || typ > 2 )
return;
this->DisplayType = typ;
this->Modified();
}
//-----------------------------------------------------------------------------
int vtkExodusIIReader::IsValidVariable( const char *type, const char *name )
{
return (this->GetVariableID( type, name ) >= 0);
}
//-----------------------------------------------------------------------------
int vtkExodusIIReader::GetVariableID( const char *type, const char *name )
{
int otyp = this->GetObjectTypeFromName( type );
if ( otyp < 0 )
{
return 0;
}
switch ( otyp )
{
case NODAL:
case EDGE_BLOCK:
case FACE_BLOCK:
case ELEM_BLOCK:
case NODE_SET:
case EDGE_SET:
case FACE_SET:
case SIDE_SET:
case ELEM_SET:
return this->GetObjectArrayIndex( otyp, name );
case ASSEMBLY:
return this->GetAssemblyArrayID( name );
case HIERARCHY:
return -1; // FIXME: There is no this->GetHierarchyArrayID( name ) and it's not clear there should be.
case MATERIAL:
return this->GetMaterialArrayID( name );
case PART:
return this->GetPartArrayID( name );
default:
return -1;
}
}
int vtkExodusIIReader::GetTimeSeriesData( int ID, const char* vName, const char* vType, vtkFloatArray* result )
{
(void)ID;
(void)vName;
(void)vType;
(void)result;
return -1;
}
void vtkExodusIIReader::SetAllArrayStatus( int otyp, int status )
{
int numObj;
int i;
switch ( otyp )
{
case EDGE_BLOCK_CONN:
case FACE_BLOCK_CONN:
case ELEM_BLOCK_ELEM_CONN:
case NODE_SET_CONN:
case EDGE_SET_CONN:
case FACE_SET_CONN:
case SIDE_SET_CONN:
case ELEM_SET_CONN:
numObj = this->GetNumberOfObjects( otyp );
for ( i = 0; i < numObj; ++i )
{
this->SetObjectStatus( otyp, i, status );
}
break;
case NODAL:
case GLOBAL:
case EDGE_BLOCK:
case FACE_BLOCK:
case ELEM_BLOCK:
case NODE_SET:
case EDGE_SET:
case FACE_SET:
case SIDE_SET:
case ELEM_SET:
numObj = this->GetNumberOfObjectArrays( otyp );
for ( i = 0; i < numObj; ++i )
{
this->SetObjectArrayStatus( otyp, i, status );
}
break;
// ---------------------
case ASSEMBLY:
numObj = this->GetNumberOfAssemblyArrays();
for ( i = 0; i < numObj; ++i )
{
this->SetAssemblyArrayStatus( i, status );
}
case PART:
numObj = this->GetNumberOfPartArrays();
for ( i = 0; i < numObj; ++i )
{
this->SetPartArrayStatus( i, status );
}
case MATERIAL:
numObj = this->GetNumberOfMaterialArrays();
for ( i = 0; i < numObj; ++i )
{
this->SetMaterialArrayStatus( i, status );
}
case HIERARCHY:
numObj = this->GetNumberOfHierarchyArrays();
for ( i = 0; i < numObj; ++i )
{
this->SetHierarchyArrayStatus( i, status );
}
default:
;
break;
}
}
void vtkExodusIIReader::NewExodusModel()
{
// These arrays are required by the Exodus II writer:
this->GenerateGlobalElementIdArrayOn();
this->GenerateGlobalNodeIdArrayOn();
this->GenerateObjectIdCellArrayOn();
if ( this->ExodusModel )
{
this->ExodusModel->Reset();
return;
}
this->ExodusModel = vtkExodusModel::New();
}
void vtkExodusIIReader::Dump()
{
vtkIndent indent;
this->PrintSelf( cout, indent );
}
bool vtkExodusIIReader::FindXMLFile()
{
// If the XML filename exists and is newer than any existing parser (or there is no parser), reread XML file.
if (
( this->Metadata->Parser && this->Metadata->Parser->GetMTime() < this->XMLFileNameMTime && this->XMLFileName ) ||
( ! Metadata->Parser ) )
{
if ( Metadata->Parser )
{
Metadata->Parser->Delete();
Metadata->Parser = 0;
}
if ( ! this->XMLFileName || ! vtksys::SystemTools::FileExists( this->XMLFileName ) )
{
if ( this->FileName )
{
vtkStdString baseName( vtksys::SystemTools::GetFilenameWithoutExtension( this->FileName ) );
vtkStdString xmlExt( baseName + ".xml" );
if ( vtksys::SystemTools::FileExists( xmlExt ) )
{
this->SetXMLFileName( xmlExt.c_str() );
return true;
}
vtkStdString dartExt( baseName + ".dart" );
if ( vtksys::SystemTools::FileExists( dartExt ) )
{
this->SetXMLFileName( dartExt.c_str() );
return true;
}
vtkStdString baseDir( vtksys::SystemTools::GetFilenamePath( this->FileName ) );
vtkStdString artifact( baseDir + "/artifact.dta" );
if ( vtksys::SystemTools::FileExists( artifact ) )
{
this->SetXMLFileName( artifact.c_str() );
return true;
}
// Catch the case where filename was non-NULL but didn't exist.
this->SetXMLFileName( 0 );
}
}
else
{
return true;
}
}
return false;
}
void vtkExodusIIReader::AdvertiseTimeSteps( vtkInformation* outInfo )
{
if ( ! this->GetHasModeShapes() )
{
int nTimes = (int) this->Metadata->Times.size();
double timeRange[2];
if ( nTimes )
{
timeRange[0] = this->Metadata->Times[0];
timeRange[1] = this->Metadata->Times[nTimes - 1];
outInfo->Set( vtkStreamingDemandDrivenPipeline::TIME_STEPS(), &this->Metadata->Times[0], nTimes );
outInfo->Set( vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2 );
this->TimeStepRange[0] = 0; this->TimeStepRange[1] = nTimes - 1;
}
}
else if (this->GetAnimateModeShapes())
{
outInfo->Remove( vtkStreamingDemandDrivenPipeline::TIME_STEPS() );
static double timeRange[] = { 0, 1 };
outInfo->Set( vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2 );
}
else
{
outInfo->Remove(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
outInfo->Remove(vtkStreamingDemandDrivenPipeline::TIME_RANGE());
}
// Advertise to downstream filters that this reader supports a fast-path
// for reading data over time.
outInfo->Set( vtkStreamingDemandDrivenPipeline::FAST_PATH_FOR_TEMPORAL_DATA(), 1 );
}
void vtkExodusIIReader::SetFastPathObjectType( const char* type )
{
if ( ! strcmp( type, "POINT" ) )
{
this->Metadata->SetFastPathObjectType( vtkExodusIIReader::NODAL );
}
else if ( ! strcmp( type, "CELL" ) )
{
this->Metadata->SetFastPathObjectType( vtkExodusIIReader::ELEM_BLOCK );
}
else if ( ! strcmp( type, "FACE" ) )
{
this->Metadata->SetFastPathObjectType( vtkExodusIIReader::FACE_BLOCK );
}
else if ( ! strcmp( type, "EDGE" ) )
{
this->Metadata->SetFastPathObjectType( vtkExodusIIReader::EDGE_BLOCK );
}
this->Modified();
}
void vtkExodusIIReader::SetFastPathObjectId(vtkIdType id)
{
this->Metadata->SetFastPathObjectId(id);
this->Modified();
}
void vtkExodusIIReader::SetFastPathIdType(const char *type)
{
this->Metadata->SetFastPathIdType(type);
this->Modified();
}
void vtkExodusIIReader::Reset()
{
this->Metadata->Reset();
this->Metadata->ResetSettings();
}
void vtkExodusIIReader::ResetSettings()
{
this->Metadata->ResetSettings();
}
void vtkExodusIIReader::SetCacheSize(double CacheSize)
{
this->Metadata->SetCacheSize(CacheSize);
}
double vtkExodusIIReader::GetCacheSize()
{
return this->Metadata->GetCacheSize();
}
void vtkExodusIIReader::ResetCache()
{
this->Metadata->ResetCache();
}
void vtkExodusIIReader::UpdateTimeInformation()
{
if ( this->Metadata->OpenFile( this->FileName ) )
{
this->Metadata->UpdateTimeInformation();
if ( ! this->GetHasModeShapes() )
{
int nTimes = (int) this->Metadata->Times.size();
if ( nTimes )
{
this->TimeStepRange[0] = 0;
this->TimeStepRange[1] = nTimes - 1;
}
}
this->Metadata->CloseFile();
}
}
|