CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Post-Processing (
-   -   Problem with sample (

flying June 10, 2009 05:48

Problem with sample
Hey foamers:

Now I need to plot the variables in a line. And I have checked from the Forum. I know that I need to use "sample". And I try to use it in the tutorials/solidDisplacementFoam/plateHole.
It is very sad that although there is no information and there is information such as below lines, I can not find any sample data.

create time

Create mesh for time = 0

Time = 0

Time = 20

Time = 40

Time = 60

Time = 80

Time = 100


Moreover, I would like to know if I need to sample data through the internal field, is it enough to change


Thanks and best wishes!

ngj June 10, 2009 05:53


Look into


where you will find a sampleDict, which shows all (I think) possible usages of the sample utility. Then choose whatever you need, and it should be working.

Best regards,


flying June 10, 2009 05:56

Thanks, I will try it. But the thing is that I have tried it in the tutorial. Does anybody also find this problem?

flying June 10, 2009 06:26

Hey ngj!

Thanks for your advice.

Follow your advice, I have got the data.However, I could not get the "mag(U)" and mag"UMean".

Would you like to give me more advice about it?

Thanks and best wishes!

ngj June 10, 2009 07:08


I cannot get the magnitude either, however, you can sample the U vector and calculate the magnitude afterward, i.e.


Or you can make a postprocessing tool, which calculates the magnitude of U over the complete computational domain, and extract the samples from this field. However, I believe the first option would be the easiest.

Best regards,


flying June 10, 2009 07:33

Thanks Niels!

It is a good method to solve the problem. However, I would like to know whether the "sample" Uitily can sample the mag(U), or I don't know how to do it.

Have a nice day!

ngj June 10, 2009 07:49

As said, I cannot get the tool to sample the magnitude. However sample the U-field and then use a small postprocessing tool in whatever language you prefer to convert the sampled U velocity components into the magnitude.

You could do something like the following. Put it into a small script and execute it from the case folder:

cd sets


for i in $list1
cd $i
list2=`ls *U*`
for j in $list2
cat $j | awk '{var = sqrt( $2*$2 + $3*$3 + $4*$4)} {print $1,var}' > $j.modified
cd ..

Best regargs,


flying June 12, 2009 09:33

I am sorry that I just have time to reply it.

Just now I copy the command line you have written. I am amazed by it. I think you are very great at coding.

Although it works, it is very sorry that I even don't know much about its meaning and I also don't know how to "Put it into a small script and execute it ". I guess you used "linux" for last commands.

If you could spend some time to tell me how to add it into a script and execute it, I will be very very grateful about it.

Thanks and best wishes!

ngj June 12, 2009 09:59


Thanks for the kind words.

All you need is to copy the text into a text-file, let us call it "". Then copy the file to your root directory, e.g. damBreak.

When you executed the sample utility, then type "sh" in the command line, and it will go through all of the files in the folder "sets" and read all those containing the U velocities, e.g. line_1_U.xy and write the data to the same folder with the name line_1_U.xy.modified. Note that you cannot have more and one vector field you are sampling, as the small script I gave you might not be able to handle that.

I hope this helps.

Best regards,


flying June 12, 2009 10:13

Thanks for your reply. It is very helpful!

flying February 11, 2010 09:51

Hey Niels:

I hope you are fine. Now I would like to observe the flow field in one plane changing with time. I could sample the plane out, but it is pity that they are put in different folders which is related with time with the same name.

I wish they could be put in one folder and I could read them as a series of time. Then, I could observe the flow field evolution with time.

My idea is to rename the file related with time and copy them in one folder. But I have no enough knowledge about linux programming. Would you like to give me some tips about it during your busy work?

Best wishes and thanks!

Xinguang Cui

All times are GMT -4. The time now is 03:59.