how to convert MeshFunction to Function with MPI

Asked by Doug Arnold

The following code shows how a MeshFunction can be converted to a DG0 function. This works on
one processor, but fails if invoked with MPI with the message "RuntimeError: non matching dimensions on input".
Is there a way around this? Thanks -- Doug

from dolfin import *
mesh = UnitSquare(2, 2)
subdomains = MeshFunction("double", mesh, 2)
subdomains.set_all(0.)
V = FunctionSpace(mesh, 'DG', 0)
k = Function(V)
k.vector()[:] = subdomains.array()

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Johan Hake (johan-hake) said :
#1

On Tuesday December 13 2011 03:46:25 you wrote:
> New question #181712 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/181712
>
> The following code shows how a MeshFunction can be converted to a DG0
> function. This works on one processor, but fails if invoked with MPI with
> the message "RuntimeError: non matching dimensions on input". Is there a
> way around this? Thanks -- Doug
>
> from dolfin import *
> mesh = UnitSquare(2, 2)
> subdomains = MeshFunction("double", mesh, 2)
> subdomains.set_all(0.)
> V = FunctionSpace(mesh, 'DG', 0)
> k = Function(V)
> k.vector()[:] = subdomains.array()

You should be able to do this using:

  k.vector().set_local(subdomains.array())

Best regards,

Johan

Can you help with this problem?

Provide an answer of your own, or ask Doug Arnold for more information if necessary.

To post a message you must log in.