Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Importing data into ParaView may be done using several different file types. This page will show you how to use comma separated value files (commonly known as CSV-files).

The main motivation behind this choice is that they can easily be opened and read in either notebook or Excel, making debugging very fast and easy. However, this choice comes with a negative side as well. The main downside is the cumulative size of the data and thus the computational time required to import data into ParaView. Another disadvantage is that all data-processing has to been done inside ParaView, where as by using e.g. VTK-files (Visualization ToolKit files) several operations may be included directly into file from the beginning. Such an operation may be the use and display of ghost cells.


Panel
borderColor#dfe1e5
bgColor#eff9ff
borderWidth2
titlePage content

Table of Contents


Setup

Before beginning, keep in mind that the setup I am about so show you are only one of many possibilities. I will aim to explain my decisions, but I encourage you to play around with it yourself as well.

The CSV-format we will look into is shown below. The example is given for a domain consisting of M x N elements. As the domain size must be specified in ParaView to make the grid, I have included the values of N and M when describing each column. We will later come back to why this is benefitial.

Code Block
languagetext
xN,     yM,     z1,     P,      U,      V       // Strings to described column
x_1,    y_1,    z_1,    P_1,    U_1,    V_1     // Number values for node 1
x_2,    y_2,    z_2,    P_2,    U_2,    V_2		// Node 2
.       .       .       .       .       .
.       .       .       .       .       .
x_NM,   y_NM,   z_NM,   P_NM,   U_NM,   V_NM	// Node N*M


First of all, the most essential columns are the three first, defining the domain using a 3D coordinate system. The next columns consist of the obtained results, all as scalar values. To include vector results, e.g. velocity, we therefore have to include the velocity components as separate values. In the case above, U and V represents a velocity vector. An important parameter when writing the coordinates is that the x-values has to change faster than the y-values. Otherwise, we will get an error when creating our structured grid. Following is a demostration of how avoid this error.

Code Block
languagetext
  -- Correct --                -- Wrong --
x,      y,      z           x,      y,      z
1,      1,      0           1,      1,      0
2,      1,      0           1,      2,      0
1,      2,      0           2,      1,      0
2,      2,      0           2,      2,      0

Examples

Simple box

Based on my own experience, the fastest way to get known to the setup is to try it out yourself. Let's start with defining the geometry for a 2D-box consisting of 3 x 3 nodes.

Code Block
languagetext
titleexample_1.csv
x3,	y3,	z1
0,	0,	0
1,	0,	0
2,	0,	0
0,	1,	0
1,	1,	0
2,	1,	0
0,	2,	0
1,	2,	0
2,	2,	0

Although our chosen domain is in 2D, the function in ParaView that converts our table to a structured grid requires three coordinates. Effectively, z = 0 is defined for all points. As already mentioned, note that the x-values are the ones changing the fastest. This is to not get any errors when importing into ParaView.

The top row in the example; "x3 y3 z1" is in ParaView only used to describe the column, thus the values below. So, when we later get into ParaView, we will not have to remember which column represented what, but rather just look at the descriptor. The numbers behind the x, y and z is something I picked up from Bailey's great tutorial on ParaView (see ParaView). They simply describe how many points there are in the current direction, thus for our box geometry of 3 x 3 x 1 nodes we get as shown above. This is helpful knowledge when we later are to convert the points to a structured grid.

Lastly, if we have some results we wish to add, simply insert them as an additional column. 

Code Block
languagetext
titleexample_1.csv
x3,	y3,	z1,	P
0,	0,	0,	1
1,	0,	0,	1
2,	0,	0,	1
0,	1,	0,	2
1,	1,	0,	2
2,	1,	0,	2
0,	2,	0,	1.5
1,	2,	0,	1.5
2,	2,	0,	1.5

Exampel file: example_1.csv

More advanced

Although we will now look at a more complex visualization, observe how the setup is pretty much just as simple as in the last example. The task is to visualize the flow around a square cylinder. The domain is 2D and consisting of 256 x 176 nodes. As we obviously don't expect you to calculated this now, we have provided you with some data to work with.

Info

If you like the image below and would like to learn how to make some yourself (and hopefully even better), check out our page on Inkscape.

