Repository navigation
Expand file tree
/
Copy pathpfcoil.py
More file actions
5453 lines (4864 loc) · 203 KB
/
Copy pathpfcoil.py
File metadata and controls
5453 lines (4864 loc) · 203 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Module containing PF coil and CS coil models."""
import logging
import math
from dataclasses import dataclass
from enum import IntEnum, unique
import numba
import numpy as np
from scipy import optimize
from scipy.linalg import svd
from scipy.special import ellipe, ellipk
from tabulate import tabulate
from process.core import constants
from process.core import process_output as op
from process.core.data_structure.base import DataStructure
from process.core.exceptions import ProcessValueError
from process.core.model import Model
from process.data_structure.pfcoil_variables import (
N_PF_COILS_IN_GROUP_MAX,
N_PF_GROUPS_MAX,
NFIXMX,
NGC2,
NPTSMX,
CSUseModel,
PFConductorModel,
)
from process.models import superconductors
from process.models.engineering.materials import (
calculate_tresca_stress,
calculate_von_mises_stress,
)
from process.models.pulse import PulseTimings
from process.models.superconductors import (
SuperconductorMaterial,
SuperconductorModel,
)
from process.models.tfcoil.base import TFCoilShapeModel
logger = logging.getLogger(__name__)
N_CS_STRESS_PROFILE_POINTS = 20
@unique
class PFLocationTypes(IntEnum):
"""Enum for PF coil location types."""
ABOVE_CS = 1
"""PF coil is stacked on top of the Central Solenoid"""
ABOVE_TF = 2
"""PF coil is stacked on top of the TF coil"""
OUTSIDE_TF = 3
"""PF coil is placed outside of the TF coil"""
GENERALLY_PLACED = 4
"""PF coil is generally placed"""
class PFCoil(Model):
"""Calculate poloidal field coil system parameters."""
def __init__(self, cs_fatigue, cs_coil):
"""Initialise Fortran module variables."""
self.outfile = constants.NOUT # output file unit
self.mfile = constants.MFILE # mfile file unit
self.cs_fatigue = cs_fatigue
self.cs_coil = cs_coil
def run(self):
"""Run the PF coil model."""
self.pfcoil()
# Poloidal field coil inductance calculation
self.induct(False)
# Volt-second capability of PF coil set
self.vsec()
def output(self):
"""Output results to output file."""
self.cs_coil.output_cs_structure()
self.outpf()
self.outvolt()
self.output_induct()
def output_induct(self):
"""Output poloidal field coil inductance calculation."""
self.induct(True)
def pfcoil(self):
"""Routine to perform calculations for the PF and Central Solenoid coils.
This subroutine performs the calculations for the PF and
Central Solenoid coils, to determine their size, location, current waveforms,
stresses etc.
Raises
------
ProcessValueError
If there are errors with PF coils.
See individual ProcessValueError instances for more details.
"""
lrow1 = 2 * NPTSMX + N_PF_GROUPS_MAX
lcol1 = N_PF_GROUPS_MAX
pcls0 = np.zeros(N_PF_GROUPS_MAX, dtype=int)
ncls0 = np.zeros(N_PF_GROUPS_MAX + 2, dtype=int)
rcls0, zcls0 = np.zeros(
(
2,
N_PF_GROUPS_MAX,
N_PF_COILS_IN_GROUP_MAX,
),
order="F",
)
ccls0 = np.zeros(int(N_PF_GROUPS_MAX / 2))
brin, bzin, rpts, zpts = np.zeros((4, NPTSMX))
bfix, bvec = np.zeros((2, lrow1))
gmat, _, _ = np.zeros((3, lrow1, lcol1), order="F")
signn = np.zeros(2)
aturn = np.zeros(NGC2)
# Toggle switch for i_pf_location()=2 coils above/below midplane
top_bottom = 1
# Set up the number of PF coils including the Central Solenoid (n_cs_pf_coils),
# and the number of PF circuits including the plasma (n_pf_cs_plasma_circuits)
if self.data.pf_coil.n_pf_coil_groups > N_PF_GROUPS_MAX:
raise ProcessValueError(
"n_pf_coil_groups is larger than n_pf_groups_max",
n_pf_coil_groups=self.data.pf_coil.n_pf_coil_groups,
n_pf_groups_max=N_PF_GROUPS_MAX,
)
# Total the number of PF coils in all groups, and check that none
# exceeds the limit
self.data.pf_coil.n_cs_pf_coils = 0
for i in range(self.data.pf_coil.n_pf_coil_groups):
if self.data.pf_coil.n_pf_coils_in_group[i] > N_PF_COILS_IN_GROUP_MAX:
raise ProcessValueError(
"PFCOIL: Too many coils in a PF coil group",
i=i,
n_pf_coils_in_group=self.data.pf_coil.n_pf_coils_in_group[i],
n_pf_coils_in_group_max=N_PF_COILS_IN_GROUP_MAX,
)
self.data.pf_coil.n_cs_pf_coils += self.data.pf_coil.n_pf_coils_in_group[i]
# Add one if an Central Solenoid is present, and make an extra group
if CSUseModel(self.data.build.i_cs_use) != CSUseModel.NO_CENTRAL_SOLENOID:
self.data.pf_coil.n_cs_pf_coils += 1
self.data.pf_coil.n_pf_coils_in_group[self.data.pf_coil.n_pf_coil_groups] = 1
# Add one for the plasma
self.data.pf_coil.n_pf_cs_plasma_circuits = self.data.pf_coil.n_cs_pf_coils + 1
# Overall current density in the Central Solenoid at beginning of pulse
self.data.pf_coil.j_cs_pulse_start = (
self.data.pf_coil.j_cs_flat_top_end
* self.data.pf_coil.f_j_cs_start_pulse_end_flat_top
)
# Set up call to MHD scaling routine for coil currents.
# First break up Central Solenoid solenoid into 'filaments'
cs_geometry = self.cs_coil.calculate_cs_geometry(
z_tf_inside_half=self.data.build.z_tf_inside_half,
f_z_cs_tf_internal=self.data.pf_coil.f_z_cs_tf_internal,
dr_cs=self.data.build.dr_cs,
dr_cs_bore=self.data.build.dr_cs_bore,
)
self.data.pf_coil.z_cs_upper = self.data.pf_coil.z_pf_coil_upper[
self.data.pf_coil.n_cs_pf_coils - 1
] = cs_geometry.z_cs_coil_upper
self.data.pf_coil.z_cs_lower = self.data.pf_coil.z_pf_coil_lower[
self.data.pf_coil.n_cs_pf_coils - 1
] = cs_geometry.z_cs_coil_lower
self.data.pf_coil.r_pf_coil_middle[self.data.pf_coil.n_cs_pf_coils - 1] = (
cs_geometry.r_cs_coil_middle
)
self.data.pf_coil.r_cs_middle = cs_geometry.r_cs_middle
self.data.pf_coil.z_cs_middle = self.data.pf_coil.z_pf_coil_middle[
self.data.pf_coil.n_cs_pf_coils - 1
] = cs_geometry.z_cs_coil_middle
self.data.pf_coil.r_cs_outer = self.data.pf_coil.r_pf_coil_outer[
self.data.pf_coil.n_cs_pf_coils - 1
] = cs_geometry.r_cs_coil_outer
self.data.pf_coil.r_cs_inner = self.data.pf_coil.r_pf_coil_inner[
self.data.pf_coil.n_cs_pf_coils - 1
] = cs_geometry.r_cs_coil_inner
self.data.pf_coil.dz_cs_full = cs_geometry.dz_cs_full
self.data.pf_coil.dr_cs_full = cs_geometry.dr_cs_full
# nfxf is the total no of filaments into which the Central Solenoid is split,
# if present
if CSUseModel(self.data.build.i_cs_use) == CSUseModel.NO_CENTRAL_SOLENOID:
self.data.pf_coil.nfxf = 0
c_cs_flat_top_end = 0.0e0
else:
self.data.pf_coil.nfxf = 2 * self.data.pf_coil.n_cs_current_filaments
# total Central Solenoid current at EOF
c_cs_flat_top_end = -(
self.data.pf_coil.a_cs_poloidal * self.data.pf_coil.j_cs_flat_top_end
)
if self.data.pf_coil.nfxf > NFIXMX:
raise ProcessValueError(
"Too many filaments nfxf representing the OH coil",
nfxf=self.data.pf_coil.nfxf,
nfixmx=NFIXMX,
)
# Symmetric up/down Central Solenoid :
# Find (R,Z) and current of each filament at BOP
(
self.data.pf_coil.r_pf_cs_current_filaments,
self.data.pf_coil.z_pf_cs_current_filaments,
self.data.pf_coil.c_pf_cs_current_filaments,
) = self.cs_coil.place_cs_filaments(
n_cs_current_filaments=self.data.pf_coil.n_cs_current_filaments,
r_cs_middle=self.data.pf_coil.r_cs_middle,
z_cs_inside_half=self.data.pf_coil.dz_cs_full / 2,
c_cs_flat_top_end=c_cs_flat_top_end,
f_j_cs_start_pulse_end_flat_top=self.data.pf_coil.f_j_cs_start_pulse_end_flat_top,
nfxf=self.data.pf_coil.nfxf,
)
# Scale PF coil locations
signn[0] = 1.0e0
signn[1] = -1.0e0
self.data.pf_coil.r_pf_outside_tf_midplane = (
self.data.superconducting_tfcoil.r_tf_outboard_out
+ self.data.pf_coil.dr_pf_tf_outboard_out_offset
)
# Place the PF coils:
# N.B. Problems here if coil=n_pf_coils_in_group(group) is greater than 2.
for group in range(self.data.pf_coil.n_pf_coil_groups):
match self.data.pf_coil.i_pf_location[group]:
case PFLocationTypes.ABOVE_CS:
# PF coil is stacked on top of the Central Solenoid
# Use a helper function to compute r_pf_coil_middle_group_array and
# z_pf_coil_middle_group_array arrays for this group
r_pf_coil_middle_group_array, z_pf_coil_middle_group_array = (
self.place_pf_above_cs(
n_pf_coils_in_group=self.data.pf_coil.n_pf_coils_in_group,
n_pf_group=group,
r_cs_middle=self.data.pf_coil.r_cs_middle,
dr_pf_cs_middle_offset=self.data.pf_coil.dr_pf_cs_middle_offset,
z_tf_inside_half=self.data.build.z_tf_inside_half,
dr_tf_inboard=self.data.build.dr_tf_inboard,
z_cs_coil_upper=self.data.pf_coil.dz_cs_full / 2,
)
)
for coil in range(self.data.pf_coil.n_pf_coils_in_group[group]):
self.data.pf_coil.r_pf_coil_middle_group_array[group, coil] = (
r_pf_coil_middle_group_array[group, coil]
)
self.data.pf_coil.z_pf_coil_middle_group_array[group, coil] = (
z_pf_coil_middle_group_array[group, coil]
)
case PFLocationTypes.ABOVE_TF:
# PF coil is on top of the TF coil
(
r_pf_coil_middle_group_array,
z_pf_coil_middle_group_array,
top_bottom,
) = self.place_pf_above_tf(
n_pf_coils_in_group=self.data.pf_coil.n_pf_coils_in_group,
n_pf_group=group,
rmajor=self.data.physics.rmajor,
triang=self.data.physics.triang,
rminor=self.data.physics.rminor,
itart=self.data.physics.itart,
itartpf=self.data.physics.itartpf,
z_tf_inside_half=self.data.build.z_tf_inside_half,
dz_tf_upper_lower_midplane=self.data.build.dz_tf_upper_lower_midplane,
z_tf_top=self.data.build.z_tf_top,
top_bottom=top_bottom,
rpf2=self.data.pf_coil.rpf2,
zref=self.data.pf_coil.zref,
)
for coil in range(self.data.pf_coil.n_pf_coils_in_group[group]):
self.data.pf_coil.r_pf_coil_middle_group_array[group, coil] = (
r_pf_coil_middle_group_array[group, coil]
)
self.data.pf_coil.z_pf_coil_middle_group_array[group, coil] = (
z_pf_coil_middle_group_array[group, coil]
)
case PFLocationTypes.OUTSIDE_TF:
# PF coil is radially outside the TF coil
(
r_pf_coil_middle_group_array,
z_pf_coil_middle_group_array,
) = self.place_pf_outside_tf(
n_pf_coils_in_group=self.data.pf_coil.n_pf_coils_in_group,
n_pf_group=group,
rminor=self.data.physics.rminor,
zref=self.data.pf_coil.zref,
i_tf_shape=self.data.tfcoil.i_tf_shape,
i_r_pf_outside_tf_placement=self.data.pf_coil.i_r_pf_outside_tf_placement,
r_pf_outside_tf_midplane=self.data.pf_coil.r_pf_outside_tf_midplane,
)
for coil in range(self.data.pf_coil.n_pf_coils_in_group[group]):
self.data.pf_coil.r_pf_coil_middle_group_array[group, coil] = (
r_pf_coil_middle_group_array[group, coil]
)
self.data.pf_coil.z_pf_coil_middle_group_array[group, coil] = (
z_pf_coil_middle_group_array[group, coil]
)
case PFLocationTypes.GENERALLY_PLACED:
(
r_pf_coil_middle_group_array,
z_pf_coil_middle_group_array,
) = self.place_pf_generally(
n_pf_coils_in_group=self.data.pf_coil.n_pf_coils_in_group,
n_pf_group=group,
rminor=self.data.physics.rminor,
rmajor=self.data.physics.rmajor,
zref=self.data.pf_coil.zref,
rref=self.data.pf_coil.rref,
)
for coil in range(self.data.pf_coil.n_pf_coils_in_group[group]):
self.data.pf_coil.r_pf_coil_middle_group_array[group, coil] = (
r_pf_coil_middle_group_array[group, coil]
)
self.data.pf_coil.z_pf_coil_middle_group_array[group, coil] = (
z_pf_coil_middle_group_array[group, coil]
)
case _:
raise ProcessValueError(
"Illegal i_pf_location value",
group=group,
i_pf_location=self.data.pf_coil.i_pf_location[group],
)
# Allocate current to the PF coils:
# "Flux swing coils" participate in cancellation of the CS
# field during a flux swing. "Equilibrium coils" are varied
# to create the equilibrium field, targeting the correct
# vertical field
# As implemented, all coils are flux swing coils
# As implemented, Location 3 and 4 coils are equilibrium
# coils.
# Flux swing coils:
if self.data.pf_coil.j_cs_pulse_start != 0.0e0: # noqa: RUF069
# Find currents for plasma initiation to null field across plasma
npts = 32 # Number of test points across plasma midplane
if npts > NPTSMX:
raise ProcessValueError(
"Too many test points npts across plasma midplane",
npts=npts,
nptsmx=NPTSMX,
)
# Position and B-field at each test point
drpt = 2.0e0 * self.data.physics.rminor / (npts - 1)
rpt0 = self.data.physics.rmajor - self.data.physics.rminor
for i in range(npts):
rpts[i] = rpt0 + (i) * drpt
zpts[i] = 0.0e0
brin[i] = 0.0e0
bzin[i] = 0.0e0
# Calculate currents in coils to produce the given field
self.data.pf_coil.ssq0, self.data.pf_coil.ccl0 = self.efc(
npts,
rpts,
zpts,
brin,
bzin,
self.data.pf_coil.nfxf,
self.data.pf_coil.r_pf_cs_current_filaments,
self.data.pf_coil.z_pf_cs_current_filaments,
self.data.pf_coil.c_pf_cs_current_filaments,
self.data.pf_coil.n_pf_coil_groups,
self.data.pf_coil.n_pf_coils_in_group,
self.data.pf_coil.r_pf_coil_middle_group_array,
self.data.pf_coil.z_pf_coil_middle_group_array,
self.data.pf_coil.alfapf,
bfix,
gmat,
bvec,
)
# Equilibrium coil currents determined by SVD targeting B
if self.data.pf_coil.i_pf_current == 1:
# Simple coil current scaling for STs (good only for A < about 1.8)
# Bypasses SVD solver
if self.data.physics.itart == 1 and self.data.physics.itartpf == 0:
for i in range(self.data.pf_coil.n_pf_coil_groups):
match self.data.pf_coil.i_pf_location[i]:
case PFLocationTypes.ABOVE_CS:
# PF coil is stacked on top of the Central Solenoid
self.data.pf_coil.ccls[i] = 0.0e0
raise ProcessValueError(
"i_pf_location(i) should not be 1 if itart=1", i=i
)
case PFLocationTypes.ABOVE_TF:
# PF coil is on top of the TF coil
self.data.pf_coil.ccls[i] = (
0.3e0
* self.data.physics.aspect**1.6e0
* self.data.physics.plasma_current
)
case PFLocationTypes.OUTSIDE_TF:
# PF coil is radially outside the TF coil
self.data.pf_coil.ccls[i] = (
-0.4e0 * self.data.physics.plasma_current
)
case _:
raise ProcessValueError(
"Illegal value of i_pf_location(i)",
i=i,
i_pf_location=self.data.pf_coil.i_pf_location[i],
)
# Vertical field (T)
self.data.physics.b_plasma_vertical_required = (
-1.0e-7
* self.data.physics.plasma_current
/ self.data.physics.rmajor
* (
math.log(8.0e0 * self.data.physics.aspect)
+ self.data.physics.beta_poloidal_vol_avg
+ (self.data.physics.ind_plasma_internal_norm / 2.0e0)
- 1.5e0
)
)
else:
# Conventional aspect ratio scaling
nfxf0 = 0
ngrp0 = 0
nocoil = 0
for i in range(self.data.pf_coil.n_pf_coil_groups):
match self.data.pf_coil.i_pf_location[i]:
case PFLocationTypes.ABOVE_CS:
# Do not allow if no central solenoid
if (
CSUseModel(self.data.build.i_cs_use)
== CSUseModel.NO_CENTRAL_SOLENOID
):
raise ProcessValueError(
"i_pf_location(i) should not be 1 if i_cs_use=0"
)
# PF coil is stacked on top of the Central Solenoid
# This coil is to balance Central Solenoid flux and should
# not be involved in equilibrium calculation -- RK 07/12
self.data.pf_coil.ccls[i] = 0.0e0
nfxf0 += self.data.pf_coil.n_pf_coils_in_group[i]
for ccount in range(
self.data.pf_coil.n_pf_coils_in_group[i]
):
self.data.pf_coil.r_pf_cs_current_filaments[nocoil] = (
self.data.pf_coil.r_pf_coil_middle_group_array[
i, ccount
]
)
self.data.pf_coil.z_pf_cs_current_filaments[nocoil] = (
self.data.pf_coil.z_pf_coil_middle_group_array[
i, ccount
]
)
self.data.pf_coil.c_pf_cs_current_filaments[nocoil] = (
self.data.pf_coil.ccls[i]
)
nocoil += 1
case PFLocationTypes.ABOVE_TF:
# PF coil is on top of the TF coil; divertor coil
# This is a fixed current for this calculation -- RK 07/12
self.data.pf_coil.ccls[i] = (
self.data.physics.plasma_current
* 2.0e0
* (
1.0e0
- (
self.data.physics.kappa
* self.data.physics.rminor
)
/ abs(
self.data.pf_coil.z_pf_coil_middle_group_array[
i, 0
]
)
)
)
nfxf0 += self.data.pf_coil.n_pf_coils_in_group[i]
for ccount in range(
self.data.pf_coil.n_pf_coils_in_group[i]
):
self.data.pf_coil.r_pf_cs_current_filaments[nocoil] = (
self.data.pf_coil.r_pf_coil_middle_group_array[
i, ccount
]
)
self.data.pf_coil.z_pf_cs_current_filaments[nocoil] = (
self.data.pf_coil.z_pf_coil_middle_group_array[
i, ccount
]
)
self.data.pf_coil.c_pf_cs_current_filaments[nocoil] = (
self.data.pf_coil.ccls[i]
)
nocoil += 1
case PFLocationTypes.OUTSIDE_TF:
# PF coil is radially outside the TF coil
# This is an equilibrium coil, current must be solved for
pcls0[ngrp0] = i + 1
ngrp0 += 1
case PFLocationTypes.GENERALLY_PLACED:
# PF coil is generally placed
# See issue 1418
# https://git.ccfe.ac.uk/process/process/-/issues/1418
# This is an equilibrium coil, current must be solved for
pcls0[ngrp0] = i + 1
ngrp0 += 1
case _:
raise ProcessValueError(
"Illegal value of i_pf_location(i)",
i=i,
i_pf_location=self.data.pf_coil.i_pf_location[i],
)
for ccount in range(ngrp0):
ncls0[ccount] = 2
rcls0[ccount, 0] = self.data.pf_coil.r_pf_coil_middle_group_array[
pcls0[ccount] - 1, 0
]
rcls0[ccount, 1] = self.data.pf_coil.r_pf_coil_middle_group_array[
pcls0[ccount] - 1, 1
]
zcls0[ccount, 0] = self.data.pf_coil.z_pf_coil_middle_group_array[
pcls0[ccount] - 1, 0
]
zcls0[ccount, 1] = self.data.pf_coil.z_pf_coil_middle_group_array[
pcls0[ccount] - 1, 1
]
npts0 = 1
rpts[0] = self.data.physics.rmajor
zpts[0] = 0.0e0
brin[0] = 0.0e0
# Added physics.ind_plasma_internal_norm term correctly -- RK 07/12
bzin[0] = (
-1.0e-7
* self.data.physics.plasma_current
/ self.data.physics.rmajor
* (
math.log(8.0e0 * self.data.physics.aspect)
+ self.data.physics.beta_poloidal_vol_avg
+ (self.data.physics.ind_plasma_internal_norm / 2.0e0)
- 1.5e0
)
)
self.data.physics.b_plasma_vertical_required = bzin[0]
_ssqef, ccls0 = self.efc(
npts0,
rpts,
zpts,
brin,
bzin,
nfxf0,
self.data.pf_coil.r_pf_cs_current_filaments,
self.data.pf_coil.z_pf_cs_current_filaments,
self.data.pf_coil.c_pf_cs_current_filaments,
ngrp0,
ncls0,
rcls0,
zcls0,
self.data.pf_coil.alfapf,
bfix,
gmat,
bvec,
)
for ccount in range(ngrp0):
self.data.pf_coil.ccls[pcls0[ccount] - 1] = ccls0[ccount]
# Flux swing from vertical field
# If this is the first visit to the routine the inductance matrix
# ind_pf_cs_plasma_mutual and the turns array have not yet been calculated,
# so we set them to (very) approximate values to avoid strange behaviour...
if self.data.pf_coil.first_call:
self.data.pf_coil.ind_pf_cs_plasma_mutual[:, :] = 1.0e0
self.data.pf_coil.n_pf_coil_turns[:] = 100.0e0
self.data.pf_coil.first_call = False
pfflux = 0.0e0
nocoil = 0
for ccount in range(self.data.pf_coil.n_pf_coil_groups):
for _i in range(self.data.pf_coil.n_pf_coils_in_group[ccount]):
pfflux += (
self.data.pf_coil.ccls[ccount]
* self.data.pf_coil.ind_pf_cs_plasma_mutual[
nocoil, self.data.pf_coil.n_pf_cs_plasma_circuits - 1
]
/ self.data.pf_coil.n_pf_coil_turns[nocoil]
)
nocoil += 1
# Flux swing required from CS coil
csflux = -(self.data.physics.vs_plasma_ramp_required) - pfflux
if CSUseModel(self.data.build.i_cs_use) == CSUseModel.FULL_PULSE:
# Required current change in CS coil
# Proposed new calculation...
# dics = csflux / ind_pf_cs_plasma_mutual
# (n_cs_pf_coils,n_pf_cs_plasma_circuits)
# BUT... ind_pf_cs_plasma_mutual(n_cs_pf_coils,n_pf_cs_plasma_circuits)
# is around 2000 times ddics below...
ddics = (
4.0e-7
* np.pi
* np.pi
* (
(self.data.build.dr_cs_bore * self.data.build.dr_cs_bore)
+ (self.data.build.dr_cs * self.data.build.dr_cs) / 6.0e0
+ (self.data.build.dr_cs * self.data.build.dr_cs_bore) / 2.0e0
)
/ (self.data.pf_coil.dz_cs_full)
)
dics = csflux / ddics
self.data.pf_coil.f_j_cs_start_end_flat_top = (
(-c_cs_flat_top_end * self.data.pf_coil.f_j_cs_start_pulse_end_flat_top)
+ dics
) / c_cs_flat_top_end
if np.abs(self.data.pf_coil.f_j_cs_start_end_flat_top) > 1.0:
logger.warning(
"Ratio of central solenoid overall current density at "
"beginning of flat-top / end of flat-top > 1 "
"(|f_j_cs_start_end_flat_top| > 1)"
)
else:
dics = 0.0e0
self.data.pf_coil.f_j_cs_start_end_flat_top = 1.0e0
logger.error("OH coil not present; check volt-second calculations...")
# Split groups of coils into one set containing ncl coils
ncl = 0
for nng in range(self.data.pf_coil.n_pf_coil_groups):
for ng2 in range(self.data.pf_coil.n_pf_coils_in_group[nng]):
self.data.pf_coil.r_pf_coil_middle[ncl] = (
self.data.pf_coil.r_pf_coil_middle_group_array[nng, ng2]
)
self.data.pf_coil.z_pf_coil_middle[ncl] = (
self.data.pf_coil.z_pf_coil_middle_group_array[nng, ng2]
)
# Currents at different times:
# If PF coil currents are computed, not input via ccl0_ma, ccls_ma:
# Then set ccl0_ma,ccls_ma from the computed pf_coil.ccl0, pf_coil.ccls
if self.data.pf_coil.i_pf_current != 0:
self.data.pf_coil.ccl0_ma[nng] = 1.0e-6 * self.data.pf_coil.ccl0[nng]
self.data.pf_coil.ccls_ma[nng] = 1.0e-6 * self.data.pf_coil.ccls[nng]
else:
# Otherwise set self.data.pf_coil.ccl0,self.data.pf_coil.ccls via
# the input ccl0_ma and ccls_ma
self.data.pf_coil.ccl0[nng] = 1.0e6 * self.data.pf_coil.ccl0_ma[nng]
self.data.pf_coil.ccls[nng] = 1.0e6 * self.data.pf_coil.ccls_ma[nng]
# Beginning of pulse: t = self.data.times.t_plant_pulse_coil_precharge
self.data.pf_coil.c_pf_cs_coil_pulse_start_ma[ncl] = (
1.0e-6 * self.data.pf_coil.ccl0[nng]
)
# Beginning of flat-top:
# t = times.t_plant_pulse_coil_precharge
# + times.t_plant_pulse_plasma_current_ramp_up
self.data.pf_coil.c_pf_cs_coil_flat_top_ma[ncl] = 1.0e-6 * (
self.data.pf_coil.ccls[nng]
- (
self.data.pf_coil.ccl0[nng]
* self.data.pf_coil.f_j_cs_start_end_flat_top
/ self.data.pf_coil.f_j_cs_start_pulse_end_flat_top
)
)
# End of flat-top:
# t = times.t_plant_pulse_coil_precharge
# +times.t_plant_pulse_plasma_current_ramp_up
# +times.t_plant_pulse_fusion_ramp+times.t_plant_pulse_burn
self.data.pf_coil.c_pf_cs_coil_pulse_end_ma[ncl] = 1.0e-6 * (
self.data.pf_coil.ccls[nng]
- (
self.data.pf_coil.ccl0[nng]
* (1.0e0 / self.data.pf_coil.f_j_cs_start_pulse_end_flat_top)
)
)
ncl += 1
# Current in Central Solenoid as a function of time
# N.B. If the Central Solenoid is not present then c_cs_flat_top_end is zero.
self.data.pf_coil.c_pf_cs_coil_pulse_start_ma[ncl] = (
-1.0e-6
* c_cs_flat_top_end
* self.data.pf_coil.f_j_cs_start_pulse_end_flat_top
)
self.data.pf_coil.c_pf_cs_coil_flat_top_ma[ncl] = (
1.0e-6 * c_cs_flat_top_end * self.data.pf_coil.f_j_cs_start_end_flat_top
)
self.data.pf_coil.c_pf_cs_coil_pulse_end_ma[ncl] = 1.0e-6 * c_cs_flat_top_end
# Set up coil current waveforms, normalised to the peak current in
# each coil
self.waveform() # sets c_pf_cs_coils_peak_ma(), f_c_pf_cs_peak_time_array()
# Calculate PF coil geometry, current and number of turns
# Dimensions are those of the winding pack, and exclude
# the steel supporting case
i = 0
self.data.pf_coil.r_pf_coil_outer_max = 0.0e0
dz = 0
for ii in range(self.data.pf_coil.n_pf_coil_groups):
for _ij in range(self.data.pf_coil.n_pf_coils_in_group[ii]):
if self.data.pf_coil.i_pf_location[ii] == PFLocationTypes.ABOVE_CS:
# PF coil is stacked on top of the Central Solenoid
dx = 0.5e0 * self.data.build.dr_cs
dz = 0.5e0 * (
self.data.build.z_tf_inside_half
* (1.0e0 - self.data.pf_coil.f_z_cs_tf_internal)
+ self.data.build.dr_tf_inboard
+ 0.1e0
) # ???
area = 4.0e0 * dx * dz * self.data.pf_coil.pf_current_safety_factor
# Number of turns
# c_pf_coil_turn_peak_input[i] is the current per turn (input)
self.data.pf_coil.n_pf_coil_turns[i] = abs(
(self.data.pf_coil.c_pf_cs_coils_peak_ma[i] * 1.0e6)
/ self.data.pf_coil.c_pf_coil_turn_peak_input[i]
)
aturn[i] = area / self.data.pf_coil.n_pf_coil_turns[i]
# Actual winding pack current density
self.data.pf_coil.j_pf_coil_wp_peak[i] = (
1.0e6 * abs(self.data.pf_coil.c_pf_cs_coils_peak_ma[i]) / area
)
# Location of edges of each coil:
# r_pf_coil_inner = inner radius, r_pf_coil_outer = outer radius
# z_pf_coil_lower = 'lower' edge z (i.e. edge nearer to midplane)
# z_pf_coil_upper = 'upper' edge z (i.e. edge further from midplane)
self.data.pf_coil.r_pf_coil_inner[i] = (
self.data.pf_coil.r_pf_coil_middle[i] - dx
)
self.data.pf_coil.r_pf_coil_outer[i] = (
self.data.pf_coil.r_pf_coil_middle[i] + dx
)
self.data.pf_coil.z_pf_coil_lower[i] = (
self.data.pf_coil.z_pf_coil_middle[i] - dz
)
if self.data.pf_coil.z_pf_coil_middle[i] < 0.0e0:
self.data.pf_coil.z_pf_coil_lower[i] = (
self.data.pf_coil.z_pf_coil_middle[i] + dz
)
self.data.pf_coil.z_pf_coil_upper[i] = (
self.data.pf_coil.z_pf_coil_middle[i] + dz
)
if self.data.pf_coil.z_pf_coil_middle[i] < 0.0e0:
self.data.pf_coil.z_pf_coil_upper[i] = (
self.data.pf_coil.z_pf_coil_middle[i] - dz
)
else:
# Other coils. N.B. Current density j_pf_coil_wp_peak[i] is defined
# in routine INITIAL for these coils.
area = (
abs(
self.data.pf_coil.c_pf_cs_coils_peak_ma[i]
* 1.0e6
/ self.data.pf_coil.j_pf_coil_wp_peak[i]
)
* self.data.pf_coil.pf_current_safety_factor
)
self.data.pf_coil.n_pf_coil_turns[i] = abs(
(self.data.pf_coil.c_pf_cs_coils_peak_ma[i] * 1.0e6)
/ self.data.pf_coil.c_pf_coil_turn_peak_input[i]
)
aturn[i] = area / self.data.pf_coil.n_pf_coil_turns[i]
dx = 0.5e0 * math.sqrt(area) # square cross-section
self.data.pf_coil.r_pf_coil_inner[i] = (
self.data.pf_coil.r_pf_coil_middle[i] - dx
)
self.data.pf_coil.r_pf_coil_outer[i] = (
self.data.pf_coil.r_pf_coil_middle[i] + dx
)
self.data.pf_coil.z_pf_coil_lower[i] = (
self.data.pf_coil.z_pf_coil_middle[i] - dx
)
if self.data.pf_coil.z_pf_coil_middle[i] < 0.0e0:
self.data.pf_coil.z_pf_coil_lower[i] = (
self.data.pf_coil.z_pf_coil_middle[i] + dx
)
self.data.pf_coil.z_pf_coil_upper[i] = (
self.data.pf_coil.z_pf_coil_middle[i] + dx
)
if self.data.pf_coil.z_pf_coil_middle[i] < 0.0e0:
self.data.pf_coil.z_pf_coil_upper[i] = (
self.data.pf_coil.z_pf_coil_middle[i] - dx
)
# Outside radius of largest PF coil (m)
self.data.pf_coil.r_pf_coil_outer_max = max(
self.data.pf_coil.r_pf_coil_outer_max,
self.data.pf_coil.r_pf_coil_outer[i],
)
i += 1
# Calculate peak field, allowable current density, resistive
# power losses and volumes and weights for each PF coil, index i
i = 0
it = 0
self.data.pf_coil.p_pf_coil_resistive_total_flat_top = 0.0e0
self.data.pf_coil.m_pf_coil_max = 0.0e0
for ii in range(self.data.pf_coil.n_pf_coil_groups):
iii = ii
for ij in range(self.data.pf_coil.n_pf_coils_in_group[ii]):
# Peak field
if ij == 0:
# Index args +1ed
_bri, _bro, _bzi, _bzo = peak_b_field_at_pf_coil(
n_coil=i + 1,
n_coil_group=iii + 1,
t_b_field_peak=it,
data=self.data,
) # returns b_pf_coil_peak, bpf2
# Issue 1871. MDK
# Allowable current density (for superconducting coils) for each coil,
# index i
if self.data.pf_coil.i_pf_conductor == PFConductorModel.SUPERCONDUCTING:
bmax = max(
abs(self.data.pf_coil.b_pf_coil_peak[i]),
abs(self.data.pf_coil.bpf2[i]),
)
self.data.pf_coil.j_pf_wp_critical[i], _jstrand, jsc, _tmarg = (
superconpf(
b_pf_peak=bmax,
fhe=self.data.pf_coil.f_a_pf_coil_void[i],
fcu=self.data.pf_coil.fcupfsu,
j_pf_wp=self.data.pf_coil.j_pf_coil_wp_peak[i],
isumat=self.data.pf_coil.i_pf_superconductor,
fhts=self.data.tfcoil.fhts,
strain=self.data.tfcoil.str_pf_con_res,
temp_pf_peak_field=self.data.tfcoil.tftmp,
bcritsc=self.data.tfcoil.bcritsc,
tcritsc=self.data.tfcoil.tcritsc,
dr_hts_tape=self.data.superconducting_tfcoil.dr_tf_hts_tape,
dx_hts_tape_rebco=self.data.superconducting_tfcoil.dx_tf_hts_tape_rebco,
dx_hts_tape_total=self.data.superconducting_tfcoil.dx_tf_hts_tape_total,
)
)
# Strand critical current calculation for costing in $/kAm
# = superconducting filaments jc * (1 - strand copper fraction)
if self.data.pf_coil.i_cs_superconductor in {2, 6, 8}:
self.data.pf_coil.j_crit_str_pf = jsc
else:
self.data.pf_coil.j_crit_str_pf = jsc * (
1 - self.data.pf_coil.fcupfsu
)
# Length of conductor
rll = (
2.0e0
* np.pi
* self.data.pf_coil.r_pf_coil_middle[i]
* self.data.pf_coil.n_pf_coil_turns[i]
)
# Resistive coils
if self.data.pf_coil.i_pf_conductor == PFConductorModel.RESISTIVE:
# Coil resistance (f_a_pf_coil_void is the void fraction)
respf = (
self.data.pf_coil.rho_pf_coil
* rll
/ (aturn[i] * (1.0e0 - self.data.pf_coil.f_a_pf_coil_void[i]))
)
# Sum resistive power losses
self.data.pf_coil.p_pf_coil_resistive_total_flat_top += (
respf
* (
1.0e6
* self.data.pf_coil.c_pf_cs_coil_pulse_start_ma[i]
/ self.data.pf_coil.n_pf_coil_turns[i]
)
** 2
)
# Winding pack volume
volpf = aturn[i] * rll
# Conductor weight (f_a_pf_coil_void is the void fraction)
if self.data.pf_coil.i_pf_conductor == PFConductorModel.SUPERCONDUCTING:
self.data.pf_coil.m_pf_coil_conductor[i] = (
volpf
* self.data.tfcoil.dcond[
self.data.pf_coil.i_pf_superconductor - 1
]
* (1.0e0 - self.data.pf_coil.f_a_pf_coil_void[i])
)
else:
self.data.pf_coil.m_pf_coil_conductor[i] = (
volpf
* constants.DEN_COPPER
* (1.0e0 - self.data.pf_coil.f_a_pf_coil_void[i])
)
# (J x B) force on coil
forcepf = (
0.5e6
* (self.data.pf_coil.b_pf_coil_peak[i] + self.data.pf_coil.bpf2[i])
* abs(self.data.pf_coil.c_pf_cs_coils_peak_ma[i])
* self.data.pf_coil.r_pf_coil_middle[i]
)
# Stress ==> cross-sectional area of supporting steel to use
if self.data.pf_coil.i_pf_conductor == PFConductorModel.SUPERCONDUCTING:
# Superconducting coil
# Updated assumptions: 500 MPa stress limit with all of the force
# supported in the conduit (steel) case.
# Now, 500 MPa replaced by sigpfcalw, sigpfcf now defaultly set to 1
areaspf = (
self.data.pf_coil.sigpfcf
* forcepf
/ (self.data.pf_coil.sigpfcalw * 1.0e6)
)
# Thickness of hypothetical steel casing assumed to encase the PF
# winding pack; in reality, the steel is distributed
# throughout the conductor. Issue #152
# Assume a case of uniform thickness around coil cross-section
# Thickness found via a simple quadratic equation
drpdz = (