← Back to team overview

dolfin team mailing list archive

Re: [Question #127978]: User-defined function in a nonlinear problem

 

Question #127978 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/127978

    Status: Expired => Open

Vladimir is still having a problem:
Hello,

Thank you very much for the respond. I'm sorry to answer so late, but I
was busy last two weeks.

I have a nonlinear diffusion problem. In a numerical scheme I would like to use function like
max{u,0}, where u is unknown function.

But, only thing I came with is this

V = FunctionSpace('CG',1 ) # piecewise-linear continuous FE space
...

def positivePart(u):
   for i in range(0, u.vector().size()):
      if  u.vector()[i] < 0:
	  u.vector()[i] = 0.0
   return u

But, this isn't a very elegant way. Moreover, it relies very much on the
choice of FE space.

I've seen have many examples like this

fun1 = Expression('x[0] + x[1] - 1.0')

class PositivePart(Expression):
  def eval(self, v, x):
    v[0] = 0
    if fun1(x)>0: v[0] = fun1(x)

positivePart = PositivePart()
...

f = project(positivePart, V)
plot(f), interactive()

where a piecewise expression is defined.Unfortunately, I can't see how I
can pass my solution u (i.e. an instance of the class Function) to get
positive part of u instead of the expression fun1(x).

How can I pass the solution function to the Expression?

Vlado

-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.