getfem-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Getfem-users] using matplotlib


From: jeff witz
Subject: Re: [Getfem-users] using matplotlib
Date: Fri, 4 Mar 2011 09:01:54 +0100

Hello,


On 4 March 2011 03:42, Luis Saavedra <address@hidden> wrote:
Hi jeff,

three questions:

 *
are using the svn version?
 
For now I don't use the svn version but I can easily switch from 4.4.1 to svn.
 
 * if you had the correct values, how they would be plotted?



First, you need at least the version 1.0.1 of matplotlib. There are very instructive example on the gallery :

http://matplotlib.sourceforge.net/examples/pylab_examples/tripcolor_demo.html

Beware if you already have a older version of matplotlb it's quite complex to handle (I remove the packaged version)
I regret that all the linux distributions only handle the 0.99 version.

For now I just want for my course to use a simple delaunay triangulation, but there is much more that can be done.


 I'm asking you because if I know what you want, it might be a good idea to integrate this into the interface without having to write the code yourself,


It would be great !

But I think that for teaching purposes building connectivity, inverse connectivity and node table is interesting.

I send you the source code that allow to plot the displacement on the mesh, but for now with wrong values.
I still believe it's quite strange that the displacements are not ordinate as the coordinate  pid, is this the normal behaviour ? 
You need to have gmsh installed.
If you are interested in I also write a little script in python that allows to get the mesh and results and work with. But all the faces are independent in this format so it's not fem behavior ....

You can find below what I think to be the good way to integrate plot in python using matplotlib.

If you look to this example :
http://matplotlib.sourceforge.net/examples/pylab_examples/shading_example.html
you can see that ray-tracing is available in matplotlib.
My point is that it is possible to have the perfect visualization tool imshow function. The main issue with complex element is that there is a need to create a lot of submesh (as X-FEM) to correctly display the picture, I think this strategy (using in paraview) is not the good one. It is much more versatile to decompose the plot in two parts.
First the the FEM value on a selected griddata (projection of the delaunay triangulation to a regular grid) that allows you to get a pixel description,
Then to plot the mesh, the main difficulty  lie on the fact that there is a need to create a Z-buffer to plot only the visible element of the mesh.

By this way, it can be quite simple to produce light but very professionnal plot (perfect for article), indeed the color variation can be stored in png (the most efficient format for this purpose) and the visible mesh and axes in vectorial (svg,pdf,eps) in order to have good results.


 



regards,
Luis


2011/3/3 jeff witz <address@hidden>
Hello,

I almost succeed in using matplotlib for plotting 2 dimensionnal linear triangle !

So I have a two dimensional NonLinearelasticity problem, so I do the computation and extract the solution

u = md.variable('u')

In order to be able to plot solution in matplotlib 1.0.1 I need node table and element table. So I build this table :


NbNod=m.pts().shape[1]
NbElem = m.cvid().shape[0]
NbNodElem=m.pid_from_cvid(0)[0].shape[0]
ElemTab = np.zeros((NbElem,NbNodElem))
for i in range(NbElem):
    for j in range(NbNodElem):
        ElemTab[i,j]=m.pid_in_cvids(i)[j]

NodTab=np.transpose(m.pts())

The main issue remain in the fact that I don't understand how the u vector is sorted.
So when I plot the results the values don't correspond to the computed solution. Could you explain me how I can sort it.

Logically this vector is 324 : 2* NbNod

I try to use mf.basic_dof_nodes(), but I don't really understand the way output vector

mf.basic_dof_nodes().shape
Out[100]: (2, 324)

which is equal to (2,2*NbNod)

Could you help me to solve this out ?

I think it would be great to be able to treat the data without leaving ipython.

I just want to plot a simple tripcolor (pcolor in matlab) with a quiver over it. It will be quite simple once I have the good u vector

I hope I can solve this before the Course I have to give Monday to show the student that everything can be done simply in python.

Best regards.




--
Jean-François WITZ

_______________________________________________
Getfem-users mailing list
address@hidden
https://mail.gna.org/listinfo/getfem-users





--
Jean-François WITZ

Attachment: Example.zip
Description: Zip archive


reply via email to

[Prev in Thread] Current Thread [Next in Thread]