# Inconsistent results with sub MixedElement functions

**URL:** <https://fenicsproject.discourse.group/t/inconsistent-results-with-sub-mixedelement-functions/6172>\
**Category:** Uncategorized\
**Created:** [July 6, 2021, 10:50pm UTC](https://fenicsproject.discourse.group/t/inconsistent-results-with-sub-mixedelement-functions/6172 "2021-07-06T22:50:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tucker](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tucker](https://fenicsproject.discourse.group/u/tucker)\
**Post date:** [July 6, 2021, 10:50pm UTC](https://fenicsproject.discourse.group/t/inconsistent-results-with-sub-mixedelement-functions/6172/1 "2021-07-06T22:50:30Z")

</div>

Upon running

```auto
import dolfin as dl

nx = 5
mesh = dl.UnitSquareMesh(nx,nx)
P1 = dl.FiniteElement("CG", mesh.ufl_cell(), 1)
P2 = dl.FiniteElement("CG", mesh.ufl_cell(), 2)

Th = dl.MixedElement([P1, P2])

Vh = dl.FunctionSpace(mesh, Th)
Vh1 = dl.FunctionSpace(mesh, P1)
Vh2 = dl.FunctionSpace(mesh, P2)

print("dimension of linear FE space = ", Vh.sub(0).dim())
print("dimension of quadratic FE space = ", Vh.sub(1).dim())
print("dimension of mixed linear/quadratic FE product space = ", Vh.dim(), "\n")

# create a function on the mixed element product-space
u = dl.Function(Vh)

print("---- dimensions of FE spaces obtained by sub() method ----")
print("dimension of linear FE space = ", u.sub(0).vector().size())
print("dimension of quadratic FE space = ", u.sub(1).vector().size(), "\n")

print("---- dimensions of FE spaces obtained by split() method ----")
u1, u2 = u.split()
print("dimension of linear FE space = ", u1.vector().size())
print("dimension of quadratic FE space = ", u2.vector().size())

```

I obtain the following results

```auto
dimension of linear FE space = 36
dimension of quadratic FE space = 121
dimension of mixed linear/quadratic FE product space = 157 

---- dimensions of FE spaces obtained by sub() method ----
dimension of linear FE space = 157
dimension of quadratic FE space = 157 

---- dimensions of FE spaces obtained by split() method ----
dimension of linear FE space = 157
dimension of quadratic FE space = 157

```

which is not at all what I had expected. For instance, I expected `u.sub(0)` to be a function whose vector representation has length equal to elements of `Vh.sub(0)`. I would like to know if this is expected behavior and if so, why is this a desirable feature. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 7, 2021, 7:00am UTC](https://fenicsproject.discourse.group/t/inconsistent-results-with-sub-mixedelement-functions/6172/2 "2021-07-07T07:00:56Z")

</div>

If you look at the documentation of split

```auto
Signature: u.split(deepcopy=False)
Docstring:
Extract any sub functions.

A sub function can be extracted from a discrete function that
is in a mixed, vector, or tensor FunctionSpace. The sub
function resides in the subspace of the mixed space.

*Arguments*
    deepcopy
        Copy sub function vector instead of sharing
File: /usr/local/lib/python3.6/dist-packages/dolfin/function/function.py
Type: method

```

you see that you can choose to copy the data or not. If you do not copy the data, it just uses a view into the full function space.  
Similarly this holds for sub:

```auto
In [2]: u.sub?                                                                  
Signature: u.sub(i, deepcopy=False)
Docstring:
Return a sub function.

The sub functions are numbered from i = 0..N-1, where N is the
total number of sub spaces.

*Arguments*
    i : int
        The number of the sub function

```

Thus running:

```python
import dolfin as dl

nx = 5
mesh = dl.UnitSquareMesh(nx,nx)
P1 = dl.FiniteElement("CG", mesh.ufl_cell(), 1)
P2 = dl.FiniteElement("CG", mesh.ufl_cell(), 2)

Th = dl.MixedElement([P1, P2])

Vh = dl.FunctionSpace(mesh, Th)
Vh1 = dl.FunctionSpace(mesh, P1)
Vh2 = dl.FunctionSpace(mesh, P2)

print("dimension of linear FE space = ", Vh.sub(0).dim())
print("dimension of quadratic FE space = ", Vh.sub(1).dim())
print("dimension of mixed linear/quadratic FE product space = ", Vh.dim(), "\n")

# create a function on the mixed element product-space
u = dl.Function(Vh)

print("---- dimensions of FE spaces obtained by sub() method ----")
for deepcopy in [True, False]:
    print(f"dimension of linear FE space (deepcopy={deepcopy}) = {u.sub(0, deepcopy=deepcopy).vector().size()}")
    print(f"dimension of quadratic FE space (deepcopy={deepcopy})= {u.sub(1,deepcopy=deepcopy).vector().size()}\n")

print("---- dimensions of FE spaces obtained by split() method ----")
for deepcopy in [True, False]:
    u1, u2 = u.split(deepcopy=deepcopy)
    print(f"dimension of linear FE space (copy={deepcopy}) = {u1.vector().size()}")
    print(f"dimension of quadratic FE space (copy={deepcopy})= {u2.vector().size()}")

```

produces

```auto
dimension of linear FE space = 36
dimension of quadratic FE space = 121
dimension of mixed linear/quadratic FE product space = 157 

---- dimensions of FE spaces obtained by sub() method ----
dimension of linear FE space (deepcopy=True) = 36
dimension of quadratic FE space (deepcopy=True)= 121

dimension of linear FE space (deepcopy=False) = 157
dimension of quadratic FE space (deepcopy=False)= 157

---- dimensions of FE spaces obtained by split() method ----
dimension of linear FE space (copy=True) = 36
dimension of quadratic FE space (copy=True)= 121
dimension of linear FE space (copy=False) = 157
dimension of quadratic FE space (copy=False)= 157

```
