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

[swak4Foam] Averaging along an axis.. swak4foam?

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 2, 2014, 14:02
Question Averaging along an axis.. swak4foam?
  #1
Senior Member
 
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14
tiam is on a distinguished road
Dear Foamers!

I am performing some channel flow LES. I would like to look at different statistics and how they converge, yet I have to be reasonable about the size of the data my simulation produces.

To stick to a simple example, let us assume that I am interested in seeing how the mean velocity profile is developing. Ideally, I would want to have OpenFOAM average the x-velocity component along z and x and produce a single profile along y. Then I can afford to save this profile at each iteration (or every 100, doesn't matter) and see how it is developing. Similar reasoning can be applied for second order moments, skewness etc.

So the question is whether I can do this averaging without starting to mess with pimpleFoam. Function objects enriched with swak4foam come to mind, so I started looking at that. As far as I see there is no averaging along an axis/direction implemented, probably because this is meangless in a lot of cases.

Any ideas? This is, after all, a pretty comon task for those who deal with turbulence investigation.
tiam is offline   Reply With Quote

Old   October 2, 2014, 15:44
Default
  #2
Senior Member
 
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22
cnsidero is on a distinguished road
There isn't an existing function object to do this but there is a utility called postChannel found in $WM_PROJECT_DIR/applications/utilities/postProcessing/miscellaneous . You could use this utility as a basis to incorporate this functionality into a function object.
cnsidero is offline   Reply With Quote

Old   October 2, 2014, 19:14
Default
  #3
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 tiam View Post
Dear Foamers!

I am performing some channel flow LES. I would like to look at different statistics and how they converge, yet I have to be reasonable about the size of the data my simulation produces.

To stick to a simple example, let us assume that I am interested in seeing how the mean velocity profile is developing. Ideally, I would want to have OpenFOAM average the x-velocity component along z and x and produce a single profile along y. Then I can afford to save this profile at each iteration (or every 100, doesn't matter) and see how it is developing. Similar reasoning can be applied for second order moments, skewness etc.

So the question is whether I can do this averaging without starting to mess with pimpleFoam. Function objects enriched with swak4foam come to mind, so I started looking at that. As far as I see there is no averaging along an axis/direction implemented, probably because this is meangless in a lot of cases.

Any ideas? This is, after all, a pretty comon task for those who deal with turbulence investigation.
Not 100% sure what you mean with "average the x-velocity component along z and x" but if you mean "Average of all cells with approximately the same y-value" then this could be what you need:
Code:
averageUxDistributionY {
        type swakExpressionAverageDistribution;
        verbose true;
        outputControlMode outputTime;
        valueType internalField;
        expression "U.x";
        weight "vol()";
        mask "1";
        abscissa "pos().y";
        binNumber 50;
        valueIfZero -100;
    }
Bana 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   October 3, 2014, 05:41
Default
  #4
Senior Member
 
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14
tiam is on a distinguished road
Thank you so much Bernhard, will look into this!

To clarify further what I am trying too achieve.. The postChannel utility implements a part of the functionality I want in the specific case of channel flow. It "collapses" some results, like mean velocity, into a single profile by averaging across the statistically homogeneous directions.

The utility works only on written data, but I would like to do similar things at run-time.

Again, in other words, I want to be able, with some flexibility, to perform averaging of statistical moments of different order along a chosen direction, which is statistically homogeneous, at run-time .
tiam is offline   Reply With Quote

Old   October 3, 2014, 08:49
Default
  #5
Senior Member
 
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14
tiam is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Not 100% sure what you mean with "average the x-velocity component along z and x" but if you mean "Average of all cells with approximately the same y-value" then this could be what you need:
Code:
averageUxDistributionY {
        type swakExpressionAverageDistribution;
        verbose true;
        outputControlMode outputTime;
        valueType internalField;
        expression "U.x";
        weight "vol()";
        mask "1";
        abscissa "pos().y";
        binNumber 50;
        valueIfZero -100;
    }
Let's see if I understood this correctly. What this will do is
1) Calculate the average of U.x for all cells with equal y
2) Place the computed average in one of the bins
2) Write out the distribution.

