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

[blockMesh] m4 and blockMesh

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 14, 2014, 10:30
Default m4 and blockMesh
  #1
New Member
 
Martin
Join Date: Oct 2013
Location: Newcastle
Posts: 21
Rep Power: 12
mahtin360 is on a distinguished road
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?
mahtin360 is offline   Reply With Quote

Old   June 14, 2014, 13:40
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
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.
alexeym is offline   Reply With Quote

Old   June 15, 2014, 15:01
Thumbs up
  #3
New Member
 
Martin
Join Date: Oct 2013
Location: Newcastle
Posts: 21
Rep Power: 12
mahtin360 is on a distinguished road
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)
);
mahtin360 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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



All times are GMT -4. The time now is 09:38.