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

integer part , groovyBC

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

Like Tree1Likes
  • 1 Post By T.D.

Reply
 
LinkBack Thread Tools Display Modes
Old   March 14, 2011, 17:40
Default integer part , groovyBC
  #1
Senior Member
 
Join Date: Sep 2010
Location: France
Posts: 193
Rep Power: 6
T.D. is on a distinguished road
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
mm.abdollahzadeh likes this.
T.D. is offline   Reply With Quote

Old   March 14, 2011, 19:01
Default
  #2
Senior Member
 
mturcios777's Avatar
 
Marco A. Turcios
Join Date: Mar 2009
Location: Vancouver, BC, Canada
Posts: 727
Rep Power: 18
mturcios777 will become famous soon enough
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.
mturcios777 is offline   Reply With Quote

Old   March 15, 2011, 06:45
Default
  #3
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by mturcios777 View Post
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
gschaider is offline   Reply With Quote

Old   March 15, 2011, 06:50
Default
  #4
Senior Member
 
Join Date: Sep 2010
Location: France
Posts: 193
Rep Power: 6
T.D. is on a distinguished road
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) ) ;
}
T.D. is offline   Reply With Quote

Old   October 12, 2012, 11:12
Default
  #5
Senior Member
 
mahdi abdollahzadeh
Join Date: Mar 2011
Location: Covilha,Portugal
Posts: 149
Rep Power: 6
mm.abdollahzadeh is on a distinguished road
Quote:
Originally Posted by T.D. View Post
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
mm.abdollahzadeh is offline   Reply With Quote

Old   October 12, 2012, 17:48
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by mm.abdollahzadeh View Post
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)
__________________
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   October 12, 2012, 21:06
Default
  #7
Senior Member
 
mahdi abdollahzadeh
Join Date: Mar 2011
Location: Covilha,Portugal
Posts: 149
Rep Power: 6
mm.abdollahzadeh is on a distinguished road
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
mm.abdollahzadeh is offline   Reply With Quote

Old   February 28, 2014, 11:41
Default
  #8
Member
 
nadine moussa
Join Date: Mar 2012
Posts: 30
Rep Power: 5
nadine is on a distinguished road
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
nadine is offline   Reply With Quote

Reply

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
groovyBC and funkySetFields married and got a kid named swak4Foam gschaider OpenFOAM 164 January 13, 2015 03:52
Wall heat transfer using groovyBC (XiFoam solver) usergk OpenFOAM 7 February 4, 2011 14:36
icem hexa - load different blockings for each part of geometry??? Catthan ANSYS Meshing & Geometry 2 May 28, 2010 11:27
How to output data from stationary part only? Aerolex FLUENT 0 November 16, 2009 23:46
Any other way of converting a multi part to a single part avoiding ANSYS Design Model LusoMundo ANSYS Meshing & Geometry 1 May 14, 2009 14:35


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