Пример #1
0
def test_2D(arpack_eigs, interface, x, num_evs, tol, atol, interactive=False):
    from fvm import JadaInterface
    from jadapy import jdqz

    numpy.random.seed(1234)

    jac_op = JadaInterface.JadaOp(interface.jacobian(x))
    mass_op = JadaInterface.JadaOp(interface.mass_matrix())

    alpha, beta = jdqz.jdqz(jac_op,
                            mass_op,
                            num_evs,
                            tol=tol,
                            subspace_dimensions=[20, 40],
                            target=0.1)
    jdqz_eigs = numpy.array(sorted(alpha / beta, key=lambda x: abs(x)))
    jdqz_eigs = jdqz_eigs[:num_evs]

    assert_allclose(jdqz_eigs.real, arpack_eigs.real, rtol=0, atol=atol)
    assert_allclose(abs(jdqz_eigs.imag),
                    abs(arpack_eigs.imag),
                    rtol=0,
                    atol=atol)

    if not interactive:
        return x

    fig, ax = plt.subplots()
    ax.scatter(jdqz_eigs.real, jdqz_eigs.imag, marker='+')
    plt.show()
Пример #2
0
def test_complex_shifted_prec_solve_2D(arpack_eigs,
                                       interface,
                                       x,
                                       num_evs,
                                       tol,
                                       atol,
                                       interactive=False):
    from fvm import JadaInterface
    from jadapy import jdqz

    numpy.random.seed(1234)

    jac_op = JadaInterface.JadaOp(interface.jacobian(x))
    mass_op = JadaInterface.JadaOp(interface.mass_matrix())
    jada_interface = JadaInterface.JadaInterface(interface,
                                                 jac_op,
                                                 mass_op,
                                                 len(x),
                                                 numpy.complex128,
                                                 preconditioned_solve=True,
                                                 shifted=True)

    assert jada_interface.preconditioned_solve
    assert jada_interface.shifted

    alpha, beta, v = jdqz.jdqz(jac_op,
                               mass_op,
                               num_evs,
                               tol=tol,
                               subspace_dimensions=[20, 40],
                               arithmetic='complex',
                               return_eigenvectors=True,
                               interface=jada_interface)
    check_eigenvalues(jac_op, mass_op, alpha / beta, v, num_evs, atol)

    jdqz_eigs = numpy.array(sorted(alpha / beta, key=lambda x: abs(x)))

    assert_allclose(jdqz_eigs.real, arpack_eigs.real, rtol=0, atol=atol)
    assert_allclose(abs(jdqz_eigs.imag),
                    abs(arpack_eigs.imag),
                    rtol=0,
                    atol=atol)

    if not interactive:
        return x

    fig, ax = plt.subplots()
    ax.scatter(jdqz_eigs.real, jdqz_eigs.imag, marker='+')
    plt.show()
Пример #3
0
def arpack_eigs(numpy_interface, numpy_x, num_evs, tol, atol):
    from fvm import JadaInterface

    A_op = JadaInterface.JadaOp(numpy_interface.jacobian(numpy_x))
    B_op = JadaInterface.JadaOp(numpy_interface.mass_matrix())

    # A_mat = A_op.mat.todense()
    # B_mat = B_op.mat.todense()

    # eigs, v = scipy.linalg.eig(A_mat, B_mat, left=False, right=True)
    eigs, v = sparse.linalg.eigs(A_op, num_evs, B_op, sigma=0.1, tol=tol)

    check_eigenvalues(A_op, B_op, eigs, v, num_evs, atol)
    eigs = numpy.array(sorted(eigs, key=lambda x: abs(x)))
    return eigs[:num_evs]