CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Pre-Processing (
-   -   question regarding the codes for setting inlet flow (

Alicelin November 10, 2009 04:59

question regarding the codes for setting inlet flow
Dear all,
I have a question about writing the codes for the inlet flow.I would like to know what's the difference between the following two codes?
Code 1:
inletk==1.5*pow(0.11*Foam:: pow(z*2,-0.18),2)*magSqr(inletU)
Code 2:

actually what's the difference in the meaning between "Foam:: pow" and "pow"?


kathrin_kissling November 10, 2009 06:46

Dear Alicelin,

you will find the difference if you try to do something like this:

volScalarField a;
volScalarField b = Foam::pow(a,2);


volScalarField a;
volScalarField b = pow(a,2);

The second one will fail. The problem is pow is firstly only defined for scalars (doubles, float, ...)
If you try to work on a derrived type like volScalarField or scalarField, which are list of scalars, in c you would have need to go:

for (i=0; i< sizeOfField; i++)
b[i] = pow(a[i],2)

Foam does this for you. It automatically loops if you work on scalarFields. But Foam needs to know, whether it should do that or not. So you have to tell it the namespace, which is FOAM and the belonging function which is pow in your case. So the macro is FOAM::pow(<something>, double);
Foam will automatically take a look on what <something> is and work accordingly.

If you have questions regarding this, please feel free to ask!


Alicelin November 11, 2009 01:11

Dear Kathrin,

Really thanks for your reply! :)

just one more question to ask.....what're "doubles" and "float" that you've mentioned in your post?


kathrin_kissling November 11, 2009 03:05

Dear Alice,

double and float are data types for floating point numbers in c/c++. The difference is in the size, which can be stored and therefore in its precision. Float gives you numbers in single precision, double in double precision.

This is really fundamental c/c++. Please refer to a textbook or webpages on c/c++. You will find it very difficult to work with OpenFOAM if you don't have experience with c++ or at least c.

Hope this helps!



Alicelin November 11, 2009 04:04

Dear Kathrin,

Really thanks a lot!:)


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