interpolate function not equal to fe solution

Asked by SMF

Hi everyone,

I am new to FE and I was wondering what the difference between fenics interpolate and the actual calculation of my following code is:

import dolfin as df
import numpy as np

mesh = df.UnitIntervalMesh(30)
f = df.Expression('(x[0] >= 0.25&&x[0] <=0.75) ? x[0]*x[0] : 0.')
V0 = df.FunctionSpace(mesh, 'DG',0)
#V0 = df.FunctionSpace(mesh, 'Lagrange', 1)
Pf = df.interpolate(f,V0)
df.plot(Pf)

u = df.TrialFunction(V0)
v = df.TestFunction(V0)

a = u*v*df.dx
L = f*v*df.dx
s = df.Function(V0)
df.solve(a==L,s)
df.plot(s)

If I use interpolate with the discontinous galerkin degree 0 elements, I see a different solution than what (I assume) would be the actual calculation behind interpolate. With Lagrange 1 and DG higher order both results match nicely. Only for DG 0 I observe a difference. Is this a bug or am I missing something here?

Thanks,
SMF

(dolfin version 1.2.0)

Edit:
Digging further through the fenics book I realized that I do a projection onto the DG 0 Space, which gives the same answer in both cases. My follow up: what is the difference between project and interpolate of an expression? I understand that it matters in case of FE solutions but in case of Expressions I cannot see why project and interpolate should differ? (for DG 0)

Question information

Language:
English Edit question
Status:
Answered
For:
FEniCS Project Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jan Blechta (blechta) said :
#1

On Fri, 19 Apr 2013 21:26:11 -0000
SMF <email address hidden> wrote:
> New question #227077 on FEniCS Project:
> https://answers.launchpad.net/fenics/+question/227077
>
> Hi everyone,
>
> am new to FE and I was wondering what the difference between fenics
> interpolate and the actual calculation of my following code is:
>
> mesh = df.UnitIntervalMesh(30)
> f = df.Expression('(x[0] >= 0.25&&x[0] <=0.75) ? x[0]*x[0] : 0.')
> V0 = df.FunctionSpace(mesh, 'DG',0)
> #V0 = df.FunctionSpace(mesh, 'Lagrange', 1)
> Pf = df.interpolate(f,V0)
> df.plot(Pf)
>
> u = df.TrialFunction(V0)
> v = df.TestFunction(V0)
>
> a = u*v*df.dx
> L = f*v*df.dx
> s = df.Function(V0)
> df.solve(a==L,s)
> df.plot(s)

That is projection. Interpolation is just interpolating by function in
its dof vertices, not solving variational problem.

>
> If I use interpolate with the discontinous galerkin degree 0
> elements, I see a different solution than (what I assume) would be
> the actual calculation behind interpolate. With Lagrange 1 and DG
> higher order both results match nicely. Only for DG 0 I observe a
> difference. Is this a bug or am I missing something here?
>
> Thanks,
> SMF
>
> (dolfin version 1.2.0)
>

Can you help with this problem?

Provide an answer of your own, or ask SMF for more information if necessary.

To post a message you must log in.