CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   From OpenFOAM to LaTeX (https://www.cfd-online.com/Forums/openfoam/143014-openfoam-latex.html)

guido.bonalumi October 14, 2014 10:36

From OpenFOAM to LaTeX
 
Hi everyone,
I am going to write my thesis with LaTex and I am looking for some advices. In particular I am interested in the best solution to plot my results.
I am not so expert with OpenFOAM so usually I look at my results through Paraview and when necessary I extract them with some tools like slices, plot over lines, etc.
It worked quite well until now, but I do not know how to plot fields, in particular velocity and pressure fields. Extracting values with slices was easy but plotting them with Octave not so much. Here you can read about my problems:
http://octave.1599824.n4.nabble.com/....html#a4666945
So now I am here to ask which is the best way to do the job. Which is the best solution to plot OpenFOAM data with LaTex? I able to plot residuals and easy plots, but I am not able to plot fields.
I have read about the sample utility but I am not sure that is the best solution.
Can anybody help me?

Thanks in advance.

alexeym October 14, 2014 11:00

Hi,

the best solution is the one that works for you.

I would propose to use matplotlib for slice plots. You sample data with sample utility, save it as VTK, then read this data with python-vtk and plot with matplotlib (here is an example).

If you prefer Octave, there is Octaviz package. Though it's no longer supported and I'm not quite sure about its ability to save vector graphics.

guido.bonalumi October 14, 2014 11:15

First of all thank you for your reply.
I think I have explained my self wrong. Actually what I am looking is a little bit different. I want to give the data directly to LaTex and create the plots with it, using packages like pgfplots, instead of importing in it images realized with other programs.
I use Octave because for some plots I think I will need to modify the data before plotting them.
For sure I am not the first one with this problem and I was looking for someone more expert than me who knows which is the best way to plot OpenFOAM data directly with LaTeX.

dkxls October 14, 2014 12:52

Actually alexeym was recommending you an very powerful alternative to Octave: Python ;)

matplotlib is a very powerful plotting library for python/numpy. I don't think there is much you can do in octave/matlab that you couldn't do with python/numpy/matplotlib.
Actually, I would rather say it's the other way round, python, especially when combined with vtk has much better plotting and data handling capabilities than octave/matlab.

Especially when you are dealing with large data, there are not many alternatives to a combination of python and ParaView/VTK. (Of course Visit and MayaVi would be two good examples for alternatives ;)).

Concerning LaTeX: I either export vector graphics from matplotlib/ParaView (mostly PDF) or export the plots as TikZ/PGF directly.
See e.g. here: https://github.com/nschloe/matplotlib2tikz
Or the corresponding matlab version here (never used that one though): https://github.com/nschloe/matlab2tikz

I should mention that I use TikZ/PGF only for line plots, not for 2D or 3D plots. I don't really see a point in that, since ParaView and matplotlib can both export high quality vector-graphics (i.e. PDFs).

guido.bonalumi October 16, 2014 18:45

Thank you very much for your advices and your kindness.
Unfortunately I do not have enough time to learn python now and I am looking for a quicker solution combining my knowledges about Octave, Paraview and LaTeX.
At the moment my biggest preoccupation involves the 2D plots (velocity and pressure fields) because I should be able to realize all the other graphs (1D) directly with LaTeX.
For what I have understood you are suggesting to export vector graphics from Paraview and import them with LaTeX. I have no reason to doubt about your solution and it is what I did until now. But why PDF? Generally I use .eps file. Do you think PDF is a better format? Just asking. I really know anything about this kind of stuff.

alexeym October 17, 2014 01:00

Quote:

Originally Posted by guido.bonalumi (Post 514727)
But why PDF? Generally I use .eps file. Do you think PDF is a better format? Just asking. I really know anything about this kind of stuff.

A bunch of explanations:

http://tex.stackexchange.com/questio...use-pdf-or-eps

guido.bonalumi October 17, 2014 05:02

From this discussion .PDF seems better, but I still have a doubt. Quoting from this discussion:
Lev Bishop:
Quote:

Pdftex will include PDF files directly without making any changes (except for unifying fonts, and even that can be disabled if needed), so you can have complete control over the final result by generating a PDF which is exactly as you want it (assuming your image editing software gives you control over image encoding lossiness, colour spaces, etc).
mforbes
Quote:

One advantage of EPS figures is the ability to use the psfrag package to replace axis labels etc. with properly LaTeXed versions generated with the same fonts etc. as your main document. I used to generate all my plots with matplotlib or MATLAB using this feature. Matplotlib's support for this is broken, but it instead provides a usetex option that allows you to embed LaTeX generated the labels directly in PDF files which I now use exclusively.
Probably I get it wrong but to me they are saying the same thing. Am I wrong? I would like to have the same font everywhere if it is possible.

dkxls October 17, 2014 05:48

I don't see any reason why one would even considering .eps. You either have to convert every singel eps-file to a pdf or use latex->dvi->pdf, who does that anymore?

Besides, .eps files can become unhandy for surface or contour plots, since they are typically bigger in size than .pdf (though this largely depends on what you are actually plotting).

About the fonts, I don't see any problems on that end, I also use same fonts throughout the entire document, needs every now and then some adjustments but nothing too fancy.

After all, you have to find the tool-set that fit's your needs the best!

guido.bonalumi October 17, 2014 08:01

Ok thank you very much! I will give it a try. I just have to understand how I can change the font from the .PDF to have the same font everywhere.


All times are GMT -4. The time now is 21:29.