def mie_sphere(mesh, Params, name="mie-sphere.pos", field="sca"): count = 0 N, params, kk = Params R, (ce, ci), jumps = params kk = Cartesian(kk) k = kk.norm() kk = kk.normalized() vals = [0 + 0j] * len(mesh.points) for ii, point in enumerate(mesh.points): _print_progress(ii, len(mesh.points), "computed", mod=1) p = Cartesian(point) pnorm = p.norm() pn = p.normalized() costheta = pn.dot(kk) for n in myrange(N): if field == "sca": cn = coeff_ext(n, params, k) * H1(n, k * pnorm) elif field == "int": cn = coeff_int(n, params, k) * J(n, ci * k * pnorm) else: cn = ((1j) ** n) * (2 * n + 1) * J(n, k * pnorm) c = eval_legendre(n, costheta) count += 1 vals[ii] += cn * c print(" --> {1} computations i.e. N={0}.".format(N, count)) mesh.write(vals, name) return vals
def mie_sphere(mesh, Params, name='mie-sphere.pos', field='sca'): count = 0 N, params, kk = Params R, (ce, ci), jumps = params kk = Cartesian(kk) k = kk.norm() kk = kk.normalized() vals = [0 + 0j] * len(mesh.points) for ii, point in enumerate(mesh.points): _print_progress(ii, len(mesh.points), 'computed', mod=1) p = Cartesian(point) pnorm = p.norm() pn = p.normalized() costheta = pn.dot(kk) for n in myrange(N): if field == 'sca': cn = coeff_ext(n, params, k) * H1(n, k * pnorm) elif field == 'int': cn = coeff_int(n, params, k) * J(n, ci * k * pnorm) else: cn = ((1j)**n) * (2 * n + 1) * J(n, k * pnorm) c = eval_legendre(n, costheta) count += 1 vals[ii] += cn * c print(' --> {1} computations i.e. N={0}.'.format(N, count)) mesh.write(vals, name) return vals
def mie_N4grid_slow(field, kk, R, C, ce, ci, jumpe, jumpi, N, point): """ Requires: kk : numpy.array([kx, ky, kz]) R : radius of the sphere C : center of the sphere ce, ci : contrast sqrt(epsExt), sqrt*espInt) jumpe: coeff jump exterior (alpha_Dir, beta_Neu) jumpi: coeff jump interior (alpha_Dir, beta_Neu) N : Number of modes """ pt = point[:] kk = Cartesian(kk) k = kk.norm() kk = kk.normalized() # be careful with this test !! if sp.linalg.norm(sp.linalg.norm(pt - C) - R) > 0.3: return 0.0 + 0j else: jumps = (jumpe, jumpi) params = (R, (ce, ci), jumps) p = Cartesian((pt[0], pt[1], pt[2])) pnorm = p.norm() pn = p.normalized() costheta = pn.dot(kk) val = 0 for n in myrange(N): if field == "sca": cn = k * coeff_ext(n, params, k) * H1p(n, k * pnorm) elif field == "int": cn = ci * k * coeff_int(n, params, k) * Jp(n, ci * k * pnorm) else: cn = k * ((1j) ** n) * (2 * n + 1) * Jp(n, k * pnorm) c = eval_legendre(n, costheta) val += cn * c return val
def mie_N4grid_slow(field, kk, R, C, ce, ci, jumpe, jumpi, N, point): """ Requires: kk : numpy.array([kx, ky, kz]) R : radius of the sphere C : center of the sphere ce, ci : contrast sqrt(epsExt), sqrt*espInt) jumpe: coeff jump exterior (alpha_Dir, beta_Neu) jumpi: coeff jump interior (alpha_Dir, beta_Neu) N : Number of modes """ pt = point[:] kk = Cartesian(kk) k = kk.norm() kk = kk.normalized() # be careful with this test !! if sp.linalg.norm(sp.linalg.norm(pt - C) - R) > 0.3: return 0. + 0j else: jumps = (jumpe, jumpi) params = (R, (ce, ci), jumps) p = Cartesian((pt[0], pt[1], pt[2])) pnorm = p.norm() pn = p.normalized() costheta = pn.dot(kk) val = 0 for n in myrange(N): if field == 'sca': cn = k * coeff_ext(n, params, k) * H1p(n, k * pnorm) elif field == 'int': cn = ci * k * coeff_int(n, params, k) * Jp(n, ci * k * pnorm) else: cn = k * ((1j)**n) * (2 * n + 1) * Jp(n, k * pnorm) c = eval_legendre(n, costheta) val += cn * c return val
def ref_inc(mesh, Params, name="ref-inc.pos", ext=True): count = 0 N, params, kk = Params R, (ce, ci), jumps = params kk = Cartesian(kk) k = kk.norm() kk = kk.normalized() vals = [0 + 0j] * len(mesh.points) for ii, point in enumerate(mesh.points): _print_progress(ii, len(mesh.points), "computed", mod=1) p = Cartesian(point) x, y, z = point count += 1 if ins: val = sp.exp(1j * ci * k * kk.dot(p)) else: val = sp.exp(1j * ce * k * kk.dot(p)) vals[ii] = val print(" --> {0} computations.".format(count)) mesh.write(vals, name)
def ref_inc(mesh, Params, name='ref-inc.pos', ext=True): count = 0 N, params, kk = Params R, (ce, ci), jumps = params kk = Cartesian(kk) k = kk.norm() kk = kk.normalized() vals = [0 + 0j] * len(mesh.points) for ii, point in enumerate(mesh.points): _print_progress(ii, len(mesh.points), 'computed', mod=1) p = Cartesian(point) x, y, z = point count += 1 if ins: val = sp.exp(1j * ci * k * kk.dot(p)) else: val = sp.exp(1j * ce * k * kk.dot(p)) vals[ii] = val print(' --> {0} computations.'.format(count)) mesh.write(vals, name)
def mie_N4grid(field, kk, R, C, ce, ci, jumpe, jumpi, N, point): """ Requires: kk : numpy.array([kx, ky, kz]) R : radius of the sphere C : center of the sphere ce, ci : contrast sqrt(epsExt), sqrt*espInt) jumpe: coeff jump exterior (alpha_Dir, beta_Neu) jumpi: coeff jump interior (alpha_Dir, beta_Neu) N : Number of modes """ pt = point[:] kk = Cartesian(kk) k = kk.norm() kk = kk.normalized() # be careful with this test !! if sp.linalg.norm(sp.linalg.norm(pt - C) - R) > 0.3: return 0.0 + 0j else: p = Cartesian((pt[0], pt[1], pt[2])) pnorm = p.norm() pn = p.normalized() costheta = pn.dot(kk) kpnorm = k * pnorm ke, ki = ce * k, ci * k keR, kiR = ke * R, ki * R ae, be = jumpe ai, bi = jumpi ke_aeai = ke * ae * ai ki_aebi = ki * ae * bi ke_aibe = ke * ai * be ke_beae = ke * be * ae ke_bebe = ke * be * be ki_bebe = ke * ae * bi ke_aibe = ke * ai * be sqrt_e = sp.sqrt(sp.pi / (2 * keR)) sqrt_i = sp.sqrt(sp.pi / (2 * kiR)) sqrt_n = sp.sqrt(sp.pi / (2 * kpnorm)) sqrt_m = sp.sqrt(sp.pi / (2 * ci * kpnorm)) val = 0 for n in myrange(N): Je = sqrt_e * jv(n + 0.5, keR) Ji = sqrt_i * jv(n + 0.5, kiR) Jpe = (n / keR) * Je - sqrt_e * jv(n + 1.5, keR) Jpi = (n / kiR) * Ji - sqrt_i * jv(n + 1.5, kiR) Ye = sqrt_e * yv(n + 0.5, keR) Ype = (n / keR) * Ye - sqrt_e * yv(n + 1.5, keR) locH1 = Je + 1j * Ye locH1p = Jpe + 1j * Ype if field == "sca": a = ke_aeai * Ji * Jpe b = ki_aebi * Jpi * Je c = ki_aebi * locH1 * Jpi d = ke_aibe * locH1p * Ji v = (2 * n + 1) * ((1j) ** n) * (a - b) / (c - d) Jn = sqrt_n * jv(n + 0.5, kpnorm) Jpn = (n / kpnorm) * Jn - sqrt_n * jv(n + 1.5, kpnorm) Yn = sqrt_n * yv(n + 0.5, kpnorm) Ypn = (n / kpnorm) * Yn - sqrt_n * yv(n + 1.5, kpnorm) locH1p = Jpn + 1j * Ypn cn = k * v * locH1p elif field == "int": a = ke_beae * locH1 * Jpe b = ke_bebe * Je * locH1p c = ki_aebi * locH1 * Jpi d = ke_aibe * locH1p * Ji v = (2 * n + 1) * ((1j) ** n) * (a - b) / (c - d) Jn = sqrt_m * jv(n + 0.5, ci * kpnorm) Jpn = (n / (ci * kpnorm)) * Jn - sqrt_m * jv(n + 1.5, ci * kpnorm) cn = ci * k * v * Jpn else: cn = k * ((1j) ** n) * (2 * n + 1) * Jp(n, k * pnorm) c = eval_legendre(n, costheta) val += cn * c return val
def mie_N4grid(field, kk, R, C, ce, ci, jumpe, jumpi, N, point): """ Requires: kk : numpy.array([kx, ky, kz]) R : radius of the sphere C : center of the sphere ce, ci : contrast sqrt(epsExt), sqrt*espInt) jumpe: coeff jump exterior (alpha_Dir, beta_Neu) jumpi: coeff jump interior (alpha_Dir, beta_Neu) N : Number of modes """ pt = point[:] kk = Cartesian(kk) k = kk.norm() kk = kk.normalized() # be careful with this test !! if sp.linalg.norm(sp.linalg.norm(pt - C) - R) > 0.3: return 0. + 0j else: p = Cartesian((pt[0], pt[1], pt[2])) pnorm = p.norm() pn = p.normalized() costheta = pn.dot(kk) kpnorm = k * pnorm ke, ki = ce * k, ci * k keR, kiR = ke * R, ki * R ae, be = jumpe ai, bi = jumpi ke_aeai = ke * ae * ai ki_aebi = ki * ae * bi ke_aibe = ke * ai * be ke_beae = ke * be * ae ke_bebe = ke * be * be ki_bebe = ke * ae * bi ke_aibe = ke * ai * be sqrt_e = sp.sqrt(sp.pi / (2 * keR)) sqrt_i = sp.sqrt(sp.pi / (2 * kiR)) sqrt_n = sp.sqrt(sp.pi / (2 * kpnorm)) sqrt_m = sp.sqrt(sp.pi / (2 * ci * kpnorm)) val = 0 for n in myrange(N): Je = sqrt_e * jv(n + 0.5, keR) Ji = sqrt_i * jv(n + 0.5, kiR) Jpe = (n / keR) * Je - sqrt_e * jv(n + 1.5, keR) Jpi = (n / kiR) * Ji - sqrt_i * jv(n + 1.5, kiR) Ye = sqrt_e * yv(n + 0.5, keR) Ype = (n / keR) * Ye - sqrt_e * yv(n + 1.5, keR) locH1 = Je + 1j * Ye locH1p = Jpe + 1j * Ype if field == 'sca': a = ke_aeai * Ji * Jpe b = ki_aebi * Jpi * Je c = ki_aebi * locH1 * Jpi d = ke_aibe * locH1p * Ji v = (2 * n + 1) * ((1j)**n) * (a - b) / (c - d) Jn = sqrt_n * jv(n + 0.5, kpnorm) Jpn = (n / kpnorm) * Jn - sqrt_n * jv(n + 1.5, kpnorm) Yn = sqrt_n * yv(n + 0.5, kpnorm) Ypn = (n / kpnorm) * Yn - sqrt_n * yv(n + 1.5, kpnorm) locH1p = Jpn + 1j * Ypn cn = k * v * locH1p elif field == 'int': a = ke_beae * locH1 * Jpe b = ke_bebe * Je * locH1p c = ki_aebi * locH1 * Jpi d = ke_aibe * locH1p * Ji v = (2 * n + 1) * ((1j)**n) * (a - b) / (c - d) Jn = sqrt_m * jv(n + 0.5, ci * kpnorm) Jpn = (n / (ci * kpnorm)) * Jn - sqrt_m * jv(n + 1.5, ci * kpnorm) cn = ci * k * v * Jpn else: cn = k * ((1j)**n) * (2 * n + 1) * Jp(n, k * pnorm) c = eval_legendre(n, costheta) val += cn * c return val