# How to convert Ufl objects to pytorch tensor?

**URL:** <https://fenicsproject.discourse.group/t/how-to-convert-ufl-objects-to-pytorch-tensor/15121>\
**Category:** UFL\
**Tags:** dolfinx\
**Created:** [July 1, 2024, 6:19pm UTC](https://fenicsproject.discourse.group/t/how-to-convert-ufl-objects-to-pytorch-tensor/15121 "2024-07-01T18:19:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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 2, 2024, 6:45am UTC](https://fenicsproject.discourse.group/t/how-to-convert-ufl-objects-to-pytorch-tensor/15121/2 "2024-07-02T06:45:54Z")

</div>

> [@K\_M\_Zaheen\_Nasir](#):
>
> Is possible to convert an ufl object to pytorch tensor or get its associated values at each nodes/qudrature points at each time step for the said conversion? If so, then how?

Interpolate said tensor into a Quadrature space. See for instance: [Mapped quadrature points, weights and solution at these quadrature points - #4 by dokken](https://fenicsproject.discourse.group/t/mapped-quadrature-points-weights-and-solution-at-these-quadrature-points/10113/4)

> [@K\_M\_Zaheen\_Nasir](#):
>
> Also, is there any ufl wrapper to wrap a python function? Because my function is a term in the weak form that needs to solved.

You could use @a-latyshev’s external operator:

> **[GitHub - a-latyshev/dolfinx-external-operator: Extension of DOLFINx...](https://github.com/a-latyshev/dolfinx-external-operator)**
>
> Extension of DOLFINx implementing the concept of external operator - a-latyshev/dolfinx-external-operator

---

_[View the full topic](https://fenicsproject.discourse.group/t/how-to-convert-ufl-objects-to-pytorch-tensor/15121)._
