CSV-format - ParaView
Transcript of CSV-format - ParaView
CSV-format - ParaView
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.
Page content
SetupExamples
Simple boxMore advanced
Import into ParaViewMake pointsMake structured grid
Additional calculationsVelocityStreamlinesVorticity
Vorticitycontours
Animation
SetupBefore 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 elements. As the domain size must be M x Nspecified in ParaView to make the grid, I have included the values of and when describing each column. We will later come back to why this N Mis benefitial.
xN, yM, z1, P, U, V // Strings to described columnx_1, y_1, z_1, P_1, U_1, V_1 // Number values for node 1x_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.
-- Correct -- -- Wrong --x, y, z x, y, z1, 1, 0 1, 1, 02, 1, 0 1, 2, 01, 2, 0 2, 1, 02, 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 nodes.3 x 3
example_1.csv
x3, y3, z10, 0, 01, 0, 02, 0, 00, 1, 01, 1, 02, 1, 00, 2, 01, 2, 02, 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 Prof. Bailey's great tutorial on ParaView (see ). They simply describe how many points there are in the ParaViewcurrent direction, thus for our box geometry of nodes we get as shown above. This is helpful knowledge when we later are to convert the 3 x 3 x 1 points to a structured grid.
Lastly, if we have some results we wish to add, simply insert them as an additional column.
example_1.csv
x3, y3, z1, P0, 0, 0, 11, 0, 0, 12, 0, 0, 10, 1, 0, 21, 1, 0, 22, 1, 0, 20, 2, 0, 1.51, 2, 0, 1.52, 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 . As we obviously don't expect you to 256 x 176 nodescalculated this now, we have provided you with some data to work with.
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 Inksc.ape
example_2.csv
x256, y176, z1, P, U, V0, 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 ParaViewTo import a file into ParaView, click or and located your file. To make it a bit more interesting, we will use which Open CTRL + O example_2.csvis attached in the section above. Then, click and a table should pop up. Make sure the table is correct, i.e. that the x-values are actually Apply,listed in the column named z-coordinates in the column named etc. If your file is not separated by commas, but by e.g. semi-colons, x256, z1simply change the under (lower left in image below). Field Delimiter Character Properites
Make points
The easiest way to visualize your data is through single points. To do so, go to . Then, select the correct Filters Alphabetical Table To Pointscolumns for and and click .x, y z Apply
If nothing shows up in the graphics window, click on it and then click on the eye next to points created under Also, make sure Pipeline Browser.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
Then, select the correct columns for and and fill in the correct values for . Whole extent may be thought of as Structured Grid. x, y z Whole Extentthe domain size for each direction. In our example, we have a rectangular grid consisting of nodes (1 in z-direction since 2D). 256 x 176 x 1Because the first index for the whole extent is 0, we therefore have to fill in the values as shown in the image below. Hopefully, it is 255 x 175 x 0now 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 nodes, we would have to insert . 3 x 3 x 1 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 calculationsAs 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 . Here, the different (x-component of velocity * iHat + y-component of velocity * jHat + z-component of velocity * kHat)Hat's are unit vectors in each direction. Lastly, click Notice how this operation has to be done before creating points or a structured grid.Apply.
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 We will not go into the details of making a plot of streamlines here, but we have included an example result below.Tracer.
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 Fill in e.g. as the array Filters Alphabetical Python Calculator. Vorname and as the expression (given that the velocity is name ). Note that the expression can be used as well, providing curl(Vel) Vel vorticity(Vel)the exact same results. Then click You may now choose to color by "Vor" to obtain the result shown below.Apply.
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
Fill in e.g. as the array name and as the expression. When clicking apply, the calculator will provide us with the Calculator. Vor_mag mag(Vor) vorticity magnitude. To make the contours, click on and choose contour by Then click Contour Vor_mag. Apply.
We will not go into the details of making a contour plot here, but an example result is shown below.
AnimationTo make an animation in ParaView, simply put each time step into it's own file and label the files as . An example is Results_name.csv.[0-n]attached here: , as well as shown below. Note that these time steps are taken from the middle of a larger sample, thus Animation_example.zipstarting at index 1000, not 0 as usual.
Results.csv.1000
x256,y176,z1,P,U,V0,0,0,-0.0105082,1,-0.00114625,1,0,0,-0.0105081,1,-0.00229337,2,0,0,-0.0105081,1,-0.00344095,3,0,0,-0.010508,1,-0.00458859,4,0,0,-0.0105078,1,-0.00573585,5,0,0,-0.0105076,1,-0.00688229,. . . . . .. . . . . .
Results.csv.1001
x256,y176,z1,P,U,V0,0,0,-0.0105884,1,-0.0011441,1,0,0,-0.0105884,1,-0.00228947,2,0,0,-0.0105883,1,-0.00343573,3,0,0,-0.0105882,1,-0.00458251,4,0,0,-0.010588,1,-0.00572937,5,0,0,-0.0105878,1,-0.00687589,. . . . . .. . . . . .
Results.csv.1002
x256,y176,z1,P,U,V0,0,0,-0.0106669,1,-0.00114134,1,0,0,-0.0106669,1,-0.00228432,2,0,0,-0.0106668,1,-0.00342859,3,0,0,-0.0106667,1,-0.00457377,4,0,0,-0.0106665,1,-0.00571948,5,0,0,-0.0106663,1,-0.0068653,. . . . . .. . . . . .
After making the CSV-files, import and plot the data using the method previously described for a single file, e.g. as a structured grid or points. However, keep in mind that the geometry has to be constant in all files during the animation, otherwise the parameter will given an Whole extenterror. The animation can be started by clicking on the green shown in the second image below.Play button