Code Block
languagetext
titleexample_2.csv
x256,	y176,	z1,	P,				U,			V
0,		0,		0,	-0.0112616,		1,			-0.00108238,
1,		0,		0,	-0.0112616,		1,			-0.00216817,
2,		0,		0,	-0.0112615,		1,			-0.00325722,
3,		0,		0,	-0.0112613,		1,			-0.00434934,
4,		0,		0,	-0.0112611,		1,			-0.00544435,
5,		0,		0,	-0.0112607,		1,			-0.00654205,
.		.		.	.				.			.
.		.		.	.				.			.
253,	175,	0,	-7.42356e-05,	1.00768,	0.0270307,
254,	175,	0,	-0.000123269,	1.00802,	0.0272095,
255,	175,	0,	-0.000215282,	1.00844,	0.0272388,

Example file: example_2.csv

Import into ParaView

To import a file into ParaView, click Open or CTRL + O and located your file. To make it a bit more interesting, we will use example_2.csv which is attached in the section above. Then, click Apply, and a table should pop up. Make sure the table is correct, i.e. that the x-values are actually listed in the column named x256, z-coordinates in the column named z1 etc. If your file is not separated by commas, but by e.g. semi-colons, simply change the Field Delimiter Character under Properites (lower left in image below). 

Make points

The easiest way to visualize your data is through single points. To do so, go to Filters → Alphabetical → Table To Points. Then, select the correct columns for x, y and z and click Apply.

If nothing shows up in the graphics window, click on it and then click on the eye next to points created under Pipeline Browser. Also, make sure the coloring of the points is set to differ from the background color.

Make structured grid

Making a structured grid is not very different from single points, but because of ParaView's automatical interpolation, it is most often desired. It also makes it a bit easier to interpret, as we get a complete, continuous geometry. To make a structured grid, go to Filters → Alphabetical → Table To Structured Grid. Then, select the correct columns for x, y and and fill in the correct values for Whole Extent. Whole extent may be thought of as the domain size for each direction. In our example, we have a rectangular grid consisting of 256 x 176 x 1 nodes (1 in z-direction since 2D). Because the first index for the whole extent is 0, we therefore have to fill in the values 255 x 175 x 0 as shown in the image below. Hopefully, it is now more obvious why I prefer including the dimensions in the column descriptors, as we most definitely will get an error if the whole extent values are wrong. Finally, click Apply.

For the simple box example in the previous section consisting of 3 x 3 x 1 nodes, we would have to insert 2 x 2 x 0

Similar to the points, if nothing shows up in the graphics window, click on it and then click on the eye next to grid created under Pipeline Browser.


Additional calculations

As previously described, e.g. velocity is imported into ParaView through it's components. This means that in order for us to get a total velocity, both vector and amplitude, we will have to calculate it in ParaView. Similar is the vorticity, which actually is the curl of the velocity.

Velocity

To calculate velocity, highlight the imported data and click on the calculator. Then choose a name for the calculation, e.g. "Vel" and type in the expression. Since we are working with a 2D example, the images below does not include a z-component. However, a default definition to calculate the velocity is (x-component of velocity * iHat + y-component of velocity * jHat + z-component of velocity * kHat). Here, the different Hat's are unit vectors in each direction. Lastly, click Apply. Notice how this operation has to be done before creating points or a structured grid.

If we now create a structured grid, we may choose to color by Vel.


Streamlines

After calculating the velocity, we are also able to display streamlines. To do so, highlight the structured grid (not points) and click on the Stream Tracer. We will not go into the details of making a plot of streamlines here, but we have included an example result below.

Vorticity

Vorticity is often a desired parameter, but as it is the curl of the velocity vector, we will have to calculate this as well. First, make sure you have already calculated the velocity and highlighted the structured grid. Then go to Filters → Alphabetical → Python Calculator. Fill in e.g. Vor as the array name and curl(Vel) as the expression (given that the velocity is name Vel). Note that the expression vorticity(Vel) can be used as well, providing the exact same results. Then click Apply. You may now choose to color by "Vor" to obtain the result shown below.

Vorticity contours

If we want to further improve our plots by adding vorticity contours, we once again need to do some calculations. This is because ParaView requires a magnitude to make contours. First, make sure you have already calculated the vorticity. Then, go to Filters → Alphabetical → Python Calculator. Fill in e.g. Vor_mag as the array name and mag(Vor) as the expression. When clicking apply, the calculator will provide us with the vorticity magnitude. To make the contours, click on Contour and choose contour by Vor_mag. Then click Apply.

We will not go into the details of making a contour plot here, but an example result is shown below.

Image Added



BibTeX Display Table