This file is indexed.

/usr/include/alberta/alberta.h is in libalberta2-dev 2.0.1-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
/*--------------------------------------------------------------------------*/
/* ALBERTA:  an Adaptive multi Level finite element toolbox using           */
/*           Bisectioning refinement and Error control by Residual          */
/*           Techniques for scientific Applications                         */
/*                                                                          */
/* file: alberta.h                                                          */
/*                                                                          */
/*                                                                          */
/* description: public header file of the ALBERTA package                   */
/*                                                                          */
/*--------------------------------------------------------------------------*/
/*                                                                          */
/*  authors:   Alfred Schmidt                                               */
/*             Zentrum fuer Technomathematik                                */
/*             Fachbereich 3 Mathematik/Informatik                          */
/*             Universitaet Bremen                                          */
/*             Bibliothekstr. 2                                             */
/*             D-28359 Bremen, Germany                                      */
/*                                                                          */
/*             Kunibert G. Siebert                                          */
/*             Institut fuer Mathematik                                     */
/*             Universitaet Augsburg                                        */
/*             Universitaetsstr. 14                                         */
/*             D-86159 Augsburg, Germany                                    */
/*                                                                          */
/*             Daniel Koester                                               */
/*             Institut fuer Mathematik                                     */
/*             Universitaet Augsburg                                        */
/*             Universitaetsstr. 14                                         */
/*             D-86159 Augsburg, Germany                                    */
/*                                                                          */
/*  http://www.alberta-fem.de                                               */
/*                                                                          */
/*  (c) by A. Schmidt and K.G. Siebert (1996-2005)                          */
/*  (c) by D. Koester (2002-2005)                                           */
/*--------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------*/
/*  Global configuration header                                             */
/*--------------------------------------------------------------------------*/

#ifdef HAVE_CONFIG_H        /* only defined during build of ALBERTA libs */
#include <config.h>
#endif

/*--------------------------------------------------------------------------*/
/*  Header-File for ALBERTA utilities                                       */
/*--------------------------------------------------------------------------*/
#ifndef _ALBERTA_H_
#define _ALBERTA_H_

#include "alberta_util.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ALBERTA_VERSION  "ALBERTA: Version 2.0"

/*--------------------------------------------------------------------------*/
/*  Definition of the space dimension and of parameters depending on the    */
/*  space dimension:							    */
/*									    */
/*  DIM_OF_WORLD:   space dimension					    */
/*                                    					    */
/*  The ?D-suffix signals different simplex dimensions (formerly ==DIM).    */
/*--------------------------------------------------------------------------*/

#ifndef DIM_OF_WORLD
# error DIM_OF_WORLD UNDEFINED
#endif

#ifndef ALBERTA_DEBUG
#warning ALBERTA_DEBUG WAS NOT DEFINED! DEFAULTING TO 0.
#define ALBERTA_DEBUG 0
#endif

/* The master dimension limit */
#define DIM_MAX          3
  
/* Various constants for dimension dependent geometrical quantities */
#define N_VERTICES(DIM) ((DIM)+1)
#define N_EDGES(DIM)    ((DIM)*((DIM)+1)/2)
#define N_WALLS(DIM)    ((DIM)+1) /* number of codim 1 subsimplexes */
#define N_FACES(DIM)    (((DIM) == 3) * N_WALLS(DIM))
#define N_NEIGH(DIM)    (((DIM) != 0) * N_WALLS(DIM))
#define DIM_FAC(DIM)    ((DIM) < 2 ? 1 : (DIM) == 2 ? 2 : 6)

#define N_VERTICES_0D    N_VERTICES(0)
#define N_EDGES_0D       N_EDGES(0)
#define N_FACES_0D       N_FACES(0)
#define N_NEIGH_0D       N_NEIGH(0)
#define N_WALLS_0D       N_WALLS(0)

#define N_VERTICES_1D    N_VERTICES(1)
#define N_EDGES_1D       N_EDGES(1)
#define N_FACES_1D       N_FACES(1)
#define N_NEIGH_1D       N_NEIGH(1)
#define N_WALLS_1D       N_WALLS(1)

#define N_VERTICES_2D    N_VERTICES(2)
#define N_EDGES_2D       N_EDGES(2)
#define N_FACES_2D       N_FACES(2)
#define N_NEIGH_2D       N_NEIGH(2)
#define N_WALLS_2D       N_WALLS(2)

#define N_VERTICES_3D    N_VERTICES(3)
#define N_EDGES_3D       N_EDGES(3)
#define N_FACES_3D       N_FACES(3)
#define N_NEIGH_3D       N_NEIGH(3)
#define N_WALLS_3D       N_WALLS(3)

#define N_VERTICES_MAX   N_VERTICES(DIM_MAX)
#define N_EDGES_MAX      N_EDGES(DIM_MAX)
#define N_FACES_MAX      N_FACES(DIM_MAX)
#define N_NEIGH_MAX      N_NEIGH(DIM_MAX)
#define N_WALLS_MAX      N_WALLS(DIM_MAX)

/* N_LAMBDA is the maximal number of barycentric coordinates, formerly DIM+1 */
/* Barycentric coords are often initialized using constant values, therefore */
/* we set this to 4.							     */
#define N_LAMBDA 4
#define LAMBDA_MAX N_LAMBDA

typedef REAL            REAL_B[N_LAMBDA];
typedef REAL_B          REAL_BB[N_LAMBDA];
typedef REAL            REAL_D[DIM_OF_WORLD];
typedef REAL_D          REAL_DD[DIM_OF_WORLD];
typedef REAL_D          REAL_BD[N_LAMBDA];
typedef struct real_dds REAL_DDS;

struct real_dds {
  REAL_D row0;
  REAL   row1[DIM_OF_WORLD-1]; /* zero size array in case of DOW == 1 */
#if DIM_OF_WORLD > 1
  REAL   row2[DIM_OF_WORLD-2]; /* zero size array in case of DOW == 2 */
#else
  REAL   row2[0];
#endif
};
  
/*--------------------------------------------------------------------------*/
/*  some useful macros depending on DIM_OF_WORLD                            */
/*--------------------------------------------------------------------------*/

#include "alberta_inlines.h"

/*--------------------------------------------------------------------------*/
/*  access to element index via element or element_info structure           */
/*--------------------------------------------------------------------------*/

#if ALBERTA_DEBUG
#define INDEX(el)   ((el) ? (el)->index : -1)
#else
#define INDEX(el)   -1
#endif

/*--------------------------------------------------------------------------*/
/*  access to leaf data (only for leaf elements)                            */
/*--------------------------------------------------------------------------*/

#define IS_LEAF_EL(el) (!(el)->child[0])
#define LEAF_DATA(el)  ((void *)(el)->child[1])

/*--------------------------------------------------------------------------*/
/*  boundary types							    */
/*--------------------------------------------------------------------------*/

#define INTERIOR      0
#define DIRICHLET     1
#define NEUMANN       -1

#define IS_NEUMANN(bound) ((bound) <= NEUMANN)
#define IS_DIRICHLET(bound) ((bound) >= DIRICHLET)
#define IS_INTERIOR(bound) ((bound) == 0)

/*--------------------------------------------------------------------------*/
/*  node types (indices in n_dof[] vectors, e.g.)			    */
/*--------------------------------------------------------------------------*/

#define N_NODE_TYPES  (DIM_MAX+1)

#define VERTEX     0
#define CENTER     1
#define EDGE       2
#define FACE       3

/*--------------------------------------------------------------------------*/
/*  basic types of the grid						    */
/*--------------------------------------------------------------------------*/

typedef signed int              DOF;
typedef struct el               EL;
typedef struct macro_el         MACRO_EL;
typedef struct el_info          EL_INFO;
typedef struct rc_list_el       RC_LIST_EL;
typedef struct mesh             MESH;

typedef struct parametric       PARAMETRIC;
typedef struct traverse_stack   TRAVERSE_STACK;

typedef struct adapt_stat       ADAPT_STAT;
typedef struct adapt_instat     ADAPT_INSTAT;

#ifndef DOF_ADMIN_DEF
typedef struct dof_admin        DOF_ADMIN;
typedef struct dof_int_vec      DOF_INT_VEC;
typedef struct dof_dof_vec      DOF_DOF_VEC;
typedef struct dof_uchar_vec    DOF_UCHAR_VEC;
typedef struct dof_schar_vec    DOF_SCHAR_VEC;
typedef struct dof_real_vec     DOF_REAL_VEC;
typedef struct dof_real_d_vec   DOF_REAL_D_VEC;
typedef struct dof_ptr_vec      DOF_PTR_VEC;
typedef struct matrix_row       MATRIX_ROW;
typedef struct dof_matrix       DOF_MATRIX;
typedef struct dowb_matrix_row  DOWB_MATRIX_ROW;
typedef struct dof_dowb_matrix  DOF_DOWB_MATRIX;
#endif

typedef struct bas_fcts         BAS_FCTS;
typedef struct fe_space         FE_SPACE;

typedef struct quadrature       QUAD;
typedef struct quadrature       QUADRATURE;
typedef struct quad_fast        QUAD_FAST;

typedef struct macro_data       MACRO_DATA;
typedef struct node_projection  NODE_PROJECTION;

typedef struct list_node        LIST_NODE;
typedef struct traverse_hook    TRAVERSE_HOOK;
typedef void   (*TRAVERSE_HOOK_FCT)(const EL_INFO *el_info, void *hook_data);

/* Traverse-hook node. See also add_traverse_hook(),
 * remove_traverse_hook(). Traverse-Hooks are special hooks
 * dynamically added and removed from the mesh. The hooks are run
 * during mesh-traversal prior to calling the element function. They
 * are intended to hide certain details from the application program,
 * e.g. to modify basis functions on a per-element basis
 * (hp-methods?). In principle, the init_element() of the PARAMETRIC
 * structure could go into a traverse hook.
 */

struct list_node {
  LIST_NODE *next;
  LIST_NODE *prev;
};

#define LIST_ENTRY(node, type, nodename)				\
  ((type *)((ptrdiff_t)node - (ptrdiff_t)&((type *)0)->nodename))

struct traverse_hook
{
  TRAVERSE_HOOK_FCT function;
  void              *data;    /* Per hook data. */
  LIST_NODE         node; /* doubly-linked list for efficient add and remove */
};

/*--------------------------------------------------------------------------*/
/*  node projection descriptor:                                             */
/*  a function pointer which calculates the projected location of a new     */
/*  vertex resulting from refinement.                                       */
/*               curved boundary					    */
/*  type:        one of INTERIOR : DIRICHLET : NEUMANN			    */
/*--------------------------------------------------------------------------*/

struct node_projection
{
  void (*func)(REAL_D old_coord, const EL_INFO *eli, const REAL_B lambda);
};

/*--------------------------------------------------------------------------*/
/*  one single element (triangle) of the grid:			            */
/*--------------------------------------------------------------------------*/
/*                                                                          */
/*  position of the nodes in 1d:                                            */
/*                                                                          */
/*  0 _____ 1   or  0 _____ 1                                               */
/*                      2                                                   */
/*                                                                          */
/*                          child[0]     child[1]                           */
/*  refinement:  0 _____ 1    0 ___ 1  0 ___ 1                              */
/*                               2        2                                 */
/*                                                                          */
/*--------------------------------------------------------------------------*/
/*                                                                          */
/*  position of the nodes in 2d                                             */
/*         2                 2                   2                 2        */
/*        /\       or       /\        or        /\       or       /\        */
/*       /  \             4/  \ 3              /  \             4/  \ 3     */
/*      /    \            /    \              /  3 \            /  6 \      */
/*    0/______\1        0/______\1          0/______\1        0/______\1    */
/*                           5                                     5        */
/*                                                                          */
/*  refinement:           2          child[0]  0    1   child[1]            */
/*                       /\                   /|    |\                      */
/*                     4/  \ 3  -->         5/ |4  3| \ 5                   */
/*                     /  6 \               /6 |    |6 \                    */
/*                   0/______\1           1/___|    |___\0                  */
/*                        5                  3  2  2  4                     */
/*                                                                          */
/*--------------------------------------------------------------------------*/
/*                                                                          */
/*  3d refinement: vertex numbering after (Baensch +) Kossaczky             */
/*                                                                          */
/*  edges:                                                                  */
/*  E0:  between V0, V1                                                     */
/*  E1:  between V0, V2                                                     */
/*  E2:  between V0, V3                                                     */
/*  E3:  between V1, V2                                                     */
/*  E4:  between V1, V3                                                     */
/*  E5:  between V2, V3                                                     */
/*                                                                          */
/*  Always edge 0 (between vertices 0 and 1) is bisected.                   */
/*                                                                          */
/*                                        V1                                */
/*                                      -+                                  */
/*                                 ----- ||                                 */
/*                     E0    ------      | |                                */
/*                     ------           |   | E3                            */
/*               ------                 |    |                              */
/*         ------                      |      |                             */
/*     V0 +. . . . . . . . . . . . . . | . . . |                            */
/*         ---               (E1)     |         +  V2                       */
/*            ---                     |         /                           */
/*               ---                 |E4      /                             */
/*                  ---              |      /                               */
/*                 E2  ---          |     / E5                              */
/*                        ---       |   /                                   */
/*                           ---   |  /                                     */
/*                              ---|/                                       */
/*                                 +                                        */
/*                                 V3                                       */
/*                                                                          */
/*--------------------------------------------------------------------------*/
/*  child:        pointers to the two children of the element		    */
/*                if (child[0]==child[1]==nil) element is a leaf of the     */
/*                        tree                                              */
/*  dof:          vector of pointers to dof vectors :-)                     */
/*  new_coord:    in case of curved boundary, coords of ref.edge midpoint   */
/*  index:        global element index (only for test purposes)		    */
/*  mark:         element is a leaf:   					    */
/*                   mark == 0         do not refine/coarsen		    */
/*                   mark > 0          refine (mark times)                  */
/*                   mark < 0          may be coarsened (mark times)        */
/*--------------------------------------------------------------------------*/

struct el
{
  EL         *child[2];
  DOF        **dof;
  S_CHAR     mark;
  REAL       *new_coord;

#if ALBERTA_DEBUG
  int        index;
#endif
};

