[SciPy-user] += Operator and Slicing of Arrays
Fri Jun 12 12:14:16 CDT 2009
I am in need of some help. I am trying to use the += operator to sum
over edge elements on a triangular mesh. Each edge has an unknown
associated with it. After solving for the unknowns, I am trying to
compute a quantity at the centroid of all triangles in the mesh. On a
flat surface, each edge will be connected to either one or two
triangles. The orientation of the edge and the normals of the
triangles determines whether each triangle attached to the edge is a
"plus" or "minus" triangle for that edge. It is possible for one
triangle to be referenced three times as a "plus" triangle, three
times as a "minus" triangle or any combination of "plus" and
"minus" (1 and 2 or 2 and 1, respectively).
I have a variable tri_idx which relates the edges to the "plus" and
"minus" triangles. I then compute the quantity at the centroid for the
"plus" triangle and "minus" triangle attached to each edge. An example
tri_idx_plus = [0 3 6 3 2 4 1 4]
tri_idx_minus = [1 2 5 3 6 0 1 4]
quantity[tri_idx_plus,...] += edge_unknown[:len(tri_idx_plus),...] *
quantity[tri_idx_minus,...] += edge_unknown[:len(tri_idx_minus)...] *
where basis_p and basis_m are basis functions that expand the unknown
of each edge into a surface function over the "plus" or "minus"
I am pretty sure the problem I am encountering is that tri_idx_plus
mentions indices 3 and 4 twice and tri_idx_minus contains index 1
twice. Is there a way of doing this operation without reverting to
looping over each edge (read: not doing this the slow way).
Thanks in advance!
More information about the SciPy-user