CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Import xyz data (

eelcovv May 26, 2010 07:51

Import xyz data
Dear Foamers,

I have a question on importing an arbitrary xyz (or csv) file into OpenFoam.

I want to run a mhdFoam calculation. But the initial B-field is obtain from Comsol, which can only export .cvs files. Is there a way to interpolate an arbitrary xyz column file onto an OpenFoam mesh ? Similar like for instance mapFields.

Many thanks!



smehdi609 May 27, 2010 14:03

There is a function called "interpolateXY" available in OpenFOAM. You can use that, but you should write a code to do this.

eelcovv May 28, 2010 08:01

Thank you for your suggestion. Although I was hoping that there would be a little utility already there which works like mapfields but instead takes a cvs data file as input.
Ideally I want to convert the magnetic field which is stored in an external cvs file in to a openFoam format B-field in the zero directory, so you can read this file when you start the simulations. Hopefully somebody has already accomplished this, otherwise I need to write it myself.


elvis May 28, 2010 10:03

Unfortunatly VTK does only have a OpenFOAMReader but no OpenFOAMWriter exists

eelcovv June 8, 2010 08:05

solution csv data import
1 Attachment(s)
Dear Foamers,

In case anybody is interested, here my solution how to read a csv asci file with asci columns on a regular grid and interpolate it on an openFoam grid file.

I wrote a little perl script which converts the cvs file with x,y,z,v1,v2,...vN data columns and put them with a new file header into a regular structure plot3d file.
Then I modified the plot3dToFoam utility in order to read the newly created p3d data file and interpolate it on the openFoam grid. The OF grid is obtained from a vector field which is called Bf, hence this must be present in the 0 directory. Rename this field in the code and recompile it if you need it to be interpolated on another grid.
So, starting from the csv file do Bfield.csv

this generates Bfield.p3d

Then run in the OF case directory

plot3DmapField Bfield.p3d

This interpolates the Bfield.p3d field into the OF Bf field in the 0 directory.

Although this OF utility works perfectly fine for me, I am sharing it because hopefully somebody can suggest improvements. Especially, the field which is being interpolated must be a vector field which is called Bf (which is the magnetic field in my case). This works for me, but it should be possible to make the utility more generic, such that the field can have any name and type. Ideally, I would have liked to have something like foamCalc, where you can give as an option the field name to interpolate on, and a external file name representing the asci file. Something like

foamCalc <of-data-fieldname> <ascifield-to-be-read-and-interpolated>

Unfortunately, how this foamCalc is programmed is a bit to untransparant for me. A suggestion for the new release of OF? I think that the interpolation of an arbitrary data field obtained from measurements or another simulation program to an OF data field should be something standard present in OF. Another ugly thing in my solution is that I define my own interpolation of the regular grid to the OF grid, but probably this should be possible with interpolation functions which are present in OF already. However, I just don't see how to do that. Anybody?

In conclusion. This utility works, recompile for your own needs, but please get back with suggestions if you have a way to make it more generic, such that others can enjoy it as well. In my opinion, this kind of generic utilities (i.e.: non-process specific solutions) should be shared as much as possible such the OF gets better accessible for a larger group of people. The more people use and share OF, the faster the developments, which is in everybodies interest (except the interest of Ansys of course).



kerim October 22, 2010 12:29

import xyz data
Dear ellcovv

I'm a new openfoam user and interested in importing terrain data in xyz format into openfoam. My data looks like this body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: "Arial"; font-size: x-small; } X Y Z 426626.39 5051125.35 2351.69 426626.39 5051155.35 2351.7 426626.39 5051185.35 2351.58 426626.39 5051215.35 2351.32 426626.39 5051245.35 2351.08 Could you help me, please?


fportela July 11, 2013 11:26

1 Attachment(s)

I managed to get the mesh converter to take in a data file (Q file) as an option. With some help from Eelco's program, I read in this data and "interpolate" it to the cell centres.

For my case it was enough to simply average the point values at the cell centre.

I am attaching it here as it might be useful to other people, note that for my case, I was reading rho u v w T from the Q-file, which differs from the standard rho rhoU rhoV rhoW T. Furthermore, the routine is quite slow as I didn't find an efficient way (honestly I don't understand most of the mesh conversion) to get the correspondence between the order in which the nodes are stored in the mesh file and the order in which they are written in OpenFOAM.

manju819 February 25, 2014 13:45

I to have a same doubt. on searching i got this csv reader at the location

N.Manjunath Reddy

hisham007 May 30, 2016 09:03

1 Attachment(s)
Dear eelcovv,

I'm new in OpenFOAM. Can you please guide me step by step how to do the interpolation in OpenFOAM start from convert the CSV file? I couldn`t understand how to keep the CSV file and run the and also how to call the plot3DmapField command? my CSV file as attached. Hope can hear from you soon.

Please help.


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