def test_anisotropic_xi_eigenvectors(rnd_data1, rnd_data2, rnd_data3, rnd_data4, rnd_data5): """ Check whether eigenvectors fulfill the QEVP. """ lc = LocalCoordinates("1") myeps = rnd_data1 + complex(0, 1) * rnd_data2 # ((epsxx, epsxy, epsxz), (epsyx, epsyy, epsyz), (epszx, epszy, epszz)) = \ # tuple(myeps) m = AnisotropicMaterial(lc, myeps) n = rnd_data3 n = n / np.sqrt(np.sum(n * n, axis=0)) x = np.zeros((3, 5)) k = rnd_data4 + complex(0, 1) * rnd_data5 kpa = k - np.sum(n * k, axis=0) * n ((_, _), (Mmatrix, Cmatrix, Kmatrix)) \ = m.calcXiQEVMatricesNorm(x, n, kpa) (eigenvalues, eigenvectors) = m.calcXiEigenvectorsNorm(x, n, kpa) #print(eigenvalues) should_be_zero = np.ones((4, 3, 5), dtype=complex) for j in range(5): for k in range(4): should_be_zero[k, :, j] = np.dot( (Mmatrix[:, :, j] * eigenvalues[k, j]**2 + Cmatrix[:, :, j] * eigenvalues[k, j] + Kmatrix[:, :, j]), eigenvectors[k, :, j]) assert np.allclose(should_be_zero, 0)
def test_anisotropic_xi_eigenvalues(rnd_data1, rnd_data2, rnd_data3, rnd_data4, rnd_data5, rnd_data6): """ Comparison of eigenvalue calculation for xi from random complex material data. Comparing polynomial calculation from determinant, from quadratic eigenvalue problem and analytical calculation from sympy. """ lc = LocalCoordinates("1") myeps = np.zeros((3, 3), dtype=complex) myeps[0:2, 0:2] = rnd_data1 + complex(0, 1) * rnd_data2 myeps[2, 2] = rnd_data3 + complex(0, 1) * rnd_data4 ((epsxx, epsxy, _), (epsyx, epsyy, _), (_, _, epszz)) = \ tuple(myeps) m = AnisotropicMaterial(lc, myeps) #n = n/np.sqrt(np.sum(n*n, axis=0)) n = np.zeros((3, 1)) n[2, :] = 1 x = np.zeros((3, 1)) k = rnd_data5 + complex(0, 1) * rnd_data6 kpa = k - np.sum(n * k, axis=0) * n (eigenvalues, _) = m.calcXiEigenvectorsNorm(x, n, kpa) xiarray = m.calcXiNormZeros(x, n, kpa) # sympy check with analytical solution kx, ky, xi = sympy.symbols('k_x k_y xi') exx, exy, _, eyx, eyy, _, _, _, ezz \ = sympy.symbols('e_xx e_xy e_xz e_yx e_yy e_yz e_zx e_zy e_zz') #eps = Matrix([[exx, exy, exz], [eyx, eyy, eyz], [ezx, ezy, ezz]]) eps = sympy.Matrix([[exx, exy, 0], [eyx, eyy, 0], [0, 0, ezz]]) v = sympy.Matrix([[kx, ky, xi]]) m = -(v * v.T)[0] * sympy.eye(3) + v.T * v + eps detm = m.det().collect(xi) soldetm = sympy.solve(detm, xi) subsdict = { kx: kpa[0, 0], ky: kpa[1, 0], exx: epsxx, exy: epsxy, eyx: epsyx, eyy: epsyy, ezz: epszz, sympy.I: complex(0, 1) } analytical_solution = np.sort_complex( np.array([sol.evalf(subs=subsdict) for sol in soldetm], dtype=complex)) numerical_solution1 = np.sort_complex(xiarray[:, 0]) numerical_solution2 = np.sort_complex(eigenvalues[:, 0]) assert np.allclose(analytical_solution - numerical_solution1, 0) assert np.allclose(analytical_solution - numerical_solution2, 0)