def test_anisotropic_xi_determinants(rnd_data1, rnd_data2, rnd_data3, rnd_data4, rnd_data5): """ Check whether xi zeros from polynomial fulfill the QEVP and the associated GLEVP. This also verifies whether A6x6 and B6x6 are constructed correctly. """ 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 xiarray = m.calcXiNormZeros(x, n, kpa) ((Amatrix6x6, Bmatrix6x6), (Mmatrix, Cmatrix, Kmatrix)) \ = m.calcXiQEVMatricesNorm(x, n, kpa) should_be_zero_1 = np.ones((4, 5), dtype=complex) should_be_zero_2 = np.ones((4, 5), dtype=complex) for j in range(5): for xi_num in range(4): should_be_zero_1[xi_num, j] = np.linalg.det( (Mmatrix[:, :, j] * xiarray[xi_num, j]**2 + Cmatrix[:, :, j] * xiarray[xi_num, j] + Kmatrix[:, :, j])) should_be_zero_2[xi_num, j] = np.linalg.det( (Amatrix6x6[:, :, j] - Bmatrix6x6[:, :, j] * xiarray[xi_num, j])) assert np.allclose(should_be_zero_1, 0) assert np.allclose(should_be_zero_2, 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)
def test_anisotropic_xi_calculation_polynomial_zeros(rnd_data1, rnd_data2, rnd_data3, rnd_data4, rnd_data5): """ Random epsilon tensor, random k vector and random n unit vector. Check whether the roots calculated give really zero for the determinant. The test should work for real and complex epsilon and k values. """ 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 should_be_zero = np.ones((4, 5), dtype=complex) xiarray = m.calcXiNormZeros(x, n, kpa) for i in range(4): should_be_zero[i, :] = m.calcXiDetNorm(xiarray[i], x, n, kpa) assert np.allclose(should_be_zero, 0)