Esempio n. 1
0
 def test_solve_mixed(self, mat, dat):
     x = op2.MixedDat(dat.dataset)
     op2.solve(mat, x, dat)
     b = mat * x
     eps = 1.0e-12
     assert_allclose(dat[0].data_ro, b[0].data_ro, eps)
     assert_allclose(dat[1].data_ro, b[1].data_ro, eps)
Esempio n. 2
0
 def test_solve_mixed(self, mat, dat):
     x = op2.MixedDat(dat.dataset)
     op2.solve(mat, x, dat)
     b = mat * x
     eps = 1.e-12
     assert_allclose(dat[0].data_ro, b[0].data_ro, eps)
     assert_allclose(dat[1].data_ro, b[1].data_ro, eps)
Esempio n. 3
0
 def test_solve(self, backend, mat, b, x, f):
     """Solve a linear system where the solution is equal to the right-hand
     side and check the result."""
     mat.assemble()
     op2.solve(mat, x, b)
     eps = 1.e-8
     assert_allclose(x.data, f.data, eps)
Esempio n. 4
0
 def test_solve(self, backend, mat, b, x, f):
     """Solve a linear system where the solution is equal to the right-hand
     side and check the result."""
     mat.assemble()
     op2.solve(mat, x, b)
     eps = 1.e-8
     assert_allclose(x.data, f.data, eps)
Esempio n. 5
0
    def timestep_iteration():
        # Advection

        if have_advection:
            tic("advection")
            tic("assembly")
            mat.zero()

            op2.par_loop(
                mass,
                elements(3, 3),
                mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC),
                coords(elem_node, op2.READ),
            )

            op2.par_loop(zero_dat, nodes, b(op2.IdentityMap, op2.WRITE))

            op2.par_loop(
                adv_rhs,
                elements(3),
                b(elem_node[op2.i[0]], op2.INC),
                coords(elem_node, op2.READ),
                tracer(elem_node, op2.READ),
                velocity(elem_node, op2.READ),
            )
            toc("assembly")
            tic("solve")
            op2.solve(mat, tracer, b)
            toc("solve")
            toc("advection")

        # Diffusion

        if have_diffusion:
            tic("diffusion")
            tic("assembly")
            mat.zero()

            op2.par_loop(
                diff_matrix,
                elements(3, 3),
                mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC),
                coords(elem_node, op2.READ),
            )

            op2.par_loop(zero_dat, nodes, b(op2.IdentityMap, op2.WRITE))

            op2.par_loop(
                diff_rhs,
                elements(3),
                b(elem_node[op2.i[0]], op2.INC),
                coords(elem_node, op2.READ),
                tracer(elem_node, op2.READ),
            )

            toc("assembly")
            tic("solve")
            op2.solve(mat, tracer, b)
            toc("solve")
            toc("diffusion")
Esempio n. 6
0
    def timestep_iteration():
        # Advection

        if have_advection:
            tic('advection')
            tic('assembly')
            mat.zero()

            op2.par_loop(
                mass, elements(3, 3),
                mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC),
                coords(elem_node, op2.READ))

            op2.par_loop(zero_dat, nodes, b(op2.IdentityMap, op2.WRITE))

            op2.par_loop(adv_rhs, elements(3), b(elem_node[op2.i[0]], op2.INC),
                         coords(elem_node, op2.READ),
                         tracer(elem_node, op2.READ),
                         velocity(elem_node, op2.READ))
            toc('assembly')
            tic('solve')
            op2.solve(mat, tracer, b)
            toc('solve')
            toc('advection')

        # Diffusion

        if have_diffusion:
            tic('diffusion')
            tic('assembly')
            mat.zero()

            op2.par_loop(
                diff_matrix, elements(3, 3),
                mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC),
                coords(elem_node, op2.READ))

            op2.par_loop(zero_dat, nodes, b(op2.IdentityMap, op2.WRITE))

            op2.par_loop(diff_rhs, elements(3), b(elem_node[op2.i[0]],
                                                  op2.INC),
                         coords(elem_node, op2.READ),
                         tracer(elem_node, op2.READ))

            toc('assembly')
            tic('solve')
            op2.solve(mat, tracer, b)
            toc('solve')
            toc('diffusion')
