CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (http://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Mass Weighted Average (http://www.cfd-online.com/Forums/openfoam-post-processing/110458-mass-weighted-average.html)

 GRAUPS December 11, 2012 14:40

Mass Weighted Average

2 Attachment(s)
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...

Attachment 17559

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!

 GRAUPS December 11, 2012 18:32

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?

 gschaider December 12, 2012 19:48

Quote:
 Originally Posted by GRAUPS (Post 397036) 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)

 GRAUPS December 12, 2012 20:34

Quote:
 Originally Posted by gschaider (Post 397264) 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 (Post 397264) 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.

 Alex2 November 26, 2015 05:51

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?