# m4 and blockMesh

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

 June 14, 2014, 09:30 m4 and blockMesh #1 New Member   Martin Nberg Join Date: Oct 2013 Location: Newcastle Upon Tyne` Posts: 11 Rep Power: 5 Hello, I have a rather simple question about using m4 to generate blockMeshDicts in OpenFOAM 2.3.0. I want to specify the dimension of my domain in an m4 blockMeshDict where all dimensions are based on a characteristic length. In order to use snappyHexMesh i'm using the same spacing in all three directions to have an aspect ratio of 1. Now I'm just wondering if there's a simple command that would give me the output of the calculation below as integer to that it can be used in blockMesh? Code: ```define(nrcellsx,calc((((dd+ud))/delta))) define(nrcellsy,calc(((1+cl+cr))/delta)) define(nrcellsz,calc(((1+ti+sc))/delta))``` Does anyone have a simple solution to this?

 June 14, 2014, 12:40 #2 Senior Member   Alexey Matveichev Join Date: Aug 2011 Location: Nancy, France Posts: 1,423 Rep Power: 25 Hi, I guess, you'd like to do floating point calculations as for integer expressions there is eval macro (https://www.gnu.org/savannah-checkou...Eval.html#Eval). You can try something like this (maybe there is easier way): Code: ```define(`calc', `esyscmd(echo "scale = 10; \$1" | bc)')dnl define(`dd', 100)dnl define(`ud', 356)dnl define(`cl', 18.09)dnl define(`cr', 20.01)dnl define(`ti', 345.5)dnl define(`sc', 567.9)dnl define(`delta', 100)dnl define(`nrcellsx_expr', format(`(%f + %f)/%f', dd, ud, delta))dnl define(`nrcellsy_expr', format(`(1 + %f + %f)/%f', cl, cr, delta))dnl define(`nrcellsz_expr', format(`(1 + %f + %f)/%f', ti, sc, delta))dnl define(`nrcellsx', calc(nrcellsx_expr))dnl nrcellsx()dnl``` To get integer value from calc macro, remove "scale = 10;" in echo command.

 June 15, 2014, 14:01 #3 New Member   Martin Nberg Join Date: Oct 2013 Location: Newcastle Upon Tyne` Posts: 11 Rep Power: 5 Hi Alexey, thanks for your reply. Using your suggestions and the example from the OpenFOAM wiki I've come up with this now Code: ```changecom(//)changequote([,]) define(calce, [esyscmd(perl -e 'printf (\$1)')]) define(calc, [esyscmd(echo " \$1" | bc)])dnl // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // convertToMeters 1; define(D, 90) define(dd, 20) define(ud, 5) define(ti, 2) define(sc, 0.5) define(cl, 1) define(cr, 1) define(delta, 25) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // define(xmin, calce(0 - dd*D)) define(xmax, calce(0 + ud*D)) define(ymin, calce(x*D - cl*D)) define(ymax, calce(x*D + cr*D)) define(zmin, calce(x*D - sc*D)) define(zmax, calce(x*D + ti*D)) define(nx_exp, format(((%f + %f)*%f)/%f, dd, ud, D, delta)) define(ny_exp, format(((1 + %f + %f)*%f)/%f, cl, cr, D, delta)) define(nz_exp, format(((1 + %f + %f)*%f)/%f, ti, sc, D, delta)) define(nx, calc(nx_exp)) define(ny, calc(ny_exp)) define(nz, calc(nz_exp)) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // vertices ( (xmin ymin zmin)//0 (xmax ymin zmin)//1 (xmax ymax zmin)//2 (xmin ymax zmin)//3 (xmin ymin zmax)//4 (xmax ymin zmax)//5 (xmax ymax zmax)//6 (xmin ymax zmax)//7 ); blocks ( hex (0 1 2 3 4 5 6 7) (nx ny nz) simpleGrading (1 1 1) );```

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

All times are GMT -4. The time now is 02:33.