Esempio n. 7
0
    def test_extruded_assemble_mat_rhs_solve(self, backend, xtr_mat,
                                             xtr_coords, xtr_elements,
                                             xtr_elem_node, extrusion_kernel,
                                             xtr_nodes, vol_comp, xtr_dnodes,
                                             vol_comp_rhs, xtr_b):
        coords_dim = 3
        coords_xtr_dim = 3  # dimension
        # BIG TRICK HERE:
        # We need the +1 in order to include the entire column of vertices.
        # Extrusion is meant to iterate over the 3D cells which are layer - 1 in number.
        # The +1 correction helps in the case of iteration over vertices which need
        # one extra layer.
        iterset = op2.Set(NUM_NODES, "verts1")
        iterset = op2.ExtrudedSet(iterset, layers=(layers + 1))
        vnodes = op2.DataSet(iterset, coords_dim)

        d_nodes_xtr = op2.DataSet(xtr_nodes, coords_xtr_dim)
        d_lnodes_xtr = op2.DataSet(xtr_nodes, 1)

        # Create an op2.Dat with the base mesh coordinates
        coords_vec = numpy.zeros(vnodes.total_size * coords_dim)
        length = len(xtr_coords.flatten())
        coords_vec[0:length] = xtr_coords.flatten()
        coords = op2.Dat(vnodes, coords_vec, numpy.float64, "dat1")

        # Create an op2.Dat with slots for the extruded coordinates
        coords_new = numpy.array([0.] * layers * NUM_NODES * coords_xtr_dim,
                                 dtype=numpy.float64)
        coords_xtr = op2.Dat(d_nodes_xtr, coords_new, numpy.float64, "dat_xtr")

        # Creat an op2.Dat to hold the layer number
        layer_vec = numpy.tile(numpy.arange(0, layers), NUM_NODES)
        layer = op2.Dat(d_lnodes_xtr, layer_vec, numpy.int32, "dat_layer")

        # Map a map for the bottom of the mesh.
        vertex_to_coords = [i for i in range(0, NUM_NODES)]
        v2coords_offset = numpy.array([0], numpy.int32)
        map_2d = op2.Map(iterset, iterset, 1, vertex_to_coords, "v2coords",
                         v2coords_offset)

        # Create Map for extruded vertices
        vertex_to_xtr_coords = [layers * i for i in range(0, NUM_NODES)]
        v2xtr_coords_offset = numpy.array([1], numpy.int32)
        map_xtr = op2.Map(iterset, xtr_nodes, 1, vertex_to_xtr_coords,
                          "v2xtr_coords", v2xtr_coords_offset)

        # Create Map for layer number
        v2xtr_layer_offset = numpy.array([1], numpy.int32)
        layer_xtr = op2.Map(iterset, xtr_nodes, 1, vertex_to_xtr_coords,
                            "v2xtr_layer", v2xtr_layer_offset)

        op2.par_loop(extrusion_kernel, iterset,
                     coords_xtr(op2.INC, map_xtr, flatten=True),
                     coords(op2.READ, map_2d, flatten=True),
                     layer(op2.READ, layer_xtr))

        # Assemble the main matrix.
        op2.par_loop(
            vol_comp, xtr_elements,
            xtr_mat(op2.INC,
                    (xtr_elem_node[op2.i[0]], xtr_elem_node[op2.i[1]])),
            coords_xtr(op2.READ, xtr_elem_node))

        eps = 1.e-5
        xtr_mat.assemble()
        assert_allclose(sum(sum(xtr_mat.values)), 36.0, eps)

        # Assemble the RHS
        xtr_f_vals = numpy.array([1] * NUM_NODES * layers, dtype=numpy.int32)
        xtr_f = op2.Dat(d_lnodes_xtr, xtr_f_vals, numpy.int32, "xtr_f")

        op2.par_loop(vol_comp_rhs, xtr_elements,
                     xtr_b(op2.INC, xtr_elem_node[op2.i[0]], flatten=True),
                     coords_xtr(op2.READ, xtr_elem_node, flatten=True),
                     xtr_f(op2.READ, xtr_elem_node))

        assert_allclose(sum(xtr_b.data), 6.0, eps)

        x_vals = numpy.zeros(NUM_NODES * layers, dtype=valuetype)
        xtr_x = op2.Dat(d_lnodes_xtr, x_vals, valuetype, "xtr_x")

        op2.solve(xtr_mat, xtr_x, xtr_b)

        assert_allclose(sum(xtr_x.data), 7.3333333, eps)
