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

How to add values of outer product to function in TensorFunctionSpace in parallel

0 votes

Hi!

A small code chunk as this:

TFS = TensorFunctionSpace(mesh, "CG", 1)
L = Function(TFS)
u_outer = outer(u, u)

Where u is some valued Function in a VectorFunctionSpace. How can u_outer be added to L in a smart way such that L becomes a function filled with the values in u_outer? Is it even possible?

I ask because the normal way of doing this applying project(u_outer, TFS) does not work in parallel (yields allow_extrapolation error, I can't allow extrapolation since it destroys my whole solver), in addition I want to apply the LagrangeInterpolator function, hence both arguments then needs to be functions..

Thanks!

asked Oct 23, 2014 by joakibo FEniCS User (1,140 points)
edited Oct 23, 2014 by joakibo

2 Answers

+3 votes
 
Best answer

Something like this could perhaps do the trick?

from dolfin import *

mesh = UnitSquareMesh(4, 4)
Q = FunctionSpace(mesh, "CG", 1)
V = VectorFunctionSpace(mesh, "CG", 1)
T = TensorFunctionSpace(mesh, "CG", 1)
u = interpolate(Constant((1,2)), V)
uiuj = Function(T)
dummy = Function(Q)
u0 = Function(Q)
u1 = Function(Q)
assign(u0, u.sub(0))
assign(u1, u.sub(1))
dummy.vector()[:] = u0.vector()*u0.vector() 
assign(uiuj.sub(0), dummy)
dummy.vector()[:] = u0.vector()*u1.vector() 
assign(uiuj.sub(1), dummy)
assign(uiuj.sub(2), dummy) # symmetric
dummy.vector()[:] = u1.vector()*u1.vector() 
assign(uiuj.sub(3), dummy)
answered Oct 23, 2014 by mikael-mortensen FEniCS Expert (29,340 points)
selected Oct 24, 2014 by joakibo

Thanks Mikael for your excellent answer!

0 votes

You can try

L = project(u_outer, TFS)

It's a bit expensive as it inverts a mass matrix, but it should work for general expressions.

answered Oct 23, 2014 by martinal FEniCS User (2,800 points)

Thanks for your answer martinal!

I forgot to provide critical information regarding my question: the problem occurrs when I'm trying to run this in parallel. On one processor project works fine, however on several processors project yields allow_extrapolation-error...

Is u on a different mesh?

...