Save scalar components as vector

Hi everyone,
I have solved a problem which has as output two scalar components, say ux and uy. Their data type is fem.Function on a scalar Functional Space.

Is it possible to save them into a vector, so that they can be exported into a xdmf file?
I try to use as_vector, without success unfortunately.

Thanks in advance

You could create a VectorFunctionSpace over the space finite element as you created the scalar elements, and use the FunctionAssigner, see: Usage of FunctionAssigner - #2 by dokken

I’m working with dolfinx, the implementation is the same as dolfin?

See: Function.assign in Dolfinx - #2 by dokken

Perfect, thank you.
Last question (I hope): using this approach is the vector function recognized by Paraview as a vector? So that the magnitude and the vector can be directly visualized?

As you are assigning data to a vector space, it will be recognized as a vector space when outputted to paraview

Thank you very much for the help!