CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Why Uprime2mean is minus in some grids? (https://www.cfd-online.com/Forums/openfoam/90082-why-uprime2mean-minus-some-grids.html)

 maysmech June 30, 2011 05:14

Why Uprime2mean is minus in some grids?

Dear Foamers,
I need mean value of u'u', v'v' and w'w' to reach to u' , v' and w'.
when uprime2mean in controlDict switched on these values were written in time folders.
But i don't know why they are minus in some grids.
Any suggestion?

 maysmech July 1, 2011 05:03

If it is mean of U'U', it should be positive, shouldn't it?

 gregor July 1, 2011 06:45

how can i delete a post ?

 maysmech July 3, 2011 07:06

Any suggestion?

as I know, uprime2mean is a symmetric tensor, thus with 6 components. cross components (say, U'W') can be negative. check if You are observing right components.

Best Regards

 maysmech July 6, 2011 08:02

You are right.
its 6 components are: U'U U'V' U'W' V'V' V'W' W'W'
As you say U'W' can be negative but my problem is U'U' is negative in some grids !

 sam1364 January 23, 2012 20:00

Hi Maysam,

Did you get any answer from your question?! do you know how uprime2Mean is calculated? I have problem to find out how this parameter is calculated.

Thanks,
Pooyan

 anon_a January 24, 2012 02:21

Call this a stupid question but I have to ask:

prime2Mean is calculated in src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverageTemplates.C
with the following code

Code:

```scalar alpha = 0.0; scalar beta = 0.0; if (faItems_[i].timeBase()) {     alpha = (totalTime_[i] - dt)/totalTime_[i];     beta = dt/totalTime_[i]; } else                                                                                                                            {     alpha = scalar(totalIter_[i] - 1)/scalar(totalIter_[i]);     beta = 1.0/scalar(totalIter_[i]); } prime2MeanField =     alpha*prime2MeanField  + beta*sqr(baseField)   - sqr(meanField);```
Shouldn't the last lines be like this?
Code:

```prime2MeanField =     alpha*prime2MeanField  + beta*sqr(baseField)   - beta*sqr(meanField);```
Or is this just in my head? I never understood...

 gregor January 24, 2012 08:59

Quote:
 Originally Posted by anon_a (Post 340770) [/CODE]Shouldn't the last lines be like this? Code: ```prime2MeanField =     alpha*prime2MeanField  + beta*sqr(baseField)   - beta*sqr(meanField);``` Or is this just in my head? I never understood...

No it shouldn't

they're using the following identy:

1/(n)sum^n(phi_i-<phi>)^2=1/n*sum^n(phi_i^2)-<phi>^2 , where <.> is an averaged value

http://en.wikipedia.org/wiki/Computa...r_the_variance

 anon_a January 24, 2012 09:57

1 Attachment(s)
Yes, I am aware of this identity (by the way, you missed 1/(n) in the first sum of the RHS).
However, I have to insist that there is something wrong.
I attach a small pdf with my derivations, can you find the error?

 gregor January 24, 2012 11:13

1 Attachment(s)
i will look through equations when i find some time, in the meanwhile you can have a look at my document.

But i think the problem is that you don't consider the mean value as a "on the fly value" so you can not simply use N<x>^2=(N-1)x^2+x^2 since you need for sigma^2_pr <x>^2_{N-1} instead <x>^2_N

Gregor

PS: And be aware that actually two steps are performed

1. removing the old mean value in addMeanSqrToPrime2Mean<scalar, scalar> in fieldAverage.C Line 175

2. evaluating the variance using current mean value calculatePrime2MeanFields<scalar, scalar> in fieldAverage.C Line192

 anon_a January 24, 2012 12:20

Sorry but there seem to be many errors in your derivations:
- In your calculations, you take (1) (which, I assume, is your interpretation of the OF expression) as correct, while I am trying to see if it can be proven.
- Where did the term <phi>_{i-1}^2 in (1) come from? It does not exist in OF.
- The substitution in (2) was performed incorrectly, terms like (n-1)/n and <phi>_{i-2}^2 are missing in the parenthesis.
- Where did sigma_{i-2} go in (3)?
- Where did the sum come up in (4)?
and so on...

To be honest, this confuses me even more.

 gregor January 24, 2012 12:41

Quote:
 Originally Posted by anon_a (Post 340902) Sorry but there seem to be many errors in your derivations: - In your calculations, you take (1) (which, I assume, is your interpretation of the OF expression) as correct, while I am trying to see if it can be proven.
So do it the other way round and look if can derive it from the algorithm

Quote:
 Originally Posted by anon_a (Post 340902) - Where did the term _{i-1}^2 in (1) come from? It does not exist in OF.
look what happens in the addMeanSqrToPrime2Mean function.

Quote:
 Originally Posted by anon_a (Post 340902) - The substitution in (2) was performed incorrectly, terms like (n-1)/n and _{i-2}^2 are missing in the parenthesis.
sigma_{i-1} = sigma_{i-2} + <phi>^2_{i-1}

thats the step performed in addMeanSqrToPrime2Mean in fieldAverageTemplates.C line 264

Code:

`prime2MeanField += sqr(meanField);`
Quote:
 Originally Posted by anon_a (Post 340902) - Where did sigma_{i-2} go in (3)?
like if have written i assume it to be zero (which might not be true for i-2 but has to be for i=0 and since all the old mean values are canceled out for every timestep it should be ok)

Quote:
 Originally Posted by anon_a (Post 340902) - Where did the sum come up in (4)?
you could write (3) as

sigma = alpha * phi^2_old + beta*phi^2 - <phi>_i^2

which is

sigma = <phi^2>_i - <phi>_i^2

or

sigma = 1/n sum(phi_i^2) - <phi>_i^2 .

I know its not nice and there are many typos but may be you still see the point

Gregor

 gregor January 24, 2012 12:56

Quote:
 Originally Posted by anon_a (Post 340902) EDIT: I now see your point about the existence of _{i-1}^2 after your note about addMeanSqrToPrime2Mean. To be honest, this confuses me even more.
You could try it by evaluting it manually. The point is you want to have a variance every time step but your final mean value is unknown, therefore you take the current mean value. But once you use the current mean value the old mean values has to be taken out.

 anon_a January 24, 2012 13:25

Well, I thought about it on the way home.
You can add and substract (N-2)/(N-1) (<x>)^2 in my last equation and the OF expression is obtained.

Thanks for your help, patience and time, it is clear now!
I assume that this square is added in the beginning to avoid numerical errors, cancellations of significant digits and so on, right?

 gregor January 24, 2012 13:36

Yes i guess it is the same reason why you calculate the average by

<phi> = alpha*<phi>_{i-1} + beta * phi

phiS += phi

phiA = phi/N

to avoid big numbers.

Sorry if wasn't that clear. Explaining something easy is an art ;)

 aka August 9, 2012 23:52

Quote:
 Originally Posted by gregor (Post 340908) You could try it by evaluting it manually. The point is you want to have a variance every time step but your final mean value is unknown, therefore you take the current mean value. But once you use the current mean value the old mean values has to be taken out.
Hi Gregor,
You said "The point is you want to have a variance every time step but your final mean value is unknown, therefore you take the current mean value." I understand most of your derivations however, I am still confused on the idea of using the "current mean value" instead of the "final mean value". For the variance, we need the final mean value and using the current mean value may have a significant effect for strongly separated flows. I also see a difference on the last term of your derivation on the "test.pdf" file. You used <phi>_i^2 on the last term in equation (2) however <phi>^2 is coming on your equation (3). It seems you are going from the current mean to the final mean value. I appreciate your help on this part. It took me some time to get convinced with the way "prim2Mean" is calculated in OpenFOAM.

Thanks a lot!

 gregor August 13, 2012 04:45

Quote:
 Originally Posted by aka (Post 376368) I understand most of your derivations however, I am still confused on the idea of using the "current mean value" instead of the "final mean value". For the variance, we need the final mean value and using the current mean value may have a significant effect for strongly separated flows.
In step 1 in the pdf file you plug in the old variance and the old mean value gets cancelled out. This means you are alway using the current mean value. The current mean value is correct but only up to the current (i-th) time step. In the next time step you update the mean value, take out the effect of the old (which is not valid anymore) value and calculate the variance using the new current mean value. However on the long run your mean value should converge and therefore shouldnt change anymore, because if your mean value is not converged there is no chance that your variances are converged.

Quote:
 Originally Posted by aka (Post 376368) I also see a difference on the last term of your derivation on the "test.pdf" file. You used _i^2 on the last term in equation (2) however ^2 is coming on your equation (3). It seems you are going from the current mean to the final mean value.
I agree that the document is very sloppy written. The point is, that your current mean value is the final value for your time series up to time i.

 aka August 22, 2012 03:33

Thanks Gregor . I appreciate it.

 arunsmec November 14, 2012 08:31

UPrime2mean has 6 components 0,1,2...5. Among these which are <uu>, <v v> and <ww>?

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