Absent Coefficient in Linear Form

Asked by Pietro Maximoff

Hello

I have a ufl file like so (for the Heat Equation with time-stepping via the theta-method):

element = FiniteElement("Lagrange", "triangle", 2)

v = TestFunction(element)
u = TrialFunction(element)
kappa = Coefficient(element)
u_old = Coefficient(element)
f = Coefficient(element)

dt = ....

a = u*v*dx + theta*dt*kappa*inner(grad(u), grad(v))*dx
L = ((u_old + dt*f)*v - (1-theta)*dt*kappa*inner(grad(u), grad(v)))*dx

The problem is that I can't assign kappa to L.kappa in the linear form, i.e.,

L.kappa = kappa

This is fine though for the Bilinear form.

On examining the generated header file, it turns out that the LinearForm class has no member kappa which is exactly the error message given.

What am I doing wrong?

Best wishes

Pietro

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Pietro Maximoff
Solved:
Last query:
Last reply:
Revision history for this message
Garth Wells (garth-wells) said :
#1

as Maximoff wrote:
> New question #95954 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/95954
>
> Hello
>
> I have a ufl file like so (for the Heat Equation with time-stepping via the theta-method):
>
> element = FiniteElement("Lagrange", "triangle", 2)
>
> v = TestFunction(element)
> u = TrialFunction(element)
> kappa = Coefficient(element)
> u_old = Coefficient(element)
> f = Coefficient(element)
>
> dt = ....
>
> a = u*v*dx + theta*dt*kappa*inner(grad(u), grad(v))*dx
> L = ((u_old + dt*f)*v - (1-theta)*dt*kappa*inner(grad(u), grad(v)))*dx
>
> The problem is that I can't assign kappa to L.kappa in the linear form, i.e.,
>
> L.kappa = kappa
>
> This is fine though for the Bilinear form.
>
> On examining the generated header file, it turns out that the LinearForm class has no member kappa which is exactly the error message given.
>
> What am I doing wrong?
>

Are you setting theta=0? In this case, UFL will discard the entire
product involving theta.

Also, your form is not correct. You cannot have the trial function u
appearing in L.

Garth

> Best wishes
>
> Pietro
>
>

Revision history for this message
Pietro Maximoff (segment-x) said :
#2

I intend to use different theta values but in this particular instance, theta = 1.

You're right, L should read:

L = ((u_old + dt*f)*v - (1-theta)*dt*kappa*inner(grad(u_old), grad(v)))*dx

Even then, kappa is absent from the LinearForm class and hence, can't be set by

L.kappa = kappa

I wonder why this is the case.

Revision history for this message
Garth Wells (garth-wells) said :
#3

Pietro Maximoff wrote:
> Question #95954 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/95954
>
> Status: Answered => Open
>
> Pietro Maximoff is still having a problem:
> I intend to use different theta values but in this particular instance,
> theta = 1.
>
> You're right, L should read:
>
> L = ((u_old + dt*f)*v - (1-theta)*dt*kappa*inner(grad(u_old),
> grad(v)))*dx
>
> Even then, kappa is absent from the LinearForm class and hence, can't be
> set by
>
> L.kappa = kappa
>
> I wonder why this is the case.
>

(1-theta) = 0 if theta=1 -> (1-theta)*dt*kappa*inner(grad(u_old) = 0 ->
UFL throws it away.

Garth

Revision history for this message
Pietro Maximoff (segment-x) said :
#4

Ahh... I see. Thanks Garth. I just assumed that even though that part of the expression will be zero, kappa'll still be generated.