I have a 1D function f which is in fact the stream function of a vector field \vec{v}.
f is the solution of a PDE and is stored in a Function() object. I would like to get the vector field \vec{v} and store it in a Function() object as well in order to use it in another advection PDE like \vec{v} \cdot \nabla q = 0 and be able to evaluate it in different points of domain, anyway all my attempts to do so have failed.
The main idea would be:
import ufl
from dolfin import *
import matplotlib.pyplot as plt
mesh = UnitSquareMesh(20,20)
V1 = FunctionSpace(mesh, 'DG', 2)
Vdim = VectorFunctionSpace(mesh, 'DG', 2)
#Example streamfunction
f = Expression('1/(x[0]*x[0] + x[1]*x[1] + 0.01)', element = V1.ufl_element())
f_interp = interpolate(f, V1)
#Get the vector field from the stream function:
v = as_vector((-f_interp.dx(1), f_interp.dx(0)))
The only other option I came up with would be sampling f in the domain to compute the derivatives with numpy and then interpolating the values back to fenics but this seems like a long detour.