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

[swak4Foam] how to repeat a cycle in groovyBC

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 6, 2013, 11:04
Default how to repeat a cycle in groovyBC
  #1
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 26
immortality is on a distinguished road
hello
I want to repeat a time cycle boundary condition for about 10 cycles.as its obvious all things should repeat from first at the end of each cycle.how can I define a time like "virtual time" that can be add to real time without need to calculating time manually.how can I perform that?each cyle takes a small time period like .002s.
thank you for replying and all advises are appreciated.
thanks.
immortality is offline   Reply With Quote

Old   January 6, 2013, 16:21
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 immortality View Post
hello
I want to repeat a time cycle boundary condition for about 10 cycles.as its obvious all things should repeat from first at the end of each cycle.how can I define a time like "virtual time" that can be add to real time without need to calculating time manually.how can I perform that?each cyle takes a small time period like .002s.
thank you for replying and all advises are appreciated.
thanks.
That is not a groovyBC-question but basic mathematics. The question you should have asked is "is there a modul-operator in groovyBC?": yes there is http://openfoamwiki.net/index.php/Co...e_implemented: (the definition is a bit different from what you expect)
__________________
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 7, 2013, 03:50
Default
  #3
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 26
immortality is on a distinguished road
thanks!but i can't understand how should i use % operator in a groovyBC condition for repeating a cycle of groovyBC conditions from starting.i should use it at the end of first time cycle?how?could you give or point me to an example?thank you very much!
immortality is offline   Reply With Quote

Old   January 7, 2013, 05:04
Default
  #4
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
I think this should get you started in learning how to work with modulo operators.
http://en.wikipedia.org/wiki/Modulo
http://en.wikipedia.org/wiki/Modulo_operation

The basic thing you want to to is something like "primetime=time%period"
Bernhard is offline   Reply With Quote

Old   January 7, 2013, 05:21
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 Bernhard View Post
I think this should get you started in learning how to work with modulo operators.
http://en.wikipedia.org/wiki/Modulo
http://en.wikipedia.org/wiki/Modulo_operation

The basic thing you want to to is something like "primetime=time%period"
Thank you, Bernhard! I was so close from making an inappropriate remark
__________________
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 7, 2013, 13:13
Default
  #6
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 26
immortality is on a distinguished road
thank you both Bernhards!
my case is like it:
Code:
fractionExpression "(0<=time()&&time()<=t1)||(t1+c1<=time()&&time()<=t1+c2)||(t1+c3<=time()&&time()<=t1+c4)||(t2+c1<=time()&&time()<=t2+c2)||(t2+c3<=time()&&time()<=t2+c4)||(t3+c1<=time()&&time()<=t3+c2)||(t3+c3<=time()&&time()<=t3+c4)||(t4+c1<=time()&&time()<=t4+c2)||(t4+c3<=time()&&time()<=t4+c4)||(t5+c1<=time()&&time()<=t5+c2)||(t5+c3<=time()&&time()<=t5+c4)?1:0";
        valueExpression "vector(0,-v_r,0)"
        gradientExpression "vector(0,0,0)"; 
        value uniform (0 -39.13957133 0);