/*--------------------------------------------------------------------------*/
/*   child_vertex_3d[el_type][child][i] =                                   */
/*       parent's local vertex index of new vertex i                        */
/*       4 stands for the newly generated vertex                            */
/*--------------------------------------------------------------------------*/
/*   child_edge_3d[el_type][child][i] =                                     */
/*       parent's local edge index of new edge i                            */
/*       new edge 2 is half of old edge 0,                                  */
/*       new edges 4,5 are really new edges, and value is different:        */
/*         child_edge_3d[][][4,5] = index of same edge in other child	    */
/*--------------------------------------------------------------------------*/
/*  vertex_of_edge_?d[edge][i], i = 1,2 are the two vertices of edge        */
/*--------------------------------------------------------------------------*/
extern int vertex_of_edge_2d[3][2];              /* defined in traverse_r.c */

extern int child_vertex_3d[3][2][4];             /* defined in traverse_r.c */
extern int child_edge_3d[3][2][6];               /* defined in traverse_r.c */
extern int vertex_of_edge_3d[6][2];              /* defined in traverse_r.c */

/*--------------------------------------------------------------------------*/
/*  edge_of_dofs_3d[i][j]: gives the local index of edge with vertices i, j */
/*--------------------------------------------------------------------------*/
extern U_CHAR  edge_of_dofs_3d[4][4];               /* defined in refine.c  */

/*--------------------------------------------------------------------------*/
/* PARAMETRIC structure, entry in MESH structure                            */
/* description of parametric meshes and elements                            */
/*--------------------------------------------------------------------------*/

struct parametric 
{
  char *name;     /* textual description analogous to BAS_FCTS. */
  int (*init_element)(const EL_INFO *info, const PARAMETRIC *parametric);
  /* init_el = 0 : non-parametric element */
  /* init_el = 1 : parametric element     */

  void (*coord_to_world)(const EL_INFO *info, const QUAD *quad,
			 int n, const REAL lambda[][N_LAMBDA], REAL_D *world);
  int (*world_to_coord)(const EL_INFO *info,
			int n, const REAL_D world[], REAL lambda[][N_LAMBDA]);
  void (*det)(const EL_INFO *info, const QUAD *quad,
	      int n, const REAL lambda[][N_LAMBDA], REAL dets[]);
  void (*grd_lambda)(const EL_INFO *info,  const QUAD *quad, 
		     int n, const REAL lambda[][N_LAMBDA],
		     REAL_D grd_lam[][N_LAMBDA], REAL dets[]);

  int not_all;             /* true:  some elements may be non-parametric */
  int use_reference_mesh;  /* true: standard routines coord_to_world, etc. */
                           /* may be used to get data about the reference  */
                           /* triangulation. Set to "false" by default.    */

  /* private entries */
  void (*inherit_parametric)(MESH *slave);
  void *data;
};

/*--------------------------------------------------------------------------*/
/*  additional information to elements during hierarchy traversal	    */
/*--------------------------------------------------------------------------*/
/*  mesh:          pointer to the mesh structure                      	    */
/*  coord:         world coordinates of the nodes                     	    */
/*                 parametric case is handled via dof_vector          	    */
/*  vertex_bound:  boundary type of the vertices                 	    */
/*  edge_bound:    boundary type of the edges                    	    */
/*  face_bound:    boundary type of the faces                    	    */
/*  projection:    node projection function for the new vertex which would  */
/*                 result from a refinement of the current element.         */
/*  neigh:         pointer to the adjacent elements       		    */
/*                 nil-pointer for a part of the boundary		    */
/*  opp_coord:     world coordinates of opposite vertices 		    */
/*  opp_vertex:    local indices of opposite vertices       		    */
/*  orientation:   orientation of the tetrahedron (+1|-1) (only 3d)	    */
/*--------------------------------------------------------------------------*/

struct el_info
{
  MESH                *mesh;
  REAL_D               coord[N_VERTICES_MAX];
  const MACRO_EL      *macro_el;
  EL                  *el, *parent;
  FLAGS                fill_flag;

  S_CHAR               vertex_bound[N_VERTICES_MAX];
  S_CHAR               edge_bound[N_EDGES_MAX];
  S_CHAR               face_bound[N_FACES_MAX];

  NODE_PROJECTION     *active_projection;
  NODE_PROJECTION     *projections[N_NEIGH_MAX + 1];
  int                  level;

  EL                  *neigh[N_NEIGH_MAX];
  U_CHAR               opp_vertex[N_NEIGH_MAX];
  U_CHAR               el_type;
  REAL_D               opp_coord[N_NEIGH_MAX];

  S_CHAR               orientation;
};

/* A macro for accessing the boundary type of the i-th wall,
 * i.e. codim one sub-simplex.
 */
#define WALL_BOUND(eli, dim, i)			\
  ((dim) == 1					\
   ? (eli)->vertex_bound[i]			\
   : ((dim) == 2				\
      ? (eli)->edge_bound[i]			\
      : (eli)->face_bound[i]))

/*--------------------------------------------------------------------------*/
/* RC_LIST_EL structure to describe a refinement/coarsening patch.          */
/* el_info:        contains information about the patch element. This is not*/
/*                 a pointer since EL_INFO structures are often overwritten */
/*                 during mesh traversal.                                   */
/* no:             index of the patch element in the patch.                 */
/* flag:           for coarsening: true iff the coarsening edge of the      */
/*                 patch element is the coarsening edge of the patch.       */
/* neigh:          neighbours to the right/left in the orientation of the   */
/*                 edge, or nil pointer for a boundary face. (dim == 3 only)*/
/* opp_vertex:     the opposite vertex of neigh[0/1]. (dim == 3 only)       */
/*--------------------------------------------------------------------------*/

struct rc_list_el
{
  EL_INFO      el_info;
  int          no;
  int          flag;
  RC_LIST_EL   *neigh[2];
  int          opp_vertex[2];
};

/*--------------------------------------------------------------------------*/
/*  flags, which information should be present in the EL_INFO structure     */
/*--------------------------------------------------------------------------*/

#define FILL_NOTHING            0x00L
#define FILL_COORDS             0x01L
#define FILL_BOUND              0x02L
#define FILL_NEIGH              0x04L
#define FILL_OPP_COORDS         0x08L
#define FILL_ORIENTATION        0x10L
#define FILL_EL_TYPE            0x20L
#define FILL_PROJECTION         0x40L

#define FILL_ANY(mesh)							\
  (0x01L|0x02L|0x04L|0x08L|0x10L|0x20L|0x40L|(mesh)->active_hooks)

/* Hook-queue flags */
#define HOOK_QUEUE_OFFSET 24

enum hook_queue_enum {
  HOOK_QUEUE_0 = 0,
  BAS_FCTS_HOOK_QUEUE = HOOK_QUEUE_0,
  HOOK_QUEUE_1,
  HOOK_QUEUE_2,
  HOOK_QUEUE_3,
  HOOK_QUEUE_4,
  HOOK_QUEUE_5,
  HOOK_QUEUE_6,
  HOOK_QUEUE_7,
};
/* Note: definition of enum must come before typedef for C++ compilation. */
typedef enum hook_queue_enum    HOOK_QUEUE_ENUM;

#define RUN_HOOKS_0 (1UL << HOOK_QUEUE_0)
#define RUN_BAS_FCTS_HOOKS RUN_HOOKS_0
#define RUN_HOOKS_1 (1UL << HOOK_QUEUE_1)
#define RUN_HOOKS_2 (1UL << HOOK_QUEUE_2)
#define RUN_HOOKS_3 (1UL << HOOK_QUEUE_3)
#define RUN_HOOKS_4 (1UL << HOOK_QUEUE_4)
#define RUN_HOOKS_5 (1UL << HOOK_QUEUE_5)
#define RUN_HOOKS_6 (1UL << HOOK_QUEUE_6)
#define RUN_HOOKS_7 (1UL << HOOK_QUEUE_7)

/*--------------------------------------------------------------------------*/
/*  flags for mesh traversal                                                */
/*--------------------------------------------------------------------------*/

#define CALL_EVERY_EL_PREORDER  0x0100L
#define CALL_EVERY_EL_INORDER   0x0200L
#define CALL_EVERY_EL_POSTORDER 0x0400L
#define CALL_LEAF_EL            0x0800L
#define CALL_LEAF_EL_LEVEL      0x1000L
#define CALL_EL_LEVEL           0x2000L
#define CALL_MG_LEVEL           0x4000L    /* used in multigrid methods */

#define TEST_FLAG(flags, el_info) \
        TEST_EXIT(!((((el_info)->fill_flag)^(flags)) & (flags)),\
                 "flag %d not set\n", (flags))

#if ALBERTA_DEBUG==1
# define DEBUG_TEST_FLAG(flags, el_info) \
                        if((((el_info)->fill_flag)^(flags)) & (flags)) \
                          print_error_funcname(funcName, __FILE__, __LINE__),\
                          print_error_msg_exit("flag %d not set\n", (flags))
#else
# define DEBUG_TEST_FLAG(flags, el_info) do { funcName = funcName; } while (0)
#endif
/*--------------------------------------------------------------------------*/
/*  one single element of the macro triangulation:			    */
/*--------------------------------------------------------------------------*/
/*  el:            pointer to the element data of the macro element         */
/*  coord:         world coordinates of the nodes on the macro element	    */
/*  vertex_bound:  boundary type of the vertices                 	    */
/*  edge_bound:    boundary type of the edges                    	    */
/*  face_bound:    boundary type of the faces                    	    */
/*  projection:    possible node projection functions for all nodes [0]     */
/*                 or for specific edges or faces (dim > 1), which will     */
/*                 override entry [0].                                      */
/*  index:         unique global index of macro element                     */
/*  neigh:         pointer to the adjacent macro elements		    */
/*                 nil-pointer for a part of the boundary		    */
/*  opp_vertex:    local indices of opposite vertices       		    */
/*  el_type:       type of corresponding element.           		    */
/*  orientation:   orientation of corresponding element.    		    */
/*--------------------------------------------------------------------------*/

struct macro_el
{
  EL               *el;
  REAL             *coord[N_VERTICES_MAX];

  S_CHAR           vertex_bound[N_VERTICES_MAX];
  S_CHAR           edge_bound[N_EDGES_MAX];
  S_CHAR           face_bound[N_FACES_MAX];

  NODE_PROJECTION *projection[N_NEIGH_MAX + 1];

  int              index;

  MACRO_EL        *neigh[N_NEIGH_MAX];
  S_CHAR           opp_vertex[N_NEIGH_MAX];

  U_CHAR           el_type;
  S_CHAR           orientation;
};

/*--------------------------------------------------------------------------*/
/*---  index based storage of macro triangulations                       ---*/
/*--------------------------------------------------------------------------*/

struct macro_data
{
  int dim;                          /* dimension of the elements            */

  int n_total_vertices;
  int n_macro_elements;

  REAL_D *coords;                   /* Length will be n_total_vertices      */ 

  int *mel_vertices;                /* mel_vertices[i*n_vertices[dim]+j]:   */
                                /* global index of jth vertex of element i  */ 

  int *neigh;                      /* neigh[i*n_neigh[dim]+j]:              */
                            /* neighbour j of element i or -1 at boundaries */

  S_CHAR *boundary;                /* boundary[i*n_neigh[dim]+j]:           */
                      /* boundary type of jth vertex/edge/face of element i */ 
  /* WARNING: In 1D the local index 0 corresponds to vertex 1 & vice versa! */
  /* (Consistent with macro_data.neigh)                                     */

  U_CHAR *el_type;                  /* el_type[i]: type of element i        */
                                    /* only used in 3d!                     */
};

#ifndef DOF_ADMIN_DEF
#define DOF_ADMIN_DEF

/*--------------------------------------------------------------------------*/
/*  dof handling                 				            */
/*--------------------------------------------------------------------------*/
#define DOF_FREE_SIZE 32
#define DOF_UNIT_ALL_FREE 0xFFFFFFFF
typedef unsigned int DOF_FREE_UNIT;
extern  DOF_FREE_UNIT dof_free_bit[DOF_FREE_SIZE];        /* in dof_admin.c */

#define FOR_ALL_DOFS(admin, todo) \
  if ((admin)->hole_count == 0) { int dof; \
  for (dof = 0; dof < (admin)->used_count; dof++) { todo; } } \
      else { DOF_FREE_UNIT _dfu, *_dof_free = (admin)->dof_free; \
        int _i, _ibit, dof=0; \
        int _n= ((admin)->size_used + DOF_FREE_SIZE-1) / DOF_FREE_SIZE; \
        for (_i = 0; _i < _n; _i++) { \
	  if ((_dfu = _dof_free[_i])) { \
	    if (_dfu == DOF_UNIT_ALL_FREE) dof += DOF_FREE_SIZE; \
	    else for (_ibit = 0; _ibit < DOF_FREE_SIZE; _ibit++) { \
               if (!(_dfu & dof_free_bit[_ibit])) { todo; } dof++; } } \
          else { \
            for (_ibit = 0; _ibit < DOF_FREE_SIZE; _ibit++){ todo; dof++;}}}}

#define FOR_ALL_FREE_DOFS(admin, todo) \
      if ((admin)->hole_count == 0) { int dof; \
        for (dof = (admin)->used_count; \
	     dof < (admin)->size; dof++)   { todo; } } \
      else { DOF_FREE_UNIT _dfu, *_dof_free = (admin)->dof_free; \
        int _i, _ibit, dof=0; \
        int _n= ((admin)->size + DOF_FREE_SIZE-1) / DOF_FREE_SIZE; \
        for (_i = 0; _i < _n; _i++) { \
	  if ((_dfu = _dof_free[_i])) { \
	    if (_dfu == DOF_UNIT_ALL_FREE) \
              for (_ibit = 0 ; _ibit < DOF_FREE_SIZE; _ibit++)\
                { todo; dof++; } \
	    else for (_ibit = 0; _ibit < DOF_FREE_SIZE; _ibit++) { \
                   if (_dfu & dof_free_bit[_ibit]) { todo; } dof++; } } \
	  else dof += DOF_FREE_SIZE; }}

struct dof_admin
{
  MESH         *mesh;
  const char   *name;

  DOF_FREE_UNIT *dof_free;    /* flag bit vector                           */
  unsigned int  dof_free_size;/* flag bit vector size                      */
  unsigned int  first_hole;   /* index of first non-zero dof_free entry    */

  U_CHAR        preserve_coarse_dofs; /* preserve non-leaf DOFs or not     */

  DOF  size;                 /* allocated size of dof_list vector          */
  DOF  used_count;           /* number of used dof indices                 */
  DOF  hole_count;           /* number of FREED dof indices (NOT size-used)*/
  DOF  size_used;            /* > max. index of a used entry               */

  int  n_dof[N_NODE_TYPES];  /* dofs from THIS dof_admin                   */
  int  n0_dof[N_NODE_TYPES]; /* dofs from previous dof_admins              */

