# Mixed vector element post-processing of derived fields

**URL:** <https://fenicsproject.discourse.group/t/mixed-vector-element-post-processing-of-derived-fields/9244>\
**Category:** Uncategorized\
**Created:** [September 9, 2022, 12:51pm UTC](https://fenicsproject.discourse.group/t/mixed-vector-element-post-processing-of-derived-fields/9244 "2022-09-09T12:51:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![skatulla](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/skatulla/32/4089_2.png) [@skatulla](https://fenicsproject.discourse.group/u/skatulla)\
**Post date:** [September 9, 2022, 12:51pm UTC](https://fenicsproject.discourse.group/t/mixed-vector-element-post-processing-of-derived-fields/9244/1 "2022-09-09T12:51:54Z")

</div>

hi

I have a nonlinear PDE problem with 2 vector fields as primary variables, u and wf. I am able to solve it and plot the corresponding solution fields, u\_h and wf\_h. However, I am stuck plotting derived fields getting the following error “TypeError: ‘numpy.ndarray’ object is not callable”. I am closely following the DOLFINX elasticity demo [https://docs.fenicsproject.org/dolfinx/v0.5.0/python/demos/demo\_elasticity.html](https://docs.fenicsproject.org/dolfinx/v0.5.0/python/demos/demo_elasticity.html), the only difference is the use of a mixed element.

I am just showing the essential pieces of code underneath:

```auto
from contextlib import ExitStack
import numpy as np
import ufl
from dolfinx import fem, nls, mesh, plot, log, io
from mpi4py import MPI
from petsc4py import PETSc

# ----------------------------------------------------------------------------------------------------------------------
# Create a box mesh of a beam
L = 20.0
H = 1.0
msh = mesh.create_box(MPI.COMM_WORLD, [np.array([0.0, 0.0, 0.0]), np.array([L, H, H])], [10, 1, 1],
                      mesh.CellType.hexahedron)
P1 = ufl.VectorElement("CG", msh.ufl_cell(), 1, dim=3) # Lagrange family, 1st order
P2 = ufl.VectorElement("CG", msh.ufl_cell(), 1, dim=3) # Lagrange family, 1st order
VY = fem.FunctionSpace(msh, ufl.MixedElement([P1, P2]))

# ----------------------------------------------------------------------------------------------------------------------
# Function space
v, yf = ufl.TestFunctions(VY) # test functions
uwf = fem.Function(VY) # combined current displacement and change of director fields
u, wf = ufl.split(uwf)

# ----------------------------------------------------------------------------------------------------------------------
# Problem formulation

# Spatial dimension
d = len(u)

def defGradTens(u_h):
    """Return an expression for the deformation gradient field"""
    return ufl.Identity(d) + ufl.grad(u_h)

..... skipping some lines of code which are not relevant

# Initialize nonlinear problem
problem = fem.petsc.NonlinearProblem(Pi, uwf, bcs)

# ----------------------------------------------------------------------------------------------------------------------
# solving the problem 

u_h = uwf.sub(0)
wf_h = uwf.sub(1)

for n in range(1, 2):
    num_its, converged = solver.solve(uwf)
    
    # plotting of derived fields
    W = fem.FunctionSpace(msh, ("Discontinuous Lagrange", 0))
    F_expr = fem.Expression(defGradTens(u_h), W.element.interpolation_points())
    F_h = Function(W)
    F_h.interpolate(F_expr)
    file.write_function(F_h, n)

```

The error occurs executing the line “F\_expr = fem.Expression(defGradTens(u\_h), W.element.interpolation\_points())”

Please advise. Many 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:** [September 9, 2022, 12:56pm UTC](https://fenicsproject.discourse.group/t/mixed-vector-element-post-processing-of-derived-fields/9244/2 "2022-09-09T12:56:07Z")

</div>

Which version of DOLFINx are you using?  
Have you tried replacing

> [@skatulla](#):
>
> ` F_expr = fem.Expression(defGradTens(u_h), W.element.interpolation_points())`

With ` F_expr = fem.Expression(defGradTens(u_h), W.element.interpolation_points)`  
as this was the syntax in v0.4.1

---

<div class="post-metadata">

**Author:** ![skatulla](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/skatulla/32/4089_2.png) [@skatulla](https://fenicsproject.discourse.group/u/skatulla)\
**Post date:** [September 9, 2022, 1:09pm UTC](https://fenicsproject.discourse.group/t/mixed-vector-element-post-processing-of-derived-fields/9244/3 "2022-09-09T13:09:43Z")

</div>

I am using DOLFINx version: 0.4.1 from the Ubuntu 22.04 repository. Yes, your suggestion fixed the error. Thanks.

However, now I am getting “RuntimeError: Function value size not equal to Expression value size” executing line " F\_h.interpolate(F\_expr)"

I am interpolating a 2nd-order tensor field and the corresponding expression is returned by the function defGradTens(u\_h).

---

<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:** [September 9, 2022, 1:21pm UTC](https://fenicsproject.discourse.group/t/mixed-vector-element-post-processing-of-derived-fields/9244/4 "2022-09-09T13:21:51Z")

</div>

> [@skatulla](#):
>
> `W = fem.FunctionSpace(msh, ("Discontinuous Lagrange", 0))`

> [@skatulla](#):
>
> I am interpolating a 2nd-order tensor field and the corresponding expression is returned by the function defGradTens(u\_h).

You should then use a `TensorFunctionSpace`

---

<div class="post-metadata">

**Author:** ![skatulla](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/skatulla/32/4089_2.png) [@skatulla](https://fenicsproject.discourse.group/u/skatulla)\
**Post date:** [September 11, 2022, 10:40am UTC](https://fenicsproject.discourse.group/t/mixed-vector-element-post-processing-of-derived-fields/9244/5 "2022-09-11T10:40:12Z")

</div>

Thanks, that makes sense and works.
