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/)
-   -   Extracting 2D velocity from the 3D velocity field (https://www.cfd-online.com/Forums/openfoam-post-processing/134011-extracting-2d-velocity-3d-velocity-field.html)

JonW April 23, 2014 11:20

Extracting 2D velocity from the 3D velocity field
 
1 Attachment(s)
Dear foamers
I have a 3D velocity filed Ux Uy Uz and from it I need to extract the flow in the horizontal plane, namely Ux and Ux, as in Uh = (Ux, Uy, 0). I need "Uh" to be volVectorField just as the general "U" field.

First I did "foamCalc components U" in the case dir.
Thereafter I loaded Ux, Uy, Uz (each is volScalarField)
Created "volVectorField U_horizontal"
Thereafter I tried something stupid like
"U_horizontal = vector(Ux,Uy,0);", which doesnt work, likely becouse vector is not volVectorField compatible.

Do anybody know how to do this? :confused:

Cheers
JonW

P.s. you can see the whole implementation from horizontal.zip

kmooney April 25, 2014 00:06

Is your goal to be able to post-process a velocity field on a plane? If so, take a look at the 'sample' utility. There you can define a plane and set the field values you want to extract / interpolate onto it.

There is an example dictionary here:

Code:

/applications/utilities/postProcessing/sampling/sample/
Cheers!
Kyle

JonW April 25, 2014 18:06

Thanks for the info Kyle, (and thanks for responding)

This was not exactly what I had in mind. I think you approach using the interpolationScheme cellPoint; would work. But it will require me to do some re-programming in terms of analysis/post processing. So in the name of my laziness, I was hoping to make as I mentioned above, so I can use my code in its current state. But, I will use what suggest in the end, if I don't find the solution.

Here is some other fatal tests, now in trying to extract the vertical velocity U_z, with a different approach (without having to use "foamCalc components U" to generate volScalarFields Ux Uy and Uz):
First I generated an empty volVectorField U_z (in the same manner as U_h in the above file), thereafter I tried the following:

U_z = vector(0,0,U.component(vector::Z).value());
U_z = vector(0,0,U.component(vector::Z));
U_z = vector(0,0,U.value().component(2));

.value() would never work as it is dimensionless, but anyway had to try.
As I mentioned before, I think vector is not volVectorField compatible, and thus the above breaks. :(

Cheers
Jon

JonW May 1, 2014 14:40

To do the stuff as explained above, I wrote a simple bash scrip, which uses awk, tail, head and grep. This file is very specific for my case, and thus have to be changed for your case. You should have some rudimentary understanding of U set-up before trying this at home. I hope this will be helpful for some, as a template. I call the script for "generateUxy.sh" and consists of the following:

# --------------------------------------------------------------------
#!/bin/sh
# --------------------------------------------------------------------
# Usually, don't have to change header1.
header1=22
header2=`expr $header1 + 1`
# In my case, I read the tailer1 number from line 21 in U:
tailer1=1060080
# tailer1=554736
tailer2=`expr $tailer1 + 1`
# --------------------------------------------------------------------
echo "---------------------------------------------------------" && \
echo " Starting transformation: [Ux,Uy,Uz] -> [Ux,Uy,0] ..." && \
head --lines=+$header1 U > Uxy1.tmp && \
sed 's/object U;/object Uxy;/g' Uxy1.tmp > Uxy2.tmp && \
tail --lines=+$header2 U > Uxy3.tmp && \
head --lines=+$tailer1 Uxy3.tmp > Uxy4a.tmp && \
tail --lines=+$tailer2 Uxy3.tmp > Uxy4b.tmp && \
awk '{print $1, $2, $3*0+99999999}' Uxy4a.tmp > Uxy5.tmp && \
sed 's/99999999/0)/g' Uxy5.tmp > Uxy6.tmp && \
cat Uxy2.tmp Uxy6.tmp Uxy4b.tmp > Uxy
echo " ...done!" && \
# --------------------------------------------------------------------
echo " Cleaning temporary data..." && \
for FILE1 in *.tmp
do
rm "$FILE1"
done
echo " ...done!" && \
echo "---------------------------------------------------------"
# --------------------------------------------------------------------


Cheers :)
Jon

JonW May 3, 2014 10:51

1 Attachment(s)
It is better to have the file (of the above), so here is the download... ;)
J.


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