CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Any way to extract data from contour plots using paraView? (https://www.cfd-online.com/Forums/openfoam/81430-any-way-extract-data-contour-plots-using-paraview.html)

Angela Wang October 26, 2010 18:28

Any way to extract data from contour plots using paraView?
 
Hi all,

I have a newbie question about how to extract x, y coordinates of interpolation points on a contour and their interpolated field values by using paraView?

Thanks.

Angela:)

nimasam October 27, 2010 05:25

after contour
choose : Filters -> Data analysis -> integrate Variables

then a new window will open, then in "showing" tab , choose "contour"

if you want to save data in ".csv" you can choose : file -> save data

Angela Wang October 27, 2010 12:13

Quote:

Originally Posted by nimasam (Post 280947)
after contour
choose : Filters -> Data analysis -> integrate Variables

then a new window will open, then in "showing" tab , choose "contour"

if you want to save data in ".csv" you can choose : file -> save data

Thanks a lot~ I works cool~~~:)

Kina July 5, 2016 11:13

I have also exported my contour data and the export seems fine. However, I plan to plot the contour with tikz.
It seems that the contour data is highly unsorted. Thus, the tikz plots don't look like they should. Is there any way to pre-sort the contour lines before exporting or do I have to manually piece the points together?

Cheers
Alex

toolpost November 29, 2017 02:55

Quote:

Originally Posted by Kina (Post 608089)
I have also exported my contour data and the export seems fine. However, I plan to plot the contour with tikz.
It seems that the contour data is highly unsorted. Thus, the tikz plots don't look like they should. Is there any way to pre-sort the contour lines before exporting or do I have to manually piece the points together?

Cheers
Alex

I am in a similar situation with gnuplot. The data exported from paraview is unsorted and 'plot with line' option makes zig zag-lines. I tried to sort the data using the contour values but doesn't work as I expected. Did you find any solution Kina? or Somebody know any other way to sort out this?

Thanks

Kina November 29, 2017 05:42

1 Attachment(s)
Quote:

Originally Posted by toolpost (Post 673259)
I am in a similar situation with gnuplot. The data exported from paraview is unsorted and 'plot with line' option makes zig zag-lines. I tried to sort the data using the contour values but doesn't work as I expected. Did you find any solution Kina? or Somebody know any other way to sort out this?

Thanks


Hey, what's up?

yes, I have managed to sort the contours by coding an octave file that reads in all the unsorted contours and builds a matrix that compares the vector length difference of all points to the current and reconstructs the contours. You might have to do a little tweaking depending on your columns of the .csv output file. This code currently sorts velocity contours I think. You can possibly also run this in matlab although I am not sure if matlab recognizes all the octave syntax correctly.

Proof picture below so you know what it actually looks like afterwards in tikz (or gnuplot, whatever)

Code:

#!/usr/bin/octave -qf
format short

filename = 'yourfile.csv';
M = dlmread(filename,',',1,0); %read in original matrix
% [p U1 U2 U3 N0 N1 N2 x y z]
M = [M(:,6) M(:,7) M(:,8) M(:,5)];        %reduce Matrix to important info
% [x y z u]
M = sortrows(M,2); %sort Matrix Y axis
M = M([(end/2+1):end],:); %isolate positive Y-Values
M(:,2) = []; %delete Y-column
% [x z u]
%M(:,3) = M(:,3) * 1.205; %Calculate real pressure from incompressible
M = sortrows(M,3); %sortieren pressure fields

p = -10^10;
n = 1;
nContours = 1;

% Datei öffnen
ISOPlot = fopen('pressureIsoLines.txt', 'w');
fprintf(ISOPlot, ' x y p \n');

