CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Post-Processing

How to calculate a zone Average

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

Like Tree6Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   November 14, 2012, 18:41
Default
  #21
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by aerogt3 View Post
I just download swak4foam, and right now I just want to get the average pressure and total mass flow rate at my velocity inlet, to compare with hand calcs and make sure I am using it correctly. To sum these, I am doing the following:

Code:
            mdot_inlet
            {
              type swakExpression;                                    
              valueType patch                                    
              patchName inlet      
              expression "phi*flip()";                                 
              accumulations
                (
                  sum                                                            
                );
              verbose true;
            }

            p_inlet
            {
              type swakExpression;                                    
              valueType patch;                                    
              patchName inlet      
              expression "p";                                 
              accumulations
                (
                  average                                                            
                );
              verbose true;
            }
I get the following error for averaging p, and I get the same error when performing the operation on faceZones.

[44] [24]
--> FOAM FATAL ERROR:
[42] --> FOAM FATAL ERROR: Could not find a field name "p" of type scalar (neither surfaceScalarField nor volScalarField) Autointerpolate: 0
[16]

And this one for mass flow rate. When I do mass flow rate calcs on faceZones, it works.

[42]
[42] --> FOAM FATAL ERROR:
[42] Parser Error at "1.5-8" :"field flip not existing or of wrong type"
"phi*flip()"
" ^^^^ "


Any ideas? As best I can tell, I am following your syntax correctly, no?
Average pressure should work ... if there is a field p. Which solver are you using

About flip(): you only need that on faceSets and faceZones. On patches the orientation of the faces is defined (all looking "in") and therefor flip() is not implemented for patches
__________________
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
gschaider is offline   Reply With Quote

Old   December 6, 2012, 14:13
Default
  #22
Member
 
Brock Lee
Join Date: Sep 2012
Location: Midwest
Posts: 36
Rep Power: 4
GRAUPS is on a distinguished road
Quote:
Originally Posted by aerogt3 View Post

Code:
            mdot_inlet
            {
              type swakExpression;                                    
              valueType patch                                    
              patchName inlet      
              expression "phi*flip()";                                 
              accumulations
                (
                  sum                                                            
                );
              verbose true;
            }

            p_inlet
            {
              type swakExpression;                                    
              valueType patch;                                    
              patchName inlet      
              expression "p";                                 
              accumulations
                (
                  average                                                            
                );
              verbose true;
            }
Looks like he is missing some semicolons after the patch name? Try that, i think it might solve your problem aerogt3.
GRAUPS is offline   Reply With Quote

Old   December 6, 2012, 14:35
Default
  #23
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by GRAUPS View Post
Looks like he is missing some semicolons after the patch name? Try that, i think it might solve your problem aerogt3.
Right. I never look for the obvious. Nevertheless: it is strange that it "found" the expression that way
__________________
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
gschaider is offline   Reply With Quote

Old   December 12, 2012, 13:00
Default
  #24
Member
 
Join Date: Mar 2009
Posts: 72
Rep Power: 8
aerogt3 is on a distinguished road
Quote:
Originally Posted by GRAUPS View Post
Looks like he is missing some semicolons after the patch name? Try that, i think it might solve your problem aerogt3.
Thanks for the reply! I have given that a try, and for a patch, it works correctly. I can successfully monitor patch average pressure, thanks!

On a faceZone however, I am not able to do it. I get the error:

Code:
Could not find a field name "p" of type scalar (neither surfaceScalarField nor volScalarField) Autointerpolate: 0
I think this is because p is simply not calculated on faceZones, and only in cells and on walls. Is this correct, or am I using the tool incorrectly?
aerogt3 is offline   Reply With Quote

Old   December 12, 2012, 13:56
Default
  #25
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by aerogt3 View Post
Thanks for the reply! I have given that a try, and for a patch, it works correctly. I can successfully monitor patch average pressure, thanks!

On a faceZone however, I am not able to do it. I get the error:

Code:
Could not find a field name "p" of type scalar (neither surfaceScalarField nor volScalarField) Autointerpolate: 0
I think this is because p is simply not calculated on faceZones, and only in cells and on walls. Is this correct, or am I using the tool incorrectly?
Yep. But if you set autointerpolate (not sure about the capitalization. Look at the examples) to true then swak interpolates it to the faces in the zone (the error message is not correct "nor volScalarField" but at least it tells that autoInterpolate is not set)
__________________
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
gschaider is offline   Reply With Quote

Old   December 12, 2012, 16:11
Default
  #26
Member
 
Join Date: Mar 2009
Posts: 72
Rep Power: 8
aerogt3 is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Yep. But if you set autointerpolate (not sure about the capitalization. Look at the examples) to true then swak interpolates it to the faces in the zone (the error message is not correct "nor volScalarField" but at least it tells that autoInterpolate is not set)
Brilliant! What a clever option, thank you so much!
aerogt3 is offline   Reply With Quote

Old   December 12, 2012, 17:17
Default
  #27
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by aerogt3 View Post
Brilliant! What a clever option, thank you so much!
Well. Without it computations on faceZones/Sets wouldn't make much sense, would they It is not set by default so that users at least in theory acknowledge the fact that this is not the "real" value but only an approximation
__________________
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
gschaider is offline   Reply With Quote

Old   December 13, 2012, 11:58
Default
  #28
Member
 
Join Date: Mar 2009
Posts: 72
Rep Power: 8
aerogt3 is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Well. Without it computations on faceZones/Sets wouldn't make much sense, would they It is not set by default so that users at least in theory acknowledge the fact that this is not the "real" value but only an approximation
True, having had to find and turn on the flag I am now very aware that its an approximation

