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

FEniCS 1.4.0 update() method needed?

+2 votes

After interpolating an Expression onto a FunctionSpace, I subtract a scalar from the Function, project this value onto the FunctionSpace, and reset the original Function to new values via the set_local method.

This creates the artifacts shown below when executing with more than 1 core.

Using the update method with 1.3 used to update the ghost vertices. However, with the code for update removed in 1.4, this fails.

from fenics import *

# Create mesh and define function space :
mesh = UnitCubeMesh(10, 10, 10)
V    = FunctionSpace(mesh, 'Lagrange', 1)

# Define Function :
u = Expression('1 + x[0]*x[0] + 2*x[1]*x[1] + 4*x[2]*x[2]')
u = interpolate(u, V)

# subtract 10 from the Function :
u_n  = project(u - 10.0, V)

# reset the Function :
u_v = u_n.vector().array()
u.vector().set_local(u_v)

File('u.pvd') << project(u, V)

output
output

P.S. is there a nifty way to center the images in this window?

asked Jun 13, 2014 by pf4d FEniCS User (2,970 points)

1 Answer

+2 votes
 
Best answer

You need to call apply after calling any of the linear algebra get/set functions.

answered Jun 13, 2014 by Garth N. Wells FEniCS Expert (35,930 points)
selected Jun 13, 2014 by pf4d

Is there a better way to do this? I am manually setting values of this 'u' function based on a conditional, I find this to be faster and more robust than using the UFL conditional.

I would like my solution to follow what you, the developers of this amazing piece of software, envisioned.

i.e., something like

u_v = u.vector().array()
u_v[u_v < 0] = 0
u.vector().set_local(u_v)
u.vector().apply('')

The above code snippet should be very fast. It's low-level, but looks fine to me.

This change in 1.4 'caught' me as well - update("") solved my problem.

Manipulating vector values in parallel and using apply
...