CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Problem with functionObjects in parallel (https://www.cfd-online.com/Forums/openfoam/112993-problem-functionobjects-parallel.html)

anishtain4 February 9, 2013 08:44

Problem with functionObjects in parallel
 
I'm using this functionObjects in controlDict so I can extract them later via foamLog to check some qualities of my solution:

Code:

functions
{
    kineticEnergy
    {
        type            coded;
        functionObjectLibs ( "libutilityFunctionObjects.so" );
        redirectType        error;
        code
        #{
                const volVectorField& U = mesh().lookupObject<volVectorField>("U");
                const scalarField& mu = mesh().lookupObject<volScalarField>("mu");
                const scalarField& rho = mesh().lookupObject<volScalarField>("rho");
                const scalarField& p = mesh().lookupObject<volScalarField>("p");
                scalar C = average(sqrt(1.4*p/rho));
                scalar TKE =0.5*average(magSqr(U-average(U))).value();
                scalar lambdaf=1.0/average(magSqr(diag(fvc::grad(U))));
                scalar Reyf = average(rho/mu)*sqrt(4.0*TKE*lambdaf/3.0);
                Info << "TKE = " << TKE << endl;
                Info << "Reyf = " << Reyf << endl;
                Info << "MaPrime = " << 2.0*TKE/C/3.0 << endl;

        #};
    }
   

}

They perform good in single process but in parallel I have to reduce them between processors with something like:
Code:

reduce(TKE,sumOp<scalar>());
reduce(Reyf,sumOp<scalar>());
reduce(Lambdaf,sumOp<scalar>());

But I want to average them not sum, or I should divide this sum to number of processors which I don't know how to get number of processors?
I'm doing this manually now which is
Info << TKE/16.0 << endl;
and I know that I can use dict.lookup but that involves reading file in every single time step which is heavily inefficient

niklas February 9, 2013 15:16

Code:

            const volScalarField& p = mesh().lookupObject<volScalarField>("p");
            const scalarField& vols = mesh().V();
            scalar pSum = gSum(vols*p);
            scalar volTot = gSum(vols);
            scalar pAv = pSum/volTot;

and if you want density averaged properties you simply add rho to the calculation
or....
you could simply write
Code:

            scalar pAv = gAverage(p);

anishtain4 February 11, 2013 14:27

Thanks niklas but my problem is not with the calculation, my problem is in the parallel case, the calculations you have mentioned would be calculated on every sub-domain which one would be printed out in the screen when you use Info<< ? Obviously you should reduce it among different processes and THIS is my problem, if I use sumOp it should be divided to number of processes or I should use some other operator other than sumOp.

niklas February 12, 2013 01:28

just try my code. Did you try it?

Did you notise the g in front of sum, gSum.
Can you guess what the g stands for.

The Info stream is only for processor 0, you also have an Sout stream, then it will
write the statement for every processor.

I think that you are not using the -parallel flag when you are running the parallel case.

anishtain4 February 12, 2013 05:27

Thanks niklas, that all make sense now but unfortunately it does not work in functionobjects of libutilityFunctionObjecs.so

btw: I use -parallel flag


All times are GMT -4. The time now is 13:32.