当前位置: 首页>>代码示例>>Python>>正文


Python op2.par_loop函数代码示例

本文整理汇总了Python中pyop2.op2.par_loop函数的典型用法代码示例。如果您正苦于以下问题:Python par_loop函数的具体用法?Python par_loop怎么用?Python par_loop使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了par_loop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_direct

    def test_direct(self, s1, d1):

        def fn(a):
            a[:] = 1.0

        op2.par_loop(fn, s1, d1(op2.WRITE))
        assert np.allclose(d1.data, 1.0)
开发者ID:OP2,项目名称:PyOP2,代码行数:7,代码来源:test_pyparloop.py

示例2: test_linalg_and_parloop

 def test_linalg_and_parloop(self, backend, x, y):
     """Linear algebra operators should force computation"""
     x._data = np.zeros(x.dataset.total_size, dtype=np.float64)
     k = op2.Kernel('void k(double *x) { *x = 1.0; }', 'k')
     op2.par_loop(k, x.dataset.set, x(op2.WRITE))
     z = x + y
     assert all(z.data == y.data + 1)
开发者ID:jabooth,项目名称:PyOP2,代码行数:7,代码来源:test_linalg.py

示例3: test_assemble_rhs

    def test_assemble_rhs(self, rhs, elements, b, coords, f, elem_node, expected_rhs):
        """Assemble a simple finite-element right-hand side and check result."""
        b.zero()
        op2.par_loop(rhs, elements, b(op2.INC, elem_node), coords(op2.READ, elem_node), f(op2.READ, elem_node))

        eps = 1.0e-12
        assert_allclose(b.data, expected_rhs, eps)
开发者ID:OP2,项目名称:PyOP2,代码行数:7,代码来源:test_matrices.py

示例4: test_uninitialized_map

 def test_uninitialized_map(self, backend, iterset, indset, x):
     """Accessing a par_loop argument via an uninitialized Map should raise
     an exception."""
     kernel_wo = "void kernel_wo(unsigned int* x) { *x = 42; }\n"
     with pytest.raises(MapValueError):
         op2.par_loop(op2.Kernel(kernel_wo, "kernel_wo"), iterset,
                      x(op2.WRITE, op2.Map(iterset, indset, 1)))
开发者ID:joshcc3,项目名称:PyOP2,代码行数:7,代码来源:test_indirect_loop.py

示例5: test_onecolor_rw

    def test_onecolor_rw(self, backend, iterset, x, iterset2indset):
        """Increment each value of a Dat by one with op2.RW."""
        kernel_rw = "void kernel_rw(unsigned int* x) { (*x) = (*x) + 1; }\n"

        op2.par_loop(op2.Kernel(kernel_rw, "kernel_rw"),
                     iterset, x(op2.RW, iterset2indset[0]))
        assert sum(x.data) == nelems * (nelems + 1) / 2
开发者ID:joshcc3,项目名称:PyOP2,代码行数:7,代码来源:test_indirect_loop.py

示例6: test_invert_arg_similar_shape

    def test_invert_arg_similar_shape(self, iterset, iter2ind1, x, y):
        self.cache.clear()
        assert len(self.cache) == 0

        kernel_swap = """
static void swap(unsigned int* x, unsigned int* y)
{
  unsigned int t;
  t = *x;
  *x = *y;
  *y = t;
}
"""
        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     x(op2.RW, iter2ind1),
                     y(op2.RW, iter2ind1))

        base._trace.evaluate(set([x]), set())
        assert len(self.cache) == 1

        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     y(op2.RW, iter2ind1),
                     x(op2.RW, iter2ind1))

        base._trace.evaluate(set([y]), set())
        assert len(self.cache) == 1
开发者ID:OP2,项目名称:PyOP2,代码行数:28,代码来源:test_caching.py

示例7: test_vector_map

    def test_vector_map(self, iterset, x2, iter2ind2):
        self.cache.clear()
        assert len(self.cache) == 0

        kernel_swap = """
static void swap(unsigned int* x)
{
  unsigned int t;
  t = x[0];
  x[0] = x[1];
  x[1] = t;
}
"""

        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     x2(op2.RW, iter2ind2))

        base._trace.evaluate(set([x2]), set())
        assert len(self.cache) == 1

        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     x2(op2.RW, iter2ind2))

        base._trace.evaluate(set([x2]), set())
        assert len(self.cache) == 1
开发者ID:OP2,项目名称:PyOP2,代码行数:27,代码来源:test_caching.py

示例8: test_sum_nodes_to_edges

    def test_sum_nodes_to_edges(self, backend):
        """Creates a 1D grid with edge values numbered consecutively.
        Iterates over edges, summing the node values."""

        nedges = nnodes - 1
        nodes = op2.Set(nnodes, "nodes")
        edges = op2.Set(nedges, "edges")

        node_vals = op2.Dat(nodes, numpy.arange(nnodes, dtype=numpy.uint32), numpy.uint32, "node_vals")
        edge_vals = op2.Dat(edges, numpy.zeros(nedges, dtype=numpy.uint32), numpy.uint32, "edge_vals")

        e_map = numpy.array([(i, i + 1) for i in range(nedges)], dtype=numpy.uint32)
        edge2node = op2.Map(edges, nodes, 2, e_map, "edge2node")

        kernel_sum = """
void kernel_sum(unsigned int* nodes, unsigned int *edge, int i)
{ *edge += nodes[0]; }
"""

        op2.par_loop(
            op2.Kernel(kernel_sum, "kernel_sum"), edges, node_vals(op2.READ, edge2node[op2.i[0]]), edge_vals(op2.INC)
        )

        expected = numpy.arange(1, nedges * 2 + 1, 2)
        assert all(expected == edge_vals.data)
