Hi
I already have a code that produces a
- vector vtx2dof that maps vertex numbers to DOF numbers for a CG1 field.
- mesh using the mesh editor.
The problem with the current code is that it is not vectorized, i.e. it uses for loops. I would appreciate feedback on how to vectorize the code.
vtx2dof code. Something like "cells = dof.all_cell_dofs" would be ideal.
ntri = mesh.num_cells()
dof = FunctionSpace(mesh,'CG',1).dofmap()
cells = numpy.empty([ntri, 3], dtype = numpy.intc)
for i in range(ntri):
cells[i, :] = dof.cell_dofs(i)
cells_ = cells.flatten()
I = cells_.argsort()
cells_ = cells_[I]
d = array([True]+(cells_[range(0,ntri*3-1)] != cells_[range(1,ntri*3)]).tolist())
vtx2dof = mesh.cells().flatten()[I][d]
mesh definition code (mesh defined in arrays n_x, n_y and n_enlist)
n_mesh = Mesh()
ed = MeshEditor()
ed.open(n_mesh, 2, 2)
ed.init_vertices(len(n_x))
for i in range(len(n_x)):
ed.add_vertex(i, n_x[i], n_y[i])
ed.init_cells(len(n_enlist)/3)
for i in range(len(n_enlist)/3):
ed.add_cell(i, n_enlist[i * 3], n_enlist[i * 3 + 1], n_enlist[i * 3 + 2])
ed.close()
Thanks a lot