CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [blockMesh] How can I define functions with m4? (https://www.cfd-online.com/Forums/openfoam-meshing/133830-how-can-i-define-functions-m4.html)

entropie April 21, 2014 10:07

How can I define functions with m4?
 
Dear OF-Users,

I'm trying to create a blockMeshDict with m4. I need to define all coordinates on the Z-axis as functions of coordinates on the X-axis. So far my m4-code looks like this:

define (x1, 7)
define (x2, 5)
...
define (x20, 4)

define (z1, calc(x1*2+1))
define (z2, calc(x2*2+1))
...
define (z20, calc(x20*2+1))
etc.

And the problem is, I have about 100 coordinates and it is a bit awkward to define all 100 coordinates one by one.

Maybe can somebody tell me how can I just once define a function for all Z-coordinates, if it's possible?

Best regards,
Olivia

cutter August 13, 2014 09:38

Hi,

you could use any scripting or programming language to write the contents of the blockMeshDict.

For example the following Python script
Code:

#!/usr/bin/env python


def func(x):
    return x*2.+1.


def main():
    for i in range(0, 11):
        x = .1*i
        z = func(x)
        print 'x{} {};'.format(i,x)
        print 'z{} {};'.format(i,z)


if __name__ == "__main__":
    main()

would result in
Code:

x0 0.0;                                                                                                                                                                                     
z0 1.0;                                                                                                                                                                                     
x1 0.1;
z1 1.2;
x2 0.2;
z2 1.4;
x3 0.3;
z3 1.6;
x4 0.4;
z4 1.8;
x5 0.5;
z5 2.0;
x6 0.6;
z6 2.2;
x7 0.7;
z7 2.4;
x8 0.8;
z8 2.6;
x9 0.9;
z9 2.8;
x10 1.0;
z10 3.0;

Cutter

cutter August 13, 2014 10:00

The above post was just a workaround for your problem. Regarding your initial question on m4, maybe the following link helps:

http://www.slac.stanford.edu/comp/un...nfo/m4_11.html


All times are GMT -4. The time now is 03:37.