This is a nice thing on its own, but it seems like I completely loose all the information about which values of U.x correspond to which y. Can I somehow make it simply write out the computed averages along with the y-values instead/in addition to computing the distribution? I.e. a two-column list:
y.pos() <U.x>
manuc likes this.
tiam is offline   Reply With Quote

Old   October 3, 2014, 15:49
Default
  #6
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 tiam View Post
Let's see if I understood this correctly. What this will do is
1) Calculate the average of U.x for all cells with equal y
2) Place the computed average in one of the bins
2) Write out the distribution.
That is right. Except that the second step 2 is called step 3 (sorry. It is not good manners to make fun of typos.) and that it 1 and 2 (the real 2) are switched: first it checks into which bin the pos().y falls and adds the U.x to the average there.

Of course it is not really a distribution but "average U.x as a function of y"

Quote:
Originally Posted by tiam View Post
This is a nice thing on its own, but it seems like I completely loose all the information about which values of U.x correspond to which y. Can I somehow make it simply write out the computed averages along with the y-values instead/in addition to computing the distribution? I.e. a two-column list:
y.pos() <U.x>
Sorry. I'm a bit slow here: for a calculation with N cells you want a Nx2-table? How is that supposed to save time/space as opposed to writing the two fields?
__________________
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   October 7, 2014, 09:54
Default
  #7
Senior Member
 
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14
tiam is on a distinguished road
Quote:
Originally Posted by gschaider View Post
That is right. Except that the second step 2 is called step 3 (sorry. It is not good manners to make fun of typos.) and that it 1 and 2 (the real 2) are switched: first it checks into which bin the pos().y falls and adds the U.x to the average there.

Of course it is not really a distribution but "average U.x as a function of y"



Sorry. I'm a bit slow here: for a calculation with N cells you want a Nx2-table? How is that supposed to save time/space as opposed to writing the two fields?
Thank you for you help Bernhard!

It turned out I am the slow one . I thought the bins were velocity values, not y values. Anyhow, this does more or less do what I wanted it to.

I am wondering about some things however:
1) the "key" in the output, that corresponds to the bin obviously, but what exactly. I have a mesh where y is [0;2] and the last "key" I get is 2.00991, which is then out of bounds.

2) Can i hardcode the bins? So that I really get an average of every cell layer.

3) A bit of a side question, I would perhaps like to average not U, but the field UMean produced by fieldAverage. But swak function objects don't seem to see that field, is there a way to hook things together? I fought with it for quite a bit and even tried to create my own UMean with swak instead, using stored variables, but miserably failed TT.
Foam fan likes this.
tiam is offline   Reply With Quote

Old   October 7, 2014, 18:30
Default
  #8
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 tiam View Post
Thank you for you help Bernhard!

It turned out I am the slow one . I thought the bins were velocity values, not y values. Anyhow, this does more or less do what I wanted it to.
Admittedly: the name of the function object may be a bit misleading. It was chosen more or less for technical reasons. But to be honest: I couldn't think of a descriptive yet reasonably short name. I'm open to suggestions

Quote:
Originally Posted by tiam View Post
I am wondering about some things however:
1) the "key" in the output, that corresponds to the bin obviously, but what exactly. I have a mesh where y is [0;2] and the last "key" I get is 2.00991, which is then out of bounds.

2) Can i hardcode the bins? So that I really get an average of every cell layer.
The functionality is based on the Distribution-class which is part of OpenFOAM. That class is for efficiency-reasons in such a way that the bin boundaries are multiples of the bin-width. So the possibilities to influence these are limited

The out-of-bounds-behaviour I'd have to check

Quote:
Originally Posted by tiam View Post
3) A bit of a side question, I would perhaps like to average not U, but the field UMean produced by fieldAverage. But swak function objects don't seem to see that field, is there a way to hook things together? I fought with it for quite a bit and even tried to create my own UMean with swak instead, using stored variables, but miserably failed TT.
If the field is registered with the mesh then swak should be able to access it. Use the listRegisteredObjects-functionObject to check which fields are available. Maybe the problem is that UMean is only registered after the first time-step but the swak-FO wants it before that
__________________
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   March 23, 2018, 09:46
Default
  #9
