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

[blockMesh] How can I define functions with m4?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 21, 2014, 11:07
Default How can I define functions with m4?
  #1
New Member
 
Olivia Nalen
Join Date: Apr 2014
Location: Vancouver
Posts: 19
Rep Power: 12
entropie is on a distinguished road
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
entropie is offline   Reply With Quote

Old   August 13, 2014, 10:38
Default
  #2
Senior Member
 
Join Date: Mar 2010
Location: Germany
Posts: 154
Rep Power: 16
cutter is on a distinguished road
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 is offline   Reply With Quote

Old   August 13, 2014, 11:00
Default
  #3
Senior Member
 
Join Date: Mar 2010
Location: Germany
Posts: 154
Rep Power: 16
cutter is on a distinguished road
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
cutter is offline   Reply With Quote

Reply

Tags
functions, mesh


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
udf-Surface Reaction Rate-parse error in line 34 priya_1985 FLUENT 1 November 10, 2014 03:48
Wall functions ivan-s Main CFD Forum 0 August 25, 2014 13:35
udf explaination Ijaz Fluent UDF and Scheme Programming 4 May 8, 2012 05:24
UDF problem libia87 Fluent UDF and Scheme Programming 1 May 4, 2012 22:49
UDF carbon conversion papteo Fluent UDF and Scheme Programming 1 August 18, 2011 08:32


All times are GMT -4. The time now is 12:43.