# expression in a 2D domain

Hi folks,

Just a quick question about defining an expression in a 2D domain. I want to have the following expression in my 2D domain:

G = some expression, if x=<y
G = some expression, if y=<x

My problem is to have an expression which is capable of understanding x=<y and y=<x.
Any suggestion is deeply appreciated.

Best,
Mo

## Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Blechta
Solved:
2013-01-28
Last query:
2013-01-28
2013-01-26
 Martin Sandve Alnæs (martinal) said on 2013-01-25: #1

Try
conditional(x[0] <= x[1], iftrueexpr, iffalseexpr)

If you need more details I need more context and which version number you
use.

Martin
Den 25. jan. 2013 02:50 skrev "Mo" <email address hidden>
følgende:

> New question #220092 on DOLFIN:
>
> Hi folks,
>
> Just a quick question about defining an expression in a 2D domain. I want
> to have the following expression in my 2D domain:
>
> G = some expression, if x=<y
> G = some expression, if y=<x
>
> My problem is to have an expression which is capable of understanding x=<y
> and y=<x.
> Any suggestion is deeply appreciated.
>
> Best,
> Mo
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

 Mo (mo-h) said on 2013-01-25: #2

#####################################################################
from dolfin import *
from math import *

# Create mesh and function space
mesh = UnitInterval(20)
V = FunctionSpace(mesh, "CG", 1)

h = 0.05

g_el = conditional(x[0] <= x[1], (1.0 - exp(-(h/(0.02 - 0.01*x[1]))*(1.0 - (x[1]/h)))*\
(1.0 - exp(-(x[0]*h/(0.02 - 0.01*x[1])))))/(1.0 - exp(-h/mu)),\
(exp(x[1]/(0.02 - 0.01*x[1]))- 1.0)*(exp(-x[0]/(0.02 - 0.01*x[1]))\
- exp(-h/(0.02 - 0.01*x[1])))/(1.0 - exp(-h/(0.02 - 0.01*x[1]))))

g_el_v = project(g_el, V)

plot(g_el_v, interactive=True)
#####################################################################

But it get the following error:

Traceback (most recent call last):
File "test_v2.py", line 11, in <module>
g_el = conditional(x[0] <= x[1], (1.0 - exp(-(h/(0.02 - 0.01*x[1]))*(1.0 - (x[1]/h)))*\
NameError: name 'x' is not defined

Here is also the version info:
fenics:
Installed: 1:1.0.0-2~ppa1~oneiric1
Candidate: 1:1.1.0-1~ppa1~oneiric1
Version table:
1:1.1.0-1~ppa1~oneiric1 0

dolfin-version: 1.0.0

Thank you again for your help.
Mo

 Mo (mo-h) said on 2013-01-25: #3

Sorry, the mesh was not correct. I corrected the code. But the error is still there.

from dolfin import *
from math import *

# Create mesh and function space
mesh = UnitSquare(20,20)
V = FunctionSpace(mesh, "CG", 1)

h = 0.05

g_el = conditional(x[0] <= x[1], (1.0 - exp(-(h/(0.02 - 0.01*x[1]))*(1.0 - (x[1]/h)))*\
(1.0 - exp(-(x[0]*h/(0.02 - 0.01*x[1])))))/(1.0 - exp(-h/mu)),\
(exp(x[1]/(0.02 - 0.01*x[1]))- 1.0)*(exp(-x[0]/(0.02 - 0.01*x[1]))\
- exp(-h/(0.02 - 0.01*x[1])))/(1.0 - exp(-h/(0.02 - 0.01*x[1]))))

g_el_v = project(g_el, V)

plot(g_el_v, interactive=True)

 Jan Blechta (blechta) said on 2013-01-26: #4

You have to define:
x = V.cell().x

 Mo (mo-h) said on 2013-01-28: #5

Thanks Jan Blechta, that solved my question.