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

How to read the parameters of a FunctionSpace?

+6 votes

Dear FEniCS users and experts,

I have a very basic question. Till now I use a python code like

V_DEGREE = 3
V = FunctionSpace(mesh, "CG", V_DEGREE)

if I want to change the space degree frequently because I need to use the degree on many different places in the code. It is possible to use something like V_DEGREE = V.degree?

Thak you in advance!

asked Jul 22, 2014 by luk.p FEniCS User (3,470 points)

2 Answers

+4 votes
 
Best answer

The command you are looking for is

V.ufl_element().degree()
answered Jul 28, 2014 by cevito FEniCS User (5,550 points)
selected Jul 30, 2014 by luk.p

Great, thank you very much.

0 votes

I will try now to answer my question. As FunctionSpace.h documentation says, the only possibility is to extract somehow this piece of information from dofmap(). For example, you can do:

from dolfin import *
mesh = UnitSquareMesh(10,10)
V =  FunctionSpace(mesh, "CG", 3)

maxCellDim = V.dofmap().max_cell_dimension()

print "maximum cell dimension = ", maxCellDim

And from maxCellDim you can obtain the degree using e.g. the fact that $\sum_{k=1}^n k = \frac{n(n+1)}{2}$. In my opinion, the reason you are not able to just write something like V.degree() is that FEniCS can use different spaces for different cells in a mesh... Or is there any different solution?

answered Jul 27, 2014 by luk.p FEniCS User (3,470 points)
...