|  | 
| 1 |  | -from numpy import* | 
| 2 |  | -from pylab import* | 
|  | 1 | +import numpy asnp | 
|  | 2 | +import pylab aspl | 
| 3 | 3 | import timeit | 
| 4 | 4 | import dbrprop | 
| 5 | 5 | 
 | 
|  | 6 | + | 
| 6 | 7 | class DBRMirror: | 
| 7 |  | - def __init__(self, data): | 
|  | 8 | + def __init__(self, data, incidentwavelength): | 
| 8 | 9 |  if isinstance(data, str): | 
| 9 |  | - data = loadtxt(data) | 
|  | 10 | + data = np.loadtxt(data) | 
| 10 | 11 |  self.n = data[:, 0] | 
| 11 |  | - self.d = array(concatenate(([0], data[1:-1, 1], [0]))) | 
|  | 12 | + self.d = np.array(np.concatenate(([0], data[1:-1, 1], [0]))) | 
|  | 13 | + self.r = self.reflection_coeff(incidentwavelength) | 
|  | 14 | + self.R = np.abs(self.r)**2 | 
|  | 15 | + self.GD = (self.r.imag * self.diff_omega(self.r.real, incidentwavelength) - self.r.real * self.diff_omega(self.r.imag, incidentwavelength))/self.R | 
|  | 16 | + self.GDD = self.diff_omega(self.GD, incidentwavelength) | 
| 12 | 17 | 
 | 
| 13 | 18 |  def reflection_coeff(self, incidentwavelength): | 
| 14 | 19 |  nm = (self.n[:-1] / self.n[1:]) | 
| 15 |  | - R = array([]) | 
|  | 20 | + r = np.empty(incidentwavelength.size) + 0j | 
|  | 21 | + i = 0 | 
| 16 | 22 |  for wavelength in incidentwavelength: | 
| 17 |  | - phi = 2j * pi * self.n[:-1] * self.d[:-1] / wavelength | 
| 18 |  | - transition_matrix = array([[0.5 * (1 + nm) * exp(-phi), 0.5 * (1 - nm) * exp(phi)], | 
| 19 |  | - [0.5 * (1 - nm) * exp(-phi), 0.5 * (1 + nm) * exp(phi)]]) | 
|  | 23 | + phi = 2j * np.pi * self.n[:-1] * self.d[:-1] / wavelength | 
|  | 24 | + transition_matrix = np.array([[0.5 * (1 + nm) * np.exp(-phi), 0.5 * (1 - nm) * np.exp(phi)], | 
|  | 25 | + [0.5 * (1 - nm) * np.exp(-phi), 0.5 * (1 + nm) * np.exp(phi)]]) | 
| 20 | 26 | 
 | 
| 21 | 27 |  general_transition_matrix = 1 | 
| 22 | 28 |  for k in range(self.n.size - 2, -1, -1): | 
| 23 |  | - general_transition_matrix = dot(general_transition_matrix, transition_matrix[:, :, k]) | 
|  | 29 | + general_transition_matrix = np.dot(general_transition_matrix, transition_matrix[:, :, k]) | 
| 24 | 30 | 
 | 
| 25 |  | - r = - general_transition_matrix.item(2) / general_transition_matrix.item(3) | 
| 26 |  | - # R = append(R, abs(r)**2) | 
| 27 |  | - R=append(R, r) | 
|  | 31 | + r[i] = - general_transition_matrix.item(2) / general_transition_matrix.item(3) | 
|  | 32 | + i+=1 | 
|  | 33 | + returnr | 
| 28 | 34 | 
 | 
| 29 |  | - phi=arctan(imag(R) /real(R)) | 
|  | 35 | + defdiff_omega(self, y, incidentwavelength): | 
| 30 | 36 |  c = 29.9792458 # in nm/fs | 
| 31 |  | - GDD = incidentwavelength ** 2 / (2 * pi * c) * gradient(incidentwavelength ** 2 / (2 * pi * c) * gradient(phi)) | 
| 32 |  | - return GDD | 
|  | 37 | + return (-incidentwavelength ** 2 / (2 * np.pi * c)) * np.gradient(y, incidentwavelength) | 
| 33 | 38 | 
 | 
|  | 39 | + # def diff_omega(self, y, incidentwavelength): | 
|  | 40 | + # res = np.zeros_like(y) | 
|  | 41 | + # res[1] = ((y[2] - y[1])/(incidentwavelength[2] - incidentwavelength[1])) | 
|  | 42 | + # res[-1] = ((y[-1] - y[-2])/(incidentwavelength[-1] - incidentwavelength[-2])) | 
|  | 43 | + # for n in range (2, y.__len__()-1): | 
|  | 44 | + # res[n] = (((y[n] - y[n-1]) / (incidentwavelength[n] - incidentwavelength[n-1])) | 
|  | 45 | + # + ((y[n+1] - y[n]) / (incidentwavelength[n+1] - incidentwavelength[n]))) | 
|  | 46 | + # c = 29.9792458 # in nm/fs | 
|  | 47 | + # return - incidentwavelength ** 2 / (2 * np.pi * c) * res | 
| 34 | 48 | 
 | 
| 35 |  | -start = timeit.default_timer() | 
| 36 | 49 | 
 | 
| 37 |  | -# data = array([ | 
| 38 |  | -# [1.0, inf], | 
| 39 |  | -# [3.5, 74.0], | 
| 40 |  | -# [3.0, 92.5], | 
| 41 |  | -# [3.5, 74.0], | 
| 42 |  | -# [3.0, 92.5], | 
| 43 |  | -# [3.5, 74.0], | 
| 44 |  | -# [3.0, 92.5], | 
| 45 |  | -# [3.5, inf] | 
| 46 |  | -# ]) | 
|  | 50 | +start = timeit.default_timer() | 
|  | 51 | +wavelength = np.linspace(800, 1200, 1000) | 
|  | 52 | +NewMirror = DBRMirror("dbr.txt", wavelength) | 
| 47 | 53 | 
 | 
| 48 |  | -New = dbrprop.DBRprop() | 
| 49 |  | -NewMirror=DBRMirror(New.data) | 
|  | 54 | +stop = timeit.default_timer() | 
|  | 55 | +print(stop-start) | 
| 50 | 56 | 
 | 
| 51 |  | -wavelength = array(linspace(400, 4000, 1000)) | 
|  | 57 | +pl.figure() | 
|  | 58 | +pl.plot(wavelength, NewMirror.R) | 
|  | 59 | +pl.xlabel("$\lambda$") | 
|  | 60 | +pl.ylabel("R") | 
|  | 61 | +pl.xlim((950,1150)) | 
|  | 62 | +pl.show(block=False) | 
| 52 | 63 | 
 | 
| 53 |  | -gdd = NewMirror.reflection_coeff(wavelength) | 
|  | 64 | +pl.figure() | 
|  | 65 | +pl.plot(wavelength, NewMirror.GDD) | 
|  | 66 | +pl.xlabel("$\lambda$") | 
|  | 67 | +pl.ylabel("GDD [fs**2]") | 
|  | 68 | +pl.xlim((1000,1080)) | 
|  | 69 | +pl.show() | 
| 54 | 70 | 
 | 
| 55 |  | -stop = timeit.default_timer() | 
| 56 |  | -print(stop - start) | 
| 57 | 71 | 
 | 
| 58 |  | -plot(wavelength, gdd) | 
| 59 |  | -xlabel("$\lambda$") | 
| 60 |  | -ylabel("GDD [fs**2]") | 
| 61 |  | -show() | 
|  | 
0 commit comments