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

dofs numbering of CR and facet numbering

+1 vote

Hello,

I would like to define u = Function(FunctionSpace(mesh, 'CR', 1)) by using the values of a FacetFunction alpha.

for j in range(mesh.num_facets()):
              print alpha.array()[j]
              u.vector()[j] = alpha.array()[j]

My problem is that I do not know if the numbering of DOFs of CR FunctionSpace coincides with the numbering of Facets. If the two numberings are not coincide, how I can get the indices of DOFs of CR which belong to a Facet F? Is there a function that gives you the index of a DOF if you know the coordinates of the point (for example F.midpoint())?

thank you in advance,
Fotini
fotini

asked Jan 29, 2014 by fotini.karakatsani FEniCS Novice (500 points)

1 Answer

+3 votes

Hi, the numberings of any mesh entities and DOFS in general do not coincide. You get indices of DOFs of function from function space using its dofmap. Below is an example of how to obtain index of DOF on a facet. As you can see, you visit each DOF on a shared facet twice. A faster way is shown in the part of code that computes u, but it does not use FacetFunction.

from dolfin import *                                                             
from math import hypot                                                           

mesh = UnitSquareMesh(2, 2)                                                      
V = FunctionSpace(mesh, "CR", 1)                                                 
dofmap = V.dofmap()                                                              

#------------------------------------------------                                

facet_f = FacetFunctionDouble(mesh, 0)                                           
for facet in facets(mesh):                                                       
  facet_f[facet] = facet.midpoint().norm()                                                                                       

v = Function(V)                                                                  
v_v = v.vector()                                                                 
for cell in cells(mesh):                                                         
  dofs = dofmap.cell_dofs(cell.index())                                          
  #dofs_x = dofmap.tabulate_coordinates(cell)                                    
  for i, facet in enumerate(facets(cell)):                                       
    v_v[dofs[i]] = facet_f[facet]                                                

#------------------------------------------------                 

N = V.dim()                                                                      
dof_x = dofmap.tabulate_all_coordinates(mesh)                                    
dof_x.resize(N, 2)                                                               

u = Function(V)                                                                  
u_v = u.vector()                                                                 
for i in range(N):                                                               
  u_v[i] = hypot(dof_x[i, 0], dof_x[i, 1])                                       

plot(u, interactive=True)                                                        
plot(v, interactive=True)     
answered Jan 29, 2014 by MiroK FEniCS Expert (80,920 points)

Thanks a lot for your help!

...