CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (http://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Groovy BC - time dependend Inlet (http://www.cfd-online.com/Forums/openfoam-pre-processing/98327-groovy-bc-time-dependend-inlet.html)

Tobi March 8, 2012 08:01

Groovy BC - time dependend Inlet
 
hi all,

i am trying to make my first own BC with groovy. I made my own scalarIcoFoam where i implemented just one scalar-field to simulate color in water or sth. like that (without diffusion).

So i wanna build a pulsating inlet for the new scalar field.

The value should switch every 0.5 seconds from value 0 to 1 and after 0.5 from 1 to 0. I think its a very simple implementation with groovy but i need some help.


Thx in advance
Tobi

Tobi March 8, 2012 08:43

1 Attachment(s)
Further question:
is it possible to create a bc for the inlet that only a few faces use that inlet condition (compare the picture | red line).
I wanna set just a few fields with value 1 to the inlet that i get a little fiber, but i dont know how.

gschaider March 8, 2012 11:17

Quote:

Originally Posted by Tobi (Post 348354)
Further question:
is it possible to create a bc for the inlet that only a few faces use that inlet condition (compare the picture | red line).
I wanna set just a few fields with value 1 to the inlet that i get a little fiber, but i dont know how.

Conditional BCs can be specified using the ?:-notation (see a C/C++/Java-book for the meaning of that). For instance "pos().y<0 ? 1 : 0" would give you 1 in the lower half of the patch. If with "only a few faces use that condition" you mean "use a Dirichlet-condition the other a Neumann-Condition" then you'll have to modify the fractionExpression too

Tobi March 9, 2012 10:45

Quote:

Originally Posted by gschaider (Post 348388)
For instance "pos().y<0 ? 1 : 0"


Hey Gschaider,
thx for your replay. I am programming with c++ but never used that kind of programming :) but now (after searching for that notation) i know what you mean.

so i can use sth. like that:


Code:

variableValue = pos().y>0.2 ? (pos().y < 0.8 ? 1 : 0) : 0
So i defined the value of variableValue between 0.2 to 0.8 to 1 and the other one to zero.
Is that correct?

And i use my own variable to set the valueExpressions:

Code:

valueExpressions "variableValue";
Thx for your help.
tobi

gschaider March 12, 2012 19:31

Quote:

Originally Posted by Tobi (Post 348566)
Hey Gschaider,
thx for your replay. I am programming with c++ but never used that kind of programming :) but now (after searching for that notation) i know what you mean.

so i can use sth. like that:


Code:

variableValue = pos().y>0.2 ? (pos().y < 0.8 ? 1 : 0) : 0
So i defined the value of variableValue between 0.2 to 0.8 to 1 and the other one to zero.
Is that correct?

And i use my own variable to set the valueExpressions:

Code:

valueExpressions "variableValue";
Thx for your help.
tobi

I think you can do it simpler with

Code:

valueExpression "(pos().y>0.2 && pos().y<0.8) ? 1 : 0";
(I think the && makes it easier to read than the nested ?: )

Tobi March 12, 2012 20:09

Oh yes, this seems better. THX!

semaviso September 4, 2012 08:29

Time dependent inlet pressure
 
Hi Foamers,

I am trying to specify runTime dependent pressure inlet boundary conditions using a GroovyBC.

The expression for this inlet pressure is:
P_inlet = 2^(-runTime+5)+10;

I tried it as follows:

inlet
{
type groovyBC;
valueExpression "2^(-runTime()+5)+10";
value 1.0e6
}

and I get ant fatal error:

"field runTime not existing or of wrong type"

Is there a way to use the run time in the boundary condition without getting this error?

Can someone help me with this.


thank you in advance,
SBU

gschaider September 4, 2012 10:41

Quote:

Originally Posted by semaviso (Post 380137)
Hi Foamers,

I am trying to specify runTime dependent pressure inlet boundary conditions using a GroovyBC.

The expression for this inlet pressure is:
P_inlet = 2^(-runTime+5)+10;

I tried it as follows:

inlet
{
type groovyBC;
valueExpression "2^(-runTime()+5)+10";
value 1.0e6
}

and I get ant fatal error:

"field runTime not existing or of wrong type"

Is there a way to use the run time in the boundary condition without getting this error?

Can someone help me with this.


thank you in advance,
SBU

Two problems:
- time() gives you the current physical time
- ^ is the out product of vectors/tensors in OpenFOAM/swak4Foam. What you probably want is the function pow(a,b) (which gives a^b). The only problem is that the current *released* version only works with constant b. This has been fixed in the current development-version of swak4Foam (the one in the Mercurial-archive). If you don't want to install that the usual log/exp-trick will help you: "exp(log(2)*(-time()+5))+10"

semaviso September 5, 2012 04:24

Bernhard,


I have used "pow(x,y)" instead of "x^y" :

inlet
{
type groovyBC;
variables "p0=10.0e5;";
valueExpression "pow(2,-time()+5) + p0";
value uniform 40.0e5;
}

and get this error:

--> FOAM FATAL ERROR:
Parser Error at "1.8-11" :"syntax error, unexpected TOKEN_time, expecting value"
"pow(2,-time()+5) + p0"
" ^^^^ "

From function parsingValue
in file PatchValueExpressionDriver.C at line 192.

FOAM exiting

please help.

thanx,
SBU

gschaider September 5, 2012 04:53

Quote:

