# How can I define functions with m4?

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

 April 21, 2014, 10:07 How can I define functions with m4? #1 New Member   Olivia Nalen Join Date: Apr 2014 Location: Vancouver Posts: 19 Rep Power: 4 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

 August 13, 2014, 09:38 #2 Senior Member   Join Date: Mar 2010 Location: Germany Posts: 140 Rep Power: 8 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

 August 13, 2014, 10:00 #3 Senior Member   Join Date: Mar 2010 Location: Germany Posts: 140 Rep Power: 8 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

 Tags functions, mesh

 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

 Similar Threads Thread Thread Starter Forum Replies Last Post longbk FLUENT 6 October 26, 2015 02:38 zqlhzx OpenFOAM Running, Solving & CFD 0 December 24, 2013 09:45 belkadi OpenFOAM Programming & Development 0 June 27, 2013 07:24 Ashi Fluent UDF and Scheme Programming 0 May 25, 2009 09:39 Fan Main CFD Forum 10 September 9, 2006 12:24

All times are GMT -4. The time now is 23:04.