# 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

- Last reply:
- 2013-01-26

Martin Sandve Alnæs (martinal) said : | #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:

> https:/

>

> 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.

>

Thank you Martin for your reply. Here is my code:

#######

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(

- 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-

Candidate: 1:1.1.0-

Version table:

1:

dolfin-version: 1.0.0

Thank you again for your help.

Mo

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(

- 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 : | #4 |

You have to define:

x = V.cell().x