  DOF_INT_VEC     *dof_int_vec;           /* linked list of int vectors    */
  DOF_DOF_VEC     *dof_dof_vec;           /* linked list of dof vectors    */
  DOF_DOF_VEC     *int_dof_vec;           /* linked list of dof vectors    */
  DOF_UCHAR_VEC   *dof_uchar_vec;         /* linked list of u_char vectors */
  DOF_SCHAR_VEC   *dof_schar_vec;         /* linked list of s_char vectors */
  DOF_REAL_VEC    *dof_real_vec;          /* linked list of real vectors   */
  DOF_REAL_D_VEC  *dof_real_d_vec;        /* linked list of real_d vectors */
  DOF_PTR_VEC     *dof_ptr_vec;           /* linked list of void * vectors */
  DOF_MATRIX      *dof_matrix;            /* linked list of matrices       */
  DOF_DOWB_MATRIX *dof_dowb_matrix;       /* linked list of block matrices */

/*--------------------------------------------------------------------------*/
/*---  pointer for administration; don't touch!                          ---*/
/*--------------------------------------------------------------------------*/

  void            *mem_info;
};


/*--------------------------------------------------------------------------*/
/*  dof vector structures            					    */
/*--------------------------------------------------------------------------*/
/*  next:        pointer to next structure containing vector of same type   */
/*  fe_space:    pointer to fe_space  structure                             */
/*  refine_interpol: dof interpolation during refinement                    */
/*  coarse_restrict: restriction of linear functionals evaluated on a finer */
/*                   grid and stored in dof vector to the coarser grid      */
/*                   during coarsening                                      */
/*                or dof interpolation during coarsening                    */
/*  size:        allocated size of vector                         	    */
/*  vec[]:    vector entries (entry is used if dof index is used)	    */
/*--------------------------------------------------------------------------*/

struct dof_int_vec
{
  DOF_INT_VEC    *next;
  const FE_SPACE *fe_space;

  const char     *name;

  DOF            size;
  int            *vec;

  void  (*refine_interpol)(DOF_INT_VEC *, RC_LIST_EL *, int n);
  void  (*coarse_restrict)(DOF_INT_VEC *, RC_LIST_EL *, int n);

/*--------------------------------------------------------------------------*/
/*---  pointer for administration; don't touch!                          ---*/
/*--------------------------------------------------------------------------*/
  void            *mem_info;

};

struct dof_dof_vec
{
  DOF_DOF_VEC    *next;
  const FE_SPACE *fe_space;

  const char     *name;

  DOF            size;
  DOF            *vec;

  void  (*refine_interpol)(DOF_DOF_VEC *, RC_LIST_EL *, int n);
  void  (*coarse_restrict)(DOF_DOF_VEC *, RC_LIST_EL *, int n);

  void            *mem_info;
};

struct dof_uchar_vec
{
  DOF_UCHAR_VEC  *next;
  const FE_SPACE *fe_space;

  const char     *name;
  DOF            size;
  U_CHAR         *vec;

  void  (*refine_interpol)(DOF_UCHAR_VEC *, RC_LIST_EL *, int n);
  void  (*coarse_restrict)(DOF_UCHAR_VEC *, RC_LIST_EL *, int n);

  void            *mem_info;
};

struct dof_schar_vec
{
  DOF_SCHAR_VEC  *next;
  const FE_SPACE *fe_space;

  const char     *name;

  DOF            size;
  S_CHAR         *vec;

  void  (*refine_interpol)(DOF_SCHAR_VEC *, RC_LIST_EL *, int n);
  void  (*coarse_restrict)(DOF_SCHAR_VEC *, RC_LIST_EL *, int n);

  void            *mem_info;
};

struct dof_real_vec
{
  DOF_REAL_VEC   *next;
  const FE_SPACE *fe_space;

  const char     *name;
  DOF            size;
  REAL           *vec;

  void  (*refine_interpol)(DOF_REAL_VEC *, RC_LIST_EL *, int n);
  void  (*coarse_restrict)(DOF_REAL_VEC *, RC_LIST_EL *, int n);

  void            *mem_info;
};

struct dof_real_d_vec
{
  DOF_REAL_D_VEC *next;
  const FE_SPACE *fe_space;

  const char     *name;
  DOF            size;
  REAL_D         *vec;

  void  (*refine_interpol)(DOF_REAL_D_VEC *, RC_LIST_EL *, int n);
  void  (*coarse_restrict)(DOF_REAL_D_VEC *, RC_LIST_EL *, int n);

  void            *mem_info;
};

struct dof_ptr_vec
{
  DOF_PTR_VEC *next;
  const FE_SPACE *fe_space;

  const char     *name;
  DOF            size;
  void          **vec;

  void  (*refine_interpol)(DOF_PTR_VEC *, RC_LIST_EL *, int n);
  void  (*coarse_restrict)(DOF_PTR_VEC *, RC_LIST_EL *, int n);

  void            *mem_info;
};

/*--------------------------------------------------------------------------*/
/*  sparse matrix with one row for each dof,                                */
/*  entries are either REAL or REAL_DD				            */
/*--------------------------------------------------------------------------*/
/*  next:        pointer to next matrix (linked list in MESH)               */
/*  matrix_row[]: pointers to row structures (or nil if row index is unused)*/
/*  size:         currently allocated size of matrix_row[]		    */
/*--------------------------------------------------------------------------*/

struct dof_matrix
{
  DOF_MATRIX     *next;
  const FE_SPACE *row_fe_space;
  const FE_SPACE *col_fe_space;

  const char     *name;

  MATRIX_ROW     **matrix_row;                 /* lists of matrix entries   */
  DOF            size;                         /* size of vector matrix_row */

  void       (*refine_interpol)(DOF_MATRIX *, RC_LIST_EL *, int n);
  void       (*coarse_restrict)(DOF_MATRIX *, RC_LIST_EL *, int n);

  void            *mem_info;
};

/* "flag" values for "type" component */
#define DOWBM_FULL (1 << 0)
#define DOWBM_SYMM (1 << 1)
#define DOWBM_DIAG (1 << 2)

typedef enum dowbm_type {
  dowbm_full = DOWBM_FULL,
  dowbm_diag = DOWBM_DIAG,
  dowbm_symm = DOWBM_SYMM
} DOWBM_TYPE;

struct dof_dowb_matrix
{
  DOF_DOWB_MATRIX *next;

  const FE_SPACE  *row_fe_space;
  const FE_SPACE  *col_fe_space;

  const char      *name;

  DOWB_MATRIX_ROW **matrix_row;               /* lists of matrix entries   */
  DOF             size;                       /* size of vector matrix_row */

  DOWBM_TYPE      type;
  void       (*refine_interpol)(DOF_DOWB_MATRIX *, RC_LIST_EL *, int n);
  void       (*coarse_restrict)(DOF_DOWB_MATRIX *, RC_LIST_EL *, int n);

  void            *mem_info;
};

/*--------------------------------------------------------------------------*/
/*  row structure for sparse matrix, with either REAL or REAL_DD entries.   */
/*--------------------------------------------------------------------------*/
/*  next:        pointer to next structure containing entries of same row   */
/*  col[]:       column indices of entries (if >= 0; else unused)	    */
/*  entry[]:     matrix entries                        			    */
/*--------------------------------------------------------------------------*/

#define ROW_LENGTH 9

struct matrix_row
{
  MATRIX_ROW *next;
  DOF        col[ROW_LENGTH];    /* column indices */
  REAL       entry[ROW_LENGTH];  /* matrix entries */
};

/* full featured blocks */
struct dowb_matrix_row
{
  DOWB_MATRIX_ROW *next;
  DOF             col[ROW_LENGTH];    /* column indices */
  union {
    REAL_DD       full[0];   /* full */
    REAL_DDS      symm[0]; /* symmetric, only upper triangle is stored */
    REAL_D        diag[0]; /* diagonal */
  } entry;  /* matrix entries */
};

/* shared by DOF_MATRIX and DOF_DOWB_MATRIX */

#define ENTRY_USED(col)         ((col) >= 0)
#define ENTRY_NOT_USED(col)     ((col) < 0)
#define UNUSED_ENTRY    -1
#define NO_MORE_ENTRIES -2

#ifndef __CBLAS_H__
typedef enum { NoTranspose,
               Transpose,
               ConjugateTranspose } MatrixTranspose;
#endif

#endif  /* DOF_ADMIN_DEF */


/*--------------------------------------------------------------------------*/
/*  Here comes the MESH (giving access to the whole triangulation)	    */
/*--------------------------------------------------------------------------*/

struct mesh
{
  const char      *name;

  int             dim;

  int             n_vertices;
  int             n_elements;
  int             n_hier_elements;

  int             n_edges;                        /* Only used for dim > 1  */
  int             n_faces;                        /* Only used for dim == 3 */
  int             max_edge_neigh;                 /* Only used for dim == 3 */

  int             n_macro_el;
  MACRO_EL        *macro_els;

  REAL            diam[DIM_OF_WORLD];
  PARAMETRIC      *parametric;

  DOF_ADMIN       **dof_admin;
  int             n_dof_admin;
  
  int             n_dof_el;         /* sum of all dofs from all admins      */
  int             n_dof[N_NODE_TYPES]; /* sum of vertex/edge/... dofs from  */
                                      /* all admins */

  int             n_node_el;   /* number of used nodes on each element      */
  int             node[N_NODE_TYPES]; /* index of first vertex/edge/... node*/

  int             cookie;    /* changed on each refine/coarsen. Use this to */
     /* check consistency of meshes and DOF vectors when reading from files.*/

/*--------------------------------------------------------------------------*/
/*---  pointer for administration; don't touch!                          ---*/
/*--------------------------------------------------------------------------*/

  void            *mem_info;

  /* Linked list of hook functions to be run during mesh-traverse
   * before the per-element method is called.
   */
  LIST_NODE traverse_hooks[8];
  FLAGS active_hooks;
};

/*--------------------------------------------------------------------------*/
/*  stack data structure for non-recursive mesh traversal                   */
/*--------------------------------------------------------------------------*/

struct traverse_stack 
{
  MESH           *traverse_mesh;
  int             traverse_level;
  FLAGS           traverse_fill_flag;

  const MACRO_EL *traverse_mel;
  int             stack_size;
  int             stack_used;
  EL_INFO        *elinfo_stack;
  U_CHAR         *info_stack;
  
  const MACRO_EL *save_traverse_mel;
  EL_INFO        *save_elinfo_stack;
  U_CHAR         *save_info_stack;
  int             save_stack_used;

  int             el_count;

  int             marker;
  
  TRAVERSE_STACK *next;
};

/*--------------------------------------------------------------------------*/
/*---  data structure for basis function representation                  ---*/
/*--------------------------------------------------------------------------*/

typedef REAL        BAS_FCT(const REAL[N_LAMBDA]);
typedef const REAL  *GRD_BAS_FCT(const REAL[N_LAMBDA]);
typedef const REAL  (*D2_BAS_FCT(const REAL[N_LAMBDA]))[N_LAMBDA];

struct bas_fcts
{
  char         *name;       /*  textual description                         */
  int          dim;         /*  dimension of the corresponding mesh.        */
  int          n_bas_fcts;  /*  number of basisfunctions on one el          */
  int          degree;      /*  maximal degree of the basis functions       */
  const int    n_dof[N_NODE_TYPES];   /* dofs from these bas_fcts           */

  void         (*init_element)(const EL_INFO *, const FE_SPACE *, U_CHAR);
  BAS_FCT      **phi;
  GRD_BAS_FCT  **grd_phi;
  D2_BAS_FCT   **D2_phi;

  const DOF    *(*get_dof_indices)(const EL *, const DOF_ADMIN *, DOF *);
  const S_CHAR *(*get_bound)(const EL_INFO *, S_CHAR *);

/*************** entries must be set for interpolation   ********************/

  const REAL   *(*interpol)(const EL_INFO *el_info, int n, const int *indices, 
			    REAL (*f)(const REAL_D),
			    REAL (*f_loc)(const EL_INFO *el_info,
					  const REAL lambda[N_LAMBDA]),
			    REAL *coeff);

  const REAL_D *(*interpol_d)(const EL_INFO *el_info, int n,
			      const int *indices,
			      const REAL *(*f)(const REAL_D, REAL_D),
			      const REAL *(*f_loc)(const EL_INFO *el_info,
						   const REAL lambda[N_LAMBDA],
						   REAL_D val),
			      REAL_D *coeff);

/********************   optional entries  ***********************************/

  const int    *(*get_int_vec)(const EL *, const DOF_INT_VEC *, int *);
  const REAL   *(*get_real_vec)(const EL *, const DOF_REAL_VEC *, REAL *);
  const REAL_D *(*get_real_d_vec)(const EL *, const DOF_REAL_D_VEC *, REAL_D *);
  const U_CHAR *(*get_uchar_vec)(const EL *, const DOF_UCHAR_VEC *, U_CHAR *);
  const S_CHAR *(*get_schar_vec)(const EL *, const DOF_SCHAR_VEC *, S_CHAR *);

  void  (*real_refine_inter)(DOF_REAL_VEC *, RC_LIST_EL *, int);
  void  (*real_coarse_inter)(DOF_REAL_VEC *, RC_LIST_EL *, int);
  void  (*real_coarse_restr)(DOF_REAL_VEC *, RC_LIST_EL *, int);

  void  (*real_d_refine_inter)(DOF_REAL_D_VEC *, RC_LIST_EL *, int);
  void  (*real_d_coarse_inter)(DOF_REAL_D_VEC *, RC_LIST_EL *, int);
  void  (*real_d_coarse_restr)(DOF_REAL_D_VEC *, RC_LIST_EL *, int);

  void  *bas_fcts_data;
};

/* Barycentric coordinates of Lagrange nodes. */
#define LAGRANGE_NODES(bfcts) ((const REAL_B *)(bfcts)->bas_fcts_data)

/*--------------------------------------------------------------------------*/
/*---  FE spaces are a triple of DOFs and BAS_FCTs on a MESH             ---*/
/*--------------------------------------------------------------------------*/

struct fe_space
{
  const char       *name;
  const DOF_ADMIN  *admin;
  const BAS_FCTS   *bas_fcts;
  MESH             *mesh;
};

/*--------------------------------------------------------------------------*/
/*---  data structures for numerical integration                         ---*/
/*--------------------------------------------------------------------------*/

struct quadrature
{
  char          *name;
  int           degree;

  int           dim;
  int           n_points;
  const double  **lambda;
  const double  *w;
};

#define MAX_N_QUAD_POINTS  64

