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

Visualising shape functions

+3 votes

Hi,

Is it possible to visualise each of the basis functions for a particular element?

Specifically, I would like to take a single triangular element, and plot the shape functions for a linear, quadratic, and cubic element, using FEniCS.

Cheers,

Chris

asked Mar 3, 2014 by christopher.laing FEniCS Novice (290 points)

1 Answer

+4 votes
 
Best answer

For linear elements it is straight forward --
For higher order elements, it looks like you have to interpolate v to a finer grid.

import dolfin
mesh = dolfin.UnitSquareMesh(10,10)
V = dolfin.FunctionSpace(mesh, 'CG', 1)
v = dolfin.Function(V)
v.vector()[70] = 1
dolfin.plot(v)
dolfin.interactive()

## continue....
V = dolfin.FunctionSpace(mesh, 'CG', 2)
v = dolfin.Function(V)
v.vector()[200] = 1

mesh2 = dolfin.UnitSquareMesh(100,100)
V2 = dolfin.FunctionSpace(mesh2, 'CG', 2)
v2 = dolfin.interpolate(v, V2)
dolfin.plot(v2)
dolfin.interactive()
answered Mar 3, 2014 by Jan FEniCS User (8,290 points)
edited Mar 4, 2014 by Jan

Wonderful! Thanks, Jan.

Just in case anybody wishes to directly copy your code, you might wish to change

V = dolfin.FunctionSpace(mesh, 'CG', 2)

to

V2 = dolfin.FunctionSpace(mesh2, 'CG', 2)

Also, should you not be setting

v2.vector()[200] = 1

after you interpolate to the new FunctionSpace? Otherwise there are surely not enough entries in the vector.

Oh, yes, I've tried a few things and then I mixed it up. Now it should work with copy and paste....

...