#NEWLINE# def test_sum_nodes_to_edges( self , backend ) : #NEWLINE# #INDENT# 'Creates a 1D grid with edge values numbered consecutively.\n        Iterates over edges, summing the node values.' #NEWLINE# nedges = ( nnodes - 1 ) #NEWLINE# nodes = op2 . Set ( nnodes , 'nodes' ) #NEWLINE# edges = op2 . Set ( nedges , 'edges' ) #NEWLINE# node_vals = op2 . Dat ( nodes , numpy . array ( range ( nnodes ) , dtype = numpy . uint32 ) , numpy . uint32 , 'node_vals' ) #NEWLINE# edge_vals = op2 . Dat ( edges , numpy . array ( ( [ 0 ] * nedges ) , dtype = numpy . uint32 ) , numpy . uint32 , 'edge_vals' ) #NEWLINE# e_map = numpy . array ( [ ( i , ( i + 1 ) ) for i in range ( nedges ) ] , dtype = numpy . uint32 ) #NEWLINE# edge2node = op2 . Map ( edges , nodes , 2 , e_map , 'edge2node' ) #NEWLINE# kernel_sum = '\nvoid kernel_sum(unsigned int* nodes[1], unsigned int *edge)\n{ *edge = nodes[0][0] + nodes[1][0]; }\n' #NEWLINE# op2 . par_loop ( op2 . Kernel ( kernel_sum , 'kernel_sum' ) , edges , node_vals ( op2 . READ , edge2node ) , edge_vals ( op2 . WRITE ) ) #NEWLINE# expected = numpy . asarray ( range ( 1 , ( ( nedges * 2 ) + 1 ) , 2 ) ) #NEWLINE# assert all ( ( expected == edge_vals . data ) )