I think it's relevant to this thread, but is it possible to calculate the integral of a scalar field's gradient over a cellZone? I have tried below, but it's not working. Perhaps a matter of syntax, or maybe am I attempting something that's not possible?


Code:
functions
(
   grad_integral
    {
        type swakExpression;
        valueType cellZone;
        zoneName fluid_2;
        accumulations (
            sum
        );
        expression "grad(p)*vol()";
        verbose true;
    }
);
aerogt3 is offline   Reply With Quote

Old   December 13, 2012, 12:55
Default
  #29
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by aerogt3 View Post
True, having had to find and turn on the flag I am now very aware that its an approximation

I think it's relevant to this thread, but is it possible to calculate the integral of a scalar field's gradient over a cellZone? I have tried below, but it's not working. Perhaps a matter of syntax, or maybe am I attempting something that's not possible?


Code:
functions
(
   grad_integral
    {
        type swakExpression;
        valueType cellZone;
        zoneName fluid_2;
        accumulations (
            sum
        );
        expression "grad(p)*vol()";
        verbose true;
    }
);
That should be possible (haven't tried it but it looks OK, assuming there is such a zone). Could you be more specific about the "not working"-part?
__________________
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
gschaider is offline   Reply With Quote

Old   December 13, 2012, 13:09
Default
  #30
Member
 
Join Date: Mar 2009
Posts: 72
Rep Power: 8
aerogt3 is on a distinguished road
Quote:
Originally Posted by gschaider View Post
That should be possible (haven't tried it but it looks OK, assuming there is such a zone). Could you be more specific about the "not working"-part?
Certainly! The zone definitely exists, so here is the error output. It looks to me that I am just not writing grad correctly, so wrong syntax?

Code:
Expression grad_integral :

--> FOAM FATAL ERROR:
 Parser Error at "1.1-4" :"field grad not existing or of wrong type"
"grad(p)*vol()"
" ^^^^        "

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 802.

FOAM exiting
aerogt3 is offline   Reply With Quote

Old   December 13, 2012, 17:29
Default
  #31
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by aerogt3 View Post
Certainly! The zone definitely exists, so here is the error output. It looks to me that I am just not writing grad correctly, so wrong syntax?

Code:
Expression grad_integral :

--> FOAM FATAL ERROR:
 Parser Error at "1.1-4" :"field grad not existing or of wrong type"
"grad(p)*vol()"
" ^^^^        "

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 802.

FOAM exiting
Sorry. My bad. Didn't look too closely the first time: "grad(p)" does not work on sets and zones. The reason is that OF only implements the differential operators for whole fields. The options to get that behaviour would be:
a) reimplement major parts of OF to work on sets and zones. Too much work (unless somebody pays for it)
b) calculate a temporary field "grad(p)". Get the relevant values from it. Throw it away. Could be done but would have major performance implications "grad(p)+grad(p)" in a 100 cell cellZone of a million cell case would mean that the gradient is calculated twice for the whole mesh (and because of the transparent handling it is not obvious to the user why this is so slow). So: no

The proposed workaround is to use expressionField to generate a field gradP with the value "grad(p)" and calc "gradP*vol()" on the zone. gradP is still calculated on the whole mesh, but the user is aware of it and he can even reuse the field in other calculations
yanxiang likes this.
__________________
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
gschaider is offline   Reply With Quote

Old   July 2, 2015, 23:32
Default swakExpression error
  #32
New Member
 
Elham
Join Date: Oct 2009
Posts: 9
Rep Power: 7
Elham is on a distinguished road
Hi,


I am a new OpenFoam user. I have modeled a single droplet falling in air and I want to calculate its velocity. So I used the following expression at the end of controlDict:


functions
{
downAverage
{
type swakExpression;
valueType internalField;
variables (
"downDirection=vector(0,-1,0);"
"thres=0.5;"
"liquidVol=sum(alpha.water>thres ? vol() : 0);"
"downVel=alpha.water>thres ? (U & downDirection) : 0;"
);
expression "downVel*vol()/liquidVol";
accumulations (
sum
);
verbose true;
}
}


But the following error appeared:


--> FOAM FATAL ERROR:
Unknown function type swakExpression

Valid functions are :

4
(
patchProbes
probes
sets
surfaces
)



From function functionObject::New(const word& name, const Time&, const dictionary&)
in file db/functionObjects/functionObject/functionObject.C at line 92.

FOAM exiting



I will really appreciate if you could tell me your idea to fix it.


Regards,
Elham
Elham is offline   Reply With Quote

Old   July 13, 2015, 03:02
Default
  #33
New Member
 
Silvan
Join Date: Jun 2014
Posts: 8
Rep Power: 3
silvan is on a distinguished road
Did you run updateSharedLibraries?

Did you include the swak libraries in the controlDict?

please see outputTime in Swak function

Quote:
Quick answer: Edit the "system/controlDict" and add the library "libsimpleFunctionObjects.so" in "libs" before "libsimpleSwakFunctionObjects.so", e.g.:

Code:
libs
(
"libsimpleFunctionObjects.so"
"libsimpleSwakFunctionObjects.so"
);
silvan is offline   Reply With Quote

Reply

Tags
openfoam 1.7.1, patchaverage, porous modellling, sampledict

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate a time average spwater OpenFOAM 2 February 24, 2010 09:04
Problem in IMPORT of ICEM input file in FLUENT csvirume FLUENT 2 September 9, 2009 01:08
calculate the average velocity of particles robert FLUENT 0 August 1, 2008 09:44
Error to re-open fluent case file J.Gimbun FLUENT 0 April 27, 2006 08:42
Sliding mesh error Karl Kevala FLUENT 4 February 21, 2001 16:52


All times are GMT -4. The time now is 10:33.