2

I have a 2d array of my coordinates, and at each coordinate I have values for pressure at that point. I want to export my data and set of coordinates in a way that I can later on open them in techplot or paraview.

I have read a lot on vtk but could not find a solution to my problem. I know it should be very easy but I am new here and in the beginning.

Thank you

Soyol
  • 763
  • 2
  • 10
  • 29

3 Answers3

3

A simple solution is to write your data in a CSV file.

The CSV file contains the coordinates of the points and the values of the variables at those points. For instance, this is the beginning of my file :

"X"          , "Y"          , "Z"          , "R"         
-5.00e+00    , -2.00e+00    , 0.00e+00     , 5.39e+00    
-3.89e+00    , -2.00e+00    , 0.00e+00     , 4.37e+00    
-2.78e+00    , -2.00e+00    , 0.00e+00     , 3.42e+00    
-1.67e+00    , -2.00e+00    , 0.00e+00     , 2.60e+00      

To visualize your data in ParaView :

  1. Open the file in ParaView.

    Import options will be displayed in the "Property" pannel (see below). Check that the field delimiter is correct, then press "Apply".

    Property pannel for the CSV reader

  2. Use the Table To Points filter

    Select the CSV reader in the pipeline browser (element with same name as your file). Go to the Filters menu, in the main menu, go down to "Alphabetical", and look for "Table To Points".

    The property pannel of this filters is displayed below. In this pannel you will have to indicate which column define the X, Y and Z coordinates of the points. Since you have 2D data, you can check the "2D points" options to ignore the Z column. Then check "Apply".

    Table To Points property pannel

    If nothing appears in the view window, click on the eye symbol next to the TableToPoints element in the pipeline browser.

  3. Create a polygonal dataset

    With these operations you can visualize your data as dots colored by the quantities. For instance :

    Visualization of the data at the points

    For a better visualization, I suggest creating a poloygonal dataset with the Delaunay 2D filter. Select the TableToPoints element in the pipeline browser, then go to the Filters menu and look for "Delaunay 2D" in the list of filters. With this filter you will have a smooth interpolated visualization. Here is the result for my example file :

    Visualization with the delaunay 2D filter

You will find additional informations about the CSV files in the ParaView wiki

Bertrand Gazanion
  • 705
  • 1
  • 14
  • 19
1

Please see the VTK File Format guide: http://www.vtk.org/wp-content/uploads/2015/04/file-formats.pdf

You will want to save your file as a structured points where the n_x and n_y size (dimension in VTK parlance) are greater than 1 and the n_z dimension is 1.

Your data file should look like

# vtk DataFile Version 2.0
This is a sample data set describing a 2D array of floats with dimensions 128 x 256.
ASCII
DATASET STRUCTURED_POINTS
DIMENSIONS 128 256 1
ORIGIN 0.0 0.0 0.0
SPACING 1.0 1.0 1.0
SCALARS pressure float 1
LOOKUP_TABLE default
1.0
1.0
...
<128*256 total entries>

Name save the file with extension .vtk and you will be able to load it in ParaView.

Cory Quammen
  • 1,243
  • 7
  • 9
  • Thank you many times for the file and the useful comment. But I am a bit confused, I here attach my result file. it is a set of data in a 6*30 matrix which each element contains the pressure at that point. and the coordinates would be "xmin=0:numberofsteps=30:xmax=4 and ymin=0:numberofsteps=6:ymax=2" – Soyol Mar 16 '16 at 17:57
  • The Google drive link is not accessible. – Cory Quammen Mar 19 '16 at 19:45
  • So in the example I posted, you will need to change the DIMENSIONS to either DIMENSIONS 30 6 1 or DIMENSIONS 6 30 1 and your spacing is probably going to be SPACING (4-0)/30 (2-0)/6 1.0 or SPACING (2-0)/6 (4-0)/30 1.0 You'll have to evaluate the equations above and substitute those values into your VTK file. – Cory Quammen Mar 24 '16 at 18:23
0

I would like to expand on the answer by Cory Quammen. When trying to apply his method I get the following error upon importing the .vtk file o Paraview (ver 5.8.1):

vtkstructuredpointsreader (0x5513c30): unrecognized keyword: scalars

I am not sure what is causing that, but I solved by explicitly defining CELL_DATA and POINT_DATA; in my case, the resulting .vtk looks like this:

# vtk DataFile Version 3.0
Vtk output for binned flow configurations (metric in Ångström)
ASCII
DATASET STRUCTURED_POINTS
DIMENSIONS 65 1 30
ORIGIN 870.6375 0.0 0.0
SPACING 1.996875 25.0 1.9977631578947368
CELL_DATA 1856
POINT_DATA 1950
SCALARS density float 1
LOOKUP_TABLE default
25.206808815618885
36.654412373503654
36.242826782279884
36.50975262319155
35.96262518604988
34.16361654279422
31.625047088384182
30.86263741338999
30.848340565843436
...

I hope this may help people experiencing the same problem.