How to evaluate inner(grad(u), grad(u))

Asked by Vladimir Dergachev

After extracting data from eigenvalue solver:

....
 r, c, rx, cx = solution.get_eigenpair(i)

 u = Function(V)
 u.vector()[:] = rx

I would like to compute the norm of its gradient (to try an implement adaptive mesh refinement), so the code is something like

       w=inner(grad(u), grad(u))

but now I don't know how to convert w to CellFunction("double", mesh) which is something I know how to access.

Any suggestions ?

Thank you !

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Anders Logg
Solved:
Last query:
Last reply:
Revision history for this message
Best Anders Logg (logg) said :
#1

On Tue, Jan 31, 2012 at 03:55:42AM -0000, Vladimir Dergachev wrote:
> New question #186361 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/186361
>
> After extracting data from eigenvalue solver:
>
> ....
> r, c, rx, cx = solution.get_eigenpair(i)
>
> u = Function(V)
> u.vector()[:] = rx
>
> I would like to compute the norm of its gradient (to try an implement adaptive mesh refinement), so the code is something like
>
> w=inner(grad(u), grad(u))
>
> but now I don't know how to convert w to CellFunction("double", mesh) which is something I know how to access.
>
> Any suggestions ?

If you want to cell-wise assemble the above form, then do something
like this:

DG0 = FunctionSpace(mesh, "DG", 0)
v = TestFunction(DG0)
w = v* inner(grad(u), grad(u))*dx
b = assemble(w)

That should give you a vector with values for the integral over each
cell.

--
Anders

Revision history for this message
Vladimir Dergachev (volodya-k) said :
#2

This is extremely helpful, thank you very much !

Revision history for this message
Vladimir Dergachev (volodya-k) said :
#3

Thanks Anders Logg, that solved my question.