Esempio n. 8
0
    def test_extruded_assemble_mat_rhs_solve(
        self, backend, xtr_mat, xtr_coords, xtr_elements,
        xtr_elem_node, extrusion_kernel, xtr_nodes, vol_comp,
            xtr_dnodes, vol_comp_rhs, xtr_b):
        coords_dim = 3
        coords_xtr_dim = 3  # dimension
        # BIG TRICK HERE:
        # We need the +1 in order to include the entire column of vertices.
        # Extrusion is meant to iterate over the 3D cells which are layer - 1 in number.
        # The +1 correction helps in the case of iteration over vertices which need
        # one extra layer.
        iterset = op2.Set(NUM_NODES, "verts1")
        iterset = op2.ExtrudedSet(iterset, layers=(layers + 1))
        vnodes = op2.DataSet(iterset, coords_dim)

        d_nodes_xtr = op2.DataSet(xtr_nodes, coords_xtr_dim)
        d_lnodes_xtr = op2.DataSet(xtr_nodes, 1)

        # Create an op2.Dat with the base mesh coordinates
        coords_vec = numpy.zeros(vnodes.total_size * coords_dim)
        length = len(xtr_coords.flatten())
        coords_vec[0:length] = xtr_coords.flatten()
        coords = op2.Dat(vnodes, coords_vec, numpy.float64, "dat1")

        # Create an op2.Dat with slots for the extruded coordinates
        coords_new = numpy.array(
            [0.] * layers * NUM_NODES * coords_xtr_dim, dtype=numpy.float64)
        coords_xtr = op2.Dat(d_nodes_xtr, coords_new, numpy.float64, "dat_xtr")

        # Creat an op2.Dat to hold the layer number
        layer_vec = numpy.tile(numpy.arange(0, layers), NUM_NODES)
        layer = op2.Dat(d_lnodes_xtr, layer_vec, numpy.int32, "dat_layer")

        # Map a map for the bottom of the mesh.
        vertex_to_coords = [i for i in range(0, NUM_NODES)]
        v2coords_offset = numpy.array([0], numpy.int32)
        map_2d = op2.Map(iterset, iterset, 1, vertex_to_coords, "v2coords", v2coords_offset)

        # Create Map for extruded vertices
        vertex_to_xtr_coords = [layers * i for i in range(0, NUM_NODES)]
        v2xtr_coords_offset = numpy.array([1], numpy.int32)
        map_xtr = op2.Map(
            iterset, xtr_nodes, 1, vertex_to_xtr_coords, "v2xtr_coords", v2xtr_coords_offset)

        # Create Map for layer number
        v2xtr_layer_offset = numpy.array([1], numpy.int32)
        layer_xtr = op2.Map(
            iterset, xtr_nodes, 1, vertex_to_xtr_coords, "v2xtr_layer", v2xtr_layer_offset)

        op2.par_loop(extrusion_kernel, iterset,
                     coords_xtr(op2.INC, map_xtr, flatten=True),
                     coords(op2.READ, map_2d, flatten=True),
                     layer(op2.READ, layer_xtr))

        # Assemble the main matrix.
        op2.par_loop(vol_comp, xtr_elements,
                     xtr_mat(op2.INC, (xtr_elem_node[op2.i[0]], xtr_elem_node[op2.i[1]])),
                     coords_xtr(op2.READ, xtr_elem_node))

        eps = 1.e-5
        xtr_mat.assemble()
        assert_allclose(sum(sum(xtr_mat.values)), 36.0, eps)

        # Assemble the RHS
        xtr_f_vals = numpy.array([1] * NUM_NODES * layers, dtype=numpy.int32)
        xtr_f = op2.Dat(d_lnodes_xtr, xtr_f_vals, numpy.int32, "xtr_f")

        op2.par_loop(vol_comp_rhs, xtr_elements,
                     xtr_b(op2.INC, xtr_elem_node[op2.i[0]], flatten=True),
                     coords_xtr(op2.READ, xtr_elem_node, flatten=True),
                     xtr_f(op2.READ, xtr_elem_node))

        assert_allclose(sum(xtr_b.data), 6.0, eps)

        x_vals = numpy.zeros(NUM_NODES * layers, dtype=valuetype)
        xtr_x = op2.Dat(d_lnodes_xtr, x_vals, valuetype, "xtr_x")

        op2.solve(xtr_mat, xtr_x, xtr_b)

        assert_allclose(sum(xtr_x.data), 7.3333333, eps)
Esempio n. 9
0
 def test_vector_solve(self, backend, vecmat, b_vec, x_vec, f_vec):
     op2.solve(vecmat, x_vec, b_vec)
     eps = 1.e-12
     assert_allclose(x_vec.data, f_vec.data, eps)
Esempio n. 10
0
 def test_solve(self, backend, mat, b, x, f):
     op2.solve(mat, x, b)
     eps = 1.e-8
     assert_allclose(x.data, f.data, eps)
Esempio n. 11
0
 def test_vector_solve(self, backend, vecmat, b_vec, x_vec, f_vec):
     """Solve a linear system with a vector matrix where the solution is
     equal to the right-hand side and check the result."""
     op2.solve(vecmat, x_vec, b_vec)
     eps = 1.e-12
     assert_allclose(x_vec.data, f_vec.data, eps)