|
[Sponsors] |
October 28, 2017, 18:43 |
Problem using C in blockMesh
|
#1 |
New Member
Join Date: Oct 2017
Posts: 4
Rep Power: 9 |
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, 09:06 |
|
#2 |
Senior Member
|
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, 13:23 |
Solved
|
#3 |
New Member
Join Date: Oct 2017
Posts: 4
Rep Power: 9 |
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, 17:30 |
|
#4 |
Senior Member
|
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)' |
|
|
|
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 |