Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4e050c4

Browse files
author
Ramzi Hadrich
committed
actual version
1 parent 62daa54 commit 4e050c4

File tree

1 file changed

+33
-71
lines changed

1 file changed

+33
-71
lines changed

‎dbr.py

Lines changed: 33 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,41 @@
11
import numpy as np
22
import pylab as pl
3-
import timeit
4-
import dbrprop
53

64

75
class DBRMirror:
8-
def __init__(self, data, incidentwavelength):
9-
if isinstance(data, str):
10-
data = np.loadtxt(data)
11-
self.n = data[:, 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)
6+
def __init__(self, data, incidentwavelength):
7+
if isinstance(data, str):
8+
data = np.loadtxt(data)
9+
if data.ndim == 1:
10+
self.n = np.loadtxt("dbr.txt")[:, 0]
11+
self.d = data
12+
else:
13+
self.n = data[:, 0]
14+
self.d = np.array(np.concatenate(([0], data[1:-1, 1], [0])))
15+
self.r = self.reflection_coeff(incidentwavelength)
16+
self.R = np.abs(self.r)**2
17+
self.GD = (self.r.imag * self.diff_omega(self.r.real, incidentwavelength) - self.r.real * self.diff_omega(self.r.imag, incidentwavelength))/self.R
18+
self.GDD = self.diff_omega(self.GD, incidentwavelength)
19+
20+
def reflection_coeff(self, incidentwavelength):
21+
nm = (self.n[:-1] / self.n[1:])
22+
general_transition_matrix = np.broadcast_to(np.eye(2, dtype= complex), (incidentwavelength.shape[0], 2, 2))
23+
24+
for i in range(0, self.n.shape[0]-1):
25+
phi = 2j * np.pi * self.n[i+1] * self.d[i+1] / incidentwavelength
26+
transition_matrix = np.array([[0.5 * (1 + nm[i]) * np.exp(-phi), 0.5 * (1 - nm[i]) * np.exp(phi)],
27+
[0.5 * (1 - nm[i]) * np.exp(-phi), 0.5 * (1 + nm[i]) * np.exp(phi)]])
28+
29+
transition_matrix = np.swapaxes(transition_matrix, 2, 0)
30+
transition_matrix = np.swapaxes(transition_matrix, 2, 1)
31+
general_transition_matrix = np.array(list(map(lambda x, y: np.dot(x, y), general_transition_matrix, transition_matrix)))
32+
33+
r = - general_transition_matrix[:,1,0] / general_transition_matrix[:,1,1]
34+
return r
35+
36+
def diff_omega(self, y, incidentwavelength):
37+
c = 299.792458 # in nm/fs
38+
return (-incidentwavelength ** 2 / (2 * np.pi * c)) * np.gradient(y, incidentwavelength)
1739

18-
def reflection_coeff(self, incidentwavelength):
19-
nm = (self.n[:-1] / self.n[1:])
20-
r = np.empty(incidentwavelength. size) + 0j
21-
general_transition_matrix = np.broadcast_to(np.eye(2, dtype= complex), (incidentwavelength.shape[0], 2, 2))
22-
23-
for i in range(0, self.n.shape[0]-1):
24-
phi = 2j * np.pi * self.n[i+1] * self.d[i+1] / incidentwavelength
25-
transition_matrix = np.array([[0.5 * (1 + nm[i]) * np.exp(-phi), 0.5 * (1 - nm[i]) * np.exp(phi)],
26-
[0.5 * (1 - nm[i]) * np.exp(-phi), 0.5 * (1 + nm[i]) * np.exp(phi)]])
27-
28-
transition_matrix = np.swapaxes(transition_matrix, 2, 0)
29-
transition_matrix = np.swapaxes(transition_matrix, 2, 1)
30-
general_transition_matrix = np.array(list(map(lambda x, y: np.dot(x, y), general_transition_matrix, transition_matrix)))
31-
32-
r = - general_transition_matrix[:,1,0] / general_transition_matrix[:,1,1]
33-
return r
34-
35-
def diff_omega(self, y, incidentwavelength):
36-
c = 299.792458 # in nm/fs
37-
return (-incidentwavelength ** 2 / (2 * np.pi * c)) * np.gradient(y, incidentwavelength)
38-
39-
40-
start = timeit.default_timer()
41-
wavelength = np.linspace(800, 1200, 1000)
42-
NewMirror = DBRMirror("dbr.txt", wavelength)
43-
44-
stop = timeit.default_timer()
45-
print(stop - start)
46-
sR = np.loadtxt("s245-R.txt", unpack=True)
47-
sGD = np.loadtxt("s245-GD.txt", unpack=True)
48-
sGDD = np.loadtxt("s245-GDD.txt", unpack=True)
49-
50-
51-
f = pl.figure()
52-
pl.plot(wavelength, NewMirror.R)
53-
pl.plot(*sR)
54-
pl.xlabel("$\lambda$")
55-
pl.ylabel("R")
56-
pl.xlim(950, 1150)
57-
pl.show(block=False)
58-
f.canvas.set_window_title("R")
59-
60-
f = pl.figure()
61-
pl.plot(wavelength, NewMirror.GD)
62-
pl.plot(*sGD)
63-
pl.xlabel("$\lambda$")
64-
pl.ylabel("GD [fs]")
65-
pl.xlim(950, 1150)
66-
f.canvas.set_window_title("GD")
67-
68-
f = pl.figure()
69-
pl.plot(wavelength, NewMirror.GDD)
70-
pl.plot(*sGDD)
71-
pl.xlabel("$\lambda$")
72-
pl.ylabel("GDD [fs$^2$]")
73-
pl.xlim(1000, 1080)
74-
pl.ylim(-1000, 0)
75-
f.canvas.set_window_title("GDD")
76-
77-
pl.show()
7840

7941

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /