Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions EMpy/RCWA.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ def get_pitch(self):
if idx.size == 0:
# warning('no BinaryGratings: better use a simple transfer matrix.')
return 1.0 # return LAMBDA: any value will do
# check that all the pitches are the same!
l = S.asarray([self.multilayer[i].pitch for i in idx])
if S.all(l == l[0]):
return l[0]

else:
# check that all the pitches are the same!
l = S.asarray([self.multilayer[i].pitch for i in idx])
if not S.all(l == l[0]):
raise ValueError("All the BinaryGratings must have the same pitch.")
else:
return l[0]
raise ValueError("All the BinaryGratings must have the same pitch.")
Comment on lines +165 to +171
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RCWA.get_pitch refactored with the following changes:



class IsotropicRCWA(RCWA):
Expand Down
21 changes: 9 additions & 12 deletions EMpy/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,17 +985,16 @@ def CM(self, wl=None):

if wl is None:
wl = self.wl
Hs = []
for K, neff, l1, l2 in zip(self.Ks, self.neffs, self.l1s, self.l2s):
Hs.append(
composeTMlist(
[
Line(self.wl, neff, 0.0, neff, l1).TM(wl),
K.TM(wl),
Line(self.wl, neff, 0.0, neff, l2).TM(wl),
]
)
Hs = [
composeTMlist(
[
Line(self.wl, neff, 0.0, neff, l1).TM(wl),
K.TM(wl),
Line(self.wl, neff, 0.0, neff, l2).TM(wl),
]
)
for K, neff, l1, l2 in zip(self.Ks, self.neffs, self.l1s, self.l2s)
]
Comment on lines -988 to +997
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NRR.CM refactored with the following changes:

return composeCM(composeTMlist(Hs), self.Ks[-1].CM(wl))


Expand Down Expand Up @@ -1330,8 +1329,6 @@ def solve(self, wls):
pf = SWG.pf400_25
elif (self.w, self.T) == (400, 125):
pf = SWG.pf400_125
elif (self.w, self.T) == (400, 225):
pf = SWG.pf400_225
Comment on lines -1333 to -1334
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SWG.solve refactored with the following changes:

elif self.w < 400 or self.w > 488 or self.T < 25 or self.T > 225:
raise ValueError("input out of bounds")
else:
Expand Down
11 changes: 4 additions & 7 deletions EMpy/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ def __init__(self, data=None, T0=300):
self.T0 = T0

def TOC(self, T):
if self.__data is not None:
return numpy.polyval(self.__data, T)
else:
return 0.0
return numpy.polyval(self.__data, T) if self.__data is not None else 0.0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ThermalOpticCoefficient.TOC refactored with the following changes:


def __call__(self, T):
return self.TOC(T)
Expand Down Expand Up @@ -213,7 +210,7 @@ def isIsotropic():

def __str__(self):
"""Return material name."""
return self.name + ", isotropic"
return f"{self.name}, isotropic"
Comment on lines -216 to +213
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function IsotropicMaterial.__str__ refactored with the following changes:



class EpsilonTensor(object):
Expand Down Expand Up @@ -255,7 +252,7 @@ def isIsotropic():

def __str__(self):
"""Return material name."""
return self.name + ", anisotropic"
return f"{self.name}, anisotropic"
Comment on lines -258 to +255
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AnisotropicMaterial.__str__ refactored with the following changes:



# Vacuum
Expand Down Expand Up @@ -361,7 +358,7 @@ def get_10400_000_100(conc000):
nE_ = numpy.interp(conc000, conc, epsE) ** 0.5

return LiquidCrystal(
"10400_000_100_" + str(conc000) + "_" + str(100 - conc000),
f"10400_000_100_{str(conc000)}_{str(100 - conc000)}",
Comment on lines -364 to +361
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_10400_000_100 refactored with the following changes:

nO_,
nE_,
nO_electrical_,
Expand Down
26 changes: 10 additions & 16 deletions EMpy/modesolvers/FD.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def __init__(self, wl, x, y, epsfunc, boundary, method="Ex"):
def _get_eps(self, xc, yc):
eps = self.epsfunc(xc, yc)
eps = numpy.c_[eps[:, 0:1], eps, eps[:, -1:]]
eps = numpy.r_[eps[0:1, :], eps, eps[-1:, :]]
return eps
return numpy.r_[eps[0:1, :], eps, eps[-1:, :]]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SVFDModeSolver._get_eps refactored with the following changes:


def build_matrix(self):

Expand Down Expand Up @@ -260,9 +259,7 @@ def build_matrix(self):
J = numpy.r_[iall, i_e, i_w, i_n, i_s]
V = numpy.r_[Ap[iall], Ae[i_w], Aw[i_e], An[i_s], As[i_n]]

A = coo_matrix((V, (I, J))).tocsr()

return A
return coo_matrix((V, (I, J))).tocsr()
Comment on lines -263 to +262
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SVFDModeSolver.build_matrix refactored with the following changes:


def solve(self, neigs, tol):

Expand All @@ -286,24 +283,21 @@ def solve(self, neigs, tol):
# sort and save the modes
idx = numpy.flipud(numpy.argsort(neff))
self.neff = neff[idx]
tmp = []
for i in idx:
tmp.append(phi[i])

if self.method == "scalar":
self.phi = tmp
elif self.method == "Ex":
tmp = [phi[i] for i in idx]
if self.method == "Ex":
self.Ex = tmp
if self.method == "Ey":
elif self.method == "Ey":
self.Ey = tmp

elif self.method == "scalar":
self.phi = tmp
Comment on lines -289 to +293
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SVFDModeSolver.solve refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)
  • Simplify conditional into switch-like form [×2] (switch)

return self

def __str__(self):
descr = (
"Semi-Vectorial Finite Difference Modesolver\n\tmethod: %s\n" % self.method
return (
"Semi-Vectorial Finite Difference Modesolver\n\tmethod: %s\n"
% self.method
)
return descr
Comment on lines -303 to -306
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SVFDModeSolver.__str__ refactored with the following changes:



class VFDModeSolver(ModeSolver):
Expand Down
43 changes: 8 additions & 35 deletions EMpy/modesolvers/FMM.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,7 @@ def translate(self):
raise ValueError("Unknown boundary.")

def __str__(self):
return "xleft = %s, xright = %s, yleft = %s, yright = %s" % (
self.xleft,
self.xright,
self.yleft,
self.yright,
)
return f"xleft = {self.xleft}, xright = {self.xright}, yleft = {self.yleft}, yright = {self.yright}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Boundary.__str__ refactored with the following changes:



class Slice(object):
Expand Down Expand Up @@ -289,15 +284,8 @@ def get_y(self, n=100):
def eval(self, x_=None, y_=None):
"""Evaluate the mode at x,y."""

if x_ is None:
x = self.get_x()
else:
x = numpy.atleast_1d(x_)
if y_ is None:
y = self.get_y()
else:
y = numpy.atleast_1d(y_)

x = self.get_x() if x_ is None else numpy.atleast_1d(x_)
y = self.get_y() if y_ is None else numpy.atleast_1d(y_)
Comment on lines -292 to +288
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FMMMode2d.eval refactored with the following changes:

nmodi = len(self.modie)
lenx = len(x)
leny = len(y)
Expand Down Expand Up @@ -501,20 +489,12 @@ def fields(self, x=None, y=None):

def intensity(self, x=None, y=None):
Ex, Ey, Ez, cBx, cBy, cBz = self.fields(x, y)
cSz = 0.5 * (Ex * numpy.conj(cBy) - Ey * numpy.conj(cBx))
return cSz
return 0.5 * (Ex * numpy.conj(cBy) - Ey * numpy.conj(cBx))
Comment on lines -504 to +492
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FMMMode2d.intensity refactored with the following changes:


def TEfrac_old(self, x_=None, y_=None):

if x_ is None:
x = self.get_x()
else:
x = numpy.atleast_1d(x_)
if y_ is None:
y = self.get_y()
else:
y = numpy.atleast_1d(y_)

x = self.get_x() if x_ is None else numpy.atleast_1d(x_)
y = self.get_y() if y_ is None else numpy.atleast_1d(y_)
Comment on lines -509 to +497
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FMMMode2d.TEfrac_old refactored with the following changes:

Ex, Ey, Ez, cBx, cBy, cBz, cSz = self.fields(x, y)
cSTE = 0.5 * EMpy.utils.trapz2(Ex * numpy.conj(cBy), y, x)
cSTM = 0.5 * EMpy.utils.trapz2(-Ey * numpy.conj(cBx), y, x)
Expand All @@ -527,15 +507,8 @@ def TEfrac(self):

def overlap_old(self, m, x_=None, y_=None):

if x_ is None:
x = self.get_x()
else:
x = numpy.atleast_1d(x_)
if y_ is None:
y = self.get_y()
else:
y = numpy.atleast_1d(y_)

x = self.get_x() if x_ is None else numpy.atleast_1d(x_)
y = self.get_y() if y_ is None else numpy.atleast_1d(y_)
Comment on lines -530 to +511
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FMMMode2d.overlap_old refactored with the following changes:

Ex, Ey, Ez, cBx, cBy, cBz = self.fields(x, y)
cSz = self.intensity(x, y)
norm = scipy.sqrt(EMpy.utils.trapz2(cSz, y, x))
Expand Down
24 changes: 12 additions & 12 deletions EMpy/modesolvers/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ def save_for_FDTD(self, mode_id="", x=None, y=None):
Ex_FDTD, Ey_FDTD, Ez_FDTD, Hx_FDTD, Hy_FDTD, Hz_FDTD = self.get_fields_for_FDTD(
x, y
)
Ex_FDTD.real.T.tofile("ex" + mode_id + ".dat", sep=" ")
Ex_FDTD.imag.T.tofile("iex" + mode_id + ".dat", sep=" ")
Ey_FDTD.real.T.tofile("ey" + mode_id + ".dat", sep=" ")
Ey_FDTD.imag.T.tofile("iey" + mode_id + ".dat", sep=" ")
Ez_FDTD.real.T.tofile("ez" + mode_id + ".dat", sep=" ")
Ez_FDTD.imag.T.tofile("iez" + mode_id + ".dat", sep=" ")
Hx_FDTD.real.T.tofile("hx" + mode_id + ".dat", sep=" ")
Hx_FDTD.imag.T.tofile("ihx" + mode_id + ".dat", sep=" ")
Hy_FDTD.real.T.tofile("hy" + mode_id + ".dat", sep=" ")
Hy_FDTD.imag.T.tofile("ihy" + mode_id + ".dat", sep=" ")
Hz_FDTD.real.T.tofile("hz" + mode_id + ".dat", sep=" ")
Hz_FDTD.imag.T.tofile("ihz" + mode_id + ".dat", sep=" ")
Ex_FDTD.real.T.tofile(f"ex{mode_id}.dat", sep=" ")
Ex_FDTD.imag.T.tofile(f"iex{mode_id}.dat", sep=" ")
Ey_FDTD.real.T.tofile(f"ey{mode_id}.dat", sep=" ")
Ey_FDTD.imag.T.tofile(f"iey{mode_id}.dat", sep=" ")
Ez_FDTD.real.T.tofile(f"ez{mode_id}.dat", sep=" ")
Ez_FDTD.imag.T.tofile(f"iez{mode_id}.dat", sep=" ")
Hx_FDTD.real.T.tofile(f"hx{mode_id}.dat", sep=" ")
Hx_FDTD.imag.T.tofile(f"ihx{mode_id}.dat", sep=" ")
Hy_FDTD.real.T.tofile(f"hy{mode_id}.dat", sep=" ")
Hy_FDTD.imag.T.tofile(f"ihy{mode_id}.dat", sep=" ")
Hz_FDTD.real.T.tofile(f"hz{mode_id}.dat", sep=" ")
Hz_FDTD.imag.T.tofile(f"ihz{mode_id}.dat", sep=" ")
Comment on lines -35 to +46
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Mode.save_for_FDTD refactored with the following changes:


def plot(self, x=None, y=None):
raise NotImplementedError()
Expand Down
Loading