<jupyter_start><jupyter_text>Phase Scan Effect on Antenna Voltage UnbalanceIn this notebook we explore the effect of a phase scan over the voltage unbalance.<jupyter_code>%load_ext autoreload
%autoreload 2
import matplotlib.pyplot as plt
import numpy as np
import skrf as rf
from tqdm.notebook import tqdm

# WEST ICRH Antenna package
import sys; sys.path.append('..')
from west_ic_antenna import WestIcrhAntenna
# nicer plot
rf.stylely()<jupyter_output><empty_output><jupyter_text>Let's use a TOPICA simulation of the WEST front face in a "L-mode plasma" at 55 MHz:<jupyter_code>freq = rf.Frequency(start=50, stop=60, npoints=1001, unit='MHz')
plasma_TOPICA = '../west_ic_antenna/data/Sparameters/front_faces/TOPICA/S_TSproto12_55MHz_Hmode_LAD6-2.5cm.s4p'

antenna = WestIcrhAntenna(frequency=freq, front_face=plasma_TOPICA)
print(f'Optimal coupling resistance expected:', antenna.front_face_Rc().max())<jupyter_output>Optimal coupling resistance expected: 1.6095500081638645<jupyter_text>First, we match the antenna, both sides at the same time to operate the antenna at 55 MHz.<jupyter_code># antenna excitation to match for
power = [1, 1]  # W
phase = [0, np.pi]  # dipole

Cs = antenna.match_both_sides(f_match=55e6, power=power, phase=phase, 
                              solution_number=1)<jupyter_output>Looking for individual solutions separately for 1st guess...
True solution #1: [53.55296435 46.40953715]
Wrong solution (out of range capacitor) ! Re-doing...
False solution #1: [150. 150.]
True solution #1: [53.17919956 46.56525553]
Searching for the active match point solution...
True solution #1: [54.14662724 46.73409217 53.85622982 46.9009773 ]<jupyter_text>Let's visualize how good the antenna is matched for the target frequency, by looking to the active S parameters (ie. taking into account the antenna excitation)<jupyter_code>s_act = antenna.s_act(power=power, phase=phase, Cs=Cs)

fig, ax = plt.subplots()
ax.plot(antenna.f_scaled, 20*np.log10(np.abs(s_act)), lw=2)
ax.set_xlabel('Frequency [MHz]')
ax.set_ylabel('Sact [dB]')
ax.legend(('Left side', 'Right side'))
ax.axvline(55, ls='--', color='gray')<jupyter_output><empty_output><jupyter_text>Now that the antenna is perfeclty matched, let's see how the voltages evolve with frequency. At the match frequency, the voltages (and currents) get very close: the antenna is balanced.<jupyter_code>fig, ax = plt.subplots()
ax.plot(antenna.f_scaled, np.abs(antenna.voltages(power, phase, Cs)), lw=2)
ax.axvline(55, ls='--', color='gray')
ax.set_xlabel('Frequency [MHz]')
ax.set_ylabel('Voltage [V]')
ax.legend(('V1', 'V2', 'V3', 'V4'), ncol=4)<jupyter_output><empty_output><jupyter_text>Note that the antenna voltages are not perfectly balanced at the match point, which is expected due to the intercouplings:<jupyter_code>fig, (ax1,ax2) = plt.subplots(2, 1, sharex=True)
ax1.plot(antenna.f_scaled, np.abs(antenna.voltages(power, phase, Cs)), lw=2)
[a.axvline(55, ls='--', color='gray') for a in (ax1,ax2)]
ax2.set_xlabel('Frequency [MHz]')
ax1.set_ylabel('Voltage [V]')
ax1.legend(('V1', 'V2', 'V3', 'V4'), ncol=4)
ax1.set_xlim(54.7, 55.3)
ax1.set_ylim(25, 37)
ax2.plot(antenna.f_scaled, 20*np.log10(np.abs(s_act)), lw=2)
fig.subplots_adjust(hspace=0)<jupyter_output><empty_output><jupyter_text>So let's see how the voltages evolve at the match frequency when we sweep the phase shift between sides:<jupyter_code>power = [1e6, 1e6]  # 1 MW each side
toroidal_phases = np.deg2rad(np.linspace(start=0, stop=360, num=36))
antenna_single_freq = WestIcrhAntenna(frequency=rf.Frequency(55, 55, 1, unit='MHz'),
                                     front_face=plasma_TOPICA, Cs=Cs) 

voltages, currents, Rcs = [], [], []
for toroidal_phase in tqdm(toroidal_phases):
    voltages.append(antenna_single_freq.voltages(power, phase=[0, toroidal_phase]))
    currents.append(antenna_single_freq.voltages(power, phase=[0, toroidal_phase]))
    Rcs.append(antenna_single_freq.Rc_WEST(power, phase=[0, toroidal_phase]))
voltages = np.array(voltages).squeeze()
currents = np.array(currents).squeeze()
Rcs = np.array(Rcs).squeeze()
# export data
np.savetxt('voltages_vs_phase.csv', 
           np.c_[np.rad2deg(toroidal_phases), np.abs(voltages)])
fig, ax = plt.subplots()
ax.plot(np.rad2deg(toroidal_phases), np.abs(voltages)/1e3, lw=2)
ax.axvline(180, ls='--', color='gray')
ax.set_xlabel('Toroidal Phase [deg]')
ax.set_ylabel('Volttage [kV]')
ax.legend(('V1', 'V2', 'V3', 'V4'), ncol=4)
ax.set_ylim(0,50)<jupyter_output><empty_output><jupyter_text>The phase sweep generates voltage (or currents) unbalance. The voltage probe toroidal phase difference is also slightly affected in this case:<jupyter_code>fig, ax = plt.subplots()
ax.plot(np.rad2deg(toroidal_phases), np.rad2deg(np.angle(voltages[:,2]) - np.angle(voltages[:,0]))%360, lw=2)
ax.plot(np.rad2deg(toroidal_phases), np.rad2deg(np.angle(voltages[:,3]) - np.angle(voltages[:,1]))%360, lw=2)
ax.plot(np.rad2deg(toroidal_phases), np.rad2deg(toroidal_phases), color='k', ls='--')
ax.axvline(180, ls='--', color='gray')
ax.set_xlabel('Toroidal Phase [deg]')
ax.set_ylabel('Phase [deg]')
ax.legend(('$\Delta  \phi$ $V_3-V_1$', '$\Delta  \phi$ $V_4-V_2$'))<jupyter_output><empty_output><jupyter_text>Coupling resistance, which is deduced from the currents, is of course also affected:<jupyter_code>fig, ax = plt.subplots()
ax.plot(np.rad2deg(toroidal_phases), Rcs, lw=2)
ax.axvline(180, ls='--', color='gray')
ax.set_xlabel('Toroidal Phase [deg]')
ax.set_ylabel('Coupling Resistances [Ohm]')
ax.legend(('Left', 'Right'), ncol=4)
ax.set_ylim(0,1.3)
from IPython.core.display import HTML
def _set_css_style(css_file_path):
    """
    Read the custom CSS file and load it into Jupyter
    Pass the file path to the CSS file
    """
    styles = open(css_file_path, "r").read()
    s = '<style>%s</style>' % styles
    return HTML(s)

_set_css_style('custom.css')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1488135593220339, 'fraction_numerical': 0.043559322033898305, 'mean_word_length': 5.975177304964539, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '93097', 'license': 'MIT', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2247, 'n_words': 505, 'path': 'doc/phase_scan.ipynb', 'repo_name': 'jhillairet/WEST_IC_antenna', 'size': '5900'}