CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Problem with functionObjects in parallel

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 9, 2013, 09:44
Default Problem with functionObjects in parallel
  #1
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 17
anishtain4 is on a distinguished road
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
anishtain4 is offline   Reply With Quote

Old   February 9, 2013, 16:16
Default
  #2
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
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);
niklas is offline   Reply With Quote

Old   February 11, 2013, 15:27
Default
  #3
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 17
anishtain4 is on a distinguished road
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.
anishtain4 is offline   Reply With Quote

Old   February 12, 2013, 02:28
Default
  #4
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
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.
niklas is offline   Reply With Quote

Old   February 12, 2013, 06:27
Default
  #5
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 17
anishtain4 is on a distinguished road
Thanks niklas, that all make sense now but unfortunately it does not work in functionobjects of libutilityFunctionObjecs.so

btw: I use -parallel flag

Last edited by anishtain4; February 12, 2013 at 08:52.
anishtain4 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel running of 3D multiphase turbulence model (unknown problem!!) MOHAMMAD67 OpenFOAM Running, Solving & CFD 7 November 23, 2015 11:53
fluent parallel problem in win7 x64 system dunga82 FLUENT 8 April 19, 2012 21:23
[snappyHexMesh] processorWeights problem with snappyhexmesh in parallel oskar OpenFOAM Meshing & Mesh Conversion 0 July 7, 2011 11:05
Parallel UDF problem, hello world version pilou FLUENT 0 March 10, 2011 09:20
cfx4 parallel sover Problem!! HELP Richard.A CFX 2 August 3, 2002 04:54


All times are GMT -4. The time now is 22:15.