Originally Posted by semaviso (Post 380279)
Bernhard,


I have used "pow(x,y)" instead of "x^y" :

inlet
{
type groovyBC;
variables "p0=10.0e5;";
valueExpression "pow(2,-time()+5) + p0";
value uniform 40.0e5;
}

and get this error:

--> FOAM FATAL ERROR:
Parser Error at "1.8-11" :"syntax error, unexpected TOKEN_time, expecting value"
"pow(2,-time()+5) + p0"
" ^^^^ "

From function parsingValue
in file PatchValueExpressionDriver.C at line 192.

FOAM exiting

please help.

thanx,
SBU

That is EXACTLY what I said: "pow currently only works with constant b"

semaviso September 5, 2012 05:28

thanks Bernhard will try it and keep you updated.
:)

peter_t May 31, 2013 06:34

Hi there,
I am doing a thesis involving flow over a bump. I am finding information on groovyBC difficult to come by. Additionally, the information I do find is somewhat complicated. I am an engineer after all not a programmer haha. If somebody could explain to me how the following code works and what each individual symbol means that would be greatly appreciated. The following is a velocity profile of a wind tunnel inlet patch.

boundaryField
{
inlet
{
type groovyBC;
variables "Umax=1.0;d=0.01;turb_profile=Umax*pow(pos().y,0.1 428571429)*pow((1/d),0.1428571429);";
valueExpression "(pos().y < d) ? vector (turb_profile, 0, 0) : vector (1, 0, 0)";
value uniform (1 0 0 );
}

Tobi May 31, 2013 07:08

Hi Peter,

you do not Need programmers knowledge to use the groovy BC. Just read it like a equation ;)


In the following lines you can see the definitions of variables
Code:

variables "Umax=1.0;d=0.01;turb_profile=Umax*pow(pos().y,0.1 428571429)*pow((1/d),0.1428571429);";
There you set the following varialbes in math-format:

U_{max} = 1,0 \frac{m}{s}
d= 0.01 m
turb\_profile = U_{max}\cdot (pos().y)^{0.1428571429} \cdot \left[\frac{1}{d}\right]^{0.1428571429}

pos().y = Position of y (so it should be the length)


The Profil used in the BC is:
Code:

valueExpression "(pos().y < d) ? vector (turb_profile, 0, 0) : vector (1, 0, 0)";
There you can see that there is an if - else condition:

if pos().y < d then use the vector: (turb_profile 0 0) else use the vector (1 0 0)


So you have a dependend vector in x-direction !

from y=0 till y = d the x-component is calculated with pos().y and the function defined above and after that you have the vector U=(1 0 0)

Hope it s clear enough!

Tobi

peter_t June 1, 2013 04:32

thanks heaps tobi that is very helpful indeed

elingfre October 18, 2013 15:34

Hey Guys,

I am looking and changing the groovyBC values and expressions for so long now, but don't get an inch further.

I got a closed System (outside wall) with an "inlet" it is also a wall, where i want to put pressure on. In the real world it is a cylinder gliding in the system and due to that pressure occures (liquid filled system).

I am so far

inlet
{
type groovyBC;
variables "pressure=22e05; T1=1e-04;Athmos=1e05:";
valueExpression "(time() < T1)? pressure : Athmos";
}

.. when i execute this there comes an error message that the Athmos couldn't be read and that the pressure was put to 500...

I want that when the time is lower than T1 the pressure occures to the system (inlet face) and after that -> goes back to normal Pressure ( 1 Bar (1e05 Pa)).


Do I have to use the fractionExpression due to my simulation? I read that it toggles the BC from Neumann to Dierlich(wrong spelling?).

Thanks for your Support!

gschaider October 19, 2013 17:28

Quote:

Originally Posted by elingfre (Post 457726)
Hey Guys,

I am looking and changing the groovyBC values and expressions for so long now, but don't get an inch further.

I got a closed System (outside wall) with an "inlet" it is also a wall, where i want to put pressure on. In the real world it is a cylinder gliding in the system and due to that pressure occures (liquid filled system).

I am so far

inlet
{
type groovyBC;
variables "pressure=22e05; T1=1e-04;Athmos=1e05:";
valueExpression "(time() < T1)? pressure : Athmos";
}

.. when i execute this there comes an error message that the Athmos couldn't be read and that the pressure was put to 500...

It's always better to copy/paste the exact error message than retelling it.
Quote:

Originally Posted by elingfre (Post 457726)
I want that when the time is lower than T1 the pressure occures to the system (inlet face) and after that -> goes back to normal Pressure ( 1 Bar (1e05 Pa)).


Do I have to use the fractionExpression due to my simulation? I read that it toggles the BC from Neumann to Dierlich(wrong spelling?).

The way you tell it you switch from one fixed value to another. Then your formulation should be find. Although I'd expect a "kick" to the system with the sudden jump you give

elingfre October 20, 2013 16:54

Thanks for you support gschaider!,
I worked it out and want to post my Example here.

inlet
{
type groovyBC;
variables "Druckstoss=22e05;Athmos=1e05;T1=5e-4;";
valueExpression "(time()< T1)? Druckstoss :Athmos ";
value uniform 1e05;
}

You only have to put a default value for the face. E.g. here 1e05 Pa (equal 1 Bar).
It works fine and triggers the boundary from 1 bar to 22 bar and back to 1 bar :)


All times are GMT -4. The time now is 19:52.