New question #114079 on DOLFIN:
https://answers.launchpad.net/dolfin/+question/114079

Hi everybody,

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

L = 
inner(grad(v),grad(u))                                     if normg(u)<= t1
1/normg(u)*inner(grad(v),grad(u))           if t1<normg(u)<=t2
2*inner(grad(v),grad(u))                                     if normg(u)>= t2

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):                                                                   
                                                                                
                 
    return sqrt(inner(grad(v),grad(v)))                                         
                                                                                
                 

L = conditional( lt(normg(u),t1), inner(grad(v),grad(u))*dx,\
                        1/normg(u)*inner(grad(v),grad(u))*dx )

# L = conditional( lt(normg(u),t1), m2*normg(u), \
#     conditional( lt(normg(u),t2), \
#     m2*t1, \
#     m1*normg(u))) \
#     *inner(grad(v),grad(u))/sqrt(inner(grad(u),grad(u)))*dx 





-- 
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 protected]
Unsubscribe : https://launchpad.net/~dolfin
More help   : https://help.launchpad.net/ListHelp

Reply via email to