# Mass Weighted Average

 Register Blogs Members List Search Today's Posts Mark Forums Read December 11, 2012, 14:40 Mass Weighted Average
#1
Member

Brock Lee
Join Date: Sep 2012
Location: Midwest
Posts: 40
Rep Power: 12 Hey guys, I'm looking to calculate a mass weighted average over a faceZone for pressure using swak4foam. Specifically, this is the equation I'm trying to implement...

Capture.PNG

My question comes when trying to implement. Is it possible in swak4foam to divide a sum by a sum within one expression? Can I do two sums separately and divide them? So far I've only seen expressions that can do one accumulation, such as the one below for mass flow rate...

Code:
mass-in
{
type swakExpression;
valueType faceZone;
zoneName interior-inlet-1;
expression "phi*flip()";
accumulations (
sum
);
verbose true;
autoInterpolate	true;
}
Also, (if possible) what is the syntax for getting the absolute value and dot product within a swakExpression? Thanks in advance!
Attached Images Capture.jpg (10.7 KB, 49 views)   December 11, 2012, 18:32 #2 Member   Brock Lee Join Date: Sep 2012 Location: Midwest Posts: 40 Rep Power: 12 Ok, I think I found an equivalent expression. The following function I believe does what I need it to do... Code: p_stat2 { type swakExpression; valueType faceZone; zoneName interior-inlet-1; expression "(p*phi*flip())/sum(phi*flip())"; accumulations ( sum ); verbose true; autoInterpolate true; } However, I would still be interested in knowing if you can perform a dot product or an absolute value within a swakExpression? Also, does anyone know if when you have backflow on a face, does it register as negative mass flow using the phi*flip() formulation? Last edited by GRAUPS; December 12, 2012 at 13:37.   December 12, 2012, 19:48 #3
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,224
Rep Power: 49  Quote:
 Originally Posted by GRAUPS Ok, I think I found an equivalent expression. The following function I believe does what I need it to do... Code: p_stat2 { type swakExpression; valueType faceZone; zoneName interior-inlet-1; expression "(p*phi*flip())/sum(phi*flip())"; accumulations ( sum ); verbose true; autoInterpolate true; } However, I would still be interested in knowing if you can perform a dot product or an absolute value within a swakExpression? Also, does anyone know if when you have backflow on a face, does it register as negative mass flow using the phi*flip() formulation?
Dot product is according to the conventions of OpenFOAM the &-operator.

Yes. You should get the correct backflow if you use flip() (the sign of phi depends on the orientation of the face. Multiplying with flip() "removes" that dependence)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request   December 12, 2012, 20:34 #4
Member

Brock Lee
Join Date: Sep 2012
Location: Midwest
Posts: 40
Rep Power: 12 Quote:
 Originally Posted by gschaider Dot product is according to the conventions of OpenFOAM the &-operator.
Awesome, thank you. And using the mag() function on a scalar I found is basically the equivalent of taking the absolute value.

Quote:
 Originally Posted by gschaider Yes. You should get the correct backflow if you use flip() (the sign of phi depends on the orientation of the face. Multiplying with flip() "removes" that dependence)