New Member
 
Hungary (Ungarn)
Join Date: Sep 2017
Posts: 16
Rep Power: 9
miha23 is on a distinguished road
Dear Bernhard!

I'm using the swakExpressionAverageDistribution type function to get the average temperature along an axis. I works fine when I use it during run-time, writing it into controlDict, but I like to use it after the simulation is complete, as a post processing.
For this, I have created a file, called "postDict" in my case directory and called the funkyDoCalc like this : "funkyDoCalc -latestTime postDict".

My postDict file cointains the followings:

Function
{
type swakExpressionAverageDistribution;
libs (
"libOpenFOAM.so"
"libsimpleSwakFunctionObjects.so"
"libswakFunctionObjects.so"
"libgroovyBC.so"
);

writeStartTime no;
valueType internalField;
expression "T";
verbose true;
weight "vol()";
mask "1";
abscissa "pos().z";
dynamicExtremesAbscissa false;
minAbscissa 0;
maxAbscissa 150;
binNumber 75;
valueIfZero 0;
accumulations ( average );

}

But this turned out with an error messege which I can not solve:

--> FOAM FATAL ERROR:
The expected return type bool is different from the stored result type "scalar"



From function tmp<Field<Type> > ExpressionResult::getResult()
in file ../../Libraries/swak4FoamParsers/lnInclude/ExpressionResultI.H at line 250.

FOAM exiting

I would be thankful is you could take a look at that, and hint some crumbs about what this file should contain.

Thank you in advance,

Gábor
miha23 is offline   Reply With Quote

Old   March 26, 2018, 07:58
Default
  #10
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 miha23 View Post
Dear Bernhard!

I'm using the swakExpressionAverageDistribution type function to get the average temperature along an axis. I works fine when I use it during run-time, writing it into controlDict, but I like to use it after the simulation is complete, as a post processing.
For this, I have created a file, called "postDict" in my case directory and called the funkyDoCalc like this : "funkyDoCalc -latestTime postDict".

My postDict file cointains the followings:

Function
{
type swakExpressionAverageDistribution;
libs (
"libOpenFOAM.so"
"libsimpleSwakFunctionObjects.so"
"libswakFunctionObjects.so"
"libgroovyBC.so"
);

writeStartTime no;
valueType internalField;
expression "T";
verbose true;
weight "vol()";
mask "1";
abscissa "pos().z";
dynamicExtremesAbscissa false;
minAbscissa 0;
maxAbscissa 150;
binNumber 75;
valueIfZero 0;
accumulations ( average );

}

But this turned out with an error messege which I can not solve:

--> FOAM FATAL ERROR:
The expected return type bool is different from the stored result type "scalar"



From function tmp<Field<Type> > ExpressionResult::getResult()
in file ../../Libraries/swak4FoamParsers/lnInclude/ExpressionResultI.H at line 250.

FOAM exiting

I would be thankful is you could take a look at that, and hint some crumbs about what this file should contain.

Thank you in advance,

Gábor
Have you tried
Code:
mask "true";
swak4Foam does not do the C-style "everything except 0 is logically true" conversion
__________________
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   March 26, 2018, 08:22
Default
  #11
New Member
 
Hungary (Ungarn)
Join Date: Sep 2017
Posts: 16
Rep Power: 9
miha23 is on a distinguished road
I tried it with - mask "true" - , and it looks like it do something, but not the thing I wanted.
It gives back one single number, i.e. an average , for the whole domain, and not the list of values in the bins.
miha23 is offline   Reply With Quote

Old   March 26, 2018, 08:32
Default
  #12
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 miha23 View Post
I tried it with - mask "true" - , and it looks like it do something, but not the thing I wanted.
It gives back one single number, i.e. an average , for the whole domain, and not the list of values in the bins.
Doesn't even write something to postProcessing? I'll have to have a look
__________________
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   March 26, 2018, 08:43
Default
  #13
New Member
 
Hungary (Ungarn)
Join Date: Sep 2017
Posts: 16
Rep Power: 9
miha23 is on a distinguished road
I used funkyDoCalc -latestTime PostDict -writeCsv, so it created a text file which contains only the time value and one average value.
If I don't add -writeCsv at the end, then it does not creates anything, nor the postProcessing directory that it used to when it runs during simulation.
miha23 is offline   Reply With Quote

