CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Meshing & Mesh Conversion

[blockMesh] Problem using C in blockMesh

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 28, 2017, 18:43
Question Problem using C in blockMesh
  #1
New Member
 
Join Date: Oct 2017
Posts: 4
Rep Power: 9
DeAldeEiam is on a distinguished road
Hello,

I have a problem with calculated values in my blockMesh file.

I get a value calculated for the amount of cells in a block
e.g. 5.666666666667
but I can only use integer
how can I round up 5.666666666667 to 6 in my blockMesh file?
I know setprecision(0) could work but how can I integrate it?

Thanks a lot

/*
this is an easy example
I get a value calculated for the amound of cells in a block
e.g. 5.666666666667
but I can only use integer6
how can I round up 5.666666666667 to 6 in my blockMesh file?
*/

roundUp 5.666666666667;

vertices
(
(0 25 10) // pt 0 (a1t)
(20 25 10) // pt 1 (a2t)
(20 3 10) // pt 2 (a3t)
(0 3 10) // pt 3 (a4t)

(0 25 0) // pt 4 (a1b)
(25 25 0) // pt 5 (a2b)
(25 2 0) // pt 6 (a3b)
(0 2 0) // pt 7 (a4b)

);

blocks
(

hex (4 7 6 5 0 3 2 1) ( 50 50 $roundUp ) simpleGrading (1 1 1)

);
DeAldeEiam is offline   Reply With Quote

Old   October 30, 2017, 09:06
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

You have #calc directive, where you can put C++ code. You can find usage examples in tutorials (using grep for example).
alexeym is offline   Reply With Quote

Old   November 7, 2017, 13:23
Default Solved
  #3
New Member
 
Join Date: Oct 2017
Posts: 4
Rep Power: 9
DeAldeEiam is on a distinguished road
Hello,

I found a solution.
You have to add Math::Round - Perl extension for rounding numbers to your calc function.

Explanation:

How to add Cpan Modules

Math::Round function

New calc function:
define(calc, [esyscmd(perl -e 'use Math::Round qw(:all); print ($1)')])
DeAldeEiam is offline   Reply With Quote

Old   November 7, 2017, 17:30
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
So, you were trying to put this into M4 script.

There is POSIX::floor and POSIX::ceil (POSIX module), which do not require installation of additional modules. I.e. you can use

Code:
perl -e 'use POSIX (floor); print floor($1)'
Though, surely you can install additional Perl modules. Or you can even go further and try to round numbers with Smalltalk.
alexeym 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
[snappyHexMesh] Problem and doubts with blockMesh, snappyHexMesh and multiple geometry luca1992 OpenFOAM Meshing & Mesh Conversion 0 August 23, 2017 12:40
[blockMesh] BlockMesh problem ari92 OpenFOAM Meshing & Mesh Conversion 2 May 27, 2017 11:23
[blockMesh] blockMesh problem with wedge blocks gned OpenFOAM Meshing & Mesh Conversion 0 September 14, 2016 06:49
[blockMesh] Problem with blockMesh and my shape TneurolF OpenFOAM Meshing & Mesh Conversion 4 June 25, 2013 14:52
Blockmesh problem with more than one block sven82 OpenFOAM Pre-Processing 1 June 4, 2013 18:08


All times are GMT -4. The time now is 07:19.