Fantastic, just wanted to make sure. Thanks for your replies.   November 26, 2015, 05:51 #5 New Member   Join Date: Jul 2013 Posts: 8 Rep Power: 11 Dear Foamers, I want to use groovybc, in order to create a T bc for a reciculation device. To do this I have do calculate the mass-flux-weighted temperature of a face. I use the following code: PHP Code:      Auslasslinks_1_5    {        type            groovyBC;        valueExpression "Tein";    variables    "massenstrom=1;Taus{Ansaug_3}=sum(T*phi)/sum(phi);cp=1007;Qdot=100;Tein=Taus-Qdot/(massenstrom*cp);";    fractionExpression "1";        value           uniform 300;        refValue        \$value;    }   Unfurtunately this bc doesn't work and my simulation crashes because of the Taus{Ansaug_3} calculation. If I calculate a faceweighted temperature instead of the mass flux weighted temperature for Taus{Ansaug_3} or if I use Taus instead of Taus{Ansaug_3}, the simulation runs. So my question: Is this a bug in groovybc or is there a bug in my code? Thank's in advance   May 3, 2019, 09:28 Mass averaged weighted kinetic energy #6 New Member   @moon Join Date: Apr 2019 Posts: 8 Rep Power: 5 Hi guys I am trying to calculate mass average weighted kinetic energy for Tank sloshing case. The equation is similar to the one discussed in this thread. (summation(mass*0.5*U*U)/ summation (mass)) Can someone help me with the syntax to write this expression using swak4Foam ? Iam new to openFoam. any help will be highly apreciated. Thank you.   May 3, 2019, 10:34 #7
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,224
Rep Power: 49  Quote:
 Originally Posted by TRIDEV G Hi guys I am trying to calculate mass average weighted kinetic energy for Tank sloshing case. The equation is similar to the one discussed in this thread. (summation(mass*0.5*U*U)/ summation (mass)) Can someone help me with the syntax to write this expression using swak4Foam ? Iam new to openFoam. any help will be highly apreciated. Thank you.

The expression for the total mass would be (assuming you have the denisty in a field rho) "sum(vol()*rho)". The sum of the kinetic energy would be "sum(vol()*rho*0.5*(U&U))" (using & for the scalar product). Now with swakExpression you could write the complete expression as "(vol()*rho*0.5*(U&U))/sum(vol()*rho)" (without the sum) and in the accumulations-list use "sum". Or you write the equation with the sum and in the accumulations use one of "min", "max", "average". But the first option needs a little less computation
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request   May 6, 2019, 06:38 #8
New Member

@moon
Join Date: Apr 2019
Posts: 8
Rep Power: 5 Quote:
 Originally Posted by gschaider The expression for the total mass would be (assuming you have the denisty in a field rho) "sum(vol()*rho)". The sum of the kinetic energy would be "sum(vol()*rho*0.5*(U&U))" (using & for the scalar product). Now with swakExpression you could write the complete expression as "(vol()*rho*0.5*(U&U))/sum(vol()*rho)" (without the sum) and in the accumulations-list use "sum". Or you write the equation with the sum and in the accumulations use one of "min", "max", "average". But the first option needs a little less computation
Hello gschaider, Thank you very much for the reply

The equation is writing results perfectly.

But I dont understand the logic behind using summation in the numerator for calculating max, min, average and not using summation for calculating sum (accumulation).

the equation calculates mass average weighted kinetic energy for each cell in the domain for each timestep and calculates sum. where is the difference coming by introducing the summation in the numerator ?

There is something that I am missing out in understanding here.

Thanks in advance    March 16, 2021, 15:41 #9 New Member   Join Date: Oct 2019 Posts: 13 Rep Power: 5 Hello Foamers, I'm new in OF, I'm studying compressible flows and for post-processing, I just want to have confirmation. I'm not sure about syntax, but I would like to calculate the mass-weighted average of one variable, defines as at my "r1-outblock-outflow" (patch name)' so is it correct to write in my controlDict (OpenFOAM v2006) Code:  weightAvgOut { #includeEtc "caseDicts/postProcessing/surfaceFieldValue/surfaceRegion.cfg" regionType patch; name "r1-outblock-outflow"; operation weightedAverage; weightField phi; fields (p T Ma total(p)); writeInterval 5; log true; } Do you think this is right? Also, does anyone know if OF can provide the total temperature?  Tags mass weighted average, swak4foam, swakexpression Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded 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 Off Pingbacks are On Refbacks are On Forum Rules Similar Threads Thread Thread Starter Forum Replies Last Post SAM Main CFD Forum 31 April 30, 2018 05:12 giogio FLUENT 9 March 6, 2018 09:24 m&s FLUENT 0 April 6, 2010 12:52 Maryam FLUENT 0 November 12, 2008 08:06 Maryam CFX 0 November 12, 2008 08:03

All times are GMT -4. The time now is 08:52.