Old   December 28, 2018, 08:46
Default
  #14
Senior Member
 
Manu Chakkingal
Join Date: Feb 2016
Location: Delft, Netherlands
Posts: 129
Rep Power: 10
manuc is on a distinguished road
Hi
I also get an out of bound value for "key". Did you manage to find why it is?

Regards
Manu
__________________
Regards
Manu
manuc is offline   Reply With Quote

Old   August 3, 2019, 08:21
Default
  #15
New Member
 
George Sof
Join Date: Jun 2019
Posts: 13
Rep Power: 7
lastjedivol is on a distinguished road
Quote:
Originally Posted by gschaider View Post
That is right. Except that the second step 2 is called step 3 (sorry. It is not good manners to make fun of typos.) and that it 1 and 2 (the real 2) are switched: first it checks into which bin the pos().y falls and adds the U.x to the average there.

Of course it is not really a distribution but "average U.x as a function of y"



Sorry. I'm a bit slow here: for a calculation with N cells you want a Nx2-table? How is that supposed to save time/space as opposed to writing the two fields?

Hello Bernhard,



I am sorry to recover an old thread here, but is it possible to calculate the distribution of averaged U.x along y, with this tool?


Thank you
lastjedivol is offline   Reply With Quote

Old   August 4, 2019, 19:14
Default
  #16
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 lastjedivol View Post
Hello Bernhard,



I am sorry to recover an old thread here, but is it possible to calculate the distribution of averaged U.x along y, with this tool?


Thank you

I don't understand how that differs from what has been discussed in the example that was discussed
__________________
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   August 6, 2019, 05:25
Default
  #17
New Member
 
George Sof
Join Date: Jun 2019
Posts: 13
Rep Power: 7
lastjedivol is on a distinguished road
Quote:
Originally Posted by gschaider View Post
I don't understand how that differs from what has been discussed in the example that was discussed

To be more specific, I need to average spatially U.z over a homogeneous direction z of a pipe. Result of the averaging should be a surface field U.z(x,y). Is it possible?
lastjedivol is offline   Reply With Quote

Old   August 7, 2019, 04:27
Default
  #18
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 lastjedivol View Post
To be more specific, I need to average spatially U.z over a homogeneous direction z of a pipe. Result of the averaging should be a surface field U.z(x,y). Is it possible?

Unfortunately not. What swakExpressionAverageDistribution can do is U.z(x)
__________________
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   August 7, 2019, 04:51
Default
  #19
New Member
 
George Sof
Join Date: Jun 2019
Posts: 13
Rep Power: 7
lastjedivol is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Unfortunately not. What swakExpressionAverageDistribution can do is U.z(x)

Thank you very much for your response. Just one more question, is there to your knowledge any other swak - tool that i can use, in order to have the result described above?
lastjedivol is offline   Reply With Quote

Old   August 7, 2019, 05:17
Default
  #20
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 lastjedivol View Post
Thank you very much for your response. Just one more question, is there to your knowledge any other swak - tool that i can use, in order to have the result described above?
I'm afraid no. There are two ways that new stuff usually gets into swak4foam
  1. I need it for a customer project
  2. Somebody else contributes it
None of these has happened for this feature.
__________________
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

Reply

Tags
averaging, les, swak4foam


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
[swak4Foam] averaging in spanwise direction of a patch kenny13 OpenFOAM Community Contributions 1 October 3, 2017 11:07
[swak4Foam] problems with averaging a new field fgarita OpenFOAM Community Contributions 1 October 28, 2016 04:27
Starting field averaging using libFunctionObject after certain time eelcovv OpenFOAM Programming & Development 25 December 7, 2015 23:28
Axis treatment in axisymmetrical problem Jakob1 OpenFOAM Pre-Processing 2 August 25, 2014 04:09
[swak4Foam] fails in parallel with -otherTime? Phicau OpenFOAM Community Contributions 3 June 26, 2013 14:00


All times are GMT -4. The time now is 09:41.