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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 8, 2014, 15:38
Default Using fieldAverage together with swak4foam expressionField
  #1
Senior Member
 
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
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

Old   October 8, 2014, 19:15
Default
  #2
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
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.
That's right

Quote:
Originally Posted by tiam View Post
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.
This is not right. Or: it is only right in your example because you set "outputControl outputTime;"

Quote:
Originally Posted by tiam View Post
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!
The primeX you calculate is IMHO not the real second moment in time because in "sqr(UMean.x-U.x)" UMean.x is different each time but you should use the final UMean.x for all time-steps (which of course is not possible without storing them). BUT: averaging "UMean.x" and "sqr(UMean.x)"and then using "variance is the mean of the square minus the square of the mean" should give you the correct value .... in my opinion
tiam and Uyan like 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 9, 2014, 06:15
Default
  #3
Senior Member
 
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14
tiam is on a distinguished road
Thank you for the reply Bernhard!

Quote:
Originally Posted by gschaider View Post
This is not right. Or: it is only right in your example because you set "outputControl outputTime;"
Indeed. I was confused by the name, I thought this controls when the fields get written, not calculated. Changing to timeStep solved the issue!

Quote:
Originally Posted by gschaider View Post
The primeX you calculate is IMHO not the real second moment in time because in "sqr(UMean.x-U.x)" UMean.x is different each time but you should use the final UMean.x for all time-steps (which of course is not possible without storing them). BUT: averaging "UMean.x" and "sqr(UMean.x)"and then using "variance is the mean of the square minus the square of the mean" should give you the correct value .... in my opinion
You are correct. As a matter of fact, the fieldAverage object itself uses the technique you propose. If one calculates the way I did one will produce contaminating data until UMean stabilizes. One will in the end converge to the real result, but it will take time to "average out" the contaminated data.

I implemented what you suggested and get the exact same results as fieldAverage.
Here is the new code.

Code:
   sqrUx 
    {
		type expressionField;
		dimension [0 2 -2 0 0 0 0];
		fieldName "sqrUx";
		expression "sqr(U.x)";
		verbose true;
		autowrite false;
		outputControl timeStep; 
    }

    fieldAverage1
    {
        type            fieldAverage;
        functionObjectLibs ( "libfieldFunctionObjects.so" );
        enabled         true;
        outputControl   outputTime;
        resetOnRestart true;

        fields
        (
            U
            {
                mean        on;
                prime2Mean  on;
                base        time;
            }

            sqrUx
            {
            	mean on;
            	prime2Mean off;
            	base time;
            }


        );
    }

    primeX2
    {
		type expressionField;
		dimension [0 2 -2 0 0 0 0];
		fieldName "primeX2";
		expression "sqrUxMean - sqr(UMean.x)";
		verbose true;
		autowrite true;
		outputControl timeStep; 
    }
Uyan, HuZexi and kostnermo like this.
tiam is offline   Reply With Quote

Old   January 13, 2015, 22:38
Default Error output > UMean not existing or of wrong type.
  #4
Member
 
Join Date: Feb 2014
Posts: 63
Rep Power: 12
Uyan is on a distinguished road
Hi,
I am using the method suggested above to find turbulent kinetic energy of an LES. It is very similar (0.5*magSqr(U-UMean)).
But it seems there is no object UMean before it is subjected to the expression step.

However whenever i use this method it always outputs an error saying
Code:
field UMean not existing or of wrong type"
"0.5*magSqr(UMean-U)"
           ^^^^^
Code:
   kturb
    {
		type expressionField;
		dimension [0 2 -2 0 0 0 0];
		fieldName "kturb";
		expression "0.5*magSqr(UMean-U)";
		verbose true;
		autowrite true;
		outputControl timeStep;
    }
UMean is defined before declaring kturb in controlDict however i still get this error.

Any Ideas how to get around this problem??

Thank you.
Uyan is offline   Reply With Quote

Old   January 14, 2015, 06:53
Default
  #5
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 Uyan View Post
Hi,
I am using the method suggested above to find turbulent kinetic energy of an LES. It is very similar (0.5*magSqr(U-UMean)).
But it seems there is no object UMean before it is subjected to the expression step.

