|
[Sponsors] |
[swak4Foam] Using fieldAverage together with swak4foam expressionField |
![]() |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
![]() |
![]() |
#1 |
Senior Member
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14 ![]() |
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 ![]() 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; } ); } 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! |
|
![]() |
![]() |
![]() |
![]() |
#2 | |||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 ![]() ![]() |
Quote:
Quote:
Quote:
__________________
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 |
||||
![]() |
![]() |
![]() |
![]() |
#3 | ||
Senior Member
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14 ![]() |
Thank you for the reply Bernhard!
Quote:
Quote:
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; } |
|||
![]() |
![]() |
![]() |
![]() |
#4 |
Member
Join Date: Feb 2014
Posts: 63
Rep Power: 12 ![]() |
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; } Any Ideas how to get around this problem?? Thank you. |
|
![]() |
![]() |
![]() |
![]() |
#5 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 ![]() ![]() |
Quote:
__________________
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 |
||
![]() |
![]() |
![]() |
![]() |
#6 |
Member
Join Date: Feb 2014
Posts: 63
Rep Power: 12 ![]() |
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; } 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. |
|
![]() |
![]() |
![]() |
![]() |
#7 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 ![]() ![]() |
Quote:
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 |
||
![]() |
![]() |
![]() |
![]() |
#8 |
Member
Join Date: Feb 2014
Posts: 63
Rep Power: 12 ![]() |
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 So I want to ask, does UMean object is destroyed after its fieldAverage function execution? |
|
![]() |
![]() |
![]() |
![]() |
#9 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 ![]() ![]() |
Quote:
__________________
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 |
||
![]() |
![]() |
![]() |
![]() |
#10 |
Member
Join Date: Feb 2014
Posts: 63
Rep Power: 12 ![]() |
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) ? |
|
![]() |
![]() |
![]() |
![]() |
#11 |
Senior Member
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 314
Rep Power: 15 ![]() |
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; } ); 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 |
|
![]() |
![]() |
![]() |
![]() |
#12 |
Member
Join Date: Feb 2014
Posts: 63
Rep Power: 12 ![]() |
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. |
|
![]() |
![]() |
![]() |
![]() |
#13 |
Senior Member
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 314
Rep Power: 15 ![]() |
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. |
|
![]() |
![]() |
![]() |
![]() |
#14 |
Senior Member
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14 ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#15 | |
Member
Matt
Join Date: Oct 2012
Posts: 39
Rep Power: 13 ![]() |
Quote:
|
||
![]() |
![]() |
![]() |
![]() |
#16 |
Senior Member
Timofey Mukha
Join Date: Mar 2012
Location: Stockholm, Sweden
Posts: 119
Rep Power: 14 ![]() |
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 } |
|
![]() |
![]() |
![]() |
![]() |
#17 |
New Member
Francesco Garita
Join Date: Oct 2016
Location: Italy
Posts: 8
Rep Power: 9 ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#18 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 ![]() ![]() |
Quote:
Code:
hasMean { type executeIfObjectExists; objectName TMean; checkType true; objectType volScalarField; objectShouldExist true; readDuringConstruction false; functions { doCalc { type swakExpression; ...
__________________
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 |
||
![]() |
![]() |
![]() |
![]() |
#19 | |
Member
a
Join Date: Oct 2014
Posts: 49
Rep Power: 11 ![]() |
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; } } Quote:
seems strange to me, please help ![]() Thanks and regards. |
||
![]() |
![]() |
![]() |
![]() |
#20 |
New Member
Francesco Garita
Join Date: Oct 2016
Location: Italy
Posts: 8
Rep Power: 9 ![]() |
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; } Good luck, Francesco |
|
![]() |
![]() |
![]() |
Tags |
fieldaverage, functionobjects, swak4foam |
|
|
![]() |
||||
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 |