CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [swak4Foam] how to repeat a cycle in groovyBC (https://www.cfd-online.com/Forums/openfoam-community-contributions/111406-how-repeat-cycle-groovybc.html)

immortality April 26, 2013 16:28

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.

immortality April 27, 2013 14:10

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)

immortality April 27, 2013 17:56

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<t_mapped&&t_mapped<t1+c1)||(t1+c2<t_mapped&&t_mapped<t1+c3) ? 1 : 0";
could somebody help?

immortality April 28, 2013 08:00

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.

immortality July 30, 2013 12:52

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<t_mappedr && t_mappedr<t1+c2r);"
if t_mapped be between [-c5r/2,c5r) as you have told it should be a negative value in earlier times and port2 should be false always,but the expressions related to port2 condition execute then it seems the mapped domain starts from zero than a negative value,on the other hand expressions of conditions that t_mapped is bigger than c5r/2 are not execute.
so it seems as I told before the mapped domain is [0,b/2).
I'm waiting to your kind clarifications. thanks.

gschaider July 30, 2013 13:26

Quote:

Originally Posted by immortality (Post 442877)
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

immortality July 30, 2013 14:04

Hi Bernhard
but negative time has no meaning and it seems it omits negative times in the modular code,doesn't?

gschaider July 31, 2013 06:50

Quote:

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

immortality July 31, 2013 16: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):confused:
whats the way to see t_mappedl values in each time step?:)

immortality August 1, 2013 11:45

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?

immortality August 1, 2013 13:52

1 Attachment(s)
Quote:

Originally Posted by gschaider (Post 442887)
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?

immortality August 1, 2013 14:02

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.

immortality August 1, 2013 16:52

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.

gschaider August 1, 2013 18:42

Quote:

Originally Posted by immortality (Post 443374)
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)

gschaider August 1, 2013 18:49

Quote:

Originally Posted by gschaider (Post 443392)
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

immortality August 2, 2013 06:51

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<x/2
OK then I should use a condition for a%b if its in [0,b/2) use itself(a%b) but if a%b becomes a number in [-b/2,0) then I have to use "a%b+b" so that all numbers be in [0,b].is my conclusion now right in your opinion dear Bernhard or not? :)

immortality August 2, 2013 15:51

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.

immortality August 3, 2013 07:59

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)

immortality August 30, 2013 06:58

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:)

gschaider September 2, 2013 17:52

Quote:

Originally Posted by immortality (Post 448884)
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


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