However whenever i use this method it always outputs an error saying
Code:
field UMean not existing or of wrong type"
"0.5*magSqr(UMean-U)"
           ^^^^^
Code:
   kturb
    {
		type expressionField;
		dimension [0 2 -2 0 0 0 0];
		fieldName "kturb";
		expression "0.5*magSqr(UMean-U)";
		verbose true;
		autowrite true;
		outputControl timeStep;
    }
UMean is defined before declaring kturb in controlDict however i still get this error.

Any Ideas how to get around this problem??

Thank you.
The problem is probably that the functionObjects are created/executed in the sequence in which they are specified. In the post you are referring to the sqrUx1 is BEFORE fieldAverage1. That means at the time of its creation there is not UMean and the failure is perfectly understandable. Try moving sqrUx1 AFTER the averaging (you'll want that anyway as otherwise you won't get the most recent value of UMean but the one from the last time-step)
__________________
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   January 14, 2015, 10:42
Default UMean Function object not existing before an expressionField
  #6
Member
 
Join Date: Feb 2014
Posts: 63
Rep Power: 12
Uyan is on a distinguished road
Hi Bernhard,
Yes as you said two function objects should be in correct order.
So I moved UMean function object above the expressionField. Still i get the same error saying UMean is not existing.

Code:
//Function Object 1
    fieldAverage1
    {
        type            fieldAverage;
        functionObjectLibs ( "libfieldFunctionObjects.so" );
        enabled         true;
        outputControl   timeStep;
        outputInterval  100;
        resetOnRestart  false;
        fields
        (
            U
            {
                mean        on;
                prime2Mean  on;
                base        time;
            }
        );
    }

//Function Object 2
    kturb
    {
		type expressionField;
		dimension [0 2 -2 0 0 0 0];
		fieldName "kturb";
		expression "0.5*magSqr(UMean-U)";
		verbose true;
		autowrite true;
		outputControl timeStep; 
                outputInterval 1;     
    }
I still get the error

Code:
"field UMean not existing or of wrong type"
"0.5*magSqr(UMean-U)"
             ^^^^^

So I thought about possible reasons,

I am not starting simulation from time 0, and there is a UMean field in the latestTime directory to read and resetOnRestart is also false.

I changed the outputInterval for both function objects to 1, but still not solved.

Any Help would be greatly appreciated.
Uyan is offline   Reply With Quote

Old   January 14, 2015, 14:17
Default
  #7
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 Uyan View Post
Hi Bernhard,
Yes as you said two function objects should be in correct order.
So I moved UMean function object above the expressionField. Still i get the same error saying UMean is not existing.

Code:
//Function Object 1
    fieldAverage1
    {
        type            fieldAverage;
        functionObjectLibs ( "libfieldFunctionObjects.so" );
        enabled         true;
        outputControl   timeStep;
        outputInterval  100;
        resetOnRestart  false;
        fields
        (
            U
            {
                mean        on;
                prime2Mean  on;
                base        time;
            }
        );
    }

//Function Object 2
    kturb
    {
		type expressionField;
		dimension [0 2 -2 0 0 0 0];
		fieldName "kturb";
		expression "0.5*magSqr(UMean-U)";
		verbose true;
		autowrite true;
		outputControl timeStep; 
                outputInterval 1;     
    }
I still get the error

Code:
"field UMean not existing or of wrong type"
"0.5*magSqr(UMean-U)"
             ^^^^^

So I thought about possible reasons,

I am not starting simulation from time 0, and there is a UMean field in the latestTime directory to read and resetOnRestart is also false.

I changed the outputInterval for both function objects to 1, but still not solved.

Any Help would be greatly appreciated.
Currently can't test it myself. A few remarks:

a) expressionField only considers fields that are in memory and ignores the one on the disk (everything else would be a performance-desaster). So field average did not load it. To check which fields are loaded you can use the listRegisteredObjects functionObject

b) when does your error occur. During construction (before the first time-step) or after the first time-step?

c) try disabling kturb altogether and using listRegisteredObjects investigate when UMean appears in memory
__________________
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   January 14, 2015, 22:31
Default UMean is not under listRegisteredObjects
  #8
Member
 
