# how to repeat a cycle in groovyBC

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

 April 26, 2013, 16:28 #21 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 yes.for instance in [0,.025) I have a value for the function.but in [.025,.05) its zero gradient and again in [.05,.075) that valueExpression again and so on. __________________ 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.

 April 27, 2013, 14:10 #22 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 I figured it out.but another issue is that I have a time duration in start of cycles that is fixed and doesn't repeat in later times. how can I set it?(imagine in the example of Bruno I have a fixed value in a few seconds at start and then interval starts) __________________ 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.

 April 27, 2013, 17:56 #23 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 I've defined t_mapped as this considering to t1 as a non-repeating value at first of the cycle: Code: `"t_mapped=(time()>=t1) ? ((time()-t1) % c4+c4/2+t1) : time();"` but this expression doesn't work(always is zero) Code: `fractionExpression "(t1

 April 28, 2013, 08:00 #24 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 Dear Bernhard. It seems you supposed incorrectly the domain that % maps into. I removed c4/2 in the formula and now it works well. It seems more correct that the domain is [0,interval) in the module-operator. __________________ 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.

 July 30, 2013, 12:52 #25 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 HI Bernhard could you modify it to be between 0 and b in a%b in next Swak4Foam? it has originated a lot of trouble for me. it seems it maps the time to [0,b/2) (although seems incorrect due to duration should be "b" but occurs in real world as I've examined) not to [-b/2,b/2) or [0, b). see it: Code: `"t_mappedr=((time())%(c5r));"` where c5r is the interval. that is used in: Code: `"port2=(t1+c1r

July 30, 2013, 13:26
#26
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,920
Rep Power: 41
Quote:
 Originally Posted by immortality HI Bernhard could you modify it to be between 0 and b in a%b in next Swak4Foam? it has originated a lot of trouble for me.
Sorry no. Because making life easier for one would break existing cases for many others. And I rechecked: the %-operator works as expected. With
Code:
`funkySetFields -time 0 -create -field test -expression "pos().x % 1"`
I get a nice sawtooth between [-0.5,0.5] as specified. And "No": it doesn't matter whether it is time or position: the implementation of % is the same
__________________
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

 July 30, 2013, 14:04 #27 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 Hi Bernhard but negative time has no meaning and it seems it omits negative times in the modular code,doesn't? __________________ 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.

July 31, 2013, 06:50
#28
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,920
Rep Power: 41
Quote:
 Originally Posted by immortality Hi Bernhard but negative time has no meaning and it seems it omits negative times in the modular code,doesn't?
As I verified in my above FSF-example negative values get correctly mapped. Always the same routine is used. So it doesn't matter whether it is a negative position or time. Check this by going to any case an there doing
Code:
```mkdir -- "-0.25"
funkySetFields -time "-0.25" -create -field test -expression "time() % 1"```
You will find that the file -0.25/test has a internal value -0.25 just as specified.
__________________
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

 July 31, 2013, 16:18 #29 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 in this expression t_mappedl should be between [0,.000933) as the result right? float number isn't a trouble? Code: `"t_mappedl=(time()>0) ? ((time())%.000933) : time();"` but I don't know why it only put t_mappedl equal to zero for negative values of (time())%.000933) (it executes the condition for t-mappedl=0 in return of being negative until it become positive and then works fine) whats the way to see t_mappedl values in each time step? __________________ 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.

 August 1, 2013, 11:45 #30 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 I have used this fields in replayTransientBCDict: Code: ```fields ( t1 t_mappedl t_mappedr ); useFunctionObjects false; addDummyPhi false;``` but the variables are not printed in time folders.how to have them? __________________ 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.

August 1, 2013, 13:52
#31
Senior Member

Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,209
Rep Power: 18
Quote:
 Originally Posted by gschaider Sorry no. Because making life easier for one would break existing cases for many others. And I rechecked: the %-operator works as expected. With Code: `funkySetFields -time 0 -create -field test -expression "pos().x % 1"` I get a nice sawtooth between [-0.5,0.5] as specified. And "No": it doesn't matter whether it is time or position: the implementation of % is the same
Hi
I examined that and it doesn't give any negative value(everything is in the domain of [0,.5).it is notable that pos().x is between 0 and .069 meter that is lower than 1.may it be the cause of not having negative values as expected?
Attached Files
 test.tar.gz (25.7 KB, 1 views)
__________________
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.

 August 1, 2013, 14:02 #32 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 I think I have figure it out and if verify me I'm going to execute it in real case. I tested : Code: `100*pos().x % 1` and every funky values were in (-.5, .5) then I conclude that : in a%b if a<=b then the result will be in [0,b/2] and if a>b they will be in [-b/2,b/2] then I have to use two different expressions for first cycle and the others. -------------------------- dear Bernhard it would be very useful if you could guide me through finding the formula implemented for this operator in Swak4Foam codes. __________________ 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; August 1, 2013 at 16:52.

 August 1, 2013, 16:52 #33 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 I have seen these in my tests: Code: `funkySetFields -time 0 -create -field test -expression "1.5 % 1"` resulted in ".5" Code: `funkySetFields -time 0 -create -field test -expression "1 % 1"` resulted in "0" Code: `funkySetFields -time 0 -create -field test -expression "1.75 % 1"` or even Code: `funkySetFields -time 0 -create -field test -expression "0.75 % 1"` resulted in "-.25" it seems be a bug if you agree because its not clear how this mapping is done. __________________ 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.

