def waves2field2(waves, fmat, jones=None, phi=0, mode=+1): """Converts scalar waves to vector field data.""" if jones is None: fvec1 = field4(fmat, jones=jonesvec((1, 0), phi), amplitude=waves, mode=mode) fvec2 = field4(fmat, jones=jonesvec((0, 1), phi), amplitude=waves, mode=mode) field1 = itranspose(fvec1) field2 = itranspose(fvec2) shape = list(field1.shape) shape.insert(-4, 2) out = np.empty(shape=shape, dtype=field1.dtype) out[..., 0, :, :, :, :] = field1 out[..., 1, :, :, :, :] = field2 else: #fvec = field4(fmat, jones = jonesvec((1,0),phi), amplitude = waves, mode = mode) fvec = field4(fmat, jones=jonesvec(jones, phi), amplitude=waves, mode=mode) out = itranspose(fvec).copy() return out
dotmdm = dtmm.linalg.dotmdm dotmv = dtmm.linalg.dotmv intensity = tmm.intensity intensity = tmm.poynting p = tmm.phase_mat(a, -kd) #p = np.exp(-1j*a*kd) #characteristic matrix cmat = dotmdm(f, p, fi) #field projection matrices - used to take the forward propagating or backward propagating waves pmat = tmm.projection_mat(fout, mode=+1) mmat = tmm.projection_mat(fin, mode=-1) pmatin = tmm.projection_mat(fin, mode=+1) #: build EM field 4-vector (Ex, Hy, Ey, Hx) of a given polarization fvec = tmm.field4(fin, jones=pol1) fvec = dotmv(pmatin, fvec) #: transmit the field and update fvec with reflected waves tfvec = tmm.transmit(fvec, cmat, fmatin=fin, fmatout=fout) #: take the backward propagating waves in input field rfvec = dotmv(mmat, fvec) tfvec = dotmv( pmat, tfvec ) #no need to do this.. there is no backpropagating waves in the output tfvecin = dotmv(pmatin, fvec) y_polarizer = tmm.polarizer4x4(pol1, fout) #y == s polarization x_polarizer = tmm.polarizer4x4(pol2, fout) #x == p polarization y_polarizerin = tmm.polarizer4x4(pol1, fin) #y == s polarization
# multiply matrices together over second axis (first axis is wavelenght, second are layers) cmat = linalg.multi_dot(m, axis=1) #the 2x2 matrices must be multiplied in reverse order... because we propagate forward cmat2 = linalg.multi_dot(m2, axis=1, reverse=True) cmat2t = linalg.multi_dot(m2t, axis=1, reverse=True) jx = jones.jonesvec((1, 0), phi) jy = jones.jonesvec((0, 1), phi) #field projection matrices - used to take the forward propagating or backward propagating waves pmat = tmm.projection_mat(fout, mode=+1) mmat = tmm.projection_mat(fin, mode=-1) fvec = tmm.field4(fin, jones=jx) #fvec = tmm.field4old(fin,jones = jx) fvec = np.array([fvec] * nwavelengths) tfvec2 = tmm.transmit2x2(fvec, cmat2, fmatout=fout[None, ...]) tfvec2r = tmm.transmit2x2(fvec, cmat2t, fmatout=fout[None, ...]) tfvec4 = tmm.transmit(fvec, cmat, fmatin=fin[None, ...], fmatout=fout[None, ...]) rfvec4 = dotmv(mmat, fvec) x_polarizerin = tmm.polarizer4x4(jx, fin) y_polarizerin = tmm.polarizer4x4(jy, fin) x_polarizer = tmm.polarizer4x4(jx, fout)