Join Date: Feb 2014
Posts: 63
Rep Power: 12
Uyan is on a distinguished road
Hi Bernhard,

I checked as you said on listRegisteredObjects, however UMean is not shown as a listedObject when i placed listField after FieldAveraging object.

Code:
  LESProperties       dictionary No
                    U   volVectorField Yes
                UMean         IOobject No
          UPrime2Mean         IOobject No
                  U_0         IOobject Yes
However UMean answer seems to be same as pitzDaily LES tutorial.

So I want to ask, does UMean object is destroyed after its fieldAverage function execution?
Uyan is offline   Reply With Quote

Old   January 15, 2015, 09:09
Default
  #9
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 Uyan View Post
Hi Bernhard,

I checked as you said on listRegisteredObjects, however UMean is not shown as a listedObject when i placed listField after FieldAveraging object.

Code:
  LESProperties       dictionary No
                    U   volVectorField Yes
                UMean         IOobject No
          UPrime2Mean         IOobject No
                  U_0         IOobject Yes
However UMean answer seems to be same as pitzDaily LES tutorial.

So I want to ask, does UMean object is destroyed after its fieldAverage function execution?
I don't quite understand: your output is from _before_ fieldAverage and after fieldAverage you only got U and U_0? In that case swak can't find it (because it has to look it up in the registry). It is possible that the field still exists in memory but is not properly registered (that can happen if another field with the same name is registered: it kicks out the original field. Then the new field is destroyed and deregisters)
__________________
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   January 15, 2015, 13:59
Default
  #10
Member
 
Join Date: Feb 2014
Posts: 63
Rep Power: 12
Uyan is on a distinguished road
Yes UMean is not in the ObjectRegistry both before and after fieldAverage function.

Does it mean I can't use the expressionField function object as a runtime-postProcessing step to calculate turbulent kinetic energy using the expression tk = 0.5*magSqr(U-UMean) ?
Uyan is offline   Reply With Quote

Old   April 28, 2015, 05:01
Default
  #11
Senior Member
 
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 314
Rep Power: 15
agustinvo is on a distinguished road
Hello,

finally did you get a solution for your problem? I am dealing with something similar, and I get the same kind of problem. These are my functions:

Code:
functions
(
    fieldAverage1
    {
        type fieldAverage;
        functionObjectLibs ("libfieldFunctionObjects.so");
        resetOnRestart true;
        resetOnOutput true;
    outputControl outputTime;
    outputWrite   10;
        fields
        (
            U
            {
                mean            on;
                prime2Mean      on;
                base            time;
            }
            p
            {
                mean            on;
                prime2Mean      on;
                base            time;
            }
            T
            {
                mean            on;
                prime2Mean      on;
                base            time;
            }

        );
    }
  
    turbulentHeatFlux
    {
        type expressionField;
    functionObjectLibs ("libfieldFunctionObjects.so"
                "libsimpleSwakFunctionObjects.so"
                "libswakFunctionObjects.so"
                "libgroovyBC.so"
               );
        outputControl outputTime;
        outputInterval 10;
        fieldName ut;
        dimension [0 1 -1 2 0 0 0];
        expression "(U-UMean)*(T-TMean)";
        autowrite true;
    }
);
And this is the error I get:
Code:
fieldAverage fieldAverage1:
    Starting averaging at time 0

Creating expression field ut ...swak4Foam: Allocating new repository for sampledMeshes
swak4Foam: Allocating new repository for sampledGlobalVariables
--> FOAM Warning : 
    From function ConcretePluginFunction<DriverType>::exists
    in file lnInclude/ConcretePluginFunction.C at line 121
    Constructor table of plugin functions for FieldValueExpressionDriver is not initialized


--> FOAM FATAL ERROR: 
 Parser Error for driver FieldValueExpressionDriver at "1.4-8" :"field UMean not existing or of wrong type"
"(U-UMean)*(T-TMean)"
     ^^^^^
-----|    

Context of the error:


- Driver constructed from scratch
  Evaluating expression "(U-UMean)*(T-TMean)"


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

FOAM exiting
and I can't figure out where the problem is.
agustinvo is offline   Reply With Quote

Old   April 28, 2015, 08:28
Default
  #12
