|
[Sponsors] |
![]() |
![]() |
#2 |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,091
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 |
|
![]() |
![]() |
![]() |
![]() |
#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.
|
|
![]() |
![]() |
![]() |
![]() |
#4 | |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,091
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; |
||
![]() |
![]() |
![]() |
![]() |
#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 1e-100.
|
|
![]() |
![]() |
![]() |
![]() |
#6 | |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,091
Rep Power: 34 ![]() ![]() |
Quote:
Code:
vf.dimensions(); As regards "vf[cellI] gives a very large value when the real value is very small as 1e-100": this should not be the case: if vf[cellI] is equal to 1e-100 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. |
||
![]() |
![]() |
![]() |
![]() |
#7 | |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
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 of-kineticEnergy0 = " << kineticEnergy0.size() << endl; Code:
scalar kineticEnergy0Ave = gAverage(kineticEnergy0); Thanks, Farzad Quote:
|
||
![]() |
![]() |
![]() |
![]() |
#8 |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,091
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 | 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 |