Hi everybody, I have a .mat file which represents a column vector (n x 1) as dimension. I’m stuck with converting it in a readable file for the sym(grad()) operator which works on Function and my file is a {dict} in which there is the array i need but i can’t really exporting.
The attached image represents the structure of the matlab file converted as follow:

You need to make a minimal reproducable example. A dolfin.Function has an underlying vector which you can assign data to. However, you need to note that the ordering of your w1_vec.mat does not necessarily align with the ordering in dolfin.Function.vector. This depends on how you have generated this data.

Substantially I did a simulation of a stokes flow around a sphere both on FEniCS and ANSYS (commercial software) . I would like to import the field u (velocity solution) obtained in ANSYS and compare with the one obtained with FEniCS. Until now I managed to convert the imported field u in a ndarray. But how I can make the sym(grad(u_array)) ? symgrad doesn’t work with this structure, then I want to convert this ndarray into a Function, here a MWE:

u = sc.io.loadmat('u1_vec.mat')
u = np.array(list(u.items())[3][1])[0,:]
V= VectorFunctionSpace(mesh, "CG", 1)
f = Function(V)
f.vector()[:] = u

this gives me the following error.
*** Error: Unable to set local values of PETSc vector.
*** Reason: Size of values array is not equal to local vector size.
*** Where: This error was encountered inside PETScVector.cpp.

in this script I only tried to save the solution from fenics as .mat then uploading it in a new file and try to convert as function, so the solution is coming from fenics not fluent, I think fenics save solution at each nodes of the mesh or am I wrong?

This depends on how you save the data from your function. If you save the data in u.vector() that will be the data at every degree of freedom.
While if you save data using u.compute_vertex_values(), you will only Get values at vertices (a CG-1 interpolation of your function).