Member
 
Join Date: Feb 2014
Posts: 63
Rep Power: 12
Uyan is on a distinguished road
Hi agustinvo,

Although the original post of this thread says you could do something like that, from my experience it can't be done, because once the fieldAverage function object finishes its execution the object also disappear from the objectRegistry. May be there is a way to

IMO You have got two options with you to calculate the turbulent heat flux,

1) Read the Mean field into your solver by changing the createFields.H and make a new volVectorField for turbulent heat flux u'T'
u'T' = (UMean-U) * (TMean-T)

I am not sure how this first method would work i have not tried something like that.

2) Second method is to use the gradient diffusion hypothesis, because in-fact that is what is happened in the transport equation (T) to close the turbulent flux term.

u'T' = alpha * grad(T)
alpha = nut/Prandtl number

you can add this new field into your solver by modifying createFields.H easily.
since u'T' is an instantaneous value you would want to take the mean of u'T', you could do that using fieldAverage function object.
Uyan is offline   Reply With Quote

Old   April 28, 2015, 09:00
Default
  #13
Senior Member
 
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 314
Rep Power: 15
agustinvo is on a distinguished road
Thanks for your answer!

I would prefer to do the first idea you propose. I will perform some DNS and I was wondering about how to get the correlation uT (turbulent heat flux). I have checked and it seems that is not possible to use swak4Foam to do this. I think that in the way you say, i.e., creating the fields in my solver, it should work. It remains to see it it does not complain about the fact of UMean, TMean... is not in the registry.

Anyway, thank you! I will update the post if this idea works.
agustinvo is offline   Reply With Quote

Old   October 13, 2015, 05:44
Default
  #14
Senior Member
 
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14
tiam is on a distinguished road
Hello everyone!

So I came back to the simulations I have been doing before with the a swak expression using a Mean field. And indeed I run into the same problems as the users above.

A hasty inspection seems to indicate that the behavior changed with the OF version. I was originally running on 2.2.0 and swak could see the Mean fields.
Now I am running with 2.3.1 and the fields are not seen anymore.

Anyone found a workaround?

Best,
Tim
tiam is offline   Reply With Quote

Old   June 9, 2016, 23:05
Default
  #15
Member
 
Matt
Join Date: Oct 2012
Posts: 39
Rep Power: 14
fatirishman53 is on a distinguished road
Quote:
Originally Posted by tiam View Post
Hello everyone!

So I came back to the simulations I have been doing before with the a swak expression using a Mean field. And indeed I run into the same problems as the users above.

A hasty inspection seems to indicate that the behavior changed with the OF version. I was originally running on 2.2.0 and swak could see the Mean fields.
Now I am running with 2.3.1 and the fields are not seen anymore.

Anyone found a workaround?

Best,
Tim
I am running into this problem with OpenFOAM 2.3 as well. Any help would be MUCH appreciated!
fatirishman53 is offline   Reply With Quote

Old   September 1, 2016, 08:15
Default
  #16
Senior Member
 
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14
tiam is on a distinguished road
Dear all,

I've been doing some tests and it appears that the mean fields are not in the registry until the second time-step. So a solution is to wrap the function objects that depend on the mean fields in a executeIfObejctExists function obejct
Code:
    checkExistence
    {
        type executeIfObjectExists;
        objectName UMean;
        checkType false;
        objectShouldExist true;
        readDuringConstruction false;
        outputControl outputTime; 
        
        functions
        {
               ...stuff that depends on mean fields
        }
tiam is offline   Reply With Quote

Old   October 21, 2016, 06:38
Default Solution to the problem
  #17
New Member
 
Francesco Garita
Join Date: Oct 2016
Location: Italy
Posts: 8
Rep Power: 10
fgarita is on a distinguished road
I got the solution:

the problem is that the field you are creating invokes UMean/TMean before they are created in the same folder, and this happens independently of the position of your expression in the controlDict. This means that if you start your simulation at time 0 and you turn on both the fieldAverage and the swakExpression at time 0, then the fields UMean and pMean will be created only at the next time-step (because this is how the fieldAverage works in OpenFOAM) and hence your swakExpression at time 0 will not find the fields it is invoking.

Therefore, the solution is to do the following in the given order:
1) turn on the fieldAverage at a certain time;
2) let the simulation run for some time-step (at least a couple to be on the safe side);
3) modify your controlDict to include your swakExpression;