for each of t1,t2,t3,t4,t5,...(I should write untill t20)
the conditins are the same but for convergency they should repeat 20 cycles.
then how can I write them by % modulo?since times are floats.
is something like this correct?(only first condition doesn't repeat)
Code:
fractionExpressin "(0<=time()&&time()<=t1)||(t1+c1<=time()%(t1+c4)&&time()%(t1+c4)<=t1+c2)||(t1+c3<=time()%(t1+c4)&&time()%(t1+c4)<=t1+c4)
because (t1+c4) is the time of each cycle I wrote as above.is this mathematically true?
thanks.
immortality is offline   Reply With Quote

Old   January 7, 2013, 15:44
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 immortality View Post
thank you both Bernhards!
my case is like it:
Code:
fractionExpression "(0<=time()&&time()<=t1)||(t1+c1<=time()&&time()<=t1+c2)||(t1+c3<=time()&&time()<=t1+c4)||(t2+c1<=time()&&time()<=t2+c2)||(t2+c3<=time()&&time()<=t2+c4)||(t3+c1<=time()&&time()<=t3+c2)||(t3+c3<=time()&&time()<=t3+c4)||(t4+c1<=time()&&time()<=t4+c2)||(t4+c3<=time()&&time()<=t4+c4)||(t5+c1<=time()&&time()<=t5+c2)||(t5+c3<=time()&&time()<=t5+c4)?1:0";
        valueExpression "vector(0,-v_r,0)"
        gradientExpression "vector(0,0,0)"; 
        value uniform (0 -39.13957133 0);
for each of t1,t2,t3,t4,t5,...(I should write untill t20)
the conditins are the same but for convergency they should repeat 20 cycles.
then how can I write them by % modulo?since times are floats.
is something like this correct?(only first condition doesn't repeat)
Code:
fractionExpressin "(0<=time()&&time()<=t1)||(t1+c1<=time()%(t1+c4)&&time()%(t1+c4)<=t1+c2)||(t1+c3<=time()%(t1+c4)&&time()%(t1+c4)<=t1+c4)
because (t1+c4) is the time of each cycle I wrote as above.is this mathematically true?
thanks.
Don't have the time to go through such long expressions. If you want to "try" your BC without running a full simulation have a look at the replayTransientBC-utility that comes with swak. This only updates the BCs and writes the files to disc. Then you can have a look at the boundaries in Paraview.

I know what your next posting is going to be: it asks for a dictionary file. There ARE example files in the Examples. Copy and adapt one
__________________
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 7, 2013, 17:35
Default
  #8
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 26
immortality is on a distinguished road
thanks bernhard.you are right!i wanted to ask how use it and where an example is!
I'll do and will ask again!
immortality is offline   Reply With Quote

Old   January 8, 2013, 07:00
Default
  #9
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 26
immortality is on a distinguished road
bernhard could you tell me if the way i wrote the conditions are right or not?
Thank you.
immortality is offline   Reply With Quote

Old   January 8, 2013, 07:52
Default
  #10
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
Quote:
Originally Posted by immortality View Post
bernhard could you tell me if the way i wrote the conditions are right or not?
Are you talking to me?

But, is your question either of the following
1. Did I implement my equation correct?
2. Did I implement the correct equation?

The answer to 1: Does it work? Do you get errors? Why do have doubts?

The answer to 2: See the above answer by Gschaider. We will not check this for ever.
Bernhard is offline   Reply With Quote

Old   January 8, 2013, 08:33
Default
  #11
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 26
immortality is on a distinguished road
thanks.yes!
i dont have enough time to learn a new tool.
None of them! I just transformed one set to second.first set is correctly working(my question definitly) is:is second equivalent to the first?
immortality is offline   Reply With Quote

Old   January 9, 2013, 07:59
Default
  #12
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 26
immortality is on a distinguished road
suppose we have two range of time: t1<t<t2 and t3<t<t4
how we can combine these two into one expression according to the % operator you had said?
thanks for help.
immortality is offline   Reply With Quote

Old   January 9, 2013, 08:08
Default
  #13
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
You can't. You can use it for a periodic signal.

Suppose you have a function f(t) denoting a single period of what you want, say, between t=0 and t=p. Also, f(t) itself is not periodic.

Simple example f(t)=t.

Putting in f(t) will give you a continuously increasing value
f(t%p) will give you a sawtooth pattern: http://www.wolframalpha.com/input/?i=plot+t%251
Bernhard is offline   Reply With Quote

Old   January 9, 2013, 11:44
Default
  #14
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 26
immortality is on a distinguished road
thank you for nice and complete explaining.I want to do same work when time is t1<t<t2,t3<t<t4,t5<t<t6,etc.when t2-t1=t4-t3=t6-t5 and t3-t1=t4-t2=t5-t3=... mean the range dimensions and their distance are equal.
for example 1<t<2,3<t<4,5<t<6,... there exist same BC fr all of them.
i'm mixed up how to map them into 1<t<2 in spite of its simplicity.
is it possible that 1<t%2<2 can be true?or it can't be done by the method of reminders?
thank you for taking your time.
immortality is offline   Reply With Quote

Old   January 9, 2013, 12:07
Default
  #15
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
Define your f(t) for t in the range 0 to 2. Then use f(t%2).

Suppose your function is 0 for 0..1, 2..3, 4..5 and 1 for 1..2, 3..4 and 5..6 etc, then you can do something like f(t)=(t%2)>1&&(t%2)<2. Good luck!
Bernhard is offline   Reply With Quote

Old   April 25, 2013, 06:09
Default
  #16
Senior Member
 
stephane sanchi
Join Date: Mar 2009
Posts: 314
Rep Power: 18
openfoam_user is on a distinguished road
Dear OF-users,

I use a groovyBCFixedValue type BC for the inlet. With a kind of ramp profile for the velocity.
"profile=(1.02*time()+0.03);"

I want to repeat the above profile each 0.05s. For example:
time(0.05)=time(0)
time(0.051)=time(0.001)
time(0.052)=time(0.002)
...
time(0.1)=time(0)
time(0.101)=time(0.001)
time(0.102)=time(0.002)
...
time(0.15)=time(0)
time(0.151)=time(0.001)
time(0.152)=time(0.002)
...

How can I use the modulo-operator (%) to obtain what I want.

Thanks for helping me.

Regards,
Stephane.
immortality likes this.
openfoam_user is offline   Reply With Quote

Old   April 25, 2013, 14:21
Default
  #17
Senior Member
 
stephane sanchi
Join Date: Mar 2009
Posts: 314
Rep Power: 18
openfoam_user is on a distinguished road
Dear OF-users,

Has someone already used the modulo-operator (%) successfully?

Can someone post a short example ?

Help s needed !

Regards,
Stephane.
openfoam_user is offline   Reply With Quote

Old   April 25, 2013, 14:59
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 openfoam_user View Post
Dear OF-users,

Has someone already used the modulo-operator (%) successfully?

Can someone post a short example ?

Help s needed !

Regards,
Stephane.
The only "problem" of the swak-% ist that it is a bit differently defined than the standard-%: while "a % b" in the standard-case maps into [0,b) in swak it maps into [-b/2,b/2) . Seemed to be a good idea at the time

So to generate a "parabolic sawtooth" you might do something like this (I'm using variables to make it clearer - I recommend this anyway). Note that tPeriodic is in the range [0,1)
Code:
variables (
  "intervall=42.;"
  "tPeriodic=((time() % intervall) + intervall/2)/intervall;"
);
expression "tPeriodic*tPeriodic";
This is only an example and I didn't actually run it.

If you're unsure if you implemented your BC correctly I recommend using the replayBC-utility before running the actual simulation
__________________
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   April 25, 2013, 16:21
Default
  #19
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 26
immortality is on a distinguished road
thank you openfoam_user.
I had same question for a long time before but didn't take a useful answer and I thought from answers I received that this is so easy to explain and just I don't figure it out and so disappointed!
maybe didn't propound it clearly.
anyway what does that expression mean(tperiodic*tperiodic)?is it just an example?
but my cycle is somewhat more complicated,if anyone can help
time(0.05)=time(0)
time(0.051)=time(0.001)
time(0.052)=time(0.002)
...
time(.075)=time(.025)

time(0.1)=time(0)
time(0.101)=time(0.001)
time(0.102)=time(0.002)
...
time(.125)=time(.025)

time(0.15)=time(0)
time(0.151)=time(0.001)
time(0.152)=time(0.002)
...
time(.175)=time(.025)

it means that pieces are not contiguous and intervals are apart.
how can set an arrangement for that?
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King.
To Be or Not To Be,Thats the Question!
The Only Stupid Question Is the One that Goes Unasked.

Last edited by immortality; April 25, 2013 at 17:12.
immortality is offline   Reply With Quote

Old   April 26, 2013, 15:26
Default
  #20
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 immortality View Post
thank you openfoam_user.
I had same question for a long time before but didn't take a useful answer and I thought from answers I received that this is so easy to explain and just I don't figure it out and so disappointed!
maybe didn't propound it clearly.
anyway what does that expression mean(tperiodic*tperiodic)?is it just an example?
Yeah. IT IS JUST AN EXAMPLE. The words "this is only an example" should have been a very clear hint. About "what does the expression mean": when you see "t^2" and in the text it says "parabolic sawtooth" you could sit down with a piece of paper and in 5 min you have it drawn: it is the rising arm of a parabola which after 42s drops to 0 and rises again.

I don't understand why you're disappointed with getting no answers when you disappoint people by not reading their answers. You've got to live with it that people are getting selective with answering. Even if some kind soul answers one of your questions per day she would only answer half of your questions

Quote:
Originally Posted by immortality View Post
but my cycle is somewhat more complicated,if anyone can help
time(0.05)=time(0)
time(0.051)=time(0.001)
time(0.052)=time(0.002)
...
time(.075)=time(.025)

time(0.1)=time(0)
time(0.101)=time(0.001)
time(0.102)=time(0.002)
...
time(.125)=time(.025)

time(0.15)=time(0)
time(0.151)=time(0.001)
time(0.152)=time(0.002)
...
time(.175)=time(.025)

it means that pieces are not contiguous and intervals are apart.
how can set an arrangement for that?
That is not really clear. You mean it is undefined between the points you specify?
__________________
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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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] reactingMultiPhaseEulerFoam problems with groovyBC zanilu70 OpenFOAM Community Contributions 4 December 13, 2016 07:46
[swak4Foam] Change in alpha and U with groovyBC in twoPhaseEulerFoam dani2702 OpenFOAM Community Contributions 0 November 17, 2016 04:30
[swak4Foam] groovyBC issue - k and epsilon sagnikmazumdar OpenFOAM Community Contributions 24 March 1, 2015 08:16
one dimensional interpolation - repeat cycle. kmgraju CFX 1 March 3, 2013 06:20
[swak4Foam] groovyBC and Eqn.setReference() benk OpenFOAM Community Contributions 3 June 2, 2011 09:49


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