UFL algebra and Function Constant etc...

Asked by Chaffra Affouda

I have a general question about the algebra in dolfin.

a = Constant(1.0) is a Constant but b = -a is a Product. Is there an easy way to convert b back to a Constant? The same would apply for Function. I know project would do it (convert a Constant to a Function) but maybe something can be done at the algebra level because I found project to be time consuming.

Thanks,
Chaffra

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

No. Constant is a dolfin type, a subclass of ufl.Coefficient. A
Coefficient represents a function provided to the compiled form at run
time, and thus cannot be removed by UFL.

You could possibly restructure your application

def foo(f):
    return -f

x = foo(Constant(1.0)) # UFL expression
y = foo(1.0) # computation directly in python

but I guess your application is more complicated than this :)

Martin

On 29 April 2011 01:30, Chaffra <email address hidden> wrote:
> New question #154649 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/154649
>
> I have a general question about the algebra in dolfin.
>
> a = Constant(1.0) is a Constant but b = -a is a Product. Is there an easy way to convert b back to a Constant? The same would apply for Function. I know project would do it (convert a Constant to a Function) but maybe something can be done at the algebra level because I found project to be time consuming.
>
> Thanks,
> Chaffra
>
> --
> 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
Chaffra Affouda (chaffra) said :
#2

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