Skip to content

base

TFCoil

Calculates the parameters of a resistive TF coil system for a fusion power plant

Source code in process/models/tfcoil/base.py
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
class TFCoil:
    """Calculates the parameters of a resistive TF coil system for a fusion power plant"""

    def __init__(self, build: Build):
        """Initialise Fortran module variables."""
        self.outfile = constants.NOUT  # output file unit
        self.iprint = 0  # switch for writing to output file (1=yes)
        self.build = build
        self.a_tf_inboard_total = tfcoil_variables.a_tf_inboard_total

    def run_base_tf(self):
        """Run main tfcoil subroutine without outputting."""

        (
            superconducting_tf_coil_variables.rad_tf_coil_inboard_toroidal_half,
            superconducting_tf_coil_variables.tan_theta_coil,
            tfcoil_variables.a_tf_inboard_total,
            superconducting_tf_coil_variables.r_tf_outboard_in,
            superconducting_tf_coil_variables.r_tf_outboard_out,
            tfcoil_variables.dx_tf_inboard_out_toroidal,
            tfcoil_variables.a_tf_leg_outboard,
            tfcoil_variables.dr_tf_plasma_case,
            tfcoil_variables.dx_tf_side_case_min,
        ) = self.tf_global_geometry(
            i_tf_case_geom=tfcoil_variables.i_tf_case_geom,
            i_f_dr_tf_plasma_case=tfcoil_variables.i_f_dr_tf_plasma_case,
            f_dr_tf_plasma_case=tfcoil_variables.f_dr_tf_plasma_case,
            tfc_sidewall_is_fraction=tfcoil_variables.tfc_sidewall_is_fraction,
            casths_fraction=tfcoil_variables.casths_fraction,
            n_tf_coils=tfcoil_variables.n_tf_coils,
            dr_tf_inboard=build_variables.dr_tf_inboard,
            dr_tf_nose_case=tfcoil_variables.dr_tf_nose_case,
            r_tf_inboard_out=build_variables.r_tf_inboard_out,
            r_tf_inboard_in=build_variables.r_tf_inboard_in,
            r_tf_outboard_mid=build_variables.r_tf_outboard_mid,
            dr_tf_outboard=build_variables.dr_tf_outboard,
        )

        tfcoil_variables.r_b_tf_inboard_peak = (
            build_variables.r_tf_inboard_out
            - tfcoil_variables.dr_tf_plasma_case
            - tfcoil_variables.dx_tf_wp_insulation
            - tfcoil_variables.dx_tf_wp_insertion_gap
        )

        (
            tfcoil_variables.b_tf_inboard_peak_symmetric,
            tfcoil_variables.c_tf_total,
            superconducting_tf_coil_variables.c_tf_coil,
            tfcoil_variables.oacdcp,
        ) = self.tf_current(
            n_tf_coils=tfcoil_variables.n_tf_coils,
            b_plasma_toroidal_on_axis=physics_variables.b_plasma_toroidal_on_axis,
            rmajor=physics_variables.rmajor,
            r_b_tf_inboard_peak=tfcoil_variables.r_b_tf_inboard_peak,
            a_tf_inboard_total=tfcoil_variables.a_tf_inboard_total,
        )

        (
            tfcoil_variables.len_tf_coil,
            tfcoil_variables.tfa,
            tfcoil_variables.tfb,
            tfcoil_variables.r_tf_arc,
            tfcoil_variables.z_tf_arc,
        ) = self.tf_coil_shape_inner(
            i_tf_shape=tfcoil_variables.i_tf_shape,
            itart=physics_variables.itart,
            i_single_null=physics_variables.i_single_null,
            r_tf_inboard_out=build_variables.r_tf_inboard_out,
            r_cp_top=build_variables.r_cp_top,
            rmajor=physics_variables.rmajor,
            rminor=physics_variables.rminor,
            r_tf_outboard_in=superconducting_tf_coil_variables.r_tf_outboard_in,
            z_tf_inside_half=build_variables.z_tf_inside_half,
            z_tf_top=build_variables.z_tf_top,
            dr_tf_inboard=build_variables.dr_tf_inboard,
            dr_tf_outboard=build_variables.dr_tf_outboard,
            r_tf_outboard_mid=build_variables.r_tf_outboard_mid,
            r_tf_inboard_mid=build_variables.r_tf_inboard_mid,
        )

    def output(self):
        """Run main tfcoil subroutine and write output."""
        self.iprint = 1
        self.tfcoil(output=bool(self.iprint))

    def tf_global_geometry(
        self,
        i_tf_case_geom: int,
        i_f_dr_tf_plasma_case: bool,
        f_dr_tf_plasma_case: float,
        tfc_sidewall_is_fraction: bool,
        casths_fraction: float,
        n_tf_coils: int,
        dr_tf_inboard: float,
        dr_tf_nose_case: float,
        r_tf_inboard_out: float,
        r_tf_inboard_in: float,
        r_tf_outboard_mid: float,
        dr_tf_outboard: float,
    ) -> tuple[float, float, float, float, float, float, float, float, float]:
        """Calculate the global geometry of the Toroidal Field (TF) coil.

        This method computes the overall geometry of the TF coil, including:

        - Toroidal angular spacing and tangent of the angle.
        - Cross-sectional areas of the inboard and outboard legs.
        - Radii and widths of the inboard and outboard legs.
        - Case thicknesses for plasma-facing and sidewall regions.

        Parameters
        ----------
        i_tf_case_geom : int
            Geometry type of the TF coil case (e.g., circular or straight plasma-facing front case).
        i_f_dr_tf_plasma_case : bool
            Whether the plasma-facing case thickness is specified as a fraction of the inboard thickness.
        f_dr_tf_plasma_case : float
            Fraction of the inboard thickness used for the plasma-facing case thickness.
        tfc_sidewall_is_fraction : bool
            Whether the sidewall case thickness is specified as a fraction of the inboard radius.
        casths_fraction : float
            Fraction of the inboard radius used for the sidewall case thickness.
        n_tf_coils : int
            Number of TF coils.
        dr_tf_inboard : float
            Radial thickness of the inboard leg of the TF coil [m].
        dr_tf_nose_case : float
            Thickness of the inboard leg case at the nose region [m].
        r_tf_inboard_out : float
            Outer radius of the inboard leg of the TF coil [m].
        r_tf_inboard_in : float
            Inner radius of the inboard leg of the TF coil [m].
        r_tf_outboard_mid : float
            Mid-plane radius of the outboard leg of the TF coil [m].
        dr_tf_outboard : float
            Radial thickness of the outboard leg of the TF coil [m].

        Returns
        -------
        tuple
            A tuple containing:
            - **rad_tf_coil_inboard_toroidal_half** (*float*): Toroidal angular spacing of each TF coil [radians].
            - **tan_theta_coil** (*float*): Tangent of the toroidal angular spacing.
            - **a_tf_inboard_total** (*float*): Cross-sectional area of the inboard leg of the TF coil [m²].
            - **r_tf_outboard_in** (*float*): Inner radius of the outboard leg of the TF coil [m].
            - **r_tf_outboard_out** (*float*): Outer radius of the outboard leg of the TF coil [m].
            - **dx_tf_inboard_out_toroidal** (*float*): Width of the inboard leg at the outer edge in the toroidal direction [m].
            - **a_tf_leg_outboard** (*float*): Cross-sectional area of the outboard leg of the TF coil [m²].
        """

        # The angular space of each TF coil in the toroidal direction [rad]
        # The angular space between each coil is the same as that of the coils

        rad_tf_coil_inboard_toroidal_half = np.pi / n_tf_coils
        tan_theta_coil = np.tan(rad_tf_coil_inboard_toroidal_half)

        # TF coil inboard legs total mid-plane cross-section area [m^2]
        if i_tf_case_geom == 0:
            # Circular plasma facing front case
            a_tf_inboard_total = np.pi * (r_tf_inboard_out**2 - r_tf_inboard_in**2)
        else:
            # Straight plasma facing front case
            a_tf_inboard_total = (
                n_tf_coils
                * np.sin(rad_tf_coil_inboard_toroidal_half)
                * np.cos(rad_tf_coil_inboard_toroidal_half)
                * r_tf_inboard_out**2
                - np.pi * r_tf_inboard_in**2
            )

        # TF coil width in toroidal direction at inboard leg outer edge [m]

        dx_tf_inboard_out_toroidal = (
            2.0e0 * r_tf_inboard_out * np.sin(rad_tf_coil_inboard_toroidal_half)
        )

        # Outer leg geometry
        # Mid-plane inner/out radial position of the TF coil outer leg [m]

        r_tf_outboard_in = r_tf_outboard_mid - (dr_tf_outboard * 0.5e0)
        r_tf_outboard_out = r_tf_outboard_mid + (dr_tf_outboard * 0.5e0)

        # Area of rectangular cross-section TF outboard leg [m^2]
        a_tf_leg_outboard = dx_tf_inboard_out_toroidal * dr_tf_outboard

        # ======================================================================
        # Plasma facing front case thickness [m]

        if i_f_dr_tf_plasma_case:
            # Set as fraction of the coil radial thickness
            dr_tf_plasma_case = f_dr_tf_plasma_case * dr_tf_inboard
        else:
            # Set directly as input
            dr_tf_plasma_case = tfcoil_variables.dr_tf_plasma_case

        # This ensures that there is sufficient radial space for the WP to not
        # clip the edges of the plasma-facing front case

        if dr_tf_plasma_case < (r_tf_inboard_in + dr_tf_inboard) * (
            1 - (np.cos(np.pi / tfcoil_variables.n_tf_coils))
        ):
            dr_tf_plasma_case = (
                1.0
                * (r_tf_inboard_in + dr_tf_inboard)
                * (1 - (np.cos(np.pi / tfcoil_variables.n_tf_coils)))
            )

        # Warn that the value has be forced to a minimum value at some point in
        # iteration
        logger.error(
            "dr_tf_plasma_case too small to accommodate the WP, forced to minimum value"
        )

        # ======================================================================

        # Case thickness of side wall [m]
        if tfc_sidewall_is_fraction:
            dx_tf_side_case_min = (
                casths_fraction
                * (r_tf_inboard_in + dr_tf_nose_case)
                * np.tan(np.pi / n_tf_coils)
            )
        else:
            dx_tf_side_case_min = tfcoil_variables.dx_tf_side_case_min

        return (
            rad_tf_coil_inboard_toroidal_half,
            tan_theta_coil,
            a_tf_inboard_total,
            r_tf_outboard_in,
            r_tf_outboard_out,
            dx_tf_inboard_out_toroidal,
            a_tf_leg_outboard,
            dr_tf_plasma_case,
            dx_tf_side_case_min,
        )

    def tf_current(
        self,
        n_tf_coils: int,
        b_plasma_toroidal_on_axis: float,
        rmajor: float,
        r_b_tf_inboard_peak: float,
        a_tf_inboard_total: float,
    ) -> tuple[float, float, float, float]:
        """Calculate the maximum B field and the corresponding TF current.

        Parameters
        ----------
        n_tf_coils : int
            Number of TF coils.
        b_plasma_toroidal_on_axis : float
            Toroidal magnetic field at the plasma center [T].
        rmajor : float
            Major radius of the plasma [m].
        r_b_tf_inboard_peak : float
            Radius at which the peak inboard B field occurs [m].
        a_tf_inboard_total : float
            Cross-sectional area of the inboard leg of the TF coil [m²].

        Returns
        -------
        tuple[float, float, float, float]
            A tuple containing:
            - **b_tf_inboard_peak_symmetric** (*float*): Maximum B field on the magnet [T].
            - **c_tf_total** (*float*): Total current in TF coils [A].
            - **c_tf_coil** (*float*): Current per TF coil [A].
            - **oacdcp** (*float*): Global inboard leg average current density in TF coils [A/m²].
        """

        # Calculation of the maximum B field on the magnet [T]
        b_tf_inboard_peak_symmetric = (
            b_plasma_toroidal_on_axis * rmajor / r_b_tf_inboard_peak
        )

        # Total current in TF coils [A]
        c_tf_total = (
            b_tf_inboard_peak_symmetric
            * r_b_tf_inboard_peak
            * (2 * np.pi / constants.RMU0)
        )

        # Current per TF coil [A]
        c_tf_coil = c_tf_total / n_tf_coils

        # Global inboard leg average current in TF coils [A/m2]
        oacdcp = c_tf_total / a_tf_inboard_total

        return b_tf_inboard_peak_symmetric, c_tf_total, c_tf_coil, oacdcp

    def tf_coil_shape_inner(
        self,
        i_tf_shape: int,
        itart: int,
        i_single_null: int,
        r_tf_inboard_out: float,
        r_cp_top: float,
        rmajor: float,
        rminor: float,
        r_tf_outboard_in: float,
        z_tf_inside_half: float,
        z_tf_top: float,
        dr_tf_inboard: float,
        dr_tf_outboard: float,
        r_tf_outboard_mid: float,
        r_tf_inboard_mid: float,
    ) -> tuple[float, np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
        """Calculate the shape of the inside of the TF coil.

        This method approximates the TF coil by a straight inboard section and four elliptical arcs.
        The model is ad hoc and does not have a physics or engineering basis.

        Parameters
        ----------
        i_tf_shape : int
            TF coil shape selection switch.
        itart : int
            TART (tight aspect ratio tokamak) switch.
        i_single_null : int
            Single null switch.
        r_tf_inboard_out : float
            Outer radius of the inboard leg of the TF coil [m].
        r_cp_top : float
            Centrepost outer radius at the top [m].
        rmajor : float
            Major radius of the plasma [m].
        rminor : float
            Minor radius of the plasma [m].
        r_tf_outboard_in : float
            Inner radius of the outboard leg of the TF coil [m].
        z_tf_inside_half : float
            Maximum inboard edge height [m].
        z_tf_top : float
            Vertical position of the top of the TF coil [m].
        dr_tf_inboard : float
            Radial thickness of the inboard leg of the TF coil [m].
        dr_tf_outboard : float
            Radial thickness of the outboard leg of the TF coil [m].
        r_tf_outboard_mid : float
            Mid-plane radius of the outboard leg of the TF coil [m].
        r_tf_inboard_mid : float
            Mid-plane radius of the inboard leg of the TF coil [m].

        Returns
        -------
        tuple[float, np.ndarray, np.ndarray, np.ndarray, np.ndarray]
            len_tf_coil (float): Total length of the TF coil.
            - tfa (np.ndarray): Arc segment lengths in R.
            - tfb (np.ndarray): Arc segment lengths in Z.
            - r_tf_arc (np.ndarray): R coordinates of arc points.
            - z_tf_arc (np.ndarray): Z coordinates of arc points.
        """
        FSTRAIGHT = 0.6
        len_tf_coil = 0.0
        r_tf_arc = np.zeros(5)
        z_tf_arc = np.zeros(5)
        tfa = np.zeros(4)
        tfb = np.zeros(4)

        if i_tf_shape == 1 and itart == 0:
            # PROCESS D-shape parameterisation
            r_tf_arc[0] = r_tf_inboard_out
            r_tf_arc[1] = rmajor - 0.2e0 * rminor
            r_tf_arc[2] = r_tf_outboard_in
            r_tf_arc[3] = r_tf_arc[1]
            r_tf_arc[4] = r_tf_arc[0]

            if i_single_null == 0:
                z_tf_arc[0] = FSTRAIGHT * z_tf_inside_half
                z_tf_arc[1] = z_tf_inside_half
                z_tf_arc[2] = 0
                z_tf_arc[3] = -z_tf_inside_half
                z_tf_arc[4] = -FSTRAIGHT * z_tf_inside_half
            else:
                z_tf_arc[0] = FSTRAIGHT * (z_tf_top - dr_tf_inboard)
                z_tf_arc[1] = z_tf_top - dr_tf_inboard
                z_tf_arc[2] = 0
                z_tf_arc[3] = -z_tf_inside_half
                z_tf_arc[4] = -FSTRAIGHT * z_tf_inside_half

            len_tf_coil = z_tf_arc[0] - z_tf_arc[4]

            for ii in range(4):
                tfa[ii] = abs(r_tf_arc[ii + 1] - r_tf_arc[ii])
                tfb[ii] = abs(z_tf_arc[ii + 1] - z_tf_arc[ii])
                aa = tfa[ii] + 0.5e0 * dr_tf_inboard
                bb = tfb[ii] + 0.5e0 * dr_tf_inboard
                len_tf_coil += 0.25e0 * self.circumference(aa, bb)

        elif i_tf_shape == 1 and itart == 1:
            # Centrepost with D-shaped
            r_tf_arc[0] = r_cp_top
            r_tf_arc[1] = rmajor - 0.2e0 * rminor
            r_tf_arc[2] = r_tf_outboard_in
            r_tf_arc[3] = r_tf_arc[1]
            r_tf_arc[4] = r_tf_arc[0]

            z_tf_arc[0] = z_tf_top - dr_tf_inboard
            z_tf_arc[1] = z_tf_top - dr_tf_inboard
            z_tf_arc[2] = 0
            z_tf_arc[3] = -z_tf_inside_half
            z_tf_arc[4] = -z_tf_inside_half

            len_tf_coil = 2 * (r_tf_arc[1] - r_tf_arc[0])

            for ii in range(1, 3):
                tfa[ii] = abs(r_tf_arc[ii + 1] - r_tf_arc[ii])
                tfb[ii] = abs(z_tf_arc[ii + 1] - z_tf_arc[ii])
                aa = tfa[ii] + 0.5e0 * dr_tf_outboard
                bb = tfb[ii] + 0.5e0 * dr_tf_outboard
                len_tf_coil += 0.25e0 * self.circumference(aa, bb)

        elif i_tf_shape == 2:
            # Picture frame coil
            if itart == 0:
                r_tf_arc[0] = r_tf_inboard_out
            if itart == 1:
                r_tf_arc[0] = r_cp_top
            r_tf_arc[1] = r_tf_outboard_in
            r_tf_arc[2] = r_tf_arc[1]
            r_tf_arc[3] = r_tf_arc[1]
            r_tf_arc[4] = r_tf_arc[0]

            z_tf_arc[0] = z_tf_top - dr_tf_inboard
            z_tf_arc[1] = z_tf_top - dr_tf_inboard
            z_tf_arc[2] = 0
            z_tf_arc[3] = -z_tf_inside_half
            z_tf_arc[4] = -z_tf_inside_half

            if itart == 0:
                len_tf_coil = 2.0e0 * (
                    2.0e0 * z_tf_inside_half
                    + dr_tf_inboard
                    + r_tf_outboard_mid
                    - r_tf_inboard_mid
                )
            elif itart == 1:
                len_tf_coil = (
                    z_tf_inside_half + z_tf_top + 2.0e0 * (r_tf_outboard_mid - r_cp_top)
                )

        return len_tf_coil, tfa, tfb, r_tf_arc, z_tf_arc

    def tf_stored_magnetic_energy(
        self,
        ind_tf_coil: float,
        c_tf_total: float,
        n_tf_coils: int,
    ) -> tuple[float, float, float]:
        """Calculates the stored magnetic energy in a single TF coil.

        Parameters
        ----------
        ind_tf_coil : float
            Self-inductance of the TF coil [H].
        c_tf_total : float
            Current in all TF coils [A].
        n_tf_coils : int
            Number of TF coils.

        Returns
        -------
        tuple[float, float, float]
            Tuple containing:
            - e_tf_magnetic_stored_total (float): Total stored magnetic energy in all TF coils [J].
            - e_tf_magnetic_stored_total_gj (float): Total stored magnetic energy in all TF coils [GJ].
            - e_tf_coil_magnetic_stored (float): Stored magnetic energy in a single TF coil [J].

        Notes
        -----
            - The stored magnetic energy in an inductor is given by:
                E = (1/2) * L * I^2
                where E is the energy [J], L is the inductance [H], and I is the current [A].
            - Total energy is for all coils; per-coil energy is divided by n_tf_coils.

        References
        ----------
            - http://hyperphysics.phy-astr.gsu.edu/hbase/electric/indeng.html

            - https://en.wikipedia.org/wiki/Inductance#Self-inductance_and_magnetic_energy
        """
        e_tf_magnetic_stored_total = 0.5 * ind_tf_coil * c_tf_total**2

        e_tf_magnetic_stored_total_gj = e_tf_magnetic_stored_total * 1.0e-9

        e_tf_coil_magnetic_stored = e_tf_magnetic_stored_total / n_tf_coils

        return (
            e_tf_magnetic_stored_total,
            e_tf_magnetic_stored_total_gj,
            e_tf_coil_magnetic_stored,
        )

    def outtf(self):
        """Writes superconducting TF coil output to file

        This routine writes the superconducting TF coil results
        to the output file.
        PROCESS Superconducting TF Coil Model, J. Morris, CCFE, 1st May 2014
        """

        # General coil parameters
        po.osubhd(self.outfile, "TF design")
        po.ovarin(
            self.outfile,
            "Conductor technology",
            "(i_tf_sup)",
            tfcoil_variables.i_tf_sup,
        )

        if tfcoil_variables.i_tf_sup == 0:
            po.ocmmnt(
                self.outfile, "  -> resistive coil : Water cooled copper (GLIDCOP AL-15)"
            )
        elif tfcoil_variables.i_tf_sup == 1:
            po.ocmmnt(self.outfile, "  -> Superconducting coil (SC)")
        elif tfcoil_variables.i_tf_sup == 2:
            po.ocmmnt(self.outfile, "  -> Resistive coil : Helium cooled aluminium")

        # SC material scaling
        if tfcoil_variables.i_tf_sup == 1:
            po.ovarin(
                self.outfile,
                "Superconductor material",
                "(i_tf_sc_mat)",
                tfcoil_variables.i_tf_sc_mat,
            )

            if tfcoil_variables.i_tf_sc_mat == 1:
                po.ocmmnt(self.outfile, "  -> ITER Nb3Sn critical surface model")
            elif tfcoil_variables.i_tf_sc_mat == 2:
                po.ocmmnt(self.outfile, "  -> Bi-2212 high temperature superconductor")
            elif tfcoil_variables.i_tf_sc_mat == 3:
                po.ocmmnt(self.outfile, "  -> NbTi")
            elif tfcoil_variables.i_tf_sc_mat == 4:
                po.ocmmnt(
                    self.outfile,
                    "  -> ITER Nb3Sn critical surface model, user-defined parameters",
                )
            elif tfcoil_variables.i_tf_sc_mat == 5:
                po.ocmmnt(self.outfile, "  -> WST Nb3Sn")
            elif tfcoil_variables.i_tf_sc_mat == 6:
                po.ocmmnt(
                    self.outfile,
                    "  -> High temperature superconductor: REBCO HTS tape in CroCo strand",
                )
            elif tfcoil_variables.i_tf_sc_mat == 7:
                po.ocmmnt(
                    self.outfile,
                    "  ->  Durham Ginzburg-Landau critical surface model for Nb-Ti",
                )
            elif tfcoil_variables.i_tf_sc_mat == 8:
                po.ocmmnt(
                    self.outfile,
                    "  ->  Durham Ginzburg-Landau critical surface model for REBCO",
                )
            elif tfcoil_variables.i_tf_sc_mat == 9:
                po.ocmmnt(
                    self.outfile,
                    "  ->  Hazelton experimental data + Zhai conceptual model for REBCO",
                )

        # Joints strategy
        po.ovarin(
            self.outfile,
            "Presence of TF demountable joints",
            "(itart)",
            physics_variables.itart,
        )
        if physics_variables.itart == 1:
            po.ocmmnt(
                self.outfile, "  -> TF coil made of a Centerpost (CP) and outer legs"
            )
            po.ocmmnt(self.outfile, "     interfaced with demountable joints")
        else:
            po.ocmmnt(self.outfile, "  -> Coils without demountable joints")

        # Centring forces support strategy
        po.ovarin(
            self.outfile,
            "TF inboard leg support strategy",
            "(i_tf_bucking)",
            tfcoil_variables.i_tf_bucking,
        )

        if tfcoil_variables.i_tf_bucking == 0:
            po.ocmmnt(self.outfile, "  -> No support structure")
        elif tfcoil_variables.i_tf_bucking == 1:
            if tfcoil_variables.i_tf_sup == 1:
                po.ocmmnt(self.outfile, "  -> Steel casing")
            elif (
                abs(tfcoil_variables.eyoung_res_tf_buck - 205.0e9)
                < np.finfo(float(tfcoil_variables.eyoung_res_tf_buck)).eps
            ):
                po.ocmmnt(self.outfile, "  -> Steel bucking cylinder")
            else:
                po.ocmmnt(self.outfile, "  -> Bucking cylinder")

        elif (
            tfcoil_variables.i_tf_bucking in (2, 3)
            and build_variables.i_tf_inside_cs == 1
        ):
            po.ocmmnt(
                self.outfile,
                "  -> TF in contact with dr_bore filler support (bucked and weged design)",
            )

        elif (
            tfcoil_variables.i_tf_bucking in (2, 3)
            and build_variables.i_tf_inside_cs == 0
        ):
            po.ocmmnt(
                self.outfile, "  -> TF in contact with CS (bucked and weged design)"
            )

        # TF coil geometry
        po.osubhd(self.outfile, "TF coil Geometry :")
        po.ovarin(
            self.outfile,
            "Number of TF coils",
            "(n_tf_coils)",
            int(tfcoil_variables.n_tf_coils),
        )
        po.ovarre(
            self.outfile,
            "Inboard TF half angle [rad]",
            "(rad_tf_coil_inboard_toroidal_half)",
            superconducting_tf_coil_variables.rad_tf_coil_inboard_toroidal_half,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Inboard leg centre radius (m)",
            "(r_tf_inboard_mid)",
            build_variables.r_tf_inboard_mid,
            "OP ",
        )
        po.ovarre(
            constants.MFILE,
            "Inboard leg inner radius (m)",
            "(r_tf_inboard_in)",
            build_variables.r_tf_inboard_in,
            "OP ",
        )
        po.ovarre(
            constants.MFILE,
            "Inboard leg outer radius (m)",
            "(r_tf_inboard_out)",
            build_variables.r_tf_inboard_out,
            "OP ",
        )
        po.ovarin(
            self.outfile,
            "WP shape selection switch",
            "(i_tf_wp_geom)",
            tfcoil_variables.i_tf_wp_geom,
        )
        po.ovarre(
            constants.MFILE,
            "Radial position of inner edge and centre of winding pack (m)",
            "(r_tf_wp_inboard_inner)",
            superconducting_tf_coil_variables.r_tf_wp_inboard_inner,
            "OP ",
        )
        po.ovarre(
            constants.MFILE,
            "Radial position of outer edge and of winding pack (m)",
            "(r_tf_wp_inboard_outer)",
            superconducting_tf_coil_variables.r_tf_wp_inboard_outer,
            "OP ",
        )
        po.ovarre(
            constants.MFILE,
            "Radial position of centre of winding pack (m)",
            "(r_tf_wp_inboard_centre)",
            superconducting_tf_coil_variables.r_tf_wp_inboard_centre,
            "OP ",
        )
        po.ovarre(
            constants.MFILE,
            "Minimum toroidal thickness of winding pack (m)",
            "(dx_tf_wp_toroidal_min)",
            superconducting_tf_coil_variables.dx_tf_wp_toroidal_min,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Outboard leg inner radius (m)",
            "(r_tf_outboard_in)",
            superconducting_tf_coil_variables.r_tf_outboard_in,
            "OP ",
        )

        po.ovarre(
            self.outfile,
            "Outboard leg centre radius (m)",
            "(r_tf_outboard_mid)",
            build_variables.r_tf_outboard_mid,
            "OP ",
        )
        po.ovarin(
            self.outfile,
            "Outboard leg nose case type",
            "(i_tf_case_geom)",
            tfcoil_variables.i_tf_case_geom,
        )
        po.ovarre(
            self.outfile,
            "Total inboard leg radial thickness (m)",
            "(dr_tf_inboard)",
            build_variables.dr_tf_inboard,
        )
        po.ovarre(
            self.outfile,
            "Total outboard leg radial thickness (m)",
            "(dr_tf_outboard)",
            build_variables.dr_tf_outboard,
        )
        po.ovarre(
            self.outfile,
            "Outboard leg toroidal thickness (m)",
            "(dx_tf_inboard_out_toroidal)",
            tfcoil_variables.dx_tf_inboard_out_toroidal,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Maximum inboard edge height (m)",
            "(z_tf_inside_half)",
            build_variables.z_tf_inside_half,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Height to top of TF coil (m)",
            "(z_tf_top)",
            build_variables.z_tf_top,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Height difference in upper and lower TF from midplane (m)",
            "(dz_tf_upper_lower_midplane)",
            build_variables.dz_tf_upper_lower_midplane,
            "OP ",
        )
        if physics_variables.itart == 1:
            po.ovarre(
                self.outfile,
                "Mean coil circumference (inboard leg not included) (m)",
                "(len_tf_coil)",
                tfcoil_variables.len_tf_coil,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Length of the inboard segment (m)",
                "(cplen)",
                tfcoil_variables.cplen,
                "OP ",
            )
        else:
            po.ovarre(
                self.outfile,
                "Mean coil circumference (including inboard leg length) (m)",
                "(len_tf_coil)",
                tfcoil_variables.len_tf_coil,
                "OP ",
            )

        # Vertical shape
        po.ovarin(
            self.outfile,
            "Vertical TF shape",
            "(i_tf_shape)",
            tfcoil_variables.i_tf_shape,
        )
        if tfcoil_variables.i_tf_shape == 1:
            po.oblnkl(self.outfile)
            po.ocmmnt(self.outfile, "D-shape coil, inner surface shape approximated by")
            po.ocmmnt(
                self.outfile,
                "by a straight segment and elliptical arcs between the following points:",
            )
            po.oblnkl(self.outfile)
        elif tfcoil_variables.i_tf_shape == 2:
            po.oblnkl(self.outfile)
            po.ocmmnt(self.outfile, "Picture frame coil, inner surface approximated by")
            po.ocmmnt(
                self.outfile, "by a straight segment between the following points:"
            )
            po.oblnkl(self.outfile)

        po.write(self.outfile, "  point              x(m)              y(m)")
        for ii in range(5):
            po.write(
                self.outfile,
                f"  {ii}              {tfcoil_variables.r_tf_arc[ii]}              {tfcoil_variables.z_tf_arc[ii]}",
            )
            po.ovarre(
                constants.MFILE,
                f"TF coil arc point {ii} R (m)",
                f"(r_tf_arc({ii + 1}))",
                tfcoil_variables.r_tf_arc[ii],
            )
            po.ovarre(
                constants.MFILE,
                f"TF coil arc point {ii} Z (m)",
                f"(z_tf_arc({ii + 1}))",
                tfcoil_variables.z_tf_arc[ii],
            )

        # CP tapering geometry
        if physics_variables.itart == 1 and tfcoil_variables.i_tf_sup != 1:
            po.osubhd(self.outfile, "Tapered Centrepost TF coil Dimensions:")
            po.ovarre(
                self.outfile,
                "TF coil centrepost outer radius at midplane (m)",
                "(r_tf_inboard_out)",
                build_variables.r_tf_inboard_out,
            )
            po.ovarre(
                self.outfile,
                "TF coil centrepost outer radius at its top (m)",
                "(r_cp_top)",
                build_variables.r_cp_top,
            )
            po.ovarre(
                self.outfile,
                "Top/miplane TF CP radius ratio (-)",
                "(f_r_cp)",
                build_variables.f_r_cp,
            )
            po.ovarre(
                self.outfile,
                "Distance from the midplane to the top of the tapered section (m)",
                "(z_cp_top)",
                superconducting_tf_coil_variables.z_cp_top,
            )
            po.ovarre(
                self.outfile,
                "Distance from the midplane to the top of the centrepost (m)",
                "(z_tf_inside_half + dr_tf_outboard)",
                build_variables.z_tf_inside_half + build_variables.dr_tf_outboard,
            )

        # Turn/WP gemoetry
        if tfcoil_variables.i_tf_sup == 1:
            # Total material fraction
            po.osubhd(self.outfile, "Global material area/fractions:")
            po.ovarre(
                self.outfile,
                "TF cross-section (total) (m2)",
                "(a_tf_inboard_total)",
                tfcoil_variables.a_tf_inboard_total,
            )
            po.ovarre(
                self.outfile,
                "Total steel cross-section (m2)",
                "(a_tf_coil_inboard_steel*n_tf_coils)",
                superconducting_tf_coil_variables.a_tf_coil_inboard_steel
                * tfcoil_variables.n_tf_coils,
            )
            po.ovarre(
                self.outfile,
                "Total steel TF fraction",
                "(f_a_tf_coil_inboard_steel)",
                superconducting_tf_coil_variables.f_a_tf_coil_inboard_steel,
            )
            po.ovarre(
                self.outfile,
                "Total Insulation cross-section (total) (m2)",
                "(a_tf_coil_inboard_insulation*n_tf_coils)",
                superconducting_tf_coil_variables.a_tf_coil_inboard_insulation
                * tfcoil_variables.n_tf_coils,
            )
            po.ovarre(
                self.outfile,
                "Total Insulation fraction",
                "(f_a_tf_coil_inboard_insulation)",
                superconducting_tf_coil_variables.f_a_tf_coil_inboard_insulation,
            )

            # External casing
            po.osubhd(self.outfile, "External steel Case Information :")
            po.ovarre(
                self.outfile,
                "Casing cross section area (per leg) (m2)",
                "(a_tf_coil_inboard_case)",
                tfcoil_variables.a_tf_coil_inboard_case,
            )
            po.ovarre(
                self.outfile,
                "Inboard leg case plasma side wall thickness (m)",
                "(dr_tf_plasma_case)",
                tfcoil_variables.dr_tf_plasma_case,
            )
            po.ovarre(
                self.outfile,
                "Inboard leg plasma case area (m^2)",
                "(a_tf_plasma_case)",
                superconducting_tf_coil_variables.a_tf_plasma_case,
            )
            po.ovarre(
                self.outfile,
                'Inboard leg case inboard "nose" thickness (m)',
                "(dr_tf_nose_case)",
                tfcoil_variables.dr_tf_nose_case,
            )
            po.ovarre(
                self.outfile,
                'Inboard leg case inboard "nose" area (m^2)',
                "(a_tf_coil_nose_case)",
                superconducting_tf_coil_variables.a_tf_coil_nose_case,
            )
            po.ovarre(
                self.outfile,
                "Inboard leg case sidewall thickness at its narrowest point (m)",
                "(dx_tf_side_case_min)",
                tfcoil_variables.dx_tf_side_case_min,
            )
            po.ovarre(
                self.outfile,
                "Inboard leg case sidewall average thickness (m)",
                "(dx_tf_side_case_average)",
                superconducting_tf_coil_variables.dx_tf_side_case_average,
            )
            po.ovarre(
                self.outfile,
                "Inboard leg case sidewall peak thickness (m)",
                "(dx_tf_side_case_peak)",
                superconducting_tf_coil_variables.dx_tf_side_case_peak,
            )
            po.ovarre(
                self.outfile,
                "External case mass per coil (kg)",
                "(m_tf_coil_case)",
                tfcoil_variables.m_tf_coil_case,
                "OP ",
            )

            # Winding pack structure
            po.osubhd(self.outfile, "TF winding pack (WP) geometry:")
            po.ovarre(
                self.outfile,
                "WP cross section area with insulation and insertion (per coil) (m2)",
                "(a_tf_wp_with_insulation)",
                superconducting_tf_coil_variables.a_tf_wp_with_insulation,
            )
            po.ovarre(
                self.outfile,
                "WP cross section area with no insulation and insertion (per coil) (m2)",
                "(a_tf_wp_no_insulation)",
                superconducting_tf_coil_variables.a_tf_wp_no_insulation,
            )
            po.ovarre(
                self.outfile,
                "Total steel area in WP (per coil) (m2)",
                "(a_tf_wp_steel)",
                tfcoil_variables.a_tf_wp_steel,
            )
            po.ovarre(
                self.outfile,
                "Winding pack radial thickness (m)",
                "(dr_tf_wp_with_insulation)",
                tfcoil_variables.dr_tf_wp_with_insulation,
                "OP ",
            )
            if tfcoil_variables.i_tf_turns_integer == 1:
                po.ovarre(
                    self.outfile,
                    "Winding pack toroidal width (m)",
                    "(dx_tf_wp_primary_toroidal)",
                    tfcoil_variables.dx_tf_wp_primary_toroidal,
                    "OP ",
                )
            else:
                po.ovarre(
                    self.outfile,
                    "Winding pack toroidal width 1 (m)",
                    "(dx_tf_wp_primary_toroidal)",
                    tfcoil_variables.dx_tf_wp_primary_toroidal,
                    "OP ",
                )
                po.ovarre(
                    self.outfile,
                    "Winding pack toroidal width 2 (m)",
                    "(dx_tf_wp_secondary_toroidal)",
                    tfcoil_variables.dx_tf_wp_secondary_toroidal,
                    "OP ",
                )

            po.ovarre(
                self.outfile,
                "Ground wall insulation thickness (m)",
                "(dx_tf_wp_insulation)",
                tfcoil_variables.dx_tf_wp_insulation,
            )
            po.ovarre(
                self.outfile,
                "Ground wall insulation area (m^2)",
                "(a_tf_wp_ground_insulation)",
                superconducting_tf_coil_variables.a_tf_wp_ground_insulation,
            )
            po.ovarre(
                self.outfile,
                "Winding pack insertion gap (m)",
                "(dx_tf_wp_insertion_gap)",
                tfcoil_variables.dx_tf_wp_insertion_gap,
            )

            # WP material fraction
            po.osubhd(self.outfile, "TF winding pack (WP) material area/fractions:")
            po.ovarre(
                self.outfile,
                "Steel WP cross-section (total) (m2)",
                "(a_tf_wp_steel*n_tf_coils)",
                tfcoil_variables.a_tf_wp_steel * tfcoil_variables.n_tf_coils,
            )
            po.ovarre(
                self.outfile,
                "Steel WP fraction",
                "(a_tf_wp_steel/a_tf_wp_with_insulation)",
                tfcoil_variables.a_tf_wp_steel
                / superconducting_tf_coil_variables.a_tf_wp_with_insulation,
            )
            po.ovarre(
                self.outfile,
                "Insulation WP fraction",
                "(a_tf_coil_wp_turn_insulation/a_tf_wp_with_insulation)",
                tfcoil_variables.a_tf_coil_wp_turn_insulation
                / superconducting_tf_coil_variables.a_tf_wp_with_insulation,
            )
            po.ovarre(
                self.outfile,
                "Cable WP fraction",
                "((a_tf_wp_with_insulation-a_tf_wp_steel-a_tf_coil_wp_turn_insulation)/a_tf_wp_with_insulation)",
                (
                    superconducting_tf_coil_variables.a_tf_wp_with_insulation
                    - tfcoil_variables.a_tf_wp_steel
                    - tfcoil_variables.a_tf_coil_wp_turn_insulation
                )
                / superconducting_tf_coil_variables.a_tf_wp_with_insulation,
            )

            # Number of turns
            po.osubhd(self.outfile, "WP turn information:")
            po.ovarin(
                self.outfile,
                "Turn parameterisation",
                "(i_tf_turns_integer)",
                tfcoil_variables.i_tf_turns_integer,
            )
            if tfcoil_variables.i_tf_turns_integer == 0:
                po.ocmmnt(self.outfile, "  Non-integer number of turns")
            else:
                po.ocmmnt(self.outfile, "  Integer number of turns")

            po.ovarre(
                self.outfile,
                "Number of turns per TF coil",
                "(n_tf_coil_turns)",
                tfcoil_variables.n_tf_coil_turns,
                "OP ",
            )
            if tfcoil_variables.i_tf_turns_integer == 1:
                po.ovarin(
                    self.outfile,
                    "Number of TF pancakes",
                    "(n_tf_wp_pancakes)",
                    tfcoil_variables.n_tf_wp_pancakes,
                )
                po.ovarin(
                    self.outfile,
                    "Number of TF layers",
                    "(n_tf_wp_layers)",
                    tfcoil_variables.n_tf_wp_layers,
                )

            po.oblnkl(self.outfile)

            if tfcoil_variables.i_tf_turns_integer == 1:
                po.ovarre(
                    self.outfile,
                    "Radial width of turn (m)",
                    "(dr_tf_turn)",
                    superconducting_tf_coil_variables.dr_tf_turn,
                )
                po.ovarre(
                    self.outfile,
                    "Toroidal width of turn (m)",
                    "(dx_tf_turn)",
                    superconducting_tf_coil_variables.dx_tf_turn,
                )
                po.ovarre(
                    self.outfile,
                    "Radial width of conductor (m)",
                    "(t_conductor_radial)",
                    superconducting_tf_coil_variables.t_conductor_radial,
                    "OP ",
                )
                po.ovarre(
                    self.outfile,
                    "Toroidal width of conductor (m)",
                    "(t_conductor_toroidal)",
                    superconducting_tf_coil_variables.t_conductor_toroidal,
                    "OP ",
                )
                po.ovarre(
                    self.outfile,
                    "Radial width of cable space",
                    "(dr_tf_turn_cable_space)",
                    superconducting_tf_coil_variables.dr_tf_turn_cable_space,
                )
                po.ovarre(
                    self.outfile,
                    "Toroidal width of cable space",
                    "(dx_tf_turn_cable_space)",
                    superconducting_tf_coil_variables.dx_tf_turn_cable_space,
                )
                po.ovarre(
                    self.outfile,
                    "Radius of turn cable space rounded corners (m)",
                    "(radius_tf_turn_cable_space_corners)",
                    superconducting_tf_coil_variables.radius_tf_turn_cable_space_corners,
                )
            else:
                po.ovarre(
                    self.outfile,
                    "Width of turn including inter-turn insulation (m)",
                    "(dx_tf_turn_general)",
                    tfcoil_variables.dx_tf_turn_general,
                    "OP ",
                )
                po.ovarre(
                    self.outfile,
                    "Width of conductor (square) (m)",
                    "(t_conductor)",
                    tfcoil_variables.t_conductor,
                    "OP ",
                )
                po.ovarre(
                    self.outfile,
                    "Width of space inside conductor (m)",
                    "(dx_tf_turn_cable_space_average)",
                    superconducting_tf_coil_variables.dx_tf_turn_cable_space_average,
                    "OP ",
                )
                po.ovarre(
                    self.outfile,
                    "Radius of turn cable space rounded corners (m)",
                    "(radius_tf_turn_cable_space_corners)",
                    superconducting_tf_coil_variables.radius_tf_turn_cable_space_corners,
                )

            po.ovarre(
                self.outfile,
                "Steel conduit thickness (m)",
                "(dx_tf_turn_steel)",
                tfcoil_variables.dx_tf_turn_steel,
            )
            po.ovarre(
                self.outfile,
                "Inter-turn insulation thickness (m)",
                "(dx_tf_turn_insulation)",
                tfcoil_variables.dx_tf_turn_insulation,
            )

            if tfcoil_variables.i_tf_sc_mat in (1, 2, 3, 4, 5, 7, 8, 9):
                po.osubhd(self.outfile, "Conductor information:")
                po.ovarre(
                    self.outfile,
                    "Diameter of central helium channel in cable",
                    "(dia_tf_turn_coolant_channel)",
                    tfcoil_variables.dia_tf_turn_coolant_channel,
                )
                po.ovarre(
                    self.outfile,
                    "Diameter of superconducting cable",
                    "(dia_tf_turn_superconducting_cable)",
                    superconducting_tf_coil_variables.dia_tf_turn_superconducting_cable,
                )
                po.ovarre(
                    self.outfile,
                    "Number of superconducting cables per turn",
                    "(n_tf_turn_superconducting_cables)",
                    superconducting_tf_coil_variables.n_tf_turn_superconducting_cables,
                )
                po.ovarre(
                    self.outfile,
                    "Length of superconductor in TF coil (m)",
                    "(len_tf_coil_superconductor)",
                    superconducting_tf_coil_variables.len_tf_coil_superconductor,
                )
                po.ovarre(
                    self.outfile,
                    "Total length of superconductor in all TF coils (m)",
                    "(len_tf_superconductor_total)",
                    superconducting_tf_coil_variables.len_tf_superconductor_total,
                )
                po.ocmmnt(self.outfile, "Fractions by area")
                po.ovarre(
                    self.outfile,
                    "internal area of the cable space",
                    "(a_tf_turn_cable_space_no_void)",
                    tfcoil_variables.a_tf_turn_cable_space_no_void,
                )
                po.ovarre(
                    self.outfile,
                    "True area of turn cable space with gaps and channels removed",
                    "(a_tf_turn_cable_space_effective)",
                    superconducting_tf_coil_variables.a_tf_turn_cable_space_effective,
                )

                po.ovarre(
                    self.outfile,
                    "Coolant fraction in conductor excluding central channel",
                    "(f_a_tf_turn_cable_space_extra_void)",
                    tfcoil_variables.f_a_tf_turn_cable_space_extra_void,
                )
                po.ovarre(
                    self.outfile,
                    "Area of steel in turn",
                    "(a_tf_turn_steel)",
                    tfcoil_variables.a_tf_turn_steel,
                )
                po.ovarre(
                    self.outfile,
                    "Area of all turn insulation in WP",
                    "(a_tf_coil_wp_turn_insulation)",
                    tfcoil_variables.a_tf_coil_wp_turn_insulation,
                )
                po.ovarre(
                    self.outfile,
                    "Total insulation area in TF coil (turn and WP)",
                    "(a_tf_coil_inboard_insulation)",
                    superconducting_tf_coil_variables.a_tf_coil_inboard_insulation,
                )
                po.ovarre(
                    self.outfile,
                    "Total steel area in inboard TF coil (turn and case)",
                    "(a_tf_coil_inboard_steel)",
                    superconducting_tf_coil_variables.a_tf_coil_inboard_steel,
                )
                po.ovarre(
                    self.outfile,
                    "Total conductor area in WP",
                    "(a_tf_wp_conductor)",
                    tfcoil_variables.a_tf_wp_conductor,
                )
                po.ovarre(
                    self.outfile,
                    "Total additional void area in WP",
                    "(a_tf_wp_extra_void)",
                    tfcoil_variables.a_tf_wp_extra_void,
                )

                po.ovarre(
                    self.outfile,
                    "Area of all coolant channels in WP",
                    "(a_tf_wp_coolant_channels)",
                    tfcoil_variables.a_tf_wp_coolant_channels,
                )

                po.ovarre(
                    self.outfile,
                    "Copper fraction of conductor",
                    "(f_a_tf_turn_cable_copper)",
                    tfcoil_variables.f_a_tf_turn_cable_copper,
                )
                po.ovarre(
                    self.outfile,
                    "Superconductor fraction of conductor",
                    "(1-f_a_tf_turn_cable_copper)",
                    1 - tfcoil_variables.f_a_tf_turn_cable_copper,
                )
                # TODO
                # po.ovarre(self.outfile,'Conductor fraction of winding pack','(tfcoil_variables.a_tf_wp_conductor/ap)',a_tf_wp_conductor/ap, 'OP ')
                # po.ovarre(self.outfile,'Conduit fraction of winding pack','(tfcoil_variables.n_tf_coil_turns*tfcoil_variables.a_tf_turn_steel/ap)',n_tf_coil_turns*tfcoil_variables.a_tf_turn_steel/ap, 'OP ')
                # po.ovarre(self.outfile,'Insulator fraction of winding pack','(tfcoil_variables.a_tf_coil_wp_turn_insulation/ap)',a_tf_coil_wp_turn_insulation/ap, 'OP ')
                # po.ovarre(self.outfile,'Helium area fraction of winding pack excluding central channel','(tfcoil_variables.a_tf_wp_extra_void/ap)',a_tf_wp_extra_void/ap, 'OP ')
                # po.ovarre(self.outfile,'Central helium channel area as fraction of winding pack','(tfcoil_variables.a_tf_wp_coolant_channels/ap)',a_tf_wp_coolant_channels/ap, 'OP ')
                ap = (
                    tfcoil_variables.a_tf_wp_conductor
                    + tfcoil_variables.n_tf_coil_turns * tfcoil_variables.a_tf_turn_steel
                    + tfcoil_variables.a_tf_coil_wp_turn_insulation
                    + tfcoil_variables.a_tf_wp_extra_void
                    + tfcoil_variables.a_tf_wp_coolant_channels
                )
                po.ovarrf(
                    self.outfile,
                    "Check total area fractions in winding pack = 1",
                    "",
                    (
                        tfcoil_variables.a_tf_wp_conductor
                        + tfcoil_variables.n_tf_coil_turns
                        * tfcoil_variables.a_tf_turn_steel
                        + tfcoil_variables.a_tf_coil_wp_turn_insulation
                        + tfcoil_variables.a_tf_wp_extra_void
                        + tfcoil_variables.a_tf_wp_coolant_channels
                    )
                    / ap,
                )
                po.ovarrf(
                    self.outfile,
                    "minimum TF conductor temperature margin  (K)",
                    "(temp_tf_superconductor_margin_min)",
                    tfcoil_variables.temp_tf_superconductor_margin_min,
                )
                po.ovarrf(
                    self.outfile,
                    "TF conductor temperature margin (K)",
                    "(temp_tf_superconductor_margin)",
                    tfcoil_variables.temp_tf_superconductor_margin,
                )

                po.ovarin(
                    self.outfile,
                    "Elastic properties behavior",
                    "(i_tf_cond_eyoung_axial)",
                    tfcoil_variables.i_tf_cond_eyoung_axial,
                )
                if tfcoil_variables.i_tf_cond_eyoung_axial == 0:
                    po.ocmmnt(self.outfile, "  Conductor stiffness neglected")
                elif tfcoil_variables.i_tf_cond_eyoung_axial == 1:
                    po.ocmmnt(self.outfile, "  Conductor stiffness is user-input")
                elif tfcoil_variables.i_tf_cond_eyoung_axial == 2:
                    po.ocmmnt(
                        self.outfile,
                        "  Conductor stiffness is set by material-specific default",
                    )

                po.ovarre(
                    self.outfile,
                    "Conductor axial Youngs modulus",
                    "(eyoung_cond_axial)",
                    tfcoil_variables.eyoung_cond_axial,
                )
                po.ovarre(
                    self.outfile,
                    "Conductor transverse Youngs modulus",
                    "(eyoung_cond_trans)",
                    tfcoil_variables.eyoung_cond_trans,
                )
        else:
            # External casing
            po.osubhd(self.outfile, "Bucking cylinder information:")
            po.ovarre(
                self.outfile,
                "Casing cross section area (per leg) (m2)",
                "(a_tf_coil_inboard_case)",
                tfcoil_variables.a_tf_coil_inboard_case,
            )
            po.ovarre(
                self.outfile,
                "Inboard leg case plasma side wall thickness (m)",
                "(dr_tf_plasma_case)",
                tfcoil_variables.dr_tf_plasma_case,
            )
            po.ovarre(
                self.outfile,
                "Inboard leg plasma case area (m^2)",
                "(a_tf_plasma_case)",
                superconducting_tf_coil_variables.a_tf_plasma_case,
            )
            po.ovarre(
                self.outfile,
                "Inboard leg bucking cylinder thickness (m)",
                "(dr_tf_nose_case)",
                tfcoil_variables.dr_tf_nose_case,
            )
            po.ovarre(
                self.outfile,
                'Inboard leg case inboard "nose" area (m^2)',
                "(a_tf_coil_nose_case)",
                superconducting_tf_coil_variables.a_tf_coil_nose_case,
            )

            # Conductor layer geometry
            po.osubhd(self.outfile, "Inboard TFC conductor sector geometry:")
            po.ovarre(
                self.outfile,
                "Inboard TFC conductor sector area with gr insulation (per leg) (m2)",
                "(a_tf_wp_with_insulation)",
                superconducting_tf_coil_variables.a_tf_wp_with_insulation,
            )
            po.ovarre(
                self.outfile,
                "Inboard TFC conductor sector area, NO ground & gap (per leg) (m2)",
                "(a_tf_wp_no_insulation)",
                superconducting_tf_coil_variables.a_tf_wp_no_insulation,
            )
            po.ovarre(
                self.outfile,
                "Ground wall insulation area (m^2)",
                "(a_tf_wp_ground_insulation)",
                superconducting_tf_coil_variables.a_tf_wp_ground_insulation,
            )
            po.ovarre(
                self.outfile,
                "Inboard conductor sector radial thickness (m)",
                "(dr_tf_wp_with_insulation)",
                tfcoil_variables.dr_tf_wp_with_insulation,
            )
            if physics_variables.itart == 1:
                po.ovarre(
                    self.outfile,
                    "Central collumn top conductor sector radial thickness (m)",
                    "(dr_tf_wp_top)",
                    superconducting_tf_coil_variables.dr_tf_wp_top,
                )

            po.ovarre(
                self.outfile,
                "Ground wall insulation thickness (m)",
                "(dx_tf_wp_insulation)",
                tfcoil_variables.dx_tf_wp_insulation,
            )
            # Turn info
            po.osubhd(self.outfile, "Coil turn information:")
            po.ovarre(
                self.outfile,
                "Number of turns per TF leg",
                "(n_tf_coil_turns)",
                tfcoil_variables.n_tf_coil_turns,
            )
            po.ovarre(
                self.outfile,
                "Turn insulation thickness",
                "(dx_tf_turn_insulation)",
                tfcoil_variables.dx_tf_turn_insulation,
            )
            po.ovarre(
                self.outfile,
                "Mid-plane CP cooling fraction",
                "(fcoolcp)",
                tfcoil_variables.fcoolcp,
            )
            po.ovarre(
                self.outfile,
                "Area of resistive conductor per coil",
                "(a_res_tf_coil_conductor)",
                tfcoil_variables.a_res_tf_coil_conductor,
            )
            po.ovarre(
                self.outfile,
                "Outboard leg current per turn (A)",
                "(c_tf_turn)",
                tfcoil_variables.c_tf_turn,
            )
            po.ovarre(
                self.outfile,
                "Inboard leg conductor volume (m3)",
                "(vol_cond_cp)",
                tfcoil_variables.vol_cond_cp,
            )
            po.ovarre(
                self.outfile,
                "Outboard leg volume per coil (m3)",
                "(voltfleg)",
                tfcoil_variables.voltfleg,
            )

        # Coil masses
        po.osubhd(self.outfile, "TF coil mass:")
        po.ovarre(
            self.outfile,
            "Superconductor mass per coil (kg)",
            "(m_tf_coil_superconductor)",
            tfcoil_variables.m_tf_coil_superconductor,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Copper mass per coil (kg)",
            "(m_tf_coil_copper)",
            tfcoil_variables.m_tf_coil_copper,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Steel conduit mass per coil (kg)",
            "(m_tf_wp_steel_conduit)",
            tfcoil_variables.m_tf_wp_steel_conduit,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Conduit insulation mass per coil (kg)",
            "(m_tf_coil_wp_turn_insulation)",
            tfcoil_variables.m_tf_coil_wp_turn_insulation,
            "OP ",
        )
        if tfcoil_variables.i_tf_sup == 1:
            po.ovarre(
                self.outfile,
                "Total conduit mass per coil (kg)",
                "(m_tf_coil_conductor)",
                tfcoil_variables.m_tf_coil_conductor,
                "OP ",
            )

        if physics_variables.itart == 1:
            po.ovarre(
                self.outfile,
                "Mass of inboard legs (kg)",
                "(whtcp)",
                tfcoil_variables.whtcp,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Mass of outboard legs (kg)",
                "(whttflgs)",
                tfcoil_variables.whttflgs,
                "OP ",
            )

        po.ovarre(
            self.outfile,
            "Mass of each TF coil (kg)",
            "(m_tf_coils_total/n_tf_coils)",
            tfcoil_variables.m_tf_coils_total / tfcoil_variables.n_tf_coils,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Total TF coil mass (kg)",
            "(m_tf_coils_total)",
            tfcoil_variables.m_tf_coils_total,
            "OP ",
        )

        # TF current and field
        po.osubhd(self.outfile, "Maximum B field and currents:")
        po.ovarre(
            self.outfile,
            "Nominal peak field assuming toroidal symmetry (T)",
            "(b_tf_inboard_peak_symmetric)",
            tfcoil_variables.b_tf_inboard_peak_symmetric,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Radius of maximum field position on inboard TF coil (m)",
            "(r_b_tf_inboard_peak)",
            tfcoil_variables.r_b_tf_inboard_peak,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Total current in all TF coils (MA)",
            "(c_tf_total/1.D6)",
            1.0e-6 * tfcoil_variables.c_tf_total,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "TF coil current (summed over all coils) (A)",
            "(c_tf_total)",
            tfcoil_variables.c_tf_total,
        )
        if tfcoil_variables.i_tf_sup == 1:
            po.ovarre(
                self.outfile,
                "Actual peak field at discrete conductor (T)",
                "(b_tf_inboard_peak_with_ripple)",
                tfcoil_variables.b_tf_inboard_peak_with_ripple,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Ratio of peak field with ripple to nominal axisymmetric peak field",
                "(f_b_tf_inboard_peak_ripple_symmetric)",
                superconducting_tf_coil_variables.f_b_tf_inboard_peak_ripple_symmetric,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Winding pack current density (A/m2)",
                "(j_tf_wp)",
                tfcoil_variables.j_tf_wp,
                "OP ",
            )

        po.ovarre(
            self.outfile,
            "Inboard leg mid-plane conductor current density (A/m2)",
            "(oacdcp)",
            tfcoil_variables.oacdcp,
        )
        if physics_variables.itart == 1:
            po.ovarre(
                self.outfile,
                "Outboard leg conductor current density (A/m2)",
                "(cdtfleg)",
                tfcoil_variables.cdtfleg,
            )
        po.ovarre(
            self.outfile,
            "Self inductance of a TF coil (H)",
            "(ind_tf_coil)",
            tfcoil_variables.ind_tf_coil,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Total stored energy in TF coils (GJ)",
            "(e_tf_magnetic_stored_total_gj)",
            tfcoil_variables.e_tf_magnetic_stored_total_gj,
            "OP ",
        )

        po.ovarre(
            self.outfile,
            "Total magnetic energy in a TF coil (J)",
            "(e_tf_coil_magnetic_stored)",
            tfcoil_variables.e_tf_coil_magnetic_stored,
            "OP ",
        )

        # TF forces
        po.osubhd(self.outfile, "TF Forces:")
        po.ovarre(
            self.outfile,
            "Inboard vertical tension per coil (N)",
            "(vforce)",
            tfcoil_variables.vforce,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Outboard vertical tension per coil (N)",
            "(vforce_outboard)",
            tfcoil_variables.vforce_outboard,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "inboard vertical tension fraction (-)",
            "(f_vforce_inboard)",
            tfcoil_variables.f_vforce_inboard,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Centring force per coil (N/m)",
            "(cforce)",
            tfcoil_variables.cforce,
            "OP ",
        )

        # Resistive coil parameters
        if tfcoil_variables.i_tf_sup != 1:
            po.osubhd(self.outfile, "Resitive loss parameters:")
            if tfcoil_variables.i_tf_sup == 0:
                po.ocmmnt(
                    self.outfile,
                    "Resistive Material : GLIDCOP AL-15 - Dispersion Strengthened Copper",
                )
            elif tfcoil_variables.i_tf_sup == 2:
                po.ocmmnt(
                    self.outfile, "Resistive Material : Pure Aluminium (99.999+ %)"
                )

            if physics_variables.itart == 1:
                po.ovarre(
                    self.outfile,
                    "CP resistivity (ohm.m)",
                    "(rho_cp)",
                    tfcoil_variables.rho_cp,
                )
                po.ovarre(
                    self.outfile,
                    "Leg resistivity (ohm.m)",
                    "(rho_tf_leg)",
                    tfcoil_variables.rho_tf_leg,
                )
                po.ovarre(
                    self.outfile,
                    "CP resistive power loss (W)",
                    "(p_cp_resistive)",
                    tfcoil_variables.p_cp_resistive,
                )
                po.ovarre(
                    self.outfile,
                    "Total legs resitive power loss, (W)",
                    "(p_tf_leg_resistive)",
                    tfcoil_variables.p_tf_leg_resistive,
                )
                po.ovarre(
                    self.outfile,
                    "joints resistive power loss (W)",
                    "(p_tf_joints_resistive)",
                    tfcoil_variables.p_tf_joints_resistive,
                )
                po.ovarre(
                    self.outfile,
                    "Outboard leg resistance per coil (ohm)",
                    "(res_tf_leg)",
                    tfcoil_variables.res_tf_leg,
                )
                po.ovarre(
                    self.outfile,
                    "Average CP temperature (K)",
                    "(temp_cp_average)",
                    tfcoil_variables.temp_cp_average,
                )
                po.ovarre(
                    self.outfile,
                    "Average leg temperature (K)",
                    "(temp_tf_legs_outboard)",
                    tfcoil_variables.temp_tf_legs_outboard,
                )

            else:
                po.ovarre(
                    self.outfile,
                    "TF resistivity (ohm.m)",
                    "(p_cp_resistive)",
                    tfcoil_variables.rho_cp,
                )
                po.ovarre(
                    self.outfile,
                    "TF coil resistive power less (total) (ohm.m)",
                    "(p_cp_resistive)",
                    tfcoil_variables.p_cp_resistive,
                )
                po.ovarre(
                    self.outfile,
                    "Average coil temperature (K)",
                    "(temp_cp_average)",
                    tfcoil_variables.temp_cp_average,
                )

        # Ripple calculations
        po.osubhd(self.outfile, "Ripple information:")
        if tfcoil_variables.i_tf_shape == 1:
            po.ovarre(
                self.outfile,
                "Max allowed tfcoil_variables.ripple amplitude at plasma outboard midplane (%)",
                "(ripple_b_tf_plasma_edge_max)",
                tfcoil_variables.ripple_b_tf_plasma_edge_max,
            )
            po.ovarre(
                self.outfile,
                "Ripple amplitude at plasma outboard midplane (%)",
                "(ripple_b_tf_plasma_edge)",
                tfcoil_variables.ripple_b_tf_plasma_edge,
                "OP ",
            )
        else:
            po.ovarre(
                self.outfile,
                "Max allowed tfcoil_variables.ripple amplitude at plasma (%)",
                "(ripple_b_tf_plasma_edge_max)",
                tfcoil_variables.ripple_b_tf_plasma_edge_max,
            )
            po.ovarre(
                self.outfile,
                "Ripple at plasma edge (%)",
                "(ripple_b_tf_plasma_edge)",
                tfcoil_variables.ripple_b_tf_plasma_edge,
            )
            po.ocmmnt(
                self.outfile,
                "  Ripple calculation to be re-defined for picure frame coils",
            )

        # Quench information
        if tfcoil_variables.i_tf_sup == 1:
            po.osubhd(self.outfile, "Quench information :")
            po.ovarre(
                self.outfile,
                "Actual quench time (or time constant) (s)",
                "(t_tf_superconductor_quench)",
                tfcoil_variables.t_tf_superconductor_quench,
            )
            po.ovarre(
                self.outfile,
                "Vacuum Vessel stress on quench (Pa)",
                "(vv_stress_quench)",
                superconducting_tf_coil_variables.vv_stress_quench,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Maximum allowed voltage during quench due to insulation (kV)",
                "(v_tf_coil_dump_quench_max_kv)",
                tfcoil_variables.v_tf_coil_dump_quench_max_kv,
            )
            po.ovarre(
                self.outfile,
                "Actual quench voltage (kV)",
                "(v_tf_coil_dump_quench_kv)",
                tfcoil_variables.v_tf_coil_dump_quench_kv,
                "OP ",
            )

            if tfcoil_variables.i_tf_sc_mat in (1, 2, 3, 4, 5):
                po.ovarre(
                    self.outfile,
                    "Maximum allowed temp during a quench (K)",
                    "(temp_tf_conductor_quench_max)",
                    tfcoil_variables.temp_tf_conductor_quench_max,
                )
            elif tfcoil_variables == 6:
                po.ocmmnt(self.outfile, "CroCo cable with jacket: ")

                if 75 in numerics.icc:
                    po.ovarre(
                        self.outfile,
                        "Maximum permitted TF coil current / copper area (A/m2)",
                        "(copperA_m2_max)",
                        rebco_variables.coppera_m2_max,
                    )

                po.ovarre(
                    self.outfile,
                    "Actual TF coil current / copper area (A/m2)",
                    "(copperA_m2)",
                    rebco_variables.coppera_m2,
                )

        # TF coil radial build
        po.osubhd(self.outfile, "Radial build of TF coil centre-line :")
        # po.write(self.outfile,5)
        # 5   format(t43,'Thickness (m)',t60,'Outer radius (m)')

        radius = build_variables.r_tf_inboard_in
        po.obuild(self.outfile, "Innermost edge of TF coil", radius, radius)

        # Radial build for SC TF coils
        if tfcoil_variables.i_tf_sup == 1:
            radius = radius + tfcoil_variables.dr_tf_nose_case
            po.obuild(
                self.outfile,
                'Coil case ("nose")',
                tfcoil_variables.dr_tf_nose_case,
                radius,
                "(dr_tf_nose_case)",
            )

            radius = radius + tfcoil_variables.dx_tf_wp_insertion_gap
            po.obuild(
                self.outfile,
                "Insertion gap for winding pack",
                tfcoil_variables.dx_tf_wp_insertion_gap,
                radius,
                "(dx_tf_wp_insertion_gap)",
            )

            radius = radius + tfcoil_variables.dx_tf_wp_insulation
            po.obuild(
                self.outfile,
                "Winding pack ground insulation",
                tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(dx_tf_wp_insulation)",
            )

            radius = (
                radius
                + 0.5e0 * tfcoil_variables.dr_tf_wp_with_insulation
                - tfcoil_variables.dx_tf_wp_insulation
                - tfcoil_variables.dx_tf_wp_insertion_gap
            )
            po.obuild(
                self.outfile,
                "Winding - first half",
                tfcoil_variables.dr_tf_wp_with_insulation / 2e0
                - tfcoil_variables.dx_tf_wp_insulation
                - tfcoil_variables.dx_tf_wp_insertion_gap,
                radius,
                "(dr_tf_wp_with_insulation/2-dx_tf_wp_insulation-dx_tf_wp_insertion_gap)",
            )

            radius = (
                radius
                + 0.5e0 * tfcoil_variables.dr_tf_wp_with_insulation
                - tfcoil_variables.dx_tf_wp_insulation
                - tfcoil_variables.dx_tf_wp_insertion_gap
            )
            po.obuild(
                self.outfile,
                "Winding - second half",
                tfcoil_variables.dr_tf_wp_with_insulation / 2e0
                - tfcoil_variables.dx_tf_wp_insulation
                - tfcoil_variables.dx_tf_wp_insertion_gap,
                radius,
                "(dr_tf_wp_with_insulation/2-dx_tf_wp_insulation-dx_tf_wp_insertion_gap)",
            )

            radius = radius + tfcoil_variables.dx_tf_wp_insulation
            po.obuild(
                self.outfile,
                "Winding pack insulation",
                tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(dx_tf_wp_insulation)",
            )

            radius = radius + tfcoil_variables.dx_tf_wp_insertion_gap
            po.obuild(
                self.outfile,
                "Insertion gap for winding pack",
                tfcoil_variables.dx_tf_wp_insertion_gap,
                radius,
                "(dx_tf_wp_insertion_gap)",
            )

            radius = radius + tfcoil_variables.dr_tf_plasma_case
            po.obuild(
                self.outfile,
                "Plasma side case min radius",
                tfcoil_variables.dr_tf_plasma_case,
                radius,
                "(dr_tf_plasma_case)",
            )

            radius = radius / np.cos(np.pi / tfcoil_variables.n_tf_coils)
            po.obuild(
                self.outfile,
                "Plasma side case max radius",
                build_variables.r_tf_inboard_out,
                radius,
                "(r_tf_inboard_out)",
            )

        # Radial build for restive coil
        else:
            radius = radius + tfcoil_variables.dr_tf_nose_case
            po.obuild(
                self.outfile,
                "Coil bucking cylindre",
                tfcoil_variables.dr_tf_nose_case,
                radius,
                "(dr_tf_nose_case)",
            )

            radius = radius + tfcoil_variables.dx_tf_wp_insulation
            po.obuild(
                self.outfile,
                "Conductor ground insulation",
                tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(dx_tf_wp_insulation)",
            )

            radius = (
                radius
                + 0.5e0 * tfcoil_variables.dr_tf_wp_with_insulation
                - tfcoil_variables.dx_tf_wp_insulation
            )
            po.obuild(
                self.outfile,
                "Conductor - first half",
                tfcoil_variables.dr_tf_wp_with_insulation / 2e0
                - tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(tfcoil_variables.dr_tf_wp_with_insulation/2-tfcoil_variables.dx_tf_wp_insulation)",
            )

            radius = (
                radius
                + 0.5e0 * tfcoil_variables.dr_tf_wp_with_insulation
                - tfcoil_variables.dx_tf_wp_insulation
            )
            po.obuild(
                self.outfile,
                "Conductor - second half",
                tfcoil_variables.dr_tf_wp_with_insulation / 2e0
                - tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(tfcoil_variables.dr_tf_wp_with_insulation/2-tfcoil_variables.dx_tf_wp_insulation)",
            )

            radius = radius + tfcoil_variables.dx_tf_wp_insulation
            po.obuild(
                self.outfile,
                "Conductor ground insulation",
                tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(dx_tf_wp_insulation)",
            )

            radius = radius + tfcoil_variables.dr_tf_plasma_case
            po.obuild(
                self.outfile,
                "Plasma side TF coil support",
                tfcoil_variables.dr_tf_plasma_case,
                radius,
                "(dr_tf_plasma_case)",
            )

        # Radial build consistency check
        if (
            abs(radius - build_variables.r_tf_inboard_in - build_variables.dr_tf_inboard)
            < 10.0e0 * np.finfo(float(radius)).eps
        ):
            po.ocmmnt(self.outfile, "TF coil dimensions are consistent")
        else:
            po.ocmmnt(self.outfile, "ERROR: TF coil dimensions are NOT consistent:")
            po.ovarre(
                self.outfile,
                "Radius of plasma-facing side of inner leg SHOULD BE [m]",
                "",
                build_variables.r_tf_inboard_in + build_variables.dr_tf_inboard,
            )
            po.ovarre(
                self.outfile,
                "Inboard TF coil radial thickness [m]",
                "(dr_tf_inboard)",
                build_variables.dr_tf_inboard,
            )
            po.oblnkl(self.outfile)

        tf_total_height = (
            build_variables.dh_tf_inner_bore + 2 * build_variables.dr_tf_inboard
        )
        tf_total_width = (
            build_variables.dr_tf_inner_bore
            + build_variables.dr_tf_inboard
            + build_variables.dr_tf_outboard
        )
        po.oblnkl(self.outfile)
        po.obuild(
            self.outfile,
            "Total height and width of TFC [m]",
            tf_total_height,
            tf_total_width,
        )

        # Top section TF coil radial build (physics_variables.itart = 1 only)
        if physics_variables.itart == 1 and tfcoil_variables.i_tf_sup != 1:
            po.osubhd(self.outfile, "Radial build of TF coil at central collumn top :")
            # write(self.outfile,5)

            # Restart the radial build at bucking cylindre inner radius
            radius = build_variables.r_tf_inboard_in
            po.obuild(self.outfile, "Innermost edge of TF coil", radius, radius)

            radius = radius + tfcoil_variables.dr_tf_nose_case
            po.obuild(
                self.outfile,
                "Coil bucking cylindre",
                tfcoil_variables.dr_tf_nose_case,
                radius,
                "(dr_tf_nose_case)",
            )

            radius = radius + tfcoil_variables.dx_tf_wp_insulation
            po.obuild(
                self.outfile,
                "Conductor ground insulation",
                tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(dx_tf_wp_insulation)",
            )

            radius = (
                radius
                + 0.5e0 * superconducting_tf_coil_variables.dr_tf_wp_top
                - tfcoil_variables.dx_tf_wp_insulation
            )
            po.obuild(
                self.outfile,
                "Conductor - first half",
                0.5e0 * superconducting_tf_coil_variables.dr_tf_wp_top
                - tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(dr_tf_wp_top/2-dx_tf_wp_insulation)",
            )

            radius = (
                radius
                + 0.5e0 * superconducting_tf_coil_variables.dr_tf_wp_top
                - tfcoil_variables.dx_tf_wp_insulation
            )
            po.obuild(
                self.outfile,
                "Conductor - second half",
                0.5e0 * superconducting_tf_coil_variables.dr_tf_wp_top
                - tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(dr_tf_wp_top/2-dx_tf_wp_insulation)",
            )

            radius = radius + tfcoil_variables.dx_tf_wp_insulation
            po.obuild(
                self.outfile,
                "Conductor ground insulation",
                tfcoil_variables.dx_tf_wp_insulation,
                radius,
                "(dx_tf_wp_insulation)",
            )

            radius = radius + tfcoil_variables.dr_tf_plasma_case
            po.obuild(
                self.outfile,
                "Plasma side TF coil support",
                tfcoil_variables.dr_tf_plasma_case,
                radius,
                "(dr_tf_plasma_case)",
            )

            # Consistency check
            if abs(radius - build_variables.r_cp_top) < np.finfo(float(radius)).eps:
                po.ocmmnt(self.outfile, "Top TF coil dimensions are consistent")
            else:
                po.ocmmnt(self.outfile, "ERROR: TF coil dimensions are NOT consistent:")
                po.ovarre(
                    self.outfile,
                    "Radius of plasma-facing side of inner leg SHOULD BE [m]",
                    "",
                    build_variables.r_cp_top,
                )
                po.oblnkl(self.outfile)

    @staticmethod
    def circumference(aaa, bbb):
        """Calculate ellipse arc circumference using Ramanujan approximation (m)
        See https://www.johndcook.com/blog/2013/05/05/ramanujan-circumference-ellipse/
        for a discussion of the precision of the formula

        An ellipse has the following formula: (x/a)² + (y/b)² = 1

        Parameters
        ----------
        aaa : float
            the value of a in the formula of the ellipse.
        bbb : float
            the value of b in the formula of the ellipse.

        Returns
        -------
        float
            an approximation of the circumference of the ellipse
        """
        hh = (aaa - bbb) ** 2 / (aaa + bbb) ** 2
        return (
            np.pi
            * (aaa + bbb)
            * (1.0e0 + (3.0e0 * hh) / (10.0e0 + np.sqrt(4.0e0 - 3.0e0 * hh)))
        )

    def cntrpst(self):
        """Evaluates the properties of a TART centrepost

        outfile : input integer : output file unit
        iprint : input integer : switch for writing to output file (1=yes)
        This subroutine evaluates the parameters of the centrepost for a
        tight aspect ratio tokamak. The centrepost is assumed to be tapered,
        i.e. narrowest on the midplane (z=0).
        """

        # Vertical distance from the midplane to the top of the tapered section [m]
        if physics_variables.itart == 1:
            superconducting_tf_coil_variables.z_cp_top = (
                build_variables.z_plasma_xpoint_upper + tfcoil_variables.dztop
            )

        if physics_variables.itart == 1 and tfcoil_variables.i_tf_sup != 1:
            tfcoil_variables.dx_tf_inboard_out_toroidal = (
                2.0e0
                * build_variables.r_cp_top
                * np.sin(
                    superconducting_tf_coil_variables.rad_tf_coil_inboard_toroidal_half
                )
            )

        # Temperature margin used in calculations (K)
        tmarg = 10.0e0

        # Number of integral step used for the coolant temperature rise
        n_tcool_it = 20

        # Coolant channels:
        acool = (
            tfcoil_variables.a_cp_cool * tfcoil_variables.n_tf_coils
        )  # Cooling cross-sectional area
        dcool = 2.0e0 * tfcoil_variables.radius_cp_coolant_channel  # Diameter
        lcool = 2.0e0 * (bv.z_tf_inside_half + bv.dr_tf_outboard)  # Length
        tfcoil_variables.n_cp_coolant_channels_total = acool / (
            np.pi * tfcoil_variables.radius_cp_coolant_channel**2
        )  # Number

        # Average conductor cross-sectional area to cool (with cooling area)
        acpav = (
            0.5e0
            * tfcoil_variables.vol_cond_cp
            / (bv.z_tf_inside_half + bv.dr_tf_outboard)
            + acool
        )
        ro = (acpav / (np.pi * tfcoil_variables.n_cp_coolant_channels_total)) ** 0.5

        # Inner legs total heating power (to be removed by coolant)
        ptot = tfcoil_variables.p_cp_resistive + fwbs_variables.pnuc_cp_tf * 1.0e6

        # Temperature calculations
        # -------------------------
        # Temperature rise in coolant (inlet to outlet)
        # **********************************************
        # Water coollant
        # --------------
        if tfcoil_variables.i_tf_sup == 0:
            # Water coolant physical properties
            coolant_density = constants.DENH2O
            coolant_cp = constants.CPH2O
            coolant_visco = constants.MUH2O
            coolant_th_cond = constants.KH2O

            # Mass flow rate [kg/s]
            cool_mass_flow = (
                acool * coolant_density * tfcoil_variables.vel_cp_coolant_midplane
            )

            # Water temperature rise
            tfcoil_variables.dtemp_cp_coolant = ptot / (cool_mass_flow * coolant_cp)

            # Constant coolant velocity
            vcool_max = tfcoil_variables.vel_cp_coolant_midplane
            # --------------

        # Helium coolant
        # --------------
        elif tfcoil_variables.i_tf_sup == 2:
            # Inlet coolant density [kg/m3]
            coolant_density = self.he_density(tfcoil_variables.temp_cp_coolant_inlet)

            # Mass flow rate [kg/s]
            cool_mass_flow = (
                acool * coolant_density * tfcoil_variables.vel_cp_coolant_midplane
            )

            # Infinitesimal power deposition used in the integral
            dptot = ptot / n_tcool_it

            tcool_calc = copy.copy(tfcoil_variables.temp_cp_coolant_inlet)  # K
            for _i in range(n_tcool_it):
                # Thermal capacity Cp
                coolant_cp = self.he_cp(tcool_calc)

                # Temperature infinitesimal increase
                tcool_calc += dptot / (cool_mass_flow * coolant_cp)

            # Outlet coolant density (minimal coolant density value)
            coolant_density = self.he_density(tcool_calc)

            # Maxium coolant velocity
            vcool_max = cool_mass_flow / (acool * coolant_density)

            # Getting the global in-outlet temperature increase
            tfcoil_variables.dtemp_cp_coolant = (
                tcool_calc - tfcoil_variables.temp_cp_coolant_inlet
            )
        # --------------

        # Average coolant temperature
        tcool_av = (
            tfcoil_variables.temp_cp_coolant_inlet
            + 0.5e0 * tfcoil_variables.dtemp_cp_coolant
        )
        # **********************************************

        # Film temperature rise
        # *********************
        # Rem : The helium cooling properties are calculated using the outlet ones
        # this is not an exact approximation for average temperature rise

        # Helium viscosity
        if tfcoil_variables.i_tf_sup == 2:
            coolant_visco = self.he_visco(tcool_av)

        # Reynolds number
        reyn = (
            coolant_density
            * tfcoil_variables.vel_cp_coolant_midplane
            * dcool
            / coolant_visco
        )

        # Helium thermal conductivity [W/(m.K)]
        if tfcoil_variables.i_tf_sup == 2:
            coolant_th_cond = self.he_th_cond(tcool_av)

        # Prandlt number
        prndtl = coolant_cp * coolant_visco / coolant_th_cond

        # Film temperature difference calculations
        # Originally prandtl was prndtl**0.3e0 but this is incorrect as from
        # Dittus-Boelter correlation where the fluid is being heated it should be as below
        nuselt = 0.023e0 * reyn**0.8e0 * prndtl**0.4e0
        h = nuselt * coolant_th_cond / dcool
        dtfilmav = ptot / (
            h
            * 2.0e0
            * np.pi
            * tfcoil_variables.radius_cp_coolant_channel
            * tfcoil_variables.n_cp_coolant_channels_total
            * lcool
        )

        # Average film temperature (in contact with te conductor)
        tcool_film = tcool_av + dtfilmav
        # *********************

        # Temperature rise in conductor
        # ------------------------------
        # Conductor thermal conductivity
        # ******
        # Copper conductor
        if tfcoil_variables.i_tf_sup == 0:
            conductor_th_cond = constants.K_COPPER

        # Aluminium
        elif tfcoil_variables.i_tf_sup == 2:
            conductor_th_cond = self.al_th_cond(tcool_film)
        # ******

        # Average temperature rise : To be changed with Garry Voss' better documented formula ?
        dtcncpav = (
            (ptot / tfcoil_variables.vol_cond_cp)
            / (
                2.0e0
                * conductor_th_cond
                * (ro**2 - tfcoil_variables.radius_cp_coolant_channel**2)
            )
            * (
                ro**2 * tfcoil_variables.radius_cp_coolant_channel**2
                - 0.25e0 * tfcoil_variables.radius_cp_coolant_channel**4
                - 0.75e0 * ro**4
                + ro**4 * np.log(ro / tfcoil_variables.radius_cp_coolant_channel)
            )
        )

        # Peak temperature rise : To be changed with Garry Voss' better documented formula ?
        dtconcpmx = (
            (ptot / tfcoil_variables.vol_cond_cp)
            / (2.0e0 * conductor_th_cond)
            * (
                (tfcoil_variables.radius_cp_coolant_channel**2 - ro**2) / 2.0e0
                + ro**2 * np.log(ro / tfcoil_variables.radius_cp_coolant_channel)
            )
        )

        # If the average conductor temperature difference is negative, set it to 0
        if dtcncpav < 0.0e0:
            logger.error("Negative conductor average temperature difference, set to 0")
            dtcncpav = 0.0e0

        # If the average conductor temperature difference is negative, set it to 0
        if dtconcpmx < 0.0e0:
            logger.error("Negative conductor peak temperature difference, set to 0")
            dtconcpmx = 0.0e0

        # Average conductor temperature
        tfcoil_variables.tcpav2 = (
            tfcoil_variables.temp_cp_coolant_inlet
            + dtcncpav
            + dtfilmav
            + 0.5e0 * tfcoil_variables.dtemp_cp_coolant
        )

        # Peak wall temperature
        tfcoil_variables.temp_cp_peak = (
            tfcoil_variables.temp_cp_coolant_inlet
            + tfcoil_variables.dtemp_cp_coolant
            + dtfilmav
            + dtconcpmx
        )
        tcoolmx = (
            tfcoil_variables.temp_cp_coolant_inlet
            + tfcoil_variables.dtemp_cp_coolant
            + dtfilmav
        )
        # -------------------------

        # Thermal hydraulics: friction factor from Z. Olujic, Chemical
        # Engineering, Dec. 1981, p. 91
        roughrat = 4.6e-5 / dcool
        fricfac = (
            1.0e0
            / (
                -2.0e0
                * np.log10(
                    roughrat / 3.7e0
                    - 5.02e0 / reyn * np.log10(roughrat / 3.7e0 + 14.5e0 / reyn)
                )
            )
            ** 2
        )

        # Pumping efficiency
        if tfcoil_variables.i_tf_sup == 0:  # Water cooled
            tfcoil_variables.etapump = 0.8e0
        elif tfcoil_variables.i_tf_sup == 2:  # Cryogenic helium
            tfcoil_variables.etapump = 0.6e0

        # Pressure drop calculation
        dpres = (
            fricfac
            * (lcool / dcool)
            * coolant_density
            * 0.5e0
            * tfcoil_variables.vel_cp_coolant_midplane**2
        )
        tfcoil_variables.p_cp_coolant_pump_elec = (
            dpres
            * acool
            * tfcoil_variables.vel_cp_coolant_midplane
            / tfcoil_variables.etapump
        )

        # Critical pressure in saturation pressure calculations (Pa)
        pcrt = 2.24e7

        # Saturation pressure
        # Ref : Keenan, Keyes, Hill, Moore, steam tables, Wiley & Sons, 1969
        # Rem 1 : ONLY VALID FOR WATER !
        # Rem 2 : Not used anywhere else in the code ...
        tclmx = tcoolmx + tmarg
        tclmxs = min(tclmx, 374.0e0)
        fc = 0.65e0 - 0.01e0 * tclmxs
        sum_ = (
            -741.9242e0
            - 29.721e0 * fc
            - 11.55286e0 * fc**2
            - 0.8685635e0 * fc**3
            + 0.1094098e0 * fc**4
            + 0.439993e0 * fc**5
            + 0.2520658e0 * fc**6
            + 0.0518684e0 * fc**7
        )
        psat = pcrt * np.exp(0.01e0 / (tclmxs + 273.0e0) * (374.0e0 - tclmxs) * sum_)
        presin = psat + dpres

        # Output section
        if self.iprint == 1:
            po.oheadr(self.outfile, "Centrepost Coolant Parameters")
            po.ovarre(
                self.outfile,
                "Centrepost coolant fraction",
                "(fcoolcp)",
                tfcoil_variables.fcoolcp,
            )
            po.ovarre(
                self.outfile, "Average coolant channel diameter (m)", "(dcool)", dcool
            )
            po.ovarre(self.outfile, "Coolant channel length (m)", "(lcool)", lcool)
            po.ovarre(
                self.outfile,
                "Inlet coolant flow speed (m/s)",
                "(vel_cp_coolant_midplane)",
                tfcoil_variables.vel_cp_coolant_midplane,
            )
            po.ovarre(
                self.outfile,
                "Outlet coolant flow speed (m/s)",
                "(vcool_max)",
                vcool_max,
            )
            po.ovarre(
                self.outfile,
                "Coolant mass flow rate (kg/s)",
                "(cool_mass_flow)",
                cool_mass_flow,
            )
            po.ovarre(
                self.outfile,
                "Number of coolant tubes",
                "(n_cp_coolant_channels_total)",
                tfcoil_variables.n_cp_coolant_channels_total,
            )
            po.ovarre(self.outfile, "Reynolds number", "(reyn)", reyn)
            po.ovarre(self.outfile, "Prandtl number", "(prndtl)", prndtl)
            po.ovarre(self.outfile, "Nusselt number", "(nuselt)", nuselt)

            po.osubhd(self.outfile, "Resistive Heating :")
            po.ovarre(
                self.outfile,
                "Average conductor resistivity (ohm.m)",
                "(rho_cp)",
                tfcoil_variables.rho_cp,
            )
            po.ovarre(
                self.outfile,
                "Resistive heating (MW)",
                "(p_cp_resistive/1.0e6)",
                tfcoil_variables.p_cp_resistive / 1.0e6,
            )
            po.ovarre(
                self.outfile,
                "Nuclear heating (MW)",
                "(pnuc_cp_tf)",
                fwbs_variables.pnuc_cp_tf,
            )
            po.ovarre(self.outfile, "Total heating (MW)", "(ptot/1.0e6)", ptot / 1.0e6)

            po.osubhd(self.outfile, "Temperatures :")
            po.ovarre(
                self.outfile,
                "Input coolant temperature (K)",
                "(tfcoil_variables.temp_cp_coolant_inlet)",
                tfcoil_variables.temp_cp_coolant_inlet,
            )
            po.ovarre(
                self.outfile,
                "Input-output coolant temperature rise (K)",
                "(dtemp_cp_coolant)",
                tfcoil_variables.dtemp_cp_coolant,
            )
            po.ovarre(self.outfile, "Film temperature rise (K)", "(dtfilmav)", dtfilmav)
            po.ovarre(
                self.outfile,
                "Average temp gradient in conductor (K/m)",
                "(dtcncpav)",
                dtcncpav,
            )
            po.ovarre(
                self.outfile,
                "Average centrepost temperature (K)",
                "(tcpav2)",
                tfcoil_variables.tcpav2,
            )
            po.ovarre(
                self.outfile,
                "Peak centrepost temperature (K)",
                "(temp_cp_peak)",
                tfcoil_variables.temp_cp_peak,
            )

            po.osubhd(self.outfile, "Pump Power :")
            po.ovarre(self.outfile, "Coolant pressure drop (Pa)", "(dpres)", dpres)
            if (
                tfcoil_variables.i_tf_sup == 0
            ):  # Saturation pressure calculated with Water data ...
                po.ovarre(
                    self.outfile, "Coolant inlet pressure (Pa)", "(presin)", presin
                )

            po.ovarre(
                self.outfile,
                "Pump power (W)",
                "(p_cp_coolant_pump_elec)",
                tfcoil_variables.p_cp_coolant_pump_elec,
            )

    def tf_field_and_force(
        self,
        i_tf_sup: int,
        r_tf_wp_inboard_outer: float,
        r_tf_wp_inboard_inner: float,
        r_tf_outboard_in: float,
        dx_tf_wp_insulation: float,
        dx_tf_wp_insertion_gap: float,
        b_tf_inboard_peak_symmetric: float,
        c_tf_total: float,
        n_tf_coils: int,
        dr_tf_plasma_case: float,
        rmajor: float,
        b_plasma_toroidal_on_axis: float,
        r_cp_top: float,
        itart: int,
        i_cp_joints: int,
        f_vforce_inboard: float,
    ) -> tuple[float, float, float, float, float]:
        """Calculates the Toroidal Field (TF) coil field, forces, vacuum vessel (VV) quench considerations,
        and resistive magnet resistance/volume.

        Parameters
        ----------
        i_tf_sup : int
            TF coil support type (1 = superconducting, 0 = resistive copper, 2 = resistive aluminium)
        r_tf_wp_inboard_outer : float
            Outer radius of the inboard winding pack [m]
        r_tf_wp_inboard_inner : float
            Inner radius of the inboard winding pack [m]
        r_tf_outboard_in : float
            Inner radius of the outboard leg [m]
        dx_tf_wp_insulation : float
            Thickness of winding pack ground insulation [m]
        dx_tf_wp_insertion_gap : float
            Thickness of winding pack insertion gap [m]
        b_tf_inboard_peak_symmetric : float
            Peak inboard magnetic field [T]
        c_tf_total : float
            Total current in TF coils [A]
        n_tf_coils : int
            Number of TF coils
        dr_tf_plasma_case : float
            Plasma-facing case thickness [m]
        rmajor : float
            Major radius of the plasma [m]
        b_plasma_toroidal_on_axis : float
            Toroidal magnetic field at plasma center [T]
        r_cp_top : float
            Centrepost outer radius at the top [m]
        itart : int
            TART (tight aspect ratio tokamak) switch (0 = standard, 1 = TART)
        i_cp_joints : ints: int
            Centrepost joints switch (1 = with sliding joints, 0 = without)
        f_vforce_inboard : float
            Inboard vertical tension fraction

        Returns
        -------
        tuple[float, float, float, float]
            Tuple containing:
            - cforce (float): Centering force per TF coil [N/m]
            - vforce (float): Inboard vertical tension [N]
            - vforce_outboard (float): Outboard vertical tension [N]
            - vforce_inboard_tot (float): Total inboard vertical force [N]
            - f_vforce_inboard (float): Inboard vertical tension fraction
        """

        # Outer/inner WP radius removing the ground insulation layer and the insertion gap [m]
        if i_tf_sup == 1:
            r_tf_wp_inboard_outer_conductor = (
                r_tf_wp_inboard_outer - dx_tf_wp_insulation - dx_tf_wp_insertion_gap
            )
            r_tf_wp_inboard_inner_conductor = (
                r_tf_wp_inboard_inner + dx_tf_wp_insulation + dx_tf_wp_insertion_gap
            )
        else:
            r_tf_wp_inboard_outer_conductor = r_tf_wp_inboard_outer - dx_tf_wp_insulation
            r_tf_wp_inboard_inner_conductor = r_tf_wp_inboard_inner + dx_tf_wp_insulation

        # Associated WP thickness
        dr_tf_wp_inboard_conductor = (
            r_tf_wp_inboard_outer_conductor - r_tf_wp_inboard_inner_conductor
        )

        # In plane forces
        # ---
        # Centering force = net inwards radial force per meters per TF coil [N/m]
        cforce = 0.5e0 * b_tf_inboard_peak_symmetric * c_tf_total / n_tf_coils

        # Vertical force per coil [N]
        # ***
        # Rem : this force does not depends on the TF shape or the presence of
        #        sliding joints, the in/outboard vertical tension repartition is
        # -#
        # Ouboard leg WP plasma side radius without ground insulation/insertion gat [m]
        if i_tf_sup == 1:
            r_tf_wp_outboard_inner_conductor = (
                r_tf_outboard_in
                + dr_tf_plasma_case
                + dx_tf_wp_insulation
                + dx_tf_wp_insertion_gap
            )
        else:
            r_tf_wp_outboard_inner_conductor = r_tf_outboard_in + dx_tf_wp_insulation

        # If the TF coil has no dr_bore it would induce division by 0.
        # In this situation, the dr_bore radius is set to a very small value : 1.0e-9 m
        if (
            abs(r_tf_wp_inboard_inner_conductor)
            < np.finfo(float(r_tf_wp_inboard_inner_conductor)).eps
        ):
            r_tf_wp_inboard_inner_conductor = 1.0e-9

        # May the force be with you
        vforce_tot = (
            0.5e0
            * (b_plasma_toroidal_on_axis * rmajor * c_tf_total)
            / (n_tf_coils * dr_tf_wp_inboard_conductor**2)
            * (
                r_tf_wp_inboard_outer_conductor**2
                * np.log(
                    r_tf_wp_inboard_outer_conductor / r_tf_wp_inboard_inner_conductor
                )
                + r_tf_wp_outboard_inner_conductor**2
                * np.log(
                    (r_tf_wp_outboard_inner_conductor + dr_tf_wp_inboard_conductor)
                    / r_tf_wp_outboard_inner_conductor
                )
                + dr_tf_wp_inboard_conductor**2
                * np.log(
                    (r_tf_wp_outboard_inner_conductor + dr_tf_wp_inboard_conductor)
                    / r_tf_wp_inboard_inner_conductor
                )
                - dr_tf_wp_inboard_conductor
                * (r_tf_wp_inboard_outer_conductor + r_tf_wp_outboard_inner_conductor)
                + 2.0e0
                * dr_tf_wp_inboard_conductor
                * (
                    r_tf_wp_inboard_outer_conductor
                    * np.log(
                        r_tf_wp_inboard_inner_conductor / r_tf_wp_inboard_outer_conductor
                    )
                    + r_tf_wp_outboard_inner_conductor
                    * np.log(
                        (r_tf_wp_outboard_inner_conductor + dr_tf_wp_inboard_conductor)
                        / r_tf_wp_outboard_inner_conductor
                    )
                )
            )
        )

        # Case of a centrepost (physics_variables.itart == 1) with sliding joints (the CP vertical are separated from the leg ones)
        # Rem SK : casing/insulation thickness not subtracted as part of the CP is genuinely connected to the legs..
        if itart == 1 and i_cp_joints == 1:
            # CP vertical tension [N]
            vforce = (
                0.25e0
                * (b_plasma_toroidal_on_axis * rmajor * c_tf_total)
                / (n_tf_coils * dr_tf_wp_inboard_conductor**2)
                * (
                    2.0e0
                    * r_tf_wp_inboard_outer_conductor**2
                    * np.log(
                        r_tf_wp_inboard_outer_conductor / r_tf_wp_inboard_inner_conductor
                    )
                    + 2.0e0
                    * dr_tf_wp_inboard_conductor**2
                    * np.log(r_cp_top / r_tf_wp_inboard_inner_conductor)
                    + 3.0e0 * dr_tf_wp_inboard_conductor**2
                    - 2.0e0
                    * dr_tf_wp_inboard_conductor
                    * r_tf_wp_inboard_outer_conductor
                    + 4.0e0
                    * dr_tf_wp_inboard_conductor
                    * r_tf_wp_inboard_outer_conductor
                    * np.log(
                        r_tf_wp_inboard_inner_conductor / r_tf_wp_inboard_outer_conductor
                    )
                )
            )

            # Vertical tension applied on the outer leg [N]
            vforce_outboard = vforce_tot - vforce

            # Inboard vertical tension fraction
            f_vforce_inboard = vforce / vforce_tot

        # Case of TF without joints or with clamped joints vertical tension
        else:
            # Inboard vertical tension [N]
            vforce = f_vforce_inboard * vforce_tot

            # Ouboard vertical tension [N]
            vforce_outboard = vforce * ((1.0e0 / f_vforce_inboard) - 1.0e0)

        # Total vertical force
        vforce_inboard_tot = vforce * n_tf_coils

        return cforce, vforce, vforce_outboard, vforce_inboard_tot, f_vforce_inboard

    @staticmethod
    def he_density(temp: float) -> float:
        """
        Subroutine calculating temperature dependent helium density at 100 bar
        from fit using the following data, valid in [4-50] K
        Ref : R.D. McCarty, Adv. Cryo. Eng., 1990, 35, 1465-1475.

        Parameters
        ----------
        temp : float
            Helium temperature [K]

        Returns
        -------
        type
            density: Heliyn density [kg/m3]
        """

        # Fit range validation
        if temp < 4.0e0 or temp > 50.0e0:
            logger.error(
                f"Helium temperature out of helium property fiting range [4-50] K. {temp=}"
            )

        # Oder 3 polynomial fit
        if temp < 29.5e0:
            density = (
                217.753831e0
                - 1.66564525e0 * temp
                - 0.160654724e0 * temp**2
                + 0.00339003258e0 * temp**3
            )

        # Linear interpolation between the fits to avoid discontinuity
        elif temp < 30.5e0:
            density = 231.40661479377616e0 - 3.917589985552496e0 * temp

        # Oder 2 polynomial fit
        else:
            density = 212.485251e0 - 4.18059786e0 * temp + 0.0289632937e0 * temp**2

        return density

    @staticmethod
    def he_cp(temp: float) -> float:
        """
        Subroutine calculating temperature dependent thermal capacity at
        constant pressures at 100 Bar from fit using the following data
        valid in [4-50] K
        Ref : R.D. McCarty, Adv. Cryo. Eng., 1990, 35, 1465-1475.

        Parameters
        ----------
        temp : float
            Helium temperature [K]

        Returns
        -------
        :
            Themal capacity at constant pressure [K/(kg.K)]
        """

        # Fit range validation
        if temp < 4.0e0 or temp > 50.0e0:
            logger.error(
                f"Helium temperature out of helium property fiting range [4-50] K. {temp=}"
            )

        # Order 3 polynomial fit in [4-30] K on the dimenion [K/(g.K)]
        if temp < 29.5e0:
            cp = (
                -0.834218557e0
                + 0.637079569e0 * temp
                - 0.0208839696e0 * temp**2
                + 0.000233433748e0 * temp**3
            )

        # Linear interpolation between the fits to avoid discontinuity
        elif (
            temp < 30.5e0
        ):  # Linear interpolation between the fits to avoid discontinuity
            cp = 4.924018467550791e0 + 0.028953709588498633e0 * temp

        # Linear fit in [30-60] K on the dimenion [K/(g.K)]
        else:
            cp = 6.11883125e0 - 0.01022048e0 * temp

        # conversion to [K/(kg.K)] and return
        return cp * 1.0e3

    @staticmethod
    def he_visco(temp: float) -> float:
        """
        Subroutine calculating temperature dependent He viscosity at 100 Bar
        from fit using the following data, valid in [4-50] K
        Ref : V.D. Arp,; R.D. McCarty ; Friend, D.G., Technical Note 1334, National
        Institute of Standards and Technology, Boulder, CO, 1998, 0.

        Parameters
        ----------
        temp : float
            Helium temperature [K]

        Returns
        -------
        :
            Themal capacity at constant pressure [Pa.s]
        """

        if temp < 4.0e0 or temp > 50.0e0:
            logger.error(
                f"Helium temperature out of helium property fiting range [4-50] K. {temp=}"
            )

        # Order 4 polynomial exponential fit in [4-25] K
        if temp < 22.5e0:
            visco = np.exp(
                -9.19688182e0
                - 4.83007225e-1 * temp
                + 3.47720002e-2 * temp**2
                - 1.17501538e-3 * temp**3
                + 1.54218249e-5 * temp**4
            )

        # Linear interpolation between the fits to avoid discontinuity
        elif temp < 27.5e0:
            visco = 6.708587487790973e-6 + 5.776427353055518e-9 * temp

        # Linear fit in [25-60] K
        else:
            visco = 5.41565319e-6 + 5.279222e-8 * temp

        return visco

    @staticmethod
    def he_th_cond(temp: float) -> float:
        """
        Subroutine calculating temperature dependent He thermal conductivity
        at 100 Bar from fit using the following data, valid in [4-50] K
        Ref : B.A. Hands B.A., Cryogenics, 1981, 21, 12, 697-703.

        Parameters
        ----------
        temp : float
            Helium temperature [K]

        Returns
        -------
        :
            Themal conductivity [W/(m.K)]
        """

        # Fit range validation
        if temp < 4.0e0 or temp > 50.0e0:
            logger.error(
                f"Helium temperature out of helium property fiting range [4-50] K. {temp=}"
            )

        # Order 4 polynomial fit
        if temp < 24.0e0:
            th_cond = (
                -7.56066334e-3
                + 1.62626819e-2 * temp
                - 1.3633619e-3 * temp**2
                + 4.84227752e-5 * temp**3
                - 6.31264281e-7 * temp**4
            )

        # Linear interpolation between the fits to avoid discontinuity
        elif temp < 25.0e0:
            th_cond = 0.05858194642349288e0 - 5.706361831471496e-5 * temp

        # Order 2 polynomial fit
        elif temp < 50.0e0:
            th_cond = (
                0.0731268577e0
                - 0.0013826223e0 * temp
                + 3.55551245e-5 * temp**2
                - 2.32185411e-7 * temp**3
            )

        # Linear interpolation between the fits to avoid discontinuity
        elif temp < 51.0e0:
            th_cond = 4.450475632499988e-2 + 3.871124250000024e-4 * temp

        # Linear fit
        else:
            th_cond = 0.04235676e0 + 0.00042923e0 * temp

        return th_cond

    @staticmethod
    def al_th_cond(temp: float) -> float:
        """
        Subroutine calculating temperature dependent Al thermal conductivity

        Parameters
        ----------
        temp : float
            Helium temperature [K]

        Returns
        -------
        :
            Themal conductivity [W/(m.K)]
        """

        # Fiting range verification
        if temp < 15.0e0 or temp > 150.0e0:
            logger.error(
                f"Aluminium temperature out of the th conductivity fit range [15-60] K. {temp=}"
            )

        # fit 15 < T < 60 K (order 3 poly)
        if temp < 60.0e0:
            th_cond = (
                16332.2073e0
                - 776.91775e0 * temp
                + 13.405688e0 * temp**2
                - 8.01e-02 * temp**3
            )

        # Linear interpolation between the fits to avoid discontinuity
        elif temp < 70.0e0:
            th_cond = 1587.9108966527328e0 - 15.19819661087886e0 * temp

        # fit 70 < T < 150 K (order 2 poly)
        elif temp < 150.0e0:
            th_cond = 1782.77406e0 - 24.7778504e0 * temp + 9.70842050e-2 * temp**2

        # constant value after that set with the fit upper limit to avoid discontinuities
        else:
            th_cond = 250.4911087866094e0

        return th_cond

    @staticmethod
    @numba.njit(cache=True)
    def tf_coil_self_inductance(
        dr_tf_inboard: float,
        r_tf_arc: np.ndarray,
        z_tf_arc: np.ndarray,
        itart: int,
        i_tf_shape: int,
        z_tf_inside_half: float,
        dr_tf_outboard: float,
        r_tf_outboard_mid: float,
        r_tf_inboard_mid: float,
    ) -> float:
        """Calculates the self-inductance of a TF coil.

        This function numerically integrates the magnetic field energy to estimate
        the self-inductance of a toroidal field (TF) coil, using the geometry
        defined by the arc points and the inboard thickness.

        Parameters
        ----------
        dr_tf_inboard : float
            Radial thickness of the inboard leg of the TF coil [m].
        r_tf_arc : numpy.ndarray
            Array of R coordinates of arc points (length 5).
        z_tf_arc : numpy.ndarray
            Array of Z coordinates of arc points (length 5).
        itart : int
            TART (tight aspect ratio tokamak) switch (0 = standard, 1 = TART).
        i_tf_shape : int
            TF coil shape selection switch (1 = D-shape, 2 = picture frame).
        z_tf_inside_half : float
            Maximum inboard edge height [m].
        dr_tf_outboard : float
            Radial thickness of the outboard leg of the TF coil [m].
        r_tf_outboard_mid : float
            Mid-plane radius of the outboard leg of the TF coil [m].
        r_tf_inboard_mid : float
            Mid-plane radius of the inboard leg of the TF coil [m].

        Returns
        -------
        float
            Self-inductance of the TF coil [H].

        Notes
        -----
        For the D-shaped coil (i_tf_shape == 1) in a standard (non-TART) configuration
        (itart == 0), the integration is performed over the coil cross-section, including both
        the inboard and outboard arcs. The field is computed for unit current,
        and the contribution from the coil's own cross-sectional area is included
        by taking the field as B(r)/2. Top/bottom symmetry is assumed.

        """
        NINTERVALS = 100

        if itart == 0 and i_tf_shape == 1:
            # Integrate over the whole TF area, including the coil thickness.
            x0 = r_tf_arc[1]
            y0 = z_tf_arc[1]

            # Minor and major radii of the inside and outside perimeters of the the
            # Inboard leg and arc.
            # Average the upper and lower halves, which are different in the
            # single null case
            ai = r_tf_arc[1] - r_tf_arc[0]
            bi = (z_tf_arc[1] - z_tf_arc[3]) / 2.0e0 - z_tf_arc[0]
            ao = ai + dr_tf_inboard
            bo = bi + dr_tf_inboard
            # Interval used for integration
            dr = ao / NINTERVALS
            # Start both integrals from the centre-point where the arcs join.
            # Initialise major radius
            r = x0 - dr / 2.0e0

            ind_tf_coil = 0

            for _ in range(NINTERVALS):
                # Field in the dr_bore for unit current
                b = constants.RMU0 / (2.0e0 * np.pi * r)
                # Find out if there is a dr_bore
                if x0 - r < ai:
                    h_bore = y0 + bi * np.sqrt(1 - ((r - x0) / ai) ** 2)
                    h_thick = bo * np.sqrt(1 - ((r - x0) / ao) ** 2) - h_bore
                else:
                    h_bore = 0.0e0
                    # Include the contribution from the straight section
                    h_thick = bo * np.sqrt(1 - ((r - x0) / ao) ** 2) + z_tf_arc[0]

                # Assume B in TF coil = 1/2  B in dr_bore
                # Multiply by 2 for upper and lower halves of coil
                ind_tf_coil += b * dr * (2.0e0 * h_bore + h_thick)
                r = r - dr

            # Outboard arc
            ai = r_tf_arc[2] - r_tf_arc[1]
            bi = (z_tf_arc[1] - z_tf_arc[3]) / 2.0e0
            ao = ai + dr_tf_inboard
            bo = bi + dr_tf_inboard
            dr = ao / NINTERVALS
            # Initialise major radius
            r = x0 + dr / 2.0e0

            for _ in range(NINTERVALS):
                # Field in the dr_bore for unit current
                b = constants.RMU0 / (2.0e0 * np.pi * r)
                # Find out if there is a dr_bore
                if r - x0 < ai:
                    h_bore = y0 + bi * np.sqrt(1 - ((r - x0) / ai) ** 2)
                    h_thick = bo * np.sqrt(1 - ((r - x0) / ao) ** 2) - h_bore
                else:
                    h_bore = 0.0e0
                    h_thick = bo * np.sqrt(1 - ((r - x0) / ao) ** 2)

                # Assume B in TF coil = 1/2  B in dr_bore
                # Multiply by 2 for upper and lower halves of coil
                ind_tf_coil += b * dr * (2.0e0 * h_bore + h_thick)
                r = r + dr
        else:
            # Picture frame TF coil
            ind_tf_coil = (
                (z_tf_inside_half + dr_tf_outboard)
                * constants.RMU0
                / np.pi
                * np.log(r_tf_outboard_mid / r_tf_inboard_mid)
            )

        return ind_tf_coil

    def generic_tf_coil_area_and_masses(self):
        """Subroutine to calculate the TF coil areas and masses"""

        # Surface areas (for cryo system) [m²]
        wbtf = (
            build_variables.r_tf_inboard_out
            * np.sin(superconducting_tf_coil_variables.rad_tf_coil_inboard_toroidal_half)
            - build_variables.r_tf_inboard_in
            * superconducting_tf_coil_variables.tan_theta_coil
        )
        tfcoil_variables.tfocrn = (
            build_variables.r_tf_inboard_in
            * superconducting_tf_coil_variables.tan_theta_coil
        )
        tfcoil_variables.tficrn = tfcoil_variables.tfocrn + wbtf

        # Total surface area of two toroidal shells covering the TF coils [m2]
        # (inside and outside surfaces)
        # = 2 * centroid coil length * 2 pi R, where R is average of i/b and o/b centres
        tfcoil_variables.tfcryoarea = (
            2.0e0
            * tfcoil_variables.len_tf_coil
            * 2.0
            * np.pi
            * 0.5e0
            * (build_variables.r_tf_inboard_mid + build_variables.r_tf_outboard_mid)
        )

    @staticmethod
    @numba.njit(cache=True)
    def stresscl(
        n_tf_layer,
        n_radial_array,
        n_tf_wp_stress_layers,
        i_tf_bucking,
        r_tf_inboard_in,
        dr_bore,
        z_tf_inside_half,
        f_z_cs_tf_internal,
        dr_cs,
        i_tf_inside_cs,
        dr_tf_inboard,
        dr_cs_tf_gap,
        i_pf_conductor,
        j_cs_flat_top_end,
        j_cs_pulse_start,
        c_pf_coil_turn_peak_input,
        n_pf_coils_in_group,
        f_dr_dz_cs_turn,
        radius_cs_turn_corners,
        f_a_cs_turn_steel,
        eyoung_steel,
        poisson_steel,
        eyoung_cond_axial,
        poisson_cond_axial,
        eyoung_cond_trans,
        poisson_cond_trans,
        eyoung_ins,
        poisson_ins,
        dx_tf_turn_insulation,
        eyoung_copper,
        poisson_copper,
        i_tf_sup,
        eyoung_res_tf_buck,
        r_tf_wp_inboard_inner,
        tan_theta_coil,
        rad_tf_coil_inboard_toroidal_half,
        r_tf_wp_inboard_outer,
        a_tf_coil_inboard_steel,
        a_tf_plasma_case,
        a_tf_coil_nose_case,
        dx_tf_wp_insertion_gap,
        dx_tf_wp_insulation,
        n_tf_coil_turns,
        i_tf_turns_integer,
        dx_tf_turn_cable_space_average,
        dr_tf_turn_cable_space,
        dia_tf_turn_coolant_channel,
        f_a_tf_turn_cable_copper,
        dx_tf_turn_steel,
        dx_tf_side_case_average,
        dx_tf_wp_toroidal_average,
        a_tf_coil_inboard_insulation,
        a_tf_wp_steel,
        a_tf_wp_conductor,
        a_tf_wp_with_insulation,
        eyoung_al,
        poisson_al,
        fcoolcp,
        n_tf_graded_layers,
        c_tf_total,
        dr_tf_plasma_case,
        i_tf_stress_model,
        vforce_inboard_tot,
        i_tf_tresca,
        a_tf_coil_inboard_case,
        vforce,
        a_tf_turn_steel,
    ):
        """TF coil stress routine

        This subroutine sets up the stress calculations for the
        TF coil set.
        PROCESS Superconducting TF Coil Model, J. Morris, CCFE, 1st May 2014

        Parameters
        ----------
        n_tf_layer :

        n_radial_array :

        n_tf_wp_stress_layers :

        i_tf_bucking :

        r_tf_inboard_in :

        dr_bore :

        z_tf_inside_half :

        f_z_cs_tf_internal :

        dr_cs :

        i_tf_inside_cs :

        dr_tf_inboard :

        dr_cs_tf_gap :

        i_pf_conductor :

        j_cs_flat_top_end :

        j_cs_pulse_start :

        c_pf_coil_turn_peak_input :

        n_pf_coils_in_group :

        f_dr_dz_cs_turn :

        radius_cs_turn_corners :

        f_a_cs_turn_steel :

        eyoung_steel :

        poisson_steel :

        eyoung_cond_axial :

        poisson_cond_axial :

        eyoung_cond_trans :

        poisson_cond_trans :

        eyoung_ins :

        poisson_ins :

        dx_tf_turn_insulation :

        eyoung_copper :

        poisson_copper :

        i_tf_sup :

        eyoung_res_tf_buck :

        r_tf_wp_inboard_inner :

        tan_theta_coil :

        rad_tf_coil_inboard_toroidal_half :

        r_tf_wp_inboard_outer :

        a_tf_coil_inboard_steel :

        a_tf_plasma_case :

        a_tf_coil_nose_case :

        dx_tf_wp_insertion_gap :

        dx_tf_wp_insulation :

        n_tf_coil_turns :

        i_tf_turns_integer :

        dx_tf_turn_cable_space_average :

        dr_tf_turn_cable_space :

        dia_tf_turn_coolant_channel :

        f_a_tf_turn_cable_copper :

        dx_tf_turn_steel :

        dx_tf_side_case_average :

        dx_tf_wp_toroidal_average :

        a_tf_coil_inboard_insulation :

        a_tf_wp_steel :

        a_tf_wp_conductor :

        a_tf_wp_with_insulation :

        eyoung_al :

        poisson_al :

        fcoolcp :

        n_tf_graded_layers :

        c_tf_total :

        dr_tf_plasma_case :

        i_tf_stress_model :

        vforce_inboard_tot :

        i_tf_tresca :

        a_tf_coil_inboard_case :

        vforce :

        a_tf_turn_steel :

        """
        jeff = np.zeros((n_tf_layer,))
        # Effective current density [A/m2]

        radtf = np.zeros((n_tf_layer + 1,))
        # Radii used to define the layers used in the stress models [m]
        # Layers are labelled from inboard to outbard

        eyoung_trans = np.zeros((n_tf_layer,))
        # Young's moduli (one per layer) of the TF coil in the
        # transverse (radial/toroidal) direction. Used in the stress
        # models [Pa]

        poisson_trans = np.zeros(
            (n_tf_layer,),
        )
        # Poisson's ratios (one per layer) of the TF coil between the
        # two transverse directions (radial and toroidal). Used in the
        # stress models.

        eyoung_member_array = np.zeros((n_tf_wp_stress_layers,))
        # Array to store the Young's moduli of the members to composite into smeared
        # properties [Pa]

        poisson_member_array = np.zeros((n_tf_wp_stress_layers,))
        # Array to store the Poisson's ratios of the members to composite into smeared
        # properti

        l_member_array = np.zeros((n_tf_wp_stress_layers,))
        # Array to store the linear dimension (thickness) of the members to composite into smeared
        # properties [m]

        eyoung_axial = np.zeros((n_tf_layer,))
        # Young's moduli (one per layer) of the TF coil in the vertical
        # direction used in the stress models [Pa]

        poisson_axial = np.zeros((n_tf_layer,))
        # Poisson's ratios (one per layer) of the TF coil between the
        # vertical and transverse directions (in that order). Used in the
        # stress models. d(transverse strain)/d(vertical strain) with
        # only vertical stress.

        sig_tf_wp_av_z = np.zeros(((n_tf_layer - i_tf_bucking) * n_radial_array,))
        # TF Inboard leg WP smeared vertical stress r distribution at mid-plane [Pa]

        sig_tf_r_max = np.zeros((n_tf_layer,))
        # Radial stress of the point of maximum shear stress of each layer [Pa]

        sig_tf_t_max = np.zeros((n_tf_layer,))
        # Toroidal stress of the point of maximum shear stress of each layer [Pa]

        sig_tf_z_max = np.zeros((n_tf_layer,))
        # Vertical stress of the point of maximum shear stress of each layer [Pa]
        # Rem : Currently constant but will be r dependent in the future

        sig_tf_vmises_max = np.zeros((n_tf_layer,))
        # Von-Mises stress of the point of maximum shear stress of each layer [Pa]

        s_shear_tf_peak = np.zeros((n_tf_layer,))
        # Maximum shear stress, for the Tresca yield criterion of each layer [Pa]
        # If the CEA correction is addopted, the CEA corrected value is used

        sig_tf_z = np.zeros((n_tf_layer * n_radial_array,))
        # TF Inboard leg vertical tensile stress at mid-plane [Pa]

        sig_tf_smeared_r = np.zeros((n_tf_layer * n_radial_array,))
        # TF Inboard leg radial smeared stress r distribution at mid-plane [Pa]

        sig_tf_smeared_t = np.zeros((n_tf_layer * n_radial_array,))
        # TF Inboard leg tangential smeared stress r distribution at mid-plane [Pa]

        sig_tf_smeared_z = np.zeros((n_tf_layer * n_radial_array,))
        # TF Inboard leg vertical smeared stress r distribution at mid-plane [Pa]

        fac_sig_z_wp_av = 0.0
        # WP averaged vertical stress unsmearing factor

        str_tf_r = np.zeros((n_radial_array * n_tf_layer,))
        str_tf_t = np.zeros((n_radial_array * n_tf_layer,))
        str_tf_z = np.zeros((n_radial_array * n_tf_layer,))

        sig_tf_case = None
        sig_tf_cs_bucked = None
        str_wp = None
        casestr = None
        insstrain = None

        # New extended plane strain model can handle it
        if (
            abs(r_tf_inboard_in) < np.finfo(float(r_tf_inboard_in)).eps
            and i_tf_stress_model != 2
        ):
            raise ProcessValueError("r_tf_inboard_in is ~= 0", 245)

        # TODO: following is no longer used/needed?
        # if tfcoil_variables.a_tf_turn_cable_space_no_void >= 0.0e0:
        #     tcbs = numpy.sqrt(tfcoil_variables.a_tf_turn_cable_space_no_void)
        # else:
        #     tcbs = 0.0e0

        # LAYER ELASTIC PROPERTIES
        # ------------------------
        # Number of bucking layers
        n_tf_bucking = i_tf_bucking

        # CS properties (bucked and wedged)
        # ---
        if i_tf_bucking >= 2:
            # Calculation performed at CS flux swing (no current on CS)
            jeff[0] = 0.0e0

            # Inner radius of the CS
            if i_tf_inside_cs == 1:
                # CS not used as wedge support i_tf_inside_cs = 1
                radtf[0] = 0.001
            else:
                radtf[0] = dr_bore

            # Superconducting CS
            if i_pf_conductor == 0:
                # Getting the turn dimention from scratch
                # as the TF is called before CS in caller.f90
                # -#

                # CS vertical cross-section area [m2]
                if i_tf_inside_cs == 1:
                    a_oh = (
                        2.0e0
                        * z_tf_inside_half
                        * f_z_cs_tf_internal
                        * (dr_bore - dr_tf_inboard)
                    )
                else:
                    a_oh = 2.0e0 * z_tf_inside_half * f_z_cs_tf_internal * dr_cs

                # Maximum current in Central Solenoid, at either BOP or EOF [MA-turns]
                # Absolute value
                curr_oh_max = (
                    1.0e-6 * np.maximum(j_cs_flat_top_end, j_cs_pulse_start) * a_oh
                )

                #  Number of turns
                n_oh_turns = (
                    1.0e6
                    * curr_oh_max
                    / c_pf_coil_turn_peak_input[sum(n_pf_coils_in_group)]
                )

                # CS Turn vertical cross-sectionnal area
                a_cs_turn = a_oh / n_oh_turns

                # CS coil turn geometry calculation - stadium shape
                # Literature: https://doi.org/10.1016/j.fusengdes.2017.04.052
                dz_cs_turn = (
                    a_cs_turn / f_dr_dz_cs_turn
                ) ** 0.5  # width of cs turn conduit
                dr_cs_turn = f_dr_dz_cs_turn * dz_cs_turn  # length of cs turn conduit
                # Radius of turn space = radius_cs_turn_cable_space
                # Radius of curved outer corrner radius_cs_turn_corners = 3mm from literature
                # f_dr_dz_cs_turn = 70 / 22 from literature
                p1 = ((dr_cs_turn - dz_cs_turn) / np.pi) ** 2
                p2 = (
                    (dr_cs_turn * dz_cs_turn)
                    - (4 - np.pi) * (radius_cs_turn_corners**2)
                    - (a_cs_turn * f_a_cs_turn_steel)
                ) / np.pi
                radius_cs_turn_cable_space = -(
                    (dr_cs_turn - dz_cs_turn) / np.pi
                ) + np.sqrt(p1 + p2)
                t_cond_oh = (
                    dz_cs_turn / 2
                ) - radius_cs_turn_cable_space  # thickness of steel conduit in cs turn

                # OH/CS conduit thickness calculated assuming square conduit [m]
                # The CS insulation layer is assumed to the same as the TF one

                # CS turn cable space thickness
                t_cable_oh = radius_cs_turn_cable_space * 2
                # -#

                # Smeared elastic properties of the CS
                # These smearing functions were written assuming transverse-
                # isotropic materials; that is not true of the CS, where the
                # stiffest dimension is toroidal and the radial and vertical
                # dimension are less stiff. Nevertheless this attempts to
                # hit the mark.
                # [EDIT: eyoung_cond is for the TF coil, not the CS coil]

                # Get transverse properties
                (eyoung_trans[0], a_working, poisson_trans[0]) = eyoung_parallel(
                    eyoung_steel,
                    f_a_cs_turn_steel,
                    poisson_steel,
                    eyoung_cond_axial,
                    1e0 - f_a_cs_turn_steel,
                    poisson_cond_axial,
                )

                # Get vertical properties
                # Split up into "members", concentric squares in cross section
                # (described in Figure 10 of the TF coil documentation)
                # Conductor
                eyoung_member_array[0] = eyoung_cond_trans
                poisson_member_array[0] = poisson_cond_trans
                l_member_array[0] = t_cable_oh
                # Steel conduit
                eyoung_member_array[1] = eyoung_steel
                poisson_member_array[1] = poisson_steel
                l_member_array[1] = 2 * t_cond_oh
                # Insulation
                eyoung_member_array[2] = eyoung_ins
                poisson_member_array[2] = poisson_ins
                l_member_array[2] = 2 * dx_tf_turn_insulation
                # [EDIT: Add central cooling channel? Would be new member #1]

                # Compute the composited (smeared) properties
                (
                    eyoung_axial[0],
                    a_working,
                    poisson_axial[0],
                    eyoung_cs_stiffest_leg,
                ) = eyoung_t_nested_squares(
                    3, eyoung_member_array, l_member_array, poisson_member_array
                )

            # resistive CS (copper)
            else:
                # Here is a rough approximation
                eyoung_trans[0] = eyoung_copper
                eyoung_axial[0] = eyoung_copper
                poisson_trans[0] = poisson_copper
                poisson_axial[0] = poisson_copper

        # ---

        # CS-TF interlayer properties
        # ---
        if i_tf_bucking == 3:
            # No current in this layer
            jeff[1] = 0.0e0

            # Outer radius of the CS
            if i_tf_inside_cs == 1:
                radtf[1] = dr_bore - dr_tf_inboard - dr_cs_tf_gap
            else:
                radtf[1] = dr_bore + dr_cs

            # Assumed to be Kapton for the moment
            # Ref : https://www.dupont.com/content/dam/dupont/products-and-services/membranes-and-films/polyimde-films/documents/DEC-Kapton-summary-of-properties.pdf
            eyoung_trans[1] = 2.5e9
            eyoung_axial[1] = 2.5e9
            poisson_trans[1] = 0.34e0  # Default value for young modulus
            poisson_axial[1] = 0.34e0  # Default value for young modulus

        # ---

        # bucking cylinder/casing properties
        # ---
        if i_tf_bucking >= 1:
            # No current in bucking cylinder/casing
            jeff[n_tf_bucking - 1] = 0.0e0

            if i_tf_sup == 1:
                eyoung_trans[n_tf_bucking - 1] = eyoung_steel
                eyoung_axial[n_tf_bucking - 1] = eyoung_steel
                poisson_trans[n_tf_bucking - 1] = poisson_steel
                poisson_axial[n_tf_bucking - 1] = poisson_steel

            # Bucking cylinder properties
            else:
                eyoung_trans[n_tf_bucking - 1] = eyoung_res_tf_buck
                eyoung_axial[n_tf_bucking - 1] = eyoung_res_tf_buck
                poisson_trans[n_tf_bucking - 1] = poisson_steel  # Seek better value #
                poisson_axial[n_tf_bucking - 1] = poisson_steel  # Seek better value #

            # Innernost TF casing radius
            radtf[n_tf_bucking - 1] = r_tf_inboard_in

        # ---

        # (Super)conductor layer properties
        # ---
        # SC coil
        if i_tf_sup == 1:
            # Inner/outer radii of the layer representing the WP in stress calculations [m]
            # These radii are chosen to preserve the true WP area; see Issue #1048
            r_wp_inner_eff = r_tf_wp_inboard_inner * np.sqrt(
                tan_theta_coil / rad_tf_coil_inboard_toroidal_half
            )
            r_wp_outer_eff = r_tf_wp_inboard_outer * np.sqrt(
                tan_theta_coil / rad_tf_coil_inboard_toroidal_half
            )

            # Area of the cylinder representing the WP in stress calculations [m2]
            a_wp_eff = (
                r_wp_outer_eff**2 - r_wp_inner_eff**2
            ) * rad_tf_coil_inboard_toroidal_half

            # Steel cross-section under the area representing the WP in stress calculations [m2]
            a_wp_steel_eff = (
                a_tf_coil_inboard_steel - a_tf_plasma_case - a_tf_coil_nose_case
            )

            # WP effective insulation thickness (SC only) [m]
            # include groundwall insulation + insertion gap in tfcoil_variables.dx_tf_turn_insulation
            # insertion gap is tfcoil_variables.dx_tf_wp_insertion_gap on 4 sides
            t_ins_eff = (
                dx_tf_turn_insulation
                + (dx_tf_wp_insertion_gap + dx_tf_wp_insulation) / n_tf_coil_turns
            )

            # Effective WP young modulus in the toroidal direction [Pa]
            # The toroidal property drives the stress calculation (J. Last report no 4)
            # Hence, the radial direction is relevant for the property smearing
            # Rem : This assumption might be re-defined for bucked and wedged design

            # Non-integer or interger number of turns
            t_cable_eyng = (
                dx_tf_turn_cable_space_average
                if i_tf_turns_integer == 0
                else dr_tf_turn_cable_space
            )

            # Average WP Young's modulus in the transverse
            # (radial and toroidal) direction
            # Split up into "members", concentric squares in cross section
            # (described in Figure 10 of the TF coil documentation)
            # Helium
            eyoung_member_array[0] = 0e0
            poisson_member_array[0] = poisson_steel
            l_member_array[0] = dia_tf_turn_coolant_channel
            # Conductor and co-wound copper
            (
                eyoung_member_array[1],
                l_member_array[1],
                poisson_member_array[1],
            ) = eyoung_series(
                np.double(eyoung_cond_trans),
                (t_cable_eyng - dia_tf_turn_coolant_channel)
                * (1.0e0 - f_a_tf_turn_cable_copper),
                np.double(poisson_cond_trans),
                np.double(eyoung_copper),
                (t_cable_eyng - dia_tf_turn_coolant_channel) * f_a_tf_turn_cable_copper,
                np.double(poisson_copper),
            )
            # Steel conduit
            eyoung_member_array[2] = eyoung_steel
            poisson_member_array[2] = poisson_steel
            l_member_array[2] = 2 * dx_tf_turn_steel
            # Insulation
            eyoung_member_array[3] = eyoung_ins
            poisson_member_array[3] = poisson_ins
            l_member_array[3] = 2 * t_ins_eff

            # Compute the composited (smeared) properties
            (
                eyoung_wp_trans,
                a_working,
                poisson_wp_trans,
                eyoung_wp_stiffest_leg,
            ) = eyoung_t_nested_squares(
                4,
                eyoung_member_array,
                l_member_array,
                poisson_member_array,
            )

            # Lateral casing correction (series-composition)
            (eyoung_wp_trans_eff, a_working, poisson_wp_trans_eff) = eyoung_series(
                eyoung_wp_trans,
                np.double(dx_tf_wp_toroidal_average),
                poisson_wp_trans,
                np.double(eyoung_steel),
                2.0e0 * dx_tf_side_case_average,
                np.double(poisson_steel),
            )

            poisson_wp_trans_eff = np.double(poisson_wp_trans_eff)

            # Average WP Young's modulus in the vertical direction
            # Split up into "members", concentric squares in cross section
            # (described in Figure 10 of the TF coil documentation)
            # Steel conduit
            eyoung_member_array[0] = eyoung_steel
            poisson_member_array[0] = poisson_steel
            l_member_array[0] = a_tf_wp_steel
            # Insulation
            eyoung_member_array[1] = eyoung_ins
            poisson_member_array[1] = poisson_ins
            l_member_array[1] = a_tf_coil_inboard_insulation
            # Copper
            eyoung_member_array[2] = eyoung_copper
            poisson_member_array[2] = poisson_copper
            l_member_array[2] = a_tf_wp_conductor * f_a_tf_turn_cable_copper
            # Conductor
            eyoung_member_array[3] = eyoung_cond_axial
            poisson_member_array[3] = poisson_cond_axial
            l_member_array[3] = a_tf_wp_conductor * (1.0e0 - f_a_tf_turn_cable_copper)
            # Helium and void
            eyoung_member_array[4] = 0e0
            poisson_member_array[4] = poisson_steel
            l_member_array[4] = (
                a_tf_wp_with_insulation
                - a_tf_wp_conductor
                - a_tf_coil_inboard_insulation
                - a_tf_wp_steel
            )
            # Compute the composite / smeared properties:
            (eyoung_wp_axial, a_working, poisson_wp_axial) = eyoung_parallel_array(
                5,
                eyoung_member_array,
                l_member_array,
                poisson_member_array,
            )

            # Average WP Young's modulus in the vertical direction, now including the lateral case
            # Parallel-composite the steel and insulation, now including the lateral case (sidewalls)
            (eyoung_wp_axial_eff, a_working, poisson_wp_axial_eff) = eyoung_parallel(
                eyoung_steel,
                a_wp_steel_eff - a_tf_wp_steel,
                poisson_steel,
                eyoung_wp_axial,
                a_working,
                poisson_wp_axial,
            )

        # Resistive coil
        else:
            # Picking the conductor material Young's modulus
            if i_tf_sup == 0:
                eyoung_cond = eyoung_copper
                poisson_cond = poisson_copper
            elif i_tf_sup == 2:
                eyoung_cond = eyoung_al
                poisson_cond = poisson_al

            # Effective WP young modulus in the toroidal direction [Pa]
            # Rem : effect of cooling pipes and insulation not taken into account
            #       for now as it needs a radially dependent Young modulus
            eyoung_wp_trans_eff = eyoung_cond
            eyoung_wp_trans = np.double(eyoung_cond)
            poisson_wp_trans_eff = np.double(poisson_cond)
            poisson_wp_trans = np.double(poisson_cond)

            # WP area using the stress model circular geometry (per coil) [m2]
            a_wp_eff = (
                r_tf_wp_inboard_outer**2 - r_tf_wp_inboard_inner**2
            ) * rad_tf_coil_inboard_toroidal_half

            # Effective conductor region young modulus in the vertical direction [Pa]
            # Parallel-composite conductor and insulator
            (eyoung_wp_axial, a_working, poisson_wp_axial) = eyoung_parallel(
                eyoung_cond,
                (a_wp_eff - a_tf_coil_inboard_insulation) * (1.0e0 - fcoolcp),
                poisson_cond,
                eyoung_ins,
                a_tf_coil_inboard_insulation,
                poisson_ins,
            )
            # Parallel-composite cooling pipes into that
            (eyoung_wp_axial, a_working, poisson_wp_axial) = eyoung_parallel(
                0e0,
                (a_wp_eff - a_tf_coil_inboard_insulation) * fcoolcp,
                poisson_cond,
                eyoung_wp_axial,
                a_working,
                poisson_wp_axial,
            )

            # Effective young modulus used in stress calculations
            eyoung_wp_axial_eff = eyoung_wp_axial
            poisson_wp_axial_eff = poisson_wp_axial

            # Effect conductor layer inner/outer radius
            r_wp_inner_eff = np.double(r_tf_wp_inboard_inner)
            r_wp_outer_eff = np.double(r_tf_wp_inboard_outer)

        # Thickness of the layer representing the WP in stress calcualtions [m]
        dr_tf_wp_eff = r_wp_outer_eff - r_wp_outer_eff

        # Thickness of WP with homogeneous stress property [m]
        dr_wp_layer = dr_tf_wp_eff / n_tf_graded_layers

        for ii in range(np.intc(n_tf_graded_layers)):
            # Homogeneous current in (super)conductor
            jeff[n_tf_bucking + ii] = c_tf_total / (
                np.pi * (r_wp_outer_eff**2 - r_wp_inner_eff**2)
            )

            # Same thickness for all WP layers in stress calculation
            radtf[n_tf_bucking + ii] = r_wp_inner_eff + ii * dr_wp_layer

            # Young modulus
            eyoung_trans[n_tf_bucking + ii] = eyoung_wp_trans_eff
            eyoung_axial[n_tf_bucking + ii] = eyoung_wp_axial_eff

            # Poisson's ratio
            poisson_trans[n_tf_bucking + ii] = poisson_wp_trans_eff
            poisson_axial[n_tf_bucking + ii] = poisson_wp_axial_eff

        # Steel case on the plasma side of the inboard TF coil
        # As per Issue #1509
        jeff[n_tf_layer - 1] = 0.0e0
        radtf[n_tf_layer - 1] = r_wp_outer_eff
        eyoung_trans[n_tf_layer - 1] = eyoung_steel
        eyoung_axial[n_tf_layer - 1] = eyoung_steel
        poisson_trans[n_tf_layer - 1] = poisson_steel
        poisson_axial[n_tf_layer - 1] = poisson_steel

        # last layer radius
        radtf[n_tf_layer] = r_wp_outer_eff + dr_tf_plasma_case

        # The ratio between the true cross sectional area of the
        # front case, and that considered by the plane strain solver
        f_tf_stress_front_case = (
            a_tf_plasma_case
            / rad_tf_coil_inboard_toroidal_half
            / (radtf[n_tf_layer] ** 2 - radtf[n_tf_layer - 1] ** 2)
        )

        # Correct for the missing axial stiffness from the missing
        # outer case steel as per the updated description of
        # Issue #1509
        eyoung_axial[n_tf_layer - 1] = (
            eyoung_axial[n_tf_layer - 1] * f_tf_stress_front_case
        )

        # ---
        # ------------------------

        # RADIAL STRESS SUBROUTINES CALL
        # ------------------------------
        # Stress model not valid the TF does not contain any hole
        # (Except if i_tf_plane_stress == 2; see Issue 1414)
        # Current action : trigger and error and add a little hole
        #                  to allow stress calculations
        # Rem SK : Can be easily ameneded playing around the boundary conditions
        # New extended plane strain model can handle it
        if abs(radtf[0]) < np.finfo(float(radtf[0])).eps and i_tf_stress_model != 2:
            radtf[0] = 1.0e-9
        # ---

        # Old generalized plane stress model
        # ---
        if i_tf_stress_model == 1:
            # Plane stress calculation (SC) [Pa]

            (sig_tf_r, sig_tf_t, deflect, radial_array) = plane_stress(
                nu=poisson_trans,
                rad=radtf,
                ey=eyoung_trans,
                j=jeff,
                nlayers=int(n_tf_layer),
                n_radial_array=int(n_radial_array),
            )

            # Vertical stress [Pa]
            sig_tf_z[:] = vforce / (
                a_tf_coil_inboard_case + a_tf_turn_steel * n_tf_coil_turns
            )  # Array equation [EDIT: Are you sure? It doesn't look like one to me]

            # Strain in vertical direction on WP
            str_wp = sig_tf_z[n_tf_bucking] / eyoung_wp_axial_eff

            # Case strain
            casestr = sig_tf_z[n_tf_bucking - 1] / eyoung_steel

            # Radial strain in insulator
            insstrain = (
                sig_tf_r[n_radial_array - 1]
                * eyoung_wp_stiffest_leg
                / eyoung_wp_trans_eff
                / eyoung_ins
            )
        # ---

        # New generalized plane strain formulation
        # ---
        # See #1670 for why i_tf_stress_model=0 was removed
        elif i_tf_stress_model in (0, 2):
            # Extended plane strain calculation [Pa]
            # Issues #1414 and #998
            # Permits build_variables.dr_bore >= 0, O(n) in layers
            # If build_variables.dr_bore > 0, same result as generalized plane strain calculation

            (
                radial_array,
                sig_tf_r,
                sig_tf_t,
                sig_tf_z,
                str_tf_r,
                str_tf_t,
                str_tf_z,
                deflect,
            ) = extended_plane_strain(
                poisson_trans,
                poisson_axial,
                eyoung_trans,
                eyoung_axial,
                radtf,
                jeff,
                vforce_inboard_tot,
                int(n_tf_layer),
                int(n_radial_array),
                int(n_tf_bucking),
            )

            # Strain in TF conductor material
            str_wp = str_tf_z[n_tf_bucking * n_radial_array]

        # ---

        # Storing the smeared properties for output

        sig_tf_smeared_r[:] = sig_tf_r  # Array equation
        sig_tf_smeared_t[:] = sig_tf_t  # Array equation
        sig_tf_smeared_z[:] = sig_tf_z  # Array equation

        # ------------------------------

        # STRESS DISTRIBUTIONS CORRECTIONS
        # --------------------------------
        # SC central solenoid coil stress unsmearing (bucked and wedged only)
        # ---
        if i_tf_bucking >= 2 and i_pf_conductor == 0:
            # Central Solenoid (OH) steel conduit stress unsmearing factors
            for ii in range(n_radial_array):
                sig_tf_r[ii] = sig_tf_r[ii] * eyoung_cs_stiffest_leg / eyoung_axial[0]
                sig_tf_t[ii] = sig_tf_t[ii] * eyoung_steel / eyoung_trans[0]
                sig_tf_z[ii] = sig_tf_z[ii] * eyoung_cs_stiffest_leg / eyoung_axial[0]

        # ---

        # No TF vertical forces on CS and CS-TF layer (bucked and wedged only)
        # ---
        # This correction is only applied if the plane stress model is used
        # as the generalized plane strain calculates the vertical stress properly
        if i_tf_bucking >= 2 and i_tf_stress_model == 1:
            for ii in range((n_tf_bucking - 1) * n_radial_array):
                sig_tf_z[ii] = 0.0e0

        # ---

        # Toroidal coil unsmearing
        # ---
        # Copper magnets
        if i_tf_sup == 0:
            # Vertical force unsmearing factor
            fac_sig_z = eyoung_copper / eyoung_wp_axial_eff

            # Toroidal WP steel stress unsmearing factor
            fac_sig_t = 1.0e0
            fac_sig_r = 1.0e0

        elif i_tf_sup == 1:
            # Vertical WP steel stress unsmearing factor
            if i_tf_stress_model != 1:
                fac_sig_z = eyoung_steel / eyoung_wp_axial_eff
                fac_sig_z_wp_av = eyoung_wp_axial / eyoung_wp_axial_eff
            else:
                fac_sig_z = 1.0e0

            # Toroidal WP steel conduit stress unsmearing factor
            fac_sig_t = eyoung_wp_stiffest_leg / eyoung_wp_trans_eff

            # Radial WP steel conduit stress unsmearing factor
            fac_sig_r = eyoung_wp_stiffest_leg / eyoung_wp_trans_eff

        elif i_tf_sup == 2:
            # Vertical WP steel stress unsmearing factor
            fac_sig_z = eyoung_al / eyoung_wp_axial_eff

            # Toroidal WP steel stress unsmearing factor
            # NO CALCULTED FOR THE MOMENT (to be done later)
            fac_sig_t = 1.0e0
            fac_sig_r = 1.0e0

        # Application of the unsmearing to the WP layers
        # For each point within the winding pack / conductor, unsmear the
        # stress. This is n_radial_array test points within tfcoil_variables.n_tf_graded_layers
        # layers starting at n_tf_bucking + 1
        # GRADED MODIF : add another do loop to allow the graded properties
        #                to be taken into account
        for ii in range(
            n_tf_bucking * n_radial_array,
            ((n_tf_bucking + n_tf_graded_layers) * n_radial_array),
        ):
            sig_tf_wp_av_z[ii - n_tf_bucking * n_radial_array] = (
                sig_tf_z[ii] * fac_sig_z_wp_av
            )
            sig_tf_r[ii] = sig_tf_r[ii] * fac_sig_r
            sig_tf_t[ii] = sig_tf_t[ii] * fac_sig_t
            sig_tf_z[ii] = sig_tf_z[ii] * fac_sig_z

        # For each point within the front case,
        # remove the correction for the missing axial
        # stiffness as per the updated description of
        # Issue #1509
        for ii in range(
            (n_tf_bucking + n_tf_graded_layers) * n_radial_array,
            (n_tf_layer * n_radial_array),
        ):
            sig_tf_z[ii] = sig_tf_z[ii] / f_tf_stress_front_case
        # ---

        # Tresca / Von Mises yield criteria calculations
        # -----------------------------
        # Array equation
        s_shear_tf = np.maximum(
            np.absolute(sig_tf_r - sig_tf_z), np.absolute(sig_tf_z - sig_tf_t)
        )

        # Array equation

        sig_tf_vmises = np.sqrt(
            0.5e0
            * (
                (sig_tf_r - sig_tf_t) ** 2
                + (sig_tf_r - sig_tf_z) ** 2
                + (sig_tf_z - sig_tf_t) ** 2
            )
        )

        # Array equation
        s_shear_cea_tf_cond = s_shear_tf.copy()

        # SC conducting layer stress distribution corrections
        # ---
        if i_tf_sup == 1:
            # GRADED MODIF : add another do loop to allow the graded properties
            #                to be taken into account
            for ii in range(
                (n_tf_bucking * n_radial_array), n_tf_layer * n_radial_array
            ):
                # Addaped Von-mises stress calculation to WP strucure [Pa]

                svmxz = sigvm(0.0e0, sig_tf_t[ii], sig_tf_z[ii], 0.0e0, 0.0e0, 0.0e0)

                svmyz = sigvm(sig_tf_r[ii], 0.0e0, sig_tf_z[ii], 0.0e0, 0.0e0, 0.0e0)
                sig_tf_vmises[ii] = max(svmxz, svmyz)

                # Maximum shear stress for the Tresca yield criterion using CEA calculation [Pa]
                s_shear_cea_tf_cond[ii] = (
                    1.02e0 * abs(sig_tf_r[ii]) + 1.6e0 * sig_tf_z[ii]
                )

        # ---
        # -----------------------------

        # Output formating : Maximum shear stress of each layer for the Tresca yield criterion
        # ----------------
        for ii in range(n_tf_layer):
            sig_max = 0.0e0
            ii_max = 0

            for jj in range(ii * n_radial_array, (ii + 1) * n_radial_array):
                # CEA out of plane approximation
                if i_tf_tresca == 1 and i_tf_sup == 1 and ii >= i_tf_bucking + 1:
                    if sig_max < s_shear_cea_tf_cond[jj]:
                        sig_max = s_shear_cea_tf_cond[jj]
                        ii_max = jj

                # Conventional Tresca
                else:
                    if sig_max < s_shear_tf[jj]:
                        sig_max = s_shear_tf[jj]
                        ii_max = jj

            # OUT.DAT output

            sig_tf_r_max[ii] = sig_tf_r[ii_max]
            sig_tf_t_max[ii] = sig_tf_t[ii_max]
            sig_tf_z_max[ii] = sig_tf_z[ii_max]
            sig_tf_vmises_max[ii] = sig_tf_vmises[ii_max]

            # Maximum shear stress for the Tresca yield criterion (or CEA OOP correction)

            if i_tf_tresca == 1 and i_tf_sup == 1 and ii >= i_tf_bucking + 1:
                s_shear_tf_peak[ii] = s_shear_cea_tf_cond[ii_max]
            else:
                s_shear_tf_peak[ii] = s_shear_tf[ii_max]

        # Constraint equation for the Tresca yield criterion

        sig_tf_wp = s_shear_tf_peak[n_tf_bucking]
        # Maximum assumed in the first graded layer

        if i_tf_bucking >= 1:
            sig_tf_case = s_shear_tf_peak[n_tf_bucking - 1]
        if i_tf_bucking >= 2:
            sig_tf_cs_bucked = s_shear_tf_peak[0]
        # ----------------

        return (
            sig_tf_r_max,
            sig_tf_t_max,
            sig_tf_z_max,
            sig_tf_vmises_max,
            s_shear_tf_peak,
            deflect,
            eyoung_axial,
            eyoung_trans,
            eyoung_wp_axial,
            eyoung_wp_trans,
            poisson_wp_trans,
            radial_array,
            s_shear_cea_tf_cond,
            poisson_wp_axial,
            sig_tf_r,
            sig_tf_smeared_r,
            sig_tf_smeared_t,
            sig_tf_smeared_z,
            sig_tf_t,
            s_shear_tf,
            sig_tf_vmises,
            sig_tf_z,
            str_tf_r,
            str_tf_t,
            str_tf_z,
            n_radial_array,
            n_tf_bucking,
            sig_tf_wp,
            sig_tf_case,
            sig_tf_cs_bucked,
            str_wp,
            casestr,
            insstrain,
            sig_tf_wp_av_z,
        )

    def out_stress(
        self,
        sig_tf_r_max,
        sig_tf_t_max,
        sig_tf_z_max,
        sig_tf_vmises_max,
        s_shear_tf_peak,
        deflect,
        eyoung_axial,
        eyoung_trans,
        eyoung_wp_axial,
        eyoung_wp_trans,
        poisson_wp_trans,
        radial_array,
        s_shear_cea_tf_cond,
        poisson_wp_axial,
        sig_tf_r,
        sig_tf_smeared_r,
        sig_tf_smeared_t,
        sig_tf_smeared_z,
        sig_tf_t,
        s_shear_tf,
        sig_tf_vmises,
        sig_tf_z,
        str_tf_r,
        str_tf_t,
        str_tf_z,
        n_radial_array,
        n_tf_bucking,
        sig_tf_wp_av_z,
    ):
        """Subroutine showing the writing the TF midplane stress analysis
        in the output file and the stress distribution in the SIG_TF.json
        file used to plot stress distributions

        Parameters
        ----------
        sig_tf_r_max :

        sig_tf_t_max :

        sig_tf_z_max :

        sig_tf_vmises_max :

        s_shear_tf_peak :

        deflect :

        eyoung_axial :

        eyoung_trans :

        eyoung_wp_axial :

        eyoung_wp_trans :

        poisson_wp_trans :

        radial_array :

        s_shear_cea_tf_cond :

        poisson_wp_axial :

        sig_tf_r :

        sig_tf_smeared_r :

        sig_tf_smeared_t :

        sig_tf_smeared_z :

        sig_tf_t :

        s_shear_tf :

        sig_tf_vmises :

        sig_tf_z :

        str_tf_r :

        str_tf_t :

        str_tf_z :

        n_radial_array :

        n_tf_bucking :

        sig_tf_wp_av_z :

        """

        def table_format_arrays(a, mult=1, delim="\t\t"):
            return delim.join([str(i * mult) for i in a])

        # Stress output section
        po.oheadr(self.outfile, "TF coils ")
        po.osubhd(self.outfile, "TF Coil Stresses (CCFE model) :")

        if tfcoil_variables.i_tf_stress_model == 1:
            po.ocmmnt(self.outfile, "Plane stress model with smeared properties")
        else:
            po.ocmmnt(self.outfile, "Generalized plane strain model")

        po.ovarre(
            self.outfile,
            "Allowable maximum shear stress in TF coil case (Tresca criterion) (Pa)",
            "(sig_tf_case_max)",
            tfcoil_variables.sig_tf_case_max,
        )

        po.ovarre(
            self.outfile,
            "Allowable maximum shear stress in TF coil conduit (Tresca criterion) (Pa)",
            "(sig_tf_wp_max)",
            tfcoil_variables.sig_tf_wp_max,
        )
        if tfcoil_variables.i_tf_tresca == 1 and tfcoil_variables.i_tf_sup == 1:
            po.ocmmnt(
                self.outfile,
                "WP conduit Tresca criterion corrected using CEA formula (i_tf_tresca = 1)",
            )

        if tfcoil_variables.i_tf_bucking >= 3:
            po.ocmmnt(
                self.outfile, "No stress limit imposed on the TF-CS interface layer"
            )
            po.ocmmnt(
                self.outfile, "  -> Too much unknow on it material choice/properties"
            )

        # OUT.DAT data on maximum shear stress values for the Tresca criterion
        po.ocmmnt(
            self.outfile,
            "Materal stress of the point of maximum shear stress (Tresca criterion) for each layer",
        )
        po.ocmmnt(
            self.outfile,
            "Please use utilities/plot_stress_tf.py for radial plots plots summary",
        )

        if tfcoil_variables.i_tf_bucking == 0:
            if tfcoil_variables.i_tf_sup == 1:
                po.write(self.outfile, "  Layers \t\t\t\t WP \t\t Outer case")
            else:
                po.write(self.outfile, "  Layers \t\t\t\t conductor \t\t Outer case")

        elif tfcoil_variables.i_tf_bucking == 1:
            if tfcoil_variables.i_tf_sup == 1:
                po.write(
                    self.outfile, "  Layers \t\t\t\t Steel case \t\t WP \t\t Outer case"
                )
            else:
                po.write(
                    self.outfile,
                    "  Layers \t\t\t\t bucking \t\t conductor \t\t Outer case",
                )

        elif tfcoil_variables.i_tf_bucking == 2:
            if tfcoil_variables.i_tf_sup == 1:
                po.write(
                    self.outfile,
                    "  Layers \t\t\t\t CS \t\t Steel case \t\t WP \t\t Outer case",
                )
            else:
                po.write(
                    self.outfile,
                    "  Layers \t\t\t\t CS \t\t bucking \t\t conductor \t\t Outer case",
                )

        elif tfcoil_variables.i_tf_bucking == 3:
            if tfcoil_variables.i_tf_sup == 1:
                po.write(
                    self.outfile,
                    "  Layers \t\t\t\t CS \t\t interface \t\t Steel case \t\t WP \t\t Outer case",
                )
            else:
                po.write(
                    self.outfile,
                    "  Layers \t\t\t\t CS \t\t interface \t\t bucking \t\t conductor \t\t Outer case",
                )

        po.write(
            self.outfile,
            f"  Radial stress \t\t\t (MPa) \t\t {table_format_arrays(sig_tf_r_max, 1e-6)}",
        )
        po.write(
            self.outfile,
            f"  Toroidal stress \t\t\t (MPa) \t\t {table_format_arrays(sig_tf_t_max, 1e-6)}",
        )
        po.write(
            self.outfile,
            f"  Vertical stress \t\t\t (MPa) \t\t {table_format_arrays(sig_tf_z_max, 1e-6)}",
        )
        po.write(
            self.outfile,
            f"  Von-Mises stress \t\t\t (MPa) \t\t {table_format_arrays(sig_tf_vmises_max, 1e-6)}",
        )

        if tfcoil_variables.i_tf_tresca == 1 and tfcoil_variables.i_tf_sup == 1:
            po.write(
                self.outfile,
                f"  Shear (CEA Tresca) \t\t\t (MPa) \t\t {table_format_arrays(s_shear_tf_peak, 1e-6)}",
            )
        else:
            po.write(
                self.outfile,
                f"  Shear (Tresca) \t\t\t (MPa) \t\t {table_format_arrays(s_shear_tf_peak, 1e-6)}",
            )

        po.write(self.outfile, "")
        po.write(
            self.outfile,
            f"  Toroidal modulus \t\t\t (GPa) \t\t {table_format_arrays(eyoung_trans, 1e-9)}",
        )
        po.write(
            self.outfile,
            f"  Vertical modulus \t\t\t (GPa) \t\t {table_format_arrays(eyoung_axial, 1e-9)}",
        )
        po.write(self.outfile, "")
        po.ovarre(
            self.outfile,
            "WP transverse modulus (GPa)",
            "(eyoung_wp_trans*1.0d-9)",
            eyoung_wp_trans * 1.0e-9,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "WP vertical modulus (GPa)",
            "(eyoung_wp_axial*1.0d-9)",
            eyoung_wp_axial * 1.0e-9,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "WP transverse Poissons ratio",
            "(poisson_wp_trans)",
            poisson_wp_trans,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "WP vertical-transverse Pois. rat.",
            "(poisson_wp_axial)",
            poisson_wp_axial,
            "OP ",
        )

        # MFILE.DAT data
        for ii in range(n_tf_bucking + 2):
            po.ovarre(
                constants.MFILE,
                f"Radial    stress at maximum shear of layer {ii + 1} (Pa)",
                f"(sig_tf_r_max({ii + 1}))",
                sig_tf_r_max[ii],
            )
            po.ovarre(
                constants.MFILE,
                f"toroidal  stress at maximum shear of layer {ii + 1} (Pa)",
                f"(sig_tf_t_max({ii + 1}))",
                sig_tf_t_max[ii],
            )
            po.ovarre(
                constants.MFILE,
                f"Vertical  stress at maximum shear of layer {ii + 1} (Pa)",
                f"(sig_tf_z_max({ii + 1}))",
                sig_tf_z_max[ii],
            )
            po.ovarre(
                constants.MFILE,
                f"Von-Mises stress at maximum shear of layer {ii + 1} (Pa)",
                f"(sig_tf_vmises_max({ii + 1}))",
                sig_tf_vmises_max[ii],
            )
            if tfcoil_variables.i_tf_tresca == 1 and tfcoil_variables.i_tf_sup == 1:
                po.ovarre(
                    constants.MFILE,
                    f"Maximum shear stress for CEA Tresca yield criterion {ii + 1} (Pa)",
                    f"(s_shear_tf_peak({ii + 1}))",
                    s_shear_tf_peak[ii],
                )
            else:
                po.ovarre(
                    constants.MFILE,
                    f"Maximum shear stress for the Tresca yield criterion {ii + 1} (Pa)",
                    f"(s_shear_tf_peak({ii + 1}))",
                    s_shear_tf_peak[ii],
                )

        # SIG_TF.json storage
        sig_file_data = {
            "Points per layers": n_radial_array,
            "Radius (m)": radial_array,
            "Radial stress (MPa)": sig_tf_r * 1e-6,
            "Toroidal stress (MPa)": sig_tf_t * 1e-6,
            "Vertical stress (MPa)": sig_tf_z * 1e-6,
            "Radial smear stress (MPa)": sig_tf_smeared_r * 1e-6,
            "Toroidal smear stress (MPa)": sig_tf_smeared_t * 1e-6,
            "Vertical smear stress (MPa)": sig_tf_smeared_z * 1e-6,
            "Von-Mises stress (MPa)": sig_tf_vmises * 1e-6,
            "CEA Tresca stress (MPa)": (
                s_shear_cea_tf_cond * 1e-6
                if tfcoil_variables.i_tf_sup == 1
                else s_shear_tf * 1e-6
            ),
            "rad. displacement (mm)": deflect * 1e3,
        }
        if tfcoil_variables.i_tf_stress_model != 1:
            sig_file_data = {
                **sig_file_data,
                "Radial strain": str_tf_r,
                "Toroidal strain": str_tf_t,
                "Vertical strain": str_tf_z,
            }

        if tfcoil_variables.i_tf_sup == 1:
            sig_file_data = {
                **sig_file_data,
                "WP smeared stress (MPa)": sig_tf_wp_av_z * 1.0e-6,
            }

        sig_file_data = {
            k: list(v) if isinstance(v, np.ndarray) else v
            for k, v in sig_file_data.items()
        }

        sig_filename = global_variables.output_prefix + "SIG_TF.json"
        with open(sig_filename, "w") as f:
            json.dump(sig_file_data, f)

        # TODO sig_tf_wp_av_z is always undefined here. This needs correcting or removing
        # if ( tfcoil_variables.i_tf_sup == 1 ) :
        # write(constants.sig_file,'(t2, "WP"    ," smeared stress", t20, "(MPa)",t26, *(F11.3,3x))') sig_tf_wp_av_z*1.0e-6
        #

        # Quantities from the plane stress stress formulation (no resitive coil output)
        if tfcoil_variables.i_tf_stress_model == 1 and tfcoil_variables.i_tf_sup == 1:
            # Other quantities (displacement strain, etc..)
            po.ovarre(
                self.outfile,
                "Maximum radial deflection at midplane (m)",
                "(deflect)",
                deflect[n_radial_array - 1],
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Vertical strain on casing",
                "(casestr)",
                tfcoil_variables.casestr,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Radial strain on insulator",
                "(insstrain)",
                tfcoil_variables.insstrain,
                "OP ",
            )

outfile = constants.NOUT instance-attribute

iprint = 0 instance-attribute

build = build instance-attribute

a_tf_inboard_total = tfcoil_variables.a_tf_inboard_total instance-attribute

run_base_tf()

Run main tfcoil subroutine without outputting.

Source code in process/models/tfcoil/base.py
 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
def run_base_tf(self):
    """Run main tfcoil subroutine without outputting."""

    (
        superconducting_tf_coil_variables.rad_tf_coil_inboard_toroidal_half,
        superconducting_tf_coil_variables.tan_theta_coil,
        tfcoil_variables.a_tf_inboard_total,
        superconducting_tf_coil_variables.r_tf_outboard_in,
        superconducting_tf_coil_variables.r_tf_outboard_out,
        tfcoil_variables.dx_tf_inboard_out_toroidal,
        tfcoil_variables.a_tf_leg_outboard,
        tfcoil_variables.dr_tf_plasma_case,
        tfcoil_variables.dx_tf_side_case_min,
    ) = self.tf_global_geometry(
        i_tf_case_geom=tfcoil_variables.i_tf_case_geom,
        i_f_dr_tf_plasma_case=tfcoil_variables.i_f_dr_tf_plasma_case,
        f_dr_tf_plasma_case=tfcoil_variables.f_dr_tf_plasma_case,
        tfc_sidewall_is_fraction=tfcoil_variables.tfc_sidewall_is_fraction,
        casths_fraction=tfcoil_variables.casths_fraction,
        n_tf_coils=tfcoil_variables.n_tf_coils,
        dr_tf_inboard=build_variables.dr_tf_inboard,
        dr_tf_nose_case=tfcoil_variables.dr_tf_nose_case,
        r_tf_inboard_out=build_variables.r_tf_inboard_out,
        r_tf_inboard_in=build_variables.r_tf_inboard_in,
        r_tf_outboard_mid=build_variables.r_tf_outboard_mid,
        dr_tf_outboard=build_variables.dr_tf_outboard,
    )

    tfcoil_variables.r_b_tf_inboard_peak = (
        build_variables.r_tf_inboard_out
        - tfcoil_variables.dr_tf_plasma_case
        - tfcoil_variables.dx_tf_wp_insulation
        - tfcoil_variables.dx_tf_wp_insertion_gap
    )

    (
        tfcoil_variables.b_tf_inboard_peak_symmetric,
        tfcoil_variables.c_tf_total,
        superconducting_tf_coil_variables.c_tf_coil,
        tfcoil_variables.oacdcp,
    ) = self.tf_current(
        n_tf_coils=tfcoil_variables.n_tf_coils,
        b_plasma_toroidal_on_axis=physics_variables.b_plasma_toroidal_on_axis,
        rmajor=physics_variables.rmajor,
        r_b_tf_inboard_peak=tfcoil_variables.r_b_tf_inboard_peak,
        a_tf_inboard_total=tfcoil_variables.a_tf_inboard_total,
    )

    (
        tfcoil_variables.len_tf_coil,
        tfcoil_variables.tfa,
        tfcoil_variables.tfb,
        tfcoil_variables.r_tf_arc,
        tfcoil_variables.z_tf_arc,
    ) = self.tf_coil_shape_inner(
        i_tf_shape=tfcoil_variables.i_tf_shape,
        itart=physics_variables.itart,
        i_single_null=physics_variables.i_single_null,
        r_tf_inboard_out=build_variables.r_tf_inboard_out,
        r_cp_top=build_variables.r_cp_top,
        rmajor=physics_variables.rmajor,
        rminor=physics_variables.rminor,
        r_tf_outboard_in=superconducting_tf_coil_variables.r_tf_outboard_in,
        z_tf_inside_half=build_variables.z_tf_inside_half,
        z_tf_top=build_variables.z_tf_top,
        dr_tf_inboard=build_variables.dr_tf_inboard,
        dr_tf_outboard=build_variables.dr_tf_outboard,
        r_tf_outboard_mid=build_variables.r_tf_outboard_mid,
        r_tf_inboard_mid=build_variables.r_tf_inboard_mid,
    )

output()

Run main tfcoil subroutine and write output.

Source code in process/models/tfcoil/base.py
108
109
110
111
def output(self):
    """Run main tfcoil subroutine and write output."""
    self.iprint = 1
    self.tfcoil(output=bool(self.iprint))

tf_global_geometry(i_tf_case_geom, i_f_dr_tf_plasma_case, f_dr_tf_plasma_case, tfc_sidewall_is_fraction, casths_fraction, n_tf_coils, dr_tf_inboard, dr_tf_nose_case, r_tf_inboard_out, r_tf_inboard_in, r_tf_outboard_mid, dr_tf_outboard)

Calculate the global geometry of the Toroidal Field (TF) coil.

This method computes the overall geometry of the TF coil, including:

  • Toroidal angular spacing and tangent of the angle.
  • Cross-sectional areas of the inboard and outboard legs.
  • Radii and widths of the inboard and outboard legs.
  • Case thicknesses for plasma-facing and sidewall regions.

Parameters:

Name Type Description Default
i_tf_case_geom int

Geometry type of the TF coil case (e.g., circular or straight plasma-facing front case).

required
i_f_dr_tf_plasma_case bool

Whether the plasma-facing case thickness is specified as a fraction of the inboard thickness.

required
f_dr_tf_plasma_case float

Fraction of the inboard thickness used for the plasma-facing case thickness.

required
tfc_sidewall_is_fraction bool

Whether the sidewall case thickness is specified as a fraction of the inboard radius.

required
casths_fraction float

Fraction of the inboard radius used for the sidewall case thickness.

required
n_tf_coils int

Number of TF coils.

required
dr_tf_inboard float

Radial thickness of the inboard leg of the TF coil [m].

required
dr_tf_nose_case float

Thickness of the inboard leg case at the nose region [m].

required
r_tf_inboard_out float

Outer radius of the inboard leg of the TF coil [m].

required
r_tf_inboard_in float

Inner radius of the inboard leg of the TF coil [m].

required
r_tf_outboard_mid float

Mid-plane radius of the outboard leg of the TF coil [m].

required
dr_tf_outboard float

Radial thickness of the outboard leg of the TF coil [m].

required

Returns:

Type Description
tuple

A tuple containing: - rad_tf_coil_inboard_toroidal_half (float): Toroidal angular spacing of each TF coil [radians]. - tan_theta_coil (float): Tangent of the toroidal angular spacing. - a_tf_inboard_total (float): Cross-sectional area of the inboard leg of the TF coil [m²]. - r_tf_outboard_in (float): Inner radius of the outboard leg of the TF coil [m]. - r_tf_outboard_out (float): Outer radius of the outboard leg of the TF coil [m]. - dx_tf_inboard_out_toroidal (float): Width of the inboard leg at the outer edge in the toroidal direction [m]. - a_tf_leg_outboard (float): Cross-sectional area of the outboard leg of the TF coil [m²].

Source code in process/models/tfcoil/base.py
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
def tf_global_geometry(
    self,
    i_tf_case_geom: int,
    i_f_dr_tf_plasma_case: bool,
    f_dr_tf_plasma_case: float,
    tfc_sidewall_is_fraction: bool,
    casths_fraction: float,
    n_tf_coils: int,
    dr_tf_inboard: float,
    dr_tf_nose_case: float,
    r_tf_inboard_out: float,
    r_tf_inboard_in: float,
    r_tf_outboard_mid: float,
    dr_tf_outboard: float,
) -> tuple[float, float, float, float, float, float, float, float, float]:
    """Calculate the global geometry of the Toroidal Field (TF) coil.

    This method computes the overall geometry of the TF coil, including:

    - Toroidal angular spacing and tangent of the angle.
    - Cross-sectional areas of the inboard and outboard legs.
    - Radii and widths of the inboard and outboard legs.
    - Case thicknesses for plasma-facing and sidewall regions.

    Parameters
    ----------
    i_tf_case_geom : int
        Geometry type of the TF coil case (e.g., circular or straight plasma-facing front case).
    i_f_dr_tf_plasma_case : bool
        Whether the plasma-facing case thickness is specified as a fraction of the inboard thickness.
    f_dr_tf_plasma_case : float
        Fraction of the inboard thickness used for the plasma-facing case thickness.
    tfc_sidewall_is_fraction : bool
        Whether the sidewall case thickness is specified as a fraction of the inboard radius.
    casths_fraction : float
        Fraction of the inboard radius used for the sidewall case thickness.
    n_tf_coils : int
        Number of TF coils.
    dr_tf_inboard : float
        Radial thickness of the inboard leg of the TF coil [m].
    dr_tf_nose_case : float
        Thickness of the inboard leg case at the nose region [m].
    r_tf_inboard_out : float
        Outer radius of the inboard leg of the TF coil [m].
    r_tf_inboard_in : float
        Inner radius of the inboard leg of the TF coil [m].
    r_tf_outboard_mid : float
        Mid-plane radius of the outboard leg of the TF coil [m].
    dr_tf_outboard : float
        Radial thickness of the outboard leg of the TF coil [m].

    Returns
    -------
    tuple
        A tuple containing:
        - **rad_tf_coil_inboard_toroidal_half** (*float*): Toroidal angular spacing of each TF coil [radians].
        - **tan_theta_coil** (*float*): Tangent of the toroidal angular spacing.
        - **a_tf_inboard_total** (*float*): Cross-sectional area of the inboard leg of the TF coil [m²].
        - **r_tf_outboard_in** (*float*): Inner radius of the outboard leg of the TF coil [m].
        - **r_tf_outboard_out** (*float*): Outer radius of the outboard leg of the TF coil [m].
        - **dx_tf_inboard_out_toroidal** (*float*): Width of the inboard leg at the outer edge in the toroidal direction [m].
        - **a_tf_leg_outboard** (*float*): Cross-sectional area of the outboard leg of the TF coil [m²].
    """

    # The angular space of each TF coil in the toroidal direction [rad]
    # The angular space between each coil is the same as that of the coils

    rad_tf_coil_inboard_toroidal_half = np.pi / n_tf_coils
    tan_theta_coil = np.tan(rad_tf_coil_inboard_toroidal_half)

    # TF coil inboard legs total mid-plane cross-section area [m^2]
    if i_tf_case_geom == 0:
        # Circular plasma facing front case
        a_tf_inboard_total = np.pi * (r_tf_inboard_out**2 - r_tf_inboard_in**2)
    else:
        # Straight plasma facing front case
        a_tf_inboard_total = (
            n_tf_coils
            * np.sin(rad_tf_coil_inboard_toroidal_half)
            * np.cos(rad_tf_coil_inboard_toroidal_half)
            * r_tf_inboard_out**2
            - np.pi * r_tf_inboard_in**2
        )

    # TF coil width in toroidal direction at inboard leg outer edge [m]

    dx_tf_inboard_out_toroidal = (
        2.0e0 * r_tf_inboard_out * np.sin(rad_tf_coil_inboard_toroidal_half)
    )

    # Outer leg geometry
    # Mid-plane inner/out radial position of the TF coil outer leg [m]

    r_tf_outboard_in = r_tf_outboard_mid - (dr_tf_outboard * 0.5e0)
    r_tf_outboard_out = r_tf_outboard_mid + (dr_tf_outboard * 0.5e0)

    # Area of rectangular cross-section TF outboard leg [m^2]
    a_tf_leg_outboard = dx_tf_inboard_out_toroidal * dr_tf_outboard

    # ======================================================================
    # Plasma facing front case thickness [m]

    if i_f_dr_tf_plasma_case:
        # Set as fraction of the coil radial thickness
        dr_tf_plasma_case = f_dr_tf_plasma_case * dr_tf_inboard
    else:
        # Set directly as input
        dr_tf_plasma_case = tfcoil_variables.dr_tf_plasma_case

    # This ensures that there is sufficient radial space for the WP to not
    # clip the edges of the plasma-facing front case

    if dr_tf_plasma_case < (r_tf_inboard_in + dr_tf_inboard) * (
        1 - (np.cos(np.pi / tfcoil_variables.n_tf_coils))
    ):
        dr_tf_plasma_case = (
            1.0
            * (r_tf_inboard_in + dr_tf_inboard)
            * (1 - (np.cos(np.pi / tfcoil_variables.n_tf_coils)))
        )

    # Warn that the value has be forced to a minimum value at some point in
    # iteration
    logger.error(
        "dr_tf_plasma_case too small to accommodate the WP, forced to minimum value"
    )

    # ======================================================================

    # Case thickness of side wall [m]
    if tfc_sidewall_is_fraction:
        dx_tf_side_case_min = (
            casths_fraction
            * (r_tf_inboard_in + dr_tf_nose_case)
            * np.tan(np.pi / n_tf_coils)
        )
    else:
        dx_tf_side_case_min = tfcoil_variables.dx_tf_side_case_min

    return (
        rad_tf_coil_inboard_toroidal_half,
        tan_theta_coil,
        a_tf_inboard_total,
        r_tf_outboard_in,
        r_tf_outboard_out,
        dx_tf_inboard_out_toroidal,
        a_tf_leg_outboard,
        dr_tf_plasma_case,
        dx_tf_side_case_min,
    )

tf_current(n_tf_coils, b_plasma_toroidal_on_axis, rmajor, r_b_tf_inboard_peak, a_tf_inboard_total)

Calculate the maximum B field and the corresponding TF current.

Parameters:

Name Type Description Default
n_tf_coils int

Number of TF coils.

required
b_plasma_toroidal_on_axis float

Toroidal magnetic field at the plasma center [T].

required
rmajor float

Major radius of the plasma [m].

required
r_b_tf_inboard_peak float

Radius at which the peak inboard B field occurs [m].

required
a_tf_inboard_total float

Cross-sectional area of the inboard leg of the TF coil [m²].

required

Returns:

Type Description
tuple[float, float, float, float]

A tuple containing: - b_tf_inboard_peak_symmetric (float): Maximum B field on the magnet [T]. - c_tf_total (float): Total current in TF coils [A]. - c_tf_coil (float): Current per TF coil [A]. - oacdcp (float): Global inboard leg average current density in TF coils [A/m²].

Source code in process/models/tfcoil/base.py
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
def tf_current(
    self,
    n_tf_coils: int,
    b_plasma_toroidal_on_axis: float,
    rmajor: float,
    r_b_tf_inboard_peak: float,
    a_tf_inboard_total: float,
) -> tuple[float, float, float, float]:
    """Calculate the maximum B field and the corresponding TF current.

    Parameters
    ----------
    n_tf_coils : int
        Number of TF coils.
    b_plasma_toroidal_on_axis : float
        Toroidal magnetic field at the plasma center [T].
    rmajor : float
        Major radius of the plasma [m].
    r_b_tf_inboard_peak : float
        Radius at which the peak inboard B field occurs [m].
    a_tf_inboard_total : float
        Cross-sectional area of the inboard leg of the TF coil [m²].

    Returns
    -------
    tuple[float, float, float, float]
        A tuple containing:
        - **b_tf_inboard_peak_symmetric** (*float*): Maximum B field on the magnet [T].
        - **c_tf_total** (*float*): Total current in TF coils [A].
        - **c_tf_coil** (*float*): Current per TF coil [A].
        - **oacdcp** (*float*): Global inboard leg average current density in TF coils [A/m²].
    """

    # Calculation of the maximum B field on the magnet [T]
    b_tf_inboard_peak_symmetric = (
        b_plasma_toroidal_on_axis * rmajor / r_b_tf_inboard_peak
    )

    # Total current in TF coils [A]
    c_tf_total = (
        b_tf_inboard_peak_symmetric
        * r_b_tf_inboard_peak
        * (2 * np.pi / constants.RMU0)
    )

    # Current per TF coil [A]
    c_tf_coil = c_tf_total / n_tf_coils

    # Global inboard leg average current in TF coils [A/m2]
    oacdcp = c_tf_total / a_tf_inboard_total

    return b_tf_inboard_peak_symmetric, c_tf_total, c_tf_coil, oacdcp

tf_coil_shape_inner(i_tf_shape, itart, i_single_null, r_tf_inboard_out, r_cp_top, rmajor, rminor, r_tf_outboard_in, z_tf_inside_half, z_tf_top, dr_tf_inboard, dr_tf_outboard, r_tf_outboard_mid, r_tf_inboard_mid)

Calculate the shape of the inside of the TF coil.

This method approximates the TF coil by a straight inboard section and four elliptical arcs. The model is ad hoc and does not have a physics or engineering basis.

Parameters:

Name Type Description Default
i_tf_shape int

TF coil shape selection switch.

required
itart int

TART (tight aspect ratio tokamak) switch.

required
i_single_null int

Single null switch.

required
r_tf_inboard_out float

Outer radius of the inboard leg of the TF coil [m].

required
r_cp_top float

Centrepost outer radius at the top [m].

required
rmajor float

Major radius of the plasma [m].

required
rminor float

Minor radius of the plasma [m].

required
r_tf_outboard_in float

Inner radius of the outboard leg of the TF coil [m].

required
z_tf_inside_half float

Maximum inboard edge height [m].

required
z_tf_top float

Vertical position of the top of the TF coil [m].

required
dr_tf_inboard float

Radial thickness of the inboard leg of the TF coil [m].

required
dr_tf_outboard float

Radial thickness of the outboard leg of the TF coil [m].

required
r_tf_outboard_mid float

Mid-plane radius of the outboard leg of the TF coil [m].

required
r_tf_inboard_mid float

Mid-plane radius of the inboard leg of the TF coil [m].

required

Returns:

Type Description
tuple[float, ndarray, ndarray, ndarray, ndarray]

len_tf_coil (float): Total length of the TF coil. - tfa (np.ndarray): Arc segment lengths in R. - tfb (np.ndarray): Arc segment lengths in Z. - r_tf_arc (np.ndarray): R coordinates of arc points. - z_tf_arc (np.ndarray): Z coordinates of arc points.

Source code in process/models/tfcoil/base.py
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
def tf_coil_shape_inner(
    self,
    i_tf_shape: int,
    itart: int,
    i_single_null: int,
    r_tf_inboard_out: float,
    r_cp_top: float,
    rmajor: float,
    rminor: float,
    r_tf_outboard_in: float,
    z_tf_inside_half: float,
    z_tf_top: float,
    dr_tf_inboard: float,
    dr_tf_outboard: float,
    r_tf_outboard_mid: float,
    r_tf_inboard_mid: float,
) -> tuple[float, np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
    """Calculate the shape of the inside of the TF coil.

    This method approximates the TF coil by a straight inboard section and four elliptical arcs.
    The model is ad hoc and does not have a physics or engineering basis.

    Parameters
    ----------
    i_tf_shape : int
        TF coil shape selection switch.
    itart : int
        TART (tight aspect ratio tokamak) switch.
    i_single_null : int
        Single null switch.
    r_tf_inboard_out : float
        Outer radius of the inboard leg of the TF coil [m].
    r_cp_top : float
        Centrepost outer radius at the top [m].
    rmajor : float
        Major radius of the plasma [m].
    rminor : float
        Minor radius of the plasma [m].
    r_tf_outboard_in : float
        Inner radius of the outboard leg of the TF coil [m].
    z_tf_inside_half : float
        Maximum inboard edge height [m].
    z_tf_top : float
        Vertical position of the top of the TF coil [m].
    dr_tf_inboard : float
        Radial thickness of the inboard leg of the TF coil [m].
    dr_tf_outboard : float
        Radial thickness of the outboard leg of the TF coil [m].
    r_tf_outboard_mid : float
        Mid-plane radius of the outboard leg of the TF coil [m].
    r_tf_inboard_mid : float
        Mid-plane radius of the inboard leg of the TF coil [m].

    Returns
    -------
    tuple[float, np.ndarray, np.ndarray, np.ndarray, np.ndarray]
        len_tf_coil (float): Total length of the TF coil.
        - tfa (np.ndarray): Arc segment lengths in R.
        - tfb (np.ndarray): Arc segment lengths in Z.
        - r_tf_arc (np.ndarray): R coordinates of arc points.
        - z_tf_arc (np.ndarray): Z coordinates of arc points.
    """
    FSTRAIGHT = 0.6
    len_tf_coil = 0.0
    r_tf_arc = np.zeros(5)
    z_tf_arc = np.zeros(5)
    tfa = np.zeros(4)
    tfb = np.zeros(4)

    if i_tf_shape == 1 and itart == 0:
        # PROCESS D-shape parameterisation
        r_tf_arc[0] = r_tf_inboard_out
        r_tf_arc[1] = rmajor - 0.2e0 * rminor
        r_tf_arc[2] = r_tf_outboard_in
        r_tf_arc[3] = r_tf_arc[1]
        r_tf_arc[4] = r_tf_arc[0]

        if i_single_null == 0:
            z_tf_arc[0] = FSTRAIGHT * z_tf_inside_half
            z_tf_arc[1] = z_tf_inside_half
            z_tf_arc[2] = 0
            z_tf_arc[3] = -z_tf_inside_half
            z_tf_arc[4] = -FSTRAIGHT * z_tf_inside_half
        else:
            z_tf_arc[0] = FSTRAIGHT * (z_tf_top - dr_tf_inboard)
            z_tf_arc[1] = z_tf_top - dr_tf_inboard
            z_tf_arc[2] = 0
            z_tf_arc[3] = -z_tf_inside_half
            z_tf_arc[4] = -FSTRAIGHT * z_tf_inside_half

        len_tf_coil = z_tf_arc[0] - z_tf_arc[4]

        for ii in range(4):
            tfa[ii] = abs(r_tf_arc[ii + 1] - r_tf_arc[ii])
            tfb[ii] = abs(z_tf_arc[ii + 1] - z_tf_arc[ii])
            aa = tfa[ii] + 0.5e0 * dr_tf_inboard
            bb = tfb[ii] + 0.5e0 * dr_tf_inboard
            len_tf_coil += 0.25e0 * self.circumference(aa, bb)

    elif i_tf_shape == 1 and itart == 1:
        # Centrepost with D-shaped
        r_tf_arc[0] = r_cp_top
        r_tf_arc[1] = rmajor - 0.2e0 * rminor
        r_tf_arc[2] = r_tf_outboard_in
        r_tf_arc[3] = r_tf_arc[1]
        r_tf_arc[4] = r_tf_arc[0]

        z_tf_arc[0] = z_tf_top - dr_tf_inboard
        z_tf_arc[1] = z_tf_top - dr_tf_inboard
        z_tf_arc[2] = 0
        z_tf_arc[3] = -z_tf_inside_half
        z_tf_arc[4] = -z_tf_inside_half

        len_tf_coil = 2 * (r_tf_arc[1] - r_tf_arc[0])

        for ii in range(1, 3):
            tfa[ii] = abs(r_tf_arc[ii + 1] - r_tf_arc[ii])
            tfb[ii] = abs(z_tf_arc[ii + 1] - z_tf_arc[ii])
            aa = tfa[ii] + 0.5e0 * dr_tf_outboard
            bb = tfb[ii] + 0.5e0 * dr_tf_outboard
            len_tf_coil += 0.25e0 * self.circumference(aa, bb)

    elif i_tf_shape == 2:
        # Picture frame coil
        if itart == 0:
            r_tf_arc[0] = r_tf_inboard_out
        if itart == 1:
            r_tf_arc[0] = r_cp_top
        r_tf_arc[1] = r_tf_outboard_in
        r_tf_arc[2] = r_tf_arc[1]
        r_tf_arc[3] = r_tf_arc[1]
        r_tf_arc[4] = r_tf_arc[0]

        z_tf_arc[0] = z_tf_top - dr_tf_inboard
        z_tf_arc[1] = z_tf_top - dr_tf_inboard
        z_tf_arc[2] = 0
        z_tf_arc[3] = -z_tf_inside_half
        z_tf_arc[4] = -z_tf_inside_half

        if itart == 0:
            len_tf_coil = 2.0e0 * (
                2.0e0 * z_tf_inside_half
                + dr_tf_inboard
                + r_tf_outboard_mid
                - r_tf_inboard_mid
            )
        elif itart == 1:
            len_tf_coil = (
                z_tf_inside_half + z_tf_top + 2.0e0 * (r_tf_outboard_mid - r_cp_top)
            )

    return len_tf_coil, tfa, tfb, r_tf_arc, z_tf_arc

tf_stored_magnetic_energy(ind_tf_coil, c_tf_total, n_tf_coils)

Calculates the stored magnetic energy in a single TF coil.

Parameters:

Name Type Description Default
ind_tf_coil float

Self-inductance of the TF coil [H].

required
c_tf_total float

Current in all TF coils [A].

required
n_tf_coils int

Number of TF coils.

required

Returns:

Type Description
tuple[float, float, float]

Tuple containing: - e_tf_magnetic_stored_total (float): Total stored magnetic energy in all TF coils [J]. - e_tf_magnetic_stored_total_gj (float): Total stored magnetic energy in all TF coils [GJ]. - e_tf_coil_magnetic_stored (float): Stored magnetic energy in a single TF coil [J].

Notes
- The stored magnetic energy in an inductor is given by:
    E = (1/2) * L * I^2
    where E is the energy [J], L is the inductance [H], and I is the current [A].
- Total energy is for all coils; per-coil energy is divided by n_tf_coils.
References
- http://hyperphysics.phy-astr.gsu.edu/hbase/electric/indeng.html

- https://en.wikipedia.org/wiki/Inductance#Self-inductance_and_magnetic_energy
Source code in process/models/tfcoil/base.py
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
def tf_stored_magnetic_energy(
    self,
    ind_tf_coil: float,
    c_tf_total: float,
    n_tf_coils: int,
) -> tuple[float, float, float]:
    """Calculates the stored magnetic energy in a single TF coil.

    Parameters
    ----------
    ind_tf_coil : float
        Self-inductance of the TF coil [H].
    c_tf_total : float
        Current in all TF coils [A].
    n_tf_coils : int
        Number of TF coils.

    Returns
    -------
    tuple[float, float, float]
        Tuple containing:
        - e_tf_magnetic_stored_total (float): Total stored magnetic energy in all TF coils [J].
        - e_tf_magnetic_stored_total_gj (float): Total stored magnetic energy in all TF coils [GJ].
        - e_tf_coil_magnetic_stored (float): Stored magnetic energy in a single TF coil [J].

    Notes
    -----
        - The stored magnetic energy in an inductor is given by:
            E = (1/2) * L * I^2
            where E is the energy [J], L is the inductance [H], and I is the current [A].
        - Total energy is for all coils; per-coil energy is divided by n_tf_coils.

    References
    ----------
        - http://hyperphysics.phy-astr.gsu.edu/hbase/electric/indeng.html

        - https://en.wikipedia.org/wiki/Inductance#Self-inductance_and_magnetic_energy
    """
    e_tf_magnetic_stored_total = 0.5 * ind_tf_coil * c_tf_total**2

    e_tf_magnetic_stored_total_gj = e_tf_magnetic_stored_total * 1.0e-9

    e_tf_coil_magnetic_stored = e_tf_magnetic_stored_total / n_tf_coils

    return (
        e_tf_magnetic_stored_total,
        e_tf_magnetic_stored_total_gj,
        e_tf_coil_magnetic_stored,
    )

outtf()

Writes superconducting TF coil output to file

This routine writes the superconducting TF coil results to the output file. PROCESS Superconducting TF Coil Model, J. Morris, CCFE, 1st May 2014

Source code in process/models/tfcoil/base.py
 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
def outtf(self):
    """Writes superconducting TF coil output to file

    This routine writes the superconducting TF coil results
    to the output file.
    PROCESS Superconducting TF Coil Model, J. Morris, CCFE, 1st May 2014
    """

    # General coil parameters
    po.osubhd(self.outfile, "TF design")
    po.ovarin(
        self.outfile,
        "Conductor technology",
        "(i_tf_sup)",
        tfcoil_variables.i_tf_sup,
    )

    if tfcoil_variables.i_tf_sup == 0:
        po.ocmmnt(
            self.outfile, "  -> resistive coil : Water cooled copper (GLIDCOP AL-15)"
        )
    elif tfcoil_variables.i_tf_sup == 1:
        po.ocmmnt(self.outfile, "  -> Superconducting coil (SC)")
    elif tfcoil_variables.i_tf_sup == 2:
        po.ocmmnt(self.outfile, "  -> Resistive coil : Helium cooled aluminium")

    # SC material scaling
    if tfcoil_variables.i_tf_sup == 1:
        po.ovarin(
            self.outfile,
            "Superconductor material",
            "(i_tf_sc_mat)",
            tfcoil_variables.i_tf_sc_mat,
        )

        if tfcoil_variables.i_tf_sc_mat == 1:
            po.ocmmnt(self.outfile, "  -> ITER Nb3Sn critical surface model")
        elif tfcoil_variables.i_tf_sc_mat == 2:
            po.ocmmnt(self.outfile, "  -> Bi-2212 high temperature superconductor")
        elif tfcoil_variables.i_tf_sc_mat == 3:
            po.ocmmnt(self.outfile, "  -> NbTi")
        elif tfcoil_variables.i_tf_sc_mat == 4:
            po.ocmmnt(
                self.outfile,
                "  -> ITER Nb3Sn critical surface model, user-defined parameters",
            )
        elif tfcoil_variables.i_tf_sc_mat == 5:
            po.ocmmnt(self.outfile, "  -> WST Nb3Sn")
        elif tfcoil_variables.i_tf_sc_mat == 6:
            po.ocmmnt(
                self.outfile,
                "  -> High temperature superconductor: REBCO HTS tape in CroCo strand",
            )
        elif tfcoil_variables.i_tf_sc_mat == 7:
            po.ocmmnt(
                self.outfile,
                "  ->  Durham Ginzburg-Landau critical surface model for Nb-Ti",
            )
        elif tfcoil_variables.i_tf_sc_mat == 8:
            po.ocmmnt(
                self.outfile,
                "  ->  Durham Ginzburg-Landau critical surface model for REBCO",
            )
        elif tfcoil_variables.i_tf_sc_mat == 9:
            po.ocmmnt(
                self.outfile,
                "  ->  Hazelton experimental data + Zhai conceptual model for REBCO",
            )

    # Joints strategy
    po.ovarin(
        self.outfile,
        "Presence of TF demountable joints",
        "(itart)",
        physics_variables.itart,
    )
    if physics_variables.itart == 1:
        po.ocmmnt(
            self.outfile, "  -> TF coil made of a Centerpost (CP) and outer legs"
        )
        po.ocmmnt(self.outfile, "     interfaced with demountable joints")
    else:
        po.ocmmnt(self.outfile, "  -> Coils without demountable joints")

    # Centring forces support strategy
    po.ovarin(
        self.outfile,
        "TF inboard leg support strategy",
        "(i_tf_bucking)",
        tfcoil_variables.i_tf_bucking,
    )

    if tfcoil_variables.i_tf_bucking == 0:
        po.ocmmnt(self.outfile, "  -> No support structure")
    elif tfcoil_variables.i_tf_bucking == 1:
        if tfcoil_variables.i_tf_sup == 1:
            po.ocmmnt(self.outfile, "  -> Steel casing")
        elif (
            abs(tfcoil_variables.eyoung_res_tf_buck - 205.0e9)
            < np.finfo(float(tfcoil_variables.eyoung_res_tf_buck)).eps
        ):
            po.ocmmnt(self.outfile, "  -> Steel bucking cylinder")
        else:
            po.ocmmnt(self.outfile, "  -> Bucking cylinder")

    elif (
        tfcoil_variables.i_tf_bucking in (2, 3)
        and build_variables.i_tf_inside_cs == 1
    ):
        po.ocmmnt(
            self.outfile,
            "  -> TF in contact with dr_bore filler support (bucked and weged design)",
        )

    elif (
        tfcoil_variables.i_tf_bucking in (2, 3)
        and build_variables.i_tf_inside_cs == 0
    ):
        po.ocmmnt(
            self.outfile, "  -> TF in contact with CS (bucked and weged design)"
        )

    # TF coil geometry
    po.osubhd(self.outfile, "TF coil Geometry :")
    po.ovarin(
        self.outfile,
        "Number of TF coils",
        "(n_tf_coils)",
        int(tfcoil_variables.n_tf_coils),
    )
    po.ovarre(
        self.outfile,
        "Inboard TF half angle [rad]",
        "(rad_tf_coil_inboard_toroidal_half)",
        superconducting_tf_coil_variables.rad_tf_coil_inboard_toroidal_half,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Inboard leg centre radius (m)",
        "(r_tf_inboard_mid)",
        build_variables.r_tf_inboard_mid,
        "OP ",
    )
    po.ovarre(
        constants.MFILE,
        "Inboard leg inner radius (m)",
        "(r_tf_inboard_in)",
        build_variables.r_tf_inboard_in,
        "OP ",
    )
    po.ovarre(
        constants.MFILE,
        "Inboard leg outer radius (m)",
        "(r_tf_inboard_out)",
        build_variables.r_tf_inboard_out,
        "OP ",
    )
    po.ovarin(
        self.outfile,
        "WP shape selection switch",
        "(i_tf_wp_geom)",
        tfcoil_variables.i_tf_wp_geom,
    )
    po.ovarre(
        constants.MFILE,
        "Radial position of inner edge and centre of winding pack (m)",
        "(r_tf_wp_inboard_inner)",
        superconducting_tf_coil_variables.r_tf_wp_inboard_inner,
        "OP ",
    )
    po.ovarre(
        constants.MFILE,
        "Radial position of outer edge and of winding pack (m)",
        "(r_tf_wp_inboard_outer)",
        superconducting_tf_coil_variables.r_tf_wp_inboard_outer,
        "OP ",
    )
    po.ovarre(
        constants.MFILE,
        "Radial position of centre of winding pack (m)",
        "(r_tf_wp_inboard_centre)",
        superconducting_tf_coil_variables.r_tf_wp_inboard_centre,
        "OP ",
    )
    po.ovarre(
        constants.MFILE,
        "Minimum toroidal thickness of winding pack (m)",
        "(dx_tf_wp_toroidal_min)",
        superconducting_tf_coil_variables.dx_tf_wp_toroidal_min,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Outboard leg inner radius (m)",
        "(r_tf_outboard_in)",
        superconducting_tf_coil_variables.r_tf_outboard_in,
        "OP ",
    )

    po.ovarre(
        self.outfile,
        "Outboard leg centre radius (m)",
        "(r_tf_outboard_mid)",
        build_variables.r_tf_outboard_mid,
        "OP ",
    )
    po.ovarin(
        self.outfile,
        "Outboard leg nose case type",
        "(i_tf_case_geom)",
        tfcoil_variables.i_tf_case_geom,
    )
    po.ovarre(
        self.outfile,
        "Total inboard leg radial thickness (m)",
        "(dr_tf_inboard)",
        build_variables.dr_tf_inboard,
    )
    po.ovarre(
        self.outfile,
        "Total outboard leg radial thickness (m)",
        "(dr_tf_outboard)",
        build_variables.dr_tf_outboard,
    )
    po.ovarre(
        self.outfile,
        "Outboard leg toroidal thickness (m)",
        "(dx_tf_inboard_out_toroidal)",
        tfcoil_variables.dx_tf_inboard_out_toroidal,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Maximum inboard edge height (m)",
        "(z_tf_inside_half)",
        build_variables.z_tf_inside_half,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Height to top of TF coil (m)",
        "(z_tf_top)",
        build_variables.z_tf_top,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Height difference in upper and lower TF from midplane (m)",
        "(dz_tf_upper_lower_midplane)",
        build_variables.dz_tf_upper_lower_midplane,
        "OP ",
    )
    if physics_variables.itart == 1:
        po.ovarre(
            self.outfile,
            "Mean coil circumference (inboard leg not included) (m)",
            "(len_tf_coil)",
            tfcoil_variables.len_tf_coil,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Length of the inboard segment (m)",
            "(cplen)",
            tfcoil_variables.cplen,
            "OP ",
        )
    else:
        po.ovarre(
            self.outfile,
            "Mean coil circumference (including inboard leg length) (m)",
            "(len_tf_coil)",
            tfcoil_variables.len_tf_coil,
            "OP ",
        )

    # Vertical shape
    po.ovarin(
        self.outfile,
        "Vertical TF shape",
        "(i_tf_shape)",
        tfcoil_variables.i_tf_shape,
    )
    if tfcoil_variables.i_tf_shape == 1:
        po.oblnkl(self.outfile)
        po.ocmmnt(self.outfile, "D-shape coil, inner surface shape approximated by")
        po.ocmmnt(
            self.outfile,
            "by a straight segment and elliptical arcs between the following points:",
        )
        po.oblnkl(self.outfile)
    elif tfcoil_variables.i_tf_shape == 2:
        po.oblnkl(self.outfile)
        po.ocmmnt(self.outfile, "Picture frame coil, inner surface approximated by")
        po.ocmmnt(
            self.outfile, "by a straight segment between the following points:"
        )
        po.oblnkl(self.outfile)

    po.write(self.outfile, "  point              x(m)              y(m)")
    for ii in range(5):
        po.write(
            self.outfile,
            f"  {ii}              {tfcoil_variables.r_tf_arc[ii]}              {tfcoil_variables.z_tf_arc[ii]}",
        )
        po.ovarre(
            constants.MFILE,
            f"TF coil arc point {ii} R (m)",
            f"(r_tf_arc({ii + 1}))",
            tfcoil_variables.r_tf_arc[ii],
        )
        po.ovarre(
            constants.MFILE,
            f"TF coil arc point {ii} Z (m)",
            f"(z_tf_arc({ii + 1}))",
            tfcoil_variables.z_tf_arc[ii],
        )

    # CP tapering geometry
    if physics_variables.itart == 1 and tfcoil_variables.i_tf_sup != 1:
        po.osubhd(self.outfile, "Tapered Centrepost TF coil Dimensions:")
        po.ovarre(
            self.outfile,
            "TF coil centrepost outer radius at midplane (m)",
            "(r_tf_inboard_out)",
            build_variables.r_tf_inboard_out,
        )
        po.ovarre(
            self.outfile,
            "TF coil centrepost outer radius at its top (m)",
            "(r_cp_top)",
            build_variables.r_cp_top,
        )
        po.ovarre(
            self.outfile,
            "Top/miplane TF CP radius ratio (-)",
            "(f_r_cp)",
            build_variables.f_r_cp,
        )
        po.ovarre(
            self.outfile,
            "Distance from the midplane to the top of the tapered section (m)",
            "(z_cp_top)",
            superconducting_tf_coil_variables.z_cp_top,
        )
        po.ovarre(
            self.outfile,
            "Distance from the midplane to the top of the centrepost (m)",
            "(z_tf_inside_half + dr_tf_outboard)",
            build_variables.z_tf_inside_half + build_variables.dr_tf_outboard,
        )

    # Turn/WP gemoetry
    if tfcoil_variables.i_tf_sup == 1:
        # Total material fraction
        po.osubhd(self.outfile, "Global material area/fractions:")
        po.ovarre(
            self.outfile,
            "TF cross-section (total) (m2)",
            "(a_tf_inboard_total)",
            tfcoil_variables.a_tf_inboard_total,
        )
        po.ovarre(
            self.outfile,
            "Total steel cross-section (m2)",
            "(a_tf_coil_inboard_steel*n_tf_coils)",
            superconducting_tf_coil_variables.a_tf_coil_inboard_steel
            * tfcoil_variables.n_tf_coils,
        )
        po.ovarre(
            self.outfile,
            "Total steel TF fraction",
            "(f_a_tf_coil_inboard_steel)",
            superconducting_tf_coil_variables.f_a_tf_coil_inboard_steel,
        )
        po.ovarre(
            self.outfile,
            "Total Insulation cross-section (total) (m2)",
            "(a_tf_coil_inboard_insulation*n_tf_coils)",
            superconducting_tf_coil_variables.a_tf_coil_inboard_insulation
            * tfcoil_variables.n_tf_coils,
        )
        po.ovarre(
            self.outfile,
            "Total Insulation fraction",
            "(f_a_tf_coil_inboard_insulation)",
            superconducting_tf_coil_variables.f_a_tf_coil_inboard_insulation,
        )

        # External casing
        po.osubhd(self.outfile, "External steel Case Information :")
        po.ovarre(
            self.outfile,
            "Casing cross section area (per leg) (m2)",
            "(a_tf_coil_inboard_case)",
            tfcoil_variables.a_tf_coil_inboard_case,
        )
        po.ovarre(
            self.outfile,
            "Inboard leg case plasma side wall thickness (m)",
            "(dr_tf_plasma_case)",
            tfcoil_variables.dr_tf_plasma_case,
        )
        po.ovarre(
            self.outfile,
            "Inboard leg plasma case area (m^2)",
            "(a_tf_plasma_case)",
            superconducting_tf_coil_variables.a_tf_plasma_case,
        )
        po.ovarre(
            self.outfile,
            'Inboard leg case inboard "nose" thickness (m)',
            "(dr_tf_nose_case)",
            tfcoil_variables.dr_tf_nose_case,
        )
        po.ovarre(
            self.outfile,
            'Inboard leg case inboard "nose" area (m^2)',
            "(a_tf_coil_nose_case)",
            superconducting_tf_coil_variables.a_tf_coil_nose_case,
        )
        po.ovarre(
            self.outfile,
            "Inboard leg case sidewall thickness at its narrowest point (m)",
            "(dx_tf_side_case_min)",
            tfcoil_variables.dx_tf_side_case_min,
        )
        po.ovarre(
            self.outfile,
            "Inboard leg case sidewall average thickness (m)",
            "(dx_tf_side_case_average)",
            superconducting_tf_coil_variables.dx_tf_side_case_average,
        )
        po.ovarre(
            self.outfile,
            "Inboard leg case sidewall peak thickness (m)",
            "(dx_tf_side_case_peak)",
            superconducting_tf_coil_variables.dx_tf_side_case_peak,
        )
        po.ovarre(
            self.outfile,
            "External case mass per coil (kg)",
            "(m_tf_coil_case)",
            tfcoil_variables.m_tf_coil_case,
            "OP ",
        )

        # Winding pack structure
        po.osubhd(self.outfile, "TF winding pack (WP) geometry:")
        po.ovarre(
            self.outfile,
            "WP cross section area with insulation and insertion (per coil) (m2)",
            "(a_tf_wp_with_insulation)",
            superconducting_tf_coil_variables.a_tf_wp_with_insulation,
        )
        po.ovarre(
            self.outfile,
            "WP cross section area with no insulation and insertion (per coil) (m2)",
            "(a_tf_wp_no_insulation)",
            superconducting_tf_coil_variables.a_tf_wp_no_insulation,
        )
        po.ovarre(
            self.outfile,
            "Total steel area in WP (per coil) (m2)",
            "(a_tf_wp_steel)",
            tfcoil_variables.a_tf_wp_steel,
        )
        po.ovarre(
            self.outfile,
            "Winding pack radial thickness (m)",
            "(dr_tf_wp_with_insulation)",
            tfcoil_variables.dr_tf_wp_with_insulation,
            "OP ",
        )
        if tfcoil_variables.i_tf_turns_integer == 1:
            po.ovarre(
                self.outfile,
                "Winding pack toroidal width (m)",
                "(dx_tf_wp_primary_toroidal)",
                tfcoil_variables.dx_tf_wp_primary_toroidal,
                "OP ",
            )
        else:
            po.ovarre(
                self.outfile,
                "Winding pack toroidal width 1 (m)",
                "(dx_tf_wp_primary_toroidal)",
                tfcoil_variables.dx_tf_wp_primary_toroidal,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Winding pack toroidal width 2 (m)",
                "(dx_tf_wp_secondary_toroidal)",
                tfcoil_variables.dx_tf_wp_secondary_toroidal,
                "OP ",
            )

        po.ovarre(
            self.outfile,
            "Ground wall insulation thickness (m)",
            "(dx_tf_wp_insulation)",
            tfcoil_variables.dx_tf_wp_insulation,
        )
        po.ovarre(
            self.outfile,
            "Ground wall insulation area (m^2)",
            "(a_tf_wp_ground_insulation)",
            superconducting_tf_coil_variables.a_tf_wp_ground_insulation,
        )
        po.ovarre(
            self.outfile,
            "Winding pack insertion gap (m)",
            "(dx_tf_wp_insertion_gap)",
            tfcoil_variables.dx_tf_wp_insertion_gap,
        )

        # WP material fraction
        po.osubhd(self.outfile, "TF winding pack (WP) material area/fractions:")
        po.ovarre(
            self.outfile,
            "Steel WP cross-section (total) (m2)",
            "(a_tf_wp_steel*n_tf_coils)",
            tfcoil_variables.a_tf_wp_steel * tfcoil_variables.n_tf_coils,
        )
        po.ovarre(
            self.outfile,
            "Steel WP fraction",
            "(a_tf_wp_steel/a_tf_wp_with_insulation)",
            tfcoil_variables.a_tf_wp_steel
            / superconducting_tf_coil_variables.a_tf_wp_with_insulation,
        )
        po.ovarre(
            self.outfile,
            "Insulation WP fraction",
            "(a_tf_coil_wp_turn_insulation/a_tf_wp_with_insulation)",
            tfcoil_variables.a_tf_coil_wp_turn_insulation
            / superconducting_tf_coil_variables.a_tf_wp_with_insulation,
        )
        po.ovarre(
            self.outfile,
            "Cable WP fraction",
            "((a_tf_wp_with_insulation-a_tf_wp_steel-a_tf_coil_wp_turn_insulation)/a_tf_wp_with_insulation)",
            (
                superconducting_tf_coil_variables.a_tf_wp_with_insulation
                - tfcoil_variables.a_tf_wp_steel
                - tfcoil_variables.a_tf_coil_wp_turn_insulation
            )
            / superconducting_tf_coil_variables.a_tf_wp_with_insulation,
        )

        # Number of turns
        po.osubhd(self.outfile, "WP turn information:")
        po.ovarin(
            self.outfile,
            "Turn parameterisation",
            "(i_tf_turns_integer)",
            tfcoil_variables.i_tf_turns_integer,
        )
        if tfcoil_variables.i_tf_turns_integer == 0:
            po.ocmmnt(self.outfile, "  Non-integer number of turns")
        else:
            po.ocmmnt(self.outfile, "  Integer number of turns")

        po.ovarre(
            self.outfile,
            "Number of turns per TF coil",
            "(n_tf_coil_turns)",
            tfcoil_variables.n_tf_coil_turns,
            "OP ",
        )
        if tfcoil_variables.i_tf_turns_integer == 1:
            po.ovarin(
                self.outfile,
                "Number of TF pancakes",
                "(n_tf_wp_pancakes)",
                tfcoil_variables.n_tf_wp_pancakes,
            )
            po.ovarin(
                self.outfile,
                "Number of TF layers",
                "(n_tf_wp_layers)",
                tfcoil_variables.n_tf_wp_layers,
            )

        po.oblnkl(self.outfile)

        if tfcoil_variables.i_tf_turns_integer == 1:
            po.ovarre(
                self.outfile,
                "Radial width of turn (m)",
                "(dr_tf_turn)",
                superconducting_tf_coil_variables.dr_tf_turn,
            )
            po.ovarre(
                self.outfile,
                "Toroidal width of turn (m)",
                "(dx_tf_turn)",
                superconducting_tf_coil_variables.dx_tf_turn,
            )
            po.ovarre(
                self.outfile,
                "Radial width of conductor (m)",
                "(t_conductor_radial)",
                superconducting_tf_coil_variables.t_conductor_radial,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Toroidal width of conductor (m)",
                "(t_conductor_toroidal)",
                superconducting_tf_coil_variables.t_conductor_toroidal,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Radial width of cable space",
                "(dr_tf_turn_cable_space)",
                superconducting_tf_coil_variables.dr_tf_turn_cable_space,
            )
            po.ovarre(
                self.outfile,
                "Toroidal width of cable space",
                "(dx_tf_turn_cable_space)",
                superconducting_tf_coil_variables.dx_tf_turn_cable_space,
            )
            po.ovarre(
                self.outfile,
                "Radius of turn cable space rounded corners (m)",
                "(radius_tf_turn_cable_space_corners)",
                superconducting_tf_coil_variables.radius_tf_turn_cable_space_corners,
            )
        else:
            po.ovarre(
                self.outfile,
                "Width of turn including inter-turn insulation (m)",
                "(dx_tf_turn_general)",
                tfcoil_variables.dx_tf_turn_general,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Width of conductor (square) (m)",
                "(t_conductor)",
                tfcoil_variables.t_conductor,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Width of space inside conductor (m)",
                "(dx_tf_turn_cable_space_average)",
                superconducting_tf_coil_variables.dx_tf_turn_cable_space_average,
                "OP ",
            )
            po.ovarre(
                self.outfile,
                "Radius of turn cable space rounded corners (m)",
                "(radius_tf_turn_cable_space_corners)",
                superconducting_tf_coil_variables.radius_tf_turn_cable_space_corners,
            )

        po.ovarre(
            self.outfile,
            "Steel conduit thickness (m)",
            "(dx_tf_turn_steel)",
            tfcoil_variables.dx_tf_turn_steel,
        )
        po.ovarre(
            self.outfile,
            "Inter-turn insulation thickness (m)",
            "(dx_tf_turn_insulation)",
            tfcoil_variables.dx_tf_turn_insulation,
        )

        if tfcoil_variables.i_tf_sc_mat in (1, 2, 3, 4, 5, 7, 8, 9):
            po.osubhd(self.outfile, "Conductor information:")
            po.ovarre(
                self.outfile,
                "Diameter of central helium channel in cable",
                "(dia_tf_turn_coolant_channel)",
                tfcoil_variables.dia_tf_turn_coolant_channel,
            )
            po.ovarre(
                self.outfile,
                "Diameter of superconducting cable",
                "(dia_tf_turn_superconducting_cable)",
                superconducting_tf_coil_variables.dia_tf_turn_superconducting_cable,
            )
            po.ovarre(
                self.outfile,
                "Number of superconducting cables per turn",
                "(n_tf_turn_superconducting_cables)",
                superconducting_tf_coil_variables.n_tf_turn_superconducting_cables,
            )
            po.ovarre(
                self.outfile,
                "Length of superconductor in TF coil (m)",
                "(len_tf_coil_superconductor)",
                superconducting_tf_coil_variables.len_tf_coil_superconductor,
            )
            po.ovarre(
                self.outfile,
                "Total length of superconductor in all TF coils (m)",
                "(len_tf_superconductor_total)",
                superconducting_tf_coil_variables.len_tf_superconductor_total,
            )
            po.ocmmnt(self.outfile, "Fractions by area")
            po.ovarre(
                self.outfile,
                "internal area of the cable space",
                "(a_tf_turn_cable_space_no_void)",
                tfcoil_variables.a_tf_turn_cable_space_no_void,
            )
            po.ovarre(
                self.outfile,
                "True area of turn cable space with gaps and channels removed",
                "(a_tf_turn_cable_space_effective)",
                superconducting_tf_coil_variables.a_tf_turn_cable_space_effective,
            )

            po.ovarre(
                self.outfile,
                "Coolant fraction in conductor excluding central channel",
                "(f_a_tf_turn_cable_space_extra_void)",
                tfcoil_variables.f_a_tf_turn_cable_space_extra_void,
            )
            po.ovarre(
                self.outfile,
                "Area of steel in turn",
                "(a_tf_turn_steel)",
                tfcoil_variables.a_tf_turn_steel,
            )
            po.ovarre(
                self.outfile,
                "Area of all turn insulation in WP",
                "(a_tf_coil_wp_turn_insulation)",
                tfcoil_variables.a_tf_coil_wp_turn_insulation,
            )
            po.ovarre(
                self.outfile,
                "Total insulation area in TF coil (turn and WP)",
                "(a_tf_coil_inboard_insulation)",
                superconducting_tf_coil_variables.a_tf_coil_inboard_insulation,
            )
            po.ovarre(
                self.outfile,
                "Total steel area in inboard TF coil (turn and case)",
                "(a_tf_coil_inboard_steel)",
                superconducting_tf_coil_variables.a_tf_coil_inboard_steel,
            )
            po.ovarre(
                self.outfile,
                "Total conductor area in WP",
                "(a_tf_wp_conductor)",
                tfcoil_variables.a_tf_wp_conductor,
            )
            po.ovarre(
                self.outfile,
                "Total additional void area in WP",
                "(a_tf_wp_extra_void)",
                tfcoil_variables.a_tf_wp_extra_void,
            )

            po.ovarre(
                self.outfile,
                "Area of all coolant channels in WP",
                "(a_tf_wp_coolant_channels)",
                tfcoil_variables.a_tf_wp_coolant_channels,
            )

            po.ovarre(
                self.outfile,
                "Copper fraction of conductor",
                "(f_a_tf_turn_cable_copper)",
                tfcoil_variables.f_a_tf_turn_cable_copper,
            )
            po.ovarre(
                self.outfile,
                "Superconductor fraction of conductor",
                "(1-f_a_tf_turn_cable_copper)",
                1 - tfcoil_variables.f_a_tf_turn_cable_copper,
            )
            # TODO
            # po.ovarre(self.outfile,'Conductor fraction of winding pack','(tfcoil_variables.a_tf_wp_conductor/ap)',a_tf_wp_conductor/ap, 'OP ')
            # po.ovarre(self.outfile,'Conduit fraction of winding pack','(tfcoil_variables.n_tf_coil_turns*tfcoil_variables.a_tf_turn_steel/ap)',n_tf_coil_turns*tfcoil_variables.a_tf_turn_steel/ap, 'OP ')
            # po.ovarre(self.outfile,'Insulator fraction of winding pack','(tfcoil_variables.a_tf_coil_wp_turn_insulation/ap)',a_tf_coil_wp_turn_insulation/ap, 'OP ')
            # po.ovarre(self.outfile,'Helium area fraction of winding pack excluding central channel','(tfcoil_variables.a_tf_wp_extra_void/ap)',a_tf_wp_extra_void/ap, 'OP ')
            # po.ovarre(self.outfile,'Central helium channel area as fraction of winding pack','(tfcoil_variables.a_tf_wp_coolant_channels/ap)',a_tf_wp_coolant_channels/ap, 'OP ')
            ap = (
                tfcoil_variables.a_tf_wp_conductor
                + tfcoil_variables.n_tf_coil_turns * tfcoil_variables.a_tf_turn_steel
                + tfcoil_variables.a_tf_coil_wp_turn_insulation
                + tfcoil_variables.a_tf_wp_extra_void
                + tfcoil_variables.a_tf_wp_coolant_channels
            )
            po.ovarrf(
                self.outfile,
                "Check total area fractions in winding pack = 1",
                "",
                (
                    tfcoil_variables.a_tf_wp_conductor
                    + tfcoil_variables.n_tf_coil_turns
                    * tfcoil_variables.a_tf_turn_steel
                    + tfcoil_variables.a_tf_coil_wp_turn_insulation
                    + tfcoil_variables.a_tf_wp_extra_void
                    + tfcoil_variables.a_tf_wp_coolant_channels
                )
                / ap,
            )
            po.ovarrf(
                self.outfile,
                "minimum TF conductor temperature margin  (K)",
                "(temp_tf_superconductor_margin_min)",
                tfcoil_variables.temp_tf_superconductor_margin_min,
            )
            po.ovarrf(
                self.outfile,
                "TF conductor temperature margin (K)",
                "(temp_tf_superconductor_margin)",
                tfcoil_variables.temp_tf_superconductor_margin,
            )

            po.ovarin(
                self.outfile,
                "Elastic properties behavior",
                "(i_tf_cond_eyoung_axial)",
                tfcoil_variables.i_tf_cond_eyoung_axial,
            )
            if tfcoil_variables.i_tf_cond_eyoung_axial == 0:
                po.ocmmnt(self.outfile, "  Conductor stiffness neglected")
            elif tfcoil_variables.i_tf_cond_eyoung_axial == 1:
                po.ocmmnt(self.outfile, "  Conductor stiffness is user-input")
            elif tfcoil_variables.i_tf_cond_eyoung_axial == 2:
                po.ocmmnt(
                    self.outfile,
                    "  Conductor stiffness is set by material-specific default",
                )

            po.ovarre(
                self.outfile,
                "Conductor axial Youngs modulus",
                "(eyoung_cond_axial)",
                tfcoil_variables.eyoung_cond_axial,
            )
            po.ovarre(
                self.outfile,
                "Conductor transverse Youngs modulus",
                "(eyoung_cond_trans)",
                tfcoil_variables.eyoung_cond_trans,
            )
    else:
        # External casing
        po.osubhd(self.outfile, "Bucking cylinder information:")
        po.ovarre(
            self.outfile,
            "Casing cross section area (per leg) (m2)",
            "(a_tf_coil_inboard_case)",
            tfcoil_variables.a_tf_coil_inboard_case,
        )
        po.ovarre(
            self.outfile,
            "Inboard leg case plasma side wall thickness (m)",
            "(dr_tf_plasma_case)",
            tfcoil_variables.dr_tf_plasma_case,
        )
        po.ovarre(
            self.outfile,
            "Inboard leg plasma case area (m^2)",
            "(a_tf_plasma_case)",
            superconducting_tf_coil_variables.a_tf_plasma_case,
        )
        po.ovarre(
            self.outfile,
            "Inboard leg bucking cylinder thickness (m)",
            "(dr_tf_nose_case)",
            tfcoil_variables.dr_tf_nose_case,
        )
        po.ovarre(
            self.outfile,
            'Inboard leg case inboard "nose" area (m^2)',
            "(a_tf_coil_nose_case)",
            superconducting_tf_coil_variables.a_tf_coil_nose_case,
        )

        # Conductor layer geometry
        po.osubhd(self.outfile, "Inboard TFC conductor sector geometry:")
        po.ovarre(
            self.outfile,
            "Inboard TFC conductor sector area with gr insulation (per leg) (m2)",
            "(a_tf_wp_with_insulation)",
            superconducting_tf_coil_variables.a_tf_wp_with_insulation,
        )
        po.ovarre(
            self.outfile,
            "Inboard TFC conductor sector area, NO ground & gap (per leg) (m2)",
            "(a_tf_wp_no_insulation)",
            superconducting_tf_coil_variables.a_tf_wp_no_insulation,
        )
        po.ovarre(
            self.outfile,
            "Ground wall insulation area (m^2)",
            "(a_tf_wp_ground_insulation)",
            superconducting_tf_coil_variables.a_tf_wp_ground_insulation,
        )
        po.ovarre(
            self.outfile,
            "Inboard conductor sector radial thickness (m)",
            "(dr_tf_wp_with_insulation)",
            tfcoil_variables.dr_tf_wp_with_insulation,
        )
        if physics_variables.itart == 1:
            po.ovarre(
                self.outfile,
                "Central collumn top conductor sector radial thickness (m)",
                "(dr_tf_wp_top)",
                superconducting_tf_coil_variables.dr_tf_wp_top,
            )

        po.ovarre(
            self.outfile,
            "Ground wall insulation thickness (m)",
            "(dx_tf_wp_insulation)",
            tfcoil_variables.dx_tf_wp_insulation,
        )
        # Turn info
        po.osubhd(self.outfile, "Coil turn information:")
        po.ovarre(
            self.outfile,
            "Number of turns per TF leg",
            "(n_tf_coil_turns)",
            tfcoil_variables.n_tf_coil_turns,
        )
        po.ovarre(
            self.outfile,
            "Turn insulation thickness",
            "(dx_tf_turn_insulation)",
            tfcoil_variables.dx_tf_turn_insulation,
        )
        po.ovarre(
            self.outfile,
            "Mid-plane CP cooling fraction",
            "(fcoolcp)",
            tfcoil_variables.fcoolcp,
        )
        po.ovarre(
            self.outfile,
            "Area of resistive conductor per coil",
            "(a_res_tf_coil_conductor)",
            tfcoil_variables.a_res_tf_coil_conductor,
        )
        po.ovarre(
            self.outfile,
            "Outboard leg current per turn (A)",
            "(c_tf_turn)",
            tfcoil_variables.c_tf_turn,
        )
        po.ovarre(
            self.outfile,
            "Inboard leg conductor volume (m3)",
            "(vol_cond_cp)",
            tfcoil_variables.vol_cond_cp,
        )
        po.ovarre(
            self.outfile,
            "Outboard leg volume per coil (m3)",
            "(voltfleg)",
            tfcoil_variables.voltfleg,
        )

    # Coil masses
    po.osubhd(self.outfile, "TF coil mass:")
    po.ovarre(
        self.outfile,
        "Superconductor mass per coil (kg)",
        "(m_tf_coil_superconductor)",
        tfcoil_variables.m_tf_coil_superconductor,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Copper mass per coil (kg)",
        "(m_tf_coil_copper)",
        tfcoil_variables.m_tf_coil_copper,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Steel conduit mass per coil (kg)",
        "(m_tf_wp_steel_conduit)",
        tfcoil_variables.m_tf_wp_steel_conduit,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Conduit insulation mass per coil (kg)",
        "(m_tf_coil_wp_turn_insulation)",
        tfcoil_variables.m_tf_coil_wp_turn_insulation,
        "OP ",
    )
    if tfcoil_variables.i_tf_sup == 1:
        po.ovarre(
            self.outfile,
            "Total conduit mass per coil (kg)",
            "(m_tf_coil_conductor)",
            tfcoil_variables.m_tf_coil_conductor,
            "OP ",
        )

    if physics_variables.itart == 1:
        po.ovarre(
            self.outfile,
            "Mass of inboard legs (kg)",
            "(whtcp)",
            tfcoil_variables.whtcp,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Mass of outboard legs (kg)",
            "(whttflgs)",
            tfcoil_variables.whttflgs,
            "OP ",
        )

    po.ovarre(
        self.outfile,
        "Mass of each TF coil (kg)",
        "(m_tf_coils_total/n_tf_coils)",
        tfcoil_variables.m_tf_coils_total / tfcoil_variables.n_tf_coils,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Total TF coil mass (kg)",
        "(m_tf_coils_total)",
        tfcoil_variables.m_tf_coils_total,
        "OP ",
    )

    # TF current and field
    po.osubhd(self.outfile, "Maximum B field and currents:")
    po.ovarre(
        self.outfile,
        "Nominal peak field assuming toroidal symmetry (T)",
        "(b_tf_inboard_peak_symmetric)",
        tfcoil_variables.b_tf_inboard_peak_symmetric,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Radius of maximum field position on inboard TF coil (m)",
        "(r_b_tf_inboard_peak)",
        tfcoil_variables.r_b_tf_inboard_peak,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Total current in all TF coils (MA)",
        "(c_tf_total/1.D6)",
        1.0e-6 * tfcoil_variables.c_tf_total,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "TF coil current (summed over all coils) (A)",
        "(c_tf_total)",
        tfcoil_variables.c_tf_total,
    )
    if tfcoil_variables.i_tf_sup == 1:
        po.ovarre(
            self.outfile,
            "Actual peak field at discrete conductor (T)",
            "(b_tf_inboard_peak_with_ripple)",
            tfcoil_variables.b_tf_inboard_peak_with_ripple,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Ratio of peak field with ripple to nominal axisymmetric peak field",
            "(f_b_tf_inboard_peak_ripple_symmetric)",
            superconducting_tf_coil_variables.f_b_tf_inboard_peak_ripple_symmetric,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Winding pack current density (A/m2)",
            "(j_tf_wp)",
            tfcoil_variables.j_tf_wp,
            "OP ",
        )

    po.ovarre(
        self.outfile,
        "Inboard leg mid-plane conductor current density (A/m2)",
        "(oacdcp)",
        tfcoil_variables.oacdcp,
    )
    if physics_variables.itart == 1:
        po.ovarre(
            self.outfile,
            "Outboard leg conductor current density (A/m2)",
            "(cdtfleg)",
            tfcoil_variables.cdtfleg,
        )
    po.ovarre(
        self.outfile,
        "Self inductance of a TF coil (H)",
        "(ind_tf_coil)",
        tfcoil_variables.ind_tf_coil,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Total stored energy in TF coils (GJ)",
        "(e_tf_magnetic_stored_total_gj)",
        tfcoil_variables.e_tf_magnetic_stored_total_gj,
        "OP ",
    )

    po.ovarre(
        self.outfile,
        "Total magnetic energy in a TF coil (J)",
        "(e_tf_coil_magnetic_stored)",
        tfcoil_variables.e_tf_coil_magnetic_stored,
        "OP ",
    )

    # TF forces
    po.osubhd(self.outfile, "TF Forces:")
    po.ovarre(
        self.outfile,
        "Inboard vertical tension per coil (N)",
        "(vforce)",
        tfcoil_variables.vforce,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Outboard vertical tension per coil (N)",
        "(vforce_outboard)",
        tfcoil_variables.vforce_outboard,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "inboard vertical tension fraction (-)",
        "(f_vforce_inboard)",
        tfcoil_variables.f_vforce_inboard,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "Centring force per coil (N/m)",
        "(cforce)",
        tfcoil_variables.cforce,
        "OP ",
    )

    # Resistive coil parameters
    if tfcoil_variables.i_tf_sup != 1:
        po.osubhd(self.outfile, "Resitive loss parameters:")
        if tfcoil_variables.i_tf_sup == 0:
            po.ocmmnt(
                self.outfile,
                "Resistive Material : GLIDCOP AL-15 - Dispersion Strengthened Copper",
            )
        elif tfcoil_variables.i_tf_sup == 2:
            po.ocmmnt(
                self.outfile, "Resistive Material : Pure Aluminium (99.999+ %)"
            )

        if physics_variables.itart == 1:
            po.ovarre(
                self.outfile,
                "CP resistivity (ohm.m)",
                "(rho_cp)",
                tfcoil_variables.rho_cp,
            )
            po.ovarre(
                self.outfile,
                "Leg resistivity (ohm.m)",
                "(rho_tf_leg)",
                tfcoil_variables.rho_tf_leg,
            )
            po.ovarre(
                self.outfile,
                "CP resistive power loss (W)",
                "(p_cp_resistive)",
                tfcoil_variables.p_cp_resistive,
            )
            po.ovarre(
                self.outfile,
                "Total legs resitive power loss, (W)",
                "(p_tf_leg_resistive)",
                tfcoil_variables.p_tf_leg_resistive,
            )
            po.ovarre(
                self.outfile,
                "joints resistive power loss (W)",
                "(p_tf_joints_resistive)",
                tfcoil_variables.p_tf_joints_resistive,
            )
            po.ovarre(
                self.outfile,
                "Outboard leg resistance per coil (ohm)",
                "(res_tf_leg)",
                tfcoil_variables.res_tf_leg,
            )
            po.ovarre(
                self.outfile,
                "Average CP temperature (K)",
                "(temp_cp_average)",
                tfcoil_variables.temp_cp_average,
            )
            po.ovarre(
                self.outfile,
                "Average leg temperature (K)",
                "(temp_tf_legs_outboard)",
                tfcoil_variables.temp_tf_legs_outboard,
            )

        else:
            po.ovarre(
                self.outfile,
                "TF resistivity (ohm.m)",
                "(p_cp_resistive)",
                tfcoil_variables.rho_cp,
            )
            po.ovarre(
                self.outfile,
                "TF coil resistive power less (total) (ohm.m)",
                "(p_cp_resistive)",
                tfcoil_variables.p_cp_resistive,
            )
            po.ovarre(
                self.outfile,
                "Average coil temperature (K)",
                "(temp_cp_average)",
                tfcoil_variables.temp_cp_average,
            )

    # Ripple calculations
    po.osubhd(self.outfile, "Ripple information:")
    if tfcoil_variables.i_tf_shape == 1:
        po.ovarre(
            self.outfile,
            "Max allowed tfcoil_variables.ripple amplitude at plasma outboard midplane (%)",
            "(ripple_b_tf_plasma_edge_max)",
            tfcoil_variables.ripple_b_tf_plasma_edge_max,
        )
        po.ovarre(
            self.outfile,
            "Ripple amplitude at plasma outboard midplane (%)",
            "(ripple_b_tf_plasma_edge)",
            tfcoil_variables.ripple_b_tf_plasma_edge,
            "OP ",
        )
    else:
        po.ovarre(
            self.outfile,
            "Max allowed tfcoil_variables.ripple amplitude at plasma (%)",
            "(ripple_b_tf_plasma_edge_max)",
            tfcoil_variables.ripple_b_tf_plasma_edge_max,
        )
        po.ovarre(
            self.outfile,
            "Ripple at plasma edge (%)",
            "(ripple_b_tf_plasma_edge)",
            tfcoil_variables.ripple_b_tf_plasma_edge,
        )
        po.ocmmnt(
            self.outfile,
            "  Ripple calculation to be re-defined for picure frame coils",
        )

    # Quench information
    if tfcoil_variables.i_tf_sup == 1:
        po.osubhd(self.outfile, "Quench information :")
        po.ovarre(
            self.outfile,
            "Actual quench time (or time constant) (s)",
            "(t_tf_superconductor_quench)",
            tfcoil_variables.t_tf_superconductor_quench,
        )
        po.ovarre(
            self.outfile,
            "Vacuum Vessel stress on quench (Pa)",
            "(vv_stress_quench)",
            superconducting_tf_coil_variables.vv_stress_quench,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Maximum allowed voltage during quench due to insulation (kV)",
            "(v_tf_coil_dump_quench_max_kv)",
            tfcoil_variables.v_tf_coil_dump_quench_max_kv,
        )
        po.ovarre(
            self.outfile,
            "Actual quench voltage (kV)",
            "(v_tf_coil_dump_quench_kv)",
            tfcoil_variables.v_tf_coil_dump_quench_kv,
            "OP ",
        )

        if tfcoil_variables.i_tf_sc_mat in (1, 2, 3, 4, 5):
            po.ovarre(
                self.outfile,
                "Maximum allowed temp during a quench (K)",
                "(temp_tf_conductor_quench_max)",
                tfcoil_variables.temp_tf_conductor_quench_max,
            )
        elif tfcoil_variables == 6:
            po.ocmmnt(self.outfile, "CroCo cable with jacket: ")

            if 75 in numerics.icc:
                po.ovarre(
                    self.outfile,
                    "Maximum permitted TF coil current / copper area (A/m2)",
                    "(copperA_m2_max)",
                    rebco_variables.coppera_m2_max,
                )

            po.ovarre(
                self.outfile,
                "Actual TF coil current / copper area (A/m2)",
                "(copperA_m2)",
                rebco_variables.coppera_m2,
            )

    # TF coil radial build
    po.osubhd(self.outfile, "Radial build of TF coil centre-line :")
    # po.write(self.outfile,5)
    # 5   format(t43,'Thickness (m)',t60,'Outer radius (m)')

    radius = build_variables.r_tf_inboard_in
    po.obuild(self.outfile, "Innermost edge of TF coil", radius, radius)

    # Radial build for SC TF coils
    if tfcoil_variables.i_tf_sup == 1:
        radius = radius + tfcoil_variables.dr_tf_nose_case
        po.obuild(
            self.outfile,
            'Coil case ("nose")',
            tfcoil_variables.dr_tf_nose_case,
            radius,
            "(dr_tf_nose_case)",
        )

        radius = radius + tfcoil_variables.dx_tf_wp_insertion_gap
        po.obuild(
            self.outfile,
            "Insertion gap for winding pack",
            tfcoil_variables.dx_tf_wp_insertion_gap,
            radius,
            "(dx_tf_wp_insertion_gap)",
        )

        radius = radius + tfcoil_variables.dx_tf_wp_insulation
        po.obuild(
            self.outfile,
            "Winding pack ground insulation",
            tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(dx_tf_wp_insulation)",
        )

        radius = (
            radius
            + 0.5e0 * tfcoil_variables.dr_tf_wp_with_insulation
            - tfcoil_variables.dx_tf_wp_insulation
            - tfcoil_variables.dx_tf_wp_insertion_gap
        )
        po.obuild(
            self.outfile,
            "Winding - first half",
            tfcoil_variables.dr_tf_wp_with_insulation / 2e0
            - tfcoil_variables.dx_tf_wp_insulation
            - tfcoil_variables.dx_tf_wp_insertion_gap,
            radius,
            "(dr_tf_wp_with_insulation/2-dx_tf_wp_insulation-dx_tf_wp_insertion_gap)",
        )

        radius = (
            radius
            + 0.5e0 * tfcoil_variables.dr_tf_wp_with_insulation
            - tfcoil_variables.dx_tf_wp_insulation
            - tfcoil_variables.dx_tf_wp_insertion_gap
        )
        po.obuild(
            self.outfile,
            "Winding - second half",
            tfcoil_variables.dr_tf_wp_with_insulation / 2e0
            - tfcoil_variables.dx_tf_wp_insulation
            - tfcoil_variables.dx_tf_wp_insertion_gap,
            radius,
            "(dr_tf_wp_with_insulation/2-dx_tf_wp_insulation-dx_tf_wp_insertion_gap)",
        )

        radius = radius + tfcoil_variables.dx_tf_wp_insulation
        po.obuild(
            self.outfile,
            "Winding pack insulation",
            tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(dx_tf_wp_insulation)",
        )

        radius = radius + tfcoil_variables.dx_tf_wp_insertion_gap
        po.obuild(
            self.outfile,
            "Insertion gap for winding pack",
            tfcoil_variables.dx_tf_wp_insertion_gap,
            radius,
            "(dx_tf_wp_insertion_gap)",
        )

        radius = radius + tfcoil_variables.dr_tf_plasma_case
        po.obuild(
            self.outfile,
            "Plasma side case min radius",
            tfcoil_variables.dr_tf_plasma_case,
            radius,
            "(dr_tf_plasma_case)",
        )

        radius = radius / np.cos(np.pi / tfcoil_variables.n_tf_coils)
        po.obuild(
            self.outfile,
            "Plasma side case max radius",
            build_variables.r_tf_inboard_out,
            radius,
            "(r_tf_inboard_out)",
        )

    # Radial build for restive coil
    else:
        radius = radius + tfcoil_variables.dr_tf_nose_case
        po.obuild(
            self.outfile,
            "Coil bucking cylindre",
            tfcoil_variables.dr_tf_nose_case,
            radius,
            "(dr_tf_nose_case)",
        )

        radius = radius + tfcoil_variables.dx_tf_wp_insulation
        po.obuild(
            self.outfile,
            "Conductor ground insulation",
            tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(dx_tf_wp_insulation)",
        )

        radius = (
            radius
            + 0.5e0 * tfcoil_variables.dr_tf_wp_with_insulation
            - tfcoil_variables.dx_tf_wp_insulation
        )
        po.obuild(
            self.outfile,
            "Conductor - first half",
            tfcoil_variables.dr_tf_wp_with_insulation / 2e0
            - tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(tfcoil_variables.dr_tf_wp_with_insulation/2-tfcoil_variables.dx_tf_wp_insulation)",
        )

        radius = (
            radius
            + 0.5e0 * tfcoil_variables.dr_tf_wp_with_insulation
            - tfcoil_variables.dx_tf_wp_insulation
        )
        po.obuild(
            self.outfile,
            "Conductor - second half",
            tfcoil_variables.dr_tf_wp_with_insulation / 2e0
            - tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(tfcoil_variables.dr_tf_wp_with_insulation/2-tfcoil_variables.dx_tf_wp_insulation)",
        )

        radius = radius + tfcoil_variables.dx_tf_wp_insulation
        po.obuild(
            self.outfile,
            "Conductor ground insulation",
            tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(dx_tf_wp_insulation)",
        )

        radius = radius + tfcoil_variables.dr_tf_plasma_case
        po.obuild(
            self.outfile,
            "Plasma side TF coil support",
            tfcoil_variables.dr_tf_plasma_case,
            radius,
            "(dr_tf_plasma_case)",
        )

    # Radial build consistency check
    if (
        abs(radius - build_variables.r_tf_inboard_in - build_variables.dr_tf_inboard)
        < 10.0e0 * np.finfo(float(radius)).eps
    ):
        po.ocmmnt(self.outfile, "TF coil dimensions are consistent")
    else:
        po.ocmmnt(self.outfile, "ERROR: TF coil dimensions are NOT consistent:")
        po.ovarre(
            self.outfile,
            "Radius of plasma-facing side of inner leg SHOULD BE [m]",
            "",
            build_variables.r_tf_inboard_in + build_variables.dr_tf_inboard,
        )
        po.ovarre(
            self.outfile,
            "Inboard TF coil radial thickness [m]",
            "(dr_tf_inboard)",
            build_variables.dr_tf_inboard,
        )
        po.oblnkl(self.outfile)

    tf_total_height = (
        build_variables.dh_tf_inner_bore + 2 * build_variables.dr_tf_inboard
    )
    tf_total_width = (
        build_variables.dr_tf_inner_bore
        + build_variables.dr_tf_inboard
        + build_variables.dr_tf_outboard
    )
    po.oblnkl(self.outfile)
    po.obuild(
        self.outfile,
        "Total height and width of TFC [m]",
        tf_total_height,
        tf_total_width,
    )

    # Top section TF coil radial build (physics_variables.itart = 1 only)
    if physics_variables.itart == 1 and tfcoil_variables.i_tf_sup != 1:
        po.osubhd(self.outfile, "Radial build of TF coil at central collumn top :")
        # write(self.outfile,5)

        # Restart the radial build at bucking cylindre inner radius
        radius = build_variables.r_tf_inboard_in
        po.obuild(self.outfile, "Innermost edge of TF coil", radius, radius)

        radius = radius + tfcoil_variables.dr_tf_nose_case
        po.obuild(
            self.outfile,
            "Coil bucking cylindre",
            tfcoil_variables.dr_tf_nose_case,
            radius,
            "(dr_tf_nose_case)",
        )

        radius = radius + tfcoil_variables.dx_tf_wp_insulation
        po.obuild(
            self.outfile,
            "Conductor ground insulation",
            tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(dx_tf_wp_insulation)",
        )

        radius = (
            radius
            + 0.5e0 * superconducting_tf_coil_variables.dr_tf_wp_top
            - tfcoil_variables.dx_tf_wp_insulation
        )
        po.obuild(
            self.outfile,
            "Conductor - first half",
            0.5e0 * superconducting_tf_coil_variables.dr_tf_wp_top
            - tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(dr_tf_wp_top/2-dx_tf_wp_insulation)",
        )

        radius = (
            radius
            + 0.5e0 * superconducting_tf_coil_variables.dr_tf_wp_top
            - tfcoil_variables.dx_tf_wp_insulation
        )
        po.obuild(
            self.outfile,
            "Conductor - second half",
            0.5e0 * superconducting_tf_coil_variables.dr_tf_wp_top
            - tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(dr_tf_wp_top/2-dx_tf_wp_insulation)",
        )

        radius = radius + tfcoil_variables.dx_tf_wp_insulation
        po.obuild(
            self.outfile,
            "Conductor ground insulation",
            tfcoil_variables.dx_tf_wp_insulation,
            radius,
            "(dx_tf_wp_insulation)",
        )

        radius = radius + tfcoil_variables.dr_tf_plasma_case
        po.obuild(
            self.outfile,
            "Plasma side TF coil support",
            tfcoil_variables.dr_tf_plasma_case,
            radius,
            "(dr_tf_plasma_case)",
        )

        # Consistency check
        if abs(radius - build_variables.r_cp_top) < np.finfo(float(radius)).eps:
            po.ocmmnt(self.outfile, "Top TF coil dimensions are consistent")
        else:
            po.ocmmnt(self.outfile, "ERROR: TF coil dimensions are NOT consistent:")
            po.ovarre(
                self.outfile,
                "Radius of plasma-facing side of inner leg SHOULD BE [m]",
                "",
                build_variables.r_cp_top,
            )
            po.oblnkl(self.outfile)

circumference(aaa, bbb) staticmethod

Calculate ellipse arc circumference using Ramanujan approximation (m) See https://www.johndcook.com/blog/2013/05/05/ramanujan-circumference-ellipse/ for a discussion of the precision of the formula

An ellipse has the following formula: (x/a)² + (y/b)² = 1

Parameters:

Name Type Description Default
aaa float

the value of a in the formula of the ellipse.

required
bbb float

the value of b in the formula of the ellipse.

required

Returns:

Type Description
float

an approximation of the circumference of the ellipse

Source code in process/models/tfcoil/base.py
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
@staticmethod
def circumference(aaa, bbb):
    """Calculate ellipse arc circumference using Ramanujan approximation (m)
    See https://www.johndcook.com/blog/2013/05/05/ramanujan-circumference-ellipse/
    for a discussion of the precision of the formula

    An ellipse has the following formula: (x/a)² + (y/b)² = 1

    Parameters
    ----------
    aaa : float
        the value of a in the formula of the ellipse.
    bbb : float
        the value of b in the formula of the ellipse.

    Returns
    -------
    float
        an approximation of the circumference of the ellipse
    """
    hh = (aaa - bbb) ** 2 / (aaa + bbb) ** 2
    return (
        np.pi
        * (aaa + bbb)
        * (1.0e0 + (3.0e0 * hh) / (10.0e0 + np.sqrt(4.0e0 - 3.0e0 * hh)))
    )

cntrpst()

Evaluates the properties of a TART centrepost

outfile : input integer : output file unit iprint : input integer : switch for writing to output file (1=yes) This subroutine evaluates the parameters of the centrepost for a tight aspect ratio tokamak. The centrepost is assumed to be tapered, i.e. narrowest on the midplane (z=0).

Source code in process/models/tfcoil/base.py
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
def cntrpst(self):
    """Evaluates the properties of a TART centrepost

    outfile : input integer : output file unit
    iprint : input integer : switch for writing to output file (1=yes)
    This subroutine evaluates the parameters of the centrepost for a
    tight aspect ratio tokamak. The centrepost is assumed to be tapered,
    i.e. narrowest on the midplane (z=0).
    """

    # Vertical distance from the midplane to the top of the tapered section [m]
    if physics_variables.itart == 1:
        superconducting_tf_coil_variables.z_cp_top = (
            build_variables.z_plasma_xpoint_upper + tfcoil_variables.dztop
        )

    if physics_variables.itart == 1 and tfcoil_variables.i_tf_sup != 1:
        tfcoil_variables.dx_tf_inboard_out_toroidal = (
            2.0e0
            * build_variables.r_cp_top
            * np.sin(
                superconducting_tf_coil_variables.rad_tf_coil_inboard_toroidal_half
            )
        )

    # Temperature margin used in calculations (K)
    tmarg = 10.0e0

    # Number of integral step used for the coolant temperature rise
    n_tcool_it = 20

    # Coolant channels:
    acool = (
        tfcoil_variables.a_cp_cool * tfcoil_variables.n_tf_coils
    )  # Cooling cross-sectional area
    dcool = 2.0e0 * tfcoil_variables.radius_cp_coolant_channel  # Diameter
    lcool = 2.0e0 * (bv.z_tf_inside_half + bv.dr_tf_outboard)  # Length
    tfcoil_variables.n_cp_coolant_channels_total = acool / (
        np.pi * tfcoil_variables.radius_cp_coolant_channel**2
    )  # Number

    # Average conductor cross-sectional area to cool (with cooling area)
    acpav = (
        0.5e0
        * tfcoil_variables.vol_cond_cp
        / (bv.z_tf_inside_half + bv.dr_tf_outboard)
        + acool
    )
    ro = (acpav / (np.pi * tfcoil_variables.n_cp_coolant_channels_total)) ** 0.5

    # Inner legs total heating power (to be removed by coolant)
    ptot = tfcoil_variables.p_cp_resistive + fwbs_variables.pnuc_cp_tf * 1.0e6

    # Temperature calculations
    # -------------------------
    # Temperature rise in coolant (inlet to outlet)
    # **********************************************
    # Water coollant
    # --------------
    if tfcoil_variables.i_tf_sup == 0:
        # Water coolant physical properties
        coolant_density = constants.DENH2O
        coolant_cp = constants.CPH2O
        coolant_visco = constants.MUH2O
        coolant_th_cond = constants.KH2O

        # Mass flow rate [kg/s]
        cool_mass_flow = (
            acool * coolant_density * tfcoil_variables.vel_cp_coolant_midplane
        )

        # Water temperature rise
        tfcoil_variables.dtemp_cp_coolant = ptot / (cool_mass_flow * coolant_cp)

        # Constant coolant velocity
        vcool_max = tfcoil_variables.vel_cp_coolant_midplane
        # --------------

    # Helium coolant
    # --------------
    elif tfcoil_variables.i_tf_sup == 2:
        # Inlet coolant density [kg/m3]
        coolant_density = self.he_density(tfcoil_variables.temp_cp_coolant_inlet)

        # Mass flow rate [kg/s]
        cool_mass_flow = (
            acool * coolant_density * tfcoil_variables.vel_cp_coolant_midplane
        )

        # Infinitesimal power deposition used in the integral
        dptot = ptot / n_tcool_it

        tcool_calc = copy.copy(tfcoil_variables.temp_cp_coolant_inlet)  # K
        for _i in range(n_tcool_it):
            # Thermal capacity Cp
            coolant_cp = self.he_cp(tcool_calc)

            # Temperature infinitesimal increase
            tcool_calc += dptot / (cool_mass_flow * coolant_cp)

        # Outlet coolant density (minimal coolant density value)
        coolant_density = self.he_density(tcool_calc)

        # Maxium coolant velocity
        vcool_max = cool_mass_flow / (acool * coolant_density)

        # Getting the global in-outlet temperature increase
        tfcoil_variables.dtemp_cp_coolant = (
            tcool_calc - tfcoil_variables.temp_cp_coolant_inlet
        )
    # --------------

    # Average coolant temperature
    tcool_av = (
        tfcoil_variables.temp_cp_coolant_inlet
        + 0.5e0 * tfcoil_variables.dtemp_cp_coolant
    )
    # **********************************************

    # Film temperature rise
    # *********************
    # Rem : The helium cooling properties are calculated using the outlet ones
    # this is not an exact approximation for average temperature rise

    # Helium viscosity
    if tfcoil_variables.i_tf_sup == 2:
        coolant_visco = self.he_visco(tcool_av)

    # Reynolds number
    reyn = (
        coolant_density
        * tfcoil_variables.vel_cp_coolant_midplane
        * dcool
        / coolant_visco
    )

    # Helium thermal conductivity [W/(m.K)]
    if tfcoil_variables.i_tf_sup == 2:
        coolant_th_cond = self.he_th_cond(tcool_av)

    # Prandlt number
    prndtl = coolant_cp * coolant_visco / coolant_th_cond

    # Film temperature difference calculations
    # Originally prandtl was prndtl**0.3e0 but this is incorrect as from
    # Dittus-Boelter correlation where the fluid is being heated it should be as below
    nuselt = 0.023e0 * reyn**0.8e0 * prndtl**0.4e0
    h = nuselt * coolant_th_cond / dcool
    dtfilmav = ptot / (
        h
        * 2.0e0
        * np.pi
        * tfcoil_variables.radius_cp_coolant_channel
        * tfcoil_variables.n_cp_coolant_channels_total
        * lcool
    )

    # Average film temperature (in contact with te conductor)
    tcool_film = tcool_av + dtfilmav
    # *********************

    # Temperature rise in conductor
    # ------------------------------
    # Conductor thermal conductivity
    # ******
    # Copper conductor
    if tfcoil_variables.i_tf_sup == 0:
        conductor_th_cond = constants.K_COPPER

    # Aluminium
    elif tfcoil_variables.i_tf_sup == 2:
        conductor_th_cond = self.al_th_cond(tcool_film)
    # ******

    # Average temperature rise : To be changed with Garry Voss' better documented formula ?
    dtcncpav = (
        (ptot / tfcoil_variables.vol_cond_cp)
        / (
            2.0e0
            * conductor_th_cond
            * (ro**2 - tfcoil_variables.radius_cp_coolant_channel**2)
        )
        * (
            ro**2 * tfcoil_variables.radius_cp_coolant_channel**2
            - 0.25e0 * tfcoil_variables.radius_cp_coolant_channel**4
            - 0.75e0 * ro**4
            + ro**4 * np.log(ro / tfcoil_variables.radius_cp_coolant_channel)
        )
    )

    # Peak temperature rise : To be changed with Garry Voss' better documented formula ?
    dtconcpmx = (
        (ptot / tfcoil_variables.vol_cond_cp)
        / (2.0e0 * conductor_th_cond)
        * (
            (tfcoil_variables.radius_cp_coolant_channel**2 - ro**2) / 2.0e0
            + ro**2 * np.log(ro / tfcoil_variables.radius_cp_coolant_channel)
        )
    )

    # If the average conductor temperature difference is negative, set it to 0
    if dtcncpav < 0.0e0:
        logger.error("Negative conductor average temperature difference, set to 0")
        dtcncpav = 0.0e0

    # If the average conductor temperature difference is negative, set it to 0
    if dtconcpmx < 0.0e0:
        logger.error("Negative conductor peak temperature difference, set to 0")
        dtconcpmx = 0.0e0

    # Average conductor temperature
    tfcoil_variables.tcpav2 = (
        tfcoil_variables.temp_cp_coolant_inlet
        + dtcncpav
        + dtfilmav
        + 0.5e0 * tfcoil_variables.dtemp_cp_coolant
    )

    # Peak wall temperature
    tfcoil_variables.temp_cp_peak = (
        tfcoil_variables.temp_cp_coolant_inlet
        + tfcoil_variables.dtemp_cp_coolant
        + dtfilmav
        + dtconcpmx
    )
    tcoolmx = (
        tfcoil_variables.temp_cp_coolant_inlet
        + tfcoil_variables.dtemp_cp_coolant
        + dtfilmav
    )
    # -------------------------

    # Thermal hydraulics: friction factor from Z. Olujic, Chemical
    # Engineering, Dec. 1981, p. 91
    roughrat = 4.6e-5 / dcool
    fricfac = (
        1.0e0
        / (
            -2.0e0
            * np.log10(
                roughrat / 3.7e0
                - 5.02e0 / reyn * np.log10(roughrat / 3.7e0 + 14.5e0 / reyn)
            )
        )
        ** 2
    )

    # Pumping efficiency
    if tfcoil_variables.i_tf_sup == 0:  # Water cooled
        tfcoil_variables.etapump = 0.8e0
    elif tfcoil_variables.i_tf_sup == 2:  # Cryogenic helium
        tfcoil_variables.etapump = 0.6e0

    # Pressure drop calculation
    dpres = (
        fricfac
        * (lcool / dcool)
        * coolant_density
        * 0.5e0
        * tfcoil_variables.vel_cp_coolant_midplane**2
    )
    tfcoil_variables.p_cp_coolant_pump_elec = (
        dpres
        * acool
        * tfcoil_variables.vel_cp_coolant_midplane
        / tfcoil_variables.etapump
    )

    # Critical pressure in saturation pressure calculations (Pa)
    pcrt = 2.24e7

    # Saturation pressure
    # Ref : Keenan, Keyes, Hill, Moore, steam tables, Wiley & Sons, 1969
    # Rem 1 : ONLY VALID FOR WATER !
    # Rem 2 : Not used anywhere else in the code ...
    tclmx = tcoolmx + tmarg
    tclmxs = min(tclmx, 374.0e0)
    fc = 0.65e0 - 0.01e0 * tclmxs
    sum_ = (
        -741.9242e0
        - 29.721e0 * fc
        - 11.55286e0 * fc**2
        - 0.8685635e0 * fc**3
        + 0.1094098e0 * fc**4
        + 0.439993e0 * fc**5
        + 0.2520658e0 * fc**6
        + 0.0518684e0 * fc**7
    )
    psat = pcrt * np.exp(0.01e0 / (tclmxs + 273.0e0) * (374.0e0 - tclmxs) * sum_)
    presin = psat + dpres

    # Output section
    if self.iprint == 1:
        po.oheadr(self.outfile, "Centrepost Coolant Parameters")
        po.ovarre(
            self.outfile,
            "Centrepost coolant fraction",
            "(fcoolcp)",
            tfcoil_variables.fcoolcp,
        )
        po.ovarre(
            self.outfile, "Average coolant channel diameter (m)", "(dcool)", dcool
        )
        po.ovarre(self.outfile, "Coolant channel length (m)", "(lcool)", lcool)
        po.ovarre(
            self.outfile,
            "Inlet coolant flow speed (m/s)",
            "(vel_cp_coolant_midplane)",
            tfcoil_variables.vel_cp_coolant_midplane,
        )
        po.ovarre(
            self.outfile,
            "Outlet coolant flow speed (m/s)",
            "(vcool_max)",
            vcool_max,
        )
        po.ovarre(
            self.outfile,
            "Coolant mass flow rate (kg/s)",
            "(cool_mass_flow)",
            cool_mass_flow,
        )
        po.ovarre(
            self.outfile,
            "Number of coolant tubes",
            "(n_cp_coolant_channels_total)",
            tfcoil_variables.n_cp_coolant_channels_total,
        )
        po.ovarre(self.outfile, "Reynolds number", "(reyn)", reyn)
        po.ovarre(self.outfile, "Prandtl number", "(prndtl)", prndtl)
        po.ovarre(self.outfile, "Nusselt number", "(nuselt)", nuselt)

        po.osubhd(self.outfile, "Resistive Heating :")
        po.ovarre(
            self.outfile,
            "Average conductor resistivity (ohm.m)",
            "(rho_cp)",
            tfcoil_variables.rho_cp,
        )
        po.ovarre(
            self.outfile,
            "Resistive heating (MW)",
            "(p_cp_resistive/1.0e6)",
            tfcoil_variables.p_cp_resistive / 1.0e6,
        )
        po.ovarre(
            self.outfile,
            "Nuclear heating (MW)",
            "(pnuc_cp_tf)",
            fwbs_variables.pnuc_cp_tf,
        )
        po.ovarre(self.outfile, "Total heating (MW)", "(ptot/1.0e6)", ptot / 1.0e6)

        po.osubhd(self.outfile, "Temperatures :")
        po.ovarre(
            self.outfile,
            "Input coolant temperature (K)",
            "(tfcoil_variables.temp_cp_coolant_inlet)",
            tfcoil_variables.temp_cp_coolant_inlet,
        )
        po.ovarre(
            self.outfile,
            "Input-output coolant temperature rise (K)",
            "(dtemp_cp_coolant)",
            tfcoil_variables.dtemp_cp_coolant,
        )
        po.ovarre(self.outfile, "Film temperature rise (K)", "(dtfilmav)", dtfilmav)
        po.ovarre(
            self.outfile,
            "Average temp gradient in conductor (K/m)",
            "(dtcncpav)",
            dtcncpav,
        )
        po.ovarre(
            self.outfile,
            "Average centrepost temperature (K)",
            "(tcpav2)",
            tfcoil_variables.tcpav2,
        )
        po.ovarre(
            self.outfile,
            "Peak centrepost temperature (K)",
            "(temp_cp_peak)",
            tfcoil_variables.temp_cp_peak,
        )

        po.osubhd(self.outfile, "Pump Power :")
        po.ovarre(self.outfile, "Coolant pressure drop (Pa)", "(dpres)", dpres)
        if (
            tfcoil_variables.i_tf_sup == 0
        ):  # Saturation pressure calculated with Water data ...
            po.ovarre(
                self.outfile, "Coolant inlet pressure (Pa)", "(presin)", presin
            )

        po.ovarre(
            self.outfile,
            "Pump power (W)",
            "(p_cp_coolant_pump_elec)",
            tfcoil_variables.p_cp_coolant_pump_elec,
        )

tf_field_and_force(i_tf_sup, r_tf_wp_inboard_outer, r_tf_wp_inboard_inner, r_tf_outboard_in, dx_tf_wp_insulation, dx_tf_wp_insertion_gap, b_tf_inboard_peak_symmetric, c_tf_total, n_tf_coils, dr_tf_plasma_case, rmajor, b_plasma_toroidal_on_axis, r_cp_top, itart, i_cp_joints, f_vforce_inboard)

Calculates the Toroidal Field (TF) coil field, forces, vacuum vessel (VV) quench considerations, and resistive magnet resistance/volume.

Parameters:

Name Type Description Default
i_tf_sup int

TF coil support type (1 = superconducting, 0 = resistive copper, 2 = resistive aluminium)

required
r_tf_wp_inboard_outer float

Outer radius of the inboard winding pack [m]

required
r_tf_wp_inboard_inner float

Inner radius of the inboard winding pack [m]

required
r_tf_outboard_in float

Inner radius of the outboard leg [m]

required
dx_tf_wp_insulation float

Thickness of winding pack ground insulation [m]

required
dx_tf_wp_insertion_gap float

Thickness of winding pack insertion gap [m]

required
b_tf_inboard_peak_symmetric float

Peak inboard magnetic field [T]

required
c_tf_total float

Total current in TF coils [A]

required
n_tf_coils int

Number of TF coils

required
dr_tf_plasma_case float

Plasma-facing case thickness [m]

required
rmajor float

Major radius of the plasma [m]

required
b_plasma_toroidal_on_axis float

Toroidal magnetic field at plasma center [T]

required
r_cp_top float

Centrepost outer radius at the top [m]

required
itart int

TART (tight aspect ratio tokamak) switch (0 = standard, 1 = TART)

required
i_cp_joints ints: int

Centrepost joints switch (1 = with sliding joints, 0 = without)

required
f_vforce_inboard float

Inboard vertical tension fraction

required

Returns:

Type Description
tuple[float, float, float, float]

Tuple containing: - cforce (float): Centering force per TF coil [N/m] - vforce (float): Inboard vertical tension [N] - vforce_outboard (float): Outboard vertical tension [N] - vforce_inboard_tot (float): Total inboard vertical force [N] - f_vforce_inboard (float): Inboard vertical tension fraction

Source code in process/models/tfcoil/base.py
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
def tf_field_and_force(
    self,
    i_tf_sup: int,
    r_tf_wp_inboard_outer: float,
    r_tf_wp_inboard_inner: float,
    r_tf_outboard_in: float,
    dx_tf_wp_insulation: float,
    dx_tf_wp_insertion_gap: float,
    b_tf_inboard_peak_symmetric: float,
    c_tf_total: float,
    n_tf_coils: int,
    dr_tf_plasma_case: float,
    rmajor: float,
    b_plasma_toroidal_on_axis: float,
    r_cp_top: float,
    itart: int,
    i_cp_joints: int,
    f_vforce_inboard: float,
) -> tuple[float, float, float, float, float]:
    """Calculates the Toroidal Field (TF) coil field, forces, vacuum vessel (VV) quench considerations,
    and resistive magnet resistance/volume.

    Parameters
    ----------
    i_tf_sup : int
        TF coil support type (1 = superconducting, 0 = resistive copper, 2 = resistive aluminium)
    r_tf_wp_inboard_outer : float
        Outer radius of the inboard winding pack [m]
    r_tf_wp_inboard_inner : float
        Inner radius of the inboard winding pack [m]
    r_tf_outboard_in : float
        Inner radius of the outboard leg [m]
    dx_tf_wp_insulation : float
        Thickness of winding pack ground insulation [m]
    dx_tf_wp_insertion_gap : float
        Thickness of winding pack insertion gap [m]
    b_tf_inboard_peak_symmetric : float
        Peak inboard magnetic field [T]
    c_tf_total : float
        Total current in TF coils [A]
    n_tf_coils : int
        Number of TF coils
    dr_tf_plasma_case : float
        Plasma-facing case thickness [m]
    rmajor : float
        Major radius of the plasma [m]
    b_plasma_toroidal_on_axis : float
        Toroidal magnetic field at plasma center [T]
    r_cp_top : float
        Centrepost outer radius at the top [m]
    itart : int
        TART (tight aspect ratio tokamak) switch (0 = standard, 1 = TART)
    i_cp_joints : ints: int
        Centrepost joints switch (1 = with sliding joints, 0 = without)
    f_vforce_inboard : float
        Inboard vertical tension fraction

    Returns
    -------
    tuple[float, float, float, float]
        Tuple containing:
        - cforce (float): Centering force per TF coil [N/m]
        - vforce (float): Inboard vertical tension [N]
        - vforce_outboard (float): Outboard vertical tension [N]
        - vforce_inboard_tot (float): Total inboard vertical force [N]
        - f_vforce_inboard (float): Inboard vertical tension fraction
    """

    # Outer/inner WP radius removing the ground insulation layer and the insertion gap [m]
    if i_tf_sup == 1:
        r_tf_wp_inboard_outer_conductor = (
            r_tf_wp_inboard_outer - dx_tf_wp_insulation - dx_tf_wp_insertion_gap
        )
        r_tf_wp_inboard_inner_conductor = (
            r_tf_wp_inboard_inner + dx_tf_wp_insulation + dx_tf_wp_insertion_gap
        )
    else:
        r_tf_wp_inboard_outer_conductor = r_tf_wp_inboard_outer - dx_tf_wp_insulation
        r_tf_wp_inboard_inner_conductor = r_tf_wp_inboard_inner + dx_tf_wp_insulation

    # Associated WP thickness
    dr_tf_wp_inboard_conductor = (
        r_tf_wp_inboard_outer_conductor - r_tf_wp_inboard_inner_conductor
    )

    # In plane forces
    # ---
    # Centering force = net inwards radial force per meters per TF coil [N/m]
    cforce = 0.5e0 * b_tf_inboard_peak_symmetric * c_tf_total / n_tf_coils

    # Vertical force per coil [N]
    # ***
    # Rem : this force does not depends on the TF shape or the presence of
    #        sliding joints, the in/outboard vertical tension repartition is
    # -#
    # Ouboard leg WP plasma side radius without ground insulation/insertion gat [m]
    if i_tf_sup == 1:
        r_tf_wp_outboard_inner_conductor = (
            r_tf_outboard_in
            + dr_tf_plasma_case
            + dx_tf_wp_insulation
            + dx_tf_wp_insertion_gap
        )
    else:
        r_tf_wp_outboard_inner_conductor = r_tf_outboard_in + dx_tf_wp_insulation

    # If the TF coil has no dr_bore it would induce division by 0.
    # In this situation, the dr_bore radius is set to a very small value : 1.0e-9 m
    if (
        abs(r_tf_wp_inboard_inner_conductor)
        < np.finfo(float(r_tf_wp_inboard_inner_conductor)).eps
    ):
        r_tf_wp_inboard_inner_conductor = 1.0e-9

    # May the force be with you
    vforce_tot = (
        0.5e0
        * (b_plasma_toroidal_on_axis * rmajor * c_tf_total)
        / (n_tf_coils * dr_tf_wp_inboard_conductor**2)
        * (
            r_tf_wp_inboard_outer_conductor**2
            * np.log(
                r_tf_wp_inboard_outer_conductor / r_tf_wp_inboard_inner_conductor
            )
            + r_tf_wp_outboard_inner_conductor**2
            * np.log(
                (r_tf_wp_outboard_inner_conductor + dr_tf_wp_inboard_conductor)
                / r_tf_wp_outboard_inner_conductor
            )
            + dr_tf_wp_inboard_conductor**2
            * np.log(
                (r_tf_wp_outboard_inner_conductor + dr_tf_wp_inboard_conductor)
                / r_tf_wp_inboard_inner_conductor
            )
            - dr_tf_wp_inboard_conductor
            * (r_tf_wp_inboard_outer_conductor + r_tf_wp_outboard_inner_conductor)
            + 2.0e0
            * dr_tf_wp_inboard_conductor
            * (
                r_tf_wp_inboard_outer_conductor
                * np.log(
                    r_tf_wp_inboard_inner_conductor / r_tf_wp_inboard_outer_conductor
                )
                + r_tf_wp_outboard_inner_conductor
                * np.log(
                    (r_tf_wp_outboard_inner_conductor + dr_tf_wp_inboard_conductor)
                    / r_tf_wp_outboard_inner_conductor
                )
            )
        )
    )

    # Case of a centrepost (physics_variables.itart == 1) with sliding joints (the CP vertical are separated from the leg ones)
    # Rem SK : casing/insulation thickness not subtracted as part of the CP is genuinely connected to the legs..
    if itart == 1 and i_cp_joints == 1:
        # CP vertical tension [N]
        vforce = (
            0.25e0
            * (b_plasma_toroidal_on_axis * rmajor * c_tf_total)
            / (n_tf_coils * dr_tf_wp_inboard_conductor**2)
            * (
                2.0e0
                * r_tf_wp_inboard_outer_conductor**2
                * np.log(
                    r_tf_wp_inboard_outer_conductor / r_tf_wp_inboard_inner_conductor
                )
                + 2.0e0
                * dr_tf_wp_inboard_conductor**2
                * np.log(r_cp_top / r_tf_wp_inboard_inner_conductor)
                + 3.0e0 * dr_tf_wp_inboard_conductor**2
                - 2.0e0
                * dr_tf_wp_inboard_conductor
                * r_tf_wp_inboard_outer_conductor
                + 4.0e0
                * dr_tf_wp_inboard_conductor
                * r_tf_wp_inboard_outer_conductor
                * np.log(
                    r_tf_wp_inboard_inner_conductor / r_tf_wp_inboard_outer_conductor
                )
            )
        )

        # Vertical tension applied on the outer leg [N]
        vforce_outboard = vforce_tot - vforce

        # Inboard vertical tension fraction
        f_vforce_inboard = vforce / vforce_tot

    # Case of TF without joints or with clamped joints vertical tension
    else:
        # Inboard vertical tension [N]
        vforce = f_vforce_inboard * vforce_tot

        # Ouboard vertical tension [N]
        vforce_outboard = vforce * ((1.0e0 / f_vforce_inboard) - 1.0e0)

    # Total vertical force
    vforce_inboard_tot = vforce * n_tf_coils

    return cforce, vforce, vforce_outboard, vforce_inboard_tot, f_vforce_inboard

he_density(temp) staticmethod

Subroutine calculating temperature dependent helium density at 100 bar from fit using the following data, valid in [4-50] K Ref : R.D. McCarty, Adv. Cryo. Eng., 1990, 35, 1465-1475.

Parameters:

Name Type Description Default
temp float

Helium temperature [K]

required

Returns:

Type Description
type

density: Heliyn density [kg/m3]

Source code in process/models/tfcoil/base.py
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
@staticmethod
def he_density(temp: float) -> float:
    """
    Subroutine calculating temperature dependent helium density at 100 bar
    from fit using the following data, valid in [4-50] K
    Ref : R.D. McCarty, Adv. Cryo. Eng., 1990, 35, 1465-1475.

    Parameters
    ----------
    temp : float
        Helium temperature [K]

    Returns
    -------
    type
        density: Heliyn density [kg/m3]
    """

    # Fit range validation
    if temp < 4.0e0 or temp > 50.0e0:
        logger.error(
            f"Helium temperature out of helium property fiting range [4-50] K. {temp=}"
        )

    # Oder 3 polynomial fit
    if temp < 29.5e0:
        density = (
            217.753831e0
            - 1.66564525e0 * temp
            - 0.160654724e0 * temp**2
            + 0.00339003258e0 * temp**3
        )

    # Linear interpolation between the fits to avoid discontinuity
    elif temp < 30.5e0:
        density = 231.40661479377616e0 - 3.917589985552496e0 * temp

    # Oder 2 polynomial fit
    else:
        density = 212.485251e0 - 4.18059786e0 * temp + 0.0289632937e0 * temp**2

    return density

he_cp(temp) staticmethod

Subroutine calculating temperature dependent thermal capacity at constant pressures at 100 Bar from fit using the following data valid in [4-50] K Ref : R.D. McCarty, Adv. Cryo. Eng., 1990, 35, 1465-1475.

Parameters:

Name Type Description Default
temp float

Helium temperature [K]

required

Returns:

Type Description
float

Themal capacity at constant pressure [K/(kg.K)]

Source code in process/models/tfcoil/base.py
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
@staticmethod
def he_cp(temp: float) -> float:
    """
    Subroutine calculating temperature dependent thermal capacity at
    constant pressures at 100 Bar from fit using the following data
    valid in [4-50] K
    Ref : R.D. McCarty, Adv. Cryo. Eng., 1990, 35, 1465-1475.

    Parameters
    ----------
    temp : float
        Helium temperature [K]

    Returns
    -------
    :
        Themal capacity at constant pressure [K/(kg.K)]
    """

    # Fit range validation
    if temp < 4.0e0 or temp > 50.0e0:
        logger.error(
            f"Helium temperature out of helium property fiting range [4-50] K. {temp=}"
        )

    # Order 3 polynomial fit in [4-30] K on the dimenion [K/(g.K)]
    if temp < 29.5e0:
        cp = (
            -0.834218557e0
            + 0.637079569e0 * temp
            - 0.0208839696e0 * temp**2
            + 0.000233433748e0 * temp**3
        )

    # Linear interpolation between the fits to avoid discontinuity
    elif (
        temp < 30.5e0
    ):  # Linear interpolation between the fits to avoid discontinuity
        cp = 4.924018467550791e0 + 0.028953709588498633e0 * temp

    # Linear fit in [30-60] K on the dimenion [K/(g.K)]
    else:
        cp = 6.11883125e0 - 0.01022048e0 * temp

    # conversion to [K/(kg.K)] and return
    return cp * 1.0e3

he_visco(temp) staticmethod

Subroutine calculating temperature dependent He viscosity at 100 Bar from fit using the following data, valid in [4-50] K Ref : V.D. Arp,; R.D. McCarty ; Friend, D.G., Technical Note 1334, National Institute of Standards and Technology, Boulder, CO, 1998, 0.

Parameters:

Name Type Description Default
temp float

Helium temperature [K]

required

Returns:

Type Description
float

Themal capacity at constant pressure [Pa.s]

Source code in process/models/tfcoil/base.py
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
@staticmethod
def he_visco(temp: float) -> float:
    """
    Subroutine calculating temperature dependent He viscosity at 100 Bar
    from fit using the following data, valid in [4-50] K
    Ref : V.D. Arp,; R.D. McCarty ; Friend, D.G., Technical Note 1334, National
    Institute of Standards and Technology, Boulder, CO, 1998, 0.

    Parameters
    ----------
    temp : float
        Helium temperature [K]

    Returns
    -------
    :
        Themal capacity at constant pressure [Pa.s]
    """

    if temp < 4.0e0 or temp > 50.0e0:
        logger.error(
            f"Helium temperature out of helium property fiting range [4-50] K. {temp=}"
        )

    # Order 4 polynomial exponential fit in [4-25] K
    if temp < 22.5e0:
        visco = np.exp(
            -9.19688182e0
            - 4.83007225e-1 * temp
            + 3.47720002e-2 * temp**2
            - 1.17501538e-3 * temp**3
            + 1.54218249e-5 * temp**4
        )

    # Linear interpolation between the fits to avoid discontinuity
    elif temp < 27.5e0:
        visco = 6.708587487790973e-6 + 5.776427353055518e-9 * temp

    # Linear fit in [25-60] K
    else:
        visco = 5.41565319e-6 + 5.279222e-8 * temp

    return visco

he_th_cond(temp) staticmethod

Subroutine calculating temperature dependent He thermal conductivity at 100 Bar from fit using the following data, valid in [4-50] K Ref : B.A. Hands B.A., Cryogenics, 1981, 21, 12, 697-703.

Parameters:

Name Type Description Default
temp float

Helium temperature [K]

required

Returns:

Type Description
float

Themal conductivity [W/(m.K)]

Source code in process/models/tfcoil/base.py
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
@staticmethod
def he_th_cond(temp: float) -> float:
    """
    Subroutine calculating temperature dependent He thermal conductivity
    at 100 Bar from fit using the following data, valid in [4-50] K
    Ref : B.A. Hands B.A., Cryogenics, 1981, 21, 12, 697-703.

    Parameters
    ----------
    temp : float
        Helium temperature [K]

    Returns
    -------
    :
        Themal conductivity [W/(m.K)]
    """

    # Fit range validation
    if temp < 4.0e0 or temp > 50.0e0:
        logger.error(
            f"Helium temperature out of helium property fiting range [4-50] K. {temp=}"
        )

    # Order 4 polynomial fit
    if temp < 24.0e0:
        th_cond = (
            -7.56066334e-3
            + 1.62626819e-2 * temp
            - 1.3633619e-3 * temp**2
            + 4.84227752e-5 * temp**3
            - 6.31264281e-7 * temp**4
        )

    # Linear interpolation between the fits to avoid discontinuity
    elif temp < 25.0e0:
        th_cond = 0.05858194642349288e0 - 5.706361831471496e-5 * temp

    # Order 2 polynomial fit
    elif temp < 50.0e0:
        th_cond = (
            0.0731268577e0
            - 0.0013826223e0 * temp
            + 3.55551245e-5 * temp**2
            - 2.32185411e-7 * temp**3
        )

    # Linear interpolation between the fits to avoid discontinuity
    elif temp < 51.0e0:
        th_cond = 4.450475632499988e-2 + 3.871124250000024e-4 * temp

    # Linear fit
    else:
        th_cond = 0.04235676e0 + 0.00042923e0 * temp

    return th_cond

al_th_cond(temp) staticmethod

Subroutine calculating temperature dependent Al thermal conductivity

Parameters:

Name Type Description Default
temp float

Helium temperature [K]

required

Returns:

Type Description
float

Themal conductivity [W/(m.K)]

Source code in process/models/tfcoil/base.py
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
@staticmethod
def al_th_cond(temp: float) -> float:
    """
    Subroutine calculating temperature dependent Al thermal conductivity

    Parameters
    ----------
    temp : float
        Helium temperature [K]

    Returns
    -------
    :
        Themal conductivity [W/(m.K)]
    """

    # Fiting range verification
    if temp < 15.0e0 or temp > 150.0e0:
        logger.error(
            f"Aluminium temperature out of the th conductivity fit range [15-60] K. {temp=}"
        )

    # fit 15 < T < 60 K (order 3 poly)
    if temp < 60.0e0:
        th_cond = (
            16332.2073e0
            - 776.91775e0 * temp
            + 13.405688e0 * temp**2
            - 8.01e-02 * temp**3
        )

    # Linear interpolation between the fits to avoid discontinuity
    elif temp < 70.0e0:
        th_cond = 1587.9108966527328e0 - 15.19819661087886e0 * temp

    # fit 70 < T < 150 K (order 2 poly)
    elif temp < 150.0e0:
        th_cond = 1782.77406e0 - 24.7778504e0 * temp + 9.70842050e-2 * temp**2

    # constant value after that set with the fit upper limit to avoid discontinuities
    else:
        th_cond = 250.4911087866094e0

    return th_cond

tf_coil_self_inductance(dr_tf_inboard, r_tf_arc, z_tf_arc, itart, i_tf_shape, z_tf_inside_half, dr_tf_outboard, r_tf_outboard_mid, r_tf_inboard_mid) staticmethod

Calculates the self-inductance of a TF coil.

This function numerically integrates the magnetic field energy to estimate the self-inductance of a toroidal field (TF) coil, using the geometry defined by the arc points and the inboard thickness.

Parameters:

Name Type Description Default
dr_tf_inboard float

Radial thickness of the inboard leg of the TF coil [m].

required
r_tf_arc ndarray

Array of R coordinates of arc points (length 5).

required
z_tf_arc ndarray

Array of Z coordinates of arc points (length 5).

required
itart int

TART (tight aspect ratio tokamak) switch (0 = standard, 1 = TART).

required
i_tf_shape int

TF coil shape selection switch (1 = D-shape, 2 = picture frame).

required
z_tf_inside_half float

Maximum inboard edge height [m].

required
dr_tf_outboard float

Radial thickness of the outboard leg of the TF coil [m].

required
r_tf_outboard_mid float

Mid-plane radius of the outboard leg of the TF coil [m].

required
r_tf_inboard_mid float

Mid-plane radius of the inboard leg of the TF coil [m].

required

Returns:

Type Description
float

Self-inductance of the TF coil [H].

Notes

For the D-shaped coil (i_tf_shape == 1) in a standard (non-TART) configuration (itart == 0), the integration is performed over the coil cross-section, including both the inboard and outboard arcs. The field is computed for unit current, and the contribution from the coil's own cross-sectional area is included by taking the field as B®/2. Top/bottom symmetry is assumed.

Source code in process/models/tfcoil/base.py
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
@staticmethod
@numba.njit(cache=True)
def tf_coil_self_inductance(
    dr_tf_inboard: float,
    r_tf_arc: np.ndarray,
    z_tf_arc: np.ndarray,
    itart: int,
    i_tf_shape: int,
    z_tf_inside_half: float,
    dr_tf_outboard: float,
    r_tf_outboard_mid: float,
    r_tf_inboard_mid: float,
) -> float:
    """Calculates the self-inductance of a TF coil.

    This function numerically integrates the magnetic field energy to estimate
    the self-inductance of a toroidal field (TF) coil, using the geometry
    defined by the arc points and the inboard thickness.

    Parameters
    ----------
    dr_tf_inboard : float
        Radial thickness of the inboard leg of the TF coil [m].
    r_tf_arc : numpy.ndarray
        Array of R coordinates of arc points (length 5).
    z_tf_arc : numpy.ndarray
        Array of Z coordinates of arc points (length 5).
    itart : int
        TART (tight aspect ratio tokamak) switch (0 = standard, 1 = TART).
    i_tf_shape : int
        TF coil shape selection switch (1 = D-shape, 2 = picture frame).
    z_tf_inside_half : float
        Maximum inboard edge height [m].
    dr_tf_outboard : float
        Radial thickness of the outboard leg of the TF coil [m].
    r_tf_outboard_mid : float
        Mid-plane radius of the outboard leg of the TF coil [m].
    r_tf_inboard_mid : float
        Mid-plane radius of the inboard leg of the TF coil [m].

    Returns
    -------
    float
        Self-inductance of the TF coil [H].

    Notes
    -----
    For the D-shaped coil (i_tf_shape == 1) in a standard (non-TART) configuration
    (itart == 0), the integration is performed over the coil cross-section, including both
    the inboard and outboard arcs. The field is computed for unit current,
    and the contribution from the coil's own cross-sectional area is included
    by taking the field as B(r)/2. Top/bottom symmetry is assumed.

    """
    NINTERVALS = 100

    if itart == 0 and i_tf_shape == 1:
        # Integrate over the whole TF area, including the coil thickness.
        x0 = r_tf_arc[1]
        y0 = z_tf_arc[1]

        # Minor and major radii of the inside and outside perimeters of the the
        # Inboard leg and arc.
        # Average the upper and lower halves, which are different in the
        # single null case
        ai = r_tf_arc[1] - r_tf_arc[0]
        bi = (z_tf_arc[1] - z_tf_arc[3]) / 2.0e0 - z_tf_arc[0]
        ao = ai + dr_tf_inboard
        bo = bi + dr_tf_inboard
        # Interval used for integration
        dr = ao / NINTERVALS
        # Start both integrals from the centre-point where the arcs join.
        # Initialise major radius
        r = x0 - dr / 2.0e0

        ind_tf_coil = 0

        for _ in range(NINTERVALS):
            # Field in the dr_bore for unit current
            b = constants.RMU0 / (2.0e0 * np.pi * r)
            # Find out if there is a dr_bore
            if x0 - r < ai:
                h_bore = y0 + bi * np.sqrt(1 - ((r - x0) / ai) ** 2)
                h_thick = bo * np.sqrt(1 - ((r - x0) / ao) ** 2) - h_bore
            else:
                h_bore = 0.0e0
                # Include the contribution from the straight section
                h_thick = bo * np.sqrt(1 - ((r - x0) / ao) ** 2) + z_tf_arc[0]

            # Assume B in TF coil = 1/2  B in dr_bore
            # Multiply by 2 for upper and lower halves of coil
            ind_tf_coil += b * dr * (2.0e0 * h_bore + h_thick)
            r = r - dr

        # Outboard arc
        ai = r_tf_arc[2] - r_tf_arc[1]
        bi = (z_tf_arc[1] - z_tf_arc[3]) / 2.0e0
        ao = ai + dr_tf_inboard
        bo = bi + dr_tf_inboard
        dr = ao / NINTERVALS
        # Initialise major radius
        r = x0 + dr / 2.0e0

        for _ in range(NINTERVALS):
            # Field in the dr_bore for unit current
            b = constants.RMU0 / (2.0e0 * np.pi * r)
            # Find out if there is a dr_bore
            if r - x0 < ai:
                h_bore = y0 + bi * np.sqrt(1 - ((r - x0) / ai) ** 2)
                h_thick = bo * np.sqrt(1 - ((r - x0) / ao) ** 2) - h_bore
            else:
                h_bore = 0.0e0
                h_thick = bo * np.sqrt(1 - ((r - x0) / ao) ** 2)

            # Assume B in TF coil = 1/2  B in dr_bore
            # Multiply by 2 for upper and lower halves of coil
            ind_tf_coil += b * dr * (2.0e0 * h_bore + h_thick)
            r = r + dr
    else:
        # Picture frame TF coil
        ind_tf_coil = (
            (z_tf_inside_half + dr_tf_outboard)
            * constants.RMU0
            / np.pi
            * np.log(r_tf_outboard_mid / r_tf_inboard_mid)
        )

    return ind_tf_coil

generic_tf_coil_area_and_masses()

Subroutine to calculate the TF coil areas and masses

Source code in process/models/tfcoil/base.py
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
def generic_tf_coil_area_and_masses(self):
    """Subroutine to calculate the TF coil areas and masses"""

    # Surface areas (for cryo system) [m²]
    wbtf = (
        build_variables.r_tf_inboard_out
        * np.sin(superconducting_tf_coil_variables.rad_tf_coil_inboard_toroidal_half)
        - build_variables.r_tf_inboard_in
        * superconducting_tf_coil_variables.tan_theta_coil
    )
    tfcoil_variables.tfocrn = (
        build_variables.r_tf_inboard_in
        * superconducting_tf_coil_variables.tan_theta_coil
    )
    tfcoil_variables.tficrn = tfcoil_variables.tfocrn + wbtf

    # Total surface area of two toroidal shells covering the TF coils [m2]
    # (inside and outside surfaces)
    # = 2 * centroid coil length * 2 pi R, where R is average of i/b and o/b centres
    tfcoil_variables.tfcryoarea = (
        2.0e0
        * tfcoil_variables.len_tf_coil
        * 2.0
        * np.pi
        * 0.5e0
        * (build_variables.r_tf_inboard_mid + build_variables.r_tf_outboard_mid)
    )

stresscl(n_tf_layer, n_radial_array, n_tf_wp_stress_layers, i_tf_bucking, r_tf_inboard_in, dr_bore, z_tf_inside_half, f_z_cs_tf_internal, dr_cs, i_tf_inside_cs, dr_tf_inboard, dr_cs_tf_gap, i_pf_conductor, j_cs_flat_top_end, j_cs_pulse_start, c_pf_coil_turn_peak_input, n_pf_coils_in_group, f_dr_dz_cs_turn, radius_cs_turn_corners, f_a_cs_turn_steel, eyoung_steel, poisson_steel, eyoung_cond_axial, poisson_cond_axial, eyoung_cond_trans, poisson_cond_trans, eyoung_ins, poisson_ins, dx_tf_turn_insulation, eyoung_copper, poisson_copper, i_tf_sup, eyoung_res_tf_buck, r_tf_wp_inboard_inner, tan_theta_coil, rad_tf_coil_inboard_toroidal_half, r_tf_wp_inboard_outer, a_tf_coil_inboard_steel, a_tf_plasma_case, a_tf_coil_nose_case, dx_tf_wp_insertion_gap, dx_tf_wp_insulation, n_tf_coil_turns, i_tf_turns_integer, dx_tf_turn_cable_space_average, dr_tf_turn_cable_space, dia_tf_turn_coolant_channel, f_a_tf_turn_cable_copper, dx_tf_turn_steel, dx_tf_side_case_average, dx_tf_wp_toroidal_average, a_tf_coil_inboard_insulation, a_tf_wp_steel, a_tf_wp_conductor, a_tf_wp_with_insulation, eyoung_al, poisson_al, fcoolcp, n_tf_graded_layers, c_tf_total, dr_tf_plasma_case, i_tf_stress_model, vforce_inboard_tot, i_tf_tresca, a_tf_coil_inboard_case, vforce, a_tf_turn_steel) staticmethod

TF coil stress routine

This subroutine sets up the stress calculations for the TF coil set. PROCESS Superconducting TF Coil Model, J. Morris, CCFE, 1st May 2014

Parameters:

Name Type Description Default
n_tf_layer
required
n_radial_array
required
n_tf_wp_stress_layers
required
i_tf_bucking
required
r_tf_inboard_in
required
dr_bore
required
z_tf_inside_half
required
f_z_cs_tf_internal
required
dr_cs
required
i_tf_inside_cs
required
dr_tf_inboard
required
dr_cs_tf_gap
required
i_pf_conductor
required
j_cs_flat_top_end
required
j_cs_pulse_start
required
c_pf_coil_turn_peak_input
required
n_pf_coils_in_group
required
f_dr_dz_cs_turn
required
radius_cs_turn_corners
required
f_a_cs_turn_steel
required
eyoung_steel
required
poisson_steel
required
eyoung_cond_axial
required
poisson_cond_axial
required
eyoung_cond_trans
required
poisson_cond_trans
required
eyoung_ins
required
poisson_ins
required
dx_tf_turn_insulation
required
eyoung_copper
required
poisson_copper
required
i_tf_sup
required
eyoung_res_tf_buck
required
r_tf_wp_inboard_inner
required
tan_theta_coil
required
rad_tf_coil_inboard_toroidal_half
required
r_tf_wp_inboard_outer
required
a_tf_coil_inboard_steel
required
a_tf_plasma_case
required
a_tf_coil_nose_case
required
dx_tf_wp_insertion_gap
required
dx_tf_wp_insulation
required
n_tf_coil_turns
required
i_tf_turns_integer
required
dx_tf_turn_cable_space_average
required
dr_tf_turn_cable_space
required
dia_tf_turn_coolant_channel
required
f_a_tf_turn_cable_copper
required
dx_tf_turn_steel
required
dx_tf_side_case_average
required
dx_tf_wp_toroidal_average
required
a_tf_coil_inboard_insulation
required
a_tf_wp_steel
required
a_tf_wp_conductor
required
a_tf_wp_with_insulation
required
eyoung_al
required
poisson_al
required
fcoolcp
required
n_tf_graded_layers
required
c_tf_total
required
dr_tf_plasma_case
required
i_tf_stress_model
required
vforce_inboard_tot
required
i_tf_tresca
required
a_tf_coil_inboard_case
required
vforce
required
a_tf_turn_steel
required
Source code in process/models/tfcoil/base.py
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
@staticmethod
@numba.njit(cache=True)
def stresscl(
    n_tf_layer,
    n_radial_array,
    n_tf_wp_stress_layers,
    i_tf_bucking,
    r_tf_inboard_in,
    dr_bore,
    z_tf_inside_half,
    f_z_cs_tf_internal,
    dr_cs,
    i_tf_inside_cs,
    dr_tf_inboard,
    dr_cs_tf_gap,
    i_pf_conductor,
    j_cs_flat_top_end,
    j_cs_pulse_start,
    c_pf_coil_turn_peak_input,
    n_pf_coils_in_group,
    f_dr_dz_cs_turn,
    radius_cs_turn_corners,
    f_a_cs_turn_steel,
    eyoung_steel,
    poisson_steel,
    eyoung_cond_axial,
    poisson_cond_axial,
    eyoung_cond_trans,
    poisson_cond_trans,
    eyoung_ins,
    poisson_ins,
    dx_tf_turn_insulation,
    eyoung_copper,
    poisson_copper,
    i_tf_sup,
    eyoung_res_tf_buck,
    r_tf_wp_inboard_inner,
    tan_theta_coil,
    rad_tf_coil_inboard_toroidal_half,
    r_tf_wp_inboard_outer,
    a_tf_coil_inboard_steel,
    a_tf_plasma_case,
    a_tf_coil_nose_case,
    dx_tf_wp_insertion_gap,
    dx_tf_wp_insulation,
    n_tf_coil_turns,
    i_tf_turns_integer,
    dx_tf_turn_cable_space_average,
    dr_tf_turn_cable_space,
    dia_tf_turn_coolant_channel,
    f_a_tf_turn_cable_copper,
    dx_tf_turn_steel,
    dx_tf_side_case_average,
    dx_tf_wp_toroidal_average,
    a_tf_coil_inboard_insulation,
    a_tf_wp_steel,
    a_tf_wp_conductor,
    a_tf_wp_with_insulation,
    eyoung_al,
    poisson_al,
    fcoolcp,
    n_tf_graded_layers,
    c_tf_total,
    dr_tf_plasma_case,
    i_tf_stress_model,
    vforce_inboard_tot,
    i_tf_tresca,
    a_tf_coil_inboard_case,
    vforce,
    a_tf_turn_steel,
):
    """TF coil stress routine

    This subroutine sets up the stress calculations for the
    TF coil set.
    PROCESS Superconducting TF Coil Model, J. Morris, CCFE, 1st May 2014

    Parameters
    ----------
    n_tf_layer :

    n_radial_array :

    n_tf_wp_stress_layers :

    i_tf_bucking :

    r_tf_inboard_in :

    dr_bore :

    z_tf_inside_half :

    f_z_cs_tf_internal :

    dr_cs :

    i_tf_inside_cs :

    dr_tf_inboard :

    dr_cs_tf_gap :

    i_pf_conductor :

    j_cs_flat_top_end :

    j_cs_pulse_start :

    c_pf_coil_turn_peak_input :

    n_pf_coils_in_group :

    f_dr_dz_cs_turn :

    radius_cs_turn_corners :

    f_a_cs_turn_steel :

    eyoung_steel :

    poisson_steel :

    eyoung_cond_axial :

    poisson_cond_axial :

    eyoung_cond_trans :

    poisson_cond_trans :

    eyoung_ins :

    poisson_ins :

    dx_tf_turn_insulation :

    eyoung_copper :

    poisson_copper :

    i_tf_sup :

    eyoung_res_tf_buck :

    r_tf_wp_inboard_inner :

    tan_theta_coil :

    rad_tf_coil_inboard_toroidal_half :

    r_tf_wp_inboard_outer :

    a_tf_coil_inboard_steel :

    a_tf_plasma_case :

    a_tf_coil_nose_case :

    dx_tf_wp_insertion_gap :

    dx_tf_wp_insulation :

    n_tf_coil_turns :

    i_tf_turns_integer :

    dx_tf_turn_cable_space_average :

    dr_tf_turn_cable_space :

    dia_tf_turn_coolant_channel :

    f_a_tf_turn_cable_copper :

    dx_tf_turn_steel :

    dx_tf_side_case_average :

    dx_tf_wp_toroidal_average :

    a_tf_coil_inboard_insulation :

    a_tf_wp_steel :

    a_tf_wp_conductor :

    a_tf_wp_with_insulation :

    eyoung_al :

    poisson_al :

    fcoolcp :

    n_tf_graded_layers :

    c_tf_total :

    dr_tf_plasma_case :

    i_tf_stress_model :

    vforce_inboard_tot :

    i_tf_tresca :

    a_tf_coil_inboard_case :

    vforce :

    a_tf_turn_steel :

    """
    jeff = np.zeros((n_tf_layer,))
    # Effective current density [A/m2]

    radtf = np.zeros((n_tf_layer + 1,))
    # Radii used to define the layers used in the stress models [m]
    # Layers are labelled from inboard to outbard

    eyoung_trans = np.zeros((n_tf_layer,))
    # Young's moduli (one per layer) of the TF coil in the
    # transverse (radial/toroidal) direction. Used in the stress
    # models [Pa]

    poisson_trans = np.zeros(
        (n_tf_layer,),
    )
    # Poisson's ratios (one per layer) of the TF coil between the
    # two transverse directions (radial and toroidal). Used in the
    # stress models.

    eyoung_member_array = np.zeros((n_tf_wp_stress_layers,))
    # Array to store the Young's moduli of the members to composite into smeared
    # properties [Pa]

    poisson_member_array = np.zeros((n_tf_wp_stress_layers,))
    # Array to store the Poisson's ratios of the members to composite into smeared
    # properti

    l_member_array = np.zeros((n_tf_wp_stress_layers,))
    # Array to store the linear dimension (thickness) of the members to composite into smeared
    # properties [m]

    eyoung_axial = np.zeros((n_tf_layer,))
    # Young's moduli (one per layer) of the TF coil in the vertical
    # direction used in the stress models [Pa]

    poisson_axial = np.zeros((n_tf_layer,))
    # Poisson's ratios (one per layer) of the TF coil between the
    # vertical and transverse directions (in that order). Used in the
    # stress models. d(transverse strain)/d(vertical strain) with
    # only vertical stress.

    sig_tf_wp_av_z = np.zeros(((n_tf_layer - i_tf_bucking) * n_radial_array,))
    # TF Inboard leg WP smeared vertical stress r distribution at mid-plane [Pa]

    sig_tf_r_max = np.zeros((n_tf_layer,))
    # Radial stress of the point of maximum shear stress of each layer [Pa]

    sig_tf_t_max = np.zeros((n_tf_layer,))
    # Toroidal stress of the point of maximum shear stress of each layer [Pa]

    sig_tf_z_max = np.zeros((n_tf_layer,))
    # Vertical stress of the point of maximum shear stress of each layer [Pa]
    # Rem : Currently constant but will be r dependent in the future

    sig_tf_vmises_max = np.zeros((n_tf_layer,))
    # Von-Mises stress of the point of maximum shear stress of each layer [Pa]

    s_shear_tf_peak = np.zeros((n_tf_layer,))
    # Maximum shear stress, for the Tresca yield criterion of each layer [Pa]
    # If the CEA correction is addopted, the CEA corrected value is used

    sig_tf_z = np.zeros((n_tf_layer * n_radial_array,))
    # TF Inboard leg vertical tensile stress at mid-plane [Pa]

    sig_tf_smeared_r = np.zeros((n_tf_layer * n_radial_array,))
    # TF Inboard leg radial smeared stress r distribution at mid-plane [Pa]

    sig_tf_smeared_t = np.zeros((n_tf_layer * n_radial_array,))
    # TF Inboard leg tangential smeared stress r distribution at mid-plane [Pa]

    sig_tf_smeared_z = np.zeros((n_tf_layer * n_radial_array,))
    # TF Inboard leg vertical smeared stress r distribution at mid-plane [Pa]

    fac_sig_z_wp_av = 0.0
    # WP averaged vertical stress unsmearing factor

    str_tf_r = np.zeros((n_radial_array * n_tf_layer,))
    str_tf_t = np.zeros((n_radial_array * n_tf_layer,))
    str_tf_z = np.zeros((n_radial_array * n_tf_layer,))

    sig_tf_case = None
    sig_tf_cs_bucked = None
    str_wp = None
    casestr = None
    insstrain = None

    # New extended plane strain model can handle it
    if (
        abs(r_tf_inboard_in) < np.finfo(float(r_tf_inboard_in)).eps
        and i_tf_stress_model != 2
    ):
        raise ProcessValueError("r_tf_inboard_in is ~= 0", 245)

    # TODO: following is no longer used/needed?
    # if tfcoil_variables.a_tf_turn_cable_space_no_void >= 0.0e0:
    #     tcbs = numpy.sqrt(tfcoil_variables.a_tf_turn_cable_space_no_void)
    # else:
    #     tcbs = 0.0e0

    # LAYER ELASTIC PROPERTIES
    # ------------------------
    # Number of bucking layers
    n_tf_bucking = i_tf_bucking

    # CS properties (bucked and wedged)
    # ---
    if i_tf_bucking >= 2:
        # Calculation performed at CS flux swing (no current on CS)
        jeff[0] = 0.0e0

        # Inner radius of the CS
        if i_tf_inside_cs == 1:
            # CS not used as wedge support i_tf_inside_cs = 1
            radtf[0] = 0.001
        else:
            radtf[0] = dr_bore

        # Superconducting CS
        if i_pf_conductor == 0:
            # Getting the turn dimention from scratch
            # as the TF is called before CS in caller.f90
            # -#

            # CS vertical cross-section area [m2]
            if i_tf_inside_cs == 1:
                a_oh = (
                    2.0e0
                    * z_tf_inside_half
                    * f_z_cs_tf_internal
                    * (dr_bore - dr_tf_inboard)
                )
            else:
                a_oh = 2.0e0 * z_tf_inside_half * f_z_cs_tf_internal * dr_cs

            # Maximum current in Central Solenoid, at either BOP or EOF [MA-turns]
            # Absolute value
            curr_oh_max = (
                1.0e-6 * np.maximum(j_cs_flat_top_end, j_cs_pulse_start) * a_oh
            )

            #  Number of turns
            n_oh_turns = (
                1.0e6
                * curr_oh_max
                / c_pf_coil_turn_peak_input[sum(n_pf_coils_in_group)]
            )

            # CS Turn vertical cross-sectionnal area
            a_cs_turn = a_oh / n_oh_turns

            # CS coil turn geometry calculation - stadium shape
            # Literature: https://doi.org/10.1016/j.fusengdes.2017.04.052
            dz_cs_turn = (
                a_cs_turn / f_dr_dz_cs_turn
            ) ** 0.5  # width of cs turn conduit
            dr_cs_turn = f_dr_dz_cs_turn * dz_cs_turn  # length of cs turn conduit
            # Radius of turn space = radius_cs_turn_cable_space
            # Radius of curved outer corrner radius_cs_turn_corners = 3mm from literature
            # f_dr_dz_cs_turn = 70 / 22 from literature
            p1 = ((dr_cs_turn - dz_cs_turn) / np.pi) ** 2
            p2 = (
                (dr_cs_turn * dz_cs_turn)
                - (4 - np.pi) * (radius_cs_turn_corners**2)
                - (a_cs_turn * f_a_cs_turn_steel)
            ) / np.pi
            radius_cs_turn_cable_space = -(
                (dr_cs_turn - dz_cs_turn) / np.pi
            ) + np.sqrt(p1 + p2)
            t_cond_oh = (
                dz_cs_turn / 2
            ) - radius_cs_turn_cable_space  # thickness of steel conduit in cs turn

            # OH/CS conduit thickness calculated assuming square conduit [m]
            # The CS insulation layer is assumed to the same as the TF one

            # CS turn cable space thickness
            t_cable_oh = radius_cs_turn_cable_space * 2
            # -#

            # Smeared elastic properties of the CS
            # These smearing functions were written assuming transverse-
            # isotropic materials; that is not true of the CS, where the
            # stiffest dimension is toroidal and the radial and vertical
            # dimension are less stiff. Nevertheless this attempts to
            # hit the mark.
            # [EDIT: eyoung_cond is for the TF coil, not the CS coil]

            # Get transverse properties
            (eyoung_trans[0], a_working, poisson_trans[0]) = eyoung_parallel(
                eyoung_steel,
                f_a_cs_turn_steel,
                poisson_steel,
                eyoung_cond_axial,
                1e0 - f_a_cs_turn_steel,
                poisson_cond_axial,
            )

            # Get vertical properties
            # Split up into "members", concentric squares in cross section
            # (described in Figure 10 of the TF coil documentation)
            # Conductor
            eyoung_member_array[0] = eyoung_cond_trans
            poisson_member_array[0] = poisson_cond_trans
            l_member_array[0] = t_cable_oh
            # Steel conduit
            eyoung_member_array[1] = eyoung_steel
            poisson_member_array[1] = poisson_steel
            l_member_array[1] = 2 * t_cond_oh
            # Insulation
            eyoung_member_array[2] = eyoung_ins
            poisson_member_array[2] = poisson_ins
            l_member_array[2] = 2 * dx_tf_turn_insulation
            # [EDIT: Add central cooling channel? Would be new member #1]

            # Compute the composited (smeared) properties
            (
                eyoung_axial[0],
                a_working,
                poisson_axial[0],
                eyoung_cs_stiffest_leg,
            ) = eyoung_t_nested_squares(
                3, eyoung_member_array, l_member_array, poisson_member_array
            )

        # resistive CS (copper)
        else:
            # Here is a rough approximation
            eyoung_trans[0] = eyoung_copper
            eyoung_axial[0] = eyoung_copper
            poisson_trans[0] = poisson_copper
            poisson_axial[0] = poisson_copper

    # ---

    # CS-TF interlayer properties
    # ---
    if i_tf_bucking == 3:
        # No current in this layer
        jeff[1] = 0.0e0

        # Outer radius of the CS
        if i_tf_inside_cs == 1:
            radtf[1] = dr_bore - dr_tf_inboard - dr_cs_tf_gap
        else:
            radtf[1] = dr_bore + dr_cs

        # Assumed to be Kapton for the moment
        # Ref : https://www.dupont.com/content/dam/dupont/products-and-services/membranes-and-films/polyimde-films/documents/DEC-Kapton-summary-of-properties.pdf
        eyoung_trans[1] = 2.5e9
        eyoung_axial[1] = 2.5e9
        poisson_trans[1] = 0.34e0  # Default value for young modulus
        poisson_axial[1] = 0.34e0  # Default value for young modulus

    # ---

    # bucking cylinder/casing properties
    # ---
    if i_tf_bucking >= 1:
        # No current in bucking cylinder/casing
        jeff[n_tf_bucking - 1] = 0.0e0

        if i_tf_sup == 1:
            eyoung_trans[n_tf_bucking - 1] = eyoung_steel
            eyoung_axial[n_tf_bucking - 1] = eyoung_steel
            poisson_trans[n_tf_bucking - 1] = poisson_steel
            poisson_axial[n_tf_bucking - 1] = poisson_steel

        # Bucking cylinder properties
        else:
            eyoung_trans[n_tf_bucking - 1] = eyoung_res_tf_buck
            eyoung_axial[n_tf_bucking - 1] = eyoung_res_tf_buck
            poisson_trans[n_tf_bucking - 1] = poisson_steel  # Seek better value #
            poisson_axial[n_tf_bucking - 1] = poisson_steel  # Seek better value #

        # Innernost TF casing radius
        radtf[n_tf_bucking - 1] = r_tf_inboard_in

    # ---

    # (Super)conductor layer properties
    # ---
    # SC coil
    if i_tf_sup == 1:
        # Inner/outer radii of the layer representing the WP in stress calculations [m]
        # These radii are chosen to preserve the true WP area; see Issue #1048
        r_wp_inner_eff = r_tf_wp_inboard_inner * np.sqrt(
            tan_theta_coil / rad_tf_coil_inboard_toroidal_half
        )
        r_wp_outer_eff = r_tf_wp_inboard_outer * np.sqrt(
            tan_theta_coil / rad_tf_coil_inboard_toroidal_half
        )

        # Area of the cylinder representing the WP in stress calculations [m2]
        a_wp_eff = (
            r_wp_outer_eff**2 - r_wp_inner_eff**2
        ) * rad_tf_coil_inboard_toroidal_half

        # Steel cross-section under the area representing the WP in stress calculations [m2]
        a_wp_steel_eff = (
            a_tf_coil_inboard_steel - a_tf_plasma_case - a_tf_coil_nose_case
        )

        # WP effective insulation thickness (SC only) [m]
        # include groundwall insulation + insertion gap in tfcoil_variables.dx_tf_turn_insulation
        # insertion gap is tfcoil_variables.dx_tf_wp_insertion_gap on 4 sides
        t_ins_eff = (
            dx_tf_turn_insulation
            + (dx_tf_wp_insertion_gap + dx_tf_wp_insulation) / n_tf_coil_turns
        )

        # Effective WP young modulus in the toroidal direction [Pa]
        # The toroidal property drives the stress calculation (J. Last report no 4)
        # Hence, the radial direction is relevant for the property smearing
        # Rem : This assumption might be re-defined for bucked and wedged design

        # Non-integer or interger number of turns
        t_cable_eyng = (
            dx_tf_turn_cable_space_average
            if i_tf_turns_integer == 0
            else dr_tf_turn_cable_space
        )

        # Average WP Young's modulus in the transverse
        # (radial and toroidal) direction
        # Split up into "members", concentric squares in cross section
        # (described in Figure 10 of the TF coil documentation)
        # Helium
        eyoung_member_array[0] = 0e0
        poisson_member_array[0] = poisson_steel
        l_member_array[0] = dia_tf_turn_coolant_channel
        # Conductor and co-wound copper
        (
            eyoung_member_array[1],
            l_member_array[1],
            poisson_member_array[1],
        ) = eyoung_series(
            np.double(eyoung_cond_trans),
            (t_cable_eyng - dia_tf_turn_coolant_channel)
            * (1.0e0 - f_a_tf_turn_cable_copper),
            np.double(poisson_cond_trans),
            np.double(eyoung_copper),
            (t_cable_eyng - dia_tf_turn_coolant_channel) * f_a_tf_turn_cable_copper,
            np.double(poisson_copper),
        )
        # Steel conduit
        eyoung_member_array[2] = eyoung_steel
        poisson_member_array[2] = poisson_steel
        l_member_array[2] = 2 * dx_tf_turn_steel
        # Insulation
        eyoung_member_array[3] = eyoung_ins
        poisson_member_array[3] = poisson_ins
        l_member_array[3] = 2 * t_ins_eff

        # Compute the composited (smeared) properties
        (
            eyoung_wp_trans,
            a_working,
            poisson_wp_trans,
            eyoung_wp_stiffest_leg,
        ) = eyoung_t_nested_squares(
            4,
            eyoung_member_array,
            l_member_array,
            poisson_member_array,
        )

        # Lateral casing correction (series-composition)
        (eyoung_wp_trans_eff, a_working, poisson_wp_trans_eff) = eyoung_series(
            eyoung_wp_trans,
            np.double(dx_tf_wp_toroidal_average),
            poisson_wp_trans,
            np.double(eyoung_steel),
            2.0e0 * dx_tf_side_case_average,
            np.double(poisson_steel),
        )

        poisson_wp_trans_eff = np.double(poisson_wp_trans_eff)

        # Average WP Young's modulus in the vertical direction
        # Split up into "members", concentric squares in cross section
        # (described in Figure 10 of the TF coil documentation)
        # Steel conduit
        eyoung_member_array[0] = eyoung_steel
        poisson_member_array[0] = poisson_steel
        l_member_array[0] = a_tf_wp_steel
        # Insulation
        eyoung_member_array[1] = eyoung_ins
        poisson_member_array[1] = poisson_ins
        l_member_array[1] = a_tf_coil_inboard_insulation
        # Copper
        eyoung_member_array[2] = eyoung_copper
        poisson_member_array[2] = poisson_copper
        l_member_array[2] = a_tf_wp_conductor * f_a_tf_turn_cable_copper
        # Conductor
        eyoung_member_array[3] = eyoung_cond_axial
        poisson_member_array[3] = poisson_cond_axial
        l_member_array[3] = a_tf_wp_conductor * (1.0e0 - f_a_tf_turn_cable_copper)
        # Helium and void
        eyoung_member_array[4] = 0e0
        poisson_member_array[4] = poisson_steel
        l_member_array[4] = (
            a_tf_wp_with_insulation
            - a_tf_wp_conductor
            - a_tf_coil_inboard_insulation
            - a_tf_wp_steel
        )
        # Compute the composite / smeared properties:
        (eyoung_wp_axial, a_working, poisson_wp_axial) = eyoung_parallel_array(
            5,
            eyoung_member_array,
            l_member_array,
            poisson_member_array,
        )

        # Average WP Young's modulus in the vertical direction, now including the lateral case
        # Parallel-composite the steel and insulation, now including the lateral case (sidewalls)
        (eyoung_wp_axial_eff, a_working, poisson_wp_axial_eff) = eyoung_parallel(
            eyoung_steel,
            a_wp_steel_eff - a_tf_wp_steel,
            poisson_steel,
            eyoung_wp_axial,
            a_working,
            poisson_wp_axial,
        )

    # Resistive coil
    else:
        # Picking the conductor material Young's modulus
        if i_tf_sup == 0:
            eyoung_cond = eyoung_copper
            poisson_cond = poisson_copper
        elif i_tf_sup == 2:
            eyoung_cond = eyoung_al
            poisson_cond = poisson_al

        # Effective WP young modulus in the toroidal direction [Pa]
        # Rem : effect of cooling pipes and insulation not taken into account
        #       for now as it needs a radially dependent Young modulus
        eyoung_wp_trans_eff = eyoung_cond
        eyoung_wp_trans = np.double(eyoung_cond)
        poisson_wp_trans_eff = np.double(poisson_cond)
        poisson_wp_trans = np.double(poisson_cond)

        # WP area using the stress model circular geometry (per coil) [m2]
        a_wp_eff = (
            r_tf_wp_inboard_outer**2 - r_tf_wp_inboard_inner**2
        ) * rad_tf_coil_inboard_toroidal_half

        # Effective conductor region young modulus in the vertical direction [Pa]
        # Parallel-composite conductor and insulator
        (eyoung_wp_axial, a_working, poisson_wp_axial) = eyoung_parallel(
            eyoung_cond,
            (a_wp_eff - a_tf_coil_inboard_insulation) * (1.0e0 - fcoolcp),
            poisson_cond,
            eyoung_ins,
            a_tf_coil_inboard_insulation,
            poisson_ins,
        )
        # Parallel-composite cooling pipes into that
        (eyoung_wp_axial, a_working, poisson_wp_axial) = eyoung_parallel(
            0e0,
            (a_wp_eff - a_tf_coil_inboard_insulation) * fcoolcp,
            poisson_cond,
            eyoung_wp_axial,
            a_working,
            poisson_wp_axial,
        )

        # Effective young modulus used in stress calculations
        eyoung_wp_axial_eff = eyoung_wp_axial
        poisson_wp_axial_eff = poisson_wp_axial

        # Effect conductor layer inner/outer radius
        r_wp_inner_eff = np.double(r_tf_wp_inboard_inner)
        r_wp_outer_eff = np.double(r_tf_wp_inboard_outer)

    # Thickness of the layer representing the WP in stress calcualtions [m]
    dr_tf_wp_eff = r_wp_outer_eff - r_wp_outer_eff

    # Thickness of WP with homogeneous stress property [m]
    dr_wp_layer = dr_tf_wp_eff / n_tf_graded_layers

    for ii in range(np.intc(n_tf_graded_layers)):
        # Homogeneous current in (super)conductor
        jeff[n_tf_bucking + ii] = c_tf_total / (
            np.pi * (r_wp_outer_eff**2 - r_wp_inner_eff**2)
        )

        # Same thickness for all WP layers in stress calculation
        radtf[n_tf_bucking + ii] = r_wp_inner_eff + ii * dr_wp_layer

        # Young modulus
        eyoung_trans[n_tf_bucking + ii] = eyoung_wp_trans_eff
        eyoung_axial[n_tf_bucking + ii] = eyoung_wp_axial_eff

        # Poisson's ratio
        poisson_trans[n_tf_bucking + ii] = poisson_wp_trans_eff
        poisson_axial[n_tf_bucking + ii] = poisson_wp_axial_eff

    # Steel case on the plasma side of the inboard TF coil
    # As per Issue #1509
    jeff[n_tf_layer - 1] = 0.0e0
    radtf[n_tf_layer - 1] = r_wp_outer_eff
    eyoung_trans[n_tf_layer - 1] = eyoung_steel
    eyoung_axial[n_tf_layer - 1] = eyoung_steel
    poisson_trans[n_tf_layer - 1] = poisson_steel
    poisson_axial[n_tf_layer - 1] = poisson_steel

    # last layer radius
    radtf[n_tf_layer] = r_wp_outer_eff + dr_tf_plasma_case

    # The ratio between the true cross sectional area of the
    # front case, and that considered by the plane strain solver
    f_tf_stress_front_case = (
        a_tf_plasma_case
        / rad_tf_coil_inboard_toroidal_half
        / (radtf[n_tf_layer] ** 2 - radtf[n_tf_layer - 1] ** 2)
    )

    # Correct for the missing axial stiffness from the missing
    # outer case steel as per the updated description of
    # Issue #1509
    eyoung_axial[n_tf_layer - 1] = (
        eyoung_axial[n_tf_layer - 1] * f_tf_stress_front_case
    )

    # ---
    # ------------------------

    # RADIAL STRESS SUBROUTINES CALL
    # ------------------------------
    # Stress model not valid the TF does not contain any hole
    # (Except if i_tf_plane_stress == 2; see Issue 1414)
    # Current action : trigger and error and add a little hole
    #                  to allow stress calculations
    # Rem SK : Can be easily ameneded playing around the boundary conditions
    # New extended plane strain model can handle it
    if abs(radtf[0]) < np.finfo(float(radtf[0])).eps and i_tf_stress_model != 2:
        radtf[0] = 1.0e-9
    # ---

    # Old generalized plane stress model
    # ---
    if i_tf_stress_model == 1:
        # Plane stress calculation (SC) [Pa]

        (sig_tf_r, sig_tf_t, deflect, radial_array) = plane_stress(
            nu=poisson_trans,
            rad=radtf,
            ey=eyoung_trans,
            j=jeff,
            nlayers=int(n_tf_layer),
            n_radial_array=int(n_radial_array),
        )

        # Vertical stress [Pa]
        sig_tf_z[:] = vforce / (
            a_tf_coil_inboard_case + a_tf_turn_steel * n_tf_coil_turns
        )  # Array equation [EDIT: Are you sure? It doesn't look like one to me]

        # Strain in vertical direction on WP
        str_wp = sig_tf_z[n_tf_bucking] / eyoung_wp_axial_eff

        # Case strain
        casestr = sig_tf_z[n_tf_bucking - 1] / eyoung_steel

        # Radial strain in insulator
        insstrain = (
            sig_tf_r[n_radial_array - 1]
            * eyoung_wp_stiffest_leg
            / eyoung_wp_trans_eff
            / eyoung_ins
        )
    # ---

    # New generalized plane strain formulation
    # ---
    # See #1670 for why i_tf_stress_model=0 was removed
    elif i_tf_stress_model in (0, 2):
        # Extended plane strain calculation [Pa]
        # Issues #1414 and #998
        # Permits build_variables.dr_bore >= 0, O(n) in layers
        # If build_variables.dr_bore > 0, same result as generalized plane strain calculation

        (
            radial_array,
            sig_tf_r,
            sig_tf_t,
            sig_tf_z,
            str_tf_r,
            str_tf_t,
            str_tf_z,
            deflect,
        ) = extended_plane_strain(
            poisson_trans,
            poisson_axial,
            eyoung_trans,
            eyoung_axial,
            radtf,
            jeff,
            vforce_inboard_tot,
            int(n_tf_layer),
            int(n_radial_array),
            int(n_tf_bucking),
        )

        # Strain in TF conductor material
        str_wp = str_tf_z[n_tf_bucking * n_radial_array]

    # ---

    # Storing the smeared properties for output

    sig_tf_smeared_r[:] = sig_tf_r  # Array equation
    sig_tf_smeared_t[:] = sig_tf_t  # Array equation
    sig_tf_smeared_z[:] = sig_tf_z  # Array equation

    # ------------------------------

    # STRESS DISTRIBUTIONS CORRECTIONS
    # --------------------------------
    # SC central solenoid coil stress unsmearing (bucked and wedged only)
    # ---
    if i_tf_bucking >= 2 and i_pf_conductor == 0:
        # Central Solenoid (OH) steel conduit stress unsmearing factors
        for ii in range(n_radial_array):
            sig_tf_r[ii] = sig_tf_r[ii] * eyoung_cs_stiffest_leg / eyoung_axial[0]
            sig_tf_t[ii] = sig_tf_t[ii] * eyoung_steel / eyoung_trans[0]
            sig_tf_z[ii] = sig_tf_z[ii] * eyoung_cs_stiffest_leg / eyoung_axial[0]

    # ---

    # No TF vertical forces on CS and CS-TF layer (bucked and wedged only)
    # ---
    # This correction is only applied if the plane stress model is used
    # as the generalized plane strain calculates the vertical stress properly
    if i_tf_bucking >= 2 and i_tf_stress_model == 1:
        for ii in range((n_tf_bucking - 1) * n_radial_array):
            sig_tf_z[ii] = 0.0e0

    # ---

    # Toroidal coil unsmearing
    # ---
    # Copper magnets
    if i_tf_sup == 0:
        # Vertical force unsmearing factor
        fac_sig_z = eyoung_copper / eyoung_wp_axial_eff

        # Toroidal WP steel stress unsmearing factor
        fac_sig_t = 1.0e0
        fac_sig_r = 1.0e0

    elif i_tf_sup == 1:
        # Vertical WP steel stress unsmearing factor
        if i_tf_stress_model != 1:
            fac_sig_z = eyoung_steel / eyoung_wp_axial_eff
            fac_sig_z_wp_av = eyoung_wp_axial / eyoung_wp_axial_eff
        else:
            fac_sig_z = 1.0e0

        # Toroidal WP steel conduit stress unsmearing factor
        fac_sig_t = eyoung_wp_stiffest_leg / eyoung_wp_trans_eff

        # Radial WP steel conduit stress unsmearing factor
        fac_sig_r = eyoung_wp_stiffest_leg / eyoung_wp_trans_eff

    elif i_tf_sup == 2:
        # Vertical WP steel stress unsmearing factor
        fac_sig_z = eyoung_al / eyoung_wp_axial_eff

        # Toroidal WP steel stress unsmearing factor
        # NO CALCULTED FOR THE MOMENT (to be done later)
        fac_sig_t = 1.0e0
        fac_sig_r = 1.0e0

    # Application of the unsmearing to the WP layers
    # For each point within the winding pack / conductor, unsmear the
    # stress. This is n_radial_array test points within tfcoil_variables.n_tf_graded_layers
    # layers starting at n_tf_bucking + 1
    # GRADED MODIF : add another do loop to allow the graded properties
    #                to be taken into account
    for ii in range(
        n_tf_bucking * n_radial_array,
        ((n_tf_bucking + n_tf_graded_layers) * n_radial_array),
    ):
        sig_tf_wp_av_z[ii - n_tf_bucking * n_radial_array] = (
            sig_tf_z[ii] * fac_sig_z_wp_av
        )
        sig_tf_r[ii] = sig_tf_r[ii] * fac_sig_r
        sig_tf_t[ii] = sig_tf_t[ii] * fac_sig_t
        sig_tf_z[ii] = sig_tf_z[ii] * fac_sig_z

    # For each point within the front case,
    # remove the correction for the missing axial
    # stiffness as per the updated description of
    # Issue #1509
    for ii in range(
        (n_tf_bucking + n_tf_graded_layers) * n_radial_array,
        (n_tf_layer * n_radial_array),
    ):
        sig_tf_z[ii] = sig_tf_z[ii] / f_tf_stress_front_case
    # ---

    # Tresca / Von Mises yield criteria calculations
    # -----------------------------
    # Array equation
    s_shear_tf = np.maximum(
        np.absolute(sig_tf_r - sig_tf_z), np.absolute(sig_tf_z - sig_tf_t)
    )

    # Array equation

    sig_tf_vmises = np.sqrt(
        0.5e0
        * (
            (sig_tf_r - sig_tf_t) ** 2
            + (sig_tf_r - sig_tf_z) ** 2
            + (sig_tf_z - sig_tf_t) ** 2
        )
    )

    # Array equation
    s_shear_cea_tf_cond = s_shear_tf.copy()

    # SC conducting layer stress distribution corrections
    # ---
    if i_tf_sup == 1:
        # GRADED MODIF : add another do loop to allow the graded properties
        #                to be taken into account
        for ii in range(
            (n_tf_bucking * n_radial_array), n_tf_layer * n_radial_array
        ):
            # Addaped Von-mises stress calculation to WP strucure [Pa]

            svmxz = sigvm(0.0e0, sig_tf_t[ii], sig_tf_z[ii], 0.0e0, 0.0e0, 0.0e0)

            svmyz = sigvm(sig_tf_r[ii], 0.0e0, sig_tf_z[ii], 0.0e0, 0.0e0, 0.0e0)
            sig_tf_vmises[ii] = max(svmxz, svmyz)

            # Maximum shear stress for the Tresca yield criterion using CEA calculation [Pa]
            s_shear_cea_tf_cond[ii] = (
                1.02e0 * abs(sig_tf_r[ii]) + 1.6e0 * sig_tf_z[ii]
            )

    # ---
    # -----------------------------

    # Output formating : Maximum shear stress of each layer for the Tresca yield criterion
    # ----------------
    for ii in range(n_tf_layer):
        sig_max = 0.0e0
        ii_max = 0

        for jj in range(ii * n_radial_array, (ii + 1) * n_radial_array):
            # CEA out of plane approximation
            if i_tf_tresca == 1 and i_tf_sup == 1 and ii >= i_tf_bucking + 1:
                if sig_max < s_shear_cea_tf_cond[jj]:
                    sig_max = s_shear_cea_tf_cond[jj]
                    ii_max = jj

            # Conventional Tresca
            else:
                if sig_max < s_shear_tf[jj]:
                    sig_max = s_shear_tf[jj]
                    ii_max = jj

        # OUT.DAT output

        sig_tf_r_max[ii] = sig_tf_r[ii_max]
        sig_tf_t_max[ii] = sig_tf_t[ii_max]
        sig_tf_z_max[ii] = sig_tf_z[ii_max]
        sig_tf_vmises_max[ii] = sig_tf_vmises[ii_max]

        # Maximum shear stress for the Tresca yield criterion (or CEA OOP correction)

        if i_tf_tresca == 1 and i_tf_sup == 1 and ii >= i_tf_bucking + 1:
            s_shear_tf_peak[ii] = s_shear_cea_tf_cond[ii_max]
        else:
            s_shear_tf_peak[ii] = s_shear_tf[ii_max]

    # Constraint equation for the Tresca yield criterion

    sig_tf_wp = s_shear_tf_peak[n_tf_bucking]
    # Maximum assumed in the first graded layer

    if i_tf_bucking >= 1:
        sig_tf_case = s_shear_tf_peak[n_tf_bucking - 1]
    if i_tf_bucking >= 2:
        sig_tf_cs_bucked = s_shear_tf_peak[0]
    # ----------------

    return (
        sig_tf_r_max,
        sig_tf_t_max,
        sig_tf_z_max,
        sig_tf_vmises_max,
        s_shear_tf_peak,
        deflect,
        eyoung_axial,
        eyoung_trans,
        eyoung_wp_axial,
        eyoung_wp_trans,
        poisson_wp_trans,
        radial_array,
        s_shear_cea_tf_cond,
        poisson_wp_axial,
        sig_tf_r,
        sig_tf_smeared_r,
        sig_tf_smeared_t,
        sig_tf_smeared_z,
        sig_tf_t,
        s_shear_tf,
        sig_tf_vmises,
        sig_tf_z,
        str_tf_r,
        str_tf_t,
        str_tf_z,
        n_radial_array,
        n_tf_bucking,
        sig_tf_wp,
        sig_tf_case,
        sig_tf_cs_bucked,
        str_wp,
        casestr,
        insstrain,
        sig_tf_wp_av_z,
    )

out_stress(sig_tf_r_max, sig_tf_t_max, sig_tf_z_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, eyoung_axial, eyoung_trans, eyoung_wp_axial, eyoung_wp_trans, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, sig_tf_r, sig_tf_smeared_r, sig_tf_smeared_t, sig_tf_smeared_z, sig_tf_t, s_shear_tf, sig_tf_vmises, sig_tf_z, str_tf_r, str_tf_t, str_tf_z, n_radial_array, n_tf_bucking, sig_tf_wp_av_z)

Subroutine showing the writing the TF midplane stress analysis in the output file and the stress distribution in the SIG_TF.json file used to plot stress distributions

Parameters:

Name Type Description Default
sig_tf_r_max
required
sig_tf_t_max
required
sig_tf_z_max
required
sig_tf_vmises_max
required
s_shear_tf_peak
required
deflect
required
eyoung_axial
required
eyoung_trans
required
eyoung_wp_axial
required
eyoung_wp_trans
required
poisson_wp_trans
required
radial_array
required
s_shear_cea_tf_cond
required
poisson_wp_axial
required
sig_tf_r
required
sig_tf_smeared_r
required
sig_tf_smeared_t
required
sig_tf_smeared_z
required
sig_tf_t
required
s_shear_tf
required
sig_tf_vmises
required
sig_tf_z
required
str_tf_r
required
str_tf_t
required
str_tf_z
required
n_radial_array
required
n_tf_bucking
required
sig_tf_wp_av_z
required
Source code in process/models/tfcoil/base.py
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
def out_stress(
    self,
    sig_tf_r_max,
    sig_tf_t_max,
    sig_tf_z_max,
    sig_tf_vmises_max,
    s_shear_tf_peak,
    deflect,
    eyoung_axial,
    eyoung_trans,
    eyoung_wp_axial,
    eyoung_wp_trans,
    poisson_wp_trans,
    radial_array,
    s_shear_cea_tf_cond,
    poisson_wp_axial,
    sig_tf_r,
    sig_tf_smeared_r,
    sig_tf_smeared_t,
    sig_tf_smeared_z,
    sig_tf_t,
    s_shear_tf,
    sig_tf_vmises,
    sig_tf_z,
    str_tf_r,
    str_tf_t,
    str_tf_z,
    n_radial_array,
    n_tf_bucking,
    sig_tf_wp_av_z,
):
    """Subroutine showing the writing the TF midplane stress analysis
    in the output file and the stress distribution in the SIG_TF.json
    file used to plot stress distributions

    Parameters
    ----------
    sig_tf_r_max :

    sig_tf_t_max :

    sig_tf_z_max :

    sig_tf_vmises_max :

    s_shear_tf_peak :

    deflect :

    eyoung_axial :

    eyoung_trans :

    eyoung_wp_axial :

    eyoung_wp_trans :

    poisson_wp_trans :

    radial_array :

    s_shear_cea_tf_cond :

    poisson_wp_axial :

    sig_tf_r :

    sig_tf_smeared_r :

    sig_tf_smeared_t :

    sig_tf_smeared_z :

    sig_tf_t :

    s_shear_tf :

    sig_tf_vmises :

    sig_tf_z :

    str_tf_r :

    str_tf_t :

    str_tf_z :

    n_radial_array :

    n_tf_bucking :

    sig_tf_wp_av_z :

    """

    def table_format_arrays(a, mult=1, delim="\t\t"):
        return delim.join([str(i * mult) for i in a])

    # Stress output section
    po.oheadr(self.outfile, "TF coils ")
    po.osubhd(self.outfile, "TF Coil Stresses (CCFE model) :")

    if tfcoil_variables.i_tf_stress_model == 1:
        po.ocmmnt(self.outfile, "Plane stress model with smeared properties")
    else:
        po.ocmmnt(self.outfile, "Generalized plane strain model")

    po.ovarre(
        self.outfile,
        "Allowable maximum shear stress in TF coil case (Tresca criterion) (Pa)",
        "(sig_tf_case_max)",
        tfcoil_variables.sig_tf_case_max,
    )

    po.ovarre(
        self.outfile,
        "Allowable maximum shear stress in TF coil conduit (Tresca criterion) (Pa)",
        "(sig_tf_wp_max)",
        tfcoil_variables.sig_tf_wp_max,
    )
    if tfcoil_variables.i_tf_tresca == 1 and tfcoil_variables.i_tf_sup == 1:
        po.ocmmnt(
            self.outfile,
            "WP conduit Tresca criterion corrected using CEA formula (i_tf_tresca = 1)",
        )

    if tfcoil_variables.i_tf_bucking >= 3:
        po.ocmmnt(
            self.outfile, "No stress limit imposed on the TF-CS interface layer"
        )
        po.ocmmnt(
            self.outfile, "  -> Too much unknow on it material choice/properties"
        )

    # OUT.DAT data on maximum shear stress values for the Tresca criterion
    po.ocmmnt(
        self.outfile,
        "Materal stress of the point of maximum shear stress (Tresca criterion) for each layer",
    )
    po.ocmmnt(
        self.outfile,
        "Please use utilities/plot_stress_tf.py for radial plots plots summary",
    )

    if tfcoil_variables.i_tf_bucking == 0:
        if tfcoil_variables.i_tf_sup == 1:
            po.write(self.outfile, "  Layers \t\t\t\t WP \t\t Outer case")
        else:
            po.write(self.outfile, "  Layers \t\t\t\t conductor \t\t Outer case")

    elif tfcoil_variables.i_tf_bucking == 1:
        if tfcoil_variables.i_tf_sup == 1:
            po.write(
                self.outfile, "  Layers \t\t\t\t Steel case \t\t WP \t\t Outer case"
            )
        else:
            po.write(
                self.outfile,
                "  Layers \t\t\t\t bucking \t\t conductor \t\t Outer case",
            )

    elif tfcoil_variables.i_tf_bucking == 2:
        if tfcoil_variables.i_tf_sup == 1:
            po.write(
                self.outfile,
                "  Layers \t\t\t\t CS \t\t Steel case \t\t WP \t\t Outer case",
            )
        else:
            po.write(
                self.outfile,
                "  Layers \t\t\t\t CS \t\t bucking \t\t conductor \t\t Outer case",
            )

    elif tfcoil_variables.i_tf_bucking == 3:
        if tfcoil_variables.i_tf_sup == 1:
            po.write(
                self.outfile,
                "  Layers \t\t\t\t CS \t\t interface \t\t Steel case \t\t WP \t\t Outer case",
            )
        else:
            po.write(
                self.outfile,
                "  Layers \t\t\t\t CS \t\t interface \t\t bucking \t\t conductor \t\t Outer case",
            )

    po.write(
        self.outfile,
        f"  Radial stress \t\t\t (MPa) \t\t {table_format_arrays(sig_tf_r_max, 1e-6)}",
    )
    po.write(
        self.outfile,
        f"  Toroidal stress \t\t\t (MPa) \t\t {table_format_arrays(sig_tf_t_max, 1e-6)}",
    )
    po.write(
        self.outfile,
        f"  Vertical stress \t\t\t (MPa) \t\t {table_format_arrays(sig_tf_z_max, 1e-6)}",
    )
    po.write(
        self.outfile,
        f"  Von-Mises stress \t\t\t (MPa) \t\t {table_format_arrays(sig_tf_vmises_max, 1e-6)}",
    )

    if tfcoil_variables.i_tf_tresca == 1 and tfcoil_variables.i_tf_sup == 1:
        po.write(
            self.outfile,
            f"  Shear (CEA Tresca) \t\t\t (MPa) \t\t {table_format_arrays(s_shear_tf_peak, 1e-6)}",
        )
    else:
        po.write(
            self.outfile,
            f"  Shear (Tresca) \t\t\t (MPa) \t\t {table_format_arrays(s_shear_tf_peak, 1e-6)}",
        )

    po.write(self.outfile, "")
    po.write(
        self.outfile,
        f"  Toroidal modulus \t\t\t (GPa) \t\t {table_format_arrays(eyoung_trans, 1e-9)}",
    )
    po.write(
        self.outfile,
        f"  Vertical modulus \t\t\t (GPa) \t\t {table_format_arrays(eyoung_axial, 1e-9)}",
    )
    po.write(self.outfile, "")
    po.ovarre(
        self.outfile,
        "WP transverse modulus (GPa)",
        "(eyoung_wp_trans*1.0d-9)",
        eyoung_wp_trans * 1.0e-9,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "WP vertical modulus (GPa)",
        "(eyoung_wp_axial*1.0d-9)",
        eyoung_wp_axial * 1.0e-9,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "WP transverse Poissons ratio",
        "(poisson_wp_trans)",
        poisson_wp_trans,
        "OP ",
    )
    po.ovarre(
        self.outfile,
        "WP vertical-transverse Pois. rat.",
        "(poisson_wp_axial)",
        poisson_wp_axial,
        "OP ",
    )

    # MFILE.DAT data
    for ii in range(n_tf_bucking + 2):
        po.ovarre(
            constants.MFILE,
            f"Radial    stress at maximum shear of layer {ii + 1} (Pa)",
            f"(sig_tf_r_max({ii + 1}))",
            sig_tf_r_max[ii],
        )
        po.ovarre(
            constants.MFILE,
            f"toroidal  stress at maximum shear of layer {ii + 1} (Pa)",
            f"(sig_tf_t_max({ii + 1}))",
            sig_tf_t_max[ii],
        )
        po.ovarre(
            constants.MFILE,
            f"Vertical  stress at maximum shear of layer {ii + 1} (Pa)",
            f"(sig_tf_z_max({ii + 1}))",
            sig_tf_z_max[ii],
        )
        po.ovarre(
            constants.MFILE,
            f"Von-Mises stress at maximum shear of layer {ii + 1} (Pa)",
            f"(sig_tf_vmises_max({ii + 1}))",
            sig_tf_vmises_max[ii],
        )
        if tfcoil_variables.i_tf_tresca == 1 and tfcoil_variables.i_tf_sup == 1:
            po.ovarre(
                constants.MFILE,
                f"Maximum shear stress for CEA Tresca yield criterion {ii + 1} (Pa)",
                f"(s_shear_tf_peak({ii + 1}))",
                s_shear_tf_peak[ii],
            )
        else:
            po.ovarre(
                constants.MFILE,
                f"Maximum shear stress for the Tresca yield criterion {ii + 1} (Pa)",
                f"(s_shear_tf_peak({ii + 1}))",
                s_shear_tf_peak[ii],
            )

    # SIG_TF.json storage
    sig_file_data = {
        "Points per layers": n_radial_array,
        "Radius (m)": radial_array,
        "Radial stress (MPa)": sig_tf_r * 1e-6,
        "Toroidal stress (MPa)": sig_tf_t * 1e-6,
        "Vertical stress (MPa)": sig_tf_z * 1e-6,
        "Radial smear stress (MPa)": sig_tf_smeared_r * 1e-6,
        "Toroidal smear stress (MPa)": sig_tf_smeared_t * 1e-6,
        "Vertical smear stress (MPa)": sig_tf_smeared_z * 1e-6,
        "Von-Mises stress (MPa)": sig_tf_vmises * 1e-6,
        "CEA Tresca stress (MPa)": (
            s_shear_cea_tf_cond * 1e-6
            if tfcoil_variables.i_tf_sup == 1
            else s_shear_tf * 1e-6
        ),
        "rad. displacement (mm)": deflect * 1e3,
    }
    if tfcoil_variables.i_tf_stress_model != 1:
        sig_file_data = {
            **sig_file_data,
            "Radial strain": str_tf_r,
            "Toroidal strain": str_tf_t,
            "Vertical strain": str_tf_z,
        }

    if tfcoil_variables.i_tf_sup == 1:
        sig_file_data = {
            **sig_file_data,
            "WP smeared stress (MPa)": sig_tf_wp_av_z * 1.0e-6,
        }

    sig_file_data = {
        k: list(v) if isinstance(v, np.ndarray) else v
        for k, v in sig_file_data.items()
    }

    sig_filename = global_variables.output_prefix + "SIG_TF.json"
    with open(sig_filename, "w") as f:
        json.dump(sig_file_data, f)

    # TODO sig_tf_wp_av_z is always undefined here. This needs correcting or removing
    # if ( tfcoil_variables.i_tf_sup == 1 ) :
    # write(constants.sig_file,'(t2, "WP"    ," smeared stress", t20, "(MPa)",t26, *(F11.3,3x))') sig_tf_wp_av_z*1.0e-6
    #

    # Quantities from the plane stress stress formulation (no resitive coil output)
    if tfcoil_variables.i_tf_stress_model == 1 and tfcoil_variables.i_tf_sup == 1:
        # Other quantities (displacement strain, etc..)
        po.ovarre(
            self.outfile,
            "Maximum radial deflection at midplane (m)",
            "(deflect)",
            deflect[n_radial_array - 1],
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Vertical strain on casing",
            "(casestr)",
            tfcoil_variables.casestr,
            "OP ",
        )
        po.ovarre(
            self.outfile,
            "Radial strain on insulator",
            "(insstrain)",
            tfcoil_variables.insstrain,
            "OP ",
        )

eyoung_parallel(eyoung_j_1, a_1, poisson_j_perp_1, eyoung_j_2, a_2, poisson_j_perp_2)

See Issue #1205 for derivation PDF This subroutine gives the smeared elastic properties of two members that are carrying a force in parallel with each other. The force goes in direction j. Members 1 and 2 are the individual members to be smeared. Member 3 is the effective smeared member (output). This is pretty easy because the smeared properties are simply the average weighted by the cross-sectional areas perpendicular to j. The assumption is that the strains in j are equal. If you're dealing with anisotropy, please pay attention to the fact that the specific Young's Modulus used here is that in the j direction, and the specific Poisson's ratio used here is that between the j and transverse directions in that order. (transverse strain / j strain, under j stress) The smeared Poisson's ratio is computed assuming the transverse dynamics are isotropic, and that the two members are free to shrink/expand under Poisson effects without interference from each other. This may not be true of your case.

To build up a composite smeared member of any number of individual members, you can pass the same properties for members 2 and 3, and call it successively, using the properties of each member as the first triplet of arguments. This way, the last triplet acts as a "working sum": call eyoung_parallel(triplet1, triplet2, tripletOUT) call eyoung_parallel(triplet3, tripletOUT, tripletOUT) call eyoung_parallel(triplet4, tripletOUT, tripletOUT) ... etc. So that tripletOUT would eventually have the smeared properties of the total composite member.

Parameters:

Name Type Description Default
eyoung_j_1
required
a_1
required
poisson_j_perp_1
required
eyoung_j_2
required
a_2
required
poisson_j_perp_2
required
Source code in process/models/tfcoil/base.py
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
@numba.njit(cache=True)
def eyoung_parallel(
    eyoung_j_1, a_1, poisson_j_perp_1, eyoung_j_2, a_2, poisson_j_perp_2
):
    """
    See Issue #1205 for derivation PDF
    This subroutine gives the smeared elastic properties of two
    members that are carrying a force in parallel with each other.
    The force goes in direction j.
    Members 1 and 2 are the individual members to be smeared.
    Member 3 is the effective smeared member (output).
    This is pretty easy because the smeared properties are simply
    the average weighted by the cross-sectional areas perpendicular
    to j.
    The assumption is that the strains in j are equal.
    If you're dealing with anisotropy, please pay attention to the
    fact that the specific Young's Modulus used here is that in
    the j direction, and the specific Poisson's ratio used here is
    that between the j and transverse directions in that order.
    (transverse strain / j strain, under j stress)
    The smeared Poisson's ratio is computed assuming the transverse
    dynamics are isotropic, and that the two members are free to
    shrink/expand under Poisson effects without interference from
    each other. This may not be true of your case.

    To build up a composite smeared member of any number of
    individual members, you can pass the same properties for
    members 2 and 3, and call it successively, using the properties
    of each member as the first triplet of arguments. This way, the
    last triplet acts as a "working sum":
    call eyoung_parallel(triplet1, triplet2, tripletOUT)
    call eyoung_parallel(triplet3, tripletOUT, tripletOUT)
    call eyoung_parallel(triplet4, tripletOUT, tripletOUT)
    ... etc.
    So that tripletOUT would eventually have the smeared properties
    of the total composite member.

    Parameters
    ----------
    eyoung_j_1 :

    a_1 :

    poisson_j_perp_1 :

    eyoung_j_2 :

    a_2 :

    poisson_j_perp_2 :

    """
    poisson_j_perp_3 = (poisson_j_perp_1 * a_1 + poisson_j_perp_2 * a_2) / (a_1 + a_2)
    eyoung_j_3 = (eyoung_j_1 * a_1 + eyoung_j_2 * a_2) / (a_1 + a_2)
    a_3 = a_1 + a_2

    return eyoung_j_3, a_3, poisson_j_perp_3

sigvm(sx, sy, sz, txy, txz, tyz)

Calculates Von Mises stress in a TF coil

This routine calculates the Von Mises combination of stresses (Pa) in a TF coil.

Parameters:

Name Type Description Default
sx float

In-plane stress in X direction [Pa]

required
sy float

In-plane stress in Y direction [Pa]

required
sz float

In-plane stress in Z direction [Pa]

required
txy float

Out-of-plane stress in X-Y plane [Pa]

required
txz float

Out-of-plane stress in X-Z plane [Pa]

required
tyz float

Out-of-plane stress in Y-Z plane [Pa]

required

Returns:

Type Description
float

Von Mises combination of stresses (Pa) in a TF coil.

Source code in process/models/tfcoil/base.py
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
@numba.njit(cache=True)
def sigvm(sx: float, sy: float, sz: float, txy: float, txz: float, tyz: float) -> float:
    """Calculates Von Mises stress in a TF coil

    This routine calculates the Von Mises combination of
    stresses (Pa) in a TF coil.

    Parameters
    ----------
    sx :
        In-plane stress in X direction [Pa]
    sy :
        In-plane stress in Y direction [Pa]
    sz :
        In-plane stress in Z direction [Pa]
    txy :
        Out-of-plane stress in X-Y plane [Pa]
    txz :
        Out-of-plane stress in X-Z plane [Pa]
    tyz :
        Out-of-plane stress in Y-Z plane [Pa]

    Returns
    -------
    :
        Von Mises combination of stresses (Pa) in a TF coil.
    """

    return np.sqrt(
        0.5
        * (
            (sx - sy) ** 2
            + (sx - sz) ** 2
            + (sz - sy) ** 2
            + 6 * (txy**2 + txz**2 + tyz**2)
        )
    )

extended_plane_strain(nu_t, nu_zt, ey_t, ey_z, rad, d_curr, v_force, nlayers, n_radial_array, i_tf_bucking)

There is a writeup of the derivation of this model on the gitlab server. https://git.ccfe.ac.uk/process/process/-/issues/1414 This surboutine estimates the radial displacement, stresses, and strains of the inboard midplane of the TF. It assumes that structures are axisymmetric and long in the axial (z) direction, the "axisymmetric extended plane strain" problem. The TF is assumed to be constructed from some number of layers, within which materials properties and current densities are uniform. The 1D radially-resolved solution is reduced to a 0D matrix inversion problem using analytic solutions to Lame's thick cylinder problem. Materials may be transverse-isotropic in Young's modulus and Poisson's ratio. The consraints are: Either zero radial stress or zero radial displacement at the inner surface (depending on whether the inner radius is zero), zero radial stress at the outer surface, total axial force (tension) is equal to the input, and optionally the axial force of an inner subset of cylinders is zero (slip conditions between the inner and outer subset). The matrix inversion / linear solve is always 4x4, no matter how many layers there are. The problem is formulated around a solution vector (A,B,eps_z,1.0,eps_z_slip) where A and B are the parameters in Lame's solution where u = A*r + B/r, u is the radial displacement. eps_z is the axial strain on the outer, force- carrying layers. eps_z_slip is the axial strain on the inner, non-force- carrying layers (optionally). The solution vector is A,B at the outermost radius, and is transformed via matrix multiplication into those A,B values at other radii. The constraints are inner products with this vector, and so when stacked form a matrix to invert.

Parameters:

Name Type Description Default
nu_t
required
nu_zt
required
ey_t
required
ey_z
required
rad
required
d_curr
required
v_force
required
nlayers
required
n_radial_array
required
i_tf_bucking
required
Source code in process/models/tfcoil/base.py
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
@numba.njit(cache=True, error_model="numpy")
def extended_plane_strain(
    nu_t,
    nu_zt,
    ey_t,
    ey_z,
    rad,
    d_curr,
    v_force,
    nlayers,
    n_radial_array,
    i_tf_bucking,
):
    """
    There is a writeup of the derivation of this model on the gitlab server.
    https://git.ccfe.ac.uk/process/process/-/issues/1414
    This surboutine estimates the radial displacement, stresses, and strains of
    the inboard midplane of the TF. It assumes that structures are axisymmetric
    and long in the axial (z) direction, the "axisymmetric extended plane strain"
    problem. The TF is assumed to be constructed from some number of layers,
    within which materials properties and current densities are uniform.
    The 1D radially-resolved solution is reduced to a 0D matrix inversion problem
    using analytic solutions to Lame's thick cylinder problem. Materials may be
    transverse-isotropic in Young's modulus and Poisson's ratio. The consraints
    are: Either zero radial stress or zero radial displacement at the inner
    surface (depending on whether the inner radius is zero), zero radial stress
    at the outer surface, total axial force (tension) is equal to the input,
    and optionally the axial force of an inner subset of cylinders is zero (slip
    conditions between the inner and outer subset). The matrix inversion / linear
    solve is always 4x4, no matter how many layers there are.
    The problem is formulated around a solution vector (A,B,eps_z,1.0,eps_z_slip)
    where A and B are the parameters in Lame's solution where u = A*r + B/r, u
    is the radial displacement. eps_z is the axial strain on the outer, force-
    carrying layers. eps_z_slip is the axial strain on the inner, non-force-
    carrying layers (optionally). The solution vector is A,B at the outermost
    radius, and is transformed via matrix multiplication into those A,B
    values at other radii. The constraints are inner products with this vector,
    and so when stacked form a matrix to invert.

    Parameters
    ----------
    nu_t :

    nu_zt :

    ey_t :

    ey_z :

    rad :

    d_curr :

    v_force :

    nlayers :

    n_radial_array :

    i_tf_bucking :

    """
    # outputs
    sigr = np.zeros((n_radial_array * nlayers,))
    # Stress distribution in the radial direction (r) [Pa]

    sigt = np.zeros((n_radial_array * nlayers,))
    # Stress distribution in the toroidal direction (t) [Pa]

    sigz = np.zeros((n_radial_array * nlayers,))
    # Stress distribution in the vertical direction (z)

    str_r = np.zeros((n_radial_array * nlayers,))
    # Strain distribution in the radial direction (r)

    str_t = np.zeros((n_radial_array * nlayers,))
    # Strain distribution in the toroidal direction (t)

    str_z = np.zeros((n_radial_array * nlayers,))
    # Uniform strain in the vertical direction (z)

    r_deflect = np.zeros((n_radial_array * nlayers,))
    # Radial displacement radial distribution [m]

    rradius = np.zeros((n_radial_array * nlayers,))
    # Radius array [m]

    # local arrays
    # Stiffness form of compliance tensor
    nu_tz = np.zeros((nlayers,))
    # Transverse-axial Poisson's ratio
    # (ratio of axial strain to transverse strain upon transverse stress)
    ey_bar_z = np.zeros((nlayers,))
    # Axial effective Young's modulus (zero cross-strains, not stresses) [Pa]
    ey_bar_t = np.zeros((nlayers,))
    # Transverse effective Young's modulus [Pa]
    nu_bar_t = np.zeros((nlayers,))
    # Transverse effective Poisson's ratio
    nu_bar_tz = np.zeros((nlayers,))
    # Transverse-axial effective Poisson's ratio
    nu_bar_zt = np.zeros((nlayers,))
    # Axial-transverse effective Poisson's ratio

    # Lorentz force parameters
    currents = np.zeros((nlayers,))
    # Currents in each layer [A]
    currents_enclosed = np.zeros((nlayers,))
    # Currents enclosed by inner radius of each layer [A]
    f_lin_fac = np.zeros((nlayers,))
    # Factor that multiplies r linearly in the force density
    f_rec_fac = np.zeros((nlayers,))
    # Factor that multiplies r reciprocally in the force density
    f_int_a = np.zeros((nlayers,))
    # Force density integral that adds to Lame parameter A
    f_int_b = np.zeros((nlayers,))
    # Force density integral that adds to Lame parameter B

    # Layer transfer matrices
    m_int = np.zeros(
        (
            5,
            5,
            nlayers,
        ),
    )
    # Matrix that transforms the Lame parmeter vector from the
    # outer radius to the inner radius of each layer
    m_ext = np.zeros(
        (
            5,
            5,
            nlayers,
        ),
    )
    # Matrix that transforms the Lame parmeter vector from the
    # inner radius of one layer to the outer radius of the
    # next inner.
    m_tot = np.zeros(
        (
            5,
            5,
            nlayers,
        ),
    )
    # Matrix that transforms the Lame parmeter vector from the
    # outer radius of the outer layer to the inner radius of
    # each.

    # Axial force inner product
    v_force_row = np.zeros(
        (
            1,
            5,
        ),
    )
    # Row vector (matrix multiplication is inner product) to
    # obtain the axial force from the force-carrying layers
    v_force_row_slip = np.zeros(
        (
            1,
            5,
        ),
    )
    # Row vector (matrix multiplication is inner product) to
    # obtain the axial force inner slip layers (no net force)
    rad_row_helper = np.zeros(
        (
            1,
            5,
        ),
    )
    # A helper variable to store [radius, 1, 0, 0, 0] in row

    # Boundary condition matrix
    m_bc = np.zeros(
        (
            4,
            5,
        ),
    )
    # Boundary condition matrix. Multiply this with the
    # outermost solution vector, (A,B,eps_z,1.0,eps_z_slip),
    # to obtain a zero vector.
    m_toinv = np.zeros(
        (
            4,
            4,
        ),
    )
    # Matrix to invert to get the solution
    RHS_vec = np.zeros((4,))
    # Right-hand-side vector to divide m_toinv
    a_vec_solution = np.zeros((5,))
    # Solution vector, Lame parameters at outer radius, strain
    # of force-carrying layers, and strain of slip layers
    # (A,B,eps_z,1,eps_z_slip)

    # Constructing the solution everywhere
    a_vec_layer = np.zeros((5,))
    # Lame parameters and strains vector at outer radius
    # of each layer

    # The stress calcualtion differential equations is analytically sloved
    # The final solution is given by the layer boundary conditions on
    # radial stress and displacement between layers solved
    # The problem is set as aa.cc = bb, cc being the constant we search

    # Inner slip layers parameters
    # Section 15 in the writeup
    # Innermost layer that takes axial force. Layers inner of this
    # have zero net axial force, to include CS decoupling.
    # This configuration JUST HAPPENS to work out because of
    # the specific i_tf_bucking options; if those are changed,
    # will need a switch here.
    nonslip_layer = i_tf_bucking

    if nonslip_layer < 1:
        nonslip_layer = 1

    # Stiffness tensor factors
    # Section 3 in the writeup
    # With Section 12 anisotropic materials properties
    # ***
    # Dependent Poisson's ratio: nu-transverse-axial
    # from nu-axial-transverse and the Young's moduli
    nu_tz[:] = nu_zt * ey_t / ey_z

    # Effective Young's Moduli and Poisson's ratios
    # holding strain, not stress, cross-terms constant
    ey_bar_z[:] = ey_z * (1 - nu_t) / (1 - nu_t - 2 * nu_tz * nu_zt)
    ey_bar_t[:] = (
        ey_t * (1 - nu_tz * nu_zt) / (1 - nu_t - 2 * nu_tz * nu_zt) / (1 + nu_t)
    )

    nu_bar_t[:] = (nu_t + nu_tz * nu_zt) / (1 - nu_tz * nu_zt)
    nu_bar_tz[:] = nu_tz / (1 - nu_t)
    nu_bar_zt[:] = nu_zt * (1 + nu_t) / (1 - nu_tz * nu_zt)

    # Lorentz force parameters
    # Section 13 in the writeup
    # ***
    # Currents in each layer [A]
    currents[:] = np.pi * d_curr * (rad[1 : nlayers + 1] ** 2 - rad[:nlayers] ** 2)
    # Currents enclosed by inner radius of each layer [A]
    currents_enclosed[0] = 0.0e0

    for ii in range(1, nlayers):
        currents_enclosed[ii] = currents_enclosed[ii - 1] + currents[ii - 1]
    # Factor that multiplies r linearly in the force density
    f_lin_fac[:] = constants.RMU0 / 2.0e0 * d_curr**2
    # Factor that multiplies r reciprocally in the force density
    f_rec_fac[:] = (
        constants.RMU0
        / 2.0e0
        * (d_curr * currents_enclosed / np.pi - d_curr**2 * rad[:nlayers] ** 2)
    )
    # Force density integral that adds to Lame parameter A
    f_int_a[:] = 0.5e0 * f_lin_fac * (
        rad[1 : nlayers + 1] ** 2 - rad[:nlayers] ** 2
    ) + f_rec_fac * np.log(rad[1 : nlayers + 1] / rad[:nlayers])
    if f_rec_fac[0] == 0e0:
        f_int_a[0] = 0.5e0 * f_lin_fac[0] * (rad[1] ** 2 - rad[0] ** 2)

    # Force density integral that adds to Lame parameter B
    f_int_b[:] = 0.25e0 * f_lin_fac * (
        rad[1 : nlayers + 1] ** 4 - rad[:nlayers] ** 4
    ) + 0.5e0 * f_rec_fac * (rad[1 : nlayers + 1] ** 2 - rad[:nlayers] ** 2)

    # Transformation matrix from outer to inner Lame parameters
    # Section 5 in the writeup
    # With Section 12 anisotropic materials properties
    # ***
    # m_int[kk] multiplies Lame parameter vector of layer kk (A,B,eps_z,1.0,eps_z_slip)
    # and transforms the values at the outer radius to the values at the inner radius
    for kk in range(nlayers):
        m_int[0, 0, kk] = 1.0e0
        m_int[1, 1, kk] = 1.0e0
        m_int[2, 2, kk] = 1.0e0
        m_int[3, 3, kk] = 1.0e0
        m_int[4, 4, kk] = 1.0e0

        m_int[0, 3, kk] = -0.5e0 / ey_bar_t[kk] * f_int_a[kk]
        m_int[1, 3, kk] = 0.5e0 / ey_bar_t[kk] * f_int_b[kk]

    # Transformation matrix between layers
    # Section 6 in the writeup
    # With Section 12 anisotropic materials properties
    # With Section 15 inner slip-decoupled layers
    # ***
    # m_ext[kk] multiplies Lame parameter vector of layer kk (A,B,eps_z,1.0,eps_z_slip)
    # and transforms the values at the inner radius to the values at the outer radius
    # of layer kk-1
    for kk in range(1, nonslip_layer - 1):
        ey_fac = ey_bar_t[kk] / ey_bar_t[kk - 1]
        m_ext[0, 2, kk] = 0.0e0
        m_ext[0, 4, kk] = 0.5e0 * (ey_fac * nu_bar_zt[kk] - nu_bar_zt[kk - 1])

    if nonslip_layer > 1:
        ey_fac = ey_bar_t[nonslip_layer - 1] / ey_bar_t[nonslip_layer - 2]
        m_ext[0, 2, nonslip_layer - 1] = 0.5e0 * ey_fac * nu_bar_zt[nonslip_layer - 1]
        m_ext[0, 4, nonslip_layer - 1] = 0.5e0 * (-nu_bar_zt[nonslip_layer - 2])

    for kk in range(nonslip_layer, nlayers):
        ey_fac = ey_bar_t[kk] / ey_bar_t[kk - 1]
        m_ext[0, 2, kk] = 0.5e0 * (ey_fac * nu_bar_zt[kk] - nu_bar_zt[kk - 1])
        m_ext[0, 4, kk] = 0.0e0

    for kk in range(1, nlayers):
        ey_fac = ey_bar_t[kk] / ey_bar_t[kk - 1]
        m_ext[0, 0, kk] = 0.5e0 * (ey_fac * (1 + nu_bar_t[kk]) + 1 - nu_bar_t[kk - 1])
        if rad[kk] > 0e0:
            m_ext[0, 1, kk] = (
                0.5e0
                / rad[kk] ** 2
                * (1 - nu_bar_t[kk - 1] - ey_fac * (1 - nu_bar_t[kk]))
            )

        m_ext[1, 0, kk] = rad[kk] ** 2 * (1 - m_ext[0, 0, kk])
        m_ext[1, 1, kk] = 1 - rad[kk] ** 2 * m_ext[0, 1, kk]
        m_ext[1, 2, kk] = -(rad[kk] ** 2) * m_ext[0, 2, kk]
        m_ext[1, 4, kk] = -(rad[kk] ** 2) * m_ext[0, 4, kk]
        m_ext[2, 2, kk] = 1.0e0
        m_ext[3, 3, kk] = 1.0e0
        m_ext[4, 4, kk] = 1.0e0

    # Total transformation matrix, from Lame parmeters at outside to
    # Lame parameters at inside of each layer
    # Section 7 in the writeup
    # ***
    m_tot[:, :, nlayers - 1] = m_int[:, :, nlayers - 1]

    for kk in range(nlayers - 2, -1, -1):
        m_tot[:, :, kk] = np.ascontiguousarray(m_int[:, :, kk]) @ (
            np.ascontiguousarray(m_ext[:, :, kk + 1])
            @ np.ascontiguousarray(m_tot[:, :, kk + 1])
        )

    # Axial force inner product. Dot-product this with the
    # outermost solution vector, (A,B,eps_z,1.0,eps_z_slip),
    # to obtain the axial force.
    # Section 8 in the writeup
    # ***
    # Axial stiffness products
    ey_bar_z_area = np.pi * sum(
        ey_bar_z[nonslip_layer - 1 : nlayers]
        * (rad[nonslip_layer : nlayers + 1] ** 2 - rad[nonslip_layer - 1 : nlayers] ** 2)
    )
    ey_bar_z_area_slip = np.pi * sum(
        ey_bar_z[: nonslip_layer - 1]
        * (rad[1:nonslip_layer] ** 2 - rad[: nonslip_layer - 1] ** 2)
    )

    # Axial stiffness inner product, for layers which carry axial force
    rad_row_helper[0, :] = [rad[nlayers] ** 2, 1e0, 0e0, 0e0, 0e0]
    v_force_row[:, :] = (
        2e0 * np.pi * ey_bar_z[nlayers - 1] * nu_bar_tz[nlayers - 1] * rad_row_helper
    )
    rad_row_helper[0, :] = [rad[nonslip_layer - 1] ** 2, 1e0, 0e0, 0e0, 0e0]
    v_force_row[:, :] = v_force_row - 2e0 * np.pi * ey_bar_z[
        nonslip_layer - 1
    ] * nu_bar_tz[nonslip_layer - 1] * (
        rad_row_helper @ np.ascontiguousarray(m_tot[:, :, nonslip_layer - 1])
    )
    for kk in range(nonslip_layer, nlayers):
        rad_row_helper[0, :] = [rad[kk] ** 2, 1e0, 0e0, 0e0, 0e0]
        v_force_row[:, :] = v_force_row + 2e0 * np.pi * (
            ey_bar_z[kk - 1] * nu_bar_tz[kk - 1] - ey_bar_z[kk] * nu_bar_tz[kk]
        ) * (rad_row_helper @ np.ascontiguousarray(m_tot[:, :, kk]))

    # Include the effect of axial stiffness
    v_force_row[0, 2] += ey_bar_z_area

    # Axial stiffness inner product, for layers which DON'T carry force
    if nonslip_layer > 1:
        rad_row_helper[0, :] = [rad[nonslip_layer - 1] ** 2, 1e0, 0e0, 0e0, 0e0]
        v_force_row_slip[:, :] = (
            2e0
            * np.pi
            * ey_bar_z[nonslip_layer - 2]
            * nu_bar_tz[nonslip_layer - 2]
            * (rad_row_helper @ np.ascontiguousarray(m_tot[:, :, nonslip_layer - 1]))
        )
        rad_row_helper[0, :] = [rad[0] ** 2, 1e0, 0e0, 0e0, 0e0]
        v_force_row_slip[:, :] -= (
            2e0
            * np.pi
            * ey_bar_z[0]
            * nu_bar_tz[0]
            * (rad_row_helper @ np.ascontiguousarray(m_tot[:, :, 0]))
        )
        for kk in range(1, nonslip_layer - 1):
            rad_row_helper[0, :] = [rad[kk] ** 2, 1e0, 0e0, 0e0, 0e0]
            v_force_row_slip[:, :] += (
                2e0
                * np.pi
                * (ey_bar_z[kk - 1] * nu_bar_tz[kk - 1] - ey_bar_z[kk] * nu_bar_tz[kk])
                * (rad_row_helper @ np.ascontiguousarray(m_tot[:, :, kk]))
            )
        # Include the effect of axial stiffness
        v_force_row_slip[0, 4] += ey_bar_z_area_slip
    else:
        # If there's no inner slip layer, still need a finite 5th
        # element to ensure no singular matrix
        v_force_row_slip[0, :] = [0e0, 0e0, 0e0, 0e0, 1e0]

    # Boundary condition matrix. Multiply this with the
    # outermost solution vector, (A,B,eps_z,1.0,eps_z_slip),
    # to obtain a zero vector.
    # Solved to get the Lame parameters.
    # Section 9 in the writeup
    # ***
    # Outer boundary condition row, zero radial stress
    m_bc[0, :] = [
        (1e0 + nu_bar_t[nlayers - 1]) * rad[nlayers] ** 2,
        -1e0 + nu_bar_t[nlayers - 1],
        nu_bar_zt[nlayers - 1] * rad[nlayers] ** 2,
        0e0,
        0e0,
    ]
    # Inner boundary condition row, zero radial stress
    # or zero displacement if rad(1)=0
    if nonslip_layer > 1:
        m_bc[1, :] = [
            (1e0 + nu_bar_t[0]) * rad[0] ** 2,
            -1e0 + nu_bar_t[0],
            0e0,
            0e0,
            nu_bar_zt[0] * rad[0] ** 2,
        ]
    else:
        m_bc[1, :] = [
            (1e0 + nu_bar_t[0]) * rad[0] ** 2,
            -1e0 + nu_bar_t[0],
            nu_bar_zt[0] * rad[0] ** 2,
            0e0,
            0e0,
        ]

    m_bc[1, :] = np.ascontiguousarray(m_bc[1, :]) @ np.ascontiguousarray(m_tot[:, :, 0])
    # Axial force boundary condition
    m_bc[2, :] = v_force_row[0, :]
    m_bc[2, 3] = m_bc[2, 3] - v_force
    # Axial force boundary condition of slip layers
    m_bc[3, :] = v_force_row_slip[0, :]

    # The solution, the outermost Lame parameters A,B
    # and the axial strains of the force-carrying and
    # slip layers eps_z and eps_z_slip.
    # Section 10 in the writeup
    # ***
    m_toinv[:, :3] = m_bc[
        :,
        :3,
    ]
    m_toinv[:, 3] = m_bc[:, 4]
    RHS_vec[:] = -m_bc[:, 3]

    a_vec_solution[:4] = np.linalg.solve(m_toinv, RHS_vec)

    a_vec_solution[4] = a_vec_solution[3]
    a_vec_solution[3] = 1

    # Radial/toroidal/vertical stress radial distribution
    # ------
    # Radial displacement, stress and strain distributions

    a_vec_layer[:] = a_vec_solution[:]
    for ii in range(nlayers - 1, -1, -1):
        a_layer = a_vec_layer[0]
        b_layer = a_vec_layer[1]

        dradius = (rad[ii + 1] - rad[ii]) / (n_radial_array - 1)

        for jj in range(ii * n_radial_array, (ii + 1) * n_radial_array):
            rradius[jj] = rad[ii] + dradius * (jj - (n_radial_array * ii))

            f_int_a_plot = 0.5e0 * f_lin_fac[ii] * (
                rad[ii + 1] ** 2 - rradius[jj] ** 2
            ) + f_rec_fac[ii] * np.log(rad[ii + 1] / (rradius[jj]))
            f_int_b_plot = 0.25e0 * f_lin_fac[ii] * (
                rad[ii + 1] ** 4 - rradius[jj] ** 4
            ) + 0.5e0 * f_rec_fac[ii] * (rad[ii + 1] ** 2 - rradius[jj] ** 2)
            a_plot = a_layer - 0.5e0 / ey_bar_t[ii] * f_int_a_plot
            b_plot = b_layer + 0.5e0 / ey_bar_t[ii] * f_int_b_plot

            # Radial displacement
            r_deflect[jj] = a_plot * rradius[jj] + b_plot / rradius[jj]

            # Radial strain
            str_r[jj] = a_plot - b_plot / rradius[jj] ** 2
            # Azimuthal strain
            str_t[jj] = a_plot + b_plot / rradius[jj] ** 2
            # Axial strain
            if ii < nonslip_layer - 1:
                str_z[jj] = a_vec_solution[4]
            else:
                str_z[jj] = a_vec_solution[2]

            # Radial stress
            sigr[jj] = ey_bar_t[ii] * (
                str_r[jj] + (nu_bar_t[ii] * str_t[jj]) + (nu_bar_zt[ii] * str_z[jj])
            )
            # Aximuthal stress
            sigt[jj] = ey_bar_t[ii] * (
                str_t[jj] + (nu_bar_t[ii] * str_r[jj]) + (nu_bar_zt[ii] * str_z[jj])
            )
            # Axial stress
            sigz[jj] = ey_bar_z[ii] * (
                str_z[jj] + (nu_bar_tz[ii] * (str_r[jj] + str_t[jj]))
            )

        a_vec_layer = np.ascontiguousarray(m_tot[:, :, ii]) @ a_vec_solution
        a_vec_layer = np.ascontiguousarray(m_ext[:, :, ii]) @ a_vec_layer
    # ------

    return rradius, sigr, sigt, sigz, str_r, str_t, str_z, r_deflect

plane_stress(nu, rad, ey, j, nlayers, n_radial_array)

Calculates the stresses in a superconductor TF coil inboard leg at the midplane using the plain stress approximation

This routine calculates the stresses in a superconductor TF coil inboard leg at midplane.

A 2 layer plane stress model developed by CCFE is used. The first layer is the steel case inboard of the winding pack, and the second layer is the winding pack itself. PROCESS Superconducting TF Coil Model, J. Morris, CCFE, 1st May 2014

Parameters:

Name Type Description Default
nu
required
rad
required
ey
required
j
required
nlayers
required
n_radial_array
required
Source code in process/models/tfcoil/base.py
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
@numba.njit(cache=True)
def plane_stress(nu, rad, ey, j, nlayers, n_radial_array):
    """Calculates the stresses in a superconductor TF coil
    inboard leg at the midplane using the plain stress approximation

    This routine calculates the stresses in a superconductor TF coil
    inboard leg at midplane.
    <P>A 2 layer plane stress model developed by CCFE is used. The first layer
    is the steel case inboard of the winding pack, and the second
    layer is the winding pack itself.
    PROCESS Superconducting TF Coil Model, J. Morris, CCFE, 1st May 2014

    Parameters
    ----------
    nu :

    rad :

    ey :

    j :

    nlayers :

    n_radial_array :

    """
    alpha = np.zeros((nlayers,))
    beta = np.zeros((nlayers,))
    # Lorentz body force parametres

    area = np.zeros((nlayers,))
    # Layer area

    aa = np.zeros((
        2 * nlayers,
        2 * nlayers,
    ))
    # Matrix encoding the integration constant cc coeficients

    bb = np.zeros((2 * nlayers,))
    # Vector encoding the alpha/beta (lorentz forces) contribution

    cc = np.zeros((2 * nlayers,))
    c1 = np.zeros((nlayers,))
    c2 = np.zeros((nlayers,))
    # Integration constants vector (solution)

    rradius = np.zeros((nlayers * n_radial_array,))
    # Radius array [m]

    sigr = np.zeros((nlayers * n_radial_array,))
    # Radial stress radial distribution [Pa]

    sigt = np.zeros((nlayers * n_radial_array,))
    # Toroidal stress radial distribution [Pa]

    r_deflect = np.zeros((nlayers * n_radial_array,))
    # Radial deflection (displacement) radial distribution [m]

    kk = ey / (1 - nu**2)

    # Lorentz forces parameterisation coeficients (array equation)
    alpha = 0.5e0 * constants.RMU0 * j**2 / kk

    inner_layer_curr = 0.0e0
    for ii in range(nlayers):
        beta[ii] = (
            0.5e0
            * constants.RMU0
            * j[ii]
            * (inner_layer_curr - np.pi * j[ii] * rad[ii] ** 2)
            / (np.pi * kk[ii])
        )

        # Layer area
        area[ii] = np.pi * (rad[ii + 1] ** 2 - rad[ii] ** 2)

        # Total current carried by the inners layers
        inner_layer_curr = inner_layer_curr + area[ii] * j[ii]
    # ***

    # Null radial stress at R(1)
    aa[0, 0] = kk[0] * (1.0e0 + nu[0])
    aa[0, 1] = -kk[0] * (1.0e0 - nu[0]) / (rad[0] ** 2)

    # Inter-layer boundary conditions
    if nlayers != 1:
        for ii in range(nlayers - 1):
            # Continuous radial normal stress at R(ii+1)
            aa[2 * ii + 1, 2 * ii] = kk[ii] * (1.0e0 + nu[ii])
            aa[2 * ii + 1, 2 * ii + 1] = -kk[ii] * (1.0e0 - nu[ii]) / rad[ii + 1] ** 2
            aa[2 * ii + 1, 2 * ii + 2] = -kk[ii + 1] * (1.0e0 + nu[ii + 1])
            aa[2 * ii + 1, 2 * ii + 3] = (
                kk[ii + 1] * (1.0e0 - nu[ii + 1]) / rad[ii + 1] ** 2
            )

            # Continuous displacement at R(ii+1)
            aa[2 * ii + 2, 2 * ii] = rad[ii + 1]
            aa[2 * ii + 2, 2 * ii + 1] = 1.0e0 / rad[ii + 1]
            aa[2 * ii + 2, 2 * ii + 2] = -rad[ii + 1]
            aa[2 * ii + 2, 2 * ii + 3] = -1.0e0 / rad[ii + 1]

    # Radial stress = 0
    aa[2 * (nlayers - 1) + 1, 2 * (nlayers - 1)] = kk[nlayers - 1] * (
        1.0e0 + nu[nlayers - 1]
    )
    aa[2 * (nlayers - 1) + 1, 2 * (nlayers - 1) + 1] = (
        -kk[nlayers - 1] * (1.0e0 - nu[nlayers - 1]) / rad[nlayers] ** 2
    )
    # ***

    # Right hand side vector bb
    # ***
    # Null radial stress at R(1)
    bb[0] = -kk[0] * (
        0.125e0 * alpha[0] * (3.0e0 + nu[0]) * rad[0] ** 2
        + 0.5e0 * beta[0] * (1.0e0 + (1.0e0 + nu[0]) * np.log(rad[0]))
    )

    # Inter-layer boundary conditions
    if nlayers != 1:
        for ii in range(nlayers - 1):
            # Continuous radial normal stress at R[ii+1]
            bb[2 * ii + 1] = -kk[ii] * (
                0.125e0 * alpha[ii] * (3.0e0 + nu[ii]) * rad[ii + 1] ** 2
                + 0.5e0 * beta[ii] * (1.0e0 + (1.0e0 + nu[ii]) * np.log(rad[ii + 1]))
            ) + kk[ii + 1] * (
                0.125e0 * alpha[ii + 1] * (3.0e0 + nu[ii + 1]) * rad[ii + 1] ** 2
                + 0.5e0
                * beta[ii + 1]
                * (1.0e0 + (1.0e0 + nu[ii + 1]) * np.log(rad[ii + 1]))
            )

            # Continuous displacement at R(ii+1)
            bb[2 * ii + 2] = (
                -0.125e0 * alpha[ii] * rad[ii + 1] ** 3
                - 0.5e0 * beta[ii] * rad[ii + 1] * np.log(rad[ii + 1])
                + 0.125e0 * alpha[ii + 1] * rad[ii + 1] ** 3
                + 0.5e0 * beta[ii + 1] * rad[ii + 1] * np.log(rad[ii + 1])
            )

    # Null radial stress at R(nlayers+1)
    bb[2 * (nlayers - 1) + 1] = -kk[nlayers - 1] * (
        0.125e0 * alpha[nlayers - 1] * (3.0e0 + nu[nlayers - 1]) * rad[nlayers] ** 2
        + 0.5e0
        * beta[nlayers - 1]
        * (1.0e0 + (1.0e0 + nu[nlayers - 1]) * np.log(rad[nlayers]))
    )
    # ***

    #  Find solution vector cc
    # ***
    # This context manager runs the code in Python by copying the data
    # out of numba, running the code, and then copying the result
    # back in. This means that the linear algebra solve is not compiled and runs
    # as if it were written in normal Python.
    # This is done because numba compiles against the SciPy algebra library,
    # not the Numpy one. We have observed some odd behaviour when using the SciPy library
    # for this specific problem and so opt for using the numpy library instead.
    # https://github.com/ukaea/PROCESS/issues/3027
    # https://github.com/scipy/scipy/issues/23639
    with numba.objmode(cc="float64[:]"):
        # These matrices can often end up being very ill-conditioned which can lead to numerical
        # instability when solving below.
        # Scaling the matrix can help reduce numerical instability by reducing the condition of matrix.
        # Here, we scale aa such that the largest element on a given row is 1.0. This does not
        # change the solution provided each element of a given row is scaled by the same scalar
        # and the corresponding entry in bb is also scaled the same amount.
        # NOTE: this does not entirely solve the numerical instability and you can get above-floating point
        # differences in the result of this function depending on system.
        row_scale = np.max(np.abs(aa), axis=1)
        # The transpose below ensures the scale is repeated along the row, not the column
        aa /= np.broadcast_to(row_scale, aa.shape).T
        bb /= row_scale

        cc = np.linalg.solve(aa, bb)

    #  Multiply c by (-1) (John Last, internal CCFE memorandum, 21/05/2013)
    for ii in range(nlayers):
        c1[ii] = cc[2 * ii]
        c2[ii] = cc[2 * ii + 1]
    # ***
    # ------

    # Radial/toroidal/vertical stress radial distribution
    # ------

    for ii in range(nlayers):
        dradius = (rad[ii + 1] - rad[ii]) / n_radial_array
        for jj in range(ii * n_radial_array, (ii + 1) * n_radial_array):
            rad_c = rad[ii] + dradius * (jj - n_radial_array * ii)
            rradius[jj] = rad_c

            # Radial stress radial distribution [Pa]
            sigr[jj] = kk[ii] * (
                (1.0e0 + nu[ii]) * c1[ii]
                - ((1.0e0 - nu[ii]) * c2[ii]) / rad_c**2
                + 0.125e0 * (3.0e0 + nu[ii]) * alpha[ii] * rad_c**2
                + 0.5e0 * beta[ii] * (1.0e0 + (1.0e0 + nu[ii]) * np.log(rad_c))
            )

            # Radial stress radial distribution [Pa]
            sigt[jj] = kk[ii] * (
                (1.0e0 + nu[ii]) * c1[ii]
                + (1.0e0 - nu[ii]) * c2[ii] / rad_c**2
                + 0.125e0 * (1.0e0 + 3.0e0 * nu[ii]) * alpha[ii] * rad_c**2
                + 0.5e0 * beta[ii] * (nu[ii] + (1.0e0 + nu[ii]) * np.log(rad_c))
            )

            #  Deflection [m]
            r_deflect[jj] = (
                c1[ii] * rad_c
                + c2[ii] / rad_c
                + 0.125e0 * alpha[ii] * rad_c**3
                + 0.5e0 * beta[ii] * rad_c * np.log(rad_c)
            )

    return sigr, sigt, r_deflect, rradius

eyoung_parallel_array(n, eyoung_j_in, a_in, poisson_j_perp_in)

See Issue #1205 for derivation PDF This subroutine gives the smeared elastic properties of two members that are carrying a force in parallel with each other. The force goes in direction j. Members 1 and 2 are the individual members to be smeared. Member 3 is the effective smeared member (output). This is pretty easy because the smeared properties are simply the average weighted by the cross-sectional areas perpendicular to j. The assumption is that the strains in j are equal. If you're dealing with anisotropy, please pay attention to the fact that the specific Young's Modulus used here is that in the j direction, and the specific Poisson's ratio used here is that between the j and transverse directions in that order. (transverse strain / j strain, under j stress) The smeared Poisson's ratio is computed assuming the transverse dynamics are isotropic, and that the two members are free to shrink/expand under Poisson effects without interference from each other. This may not be true of your case.

To build up a composite smeared member of any number of individual members, you can pass the same properties for members 2 and 3, and call it successively, using the properties of each member as the first triplet of arguments. This way, the last triplet acts as a "working sum": call eyoung_parallel(triplet1, triplet2, tripletOUT) call eyoung_parallel(triplet3, tripletOUT, tripletOUT) call eyoung_parallel(triplet4, tripletOUT, tripletOUT) ... etc. So that tripletOUT would eventually have the smeared properties of the total composite member.

Parameters:

Name Type Description Default
n
required
eyoung_j_in
required
a_in
required
poisson_j_perp_in
required
Source code in process/models/tfcoil/base.py
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
@numba.njit(cache=True)
def eyoung_parallel_array(n, eyoung_j_in, a_in, poisson_j_perp_in):
    """
    See Issue #1205 for derivation PDF
    This subroutine gives the smeared elastic properties of two
    members that are carrying a force in parallel with each other.
    The force goes in direction j.
    Members 1 and 2 are the individual members to be smeared.
    Member 3 is the effective smeared member (output).
    This is pretty easy because the smeared properties are simply
    the average weighted by the cross-sectional areas perpendicular
    to j.
    The assumption is that the strains in j are equal.
    If you're dealing with anisotropy, please pay attention to the
    fact that the specific Young's Modulus used here is that in
    the j direction, and the specific Poisson's ratio used here is
    that between the j and transverse directions in that order.
    (transverse strain / j strain, under j stress)
    The smeared Poisson's ratio is computed assuming the transverse
    dynamics are isotropic, and that the two members are free to
    shrink/expand under Poisson effects without interference from
    each other. This may not be true of your case.

    To build up a composite smeared member of any number of
    individual members, you can pass the same properties for
    members 2 and 3, and call it successively, using the properties
    of each member as the first triplet of arguments. This way, the
    last triplet acts as a "working sum":
    call eyoung_parallel(triplet1, triplet2, tripletOUT)
    call eyoung_parallel(triplet3, tripletOUT, tripletOUT)
    call eyoung_parallel(triplet4, tripletOUT, tripletOUT)
    ... etc.
    So that tripletOUT would eventually have the smeared properties
    of the total composite member.

    Parameters
    ----------
    n :

    eyoung_j_in :

    a_in :

    poisson_j_perp_in :

    """
    eyoung_j_out = 0
    a_out = 0
    poisson_j_perp_out = 0

    # Parallel-composite them all together
    for ii in range(n):
        eyoung_j_out, a_out, poisson_j_perp_out = eyoung_parallel(
            eyoung_j_in[ii],
            a_in[ii],
            poisson_j_perp_in[ii],
            eyoung_j_out,
            a_out,
            poisson_j_perp_out,
        )

    return eyoung_j_out, a_out, poisson_j_perp_out

eyoung_t_nested_squares(n, eyoung_j_in, l_in, poisson_j_perp_in)

This subroutine gives the smeared transverse elastic properties of n members whose cross sectional areas are nested squares. It uses the subroutines eyoung_series and eyoung_parallel, above, so please be aware of the assumptions inherent in those subroutines.

It assumes that each "leg" of the square cross section (vertical slice, as described in Figure 10 of the TF coil documentation) is composed of several layers under stress in series, and each leg is under stress in parallel with every other leg.

Parameters:

Name Type Description Default
n
required
eyoung_j_in
required
l_in
required
poisson_j_perp_in
required
Source code in process/models/tfcoil/base.py
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
@numba.njit(cache=True)
def eyoung_t_nested_squares(n, eyoung_j_in, l_in, poisson_j_perp_in):
    """
    This subroutine gives the smeared transverse elastic
    properties of n members whose cross sectional areas are
    nested squares. It uses the subroutines eyoung_series and
    eyoung_parallel, above, so please be aware of the assumptions
    inherent in those subroutines.

    It assumes that each "leg" of the square cross section
    (vertical slice, as described in Figure 10 of the TF coil
    documentation) is composed of several layers under stress in
    series, and each leg is under stress in parallel with every
    other leg.

    Parameters
    ----------
    n :

    eyoung_j_in :

    l_in :

    poisson_j_perp_in :

    """
    eyoung_j_working = np.zeros((n,))
    l_working = np.zeros((n,))
    poisson_j_perp_working = np.zeros((n,))

    # First member
    eyoung_j_working[0] = eyoung_j_in[0]
    l_working[0] = l_in[0]
    poisson_j_perp_working[0] = poisson_j_perp_in[0]

    for ii in range(1, n):
        # Initialize the leg of which this is the new member
        eyoung_j_working[ii] = eyoung_j_in[ii]
        l_working[ii] = l_working[ii - 1] + l_in[ii]
        poisson_j_perp_working[ii] = poisson_j_perp_in[ii]

        # Serial-composite the new layer of this member into the previous legs
        # changed from range(ii-1) because range(0) == []
        for jj in range(ii):
            (
                eyoung_j_working[jj],
                l_working[jj],
                poisson_j_perp_working[jj],
            ) = eyoung_series(
                eyoung_j_working[ii],
                l_in[ii],
                poisson_j_perp_working[ii],
                eyoung_j_working[jj],
                l_working[jj],
                poisson_j_perp_working[jj],
            )

    # Find stiffest leg
    eyoung_stiffest = max(eyoung_j_working)

    eyoung_j_out = 0
    l_out = 0
    poisson_j_perp_out = 0

    # Parallel-composite them all together
    for ii in range(n):
        eyoung_j_out, l_out, poisson_j_perp_out = eyoung_parallel(
            eyoung_j_working[ii],
            l_in[ii],
            poisson_j_perp_working[ii],
            eyoung_j_out,
            l_out,
            poisson_j_perp_out,
        )

    return eyoung_j_out, l_out, poisson_j_perp_out, eyoung_stiffest

eyoung_series(eyoung_j_1, l_1, poisson_j_perp_1, eyoung_j_2, l_2, poisson_j_perp_2)

See Issue #1205 for derivation PDF This subroutine gives the smeared elastic properties of two members that are carrying a force in series with each other. The force goes in direction j. The assumption is that the stresses in j are equal. The smeared Young's modulus is the inverse of the average of the inverse of the Young's moduli, weighted by the length of the members in j. Members 1 and 2 are the individual members to be smeared. Member 3 is the effective smeared member (output). The smeared Poisson's ratio is the averaged of the Poisson's ratios, weighted by the quantity (Young's modulus / length of the members in j).

If you're dealing with anisotropy, please pay attention to the fact that the specific Young's Modulus used here is that in the j direction, and the specific Poisson's ratio used here is that between the j and transverse directions in that order. (transverse strain / j strain, under j stress) The smeared Poisson's ratio is computed assuming the transverse dynamics are isotropic, and that the two members are free to shrink/expand under Poisson effects without interference from each other. This may not be true of your case.

To build up a composite smeared member of any number of individual members, you can pass the same properties for members 2 and 3, and call it successively, using the properties of each member as the first triplet of arguments. This way, the last triplet acts as a "working sum": call eyoung_series(triplet1, triplet2, tripletOUT) call eyoung_series(triplet3, tripletOUT, tripletOUT) call eyoung_series(triplet4, tripletOUT, tripletOUT) ... etc. So that tripletOUT would eventually have the smeared properties of the total composite member.

Parameters:

Name Type Description Default
eyoung_j_1
required
l_1
required
poisson_j_perp_1
required
eyoung_j_2
required
l_2
required
poisson_j_perp_2
required
Source code in process/models/tfcoil/base.py
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
@numba.njit(cache=True)
def eyoung_series(eyoung_j_1, l_1, poisson_j_perp_1, eyoung_j_2, l_2, poisson_j_perp_2):
    """
    See Issue #1205 for derivation PDF
    This subroutine gives the smeared elastic properties of two
    members that are carrying a force in series with each other.
    The force goes in direction j.
    The assumption is that the stresses in j are equal.
    The smeared Young's modulus is the inverse of the average of
    the inverse of the Young's moduli, weighted by the length
    of the members in j.
    Members 1 and 2 are the individual members to be smeared.
    Member 3 is the effective smeared member (output).
    The smeared Poisson's ratio is the averaged of the Poisson's
    ratios, weighted by the quantity (Young's modulus / length of
    the members in j).

    If you're dealing with anisotropy, please pay attention to the
    fact that the specific Young's Modulus used here is that in
    the j direction, and the specific Poisson's ratio used here is
    that between the j and transverse directions in that order.
    (transverse strain / j strain, under j stress)
    The smeared Poisson's ratio is computed assuming the transverse
    dynamics are isotropic, and that the two members are free to
    shrink/expand under Poisson effects without interference from
    each other. This may not be true of your case.

    To build up a composite smeared member of any number of
    individual members, you can pass the same properties for
    members 2 and 3, and call it successively, using the properties
    of each member as the first triplet of arguments. This way, the
    last triplet acts as a "working sum":
    call eyoung_series(triplet1, triplet2, tripletOUT)
    call eyoung_series(triplet3, tripletOUT, tripletOUT)
    call eyoung_series(triplet4, tripletOUT, tripletOUT)
    ... etc.
    So that tripletOUT would eventually have the smeared properties
    of the total composite member.

    Parameters
    ----------
    eyoung_j_1 :

    l_1 :

    poisson_j_perp_1 :

    eyoung_j_2 :

    l_2 :

    poisson_j_perp_2 :

    """

    if eyoung_j_1 * eyoung_j_2 == 0:
        # poisson_j_perp_3 = 0
        poisson_j_perp_3 = poisson_j_perp_1 if eyoung_j_1 == 0 else poisson_j_perp_2

        eyoung_j_3 = 0.0
        l_3 = l_1 + l_2
    else:
        poisson_j_perp_3 = (
            poisson_j_perp_1 * l_1 / eyoung_j_1 + poisson_j_perp_2 * l_2 / eyoung_j_2
        ) / (l_1 / eyoung_j_1 + l_2 / eyoung_j_2)
        eyoung_j_3 = (l_1 + l_2) / (l_1 / eyoung_j_1 + l_2 / eyoung_j_2)
        l_3 = l_1 + l_2

    eyoung_j_3 = eyoung_j_3
    poisson_j_perp_3 = np.array(poisson_j_perp_3)

    return eyoung_j_3, l_3, poisson_j_perp_3