splitting mixed vectors

Asked by Jaroslav Hron

Hi. If w is a function from a MixedSpace, what is the exact difference between (v,p)=w.split() and (v,p)=split(w)?
JH

Example:

mesh = UnitSquare(32,32)
V = VectorFunctionSpace(mesh, "CG", 2)
P = FunctionSpace(mesh, "CG",1)
W = MixedFunctionSpace([V,P])

(u, q) = TestFunctions(W)

w = Function(W)
(v, p) = w.split() # <- this doesn't work, gives Exception: Form (<empty Form>) seems to be zero: cannot compile it.

#(v, p) = (as_vector((w[0], w[1])), w[2]) # <- this is ok
#(v,p) = split(w) # <- this is ok

F = -p*div(u)*dx + inner(grad(v),grad(u))*dx + div(v)*q*dx
solve(F==0, w , bcs=bcs)

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
Garth Wells (garth-wells) said :
#1

On 30 August 2012 21:15, Jaroslav Hron
<email address hidden> wrote:
> New question #207313 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/207313
>
> Hi. If w is a function from a MixedSpace, what is the exact difference between (v,p)=w.split() and (v,p)=split(w)?

The difference is a bit tricky. The Python interface is a synthesis of
UFL (the form language) and DOLFIN (the solver environment). The
'split' version

    (v,p)=split(w)

is a UFL function. UFL Functions and Coefficients are abstract in that
they don't have any data (e.g. no dof map, no dof vector). The 'split'
version

    (v,p)=w.split()

is a DOLFIN function that works with a concrete Function w (i.e., one
that does have data). Generally, you'll want to use split(w) when
constructing forms but before solving, and split() after a solve.

What's awkward is that in the Python interface a Function is a
subclass of both a UFL Function and a DOLFIN Function. It's something
that we'll look at in the future to clean up.

Garth

> JH
>
> Example:
>
> mesh = UnitSquare(32,32)
> V = VectorFunctionSpace(mesh, "CG", 2)
> P = FunctionSpace(mesh, "CG",1)
> W = MixedFunctionSpace([V,P])
>
> (u, q) = TestFunctions(W)
>
> w = Function(W)
> (v, p) = w.split() # <- this doesn't work, gives Exception: Form (<empty Form>) seems to be zero: cannot compile it.
>
> #(v, p) = (as_vector((w[0], w[1])), w[2]) # <- this is ok
> #(v,p) = split(w) # <- this is ok
>
> F = -p*div(u)*dx + inner(grad(v),grad(u))*dx + div(v)*q*dx
> solve(F==0, w , bcs=bcs)
>
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Can you help with this problem?

Provide an answer of your own, or ask Jaroslav Hron for more information if necessary.

To post a message you must log in.