
[Sponsors] 
November 2, 2010, 15:01 

#2 
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,089
Rep Power: 34 
Hi,
I think that gSum() is global sum, which means that gSum() sums over all the processors in a parallel run. Philip 

June 1, 2018, 02:04 

#3 
New Member
javad haqqani
Join Date: Dec 2017
Posts: 16
Rep Power: 8 
Now how can one perform a partial summation? I need to sum up half of a volScalarField.


June 1, 2018, 04:21 

#4  
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,089
Rep Power: 34 
Quote:
Code:
scalar sumVf = 0.0; forAll(vf, cellI) { // Sum up cells with a cell index less than 5 (you can use your own criteria here) if (cellI < 5) { sumVf += vf[cellI]; } } // Sync sum across processors reduce(sumVf, sumOp<scalar>()); Info<< "The global sumVf is: " << sumVf << endl; 

June 1, 2018, 05:23 

#5 
New Member
javad haqqani
Join Date: Dec 2017
Posts: 16
Rep Power: 8 
I've done that; but I need Vf's dimension. Plus, i'm dealing with very small numbers and the vf[cellI] gives a very large value when the real velue is very small as 1e100.


June 1, 2018, 06:37 

#6  
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,089
Rep Power: 34 
Quote:
Code:
vf.dimensions(); As regards "vf[cellI] gives a very large value when the real value is very small as 1e100": this should not be the case: if vf[cellI] is equal to 1e100 then that is what it should return; if you are getting some other large number then I suggest you check that you are not indexing outside the bounds of the array. Also, I suggest you give more details about your problem and your attempted solutions. 

February 4, 2023, 20:34 

#7  
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 205
Rep Power: 7 
Dear Philip
Thanks for explaining how to use "reduce" command properly. I have another question; Code:
volScalarField kineticEnergy0("kineticEnergy0", 0.5*magSqr(U)); Info << "size ofkineticEnergy0 = " << kineticEnergy0.size() << endl; Code:
scalar kineticEnergy0Ave = gAverage(kineticEnergy0); Thanks, Farzad Quote:


February 7, 2023, 05:32 

#8 
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,089
Rep Power: 34 
The total energy can be calculated as
Code:
const volScalarField kineticEnergy("kineticEnergy", 0.5*magSqr(U)); const scalar totalKineticEnergy = gSum(kineticEnergy); Code:
const scalar averageKineticEnergy = gAverage(kineticEnergy); Code:
const scalar volumeWeightedAverageKineticEnergy = gAverage(kineticEnergy.primitiveField()*mesh.V())/gSum(mesh.V()); 

Tags 
gsum(), sum() 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Transient simulation not converging  skabilan  OpenFOAM Running, Solving & CFD  14  December 16, 2019 23:12 
How to write k and epsilon before the abnormal end  xiuying  OpenFOAM Running, Solving & CFD  8  August 27, 2013 15:33 
Convergence moving mesh  lr103476  OpenFOAM Running, Solving & CFD  30  November 19, 2007 14:09 
IcoFoam parallel woes  msrinath80  OpenFOAM Running, Solving & CFD  9  July 22, 2007 02:58 
Could anybody help me see this error and give help  liugx212  OpenFOAM Running, Solving & CFD  3  January 4, 2006 18:07 