elcocodrilotito

cavity class

Aug 5th, 2024
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.91 KB | None | 0 0
  1. import numpy as np
  2. from scipy.signal import argrelextrema
  3.  
  4. class Device:
  5.     def __init__(self, fc, Q, kin_factor, fe, gamma, C):
  6.         self.Q = Q
  7.         self.fc = fc
  8.         self.wc = 2*np.pi*fc
  9.        
  10.         self.k = 2*np.pi*self.fc/self.Q # Decay rate
  11.         self.Af_c = self.fc/self.Q # Cavity linewidth
  12.  
  13.         self.kin = kin_factor*self.k # Waveguide coupling rate
  14.    
  15.         self.fe = fe
  16.         self.we = 2*np.pi*fe
  17.         self.gamma = gamma
  18.  
  19.         self.C = C
  20.         self.g = np.sqrt(self.C*self.k*self.gamma/4)
  21.  
  22.         self.span = 4*self.Af_c
  23.  
  24.         self.Ace = (fe-fc)/1e9
  25.    
  26.     def r(self, fp):
  27.         wp = 2*np.pi*fp
  28.         return 1-self.kin/(1j*(wp-self.wc)+self.k/2+self.g**2/(1j*(wp-self.we)+self.gamma/2))
  29.    
  30.     def R(self, fp):
  31.         return np.abs(self.r(fp))**2
  32.    
  33.     def phase(self, fp):
  34.         return np.angle(self.r(fp))
  35.    
  36.     def find_extrema(self):
  37.         fp = np.linspace(self.fc-self.span, self.fc+self.span, 1000000)
  38.         x_axis = (fp-self.fc)/1e9
  39.         R = self.R(fp)
  40.  
  41.         # Finding local extrema
  42.         # Local maxima
  43.         maxima = argrelextrema(R, np.greater_equal)
  44.         f_max = x_axis[maxima]
  45.         R_max = R[maxima]
  46.  
  47.         # Local minima
  48.         minima = argrelextrema(R, np.less_equal)
  49.         f_min = x_axis[minima]
  50.         R_min = R[minima]
  51.  
  52.         # Find extrema closest to emitter frequency
  53.         index_high = np.argmin(np.abs(f_max-self.Ace))
  54.         f_high = f_max[index_high]
  55.         R_high = R_max[index_high]
  56.         index_low = np.argmin(np.abs(f_min-self.Ace))
  57.         f_low = f_min[index_low]
  58.         R_low = R_min[index_low]
  59.  
  60.         return [f_high, R_high, f_low, R_low]
  61.    
  62.     def find_overlapping_splitting(self):
  63.         f_high, R_high, f_low, R_low = self.find_extrema()
  64.  
  65.         res = 100
  66.         Ass = np.linspace(0, 2*(f_low-f_high), res) # Spin splitting (GHz)
  67.  
  68.         fp = np.linspace(self.fe-2*Ass*1e9, self.fe+2*Ass*1e9, 10000)
  69.         x_axis = (fp-self.fc)/1e9
  70.         wp = 2*np.pi*fp
  71.  
  72.         diff = np.zeros(np.shape(Ass))
  73.         for i, Ass_i in enumerate(Ass):
  74.             we_i = self.we + 2*np.pi*Ass_i*1e9
  75.             r_i = 1-self.kin/(1j*(wp-self.wc)+self.k/2+self.g**2/(1j*(wp-we_i)+self.gamma/2))
  76.             R_i = np.abs(r_i)**2
  77.  
  78.             # Finding local extrema
  79.             # Local maxima
  80.             maxima_i = argrelextrema(R_i, np.greater)
  81.             f_max_i = x_axis[maxima_i]
  82.             R_max_i = R_i[maxima_i]
  83.  
  84.             # Find extrema closest to emitter frequency
  85.             Ace_i = self.Ace + Ass_i
  86.             index_high_i = np.argmin(np.abs(f_max_i-Ace_i))
  87.             f_high_i = f_max_i[index_high_i]
  88.             R_high_i = R_max_i[index_high_i]
  89.            
  90.             diff[i] = np.abs(f_high_i - f_low)
  91.  
  92.         index_overlap_high_low = np.argmin(diff)
  93.         Ass_overlap = Ass[index_overlap_high_low]
  94.  
  95.         return Ass_overlap
Add Comment
Please, Sign In to add comment