示例#1
0
def test_eval_multiple(W):
    u = Function(W)
    u.vector.set(1.0)
    mesh = W.mesh
    x0 = (mesh.geometry.x(0) + mesh.geometry.x(1)) / 2.0
    x = np.array([x0, x0 + 1.0e8])
    tree = geometry.BoundingBoxTree(mesh, W.mesh.geometry.dim)
    cells = geometry.compute_first_entity_collision(tree, mesh, x)
    u.eval(x[0], cells[0])
示例#2
0
def xtest_near_evaluations(R, mesh):
    # Test that we allow point evaluation that are slightly outside
    bb_tree = cpp.geometry.BoundingBoxTree(mesh, mesh.geometry.dim)
    u0 = Function(R)
    u0.vector.set(1.0)
    a = mesh.geometry.x(0)
    offset = 0.99 * np.finfo(float).eps

    a_shift_x = np.array([a[0] - offset, a[1], a[2]])
    assert u0.eval(a, bb_tree)[0] == pytest.approx(
        u0.eval(a_shift_x, bb_tree)[0])

    a_shift_xyz = np.array([
        a[0] - offset / math.sqrt(3), a[1] - offset / math.sqrt(3),
        a[2] - offset / math.sqrt(3)
    ])
    assert u0.eval(a, bb_tree)[0] == pytest.approx(
        u0.eval(a_shift_xyz, bb_tree)[0])
示例#3
0
def test_eval(R, V, W, Q, mesh):
    u0 = Function(R)
    u1 = Function(V)
    u2 = Function(W)
    u3 = Function(Q)

    def e1(x):
        return x[:, 0] + x[:, 1] + x[:, 2]

    def e2(x):
        values = np.empty((x.shape[0], 3))
        values[:, 0] = x[:, 0] + x[:, 1] + x[:, 2]
        values[:, 1] = x[:, 0] - x[:, 1] - x[:, 2]
        values[:, 2] = x[:, 0] + x[:, 1] + x[:, 2]
        return values

    def e3(x):
        values = np.empty((x.shape[0], 9))
        values[:, 0] = x[:, 0] + x[:, 1] + x[:, 2]
        values[:, 1] = x[:, 0] - x[:, 1] - x[:, 2]
        values[:, 2] = x[:, 0] + x[:, 1] + x[:, 2]
        values[:, 3] = x[:, 0]
        values[:, 4] = x[:, 1]
        values[:, 5] = x[:, 2]
        values[:, 6] = -x[:, 0]
        values[:, 7] = -x[:, 1]
        values[:, 8] = -x[:, 2]
        return values

    u0.vector.set(1.0)
    u1.interpolate(e1)
    u2.interpolate(e2)
    u3.interpolate(e3)

    x0 = (mesh.geometry.x(0) + mesh.geometry.x(1)) / 2.0
    tree = geometry.BoundingBoxTree(mesh, mesh.geometry.dim)
    cells = geometry.compute_first_entity_collision(tree, mesh, x0)
    assert np.allclose(u3.eval(x0, cells)[:3],
                       u2.eval(x0, cells),
                       rtol=1e-15,
                       atol=1e-15)
    with pytest.raises(ValueError):
        u0.eval([0, 0, 0, 0], 0)
    with pytest.raises(ValueError):
        u0.eval([0, 0], 0)