Function.split() vs Split(Function)

Hi I was trying to understand what the difference between the two splits. In particular I would really appreciate an example of different use cases.

For example if I have the following:

U2 = ufl.VectorElement("Lagrange", domain.ufl_cell(), 2) # For displacement
P1 = ufl.FiniteElement("Lagrange", domain.ufl_cell(), 1) # For  pressure
TH = ufl.MixedElement([U2, P1])     # Taylor-Hood style mixed element
ME = FunctionSpace(domain, TH)    # Total space for all DOFs

w = Function(ME)

I understand u, p = split(w) would give me the functions for the two subelements

However I don’t understand what u, p = w.split() would output.

Thanks again for the help.

2 Likes

ufl.split splits it into ufl representations of the sub function, i.e.

u, p = ufl.split(w)
print(type(u), type(p)))

returns

<class 'ufl.tensors.ListTensor'> <class 'ufl.indexed.Indexed'>

while
u,p = w.split()
returns dolfinx functions, which can in turn be collapsed to give contiguous views into dof data

1 Like

So just to confirm my understanding u,p = ufl.split(w) is normally used when creating the variational forms to then put into a solver.

Meanwhile u,p = w.split()`` is the same as calling u = w.sub(0) p = w.sub(1)``` and would be used when post processing data.

3 Likes

Yes. You can also w.split to access things such as interpolation into a component of a Mixed space

2 Likes

Hi, I have an additional question.

Can Function.split() and split(Function) all be used to assemble the bilinear form and linear form in variational formulation?
The reason why I guess this is that in my code, both methods can work.

You should not use Function.split() in a variational form.
ufl.split should be used in variational forms.
Function.split should be used for interpolation etc.