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

[swak4Foam] integer part , groovyBC

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By T.D.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 14, 2011, 17:40
Default integer part , groovyBC
  #1
Senior Member
 
Join Date: Sep 2010
Posts: 226
Rep Power: 17
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: 740
Rep Power: 28
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: 4,225
Rep Power: 51
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
Posts: 226
Rep Power: 17
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, 12:12
Default
  #5
Senior Member
 
mahdi abdollahzadeh
Join Date: Mar 2011
Location: Covilha,Portugal
Posts: 153
Rep Power: 15
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, 18:48
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
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, 22:06
Default
  #7
Senior Member
 
mahdi abdollahzadeh
Join Date: Mar 2011
Location: Covilha,Portugal
Posts: 153
Rep Power: 15
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: 14
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

Old   May 26, 2017, 14:09
Default
  #9
New Member
 
Simone Colucci
Join Date: Mar 2016
Location: Pisa (Italy)
Posts: 23
Rep Power: 10
S.Colucci is on a distinguished road
Hi Nadine,
I have the same problem, did you fix that?
Thanks
Simone
Quote:
Originally Posted by nadine View Post
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
S.Colucci is offline   Reply With Quote

Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Messages: Self intersecting faces, Solid Part is not closed, Floating point. bigtoasty STAR-CCM+ 1 March 4, 2016 06:05
[swak4Foam] Varying heat flux using groovyBC with chtMultiRegionSimpleFoam hcl734 OpenFOAM Community Contributions 5 December 15, 2015 09:55
[swak4Foam] groovyBC interFoam splitted inlet -- massflowrate FerdiFuchs OpenFOAM Community Contributions 1 October 1, 2014 08:51
replacing of shock tube high pressure part with a boundary condition for low pressure immortality Main CFD Forum 0 May 2, 2013 14:30
what boundary condition is proper for simulation of shock-tube low pressure part? immortality OpenFOAM Running, Solving & CFD 0 May 2, 2013 14:22


All times are GMT -4. The time now is 18:13.