Beispiel #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)
Beispiel #2
0
def test_keys():
    mv = MultiVector()
    mi1 = Multiindex([1, 2, 3])
    mi2 = Multiindex([1, 2, 4])
    mv[mi1] = FlatVector([3, 4, 5])
    mv[mi2] = FlatVector([3, 4, 7])
    keys = mv.keys()
    assert_equal(sorted(keys), sorted([mi1, mi2]))
    inds = mv.active_indices()
    assert_equal(sorted(inds), sorted([mi1, mi2]))