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

How to compute an element-wise norm of a functional

+4 votes

Hello:
I'm new to Fenics, so maybe this question is a little basic, but i've been looking for in the manual and in the launchpad forums and I haven't found the answer yet.

I need to compute locally (for each element) the L2 norm of the residual, and then possibly plot it in a colormap.

Can this be done in Fenics? How?

Thank you

Fernando

asked Jun 6, 2013 by Fernando Lizarraga FEniCS Novice (220 points)

1 Answer

+6 votes
 
Best answer

Yes, this is easy to do. If you have an Expression called R (could be the residual and it could be something else), then define a DG function (piecewise constant) and assemble into a Vector. Add a weight for the inverse cell area.

DG = FunctionSpace(mesh, "DG", 0)
v = TestFunction(DG)
a = CellVolume(mesh)
r = assemble(R*v/a*dx).array() 

r will then be an array with your indicators. To plot it, either create a DG Function with those values (by assembling right into the Vector of that Function), or create a MeshFunction with values given by the array r.

answered Jun 6, 2013 by logg FEniCS Expert (11,790 points)
selected Jun 6, 2013 by Fernando Lizarraga
It works, now I have to figure out why !
Thank you very much.
I'll leave that as an exercise! ;-)
...