开发者ID:joshcc3,项目名称:PyOP2,代码行数:25,代码来源:test_iteration_space_dats.py

示例9: test_assemble_mat

 def test_assemble_mat(self, backend, mass, mat, coords, elements, elem_node,
                       elem_vnode, expected_matrix):
     op2.par_loop(mass, elements(3,3),
                  mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC),
                  coords(elem_vnode, op2.READ))
     eps=1.e-5
     assert_allclose(mat.values, expected_matrix, eps)
开发者ID:RomainBrault,项目名称:PyOP2,代码行数:7,代码来源:test_matrices.py

示例10: test_invert_arg_similar_shape

    def test_invert_arg_similar_shape(self, backend, iterset, iter2ind1, x, y):
        self.cache.clear()
        assert len(self.cache) == 0

        kernel_swap = """
void kernel_swap(unsigned int* x, unsigned int* y)
{
  unsigned int t;
  t = *x;
  *x = *y;
  *y = t;
}
"""
        op2.par_loop(op2.Kernel(kernel_swap, "kernel_swap"),
                     iterset,
                     x(iter2ind1[0], op2.RW),
                     y(iter2ind1[0], op2.RW))

        assert len(self.cache) == 1

        op2.par_loop(op2.Kernel(kernel_swap, "kernel_swap"),
                     iterset,
                     y(iter2ind1[0], op2.RW),
                     x(iter2ind1[0], op2.RW))

        assert len(self.cache) == 1
开发者ID:RomainBrault,项目名称:PyOP2,代码行数:26,代码来源:test_caching.py

示例11: test_1d_inc_no_data

    def test_1d_inc_no_data(self, k1_inc_to_global, set, d1):
        g = op2.Global(1, dtype=numpy.uint32)
        op2.par_loop(k1_inc_to_global, set,
                     g(op2.INC),
                     d1(op2.READ))

        assert g.data == d1.data.sum()
开发者ID:OP2,项目名称:PyOP2,代码行数:7,代码来源:test_global_reduction.py

示例12: test_idx_order

    def test_idx_order(self, backend, iterset, iter2ind2, x):
        self.cache.clear()
        assert len(self.cache) == 0

        kernel_swap = """
void kernel_swap(unsigned int* x, unsigned int* y)
{
  unsigned int t;
  t = *x;
  *x = *y;
  *y = t;
}
"""
        op2.par_loop(op2.Kernel(kernel_swap, "kernel_swap"),
                     iterset,
                     x(iter2ind2[0], op2.RW),
                     x(iter2ind2[1], op2.RW))

        assert len(self.cache) == 1

        op2.par_loop(op2.Kernel(kernel_swap, "kernel_swap"),
                     iterset,
                     x(iter2ind2[1], op2.RW),
                     x(iter2ind2[0], op2.RW))

        assert len(self.cache) == 1
开发者ID:RomainBrault,项目名称:PyOP2,代码行数:26,代码来源:test_caching.py

示例13: get_restriction_weights

def get_restriction_weights(coarse, fine):
    mesh = coarse.mesh()
    assert hasattr(mesh, "_shared_data_cache")
    cache = mesh._shared_data_cache["hierarchy_restriction_weights"]
    key = entity_dofs_key(coarse.fiat_element.entity_dofs())
    try:
        return cache[key]
    except KeyError:
        # We hit each fine dof more than once since we loop
        # elementwise over the coarse cells.  So we need a count of
        # how many times we did this to weight the final contribution
        # appropriately.
        if not (coarse.ufl_element() == fine.ufl_element()):
            raise ValueError("Can't transfer between different spaces")
        if coarse.fiat_element.entity_dofs() == coarse.fiat_element.entity_closure_dofs():
            return cache.setdefault(key, None)
        ele = coarse.ufl_element()
        if isinstance(ele, ufl.VectorElement):
            ele = ele.sub_elements()[0]
            weights = firedrake.Function(firedrake.FunctionSpace(fine.mesh(), ele))
        else:
            weights = firedrake.Function(fine)
        c2f_map = coarse_to_fine_node_map(coarse, fine)
        kernel = get_count_kernel(c2f_map.arity)
        op2.par_loop(kernel, op2.LocalSet(mesh.cell_set),
                     weights.dat(op2.INC, c2f_map[op2.i[0]]))
        weights.assign(1/weights)
        return cache.setdefault(key, weights)
开发者ID:kalogirou,项目名称:firedrake,代码行数:28,代码来源:utils.py

示例14: test_indirect

    def test_indirect(self, s1, d2, m12):

        def fn(a):
            a[0] = 1.0

        op2.par_loop(fn, s1, d2(op2.WRITE, m12))
        assert np.allclose(d2.data, 1.0)
开发者ID:OP2,项目名称:PyOP2,代码行数:7,代码来源:test_pyparloop.py

示例15: test_2d_read

    def test_2d_read(self, backend, k2_write_to_dat, set, d1):
        g = op2.Global(2, (1, 2), dtype=numpy.uint32)
        op2.par_loop(k2_write_to_dat, set,
                     d1(op2.IdentityMap, op2.WRITE),
                     g(op2.READ))

        assert all(d1.data == g.data.sum())
开发者ID:RomainBrault,项目名称:PyOP2,代码行数:7,代码来源:test_global_reduction.py


注:本文中的pyop2.op2.par_loop函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。