On Friday August 30 2013 23:19:09 Garth N. Wells wrote: > On 30 August 2013 22:50, Johan Hake <[email protected]> wrote: > > On Friday August 30 2013 15:47:28 Garth N. Wells wrote: > >> The functions GenericDofmap::vertex_to_dof_map and > >> GenericDofMap::dof_to_vertex_map are not properly documented (the doc > >> string is the same for both), and I think that they are back to front. > >> The docstring in DofMap has inconsistencies. I would expect that > >> > >> map0 = GenericDofmap::vertex_to_dof_map(...) > >> > >> would mean a map from vertex to dof, i.e. > >> > >> map0[vertex_index] -> dof index > >> > >> and that > >> > >> map1 = GenericDofmap::dof_to_vertex_map(...) > >> > >> would mean a map from dof index to > >> > >> map1[dof_index] -> vertex index > >> > >> Tests (see below code) and the return types also indicate that things > >> are back to front. Can someone clarify the situation? > > > > The map was introduced to help a user map vertex based data onto a > > Function.> > > from dolfin import * > > import numpy as np > > > > mesh = UnitSquareMesh(20,20) > > V = VectorFunctionSpace(mesh, "CG", 1) > > u = Function(V) > > vertex_to_dof_map = V.dofmap().vertex_to_dof_map(mesh) > > > > data = np.reshape(mesh.coordinates()[:], (mesh.num_vertices()*2)) > > u.vector()[:] = data[vertex_to_dof_map] > > plot(u, interactive=True) > > > > The size of the data array should be: > > mesh.num_vertices()*u.value_size() > > > > The documentation should be improved, and not least properly mapped from > > C++ to Python. > > > > The name refer to the mapping that turn vertex based data to dof based and > > reads quite well when used as above. I can see that the word map can be > > missleading. It is not a "map" data structure. It is an index set that > > "maps values". > > > > Still confused? > > I'm not confused. It's clear that the function names are > back-to-front. It doesn't matter what they were included for - they > are members of GenericDofMap and must make sense in that context. > > Since reading from left to right is a well established convention, I > propose that (a) the function names be fixed by reversing them; and > (b) the doc strings be fixed.
Agree on (b). I am not fully convinced by (a). I am not sure what your example tries to show. You are not using the mapping the intended way and I am therefore confused about the whole back-to-front, front-to-back discussion. Johan > Garth > > > Johan > > > >> Garth > >> > >> > >> > >> from dolfin import * > >> > >> mesh = UnitSquareMesh(4, 4) > >> V = FunctionSpace(mesh, "Lagrange", 1) > >> > >> dof_to_vertex = V.dofmap().dof_to_vertex_map(mesh) > >> vertex_to_dof = V.dofmap().vertex_to_dof_map(mesh) > >> > >> for c in cells(mesh): > >> print "Cell index:", c.index() > >> > >> # Get cell dofs > >> dofs = V.dofmap().cell_dofs(c.index()) > >> print " Cell dofs:", dofs > >> > >> # Get vertices from cell > >> cell_vertices0 = sorted([v.index() for v in vertices(c)]) > >> print " Cell vertex indices (from cell):", cell_vertices0 > >> > >> # Get vertices from dof_to_vertex > >> cell_vertices1 = sorted([dof_to_vertex[dof] for dof in dofs]) > >> print " Cell vertex indices (from dof_to_vertex_map):", > >> cell_vertices1 > >> > >> # Get vertices from vertex_to_dof_map > >> cell_vertices2 = sorted([vertex_to_dof[dof] for dof in dofs]) > >> print " Cell vertex indices (from vertex_to_dof_map):", > >> cell_vertices2 > >> > >> _______________________________________________ > >> fenics mailing list > >> [email protected] > >> http://fenicsproject.org/mailman/listinfo/fenics _______________________________________________ fenics mailing list [email protected] http://fenicsproject.org/mailman/listinfo/fenics
