CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   probe a line (https://www.cfd-online.com/Forums/openfoam-post-processing/117844-probe-line.html)

GerhardHolzinger May 16, 2013 04:17

probe a line
 
1 Attachment(s)
Hi all,

I wrote a little python script that allows me to probe a line.
Actually, I state the start and the end of the line as well as the number of points and my script generates a probesDict containing the defined points.

Have a look at it and if you find my nasty bit of code useful, feel free to use it, or even improve it.

The script assumes a file named "probeLineDict" to reside in the system directory. The script itself needs to be executed from the case directory. However, you can change the paths inside the script to get a different behaviour.

kmooney May 20, 2013 23:13

I believe that the 'sample' utility can do this as well. Give a start point, and end point, fields to sample, and number of sample points, it will extract the data requested.

http://www.openfoam.org/docs/user/sample.php

GerhardHolzinger May 21, 2013 02:43

Quote:

Originally Posted by kmooney (Post 428777)
I believe that the 'sample' utility can do this as well.

You are right. However, if I use the probe function to do the job, I get a good time resolution.

I use sample as well, but in some cases I fell the need for higher time resolution. And writing everything to disk at a short interval and running sample afterwards is simply a waste of space.

laubeg May 21, 2013 04:37

Hi Gerhard,

I think in Line 25 it should be 'filename' instead of 'filenameW'.

And just to make things clear for future visitors of this thread: This file does not probe anything itselve, as one might expect from the title, but writes line coordinates to a probesDict, that is used by the 'native' OpenFOAM probeLocation application. As far as I know, you have to run this in advance of the processing itselve.

I never used the probe application, so Gerhard, maybe you could tell us a little more about the overall process: run Script -> run Solver -> find values in ./probes/-folder? Or is there anything else to consider? Do you have to modify the controlDict as well?

Thanks for the script! I hope that future generations of OpenFOAM will have a probe-application as good as the sample-app, but so far, this is a good workaround.

GerhardHolzinger May 21, 2013 04:54

Quote:

Originally Posted by laubeg (Post 428822)
This file does not probe anything itselve, as one might expect from the title, but writes line coordinates to a probesDict, that is used by the 'native' OpenFOAM probeLocation application. As far as I know, you have to run this in advance of the processing itselve.

You are completely right. My first post was indeed short of the information of how to use the script.

The script reads probeLineDict and generates entries for the regular probe function object. However, defining (start, end, nPoints) is much easier than writing 50 points along a line manually into probesDict.

The script overwrites probesDict. However, you can change the name of the file into which the script writes. If you are already using probes, make sure they do not collide.

The variable filename is the name of the file which contains the definition of the line to be probed. The variable filenameW is the name of the file into which the generated dictionary for probes is written.

The definition of the probe function object in controlDict must make use of an external file for the definition of the probes, otherwise, the generated file would be useless. I let the script write a seperate file in order to prevent it from messing up the controlDict.

The usage follow this procedure.

Put the probeLineDict into the system directory.
Run probeLine.py from the case directory
Run the solver

The controlDict contains this code:

Code:

functions
{
    probes1
    {
        type probes;

        functionObjectLibs ("libsampling.so");

        dictionary probesDict;
    }
   
    probes2
    {
        type probes;

        functionObjectLibs ("libsampling.so");

        dictionary probesDict2;
    }
}


laubeg May 21, 2013 05:12

Thanks for the explanation!

Quote:

Originally Posted by GerhardHolzinger (Post 428828)
The variable filename is the name of the file which contains the definition of the line to be probed. The variable filenameW is the name of the file into which the generated dictionary for probes is written.

From line 23 to 25 you define 'filename' and use 'filenameW' afterwards.

Copied from your zip-file, line 23 to 25:
Code:

filename = './system/' + probesDict
#filenameW = probesDict
mywfile = open(filenameW,'w')

As far as I know, '#' is interpreted as a comment. Anyway I get an error, running the script:

Code:

Traceback (most recent call last):
  File "Y:\Home\laubeg\SharedFolder\Fehlman1\Fehlman2D_4\probeLine.py", line 25, in <module>
    mywfile = open(filenameW,'w')
NameError: name 'filenameW' is not defined


GerhardHolzinger May 21, 2013 06:04

1 Attachment(s)
Hi, sorry for posting a buggy script. Mea culpa.

The code

Code:

filename = './system/' + probesDict
#filenameW = probesDict

should read

Code:

filenameW = './system/' + probesDict
#filenameW = probesDict

I used the commented filename-statements to test the script without the need of having an system directory present. However, filename and filenameW are not very good variable names.

jiujiumin June 5, 2013 09:56

Quote:

Originally Posted by GerhardHolzinger (Post 428828)
You are completely right. My first post was indeed short of the information of how to use the script.

The script reads probeLineDict and generates entries for the regular probe function object. However, defining (start, end, nPoints) is much easier than writing 50 points along a line manually into probesDict.

The script overwrites probesDict. However, you can change the name of the file into which the script writes. If you are already using probes, make sure they do not collide.

The variable filename is the name of the file which contains the definition of the line to be probed. The variable filenameW is the name of the file into which the generated dictionary for probes is written.

The definition of the probe function object in controlDict must make use of an external file for the definition of the probes, otherwise, the generated file would be useless. I let the script write a seperate file in order to prevent it from messing up the controlDict.

The usage follow this procedure.

Put the probeLineDict into the system directory.
Run probeLine.py from the case directory
Run the solver

The controlDict contains this code:

Code:

functions
{
    probes1
    {
        type probes;
 
        functionObjectLibs ("libsampling.so");
 
        dictionary probesDict;
    }
 
    probes2
    {
        type probes;
 
        functionObjectLibs ("libsampling.so");
 
        dictionary probesDict2;
    }
}


this : Run probeLine.py from the case directory how to work?

jiujiumin June 9, 2013 23:45

The probesDict file where can i find?????
 
Quote:

Originally Posted by GerhardHolzinger (Post 428846)
Hi, sorry for posting a buggy script. Mea culpa.

The code

Code:

filename = './system/' + probesDict
#filenameW = probesDict

should read

Code:

filenameW = './system/' + probesDict
#filenameW = probesDict

I used the commented filename-statements to test the script without the need of having an system directory present. However, filename and filenameW are not very good variable names.

The probesDict file where can i find?????
The probesDict file where can i find?????
The probesDict file where can i find?????
The probesDict file where can i find?????

laubeg June 10, 2013 03:27

Hi,

sorry for being rude, but did you even try to find a solution for one of your problems?

Here is one for running the python script: http://www.google.com

And one for the probesDict: Read the thread from the beginning or try the former solution!

This is a forum, not a google search. Regards!

jiujiumin June 11, 2013 09:13

sorry at the time i am very anxious
 
Quote:

Originally Posted by laubeg (Post 433019)
Hi,

sorry for being rude, but did you even try to find a solution for one of your problems?

Here is one for running the python script: http://www.google.com

And one for the probesDict: Read the thread from the beginning or try the former solution!

This is a forum, not a google search. Regards!

sorry never next and at the time i am very anxious.
At the same time
I have another question how do I set the probeLine.py file to probe many lines at the same time? such as two lines at a time. thanks

ari003 June 11, 2020 15:36

Quote:

Originally Posted by GerhardHolzinger (Post 428846)
Hi, sorry for posting a buggy script. Mea culpa.

The code

Code:

filename = './system/' + probesDict
#filenameW = probesDict

should read

Code:

filenameW = './system/' + probesDict
#filenameW = probesDict

I used the commented filename-statements to test the script without the need of having an system directory present. However, filename and filenameW are not very good variable names.

Sir I m trying the way which you just mentioned here but however I m confused whether to keep the python file and probeLineDict in the same system folder or not . Also do I have to include anything in controlDict folder?
I ll remain hopeful to get your reply.

ari003 June 13, 2020 21:09

Anyone from the forum can I get a response. I m in serious need. Please I ll remain hopeful.

mcgoldba July 11, 2020 14:08

Quote:

Originally Posted by ari003 (Post 774144)
Sir I m trying the way which you just mentioned here but however I m confused whether to keep the python file and probeLineDict in the same system folder or not . Also do I have to include anything in controlDict folder?
I ll remain hopeful to get your reply.

Hi Ari,

I have just started to look at using this script myself, and have not yet tested it. However, to answer your question, I believe the "probeLine.py" file should go into the main case directory, and the "probeLineDict" file should go into the "system/" sub-directory.

This is shown on line 17 of the python script:

Code:

filename = './system/' + probeLineDictName
Regards

mcgoldba July 11, 2020 14:13

In regards to your question about the controlDict, this was answered earlier in Gerhard's post:

Quote:

Originally Posted by GerhardHolzinger (Post 428828)

The controlDict contains this code:

Code:

functions
{
    probes1
    {
        type probes;

        functionObjectLibs ("libsampling.so");

        dictionary probesDict;
    }
   
    probes2
    {
        type probes;

        functionObjectLibs ("libsampling.so");

        dictionary probesDict2;
    }
}




All times are GMT -4. The time now is 04:34.