August 1, 2013, 18:42
#34
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,920
Rep Power: 41
Quote:
 Originally Posted by immortality I have seen these in my tests: Code: `funkySetFields -time 0 -create -field test -expression "1.5 % 1"` resulted in ".5" Code: `funkySetFields -time 0 -create -field test -expression "1 % 1"` resulted in "0" Code: `funkySetFields -time 0 -create -field test -expression "1.75 % 1"` or even Code: `funkySetFields -time 0 -create -field test -expression "0.75 % 1"` resulted in "-.25" it seems be a bug if you agree because its not clear how this mapping is done.
No. It is not a bug. It is just different. To quote from http://openfoamwiki.net/index.php/Co...funkySetFields

Code:
`A modulo-operator. Somehow differently defined from the standard C++ %-operator: the value of (x − ε) % x is − ε (not x − ε - if you don't understand what I mean, please test for yourself - for most applications of this operator this is in my opinion the more practical implementation)`
With your example (% 1) you get a straight line that starts at x=-0.5, y=-0.5 and goes to x=0.5,y=0.5. At x=0.5 it jumps to -0.5 and goes up again. For generating spatial distributions this definition is more convenient (I think). And as I said: I won't change it because it will break the expressions of everyone who used it up to now (and who obviously bothered to read the documentation and if he didn't understand it took it on himself to do some experimentation. I won't punish these people just because you didn't read and experiment)
__________________
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

August 1, 2013, 18:49
#35
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,920
Rep Power: 41
Quote:
 Originally Posted by gschaider With your example (% 1) you get a straight line that starts at x=-0.5, y=-0.5 and goes to x=0.5,y=0.5. At x=0.5 it jumps to -0.5 and goes up again. For generating spatial distributions this definition is more convenient (I think). And as I said: I won't change it because it will break the expressions of everyone who used it up to now (and who obviously bothered to read the documentation and if he didn't understand it took it on himself to do some experimentation. I won't punish these people just because you didn't read and experiment)
OK. You experimented (only saw the last entry). You just got to the wrong conclusions
__________________
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

 August 2, 2013, 06:51 #36 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 Hi thanks for explanations.but in http://openfoamwiki.net/index.php/Co...funkySetFields in .4%1 for example epsilon is .6 and the answer of .4%1(even in your method) becomes .4 not -.6 so I think maybe the formula you mentioned is only applicable for epsilons

 August 2, 2013, 15:51 #37 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 now I have modified the expression that implemented % in my case like the way I told in upper post and it seems to work nice till now.when it ends second cycle I'll let you know. __________________ 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.

August 3, 2013, 07:59
#38
Senior Member

Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,209
Rep Power: 18
Quote:
 variables ( "intervall=42.;" "tPeriodic=((time() % intervall) + intervall/2)/intervall;" ); expression "tPeriodic*tPeriodic";
in your suggestion dear Bernhard it seems that the idea for position has implemented for time here.in time()=0 tPeriodic becomes .5,means it starts from middle of the interval while we expect that time be started from beginning. it may be appropriate for position when there is no importance in the order of values,they can map at first or at last no matter but in time the order is important.
so I implemented this expression that maintain positive half and maps negative part forward after positive part of the modulo operation result:
Code:
`0<=(time())%(c) && (time())%(c)<=c/2 ? (time())%(c) : (time())%(c)+c)`
__________________
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.

 August 30, 2013, 06:58 #39 Senior Member     Ehsan Join Date: Oct 2012 Location: Iran Posts: 2,209 Rep Power: 18 dear Bernhard it has been run for more than 50 cycles with correct timing,I suggest you define another modulo operator(like "%t"or "%%" for example) for time that maps exactly to [0,b) in the case of a%b so that the probability of mistakes of users reduces and use the notation of a%b that seems more clear than (x-epsilon)%x __________________ 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.

September 2, 2013, 17:52
#40
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,920
Rep Power: 41
Quote:
 Originally Posted by immortality dear Bernhard it has been run for more than 50 cycles with correct timing,I suggest you define another modulo operator(like "%t"or "%%" for example) for time that maps exactly to [0,b) in the case of a%b so that the probability of mistakes of users reduces and use the notation of a%b that seems more clear than (x-epsilon)%x
Write a feature request on the Mantis and I'll think about it. I'm not a big fan of bloating the grammar with stuff that can easily be written with a simple transformation. So if the %%-variant breaks the grammar I'll probably not add it
__________________
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

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post gschaider OpenFOAM 164 January 13, 2015 03:52 treima OpenFOAM Running, Solving & CFD 29 September 18, 2014 10:56 STiss OpenFOAM Programming & Development 3 October 11, 2013 02:04 treima OpenFOAM Programming & Development 2 January 26, 2013 03:37 benk OpenFOAM 3 June 2, 2011 08:49

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