do
        if (M(n,3) != p)
                nContours++;
                n0 = n;
                p = M(n,3);

                do
                        n++;

                        if (n == rows(M))
                                break;
                        endif

                until (M(n+1,3) != p)
                n1 = n;

                MTemp = M([n0:n1],:);        %Temporäre Matrix Pressure-Isoline
                MTemp = sortrows(MTemp,1); %approx. average of matrix
                MTempInit = MTemp;
                MTIso = [];
                MdTemp = [];

                rRef = MTemp(ceil(end/2),:); %start ref point
                MTemp(ceil(end/2),:) = [];        %delete ref

                MdTemp = [sqrt((MTemp(:,1)-rRef(1)).^2 + (MTemp(:,2) - rRef(2)).^2) MTemp];
                MdTemp = sortrows(MdTemp,1); %Matrix: vector differences from ref point

                MTIso = [0 rRef];
                MTIso = [MdTemp(1,:) ; MTIso];

                rRef = MdTemp(1,(2:end));        %new ref point

                for i = 1:rows(MTemp)
                        if (MTemp(i,:) == rRef)
                                MTemp(i,:) = [];
                                break;
                        endif
                endfor

escape = 0;

        do

                rRef1 = MTIso(1,(2:end));        %new ref point
                rRef2 = MTIso(end,(2:end));

                MTempRef = MTemp;
                for i = 1:rows(MTempRef)
                        if (MTempRef(i,:) == rRef1)
                                MTempRef(i,:) = [];
                                break;
                        endif
                endfor
                for i = 1:rows(MTempRef)
                        if (MTempRef(i,:) == rRef2)
                                MTempRef(i,:) = [];
                                break;
                        endif
                endfor

                MdTemp1 = [sqrt((MTempRef(:,1)-rRef1(1)).^2 + (MTempRef(:,2) - rRef1(2)).^2) MTempRef];
                MdTemp1 = sortrows(MdTemp1,1); %new vector diff matrix
                if (rows(MdTemp1)>0)
                        dCheck1 = MdTemp1(1,1);
                else
                        dCheck1 = 10e3;
                endif

                MdTemp2 = [sqrt((MTempRef(:,1)-rRef2(1)).^2 + (MTempRef(:,2) - rRef2(2)).^2) MTempRef];
                MdTemp2 = sortrows(MdTemp2,1); %new vector diff matrix
                if (rows(MdTemp2)>0)
                        dCheck2 = MdTemp2(1,1);
                else
                        dCheck2 = 10e3;
                endif

                if (dCheck1 < dCheck2)
                        if (rows(MdTemp1) > 0)
                        MTIso = [MdTemp1(1,:) ; MTIso];
                        rRef = rRef1;        %new ref point
                        endif
                else
                        if (rows(MdTemp1) > 0)
                        MTIso = [MTIso ; MdTemp2(1,:)];
                        rRef = rRef2;        %new ref point
                        endif
                endif

        if (rows(MTemp) > 2)        %delete ref point
                for i = 1:rows(MTemp)
                        if (MTemp(i,:) == rRef)
                                MTemp(i,:) = [];
                                break;
                        endif
                endfor

        else
                MTemp = [];
                escape = 1;

        endif

        until (escape == 1)

        endif

        if (n < rows(M))
                n++;
        endif

        for i = (1:rows(MTIso))

                fprintf(ISOPlot, ' %f %f %f \n', MTIso(i,2:end)');

                if (MTIso(i,1) >= 0.15)
                        fprintf(ISOPlot, '\n');
                endif

        endfor

fprintf(ISOPlot, '\n');

until (n == rows(M))

fclose(ISOPlot);


toolpost November 29, 2017 20:02

Quote:

Originally Posted by Kina (Post 673282)
Hey, what's up?

yes, I have managed to sort the contours by coding an octave file that reads in all the unsorted contours and builds a matrix that compares the vector length difference of all points to the current and reconstructs the contours. You might have to do a little tweaking depending on your columns of the .csv output file. This code currently sorts velocity contours I think. You can possibly also run this in matlab although I am not sure if matlab recognizes all the octave syntax correctly.

Proof picture below so you know what it actually looks like afterwards in tikz (or gnuplot, whatever)

Hello Kina!

Thanks for the code! I have been searching yesterday and trying to tackle with a matlab code 'points2contour', which I found in mathworks website. I will try to modify your code as per my data and let you know the results. Also, I use octave, not comfortable with matlab. :)

