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

[swak4Foam] Using fieldAverage together with swak4foam expressionField

Register Blogs Community New Posts Updated Threads Search

Like Tree18Likes

 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old   October 8, 2014, 14:38
Default Using fieldAverage together with swak4foam expressionField
  #1
Senior Member
 
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 118
Rep Power: 14
tiam is on a distinguished road
I have been messing with trying to use fieldAverage and swak generated expressionFields together, so I would like to share my experience and possibly get some tips about how to do this better. Maybe some of the stuff I'll write might seem trivial, but hey, is should save time for someone .

Let us amagine the following: we want to calculate the prime2Mean of U ourselves using an expressionField.
We will use UMean from fieldAverage, calculate "(UMean-U)^2" at every timestep as an expressionField and then use fieldAverage to find the mean of the expressionField.

Here are some points that I had to figure out along the way.

1) The order matters.
The order in which we declare objects in the controlDict matters, because all the fields/IOobjects that a functionObject uses have to be available at the time of the objects declaration. For this reason we will not be able to have only one fieldAverage, but will have to declare two separate ones.

2) expressionFields are evaluated only at write-time
Or at least that is the only way I can explain that my code didn't work , some comment from an experienced user is welcome here.. Can we enforce to update at every timestep in memory?
This will screw up the averaging of the expressionField. A work around that I used was to run manipulateField on all the relevant expressionFields. This seems to work, but bloats the code.

So for the xx component of the prime2Mean the following controlDict seems to work.
Code:
   //This will give UMean
   fieldAverage1
    {
        type            fieldAverage;
        functionObjectLibs ( "libfieldFunctionObjects.so" );
        enabled         true;
        outputControl   outputTime;
        resetOnRestart true;

        fields
        (
            U
            {
                mean        on;
                prime2Mean  on; //for testing
                base        time;
            }
        );
    }

   //This will calculate the X-component of the prime2Mean
   primeX
    {
		type expressionField;
		dimension [0 2 -2 0 0 0 0];
		fieldName "primeX";
		expression "sqr(UMean.x-U.x)";
		verbose true;
		autowrite true;
		outputControl outputTime;
    }

    //This will force the update
    updatePrimeX
    {
    	type manipulateField;
    	fieldName "primeX";
    	mask "true";
    	expression "sqr(UMean.x-U.x)";
    }

    //This will calculate the mean of primeX
    fieldAverage2
    {
        type            fieldAverage;
        functionObjectLibs ( "libfieldFunctionObjects.so" );
        enabled         true;
        outputControl   outputTime;
        resetOnRestart true;

        fields
        (
            primeX
            {
                mean        on;
                prime2Mean  off;
                base        time;
            }
        );
    }
If anyone is wondering why I am doing this, it is because I want to calculate higher order-statistics: skewness and flatness.
The whole thing is not extensively tested, so don't trust this code .
All tips and comments, especially about why this might fail are more than welcome!
tiam is offline   Reply With Quote

 

Tags
fieldaverage, functionobjects, 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] problems with averaging a new field fgarita OpenFOAM Community Contributions 1 October 28, 2016 03:27
[swak4Foam] expressionField + execFlowFunctionObjects + AMI pbachant OpenFOAM Community Contributions 0 July 16, 2015 01:09
[swak4Foam] Using swak4foam to implement a BC for heat convection with h(Tamb,Twall) zfaraday OpenFOAM Community Contributions 5 January 19, 2015 14:05
[swak4Foam] expressionField aylalisa OpenFOAM Community Contributions 1 October 28, 2014 17:42
[swak4Foam] fails in parallel with -otherTime? Phicau OpenFOAM Community Contributions 3 June 26, 2013 13:00


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