This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

dof_to_vertex_map dolfin 1.3.0

0 votes

Dear all

I have an error when i run the following minimal problem:

from dolfin import*
import numpy as np
mesh=UnitCubeMesh(16, 16, 16)
V = VectorFunctionSpace(mesh, "CG", 2)
noise = Function(V)
noise_vec = np.random.normal(0,0.5,171717)
noise.vector()[:] = noise_vec[vertex_to_dof_map(V)]

Bellow the report error

File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/cpp/fem.py", line 724, in vertex_to_dof_map
return _fem.vertex_to_dof_map(*args)
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at


*** fenics@fenicsproject.org


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to tabulate dof to vertex map.
*** Reason: Can only tabulate dofs on vertices.
*** Where: This error was encountered inside DofMap.cpp.
*** Process: 0


*** DOLFIN version: 1.3.0
*** Git changeset: 45ff879f5d3641a30d04335983e6cbd4823d1b6d

Any help will be appreciated.

asked Jul 30, 2016 by meftahi FEniCS Novice (300 points)

1 Answer

0 votes

vertex_to_dof_map only works with a scalar CG1 FunctionSpace, but why do you need this?

For a CG1 VectorFunctionSpace, you can exploit that the DOFs are stores as vx0 vy0 vz0 vx1 vy1 vz0 ...

If you want to have a CG2 noise vector with some special spatial dependence, you could make use of

myx = interpolate(Expression("x[0]"), FunctionSpace(mesh,'CG',2)).vector()
myy = interpolate(Expression("x[1]"), FunctionSpace(mesh,'CG',2)).vector()
myz = interpolate(Expression("x[2]"), FunctionSpace(mesh,'CG',2)).vector()
answered Aug 2, 2016 by KristianE FEniCS Expert (12,900 points)
...