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/)
-   -   Inquire about the max() function in OpenFOAM (https://www.cfd-online.com/Forums/openfoam-programming-development/180678-inquire-about-max-function-openfoam.html)

harvee November 28, 2016 06:58

Inquire about the max() function in OpenFOAM
 
Hey there!
I'm confused about how the max() function works.
Currently I'm making a AMR sensor using gradrho &gradU
Code as following:
In rhoCentralFoam.C ,I add this lines.
Code:

//----------------------------sensor-------------------------------------//
        volScalarField Uy = mag(U.component(vector::Y));
        volVectorField gradUy = fvc::grad(Uy);
        volScalarField gradUyy = mag(gradUy.component(vector::Y));
        gradUyyN = gradUyy/max(gradUyy);

//        using tensor
        volTensorField gradU0 = fvc::grad(U);
        volScalarField gradU1 = mag(gradU0.component(tensor::YY));
        gradUtN = gradU1/max(gradU1);

        volScalarField gradrho = mag(fvc::grad(rho));
        gradrhoN = gradrho/max(gradrho);

//----------------------------sensor-------------------------------------//

I used two method to calculate the {partialUy/partialY},the result shows they're identical.However,after applied the max() function for normalization.
For using as sensor I want it ranges from 0-1.
gradrhoN works fine,and it's value range from 0-1.
But,the range of gradUyyN or gradUtN (which has the same value) shows a changing range approximately from a non-zero extremly small value to about 0.5.
Why the max value / max value is not 1?
thank you:)

hk318i November 29, 2016 10:28

Are you testing this code in parallel?

harvee November 29, 2016 10:30

hi
 
Quote:

Originally Posted by hk318i (Post 627422)
Are you testing this code in parallel?

no,I'm using single cpu.
I just find the solution.
Use gMax instead of max gives the correct value.

hk318i November 29, 2016 10:37

Exactly, that's why I asked. But if you are running on single processor, max() should work fine.

harvee November 29, 2016 10:44

Quote:

Originally Posted by hk318i (Post 627425)
Exactly, that's why I asked. But if you are running on single processor, max() should work fine.

gradrho = fvc::grad(rho);
gradrhoMag = mag(gradrho);
gradrhoMax = max(gradrhoMag);

when I check the value of gradrhoMag and gradrhoMax, the maximum of gradrhoMag=gradrhoMax, but when I use max() for doing gradU,it's not work.
the value is almost twice bigger than the maximum of gradUMag.


All times are GMT -4. The time now is 06:29.