CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   how to repeat a cycle in groovyBC (https://www.cfd-online.com/Forums/openfoam-solving/111406-how-repeat-cycle-groovybc.html)

 immortality January 6, 2013 11:04

how to repeat a cycle in groovyBC

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.
thanks.

 gschaider January 6, 2013 16:21

Quote:
 Originally Posted by immortality (Post 400319) 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)

 immortality January 7, 2013 03:50

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!

 Bernhard January 7, 2013 05:04

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"

 gschaider January 7, 2013 05:21

Quote:
 Originally Posted by Bernhard (Post 400436) 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

 immortality January 7, 2013 13:13

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.

 gschaider January 7, 2013 15:44

Quote:
 Originally Posted by immortality (Post 400537) 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

 immortality January 7, 2013 17:35

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 January 8, 2013 07:00

bernhard could you tell me if the way i wrote the conditions are right or not?
Thank you.

 Bernhard January 8, 2013 07:52

Quote:
 Originally Posted by immortality (Post 400698) 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.

 immortality January 8, 2013 08:33

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 January 9, 2013 07:59

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.

 Bernhard January 9, 2013 08:08

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

 immortality January 9, 2013 11:44

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.

 Bernhard January 9, 2013 12:07

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!

 openfoam_user April 25, 2013 05:09

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.

 openfoam_user April 25, 2013 13:21

Dear OF-users,

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

Can someone post a short example ?

Help s needed !

Regards,
Stephane.

 gschaider April 25, 2013 13:59

Quote:
 Originally Posted by openfoam_user (Post 423179) 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

 immortality April 25, 2013 15:21

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?

 gschaider April 26, 2013 14:26

Quote:
 Originally Posted by immortality (Post 423199) 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 (Post 423199) 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?

All times are GMT -4. The time now is 05:50.