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

How to create a dolfin function that operates on vertex index rather than position

0 votes

Is it possible to create a dolfin function that operates on the index of a vertex rather than its position coordinates? It appears that the GenericFunction class only allows you to implement the eval function which takes coordinates of a point rather than the index of a vertex.

I would like to use this function in a boundary condition.

asked Nov 17, 2016 by rviertel FEniCS Novice (700 points)

1 Answer

0 votes

Consider a VertexFunction. This subtype of MeshFunction has values only defined at vertices of the mesh, indexed by the vertices of the mesh.

from dolfin import *

mesh = UnitSquareMesh(4, 4)

vf = VertexFunction('size_t', mesh, 0)

for v in vertices(mesh):
  vf[v] = v.index()

print vf.array()

Bear in mind that boundary conditions are naturally applied to facets: e.g.

 ff = FacetFunction('size_t', mesh, 0)
 ds = Measure('ds', subdomain_data=ff)

Is is possible to apply boundary conditions to pointwise data. But this must be done geometrically using DirichletBC I believe. Someone may correct me.

answered Nov 17, 2016 by nate FEniCS Expert (17,050 points)

Assuming that I use a P1 lagrange element then are not the boundary conditions naturally applied to boundary nodes not facets?

I had considered using the DirichletBC class in conjunction with a VertexFunction, but DirichletBC only takes a GeneralFunction as an argument, which requires point data, mesh functions can only be used with it to specify the boundary. Are there any other classes that can be used to specify a boundary condition?

Boundary conditions are applied to facets. You must integrate the basis of your FE solution space over subsets of the exterior boundary to compute boundary terms. You may be interested in applying DirichletBC "pointwise" as I suggested. Documentation here.

...