CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   integer part , groovyBC (http://www.cfd-online.com/Forums/openfoam/86107-integer-part-groovybc.html)

T.D. March 14, 2011 17:40

integer part , groovyBC
 
Hi,
Any ideas how to get the integer part of a decimal number inside the groovyBC library?
example: integer part of "2.356" to be "2", and "5.897" to be "5"

so it is rounding towards zero

??

if it does not exist in the groovyBC, how to do that inside the openFoam library?

thanks

mturcios777 March 14, 2011 19:01

The C++ function floor() would do the trick, but from the groovyBC page it is not evident if these have been implemented. In a related note, I used funkySetFields to set some initial conditions and used an error function distribution. erf() wasn't listed with implemented functions, but it worked anyway. I think if its implemented in standard C/C++ math libraries, it should work.

gschaider March 15, 2011 06:45

Quote:

Originally Posted by mturcios777 (Post 299412)
The C++ function floor() would do the trick, but from the groovyBC page it is not evident if these have been implemented. In a related note, I used funkySetFields to set some initial conditions and used an error function distribution. erf() wasn't listed with implemented functions, but it worked anyway. I think if its implemented in standard C/C++ math libraries, it should work.

Sorry no. The reason that erf worked is that the documentation wasn't up to date in that respect. I'm afraid floor won't work. What works is the modulo operator % (it has the same weird behaviour as in funkySetFields ... see documentation there). So something like "T-(T % 1)" might give you somethin 'floor'-like.

BTW: should the behaviour of groovyBC etc differ from the documentaiton feel free to modify the documentation

BTW2: if a feature-request pops up in the swak4Foam-Mantis I might implement the floor-function

T.D. March 15, 2011 06:50

Hi,
thanks, yes i solved it that way
and here is my square wave of ampitude A, and period T=10

//assign a square wave of amplitude A=0.015 at the U boundary Patch "upperWall" as function of time
// Get index of patch at upperWall
label indexOfPatch = mesh.boundaryMesh().findPatchID("upperWall");
forAll(mesh.boundaryMesh()[indexOfPatch],celll)
{

U.boundaryField()[indexOfPatch][celll].component(0) = 0.015 * pow( -1, floor( (runTime.value())/10) ) ;
}

mm.abdollahzadeh October 12, 2012 11:12

Quote:

Originally Posted by T.D. (Post 299405)
Hi,
Any ideas how to get the integer part of a decimal number inside the groovyBC library?
example: integer part of "2.356" to be "2", and "5.897" to be "5"

so it is rounding towards zero

??

if it does not exist in the groovyBC, how to do that inside the openFoam library?

thanks

Dear Friend

Do you know how to use floor function inside openfoam code?

I want to do floor(T.internalfield)

Best
Mahdi

gschaider October 12, 2012 17:48

Quote:

Originally Posted by mm.abdollahzadeh (Post 386298)
Dear Friend

Do you know how to use floor function inside openfoam code?

I want to do floor(T.internalfield)

Best
Mahdi

As there is no floor (and ceil for the matter) implemented for fields in OF there currently is no equivalent in the groovyBC-grammar. BUT: you can do something like this using the % to get the non-integer part and subtracting it from the original value: http://openfoamwiki.net/index.php/Co...e_implemented:

(note that due to the way % is defined in OF you've got to add/subtract 0.5 before/after using the operator to get the result you want. But you'll figure that out)

mm.abdollahzadeh October 12, 2012 21:06

Dear Friend

Thanks for your reply .

The problem was that if you try to use the floor function inside the openfoam code (notgroovybc) it will gives you the error that floor can be used just for float or long float or double varibales.
But i solved it.
If you go to primitive folder and change in all the files acording to sqrt ... and then recomplie your openfoam folder ... floor will work will all types of variables

Best
Mahdi

nadine February 28, 2014 11:41

Hello Mahdi,

I want to do the same, can you please be more specific about your answer?

If you go to primitive folder and change in all the files acording to sqrt ... and then recomplie your openfoam folder ... floor will work will all types of variables

which primitive folder? and what did you changed?

thank you,
Nadine


All times are GMT -4. The time now is 09:29.