Understanding the size of CG and DG function spaces in Fenics

Howdy,

So I’m just trying to understand why the size of function spaces are different than I expect in Fenics.

order_of_polynomial = 1
spatial_mesh= IntervalMesh(n,a,b)
a=0.0
b=1.0
n=32
V = FunctionSpace(spatial_mesh,"CG",order_of_polynomial)
print(V.dim())

I would expect since I choose the number of cells (elements) in 1d to be 32, then the number of basis functions would be 32, one for each element. However it is 33, which I’m not sure why this is.

Furthermore, if I rerun the same code except changing “CG” to “DG” e.g.

V = FunctionSpace(spatial_mesh,"DG",order_of_polynomial)

I see the number of basis functions is 64. Which is twice what I expect, since I would think on an element I_j and I_{j+1} each would have their own linear basis function, but be discontinous across the facet that these elements share. It seems to me perhaps on an 1d element, one defines two basis functions that are on each half of the interval, and the discontinous jump happens at the halfway point within the interval.

Some clarity would be grealy appreciated. Am I misunderstanding what V.dim() is suppose to return i.e it is not the number of basis functiosn present? Thank you.

A first order Lagrange space has one degree of freedom per vertex (see DefElement) This means that an interval with one element has two degrees of freedom (as it has two vertices). Adding another cell to this interval; you get one more vertex, i.e. One more degree of freedom. Thus number of dofs=number of cells + 1.

For DG functions of order 1, you have 2 degrees of freedom per cell.