I am solving Stokes equations in steady state and I want to extract the components of the velocity field for post processing, I have been looking and trying solutions for hours now but to no avail. The doc in this regard is very sparse and sometimes outdated. Here is what I attempted with no luck:
After computing the solution (velocity vector u)
nx = Constant((1.0,0.0))
ux = dot(u,nx)
However the Dot object can’t be saved in a file nor can I access its values with ux.vector().get_local().
If that’s the way to go, how do you access the values of the dot product?
I also tried to access directly the values of u using u.vector().get_local() but the array produced is a flat one. I looked into reshaping it to get a (ux,uy) but I have no idea how it is structured.
I must be missing something, because this should be quite straight forward.
There are several ways of doing this.
First, you can split the fields, Lets say you have the combined vector up, containing the Mixed space for velocity and pressure. Then the first component can be obtained by: u0=up.sub(0).sub(0,deepcopy=True)
Note that if you just save the velocity field to file:
u,p=up.split(deepcopy=True)
File("u.pvd")<<u
You can visualize the magnitude or each component in paraview.
Thanks Doken, I already splitted the mixed space and have access to u and p and I saved them as .pvd and I am able to play with them on paraview. However, I would like to do post-processing in python once the solution is computed and access the x and y components of the velocity field.
Thanks, I will try your solution dokken. In the mean time, I found an (ugly) work around where I save the velocity field as pvd then use meshio to reload the file and access the different components of the field from the x,y positions of the nodes to the ux,uy components of the velocity.