/*--------------------------------------------------------------------------*/
/*--- data structure with precomputed values of basis functions at       ---*/
/*--- quadrature nodes on the standard element                           ---*/
/*--------------------------------------------------------------------------*/

#define INIT_PHI       1
#define INIT_GRD_PHI   2
#define INIT_D2_PHI    4

struct quad_fast
{
  const QUAD        *quad;
  const BAS_FCTS    *bas_fcts;

  int               n_points;
  int               n_bas_fcts;
  const double      *w;

  U_CHAR            init_flag;

  REAL              **phi;
  REAL              (**grd_phi)[N_LAMBDA];
  REAL              (**D2_phi)[N_LAMBDA][N_LAMBDA];
};

/*--------------------------------------------------------------------------*/
/*---  data structure for adaptive methods                               ---*/
/*--------------------------------------------------------------------------*/

struct adapt_stat
{
  const char  *name;
  REAL        tolerance;
  REAL        p;                         /* power in estimator norm        */
  int         max_iteration;
  int         info;

  REAL   (*estimate)(MESH *mesh, ADAPT_STAT *adapt);
  REAL   (*get_el_est)(EL *el);          /* local error estimate           */
  REAL   (*get_el_estc)(EL *el);         /* local coarsening error estimate*/
  U_CHAR (*marking)(MESH *mesh, ADAPT_STAT *adapt);

  void   *est_info;                      /* estimator parameters           */
  REAL   err_sum, err_max;               /* sum and max of el_est          */

  void   (*build_before_refine)(MESH *mesh, U_CHAR flag);
  void   (*build_before_coarsen)(MESH *mesh, U_CHAR flag);
  void   (*build_after_coarsen)(MESH *mesh, U_CHAR flag);
  void   (*solve)(MESH *mesh);

  int    refine_bisections;
  int    coarsen_allowed;                /* 0 : 1                          */
  int    coarse_bisections;

  int    strategy;                       /* 1=GR, 2=MS, 3=ES, 4=GERS       */
  REAL   MS_gamma, MS_gamma_c;           /* maximum strategy               */
  REAL   ES_theta, ES_theta_c;           /* equidistribution strategy      */
  REAL   GERS_theta_star, GERS_nu, GERS_theta_c;  /* willy's strategy      */
};


struct adapt_instat
{
  const char  *name;

  ADAPT_STAT adapt_initial[1];
  ADAPT_STAT adapt_space[1];

  REAL   time;
  REAL   start_time, end_time;
  REAL   timestep;

  void   (*init_timestep)(MESH *mesh, ADAPT_INSTAT *adapt);
  void   (*set_time)(MESH *mesh, ADAPT_INSTAT *adapt);
  void   (*one_timestep)(MESH *mesh, ADAPT_INSTAT *adapt);
  REAL   (*get_time_est)(MESH *mesh, ADAPT_INSTAT *adapt);
  void   (*close_timestep)(MESH *mesh, ADAPT_INSTAT *adapt);

  int    strategy; 
  int    max_iteration;

  REAL   tolerance;
  REAL   rel_initial_error;
  REAL   rel_space_error;
  REAL   rel_time_error;
  REAL   time_theta_1;
  REAL   time_theta_2;
  REAL   time_delta_1;
  REAL   time_delta_2;
  int    info;
};

#define MESH_REFINED   1
#define MESH_COARSENED 2

#define H1_NORM  1
#define L2_NORM  2

/*--------------------------------------------------------------------------*/
/*---  data structures for matrix and vector update                      ---*/
/*--------------------------------------------------------------------------*/

typedef struct el_matrix_info  EL_MATRIX_INFO;
struct el_matrix_info
{
  int              n_row;
  const DOF_ADMIN  *row_admin;
  const DOF        *(*get_row_dof)(const EL *,const DOF_ADMIN *, DOF *);

  int              n_col;
  const DOF_ADMIN  *col_admin;
  const DOF        *(*get_col_dof)(const EL *,const DOF_ADMIN *, DOF *);

  const S_CHAR     *(*get_bound)(const EL_INFO *, S_CHAR *);

  REAL             factor;

  const REAL       **(*el_matrix_fct)(const EL_INFO *, void *);
  void             *fill_info;

  FLAGS            fill_flag;
};

typedef struct el_dowb_matrix_info  EL_DOWB_MATRIX_INFO;
struct el_dowb_matrix_info
{
  int              n_row;
  const DOF_ADMIN  *row_admin;
  const DOF        *(*get_row_dof)(const EL *,const DOF_ADMIN *, DOF *);

  int              n_col;
  const DOF_ADMIN  *col_admin;
  const DOF        *(*get_col_dof)(const EL *,const DOF_ADMIN *, DOF *);

  const S_CHAR     *(*get_bound)(const EL_INFO *, S_CHAR *);

  REAL             factor;

  const void       **(*el_matrix_fct)(const EL_INFO *, void *);
  void             *fill_info;

  FLAGS            fill_flag;
  DOWBM_TYPE       type; /* dowbm_full, _symm or _diag */
};

typedef struct el_vec_info  EL_VEC_INFO;
struct el_vec_info
{
  int              n_dof;
  const DOF_ADMIN  *admin;
  const DOF        *(*get_dof)(const EL *,const DOF_ADMIN *, DOF *);
  const S_CHAR     *(*get_bound)(const EL_INFO *, S_CHAR *);

  REAL             factor;

  const REAL       *(*el_vec_fct)(const EL_INFO *, void *);
  void             *fill_info;

  FLAGS            fill_flag;
};

typedef struct el_vec_d_info  EL_VEC_D_INFO;
struct el_vec_d_info
{
  int              n_dof;
  const DOF_ADMIN  *admin;
  const DOF        *(*get_dof)(const EL *,const DOF_ADMIN *, DOF *);
  const S_CHAR     *(*get_bound)(const EL_INFO *, S_CHAR *);

  REAL             factor;

  const REAL_D     *(*el_vec_fct)(const EL_INFO *, void *);
  void             *fill_info;

  FLAGS            fill_flag;
};

/*--------------------------------------------------------------------------*/
/*---  data structure about the differential operator for matrix assemblage */
/*--------------------------------------------------------------------------*/

typedef struct operator_info  OPERATOR_INFO;
struct operator_info
{
  const FE_SPACE *row_fe_space;
  const FE_SPACE *col_fe_space;

  const QUAD *quad[3];

  int       (*init_element)(const EL_INFO *, const QUAD *[3], void *);
  const REAL (*(*LALt)(const EL_INFO *, const QUAD *, int, void *))[N_LAMBDA];
  int        LALt_pw_const;
  int        LALt_symmetric;
  const REAL *(*Lb0)(const EL_INFO *, const QUAD *, int, void *);
  int        Lb0_pw_const;
  const REAL *(*Lb1)(const EL_INFO *, const QUAD *, int, void *);
  int        Lb1_pw_const;
  int        Lb0_Lb1_anti_symmetric;
  REAL       (*c)(const EL_INFO *, const QUAD *, int, void *);
  int        c_pw_const;

  int        use_get_bound;
  void       *user_data;
  FLAGS      fill_flag;
};

typedef struct dowb_operator_info DOWB_OPERATOR_INFO;
struct dowb_operator_info
{
  const FE_SPACE *row_fe_space;
  const FE_SPACE *col_fe_space;

  const QUAD *quad[3];

  int         (*init_element)(const EL_INFO *, const QUAD *[3], void *);
  union {
    const REAL_DD (*(*full)(const EL_INFO *,
			    const QUAD *, int, void *))[N_LAMBDA];
    const REAL_DDS (*(*symm)(const EL_INFO *,
			     const QUAD *, int, void *))[N_LAMBDA];
    const REAL_D (*(*diag)(const EL_INFO *,
			   const QUAD *, int, void *))[N_LAMBDA];
  } LALt;
  int           LALt_pw_const;
  int           LALt_symmetric;
  union {
    const REAL_DD  *(*full)(const EL_INFO *, const QUAD *, int, void *);
    const REAL_DDS *(*symm)(const EL_INFO *, const QUAD *, int, void *);
    const REAL_D   *(*diag)(const EL_INFO *, const QUAD *, int, void *);
  } Lb0;
  int           Lb0_pw_const;
  union {
    const REAL_DD  *(*full)(const EL_INFO *, const QUAD *, int, void *);
    const REAL_DDS *(*symm)(const EL_INFO *, const QUAD *, int, void *);
    const REAL_D   *(*diag)(const EL_INFO *, const QUAD *, int, void *);
  } Lb1;
  int           Lb1_pw_const;
  int           Lb0_Lb1_anti_symmetric;
  union {
    const REAL_D   *(*full)(const EL_INFO *, const QUAD *, int, void *);
    const REAL_DDS *(*symm)(const EL_INFO *, const QUAD *, int, void *);
    const REAL     *(*diag)(const EL_INFO *, const QUAD *, int, void *);
  } c;    
  int           c_pw_const;

  int        use_get_bound;
  void       *user_data;
  FLAGS      fill_flag;
  DOWBM_TYPE type; /* dowbm_full, _symm or _diag */
};

/*--------------------------------------------------------------------------*/
/*  calculate element stiffness matrices by preevaluated integrals over the */
/*  the reference element.                                                  */
/*--------------------------------------------------------------------------*/

typedef struct q11_psi_phi   Q11_PSI_PHI;
typedef struct q01_psi_phi   Q01_PSI_PHI;
typedef struct q10_psi_phi   Q10_PSI_PHI;
typedef struct q00_psi_phi   Q00_PSI_PHI;

struct q11_psi_phi
{
  const BAS_FCTS     *psi;
  const BAS_FCTS     *phi;
  const QUAD         *quad;

  const int   **n_entries;
  const REAL  ***values;
  const int   ***k;
  const int   ***l;
};

struct q01_psi_phi
{
  const BAS_FCTS     *psi;
  const BAS_FCTS     *phi;
  const QUAD         *quad;

  const int   **n_entries;
  const REAL  ***values;
  const int   ***l;
};

struct q10_psi_phi
{
  const BAS_FCTS     *psi;
  const BAS_FCTS     *phi;
  const QUAD         *quad;

  const int   **n_entries;
  const REAL  ***values;
  const int   ***k;
};

struct q00_psi_phi
{
  const BAS_FCTS     *psi;
  const BAS_FCTS     *phi;
  const QUAD         *quad;

  const REAL  **values;
};


/*--------------------------------------------------------------------------*/
/*   data type for preconditioning                                          */
/*--------------------------------------------------------------------------*/

typedef struct precon PRECON;
struct precon
{
  void    *precon_data;

  int     (*init_precon)(void *precon_data);
  void    (*precon)(void *precon_data, int n, REAL *vec);
  void    (*exit_precon)(void *precon_data);
};

const PRECON *get_diag_precon_s(const DOF_MATRIX *, const DOF_SCHAR_VEC *);
const PRECON *get_diag_precon_d(const DOF_MATRIX *, const DOF_SCHAR_VEC *);
const PRECON *get_diag_precon_dowb(const DOF_DOWB_MATRIX *,
				   const DOF_SCHAR_VEC *);

const PRECON *get_HB_precon_s(const FE_SPACE *, const DOF_SCHAR_VEC *, int, int);
const PRECON *get_HB_precon_d(const FE_SPACE *, const DOF_SCHAR_VEC *, int, int);

const PRECON *get_BPX_precon_s(const FE_SPACE *, const DOF_SCHAR_VEC *, int, int);
const PRECON *get_BPX_precon_d(const FE_SPACE *, const DOF_SCHAR_VEC *, int, int);

/*--------------------------------------------------------------------------*/
/*  solver identification for interface to OEM-lib                          */
/*--------------------------------------------------------------------------*/
typedef enum {NoSolver, BiCGStab, CG, TfQMR, GMRes, ODir, ORes} OEM_SOLVER;

/*--------------------------------------------------------------------------*/
/*--- abstract multigrid                                                 ---*/
/*--------------------------------------------------------------------------*/

typedef struct multi_grid_info MULTI_GRID_INFO;

struct multi_grid_info
{
  REAL             tolerance;                     /* tol. for resid         */
  REAL             exact_tolerance;               /* tol. for exact_solver  */

  int              cycle;                         /* 1=V-cycle, 2=W-cycle   */
  int              n_pre_smooth, n_in_smooth;     /* no of smoothing loops  */
  int              n_post_smooth;                 /* no of smoothing loops  */
  int              mg_levels;                     /* current no. of levels  */
  int              exact_level;                   /* level for exact_solver */
  int              max_iter;                      /* max. no of MG iter's   */
  int              info;

  int              (*init_multi_grid)(MULTI_GRID_INFO *mg_info);
  void             (*pre_smooth)(MULTI_GRID_INFO *mg_info, int level, int n);
  void             (*in_smooth)(MULTI_GRID_INFO *mg_info, int level, int n);
  void             (*post_smooth)(MULTI_GRID_INFO *mg_info, int level, int n);
  void             (*mg_restrict)(MULTI_GRID_INFO *mg_info, int level);
  void             (*mg_prolongate)(MULTI_GRID_INFO *mg_info, int level);
  void             (*exact_solver)(MULTI_GRID_INFO *mg_info, int level);
  REAL             (*mg_resid)(MULTI_GRID_INFO *mg_info, int level);
  void             (*exit_multi_grid)(MULTI_GRID_INFO *mg_info);

  void             *data;                         /* application dep. data */

};
int MG(MULTI_GRID_INFO *mg_info);

/*--------------------------------------------------------------------------*/
/*--- concrete multigrid                                                 ---*/
/*--------------------------------------------------------------------------*/

typedef struct mg_s_info MG_S_INFO;
struct mg_s_info
{
  MULTI_GRID_INFO  *mg_info;                      /* abstract MG info       */

  const FE_SPACE      *fe_space;
  DOF_MATRIX          *mat;
  const DOF_REAL_VEC  *f;
  DOF_REAL_VEC        *u;
  const DOF_SCHAR_VEC *bound;

  int              smoother,     exact_solver;
  REAL             smooth_omega, exact_omega;

  int              size;                          /* current size of vectors*/
  DOF_MATRIX       **matrix;                      /* one for each level     */
  REAL             **f_h;                         /* one for each level     */
  REAL             **u_h;                         /* one for each level     */
  REAL             **r_h;                         /* one for each level     */
  int              *dofs_per_level;               /* count dofs per level   */

  int              sort_size;                     /* size of sort vectors   */
  DOF              *sort_dof;                     /* dofs in order of levels*/
  DOF              *(dof_parent[2]);              /* (for linear elements)  */
  U_CHAR           *dof_level;
  S_CHAR           *sort_bound;                   /* sorted bound           */

