# Piecewise defined form (conditional in ufl file?)

Asked by Cataldo Manigrasso on 2010-06-09

Hi everybody,

I need to write in a ufl file a piecewise defined functional:

L =

normg() is a function that gives the norm of the gradient. I tried to use conditional(condition, true_form, false_form) in a nested way, but it doesn't seem to work. Also reducing the form to one condition instead of two (i.e. a L= condition( norm(grad(u)), first_form, second_form) doesn't work. I tried to use a simpler condition like 3>2, but there was no improvement. I get an error "Conditional is not yet supported (yet)". Am I doing a mistake or it is not yet available? I hope not, I really need it and it seems it is working if one reads the documentation.

Thanks a lot for the help!

Here is the code of the ufl file:

t1=1
t2=2

element=FiniteElement("CG","triangle",1) v = TestFunction(element)
w = TrialFunction(element)
f = Coefficient(element)
u = Coefficient(element)
# Euclidean norm of the gradient
def normg(v):

# L = conditional( lt(normg(u),t1), m2*normg(u), \
# conditional( lt(normg(u),t2), \
# m2*t1, \
# m1*normg(u))) \

## Question information

Language:
English Edit question
Status:
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
2010-06-09
2010-06-09
 Kristian B. Ølgaard (k.b.oelgaard) said on 2010-06-09: #1

On 9 June 2010 19:10, Cataldo Manigrasso
> New question #114079 on DOLFIN:
>
> Hi everybody,
>
> I need to write in a ufl file a piecewise defined functional:
>
> L =
>
> normg() is a function that gives the norm of the gradient. I tried to use conditional(condition, true_form, false_form) in a nested way, but it doesn't seem to work. Also reducing the form to one condition instead of two (i.e. a L= condition( norm(grad(u)), first_form, second_form) doesn't work. I tried to use a simpler condition like 3>2, but there was no improvement. I get an error "Conditional is not yet supported (yet)". Am I doing a mistake or it is not yet available? I hope not, I really need it and it seems it is working if one reads the documentation.

Conditionals are not supported (yet). As the error says. It is
supported in UFL, meaning that it is possible to create the form, but
the form compiler FFC does not generate any code because that has not
been implemented.
There is a blueprint for this
looks like it has been assigned to me...
However, it is not on top of my TODO list and I can't say when I'll
get around to fix it. It is possible to implement a workaround until I
fix it by handling the conditionals in main.cpp and manipulate the
values of the Coefficient u.

Kristian

> Thanks a lot for the help!
>
> Here is the code of the ufl file:
>
> t1=1
> t2=2
>
> element=FiniteElement("CG","triangle",1)                                                                                                                                        v = TestFunction(element)
> w = TrialFunction(element)
> f  = Coefficient(element)
> u  = Coefficient(element)
> # Euclidean norm of the gradient
> def normg(v):
>
>
> # L = conditional( lt(normg(u),t1), m2*normg(u), \
> #     conditional( lt(normg(u),t2), \
> #     m2*t1, \
> #     m1*normg(u))) \
>
>
>
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________