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

[swak4Foam] Groovy BC - time dependend Inlet

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 8, 2012, 07:01
Default Groovy BC - time dependend Inlet
  #1
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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 is offline   Reply With Quote

Old   March 8, 2012, 07:43
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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.
Attached Images
File Type: jpg scalar.jpg (19.6 KB, 368 views)
Tobi is offline   Reply With Quote

Old   March 8, 2012, 10:17
Default
  #3
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 Tobi View Post
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
gschaider is offline   Reply With Quote

Old   March 9, 2012, 09:45
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Quote:
Originally Posted by gschaider View Post
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
Tobi is offline   Reply With Quote

Old   March 12, 2012, 18:31
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 Tobi View Post
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 ?: )
Tushar@cfd likes this.
gschaider is offline   Reply With Quote

Old   March 12, 2012, 19:09
Default
  #6
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Oh yes, this seems better. THX!
Tobi is offline   Reply With Quote

Old   September 4, 2012, 08:29
Default Time dependent inlet pressure
  #7
New Member
 
Sibusiso Mavuso
Join Date: Jul 2010
Location: South Africa/Pretoria
Posts: 22
Rep Power: 15
semaviso is on a distinguished road
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
semaviso is offline   Reply With Quote

Old   September 4, 2012, 10:41
Default
  #8
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 semaviso View Post
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"
gschaider is offline   Reply With Quote

Old   September 5, 2012, 04:24
Default
  #9
New Member
 
Sibusiso Mavuso
Join Date: Jul 2010
Location: South Africa/Pretoria
Posts: 22
Rep Power: 15
semaviso is on a distinguished road
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
semaviso is offline   Reply With Quote

Old   September 5, 2012, 04:53
Default
  #10
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 semaviso View Post
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"
gschaider is offline   Reply With Quote

Old   September 5, 2012, 05:28
Default
  #11
New Member
 
Sibusiso Mavuso
Join Date: Jul 2010
Location: South Africa/Pretoria
Posts: 22
Rep Power: 15
semaviso is on a distinguished road
thanks Bernhard will try it and keep you updated.
semaviso is offline   Reply With Quote

Old   May 31, 2013, 06:34
Default
  #12
New Member
 
Join Date: Mar 2013
Posts: 10
Rep Power: 13
peter_t is on a distinguished road
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 );
}
peter_t is offline   Reply With Quote

Old   May 31, 2013, 07:08
Default
  #13
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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
vcvedant, Aaron_L and oumnion like this.
Tobi is offline   Reply With Quote

Old   June 1, 2013, 04:32
Default
  #14
New Member
 
Join Date: Mar 2013
Posts: 10
Rep Power: 13
peter_t is on a distinguished road
thanks heaps tobi that is very helpful indeed
peter_t is offline   Reply With Quote

Old   October 18, 2013, 15:34
Post
  #15
New Member
 
Join Date: Apr 2013
Posts: 2
Rep Power: 0
elingfre is on a distinguished road
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!
elingfre is offline   Reply With Quote

Old   October 19, 2013, 17:28
Default
  #16
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 elingfre View Post
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 View Post
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
__________________
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 20, 2013, 16:54
Default
  #17
New Member
 
Join Date: Apr 2013
Posts: 2
Rep Power: 0
elingfre is on a distinguished road
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
elingfre is offline   Reply With Quote

Old   August 14, 2019, 05:22
Default
  #18
Member
 
James
Join Date: Jan 2014
Posts: 38
Rep Power: 12
Madeinspace is on a distinguished road
Hi there,


I am trying to tweak this sine wave inlet BC into generating square wave but I don't seem to figure outhow to generate square wave. The BC below gives me continuous flow. But what I want is inlet that opens say every 0.5s and last for 0.1s.



Would really apperaeciate your feedback !


dropInlet
{
type groovyBC;
variables "xp=pts().x;minX=min(xp);maxX=max(xp);unif=-0.2*normal();";
valueExpression "10*(1+0.5*sin(500*time()))*unif";
value uniform (0.0 0.0 0.0);
}
Madeinspace is offline   Reply With Quote

Old   August 15, 2019, 12:35
Default
  #19
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 Madeinspace View Post
Hi there,


I am trying to tweak this sine wave inlet BC into generating square wave but I don't seem to figure outhow to generate square wave. The BC below gives me continuous flow. But what I want is inlet that opens say every 0.5s and last for 0.1s.



A quick way to generate a square wave with "frequency" and "height" 1 would be something like

Code:
valueExpression "(time() % 1)>0 ? 0 : 1";
for discussions on the (a bit different) implementation of the modulo operator % in swak4foam see how to repeat a cycle in groovyBC and https://openfoamwiki.net/index.php/C...e_implemented:
__________________
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 21, 2019, 15:43
Default
  #20
Member
 
James
Join Date: Jan 2014
Posts: 38
Rep Power: 12
Madeinspace is on a distinguished road
Quote:
Originally Posted by gschaider View Post
A quick way to generate a square wave with "frequency" and "height" 1 would be something like

Code:
valueExpression "(time() % 1)>0 ? 0 : 1";
for discussions on the (a bit different) implementation of the modulo operator % in swak4foam see how to repeat a cycle in groovyBC and https://openfoamwiki.net/index.php/C...e_implemented:

Thank you gschaider,


It does exactly what I wanted to do. I set it at the inlet BC with alpha.water and I get continuous water flow into domain for 0.5 s, then it stops for the next 0.5 s and repeats. But I don't really know how does it work and would really appreciate your feedback. It looks like "%" here is a different than a modulo operator in OF then how does the use of % repeat the cycle every 0.5 s?


I have a new BC created in OF where I am trying to mimic exacty the same thing. I have a working BC code for continuous flow but when I tried to get it in cycle similar to groovy BC then it complains to compile: invalid operands of types double’ and ‘Int’ to binary ‘operator%’. I accessed time and used % operator inside the code as shown below. It doesn't look like % operator works the same way for groovy and OF.


scalar t_ = this->db().time().value();

t_ % 1 > 0






Many thanks!
Madeinspace 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
Elastic or Plastic Deformations in OpenFOAM NickolasPl OpenFOAM Pre-Processing 36 September 23, 2023 08:22
[Other] Contribution a new utility: refine wall layer mesh based on yPlus field lakeat OpenFOAM Community Contributions 58 December 23, 2021 02:36
pimpleDyMFoam computation randomly stops babapeti OpenFOAM Running, Solving & CFD 5 January 24, 2018 05:28
Help for the small implementation in turbulence model shipman OpenFOAM Programming & Development 25 March 19, 2014 10:08
Micro Scale Pore, icoFoam gooya_kabir OpenFOAM Running, Solving & CFD 2 November 2, 2013 13:58


All times are GMT -4. The time now is 20:21.