# Problem with functionObjects in parallel

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

 February 9, 2013, 09:44 Problem with functionObjects in parallel #1 Senior Member   Mahdi Hosseinali Join Date: Apr 2009 Location: NB, Canada Posts: 236 Rep Power: 10 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("U"); const scalarField& mu = mesh().lookupObject("mu"); const scalarField& rho = mesh().lookupObject("rho"); const scalarField& p = mesh().lookupObject("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()); reduce(Reyf,sumOp()); reduce(Lambdaf,sumOp());``` 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

 February 9, 2013, 16:16 #2 Super Moderator     Niklas Nordin Join Date: Mar 2009 Location: Stockholm, Sweden Posts: 693 Rep Power: 21 Code: ``` const volScalarField& p = mesh().lookupObject("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);`

 February 11, 2013, 15:27 #3 Senior Member   Mahdi Hosseinali Join Date: Apr 2009 Location: NB, Canada Posts: 236 Rep Power: 10 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.

 February 12, 2013, 02:28 #4 Super Moderator     Niklas Nordin Join Date: Mar 2009 Location: Stockholm, Sweden Posts: 693 Rep Power: 21 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.

 February 12, 2013, 06:27 #5 Senior Member   Mahdi Hosseinali Join Date: Apr 2009 Location: NB, Canada Posts: 236 Rep Power: 10 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.

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post MOHAMMAD67 OpenFOAM Running, Solving & CFD 7 November 23, 2015 11:53 dunga82 FLUENT 8 April 19, 2012 20:23 oskar OpenFOAM Native Meshers: snappyHexMesh and Others 0 July 7, 2011 10:05 pilou FLUENT 0 March 10, 2011 09:20 Richard.A CFX 2 August 3, 2002 03:54

All times are GMT -4. The time now is 00:36.