# [blockMesh] Problem using C in blockMesh

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

 October 28, 2017, 17:43 Problem using C in blockMesh #1 New Member   Join Date: Oct 2017 Posts: 4 Rep Power: 8 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) );

 October 30, 2017, 08:06 #2 Senior Member   Alexey Matveichev Join Date: Aug 2011 Location: Nancy, France Posts: 1,938 Rep Power: 38 Hi, You have #calc directive, where you can put C++ code. You can find usage examples in tutorials (using grep for example).

 November 7, 2017, 12:23 Solved #3 New Member   Join Date: Oct 2017 Posts: 4 Rep Power: 8 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)')])

 November 7, 2017, 16:30 #4 Senior Member   Alexey Matveichev Join Date: Aug 2011 Location: Nancy, France Posts: 1,938 Rep Power: 38 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.