← Back to team overview

dolfin team mailing list archive

Re: [Question #102925]: operator that depends on the gradient of a function

 



On 02/03/10 11:19, Richard Norton wrote:
New question #102925 on DOLFIN:
https://answers.launchpad.net/dolfin/+question/102925

I cannot figure out how to fix the following problem...  In the following code I would like to modify sigma so that it defines an operator from u to a vector in R^2 in the following way...

def sigma(u):
   If abs(u.dx(1))<  1:
       return as_vector( [u.dx(0), 0])
   else:
       return as_vector( [u.dx(0), 2*(u.dx(1)**2 -1)*u.dx(1)] )

so that sigma returns something different if the gradient of u in the y direction has magnitude less than 1 (at each point in the domain).  I suspect there is a problem with "abs(u.dx(1))<  1"


Conditional statement are not (yet) supported in the generated code. What you can do is create a new Function and make it equal to

   w = 2*(u.dx(1)**2 -1)*u.dx(1)

and then zero it when abs(u.dx(1)) <  1.

There is a blueprint to add support for conditional statements.

  https://blueprints.launchpad.net/ffc/+spec/ufl-conditionals

Garth

---------------------------------------
mesh = UnitSquare(n, n)
V = FunctionSpace(mesh, "CG", 1)

...

# Test and trial functions
v = TestFunction(V)
u = TrialFunction(V)
uold = Function(V)

def sigma(u):
       return as_vector( [u.dx(0), 2*(u.dx(1)**2 -1)*u.dx(1)] )
	
# Variational problem
a = dot(grad(u), grad(v))*dx
L = dot(sigma(uold),grad(v))*dx





References