Numbering of dofs

Asked by Claas Abert

I'm using the trunk version of dolfin and I have two questions concerning the numbering of dofs:

1) Same mesh, different function spaces:
I have a FunctionSpace VS and a VectorFunctionSpace VV (same family and degree)
I want to identify the dofs of the FunctionSpace (d1, d2...) with thoses of the VectorFunctionSpace (d1_x, d2_x ...).

Can I assume that the mapping for a given cell i is always like:

VS.dofmap().cell_dofs(i) => [d1, d2, d3, d4]

VV.dofmap().cell_dofs(i) => [d1_x, d2_x, d3_x, d4_x, d1_y, d2_y, ...]

2) Mesh and extracted SubMesh, same FunctionSpace
Can I assume that the cell_dofs of the same cell in Mesh and SubMesh can be identified like:

dofmap.cell_dofs(i) => [d1, d2, d3, d4]

subdofmap.cell_dofs(cellmap[i]) => [d1, d2, d3, d4]

Thank you very much,
Claas

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Claas Abert
Solved:
Last query:
Last reply:
Revision history for this message
Garth Wells (garth-wells) said :
#1

On Thu, Sep 20, 2012 at 9:41 AM, Claas Abert
<email address hidden> wrote:
> New question #209095 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/209095
>
> I'm using the trunk version of dolfin and I have two questions concerning the numbering of dofs:
>
> 1) Same mesh, different function spaces:
> I have a FunctionSpace VS and a VectorFunctionSpace VV (same family and degree)
> I want to identify the dofs of the FunctionSpace (d1, d2...) with thoses of the VectorFunctionSpace (d1_x, d2_x ...).
>
> Can I assume that the mapping for a given cell i is always like:
>
> VS.dofmap().cell_dofs(i) => [d1, d2, d3, d4]
>

Not sure what you're asking here - d1, d2, etc could be anything.

> VV.dofmap().cell_dofs(i) => [d1_x, d2_x, d3_x, d4_x, d1_y, d2_y, ...]
>

No.

> 2) Mesh and extracted SubMesh, same FunctionSpace
> Can I assume that the cell_dofs of the same cell in Mesh and SubMesh can be identified like:
>
> dofmap.cell_dofs(i) => [d1, d2, d3, d4]
>
> subdofmap.cell_dofs(cellmap[i]) => [d1, d2, d3, d4]
>

You cannot safely make any assumptions as to how dofs are ordered.

Garth

>
> Thank you very much,
> Claas
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
James Maddison (jamesmadd) said :
#2

Is there any way to access information regarding the ordering of dofs? For example, are there any methods available that relate the values in mesh.coordinates() to the values in field.vector().array()?

Revision history for this message
Claas Abert (cabert) said :
#3

Thank you Garth for the quick answer,

I think my explanation was a bit confusing. The concrete problem at hand for question 1 is:

mesh = UnitCube(1, 1, 1)
VS = FunctionSpace(mesh, "Lagrange", 1)
VV = VectorFunctionSpace(mesh, "Lagrange", 1)

a = Function(VV)
b = Function(VV)

Now I want to assemble a matrix A that gives the pointwise inner product with a:

A*b := inner(a,b)

The resulting vector should be compatible to functions of the function space VS.
In order to set up the sparsity pattern and to fill the matrix with values of a.vector(), I need some kind of mapping between the dofs of VS and VV, i.e. for each dof i of the VS space I want to know the corresponding dofs ix, iy, iz of the VV space. (Not sure if I'm using the word dof right, I mean the indices of the underlying vector objects)

Best regards, Claas

Revision history for this message
Garth Wells (garth-wells) said :
#4

On Thu, Sep 20, 2012 at 10:50 AM, James Maddison
<email address hidden> wrote:
> Question #209095 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/209095
>
> James Maddison posted a new comment:
> Is there any way to access information regarding the ordering of dofs?
> For example, are there any methods available that relate the values in
> mesh.coordinates() to the values in field.vector().array()?
>

No, because this would only work in the limited case of scalar P1
continuous elements.

There is a function

    GenericDofMap::tabulate_coordinates

that tabulates the spatial coordinates of each dof on a cell.

Garth

> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Garth Wells (garth-wells) said :
#5

On Thu, Sep 20, 2012 at 11:15 AM, Claas Abert
<email address hidden> wrote:
> Question #209095 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/209095
>
> Status: Answered => Open
>
> Claas Abert is still having a problem:
> Thank you Garth for the quick answer,
>
> I think my explanation was a bit confusing. The concrete problem at hand
> for question 1 is:
>
> mesh = UnitCube(1, 1, 1)
> VS = FunctionSpace(mesh, "Lagrange", 1)
> VV = VectorFunctionSpace(mesh, "Lagrange", 1)
>
> a = Function(VV)
> b = Function(VV)
>
> Now I want to assemble a matrix A that gives the pointwise inner product
> with a:
>
> A*b := inner(a,b)
>
> The resulting vector should be compatible to functions of the function space VS.
> In order to set up the sparsity pattern and to fill the matrix with values of a.vector(), I need some kind of mapping between the dofs of VS and VV, i.e. for each dof i of the VS space I want to know the corresponding dofs ix, iy, iz of the VV space. (Not sure if I'm using the word dof right, I mean the indices of the underlying vector objects)
>

It's not possible to guarantee any relationship between dofs in VS and
VV. If you make VS a subspace of VV, then VS is a view into VV.

Garth

> Best regards, Claas
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Claas Abert (cabert) said :
#6

OK, thank you. I have however one last question. If I do:

V = VectorFunctionSpace(mesh, "Lagrange", 1)

is there at least guaranteed that the dofs for a cell i

dofs_x = V.sub(0).dofmap().cell_dofs(i)
dofs_y = V.sub(1).dofmap().cell_dofs(i)
dofs_z = V.sub(2).dofmap().cell_dofs(i)

are numbered in the same way, i.e. that

v = Function(V).vector()
(v[dofs_x[j]], v[dofs_y[j]], v[dofs_z[j]])

gives the x,y,z values of the vector function at a single mesh node charaterized by i and j?

Thanks in advance, Claas

Revision history for this message
Garth Wells (garth-wells) said :
#7

On Thu, Sep 20, 2012 at 4:41 PM, Claas Abert
<email address hidden> wrote:
> Question #209095 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/209095
>
> Status: Answered => Open
>
> Claas Abert is still having a problem:
> OK, thank you. I have however one last question. If I do:
>
> V = VectorFunctionSpace(mesh, "Lagrange", 1)
>
> is there at least guaranteed that the dofs for a cell i
>
> dofs_x = V.sub(0).dofmap().cell_dofs(i)
> dofs_y = V.sub(1).dofmap().cell_dofs(i)
> dofs_z = V.sub(2).dofmap().cell_dofs(i)
>
> are numbered in the same way, i.e. that
>
> v = Function(V).vector()
> (v[dofs_x[j]], v[dofs_y[j]], v[dofs_z[j]])
>
> gives the x,y,z values of the vector function at a single mesh node
> charaterized by i and j?
>

No. DOLFIN will by default apply a graph re-ordering algorithm to the
dof map (actually to graph generated by (dof map x dof map)) that
treats the problem as an abstract graph, and hence has no concept of
dof components.

The only safe way to work with dofs is via the GenericDofMap member functions.

Garth

> Thanks in advance, Claas
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Claas Abert (cabert) said :
#8

Thank you very much Garth. I will try that out in the next days.