diff() converts a constant to a zero

Asked by B. Emek Abali

if I want to use an expression or its derivative

V=VectorFunctionSpace(...)
v=Function(V)
z=variable(v)
a=det(grad(v))
Da=diff(a,z)
form = v[i]*Da[i]*dx

it is fine, but if the expresion is a constant

b=10.0
Db=diff(b,z)
form = v[i]*Db[i]*dx

the diff() returns a Zero and thus raise an error
TypeError: unsupported operand type(s) for +: 'set' and 'tuple'

How should I define the constant expression that it differentiates as a list with three zeros?

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

I found and fixed the set + tuple bug quickly, but I'm not sure if that
really solves your problem.

Why do you want a zero form? There are currently problems with
representing 0*dx in UFL that occur in other contexts as well.

Martin

On 13 April 2011 13:57, B. Emek Abali
<email address hidden>wrote:

> New question #152662 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/152662
>
> if I want to use an expression or its derivative
>
> V=VectorFunctionSpace(...)
> v=Function(V)
> z=variable(v)
> a=det(grad(v))
> Da=diff(a,z)
> form = v[i]*Da[i]*dx
>
> it is fine, but if the expresion is a constant
>
> b=10.0
> Db=diff(b,z)
> form = v[i]*Db[i]*dx
>
> the diff() returns a Zero and thus raise an error
> TypeError: unsupported operand type(s) for +: 'set' and 'tuple'
>
> How should I define the constant expression that it differentiates as a
> list with three zeros?
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
B. Emek Abali (bilenemek) said :
#2

Thanks Martin,

how should I get the fixed code (sorry that I am not much familiar but on Ubuntu will updating work? )

I was just explaining the problem I've had with the most single formulation, surely the form has (much) more than one single term :)

Revision history for this message
B. Emek Abali (bilenemek) said :
#3

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

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#4

The fix hasn't been released yet, so you have to either wait for a release
or install from source.

Martin

On 13 April 2011 17:48, B. Emek Abali
<email address hidden>wrote:

> Question #152662 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/152662
>
> Status: Answered => Solved
>
> B. Emek Abali confirmed that the question is solved:
> Thanks Martin,
>
> how should I get the fixed code (sorry that I am not much familiar but
> on Ubuntu will updating work? )
>
> I was just explaining the problem I've had with the most single
> formulation, surely the form has (much) more than one single term :)
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
B. Emek Abali (bilenemek) said :
#5

I'll wait,

FEniCS is developing quicker than myself :P

probably until I achieve the compilation from source it will be released,

thanks a lot.

Revision history for this message
Anders Logg (logg) said :
#6

On Wed, Apr 13, 2011 at 04:55:47PM -0000, B. Emek Abali wrote:
> Question #152662 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/152662
>
> B. Emek Abali posted a new comment:
> I'll wait,
>
> FEniCS is developing quicker than myself :P
>
> probably until I achieve the compilation from source it will be
> released,

Installing UFL is very easy:

  bzr clone lp:ufl
  cd ufl
  sudo python setup.py install

--
Anders

Revision history for this message
B. Emek Abali (bilenemek) said :
#7

Thanks Anders, even installing was right :) Thanks for all the good work..