Exemplo n.º 1
0
 def clean(self, tol=None):
     if goodtest(self):
         self.epsilon = aux_clean(self.epsilon, tol)
     else:
         raise Exception(
             "Medium object is not well-formed, check for improper attributes"
         )
Exemplo n.º 2
0
 def clean(self, tol=None):
     if goodtest(self, test_type='wave'):
         self.kvec = aux_clean(self.kvec, tol)
         self.efield = aux_clean(self.efield, tol)
         self.medium = aux_clean(self.medium, tol)
     else:
         raise Exception(
             "Wave object is not well-formed, check for improper attributes"
         )
Exemplo n.º 3
0
 def clean(self, tol=None):
     if goodtest(self, test_type='surface'):
         self.normal = aux_clean(self.normal, tol)
         self.out = aux_clean(self.out, tol)
         self.into = aux_clean(self.into, tol)
     else:
         raise Exception(
             "Surface object is not well-formed, check for improper attributes"
         )
Exemplo n.º 4
0
 def jones(self):
     if goodtest(self, test_type='wave'):
         if type(self.efield) is numpy.ndarray:
             if isinstance(self.phase, (int, float, complex)):
                 return numpy.exp(1j * self.phase) * self.efield
             else:
                 return self.efield
         else:
             raise Exception("No electric field found")
     else:
         raise Exception(
             "Wave object is not well-formed, check for improper attributes"
         )
Exemplo n.º 5
0
 def k(self, k0=None):
     if goodtest(self, test_type='wave'):
         if type(self.kvec) is numpy.ndarray:
             vec = copy.deepcopy(self.kvec)
             vecC = numpy.conj(vec)
             norm = numpy.sqrt(vecC.T @ vec)[0, 0]
             if isinstance(k0, (int, float)) and k0 > 0:
                 return k0 * norm.real
             else:
                 return norm.real
         else:
             raise Exception("No kvec found")
     else:
         raise Exception(
             "Wave object is not well-formed, check for improper attributes"
         )
Exemplo n.º 6
0
 def index(self, k0=None):
     if goodtest(self, test_type='wave'):
         if k0 is None:
             k0 = 1
         if numpy.shape(self.kvec) == (3, 1):
             kre = self.kvec.real
             kim = self.kvec.imag
             Nre = numpy.sqrt((kre.T @ kre)[0, 0]) / k0
             Nim = numpy.sqrt((kim.T @ kim)[0, 0]) / k0
             return [Nre, Nim]
         else:
             raise Exception("No wave vector found")
     else:
         raise Exception(
             "Wave object is not well-formed, check for improper attributes"
         )
Exemplo n.º 7
0
    def rotate(self, ang, axis, **kwargs):

        medmove = kwargs.pop('medmove', None)
        fix = kwargs.pop('fix', None)
        verbose = kwargs.pop('verbose', None)

        if len(kwargs) != 0:
            print("Undefined argument passed to wave.rotate")

        if goodtest(self, test_type='wave'):
            medQ = isinstance(self.medium, numpy.ndarray)
            if fix and medQ:
                back = aux_check_ab(self)
            rotate_copy(self, ang, axis, medmove, verbose)
            if fix and medQ:
                self.fixmode(ab=back, conserve=True)
        else:
            raise Exception(
                "Wave object is not well-formed, check for improper attributes"
            )
Exemplo n.º 8
0
    def fixmode(self, **kwargs):

        ab = kwargs.pop('ab', None)
        k0 = kwargs.pop('k0', None)
        conserve = kwargs.pop('conserve', None)
        verbose = kwargs.pop('verbose', None)

        if len(kwargs) != 0:
            print("Undefined argument passed to wave.fixmode")

        if goodtest(self, test_type='wave'):
            back = aux_fixmode(wave=self,
                               ab=ab,
                               k0=k0,
                               conserve=conserve,
                               verbose=verbose)
            self.kvec = back[0]
            self.efield = back[1]
        else:
            raise Exception(
                "Wave object is not well-formed, check for improper attributes"
            )
Exemplo n.º 9
0
 def propagate(self, vec, k0=None, wrap=None):
     if k0 is None:
         k0 = 1
     elif not isinstance(k0, (int, float)) or k0 <= 0:
         k0 = 1
         print("Invalid input for k0, setting equal to 1")
     if goodtest(self, test_type='wave'):
         if type(vec) is numpy.ndarray and numpy.shape(vec) == (3, 1):
             currentphase = copy.deepcopy(self.phase)
             kvec = copy.deepcopy(self.kvec)
             newphase = currentphase + k0 * (kvec.T @ vec)[0, 0]
             if wrap:
                 self.phase = newphase % (2 * numpy.pi)
             else:
                 self.phase = newphase
         else:
             raise Exception(
                 "Propagation direction must be specified as a (3,1) numpy array"
             )
     else:
         raise Exception(
             "Wave object is not well-formed, check for improper attributes"
         )
Exemplo n.º 10
0
    def poynting(self, **kwargs):

        scale = kwargs.pop('scale', None)
        norm = kwargs.pop('norm', None)

        if len(kwargs) != 0:
            print("Undefined argument passed to wave.poynting")

        if goodtest(self, test_type='wave'):
            if scale is None or not isinstance(scale, (int, float)):
                scale = 1
            ee = self.efield
            kk = self.kvec
            hh = numpy.cross(kk.T, ee.T).T
            hhc = numpy.conj(hh)
            S = 0.5 * scale * numpy.cross(ee.T, hhc.T).T
            if norm:
                Snorm = numpy.sqrt(numpy.conj(S.T) @ S)[0, 0]
                S = S / Snorm
            return S
        else:
            raise Exception(
                "Wave object is not well-formed, check for improper attributes"
            )