|
[Sponsors] |
June 14, 2014, 10:30 |
m4 and blockMesh
|
#1 |
New Member
Martin
Join Date: Oct 2013
Location: Newcastle
Posts: 21
Rep Power: 12 |
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)) |
|
June 14, 2014, 13:40 |
|
#2 |
Senior Member
|
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 |
|
June 15, 2014, 15:01 |
|
#3 |
New Member
Martin
Join Date: Oct 2013
Location: Newcastle
Posts: 21
Rep Power: 12 |
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 | Search this Thread |
Display Modes | |
|
|