# TensorFunctionSpace to FunctionSpace

**URL:** <https://fenicsproject.discourse.group/t/tensorfunctionspace-to-functionspace/13741>\
**Category:** General\
**Created:** [February 27, 2024, 10:49pm UTC](https://fenicsproject.discourse.group/t/tensorfunctionspace-to-functionspace/13741 "2024-02-27T22:49:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![charithjeewantha](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/charithjeewantha/32/3948_2.png) [@charithjeewantha](https://fenicsproject.discourse.group/u/charithjeewantha)\
**Post date:** [February 27, 2024, 10:49pm UTC](https://fenicsproject.discourse.group/t/tensorfunctionspace-to-functionspace/13741/1 "2024-02-27T22:49:35Z")

</div>

Hello FEniCSx community!

I have been using `TensorFunctionSpace` to calculate stress values. But according to [this post,](https://fenicsproject.discourse.group/t/module-dolfinx-fem-has-no-attribute-tensorfunctionspace/13148) I realized that it is discontinued from the `dolfinx.fem` module.

The way I used the `TensorFunctionSpace` is:

```auto
    Function_space_for_sigma = TensorFunctionSpace(mesh, ("DG", 1))

    expr= Expression(sigma(u_n,p_n),Function_space_for_sigma.element.interpolation_points())
    sigma_values = Function(Function_space_for_sigma)
    sigma_values.interpolate(expr)

```

This is very much similar to what they have done in: [The von Mises stresses](https://jsdokken.com/dolfinx-tutorial/chapter2/linearelasticity_code.html#:~:text=piecewise%20continuous%20functions%2C-,the%20von%20mises%20stresses,-will%20be%20a)

My question is, if I only changed the first line to:  
` Function_space_for_sigma = FunctionSpace(mesh, ("DG", 1))`  
is the output exactly the same as it was in the case of:  
`Function_space_for_sigma = TensorFunctionSpace(mesh, ("DG", 1))`

Thank you

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/sven/32/8155_2.png) [@Sven](https://fenicsproject.discourse.group/u/Sven)\
**Post date:** [February 28, 2024, 1:25am UTC](https://fenicsproject.discourse.group/t/tensorfunctionspace-to-functionspace/13741/2 "2024-02-28T01:25:30Z")

</div>

If you read the first post you linked you will see it points you to the GitHub pull request that updates the process for both Vector and Tensor spaces. Reviewing [Pull #2766](https://github.com/FEniCS/dolfinx/pull/2766/files) you can see that under changes to “python/test/unit/fem/test\_assembler.py” the replacements for those spaces are provided. Therefore the answer is no, you need to modify the FunctionSpace appropriately as given in that example.

---

<div class="post-metadata">

**Author:** ![charithjeewantha](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/charithjeewantha/32/3948_2.png) [@charithjeewantha](https://fenicsproject.discourse.group/u/charithjeewantha)\
**Post date:** [February 28, 2024, 5:37am UTC](https://fenicsproject.discourse.group/t/tensorfunctionspace-to-functionspace/13741/3 "2024-02-28T05:37:11Z")

</div>

@Sven Thanks a lot for the proper direction on to the git page. With that help, I was able to get done!  
My code will look like this:

```auto
    gdim = mesh.geometry.dim
    Function_space_for_sigma = FunctionSpace(mesh, ("DG", 1, (gdim, gdim)))
    
    expr= Expression(sigma(u_n,p_n), Function_space_for_sigma.element.interpolation_points())

    sigma_values = Function(Function_space_for_sigma)

    sigma_values.interpolate(expr)

```
