def propagate_2x2_effective_2(field, wavenumbers, layer_in, layer_out, effective_layer_in, effective_layer_out, beta=0, phi=0, nsteps=1, diffraction=True, split_diffraction=False, reflection=True, betamax=BETAMAX, mode=+1, refl=None, bulk=None, out=None, tmpdata=None): shape = field.shape[-2:] d_eff, epsv_eff, epsa_eff = effective_layer_out if diffraction <= 1: if diffraction: dmat = corrected_E_diffraction_matrix(shape, wavenumbers, beta, phi, d=d_eff, epsv=epsv_eff, epsa=epsa_eff, mode=mode, betamax=betamax) else: dmat = None return _transfer_ray_2x2_2(field, wavenumbers, layer_in, layer_out, dmat=dmat, beta=beta, phi=phi, nsteps=nsteps, reflection=reflection, betamax=betamax, mode=mode, refl=refl, bulk=bulk, out=out, tmpdata=tmpdata) else: fout = 0. fpart = None ffield = fft2(field) if refl is not None: frefl = fft2(refl) _refl = 0. else: _refl = None try: broadcast_shape = beta.shape beta = beta[..., 0] phi = phi[..., 0] except IndexError: broadcast_shape = () windows, (betas, phis) = fft_mask(field.shape, wavenumbers, int(diffraction), betax_off=beta * np.cos(phi), betay_off=beta * np.sin(phi), betamax=betamax) n = len(windows) betas = betas.reshape((n, ) + broadcast_shape) phis = phis.reshape((n, ) + broadcast_shape) if split_diffraction == False: dmats = corrected_E_diffraction_matrix(shape, wavenumbers, betas, phis, d=d_eff, epsv=epsv_eff, epsa=epsa_eff, mode=mode, betamax=betamax) idata = zip(windows, betas, phis, dmats) else: idata = zip(windows, betas, phis) for data in idata: if split_diffraction == False: window, beta, phi, dmat = data else: window, beta, phi = data dmat = corrected_E_diffraction_matrix(shape, wavenumbers, beta, phi, d=d_eff, epsv=epsv_eff, epsa=epsa_eff, mode=mode, betamax=betamax) fpart = np.multiply(ffield, window, out=fpart) fpart_re = ifft2(fpart, out=fpart) if refl is not None: reflpart = frefl * window reflpart_re = ifft2(reflpart) else: reflpart_re = None _out, __refl = _transfer_ray_2x2_2(fpart_re, wavenumbers, layer_in, layer_out, dmat=dmat, beta=beta, phi=phi, nsteps=nsteps, betamax=betamax, reflection=reflection, mode=mode, bulk=bulk, out=out, refl=reflpart_re, tmpdata=tmpdata) fout += _out if refl is not None and reflection != 0: _refl += __refl if out is not None: out[...] = fout else: out = fout if refl is not None: refl[...] = _refl return out, refl
def propagate_4x4_effective_3(field, wavenumbers, layer, effective_layer, beta=0, phi=0, nsteps=1, diffraction=True, betamax=BETAMAX, out=None): d_eff, epsv_eff, epsa_eff = effective_layer if diffraction == 1: dmat1 = second_field_diffraction_matrix(field.shape[-2:], wavenumbers, beta, phi, d_eff / 2, epsv=epsv_eff, epsa=epsa_eff, betamax=betamax) dmat2 = first_field_diffraction_matrix(field.shape[-2:], wavenumbers, beta, phi, d_eff / 2, epsv=epsv_eff, epsa=epsa_eff, betamax=betamax) return _transfer_ray_4x4_3(field, wavenumbers, layer, dmat1, dmat2, beta=beta, phi=phi, nsteps=nsteps, betamax=betamax, out=out) elif diffraction > 1: fout = np.zeros_like(field) _out = None try: broadcast_shape = beta.shape beta = beta[..., 0] phi = phi[..., 0] except IndexError: broadcast_shape = () windows, (betas, phis) = fft_mask(field.shape, wavenumbers, int(diffraction), betax_off=beta * np.cos(phi), betay_off=beta * np.sin(phi), betamax=betamax) n = len(windows) betas = betas.reshape((n, ) + broadcast_shape) phis = phis.reshape((n, ) + broadcast_shape) dmats1 = second_field_diffraction_matrix(field.shape[-2:], wavenumbers, betas, phis, d_eff / 2, epsv=epsv_eff, epsa=epsa_eff, betamax=betamax) dmats2 = first_field_diffraction_matrix(field.shape[-2:], wavenumbers, betas, phis, d_eff / 2, epsv=epsv_eff, epsa=epsa_eff, betamax=betamax) for window, beta, phi, dmat1, dmat2 in zip(windows, betas, phis, dmats1, dmats2): fpart = np.multiply(field, window, out=_out) _out = _transfer_ray_4x4_3(fpart, wavenumbers, layer, dmat1, dmat2, beta=beta, phi=phi, nsteps=nsteps, betamax=betamax, out=_out) fout = np.add(fout, _out, out=fout) # for window, b, p in zip(windows, betas, phis): # fpart = np.multiply(field, window, out = _out) # # beta = b.reshape(broadcast_shape) # phi = p.reshape(broadcast_shape) # # dmat1 = second_field_diffraction_matrix(field.shape[-2:], wavenumbers, beta, phi,d_eff/2, epsv = epsv_eff, # epsa = epsa_eff,betamax = betamax) # dmat2 = first_field_diffraction_matrix(field.shape[-2:], wavenumbers, beta, phi,d_eff/2, epsv = epsv_eff, # epsa = epsa_eff,betamax = betamax) # # _out = _transfer_ray_4x4_1(fpart, wavenumbers, layer, dmat1,dmat2, # beta = beta, phi = phi, nsteps = nsteps, # betamax = betamax, out = _out,_reuse = _reuse) # fout = np.add(fout, _out, out = fout) if out is not None: out[...] = fout else: out = fout return out
def propagate_2x2_effective_1(field, wavenumbers, layer_in, layer_out, effective_layer_in, effective_layer_out, beta=0, phi=0, nsteps=1, diffraction=True, reflection=True, betamax=BETAMAX, mode=+1, tmpdata=None, split_diffraction=False, refl=None, bulk=None, out=None): d_out, epsv_out, epsa_out = effective_layer_out shape = field.shape[-2:] if diffraction <= 1: if diffraction == 1: dmat1 = first_E_diffraction_matrix(shape, wavenumbers, beta, phi, d_out / 2, epsv=epsv_out, epsa=epsa_out, mode=mode, betamax=betamax) dmat2 = second_E_diffraction_matrix(shape, wavenumbers, beta, phi, d_out / 2, epsv=epsv_out, epsa=epsa_out, mode=mode, betamax=betamax) else: dmat1, dmat2 = None, None return _transfer_ray_2x2_1(field, wavenumbers, layer_out, effective_layer_in, effective_layer_out, dmat1, dmat2, beta=beta, phi=phi, nsteps=nsteps, reflection=reflection, betamax=betamax, mode=mode, refl=refl, bulk=bulk, out=out, tmpdata=tmpdata) elif diffraction > 1: fout = np.zeros_like(field) reflpart = None fpart = None _out = None if refl is not None: _refl = np.zeros_like(refl) else: _refl = None try: broadcast_shape = beta.shape beta = beta[..., 0] phi = phi[..., 0] except IndexError: broadcast_shape = () windows, (betas, phis) = fft_mask(field.shape, wavenumbers, int(diffraction), betax_off=beta * np.cos(phi), betay_off=beta * np.sin(phi), betamax=betamax) n = len(windows) betas = betas.reshape((n, ) + broadcast_shape) phis = phis.reshape((n, ) + broadcast_shape) if split_diffraction == False: dmats1 = first_E_diffraction_matrix(shape, wavenumbers, betas, phis, d_out / 2, epsv=epsv_out, epsa=epsa_out, mode=mode, betamax=betamax) dmats2 = second_E_diffraction_matrix(shape, wavenumbers, betas, phis, d_out / 2, epsv=epsv_out, epsa=epsa_out, mode=mode, betamax=betamax) idata = zip(windows, betas, phis, dmats1, dmats2) else: idata = zip(windows, betas, phis) for data in idata: if split_diffraction == False: window, beta, phi, dmat1, dmat2 = data else: window, beta, phi = data dmat1 = first_E_diffraction_matrix(shape, wavenumbers, beta, phi, d_out / 2, epsv=epsv_out, epsa=epsa_out, mode=mode, betamax=betamax) dmat2 = second_E_diffraction_matrix(shape, wavenumbers, beta, phi, d_out / 2, epsv=epsv_out, epsa=epsa_out, mode=mode, betamax=betamax) fpart = np.multiply(field, window, out=fpart) if refl is not None: reflpart = np.multiply(refl, window, out=reflpart) else: reflpart = None _out, __refl = _transfer_ray_2x2_1(fpart, wavenumbers, layer_out, effective_layer_in, effective_layer_out, dmat1, dmat2, beta=beta, phi=phi, nsteps=nsteps, reflection=reflection, betamax=betamax, mode=mode, bulk=bulk, out=_out, refl=reflpart, tmpdata=tmpdata) np.add(fout, _out, fout) if refl is not None and reflection != 0: np.add(_refl, __refl, out=_refl) if out is not None: out[...] = fout else: out = fout if refl is not None: refl[...] = _refl return out, refl
def propagate_4x4_effective_4(field, wavenumbers, layer, effective_layer, beta=0, phi=0, nsteps=1, diffraction=True, betamax=BETAMAX, out=None): d_eff, epsv_eff, epsa_eff = effective_layer if diffraction <= 1: if diffraction != 0: dmat = corrected_field_diffraction_matrix(field.shape[-2:], wavenumbers, beta, phi, d=d_eff, epsv=epsv_eff, epsa=epsa_eff, betamax=betamax) else: dmat = None return _transfer_ray_4x4_4(field, wavenumbers, layer, beta=beta, phi=phi, nsteps=nsteps, dmat=dmat, out=out) else: fout = np.zeros_like(field) _out = None field = fft2(field) try: broadcast_shape = beta.shape beta = beta[..., 0] phi = phi[..., 0] except IndexError: broadcast_shape = () windows, (betas, phis) = fft_mask(field.shape, wavenumbers, int(diffraction), betax_off=beta * np.cos(phi), betay_off=beta * np.sin(phi), betamax=betamax) n = len(windows) betas = betas.reshape((n, ) + broadcast_shape) phis = phis.reshape((n, ) + broadcast_shape) if diffraction != 0: dmats = corrected_field_diffraction_matrix(field.shape[-2:], wavenumbers, betas, phis, d=d_eff, epsv=epsv_eff, epsa=epsa_eff) else: dmats = [None] * n for window, b, p, dmat in zip(windows, betas, phis, dmats): fpart = np.multiply(field, window, out=_out) fpart_re = ifft2(fpart, out=fpart) _out = _transfer_ray_4x4_4(fpart_re, wavenumbers, layer, beta=b, phi=p, nsteps=nsteps, dmat=dmat) fout = np.add(fout, _out, out=fout) # for window, b, p in zip(windows, betas, phis): # fpart = field * window # fpart_re = ifft2(fpart) # # b = b.reshape(beta_shape) # p = p.reshape(beta_shape) # # if diffraction != 0: # dmat = corrected_field_diffraction_matrix(field.shape[-2:], wavenumbers, b,p, d=d_eff, # epsv = epsv_eff, epsa = epsa_eff) # else: # dmat = None # # _out = _transfer_ray_4x4_2(fpart_re, wavenumbers, layer, # beta = b, phi = p, nsteps = nsteps, # dmat = dmat,_reuse = _reuse) # fout += _out if out is not None: out[...] = fout else: out = fout return out