CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   How to calculate a zone Average (https://www.cfd-online.com/Forums/openfoam-post-processing/80362-how-calculate-zone-average.html)

gschaider November 14, 2012 17:41

Quote:

Originally Posted by aerogt3 (Post 389481)
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

GRAUPS December 6, 2012 13:13

Quote:

Originally Posted by aerogt3 (Post 389481)

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.

gschaider December 6, 2012 13:35

Quote:

Originally Posted by GRAUPS (Post 396159)
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

aerogt3 December 12, 2012 12:00

Quote:

Originally Posted by GRAUPS (Post 396159)
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?

gschaider December 12, 2012 12:56

Quote:

Originally Posted by aerogt3 (Post 397189)
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)

aerogt3 December 12, 2012 15:11

Quote:

Originally Posted by gschaider (Post 397204)
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!

gschaider December 12, 2012 16:17

Quote:

Originally Posted by aerogt3 (Post 397221)
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

aerogt3 December 13, 2012 10:58

Quote:

Originally Posted by gschaider (Post 397242)
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 :D

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;
    }
);


gschaider December 13, 2012 11:55

Quote:

Originally Posted by aerogt3 (Post 397370)
True, having had to find and turn on the flag I am now very aware that its an approximation :D

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?

aerogt3 December 13, 2012 12:09

Quote:

Originally Posted by gschaider (Post 397384)
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


gschaider December 13, 2012 16:29

Quote:

Originally Posted by aerogt3 (Post 397387)
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

Elham July 2, 2015 23:32

swakExpression error
 
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

silvan July 13, 2015 03:02

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"
);



Tellur October 14, 2015 22:11

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 October 16, 2015 00:23

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 October 20, 2015 23:55

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.

zhxter October 27, 2015 09:30

How to calculate the sum of energy for a given zone?
 
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?


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