コード例 #1
0
def test_point_array():
    p = Point(1, 2, 3)
    assert np.all(p.array() == (1, 2, 3))

    # Point.array() is a copy, no in-place modification
    p.array()[:] += 1000.0
    assert np.all(p.array() == (1, 2, 3))
コード例 #2
0
def test_mixed_parallel():
    mesh = UnitSquareMesh(MPI.comm_world, 5, 8)
    V = VectorElement("Lagrange", triangle, 4)
    Q = FiniteElement("Lagrange", triangle, 5)
    W = FunctionSpace(mesh, Q * V)
    F = Function(W)

    @function.expression.numba_eval
    def expr_eval(values, x, cell_idx):
        values[:, 0] = x[:, 0]
        values[:, 1] = x[:, 1]
        values[:, 2] = numpy.sin(x[:, 0] + x[:, 1])

    F.interpolate(Expression(expr_eval, shape=(3, )))

    # Generate random points in this mesh partition (one per cell)
    x = numpy.zeros(3)
    for c in Cells(mesh):
        x[0] = random()
        x[1] = random() * (1 - x[0])
        x[2] = (1 - x[0] - x[1])
        p = Point(0.0, 0.0)
        for i, v in enumerate(VertexRange(c)):
            p += v.point() * x[i]
        p = p.array()[:2]

        val = F(p)
        assert numpy.allclose(val[0], p[0])
        assert numpy.isclose(val[1], p[1])
        assert numpy.isclose(val[2], numpy.sin(p[0] + p[1]))
コード例 #3
0
def test_p4_parallel_3d():
    mesh = UnitCubeMesh(MPI.comm_world, 3, 5, 8)
    Q = FunctionSpace(mesh, ("CG", 5))
    F = Function(Q)

    @function.expression.numba_eval
    def x0(values, x, cell_idx):
        values[:, 0] = x[:, 0]

    F.interpolate(Expression(x0))

    # Generate random points in this mesh partition (one per cell)
    x = numpy.zeros(4)
    tree = cpp.geometry.BoundingBoxTree(mesh, mesh.geometry.dim)
    for c in Cells(mesh):
        x[0] = random()
        x[1] = random() * (1 - x[0])
        x[2] = random() * (1 - x[0] - x[1])
        x[3] = 1 - x[0] - x[1] - x[2]
        p = Point(0.0, 0.0, 0.0)
        for i, v in enumerate(VertexRange(c)):
            p += v.point() * x[i]
        p = p.array()

        assert numpy.isclose(F(p, tree)[0], p[0])
コード例 #4
0
def test_p4_parallel_2d():
    mesh = UnitSquareMesh(MPI.comm_world, 5, 8)
    Q = FunctionSpace(mesh, ("CG", 4))
    F = Function(Q)
    F.interpolate(Expression("x[0]", degree=4))

    # Generate random points in this mesh partition (one per cell)
    x = numpy.zeros(3)
    for c in Cells(mesh):
        x[0] = random()
        x[1] = random() * (1 - x[0])
        x[2] = 1 - x[0] - x[1]
        p = Point(0.0, 0.0)
        for i, v in enumerate(VertexRange(c)):
            p += v.point() * x[i]
        p = p.array()[:2]

        assert numpy.isclose(F(p)[0], p[0])
コード例 #5
0
def test_mixed_parallel():
    mesh = UnitSquareMesh(MPI.comm_world, 5, 8)
    V = VectorElement("Lagrange", triangle, 4)
    Q = FiniteElement("Lagrange", triangle, 5)
    W = FunctionSpace(mesh, Q * V)
    F = Function(W)
    F.interpolate(Expression(("x[0]", "x[1]", "sin(x[0] + x[1])"), degree=5))

    # Generate random points in this mesh partition (one per cell)
    x = numpy.zeros(3)
    for c in Cells(mesh):
        x[0] = random()
        x[1] = random() * (1 - x[0])
        x[2] = (1 - x[0] - x[1])
        p = Point(0.0, 0.0)
        for i, v in enumerate(VertexRange(c)):
            p += v.point() * x[i]
        p = p.array()[:2]

        val = F(p)
        assert numpy.allclose(val[0], p[0])
        assert numpy.isclose(val[1], p[1])
        assert numpy.isclose(val[2], numpy.sin(p[0] + p[1]))