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

How to calculate a zone Average

Register Blogs Community New Posts Updated Threads Search

Like Tree13Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 14, 2012, 18:41
Default
  #21
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
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: 40
Rep Power: 14
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: 4,225
Rep Power: 51
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: 90
Rep Power: 17
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: 4,225
Rep Power: 51
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: 90
Rep Power: 17
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: 4,225
Rep Power: 51
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: 90
Rep Power: 17
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: 4,225
Rep Power: 51
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: 90
Rep Power: 17
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: 4,225
Rep Power: 51
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 3, 2015, 00:32
Default swakExpression error
  #32
Senior Member
 
Elham
Join Date: Oct 2009
Posts: 184
Rep Power: 17
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, 04:02
Default
  #33
New Member
 
Silvan
Join Date: Jun 2014
Posts: 12
Rep Power: 12
silvan is on a distinguished road
Did you run updateSharedLibraries?

Did you include the swak libraries in the controlDict?

please see http://www.cfd-online.com/Forums/ope...tml#post552461

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

Old   October 14, 2015, 23:11
Default
  #34
New Member
 
Dasein
Join Date: Mar 2015
Posts: 21
Rep Power: 11
Tellur is on a distinguished road
Hi Everyone,

I am trying to calculate area weighted average velocities on a certain level above the floor height. To do that I use the following topoSet dictionary:

Quote:
actions
(
// Surface_1
{
name Surface_1;
type faceSet;
action new;
source surfaceToCell;
sourceInfo
{
file "Surface1.stl";
outsidePoints ((15 15 15));
includeCut true;
includeInside false;
includeOutside false;
nearDistance -1;
curvature 0.9;


}
}

{
name Surface_1;
type faceZoneSet;
action new;
source setToFaceZone;
sourceInfo
{
faceSet Surface_1;
}
}
);
After I've created my faceZone I use swak4foam to calculate the weighted average velocity, following the recommendations above:

Quote:
weightedAverageVel
{
type swakExpression;
valueType faceZone;
zoneName Surface_1; // or whatever is your zoneName
accumulations (
min
//average
);
autoInterpolate true;
expression "sum(mag(U)*area())/sum(area())";
verbose true;
outputInterval 1;
outputControlMode timeStep;


}
);
The whole thing seems to work but I'm not sure if I can trust my results, velocities seem quite low. I can't help feeling that I've made a mistake somewhere in the math.

If anyone has used swak4foam for this before I'd be obliged if you pitched in.

Thank you in advance!

Kind regards,
Theodore.
Tellur is offline   Reply With Quote

Old   October 16, 2015, 01:23
Default
  #35
New Member
 
Dasein
Join Date: Mar 2015
Posts: 21
Rep Power: 11
Tellur is on a distinguished road
And one more question if I may. I looked around for this but couldn't find an answer. It is related to my very bad knowledge of C++ and coding in general but should be a novice question for the experienced people on this board.

I have a big number of faceZones I want to calculate parameters for.

Is there a way to list all the faceZones in one zoneName parameter? I tried the typical C++ list but wouldn't work. If this is possible, would it still create different post processing text files (I would prefer this)?

Furthermore, is there a way to list a number of expressions in one object? I would like to get the results of multiple parameters in one file instead of separate.

Thank you so much in advance and excuse my novice questions.

Kind regards,
Theodore.
Tellur is offline   Reply With Quote

Old   October 21, 2015, 00:55
Default
  #36
New Member
 
Dasein
Join Date: Mar 2015
Posts: 21
Rep Power: 11
Tellur is on a distinguished road
Hello again, I seem to have another issue although this is not related to swak4foam.

I am using the topoSet to acquire the faceZoneSets in which I want to use swak4foam to calculate my average velocity. I have one surface stl for each of the faceZones (imagine this is a plane 1.2m above the floor of my building in the model).

However, when I use foamToVTK to preview these zones, after they have been generated, I get a collection of cells that is ALL over the place and really nowhere near to where the surface is. The options I used are below:

Quote:
{
name T1A_Bathroom1;
type faceSet;
action new;
source surfaceToCell;
sourceInfo
{
file "CalculationPlanes/Tower_1/UnitA/Bathroom1.stl";
outsidePoints ((50 50 200));
includeCut true;
includeInside false;
includeOutside false;
nearDistance -1;
curvature 0.9;


}
}

{
name T1A_Bathroom1;
type faceZoneSet;
action new;
source setToFaceZone;
sourceInfo
{
faceSet T1A_Bathroom1;
}
}
I wonder if I am doing something wrong. I tried to go over relevant threads and dictionairies but I'm having trouble understanding the impact of the options like outside points (especially since this is a planar surface and curvature.

I should also stress that I already used includeInside true without much success. Is there something terribly wrong in my code or is it just a visualization problem?

I'd appreciate any wisdom

Kind regards,
Theodore.
Tellur is offline   Reply With Quote

Old   October 27, 2015, 10:30
Default How to calculate the sum of energy for a given zone?
  #37
Member
 
Xiantao Zhang
Join Date: Nov 2014
Posts: 31
Rep Power: 12
zhxter is on a distinguished road
I use openfoam to simulate waves.

For example, the length of numerical wave tank is 20m, and from 15 to 20m is the damping zone. I want to calculate the whole energy in the zone from 0 to 15m.

Does anyone know how to do this?
zhxter is offline   Reply With Quote

Reply

Tags
openfoam 1.7.1, patchaverage, porous modellling, sampledict


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 Off
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 02:08
calculate the average velocity of particles robert FLUENT 0 August 1, 2008 10:44
Error to re-open fluent case file J.Gimbun FLUENT 0 April 27, 2006 09:42
Sliding mesh error Karl Kevala FLUENT 4 February 21, 2001 16:52


All times are GMT -4. The time now is 15:50.