This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Operations on functions

0 votes

Hi. I need to perform the following operation

u = u*u1,

where u - function, u1 - other function or expression.
Can i do it without solve method?

P.S. I can do it manualy with .vector() method, but MPI stop warking in this case.
P.S.S. u.assign(u+u1) not working.

asked Nov 23, 2013 by Sheva FEniCS Novice (910 points)
edited Nov 23, 2013 by Sheva

2 Answers

0 votes
 
Best answer

For example:
dump.assign(project((+temp), V))

answered Jun 4, 2017 by Sheva FEniCS Novice (910 points)
0 votes

If u and u1 are scalar functions you can construct an Expression.

result = Expression("u*u1", u=u, u1=u1)

There might be more options but it is difficult to suggest further if you do not give us more information about what you want:

  • u1+u or u*u1.
  • Is it important that u is both the assigner and the assigned?
answered Nov 25, 2013 by johanhake FEniCS Expert (22,480 points)

If i use result = Expression("u*u1", u=u, u1=u1) i have TypeError: expected default arguments for member variables to be scalars.

i have

mesh = Mesh("again.xml")
V = FunctionSpace(mesh, 'Lagrange', 1)
temp = Function(V)
dump = Function(V)

And i need result = temp + dump . Simple sum of two vectors, but i don't want use solve().
At now i use temp.vector()[i] = temp.vector()[i] + dump.vector()[i] . But i can't use MPI in this case.

Please provide a minimal but runable example of what you try to accomplish because your comments do not make sense. Here both temp and dump are scalar Functions.

Ok. I try this

u = Function(V)
u0 = Function(V)
solve(a==L, u, bcs)
result = Expression("u0+u", u0=u0, u=u)

and have TypeError: expected default arguments for member variables to be scalars.

Provide a minimal but runable example. Your example is not the latter.

from dolfin import *
mesh = UnitCube(6, 4, 5)
V = FunctionSpace(mesh, 'Lagrange', 1)
u = TrialFunction(V) 
v = TestFunction(V) 
u0 = Function(V)

S = Expression("(x[0]*x[0]+x[1]*x[1]+(x[2]-30)*(x[2]-30)<100)?((t<=600)?s: 0): 0.0",t=0.,s=0.)


bcs = []

du0 = u.dx(0)

a = (u*v+ du0*v)*dx
L = (S+u0)*v*dx
u = Function(V)

solve(a==L, u, bcs) 

fi = File('result.pvd')

result = Expression("u0+u", u0=u0, u=u)
fi << result
...