This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Mixed element variables plot with Matplotlib

+1 vote

Hi. I'm working on the following MixedElement code, where I solve an advection-diffusion equation problem and plot velocity, pressure and concentration.

I want to plot those scalar and vector fields on Matplotlib, using quiver, streamline and scatter, so I need the answers organized on arrays for just do "quiver(X,Y, Vx, Vy)".

To plot with Matplotlib, the Functions and Coordinates must be converted to NumPy arrays X, Y, Vx, Vy in a organized way.

The trivial way explained on tutorial "ans.vector().array()" needs the dof to vertex map. But the usual methods such as dof_to_vertex_map(U) doesn't work on MixedFunctionSpaces.

So, I'm having trouble to understand how to solve this mapping and ploting problem. Could someone help me?

I am very grateful for your attention and for any help.

mesh = generate_mesh(channel, res)
FE_V = FiniteElement('P', 'triangle', 2)
FE_P = FiniteElement('P', 'triangle', 1)
elem = MixedElement([FE_P, FE_V, FE_V, FE_P])
U = FunctionSpace(mesh, elem)
[...]
solve(F==0, ans, BC)
pp,ux,uy,aa = split(ans1)
uu = as_vector([ux,uy])

plot(pp, title = 'Pressure')
plot(uu, title = 'Velocity')
plot(aa, title = 'Concentration')
interactive()
asked Jan 18, 2017 by Nelson Tamashiro FEniCS Novice (160 points)

1 Answer

+1 vote
 
Best answer

I usually project to non-mixed fields, i.e.

 pp = project(pp,FunctionSpace(mesh,'CG',1))
answered Jan 18, 2017 by KristianE FEniCS Expert (12,900 points)
selected Jan 18, 2017 by Nelson Tamashiro

Smart solution. Thanks.

...