# Path: EMpy/modesolvers/interface.py
# class Mode(object):
#     def get_x(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def get_y(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def intensity(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def TEfrac(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def overlap(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def get_fields_for_FDTD(self, x, y):
#         raise NotImplementedError()
# 
#     def save_for_FDTD(self, mode_id="", x=None, y=None):
#         """Save mode's fields on a staggered grid."""
#         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=" ")
# 
#     def plot(self, x=None, y=None):
#         raise NotImplementedError()
# 
# class ModeSolver(object):
#     def solve(self, *argv):
#         raise NotImplementedError()


from builtins import zip
from builtins import str
from builtins import range
from EMpy.modesolvers.interface import Mode, ModeSolver
        from scipy.sparse import coo_matrix
        from scipy.sparse.linalg import eigen
        from scipy.sparse import coo_matrix
        from scipy.sparse import coo_matrix
        from scipy.sparse.linalg import eigen
import numpy
import scipy
import scipy.optimize
import EMpy.utils
            import pylab
            import pylab
        neffs = neffs[idx]
        tmpx = []
        tmpy = []
        for i in idx:
            tmpx.append(Hxs[i])
            tmpy.append(Hys[i])
        Hxs = tmpx
        Hys = tmpy

        [Hzs, Exs, Eys, Ezs] = self.compute_other_fields(neffs, Hxs, Hys)

        self.modes = []
        for (neff, Hx, Hy, Hz, Ex, Ey, Ez) in zip(neffs, Hxs, Hys, Hzs, Exs, Eys, Ezs):
            self.modes.append(
                FDMode(
                    self.wl, self.x, self.y, neff, Ex, Ey, Ez, Hx, Hy, Hz
                ).normalize()
            )

        return self

    def save_modes_for_FDTD(self, x=None, y=None):
        for im, m in enumerate(self.modes):
            m.save_for_FDTD(str(im), x, y)

    def __str__(self):
        descr = "Vectorial Finite Difference Modesolver\n"
        return descr



# Path: EMpy/modesolvers/interface.py
# class Mode(object):
#     def get_x(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def get_y(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def intensity(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def TEfrac(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def overlap(self, x=None, y=None):
#         raise NotImplementedError()
# 
#     def get_fields_for_FDTD(self, x, y):
#         raise NotImplementedError()
# 
#     def save_for_FDTD(self, mode_id="", x=None, y=None):
#         """Save mode's fields on a staggered grid."""
#         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=" ")
# 
#     def plot(self, x=None, y=None):
#         raise NotImplementedError()
# 
# class ModeSolver(object):
#     def solve(self, *argv):
#         raise NotImplementedError()


# Path: EMpy/modesolvers/FD.py
from builtins import zip
from builtins import str
from builtins import range
from EMpy.modesolvers.interface import Mode, ModeSolver
        from scipy.sparse import coo_matrix
        from scipy.sparse.linalg import eigen
        from scipy.sparse import coo_matrix
        from scipy.sparse import coo_matrix
        from scipy.sparse.linalg import eigen
import numpy
import scipy
import scipy.optimize
import EMpy.utils
            import pylab
            import pylab

        neffs = neffs[idx]
        tmpx = []
        tmpy = []
        for i in idx:
            tmpx.append(Hxs[i])
            tmpy.append(Hys[i])
        Hxs = tmpx
        Hys = tmpy

        [Hzs, Exs, Eys, Ezs] = self.compute_other_fields(neffs, Hxs, Hys)

        self.modes = []
        for (neff, Hx, Hy, Hz, Ex, Ey, Ez) in zip(neffs, Hxs, Hys, Hzs, Exs, Eys, Ezs):
            self.modes.append(
                FDMode(
                    self.wl, self.x, self.y, neff, Ex, Ey, Ez, Hx, Hy, Hz
                ).normalize()
            )

        return self

    def save_modes_for_FDTD(self, x=None, y=None):
        for im, m in enumerate(self.modes):
            m.save_for_FDTD(str(im), x, y)

    def __str__(self):
        descr = "Vectorial Finite Difference Modesolver\n"
        return descr



class FDMode(Mode):