diff --git a/meanas/fdfd/bloch.py b/meanas/fdfd/bloch.py index 55abbee..0d0ac1a 100644 --- a/meanas/fdfd/bloch.py +++ b/meanas/fdfd/bloch.py @@ -684,11 +684,11 @@ def eigsolve( Qi = Qi_func(theta) c2 = numpy.cos(2 * theta) s2 = numpy.sin(2 * theta) - F = -0.5*s2 * (ZtAZ - DtAD) + c2 * symZtAD + F = -0.5 * s2 * (ZtAZ - DtAD) + c2 * symZtAD trace_deriv = _rtrace_AtB(Qi, F) G = Qi @ F.conj().T @ Qi.conj().T - H = -0.5*s2 * (ZtZ - DtD) + c2 * symZtD + H = -0.5 * s2 * (ZtZ - DtD) + c2 * symZtD trace_deriv -= _rtrace_AtB(G, H) trace_deriv *= 2 @@ -696,12 +696,12 @@ def eigsolve( U_sZtD = U @ symZtD - dE = 2.0 * (_rtrace_AtB(U, symZtAD) - - _rtrace_AtB(ZtAZU, U_sZtD)) + dE = 2.0 * (_rtrace_AtB(U, symZtAD) + - _rtrace_AtB(ZtAZU, U_sZtD)) - d2E = 2 * (_rtrace_AtB(U, DtAD) - - _rtrace_AtB(ZtAZU, U @ (DtD - 4 * symZtD @ U_sZtD)) - - 4 * _rtrace_AtB(U, symZtAD @ U_sZtD)) + d2E = 2 * (_rtrace_AtB(U, DtAD) + - _rtrace_AtB(ZtAZU, U @ (DtD - 4 * symZtD @ U_sZtD)) + - 4 * _rtrace_AtB(U, symZtAD @ U_sZtD)) # Newton-Raphson to find a root of the first derivative: theta = -dE / d2E diff --git a/meanas/fdfd/waveguide_2d.py b/meanas/fdfd/waveguide_2d.py index 2d5cf92..dbc24b3 100644 --- a/meanas/fdfd/waveguide_2d.py +++ b/meanas/fdfd/waveguide_2d.py @@ -253,7 +253,8 @@ def operator_e( mu_yx = sparse.diags(numpy.hstack((mu_parts[1], mu_parts[0]))) mu_z_inv = sparse.diags(1 / mu_parts[2]) - op = (omega * omega * mu_yx @ eps_xy + op = ( + omega * omega * mu_yx @ eps_xy + mu_yx @ sparse.vstack((-Dby, Dbx)) @ mu_z_inv @ sparse.hstack((-Dfy, Dfx)) + sparse.vstack((Dfx, Dfy)) @ eps_z_inv @ sparse.hstack((Dbx, Dby)) @ eps_xy ) @@ -321,7 +322,8 @@ def operator_h( mu_xy = sparse.diags(numpy.hstack((mu_parts[0], mu_parts[1]))) mu_z_inv = sparse.diags(1 / mu_parts[2]) - op = (omega * omega * eps_yx @ mu_xy + op = ( + omega * omega * eps_yx @ mu_xy + eps_yx @ sparse.vstack((-Dfy, Dfx)) @ eps_z_inv @ sparse.hstack((-Dby, Dbx)) + sparse.vstack((Dbx, Dby)) @ mu_z_inv @ sparse.hstack((Dfx, Dfy)) @ mu_xy ) @@ -799,14 +801,12 @@ def sensitivity( Dfx, Dfy = deriv_forward(dxes[0]) Dbx, Dby = deriv_back(dxes[1]) - eps_x, eps_y, eps_z = numpy.split(epsilon, 3) eps_xy = sparse.diags(numpy.hstack((eps_x, eps_y))) eps_z_inv = sparse.diags(1 / eps_z) - mu_x, mu_y, mu_z = numpy.split(mu, 3) + mu_x, mu_y, _mu_z = numpy.split(mu, 3) mu_yx = sparse.diags(numpy.hstack((mu_y, mu_x))) - mu_z_inv = sparse.diags(1 / mu_z) dv_e = dxes[0][0][:, None, None] * dxes[0][1][None, :, None] * dxes[0][2][None, None, :] dv_h = dxes[1][0][:, None, None] * dxes[1][1][None, :, None] * dxes[1][2][None, None, :] @@ -816,7 +816,7 @@ def sensitivity( sens_xy1 = (hv_yx_conj @ (omega * omega @ mu_yx)) * ev_xy sens_xy2 = (hv_yx_conj @ sparse.vstack((Dfx, Dfy)) @ eps_z_inv @ sparse.hstack((Dbx, Dby))) * ev_xy - sens_z = (hv_yx_conj @ sparse.vstack((Dfx, Dfy)) @ (-eps_z_inv * eps_z_inv)) * (sparse.hstack((Dbx, Dby)) @ eps_xy @ ev_xy) + sens_z = (hv_yx_conj @ sparse.vstack((Dfx, Dfy)) @ (-eps_z_inv * eps_z_inv)) * (sparse.hstack((Dbx, Dby)) @ eps_xy @ ev_xy) norm = hv_yx_conj @ ev_xy sens_tot = numpy.concatenate([sens_xy1 + sens_xy2, sens_z]) / (2 * wavenumber * norm) diff --git a/meanas/fdtd/boundaries.py b/meanas/fdtd/boundaries.py index e82deef..131d741 100644 --- a/meanas/fdtd/boundaries.py +++ b/meanas/fdtd/boundaries.py @@ -19,9 +19,13 @@ def conducting_boundary( dirs.remove(direction) u, v = dirs + boundary_slice: list[Any] + shifted1_slice: list[Any] + shifted2_slice: list[Any] + if polarity < 0: - boundary_slice = [slice(None)] * 3 # type: list[Any] - shifted1_slice = [slice(None)] * 3 # type: list[Any] + boundary_slice = [slice(None)] * 3 + shifted1_slice = [slice(None)] * 3 boundary_slice[direction] = 0 shifted1_slice[direction] = 1 @@ -42,7 +46,7 @@ def conducting_boundary( if polarity > 0: boundary_slice = [slice(None)] * 3 shifted1_slice = [slice(None)] * 3 - shifted2_slice = [slice(None)] * 3 # type: list[Any] + shifted2_slice = [slice(None)] * 3 boundary_slice[direction] = -1 shifted1_slice[direction] = -2 shifted2_slice[direction] = -3