expression in a 2D domain

Asked by Mo

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:
Last query:
Last reply:
Revision history for this message
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://answers.launchpad.net/dolfin/+question/220092
>
> 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.
>

Revision history for this message
Mo (mo-h) said :
#2

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

Revision history for this message
Mo (mo-h) said :
#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)

Revision history for this message
Best Jan Blechta (blechta) said :
#4

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

Revision history for this message
Mo (mo-h) said :
#5

Thanks Jan Blechta, that solved my question.