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

[swak4Foam] Swak4Foam/GroovyBC for total pressure in simpleFoam

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 10, 2014, 13:05
Default Swak4Foam/GroovyBC for total pressure in simpleFoam
  #1
Senior Member
 
Phoevos
Join Date: Mar 2009
Posts: 104
Rep Power: 17
fivos is on a distinguished road
Hi to everyone,

I am trying to set up a case where I define the total pressure at the inlet and the static pressure at the outlet of the computational domain. I am working with the simpleFoam solver and since it does not support total pressure BCs I am trying to implement the condition using Groovy BC.

So, since simpleFoam works using kinematic pressure (p/rho) instead of the actual pressure, the formula for the kinematic total pressure is:

ptot = p + 1/2 * |u|^2 (all p refer to kinematic pressures)

thus I have to set on the boundary the value of p = ptot - 1/2* |u|^2. I tried to do so in the following way, but it does not work:

(the following is the relevant entry in the p file of the '0' folder for simpleFoam)
Code:
  
 inlet
    {
         type            groovyBC;  
         variables      
         (
               "ptotal=3444476.5;"
               "umag=average(mag(U()));"
               "pstatic=max(0,ptotal-0.5*pow(umag,2));"
         )
         valueExpression "pstatic";
         value           uniform 3444476.5;
    }
I get errors at mag(U()):

Code:
--> FOAM FATAL ERROR: 
 Parser Error for driver PatchValueExpressionDriver at "1.14" :"syntax error, unexpected '('"
"average(mag(U()))"
               ^
---------------|
I have tried using velocity as U, withouth the parenthesis, but still it does not work; it may not crash, but the results I get are incorrect.

How should I define the velocity vector, in order to get the average velocity magnitude on the face, so that I can use it for the calculation?

Thanks in advance.
fivos is offline   Reply With Quote

Old   February 11, 2014, 07:10
Default
  #2
Senior Member
 
Phoevos
Join Date: Mar 2009
Posts: 104
Rep Power: 17
fivos is on a distinguished road
It seems that the problem I have is more complicated...
I tried to replace the condition at inlet with something much simpler, but it does not work either.

The new boundary condition I use is (as before this is from the p entry in the 0 folder):

inlet
{
type groovyBC;
variables "pressure=6722.237;"
valueExpression "pressure";
value uniform 6722.237;
}

This condition of course is the trivial fixed value. However, upon execution, after the first iteration, the value of pressure at the boundary is 0, which obviously is not what is defined in the groovyBC...

Regarding the compilation of the swak4Foam package, I did not get any errors (apart from the issue with the python configuration, but I am not interested in python integration right now) and I have all the relevant libraries generated.

Of course I have the required libraries included in the controlDict file:

libs (
"libOpenFOAM.so"
"libsimpleSwakFunctionObjects.so"
"libswakFunctionObjects.so"
"libgroovyBC.so"
);