If everything went fine, you will find your new field together will all the others.

I had the same problem and I solved it this way. I do not think this depends on your OpenFOAM version.

Francesco
fgarita is offline   Reply With Quote

Old   October 21, 2016, 07: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 fgarita View Post
I got the solution:

the problem is that the field you are creating invokes UMean/TMean before they are created in the same folder, and this happens independently of the position of your expression in the controlDict. This means that if you start your simulation at time 0 and you turn on both the fieldAverage and the swakExpression at time 0, then the fields UMean and pMean will be created only at the next time-step (because this is how the fieldAverage works in OpenFOAM) and hence your swakExpression at time 0 will not find the fields it is invoking.

Therefore, the solution is to do the following in the given order:
1) turn on the fieldAverage at a certain time;
2) let the simulation run for some time-step (at least a couple to be on the safe side);
3) modify your controlDict to include your swakExpression;

If everything went fine, you will find your new field together will all the others.

I had the same problem and I solved it this way. I do not think this depends on your OpenFOAM version.

Francesco
There is a possibility in swak4Foam to only execute some function objects only if a certain field exists in memory
Code:
 
hasMean
{
     type executeIfObjectExists;
     objectName TMean; 
     checkType true;   
     objectType volScalarField;     
     objectShouldExist true; 
     readDuringConstruction false;           
     functions {                   
         doCalc  { 
             type swakExpression;
...
The functions-list is only executed if the field TMean exists in memory and is a volScalarField
sylvester, Luttappy and manuc like 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   December 14, 2016, 03:07
Default problem in using expressionField
  #19
Member
 
a
Join Date: Oct 2014
Posts: 49
Rep Power: 12
cfd@kgp is on a distinguished road
Dear Swak4Foam experts',

I tried using the following expressionField,

Code:
magSqrGradTinto2
{
type expressionField;
outputControl outputTime;
outputInterval 1;
fieldName magSqrGradTinto2;
expression "(magSqr(snGrad(T)))*2.0";
autowrite true;
}
}
and I get following error
Quote:
Creating expression field magSqrGradTby2 ...swak4Foam: Allocating new repository for sampledMeshes
swak4Foam: Allocating new repository for sampledGlobalVariables


--> FOAM FATAL ERROR:
Parser Error for driver FieldValueExpressionDriver at "1.21-23" :"syntax error, unexpected number"
"(magSqr(snGrad(T)))*2.0"
^^^
----------------------|

Context of the error:


- Driver constructed from scratch
Evaluating expression "(magSqr(snGrad(T)))*2.0"


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

FOAM exiting
if the multiplication of 2 is removed then OpenFoam do not show any errors.

seems strange to me, please help

Thanks and regards.
cfd@kgp is offline   Reply With Quote

Old   December 14, 2016, 04:07
Default Solution to your problem
  #20
New Member
 
Francesco Garita
Join Date: Oct 2016
Location: Italy
Posts: 8
Rep Power: 10
fgarita is on a distinguished road
Hi,

Try to write the following:

Code:
magSqrGradTinto2
 {  type expressionField;
 outputControl outputTime;
 outputInterval 1;
 fieldName magSqrGradTinto2;
 expression "(magSqr(snGrad(T))) + (magSqr(snGrad(T)))";
 autowrite true;
 }
This will solve the problem. I had the same problem some time ago, when trying to compute another quantity, and this was the only workaround I managed to find.

Good luck,
Francesco
cfd@kgp likes this.
fgarita is offline   Reply With Quote

Reply

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 04:27
[swak4Foam] expressionField + execFlowFunctionObjects + AMI pbachant OpenFOAM Community Contributions 0 July 16, 2015 02:09
[swak4Foam] Using swak4foam to implement a BC for heat convection with h(Tamb,Twall) zfaraday OpenFOAM Community Contributions 5 January 19, 2015 15:05
[swak4Foam] expressionField aylalisa OpenFOAM Community Contributions 1 October 28, 2014 18:42
[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 07:36.