Your reply and willingness to help is really appreciated.

Thanks

Kina November 30, 2017 10:42

Quote:

Originally Posted by toolpost (Post 673376)
Hello Kina!

Thanks for the code! I have been searching yesterday and trying to tackle with a matlab code 'points2contour', which I found in mathworks website. I will try to modify your code as per my data and let you know the results. Also, I use octave, not comfortable with matlab. :)

Your reply and willingness to help is really appreciated.

Thanks

Yeah alright! Just to tell you one or two lines for better understanding: the code takes the first point of each contour it reads from the file and tries to find the nearest point of the same contour by the minimal distance. Then, the point is removed from the original file matrix. If the distance exceeds a certain threshold, it switches over to the next contour. That's what I remember from it. If you use octave you should be able to follow the code. It worked for me.

Cheers

toolpost December 2, 2017 22:54

1 Attachment(s)
Quote:

Originally Posted by Kina (Post 673449)
Yeah alright! Just to tell you one or two lines for better understanding: the code takes the first point of each contour it reads from the file and tries to find the nearest point of the same contour by the minimal distance. Then, the point is removed from the original file matrix. If the distance exceeds a certain threshold, it switches over to the next contour. That's what I remember from it. If you use octave you should be able to follow the code. It worked for me.

Cheers

Hi Kina!

Thanks for the detailed info. I have used the code without much modifications, though I faced some minor issues. I noticed that an iso-contour from paraview bears not exactly same contour values, minor deviations in the order of 0.001 were present. So, I had to re-export the data from paraview with precision set to 4, and thus able to sort most of the contours. Still,some repetitions and random jumps were there. But, I managed to edit the output file manually without much headache. Please see the figure attached.

Thanks again for the help!

Jabir

Kina December 3, 2017 05:27

Quote:

Originally Posted by toolpost (Post 673724)
Hi Kina!

Thanks for the detailed info. I have used the code without much modifications, though I faced some minor issues. I noticed that an iso-contour from paraview bears not exactly same contour values, minor deviations in the order of 0.001 were present. So, I had to re-export the data from paraview with precision set to 4, and thus able to sort most of the contours. Still,some repetitions and random jumps were there. But, I managed to edit the output file manually without much headache. Please see the figure attached.

Thanks again for the help!

Jabir

Hey Jabir,

looks good so far :) some minor manipulation of the output was also necessary for me. Instead of lowering the output resolution you could have also put in another threshold for the p value in form of changing:

Code:

do
        if (M(n,3) != p)
                nContours++;
                n0 = n;
                p = M(n,3);

at the beginning to

Code:

do
        if (M(n,3) < 0.99 * p || M(n,3) > 1.01 * p)
                nContours++;
                n0 = n;
                p = M(n,3);

which would give you roughly 1% of tolerance of the referenced p value before switching over to a new contour. Apart from that: glad I could help you!

Best wishes for the rest of your project
Alex

toolpost December 3, 2017 21:37

Quote:

Originally Posted by Kina (Post 673742)
Code:

do
    if (M(n,3) != p)
        nContours++;
        n0 = n;
        p = M(n,3);

at the beginning to

Code:

do
    if (M(n,3) < 0.99 * p || M(n,3) > 1.01 * p)
        nContours++;
        n0 = n;
        p = M(n,3);

which would give you roughly 1% of tolerance of the referenced p value before switching over to a new contour.

Hello Alex!

That's a cool idea to give some tolerance to the contour magnitude. I will definitely try this next time.

Thanks for your help. I really appreciate it. :)

Jabir


All times are GMT -4. The time now is 06:20.