  int              sort_invers_size;              /* size of inv. sort list */
  int              *sort_dof_invers;              /* inverse sort list      */
};
/*--------------------------------------------------------------------------*/
/*  sort_dof[ sorted dof ]          = unsorted dof                          */
/*  sort_dof_invers[ unsorted dof ] = sorted dof                            */
/*--------------------------------------------------------------------------*/

/* file MG_s1.c DOF_sort routines *******************************************/
void MG_s_setup_levels(MG_S_INFO *mg_s_info);
void MG_s_setup_mat_b(MG_S_INFO *mg_s_info,
		      DOF_MATRIX *mat, const DOF_SCHAR_VEC *bound);
void MG_s_dof_copy_to_sparse(MG_S_INFO *mg_s_info,
			     const DOF_REAL_VEC *x, REAL *y);
void MG_s_dof_copy_from_sparse(MG_S_INFO *mg_s_info, 
			       const REAL *x, DOF_REAL_VEC *y);
void MG_s_reset_mat(MG_S_INFO *mg_s_info);
void MG_s_sort_mat(MG_S_INFO *mg_s_info);
void MG_s_free_mem(MG_S_INFO *mg_s_info);

/* file MG_s2.c: DOF_sort independent routines ******************************/
void MG_s_restrict_mg_matrices(MG_S_INFO *mg_s_info);
void MG_s_restrict(MULTI_GRID_INFO *mg_info, int mg_level);
void MG_s_prolongate(MULTI_GRID_INFO *mg_info, int mg_level);
REAL MG_s_resid(MULTI_GRID_INFO *mg_info, int mg_level);
void MG_s_smoother(MULTI_GRID_INFO *mg_info, int mg_level, int n);
void MG_s_exact_solver(MULTI_GRID_INFO *mg_info, int mg_level);
void MG_s_gemv(MG_S_INFO *mg_s_info, int mg_level, MatrixTranspose transpose, 
	       REAL alpha, DOF_MATRIX *a, REAL *x, REAL beta, REAL *y);


/* file MG_s.c: *************************************************************/
int mg_s(DOF_MATRIX *matrix, DOF_REAL_VEC *u, const DOF_REAL_VEC *f,
	 const DOF_SCHAR_VEC *bound, 
	 REAL tol, int max_iter, int info, char *prefix);
MG_S_INFO *mg_s_init(DOF_MATRIX *matrix, const DOF_SCHAR_VEC *bound, 
		     int info, char *prefix);
int mg_s_solve(MG_S_INFO *mg_s_info,
	       DOF_REAL_VEC *u, const DOF_REAL_VEC *f, REAL tol, int max_iter);
void mg_s_exit(MG_S_INFO *mg_s_info);

/*--------------------------------------------------------------------------*/
/* Graphic output Definitions                                               */
/*--------------------------------------------------------------------------*/

typedef void * GRAPH_WINDOW;
typedef float  GRAPH_RGBCOLOR[3];

/** flags used by graph_mesh(): ****/
#define GRAPH_MESH_BOUNDARY        1
#define GRAPH_MESH_ELEMENT_MARK    2
#define GRAPH_MESH_VERTEX_DOF      4
#define GRAPH_MESH_ELEMENT_INDEX   8

/*--------------------------------------------------------------------------*/
/*  very usefull macro definitons                                           */
/*--------------------------------------------------------------------------*/

#define GET_MESH(dim,name,macro_data,init_node_proj) \
 check_and_get_mesh((dim),DIM_OF_WORLD,ALBERTA_DEBUG, \
                    ALBERTA_VERSION,(name),(macro_data), \
                    (init_node_proj))

