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
|
/*****************************************************************************
*
* Copyright (c) 2000 - 2010, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400124
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ***************************************************************************
// avtSAMRAIFileFormat.C
//
// Purpose: Read SAMRAI data files
//
// Programmer: Walter Herrera Jimenez
// Creation: July 7, 2003
//
// Modifications:
// Mark C. Miller
// Eric Brugger
// Kathleen Bonnell
//
// ****************************************************************************
#define USE_UNIQUE_SPECIES
#include <avtSAMRAIFileFormat.h>
#include <AutoArray.h>
#include <BJHash.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <vtkCellData.h>
#include <vtkFloatArray.h>
#include <vtkIntArray.h>
#include <vtkPoints.h>
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkUnsignedCharArray.h>
#include <avtCallback.h>
#include <avtDatabaseMetaData.h>
#include <avtGhostData.h>
#include <avtIntervalTree.h>
#include <avtIOInformation.h>
#include <avtMaterial.h>
#include <avtMixedVariable.h>
#include <avtSpecies.h>
#include <avtStructuredDomainBoundaries.h>
#include <avtStructuredDomainNesting.h>
#include <avtVariableCache.h>
#include <Expression.h>
#include <BadIndexException.h>
#include <DebugStream.h>
#include <InvalidVariableException.h>
#include <InvalidFilesException.h>
#include <UnexpectedValueException.h>
#include <Utility.h>
#include <DataNode.h>
#include <snprintf.h>
// Define this symbol BEFORE including hdf5.h to indicate the HDF5 code
// in this file uses version 1.6 of the HDF5 API. This is harmless for
// versions of HDF5 before 1.8 and ensures correct compilation with
// version 1.8 and thereafter. When, and if, the HDF5 code in this file
// is explicitly upgraded to the 1.8 API, this symbol should be removed.
#define H5_USE_16_API
#include <hdf5.h>
#include <visit-hdf5.h>
using std::vector;
using std::string;
// the version of the SAMRAI writer the current reader code matches
static const float expected_version_number[] = {2.0,3.0};
static const char *inferredVoidMatName = "inferred void";
static const int MAX_GHOST_LAYERS = 2;
static const int MAX_GHOST_CODES = MAX_GHOST_LAYERS *
MAX_GHOST_LAYERS *
MAX_GHOST_LAYERS;
static string GetDirName(const char *path);
#define SAFE_DELETE(P) \
if (P != 0) \
{ \
delete[] P; \
P = 0; \
}
int avtSAMRAIFileFormat::objcnt = 0;
// ****************************************************************************
// Function: avtSAMRAIFileFormat::InitializeHDF5
//
// Purpose: Initialize interaction with the HDF5 library
//
// Programmer: Mark C. Miller
// Creation: Decmeber 10, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::InitializeHDF5(void)
{
debug5 << "Initializing HDF5 Library" << endl;
H5open();
H5Eset_auto(NULL, NULL);
}
// ****************************************************************************
// Function: avtSAMRAIFileFormat::FinalizeHDF5
//
// Purpose: End interaction with the HDF5 library
//
// Programmer: Mark C. Miller
// Creation: Decmeber 10, 2003
//
// Modifications:
//
// Mark C. Miller, Tue Apr 14 17:21:23 PDT 2009
// Replaced call to H5close with H5garbage_collect. Calling H5close is
// problematic as VisIt may have other plugins instantiated which are
// still interacting with HDF5. Calling garbage collect routine achieves
// the desired goal of reducing memory usage without effecting other
// plugins that might still be using the HDF5 library.
// ****************************************************************************
void
avtSAMRAIFileFormat::FinalizeHDF5(void)
{
debug5 << "Garbage collecting HDF5 Library" << endl;
H5garbage_collect();
}
// ****************************************************************************
// Constructor: avtSAMRAIFileFormat::avtSAMRAIFileFormat
//
// Arguments:
// fname the file name of the root metadata file
//
// Programmer: Walter Herrera Jimenez
// Creation: July 07, 2003
//
// Modifications:
//
// Mark C. Miller, Thu Jan 29 11:21:41 PST 2004
// Added initialization for var_max_ghost data member
//
// Mark C. Miller, Mon Aug 23 14:17:55 PDT 2004
// Added initialization for h5files data member
//
// Hank Childs, Sat Mar 5 11:46:24 PST 2005
// Initialize have_read_metadata_file.
//
// Mark C. Miller, Wed Nov 9 12:35:15 PST 2005
// Initialized cycle/time info to INVALID values
//
// ****************************************************************************
avtSAMRAIFileFormat::avtSAMRAIFileFormat(const char *fname)
: avtSTMDFileFormat(&fname, 1)
{
int i;
// do HDF5 library initialization on consturction of first instance
if (avtSAMRAIFileFormat::objcnt == 0)
InitializeHDF5();
avtSAMRAIFileFormat::objcnt++;
time_step_number = INVALID_CYCLE;
time = INVALID_TIME;
cached_patches = NULL;
xlo = NULL;
dx = NULL;
num_patches_level = NULL;
ratios_coarser_levels = NULL;
var_cell_centered = NULL;
patch_extents = NULL;
var_extents = NULL;
var_names = NULL;
var_num_components = NULL;
var_num_ghosts = NULL;
patch_map = NULL;
child_array = NULL;
child_pointer_array = NULL;
parent_array = NULL;
parent_pointer_array = NULL;
num_vars = 0;
num_patches = 0;
child_array_length = 0;
parent_array_length = 0;
dir_name = GetDirName(fname);
file_name = fname;
last_patch = -1;
has_ghost = false;
ghosting_is_consistent = true;
for (i = 0; i < 3; i++)
var_max_ghosts[i] = 0;
has_mats = false;
inferVoidMaterial = false;
num_mats = 0;
mat_num_ghosts = 0;
mat_names = 0;
mat_var_num_components = 0;
mat_var_names = 0;
sparse_mat_info = 0;
has_specs = false;
nmatspec = 0;
num_spec_vars = 0;
spec_var_names = 0;
expr_keys = NULL;
expr_types = NULL;
expr_defns = NULL;
h5files = new hid_t[MAX_FILES];
for (i = 0 ; i < MAX_FILES ; i++)
{
h5files[i] = -1;
}
have_read_metadata_file = false;
}
// ****************************************************************************
// Destructor: avtSAMRAIFileFormat::FreeUpResources
//
// Programmer: Mark C. Miller
// Creation: November 18, 2004
//
// ****************************************************************************
void
avtSAMRAIFileFormat::FreeUpResources()
{
for (int i = 0 ; i < nFiles ; i++)
{
CloseFile(i);
}
}
// ****************************************************************************
// Destructor: avtSAMRAIFileFormat::~avtSAMRAIFileFormat
//
// Programmer: Walter Herrera Jimenez
// Creation: June 19, 2003
//
// Modifications:
//
// Mark C. Miller, Mon Aug 23 14:17:55 PDT 2004
// Added deletion of h5files data member
//
// Mark C. Miller, Thu Nov 18 18:04:01 PST 2004
// Added call to FreeUpResources
//
// ****************************************************************************
avtSAMRAIFileFormat::~avtSAMRAIFileFormat()
{
int i,v;
FreeUpResources();
SAFE_DELETE(xlo);
SAFE_DELETE(dx);
SAFE_DELETE(num_patches_level);
SAFE_DELETE(ratios_coarser_levels)
SAFE_DELETE(patch_extents);
if (var_extents != NULL) {
for(v=0; v<num_vars; v++) {
delete[] var_extents[v];
}
delete[] var_extents;
}
var_extents = NULL;
//
// cleanup variable information
//
SAFE_DELETE(var_names);
SAFE_DELETE(var_cell_centered);
SAFE_DELETE(var_num_components);
SAFE_DELETE(var_num_ghosts);
//
// cleanup parent/child information
//
SAFE_DELETE(patch_map);
SAFE_DELETE(child_array);
SAFE_DELETE(child_pointer_array);
SAFE_DELETE(parent_array);
SAFE_DELETE(parent_pointer_array);
//
// clean up stuff having to do with species
//
SAFE_DELETE(nmatspec);
SAFE_DELETE(spec_var_names);
for (i = 0; i < num_mats; i++)
SAFE_DELETE(mat_specs[mat_names[i]]);
std::map<std::string, std::map<std::string, matinfo_t*> >::iterator ms;
for (ms = mat_specs_matinfo.begin();
ms != mat_specs_matinfo.end(); ms++)
{
std::map<std::string, matinfo_t*>::iterator mms;
for (mms = ms->second.begin();
mms != ms->second.end(); mms++)
{
SAFE_DELETE(mms->second);
}
}
//
// clean up stuff having to do with materials
//
std::map<std::string, matinfo_t*>::iterator m;
for (m = mat_names_matinfo.begin();
m != mat_names_matinfo.end(); m++)
{
SAFE_DELETE(m->second);
}
std::map<std::string, std::map<std::string, matinfo_t*> >::iterator mv;
for (mv = mat_var_names_matinfo.begin();
mv != mat_var_names_matinfo.end(); mv++)
{
std::map<std::string, matinfo_t*>::iterator mmv;
for (mmv = mv->second.begin();
mmv != mv->second.end(); mmv++)
{
SAFE_DELETE(mmv->second);
}
}
SAFE_DELETE(mat_names);
SAFE_DELETE(mat_var_names);
SAFE_DELETE(mat_num_ghosts);
SAFE_DELETE(mat_var_num_components);
SAFE_DELETE(sparse_mat_info);
SAFE_DELETE(expr_keys);
SAFE_DELETE(expr_types);
SAFE_DELETE(expr_defns);
//
// cleanup the mesh cache
//
if (cached_patches != 0)
{
int p;
for (p=0; p<num_patches; p++)
{
if (cached_patches[p] != 0)
{
if (has_ghost)
{
int g;
for (g=0; g<MAX_GHOST_CODES; g++) {
// XXX is it necessary??
if (cached_patches[p][g] != 0)
cached_patches[p][g]->Delete();
}
}
else
{
if (cached_patches[p][0] != 0)
cached_patches[p][0]->Delete();
}
delete[] cached_patches[p];
}
}
delete[] cached_patches;
}
cached_patches = 0;
SAFE_DELETE(h5files);
// handle HDF5 library termination on descrution of last instance
avtSAMRAIFileFormat::objcnt--;
if (avtSAMRAIFileFormat::objcnt == 0)
FinalizeHDF5();
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::OpenFile
//
// Purpose:
// Opens and registers or uses a named file and sets knowledge of the file
// in the file format
//
// Programmer: Mark C. Miller
// Creation: August 19, 2004
//
// ****************************************************************************
hid_t
avtSAMRAIFileFormat::OpenFile(const char *fileName)
{
//
// See if we've seen this file name already
//
int fileIndex = -1;
for (int i = 0 ; i < nFiles ; i++)
{
if (strcmp(filenames[i], fileName) == 0)
{
fileIndex = i;
break;
}
}
if (fileIndex == -1)
{
//
// We have asked for a previously unseen file. Add it to the list and
// continue. AddFile will automatically take care of overflow issues.
//
fileIndex = AddFile(fileName);
}
//
// Make sure this is in range.
//
if (fileIndex < 0 || fileIndex >= nFiles)
{
EXCEPTION2(BadIndexException, fileIndex, nFiles);
}
//
// Check to see if the file is already open.
//
if (h5files[fileIndex] >= 0)
{
UsedFile(fileIndex);
return h5files[fileIndex];
}
debug4 << "Opening HDF5 file " << filenames[fileIndex] << endl;
//
// Open the HDF5 file.
//
h5files[fileIndex] = H5Fopen(filenames[fileIndex], H5F_ACC_RDONLY, H5P_DEFAULT);
//
// Check to see if we got a valid handle.
//
if (h5files[fileIndex] < 0)
{
EXCEPTION1(InvalidFilesException, filenames[fileIndex]);
}
RegisterFile(fileIndex);
return h5files[fileIndex];
}
// ****************************************************************************
// Method: avtSAMRAIlFileFormat::CloseFile
//
// Purpose:
// Implements the AVT interface's CloseFile method
//
// Programmer: Mark C. Miller
// Creation: August 19, 2004
//
// ****************************************************************************
void
avtSAMRAIFileFormat::CloseFile(int f)
{
if (h5files[f] >= 0)
{
debug4 << "Closing HDF5 file " << filenames[f] << endl;
H5Fclose(h5files[f]);
UnregisterFile(f);
h5files[f] = -1;
}
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::ActivateTimestep
//
// Purpose:
// This is called by the generic database to signal that this file format
// is going to be used soon. It is important that each file format defer
// as much work as possible, since there can be many (one per timestep),
// and we won't need all their work at once, if at all.
//
// In this case, we will have the SAMRAI file format prepare its nesting
// objects.
//
// Programmer: Hank Childs
// Creation: March 5, 2005
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ActivateTimestep(void)
{
// Make sure the domain nest info object exists
ReadMetaDataFile();
BuildDomainAuxiliaryInfo();
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::RegisterVariableList
//
// Purpose:
// Records the active variable name so per-variable ghosting can be applied
// during GetMesh calls.
//
// Programmer: Mark C. Miller
// Creation: December 9, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::RegisterVariableList(const char *prim_var_name,
const std::vector<CharStrRef> &)
{
active_visit_var_name = prim_var_name;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::CanCacheVariable
//
// Purpose:
// Determines if the given variable can be cached above the layer of the
// plugin. In some cases, particularly where different ghosting is used
// for different variables, the mesh variable cannot be cached.
//
// Programmer: Mark C. Miller
// Creation: December 10, 2003
//
// ****************************************************************************
bool
avtSAMRAIFileFormat::CanCacheVariable(const char *var_name)
{
if (strncmp(var_name,"amr_mesh",8) == 0)
{
if (has_ghost == false)
return true;
else
return false;
}
else
return true;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::GetMesh
//
// Purpose:
// Returns the mesh with the given name for the given time step and
// domain. This function will return a cached reference to the mesh
// for this domain, since the mesh does not change over time.
//
// Note: The Generic Database (which calls this function) already handles
// caching for a single time step.
//
// Arguments:
// ts the time step
// dom the domain number
// mesh the name of the mesh to read
//
// Programmer: Walter Herrera Jimenez
// Creation: June 19, 2003
//
// Modifications
//
// Mark C. Miller, Mon Nov 10 09:55:59 PST 2003
// Added call to BuildDomainNestingInfo
//
// Mark C. Miller, Tue Dec 9 10:45:46 PST 2003
// Changed name of BuildDomainNestingInfo to BuildDomainAuxiliaryInfo
//
// Brad Whitlock, Fri Mar 5 10:19:32 PDT 2004
// Changed for Windows compiler.
//
// Hank Childs, Sat Mar 5 10:35:11 PST 2005
// The domain nesting is now calculated in activate timestep.
//
// ****************************************************************************
vtkDataSet *
avtSAMRAIFileFormat::GetMesh(int patch, const char *)
{
int ghostCode = GetGhostCodeForVar(active_visit_var_name.c_str());
debug5 << "Ghost code for variable \"" << active_visit_var_name.c_str()
<< "\" is " << ghostCode << endl;
if (cached_patches[patch][ghostCode] != NULL)
{
debug5 << "avtSAMRAIFileFormat::GetMesh returning cached value for \""
<< active_visit_var_name.c_str() << "\"" << endl;
// The reference count will be decremented by the generic database,
// because it will assume it owns it.
cached_patches[patch][ghostCode]->Register(NULL);
return cached_patches[patch][ghostCode];
}
vtkDataSet *ds = ReadMesh(patch);
cached_patches[patch][ghostCode] = ds;
ds->Register(NULL);
return ds;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::ReadMesh
//
// Purpose:
// Reads the patch with the given id for the given time step and
// domain from the file. NOTE: time step is ignored in this case
// because the mesh does not change over time.
//
// Arguments:
// patch the patch number
//
// Programmer: Walter Herrera Jimenez
// Creation: July 11, 2003
//
// Modificatioons:
// Mark C. Miller, Tue Dec 9 08:54:54 PST 2003
// Added support for ghosting. Note that it can vary depending upon the
// variable requested.
//
// Mark C. Miller, Wed Jan 7 11:35:37 PST 2004
// Elminated traversal of ALE coordinate data and replaced with a SetData
// call
//
// Brad Whitlock, Fri Mar 5 10:19:32 PDT 2004
// Changed for Windows compiler.
//
// Mark C. Miller, Tue Aug 24 20:11:52 PDT 2004
// Added code to set up the magic 'base_index' array
//
// Hank Childs, Fri Aug 27 17:16:05 PDT 2004
// Rename ghost data array.
//
// Mark C. Miller, Mon Mar 31 14:27:21 PDT 2008
// Modified to handle the 'materials' variable ghosting correctly.
// ****************************************************************************
vtkDataSet *
avtSAMRAIFileFormat::ReadMesh(int patch)
{
vtkDataSet *retval;
debug5 << "avtSAMRAIFileFormat::ReadMesh for patch " << patch << endl;
int dim = num_dim_problem < 3 ? num_dim_problem: 3;
int level = patch_map[patch].level_number;
bool should_ghost_this_patch = has_ghost;
int num_ghosts[3] = {0,0,0};
// set ghost information
if (has_ghost)
{
//
// lookup ghost layer information for the active variable
//
std::map<std::string, var_t>::const_iterator cur_var;
cur_var = var_names_num_components.find(active_visit_var_name);
if (active_visit_var_name == "amr_mesh" ||
active_visit_var_name == "materials")
{
num_ghosts[0] = var_max_ghosts[0];
num_ghosts[1] = var_max_ghosts[1];
num_ghosts[2] = var_max_ghosts[2];
should_ghost_this_patch = true;
}
else if (cur_var == var_names_num_components.end())
{
num_ghosts[0] = 0;
num_ghosts[1] = 0;
num_ghosts[2] = 0;
should_ghost_this_patch = false;
}
else
{
num_ghosts[0] = (*cur_var).second.num_ghosts[0];
num_ghosts[1] = (*cur_var).second.num_ghosts[1];
num_ghosts[2] = (*cur_var).second.num_ghosts[2];
if ((num_ghosts[0] == 0) &&
(num_ghosts[1] == 0) &&
(num_ghosts[2] == 0))
should_ghost_this_patch = false;
}
if (should_ghost_this_patch)
debug5 << "avtSAMRAIFileFormat::ReadMesh has ghost layers " <<
num_ghosts[0] << ", " << num_ghosts[1] << ", " << num_ghosts[2] << endl;
}
// compute logical size in each dimension of this patch
int i, dimensions[] = {1, 1, 1};
for (i=0; i<dim; i++) {
dimensions[i] = patch_extents[patch].upper[i] -
patch_extents[patch].lower[i] + 2 +
2 * num_ghosts[i];
}
if (grid_type == "RECTILINEAR" || grid_type == "CARTESIAN")
{
// compute physical origin and cell-spacing
float spacing[] = {0, 0, 0};
float origin[] = {0, 0, 0};
for (i=0; i<dim; i++) {
spacing[i] = dx[level * 3 + i];
origin[i] = patch_extents[patch].xlo[i] -
spacing[i] * num_ghosts[i];
}
vtkFloatArray *coords[3];
for (i = 0 ; i < 3 ; i++)
{
// Default number of components for an array is 1.
coords[i] = vtkFloatArray::New();
coords[i]->SetNumberOfTuples(dimensions[i]);
for (int j = 0 ; j < dimensions[i] ; j++)
{
float c = origin[i] + j * spacing[i];
coords[i]->SetComponent(j, 0, c);
}
}
vtkRectilinearGrid *rGrid = vtkRectilinearGrid::New();
rGrid->SetDimensions(dimensions);
rGrid->SetXCoordinates(coords[0]);
coords[0]->Delete();
rGrid->SetYCoordinates(coords[1]);
coords[1]->Delete();
rGrid->SetZCoordinates(coords[2]);
coords[2]->Delete();
retval = rGrid;
}
else if (grid_type == "ALE" || grid_type == "DEFORMED")
{
char var_name[100];
sprintf(var_name, "Coords");
vtkDataArray * array = GetVectorVar(patch, var_name);
vtkPoints *points = vtkPoints::New();
points->SetData(array);
array->Delete();
vtkStructuredGrid *sGrid = vtkStructuredGrid::New();
sGrid->SetDimensions(dimensions);
sGrid->SetPoints(points);
points->Delete();
retval = sGrid;
}
else {
char dummyVarName[128];
sprintf(dummyVarName,"amr_mesh, patch %d", patch);
EXCEPTION1(InvalidVariableException, dummyVarName);
}
// Add ghost information if we should
if (should_ghost_this_patch)
{
int nghost = 0;
int ncells = 1;
int i;
for (i = 0; i < dim; i++)
ncells *= (dimensions[i]-1);
vtkUnsignedCharArray *ghostCells = vtkUnsignedCharArray::New();
ghostCells->SetName("avtGhostZones");
ghostCells->Allocate(ncells);
// fill in ghost value (0/1) for each cell
for (i = 0; i < ncells; i++)
{
bool in_ghost_layers = false;
// determine if cell is in ghost layers
int cell_idx = i;
for (int j = 0; j < dim; j++)
{
int nj = dimensions[j] - 1;
int jidx = cell_idx % nj;
if ((jidx < num_ghosts[j]) || (jidx >= nj - num_ghosts[j]))
{
in_ghost_layers = true;
break;
}
cell_idx = cell_idx / nj;
}
if (in_ghost_layers)
{
unsigned char v = 0;
avtGhostData::AddGhostZoneType(v,
DUPLICATED_ZONE_INTERNAL_TO_PROBLEM);
ghostCells->InsertNextValue(v);
nghost++;
}
else
ghostCells->InsertNextValue((unsigned char)0);
}
// now, attach the ghost data to the grid
retval->GetCellData()->AddArray(ghostCells);
ghostCells->Delete();
debug5 << "avtSAMRAIFileFormat::ReadMesh ghosted " <<
100*nghost/ncells << "% of cells" << endl;
}
//
// Emulate VisIt's notion of a block-structured grid by setting
// the 'base_index' magic data array for this vtk grid
//
vtkIntArray *arr = vtkIntArray::New();
arr->SetNumberOfTuples(3);
for (i=0; i<dim; i++)
arr->SetValue(i, patch_extents[patch].lower[i] - num_ghosts[i]);
for (i=dim; i<3; i++)
arr->SetValue(i, 0);
arr->SetName("base_index");
retval->GetFieldData()->AddArray(arr);
arr->Delete();
return retval;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::GetVar
//
// Purpose:
// Reads the variable with the given name for the given time step and
// domain.
//
// Note: The Generic Database (which calls this function) already handles
// caching for a single time step.
//
// Arguments:
// ts the time step
// dom the domain number
// name the name of the variable to read
//
// Programmer: Walter Herrera Jimenez
// Creation: July 18, 2003
//
// Modifications:
// Kathleen Bonnell, Mon Dec 22 15:06:41 PST 2003
// Added code to delete hdims, max_hdims.
//
// Mark C. Miller, Tue Jan 13 14:23:38 PST 2004
// Replaced with call to ReadVar to reduce duplication of code
//
// ****************************************************************************
vtkDataArray *
avtSAMRAIFileFormat::GetVar(int patch, const char *visit_var_name)
{
return ReadVar(patch, visit_var_name);
}
vtkDataArray *
avtSAMRAIFileFormat::GetVectorVar(int patch, const char *visit_var_name)
{
return ReadVar(patch, visit_var_name);
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::ReadVar
//
// Purpose:
// Reads a scalar, vector or tensor variable with the given name for the
// given domain.
//
// Arguments:
// patch the patch number
// visit_var_name the name of the variable to read
// expected_num_comps the expected number of components
//
// Programmer: Walter Herrera Jimenez
// Creation: July 18, 2003
//
// Modifications:
// Eric Brugger, Tue Dec 30 16:37:26 PST 2003
// I modified the routine to properly read vector (and coordinate) data.
// This involved file format as well as reader changes. In this case
// I modified the routine to handle the variable name without the extension
// (.00, .01, .02) identifying the component.
//
// Mark C. Miller, Wed Jan 7 11:35:37 PST 2004
// I eliminated use of VTK SetComponent methods as well as extra buffer
// copies. Now, HDF5 reads the data directly into the buffer space allocated
// by VTK in the vtkFloatArray object.
//
// Mark C. Miller, Tue Jan 13 13:45:31 PST 2004
// Renamed from GetVectorVar to ReadVar
//
// Brad Whitlock, Fri Mar 5 10:19:32 PDT 2004
// Changed for Windows compiler.
//
// Mark C. Miller, Wed May 19 10:56:11 PDT 2004
// Re-factored code having to do with guessing variable type to avtTypes
// function GuessVarTypeFromNumDimsAndComps
//
// Mark C. Miller, Mon Aug 23 14:17:55 PDT 2004
// Made it use OpenFile instead of H5Fopen directly. Removed call to
// H5Fclose
//
// Mark C. Miller, Thu Apr 6 17:06:33 PDT 2006
// Added conditional compilation for hssize_t type
//
// Mark C. Miller, Mon Nov 5 19:08:57 PST 2007
// Added support for mixed variable components
//
// ****************************************************************************
vtkDataArray *
avtSAMRAIFileFormat::ReadVar(int patch,
const char *visit_var_name)
{
debug5 << "avtSAMRAIFileFormat::ReadVar for variable " << visit_var_name
<< "on patch " << patch << endl;
string var_name = visit_var_name;
// find the variable name in our variable list
std::map<std::string, var_t>::const_iterator cur_var;
cur_var = var_names_num_components.find(var_name);
if (cur_var == var_names_num_components.end())
{
EXCEPTION1(InvalidVariableException, visit_var_name);
}
// get component count, centering and ghost information for this variable
int num_components = (*cur_var).second.num_components;
int cell_centered = (*cur_var).second.cell_centered;
int num_ghosts[3] = {(*cur_var).second.num_ghosts[0],
(*cur_var).second.num_ghosts[1],
(*cur_var).second.num_ghosts[2]};
// compute total number of samples
int extent = cell_centered == 1 ? 1 : 2;
int dim = num_dim_problem < 3 ? num_dim_problem: 3;
int num_data_samples = 1;
int i;
for (i=0; i<dim; i++) {
num_data_samples *= patch_extents[patch].upper[i] -
patch_extents[patch].lower[i] + extent + 2 * num_ghosts[i];
}
// verify we actually have data on this patch
for (int v = 0; v < num_vars; v++) {
if (var_names[v] == var_name) {
if (!var_extents[v][patch].data_is_defined) {
return NULL;
}
break;
}
}
// determine the name of the file that contains the variable and open it
char file[2048];
sprintf(file, "%sprocessor_cluster.%05d.samrai",
dir_name.c_str(), patch_map[patch].file_cluster_number);
hid_t h5f_file = OpenFile(file);
if (h5f_file < 0)
{
EXCEPTION1(InvalidFilesException, file);
}
// guess var_type from problem dimensions and number of components
avtVarType var_type = GuessVarTypeFromNumDimsAndComps(num_dim_problem, num_components);
if (var_type == AVT_UNKNOWN_TYPE)
{
EXCEPTION1(InvalidVariableException, visit_var_name);
}
// determine number of components to allocate in VTK data array
int num_alloc_comps = 0;
switch (var_type)
{
case AVT_SCALAR_VAR: num_alloc_comps = 1; break;
case AVT_VECTOR_VAR: num_alloc_comps = 3; break;
case AVT_SYMMETRIC_TENSOR_VAR:
case AVT_TENSOR_VAR: num_alloc_comps = 9; break;
default: break;
}
if (num_alloc_comps == 0)
{
EXCEPTION2(UnexpectedValueException, "a value other than zero", num_alloc_comps);
}
// allocate VTK data array for this variable
vtkFloatArray *var_data = vtkFloatArray::New();
var_data->SetNumberOfComponents(num_alloc_comps);
var_data->SetNumberOfTuples(num_data_samples);
float *fbuf = (float*) var_data->GetVoidPointer(0);
for (i = 0 ; i < num_components ; i++)
{
// determine name of the HDF5 dataset and open it
char variable[256];
char mixvar[512];
if (var_type == AVT_SCALAR_VAR)
{
sprintf(variable, "/processor.%05d/level.%05d/patch.%05d/%s",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number,
var_name.c_str());
sprintf(mixvar, "/processor.%05d/level.%05d/patch.%05d/material_state/%s",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number,
var_name.c_str());
}
else
{
sprintf(variable, "/processor.%05d/level.%05d/patch.%05d/%s.%02d",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number,
var_name.c_str(), i);
sprintf(mixvar, "/processor.%05d/level.%05d/patch.%05d/material_state/%s.%02d",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number,
var_name.c_str(), i);
}
hid_t h5d_variable = H5Dopen(h5f_file, variable);
if (h5d_variable < 0)
{
EXCEPTION1(InvalidFilesException, file);
}
// check dataset size agrees with what we computed for num_data_samples
hid_t h5d_space = H5Dget_space(h5d_variable);
int hndims = H5Sget_simple_extent_ndims(h5d_space);
hsize_t *hdims = new hsize_t[hndims];
hsize_t *max_hdims = new hsize_t[hndims];
H5Sget_simple_extent_dims(h5d_space, hdims, max_hdims);
hsize_t hsum = 1;
for (int j = 0; j < hndims; j++)
hsum *= hdims[j];
if ((hsize_t) num_data_samples != hsum)
{
EXCEPTION2(UnexpectedValueException, num_data_samples, hsum);
}
H5Sclose(h5d_space);
delete [] hdims;
delete [] max_hdims;
// create dataspace and selection to read directly into fbuf
hsize_t nvals = num_alloc_comps * num_data_samples;
hid_t memspace = H5Screate_simple(1, &nvals, &nvals);
#if HDF5_VERSION_GE(1,6,4)
hsize_t start = i;
#else
hssize_t start = i;
#endif
hsize_t stride = num_alloc_comps;
hsize_t count = num_data_samples;
H5Sselect_hyperslab(memspace, H5S_SELECT_SET, &start, &stride, &count, NULL);
H5Dread(h5d_variable, H5T_NATIVE_FLOAT, memspace, H5S_ALL, H5P_DEFAULT, fbuf);
H5Dclose(h5d_variable);
H5Sclose(memspace);
//
// Ok, now read any material-specific fractional values for this component
//
hid_t h5d_mixvar = H5Dopen(h5f_file, mixvar);
if (h5d_mixvar < 0)
continue;
// allocate a float buffer for the mixed values
h5d_space = H5Dget_space(h5d_mixvar);
hndims = H5Sget_simple_extent_ndims(h5d_space);
hdims = new hsize_t[hndims];
max_hdims = new hsize_t[hndims];
H5Sget_simple_extent_dims(h5d_space, hdims, max_hdims);
hsum = 1;
for (int j = 0; j < hndims; j++)
hsum *= hdims[j];
float *mbuf = new float[(int)hsum];
// do the actual read
H5Dread(h5d_mixvar, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, mbuf);
//
// Create VisIt's mixed variable structure and stuff it into the cache
//
avtMixedVariable *mv = new avtMixedVariable(mbuf, (int) hsum,
visit_var_name);
void_ref_ptr vr = void_ref_ptr(mv, avtMixedVariable::Destruct);
cache->CacheVoidRef(visit_var_name, AUXILIARY_DATA_MIXED_VARIABLE, timestep,
patch, vr);
// Clean everything for the mixed var case up
H5Sclose(h5d_space);
delete [] hdims;
delete [] max_hdims;
H5Dclose(h5d_mixvar);
}
// fill in 0's when necessary
if (num_alloc_comps != num_components)
{
int i;
for (i=0; i < num_data_samples; i++)
{
int j;
for (j = num_components; j < num_alloc_comps; j++)
fbuf[i * num_alloc_comps + j] = 0.0;
}
}
// update last patch/var information
last_visit_var_name = visit_var_name;
last_patch = patch;
return var_data;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::ReadMatSpecFractions
//
// Purpose:
// Reads material volume and species fraction arrays for a given material
//
// Programmer: Mark C. Miller, adapted from GetVar
// Creation: December 12, 2003
//
// Modifications:
// Kathleen Bonnell, Mon Dec 22 15:06:41 PST 2003
// Added code to delete hdims, max_hdims.
//
// Brad Whitlock, Fri Mar 5 10:19:32 PDT 2004
// Changed for Windows compiler.
//
// Mark C. Miller, Mon Aug 23 14:17:55 PDT 2004
// Made it use OpenFile instead of H5Fopen and removed call to H5Fclose
//
// ****************************************************************************
float *
avtSAMRAIFileFormat::ReadMatSpecFractions(int patch, string mat_name,
string spec_name)
{
int i;
debug5 << "avtSAMRAIFileFormat::ReadMatSpecFractions for material "
<< mat_name.c_str() << ", on patch " << patch << endl;
// if we ever get here expecting to actually read fractions for the
// inferred void material, something is really wrong
if (mat_name == inferredVoidMatName)
{
EXCEPTION2(UnexpectedValueException, "something other than void", mat_name);
}
int matNo = -1;
for (i = 0; i < num_mats; i++)
{
if (mat_names[i] == mat_name)
{
matNo = i;
break;
}
}
if (matNo == -1)
{
EXCEPTION1(InvalidVariableException, mat_name.c_str());
}
int dim = num_dim_problem < 3 ? num_dim_problem: 3;
int num_data_samples = 1;
for (i=0; i<dim; i++) {
num_data_samples *= patch_extents[patch].upper[i] -
patch_extents[patch].lower[i] + 1 +
2 * mat_num_ghosts[i];
}
char file[512];
sprintf(file, "%sprocessor_cluster.%05d.samrai",
dir_name.c_str(), patch_map[patch].file_cluster_number);
char variable[1024];
if (spec_name == "")
{
sprintf(variable, "/processor.%05d/level.%05d/patch.%05d/"
"materials/%s/%s-fractions",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number,
mat_name.c_str(), mat_name.c_str());
}
else
{
sprintf(variable, "/processor.%05d/level.%05d/patch.%05d/"
"materials/%s/species/%s",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number,
mat_name.c_str(), spec_name.c_str());
}
hid_t h5f_file = OpenFile(file);
if (h5f_file < 0)
{
EXCEPTION1(InvalidFilesException, file);
}
hid_t h5d_variable = H5Dopen(h5f_file, variable);
if (h5d_variable < 0)
{
EXCEPTION1(InvalidFilesException, file);
}
// check dataset size agrees with what we computed for num_data_samples
hid_t h5d_space = H5Dget_space(h5d_variable);
int hndims = H5Sget_simple_extent_ndims(h5d_space);
hsize_t *hdims = new hsize_t[hndims];
hsize_t *max_hdims = new hsize_t[hndims];
H5Sget_simple_extent_dims(h5d_space, hdims, max_hdims);
hsize_t hsum = 1;
for (i = 0; i < hndims; i++)
hsum *= hdims[i];
if ((hsize_t) num_data_samples != hsum)
{
EXCEPTION2(UnexpectedValueException, num_data_samples, hsum);
}
H5Sclose(h5d_space);
delete [] hdims;
delete [] max_hdims;
float *buffer = new float[num_data_samples];
H5Dread(h5d_variable, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
buffer);
H5Dclose(h5d_variable);
return buffer;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::ReadSparseMaterialData
//
// Purpose: Read sparse mixed material information a la Silo's mixed structs
//
// Programmer: Mark C. Miller,
// Creation: November 1, 2005
//
// ****************************************************************************
avtMaterial *
avtSAMRAIFileFormat::ReadSparseMaterialData(int patch, const int *matnos,
const char **matnames)
{
int i;
int one = 1;
avtMaterial *mat = 0;
char domName[256];
SNPRINTF(domName, sizeof(domName), "patch_%d", patch);
// compute logical size in each dimension of this patch
int dim = num_dim_problem < 3 ? num_dim_problem: 3;
int dims[] = {1, 1, 1};
int ncells = 1;
for (i=0; i<dim; i++)
{
dims[i] = patch_extents[patch].upper[i] -
patch_extents[patch].lower[i] + 1 +
2 * mat_num_ghosts[i];
ncells *= dims[i];
}
char file[512];
sprintf(file, "%sprocessor_cluster.%05d.samrai",
dir_name.c_str(), patch_map[patch].file_cluster_number);
hid_t h5_file = OpenFile(file);
if (h5_file < 0)
{
EXCEPTION1(InvalidFilesException, file);
}
char dsName[1024];
sprintf(dsName, "/processor.%05d/level.%05d/patch.%05d/"
"materials/mat_list",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number);
// First, try reading a dataset of size equal to patch size.
int *matlist = 0;
int len = -1;
ReadDataset(h5_file, dsName,
"int", 1, &len, (void**) &matlist, true);
// If the above read failed, it may be clean in one material.
// So, try to read that.
if (len == 1)
{
int *matlist_tmp = new int[ncells];
for (i = 0; i < ncells; i++)
matlist_tmp[i] = matlist[0];
delete [] matlist;
mat = new avtMaterial(num_mats, //silomat->nmat,
matnos, //silomat->matnos,
(char**) matnames, //silomat->matnames,
dim, //silomat->ndims,
dims, //silomat->dims,
0, //silomat->major_order,
matlist_tmp, //silomat->matlist,
0, //silomat->mixlen,
0, //silomat->mix_mat,
0, //silomat->mix_next,
0, //silomat->mix_zone,
0, //silomat->mix_vf
domName);
delete [] matlist_tmp;
return mat;
}
// ok, try to read the mix info, if it exists
sprintf(dsName, "/processor.%05d/level.%05d/patch.%05d/"
"materials/next_mat",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number);
int *mix_next = 0;
int *mix_mat = 0;
int *mix_zone = 0;
float *mix_vf = 0;
int mixlen = -1;
ReadDataset(h5_file, dsName,
"int", 1, &mixlen, (void**) &mix_next, true);
if (mixlen > 0 && mix_next != 0)
{
sprintf(dsName, "/processor.%05d/level.%05d/patch.%05d/"
"materials/mix_mat",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number);
ReadDataset(h5_file, dsName,
"int", 1, &mixlen, (void**) &mix_mat, false);
sprintf(dsName, "/processor.%05d/level.%05d/patch.%05d/"
"materials/mix_zones",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number);
ReadDataset(h5_file, dsName,
"int", 1, &mixlen, (void**) &mix_zone, false);
sprintf(dsName, "/processor.%05d/level.%05d/patch.%05d/"
"materials/vol_fracs",
patch_map[patch].processor_number,
patch_map[patch].level_number,
patch_map[patch].patch_number);
ReadDataset(h5_file, dsName,
"float", 1, &mixlen, (void**) &mix_vf, false);
}
mat = new avtMaterial(num_mats, //silomat->nmat,
matnos, //silomat->matnos,
(char**) matnames, //silomat->matnames,
dim, //silomat->ndims,
dims, //silomat->dims,
0, //silomat->major_order,
matlist, //silomat->matlist,
mixlen, //silomat->mixlen,
mix_mat, //silomat->mix_mat,
mix_next, //silomat->mix_next,
mix_zone, //silomat->mix_zone,
mix_vf, //silomat->mix_vf
domName);
SAFE_DELETE(matlist);
SAFE_DELETE(mix_mat);
SAFE_DELETE(mix_next);
SAFE_DELETE(mix_zone);
SAFE_DELETE(mix_vf);
return mat;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::GetMaterial
//
// Purpose:
// Gets an avtMaterial object for a given patch
//
// Programmer: Mark C. Miller
// Creation: December 12, 2003
//
// Modifications:
// Mark C. Miller, Wed Jan 7 11:35:37 PST 2004
// Added stuff to compute compression achieved
//
// Mark C. Miller, Thu May 6 22:07:32 PDT 2004
// Used new material constructors
//
// Eric Brugger, Wed May 12 13:37:29 PDT 2004
// Modify the allocation of an array of float pointers so that it
// compiles on all platforms.
//
// Kathleen Bonnell, Mon May 23 16:55:35 PDT 2005
// Fix memory leaks.
//
// Mark C. Miller, Mon Nov 5 19:10:12 PST 2007
// Added support for sparse material information
//
// ****************************************************************************
avtMaterial *
avtSAMRAIFileFormat::GetMaterial(int patch, const char *matObjName)
{
int i;
double bytesInFile = 0.0;
static double bytesInFileTotal = 0.0;
double bytesInMem = 0.0;
static double bytesInMemTotal = 0.0;
avtMaterial *mat = NULL;
debug5 << "avtSAMRAIFileFormat::GetMaterial getting materials on patch "
<< patch << endl;
// if we don't have any materials, there is nothing to do
if (has_mats == false)
{
EXCEPTION1(InvalidVariableException, matObjName);
}
// re-format global mat numbers and names
int *matnos = new int[num_mats];
char **matnames = new char*[num_mats];
for (i = 0; i < num_mats; i++)
{
matnos[i] = i;
matnames[i] = CXX_strdup(mat_names[i].c_str());
}
// if we have the newer, sparse format read and return that
if (sparse_mat_info && sparse_mat_info[patch].data_is_defined != 0)
{
mat = ReadSparseMaterialData(patch, matnos, (const char**) matnames);
// free up the matnames and numbers
SAFE_DELETE(matnos);
for (i = 0; i < num_mats; i++)
SAFE_DELETE(matnames[i]);
SAFE_DELETE(matnames);
return mat;
}
// first, determine which material nos., if any, we actually have on this patch
bool oneMat = false;
std::vector<int> matList;
for (i = 0; i < num_mats; i++)
{
// since the inferred "void" material doesn't really exist, we skip it
if (mat_names[i] == inferredVoidMatName)
continue;
int matCompFlag = mat_names_matinfo[mat_names[i]][patch].mat_comp_flag;
switch (matCompFlag)
{
case 0: // this material covers no part of the patch
break;
case 1: // this material covers the patch, wholly
matList.push_back(i);
oneMat = true;
break;
case 2: // this material covers the patch, partially
matList.push_back(i);
break;
default:
{
EXCEPTION2(UnexpectedValueException,
"a value for material_composition_flag of 0,1 or 2",
matCompFlag);
}
}
}
// if we get to here, we must have some material
if (matList.size() == 0)
{
// if we didn't find any materials on this patch AND we
// are NOT inferring a void material, it must be an error
if (inferVoidMaterial == false)
{
EXCEPTION1(InvalidVariableException, matObjName);
}
else
{
// this is the case where we have a clean, inferred void
// material
oneMat = true;
matList.push_back(num_mats-1);
}
}
// if we encountered the 'one mat' case, above, make sure we only got
// one material
if ((oneMat == true) && (matList.size() > 1))
{
EXCEPTION2(UnexpectedValueException, 1, matList.size());
}
// compute logical size in each dimension of this patch
int dim = num_dim_problem < 3 ? num_dim_problem: 3;
int dims[] = {1, 1, 1};
int ncells = 1;
for (i=0; i<dim; i++)
{
dims[i] = patch_extents[patch].upper[i] -
patch_extents[patch].lower[i] + 1 +
2 * mat_num_ghosts[i];
ncells *= dims[i];
}
if (oneMat)
{
// create a matlist array for this single material
int *matlist = new int[ncells];
for (i = 0; i < ncells; i++)
matlist[i] = matList[0];
mat = new avtMaterial(num_mats, //silomat->nmat,
matnos, //silomat->matnos,
matnames, //silomat->matnames,
dim, //silomat->ndims,
dims, //silomat->dims,
0, //silomat->major_order,
matlist, //silomat->matlist,
0, //silomat->mixlen,
0, //silomat->mix_mat,
0, //silomat->mix_next,
0, //silomat->mix_zone,
0 //silomat->mix_vf
);
bytesInFile = 0.0;
bytesInMem = (ncells * sizeof(int));
delete [] matlist;
}
else
{
float **vfracs = new float*[num_mats];
for (i = 0; i < num_mats; i++)
vfracs[i] = 0;
// read the volume fractions for each material
for (i = 0; i < matList.size(); i++)
{
vfracs[matList[i]] = ReadMatSpecFractions(patch, mat_names[matList[i]]);
bytesInFile += (ncells * sizeof(float));
}
// check to see if we've hit the case where we need to infer
// the void material for this patch and that it is ok to do so
if (matList.size() == 1)
{
if (inferVoidMaterial == false)
{
EXCEPTION2(UnexpectedValueException, "2 or more materials", 1);
}
// infer the void's volume fractions
vfracs[num_mats-1] = new float[ncells];
for (i = 0; i < ncells; i++)
vfracs[num_mats-1][i] = 1.0 - vfracs[matList[0]][i];
}
//
// Construct the object we came here for
//
char domName[256];
SNPRINTF(domName, sizeof(domName),"%d", patch);
mat = new avtMaterial(num_mats, matnos, matnames, dim, dims, 0,
vfracs, domName);
for (i = 0; i < num_mats; i++)
SAFE_DELETE(vfracs[i]);
SAFE_DELETE(vfracs);
bytesInMem = (ncells * sizeof(int) + mat->GetMixlen() * (3*sizeof(int)+sizeof(float)));
}
// free up the matnames and numbers
SAFE_DELETE(matnos);
for (i = 0; i < num_mats; i++)
SAFE_DELETE(matnames[i]);
SAFE_DELETE(matnames);
bytesInFileTotal += bytesInFile;
bytesInMemTotal += bytesInMem;
debug5 << "compression of material data on patch " << patch << " is "
<< bytesInFile / bytesInMem << "x [cummulative = "
<< bytesInFileTotal / bytesInMemTotal << "x]" << endl;
return mat;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::ConvertVolumeFractionFields
//
// Purpose: Converts full-zonal arrays of volume fraction fields into AVT's
// (and Silo's) material field plus mix arrays representation.
//
// Programmer: Mark C. Miller
// Creation: December 12, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ConvertVolumeFractionFields(vector<int> matIds,
float **vfracs, int ncells, int* &matfield, int &mixlen, int* &mix_mat,
int* &mix_next, int* &mix_zone, float* &mix_vf)
{
int i,m,z;
// compute a value to be used as the 'notSet' value in matfield array
int notSet = matIds[0];
for (m = 1; m < matIds.size(); m++)
{
if (notSet < matIds[m])
notSet = matIds[m];
}
notSet++; // one more than largest mat number
// allocate and fill matfield array with the 'notSet' value
matfield = new int[ncells];
for (i = 0; i < ncells; i++)
matfield[i] = notSet;
// pre-compute size of mix arrays
mixlen = 0;
for (m = 0; m < matIds.size(); m++)
{
for (z = 0; z < ncells; z++)
{
if ((vfracs[m][z] > 0.0) &&
(vfracs[m][z] < 1.0))
mixlen++;
}
}
// allocate mix arrays
mix_mat = new int[mixlen];
mix_vf = new float[mixlen];
mix_zone = new int[mixlen];
mix_next = new int[mixlen];
// loop over materials
mixlen = 0;
for (m = 0; m < matIds.size(); m++)
{
float *frac = vfracs[m];
// loop over zones
for (z = 0; z < ncells; z++)
{
if (frac[z] == 1.0)
{
if (matfield[z] != notSet)
{
EXCEPTION2(UnexpectedValueException, "the 'notSet' value", matfield[z]);
}
matfield[z] = matIds[m];
}
else if ((1.0 > frac[z]) && (frac[z] > 0.0))
{
if (matfield[z] == notSet)
{
// put the first entry in the list for this zone
matfield[z] = -(mixlen+1);
mix_mat [mixlen] = matIds[m];
mix_vf [mixlen] = frac[z];
mix_zone[mixlen] = z;
mix_next[mixlen] = 0;
}
else
{
if (matfield[z] >= 0)
{
EXCEPTION2(UnexpectedValueException, "a value < 0", matfield[z]);
}
// walk forward through the list for this zone
int j = -(matfield[z]+1);
while (mix_next[j] != 0)
j = mix_next[j];
// link up last entry in list with the new entry
mix_next[j] = mixlen;
// put in the new entry
mix_mat [mixlen] = matIds[m];
mix_vf [mixlen] = frac[z];
mix_zone[mixlen] = z;
mix_next[mixlen] = 0;
}
mixlen++;
}
else if (frac[z] != 0.0)
{
EXCEPTION2(UnexpectedValueException, "a value between 0.0 and 1.0",
frac[z]);
}
}
}
#if 0
debug5 << DebugMixedMaterials(ncells, matfield, mix_next, mix_mat,
mix_vf, mix_zone) << endl;
#endif
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::DebugMixedMaterials
//
// Purpose:
// Checks mixed material arrays for correctness
//
// Programmer: Mark C. Miller
// Creation: December 12, 2003
//
// ****************************************************************************
char
avtSAMRAIFileFormat::DebugMixedMaterials(int ncells, int* &matfield,
int* &mix_next, int* &mix_mat, float* &mix_vf, int* &mix_zone)
{
debug5 << "parsing mixed arrays..." << endl;
int z;
int nclean = 0;
int nmixed = 0;
for (z = 0; z < ncells; z++)
{
if (matfield[z] >= 0)
{
nclean++;
debug5 << "zone " << z << " is clean in material " << matfield[z] << endl;
}
else
{
nmixed++;
debug5 << "zone " << z << " is mixed with materials ";
int mixidx = -(matfield[z]+1);
float vfsum = 0.0;
// deal with index into first entry
if (mixidx == 0)
{
debug5 << mix_mat[0] << " (" << (int) (100*mix_vf[0]) << "%), ";
vfsum += mix_vf[0];
mixidx = mix_next[0];
}
while (mixidx != 0)
{
debug5 << mix_mat[mixidx] << " (" << (int) (100*mix_vf[mixidx]) << "%), ";
vfsum += mix_vf[mixidx];
mixidx = mix_next[mixidx];
}
debug5 << endl;
if (vfsum != 1.0)
debug5 << "***VOL-FRAC SUM ERROR***" << endl;
}
}
debug5 << "clean/mixed = " << nclean << "/" << nmixed << endl;
return ' ';
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::GetSpecies
//
// Purpose:
// Gets an avtSpecies object for a given patch
//
// Programmer: Mark C. Miller
// Creation: December 18, 2003
//
// Modifications:
// Mark C. Miller, Wed Jan 7 11:35:37 PST 2004
// Added stuff to compute amount of compression achieved
//
// Kathleen Bonnell, Mon May 23 16:55:35 PDT 2005
// Fix memory leaks.
//
// ****************************************************************************
avtSpecies *
avtSAMRAIFileFormat::GetSpecies(int patch, const char *specObjName)
{
int i;
avtMaterial* mat = 0;
double bytesInFile = 0.0;
static double bytesInFileTotal = 0.0;
double bytesInMem = 0.0;
static double bytesInMemTotal = 0.0;
if (has_specs == false)
{
EXCEPTION1(InvalidVariableException, specObjName);
}
//
// we need the mixed material format computed during a GetMaterial call
//
void_ref_ptr vrTmp = cache->GetVoidRef("materials", AUXILIARY_DATA_MATERIAL,
timestep, patch);
if (*vrTmp == 0)
{
void *p = (void*) GetMaterial(patch, "materials");
vrTmp = void_ref_ptr(p, avtMaterial::Destruct);
cache->CacheVoidRef("materials", AUXILIARY_DATA_MATERIAL, timestep,
patch, vrTmp);
}
mat = (avtMaterial*) *vrTmp;
if (mat == 0)
{
char str[1024];
sprintf(str,"Unable to obtain material object on patch %d to satisfy "
"cooresponding query for species object \"%s\"", patch,
specObjName);
EXCEPTION1(InvalidFilesException, str);
}
debug5 << "avtSAMRAIFileFormat::GetSpecies getting species on patch "
<< patch << endl;
//
// scan the material "extents" info to determine which species to read
//
int totalNumSpecs = 0;
vector<int> matList;
for (i = 0; i < num_mats; i++)
{
// since the inferred "void" material doesn't really exist, we skip it
if (mat_names[i] == inferredVoidMatName)
continue;
int matCompFlag = mat_names_matinfo[mat_names[i]][patch].mat_comp_flag;
switch (matCompFlag)
{
case 0: // this material covers no part of the patch
break;
case 1: // this material covers the patch, wholly
case 2: // this material covers the patch, partially
{
matList.push_back(i);
totalNumSpecs += nmatspec[i];
break;
}
default:
{
EXCEPTION2(UnexpectedValueException,
"a value for material_composition_flag of 0,1 or 2",
matCompFlag);
}
}
}
// compute logical size in each dimension of this patch
int dim = num_dim_problem < 3 ? num_dim_problem: 3;
int dims[] = {1, 1, 1};
int ncells = 1;
for (i=0; i<dim; i++)
{
dims[i] = patch_extents[patch].upper[i] -
patch_extents[patch].lower[i] + 1 +
2 * mat_num_ghosts[i];
ncells *= dims[i];
}
// if this patch has no species, return a clean species object
if (totalNumSpecs == 0)
{
int mixlen = mat->GetMixlen();
int *mixList = new int[mixlen];
for (i = 0; i < mixlen; i++)
mixList[i] = 0;
int *specList = new int[ncells];
for (i = 0; i < ncells; i++)
specList[i] = 0;
avtSpecies *spec = new avtSpecies(num_mats, nmatspec, dim, dims, specList, mixlen,
mixList, 0, NULL);
bytesInFile = 0.0;
bytesInMem = (mixlen + ncells) * sizeof(int);
bytesInFileTotal += bytesInFile;
bytesInMemTotal += bytesInMem;
debug5 << "compression of species data on patch " << patch << " is "
<< bytesInFile / bytesInMem << "x [cummulative = "
<< bytesInFileTotal / bytesInMemTotal << "x]" << endl;
delete [] mixList;
delete [] specList;
return spec;
}
//
// build an array, indexed by material number, with pointers to
// mass fractions arrays. Only those materials that are ON this
// patch AND have more than 0 species have non-NULL mass fraction
// arrays
//
int currPatchMatId = 0;
vector<float**> matSpecFracs;
for (i = 0; i < num_mats; i++)
{
if (i == matList[currPatchMatId])
{
string matName = mat_names[i];
int numSpecs = nmatspec[i];
if (numSpecs > 0)
{
int j;
float **specFracs = new float*[numSpecs];
for (j = 0; j < numSpecs; j++)
{
specFracs[j] = ReadMatSpecFractions(patch, matName,
mat_specs[matName][j]);
bytesInFile += (ncells * sizeof(float));
}
matSpecFracs.push_back(specFracs);
}
else
{
matSpecFracs.push_back(NULL);
}
// inc. to next material id to be on the
// the lookout for
currPatchMatId++;
}
else
{
matSpecFracs.push_back(NULL);
}
}
int *specList;
int nspecies_mf;
float *species_mf;
int *mixList;
ConvertMassFractionFields(matList, matSpecFracs, ncells, mat,
specList, nspecies_mf, species_mf, mixList);
avtSpecies *spec = new avtSpecies(num_mats, nmatspec, dim, dims, specList,
mat->GetMixlen(), mixList, nspecies_mf,
species_mf);
//
// free up species fields
//
currPatchMatId = 0;
for (i = 0; i < num_mats; i++)
{
if (i == matList[currPatchMatId])
{
int j;
int numSpecs = nmatspec[i];
if (numSpecs > 0)
{
for (j = 0; j < numSpecs; j++)
SAFE_DELETE(matSpecFracs[i][j]);
}
SAFE_DELETE(matSpecFracs[i]);
currPatchMatId++;
}
}
free(species_mf);
SAFE_DELETE(mixList);
SAFE_DELETE(specList);
bytesInMem = (mat->GetMixlen() + ncells) * sizeof(int) + nspecies_mf * sizeof(float);
bytesInFileTotal += bytesInFile;
bytesInMemTotal += bytesInMem;
debug5 << "compression of species data on patch " << patch << " is "
<< bytesInFile / bytesInMem << "x [cummulative = "
<< bytesInFileTotal / bytesInMemTotal << "x]" << endl;
return spec;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::ConvertMassFractionFields
//
// Purpose: Convert from field per species to Silo representation
//
// Programmer: Mark C. Miller
// Creation: December 20, 2003
//
// Modifications:
// Mark C. Miller, Wed Jan 7 11:35:37 PST 2004
// Added stuff to compute unique species vectors for compression
//
// Mark C. Miller, Wed May 19 21:31:28 PDT 2004
// Corrected off by one error in mixed mat traversal
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ConvertMassFractionFields(vector<int> matIds,
vector<float**> matSpecFracs, int ncells, avtMaterial *mat,
int* &speclist, int &nspecies_mf, float* &species_mf, int* &mixlist)
{
int i,j;
const int* matlist = mat->GetMatlist();
const int* mix_mat = mat->GetMixMat();
const int* mix_next = mat->GetMixNext();
int mixlen = mat->GetMixlen();
#ifdef USE_UNIQUE_SPECIES
UniqueSpeciesMF uniq_species_mf(ncells,1.5);
#else
AutoArray<float> aaspecies_mf(ncells,ncells,true);
#endif
speclist = new int[ncells];
mixlist = new int[mixlen];
nspecies_mf = 1;
for (i = 0; i < ncells; i++)
{
int matNum = matlist[i];
if (matNum >= 0) // clean zone
{
// if this material has species, it should have species mf pointers
if ((nmatspec[matNum] != 0) && (matSpecFracs[matNum] == NULL))
{
EXCEPTION2(UnexpectedValueException, 0, nmatspec[matNum]);
}
if (nmatspec[matNum] == 0)
speclist[i] = 0;
else
{
#ifdef USE_UNIQUE_SPECIES
float *mf_vec = new float[nmatspec[matNum]];
for (j = 0; j < nmatspec[matNum]; j++)
mf_vec[j] = matSpecFracs[matNum][j][i];
speclist[i] = uniq_species_mf.IndexOfMFVector(mf_vec, nmatspec[matNum]);
delete [] mf_vec;
#else
speclist[i] = nspecies_mf;
for (j = 0; j < nmatspec[matNum]; j++)
aaspecies_mf[nspecies_mf++] = matSpecFracs[matNum][j][i];
#endif
}
}
else // mixed zone
{
speclist[i] = -INT_MAX;
int mixidx = -(matlist[i]+1);
while (true)
{
matNum = mix_mat[mixidx];
// if this material has species, it should have species mf pointers
if ((nmatspec[matNum] != 0) && (matSpecFracs[matNum] == NULL))
{
EXCEPTION2(UnexpectedValueException, 0, nmatspec[matNum]);
}
#ifdef USE_UNIQUE_SPECIES
float *mf_vec = new float[nmatspec[matNum]];
for (j = 0; j < nmatspec[matNum]; j++)
mf_vec[j] = matSpecFracs[matNum][j][i];
mixlist[mixidx] = uniq_species_mf.IndexOfMFVector(mf_vec, nmatspec[matNum]);
delete [] mf_vec;
#else
mixlist[mixidx] = nspecies_mf;
for (j = 0; j < nmatspec[matNum]; j++)
aaspecies_mf[nspecies_mf++] = matSpecFracs[matNum][j][i];
#endif
if (mix_next[mixidx] == 0)
break;
mixidx = mix_next[mixidx]-1;
}
}
}
#ifdef USE_UNIQUE_SPECIES
species_mf = uniq_species_mf.GetData();
nspecies_mf = uniq_species_mf.GetSize();
#else
species_mf = aaspecies_mf.GetData();
if (nspecies_mf != aaspecies_mf.GetSize())
{
EXCEPTION2(UnexpectedValueException, aaspecies_mf.GetSize(), nspecies_mf);
}
#endif
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::GetAuxiliaryData
//
// Purpose:
// Gets auxiliary data about the file format.
//
// Programmer: Walter Herrera Jimenez
// Creation: July 21, 2003
//
// Modifications:
// Eric Brugger, Tue Dec 30 16:37:26 PST 2003
// I modified the routine to properly read vector (and coordinate) data.
// This involved file format as well as reader changes. In this case
// I modified the way the routine built the interval tree from the
// extents associated with a vector.
//
// Mark C. Miller, Thu Oct 21 22:11:28 PDT 2004
// Fixed spatail extents for ALE mesh
//
// Kathleen Bonnell, Mon Aug 14 16:40:30 PDT 2006
// API change for avtIntervalTree.
//
// ****************************************************************************
void *
avtSAMRAIFileFormat::GetAuxiliaryData(const char *var, int patch,
const char *type, void *,
DestructorFunction &df)
{
string name = var;
void *rv = NULL;
avtIntervalTree *itree = NULL;
//
// For an ale grid, a spatial extents query is *really* a data extents
// query on the "Coords" variable
//
if ((strcmp(type, AUXILIARY_DATA_DATA_EXTENTS) == 0) ||
((strcmp(type, AUXILIARY_DATA_SPATIAL_EXTENTS) == 0) &&
(grid_type == "ALE" || grid_type == "DEFORMED"))) {
if (strcmp(type, AUXILIARY_DATA_SPATIAL_EXTENTS) == 0)
name = "Coords";
debug5 << "avtSAMRAIFileFormat::GetAuxiliaryData getting DATA_EXTENTS" << endl;
std::map<std::string, var_t>::const_iterator cur_var;
cur_var = var_names_num_components.find(name);
if (cur_var == var_names_num_components.end())
return NULL;
int num_components = (*cur_var).second.num_components;
if (num_components == 1 ) {
itree = new avtIntervalTree(num_patches, 1);
for (int v = 0; v < num_vars; v++) {
if (var_names[v] == name) {
for (int patch = 0 ; patch < num_patches ; patch++) {
if (var_extents[v][patch].data_is_defined) {
double range[2] = { var_extents[v][patch].min,
var_extents[v][patch].max };
itree->AddElement(patch, range);
}
else {
// if the varible does no have values, what will we add?
}
}
break;
}
}
} else {
itree = new avtIntervalTree(num_patches, 3);
for (int patch = 0 ; patch < num_patches; patch++) {
bool data_defined = true;
double range[6] = { 0, 0, 0, 0, 0, 0 };
int dim = num_components <= 3 ? num_components : 3;
for (int i=0; i<dim; i++) {
int ipatch = i * num_patches + patch;
for (int v = 0; v < num_vars; v++) {
if (var_names[v] == name) {
if (var_extents[v][ipatch].data_is_defined) {
range[i*2] = var_extents[v][ipatch].min;
range[i*2+1] = var_extents[v][ipatch].max;
}
else {
data_defined = false;
}
break;
}
}
}
if (data_defined) {
itree->AddElement(patch, range);
}
else {
// if the varible does no have values, what do we add?
}
}
}
itree->Calculate(true);
rv = (void *) itree;
df = avtIntervalTree::Destruct;
}
else if (strcmp(type, AUXILIARY_DATA_SPATIAL_EXTENTS) == 0) {
debug5 << "avtSAMRAIFileFormat::GetAuxiliaryData getting SPATIAL_EXTENTS" << endl;
itree = new avtIntervalTree(num_patches, 3);
for (int patch = 0 ; patch < num_patches ; patch++) {
double bounds[] = {0, 0, 0, 0, 0, 0};
int dim = num_dim_problem < 3 ? num_dim_problem: 3;
for (int j=0; j<dim; j++) {
bounds[j*2] = patch_extents[patch].xlo[j];
bounds[j*2+1] = patch_extents[patch].xup[j];
}
itree->AddElement(patch, bounds);
}
itree->Calculate(true);
rv = (void *) itree;
df = avtIntervalTree::Destruct;
}
else if (strcmp(type, AUXILIARY_DATA_MATERIAL) == 0)
{
rv = (void *) GetMaterial(patch, var);
df = avtMaterial::Destruct;
}
else if (strcmp(type, AUXILIARY_DATA_SPECIES) == 0)
{
rv = (void *) GetSpecies(patch, var);
df = avtSpecies::Destruct;
}
return rv;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::PopulateIOInformation
//
// Purpose:
// Populates IO Information Hints
//
// Programmer: Mark C. Miller
// Creation: August 19. 2004
//
// ****************************************************************************
void
avtSAMRAIFileFormat::PopulateIOInformation(avtIOInformation &ioInfo)
{
if (num_patches <= 1)
{
debug5 << "No need to do I/O optimization because there is only "
<< "one patch" << endl;
ioInfo.SetNDomains(1);
return;
}
if (num_clusters <= 1)
{
debug5 << "No need to do I/O optimization because there is only "
<< "one file for all patches" << endl;
ioInfo.SetNDomains(num_patches);
return;
}
//
// create an initial vector for each file cluster
//
vector< vector<int> > groups;
int i;
for (i = 0; i < num_clusters; i++)
{
vector<int> dummy;
groups.push_back(dummy);
}
//
// use the patch map and stick each patch into its respective cluster group
//
for (i = 0; i < num_patches; i++)
{
int clusterNum = patch_map[i].file_cluster_number;
groups[clusterNum].push_back(i);
}
ioInfo.SetNDomains(num_patches);
ioInfo.AddHints(groups);
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::GetCycleFromFilename, GetCycle, GetTime
//
// Programmer: Mark C. Miller
// Creation: November 8, 2005
//
// ****************************************************************************
int
avtSAMRAIFileFormat::GetCycleFromFilename(const char *f) const
{
if (f)
{
const int len1 = strlen("00000/summary.samrai");
const int len2 = strlen(f);
if (len2 > len1)
{
int cycle;
if (sscanf(&f[len2-len1], "%05d", &cycle) == 1)
return cycle;
}
}
return INVALID_CYCLE;
}
int
avtSAMRAIFileFormat::GetCycle()
{
if (time_step_number != INVALID_CYCLE)
return time_step_number;
hid_t summaryFile = H5Fopen(file_name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
ReadTimeStepNumber(summaryFile);
ReadTime(summaryFile); // might as well do this too since we're here
H5Fclose(summaryFile);
return time_step_number;
}
double
avtSAMRAIFileFormat::GetTime()
{
if (time != INVALID_TIME)
return time;
hid_t summaryFile = H5Fopen(file_name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
ReadTime(summaryFile);
ReadTimeStepNumber(summaryFile); // might as well do this too since we're here
H5Fclose(summaryFile);
return time;
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::PopulateDatabaseMetaData
//
// Purpose:
// Returns meta-data about the database.
//
// Arguments:
// md The meta-data structure to populate
//
// Programmer: Walter Herrera Jimenez
// Creation: June 19, 2003
//
// Modifications:
//
// Hank Childs, Wed Apr 14 08:02:14 PDT 2004
// Back out undocumented changes made by Mark Miller with adding material
// numbers to material names.
//
// Mark C. Miller, Mon Aug 23 14:17:55 PDT 2004
// Added code to set cycle/time info
//
// Hank Childs, Wed Jan 11 09:36:13 PST 2006
// Change rectilinear mesh type to AMR mesh type.
//
// Mark C. Miller, Wed Apr 25 15:58:58 PDT 2007
// Added md-specific code to NOT include default plot for a mesh with
// only 1 level. Added warning for this as well.
//
// Mark C. Miller, Sat Nov 3 09:31:00 PST 2007
// Made it create a subset plot of patches in cases num_levels == 1.
//
// Mark C. Miller, Mon Nov 5 19:34:12 PST 2007
// Added expressions
//
// ****************************************************************************
void
avtSAMRAIFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
{
int i;
debug5 << "avtSAMRAIFileFormat::PopulateDatabaseMetaData getting data" << endl;
{
static const char *mesh_name = "amr_mesh";
ReadMetaDataFile();
//
// Set cycle/time info
//
md->SetCycle(timestep, time_step_number);
md->SetCycleIsAccurate(true, timestep);
md->SetTime(timestep, time);
md->SetTimeIsAccurate(true, timestep);
avtMeshMetaData *mesh = new avtMeshMetaData;
mesh->name = mesh_name;
mesh->meshType = AVT_AMR_MESH;
mesh->topologicalDimension = num_dim_problem;
mesh->spatialDimension = num_dim_problem; // should really be set rank of "Coords"
mesh->hasSpatialExtents = false;
// spoof a group/domain mesh
mesh->numBlocks = num_patches;
mesh->blockTitle = "patches";
mesh->blockPieceName = "patch";
mesh->numGroups = num_levels;
mesh->groupTitle = "levels";
mesh->groupPieceName = "level";
vector<int> groupIds(num_patches);
vector<string> blockPieceNames(num_patches);
for (i = 0; i < num_patches; i++)
{
char tmpName[64];
sprintf(tmpName,"level%d,patch%d",patch_map[i].level_number, patch_map[i].patch_number);
groupIds[i] = patch_map[i].level_number;
blockPieceNames[i] = tmpName;
}
mesh->blockNames = blockPieceNames;
md->Add(mesh);
md->AddGroupInformation(num_levels, num_patches, groupIds);
//
// add material information, if any
//
if (has_mats == true)
{
// re-format the material names for avt's API
vector<string> matnames;
for (i = 0; i < num_mats; i++)
matnames.push_back(mat_names[i]);
// add the material object
avtMaterialMetaData *mmd = new avtMaterialMetaData("materials", mesh_name,
num_mats, matnames);
md->Add(mmd);
//
// add species information, if any
//
if (has_specs == true)
{
int j, k;
vector<int> nmatspecVector;
vector<vector<string> > spec_names;
for (j = 0; j < num_mats; j++)
{
vector<string> tmp_string_vector;
nmatspecVector.push_back(nmatspec[j]);
for (k = 0; k < nmatspec[j]; k++)
tmp_string_vector.push_back(mat_specs[mat_names[j]][k]);
spec_names.push_back(tmp_string_vector);
}
avtSpeciesMetaData *smd = new avtSpeciesMetaData("species",
mesh_name, "materials", num_mats,
nmatspecVector, spec_names);
md->Add(smd);
}
}
//
// add default plot (but only if we actually have 'levels'
//
if (num_patches > 1)
{
avtDefaultPlotMetaData *plot = new avtDefaultPlotMetaData("Subset_1.0",
num_levels > 1 ? "levels" : "patches");
char attribute[250];
sprintf(attribute,"%d NULL ViewerPlot", INTERNAL_NODE);
plot->AddAttribute(attribute);
sprintf(attribute,"%d ViewerPlot SubsetAttributes", INTERNAL_NODE);
plot->AddAttribute(attribute);
sprintf(attribute,"%d SubsetAttributes lineWidth 1", INT_NODE);
plot->AddAttribute(attribute);
sprintf(attribute,"%d SubsetAttributes wireframe true", BOOL_NODE);
plot->AddAttribute(attribute);
md->Add(plot);
}
#ifdef MDSERVER
else
{
char msg[512];
static bool haveIssuedWarning = false;
SNPRINTF(msg, sizeof(msg), "Ordinarily, VisIt displays a wireframe, subset "
"plot of 'levels' automatically upon opening a SAMRAI file. However, such "
"a plot is not applicable in the case that there is only one patch. So, "
"the normal subset plot is not being displayed.");
if (!haveIssuedWarning)
{
haveIssuedWarning = true;
if (!avtCallback::IssueWarning(msg))
cerr << msg << endl;
}
}
#endif
//
// add scalar and vector variables
//
std::map<std::string, var_t>::const_iterator var_it;
for (var_it = var_names_num_components.begin();
var_it != var_names_num_components.end();
var_it++) {
if ((*var_it).first == "Coords") {
continue;
}
char *var_name = new char[(*var_it).first.size() + 20];
sprintf(var_name, "%s", (*var_it).first.c_str());
// set the centering
avtCentering centering;
if ( (*var_it).second.cell_centered == 1)
centering = AVT_ZONECENT;
else
centering = AVT_NODECENT;
if ((*var_it).second.num_components == 1) // scalar field
{
AddScalarVarToMetaData(md, var_name, mesh_name, centering);
}
else if ((*var_it).second.num_components == num_dim_problem) // vector field
{
AddVectorVarToMetaData(md, var_name, mesh_name, centering, 3);
}
else if (((num_dim_problem == 2) && ((*var_it).second.num_components == 3)) ||
((num_dim_problem == 3) && ((*var_it).second.num_components == 6)))
{
AddSymmetricTensorVarToMetaData(md, var_name, mesh_name, centering,
(*var_it).second.num_components);
}
else if (((num_dim_problem == 2) && ((*var_it).second.num_components == 4)) ||
((num_dim_problem == 3) && ((*var_it).second.num_components == 9)))
{
AddTensorVarToMetaData(md, var_name, mesh_name, centering,
(*var_it).second.num_components);
}
else {
EXCEPTION1(InvalidVariableException, (*var_it).first.c_str());
}
delete [] var_name;
}
// the code below to create a custom SIL is currently disabled
#if 0
// build the custom SIL
avtSILMetaData *sil = new avtSILMetaData(mesh_name);
// create the collection class for levels
int levelCollId = sil->AddCollectionClass("levels", "level", num_levels);
// create the collections of patches on each level
int *tmpIndices = new int[num_patches];
int globalPatchIndex = 0;
for (int i = 0; i < num_levels; i++)
{
// find all patches in global patch map on this level
int levelPatchIndex = 0;
while (patch_map[globalPatchIndex].level_number == i)
tmpIndices[levelPatchIndex++] = globalPatchIndex++;
// add a collection of patches underneath this level
int localPatchCollId =
sil->AddCollection("patches", "patch", levelPatchIndex, levelCollId,
i, -1, NULL);
}
delete [] tmpIndices;
// create the collections of levels patches on each patch
md->Add(sil);
#endif
for (i = 0; i < num_exprs; i++)
{
Expression exp;
exp.SetName(expr_keys[i]);
exp.SetDefinition(expr_defns[i]);
if (expr_types[i] == "scalar")
exp.SetType(Expression::ScalarMeshVar);
else if (expr_types[i] == "vector")
exp.SetType(Expression::VectorMeshVar);
else if (expr_types[i] == "tensor")
exp.SetType(Expression::TensorMeshVar);
else if (expr_types[i] == "array")
exp.SetType(Expression::ArrayMeshVar);
md->AddExpression(&exp);
}
}
}
// ****************************************************************************
// Method: avtSAMRAIFileFormat::ReadMetaDataFile
//
// Purpose:
// Read the database meta-data (root) file
//
// Arguments:
// in the open ifstream to read from
//
// Programmer: Walter Herrera Jimenez
// Creation: July 07, 2003
//
// Modifications:
//
// Mark C. Miller, Mon Dec 8 12:03:06 PST 2003
// Added call to ReadAndCheckVDRVersions();
// Added call to ReadVarNumGhosts();
//
// Brad Whitlock, Fri Mar 5 10:19:32 PDT 2004
// Changed for Windows compiler.
//
// Mark C. Miller, Mon Aug 23 14:17:55 PDT 2004
// Made it use OpenFile instead of H5Fopen & removed call to H5Fclose
//
// Hank Childs, Sat Mar 5 11:47:52 PST 2005
// Make sure we don't read the information twice.
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadMetaDataFile()
{
if (have_read_metadata_file)
return;
debug5 << "avtSAMRAIFileFormat::ReadMetaDataFile reading SAMRAI summary "
"file, \"" << file_name.c_str() << "\"" << endl;
hid_t h5_file = OpenFile(file_name.c_str());
if (h5_file < 0)
{
debug1 << "Unable to open metadata file " << file_name.c_str() << endl;
}
else
{
ReadAndCheckVDRVersion(h5_file);
ReadTimeStepNumber(h5_file);
ReadTime(h5_file);
ReadTimeOfDump(h5_file);
ReadGridType(h5_file);
ReadNumDimensions(h5_file);
ReadNumLevels(h5_file);
ReadXLO(h5_file);
ReadDX(h5_file);
ReadNumPatches(h5_file);
ReadNumPatchesLevel(h5_file);
ReadRatiosCoarserLevels(h5_file);
ReadNumClusters(h5_file);
ReadNumProcessors(h5_file);
ReadNumVariables(h5_file);
ReadVarCellCentered(h5_file);
ReadVarNames(h5_file);
ReadVarNumGhosts(h5_file);
ReadVarNumComponents(h5_file);
ReadVarExtents(h5_file);
ReadPatchExtents(h5_file);
ReadPatchMap(h5_file);
ReadChildArrayLength(h5_file);
ReadChildArray(h5_file);
ReadChildPointerArray(h5_file);
ReadParentArrayLength(h5_file);
ReadParentArray(h5_file);
ReadParentPointerArray(h5_file);
ReadMaterialInfo(h5_file);
ReadSpeciesInfo(h5_file);
ReadExpressions(h5_file);
cached_patches = new vtkDataSet**[num_patches];
for (int p=0; p<num_patches; p++)
{
if (has_ghost)
{
cached_patches[p] = new vtkDataSet*[MAX_GHOST_CODES];
for (int g = 0; g<MAX_GHOST_CODES; g++)
cached_patches[p][g] = NULL;
}
else
{
cached_patches[p] = new vtkDataSet*[1];
cached_patches[p][0] = NULL;
}
}
}
have_read_metadata_file = true;
}
// ****************************************************************************
// Method: ReadTime
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadTime(hid_t &h5_file)
{
bool isOptional = false;
int numVals = 1;
double *ptime = &time;
ReadDataset(h5_file, "/BASIC_INFO/time", "double", 1, &numVals,
(void**) &ptime, isOptional);
}
// ****************************************************************************
// Method: ReadAndCheckVDRVersion
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Mark C. Miller
// Creation: December 8, 2003
//
// Modifications:
// Kathleen Bonnell, Thu Apr 3 13:28:25 PDT 2008
// Fixed use of '=' where it should be '=='.
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadAndCheckVDRVersion(hid_t &h5_file)
{
// cerr << "WARNING, SAMRAI VERSION CHECK DISABLED" << endl;
// return;
hid_t h5_dataset = H5Dopen(h5_file,"/BASIC_INFO/VDR_version_number");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/VDR_version_number does not exist. Unable "
"to confirm file's version compatibility with reader plugin", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
float obtained_version_number;
H5Dread(h5_dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
&obtained_version_number);
H5Dclose(h5_dataset);
bool hasExpectedVersionNumber = false;
for (int n = 0;
n < sizeof(expected_version_number)/sizeof(expected_version_number[0]);
n++)
{
if (obtained_version_number == expected_version_number[n])
{
hasExpectedVersionNumber = true;
break;
}
}
if (hasExpectedVersionNumber == false)
{
char str[2048];
sprintf(str, "The file \"%s\" appears to be a SAMRAI file "
"written for input to VisIt. However, the version of the writer "
"SAMRAI used to produce this file, %f, does not match any of the "
"version numbers the VisIt reader plugin you are now trying to use "
"is designed for, %f, %f",
file_name.c_str(),obtained_version_number,
expected_version_number[0],expected_version_number[1]);
EXCEPTION1(InvalidFilesException, str);
}
}
// ****************************************************************************
// Method: ReadTimeStepNumber
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadTimeStepNumber(hid_t &h5_file)
{
bool isOptional = false;
int numVals = 1;
int *ptsn = &time_step_number;
ReadDataset(h5_file, "/BASIC_INFO/time_step_number", "int", 1, &numVals,
(void**) &ptsn, isOptional);
}
// ****************************************************************************
// Method: ReadTimeOfDump
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadTimeOfDump(hid_t &h5_file)
{
bool isOptional = false;
int numVals = 1;
string *pstr = &time_dump;
ReadDataset(h5_file, "/BASIC_INFO/time_of_dump", "string", 1, &numVals,
(void**) &pstr, isOptional);
}
// ****************************************************************************
// Method: ReadNumDimensions
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadNumDimensions(hid_t &h5_file)
{
bool isOptional = false;
int numVals = 1;
int *pnum_dim = &num_dim_problem;
ReadDataset(h5_file, "/BASIC_INFO/number_dimensions_of_problem", "int", 1,
&numVals, (void**) &pnum_dim, isOptional);
}
// ****************************************************************************
// Method: ReadXLO
//
// Purpose:
// Read the lower coordinates of the grid
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadXLO(hid_t &h5_file)
{
bool isOptional = false;
int numVals = 3;
ReadDataset(h5_file, "/BASIC_INFO/XLO", "double", 1, &numVals,
(void**) &xlo, isOptional);
}
// ****************************************************************************
// Method: ReadNumLevels
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadNumLevels(hid_t &h5_file)
{
bool isOptional = false;
int numVals = 1;
int *pnl = &num_levels;
ReadDataset(h5_file, "/BASIC_INFO/number_levels", "int", 1, &numVals,
(void**) &pnl, isOptional);
}
// ****************************************************************************
// Method: ReadDx
//
// Purpose:
// Read the width of the cells on each level
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadDX(hid_t &h5_file)
{
bool isOptional = false;
int dims[2] = {num_levels,3};
ReadDataset(h5_file, "/BASIC_INFO/dx", "double", 2, dims, (void**) &dx,
isOptional);
}
// ****************************************************************************
// Method: ReadNumPatches
//
// Purpose:
// Read the number of global patches
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadNumPatches(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/number_global_patches");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/number_global_patches", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
&num_patches);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadNumPatchesLevel
//
// Purpose:
// Read the number of patches on each level
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadNumPatchesLevel(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file,"/BASIC_INFO/number_patches_at_level");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/number_patches_at_level",
file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
num_patches_level = new int[num_levels];
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
num_patches_level);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadRatiosCoarserLevels
//
// Purpose:
// Read the ratios to coarser levels
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadRatiosCoarserLevels(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file,
"/BASIC_INFO/ratios_to_coarser_levels");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/ratios_to_coarser_levels",
file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
ratios_coarser_levels = new int[num_levels * 3];
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
ratios_coarser_levels);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadNumClusters
//
// Purpose:
// Read the number of clusters
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadNumClusters(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/number_file_clusters");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/number_file_clusters",
file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
&num_clusters);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadNumProcessors
//
// Purpose:
// Read the number of processors
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadNumProcessors(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/number_processors");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/number_processors", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
&num_procs);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadNumVariables
//
// Purpose:
// Read the number of variables
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadNumVariables(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/number_visit_variables");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/number_visit_variables",
file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
&num_vars);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadVarCellCentered
//
// Purpose:
// Read the cell centered flag for each variable
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadVarCellCentered(hid_t &h5_file)
{
if (num_vars <= 0)
return;
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/var_cell_centered");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/var_cell_centered", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
var_cell_centered = new int[num_vars];
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
var_cell_centered);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadGridType
//
// Purpose:
// Read the type of the grid
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadGridType(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/grid_type");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/grid_type", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
hid_t h5_disk_datatype = H5Tcopy(h5_dataset);
int datatype_size = H5Tget_size(h5_disk_datatype);
hid_t h5_mem_datatype = H5Tcopy(H5T_C_S1);
H5Tset_size(h5_mem_datatype, datatype_size);
char *buffer = new char[datatype_size];
H5Dread(h5_dataset, h5_mem_datatype, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer);
H5Tclose(h5_mem_datatype);
H5Tclose(h5_disk_datatype);
H5Dclose(h5_dataset);
grid_type = buffer;
delete [] buffer;
}
// ****************************************************************************
// Method: ReadVarNames
//
// Purpose:
// Read the name of the variables
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// Modificaitons:
// Mark C. Miller, changed to use ReadDataset helper function
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadVarNames(hid_t &h5_file)
{
if (num_vars <= 0)
return;
bool isOptional = false;
ReadDataset(h5_file, "/BASIC_INFO/var_names", "string", 1, &num_vars,
(void**) &var_names, isOptional);
}
// ****************************************************************************
// Method: ReadVarNumComponents
//
// Purpose:
// Read the number of components of each variable
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// Modifications:
// Mark C. Miller ,Thu Dec 11 14:43:24 PST 2003
// Modified to be a little more general
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadVarNumComponents(hid_t &h5_file)
{
bool isOptional = false;
ReadDataset(h5_file, "/BASIC_INFO/var_number_components", "int",
1, &num_vars, (void**) &var_num_components, isOptional);
for (int v = 0; v < num_vars; v++) {
string var_name = var_names[v].c_str();
var_t var = { var_num_components[v], var_cell_centered[v],
{ var_num_ghosts[v*3+0],
var_num_ghosts[v*3+1],
var_num_ghosts[v*3+2]}};
var_names_num_components[var_name] = var;
}
}
// ****************************************************************************
// Method: ReadVarNumGhosts
//
// Purpose:
// Read the number of ghost cells in each dimensio. Also, set flags
// indicating if we have ghosting and if ghosting is consistent.
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Mark C. Miller
// Creation: December 8, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadVarNumGhosts(hid_t &h5_file)
{
if (num_vars <= 0)
return;
int dims[2] = {-1, 3};
ReadDataset(h5_file, "/BASIC_INFO/var_number_ghosts", "int",
2, dims, (void**) &var_num_ghosts);
if (dims[0] == 0)
{
var_num_ghosts = new int[num_vars * 3];
for (int v = 0; v < num_vars * 3; v++)
var_num_ghosts[v] = 0;
has_ghost = false;
ghosting_is_consistent = true;
return;
}
if (dims[0] != num_vars)
{
EXCEPTION2(UnexpectedValueException, num_vars, dims[0]);
}
// When ghosting is not same for ALL variables in the file, we need
// to tell VisIt NOT to cache pieces of the mesh above the plugin.
// So, we examine the ghost information here for differences between
// variables. If there are no differences, things can proceed as
// normal. Otherwise, we need to turn off caching above the plugin.
// We do this by setting a boolean indicating if ghosting is
// consistent or not. Also, for the mesh 'variable', we need to know
// the maximal amount of ghosting, so we compute that here too
ghosting_is_consistent = true;
for (int v = 1; v < num_vars; v++) {
if ((var_num_ghosts[v*3+0] != var_num_ghosts[0*3+0]) ||
(var_num_ghosts[v*3+1] != var_num_ghosts[0*3+1]) ||
(var_num_ghosts[v*3+2] != var_num_ghosts[0*3+2]))
ghosting_is_consistent = false;
if (var_num_ghosts[v*3+0] > var_max_ghosts[0])
var_max_ghosts[0] = var_num_ghosts[v*3+0];
if (var_num_ghosts[v*3+1] > var_max_ghosts[1])
var_max_ghosts[1] = var_num_ghosts[v*3+1];
if (var_num_ghosts[v*3+2] > var_max_ghosts[2])
var_max_ghosts[2] = var_num_ghosts[v*3+2];
}
// finally, lets just make sure we actually do have ghost zones
if (ghosting_is_consistent && (var_num_ghosts[0] == 0) &&
(var_num_ghosts[1] == 0) &&
(var_num_ghosts[2] == 0))
has_ghost = false;
else
has_ghost = true;
}
// ****************************************************************************
// Method: ReadVarExtents
//
// Purpose:
// Read the extents for each variable
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// Modifications:
// Eric Brugger, Tue Dec 30 16:37:26 PST 2003
// I modified the routine to properly read vector (and coordinate) data.
// This involved file format as well as reader changes. In this case
// I modified the way the extents were read and stored for a vector.
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadVarExtents(hid_t &h5_file)
{
if (num_vars <= 0)
return;
hid_t h5_mem_datatype = H5Tcreate (H5T_COMPOUND, sizeof(var_extents_t));
H5Tinsert (h5_mem_datatype, "data_is_defined",
HOFFSET(var_extents_t,data_is_defined), H5T_NATIVE_CHAR);
H5Tinsert (h5_mem_datatype, "min",
HOFFSET(var_extents_t,min), H5T_NATIVE_DOUBLE);
H5Tinsert (h5_mem_datatype, "max",
HOFFSET(var_extents_t,max), H5T_NATIVE_DOUBLE);
var_extents = new var_extents_t* [num_vars];
for (int v = 0; v < num_vars; v++) {
std::map<std::string, var_t>::const_iterator cur_var;
cur_var = var_names_num_components.find(var_names[v]);
if (cur_var == var_names_num_components.end())
{
EXCEPTION1(InvalidVariableException, var_names[v]);
}
int num_components = (*cur_var).second.num_components;
var_extents[v] = new var_extents_t[num_patches*num_components];
if (num_components == 1)
{
char ds_name[50];
sprintf(ds_name, "/extents/%s-Extents", var_names[v].c_str());
hid_t h5_dataset = H5Dopen(h5_file, ds_name);
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::%s", file_name.c_str(), ds_name);
EXCEPTION1(InvalidFilesException, str);
}
H5Dread(h5_dataset, h5_mem_datatype, H5S_ALL, H5S_ALL,
H5P_DEFAULT, var_extents[v]);
H5Dclose(h5_dataset);
}
else
{
for (int c = 0; c < num_components; c++)
{
char ds_name[50];
sprintf(ds_name, "/extents/%s.%02d-Extents",
var_names[v].c_str(), c);
hid_t h5_dataset = H5Dopen(h5_file, ds_name);
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::%s", file_name.c_str(), ds_name);
EXCEPTION1(InvalidFilesException, str);
}
H5Dread(h5_dataset, h5_mem_datatype, H5S_ALL, H5S_ALL,
H5P_DEFAULT, &(var_extents[v][c*num_patches]));
H5Dclose(h5_dataset);
}
}
}
H5Tclose(h5_mem_datatype);
}
// ****************************************************************************
// Method: ReadPatchExtents
//
// Purpose:
// Read the spatial extents for each patch
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// Modifications:
//
// Mark C. Miller, Mon Jan 12 17:29:19 PST 2004
// Added code to override xlo/xup (spatial) extents of each patch with
// knowledge of extents of coordinate array if its an ALE grid
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadPatchExtents(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file, "/extents/patch_extents");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/extents/patch_extents", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
patch_extents = new patch_extents_t[num_patches];
hsize_t dim[] = {3};
hid_t h5_lower_datatype = H5Tarray_create(H5T_NATIVE_INT, 1, dim, NULL);
hid_t h5_upper_datatype = H5Tarray_create(H5T_NATIVE_INT, 1, dim, NULL);
hid_t h5_xlo_datatype = H5Tarray_create(H5T_NATIVE_DOUBLE, 1, dim, NULL);
hid_t h5_xup_datatype = H5Tarray_create(H5T_NATIVE_DOUBLE, 1, dim, NULL);
int size = H5Tget_size(h5_lower_datatype) +
H5Tget_size(h5_upper_datatype) +
H5Tget_size(h5_xlo_datatype) +
H5Tget_size(h5_xup_datatype);
hid_t h5_datatype = H5Tcreate (H5T_COMPOUND, size);
int offset_lower = 0;
int offset_upper = H5Tget_size(h5_lower_datatype);
int offset_xlo = offset_upper + H5Tget_size(h5_upper_datatype);
int offset_xup = offset_xlo + H5Tget_size(h5_xlo_datatype);
H5Tinsert(h5_datatype, "lower", offset_lower, h5_lower_datatype);
H5Tinsert(h5_datatype, "upper", offset_upper, h5_upper_datatype);
H5Tinsert(h5_datatype, "xlo", offset_xlo, h5_xlo_datatype);
H5Tinsert(h5_datatype, "xup", offset_xup, h5_xup_datatype);
H5Dread(h5_dataset, h5_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
patch_extents);
H5Dclose(h5_dataset);
H5Tclose(h5_lower_datatype);
H5Tclose(h5_upper_datatype);
H5Tclose(h5_xlo_datatype);
H5Tclose(h5_xup_datatype);
H5Tclose(h5_datatype);
// override xlo/xup data with extents from the "Coord" variable
if (grid_type == "ALE" || grid_type == "DEFORMED")
{
// find the index for the coordinate field
int v;
for (v = 0; v < num_vars; v++)
{
if (var_names[v] == "Coords")
break;
}
// now move the var_extents data to patch_extents
int p;
for (p = 0; p < num_patches; p++)
{
patch_extents[p].xlo[0] = var_extents[v][0*num_patches].min;
patch_extents[p].xup[0] = var_extents[v][0*num_patches].max;
patch_extents[p].xlo[1] = var_extents[v][1*num_patches].min;
patch_extents[p].xup[1] = var_extents[v][1*num_patches].max;
if (num_dim_problem > 2)
{
patch_extents[p].xlo[2] = var_extents[v][2*num_patches].min;
patch_extents[p].xup[2] = var_extents[v][2*num_patches].max;
}
else
{
patch_extents[p].xlo[2] = 0.0;
patch_extents[p].xup[2] = 0.0;
}
}
}
}
// ****************************************************************************
// Method: ReadPatchMap
//
// Purpose:
// Read the patch map: cluster, processor, level and local number of patch
// for each patch
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadPatchMap(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file, "/extents/patch_map");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/extents/patch_map", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
hid_t h5_datatype = H5Tcreate (H5T_COMPOUND, sizeof(patch_map_t));
H5Tinsert (h5_datatype, "processor_number",
HOFFSET(patch_map_t,processor_number), H5T_NATIVE_INT);
H5Tinsert (h5_datatype, "file_cluster_number",
HOFFSET(patch_map_t,file_cluster_number), H5T_NATIVE_INT);
H5Tinsert (h5_datatype, "level_number",
HOFFSET(patch_map_t,level_number), H5T_NATIVE_INT);
H5Tinsert (h5_datatype, "patch_number",
HOFFSET(patch_map_t,patch_number), H5T_NATIVE_INT);
patch_map = new patch_map_t[num_patches];
H5Dread(h5_dataset, h5_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, patch_map);
H5Dclose(h5_dataset);
H5Tclose(h5_datatype);
}
// ****************************************************************************
// Method: ReadChildArrayLength
//
// Purpose:
// Read the length of the array of children of each patch
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadChildArrayLength(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/child_array_length");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/child_array_length", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
&child_array_length);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadChildArray
//
// Purpose:
// Read the array of children of each patch
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadChildArray(hid_t &h5_file)
{
if (child_array_length == 0)
return;
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/child_array");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/child_array", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
child_array = new int[child_array_length];
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
child_array);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadChildPointerArray
//
// Purpose:
// Read the array of pointers to children of each patch
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadChildPointerArray(hid_t &h5_file)
{
if (child_array_length == 0)
return;
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/child_pointer_array");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/child_pointer_array", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
hid_t h5_datatype = H5Tcreate (H5T_COMPOUND, sizeof(child_t));
H5Tinsert (h5_datatype, "offset",
HOFFSET(child_t,offset), H5T_NATIVE_INT);
H5Tinsert (h5_datatype, "number_children",
HOFFSET(child_t,number_children), H5T_NATIVE_INT);
child_pointer_array = new child_t[num_patches];
H5Dread(h5_dataset, h5_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
child_pointer_array);
H5Dclose(h5_dataset);
H5Tclose(h5_datatype);
}
// ****************************************************************************
// Method: ReadParentArrayLength
//
// Purpose:
// Read the length of the array of parents of each patch
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadParentArrayLength(hid_t &h5_file)
{
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/parent_array_length");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/parent_array_length", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
&parent_array_length);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadParentArray
//
// Purpose:
// Read the array of parents of each patch
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadParentArray(hid_t &h5_file)
{
if (parent_array_length == 0)
return;
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/parent_array");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/parent_array", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
parent_array = new int[parent_array_length];
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
parent_array);
H5Dclose(h5_dataset);
}
// ****************************************************************************
// Method: ReadParentPointerArray
//
// Purpose:
// Read the array of pointers to parents of each patch
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Walter Herrera Jimenez
// Creation: August 20, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadParentPointerArray(hid_t &h5_file)
{
if (parent_array_length == 0)
return;
hid_t h5_dataset = H5Dopen(h5_file, "/BASIC_INFO/parent_pointer_array");
if (h5_dataset < 0) {
char str[1024];
sprintf(str, "%s::/BASIC_INFO/parent_pointer_array", file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
hid_t h5_datatype = H5Tcreate (H5T_COMPOUND, sizeof(parent_t));
H5Tinsert (h5_datatype, "offset",
HOFFSET(parent_t,offset), H5T_NATIVE_INT);
H5Tinsert (h5_datatype, "number_parents",
HOFFSET(parent_t,number_parents), H5T_NATIVE_INT);
parent_pointer_array = new parent_t[num_patches];
H5Dread(h5_dataset, h5_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
parent_pointer_array);
H5Dclose(h5_dataset);
H5Tclose(h5_datatype);
}
// ****************************************************************************
// Method: ReadMaterialInfo
//
// Purpose:
// Read material information from the metadata file
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Mark C. Miller
// Creation: December 12, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadMaterialInfo(hid_t &h5_file)
{
// read material names
num_mats = -1;
bool isOptional = true;
ReadDataset(h5_file, "/materials/material_names", "string", 1, &num_mats,
(void**) &mat_names, isOptional);
if (num_mats > 0)
has_mats = true;
else
has_mats = false;
// if we don't have any materials, we're done
if (has_mats == false)
return;
// read names of material-specific variables
num_mat_vars = -1;
mat_var_names = 0;
ReadDataset(h5_file, "/materials/material_variable_names", "string",
1, &num_mat_vars, (void**) &mat_var_names, isOptional);
if (num_mat_vars == -1)
num_mat_vars = 0;
// if we do have materials, all the remaining information is required
isOptional = false;
// read information on ghosting for material variables
int numVals = 3;
ReadDataset(h5_file, "/materials/material_number_ghosts", "int",
1, &numVals, (void**) &mat_num_ghosts, isOptional);
// read information on components counts of material-specific variables
ReadDataset(h5_file, "/materials/material_variable_number_components", "int",
1, &num_mat_vars, (void**) &mat_var_num_components, isOptional);
for (int mv = 0; mv < num_mat_vars; mv++) {
string mat_var_name = mat_var_names[mv].c_str();
var_t var = { var_num_components[mv], 1,
{ mat_num_ghosts[0],
mat_num_ghosts[1],
mat_num_ghosts[2]}};
mat_var_names_num_components[mat_var_name] = var;
}
// read information on sparse material storage, if available
ReadDataset(h5_file, "/extents/materials/sparse_material_list",
"matinfo_t", 1, &num_patches, (void**) &sparse_mat_info, true);
// Read "extents" information for each material
for (int m = 0; m < num_mats && sparse_mat_info == 0; m++)
{
matinfo_t *tmpInfo = 0;
char dsName[1024];
sprintf(dsName,"/extents/materials/%s/%s-Fractions",
mat_names[m].c_str(), mat_names[m].c_str());
ReadDataset(h5_file, dsName, "matinfo_t", 1, &num_patches,
(void**) &tmpInfo, isOptional);
mat_names_matinfo[mat_names[m]] = tmpInfo;
for (int mv = 0; mv < num_mat_vars; mv++)
{
tmpInfo = 0;
char dsName[1024];
sprintf(dsName,"/extents/materials/%s/material_variables/%s",
mat_names[m].c_str(), mat_var_names[mv].c_str());
ReadDataset(h5_file, dsName, "matinfo_t", 1, &num_patches,
(void**) &tmpInfo, isOptional);
mat_var_names_matinfo[mat_names[m]][mat_var_names[mv]] = tmpInfo;
}
}
// check if we'll ever need to infer the "void" material for this database
inferVoidMaterial = false;
int p;
for (p = 0; p < num_patches && sparse_mat_info == 0; p++)
{
int i, n0 = 0, n1 = 0, n2 = 0;
for (i = 0; i < num_mats; i++)
{
int matCompFlag = mat_names_matinfo[mat_names[i]][p].mat_comp_flag;
switch (matCompFlag)
{
case 0: // this material covers no part of the patch
n0++;
break;
case 1: // this material covers the patch, wholly
n1++;
break;
case 2: // this material covers the patch, partially
n2++;
break;
}
}
if (n1 == 0 && n2 == 1)
{
inferVoidMaterial = true;
break;
}
}
// if we need to infer the "void" material, adjust the material count/names
if (inferVoidMaterial)
{
string *new_mat_names = new string[num_mats+1];
// copy over the existing names
int i;
for (i = 0; i < num_mats; i++)
new_mat_names[i] = mat_names[i];
new_mat_names[num_mats] = inferredVoidMatName;
SAFE_DELETE(mat_names);
mat_names = new_mat_names;
num_mats++;
}
}
// ****************************************************************************
// Method: ReadSpeciesInfo
//
// Purpose:
// Read species information from the metadata file
//
// Arguments:
// IN: h5_file the handle of the file to be read
//
// Programmer: Mark C. Miller
// Creation: December 18, 2003
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadSpeciesInfo(hid_t &h5_file)
{
// read species variable names
num_spec_vars = -1;
bool isOptional = true;
ReadDataset(h5_file, "/materials/species_variable_names", "string", 1, &num_spec_vars,
(void**) &spec_var_names, isOptional);
if (num_spec_vars > 0)
has_specs = true;
else
has_specs = false;
// if we don't have any species, we're done
if (has_specs == false)
return;
nmatspec = new int[num_mats];
// for each material, try to obtain the names of its constituent species
int i;
bool atLeastOneMaterialHasSpecies = false;
for (i = 0; i < num_mats; i++)
{
char matSpecName[512];
sprintf(matSpecName,"/materials/species/%s", mat_names[i].c_str());
string* tmpString = 0;
if (mat_names[i] != inferredVoidMatName)
{
nmatspec[i] = -1;
ReadDataset(h5_file, matSpecName, "string", 1, &nmatspec[i],
(void**) &tmpString, isOptional);
}
else
nmatspec[i] = 0;
// if the given material has no constituent species, its count is 0
if (nmatspec[i] == 0)
{
mat_specs[mat_names[i]] = 0;
}
else
{
mat_specs[mat_names[i]] = tmpString;
atLeastOneMaterialHasSpecies = true;
}
}
// if no material was found to have constituent species, ignore species data
if (atLeastOneMaterialHasSpecies == false)
return;
// if we do have species, all the remaining information is required
isOptional = false;
// Read "extents" information for each species
for (int m = 0; m < num_mats; m++)
{
int s;
for (s = 0; s < nmatspec[m]; s++)
{
matinfo_t *tmpInfo = 0;
char dsName[1024];
string matName = mat_names[m];
string specName = mat_specs[matName][s];
sprintf(dsName,"/extents/materials/%s/species/%s",
matName.c_str(), specName.c_str());
ReadDataset(h5_file, dsName, "matinfo_t", 1, &num_patches,
(void**) &tmpInfo, isOptional);
mat_specs_matinfo[matName][specName] = tmpInfo;
}
}
}
// ****************************************************************************
// Method: ReadExpressions
//
// Purpose: Read any visit expressions defined in the file
//
// Programmer: Mark C. Miller
// Creation: November 1, 2007
//
// Modifications:
// Mark C. Miller, Mon Mar 31 14:27:21 PDT 2008
// Remvoed extraneous cerr statement.
//
// ****************************************************************************
void
avtSAMRAIFileFormat::ReadExpressions(hid_t &h5_file)
{
bool isOptional = true;
num_exprs = -1;
if (ReadDataset(h5_file, "/visit_expressions/expression_keys",
"string", 1, &num_exprs, (void**) &expr_keys, isOptional)
&& num_exprs > 0)
{
isOptional = false;
ReadDataset(h5_file, "/visit_expressions/expression_types",
"string", 1, &num_exprs, (void**) &expr_types, isOptional);
ReadDataset(h5_file, "/visit_expressions/expressions",
"string", 1, &num_exprs, (void**) &expr_defns, isOptional);
}
else
{
num_exprs = 0;
}
}
// ****************************************************************************
// Method: BuildDomainAuxiliaryInfo
//
// Purpose:
// Builds the domain nesting information object and caches it
//
// Programmer: Mark C. Miller
// Creation: October 13, 2003
//
// Modifications:
//
// Mark C. Miller, Mon Nov 10 09:55:59 PST 2003
// Added code to check to see if its in cache before we try to build it.
// This makes it ok to include a call to BuildDomainAuxiliaryInfo() in the
// GetMesh method without serious performance drawbacks.
//
// Hank Childs, Wed Nov 12 17:58:16 PST 2003
// Also create the rectilinear domain boundaries structure.
//
// Mark C. Miller, Tue Dec 9 10:45:46 PST 2003
// Changed name from BuildDomainNestingInfo to BuildDomainAuxiliaryInfo
// since it does more than build domain nesting information
//
// Mark C. Miller, Mon Jan 12 17:29:19 PST 2004
// I switched to use avtCurvilinearDomainBoundaries when its in ALE
// mesh
//
// Brad Whitlock, Fri Mar 5 10:19:32 PDT 2004
// Changed for Windows compiler.
//
// Mark C. Miller, Thu Sep 13 11:33:09 PDT 2007
// Skip this work if we're on the mdserver
//
// ****************************************************************************
void
avtSAMRAIFileFormat::BuildDomainAuxiliaryInfo()
{
#ifdef MDSERVER
return;
#endif
// first, look to see if we don't already have it cached
void_ref_ptr vrTmp = cache->GetVoidRef("any_mesh",
AUXILIARY_DATA_DOMAIN_NESTING_INFORMATION,
timestep, -1);
if ((*vrTmp == NULL) && (child_array_length > 0))
{
//
// build the avtDomainNesting object
//
avtStructuredDomainNesting *dn =
new avtStructuredDomainNesting(num_patches, num_levels);
dn->SetNumDimensions(num_dim_problem);
//
// Set refinement level ratio information
//
vector<int> ratios(3,1);
dn->SetLevelRefinementRatios(0, ratios);
int i;
for (i = 1; i < num_levels; i++)
{
vector<int> ratios(3);
ratios[0] = ratios_coarser_levels[3*i+0];
ratios[1] = ratios_coarser_levels[3*i+1];
ratios[2] = ratios_coarser_levels[3*i+2];
dn->SetLevelRefinementRatios(i, ratios);
}
//
// set each domain's level, children and logical extents
//
for (i = 0; i < num_patches; i++)
{
vector<int> childPatches;
for (int j = 0; j < child_pointer_array[i].number_children; j++)
{
int offset = child_pointer_array[i].offset;
childPatches.push_back(child_array[offset+j]);
}
vector<int> logExts(6);
logExts[0] = patch_extents[i].lower[0];
logExts[1] = patch_extents[i].lower[1];
logExts[2] = patch_extents[i].lower[2];
logExts[3] = patch_extents[i].upper[0];
logExts[4] = patch_extents[i].upper[1];
logExts[5] = patch_extents[i].upper[2];
dn->SetNestingForDomain(i, patch_map[i].level_number,
childPatches, logExts);
}
void_ref_ptr vr = void_ref_ptr(dn, avtStructuredDomainNesting::Destruct);
cache->CacheVoidRef("any_mesh", AUXILIARY_DATA_DOMAIN_NESTING_INFORMATION,
timestep, -1, vr);
}
void_ref_ptr dbTmp = cache->GetVoidRef("any_mesh",
AUXILIARY_DATA_DOMAIN_BOUNDARY_INFORMATION,
timestep, -1);
if ((*dbTmp == NULL) && !has_ghost)
{
bool canComputeNeighborsFromExtents = true;
avtStructuredDomainBoundaries *sdb = 0;
if (grid_type == "ALE" || grid_type == "DEFORMED")
sdb = new avtCurvilinearDomainBoundaries(canComputeNeighborsFromExtents);
else
sdb = new avtRectilinearDomainBoundaries(canComputeNeighborsFromExtents);
sdb->SetNumDomains(num_patches);
for (int i = 0 ; i < num_patches ; i++)
{
int e[6];
e[0] = patch_extents[i].lower[0];
e[1] = patch_extents[i].upper[0]+1;
e[2] = patch_extents[i].lower[1];
e[3] = patch_extents[i].upper[1]+1;
e[4] = patch_extents[i].lower[2];
e[5] = patch_extents[i].upper[2]+1;
sdb->SetIndicesForAMRPatch(i, patch_map[i].level_number, e);
}
sdb->CalculateBoundaries();
void_ref_ptr vsdb = void_ref_ptr(sdb,avtStructuredDomainBoundaries::Destruct);
cache->CacheVoidRef("any_mesh",
AUXILIARY_DATA_DOMAIN_BOUNDARY_INFORMATION,
timestep, -1, vsdb);
}
}
// ****************************************************************************
// Method: GetGhostCodeForVar
//
// Purpose:
// Returns the ghost code for a given variable. The ghost code is a simple
// conversion from a base-MAX_GHOST_LAYERS integer of num_dim_problem digits
// to a base-10 integer.
//
// Programmer: Mark C. Miller
// Creation: December 9, 2003
//
// Modifications:
// Mark C. Miller, Mon Mar 31 14:27:21 PDT 2008
// Modified to handle the 'materials' variable correctly.
//
// ****************************************************************************
int
avtSAMRAIFileFormat::GetGhostCodeForVar(const char *visit_var_name)
{
if (!has_ghost)
return 0;
string var_name = visit_var_name;
int num_ghosts[3];
if (var_name == "amr_mesh" ||
var_name == "materials")
{
num_ghosts[0] = var_max_ghosts[0];
num_ghosts[1] = var_max_ghosts[1];
num_ghosts[2] = var_max_ghosts[2];
}
else
{
std::map<std::string, var_t>::const_iterator cur_var;
cur_var = var_names_num_components.find(var_name);
if (cur_var == var_names_num_components.end())
return 0;
num_ghosts[0] = (*cur_var).second.num_ghosts[0];
num_ghosts[1] = (*cur_var).second.num_ghosts[1];
num_ghosts[2] = (*cur_var).second.num_ghosts[2];
}
int code = 0;
int powr = 1;
for (int i = 0; i < num_dim_problem; i++)
{
code += num_ghosts[i] * powr;
powr *= MAX_GHOST_LAYERS;
}
return code;
}
// ****************************************************************************
// Method: ReadDataset
//
// Purpose: Read dataset of specified size and type. If size is not specified
// by caller, read the dataset and fill in the dims array. If it is specified
// by caller, compare to size in file and throw an exception if wrong.
//
// Programmer: Mark C. Miller, adapted from Walter Herrar Jimenez
// Creation: December 11, 2003
//
// Modifications:
// Kathleen Bonnell, Mon Dec 22 15:06:41 PST 2003
// Added code dynamically allocate hdims max_hdims, so that code will build
// on IRIX.
//
// Brad Whitlock, Fri Mar 5 10:19:32 PDT 2004
// Changed for Windows compiler.
//
// ****************************************************************************
bool
avtSAMRAIFileFormat::ReadDataset(hid_t &hdfFile, const char *dsPath,
const char *typeName, int ndims, int *dims, void **data, bool isOptional)
{
// confirm total number of entries > 0
int i;
for (i = 0; i < ndims; i++)
{
if (dims[i] == 0)
return false;
}
hid_t h5_dataset = H5Dopen(hdfFile, dsPath);
if (h5_dataset < 0)
{
if (isOptional)
{
for (i = 0; i < ndims; i++)
{
if (dims[i] == -1)
dims[i] = 0;
}
*data = 0;
return false;
}
else
{
char str[1024];
sprintf(str, "Required dataset \"%s\", not present in file \"%s\"",
dsPath, file_name.c_str());
EXCEPTION1(InvalidFilesException, str);
}
}
// determine # entries in dataset
hid_t h5d_space = H5Dget_space(h5_dataset);
int hndims = H5Sget_simple_extent_ndims(h5d_space);
if (hndims != ndims)
{
H5Dclose(h5_dataset);
EXCEPTION2(UnexpectedValueException, ndims, hndims);
}
hsize_t *hdims = new hsize_t[hndims];
hsize_t *max_hdims = new hsize_t[hndims];
H5Sget_simple_extent_dims(h5d_space, hdims, max_hdims);
H5Sclose(h5d_space);
int num_vals = 1;
for (i = 0; i < hndims; i++)
{
if (dims[i] == -1)
dims[i] = hdims[i];
else
{
if (dims[i] != hdims[i])
{
H5Dclose(h5_dataset);
EXCEPTION2(UnexpectedValueException, dims[i], hdims[i]);
}
}
num_vals *= dims[i];
}
delete [] hdims;
delete [] max_hdims;
// if we don't have anything to read or we've only be called to return
// the size, just return now
if ((num_vals == 0) || (data == 0))
{
if (data != 0)
*data = 0;
H5Dclose(h5_dataset);
return true;
}
if (strncmp(typeName,"string",6) == 0)
{
hid_t h5_disk_datatype = H5Tcopy(h5_dataset);
int datatype_size = H5Tget_size(h5_disk_datatype);
hid_t h5_mem_datatype = H5Tcopy(H5T_C_S1);
H5Tset_size(h5_mem_datatype, datatype_size);
char *buffer = new char[num_vals * datatype_size];
string *tmp_data;
if (*data == 0)
tmp_data = new std::string[num_vals];
else
tmp_data = (string*) *data;
// read the data
H5Dread(h5_dataset, h5_mem_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
buffer);
// close up everything
H5Tclose(h5_mem_datatype);
H5Tclose(h5_disk_datatype);
for (int v = 0; v < num_vals; v++) {
tmp_data[v] = &buffer[v * datatype_size];
}
*data = (void*) tmp_data;
delete [] buffer;
}
else if (strncmp(typeName,"int",3) == 0)
{
int *tmp_data;
if (*data == 0)
tmp_data = new int[num_vals];
else
tmp_data = (int *) *data;
H5Dread(h5_dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
tmp_data);
*data = (void *) tmp_data;
}
else if (strncmp(typeName,"double",6) == 0)
{
double *tmp_data;
if (*data == 0)
tmp_data = new double[num_vals];
else
tmp_data = (double *) *data;
H5Dread(h5_dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
tmp_data);
*data = (void *) tmp_data;
}
else if (strncmp(typeName,"float",6) == 0)
{
float *tmp_data;
if (*data == 0)
tmp_data = new float[num_vals];
else
tmp_data = (float *) *data;
H5Dread(h5_dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
tmp_data);
*data = (void *) tmp_data;
}
else if (strncmp(typeName,"matinfo_t",9) == 0)
{
// build the hdf5 type
hid_t h5_mem_datatype = H5Tcreate (H5T_COMPOUND, sizeof(matinfo_t));
H5Tinsert (h5_mem_datatype, "data_is_defined",
HOFFSET(matinfo_t,data_is_defined), H5T_NATIVE_UCHAR);
H5Tinsert (h5_mem_datatype, "material_composition_flag",
HOFFSET(matinfo_t,mat_comp_flag), H5T_NATIVE_INT);
H5Tinsert (h5_mem_datatype, "species_composition_flag",
HOFFSET(matinfo_t,spec_comp_flag), H5T_NATIVE_INT);
H5Tinsert (h5_mem_datatype, "min",
HOFFSET(matinfo_t,min), H5T_NATIVE_DOUBLE);
H5Tinsert (h5_mem_datatype, "max",
HOFFSET(matinfo_t,max), H5T_NATIVE_DOUBLE);
matinfo_t *tmp_data;
if (*data == 0)
tmp_data = new matinfo_t[num_vals];
else
tmp_data = (matinfo_t*) *data;
H5Dread(h5_dataset, h5_mem_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
tmp_data);
H5Tclose(h5_mem_datatype);
*data = (void *) tmp_data;
}
H5Dclose(h5_dataset);
return true;
}
// ****************************************************************************
// Function: GetDirName
//
// Purpose:
// Returns the directory from a full path name
//
// Arguments:
// path the full path name
//
// Programmer: Jeremy Meredith
// Creation: April 7, 2003
//
// Modifications:
// Kathleen Bonnell, Mon Nov 3 17:53:33 PST 2008
// Use VISIT_SLASH_CHAR instead of '/' so that this works on Windows.
//
// ****************************************************************************
string
GetDirName(const char *path)
{
string dir = "";
int len = strlen(path);
const char *last = path + (len-1);
while (*last != VISIT_SLASH_CHAR && last > path)
{
last--;
}
if (*last != VISIT_SLASH_CHAR)
{
return "";
}
char str[1024];
strcpy(str, path);
str[last-path+1] = '\0';
return str;
}
int UniqueSpeciesMF::DefaultSize = DEFAULT_SIZE;
float UniqueSpeciesMF::DefaultMinc = DEFAULT_MINC;
// ****************************************************************************
// Constructor: UniqueSpeciesMF
//
// Programmer: Mark C. Miller
// Creation: January 6, 2004
//
// ****************************************************************************
UniqueSpeciesMF::UniqueSpeciesMF(int initSize, float _minc)
{
// sanity checks
if (initSize < 0)
initSize = DefaultSize;
if (_minc < 1.0)
_minc = DefaultMinc;
dataRetrieved = false;
max_nspecies_mf = initSize;
minc = _minc;
nspecies_mf = 0;
species_mf = (float *) malloc(max_nspecies_mf * sizeof(float));
}
// ****************************************************************************
// Destructor: ~UniqueSpeciesMF
//
// Programmer: Mark C. Miller
// Creation: January 6, 2004
//
// ****************************************************************************
UniqueSpeciesMF::~UniqueSpeciesMF()
{
if (!dataRetrieved && species_mf != 0)
free(species_mf);
}
// ****************************************************************************
// Method: UniqueSpeciesMF::GetSize
//
// Purpose: Returns the current size of the species_mf array
//
// Programmer: Mark C. Miller
// Creation: January 6, 2004
//
// ****************************************************************************
int
UniqueSpeciesMF::GetSize()
{
return nspecies_mf;
}
// ****************************************************************************
// Method: UniqueSpeciesMF::GetMaxSize
//
// Purpose: Returns the current max size of the species_mf array
//
// Programmer: Mark C. Miller
// Creation: January 6, 2004
//
// ****************************************************************************
int
UniqueSpeciesMF::GetMaxSize()
{
return max_nspecies_mf;
}
// ****************************************************************************
// Method: UniqueSpeciesMF::GetData
//
// Purpose: Returns the species_mf array
//
// Programmer: Mark C. Miller
// Creation: January 6, 2004
//
// ****************************************************************************
float *
UniqueSpeciesMF::GetData()
{
if (dataRetrieved)
return 0;
dataRetrieved = true;
// downsize the array as necessary
if (nspecies_mf < max_nspecies_mf)
{
species_mf = (float*) realloc((void*)species_mf,
nspecies_mf * sizeof(float));
max_nspecies_mf = nspecies_mf;
}
float *retval = species_mf;
species_mf = 0;
return retval;
}
// ****************************************************************************
// Method: UniqueSpeciesMF::IndexOfMFVector
//
// Purpose: Installs a new species vector in the species_mf array and returns
// its index or returns the index of an existing matching vector.
//
// Programmer: Mark C. Miller
// Creation: January 6, 2004
//
// ****************************************************************************
int
UniqueSpeciesMF::IndexOfMFVector(float *mf_vector, int nvals)
{
if (dataRetrieved)
return -1;
// compute a key based on Bob Burtle's hashing algorithm
unsigned int hval = BJHash::Hash((unsigned char*)mf_vector,
nvals * sizeof(float), 0xdeadbeef);
// look up the key in the map, if it isn't found STL will create the entry
// using the default constructor
int retval = vmap[hval].idx;
// if the key wasn't found, we've got a new species mf vector, so add it
if (retval == -1)
{
// increase size of species_mf array if necessary
if ((nspecies_mf + nvals) >= max_nspecies_mf)
{
max_nspecies_mf = (int) (max_nspecies_mf * minc);
species_mf = (float*) realloc((void*)species_mf,
max_nspecies_mf * sizeof(float));
}
// put the index for this mf vector into the map
vmap[hval].idx = nspecies_mf;
retval = nspecies_mf;
// put the mf vector in the species_mf array
int i;
for (i = 0; i < nvals; i++)
species_mf[nspecies_mf++] = mf_vector[i];
}
return retval;
}
|