Beispiel #1
0
def test_prec_solve_2D(arpack_eigs, interface, x, num_evs, tol, atol, interactive=False):
    from fvm import JadaHYMLSInterface

    from jadapy import EpetraInterface
    from jadapy import jdqz

    numpy.random.seed(1234)

    jac_op = EpetraInterface.CrsMatrix(interface.jacobian(x))
    mass_op = EpetraInterface.CrsMatrix(interface.mass_matrix())
    jada_interface = JadaHYMLSInterface.JadaHYMLSInterface(interface.map, interface, preconditioned_solve=True)

    alpha, beta = jdqz.jdqz(jac_op, mass_op, num_evs, tol=tol, subspace_dimensions=[20, 40],
                            interface=jada_interface)
    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()
Beispiel #2
0
def generate_Epetra_test_matrix(map, shape, dtype):
    try:
        from PyTrilinos import Epetra
        from jadapy import EpetraInterface
    except ImportError:
        pytest.skip("Trilinos not found")

    a1 = generate_test_matrix(shape, dtype)
    a2 = EpetraInterface.CrsMatrix(Epetra.Copy, map, shape[1])

    for i in range(shape[0]):
        for j in range(shape[1]):
            a2[i, j] = a1[i, j]
    a2.FillComplete()

    return a1, a2