예제 #1
0
def test_matrixization():
    def mult_assemble(a, basis):
        return MultiplicationOperator(a(0), basis)

    mean_func = ConstFunction(2)
    a = [ConstFunction(3), ConstFunction(4)]
    rvs = [UniformRV(), NormalRV(mu=0.5)]
    coeff_field = ListCoefficientField(mean_func, a, rvs)

    A = MultiOperator(coeff_field, mult_assemble)
    mis = [Multiindex([0]),
#           Multiindex([1]),
#           Multiindex([0, 1]),
           Multiindex([0, 2])]
    mesh = UnitSquare(1, 1)
    fs = FunctionSpace(mesh, "CG", 2)
    F = [interpolate(Expression("*".join(["x[0]"] * i)), fs) for i in range(1, 5)]
    vecs = [FEniCSVector(f) for f in F]

    w = MultiVector()
    for mi, vec in zip(mis, vecs):
        w[mi] = vec

    P = w.to_euclidian_operator
    Q = w.from_euclidian_operator
    
    Pw = P.apply(w)
    assert type(Pw) == np.ndarray and len(Pw) == sum((v for v in w.dim.values()))
    QPw = Q.apply(Pw)
    assert w.active_indices() == QPw.active_indices()
    for mu in w.active_indices():
        assert_equal(w[mu].array, QPw[mu].array)
 
    A_linear = P * A * Q
    A_mat = evaluate_operator_matrix(A_linear)
예제 #2
0
    def test_symmetry(A=None, w0=None, **kwargs):
        from spuq.linalg.operator import evaluate_operator_matrix
        v = w0
        P = v.to_euclidian_operator
        Q = v.from_euclidian_operator
        print "Computing the matrix. This may take a while..."
        A_mat = evaluate_operator_matrix(P * A * Q)

        import scipy.linalg as la
        print "norm(A-A^T) = %s" % la.norm(A_mat - A_mat.T)
        print "norm(A) = %s" % la.norm(A_mat)
        B = 0.5 * (A_mat + A_mat.T)
        lam = la.eig(B)[0]
        print "l_min = %s, l_max = %s" % (min(lam), max(lam))