A final note: I am using OpenFoam 2.2.x and for swak4Foam I use the version from Bruno (post#8 - http://www.cfd-online.com/Forums/ope...tml#post434217, as suggested by the relevant page in the wiki http://openfoamwiki.net/index.php/Contrib/swak4Foam).

Any ideas on that?
fivos is offline   Reply With Quote

Old   February 13, 2014, 06:57
Default
  #3
Senior Member
 
Phoevos
Join Date: Mar 2009
Posts: 104
Rep Power: 17
fivos is on a distinguished road
Ok, after some searching I have found the solution of the problems. First of all when closing the variables section there should be a semicolon.

For the pressure/total pressure boundary conditions it seems that it is more stable to dynamically alter the velocity on the boundary according to the local pressure, instead of pressure itself; the reason is that when fixing pressure at the inlet, there might be development of unphysical recirculation which destabilize the solution. By altering the velocity (and keeping zero gradient for pressure) at inlet the solution is much stabler.

For fixing pressure, by dynamically altering the velocity the condition is:

Code:
  
  inlet
    {
     type            groovyBC;
    value           uniform (-0.65 0 0); 
    variables     
    (    
        "ptarget=344447.65;"
        "umag{inlet}=sum(mag(U)*mag(Sf()))/sum(mag(Sf()));"
        "pstat{inlet}=sum(p*mag(Sf()))/sum(mag(Sf()));"
        "pdiff=(ptarget-pstat)/ptarget;"
        "relax=0.1;"
        "uvel=(umag+pdiff*relax);"
    );
    valueExpression     "vector(-uvel,0,0)";   
    }
Similarly, to fix total pressure by dynamically altering the velocity:

Code:
 
   inlet
    {
     type            groovyBC;
    value           uniform (-0.5 0 0); 
    variables     
    (    
        "ptot_target=344447.65;"
        "umag{inlet}=sum(mag(U)*mag(Sf()))/sum(mag(Sf()));"
        "pstat{inlet}=sum(p*mag(Sf()))/sum(mag(Sf()));"
        "ptot=pstat+0.5*umag*umag;"
        "pdiff=(ptot_target-ptot)/ptot_target;"
        "relax=0.1;"
        "uvel=(umag+pdiff*relax);"   
    );
    valueExpression     "vector(-uvel,0,0)";   
    }
Note that groovyBC should be installed to use the above with simpleFoam.
Hope it will be useful for others...
fivos is offline   Reply With Quote

Old   February 13, 2014, 20:12
Default
  #4
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 fivos View Post
Ok, after some searching I have found the solution of the problems. First of all when closing the variables section there should be a semicolon.

For the pressure/total pressure boundary conditions it seems that it is more stable to dynamically alter the velocity on the boundary according to the local pressure, instead of pressure itself; the reason is that when fixing pressure at the inlet, there might be development of unphysical recirculation which destabilize the solution. By altering the velocity (and keeping zero gradient for pressure) at inlet the solution is much stabler.
Just stumbled on this thread. Glad this is solved. Just one question: you really want to calculate these things on "average over the whole patch" and not on a "per face" basis? Because then a valueExpression "ptot-0.5*pow(mag(U),2)" should be sufficient
__________________
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   February 14, 2014, 08:44
Default
  #5
Senior Member
 
Phoevos
Join Date: Mar 2009
Posts: 104
Rep Power: 17
fivos is on a distinguished road
Hi Bernhard,

The idea to average on the face was to enhance stability. I could (or anyone else interested) try the per face calculation, instead of the per patch averaging and see what I get, but the results I got were really satisfactory. I will keep it in mind for any future calculations.

So thank you for your comment and also I would like to particularly thank you for your contribution as a whole (I refer to swak4Foam).
fivos is offline   Reply With Quote

Old   February 14, 2014, 12:51
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 fivos View Post
Hi Bernhard,

The idea to average on the face was to enhance stability. I could (or anyone else interested) try the per face calculation, instead of the per patch averaging and see what I get, but the results I got were really satisfactory. I will keep it in mind for any future calculations.
OK. Depends on the circumstances but maybe using the new pressure only as a fraction might help here. You could introduce a storedVariable pOld and then do in the variables something like (only a sketch): "pNew= <that is 'your' pressure>;" "pVal=f*pNew+(1-f)*pOld;" "pOld=p;". pVal will be used in the valueExpression. If everything runs smooth pVal will approach pNew in a few timesteps. If it doesn't then pVal will at least be 'smoother'

For usage of storedVariables see the incomplete reference guide and examples
__________________
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


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
Getting hydrostatic pressure in a vertical box using simpleFOAM maxou1993 OpenFOAM Running, Solving & CFD 3 June 13, 2022 06:02
interFoam (HELYX-OS) pressure boundary conditions SFr OpenFOAM Running, Solving & CFD 8 June 23, 2016 17:36
CFX Solver stopped with error when requested for backup during solver running Mfaizan CFX 40 May 13, 2016 07:50
sonicFoam - pressure driven pipe: flow continuity violation and waveTransmissive BC Endel OpenFOAM Running, Solving & CFD 3 September 11, 2014 17:29
Pressure BC for combustion chamber Giuki FLUENT 1 July 19, 2011 12:35


All times are GMT -4. The time now is 04:03.