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) # print A_mat test_main()
def assert_polyfun_equal(p1, p2): x = np.poly1d([1, 0]) assert_array_almost_equal(p1(x), p2(x)) def test_poly1d_func(): p4 = np.array([3.0, 4, 5, 6]) pf = Poly1dFunction(np.poly1d(p4)) assert_equal(pf(2), 24 + 16 + 10 + 6) pf = Poly1dFunction.from_coeffs(p4) assert_equal(pf(2), 24 + 16 + 10 + 6) def test_poly1d_func_deriv(): p4 = np.array([3.0, 4, 5, 6]) p3 = np.array([9.0, 8, 5]) p2 = np.array([18.0, 8]) pf = Poly1dFunction(np.poly1d(p4)) assert_polyfun_equal(pf, np.poly1d(p4)) assert_polyfun_equal(pf.D, np.poly1d(p3)) assert_polyfun_equal(pf.D.D, np.poly1d(p2)) def test_poly1d_func_ops(): p1 = Poly1dFunction.from_coeffs([5.0, 4]) p2 = Poly1dFunction.from_coeffs([2.0, 3, 4]) assert_equal((p1 * p2)(3), 19 * 31) assert_equal((p1 + p2)(3), 19 + 31) test_main(True)