#define GET_DOF_VEC(ptr, dof_vec)\
   TEST_EXIT((dof_vec)  && ((ptr) = (dof_vec)->vec),\
      "%s == nil\n", (dof_vec) ? NAME(dof_vec) : #dof_vec)


/*--------------------------------------------------------------------------*/
/*  defined in graphXO.c                                                    */
/*--------------------------------------------------------------------------*/
extern const GRAPH_RGBCOLOR rgb_black; 
extern const GRAPH_RGBCOLOR rgb_white;  
extern const GRAPH_RGBCOLOR rgb_red;    
extern const GRAPH_RGBCOLOR rgb_green;  
extern const GRAPH_RGBCOLOR rgb_blue;   
extern const GRAPH_RGBCOLOR rgb_yellow; 
extern const GRAPH_RGBCOLOR rgb_magenta;
extern const GRAPH_RGBCOLOR rgb_cyan;   
extern const GRAPH_RGBCOLOR rgb_grey50; 

extern const GRAPH_RGBCOLOR rgb_albert;
extern const GRAPH_RGBCOLOR rgb_alberta;


/*--------------------------------------------------------------------------*/
/*  used in wall_quad_fast.c                                                */
/*--------------------------------------------------------------------------*/

/* We use sort_face_indices() & friends and build the tables for every
 * relative permutation possible.
 */

typedef struct wall_quad_fast WALL_QUAD_FAST;

#define CARD_SN_MAX 6 /* this must be (N_LAMBDA-1)! */

struct wall_quad_fast
{
  const QUAD             *quad;
  
  int                    n_points;
  int                    n_bas_fcts;
  const REAL             *w;
  REAL_B                 *lambda[CARD_SN_MAX][N_FACES_MAX];
  U_CHAR                 init_flag;
  
  REAL                   **phi[CARD_SN_MAX][N_FACES_MAX];

  WALL_QUAD_FAST         *next;
  BAS_FCTS               *bas_fcts;

  REAL_B                 **grd_phi[CARD_SN_MAX][N_FACES_MAX];
  REAL_BB                **D2_phi[CARD_SN_MAX][N_FACES_MAX];
};

/*--------------------------------------------------------------------------*/
/*  functions supplied by ALBERTA                                           */
/*--------------------------------------------------------------------------*/

/***   file coarsen.c   *****************************************************/
extern U_CHAR coarsen(MESH *mesh);
extern U_CHAR global_coarsen(MESH *mesh, int no);
extern int  get_max_level(MESH *mesh);

/***   file dof_admin.c   ***************************************************/
/*extern void add_bas_fcts_to_admin(DOF_ADMIN *admin, const BAS_FCTS *bas_fcts);*/
extern const DOF_ADMIN *get_vertex_admin(MESH *mesh);

void add_element_matrix(DOF_MATRIX *, REAL, int, int, const DOF *, 
			const DOF *, const REAL **, const S_CHAR *);
void add_element_dowb_matrix(DOF_DOWB_MATRIX *, REAL, int, int, const DOF *, 
			     const DOF *, const void **, const S_CHAR *);
void add_element_vec(DOF_REAL_VEC *, REAL, int, const DOF *,
		     const REAL *, const S_CHAR *);
void add_element_d_vec(DOF_REAL_D_VEC *, REAL, int, const DOF *,
		       const REAL_D *, const S_CHAR *);

extern void dof_compress(MESH *mesh);
extern void clear_dof_matrix(DOF_MATRIX *matrix);
extern void clear_dof_dowb_matrix(DOF_DOWB_MATRIX *matrix);
extern void print_dof_matrix(const DOF_MATRIX *matrix);
extern void print_dof_dowb_matrix(const DOF_DOWB_MATRIX *matrix);
extern void print_dof_real_vec(const DOF_REAL_VEC *drv);
extern void print_dof_real_d_vec(const DOF_REAL_D_VEC *drdv);
extern void print_dof_ptr_vec(const DOF_PTR_VEC *dpv);
extern void print_dof_int_vec(const DOF_INT_VEC *div);
extern void print_dof_uchar_vec(const DOF_UCHAR_VEC *div);
extern void print_dof_schar_vec(const DOF_SCHAR_VEC *div);
/* BLAS 1 */
extern REAL dof_nrm2(const DOF_REAL_VEC *x);
extern REAL dof_asum(const DOF_REAL_VEC *x);
extern void dof_set(REAL alpha, DOF_REAL_VEC *x);
extern void dof_scal(REAL alpha, DOF_REAL_VEC *x);
extern REAL dof_dot(const DOF_REAL_VEC *x, const DOF_REAL_VEC *y);
extern void dof_copy(const DOF_REAL_VEC *x, DOF_REAL_VEC *y);
extern void dof_axpy(REAL alpha, const DOF_REAL_VEC *x, DOF_REAL_VEC *y);
/*  some non BLAS  */
extern void dof_xpay(REAL alpha, const DOF_REAL_VEC *x, DOF_REAL_VEC *y);
extern REAL dof_min(const DOF_REAL_VEC *x);
extern REAL dof_max(const DOF_REAL_VEC *x);
/* BLAS 2 */
extern void dof_gemv(MatrixTranspose transpose, REAL alpha,
		     const DOF_MATRIX *a, const DOF_REAL_VEC *x,
		     REAL beta, DOF_REAL_VEC *y);
extern void dof_mv(MatrixTranspose transpose, const DOF_MATRIX *a,
		   const DOF_REAL_VEC *x, DOF_REAL_VEC *y);

/* now the same for REAL_D */
extern void dof_axpy_d(REAL alpha, const DOF_REAL_D_VEC *x, DOF_REAL_D_VEC *y);
extern void dof_copy_d(const DOF_REAL_D_VEC *x, DOF_REAL_D_VEC *y);
extern REAL dof_dot_d(const DOF_REAL_D_VEC *x, const DOF_REAL_D_VEC *y);
extern REAL dof_nrm2_d(const DOF_REAL_D_VEC *x);
extern void dof_scal_d(REAL alpha, DOF_REAL_D_VEC *x);
extern void dof_set_d(REAL alpha, DOF_REAL_D_VEC *x);
extern void dof_xpay_d(REAL alpha, const DOF_REAL_D_VEC *x, DOF_REAL_D_VEC *y);
extern REAL dof_min_d(const DOF_REAL_D_VEC *x);
extern REAL dof_max_d(const DOF_REAL_D_VEC *x);
/*---    BLAS 2 for REAL_D                                               ---*/
extern void dof_mv_d(MatrixTranspose transpose, const DOF_MATRIX *a,
		     const DOF_REAL_D_VEC *x, DOF_REAL_D_VEC *y);
extern void dof_mv_dowb(MatrixTranspose transpose, const DOF_DOWB_MATRIX *a,
			const DOF_REAL_D_VEC *x, DOF_REAL_D_VEC *y);
extern void dof_gemv_d(MatrixTranspose transpose, REAL alpha,
		       const DOF_MATRIX *a, const DOF_REAL_D_VEC *x,
		       REAL beta, DOF_REAL_D_VEC *y);
extern void dof_gemv_dowb(MatrixTranspose transpose, REAL alpha,
			  const DOF_DOWB_MATRIX *a, const DOF_REAL_D_VEC *x,
			  REAL beta, DOF_REAL_D_VEC *y);

void update_matrix(DOF_MATRIX *dof_matrix, const EL_MATRIX_INFO *minfo);
void update_dowb_matrix(DOF_DOWB_MATRIX *dof_matrix,
			const EL_DOWB_MATRIX_INFO *minfo);
void update_real_vec(DOF_REAL_VEC *drv, const EL_VEC_INFO *vec_info);
void update_real_d_vec(DOF_REAL_D_VEC *drdv, const EL_VEC_D_INFO *vecd_info);

/***   file wall_quad_fast.c   *********************************************/

extern const WALL_QUAD_FAST *get_wall_quad_fast(const BAS_FCTS *, 
						const QUAD *, 
						U_CHAR init_flag);

/***   file macro.c   *******************************************************/
extern void macro_test(MACRO_DATA *data, const char *new_filename);

extern MACRO_DATA *read_macro(const char *name);
extern MACRO_DATA *read_macro_bin(const char *name);
extern MACRO_DATA *read_macro_xdr(const char *name);

extern int write_macro(MESH *mesh, const char *name);
extern int write_macro_bin(MESH *mesh, const char *name);
extern int write_macro_xdr(MESH *mesh, const char *name);

extern int write_macro_data(MACRO_DATA *data, const char *name);
extern int write_macro_data_bin(MACRO_DATA *data, const char *name);
extern int write_macro_data_xdr(MACRO_DATA *data, const char *name);

extern MACRO_DATA *alloc_macro_data(int dim, int nv, int ne, FLAGS);
extern void free_macro_data(MACRO_DATA *data);
extern void compute_neigh_fast(MACRO_DATA *data);
extern void dirichlet_boundary(MACRO_DATA *data);

extern MACRO_DATA *mesh2macro_data(MESH *mesh);
extern void macro_data2mesh(MESH *mesh, const MACRO_DATA *data,
			    NODE_PROJECTION *(*n_proj)(MESH *,MACRO_EL *,int));


/***   file memory.c   ******************************************************/
extern MESH *check_and_get_mesh(int dim, int dow, int neigh,
				const char *version, const char *name,
				const MACRO_DATA *macro_data,
				NODE_PROJECTION *(*init_node_proj)
				(MESH *, MACRO_EL *, int));
extern void add_traverse_hook(MESH *mesh,
			      TRAVERSE_HOOK *hook,
			      HOOK_QUEUE_ENUM queue);
extern void remove_traverse_hook(MESH *mesh,
				 TRAVERSE_HOOK *hook,
				 HOOK_QUEUE_ENUM queue);
extern void free_dof_admin(DOF_ADMIN *admin, MESH *mesh);
extern void free_int_dof_vec(DOF_DOF_VEC *vec);
extern void free_dof_int_vec(DOF_INT_VEC *vec);
extern void free_dof_dof_vec(DOF_DOF_VEC *vec);
extern void free_dof_matrix(DOF_MATRIX *mat);
extern void free_dof_dowb_matrix(DOF_DOWB_MATRIX *mat);
extern void free_dof_real_vec(DOF_REAL_VEC *vec);
extern void free_dof_real_d_vec(DOF_REAL_D_VEC *vec);
extern void free_dof_schar_vec(DOF_SCHAR_VEC *vec);
extern void free_dof_uchar_vec(DOF_UCHAR_VEC *vec);
extern void free_dof_ptr_vec(DOF_PTR_VEC *vec);
extern void free_fe_space(FE_SPACE *fe_space);
extern void free_real_d(MESH *mesh, REAL *ptr);
extern void free_matrix_row(const FE_SPACE *, MATRIX_ROW *);
extern void free_dowb_matrix_row(const FE_SPACE *, DOWBM_TYPE type, 
				 DOWB_MATRIX_ROW *);
extern void free_element(EL *el, MESH *mesh);
extern void free_rc_list(MESH *mesh, RC_LIST_EL *list); /* only for 3D */
extern void free_mesh(MESH *);
extern void free_dof(DOF *dof, MESH *mesh, int position,
		     const int is_coarse_dof);

extern DOF             *get_dof(MESH *mesh, int position);
extern const FE_SPACE  *get_fe_space(MESH *mesh, const char *name,
				     const int ndof[N_NODE_TYPES],
				     const BAS_FCTS *bas_fcts,
				     const U_CHAR preserve_coarse_dofs);
extern DOF_INT_VEC     *get_dof_int_vec(const char *name, const FE_SPACE *);
extern DOF_DOF_VEC     *get_int_dof_vec(const char *name, const FE_SPACE *);
extern DOF_DOF_VEC     *get_dof_dof_vec(const char *name, const FE_SPACE *);
extern DOF_MATRIX      *get_dof_matrix(const char *name, 
				       const FE_SPACE *row_fe_space,
				       const FE_SPACE *col_fe_space);
extern DOF_DOWB_MATRIX *get_dof_dowb_matrix(const char *name, 
					    const FE_SPACE *row_fe_space,
					    const FE_SPACE *col_fe_space,
					    DOWBM_TYPE type);
extern DOF_REAL_VEC    *get_dof_real_vec(const char *name, const FE_SPACE *);
extern DOF_REAL_D_VEC  *get_dof_real_d_vec(const char *name, const FE_SPACE *);
extern DOF_SCHAR_VEC   *get_dof_schar_vec(const char *name, const FE_SPACE *);
extern DOF_UCHAR_VEC   *get_dof_uchar_vec(const char *name, const FE_SPACE *);
extern DOF_PTR_VEC     *get_dof_ptr_vec(const char *name, const FE_SPACE *);
extern REAL            *get_real_d(MESH *mesh);
extern MATRIX_ROW      *get_matrix_row(const FE_SPACE *);
extern DOWB_MATRIX_ROW *get_dowb_matrix_row(const FE_SPACE *, DOWBM_TYPE type);
extern EL              *get_element(MESH *mesh);
extern RC_LIST_EL      *get_rc_list(MESH *mesh);           /* only for 3D */
extern size_t init_leaf_data(MESH *mesh, size_t size, 
		     void (*refine_leaf_data)(EL *parent, EL *child[2]),
		     void (*coarsen_leaf_data)(EL *parent, EL *child[2]));

/***   file submesh.c  ******************************************************/
extern MESH *get_submesh(MESH *master, const char *name,
			 int (*binding_method)(MESH *master, MACRO_EL *el,
					       int face, void *data),
			 void *data);

extern void unchain_submesh(MESH *slave);

extern MESH *read_submesh(MESH *master,
			  const char *slave_filename,
			  int (*binding_method)(MESH *master, MACRO_EL *el,
						int face, void *data),
			  NODE_PROJECTION *(*)(MESH *, MACRO_EL *, int),
			  void *data);

extern MESH *read_submesh_xdr(MESH *master,
			      const char *slave_filename,
			      int (*binding_method)(MESH *master, MACRO_EL *el,
						    int face, void *data),
			      NODE_PROJECTION *(*)(MESH *, MACRO_EL *, int),
			      void *data);

extern void trace_dof_real_vec(DOF_REAL_VEC *slave_vec,
			       DOF_REAL_VEC *master_vec);

extern void trace_dof_real_d_vec(DOF_REAL_D_VEC *slave_vec,
				 DOF_REAL_D_VEC *master_vec);

extern void get_slave_dof_mapping(const FE_SPACE *m_fe_space,
				  DOF_INT_VEC *s_map);

extern MESH *get_master(MESH *slave);
extern DOF_PTR_VEC *get_master_binding(MESH *slave);
extern DOF_PTR_VEC *get_slave_binding(MESH *slave);

/***   file level.c    ******************************************************/
extern REAL level_element_det_2d(const REAL_D coord[]);
extern void level_coord_to_world_2d(const REAL_D coord[],
				    const REAL_B lambda,
				    REAL_D world);
extern void level_coord_to_el_coord_2d(const REAL_B v_lambda[],
				       const REAL_B lambda,
				       REAL_B el_lambda);
extern REAL level_element_det_3d(const REAL_D coord[]);
extern void level_coord_to_world_3d(const REAL_D coord[],
				    const REAL_B lambda,
				    REAL_D world);
extern void level_coord_to_el_coord_3d(const REAL_B v_lambda[],
				       const REAL_B lambda,
				       REAL_B el_lambda);

extern int find_level(MESH *mesh, FLAGS fill_flag, const DOF_REAL_VEC *Level,
		      REAL value,
		      int (*init)(const EL_INFO *el_info,
				  REAL v[], 
				  int N, int face, const REAL_B lambda[]),
		      void (*cal)(const EL_INFO *el_info,
				  REAL v[],
				  int i, 
				  int face, const REAL_B lambda[], 
				  const REAL_D coord[]));
extern void set_element_mark(MESH *mesh, FLAGS fill_flag, S_CHAR mark);

/***   file numint.c   ******************************************************/
const QUAD *get_quadrature(int dim, int degree);
const QUAD *get_lumping_quadrature(int dim);
void print_quadrature(const QUAD *quad);
REAL  integrate_std_simp(const QUAD *quad, REAL (*f)(const REAL *));
const REAL   *f_at_qp(const QUAD*, REAL (*f)(const REAL [N_LAMBDA]), REAL*);
int   max_quad_points(void);
const REAL_D *f_d_at_qp(const QUAD *quad,
			const REAL *(*f)(const REAL[N_LAMBDA]),
			REAL_D *vec);
const REAL_D *grd_f_at_qp(const QUAD *,
			  const REAL *(*)(const REAL [N_LAMBDA]), 
			  REAL_D *);
const REAL_DD *grd_f_d_at_qp(const QUAD *, 
			     const REAL_D *(*)(const REAL [N_LAMBDA]),
			     REAL_DD *);
const QUAD_FAST *get_quad_fast(const BAS_FCTS *, const QUAD *, 
				      U_CHAR init_flag);

/***   file refine.c   ******************************************************/
extern U_CHAR refine(MESH *mesh);
extern U_CHAR global_refine(MESH *mesh, int mark);

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

/***   file adapt.c   *******************************************************/
extern void adapt_method_stat(MESH *mesh, ADAPT_STAT *adapt);
extern void adapt_method_instat(MESH *mesh, ADAPT_INSTAT *adapt);
extern int marking(MESH *mesh, ADAPT_STAT *adapt);
extern ADAPT_INSTAT *get_adapt_instat(const int dim, const char *name,
				      const char *prefix,
				      int info, ADAPT_INSTAT *adapt_instat);
extern ADAPT_STAT *get_adapt_stat(const int dim, const char *name,
				  const char *prefix,
				  int info, ADAPT_STAT *adapt_stat);

/***   file assemble.c   ****************************************************/
const EL_MATRIX_INFO *fill_matrix_info(const OPERATOR_INFO *, 
				       EL_MATRIX_INFO *);
const Q00_PSI_PHI *get_q00_psi_phi(const BAS_FCTS *psi, const BAS_FCTS *phi,
				   const QUAD *quad);
const Q01_PSI_PHI *get_q01_psi_phi(const BAS_FCTS *psi, const BAS_FCTS *phi,
				   const QUAD *quad);
const Q10_PSI_PHI *get_q10_psi_phi(const BAS_FCTS *psi, const BAS_FCTS *phi,
				   const QUAD *quad);
const Q11_PSI_PHI *get_q11_psi_phi(const BAS_FCTS *psi, const BAS_FCTS *phi,
				   const QUAD *quad);

/***   file assemble_dowb.c  ************************************************/
const EL_DOWB_MATRIX_INFO *
fill_dowb_matrix_info(const DOWB_OPERATOR_INFO *operator_info, 
		      EL_DOWB_MATRIX_INFO *matrix_info);

/***   file bas_fct.c   *****************************************************/
extern const BAS_FCTS *get_bas_fcts(const char *name);
extern const BAS_FCTS *get_discontinuous_lagrange(int dim, int degree);
extern const BAS_FCTS *get_lagrange(int dim, int degree);
extern int new_bas_fcts(const BAS_FCTS * bas_fcts);

/***   file check.c   *******************************************************/
extern void check_mesh(MESH *mesh);

/***   file dof_admin.c   ***************************************************/
extern void free_dof_index(DOF_ADMIN *admin, int dof);
extern int  get_dof_index(DOF_ADMIN *admin);
extern void enlarge_dof_lists(DOF_ADMIN *admin, int minsize);
extern void update_dof_matrix(DOF_MATRIX *, REAL, int, const REAL **, 
			      const DOF *, const S_CHAR *);
extern void update_dof_dowb_matrix(DOF_DOWB_MATRIX *, REAL, int,
				   const void **, 
				   const DOF *, const S_CHAR *);
extern void update_dof_real_vec(DOF_REAL_VEC *, REAL, int, const REAL *,
				const DOF *, const S_CHAR *);
extern void update_dof_real_d_vec(DOF_REAL_D_VEC *, REAL, int, const REAL_D *,
				  const DOF *, const S_CHAR *);
extern void test_dof_matrix(DOF_MATRIX *matrix);
extern void test_dof_dowb_matrix(DOF_DOWB_MATRIX *matrix);

/***   file element.c   ***************************************************/
/* These routines are partially available as _?d-versions to avoid looking*/
/* up the dimension. This should be a small efficiency bonus.             */

extern int *sorted_wall_indices(const int dim, int face, int permno);
extern int wall_orientation(int dim, const EL *el, int face, int **vecp);
extern int *sort_wall_indices(const int dim,
				    const EL *el, int face, int *vec);

/* Dimension dependent routines, 0d, just dummies in most cases. */
extern int *sorted_wall_indices_0d(int face, int permno);
extern int wall_orientation_0d(const EL *el, int face, int **vec);
extern int *sort_wall_indices_0d(const EL *el, int face, int *vec);
extern int world_to_coord_0d(const EL_INFO *el_info, const REAL *,
			     REAL_B);
extern const REAL *coord_to_world_0d(const EL_INFO *, const REAL *, REAL_D);
extern REAL el_det_0d(const EL_INFO *);
extern REAL el_volume_0d(const EL_INFO *el_info);
extern REAL el_grd_lambda_0d(const EL_INFO *el_info,
			     REAL grd_lam[N_LAMBDA][DIM_OF_WORLD]);
extern REAL get_wall_normal_0d(const EL_INFO *, int , REAL *);

/* Dimension dependent routines, 1d */
extern int *sorted_wall_indices_1d(int face, int permno);
extern int wall_orientation_1d(const EL *el, int face, int **vec);
extern int *sort_wall_indices_1d(const EL *el, int face, int *vec);
extern int world_to_coord_1d(const EL_INFO *el_info, const REAL *,
			     REAL_B);
extern const REAL *coord_to_world_1d(const EL_INFO *, const REAL *, REAL_D);
extern REAL el_det_1d(const EL_INFO *);
extern REAL el_volume_1d(const EL_INFO *el_info);
extern REAL el_grd_lambda_1d(const EL_INFO *,
			     REAL grd_lam[N_LAMBDA][DIM_OF_WORLD]);
extern REAL get_wall_normal_1d(const EL_INFO *, int , REAL *);

#if DIM_OF_WORLD > 1
/* Dimension dependent routines, 2d */
extern int *sorted_wall_indices_2d(int face, int permno);
extern int wall_orientation_2d(const EL *el, int face, int **vec);
extern int *sort_wall_indices_2d(const EL *el, int face, int *vec);
extern int world_to_coord_2d(const EL_INFO *el_info, const REAL *,
			     REAL_B);
extern const REAL *coord_to_world_2d(const EL_INFO *, const REAL *, REAL_D);
extern REAL el_det_2d(const EL_INFO *);
extern REAL el_volume_2d(const EL_INFO *el_info);
extern REAL el_grd_lambda_2d(const EL_INFO *,
			     REAL grd_lam[N_LAMBDA][DIM_OF_WORLD]);
extern REAL get_wall_normal_2d(const EL_INFO *, int , REAL *);

#if DIM_OF_WORLD > 2
/* Dimension dependent routines, 3d */
extern int *sorted_wall_indices_3d(int face, int permno);
extern int wall_orientation_3d(const EL *el, int face, int **vec);
extern int *sort_wall_indices_3d(const EL *el, int face, int *vec);
extern int world_to_coord_3d(const EL_INFO *el_info, const REAL *,
			     REAL_B);
extern const REAL *coord_to_world_3d(const EL_INFO *, const REAL *, REAL_D);
extern REAL el_det_3d(const EL_INFO *);
extern REAL el_volume_3d(const EL_INFO *el_info);
extern REAL el_grd_lambda_3d(const EL_INFO *,
			     REAL grd_lam[N_LAMBDA][DIM_OF_WORLD]);
extern REAL get_wall_normal_3d(const EL_INFO *, int , REAL *);
#endif
#endif

/* Below we provide wrapper functions which distinguish the dimension
 * dependent routines by the co-dimension rather than by the dimension
 * of the underlying mesh. We start by defining a preprocessor macro
 * which spares us some typing and especially typos.
 *
 * In addition, we provide wrapper functions which decide by looking
 * at el_info->mesh->dim what to do.
 *
 */
#if DIM_OF_WORLD == 1

# define ALBERTA_CODIM_WRAPPER(ret, name, argtypes, argnames)	\
static inline ret name argtypes					\
{								\
  FUNCNAME(#name);						\
  								\
  switch (el_info->mesh->dim) {					\
  case 0: return name##_0d argnames;				\
  case 1: return name##_1d argnames;				\
  default:							\
    ERROR_EXIT("Illegal dim!\n");				\
    return (ret)0; /* just to make the compiler happy */	\
  }								\
}

# define ALBERTA_CODIM_ALIAS(ret, name, argtypes, argnames)		\
static inline ret name##_0cd argtypes { return name##_1d argnames; }	\
static inline ret name##_1cd argtypes { return name##_0d argnames; }

/* Variants which start at DOW == 2 and thus are empty here */
# define ALBERTA_CODIM_ALIAS_2(ret, name, argtypes, argnames)
# define ALBERTA_VOID_CODIM_ALIAS_2(name, argtypes, argnames)

#elif DIM_OF_WORLD == 2

# define ALBERTA_CODIM_WRAPPER(ret, name, argtypes, argnames)	\
static inline ret name argtypes					\
{								\
  FUNCNAME(#name);						\
								\
  switch (el_info->mesh->dim) {					\
  case 0: return name##_0d argnames;				\
  case 1: return name##_1d argnames;				\
  case 2: return name##_2d argnames;				\
  default:							\
    ERROR_EXIT("Illegal dim!\n");				\
    return (ret)0; /* just to make the compiler happy ... */	\
  }								\
}

# define ALBERTA_CODIM_ALIAS(ret, name, argtypes, argnames)		\
static inline ret name##_0cd argtypes { return name##_2d argnames; }	\
static inline ret name##_1cd argtypes { return name##_1d argnames; }	\
static inline ret name##_2cd argtypes { return name##_0d argnames; }

/* Variants which start at DOW == 2 */
# define ALBERTA_CODIM_ALIAS_2(ret, name, argtypes, argnames)		\
static inline ret name##_0cd argtypes { return name##_2d argnames; }
# define ALBERTA_VOID_CODIM_ALIAS_2(name, argtypes, argnames)		\
static inline void name##_0cd argtypes { name##_2d argnames; }

#elif DIM_OF_WORLD == 3

# define ALBERTA_CODIM_WRAPPER(ret, name, argtypes, argnames)	\
static inline ret name argtypes					\
{								\
  FUNCNAME(#name);						\
  								\
  switch (el_info->mesh->dim) {					\
  case 0: return name##_0d argnames;				\
  case 1: return name##_1d argnames;				\
  case 2: return name##_2d argnames;				\
  case 3: return name##_3d argnames;				\
  default:							\
    ERROR_EXIT("Illegal dim!\n");				\
    return (ret)0; /* just to make the compiler happy ... */	\
  }								\
}

# define ALBERTA_CODIM_ALIAS(ret, name, argtypes, argnames)		\
static inline ret name##_0cd argtypes { return name##_3d argnames; }	\
static inline ret name##_1cd argtypes { return name##_2d argnames; }	\
static inline ret name##_2cd argtypes { return name##_1d argnames; }	\
static inline ret name##_3cd argtypes { return name##_0d argnames; }

/* Variants which start at DOW == 2 */
# define ALBERTA_CODIM_ALIAS_2(ret, name, argtypes, argnames)		\
static inline ret name##_0cd argtypes { return name##_3d argnames; }	\
static inline ret name##_1cd argtypes { return name##_2d argnames; }
# define ALBERTA_VOID_CODIM_ALIAS_2(name, argtypes, argnames)	\
static inline void name##_0cd argtypes { name##_3d argnames; }	\
static inline void name##_1cd argtypes { name##_2d argnames; }

#else
# error Unsupported DIM_OF_WORLD
#endif

/* ..._Xcd() alias definitions */
ALBERTA_CODIM_ALIAS(int, world_to_coord,
		    (const EL_INFO *el_info,
		     const REAL *xy,
		     REAL_B lambda),
		    (el_info, xy, lambda))
ALBERTA_CODIM_ALIAS(const REAL *, coord_to_world,
		    (const EL_INFO *el_info, const REAL *l, REAL_D w),
		    (el_info, l, w))
ALBERTA_CODIM_ALIAS(REAL, el_volume, (const EL_INFO *el_info), (el_info))
ALBERTA_CODIM_ALIAS(REAL, el_det, (const EL_INFO *el_info), (el_info))
ALBERTA_CODIM_ALIAS(REAL, el_grd_lambda,
		    (const EL_INFO *el_info,
		     REAL grd_lam[N_LAMBDA][DIM_OF_WORLD]),
		    (el_info, grd_lam))
ALBERTA_CODIM_ALIAS(REAL, get_wall_normal,
		    (const EL_INFO *el_info, int i0, REAL *normal),
		    (el_info, i0, normal))
ALBERTA_CODIM_ALIAS(int *, sorted_wall_indices,
		    (int face, int permno),
		    (face, permno))
ALBERTA_CODIM_ALIAS(int, wall_orientation,
		    (const EL *el, int face, int **vecp),
		    (el, face, vecp))
ALBERTA_CODIM_ALIAS(int *, sort_wall_indices,
		    (const EL *el, int face, int *vec),
		    (el, face, vec))

/* Wrappers which look at el_info->mesh->dim */
ALBERTA_CODIM_WRAPPER(int, world_to_coord,
		      (const EL_INFO *el_info, const REAL *x, REAL_B lambda),
		      (el_info, x, lambda))
ALBERTA_CODIM_WRAPPER(const REAL *, coord_to_world,
		      (const EL_INFO *el_info, const REAL *lambda, REAL_D x),
		      (el_info, lambda, x))
ALBERTA_CODIM_WRAPPER(REAL, el_volume, (const EL_INFO *el_info), (el_info))
ALBERTA_CODIM_WRAPPER(REAL, el_det, (const EL_INFO *el_info), (el_info))
ALBERTA_CODIM_WRAPPER(REAL, el_grd_lambda,
		      (const EL_INFO *el_info,
		       REAL grd_lam[N_LAMBDA][DIM_OF_WORLD]),
		      (el_info, grd_lam))
ALBERTA_CODIM_WRAPPER(REAL, get_wall_normal,
		      (const EL_INFO *el_info, int i0, REAL *normal),
		      (el_info, i0, normal))

/* Some special wrapper functions, used for some stuff defined in
 * level.c 
 */
ALBERTA_CODIM_ALIAS_2(REAL, level_element_det, (const REAL_D coord[]), (coord))
ALBERTA_VOID_CODIM_ALIAS_2(level_coord_to_world,
			   (const REAL_D coord[],
			    const REAL_B lambda,
			    REAL_D world),
			   (coord, lambda, world))
ALBERTA_VOID_CODIM_ALIAS_2(level_coord_to_el_coord,
			   (const REAL_B v_lambda[],
			    const REAL_B lambda,
			    REAL_B el_lambda),
			   (v_lambda, lambda, el_lambda))

/***   file estimator.c   **************************************************/
#define INIT_UH 1
#define INIT_GRD_UH 2
REAL ellipt_est(const DOF_REAL_VEC *uh, ADAPT_STAT *adapt,
		REAL *(*rw_est)(EL *), REAL *(*rw_estc)(EL *),
                int degree, int norm, REAL C[3], const REAL_DD A,
                REAL (*f)(const EL_INFO *,const QUAD *,int,REAL,const REAL_D),
		FLAGS f_flag);
REAL heat_est(const DOF_REAL_VEC *uh, ADAPT_INSTAT *adapt,
	      REAL *(*rw_est)(EL *), REAL *(*rw_estc)(EL *),
	      int degree, REAL C[4], 
	      const DOF_REAL_VEC *uh_old, const REAL_DD A,
	      REAL (*f)(const EL_INFO *, const QUAD *, int iq, REAL t,
			REAL u, const REAL_D grd_u),
	      FLAGS f_flag);
/***   file estimator_dowb.c ************************************************/
REAL ellipt_est_d(const DOF_REAL_D_VEC *uh, ADAPT_STAT *adapt,
		  REAL *(*rw_est)(EL *), REAL *(*rw_estc)(EL *),
		  int degree, int norm, REAL C[3],
		  const REAL_DD A[DIM_OF_WORLD][DIM_OF_WORLD],
		  const REAL *(*f)(const EL_INFO *,
				   const QUAD *, int qp,
				   const REAL_D uh, const REAL_DD grd_uh,
                                   REAL_D res),
		  FLAGS f_flag);
REAL heat_est_d(const DOF_REAL_D_VEC *uh, ADAPT_INSTAT *adapt,
		REAL *(*rw_est)(EL *), REAL *(*rw_estc)(EL *),
		int degree, REAL C[4], 
		const DOF_REAL_D_VEC *uh_old,
		const REAL_DD A[DIM_OF_WORLD][DIM_OF_WORLD],
		const REAL *(*f)(const EL_INFO *, const QUAD *, int iq, REAL t,
				 const REAL_D u, const REAL_DD grd_u,
				 REAL_D res),
		FLAGS f_flag);
/***   file error.c   *******************************************************/
REAL max_err_at_qp(REAL (*)(const REAL_D), const DOF_REAL_VEC *, const QUAD *);
REAL max_err_d_at_qp(const REAL *(*)(const REAL_D, REAL_D), 
		     const DOF_REAL_D_VEC *, const QUAD *);
REAL max_err_at_vert(REAL (*)(const REAL_D), const DOF_REAL_VEC *);
REAL L2_err(REAL (*)(const REAL_D), const DOF_REAL_VEC *, const QUAD *, int, 
	     REAL *(*)(EL *), REAL *);
REAL H1_err(const REAL *(*)(const REAL_D, REAL_D), const DOF_REAL_VEC *, 
	     const QUAD *, int, REAL *(*)(EL *), REAL *);
REAL H1_err_d(const REAL_D *(*grd_u)(const REAL_D, REAL_DD),
	       const DOF_REAL_D_VEC *uh, const QUAD *quad, int rel_err,
	       REAL *(*rw_err_el)(EL *), REAL *max_h1_err2);
REAL L2_err_d(const REAL *(*)(const REAL_D, REAL_D), const DOF_REAL_D_VEC *,
	       const QUAD *, int, REAL *(*)(EL *), REAL *);

/***   file eval.c   ********************************************************/
REAL eval_uh(const REAL_B lambda, const REAL *uh_loc, const BAS_FCTS *b);
REAL eval_uh_fast(const REAL *uh_loc, const REAL *phi_val, int n_bfcts);
const REAL *eval_grd_uh(const REAL [N_LAMBDA], const REAL_D [N_LAMBDA],
			const REAL *, const BAS_FCTS *, REAL_D);
const REAL *eval_grd_uh_fast(const REAL_D [N_LAMBDA], const REAL *,
			     const REAL (*)[N_LAMBDA], int , REAL_D);
const REAL_D *eval_D2_uh(const REAL [N_LAMBDA], const REAL_D [N_LAMBDA],
			 const REAL *, const BAS_FCTS *, REAL_DD);
const REAL_D *eval_D2_uh_fast(const REAL_D [N_LAMBDA], const REAL *, 
			      const REAL (*)[N_LAMBDA][N_LAMBDA],
			      int, REAL_DD);

const REAL *eval_uh_d(const REAL [N_LAMBDA], const REAL_D *, const BAS_FCTS *,
		      REAL_D);
const REAL *eval_uh_d_fast(const REAL_D *, const REAL *, int, REAL_D);
const REAL_D *eval_grd_uh_d(const REAL [N_LAMBDA], const REAL_D [N_LAMBDA],
			     const REAL_D *, const BAS_FCTS *, REAL_DD);
const REAL_D *eval_grd_uh_d_fast(const REAL_D [N_LAMBDA], const REAL_D *, 
				 const REAL (*)[N_LAMBDA], int, REAL_DD);
const REAL_DD *eval_D2_uh_d(const REAL [N_LAMBDA], const REAL_D [N_LAMBDA],
			    const REAL_D *, const BAS_FCTS *, REAL_DD *);
const REAL_DD *eval_D2_uh_d_fast(const REAL_D [N_LAMBDA], const REAL_D *, 
				 const REAL (*)[N_LAMBDA][N_LAMBDA], int, 
				 REAL_DD *);

const REAL *uh_at_qp(const QUAD_FAST *, const REAL *uh_loc, REAL *vec);
const REAL_D *grd_uh_at_qp(const QUAD_FAST *,
			   const REAL_D grd_lambda[N_LAMBDA],
			   const REAL *uh_loc, REAL_D *vec);
const REAL_D *param_grd_uh_at_qp(const QUAD_FAST *fast,
				 REAL_D Lambda[][N_LAMBDA],
				 const REAL *uh_loc, REAL_D *vec);
const REAL_DD *D2_uh_at_qp(const QUAD_FAST *, const REAL_D [N_LAMBDA],
			   const REAL *, REAL_DD *);
const REAL_D *uh_d_at_qp(const QUAD_FAST *fast, const REAL_D *uh_loc,
			 REAL_D *vec);
const REAL_DD *grd_uh_d_at_qp(const QUAD_FAST *fast,
			      const REAL_D grd_lambda[N_LAMBDA], 
			      const REAL_D *uh_loc, REAL_DD *vec);
const REAL_DD *param_grd_uh_d_at_qp(const QUAD_FAST *fast,
				    REAL_D Lambda[][N_LAMBDA], 
				    const REAL_D *uh_loc, REAL_DD *vec);
const REAL_DD (*D2_uh_d_at_qp(const QUAD_FAST *, const REAL_D [N_LAMBDA],
			      const REAL_D *, 
			      REAL_DD (*)[DIM_OF_WORLD]))[DIM_OF_WORLD];
REAL eval_div_uh_d(const REAL lambda[N_LAMBDA],
		   const REAL_D grd_lambda[N_LAMBDA],
		   const REAL_D *uh_loc, const BAS_FCTS *b);
REAL eval_div_uh_d_fast(const REAL_D grd_lambda[N_LAMBDA],
			const REAL_D *uh_loc, 
			const REAL (*grd_phi)[N_LAMBDA], int n_bas_fcts);
const REAL *div_uh_d_at_qp(const QUAD_FAST *fast,
			   const REAL_D Lambda[N_LAMBDA], 
			   const REAL_D *uh_loc, REAL *vec);
const REAL *param_div_uh_d_at_qp(const QUAD_FAST *fast,
				 const REAL_D Lambda[][N_LAMBDA], 
				 const REAL_D *uh_loc, REAL *vec);
const REAL_DD *param_D2_uh_at_qp(const QUAD_FAST *fast,
				 const REAL_D Lambda[][N_LAMBDA],
				 const REAL *uh_loc, REAL_DD *vec);
const REAL_DD (*param_D2_uh_d_at_qp(const QUAD_FAST *fast,
				    const REAL_D grd_lam[][N_LAMBDA],
				    const REAL_D *uh_loc, 
			    REAL_DD (*vec)[DIM_OF_WORLD]))[DIM_OF_WORLD];
REAL H1_norm_uh(const QUAD *quad, const DOF_REAL_VEC *u_h);
REAL L2_norm_uh(const QUAD *quad, const DOF_REAL_VEC *u_h);
REAL H1_norm_uh_d(const QUAD *quad, const DOF_REAL_D_VEC *u_h);
REAL L2_norm_uh_d(const QUAD *quad, const DOF_REAL_D_VEC *u_h);
extern void interpol(REAL (*fct)(const REAL_D), DOF_REAL_VEC *);
extern void interpol_d(const REAL *(*)(const REAL_D, REAL_D), 
		       DOF_REAL_D_VEC *);

/***   file graphXO.c   ******************************************************/
GRAPH_WINDOW graph_open_window(const char *title, const char *geometry,
			       REAL *world, MESH *mesh);
void graph_close_window(GRAPH_WINDOW win);
void graph_clear_window(GRAPH_WINDOW win, const GRAPH_RGBCOLOR c);

void graph_mesh(GRAPH_WINDOW win, MESH *mesh, const GRAPH_RGBCOLOR c,
		FLAGS flag);
void graph_drv(GRAPH_WINDOW win, const DOF_REAL_VEC *uh,
	       REAL min, REAL max, int refine);
void graph_drv_d(GRAPH_WINDOW win, const DOF_REAL_D_VEC *uh,
		 REAL min, REAL max, int refine);
void graph_el_est(GRAPH_WINDOW win, MESH *mesh, REAL (*get_el_est)(EL *el),
		  REAL min, REAL max);

void graph_point(GRAPH_WINDOW, const REAL [2], const GRAPH_RGBCOLOR, float);
void graph_points(GRAPH_WINDOW win, int np, REAL (*p)[2], 
		  const GRAPH_RGBCOLOR c, float ps);
void graph_line(GRAPH_WINDOW, const REAL [2], const REAL [2], 
		const GRAPH_RGBCOLOR, float);

void graph_fvalues_2d(GRAPH_WINDOW win, MESH *mesh,
		      REAL(*fct)(const EL_INFO *el_info, const REAL *lambda),
		      FLAGS flags, REAL min, REAL max, int refine);
void graph_level_2d(GRAPH_WINDOW win, const DOF_REAL_VEC *v, REAL level,
		    const GRAPH_RGBCOLOR c, int refine);
void graph_levels_2d(GRAPH_WINDOW win, const DOF_REAL_VEC *v,
		     int n, REAL const *levels, const GRAPH_RGBCOLOR *color,
		     int refine);
void graph_level_d_2d(GRAPH_WINDOW, const DOF_REAL_D_VEC *,
		      REAL, const GRAPH_RGBCOLOR, int);
void graph_levels_d_2d(GRAPH_WINDOW, const DOF_REAL_D_VEC *,
		       int, const REAL *, const GRAPH_RGBCOLOR *, int);

/* multigrid level display routines:  */
void graph_mesh_mg_2d(GRAPH_WINDOW win, MESH *mesh, const GRAPH_RGBCOLOR c,
		      FLAGS flags, int mg_level);
void graph_values_mg_2d(GRAPH_WINDOW win, const DOF_REAL_VEC *v, 
			REAL min, REAL max, int refine,
			int mg_level, const FE_SPACE *fe_space,
			const int *sort_dof_invers);

/***   file l2scp.c   *******************************************************/
void dirichlet_bound(REAL (*)(const REAL_D), DOF_REAL_VEC *, DOF_REAL_VEC *,
		     DOF_SCHAR_VEC *);
void L2scp_fct_bas(REAL (*f)(const REAL_D), const QUAD *, DOF_REAL_VEC *fh);

void dirichlet_bound_d(const REAL *(*)(const REAL_D, REAL_D),
		       DOF_REAL_D_VEC *, DOF_REAL_D_VEC *, DOF_SCHAR_VEC *);
void L2scp_fct_bas_d(const REAL *(*f)(const REAL_D, REAL_D), const QUAD *,
		     DOF_REAL_D_VEC *fhd);

/*---  file oem_solve_s.c  -------------------------------------------------*/
int oem_solve_s(const DOF_MATRIX *A, const DOF_REAL_VEC *f, 
		DOF_REAL_VEC *u,  OEM_SOLVER, REAL, int, int, int, int);
int mat_vec_s(void *ud, int dim, const REAL *x, REAL *y);
void *init_mat_vec_s(MatrixTranspose,
		     const DOF_MATRIX *, const DOF_SCHAR_VEC *);
void exit_mat_vec_s(void *);

/*---  file oem_solve_d.c  -------------------------------------------------*/
int oem_solve_d(const DOF_MATRIX *A, const DOF_REAL_D_VEC *f, 
		DOF_REAL_D_VEC *u,  OEM_SOLVER, REAL, int, int, int, int);
int mat_vec_d(void *ud, int dim, const REAL *x, REAL *y);
void *init_mat_vec_d(MatrixTranspose, const DOF_MATRIX *,
		     const DOF_SCHAR_VEC *);
void exit_mat_vec_d(void *);

/*---  file oem_solve_dowb.c  ----------------------------------------------*/
int oem_solve_dowb(const DOF_DOWB_MATRIX *A, const DOF_REAL_D_VEC *f, 
		   DOF_REAL_D_VEC *u,  OEM_SOLVER, REAL, int, int, int, int);
int mat_vec_dowb(void *ud, int dim, const REAL *x, REAL *y);
void *init_mat_vec_dowb(MatrixTranspose, const DOF_DOWB_MATRIX *,
			const DOF_SCHAR_VEC *);
void exit_mat_vec_dowb(void *);

/*---  file parametric.c  --------------------------------------------------*/
void use_lagrange_parametric(MESH *mesh, int degree,
			     NODE_PROJECTION *n_proj, int strategy);
DOF_REAL_D_VEC *get_lagrange_coords(MESH *mesh);
DOF_UCHAR_VEC *get_lagrange_coord_flags(MESH *mesh);

/*--  file sor.c  ----------------------------------------------------------*/
int sor_dowb(DOF_DOWB_MATRIX *a, const DOF_REAL_D_VEC *f,
	     const DOF_SCHAR_VEC *b,
	     DOF_REAL_D_VEC *u, REAL omega, REAL tol, int max_iter, int info);
int sor_d(DOF_MATRIX *a, const DOF_REAL_D_VEC *f, const DOF_SCHAR_VEC *b,
	  DOF_REAL_D_VEC *u, REAL omega, REAL tol, int max_iter, int info);
int sor_s(DOF_MATRIX *a, const DOF_REAL_VEC *f, const DOF_SCHAR_VEC *b,
	  DOF_REAL_VEC *u, REAL omega, REAL tol, int max_iter, int info);

/***  file ssor.c  **********************************************************/
int ssor_dowb(DOF_DOWB_MATRIX *a,
	      const DOF_REAL_D_VEC *f, const DOF_SCHAR_VEC *b,
	      DOF_REAL_D_VEC *u, REAL omega, REAL tol, int max_iter, int info);
int ssor_d(DOF_MATRIX *a, const DOF_REAL_D_VEC *f, const DOF_SCHAR_VEC *b,
	   DOF_REAL_D_VEC *u, REAL omega, REAL tol, int max_iter, int info);
int ssor_s(DOF_MATRIX *a, const DOF_REAL_VEC *f, const DOF_SCHAR_VEC *b,
	   DOF_REAL_VEC *u, REAL omega, REAL tol, int max_iter, int info);

/***   file traverse_r.c  ***************************************************/
extern void mesh_traverse(MESH *mesh, int level, FLAGS fill_flag,
			  void (*el_fct)(const EL_INFO *, void *data), 
			  void *data);
extern void fill_macro_info(MESH *mesh, const MACRO_EL *mel, EL_INFO *elinfo);
extern void fill_elinfo(int ichild, const EL_INFO *parent_info, EL_INFO *elinfo);

/***   file traverse_nr.c ***************************************************/
extern TRAVERSE_STACK *get_traverse_stack(void);
extern void free_traverse_stack(TRAVERSE_STACK *stack);
extern const EL_INFO *traverse_first(TRAVERSE_STACK *stack,
				     MESH *mesh, int level, FLAGS fill_flag);
extern const EL_INFO *traverse_next(TRAVERSE_STACK *stack, const EL_INFO *);
extern const EL_INFO *traverse_neighbour(TRAVERSE_STACK *stack, const EL_INFO *,
					 int neighbour);
extern const EL_INFO *traverse_parent(const TRAVERSE_STACK *stack,
				      const EL_INFO *child);
extern const EL_INFO *subtree_traverse_first(TRAVERSE_STACK *stack,
					     const EL_INFO *local_root,
					     int level, FLAGS fill_flag);

#define TRAVERSE_START(mesh, stack, level, fill_flag, eli)	\
if (((eli) = traverse_first(stack, mesh, level, fill_flag))) do
#define TRAVERSE_STOP(stack, eli)		\
while (((eli) = traverse_next(stack, eli)))

/*---  file trav_xy.c  -----------------------------------------------------*/
extern int find_el_at_pt(MESH *mesh, const REAL_D xy,
			 EL_INFO **el_info_p, FLAGS flag, REAL bary[N_LAMBDA],
			 const MACRO_EL *start_mel,
			 const REAL_D xy0, REAL *sp);

/***   file read_mesh.c  *********************************************/
MESH *read_mesh(const char *fn, REAL *timeptr,
		NODE_PROJECTION *(*n_proj)(MESH *, MACRO_EL *, int));
DOF_REAL_VEC   *read_dof_real_vec(const char *, MESH *, FE_SPACE *);
DOF_REAL_D_VEC *read_dof_real_d_vec(const char *, MESH *, FE_SPACE *);
DOF_INT_VEC    *read_dof_int_vec(const char *, MESH *, FE_SPACE *);
DOF_SCHAR_VEC  *read_dof_schar_vec(const char *, MESH *, FE_SPACE *);
DOF_UCHAR_VEC  *read_dof_uchar_vec(const char *, MESH *, FE_SPACE *);

MESH *read_mesh_xdr(const char *, REAL *,
		    NODE_PROJECTION *(*)(MESH *, MACRO_EL *, int));
DOF_REAL_VEC   *read_dof_real_vec_xdr(const char *, MESH *, FE_SPACE *);
DOF_REAL_D_VEC *read_dof_real_d_vec_xdr(const char *, MESH *, FE_SPACE *);
DOF_INT_VEC    *read_dof_int_vec_xdr(const char *, MESH *, FE_SPACE *);
DOF_SCHAR_VEC  *read_dof_schar_vec_xdr(const char *, MESH *, FE_SPACE *);
DOF_UCHAR_VEC  *read_dof_uchar_vec_xdr(const char *, MESH *, FE_SPACE *);

/***   file write_mesh.c  ********************************************/
int write_mesh(MESH *, const char *, REAL);
int write_dof_real_vec(const DOF_REAL_VEC *, const char *);
int write_dof_real_d_vec(const DOF_REAL_D_VEC *, const char *);
int write_dof_int_vec(const DOF_INT_VEC *, const char *);
int write_dof_schar_vec(const DOF_SCHAR_VEC *, const char *);
int write_dof_uchar_vec(const DOF_UCHAR_VEC *, const char *);

int write_mesh_xdr(MESH *, const char *, REAL);
int write_dof_real_vec_xdr(const DOF_REAL_VEC *, const char *);
int write_dof_real_d_vec_xdr(const DOF_REAL_D_VEC *, const char *);
int write_dof_int_vec_xdr(const DOF_INT_VEC *, const char *);
int write_dof_schar_vec_xdr(const DOF_SCHAR_VEC *, const char *);
int write_dof_uchar_vec_xdr(const DOF_UCHAR_VEC *, const char *);

int write_dof_matrix_pbm(const DOF_MATRIX *matrix,
			 const char *filename);

/***   file write_mesh_gmv.c  ********************************************/

int write_mesh_gmv(MESH *mesh, const char *file_name, int write_ascii,
		   int use_refined_grid,
		   const int n_drv,
		   DOF_REAL_VEC **drv_ptr,
		   const int n_drdv,
		   DOF_REAL_D_VEC **drdv_ptr,
		   DOF_REAL_D_VEC *velocity, 
		   REAL sim_time);

int write_dof_vec_gmv(MESH *mesh,
		      const char *mesh_file, 
		      const char *file_name, int write_ascii,
		      int use_refined_grid,
		      const int n_drv,
		      DOF_REAL_VEC **drv_ptr,
		      const int n_drdv,
		      DOF_REAL_D_VEC **drdv_ptr,
		      DOF_REAL_D_VEC *velocity,
		      REAL sim_time);

/*--  file write_mesh_ps.c  ------------------------------------------------*/
void write_mesh_ps(MESH *mesh, const char *filename, const char *title,
                   const REAL x[2], const REAL y[2], int keepaspect, 
                   int draw_bound);

/*--------------------------------------------------------------------------*/
/*  interface for Lagrange elements for the gltools                         */
/*  file  gltools.c                                                         */
/*--------------------------------------------------------------------------*/
typedef void*    GLTOOLS_WINDOW;

GLTOOLS_WINDOW open_gltools_window(const char *, const char *, const REAL *,
				   MESH *, int);
void close_gltools_window(GLTOOLS_WINDOW);

extern int gltools_get_next_dialog(void);
extern void gltools_set_next_dialog(int dialog);
void gltools_est(GLTOOLS_WINDOW, MESH *, REAL (*)(EL *), REAL, REAL);
void gltools_disp_mesh(GLTOOLS_WINDOW, MESH *, int, const DOF_REAL_D_VEC *);
void gltools_mesh(GLTOOLS_WINDOW win, MESH *, int);
void gltools_disp_drv(GLTOOLS_WINDOW, const DOF_REAL_VEC *,
		      REAL, REAL, const DOF_REAL_D_VEC *);
void gltools_drv(GLTOOLS_WINDOW, const DOF_REAL_VEC *, REAL, REAL);
void gltools_disp_drv_d(GLTOOLS_WINDOW, const DOF_REAL_D_VEC *, 
			REAL, REAL, const DOF_REAL_D_VEC *);
void gltools_drv_d(GLTOOLS_WINDOW, const DOF_REAL_D_VEC *, REAL, REAL);
void gltools_disp_vec(GLTOOLS_WINDOW, const DOF_REAL_D_VEC *, 
		      REAL, REAL, const DOF_REAL_D_VEC *);
void gltools_vec(GLTOOLS_WINDOW, const DOF_REAL_D_VEC *, REAL, REAL);

/*--------------------------------------------------------------------------*/
/*  interface for Lagrange elements for the dxtools                         */
/*  file  dxtools.c                                                         */
/*--------------------------------------------------------------------------*/

typedef struct dxtools_window DXTOOLS_WINDOW;

extern DXTOOLS_WINDOW *open_dxtools_window(const char *title,
					   const char *geometry);

extern void close_dxtools_window(DXTOOLS_WINDOW *win);
extern void dxtools_mesh(DXTOOLS_WINDOW *win, MESH *mesh);
extern void dxtools_drv(DXTOOLS_WINDOW *win, const DOF_REAL_VEC *u);
extern void dxtools_drdv(DXTOOLS_WINDOW *win, const DOF_REAL_D_VEC *u);

#ifdef __cplusplus
}
#endif

#endif  /* !_ALBERTA_H_ */