Interpolate a grad of a function

Asked by Nicolas Verdon

Hi,

I'm trying (as an example) to interpolate the values of a gradient of a given vector onto an estimated space but I get the following error :

TypeError: in method 'Function_interpolate', argument 2 of type 'dolfin::GenericFunction const &'

To clarify the question, I put here what's in my code :

mesh = Box(-200, -20, -20, 200, 20, 20, 10, 1, 1)
V = FunctionSpace(mesh, "Lagrange", 2)
Ve = VectorFunctionSpace(mesh, "Lagrange", 2)

uFunc = Expression("x[0]+x[1]+x[2]")
u = interpolate(uFunc,V)

w = interpolate(grad(u),Ve)

In fact, the reason for programming this test is to compute a divergence of a tensor, and check if the value of the divergence tends to zero.. I thought the interpoplate command should help me for this purpose but I have the sme problem even for the simplest case of grad(u) where u is a given function.

Could you please say me what I've written wrong, or give me other solutions I could explore.
Thanks in advance,

Nicolas Verdon

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Martin Sandve Alnæs
Solved:
Last query:
Last reply:
Revision history for this message
Best Martin Sandve Alnæs (martinal) said :
#1

Interpolation of arbitrary UFL expressions is not implemented, but try
instead project(grad(u), V), which projects any UFL expression into a
function space by solving a linear system.

Martin

On 29 September 2011 14:25, Nicolas Verdon
<email address hidden> wrote:
> New question #172701 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/172701
>
> Hi,
>
> I'm trying (as an example) to interpolate the values of a gradient of a given vector onto an estimated space but I get the following error :
>
> TypeError: in method 'Function_interpolate', argument 2 of type 'dolfin::GenericFunction const &'
>
> To clarify the question, I put here what's in my code :
>
>
> mesh = Box(-200, -20, -20, 200, 20, 20, 10, 1, 1)
> V = FunctionSpace(mesh, "Lagrange", 2)
> Ve = VectorFunctionSpace(mesh, "Lagrange", 2)
>
> uFunc = Expression("x[0]+x[1]+x[2]")
> u = interpolate(uFunc,V)
>
> w = interpolate(grad(u),Ve)
>
>
> In fact, the reason for programming this test is to compute a divergence of a tensor, and check if the value of the divergence tends to zero.. I thought the interpoplate command should help me for this purpose but I have the sme problem even for the simplest case of grad(u) where u is a given function.
>
>
> Could you please say me what I've written wrong, or give me other solutions I could explore.
> Thanks in advance,
>
>
> Nicolas Verdon
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Nicolas Verdon (verdon-nicolas) said :
#2

Thanks Martin Sandve Alnæs, that solved my question.