/
antenna.py
1741 lines (1445 loc) · 58.7 KB
/
antenna.py
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
# -*- coding: utf-8 -*-
"""
WEST ICRH Antenna RF Model
.. module:: west_ic_antenna.antenna
.. autosummary::
:toctree: generated/
WestIcrhAntenna
"""
import os
import scipy
import skrf as rf
import numpy as np
# Type Hinting Definition
from typing import Union, Sequence, List, Tuple, TYPE_CHECKING
from numbers import Number
NumberLike = Union[Number, Sequence[Number], np.ndarray]
if TYPE_CHECKING:
from skrf import Network, Circuit, Frequency
# #### Default parameters ####
here = os.path.dirname(os.path.abspath(__file__))
S_PARAMS_DIR = here + "/data/Sparameters/"
# NB : bridge and impedance transformer should be defined for the same frequencies
DEFAULT_BRIDGE = S_PARAMS_DIR + "WEST_ICRH_Bridge_30to70MHz.s3p"
DEFAULT_IMPEDANCE_TRANSFORMER = S_PARAMS_DIR + "WEST_ICRH_Transf_Window_PumpHolePMC.s2p"
DEFAULT_SERVICE_STUB = S_PARAMS_DIR + "WEST_ICRH_Stub_30to70MHz.s3p"
# antenna front face data are interpolated on bridge's frequencies
DEFAULT_FRONT_FACE = (
S_PARAMS_DIR + "front_faces/WEST_ICRH_antenna_front_face_curved_30to70MHz.s4p"
)
# Optimal Impedance at T-junction
Z_T_OPT = 2.89 - 0.17j
class WestIcrhAntenna:
"""
WEST ICRH Antenna circuit model.
Parameters
----------
frequency : scikit-rf :class:`skrf.frequency.Frequency` or None, optional
frequency object to build the circuit with.
The default is None: frequency band is the one from antenna elements.
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF].
Default is [50,50,50,50] [pF]
front_face: str or :class:`skrf.network.Network`, optional
path to the Touchstone file of the antenna front face.
Default is None (Vacuum case).
If the frequency band of the front_face Network is a unique point,
as typically for TOPICA results for example, the s-parameters
of the front_face Network is duplicated for all the frequencies
defined by `frequency`.
Note
----
front face ports are defined as (view from behind, ie from torus hall)::
port1 port2
port3 port4
Capacitor names are defined as (view from behind the antenna)::
C1 C3
C2 C4
Voltages are defined the same way::
V1 V3
V2 V4
Examples
--------
Building a WEST ICRH antenna model for a given frequency band:
>>> freq = rf.Frequency(50, 60, 101, unit='MHz')
>>> Cs = [50, 40, 60, 70]
>>> west_antenna = WestIcrhAntenna(freq, Cs) # Vacuum loading case
Building a WEST ICRH antenna model for a given front-face configuration:
>>> # Here the s-param of the front_face are duplicated for all frequ
>>> WestIcrhAntenna(front_face='./data/Sparameters/front_faces/TOPICA/S_TSproto12_55MHz_Profile1.s4p')
"""
def __init__(self, frequency: Union['Frequency', None] = None,
Cs: NumberLike = [50, 50, 50, 50],
front_face: Union[str, None] = None):
self._frequency = frequency or rf.Network(DEFAULT_BRIDGE).frequency
self._Cs = Cs
# display debug print?
self.DEBUG = False
# load networks
_bridge = rf.Network(DEFAULT_BRIDGE)
self.bridge = _bridge.interpolate(self.frequency)
self.bridge_left = self.bridge.copy()
self.bridge_left.name = "bridge_left"
self.bridge_right = self.bridge.copy()
self.bridge_right.name = "bridge_right"
_windows_impedance_transformer = rf.Network(DEFAULT_IMPEDANCE_TRANSFORMER)
self.windows_impedance_transformer = _windows_impedance_transformer.interpolate(
self.frequency
)
self.windows_impedance_transformer_left = (
self.windows_impedance_transformer.copy()
)
self.windows_impedance_transformer_right = (
self.windows_impedance_transformer.copy()
)
self.windows_impedance_transformer_left.name = "line_left"
self.windows_impedance_transformer_right.name = "line_right"
_service_stub = rf.Network(DEFAULT_SERVICE_STUB).interpolate(self.frequency)
self.service_stub_left = _service_stub.copy()
self.service_stub_left.name = "service_stub_left"
self.service_stub_right = _service_stub.copy()
self.service_stub_right.name = "service_stub_right"
# service stub shorts
self.short_left = rf.Circuit.Ground(self.frequency, name="short_left")
self.short_right = rf.Circuit.Ground(self.frequency, name="short_right")
# additional elements which will be usefull later
self.port_left = rf.Circuit.Port(
self.frequency,
"port_left",
z0=self.windows_impedance_transformer_left.z0[:, 0],
)
self.port_right = rf.Circuit.Port(
self.frequency,
"port_right",
z0=self.windows_impedance_transformer_right.z0[:, 0],
)
# antenna front-face
front_face = front_face or DEFAULT_FRONT_FACE
if type(front_face) == str:
# if a string, this should be a path to a Touchstone file
self._antenna = rf.Network(front_face)
elif type(front_face) == rf.network.Network:
# if a Network
self._antenna = front_face.copy()
self._antenna.name = self._antenna.name or "antenna" # set a name if not exist
# Renormalize to 50 ?
# self.bridge_left.renormalize(50)
# self.bridge_right.renormalize(50)
# self.windows_impedance_transformer_left.renormalize(50)
# self.windows_impedance_transformer_right.renormalize(50)
# self._antenna.renormalize(50)
# if the antenna front-face Network is defined on a single point (ex: from TOPICA)
# duplicate this points to the other frequencies
front_face_freq = self._antenna.frequency
if len(front_face_freq) == 1:
new_freq = (
self._frequency
) # rf.Frequency(front_face_freq.f, front_face_freq.f, unit='Hz', npoints=2)
new_ntw = rf.Network(frequency=new_freq)
new_ntw.z0 = np.repeat(self._antenna.z0, len(new_freq), axis=0)
new_ntw.s = np.repeat(self._antenna.s, len(new_freq), axis=0)
new_ntw.name = self._antenna.name or "antenna" # set a name if not exist
self.antenna = new_ntw
else:
# interpolate the results for the frequency band
self.antenna = self._antenna.interpolate(self._frequency)
def __repr__(self) -> str:
return f"WEST ICRH Antenna: C={self._Cs} pF, {self._frequency}"
def capa(
self,
C: float, R: float = 1e-2, L: float = 29.9,
R1: float = 1e-2, C1: float = 25.7, L1: float = 2.4,
z0_bridge: Union[float, None] = None,
z0_antenna: Union[float, None] = None,
):
"""
Equivalent lumped Network model of a WEST ICRH antenna capacitor.
The electrical circuit of an equivalent lumped model is::
port1 (bridge side) port2 (antenna side)
o-- R1 -- L1 --- R -- L -- C --- L1 -- R1 --o
| |
C1 C1
| |
gnd gnd
The default values for R1, L1, C1, R and L have been adjusted to fit
the full-wave modelling of the capacitors [#]_
Parameters
----------
C : float
Capacitance in [pF]
R : float, optional
series resitance in [Ohm].
The default is 1e-2.
L : float, optional
series inductance in [nH].
The default is 29.9.
R1 : float, optional
input/output serie resistance in [Ohm].
The default is 1e-2.
C1 : float, optional
shunt capacitance in [pF].
The default is 25.7.
L1 : float, optional
input/output series inductance in [nH].
The default is 2.4.
z0_bridge : float, optional
Bridge side characteristic impedance in [Ohm].
The default is bridge z0.
z0_antenna : float, optional
Antenna side charactetistic impedance in [Ohm].
The default is the antenna z0
Returns
-------
capa : scikit-rf Network
Equivalent lumped WEST capacitor model Network
References
----------
.. [#] Hillairet, J., 2020. RF network analysis of the WEST ICRH antenna with the open-source python scikit-RF package.
AIP Conference Proceedings 2254, 070010.
https://doi.org/10/ghbw5p
"""
z0_bridge = z0_bridge or self.bridge.z0[:, 1]
z0_antenna = z0_antenna or self.antenna.z0[:, 0]
# dummy transmission line to create lumped components
# the 50 Ohm characteristic impedance is artifical. However, the R,L,R1,L1,C1 values
# have been fitted to full-wave solutions using this 50 ohm value, so it should not be modified
line = rf.media.DefinedGammaZ0(frequency=self.frequency, z0=50)
pre = (
line.resistor(R1)
** line.inductor(L1 * 1e-9)
** line.shunt_capacitor(C1 * 1e-12)
)
post = (
line.shunt_capacitor(C1 * 1e-12)
** line.resistor(R1)
** line.inductor(L1 * 1e-9)
)
cap = line.resistor(R) ** line.inductor(L * 1e-9) ** line.capacitor(C * 1e-12)
capa = pre ** cap ** post
# should we renormalize of not z0 to the Network's z0 they will be connected to?
# ANSYS Designer seems not doing it and leaves to 50 ohm
# renormalizing the z0 will lead to decrease the matched capacitances by ~10pF @55MHz
# In reality, values are closer to 50 pF at 55 MHz
# capa.z0 = [z0_bridge, z0_antenna]
return capa
def _antenna_circuit(self, Cs: NumberLike) -> 'Circuit':
"""
Antenna scikit-rf Circuit.
Parameters
----------
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF]
Returns
-------
circuit: :class:`skrf.circuit.Circuit`
Antenna Circuit
"""
C1, C2, C3, C4 = Cs
# left side
capa_C1 = self.capa(
C1, z0_bridge=self.bridge_left.z0[0][1], z0_antenna=self.antenna.z0[0][0]
)
capa_C1.name = "C1"
capa_C2 = self.capa(
C2, z0_bridge=self.bridge_left.z0[0][2], z0_antenna=self.antenna.z0[0][2]
)
capa_C2.name = "C2"
# right side
capa_C3 = self.capa(
C3, z0_bridge=self.bridge_right.z0[0][1], z0_antenna=self.antenna.z0[0][1]
)
capa_C3.name = "C3"
capa_C4 = self.capa(
C4, z0_bridge=self.bridge_right.z0[0][2], z0_antenna=self.antenna.z0[0][3]
)
capa_C4.name = "C4"
# WARNING !
# antenna port numbering convention does not follow capa and voltage :
# view from behind:
# port1 port2
# port3 port4
# while for capa and voltage it is:
# C1 C3
# C2 C4
# service stub 3rd ports are left open
connections = [
[(self.antenna, 0), (capa_C1, 1)],
[(self.antenna, 1), (capa_C3, 1)],
[(self.antenna, 2), (capa_C2, 1)],
[(self.antenna, 3), (capa_C4, 1)],
[(capa_C1, 0), (self.bridge_left, 1)],
[(capa_C2, 0), (self.bridge_left, 2)],
[(capa_C3, 0), (self.bridge_right, 1)],
[(capa_C4, 0), (self.bridge_right, 2)],
[(self.bridge_left, 0), (self.windows_impedance_transformer_left, 1)],
[(self.bridge_right, 0), (self.windows_impedance_transformer_right, 1)],
# [(self.windows_impedance_transformer_left, 0), (self.port_left, 0)], # no stub
# [(self.windows_impedance_transformer_right, 0), (self.port_right, 0)], # no stub
[(self.windows_impedance_transformer_left, 0), (self.service_stub_left, 1)],
[(self.service_stub_left, 0), (self.port_left, 0)],
[
(self.windows_impedance_transformer_right, 0),
(self.service_stub_right, 1),
],
[(self.service_stub_right, 0), (self.port_right, 0)],
[(self.service_stub_left, 2), (self.short_left, 0)],
[(self.service_stub_right, 2), (self.short_right, 0)],
]
return rf.Circuit(connections)
@property
def Cs(self) -> List:
"""
Antenna capacitance array [C1, C2, C3, C4] in [pF].
"""
return self._Cs
@Cs.setter
def Cs(self, Cs: NumberLike):
"""
Set antenna capacitance array [C1, C2, C3, C4].
Parameters
----------
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF]
"""
self._Cs = Cs
def circuit(self, Cs: Union[List, None] = None) -> 'Circuit':
"""
Build the antenna circuit for a given set of capacitance.
Parameters
----------
Cs : list or array or None
antenna 4 capacitances [C1, C2, C3, C4] in [pF].
Default is None (use internal Cs).
Returns
-------
circuit: :class:`skrf.circuit.Circuit`
Antenna Circuit
"""
Cs = Cs or self.Cs
self._circuit = self._antenna_circuit(Cs)
return self._circuit
def _optim_fun_one_side(self, C: List, f_match: float = 55e6,
side: str = 'left',
z_match: complex = 29.89 + 0j) -> float:
"""
Optimisation function to match one antenna side.
The function returns the residual defined as:
.. math::
r = (\\Re[Z] - \\Re[Z_{match}])^2 + (\\Im[Z] - \\Im[Z_{match}])^2
Parameters
----------
C : list or array
half-antenna 2 capacitances [Ctop, Cbot] in [pF].
f_match: float, optional
match frequency in [Hz].
Default is 55 MHz.
side : str, optional
antenna side to match: 'left' or 'right'
z_match: complex, optional
antenna feeder characteristic impedance to match on.
Default is 29.89 Ohm
Returns
-------
r : float
Residuals of Z - Z_match
r = (Z_re - np.real(z_match))**2 + (Z_im - np.imag(z_match))**2
"""
# print(C)
Ctop, Cbot = C
if side == "left":
Cs = [Ctop, Cbot, 150, 150]
elif side == "right":
Cs = [150, 150, Ctop, Cbot]
# Create Antenna network for the capacitances Cs
# # from Network ('classic way')
# ntw = half_antenna_network(C, Zload=z_load)
# # from Circuit
self._antenna_match.Cs = Cs
ntw = self._antenna_match.circuit(Cs).network
# retrieve Z and compare to objective
index_f_match = np.argmin(np.abs(ntw.f - f_match))
if side == "left":
Z_re = ntw.z_re[index_f_match, 0, 0].squeeze()
Z_im = ntw.z_im[index_f_match, 0, 0].squeeze()
elif side == "right":
Z_re = ntw.z_re[index_f_match, 1, 1].squeeze()
Z_im = ntw.z_im[index_f_match, 1, 1].squeeze()
r = np.array(
[ # residuals for both real and imaginary parts
(Z_re - np.real(z_match)),
(Z_im - np.imag(z_match)),
]
)
r = (Z_re - np.real(z_match)) ** 2 + (Z_im - np.imag(z_match)) ** 2
return r
def _optim_fun_both_sides(
self,
Cs: List,
f_match: float = 55e6,
z_match: NumberLike = [29.89 + 0j, 29.89 + 0j],
power: NumberLike = [1, 1],
phase: NumberLike = [0, np.pi],
) -> float:
"""
Optimisation function to match both antenna sides.
Optimization is made for active Z parameters, that is taking into
account the antenna excitation.
The residual used for the optimization is calculated as:
.. math::
r = \\sqrt{ \\sum_k |s_{act, k}|^2 }
for the `f_match` frequency.
Parameters
----------
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF].
f_match: float, optional
match frequency in [Hz].
Default is 55 MHz.
z_match: array of complex, optional
antenna feeder characteristic impedance to match on.
Default is [30,30] ohm
power : list or array
Input power at external ports in Watts [W].
Default is [1,1] W.
phase : list or array
Input phase at external ports in radian [rad].
Default is dipole [0,pi] rad.
Returns
-------
r : float
Residual related to Z_act - Z_match
"""
# Create Antenna network for the capacitances Cs
s_act = self._antenna_match.s_act(power, phase, Cs=list(Cs))
# retrieve Z and compare to objective
index_f_match = np.argmin(np.abs(self._antenna_match.f - f_match))
r = np.sqrt(np.sum(np.abs(s_act[index_f_match, :]) ** 2))
if self.DEBUG:
print(Cs, r)
return r
def match_one_side(
self,
f_match: float = 55e6,
solution_number: int = 1,
side: str = "left",
z_match: complex = 29.89 + 0j,
decimals: Union[int, None] = None,
) -> NumberLike:
"""
Search best capacitance to match the specified side of the antenna.
Capacitance of the non-matched side are set to 120 [pF].
Parameters
----------
f_match: float, optional
match frequency in [Hz].
Default is 55 MHz.
solution_number: int, optional
1 or 2: 1 for C_top > C_lower or 2 for C_top < C_lower
side : str, optional
antenna side to match: 'left' or 'right'
z_match: complex, optional
antenna feeder characteristic impedance to match on.
Default is 30 ohm
decimals : int or None, optional
Round the capacitances to the given number of decimals.
Default is None (no rounding)
Returns
-------
Cs_match : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF].
"""
# creates an antenna circuit for single frequency only to speed-up calculations
freq_match = rf.Frequency(f_match, f_match, npoints=1, unit="Hz")
self._antenna_match = WestIcrhAntenna(freq_match, front_face=self.antenna)
# setup constraint optimization to force finding the requested solution
sol_sign = +1 if solution_number == 1 else -1
A = np.array([[1, 0], [0, 1], [sol_sign * -1, sol_sign * 1]])
lb = np.array([12, 12, -np.inf])
ub = np.array([150, 150, 0])
const = scipy.optimize.LinearConstraint(A, lb, ub)
# try finding a solution until it's a physical one.
success = False
while success == False:
# generate a random C sets, centered on 70 +/- 40
# satisfying the solution condition
contin = True
while contin:
C0 = 70 + (-1 + 2 * np.random.rand(2)) * 40
if C0[0] > C0[1] and solution_number == 1:
contin = False
elif C0[0] < C0[1] and solution_number == 2:
contin = False
sol = scipy.optimize.minimize(
self._optim_fun_one_side,
C0,
args=(f_match, side, z_match),
constraints=const,
method="SLSQP",
)
# test if the solution found is the capacitor range
success = sol.success
if (
np.isclose(sol.x, 150).any()
or np.isclose(sol.x, 12).any()
or np.isclose(sol.x[0], sol.x[1])
):
success = False
print("Wrong solution (out of range capacitor) ! Re-doing...")
print(success, f"solution #{solution_number}:", sol.x)
if side == "left":
Cs = [sol.x[0], sol.x[1], 150, 150]
elif side == "right":
Cs = [150, 150, sol.x[0], sol.x[1]]
# round result to realistic values if requested
if decimals:
Cs = list(np.round(Cs, decimals=decimals))
print("Rounded result:", Cs)
return Cs
def match_both_sides_separately(
self,
f_match: float = 55e6,
solution_number: int = 1,
z_match: NumberLike = [29.89 + 0j, 29.87 + 0j],
decimals: Union[int, None] = None,
) -> NumberLike:
"""
Match both sides separatly and returns capacitance values for each sides.
Match the left side with right side unmatched, then match the right side
with the left side unmatched. Combine the results
Parameters
----------
f_match: float, optional
match frequency in [Hz]. Default is 55 MHz.
solution_number: int, optional
1 or 2: 1 for C_top > C_lower or 2 for C_top < C_lower
z_match: complex, optional
antenna feeder characteristic impedance to match on. Default is 30 ohm
decimals : int, optional
Round the capacitances to the given number of decimals. Default is None (no rounding)
Returns
-------
Cs_match : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF].
"""
C_left = self.match_one_side(
side="left",
f_match=f_match,
solution_number=solution_number,
z_match=z_match[0],
decimals=decimals,
)
C_right = self.match_one_side(
side="right",
f_match=f_match,
solution_number=solution_number,
z_match=z_match[1],
decimals=decimals,
)
C_match = [C_left[0], C_left[1], C_right[2], C_right[3]]
return C_match
def match_both_sides(
self,
f_match: float = 55e6,
power: NumberLike = [1, 1],
phase: NumberLike = [0, np.pi],
solution_number: int = 1,
z_match: NumberLike = [29.89 + 0j, 29.89 + 0j],
decimals: Union[int, None] = None,
method: str = 'SLSQP',
C0: Union[None, list] = None,
delta_C: float = 5,
maxiter: int = 500
) -> NumberLike:
"""
Match both sides at the same time for a given frequency target.
Optimization is made for active Z parameters, that is taking into
account the antenna excitation.
Parameters
----------
f_match: float, optional
match frequency in [Hz]. Default is 55 MHz.
solution_number: int, optional
1 or 2: 1 for C_top > C_lower or 2 for C_top < C_lower
z_match: array of complex, optional
antenna feeder characteristic impedance to match on. Default is 30 ohm
decimals : int, optional
Round the capacitances to the given number of decimals. Default is None (no rounding)
power : list or array
Input power at external ports in Watts [W]. Default is [1, 1] W.
phase : list or array
Input phase at external ports in radian [rad]. Defalt is dipole [0, pi] rad.
method : str, optional
Scipy Optimization mathod. 'SLSQP' (default) or 'COBYLA'
C0 : list or None, optional
Initial guess of the matching point. If None, the initial guess
is obtained from matching both sides separately. Default is None.
delta_C : float, optional
Maximum capacitance shift to look for a solution. Default is 5.
maxiter : int
Maximum number of optimization function evaluations.
Returns
-------
Cs_match : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF].
"""
self._steps = [] # to keep track of minimizer intermediate steps
# creates an antenna circuit for a single frequency only to speed-up calculations
freq_match = rf.Frequency(f_match, f_match, npoints=1, unit="Hz")
self._antenna_match = WestIcrhAntenna(freq_match, front_face=self.antenna)
# setup constraint optimization to force finding the requested solution
sol_sign = +1 if solution_number == 1 else -1
A = np.array(
[
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1],
[sol_sign * -1, sol_sign * 1, 0, 0],
[0, 0, sol_sign * -1, sol_sign * 1],
]
)
lb = np.array([12, 12, 12, 12, -np.inf, -np.inf])
ub = np.array([150, 150, 150, 150, 0, 0])
const = scipy.optimize.LinearConstraint(A, lb, ub)
if not C0:
# initial guess from both side separately
print("Looking for individual solutions separately for 1st guess...")
C0 = self.match_both_sides_separately(
f_match=f_match,
solution_number=solution_number,
z_match=z_match,
decimals=decimals,
)
print("Searching for the active match point solution...")
success = False
while success == False:
print(f"Reducing search range to +/- {delta_C}pF around individual solutions")
lb = np.array([C0[0]-delta_C, C0[1]-delta_C, C0[2]-delta_C, C0[3]-delta_C, -np.inf, -np.inf])
ub = np.array([C0[0]+delta_C, C0[1]+delta_C, C0[2]+delta_C, C0[3]+delta_C, 0, 0])
const = scipy.optimize.LinearConstraint(A, lb, ub)
if method == 'SLSQP':
sol = scipy.optimize.minimize(
self._optim_fun_both_sides, C0,
args=(f_match, z_match, power, phase),
constraints=const, method='SLSQP',
options={'disp': self.DEBUG, 'ftol': 1e-3, 'maxiter': maxiter},
callback=self._callback
)
elif method == 'COBYLA':
sol = scipy.optimize.minimize(
self._optim_fun_both_sides, C0,
args=(f_match, z_match, power, phase),
constraints=const,
method="COBYLA",
options={"disp": self.DEBUG, 'rhobeg': 0.01, 'maxiter': maxiter},
)
else:
raise ValueError(f'Optimisation method {method} is unknow.')
# test if the solution found is the capacitor range
success = sol.success
if (
np.isclose(sol.x, 150).any()
or np.isclose(sol.x, 12).any()
or np.isclose(sol.x[0], sol.x[1])
or np.isclose(sol.x[2], sol.x[3])
):
success = False
print("Wrong solution (out of range capacitor) ! Re-doing...")
print(success, f"solution #{solution_number}:", sol.x)
Cs = [sol.x[0], sol.x[1], sol.x[2], sol.x[3]]
# round result to realistic values if requested
if decimals:
Cs = list(np.round(Cs, decimals=decimals))
print("Rounded result:", Cs)
return Cs
def _callback(self, xk, step=[0]):
""" Store intermediate steps of the minimizer.
"""
self._steps.append(xk)
def optimum_frequency_index(self, power: NumberLike, phase: NumberLike,
Cs: Union[NumberLike, None] = None) -> NumberLike:
"""
Array indexes of the optimum frequency with respect to active S-parameters for a given excitation.
Parameters
----------
power : list or array
Input power at external ports in Watts [W]
phase : list or array
Input phase at external ports in radian [rad]
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF]. Default is None (use internal Cs)
Returns
-------
f_opt_idx : array (2x1)
array indexes of the optimum frequencies for each sides of the antenna
"""
# use internal capacitances if not passed
Cs = Cs or self.Cs
# active S-parameters for dipole excitation
s_act = self.s_act(power, phase, Cs=Cs)
f_opt_idx = np.argmin(np.abs(s_act), axis=0)
return f_opt_idx
def optimum_frequency(self, power: NumberLike, phase: NumberLike,
Cs: Union[NumberLike, None] = None) -> NumberLike:
"""
Optimum frequency with respect to active S-parameters for a given excitation.
Parameters
----------
power : list or array
Input power at external ports in Watts [W]
phase : list or array
Input phase at external ports in radian [rad]
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF]. Default is None (use internal Cs)
Returns
-------
f_opt : array (2x1)
optimum frequencies for each sides of the antenna
"""
# use internal capacitances if not passed
Cs = Cs or self.Cs
f_opt = self.frequency.f[self.optimum_frequency_index(power, phase, Cs=Cs)]
return f_opt
def _Xs(self, f: Union[NumberLike, None] = None) -> NumberLike:
"""
Strap Reactance fit with frequency.
This fit is obtained from the full-wave simulation of the front-face
in vacuum.
Parameters
----------
f : array or None, optional
frequency in Hz.
Default is None (uses internal frequency)
Returns
-------
Xs : real array
strap reactance (nb_f, 1)
"""
f = f or self.frequency.f
# scaled frequency
f_MHz = f / 1e6
Xs = 1.66e-04 * f_MHz ** 3 - 1.53e-02 * f_MHz ** 2 + 1.04 * f_MHz - 7.77
return Xs
def load(self, Rc: float, Xs: Union[float, None] = None):
"""
Load the antenna model with an ideal plasma load (no poloidal and toroidal cross coupling).
Parameters
----------
Rc : float
Coupling Resistance [Ohm]
Xs : float, optional
Strap reactance.
The default is None (uses frequency best fit).
Returns
-------
None.
"""
# reactance : if not passed, use best fit
Xs = Xs or self._Xs()
# interpolating the default z0 with the one of the CAD model
# to keep the same z0 behaviour
f = rf.interp1d(self._antenna.f, self._antenna.z0[:, 0])
_z0 = f(self.f)
# port and short definitions
_port1 = rf.Circuit.Port(self.frequency, "Port1", z0=_z0)
_port2 = rf.Circuit.Port(self.frequency, "Port2", z0=_z0)
_port3 = rf.Circuit.Port(self.frequency, "Port3", z0=_z0)
_port4 = rf.Circuit.Port(self.frequency, "Port4", z0=_z0)
_short1 = rf.Circuit.Ground(self.frequency, "Gnd1", z0=_z0)
_short2 = rf.Circuit.Ground(self.frequency, "Gnd2", z0=_z0)
_short3 = rf.Circuit.Ground(self.frequency, "Gnd3", z0=_z0)
_short4 = rf.Circuit.Ground(self.frequency, "Gnd4", z0=_z0)
# load definition
z_s = Rc + 1j * Xs
media = rf.DefinedGammaZ0(frequency=self.frequency, z0=_z0)
_load1 = media.resistor(z_s, name="load1", z0=_z0)
_load2 = media.resistor(z_s, name="load2", z0=_z0)
_load3 = media.resistor(z_s, name="load3", z0=_z0)
_load4 = media.resistor(z_s, name="load4", z0=_z0)
cnx = [
[(_port1, 0), (_load1, 0)],
[(_load1, 1), (_short1, 0)],
[(_port2, 0), (_load2, 0)],
[(_load2, 1), (_short2, 0)],
[(_port3, 0), (_load3, 0)],
[(_load3, 1), (_short3, 0)],
[(_port4, 0), (_load4, 0)],
[(_load4, 1), (_short4, 0)],
]
crt = rf.Circuit(cnx)
_antenna = crt.network
_antenna.name = "antenna"
self.antenna = _antenna
def b(self, a: NumberLike, Cs: Union[NumberLike, None] = None) -> NumberLike:
"""
Reflected power-wave from a given input power-wave, defined by b=S x a.
Parameters
----------
a : array
input power-wave array
Cs : list or array or None
antenna 4 capacitances [C1, C2, C3, C4] in [pF].
Default is None (use internal Cs)
Returns
-------
b : array
output power-wave array
"""
Cs = Cs or self.Cs # if not passed use internal Cs
a_left, a_right = a
# power waves
_a = np.zeros(self.circuit(Cs).s.shape[1], dtype="complex")
# left input
_a[21] = a_left
# right input
_a[23] = a_right
self._b = self._circuit.s @ _a
return self._b
def _currents(self, power: NumberLike, phase: NumberLike,
Cs: Union[NumberLike, None] = None) -> NumberLike:
"""
Currents at the antenna front face ports (after capacitors).
OLD EVALUATION BEFORE CIRCUIT IMPLEMENTS VOLTAGE AND CURRENTS
Parameters
----------
power : list or array
Input power at external ports in Watts [W]
phase : list or array
Input phase at external ports in radian [rad]
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF]. Default is None (use internal Cs)
Returns
-------
Is : complex array (nb_f,4)
Currents at antenna front face ports [I1, I2, I3, I4]
Example
-------
>>> I1, I2, I3, I4 = west_antenna._currents([1, 1], [0, pi])
"""
Cs = Cs or self.Cs # if not passed use internal Cs
a = self.circuit(Cs)._a_external(power, phase)
b = self.b(a, Cs)
I1 = (b[:, 0] - b[:, 1]) / np.sqrt(self.antenna.z0[:, 0])
I2 = (b[:, 4] - b[:, 5]) / np.sqrt(self.antenna.z0[:, 2])
I3 = (b[:, 2] - b[:, 3]) / np.sqrt(self.antenna.z0[:, 1])
I4 = (b[:, 6] - b[:, 7]) / np.sqrt(self.antenna.z0[:, 3])
return np.c_[I1, I2, I3, I4]
def _voltages(self, power: NumberLike, phase: NumberLike,
Cs: Union[NumberLike, None] = None) -> NumberLike:
"""
Voltages at the antenna front face ports (after capacitors).
OLD EVALUATION BEFORE CIRCUIT IMPLEMENTS VOLTAGE AND CURRENTS
Parameters
----------
power : list or array
Input power at external ports in Watts [W]
phase : list or array
Input phase at external ports in radian [rad]
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF]. Default is None (use internal Cs)
Returns
-------
Vs : complex array (nb_f,4)