CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Ustar computation in atmBoundaryLayerInletVelocityFvPatchVectorField.C (https://www.cfd-online.com/Forums/openfoam-programming-development/140558-ustar-computation-atmboundarylayerinletvelocityfvpatchvectorfield-c.html)

Okke79 August 18, 2014 05:58

Ustar computation in atmBoundaryLayerInletVelocityFvPatchVectorField.C
 
Hello,

My question concerns the computation of Ustar in atmBoundaryLayerInletVelocityFvPatchVectorField.C.

I do not understand why the forAll loop is taken over Ustar_ (in OF-2.2.x):

forAll (Ustar_, i){[I]Ustar_[i] = kappa_*Uref_/(log((Href_ + z0_[i])/max(z0_ , 0.001)));}

Is this in the case of different roughness lengths, z0, in the computational domain? If so, why is this loop then not taken over z0?

In previous versions of Openfoam (e.g. OF-2.0.x, no loop was applied at all).

Very much looking forward to an answer!

Kind regards,
Okke

marupio August 19, 2014 05:14

It doesn't matter which one you put into the forAll loop, just as long as it has the correct size. forAll(a, i) is short for: for(label i=0; i < a.size(); i++) so if Ustar and z0_ have the same size, it makes no difference. Since they are accessed by the same index, I'd say that's the case.

Why is it even in a forAll loop anyway? Looping over all the cells can be up to 10 times slower than using full field operations. The only reason I suspect they put it into a forAll is because of the function log((Href_ + z0_[i])/... the log(scalar + field) may not work.

Quick inspection shows this is not very good code anyway. They use max(z0_ , 0.001) within a loop, when this operation is itself a loop, and produces the same result all the time. The first thing I would do to improve this is to store the result ahead of time and use that in the loop.

My two cents. Share and enjoy!


All times are GMT -4. The time now is 21:37.